chainlink.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ACCTYPES, BTC, CHECK, Cryptocurrency, E, Link, LinkTable, RemoteProof, Revoke, SHA256, ST, SelfSig, Track, Untrack, Warnings, asyncify, athrow, bitcoyne, cheerio, colors, constants, date_to_unix, db, deq, dict_union, env, format_fingerprint, iced, log, make_email, make_esc, proofs, req, request, scrapemod, util, __iced_k, __iced_k_noop, _ref, _ref1, _ref2,
  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. __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  7. iced = require('iced-runtime').iced;
  8. __iced_k = __iced_k_noop = function() {};
  9. db = require('./db');
  10. req = require('./req');
  11. log = require('./log');
  12. constants = require('./constants').constants;
  13. SHA256 = require('./keyutils').SHA256;
  14. E = require('./err').E;
  15. _ref = require('pgp-utils').util, format_fingerprint = _ref.format_fingerprint, Warnings = _ref.Warnings, asyncify = _ref.asyncify;
  16. make_esc = require('iced-error').make_esc;
  17. ST = constants.signature_types;
  18. ACCTYPES = constants.allowed_cryptocurrency_types;
  19. _ref1 = require('./util'), dict_union = _ref1.dict_union, date_to_unix = _ref1.date_to_unix, make_email = _ref1.make_email;
  20. proofs = require('keybase-proofs');
  21. cheerio = require('cheerio');
  22. request = require('request');
  23. colors = require('./colors');
  24. deq = require('deep-equal');
  25. util = require('util');
  26. env = require('./env').env;
  27. scrapemod = require('./scrapers');
  28. _ref2 = require('./display'), CHECK = _ref2.CHECK, BTC = _ref2.BTC;
  29. athrow = require('iced-utils').util.athrow;
  30. bitcoyne = require('bitcoyne');
  31. exports.Link = Link = (function() {
  32. Link.ID_TYPE = constants.ids.sig_chain_link;
  33. function Link(_arg) {
  34. this.id = _arg.id, this.obj = _arg.obj;
  35. this.id || (this.id = this.obj.payload_hash);
  36. this._revoked = false;
  37. }
  38. Link.prototype.export_to_user = function() {
  39. return {
  40. seqno: this.seqno(),
  41. payload_hash: this.id,
  42. sig_id: this.sig_id()
  43. };
  44. };
  45. Link.prototype.prev = function() {
  46. return this.obj.prev;
  47. };
  48. Link.prototype.seqno = function() {
  49. return this.obj.seqno;
  50. };
  51. Link.prototype.sig = function() {
  52. return this.obj.sig;
  53. };
  54. Link.prototype.payload_json_str = function() {
  55. return this.obj.payload_json;
  56. };
  57. Link.prototype.fingerprint = function() {
  58. return this.obj.fingerprint.toLowerCase();
  59. };
  60. Link.prototype.short_key_id = function() {
  61. return this.fingerprint().slice(-8).toUpperCase();
  62. };
  63. Link.prototype.is_self_sig = function() {
  64. return false;
  65. };
  66. Link.prototype.self_signer = function() {
  67. var _ref3, _ref4, _ref5;
  68. return (_ref3 = this.payload_json()) != null ? (_ref4 = _ref3.body) != null ? (_ref5 = _ref4.key) != null ? _ref5.username : void 0 : void 0 : void 0;
  69. };
  70. Link.prototype.sig_type = function() {
  71. return this.obj.sig_type;
  72. };
  73. Link.prototype.sig_id = function() {
  74. return this.obj.sig_id;
  75. };
  76. Link.prototype.remote_id = function() {
  77. return this.obj.remote_id;
  78. };
  79. Link.prototype.body = function() {
  80. var _ref3;
  81. return (_ref3 = this.payload_json()) != null ? _ref3.body : void 0;
  82. };
  83. Link.prototype.ctime = function() {
  84. return date_to_unix(this.obj.ctime);
  85. };
  86. Link.prototype.revoke = function() {
  87. return this._revoked = true;
  88. };
  89. Link.prototype.is_revoked = function() {
  90. return this._revoked;
  91. };
  92. Link.prototype.to_track_obj = function() {
  93. return {
  94. seqno: this.seqno(),
  95. sig_id: this.sig_id(),
  96. payload_hash: this.id
  97. };
  98. };
  99. Link.prototype.payload_json = function() {
  100. var e, ret, s;
  101. if (this._payload_obj == null) {
  102. s = this.payload_json_str();
  103. ret = {};
  104. try {
  105. ret = JSON.parse(s);
  106. } catch (_error) {
  107. e = _error;
  108. log.error("Error parsing JSON " + s + ": " + e.message);
  109. }
  110. this._payload_obj = ret;
  111. }
  112. return this._payload_obj;
  113. };
  114. Link.prototype.walk = function(_arg) {
  115. var fn, key, parent;
  116. fn = _arg.fn, parent = _arg.parent, key = _arg.key;
  117. return fn({
  118. value: this,
  119. key: key,
  120. parent: parent
  121. });
  122. };
  123. Link.prototype.flatten = function() {
  124. return [this];
  125. };
  126. Link.prototype.is_leaf = function() {
  127. return true;
  128. };
  129. Link.prototype.is_revocable = function() {
  130. return false;
  131. };
  132. Link.prototype.matches = function(rxx) {
  133. return !!(JSON.stringify(this.condense()).match(rxx));
  134. };
  135. Link.prototype.condense = function() {
  136. return this.payload_json();
  137. };
  138. Link.prototype.summary = function() {
  139. return {
  140. seqno: this.seqno(),
  141. id: this.sig_id(),
  142. type: this.type_str(),
  143. ctime: this.ctime(),
  144. live: !(this.is_revoked()),
  145. payload: this.condense()
  146. };
  147. };
  148. Link.prototype.verify = function() {
  149. var a, b, err, j;
  150. err = null;
  151. if ((a = this.obj.payload_hash) !== (b = this.id)) {
  152. err = new E.CorruptionError("Link ID mismatch: " + a + " != " + b);
  153. } else if ((j = SHA256(this.payload_json_str()).toString('hex')) !== this.id) {
  154. err = new E.CorruptionError("Link has wrong id: " + this.id + " != " + this.j);
  155. }
  156. return err;
  157. };
  158. Link.prototype.store = function(cb) {
  159. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k, _ref3;
  160. __iced_k = __iced_k_noop;
  161. ___iced_passed_deferral = iced.findDeferral(arguments);
  162. if (((_ref3 = this.obj.prev) != null ? _ref3.length : void 0) === 0) {
  163. this.obj.prev = null;
  164. }
  165. log.debug("| putting link: " + this.id);
  166. (function(_this) {
  167. return (function(__iced_k) {
  168. __iced_deferrals = new iced.Deferrals(__iced_k, {
  169. parent: ___iced_passed_deferral,
  170. filename: "/home/jacko/node-client/src/chainlink.iced",
  171. funcname: "Link.store"
  172. });
  173. db.put({
  174. type: Link.ID_TYPE,
  175. key: _this.id,
  176. value: _this.obj
  177. }, __iced_deferrals.defer({
  178. assign_fn: (function() {
  179. return function() {
  180. return err = arguments[0];
  181. };
  182. })(),
  183. lineno: 118
  184. }));
  185. __iced_deferrals._fulfill();
  186. });
  187. })(this)((function(_this) {
  188. return function() {
  189. return cb(err);
  190. };
  191. })(this));
  192. };
  193. Link.prototype.refresh = function(cb) {
  194. return cb(null);
  195. };
  196. Link.alloc = function(_arg) {
  197. var id, klass, obj;
  198. obj = _arg.obj, id = _arg.id;
  199. klass = (function() {
  200. switch (obj.sig_type) {
  201. case ST.SELF_SIG:
  202. return SelfSig;
  203. case ST.REMOTE_PROOF:
  204. return RemoteProof;
  205. case ST.TRACK:
  206. return Track;
  207. case ST.CRYPTOCURRENCY:
  208. return Cryptocurrency;
  209. case ST.REVOKE:
  210. return Revoke;
  211. case ST.UNTRACK:
  212. return Untrack;
  213. default:
  214. return Link;
  215. }
  216. })();
  217. return new klass({
  218. obj: obj,
  219. id: id
  220. });
  221. };
  222. Link.load = function(id, cb) {
  223. var err, obj, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  224. __iced_k = __iced_k_noop;
  225. ___iced_passed_deferral = iced.findDeferral(arguments);
  226. ret = null;
  227. (function(_this) {
  228. return (function(__iced_k) {
  229. __iced_deferrals = new iced.Deferrals(__iced_k, {
  230. parent: ___iced_passed_deferral,
  231. filename: "/home/jacko/node-client/src/chainlink.iced",
  232. funcname: "Link.load"
  233. });
  234. db.get({
  235. type: Link.ID_TYPE,
  236. key: id
  237. }, __iced_deferrals.defer({
  238. assign_fn: (function() {
  239. return function() {
  240. err = arguments[0];
  241. return obj = arguments[1];
  242. };
  243. })(),
  244. lineno: 144
  245. }));
  246. __iced_deferrals._fulfill();
  247. });
  248. })(this)((function(_this) {
  249. return function() {
  250. if (typeof err !== "undefined" && err !== null) {
  251. } else if (typeof obj !== "undefined" && obj !== null) {
  252. ret = Link.alloc({
  253. id: id,
  254. obj: obj
  255. });
  256. if ((err = ret.verify()) != null) {
  257. ret = null;
  258. }
  259. }
  260. return cb(err, ret);
  261. };
  262. })(this));
  263. };
  264. Link.prototype.insert_into_table = function() {
  265. return log.warn("unhandled public sig type: " + (this.sig_type()));
  266. };
  267. return Link;
  268. })();
  269. SelfSig = (function(_super) {
  270. __extends(SelfSig, _super);
  271. function SelfSig() {
  272. return SelfSig.__super__.constructor.apply(this, arguments);
  273. }
  274. SelfSig.prototype.is_self_sig = function() {
  275. return true;
  276. };
  277. SelfSig.prototype.condense = function() {
  278. return "self";
  279. };
  280. SelfSig.prototype.type_str = function() {
  281. return "self";
  282. };
  283. SelfSig.prototype.is_revocable = function() {
  284. return true;
  285. };
  286. SelfSig.prototype.insert_into_table = function(_arg) {
  287. var table;
  288. table = _arg.table;
  289. return table.insert(this.sig_type(), this);
  290. };
  291. return SelfSig;
  292. })(Link);
  293. RemoteProof = (function(_super) {
  294. __extends(RemoteProof, _super);
  295. function RemoteProof() {
  296. return RemoteProof.__super__.constructor.apply(this, arguments);
  297. }
  298. RemoteProof.prototype.proof_service_object = function() {
  299. var _ref3, _ref4;
  300. return (_ref3 = this.payload_json()) != null ? (_ref4 = _ref3.body) != null ? _ref4.service : void 0 : void 0;
  301. };
  302. RemoteProof.prototype.proof_type = function() {
  303. return this.obj.proof_type;
  304. };
  305. RemoteProof.prototype.proof_state = function() {
  306. return this.obj.proof_state;
  307. };
  308. RemoteProof.prototype.remote_username = function() {
  309. var _ref3;
  310. return (_ref3 = this.proof_service_object()) != null ? _ref3.username : void 0;
  311. };
  312. RemoteProof.prototype.api_url = function() {
  313. return this.obj.api_url;
  314. };
  315. RemoteProof.prototype.human_url = function() {
  316. return this.obj.human_url;
  317. };
  318. RemoteProof.prototype.proof_text_check = function() {
  319. return this.obj.proof_text_check;
  320. };
  321. RemoteProof.prototype.type_str = function() {
  322. return "proof";
  323. };
  324. RemoteProof.prototype.is_revocable = function() {
  325. return true;
  326. };
  327. RemoteProof.prototype.condense = function() {
  328. var key, pso, val;
  329. pso = this.proof_service_object();
  330. key = pso.name || pso.protocol;
  331. if (key.slice(-1)[0] !== ':') {
  332. key += ":";
  333. }
  334. val = pso.username || pso.domain || pso.hostname;
  335. return [key, val].join('//');
  336. };
  337. RemoteProof.prototype.insert_into_table = function(_arg) {
  338. var S, index, keys, opts, states, sub_id, table, _ref3;
  339. table = _arg.table, index = _arg.index, opts = _arg.opts;
  340. log.debug("+ RemoteProof::insert_into_table");
  341. S = constants.proof_state;
  342. states = [S.OK, S.TEMP_FAILURE, S.LOOKING];
  343. if (opts != null ? opts.show_perm_failures : void 0) {
  344. states.push(S.PERM_FAILURE);
  345. }
  346. if (_ref3 = this.proof_state(), __indexOf.call(states, _ref3) >= 0) {
  347. keys = [this.sig_type(), this.proof_type()];
  348. if ((sub_id = this.get_sub_id()) != null) {
  349. keys.push(sub_id);
  350. }
  351. table.insert_path(keys, this);
  352. } else {
  353. log.debug("Skipping remote proof in state " + (this.proof_state()) + ": " + (this.payload_json_str()));
  354. }
  355. return log.debug("- RemoteProof::insert_into_table");
  356. };
  357. RemoteProof.prototype.get_sub_id = function() {
  358. var _ref3;
  359. return (_ref3 = scrapemod.alloc_stub(this.proof_type())) != null ? _ref3.get_sub_id(this.proof_service_object()) : void 0;
  360. };
  361. RemoteProof.prototype.check_remote_proof = function(_arg, cb) {
  362. var arg, e2, err, errmsg, esc, msg, ok, proof_vec, rc, rsc, scraper, skip, type, type_s, username, warnings, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  363. __iced_k = __iced_k_noop;
  364. ___iced_passed_deferral = iced.findDeferral(arguments);
  365. skip = _arg.skip, type = _arg.type, warnings = _arg.warnings, proof_vec = _arg.proof_vec;
  366. username = this.self_signer();
  367. esc = make_esc(cb, "SigChain::Link::check_remote_proof'");
  368. (function(_this) {
  369. return (function(__iced_k) {
  370. if ((type_s = proofs.proof_type_to_string[type]) == null) {
  371. err = new E.VerifyError("Unknown proof type (" + type + ") found; consider a `keybase update`");
  372. (function(__iced_k) {
  373. __iced_deferrals = new iced.Deferrals(__iced_k, {
  374. parent: ___iced_passed_deferral,
  375. filename: "/home/jacko/node-client/src/chainlink.iced",
  376. funcname: "RemoteProof.check_remote_proof"
  377. });
  378. athrow(err, esc(__iced_deferrals.defer({
  379. lineno: 228
  380. })));
  381. __iced_deferrals._fulfill();
  382. })(__iced_k);
  383. } else {
  384. return __iced_k();
  385. }
  386. });
  387. })(this)((function(_this) {
  388. return function() {
  389. log.debug("+ " + username + ": checking remote " + type_s + " proof");
  390. (function(__iced_k) {
  391. if (!skip && !_this.api_url()) {
  392. (function(__iced_k) {
  393. __iced_deferrals = new iced.Deferrals(__iced_k, {
  394. parent: ___iced_passed_deferral,
  395. filename: "/home/jacko/node-client/src/chainlink.iced",
  396. funcname: "RemoteProof.check_remote_proof"
  397. });
  398. _this.refresh(__iced_deferrals.defer({
  399. assign_fn: (function() {
  400. return function() {
  401. return e2 = arguments[0];
  402. };
  403. })(),
  404. lineno: 233
  405. }));
  406. __iced_deferrals._fulfill();
  407. })(function() {
  408. return __iced_k(typeof e2 !== "undefined" && e2 !== null ? log.warn("Error fetching URL for proof: " + e2.message) : void 0);
  409. });
  410. } else {
  411. return __iced_k();
  412. }
  413. })(function() {
  414. rsc = JSON.stringify(_this.proof_service_object());
  415. log.debug("| remote service desc is " + rsc);
  416. (function(__iced_k) {
  417. __iced_deferrals = new iced.Deferrals(__iced_k, {
  418. parent: ___iced_passed_deferral,
  419. filename: "/home/jacko/node-client/src/chainlink.iced",
  420. funcname: "RemoteProof.check_remote_proof"
  421. });
  422. scrapemod.alloc(type, esc(__iced_deferrals.defer({
  423. assign_fn: (function() {
  424. return function() {
  425. return scraper = arguments[0];
  426. };
  427. })(),
  428. lineno: 240
  429. })));
  430. __iced_deferrals._fulfill();
  431. })(function() {
  432. arg = {
  433. api_url: _this.api_url(),
  434. signature: _this.sig(),
  435. proof_text_check: _this.proof_text_check(),
  436. remote_id: "" + _this.remote_id(),
  437. human_url: _this.human_url()
  438. };
  439. arg = dict_union(arg, _this.proof_service_object());
  440. proof_vec.push(scraper.to_proof(arg));
  441. errmsg = "";
  442. (function(__iced_k) {
  443. if (skip) {
  444. return __iced_k(rc = proofs.constants.v_codes.OK);
  445. } else {
  446. (function(__iced_k) {
  447. if (!_this.api_url()) {
  448. return __iced_k(rc = proofs.constants.v_codes.NOT_FOUND);
  449. } else {
  450. log.debug("+ Calling into scraper -> " + rsc + "@" + type_s + " -> " + (_this.api_url()));
  451. (function(__iced_k) {
  452. __iced_deferrals = new iced.Deferrals(__iced_k, {
  453. parent: ___iced_passed_deferral,
  454. filename: "/home/jacko/node-client/src/chainlink.iced",
  455. funcname: "RemoteProof.check_remote_proof"
  456. });
  457. scraper.validate(arg, __iced_deferrals.defer({
  458. assign_fn: (function() {
  459. return function() {
  460. err = arguments[0];
  461. return rc = arguments[1];
  462. };
  463. })(),
  464. lineno: 259
  465. }));
  466. __iced_deferrals._fulfill();
  467. })(function() {
  468. log.debug("- Called scraper -> " + rc);
  469. return __iced_k(typeof err !== "undefined" && err !== null ? errmsg = ": " + err.message : void 0);
  470. });
  471. }
  472. })(__iced_k);
  473. }
  474. })(function() {
  475. ok = false;
  476. if (rc !== proofs.constants.v_codes.OK) {
  477. warnings.push(new E.RemoteCheckError("Remote check failed (code: " + rc + ")"));
  478. _this.obj.proof_state = rc;
  479. } else {
  480. ok = true;
  481. log.debug("| proof checked out");
  482. }
  483. msg = scraper.format_msg({
  484. arg: arg,
  485. ok: ok
  486. });
  487. if (skip) {
  488. msg.push("(you've recently OK'ed this proof)");
  489. }
  490. if (!ok) {
  491. msg.push("(failed with code " + rc + errmsg + ")");
  492. }
  493. log.lconsole("error", log["package"]().INFO, msg.join(' '));
  494. log.debug("- " + username + ": checked remote " + type_s + " proof");
  495. return cb(null);
  496. });
  497. });
  498. });
  499. };
  500. })(this));
  501. };
  502. RemoteProof.prototype.remote_proof_to_track_obj = function() {
  503. var _ref3, _ref4;
  504. return {
  505. ctime: this.obj.ctime,
  506. etime: this.obj.etime,
  507. seqno: this.obj.seqno,
  508. curr: this.id,
  509. sig_type: this.obj.sig_type,
  510. sig_id: this.obj.sig_id,
  511. remote_key_proof: {
  512. check_data_json: (_ref3 = this.payload_json()) != null ? (_ref4 = _ref3.body) != null ? _ref4.service : void 0 : void 0,
  513. state: this.obj.proof_state,
  514. proof_type: this.obj.proof_type
  515. }
  516. };
  517. };
  518. RemoteProof.prototype.to_list_display = function(opts) {
  519. var name, _ref3;
  520. name = (_ref3 = scrapemod.alloc_stub(this.proof_type())) != null ? _ref3.to_list_display(this.proof_service_object()) : void 0;
  521. if ((opts != null ? opts.with_sig_ids : void 0) || ((opts != null ? opts.with_proof_states : void 0) != null)) {
  522. return {
  523. name: name,
  524. sig_id: this.sig_id(),
  525. proof_state: this.proof_state()
  526. };
  527. } else {
  528. return name;
  529. }
  530. };
  531. RemoteProof.prototype.refresh = function(cb) {
  532. var arg, body, err, row, u, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  533. __iced_k = __iced_k_noop;
  534. ___iced_passed_deferral = iced.findDeferral(arguments);
  535. err = null;
  536. log.debug("+ refresh RemoteProof link");
  537. (function(_this) {
  538. return (function(__iced_k) {
  539. if (_this.api_url() == null) {
  540. log.debug("| Proof_id = " + _this.obj.proof_id);
  541. arg = {
  542. endpoint: "sig/remote_proof",
  543. args: {
  544. proof_id: _this.obj.proof_id
  545. }
  546. };
  547. log.debug("| request proof refresh for id=" + _this.obj.proof_id);
  548. (function(__iced_k) {
  549. __iced_deferrals = new iced.Deferrals(__iced_k, {
  550. parent: ___iced_passed_deferral,
  551. filename: "/home/jacko/node-client/src/chainlink.iced",
  552. funcname: "RemoteProof.refresh"
  553. });
  554. req.get(arg, __iced_deferrals.defer({
  555. assign_fn: (function() {
  556. return function() {
  557. err = arguments[0];
  558. return body = arguments[1];
  559. };
  560. })(),
  561. lineno: 315
  562. }));
  563. __iced_deferrals._fulfill();
  564. })(function() {
  565. (function(__iced_k) {
  566. if ((err == null) && ((row = typeof body !== "undefined" && body !== null ? body.row : void 0) != null) && ((u = row.api_url) != null)) {
  567. log.debug("| Refreshed with api_url -> " + u);
  568. _this.obj.api_url = u;
  569. _this.obj.human_url = row.human_url;
  570. (function(__iced_k) {
  571. __iced_deferrals = new iced.Deferrals(__iced_k, {
  572. parent: ___iced_passed_deferral,
  573. filename: "/home/jacko/node-client/src/chainlink.iced",
  574. funcname: "RemoteProof.refresh"
  575. });
  576. _this.store(__iced_deferrals.defer({
  577. assign_fn: (function() {
  578. return function() {
  579. return err = arguments[0];
  580. };
  581. })(),
  582. lineno: 320
  583. }));
  584. __iced_deferrals._fulfill();
  585. })(__iced_k);
  586. } else {
  587. return __iced_k();
  588. }
  589. })(__iced_k);
  590. });
  591. } else {
  592. return __iced_k();
  593. }
  594. });
  595. })(this)((function(_this) {
  596. return function() {
  597. log.debug("- refresh RemoteProof link");
  598. return cb(err);
  599. };
  600. })(this));
  601. };
  602. RemoteProof.prototype.is_self_sig = function() {
  603. return true;
  604. };
  605. return RemoteProof;
  606. })(Link);
  607. Track = (function(_super) {
  608. __extends(Track, _super);
  609. function Track() {
  610. return Track.__super__.constructor.apply(this, arguments);
  611. }
  612. Track.prototype.to_table_obj = function() {
  613. var ret;
  614. ret = this.body().track;
  615. ret.ctime = this.ctime();
  616. return ret;
  617. };
  618. Track.prototype.is_self_sig = function() {
  619. return true;
  620. };
  621. Track.prototype.condense = function() {
  622. return this.body().track.basics.username;
  623. };
  624. Track.prototype.type_str = function() {
  625. return "track";
  626. };
  627. Track.prototype.insert_into_table = function(_arg) {
  628. var id, opts, path, table, _ref3, _ref4;
  629. table = _arg.table, opts = _arg.opts;
  630. log.debug("+ Track::insert_into_table " + (this.sig_id()));
  631. if ((id = (_ref3 = this.body()) != null ? (_ref4 = _ref3.track) != null ? _ref4.id : void 0 : void 0) == null) {
  632. log.warn("Missing track in signature");
  633. log.debug("Full JSON in signature:");
  634. log.debug(this.payload_json_str());
  635. } else {
  636. path = [this.sig_type(), id];
  637. if (opts.show_revoked) {
  638. path.push(this.seqno());
  639. }
  640. table.insert_path(path, this);
  641. }
  642. return log.debug("- Track::insert_into_table " + (this.sig_id()) + " (uid=" + id + ")");
  643. };
  644. return Track;
  645. })(Link);
  646. Cryptocurrency = (function(_super) {
  647. __extends(Cryptocurrency, _super);
  648. function Cryptocurrency() {
  649. return Cryptocurrency.__super__.constructor.apply(this, arguments);
  650. }
  651. Cryptocurrency.prototype.to_cryptocurrency = function(opts) {
  652. var _ref3;
  653. return (_ref3 = this.body()) != null ? _ref3.cryptocurrency : void 0;
  654. };
  655. Cryptocurrency.prototype.condense = function() {
  656. var d, ret;
  657. d = this.body().cryptocurrency;
  658. ret = {};
  659. ret[d.type] = d.address;
  660. return ret;
  661. };
  662. Cryptocurrency.prototype.type_str = function() {
  663. return "currency";
  664. };
  665. Cryptocurrency.prototype.is_revocable = function() {
  666. return true;
  667. };
  668. Cryptocurrency.prototype.display_cryptocurrency = function(opts, cb) {
  669. var cc, msg;
  670. cc = this.to_cryptocurrency(opts);
  671. msg = [BTC, cc.type, colors.green(cc.address)];
  672. log.lconsole("error", log["package"]().INFO, msg.join(' '));
  673. return cb(null);
  674. };
  675. Cryptocurrency.prototype.insert_into_table = function(_arg) {
  676. var err, id, index, opts, path, ret, table, _ref3, _ref4, _ref5;
  677. table = _arg.table, index = _arg.index, opts = _arg.opts;
  678. log.debug("+ Cryptocurrency::insert_into_table " + (this.sig_id()));
  679. if ((id = (_ref3 = this.body()) != null ? (_ref4 = _ref3.cryptocurrency) != null ? _ref4.address : void 0 : void 0) == null) {
  680. log.warn("Missing Cryptocurrency address");
  681. log.debug("Full JSON in signature:");
  682. log.debug(this.payload_json_str());
  683. } else if ((_ref5 = bitcoyne.address.check(id, {
  684. version: ACCTYPES
  685. }), err = _ref5[0], ret = _ref5[1], _ref5) == null) {
  686. log.error("Error in checking cryptocurrency address: " + id);
  687. } else if (err != null) {
  688. log.warn("Error in cryptocurrency address: " + err.message);
  689. } else {
  690. path = [this.sig_type(), ret.version];
  691. if (opts != null ? opts.show_revoked : void 0) {
  692. path.push(this.seqno());
  693. }
  694. table.insert_path(path, this);
  695. }
  696. return log.debug("- Cryptocurrency::insert_into_table " + (this.sig_id()));
  697. };
  698. return Cryptocurrency;
  699. })(Link);
  700. Revoke = (function(_super) {
  701. __extends(Revoke, _super);
  702. function Revoke() {
  703. return Revoke.__super__.constructor.apply(this, arguments);
  704. }
  705. Revoke.prototype.insert_into_table = function(_arg) {
  706. var index;
  707. index = _arg.index;
  708. log.debug("+ Revoke::insert_into_table");
  709. return log.debug("- Revoke::insert_into_table");
  710. };
  711. return Revoke;
  712. })(Link);
  713. Untrack = (function(_super) {
  714. __extends(Untrack, _super);
  715. function Untrack() {
  716. return Untrack.__super__.constructor.apply(this, arguments);
  717. }
  718. Untrack.prototype.insert_into_table = function(_arg) {
  719. var id, index, link, links, opts, table, _i, _len, _ref3, _ref4, _ref5;
  720. table = _arg.table, index = _arg.index, opts = _arg.opts;
  721. log.debug("+ Untrack::insert_into_table");
  722. if ((id = (_ref3 = this.body()) != null ? (_ref4 = _ref3.untrack) != null ? _ref4.id : void 0 : void 0) == null) {
  723. log.warn("Mssing untrack in signature: " + (this.payload_json_str()));
  724. } else if ((link = (_ref5 = table.get(ST.TRACK)) != null ? _ref5.get(id) : void 0) == null) {
  725. log.debug("Unexpected untrack of " + id + " in signature chain");
  726. } else if (!(link.is_leaf()) && !(opts != null ? opts.show_revoked : void 0)) {
  727. log.warn("Unexpected multi-follow");
  728. } else {
  729. links = link.is_leaf() ? [link] : link.flatten();
  730. for (_i = 0, _len = links.length; _i < _len; _i++) {
  731. link = links[_i];
  732. if (link.is_revoked()) {
  733. log.debug("| Tracking was already revoked for " + id + " (ignoring untrack)");
  734. } else {
  735. link.revoke();
  736. }
  737. }
  738. }
  739. return log.debug("- Untrack::insert_into_table");
  740. };
  741. return Untrack;
  742. })(Link);
  743. exports.LinkTable = LinkTable = (function() {
  744. function LinkTable(table) {
  745. this.table = table != null ? table : {};
  746. }
  747. LinkTable.prototype.insert = function(key, value) {
  748. return this.table[key] = value;
  749. };
  750. LinkTable.prototype.insert_path = function(path, value) {
  751. var d, k, v, _i, _len, _ref3;
  752. d = this;
  753. _ref3 = path.slice(0, -1);
  754. for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
  755. k = _ref3[_i];
  756. if ((v = d.get(k)) == null) {
  757. v = new LinkTable();
  758. d.insert(k, v);
  759. }
  760. d = v;
  761. }
  762. return d.insert(path.slice(-1)[0], value);
  763. };
  764. LinkTable.prototype.get = function(key) {
  765. return this.table[key];
  766. };
  767. LinkTable.prototype.keys = function() {
  768. return Object.keys(this.table);
  769. };
  770. LinkTable.prototype.get_path = function(path) {
  771. var p, v, _i, _len;
  772. v = this;
  773. for (_i = 0, _len = path.length; _i < _len; _i++) {
  774. p = path[_i];
  775. if (v != null) {
  776. v = v.get(p);
  777. }
  778. }
  779. return v;
  780. };
  781. LinkTable.prototype.remove = function(key) {
  782. return delete this.table[key];
  783. };
  784. LinkTable.prototype.to_dict = function() {
  785. return this.table;
  786. };
  787. LinkTable.prototype.is_leaf = function() {
  788. return false;
  789. };
  790. LinkTable.prototype.walk = function(_arg) {
  791. var fn, k, v, _ref3, _results;
  792. fn = _arg.fn;
  793. _ref3 = this.table;
  794. _results = [];
  795. for (k in _ref3) {
  796. v = _ref3[k];
  797. _results.push(v.walk({
  798. fn: fn,
  799. parent: this,
  800. key: k
  801. }));
  802. }
  803. return _results;
  804. };
  805. LinkTable.prototype.flatten = function() {
  806. var fn, out;
  807. out = [];
  808. fn = function(_arg) {
  809. var key, parent, value;
  810. key = _arg.key, value = _arg.value, parent = _arg.parent;
  811. return out.push(value);
  812. };
  813. this.walk({
  814. fn: fn
  815. });
  816. return out;
  817. };
  818. LinkTable.prototype.prune = function(prune_condition) {
  819. var fn;
  820. fn = function(_arg) {
  821. var key, parent, value;
  822. key = _arg.key, value = _arg.value, parent = _arg.parent;
  823. if (prune_condition(value)) {
  824. return parent.remove(key);
  825. }
  826. };
  827. return this.walk({
  828. fn: fn
  829. });
  830. };
  831. LinkTable.prototype.select = function(keys) {
  832. var k, out, _i, _len;
  833. out = new LinkTable;
  834. for (_i = 0, _len = keys.length; _i < _len; _i++) {
  835. k = keys[_i];
  836. out.insert(k, this.get(k));
  837. }
  838. return out;
  839. };
  840. return LinkTable;
  841. })();
  842. }).call(this);