aa-schnorr-multisig-sdk
Version:
Account Abstraction Schnorr Multi-Signatures SDK
68 lines (67 loc) • 3.63 kB
JavaScript
;
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;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchnorrSigner = void 0;
const secp256k1_1 = require("secp256k1");
const converters_1 = require("../helpers/converters");
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);
let privKeyBytes;
do
privKeyBytes = Buffer.from(_privKey);
while (!(0, secp256k1_1.privateKeyVerify)(privKeyBytes));
const pubKey = Buffer.from((0, secp256k1_1.publicKeyCreate)(privKeyBytes));
const data = {
publicKey: pubKey,
privateKey: privKeyBytes,
};
const keys = new types_1.KeyPair(data);
__classPrivateFieldSet(this, _SchnorrSigner_privateKey, keys.privateKey, "f");
__classPrivateFieldSet(this, _SchnorrSigner_publicKey, keys.publicKey, "f");
}
getAddress() {
return (0, converters_1.pubKey2Address)(__classPrivateFieldGet(this, _SchnorrSigner_publicKey, "f").buffer);
}
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"));
}
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 = null) {
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();