announce.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ACCTYPES, AnnouncementSigGen, ArgumentParser, Base, C, Command, E, PackageJson, S, ST, User, a_json_parse, add_option_dict, assert, bitcoyne, dict_union, drain, fs, iced, iutils, log, make_esc, prompt_remote_name, prompt_yn, proofs, req, session, stream_open, util, __iced_k, __iced_k_noop, _ref,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. iced = require('iced-runtime').iced;
  7. __iced_k = __iced_k_noop = function() {};
  8. Base = require('./base').Base;
  9. log = require('../log');
  10. ArgumentParser = require('argparse').ArgumentParser;
  11. add_option_dict = require('./argparse').add_option_dict;
  12. C = require('../constants').constants;
  13. ST = C.signature_types;
  14. ACCTYPES = C.allowed_cryptocurrency_types;
  15. PackageJson = require('../package').PackageJson;
  16. E = require('../err').E;
  17. make_esc = require('iced-error').make_esc;
  18. _ref = require('../prompter'), prompt_yn = _ref.prompt_yn, prompt_remote_name = _ref.prompt_remote_name;
  19. User = require('../user').User;
  20. req = require('../req').req;
  21. assert = require('assert');
  22. session = require('../session');
  23. S = require('../services');
  24. dict_union = require('../util').dict_union;
  25. iutils = require('iced-utils');
  26. drain = iutils.drain.drain;
  27. a_json_parse = iutils.util.a_json_parse;
  28. util = require('util');
  29. fs = require('fs');
  30. proofs = require('keybase-proofs');
  31. bitcoyne = require('bitcoyne');
  32. AnnouncementSigGen = require('../sigs').AnnouncementSigGen;
  33. stream_open = function(f, cb) {
  34. var ret;
  35. ret = fs.createReadStream(f);
  36. ret.on('error', function(err) {
  37. err = new E.NotFoundError("Could not open file '" + f + "': " + err.code);
  38. return cb(err, null);
  39. });
  40. return ret.on('open', function() {
  41. return cb(null, ret);
  42. });
  43. };
  44. exports.Command = Command = (function(_super) {
  45. __extends(Command, _super);
  46. function Command() {
  47. return Command.__super__.constructor.apply(this, arguments);
  48. }
  49. Command.prototype.OPTS = {
  50. j: {
  51. alias: 'json',
  52. action: 'storeTrue',
  53. help: 'interpret the announcement as JSON object'
  54. },
  55. e: {
  56. alias: 'encode',
  57. action: 'storeTrue',
  58. help: 'encode the announcement with base64-encoding'
  59. },
  60. f: {
  61. alias: 'file',
  62. help: 'Specify a file as the announcment'
  63. },
  64. m: {
  65. alias: 'message',
  66. help: 'Specify a message as the announcement"'
  67. }
  68. };
  69. Command.prototype.use_session = function() {
  70. return true;
  71. };
  72. Command.prototype.needs_configuration = function() {
  73. return true;
  74. };
  75. Command.prototype.add_subcommand_parser = function(scp) {
  76. var name, opts, sub;
  77. opts = {
  78. aliases: [],
  79. help: "make an announcement, stored to your signature chain"
  80. };
  81. name = "announce";
  82. sub = scp.addParser(name, opts);
  83. add_option_dict(sub, this.OPTS);
  84. return opts.aliases.concat([name]);
  85. };
  86. Command.prototype.parse_args = function(cb) {
  87. var err;
  88. err = null;
  89. if (this.argv.encode && this.argv.json) {
  90. err = new E.ArgsError("can't specify both -j/--json and -e/--encode");
  91. } else if (this.argv.file && this.argv.message) {
  92. err = new E.ArgsError("can't specify both -f/--file and -m/--message");
  93. }
  94. return cb(err);
  95. };
  96. Command.prototype.allocate_proof_gen = function(cb) {
  97. var arg, err, klass, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  98. __iced_k = __iced_k_noop;
  99. ___iced_passed_deferral = iced.findDeferral(arguments);
  100. klass = AnnouncementSigGen;
  101. arg = {
  102. announcement: this.announcement
  103. };
  104. (function(_this) {
  105. return (function(__iced_k) {
  106. __iced_deferrals = new iced.Deferrals(__iced_k, {
  107. parent: ___iced_passed_deferral,
  108. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  109. funcname: "Command.allocate_proof_gen"
  110. });
  111. _this.me.gen_sig_base({
  112. klass: klass,
  113. arg: arg
  114. }, __iced_deferrals.defer({
  115. assign_fn: (function(__slot_1) {
  116. return function() {
  117. err = arguments[0];
  118. return __slot_1.gen = arguments[1];
  119. };
  120. })(_this),
  121. lineno: 88
  122. }));
  123. __iced_deferrals._fulfill();
  124. });
  125. })(this)((function(_this) {
  126. return function() {
  127. return cb(err);
  128. };
  129. })(this));
  130. };
  131. Command.prototype.load_announcement = function(cb) {
  132. var esc, f, m, stream, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  133. __iced_k = __iced_k_noop;
  134. ___iced_passed_deferral = iced.findDeferral(arguments);
  135. stream = null;
  136. esc = make_esc(cb, "Command::load_announcement");
  137. (function(_this) {
  138. return (function(__iced_k) {
  139. if ((m = _this.argv.message) != null) {
  140. return __iced_k(_this.raw = new Buffer(m, 'utf8'));
  141. } else {
  142. (function(__iced_k) {
  143. if ((f = _this.argv.file) != null) {
  144. (function(__iced_k) {
  145. __iced_deferrals = new iced.Deferrals(__iced_k, {
  146. parent: ___iced_passed_deferral,
  147. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  148. funcname: "Command.load_announcement"
  149. });
  150. stream_open(f, esc(__iced_deferrals.defer({
  151. assign_fn: (function() {
  152. return function() {
  153. return stream = arguments[0];
  154. };
  155. })(),
  156. lineno: 98
  157. })));
  158. __iced_deferrals._fulfill();
  159. })(__iced_k);
  160. } else {
  161. return __iced_k(stream = process.stdin);
  162. }
  163. })(__iced_k);
  164. }
  165. });
  166. })(this)((function(_this) {
  167. return function() {
  168. (function(__iced_k) {
  169. if (stream != null) {
  170. (function(__iced_k) {
  171. __iced_deferrals = new iced.Deferrals(__iced_k, {
  172. parent: ___iced_passed_deferral,
  173. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  174. funcname: "Command.load_announcement"
  175. });
  176. drain(stream, esc(__iced_deferrals.defer({
  177. assign_fn: (function(__slot_1) {
  178. return function() {
  179. return __slot_1.raw = arguments[0];
  180. };
  181. })(_this),
  182. lineno: 102
  183. })));
  184. __iced_deferrals._fulfill();
  185. })(__iced_k);
  186. } else {
  187. return __iced_k();
  188. }
  189. })(function() {
  190. return cb(null);
  191. });
  192. };
  193. })(this));
  194. };
  195. Command.prototype.encode_ennouncement = function(cb) {
  196. var data, encoding, esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  197. __iced_k = __iced_k_noop;
  198. ___iced_passed_deferral = iced.findDeferral(arguments);
  199. esc = make_esc(cb, "Command::encode_announcement");
  200. (function(_this) {
  201. return (function(__iced_k) {
  202. if (_this.argv.json) {
  203. (function(__iced_k) {
  204. __iced_deferrals = new iced.Deferrals(__iced_k, {
  205. parent: ___iced_passed_deferral,
  206. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  207. funcname: "Command.encode_ennouncement"
  208. });
  209. a_json_parse(_this.raw.toString('utf8'), esc(__iced_deferrals.defer({
  210. assign_fn: (function() {
  211. return function() {
  212. return data = arguments[0];
  213. };
  214. })(),
  215. lineno: 110
  216. })));
  217. __iced_deferrals._fulfill();
  218. })(function() {
  219. return __iced_k(encoding = "json");
  220. });
  221. } else {
  222. return __iced_k(_this.argv.encode ? (data = _this.raw.toString('base64'), encoding = "base64") : (encoding = "utf8", data = _this.raw.toString('utf8')));
  223. }
  224. });
  225. })(this)((function(_this) {
  226. return function() {
  227. _this.announcement = {
  228. data: data,
  229. encoding: encoding
  230. };
  231. return cb(null);
  232. };
  233. })(this));
  234. };
  235. Command.prototype.run = function(cb) {
  236. var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  237. __iced_k = __iced_k_noop;
  238. ___iced_passed_deferral = iced.findDeferral(arguments);
  239. esc = make_esc(cb, "Command::run");
  240. (function(_this) {
  241. return (function(__iced_k) {
  242. __iced_deferrals = new iced.Deferrals(__iced_k, {
  243. parent: ___iced_passed_deferral,
  244. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  245. funcname: "Command.run"
  246. });
  247. _this.parse_args(esc(__iced_deferrals.defer({
  248. lineno: 125
  249. })));
  250. __iced_deferrals._fulfill();
  251. });
  252. })(this)((function(_this) {
  253. return function() {
  254. (function(__iced_k) {
  255. __iced_deferrals = new iced.Deferrals(__iced_k, {
  256. parent: ___iced_passed_deferral,
  257. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  258. funcname: "Command.run"
  259. });
  260. session.login(esc(__iced_deferrals.defer({
  261. lineno: 126
  262. })));
  263. __iced_deferrals._fulfill();
  264. })(function() {
  265. (function(__iced_k) {
  266. __iced_deferrals = new iced.Deferrals(__iced_k, {
  267. parent: ___iced_passed_deferral,
  268. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  269. funcname: "Command.run"
  270. });
  271. User.load_me({
  272. secret: true
  273. }, esc(__iced_deferrals.defer({
  274. assign_fn: (function(__slot_1) {
  275. return function() {
  276. return __slot_1.me = arguments[0];
  277. };
  278. })(_this),
  279. lineno: 127
  280. })));
  281. __iced_deferrals._fulfill();
  282. })(function() {
  283. (function(__iced_k) {
  284. __iced_deferrals = new iced.Deferrals(__iced_k, {
  285. parent: ___iced_passed_deferral,
  286. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  287. funcname: "Command.run"
  288. });
  289. _this.load_announcement(esc(__iced_deferrals.defer({
  290. lineno: 128
  291. })));
  292. __iced_deferrals._fulfill();
  293. })(function() {
  294. (function(__iced_k) {
  295. __iced_deferrals = new iced.Deferrals(__iced_k, {
  296. parent: ___iced_passed_deferral,
  297. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  298. funcname: "Command.run"
  299. });
  300. _this.encode_ennouncement(esc(__iced_deferrals.defer({
  301. lineno: 129
  302. })));
  303. __iced_deferrals._fulfill();
  304. })(function() {
  305. (function(__iced_k) {
  306. __iced_deferrals = new iced.Deferrals(__iced_k, {
  307. parent: ___iced_passed_deferral,
  308. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  309. funcname: "Command.run"
  310. });
  311. _this.allocate_proof_gen(esc(__iced_deferrals.defer({
  312. lineno: 130
  313. })));
  314. __iced_deferrals._fulfill();
  315. })(function() {
  316. (function(__iced_k) {
  317. __iced_deferrals = new iced.Deferrals(__iced_k, {
  318. parent: ___iced_passed_deferral,
  319. filename: "/Users/max/src/keybase/node-client/src/command/announce.iced",
  320. funcname: "Command.run"
  321. });
  322. _this.gen.run(esc(__iced_deferrals.defer({
  323. lineno: 131
  324. })));
  325. __iced_deferrals._fulfill();
  326. })(function() {
  327. log.info("Success!");
  328. return cb(null);
  329. });
  330. });
  331. });
  332. });
  333. });
  334. });
  335. };
  336. })(this));
  337. };
  338. return Command;
  339. })(Base);
  340. }).call(this);