UNPKG

keybase-proofs

Version:

Publicly-verifiable proofs of identity

150 lines (136 loc) 5.45 kB
// Generated by IcedCoffeeScript 108.0.11 (function() { var BaseScraper, GenericSocialScraper, constants, iced, sncmp, v_codes, __iced_k, __iced_k_noop, _ref, __hasProp = {}.hasOwnProperty, __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; }; iced = require('iced-runtime'); __iced_k = __iced_k_noop = function() {}; _ref = require('./base'), sncmp = _ref.sncmp, BaseScraper = _ref.BaseScraper; constants = require('../constants').constants; v_codes = constants.v_codes; exports.GenericSocialScraper = GenericSocialScraper = (function(_super) { __extends(GenericSocialScraper, _super); function GenericSocialScraper(opts) { GenericSocialScraper.__super__.constructor.call(this, opts); } GenericSocialScraper.prototype._check_args = function(args) { if (!(args.username != null)) { return new Error("Bad args to GenericSocialScraper proof: no username given"); } else { return null; } }; GenericSocialScraper.prototype.hunt2 = function(_arg, cb) { var bad_args_err, err, name, out, pproof, username; username = _arg.username, name = _arg.name; out = {}; bad_args_err = function(e, rc) { out.rc = rc != null ? rc : v_codes.BAD_ARGS; return new Error("Bad args to GenericSocialScraper proofs" + (e ? ": " + e : "")); }; if (!(username != null)) { err = bad_args_err("no username given"); } else if (!(name != null)) { err = bad_args_err("no service name given"); } else if (name.indexOf('.') === -1) { err = bad_args_err("service name `" + name + "` is likely wrong - no dot in name."); } else if ((pproof = this.libs.create_paramproofs_url_and_path({ name: name, username: username })) == null) { err = bad_args_err("unknown service `" + name + "`", v_codes.SERVICE_DEAD); } else { out = { rc: v_codes.OK, api_url: pproof.api_url, remote_id: username }; } return cb(err, out); }; GenericSocialScraper.prototype._find_proofs_in_json = function(_arg) { var check_path, err, found, kb_username, obj, path, rc, sig_id, step; check_path = _arg.check_path, obj = _arg.obj, kb_username = _arg.kb_username, sig_id = _arg.sig_id; rc = v_codes.NOT_FOUND; err = null; path = check_path.concat(); while (step = path.shift()) { obj = obj[step]; if (obj == null) { break; } } if (!((obj != null) && Array.isArray(obj))) { err = new Error("did not find proof list on " + (check_path.join('.')) + " in json data"); return [err, rc]; } found = obj.find(function(x) { return x && sncmp(x.kb_username, kb_username) && sncmp(x.sig_hash, sig_id); }); if (found != null) { rc = v_codes.OK; } else { err = new Error("user not found in proof list"); } return [err, rc]; }; GenericSocialScraper.prototype.check_status = function(_arg, cb) { var api_url, e, err, html, kb_username, name, obj, pproof, rc, sig_id, username, ___iced_passed_deferral, __iced_deferrals, __iced_k; __iced_k = __iced_k_noop; ___iced_passed_deferral = iced.findDeferral(arguments); kb_username = _arg.kb_username, username = _arg.username, name = _arg.name, api_url = _arg.api_url, sig_id = _arg.sig_id; pproof = this.libs.create_paramproofs_url_and_path({ name: name, username: username }); if (pproof == null) { return cb(new Error("bad service name"), v_codes.SERVICE_DEAD); } (function(_this) { return (function(__iced_k) { __iced_deferrals = new iced.Deferrals(__iced_k, { parent: ___iced_passed_deferral, filename: "/home/sy/go/src/github.com/keybase/proofs/src/scrapers/generic_social.iced", funcname: "GenericSocialScraper.check_status" }); _this._get_url_body({ url: pproof.api_url }, __iced_deferrals.defer({ assign_fn: (function() { return function() { err = arguments[0]; rc = arguments[1]; return html = arguments[2]; }; })(), lineno: 68 })); __iced_deferrals._fulfill(); }); })(this)((function(_this) { return function() { var _ref1; if (rc === v_codes.OK) { try { obj = JSON.parse(html); } catch (_error) { e = _error; err = new Error("unable to parse JSON content: " + (e.toString())); rc = v_codes.CONTENT_FAILURE; } if (!err) { _ref1 = _this._find_proofs_in_json({ check_path: pproof.check_path, obj: obj, kb_username: kb_username, sig_id: sig_id }), err = _ref1[0], rc = _ref1[1]; } } return cb(err, rc); }; })(this)); }; return GenericSocialScraper; })(BaseScraper); }).call(this);