UNPKG

@desig/web3

Version:

Desig: The Blockchain-Agnostic Multisig Solution

51 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DesigKeypair = void 0; const core_1 = require("@desig/core"); const supported_chains_1 = require("@desig/supported-chains"); const bs58_1 = require("bs58"); const zod_1 = require("zod"); const utils_1 = require("./utils"); class DesigKeypair { constructor(secretKey) { this._parseShareString = (shareString) => { const { share, id, index, t, n } = core_1.SecretSharing.extract((0, bs58_1.decode)(shareString)); this.id = id; this.index = index; this.t = t; this.n = n; this.share = share; }; this.getThreshold = () => ({ index: (0, bs58_1.encode)(this.index), t: (0, utils_1.toSmallNumber)(this.t, this.ec.ff.en), n: (0, utils_1.toSmallNumber)(this.n, this.ec.ff.en), }); this.getShare = () => core_1.SecretSharing.compress({ index: this.index, t: this.t, n: this.n, id: this.id, share: this.share, }); this.getSecretKey = () => `${this.curve}/${(0, bs58_1.encode)(this.masterkey)}/${(0, bs58_1.encode)(this.getShare())}`; this.proactivate = (zero) => { const sss = new core_1.SecretSharing(this.ec.ff); const share = sss.merge(this.getShare(), zero); this._parseShareString((0, bs58_1.encode)(share)); return this.getShare(); }; if (!secretKey) throw new Error('Invalid secret key.'); const [curve, masterkey, shareString] = secretKey.split('/'); const result = zod_1.z.nativeEnum(supported_chains_1.Curve).safeParse(curve); if (!result.success) throw new Error('Unsupported elliptic curve.'); this.curve = result.data; this.ec = utils_1.ec[this.curve]; this.masterkey = (0, bs58_1.decode)(masterkey); this._parseShareString(shareString); } } exports.DesigKeypair = DesigKeypair; //# sourceMappingURL=keypair.js.map