UNPKG

@desig/web3

Version:

Desig: The Blockchain-Agnostic Multisig Solution

54 lines 2.75 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Multisig = void 0; const zod_1 = require("zod"); const connection_1 = require("../connection"); const bs58_1 = require("bs58"); const utils_1 = require("../utils"); const supported_chains_1 = require("@desig/supported-chains"); class Multisig extends connection_1.Connection { constructor(cluster, privkey) { super(cluster, (0, bs58_1.decode)(privkey)); this.watch = (multisigId, callback) => { const unwatch = this.on(connection_1.EventStreaming.multisig, multisigId, callback); return unwatch; }; this.getMultisig = (multisigId) => __awaiter(this, void 0, void 0, function* () { const { data } = yield this.connection.get(`/multisig/${multisigId}`); return data; }); this.initializeMultisig = (curve, payload) => __awaiter(this, void 0, void 0, function* () { zod_1.z.nativeEnum(supported_chains_1.Curve).parse(curve); zod_1.z.object({ t: zod_1.z.number().int().gte(1).lte(101), n: zod_1.z.number().int().gte(1).lte(101), pubkeys: zod_1.z .array(zod_1.z.string().refine((pubkey) => (0, utils_1.isAddress)(pubkey), (pubkey) => ({ message: `Invalid pubkey format: ${pubkey}.` }))) .nonempty(), }) .refine(({ t, n }) => t <= n, { message: 'The threshold t must be less than or equal to n.', }) .refine(({ n, pubkeys }) => n === pubkeys.length, { message: 'Insufficient number of member pubkeys.', }) .parse(payload); const Authorization = yield this.getAuthorization(payload); const { data } = yield this.connection.post('/multisig', payload, { headers: { Authorization, 'X-Desig-Curve': curve }, }); return data; }); } } exports.Multisig = Multisig; //# sourceMappingURL=index.js.map