sigchain.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ACCTYPES, BTC, CHECK, E, Link, LinkTable, Proof, ProofSet, SHA256, ST, SigCache, SigChain, Warnings, asyncify, athrow, bitcoyne, cheerio, colors, constants, date_to_unix, db, deq, dict_union, env, format_fingerprint, fs, iced, libkeybase, log, make_email, make_esc, merkle_client, proofs, req, request, scrapemod, util, __iced_k, __iced_k_noop, _ref, _ref1, _ref2, _ref3, _ref4;
  4. iced = require('iced-runtime').iced;
  5. __iced_k = __iced_k_noop = function() {};
  6. db = require('./db');
  7. req = require('./req');
  8. log = require('./log');
  9. constants = require('./constants').constants;
  10. SHA256 = require('./keyutils').SHA256;
  11. E = require('./err').E;
  12. _ref = require('pgp-utils').util, format_fingerprint = _ref.format_fingerprint, Warnings = _ref.Warnings, asyncify = _ref.asyncify;
  13. make_esc = require('iced-error').make_esc;
  14. ST = constants.signature_types;
  15. ACCTYPES = constants.allowed_cryptocurrency_types;
  16. _ref1 = require('./util'), dict_union = _ref1.dict_union, date_to_unix = _ref1.date_to_unix, make_email = _ref1.make_email;
  17. proofs = require('keybase-proofs');
  18. cheerio = require('cheerio');
  19. request = require('request');
  20. colors = require('./colors');
  21. deq = require('deep-equal');
  22. util = require('util');
  23. fs = require('fs');
  24. env = require('./env').env;
  25. scrapemod = require('./scrapers');
  26. _ref2 = require('./display'), CHECK = _ref2.CHECK, BTC = _ref2.BTC;
  27. athrow = require('iced-utils').util.athrow;
  28. merkle_client = require('./merkle_client').merkle_client;
  29. bitcoyne = require('bitcoyne');
  30. _ref3 = require('./chainlink'), Link = _ref3.Link, LinkTable = _ref3.LinkTable;
  31. _ref4 = require('libkeybase').assertion, Proof = _ref4.Proof, ProofSet = _ref4.ProofSet;
  32. libkeybase = require('libkeybase');
  33. exports.SigChain = SigChain = (function() {
  34. function SigChain(uid, username, _links) {
  35. this.uid = uid;
  36. this.username = username;
  37. this._links = _links != null ? _links : [];
  38. this._lookup = {};
  39. this._index_links(this._links);
  40. this._true_last = null;
  41. }
  42. SigChain.prototype._index_links = function(list) {
  43. var l, _i, _len, _results;
  44. _results = [];
  45. for (_i = 0, _len = list.length; _i < _len; _i++) {
  46. l = list[_i];
  47. _results.push(this._lookup[l.id] = l);
  48. }
  49. return _results;
  50. };
  51. SigChain.prototype.lookup = function(id) {
  52. return this._lookup[id];
  53. };
  54. SigChain.load = function(uid, username, curr, cb) {
  55. var err, link, links, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  56. __iced_k = __iced_k_noop;
  57. ___iced_passed_deferral = iced.findDeferral(arguments);
  58. log.debug("+ " + uid + ": load signature chain");
  59. links = [];
  60. err = null;
  61. ret = null;
  62. (function(_this) {
  63. return (function(__iced_k) {
  64. var _results, _while;
  65. _results = [];
  66. _while = function(__iced_k) {
  67. var _break, _continue, _next;
  68. _break = function() {
  69. return __iced_k(_results);
  70. };
  71. _continue = function() {
  72. return iced.trampoline(function() {
  73. return _while(__iced_k);
  74. });
  75. };
  76. _next = function(__iced_next_arg) {
  77. _results.push(__iced_next_arg);
  78. return _continue();
  79. };
  80. if (!(curr && (err == null))) {
  81. return _break();
  82. } else {
  83. log.debug("| " + uid + ": Loading link " + curr);
  84. (function(__iced_k) {
  85. __iced_deferrals = new iced.Deferrals(__iced_k, {
  86. parent: ___iced_passed_deferral,
  87. filename: "/home/jacko/node-client/src/sigchain.iced",
  88. funcname: "SigChain.load"
  89. });
  90. Link.load(curr, __iced_deferrals.defer({
  91. assign_fn: (function() {
  92. return function() {
  93. err = arguments[0];
  94. return link = arguments[1];
  95. };
  96. })(),
  97. lineno: 56
  98. }));
  99. __iced_deferrals._fulfill();
  100. })(function() {
  101. return _next(err != null ? (log.error("Couldn't find link: " + last), log.debug("| -> error")) : typeof link !== "undefined" && link !== null ? (links.push(link), curr = link.prev(), log.debug("| -> found link and previous; prev=" + curr)) : (log.debug("| -> reached the chain end"), curr = null));
  102. });
  103. }
  104. };
  105. _while(__iced_k);
  106. });
  107. })(this)((function(_this) {
  108. return function() {
  109. if (err == null) {
  110. ret = new SigChain(uid, username, links.reverse());
  111. }
  112. log.debug("- " + uid + ": loaded signature chain");
  113. return cb(err, ret);
  114. };
  115. })(this));
  116. };
  117. SigChain.prototype.last_seqno = function() {
  118. var l;
  119. if ((l = this.last()) != null) {
  120. return l.seqno();
  121. } else {
  122. return null;
  123. }
  124. };
  125. SigChain.prototype._update = function(cb) {
  126. var args, body, did_update, esc, link, new_links, obj, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  127. __iced_k = __iced_k_noop;
  128. ___iced_passed_deferral = iced.findDeferral(arguments);
  129. log.debug("+ sigchain::_update");
  130. esc = make_esc(cb, "_update");
  131. args = {
  132. uid: this.uid,
  133. low: this.last_seqno() + 1
  134. };
  135. (function(_this) {
  136. return (function(__iced_k) {
  137. __iced_deferrals = new iced.Deferrals(__iced_k, {
  138. parent: ___iced_passed_deferral,
  139. filename: "/home/jacko/node-client/src/sigchain.iced",
  140. funcname: "SigChain._update"
  141. });
  142. req.get({
  143. endpoint: "sig/get",
  144. args: args
  145. }, esc(__iced_deferrals.defer({
  146. assign_fn: (function() {
  147. return function() {
  148. return body = arguments[0];
  149. };
  150. })(),
  151. lineno: 82
  152. })));
  153. __iced_deferrals._fulfill();
  154. });
  155. })(this)((function(_this) {
  156. return function() {
  157. log.debug("| found " + body.sigs.length + " new signatures");
  158. new_links = [];
  159. did_update = false;
  160. (function(__iced_k) {
  161. var _i, _len, _ref5, _results, _while;
  162. _ref5 = body.sigs;
  163. _len = _ref5.length;
  164. _i = 0;
  165. _results = [];
  166. _while = function(__iced_k) {
  167. var _break, _continue, _next;
  168. _break = function() {
  169. return __iced_k(_results);
  170. };
  171. _continue = function() {
  172. return iced.trampoline(function() {
  173. ++_i;
  174. return _while(__iced_k);
  175. });
  176. };
  177. _next = function(__iced_next_arg) {
  178. _results.push(__iced_next_arg);
  179. return _continue();
  180. };
  181. if (!(_i < _len)) {
  182. return _break();
  183. } else {
  184. obj = _ref5[_i];
  185. link = Link.alloc({
  186. obj: obj
  187. });
  188. (function(__iced_k) {
  189. __iced_deferrals = new iced.Deferrals(__iced_k, {
  190. parent: ___iced_passed_deferral,
  191. filename: "/home/jacko/node-client/src/sigchain.iced",
  192. funcname: "SigChain._update"
  193. });
  194. asyncify(link.verify(), esc(__iced_deferrals.defer({
  195. lineno: 88
  196. })));
  197. __iced_deferrals._fulfill();
  198. })(function() {
  199. new_links.push(link);
  200. return _next(did_update = true);
  201. });
  202. }
  203. };
  204. _while(__iced_k);
  205. })(function() {
  206. _this._links = _this._links.concat(new_links);
  207. _this._new_links = new_links;
  208. _this._index_links(new_links);
  209. log.debug("- sigchain::_update");
  210. return cb(null, did_update);
  211. });
  212. };
  213. })(this));
  214. };
  215. SigChain.prototype.store = function(cb) {
  216. var err, link, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  217. __iced_k = __iced_k_noop;
  218. ___iced_passed_deferral = iced.findDeferral(arguments);
  219. err = null;
  220. (function(_this) {
  221. return (function(__iced_k) {
  222. var _ref5;
  223. if ((_ref5 = _this._new_links) != null ? _ref5.length : void 0) {
  224. log.debug("+ writing dirty signature chain");
  225. (function(__iced_k) {
  226. var _i, _len, _ref6, _results, _while;
  227. _ref6 = _this._new_links;
  228. _len = _ref6.length;
  229. _i = 0;
  230. _results = [];
  231. _while = function(__iced_k) {
  232. var _break, _continue, _next;
  233. _break = function() {
  234. return __iced_k(_results);
  235. };
  236. _continue = function() {
  237. return iced.trampoline(function() {
  238. ++_i;
  239. return _while(__iced_k);
  240. });
  241. };
  242. _next = function(__iced_next_arg) {
  243. _results.push(__iced_next_arg);
  244. return _continue();
  245. };
  246. if (!(_i < _len)) {
  247. return _break();
  248. } else {
  249. link = _ref6[_i];
  250. if (err == null) {
  251. (function(__iced_k) {
  252. __iced_deferrals = new iced.Deferrals(__iced_k, {
  253. parent: ___iced_passed_deferral,
  254. filename: "/home/jacko/node-client/src/sigchain.iced",
  255. funcname: "SigChain.store"
  256. });
  257. link.store(__iced_deferrals.defer({
  258. assign_fn: (function() {
  259. return function() {
  260. return err = arguments[0];
  261. };
  262. })(),
  263. lineno: 104
  264. }));
  265. __iced_deferrals._fulfill();
  266. })(_next);
  267. } else {
  268. return _continue();
  269. }
  270. }
  271. };
  272. _while(__iced_k);
  273. })(function() {
  274. return __iced_k(log.debug("- wrote signature chain"));
  275. });
  276. } else {
  277. return __iced_k();
  278. }
  279. });
  280. })(this)((function(_this) {
  281. return function() {
  282. return cb(err);
  283. };
  284. })(this));
  285. };
  286. SigChain.prototype.update = function(remote_seqno, cb) {
  287. var a, b, did_update, err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  288. __iced_k = __iced_k_noop;
  289. ___iced_passed_deferral = iced.findDeferral(arguments);
  290. err = null;
  291. did_update = false;
  292. (function(_this) {
  293. return (function(__iced_k) {
  294. if (((a = remote_seqno) == null) || a > (b = _this.last_seqno())) {
  295. log.debug("| sigchain update: " + a + " vs. " + b);
  296. (function(__iced_k) {
  297. __iced_deferrals = new iced.Deferrals(__iced_k, {
  298. parent: ___iced_passed_deferral,
  299. filename: "/home/jacko/node-client/src/sigchain.iced",
  300. funcname: "SigChain.update"
  301. });
  302. _this._update(__iced_deferrals.defer({
  303. assign_fn: (function() {
  304. return function() {
  305. err = arguments[0];
  306. return did_update = arguments[1];
  307. };
  308. })(),
  309. lineno: 115
  310. }));
  311. __iced_deferrals._fulfill();
  312. })(function() {
  313. return __iced_k((remote_seqno != null) && ((a = remote_seqno) !== (b = _this.last_seqno())) ? err = new E.CorruptionError("failed to appropriately update chain: " + a + " != " + b) : void 0);
  314. });
  315. } else {
  316. return __iced_k();
  317. }
  318. });
  319. })(this)((function(_this) {
  320. return function() {
  321. return cb(err, did_update);
  322. };
  323. })(this));
  324. };
  325. SigChain.prototype.last = function() {
  326. var _ref5;
  327. if ((_ref5 = this._links) != null ? _ref5.length : void 0) {
  328. return this._links.slice(-1)[0];
  329. } else {
  330. return null;
  331. }
  332. };
  333. SigChain.prototype.true_last = function() {
  334. return this._true_last || this.last();
  335. };
  336. SigChain.prototype.is_track_fresh = function(id) {
  337. var l, _i, _ref5, _ref6;
  338. _ref5 = this._links;
  339. for (_i = _ref5.length - 1; _i >= 0; _i += -1) {
  340. l = _ref5[_i];
  341. if (l.id === id) {
  342. return true;
  343. } else if (!((_ref6 = l.sig_type()) === ST.TRACK || _ref6 === ST.UNTRACK)) {
  344. return false;
  345. }
  346. }
  347. return false;
  348. };
  349. SigChain.prototype._compress = function(_arg) {
  350. var index, link, opts, out, seq, verified_links, _i, _len;
  351. verified_links = _arg.verified_links, opts = _arg.opts;
  352. log.debug("+ compressing signature chain");
  353. out = new LinkTable();
  354. index = {};
  355. seq = {};
  356. for (_i = 0, _len = verified_links.length; _i < _len; _i++) {
  357. link = verified_links[_i];
  358. index[link.sig_id()] = link;
  359. seq[link.seqno()] = link;
  360. link.insert_into_table({
  361. table: out,
  362. index: index,
  363. opts: opts
  364. });
  365. }
  366. if (!opts.show_revoked) {
  367. out.prune(function(obj) {
  368. return obj.is_revoked();
  369. });
  370. }
  371. log.debug("- signature chain compressed");
  372. this.table = out;
  373. this.index = index;
  374. return this.seq = seq;
  375. };
  376. SigChain.prototype.flattened_remote_proofs = function() {
  377. var _ref5, _ref6;
  378. return ((_ref5 = this.table) != null ? (_ref6 = _ref5.get(ST.REMOTE_PROOF)) != null ? _ref6.flatten() : void 0 : void 0) || [];
  379. };
  380. SigChain.prototype.remote_proofs_to_track_obj = function() {
  381. var link, links, _i, _len, _results;
  382. links = this.flattened_remote_proofs();
  383. _results = [];
  384. for (_i = 0, _len = links.length; _i < _len; _i++) {
  385. link = links[_i];
  386. if (!link.is_revoked()) {
  387. _results.push(link.remote_proof_to_track_obj());
  388. }
  389. }
  390. return _results;
  391. };
  392. SigChain.prototype.merkle_root_to_track_obj = function() {
  393. var ret;
  394. if (this._merkle_root != null) {
  395. ret = {
  396. hash: this._merkle_root.hash,
  397. seqno: this._merkle_root.seqno,
  398. ctime: this._merkle_root.ctime
  399. };
  400. } else {
  401. ret = null;
  402. }
  403. return ret;
  404. };
  405. SigChain.prototype.get_track_obj = function(uid) {
  406. var _ref5, _ref6;
  407. return (_ref5 = this.table) != null ? (_ref6 = _ref5.get_path([ST.TRACK, uid])) != null ? _ref6.to_table_obj() : void 0 : void 0;
  408. };
  409. SigChain.prototype.verify_sig = function(_arg, cb) {
  410. var debug_file, eldest_kid, esc, key, last_lkb_link, link, lkb_chain_link, lkb_sig_chain, merkle_data, opts, parsed_keys, seqnos, sig_blobs, verified_links, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  411. __iced_k = __iced_k_noop;
  412. ___iced_passed_deferral = iced.findDeferral(arguments);
  413. opts = _arg.opts, key = _arg.key, parsed_keys = _arg.parsed_keys, merkle_data = _arg.merkle_data;
  414. esc = make_esc(cb, "SigChain::verify_sig");
  415. this.pubkey = key;
  416. log.debug("+ " + this.username + ": verifying sig");
  417. sig_blobs = (function() {
  418. var _i, _len, _ref5, _results;
  419. _ref5 = this._links;
  420. _results = [];
  421. for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
  422. link = _ref5[_i];
  423. _results.push(link.obj);
  424. }
  425. return _results;
  426. }).call(this);
  427. eldest_kid = merkle_data.eldest_kid;
  428. (function(_this) {
  429. return (function(__iced_k) {
  430. __iced_deferrals = new iced.Deferrals(__iced_k, {
  431. parent: ___iced_passed_deferral,
  432. filename: "/home/jacko/node-client/src/sigchain.iced",
  433. funcname: "SigChain.verify_sig"
  434. });
  435. libkeybase.SigChain.replay({
  436. sig_blobs: sig_blobs,
  437. parsed_keys: parsed_keys,
  438. uid: _this.uid,
  439. username: _this.username,
  440. eldest_kid: eldest_kid,
  441. sig_cache: SigCache,
  442. log: log.debug
  443. }, esc(__iced_deferrals.defer({
  444. assign_fn: (function() {
  445. return function() {
  446. return lkb_sig_chain = arguments[0];
  447. };
  448. })(),
  449. lineno: 208
  450. })));
  451. __iced_deferrals._fulfill();
  452. });
  453. })(this)((function(_this) {
  454. return function() {
  455. var _i, _len, _ref5;
  456. last_lkb_link = lkb_sig_chain.get_links().slice(-1)[0];
  457. if (last_lkb_link != null) {
  458. if (last_lkb_link.sig_id !== merkle_data.sig_id) {
  459. cb(new Error("Last sig id (" + last_lkb_link.sig_id + ") doesn't match the Merkle tree (" + merkle_data.sig_id + ")"));
  460. return;
  461. }
  462. if (last_lkb_link.seqno !== merkle_data.seqno) {
  463. cb(new Error("Last seqno (" + last_lkb_link.seqno + ") doesn't match the Merkle tree (" + merkle_data.seqno + ")"));
  464. return;
  465. }
  466. }
  467. seqnos = {};
  468. _ref5 = lkb_sig_chain.get_links();
  469. for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
  470. lkb_chain_link = _ref5[_i];
  471. seqnos[lkb_chain_link.seqno] = true;
  472. }
  473. verified_links = (function() {
  474. var _j, _len1, _ref6, _results;
  475. _ref6 = this._links;
  476. _results = [];
  477. for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
  478. link = _ref6[_j];
  479. if (seqnos[link.seqno()]) {
  480. _results.push(link);
  481. }
  482. }
  483. return _results;
  484. }).call(_this);
  485. opts = opts || {};
  486. _this._compress({
  487. opts: opts,
  488. verified_links: verified_links
  489. });
  490. debug_file = process.env.KEYBASE_DEBUG_UNBOX_COUNT_FILE;
  491. (function(__iced_k) {
  492. if (debug_file != null) {
  493. (function(__iced_k) {
  494. __iced_deferrals = new iced.Deferrals(__iced_k, {
  495. parent: ___iced_passed_deferral,
  496. filename: "/home/jacko/node-client/src/sigchain.iced",
  497. funcname: "SigChain.verify_sig"
  498. });
  499. fs.writeFile(debug_file, "" + libkeybase.debug.unbox_count, __iced_deferrals.defer({
  500. lineno: 236
  501. }));
  502. __iced_deferrals._fulfill();
  503. })(__iced_k);
  504. } else {
  505. return __iced_k();
  506. }
  507. })(function() {
  508. log.debug("- " + _this.username + ": verified sig");
  509. return cb(null, lkb_sig_chain.get_sibkeys({}));
  510. });
  511. };
  512. })(this));
  513. };
  514. SigChain.prototype.list_trackees = function() {
  515. var k, out, tab, v, _ref5, _ref6;
  516. out = [];
  517. if ((tab = (_ref5 = this.table) != null ? (_ref6 = _ref5.get(ST.TRACK)) != null ? _ref6.to_dict() : void 0 : void 0)) {
  518. for (k in tab) {
  519. v = tab[k];
  520. out.push(v.payload_json());
  521. }
  522. }
  523. return out;
  524. };
  525. SigChain.prototype.list_cryptocurrency_addresses = function(opts) {
  526. var k, obj, out, tab, v, _ref5, _ref6;
  527. if (opts == null) {
  528. opts = {};
  529. }
  530. out = null;
  531. if ((tab = (_ref5 = this.table) != null ? (_ref6 = _ref5.get(ST.CRYPTOCURRENCY)) != null ? _ref6.to_dict() : void 0 : void 0) != null) {
  532. for (k in tab) {
  533. v = tab[k];
  534. if (!((obj = v.to_cryptocurrency(opts)) != null)) {
  535. continue;
  536. }
  537. out || (out = {});
  538. out[obj.type] = obj.address;
  539. }
  540. }
  541. return out;
  542. };
  543. SigChain.prototype.list_remote_proofs = function(opts) {
  544. var k, obj, out, tab, type, v, _ref5, _ref6;
  545. if (opts == null) {
  546. opts = {};
  547. }
  548. out = null;
  549. if ((tab = (_ref5 = this.table) != null ? (_ref6 = _ref5.get(ST.REMOTE_PROOF)) != null ? _ref6.to_dict() : void 0 : void 0) != null) {
  550. for (type in tab) {
  551. obj = tab[type];
  552. type = proofs.proof_type_to_string[parseInt(type)];
  553. out || (out = {});
  554. out[type] = obj.is_leaf() ? obj.to_list_display(opts) : (function() {
  555. var _ref7, _results;
  556. _ref7 = obj.to_dict();
  557. _results = [];
  558. for (k in _ref7) {
  559. v = _ref7[k];
  560. _results.push(v.to_list_display(opts));
  561. }
  562. return _results;
  563. })();
  564. }
  565. }
  566. return out;
  567. };
  568. SigChain.prototype.display_cryptocurrency_addresses = function(opts, cb) {
  569. var esc, k, tab, v, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  570. __iced_k = __iced_k_noop;
  571. ___iced_passed_deferral = iced.findDeferral(arguments);
  572. esc = make_esc(cb, "SigChain::display_cryptocurrency_addresses");
  573. (function(_this) {
  574. return (function(__iced_k) {
  575. var _ref5, _ref6;
  576. if ((tab = (_ref5 = _this.table) != null ? (_ref6 = _ref5.get(ST.CRYPTOCURRENCY)) != null ? _ref6.to_dict() : void 0 : void 0) != null) {
  577. (function(__iced_k) {
  578. var _i, _k, _keys, _ref7, _results, _while;
  579. _ref7 = tab;
  580. _keys = (function() {
  581. var _results1;
  582. _results1 = [];
  583. for (_k in _ref7) {
  584. _results1.push(_k);
  585. }
  586. return _results1;
  587. })();
  588. _i = 0;
  589. _results = [];
  590. _while = function(__iced_k) {
  591. var _break, _continue, _next;
  592. _break = function() {
  593. return __iced_k(_results);
  594. };
  595. _continue = function() {
  596. return iced.trampoline(function() {
  597. ++_i;
  598. return _while(__iced_k);
  599. });
  600. };
  601. _next = function(__iced_next_arg) {
  602. _results.push(__iced_next_arg);
  603. return _continue();
  604. };
  605. if (!(_i < _keys.length)) {
  606. return _break();
  607. } else {
  608. k = _keys[_i];
  609. v = _ref7[k];
  610. (function(__iced_k) {
  611. __iced_deferrals = new iced.Deferrals(__iced_k, {
  612. parent: ___iced_passed_deferral,
  613. filename: "/home/jacko/node-client/src/sigchain.iced",
  614. funcname: "SigChain.display_cryptocurrency_addresses"
  615. });
  616. v.display_cryptocurrency(opts, esc(__iced_deferrals.defer({
  617. lineno: 282
  618. })));
  619. __iced_deferrals._fulfill();
  620. })(_next);
  621. }
  622. };
  623. _while(__iced_k);
  624. })(__iced_k);
  625. } else {
  626. return __iced_k();
  627. }
  628. });
  629. })(this)((function(_this) {
  630. return function() {
  631. return cb(null);
  632. };
  633. })(this));
  634. };
  635. SigChain.prototype.check_assertions = function(_arg, cb) {
  636. var assertions, err, gpg_keys, key, proof_set, proof_vec, username, _i, _len;
  637. gpg_keys = _arg.gpg_keys, username = _arg.username, assertions = _arg.assertions, proof_vec = _arg.proof_vec;
  638. err = null;
  639. for (_i = 0, _len = gpg_keys.length; _i < _len; _i++) {
  640. key = gpg_keys[_i];
  641. proof_vec.push(new Proof({
  642. key: "fingerprint",
  643. value: key.fingerprint().toString('hex')
  644. }));
  645. }
  646. proof_vec.push(new Proof({
  647. key: "keybase",
  648. value: username
  649. }));
  650. proof_set = new ProofSet(proof_vec);
  651. if (!assertions.match_set(proof_set)) {
  652. err = new E.FailedAssertionError("Assertion set failed");
  653. }
  654. return cb(err);
  655. };
  656. SigChain.prototype.check_remote_proofs = function(_arg, cb) {
  657. var assertions, esc, gpg_keys, key, link, links, msg, n, proof_vec, skip, tab, type, v, warnings, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len;
  658. __iced_k = __iced_k_noop;
  659. ___iced_passed_deferral = iced.findDeferral(arguments);
  660. skip = _arg.skip, gpg_keys = _arg.gpg_keys, assertions = _arg.assertions;
  661. esc = make_esc(cb, "SigChain::check_remote_proofs");
  662. log.debug("+ " + this.username + ": checking remote proofs (skip=" + skip + ")");
  663. warnings = new Warnings();
  664. for (_i = 0, _len = gpg_keys.length; _i < _len; _i++) {
  665. key = gpg_keys[_i];
  666. msg = CHECK + " " + colors.green("public key fingerprint: " + (format_fingerprint(key.fingerprint().toString('hex'))));
  667. log.lconsole("error", log["package"]().INFO, msg);
  668. }
  669. n = 0;
  670. proof_vec = [];
  671. (function(_this) {
  672. return (function(__iced_k) {
  673. var _ref5;
  674. if ((tab = (_ref5 = _this.table) != null ? _ref5.get(ST.REMOTE_PROOF) : void 0) != null) {
  675. log.debug("| Loaded table with " + (tab.keys().length) + " keys");
  676. (function(__iced_k) {
  677. var _j, _k, _keys, _ref6, _results, _while;
  678. _ref6 = tab.to_dict();
  679. _keys = (function() {
  680. var _results1;
  681. _results1 = [];
  682. for (_k in _ref6) {
  683. _results1.push(_k);
  684. }
  685. return _results1;
  686. })();
  687. _j = 0;
  688. _results = [];
  689. _while = function(__iced_k) {
  690. var _break, _continue, _next;
  691. _break = function() {
  692. return __iced_k(_results);
  693. };
  694. _continue = function() {
  695. return iced.trampoline(function() {
  696. ++_j;
  697. return _while(__iced_k);
  698. });
  699. };
  700. _next = function(__iced_next_arg) {
  701. _results.push(__iced_next_arg);
  702. return _continue();
  703. };
  704. if (!(_j < _keys.length)) {
  705. return _break();
  706. } else {
  707. type = _keys[_j];
  708. v = _ref6[type];
  709. type = parseInt(type);
  710. links = v.flatten();
  711. (function(__iced_k) {
  712. var _l, _len1, _ref7, _results1, _while;
  713. _ref7 = links;
  714. _len1 = _ref7.length;
  715. _l = 0;
  716. _results1 = [];
  717. _while = function(__iced_k) {
  718. var _break, _continue, _next;
  719. _break = function() {
  720. return __iced_k(_results1);
  721. };
  722. _continue = function() {
  723. return iced.trampoline(function() {
  724. ++_l;
  725. return _while(__iced_k);
  726. });
  727. };
  728. _next = function(__iced_next_arg) {
  729. _results1.push(__iced_next_arg);
  730. return _continue();
  731. };
  732. if (!(_l < _len1)) {
  733. return _break();
  734. } else {
  735. link = _ref7[_l];
  736. (function(__iced_k) {
  737. __iced_deferrals = new iced.Deferrals(__iced_k, {
  738. parent: ___iced_passed_deferral,
  739. filename: "/home/jacko/node-client/src/sigchain.iced",
  740. funcname: "SigChain.check_remote_proofs"
  741. });
  742. link.check_remote_proof({
  743. skip: skip,
  744. type: type,
  745. warnings: warnings,
  746. proof_vec: proof_vec
  747. }, esc(__iced_deferrals.defer({
  748. lineno: 323
  749. })));
  750. __iced_deferrals._fulfill();
  751. })(function() {
  752. return _next(n++);
  753. });
  754. }
  755. };
  756. _while(__iced_k);
  757. })(_next);
  758. }
  759. };
  760. _while(__iced_k);
  761. })(__iced_k);
  762. } else {
  763. return __iced_k(log.debug("| No remote proofs found"));
  764. }
  765. });
  766. })(this)((function(_this) {
  767. return function() {
  768. (function(__iced_k) {
  769. if (assertions != null) {
  770. (function(__iced_k) {
  771. __iced_deferrals = new iced.Deferrals(__iced_k, {
  772. parent: ___iced_passed_deferral,
  773. filename: "/home/jacko/node-client/src/sigchain.iced",
  774. funcname: "SigChain.check_remote_proofs"
  775. });
  776. _this.check_assertions({
  777. gpg_keys: gpg_keys,
  778. proof_vec: proof_vec,
  779. username: _this.username,
  780. assertions: assertions
  781. }, esc(__iced_deferrals.defer({
  782. lineno: 329
  783. })));
  784. __iced_deferrals._fulfill();
  785. })(__iced_k);
  786. } else {
  787. return __iced_k();
  788. }
  789. })(function() {
  790. log.debug("- " + _this.username + ": checked remote proofs");
  791. return cb(null, warnings, n);
  792. });
  793. };
  794. })(this));
  795. };
  796. return SigChain;
  797. })();
  798. SigCache = (function() {
  799. function SigCache() {}
  800. SigCache.get = function(_arg, cb) {
  801. var esc, payload_buffer, sig_id, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  802. __iced_k = __iced_k_noop;
  803. ___iced_passed_deferral = iced.findDeferral(arguments);
  804. sig_id = _arg.sig_id;
  805. esc = make_esc(cb, "SigCache::get");
  806. (function(_this) {
  807. return (function(__iced_k) {
  808. __iced_deferrals = new iced.Deferrals(__iced_k, {
  809. parent: ___iced_passed_deferral,
  810. filename: "/home/jacko/node-client/src/sigchain.iced",
  811. funcname: "SigCache.get"
  812. });
  813. db.get({
  814. type: "sig_cache",
  815. key: sig_id,
  816. json: false
  817. }, esc(__iced_deferrals.defer({
  818. assign_fn: (function() {
  819. return function() {
  820. return payload_buffer = arguments[0];
  821. };
  822. })(),
  823. lineno: 341
  824. })));
  825. __iced_deferrals._fulfill();
  826. });
  827. })(this)((function(_this) {
  828. return function() {
  829. return cb(null, payload_buffer);
  830. };
  831. })(this));
  832. };
  833. SigCache.put = function(_arg, cb) {
  834. var esc, payload_buffer, sig_id, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  835. __iced_k = __iced_k_noop;
  836. ___iced_passed_deferral = iced.findDeferral(arguments);
  837. sig_id = _arg.sig_id, payload_buffer = _arg.payload_buffer;
  838. esc = make_esc(cb, "SigCache::put");
  839. (function(_this) {
  840. return (function(__iced_k) {
  841. __iced_deferrals = new iced.Deferrals(__iced_k, {
  842. parent: ___iced_passed_deferral,
  843. filename: "/home/jacko/node-client/src/sigchain.iced",
  844. funcname: "SigCache.put"
  845. });
  846. db.put({
  847. type: "sig_cache",
  848. key: sig_id,
  849. value: payload_buffer,
  850. json: false
  851. }, esc(__iced_deferrals.defer({
  852. lineno: 346
  853. })));
  854. __iced_deferrals._fulfill();
  855. });
  856. })(this)((function(_this) {
  857. return function() {
  858. return cb(null);
  859. };
  860. })(this));
  861. };
  862. return SigCache;
  863. })();
  864. }).call(this);