UNPKG

3box

Version:
375 lines (320 loc) 12.1 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var verifier = require('./utils/verifier'); var Verified = /*#__PURE__*/function () { /** * Please use **box.verified** to get the instance of this class */ function Verified(box) { (0, _classCallCheck2["default"])(this, Verified); this._box = box; } (0, _createClass2["default"])(Verified, [{ key: "_addVerifiedPublicAccount", value: function () { var _addVerifiedPublicAccount2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(key, proof, verificationFunction) { var account; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return verificationFunction(this._box.DID, proof); case 2: account = _context.sent; _context.next = 5; return this._box["public"].set('proof_' + key, proof); case 5: return _context.abrupt("return", account); case 6: case "end": return _context.stop(); } } }, _callee, this); })); function _addVerifiedPublicAccount(_x, _x2, _x3) { return _addVerifiedPublicAccount2.apply(this, arguments); } return _addVerifiedPublicAccount; }() }, { key: "_getVerifiedPublicAccount", value: function () { var _getVerifiedPublicAccount2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(key, verificationFunction) { var proof; return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return this._box["public"].get('proof_' + key); case 2: proof = _context2.sent; return _context2.abrupt("return", verificationFunction(this._box.DID, proof)); case 4: case "end": return _context2.stop(); } } }, _callee2, this); })); function _getVerifiedPublicAccount(_x4, _x5) { return _getVerifiedPublicAccount2.apply(this, arguments); } return _getVerifiedPublicAccount; }() }, { key: "_addVerifiedPrivateAccount", value: function () { var _addVerifiedPrivateAccount2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(key, proof, verificationFunction) { var account; return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return verificationFunction(this._box.DID, proof); case 2: account = _context3.sent; _context3.next = 5; return this._box["private"].set('proof_' + key, proof); case 5: return _context3.abrupt("return", account); case 6: case "end": return _context3.stop(); } } }, _callee3, this); })); function _addVerifiedPrivateAccount(_x6, _x7, _x8) { return _addVerifiedPrivateAccount2.apply(this, arguments); } return _addVerifiedPrivateAccount; }() }, { key: "_getVerifiedPrivateAccount", value: function () { var _getVerifiedPrivateAccount2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(key, verificationFunction) { var proof; return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return this._box["private"].get('proof_' + key); case 2: proof = _context4.sent; return _context4.abrupt("return", verificationFunction(this._box.DID, proof)); case 4: case "end": return _context4.stop(); } } }, _callee4, this); })); function _getVerifiedPrivateAccount(_x9, _x10) { return _getVerifiedPrivateAccount2.apply(this, arguments); } return _getVerifiedPrivateAccount; }() /** * Returns the verified DID of the user * * @return {String} The DID of the user */ }, { key: "DID", value: function () { var _DID = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() { return _regenerator["default"].wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: return _context5.abrupt("return", this._box.DID); case 1: case "end": return _context5.stop(); } } }, _callee5, this); })); function DID() { return _DID.apply(this, arguments); } return DID; }() /** * Verifies that the user has a valid github account * Throws an error otherwise. * * @return {Object} Object containing username, and proof */ }, { key: "github", value: function () { var _github = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() { return _regenerator["default"].wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: return _context6.abrupt("return", this._getVerifiedPublicAccount('github', verifier.verifyGithub)); case 1: case "end": return _context6.stop(); } } }, _callee6, this); })); function github() { return _github.apply(this, arguments); } return github; }() /** * Adds a github verification to the users profile * Throws an error if the verification fails. * * @param {Object} gistUrl URL of the proof * @return {Object} Object containing username, and proof */ }, { key: "addGithub", value: function () { var _addGithub = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(gistUrl) { return _regenerator["default"].wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: return _context7.abrupt("return", this._addVerifiedPublicAccount('github', gistUrl, verifier.verifyGithub)); case 1: case "end": return _context7.stop(); } } }, _callee7, this); })); function addGithub(_x11) { return _addGithub.apply(this, arguments); } return addGithub; }() /** * Verifies that the user has a valid twitter account * Throws an error otherwise. * * @return {Object} Object containing username, proof, and the verifier */ }, { key: "twitter", value: function () { var _twitter = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() { return _regenerator["default"].wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: return _context8.abrupt("return", this._getVerifiedPublicAccount('twitter', verifier.verifyTwitter)); case 1: case "end": return _context8.stop(); } } }, _callee8, this); })); function twitter() { return _twitter.apply(this, arguments); } return twitter; }() /** * Adds a twitter verification to the users profile * Throws an error if the verification fails. * * @param {String} claim A did-JWT claim ownership of a twitter username * @return {Object} Object containing username, proof, and the verifier */ }, { key: "addTwitter", value: function () { var _addTwitter = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(claim) { return _regenerator["default"].wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: return _context9.abrupt("return", this._addVerifiedPublicAccount('twitter', claim, verifier.verifyTwitter)); case 1: case "end": return _context9.stop(); } } }, _callee9, this); })); function addTwitter(_x12) { return _addTwitter.apply(this, arguments); } return addTwitter; }() /** * Verifies that the user has a verified email account * Throws an error otherwise. * * @return {Object} Object containing username, proof, and the verifier */ }, { key: "email", value: function () { var _email = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() { return _regenerator["default"].wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: return _context10.abrupt("return", this._getVerifiedPrivateAccount('email', verifier.verifyEmail)); case 1: case "end": return _context10.stop(); } } }, _callee10, this); })); function email() { return _email.apply(this, arguments); } return email; }() /** * Adds an email verification to the users profile * Throws an error if the verification fails. * * @param {String} claim A did-JWT claim ownership of an email username * @return {Object} Object containing username, proof, and the verifier */ }, { key: "addEmail", value: function () { var _addEmail = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(claim) { return _regenerator["default"].wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: return _context11.abrupt("return", this._addVerifiedPrivateAccount('email', claim, verifier.verifyEmail)); case 1: case "end": return _context11.stop(); } } }, _callee11, this); })); function addEmail(_x13) { return _addEmail.apply(this, arguments); } return addEmail; }() }]); return Verified; }(); module.exports = Verified;