UNPKG

@runonflux/aa-schnorr-multisig-sdk

Version:

Account Abstraction Schnorr Multi-Signatures SDK

75 lines (74 loc) 4.18 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _SchnorrSigner_privateKey, _SchnorrSigner_publicKey, _SchnorrSigner_address; Object.defineProperty(exports, "__esModule", { value: true }); exports.SchnorrSigner = void 0; const secp256k1_1 = require("secp256k1"); const converters_1 = require("../helpers/converters"); const core_1 = require("../core"); const types_1 = require("../types"); const Schnorrkel_1 = require("./Schnorrkel"); class SchnorrSigner extends Schnorrkel_1.Schnorrkel { constructor(_privKey) { super(); _SchnorrSigner_privateKey.set(this, void 0); _SchnorrSigner_publicKey.set(this, void 0); _SchnorrSigner_address.set(this, void 0); const privKey = Buffer.from(_privKey); if (!(0, secp256k1_1.privateKeyVerify)(privKey)) throw new Error("Invalid private key"); const pubKey = Buffer.from((0, secp256k1_1.publicKeyCreate)(privKey)); const data = { publicKey: pubKey, privateKey: privKey, }; const pubKeyUncompressed = Buffer.from((0, secp256k1_1.publicKeyCreate)(privKey, false)); const address = (0, converters_1.pubKey2Address)(pubKeyUncompressed); const keys = new types_1.KeyPair(data); __classPrivateFieldSet(this, _SchnorrSigner_privateKey, keys.privateKey, "f"); __classPrivateFieldSet(this, _SchnorrSigner_publicKey, keys.publicKey, "f"); __classPrivateFieldSet(this, _SchnorrSigner_address, address, "f"); } getAddress() { return __classPrivateFieldGet(this, _SchnorrSigner_address, "f"); } getPubKey() { return __classPrivateFieldGet(this, _SchnorrSigner_publicKey, "f"); } getPubNonces() { return this.getPublicNonces(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f")); } generatePubNonces() { return this.generatePublicNonces(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f")); } restorePubNonces(kPrivateKey, kTwoPrivateKey) { return this.restorePublicNonces(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f"), kPrivateKey, kTwoPrivateKey); } hasNonces() { return this.hasNonce(__classPrivateFieldGet(this, _SchnorrSigner_publicKey, "f")); } signMultiSigMsg(msg, publicKeys, publicNonces) { return this.multiSigSign(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f"), msg, publicKeys, publicNonces); } signMultiSigHash(hash, publicKeys, publicNonces) { return this.multiSigSignHash(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f"), hash, publicKeys, publicNonces); } signMessage(msg, hashFn = core_1._hashMessage) { return Schnorrkel_1.Schnorrkel.sign(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f"), msg, hashFn); } signHash(hash) { return Schnorrkel_1.Schnorrkel.signHash(__classPrivateFieldGet(this, _SchnorrSigner_privateKey, "f"), hash); } } exports.SchnorrSigner = SchnorrSigner; _SchnorrSigner_privateKey = new WeakMap(), _SchnorrSigner_publicKey = new WeakMap(), _SchnorrSigner_address = new WeakMap();