UNPKG

@fireblocks/psbt-sdk

Version:

SDK for signing Partially Signed Bitcoin Transactions (PSBTs) using Fireblocks

42 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FireblocksSigner = void 0; const fireblocksUtils_1 = require("./fireblocksUtils"); class FireblocksSigner { constructor(fireblocks, assetId, vaultId, addressIndex, publicKey, derivationPath, note) { this.fireblocks = fireblocks; this.assetId = assetId; this.vaultId = vaultId; this.addressIndex = addressIndex; this.publicKey = publicKey; this.derivationPath = derivationPath; this.note = note; } static async create({ fireblocks, assetId, vaultId, addressIndex, note, }) { const fireblocksSDK = (0, fireblocksUtils_1.createFireblocksClient)(fireblocks || {}); const publicKeyInfo = await fireblocksSDK.vaults.getPublicKeyInfoForAddress({ assetId, vaultAccountId: vaultId, change: 0, addressIndex: addressIndex !== null && addressIndex !== void 0 ? addressIndex : 0, compressed: true, }); if (!publicKeyInfo.data.publicKey) { throw new Error("Failed to retrieve public key from Fireblocks"); } const publicKey = Buffer.from(publicKeyInfo.data.publicKey, "hex"); return new FireblocksSigner(fireblocksSDK, assetId, vaultId, addressIndex !== null && addressIndex !== void 0 ? addressIndex : 0, publicKey, [44, assetId === "BTC" ? 0 : 1, Number(vaultId), 0, addressIndex !== null && addressIndex !== void 0 ? addressIndex : 0], note); } async sign(hash, lowR) { return await (0, fireblocksUtils_1.rawSign)({ fireblocks: this.fireblocks, assetId: this.assetId, vaultId: this.vaultId, addressIndex: this.addressIndex, content: hash.toString("hex"), note: this.note, }); } } exports.FireblocksSigner = FireblocksSigner; //# sourceMappingURL=fireblocksSigner.js.map