UNPKG

did-sdk-dev

Version:
73 lines 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var constant_1 = require("./common/constant"); var index_1 = require("./crypto/index"); var utils = (function () { function utils() { var _this = this; this.newDid = function () { return constant_1.constant.document.id + _this.newAccount(); }; this.newAccount = function () { var newAccountName = ''; var characters = 'abcdefghijklmnopqrstuvwxyz12345'; var charactersLength = characters.length; for (var i = 0; i < 12; i++) { newAccountName += characters.charAt(Math.floor(Math.random() * charactersLength)); } return newAccountName; }; this.getAccount = function (did) { return did.split(":").pop(); }; this.getDocumentKey = function (publicKey, id) { for (var i = 0; i < publicKey.length; i++) { if (publicKey[i].id == id) { return publicKey[i]; } } return null; }; this.getDidByKeyId = function (keyId) { var keyid = keyId.split("#"); if (keyid.length > 0) { return keyid[0]; } else { return null; } }; this.setDocumentKey = function (publicKey, key, keyId) { var i = 0; for (; i < publicKey.length; i++) { if (publicKey[i].id == keyId) { publicKey[i].publicKeyHex = key.pubKey; return publicKey; } } var did = _this.getDidByKeyId(keyId); if (!did) { return null; } publicKey.push({ id: did + '#key-' + i, type: key.type, publicKeyHex: key.pubKey, }); return publicKey; }; this.proof = function (msg, creator, hexPriKey) { var msgStr = JSON.stringify(msg); var signatureValue = new index_1.crypto().sign(msgStr, hexPriKey); return { "type": constant_1.constant.proof.type, "creator": creator, signatureValue: signatureValue, }; }; } return utils; }()); exports.utils = utils; ; //# sourceMappingURL=utils.js.map