UNPKG

wallet-storage-client

Version:
39 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScriptTemplateSABPPP = exports.brc29ProtocolID = void 0; const sdk_1 = require("@bsv/sdk"); const index_client_1 = require("./index.client"); const sdk_2 = require("@bsv/sdk"); exports.brc29ProtocolID = [2, '3241645161d8']; class ScriptTemplateSABPPP { constructor(params) { this.params = params; /** * P2PKH unlock estimateLength is a constant */ this.unlockLength = 108; this.p2pkh = new sdk_2.P2PKH(); (0, index_client_1.verifyTruthy)(params.derivationPrefix); (0, index_client_1.verifyTruthy)(params.derivationSuffix); } getKeyID() { return `${this.params.derivationPrefix} ${this.params.derivationSuffix}`; } getKeyDeriver(privKey) { if (typeof privKey === 'string') privKey = sdk_2.PrivateKey.fromHex(privKey); if (!this.params.keyDeriver || this.params.keyDeriver.rootKey.toHex() !== privKey.toHex()) return new sdk_1.KeyDeriver(privKey); return this.params.keyDeriver; } lock(lockerPrivKey, unlockerPubKey) { const address = this.getKeyDeriver(lockerPrivKey).derivePublicKey(exports.brc29ProtocolID, this.getKeyID(), unlockerPubKey, false).toAddress(); const r = this.p2pkh.lock(address); return r; } unlock(unlockerPrivKey, lockerPubKey, sourceSatoshis, lockingScript) { const derivedPrivateKey = this.getKeyDeriver(unlockerPrivKey).derivePrivateKey(exports.brc29ProtocolID, this.getKeyID(), lockerPubKey).toHex(); const r = this.p2pkh.unlock((0, index_client_1.asBsvSdkPrivateKey)(derivedPrivateKey), "all", false, sourceSatoshis, lockingScript); return r; } } exports.ScriptTemplateSABPPP = ScriptTemplateSABPPP; //# sourceMappingURL=ScriptTemplateSABPPP.js.map