utxo-lib 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/src/address.d.ts +11 -0
- package/dist/src/address.d.ts.map +1 -0
- package/dist/src/address.js +37 -0
- package/dist/src/addressFormat.d.ts +53 -0
- package/dist/src/addressFormat.d.ts.map +1 -0
- package/dist/src/addressFormat.js +110 -0
- package/dist/src/bitgo/Musig2.d.ts +51 -0
- package/dist/src/bitgo/Musig2.d.ts.map +1 -0
- package/dist/src/bitgo/Musig2.js +175 -0
- package/dist/src/bitgo/Unspent.d.ts +95 -0
- package/dist/src/bitgo/Unspent.d.ts.map +1 -0
- package/dist/src/bitgo/Unspent.js +138 -0
- package/dist/src/bitgo/UtxoPsbt.d.ts +132 -0
- package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/UtxoPsbt.js +469 -0
- package/dist/src/bitgo/UtxoTransaction.d.ts +22 -0
- package/dist/src/bitgo/UtxoTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/UtxoTransaction.js +97 -0
- package/dist/src/bitgo/UtxoTransactionBuilder.d.ts +26 -0
- package/dist/src/bitgo/UtxoTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/UtxoTransactionBuilder.js +67 -0
- package/dist/src/bitgo/bbc/DashPsbt.d.ts +12 -0
- package/dist/src/bitgo/bbc/DashPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/DashPsbt.js +27 -0
- package/dist/src/bitgo/bbc/DashTransaction.d.ts +39 -0
- package/dist/src/bitgo/bbc/DashTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/DashTransaction.js +109 -0
- package/dist/src/bitgo/bbc/DashTransactionBuilder.d.ts +14 -0
- package/dist/src/bitgo/bbc/DashTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/DashTransactionBuilder.js +28 -0
- package/dist/src/bitgo/bbc/index.d.ts +4 -0
- package/dist/src/bitgo/bbc/index.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/index.js +16 -0
- package/dist/src/bitgo/bitcoincash/address.d.ts +35 -0
- package/dist/src/bitgo/bitcoincash/address.d.ts.map +1 -0
- package/dist/src/bitgo/bitcoincash/address.js +151 -0
- package/dist/src/bitgo/bitcoincash/index.d.ts +2 -0
- package/dist/src/bitgo/bitcoincash/index.d.ts.map +1 -0
- package/dist/src/bitgo/bitcoincash/index.js +14 -0
- package/dist/src/bitgo/dash/DashPsbt.d.ts +12 -0
- package/dist/src/bitgo/dash/DashPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/dash/DashPsbt.js +27 -0
- package/dist/src/bitgo/dash/DashTransaction.d.ts +39 -0
- package/dist/src/bitgo/dash/DashTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/dash/DashTransaction.js +109 -0
- package/dist/src/bitgo/dash/DashTransactionBuilder.d.ts +14 -0
- package/dist/src/bitgo/dash/DashTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/dash/DashTransactionBuilder.js +28 -0
- package/dist/src/bitgo/dash/index.d.ts +4 -0
- package/dist/src/bitgo/dash/index.d.ts.map +1 -0
- package/dist/src/bitgo/dash/index.js +16 -0
- package/dist/src/bitgo/index.d.ts +17 -0
- package/dist/src/bitgo/index.d.ts.map +1 -0
- package/dist/src/bitgo/index.js +30 -0
- package/dist/src/bitgo/keyutil.d.ts +17 -0
- package/dist/src/bitgo/keyutil.d.ts.map +1 -0
- package/dist/src/bitgo/keyutil.js +37 -0
- package/dist/src/bitgo/nonStandardHalfSigned.d.ts +7 -0
- package/dist/src/bitgo/nonStandardHalfSigned.d.ts.map +1 -0
- package/dist/src/bitgo/nonStandardHalfSigned.js +56 -0
- package/dist/src/bitgo/outputScripts.d.ts +84 -0
- package/dist/src/bitgo/outputScripts.d.ts.map +1 -0
- package/dist/src/bitgo/outputScripts.js +297 -0
- package/dist/src/bitgo/parseInput.d.ts +92 -0
- package/dist/src/bitgo/parseInput.d.ts.map +1 -0
- package/dist/src/bitgo/parseInput.js +344 -0
- package/dist/src/bitgo/psbt/fromHalfSigned.d.ts +24 -0
- package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -0
- package/dist/src/bitgo/psbt/fromHalfSigned.js +91 -0
- package/dist/src/bitgo/psbt/scriptTypes.d.ts +6 -0
- package/dist/src/bitgo/psbt/scriptTypes.d.ts.map +1 -0
- package/dist/src/bitgo/psbt/scriptTypes.js +23 -0
- package/dist/src/bitgo/signature.d.ts +84 -0
- package/dist/src/bitgo/signature.d.ts.map +1 -0
- package/dist/src/bitgo/signature.js +222 -0
- package/dist/src/bitgo/tnumber.d.ts +9 -0
- package/dist/src/bitgo/tnumber.d.ts.map +1 -0
- package/dist/src/bitgo/tnumber.js +31 -0
- package/dist/src/bitgo/transaction.d.ts +29 -0
- package/dist/src/bitgo/transaction.d.ts.map +1 -0
- package/dist/src/bitgo/transaction.js +247 -0
- package/dist/src/bitgo/types.d.ts +5 -0
- package/dist/src/bitgo/types.d.ts.map +1 -0
- package/dist/src/bitgo/types.js +12 -0
- package/dist/src/bitgo/wallet/Psbt.d.ts +47 -0
- package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/Psbt.js +232 -0
- package/dist/src/bitgo/wallet/Unspent.d.ts +47 -0
- package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/Unspent.js +154 -0
- package/dist/src/bitgo/wallet/WalletKeys.d.ts +72 -0
- package/dist/src/bitgo/wallet/WalletKeys.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletKeys.js +104 -0
- package/dist/src/bitgo/wallet/WalletOutput.d.ts +18 -0
- package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletOutput.js +69 -0
- package/dist/src/bitgo/wallet/WalletScripts.d.ts +7 -0
- package/dist/src/bitgo/wallet/WalletScripts.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletScripts.js +15 -0
- package/dist/src/bitgo/wallet/WalletUnspentSigner.d.ts +19 -0
- package/dist/src/bitgo/wallet/WalletUnspentSigner.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletUnspentSigner.js +47 -0
- package/dist/src/bitgo/wallet/chains.d.ts +57 -0
- package/dist/src/bitgo/wallet/chains.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/chains.js +106 -0
- package/dist/src/bitgo/wallet/index.d.ts +8 -0
- package/dist/src/bitgo/wallet/index.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/index.js +20 -0
- package/dist/src/bitgo/zcash/ZcashBufferutils.d.ts +26 -0
- package/dist/src/bitgo/zcash/ZcashBufferutils.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashBufferutils.js +157 -0
- package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +36 -0
- package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashPsbt.js +146 -0
- package/dist/src/bitgo/zcash/ZcashTransaction.d.ts +61 -0
- package/dist/src/bitgo/zcash/ZcashTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashTransaction.js +341 -0
- package/dist/src/bitgo/zcash/ZcashTransactionBuilder.d.ts +21 -0
- package/dist/src/bitgo/zcash/ZcashTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashTransactionBuilder.js +105 -0
- package/dist/src/bitgo/zcash/address.d.ts +8 -0
- package/dist/src/bitgo/zcash/address.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/address.js +57 -0
- package/dist/src/bitgo/zcash/hashZip0244.d.ts +27 -0
- package/dist/src/bitgo/zcash/hashZip0244.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/hashZip0244.js +184 -0
- package/dist/src/bitgo/zcash/index.d.ts +4 -0
- package/dist/src/bitgo/zcash/index.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/index.js +16 -0
- package/dist/src/classify.d.ts +19 -0
- package/dist/src/classify.d.ts.map +1 -0
- package/dist/src/classify.js +89 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +36 -0
- package/dist/src/networks.d.ts +119 -0
- package/dist/src/networks.d.ts.map +1 -0
- package/dist/src/networks.js +477 -0
- package/dist/src/noble_ecc.d.ts +28 -0
- package/dist/src/noble_ecc.d.ts.map +1 -0
- package/dist/src/noble_ecc.js +168 -0
- package/dist/src/payments/index.d.ts +4 -0
- package/dist/src/payments/index.d.ts.map +1 -0
- package/dist/src/payments/index.js +8 -0
- package/dist/src/payments/p2tr.d.ts +3 -0
- package/dist/src/payments/p2tr.d.ts.map +1 -0
- package/dist/src/payments/p2tr.js +348 -0
- package/dist/src/payments/p2tr_ns.d.ts +3 -0
- package/dist/src/payments/p2tr_ns.d.ts.map +1 -0
- package/dist/src/payments/p2tr_ns.js +134 -0
- package/dist/src/taproot.d.ts +141 -0
- package/dist/src/taproot.d.ts.map +1 -0
- package/dist/src/taproot.js +384 -0
- package/dist/src/templates/multisig/index.d.ts +4 -0
- package/dist/src/templates/multisig/index.d.ts.map +1 -0
- package/dist/src/templates/multisig/index.js +8 -0
- package/dist/src/templates/multisig/input.d.ts +7 -0
- package/dist/src/templates/multisig/input.d.ts.map +1 -0
- package/dist/src/templates/multisig/input.js +25 -0
- package/dist/src/templates/multisig/output.d.ts +7 -0
- package/dist/src/templates/multisig/output.d.ts.map +1 -0
- package/dist/src/templates/multisig/output.js +38 -0
- package/dist/src/templates/nulldata.d.ts +10 -0
- package/dist/src/templates/nulldata.d.ts.map +1 -0
- package/dist/src/templates/nulldata.js +17 -0
- package/dist/src/templates/pubkey/index.d.ts +4 -0
- package/dist/src/templates/pubkey/index.d.ts.map +1 -0
- package/dist/src/templates/pubkey/index.js +8 -0
- package/dist/src/templates/pubkey/input.d.ts +7 -0
- package/dist/src/templates/pubkey/input.d.ts.map +1 -0
- package/dist/src/templates/pubkey/input.js +14 -0
- package/dist/src/templates/pubkey/output.d.ts +7 -0
- package/dist/src/templates/pubkey/output.d.ts.map +1 -0
- package/dist/src/templates/pubkey/output.js +15 -0
- package/dist/src/templates/pubkeyhash/index.d.ts +4 -0
- package/dist/src/templates/pubkeyhash/index.d.ts.map +1 -0
- package/dist/src/templates/pubkeyhash/index.js +8 -0
- package/dist/src/templates/pubkeyhash/input.d.ts +7 -0
- package/dist/src/templates/pubkeyhash/input.d.ts.map +1 -0
- package/dist/src/templates/pubkeyhash/input.js +16 -0
- package/dist/src/templates/pubkeyhash/output.d.ts +6 -0
- package/dist/src/templates/pubkeyhash/output.d.ts.map +1 -0
- package/dist/src/templates/pubkeyhash/output.js +20 -0
- package/dist/src/templates/scripthash/index.d.ts +4 -0
- package/dist/src/templates/scripthash/index.d.ts.map +1 -0
- package/dist/src/templates/scripthash/index.js +8 -0
- package/dist/src/templates/scripthash/input.d.ts +6 -0
- package/dist/src/templates/scripthash/input.d.ts.map +1 -0
- package/dist/src/templates/scripthash/input.js +43 -0
- package/dist/src/templates/scripthash/output.d.ts +6 -0
- package/dist/src/templates/scripthash/output.d.ts.map +1 -0
- package/dist/src/templates/scripthash/output.js +15 -0
- package/dist/src/templates/taproot/index.d.ts +4 -0
- package/dist/src/templates/taproot/index.d.ts.map +1 -0
- package/dist/src/templates/taproot/index.js +8 -0
- package/dist/src/templates/taproot/input.d.ts +6 -0
- package/dist/src/templates/taproot/input.d.ts.map +1 -0
- package/dist/src/templates/taproot/input.js +23 -0
- package/dist/src/templates/taproot/output.d.ts +6 -0
- package/dist/src/templates/taproot/output.d.ts.map +1 -0
- package/dist/src/templates/taproot/output.js +15 -0
- package/dist/src/templates/taprootnofn/index.d.ts +4 -0
- package/dist/src/templates/taprootnofn/index.d.ts.map +1 -0
- package/dist/src/templates/taprootnofn/index.js +8 -0
- package/dist/src/templates/taprootnofn/input.d.ts +7 -0
- package/dist/src/templates/taprootnofn/input.d.ts.map +1 -0
- package/dist/src/templates/taprootnofn/input.js +24 -0
- package/dist/src/templates/taprootnofn/output.d.ts +7 -0
- package/dist/src/templates/taprootnofn/output.d.ts.map +1 -0
- package/dist/src/templates/taprootnofn/output.js +28 -0
- package/dist/src/templates/witnesscommitment/index.d.ts +3 -0
- package/dist/src/templates/witnesscommitment/index.d.ts.map +1 -0
- package/dist/src/templates/witnesscommitment/index.js +6 -0
- package/dist/src/templates/witnesscommitment/output.d.ts +8 -0
- package/dist/src/templates/witnesscommitment/output.d.ts.map +1 -0
- package/dist/src/templates/witnesscommitment/output.js +31 -0
- package/dist/src/templates/witnesspubkeyhash/index.d.ts +4 -0
- package/dist/src/templates/witnesspubkeyhash/index.d.ts.map +1 -0
- package/dist/src/templates/witnesspubkeyhash/index.js +8 -0
- package/dist/src/templates/witnesspubkeyhash/input.d.ts +7 -0
- package/dist/src/templates/witnesspubkeyhash/input.d.ts.map +1 -0
- package/dist/src/templates/witnesspubkeyhash/input.js +19 -0
- package/dist/src/templates/witnesspubkeyhash/output.d.ts +6 -0
- package/dist/src/templates/witnesspubkeyhash/output.d.ts.map +1 -0
- package/dist/src/templates/witnesspubkeyhash/output.js +15 -0
- package/dist/src/templates/witnessscripthash/index.d.ts +4 -0
- package/dist/src/templates/witnessscripthash/index.d.ts.map +1 -0
- package/dist/src/templates/witnessscripthash/index.js +8 -0
- package/dist/src/templates/witnessscripthash/input.d.ts +6 -0
- package/dist/src/templates/witnessscripthash/input.d.ts.map +1 -0
- package/dist/src/templates/witnessscripthash/input.js +35 -0
- package/dist/src/templates/witnessscripthash/output.d.ts +6 -0
- package/dist/src/templates/witnessscripthash/output.d.ts.map +1 -0
- package/dist/src/templates/witnessscripthash/output.js +15 -0
- package/dist/src/testutil/index.d.ts +3 -0
- package/dist/src/testutil/index.d.ts.map +1 -0
- package/dist/src/testutil/index.js +15 -0
- package/dist/src/testutil/keys.d.ts +10 -0
- package/dist/src/testutil/keys.d.ts.map +1 -0
- package/dist/src/testutil/keys.js +40 -0
- package/dist/src/testutil/mock.d.ts +21 -0
- package/dist/src/testutil/mock.d.ts.map +1 -0
- package/dist/src/testutil/mock.js +86 -0
- package/dist/src/transaction_builder.d.ts +47 -0
- package/dist/src/transaction_builder.d.ts.map +1 -0
- package/dist/src/transaction_builder.js +1084 -0
- package/package.json +87 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { Network } from '../..';
|
3
|
+
import { UtxoTransactionBuilder } from '../UtxoTransactionBuilder';
|
4
|
+
import { WalletUnspentSigner } from './WalletUnspentSigner';
|
5
|
+
import { KeyName, RootWalletKeys } from './WalletKeys';
|
6
|
+
import { UtxoTransaction } from '../UtxoTransaction';
|
7
|
+
import { Triple } from '../types';
|
8
|
+
import { UnspentWithPrevTx, Unspent } from '../Unspent';
|
9
|
+
import { ChainCode } from './chains';
|
10
|
+
import { UtxoPsbt } from '../UtxoPsbt';
|
11
|
+
export interface WalletUnspent<TNumber extends number | bigint = number> extends Unspent<TNumber> {
|
12
|
+
chain: ChainCode;
|
13
|
+
index: number;
|
14
|
+
}
|
15
|
+
export interface NonWitnessWalletUnspent<TNumber extends number | bigint = number> extends UnspentWithPrevTx<TNumber>, WalletUnspent<TNumber> {
|
16
|
+
}
|
17
|
+
export declare function isWalletUnspent<TNumber extends number | bigint>(u: Unspent<TNumber>): u is WalletUnspent<TNumber>;
|
18
|
+
export declare function signInputWithUnspent<TNumber extends number | bigint>(txBuilder: UtxoTransactionBuilder<TNumber>, inputIndex: number, unspent: WalletUnspent<TNumber>, unspentSigner: WalletUnspentSigner<RootWalletKeys>): void;
|
19
|
+
/**
|
20
|
+
* @param tx
|
21
|
+
* @param inputIndex
|
22
|
+
* @param unspents
|
23
|
+
* @param walletKeys
|
24
|
+
* @return triple of booleans indicating a valid signature for each pubkey
|
25
|
+
*/
|
26
|
+
export declare function verifySignatureWithUnspent<TNumber extends number | bigint>(tx: UtxoTransaction<TNumber>, inputIndex: number, unspents: Unspent<TNumber>[], walletKeys: RootWalletKeys): Triple<boolean>;
|
27
|
+
/**
|
28
|
+
* @deprecated
|
29
|
+
* Used in certain legacy signing methods that do not derive signing data from index/chain
|
30
|
+
*/
|
31
|
+
export interface WalletUnspentLegacy<TNumber extends number | bigint = number> extends WalletUnspent<TNumber> {
|
32
|
+
/** @deprecated - obviated by signWithUnspent */
|
33
|
+
redeemScript?: string;
|
34
|
+
/** @deprecated - obviated by verifyWithUnspent */
|
35
|
+
witnessScript?: string;
|
36
|
+
}
|
37
|
+
export declare function addReplayProtectionUnspentToPsbt(psbt: UtxoPsbt, u: Unspent<bigint>, redeemScript: Buffer,
|
38
|
+
/**
|
39
|
+
* @deprecated
|
40
|
+
*/
|
41
|
+
network?: Network): void;
|
42
|
+
export declare function addWalletUnspentToPsbt(psbt: UtxoPsbt, u: WalletUnspent<bigint>, rootWalletKeys: RootWalletKeys, signer: KeyName, cosigner: KeyName,
|
43
|
+
/**
|
44
|
+
* @deprecated
|
45
|
+
*/
|
46
|
+
network?: Network): void;
|
47
|
+
//# sourceMappingURL=Unspent.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Unspent.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/Unspent.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,OAAO,EAAY,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAWnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAS,MAAM,UAAU,CAAC;AACzC,OAAO,EAAY,iBAAiB,EAAE,OAAO,EAAqC,MAAM,YAAY,CAAC;AACrG,OAAO,EAAE,SAAS,EAAY,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,MAAM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,EACd,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAClB,YAAY,EAAE,MAAM;AACpB;;GAEG;AACH,OAAO,GAAE,OAAsB,GAC9B,IAAI,CAqBN;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,QAAQ,EACd,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO;AACjB;;GAEG;AACH,OAAO,GAAE,OAAsB,GAC9B,IAAI,CAkFN"}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.addWalletUnspentToPsbt = exports.addReplayProtectionUnspentToPsbt = exports.verifySignatureWithUnspent = exports.signInputWithUnspent = exports.isWalletUnspent = void 0;
|
4
|
+
const __1 = require("../..");
|
5
|
+
const outputScripts_1 = require("../outputScripts");
|
6
|
+
const address_1 = require("../../address");
|
7
|
+
const signature_1 = require("../signature");
|
8
|
+
const Unspent_1 = require("../Unspent");
|
9
|
+
const chains_1 = require("./chains");
|
10
|
+
const Musig2_1 = require("../Musig2");
|
11
|
+
function isWalletUnspent(u) {
|
12
|
+
return u.chain !== undefined;
|
13
|
+
}
|
14
|
+
exports.isWalletUnspent = isWalletUnspent;
|
15
|
+
function signInputWithUnspent(txBuilder, inputIndex, unspent, unspentSigner) {
|
16
|
+
const { walletKeys, signer, cosigner } = unspentSigner.deriveForChainAndIndex(unspent.chain, unspent.index);
|
17
|
+
const scriptType = outputScripts_1.scriptTypeForChain(unspent.chain);
|
18
|
+
const pubScript = outputScripts_1.createOutputScript2of3(walletKeys.publicKeys, scriptType).scriptPubKey;
|
19
|
+
const pubScriptExpected = address_1.toOutputScript(unspent.address, txBuilder.network);
|
20
|
+
if (!pubScript.equals(pubScriptExpected)) {
|
21
|
+
throw new Error(`pubscript mismatch: expected ${pubScriptExpected.toString('hex')} got ${pubScript.toString('hex')}`);
|
22
|
+
}
|
23
|
+
signature_1.signInput2Of3(txBuilder, inputIndex, scriptType, walletKeys.publicKeys, signer, cosigner.publicKey, unspent.value);
|
24
|
+
}
|
25
|
+
exports.signInputWithUnspent = signInputWithUnspent;
|
26
|
+
/**
|
27
|
+
* @param tx
|
28
|
+
* @param inputIndex
|
29
|
+
* @param unspents
|
30
|
+
* @param walletKeys
|
31
|
+
* @return triple of booleans indicating a valid signature for each pubkey
|
32
|
+
*/
|
33
|
+
function verifySignatureWithUnspent(tx, inputIndex, unspents, walletKeys) {
|
34
|
+
if (tx.ins.length !== unspents.length) {
|
35
|
+
throw new Error(`input length must match unspents length`);
|
36
|
+
}
|
37
|
+
const unspent = unspents[inputIndex];
|
38
|
+
if (!isWalletUnspent(unspent)) {
|
39
|
+
return [false, false, false];
|
40
|
+
}
|
41
|
+
return signature_1.verifySignatureWithPublicKeys(tx, inputIndex, unspents.map((u) => Unspent_1.toOutput(u, tx.network)), walletKeys.deriveForChainAndIndex(unspent.chain, unspent.index).publicKeys);
|
42
|
+
}
|
43
|
+
exports.verifySignatureWithUnspent = verifySignatureWithUnspent;
|
44
|
+
function addReplayProtectionUnspentToPsbt(psbt, u, redeemScript,
|
45
|
+
/**
|
46
|
+
* @deprecated
|
47
|
+
*/
|
48
|
+
network = psbt.network) {
|
49
|
+
if (network !== psbt.network) {
|
50
|
+
throw new Error(`network parameter does not match psbt.network`);
|
51
|
+
}
|
52
|
+
const { txid, vout } = Unspent_1.toPrevOutput(u, psbt.network);
|
53
|
+
const isZcash = __1.getMainnet(psbt.network) !== __1.networks.zcash;
|
54
|
+
// Because Zcash directly hashes the value for non-segwit transactions, we do not need to check indirectly
|
55
|
+
// with the previous transaction. Therefore, we can treat Zcash non-segwit transactions as Bitcoin
|
56
|
+
// segwit transactions
|
57
|
+
if (!Unspent_1.isUnspentWithPrevTx(u) && !isZcash) {
|
58
|
+
throw new Error('Error, require previous tx to add to PSBT');
|
59
|
+
}
|
60
|
+
psbt.addInput({
|
61
|
+
hash: txid,
|
62
|
+
index: vout,
|
63
|
+
redeemScript,
|
64
|
+
});
|
65
|
+
if (!isZcash) {
|
66
|
+
psbt.updateInput(vout, { nonWitnessUtxo: u.prevTx });
|
67
|
+
}
|
68
|
+
}
|
69
|
+
exports.addReplayProtectionUnspentToPsbt = addReplayProtectionUnspentToPsbt;
|
70
|
+
function addWalletUnspentToPsbt(psbt, u, rootWalletKeys, signer, cosigner,
|
71
|
+
/**
|
72
|
+
* @deprecated
|
73
|
+
*/
|
74
|
+
network = psbt.network) {
|
75
|
+
if (network !== psbt.network) {
|
76
|
+
throw new Error(`network parameter does not match psbt.network`);
|
77
|
+
}
|
78
|
+
const { txid, vout, script, value } = Unspent_1.toPrevOutput(u, psbt.network);
|
79
|
+
const walletKeys = rootWalletKeys.deriveForChainAndIndex(u.chain, u.index);
|
80
|
+
const scriptType = outputScripts_1.scriptTypeForChain(u.chain);
|
81
|
+
psbt.addInput({
|
82
|
+
hash: txid,
|
83
|
+
index: vout,
|
84
|
+
witnessUtxo: {
|
85
|
+
script,
|
86
|
+
value,
|
87
|
+
},
|
88
|
+
});
|
89
|
+
const inputIndex = psbt.inputCount - 1;
|
90
|
+
// Because Zcash directly hashes the value for non-segwit transactions, we do not need to check indirectly
|
91
|
+
// with the previous transaction. Therefore, we can treat Zcash non-segwit transactions as Bitcoin
|
92
|
+
// segwit transactions
|
93
|
+
if (!chains_1.isSegwit(u.chain) && __1.getMainnet(psbt.network) !== __1.networks.zcash) {
|
94
|
+
if (!Unspent_1.isUnspentWithPrevTx(u)) {
|
95
|
+
throw new Error('Error, require previous tx to add to PSBT');
|
96
|
+
}
|
97
|
+
psbt.updateInput(inputIndex, { nonWitnessUtxo: u.prevTx });
|
98
|
+
}
|
99
|
+
const isBackupFlow = signer === 'backup' || cosigner === 'backup';
|
100
|
+
if (scriptType === 'p2tr' || (scriptType === 'p2trMusig2' && isBackupFlow)) {
|
101
|
+
const createSpendScriptP2trFn = scriptType === 'p2tr' ? outputScripts_1.createSpendScriptP2tr : outputScripts_1.createSpendScriptP2trMusig2;
|
102
|
+
const { controlBlock, witnessScript, leafVersion, leafHash } = createSpendScriptP2trFn(walletKeys.publicKeys, [
|
103
|
+
walletKeys[signer].publicKey,
|
104
|
+
walletKeys[cosigner].publicKey,
|
105
|
+
]);
|
106
|
+
psbt.updateInput(inputIndex, {
|
107
|
+
tapLeafScript: [{ controlBlock, script: witnessScript, leafVersion }],
|
108
|
+
tapBip32Derivation: [signer, cosigner].map((key) => ({
|
109
|
+
leafHashes: [leafHash],
|
110
|
+
pubkey: outputScripts_1.toXOnlyPublicKey(walletKeys[key].publicKey),
|
111
|
+
path: rootWalletKeys.getDerivationPath(rootWalletKeys[key], u.chain, u.index),
|
112
|
+
masterFingerprint: rootWalletKeys[key].fingerprint,
|
113
|
+
})),
|
114
|
+
});
|
115
|
+
}
|
116
|
+
else if (scriptType === 'p2trMusig2') {
|
117
|
+
const { internalPubkey: tapInternalKey, outputPubkey: tapOutputKey, taptreeRoot, } = outputScripts_1.createKeyPathP2trMusig2(walletKeys.publicKeys);
|
118
|
+
const participantPubKeys = [walletKeys.user.publicKey, walletKeys.bitgo.publicKey];
|
119
|
+
const participantsKeyValData = Musig2_1.encodePsbtMusig2ParticipantsKeyValData({
|
120
|
+
tapOutputKey,
|
121
|
+
tapInternalKey,
|
122
|
+
participantPubKeys,
|
123
|
+
});
|
124
|
+
psbt.addProprietaryKeyValToInput(inputIndex, participantsKeyValData);
|
125
|
+
psbt.updateInput(inputIndex, {
|
126
|
+
tapInternalKey: tapInternalKey,
|
127
|
+
tapMerkleRoot: taptreeRoot,
|
128
|
+
tapBip32Derivation: [signer, cosigner].map((key) => ({
|
129
|
+
leafHashes: [],
|
130
|
+
pubkey: outputScripts_1.toXOnlyPublicKey(walletKeys[key].publicKey),
|
131
|
+
path: rootWalletKeys.getDerivationPath(rootWalletKeys[key], u.chain, u.index),
|
132
|
+
masterFingerprint: rootWalletKeys[key].fingerprint,
|
133
|
+
})),
|
134
|
+
});
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
const { witnessScript, redeemScript } = outputScripts_1.createOutputScript2of3(walletKeys.publicKeys, scriptType);
|
138
|
+
psbt.updateInput(inputIndex, {
|
139
|
+
bip32Derivation: [0, 1, 2].map((idx) => ({
|
140
|
+
pubkey: walletKeys.triple[idx].publicKey,
|
141
|
+
path: walletKeys.paths[idx],
|
142
|
+
masterFingerprint: rootWalletKeys.triple[idx].fingerprint,
|
143
|
+
})),
|
144
|
+
});
|
145
|
+
if (witnessScript) {
|
146
|
+
psbt.updateInput(inputIndex, { witnessScript });
|
147
|
+
}
|
148
|
+
if (redeemScript) {
|
149
|
+
psbt.updateInput(inputIndex, { redeemScript });
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
exports.addWalletUnspentToPsbt = addWalletUnspentToPsbt;
|
154
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVW5zcGVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvVW5zcGVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw2QkFBc0Q7QUFFdEQsb0RBTzBCO0FBQzFCLDJDQUErQztBQUMvQyw0Q0FBNEU7QUFLNUUsd0NBQXFHO0FBQ3JHLHFDQUErQztBQUUvQyxzQ0FBbUU7QUFXbkUsU0FBZ0IsZUFBZSxDQUFrQyxDQUFtQjtJQUNsRixPQUFRLENBQTRCLENBQUMsS0FBSyxLQUFLLFNBQVMsQ0FBQztBQUMzRCxDQUFDO0FBRkQsMENBRUM7QUFFRCxTQUFnQixvQkFBb0IsQ0FDbEMsU0FBMEMsRUFDMUMsVUFBa0IsRUFDbEIsT0FBK0IsRUFDL0IsYUFBa0Q7SUFFbEQsTUFBTSxFQUFFLFVBQVUsRUFBRSxNQUFNLEVBQUUsUUFBUSxFQUF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ICAgICAgIHBhdGg6IHJvb3RXYWxsZXRLZXlzLmdldERlcml2YXRpb25QYXRoKHJvb3RXYWxsZXRLZXlzW2tleV0sIHUuY2hhaW4sIHUuaW5kZXgpLFxuICAgICAgICBtYXN0ZXJGaW5nZXJwcmludDogcm9vdFdhbGxldEtleXNba2V5XS5maW5nZXJwcmludCxcbiAgICAgIH0pKSxcbiAgICB9KTtcbiAgfSBlbHNlIHtcbiAgICBjb25zdCB7IHdpdG5lc3NTY3JpcHQsIHJlZGVlbVNjcmlwdCB9ID0gY3JlYXRlT3V0cHV0U2NyaXB0Mm9mMyh3YWxsZXRLZXlzLnB1YmxpY0tleXMsIHNjcmlwdFR5cGUpO1xuICAgIHBzYnQudXBkYXRlSW5wdXQoaW5wdXRJbmRleCwge1xuICAgICAgYmlwMzJEZXJpdmF0aW9uOiBbMCwgMSwgMl0ubWFwKChpZHgpID0+ICh7XG4gICAgICAgIHB1YmtleTogd2FsbGV0S2V5cy50cmlwbGVbaWR4XS5wdWJsaWNLZXksXG4gICAgICAgIHBhdGg6IHdhbGxldEtleXMucGF0aHNbaWR4XSxcbiAgICAgICAgbWFzdGVyRmluZ2VycHJpbnQ6IHJvb3RXYWxsZXRLZXlzLnRyaXBsZVtpZHhdLmZpbmdlcnByaW50LFxuICAgICAgfSkpLFxuICAgIH0pO1xuICAgIGlmICh3aXRuZXNzU2NyaXB0KSB7XG4gICAgICBwc2J0LnVwZGF0ZUlucHV0KGlucHV0SW5kZXgsIHsgd2l0bmVzc1NjcmlwdCB9KTtcbiAgICB9XG4gICAgaWYgKHJlZGVlbVNjcmlwdCkge1xuICAgICAgcHNidC51cGRhdGVJbnB1dChpbnB1dEluZGV4LCB7IHJlZGVlbVNjcmlwdCB9KTtcbiAgICB9XG4gIH1cbn1cbiJdfQ==
|
@@ -0,0 +1,72 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/**
|
3
|
+
* Classes for deriving key triples for wallet addresses.
|
4
|
+
*
|
5
|
+
* By default, BitGo wallets consist of a triple of bip32 extend keypairs.
|
6
|
+
* Every wallet address can be identified by _(chain: number, index: number)_.
|
7
|
+
* The key set for a particular address can be obtained by deriving with the path
|
8
|
+
* `0/0/${chain}/${index}`. (In rare cases the prefix 0/0 can be different)
|
9
|
+
*
|
10
|
+
* Since we never use other derivations for utxo address scripts, the classes defined here only
|
11
|
+
* allow exactly one level of derivation.
|
12
|
+
*/
|
13
|
+
import { BIP32Interface } from 'bip32';
|
14
|
+
import { Triple } from '../types';
|
15
|
+
export declare type KeyName = 'user' | 'backup' | 'bitgo';
|
16
|
+
export declare function eqPublicKey(a: BIP32Interface, b: BIP32Interface): boolean;
|
17
|
+
/**
|
18
|
+
* Base class for RootWalletKeys and DerivedWalletKeys.
|
19
|
+
* Keys can be either public keys or private keys.
|
20
|
+
*/
|
21
|
+
export declare class WalletKeys {
|
22
|
+
readonly triple: Triple<BIP32Interface>;
|
23
|
+
readonly publicKeys: Triple<Buffer>;
|
24
|
+
/**
|
25
|
+
* @param triple - bip32 key triple
|
26
|
+
*/
|
27
|
+
constructor(triple: Triple<BIP32Interface>);
|
28
|
+
get user(): BIP32Interface;
|
29
|
+
get backup(): BIP32Interface;
|
30
|
+
get bitgo(): BIP32Interface;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Set of WalletKeys derived from RootWalletKeys. Suitable for signing transaction inputs.
|
34
|
+
* Contains reference to the RootWalletKeys this was derived from as well as the paths used
|
35
|
+
* for derivation.
|
36
|
+
*/
|
37
|
+
export declare class DerivedWalletKeys extends WalletKeys {
|
38
|
+
parent: RootWalletKeys;
|
39
|
+
paths: Triple<string>;
|
40
|
+
/**
|
41
|
+
* @param parent - wallet keys to derive from
|
42
|
+
* @param paths - paths to derive with
|
43
|
+
*/
|
44
|
+
constructor(parent: RootWalletKeys, paths: Triple<string>);
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* Set of root wallet keys, typically instantiated using the wallet xpub triple.
|
48
|
+
*/
|
49
|
+
export declare class RootWalletKeys extends WalletKeys {
|
50
|
+
readonly derivationPrefixes: Triple<string>;
|
51
|
+
static readonly defaultPrefix = "0/0";
|
52
|
+
/**
|
53
|
+
* @param triple - bip32 key triple
|
54
|
+
* @param derivationPrefixes - Certain v1 wallets or their migrated v2 counterparts
|
55
|
+
* can have a nonstandard prefix.
|
56
|
+
*/
|
57
|
+
constructor(triple: Triple<BIP32Interface>, derivationPrefixes?: Triple<string>);
|
58
|
+
/**
|
59
|
+
* @param key
|
60
|
+
* @param chain
|
61
|
+
* @param index
|
62
|
+
* @return full derivation path for key, including key-specific prefix
|
63
|
+
*/
|
64
|
+
getDerivationPath(key: BIP32Interface, chain: number, index: number): string;
|
65
|
+
/**
|
66
|
+
* @param chain
|
67
|
+
* @param index
|
68
|
+
* @return walletKeys for a particular address identified by (chain, index)
|
69
|
+
*/
|
70
|
+
deriveForChainAndIndex(chain: number, index: number): DerivedWalletKeys;
|
71
|
+
}
|
72
|
+
//# sourceMappingURL=WalletKeys.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WalletKeys.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/WalletKeys.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,oBAAY,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElD,wBAAgB,WAAW,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,CAEzE;AAED;;;GAGG;AACH,qBAAa,UAAU;aAMO,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAL1D,SAAgB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAE3C;;OAEG;gBACyB,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAY1D,IAAI,IAAI,IAAI,cAAc,CAEzB;IAED,IAAI,MAAM,IAAI,cAAc,CAE3B;IAED,IAAI,KAAK,IAAI,cAAc,CAE1B;CACF;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAK5B,MAAM,EAAE,cAAc;IAAS,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;IAJvE;;;OAGG;gBACgB,MAAM,EAAE,cAAc,EAAS,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;CAGxE;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;aAU1B,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC;IATpD,MAAM,CAAC,QAAQ,CAAC,aAAa,SAAS;IAEtC;;;;OAIG;gBAED,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,EACd,kBAAkB,GAAE,MAAM,CAAC,MAAM,CAIhD;IAWH;;;;;OAKG;IACH,iBAAiB,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAW5E;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB;CAMxE"}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.RootWalletKeys = exports.DerivedWalletKeys = exports.WalletKeys = exports.eqPublicKey = void 0;
|
4
|
+
function eqPublicKey(a, b) {
|
5
|
+
return a.publicKey.equals(b.publicKey);
|
6
|
+
}
|
7
|
+
exports.eqPublicKey = eqPublicKey;
|
8
|
+
/**
|
9
|
+
* Base class for RootWalletKeys and DerivedWalletKeys.
|
10
|
+
* Keys can be either public keys or private keys.
|
11
|
+
*/
|
12
|
+
class WalletKeys {
|
13
|
+
/**
|
14
|
+
* @param triple - bip32 key triple
|
15
|
+
*/
|
16
|
+
constructor(triple) {
|
17
|
+
this.triple = triple;
|
18
|
+
triple.forEach((a, i) => {
|
19
|
+
triple.forEach((b, j) => {
|
20
|
+
if (eqPublicKey(a, b) && i !== j) {
|
21
|
+
throw new Error(`wallet keys must be distinct`);
|
22
|
+
}
|
23
|
+
});
|
24
|
+
});
|
25
|
+
this.publicKeys = this.triple.map((k) => k.publicKey);
|
26
|
+
}
|
27
|
+
get user() {
|
28
|
+
return this.triple[0];
|
29
|
+
}
|
30
|
+
get backup() {
|
31
|
+
return this.triple[1];
|
32
|
+
}
|
33
|
+
get bitgo() {
|
34
|
+
return this.triple[2];
|
35
|
+
}
|
36
|
+
}
|
37
|
+
exports.WalletKeys = WalletKeys;
|
38
|
+
/**
|
39
|
+
* Set of WalletKeys derived from RootWalletKeys. Suitable for signing transaction inputs.
|
40
|
+
* Contains reference to the RootWalletKeys this was derived from as well as the paths used
|
41
|
+
* for derivation.
|
42
|
+
*/
|
43
|
+
class DerivedWalletKeys extends WalletKeys {
|
44
|
+
/**
|
45
|
+
* @param parent - wallet keys to derive from
|
46
|
+
* @param paths - paths to derive with
|
47
|
+
*/
|
48
|
+
constructor(parent, paths) {
|
49
|
+
super(parent.triple.map((k, i) => k.derivePath(paths[i])));
|
50
|
+
this.parent = parent;
|
51
|
+
this.paths = paths;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.DerivedWalletKeys = DerivedWalletKeys;
|
55
|
+
/**
|
56
|
+
* Set of root wallet keys, typically instantiated using the wallet xpub triple.
|
57
|
+
*/
|
58
|
+
class RootWalletKeys extends WalletKeys {
|
59
|
+
/**
|
60
|
+
* @param triple - bip32 key triple
|
61
|
+
* @param derivationPrefixes - Certain v1 wallets or their migrated v2 counterparts
|
62
|
+
* can have a nonstandard prefix.
|
63
|
+
*/
|
64
|
+
constructor(triple, derivationPrefixes = [
|
65
|
+
RootWalletKeys.defaultPrefix,
|
66
|
+
RootWalletKeys.defaultPrefix,
|
67
|
+
RootWalletKeys.defaultPrefix,
|
68
|
+
]) {
|
69
|
+
super(triple);
|
70
|
+
this.derivationPrefixes = derivationPrefixes;
|
71
|
+
derivationPrefixes.forEach((p) => {
|
72
|
+
if (p.startsWith('/') || p.endsWith('/')) {
|
73
|
+
throw new Error(`derivation prefix must not start or end with a slash`);
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* @param key
|
79
|
+
* @param chain
|
80
|
+
* @param index
|
81
|
+
* @return full derivation path for key, including key-specific prefix
|
82
|
+
*/
|
83
|
+
getDerivationPath(key, chain, index) {
|
84
|
+
if (!this.derivationPrefixes) {
|
85
|
+
throw new Error(`no derivation prefixes`);
|
86
|
+
}
|
87
|
+
const prefix = this.derivationPrefixes.find((prefix, i) => eqPublicKey(key, this.triple[i]));
|
88
|
+
if (prefix === undefined) {
|
89
|
+
throw new Error(`key not in walletKeys`);
|
90
|
+
}
|
91
|
+
return `${prefix}/${chain}/${index}`;
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* @param chain
|
95
|
+
* @param index
|
96
|
+
* @return walletKeys for a particular address identified by (chain, index)
|
97
|
+
*/
|
98
|
+
deriveForChainAndIndex(chain, index) {
|
99
|
+
return new DerivedWalletKeys(this, this.triple.map((k) => this.getDerivationPath(k, chain, index)));
|
100
|
+
}
|
101
|
+
}
|
102
|
+
exports.RootWalletKeys = RootWalletKeys;
|
103
|
+
RootWalletKeys.defaultPrefix = '0/0';
|
104
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2FsbGV0S2V5cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvV2FsbGV0S2V5cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFpQkEsU0FBZ0IsV0FBVyxDQUFDLENBQWlCLEVBQUUsQ0FBaUI7SUFDOUQsT0FBTyxDQUFDLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsU0FBUyxDQUFDLENBQUM7QU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XJyb3IoYGtleSBub3QgaW4gd2FsbGV0S2V5c2ApO1xuICAgIH1cbiAgICByZXR1cm4gYCR7cHJlZml4fS8ke2NoYWlufS8ke2luZGV4fWA7XG4gIH1cblxuICAvKipcbiAgICogQHBhcmFtIGNoYWluXG4gICAqIEBwYXJhbSBpbmRleFxuICAgKiBAcmV0dXJuIHdhbGxldEtleXMgZm9yIGEgcGFydGljdWxhciBhZGRyZXNzIGlkZW50aWZpZWQgYnkgKGNoYWluLCBpbmRleClcbiAgICovXG4gIGRlcml2ZUZvckNoYWluQW5kSW5kZXgoY2hhaW46IG51bWJlciwgaW5kZXg6IG51bWJlcik6IERlcml2ZWRXYWxsZXRLZXlzIHtcbiAgICByZXR1cm4gbmV3IERlcml2ZWRXYWxsZXRLZXlzKFxuICAgICAgdGhpcyxcbiAgICAgIHRoaXMudHJpcGxlLm1hcCgoaykgPT4gdGhpcy5nZXREZXJpdmF0aW9uUGF0aChrLCBjaGFpbiwgaW5kZXgpKSBhcyBUcmlwbGU8c3RyaW5nPlxuICAgICk7XG4gIH1cbn1cbiJdfQ==
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { UtxoPsbt } from '../UtxoPsbt';
|
2
|
+
import { RootWalletKeys } from './WalletKeys';
|
3
|
+
import { ChainCode } from './chains';
|
4
|
+
/**
|
5
|
+
* Add a verifiable wallet output to the PSBT. The output and all data
|
6
|
+
* needed to verify it from public keys only are added to the PSBT.
|
7
|
+
* Typically these are change outputs
|
8
|
+
*
|
9
|
+
* @param psbt the PSBT to add change output to
|
10
|
+
* @param rootWalletKeys keys that will be able to spend the output
|
11
|
+
* @param chain chain code to use for deriving scripts (and to determine script
|
12
|
+
* type) chain is an API parameter in the BitGo API, and may be
|
13
|
+
* any valid ChainCode
|
14
|
+
* @param index derivation index for the change address
|
15
|
+
* @param value value of the change output
|
16
|
+
*/
|
17
|
+
export declare function addWalletOutputToPsbt(psbt: UtxoPsbt, rootWalletKeys: RootWalletKeys, chain: ChainCode, index: number, value: bigint): void;
|
18
|
+
//# sourceMappingURL=WalletOutput.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WalletOutput.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/WalletOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAsB,MAAM,UAAU,CAAC;AAGzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,EACd,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAgDN"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.addWalletOutputToPsbt = void 0;
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
5
|
+
const chains_1 = require("./chains");
|
6
|
+
const outputScripts_1 = require("../outputScripts");
|
7
|
+
/**
|
8
|
+
* Add a verifiable wallet output to the PSBT. The output and all data
|
9
|
+
* needed to verify it from public keys only are added to the PSBT.
|
10
|
+
* Typically these are change outputs
|
11
|
+
*
|
12
|
+
* @param psbt the PSBT to add change output to
|
13
|
+
* @param rootWalletKeys keys that will be able to spend the output
|
14
|
+
* @param chain chain code to use for deriving scripts (and to determine script
|
15
|
+
* type) chain is an API parameter in the BitGo API, and may be
|
16
|
+
* any valid ChainCode
|
17
|
+
* @param index derivation index for the change address
|
18
|
+
* @param value value of the change output
|
19
|
+
*/
|
20
|
+
function addWalletOutputToPsbt(psbt, rootWalletKeys, chain, index, value) {
|
21
|
+
const walletKeys = rootWalletKeys.deriveForChainAndIndex(chain, index);
|
22
|
+
const scriptType = chains_1.scriptTypeForChain(chain);
|
23
|
+
if (scriptType === 'p2tr' || scriptType === 'p2trMusig2') {
|
24
|
+
const payment = scriptType === 'p2tr' ? outputScripts_1.createPaymentP2tr(walletKeys.publicKeys) : outputScripts_1.createPaymentP2trMusig2(walletKeys.publicKeys);
|
25
|
+
const allLeafHashes = payment.redeems.map((r) => bitcoinjs_lib_1.taproot.hashTapLeaf(r.output));
|
26
|
+
psbt.addOutput({
|
27
|
+
script: payment.output,
|
28
|
+
value,
|
29
|
+
tapTree: payment.tapTree,
|
30
|
+
tapInternalKey: payment.internalPubkey,
|
31
|
+
tapBip32Derivation: [0, 1, 2].map((idx) => {
|
32
|
+
const pubkey = outputScripts_1.toXOnlyPublicKey(walletKeys.triple[idx].publicKey);
|
33
|
+
const leafHashes = [];
|
34
|
+
payment.redeems.forEach((r, idx) => {
|
35
|
+
if (r.pubkeys.find((pk) => pk.equals(pubkey))) {
|
36
|
+
leafHashes.push(allLeafHashes[idx]);
|
37
|
+
}
|
38
|
+
});
|
39
|
+
return {
|
40
|
+
leafHashes,
|
41
|
+
pubkey,
|
42
|
+
path: walletKeys.paths[idx],
|
43
|
+
masterFingerprint: rootWalletKeys.triple[idx].fingerprint,
|
44
|
+
};
|
45
|
+
}),
|
46
|
+
});
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
const { scriptPubKey, witnessScript, redeemScript } = outputScripts_1.createOutputScript2of3(walletKeys.publicKeys, scriptType);
|
50
|
+
psbt.addOutput({
|
51
|
+
script: scriptPubKey,
|
52
|
+
value,
|
53
|
+
bip32Derivation: [0, 1, 2].map((idx) => ({
|
54
|
+
pubkey: walletKeys.triple[idx].publicKey,
|
55
|
+
path: walletKeys.paths[idx],
|
56
|
+
masterFingerprint: rootWalletKeys.triple[idx].fingerprint,
|
57
|
+
})),
|
58
|
+
});
|
59
|
+
const outputIndex = psbt.txOutputs.length - 1;
|
60
|
+
if (witnessScript) {
|
61
|
+
psbt.updateOutput(outputIndex, { witnessScript });
|
62
|
+
}
|
63
|
+
if (redeemScript) {
|
64
|
+
psbt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aWR4XS5wdWJsaWNLZXksXG4gICAgICAgIHBhdGg6IHdhbGxldEtleXMucGF0aHNbaWR4XSxcbiAgICAgICAgbWFzdGVyRmluZ2VycHJpbnQ6IHJvb3RXYWxsZXRLZXlzLnRyaXBsZVtpZHhdLmZpbmdlcnByaW50LFxuICAgICAgfSkpLFxuICAgIH0pO1xuICAgIGNvbnN0IG91dHB1dEluZGV4ID0gcHNidC50eE91dHB1dHMubGVuZ3RoIC0gMTtcbiAgICBpZiAod2l0bmVzc1NjcmlwdCkge1xuICAgICAgcHNidC51cGRhdGVPdXRwdXQob3V0cHV0SW5kZXgsIHsgd2l0bmVzc1NjcmlwdCB9KTtcbiAgICB9XG4gICAgaWYgKHJlZGVlbVNjcmlwdCkge1xuICAgICAgcHNidC51cGRhdGVPdXRwdXQob3V0cHV0SW5kZXgsIHsgcmVkZWVtU2NyaXB0IH0pO1xuICAgIH1cbiAgfVxufVxuIl19
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Network } from '../..';
|
2
|
+
import { ChainCode } from '..';
|
3
|
+
import { RootWalletKeys } from './WalletKeys';
|
4
|
+
import { SpendableScript } from '../outputScripts';
|
5
|
+
export declare function getWalletOutputScripts(keys: RootWalletKeys, chain: ChainCode, index: number): SpendableScript;
|
6
|
+
export declare function getWalletAddress(keys: RootWalletKeys, chain: ChainCode, index: number, network: Network): string;
|
7
|
+
//# sourceMappingURL=WalletScripts.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WalletScripts.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/WalletScripts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAW,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,SAAS,EAAiB,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAsB,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEvE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAK7G;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAEhH"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getWalletAddress = exports.getWalletOutputScripts = void 0;
|
4
|
+
const __1 = require("../..");
|
5
|
+
const __2 = require("..");
|
6
|
+
const outputScripts_1 = require("../outputScripts");
|
7
|
+
function getWalletOutputScripts(keys, chain, index) {
|
8
|
+
return __2.outputScripts.createOutputScript2of3(keys.deriveForChainAndIndex(chain, index).publicKeys, outputScripts_1.scriptTypeForChain(chain));
|
9
|
+
}
|
10
|
+
exports.getWalletOutputScripts = getWalletOutputScripts;
|
11
|
+
function getWalletAddress(keys, chain, index, network) {
|
12
|
+
return __1.address.fromOutputScript(getWalletOutputScripts(keys, chain, index).scriptPubKey, network);
|
13
|
+
}
|
14
|
+
exports.getWalletAddress = getWalletAddress;
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2FsbGV0U2NyaXB0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvV2FsbGV0U2NyaXB0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw2QkFBeUM7QUFDekMsMEJBQThDO0FBRTlDLG9EQUF1RTtBQUV2RSxTQUFnQixzQkFBc0IsQ0FBQyxJQUFvQixFQUFFLEtBQWdCLEVBQUUsS0FBYTtJQUMxRixPQUFPLGlCQUFhLENBQUMsc0JBQXNCLENBQ3pDLElBQUksQ0FBQyxzQkFBc0IsQ0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IGdldFdhbGxldEFkZHJlc3Moa2V5czogUm9vdFdhbGxldEtleXMsIGNoYWluOiBDaGFpbkNvZGUsIGluZGV4OiBudW1iZXIsIG5ldHdvcms6IE5ldHdvcmspOiBzdHJpbmcge1xuICByZXR1cm4gYWRkcmVzcy5mcm9tT3V0cHV0U2NyaXB0KGdldFdhbGxldE91dHB1dFNjcmlwdHMoa2V5cywgY2hhaW4sIGluZGV4KS5zY3JpcHRQdWJLZXksIG5ldHdvcmspO1xufVxuIl19
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { BIP32Interface } from 'bip32';
|
2
|
+
import { DerivedWalletKeys, RootWalletKeys, WalletKeys } from './WalletKeys';
|
3
|
+
import { Triple } from '../types';
|
4
|
+
export declare class WalletUnspentSigner<T extends WalletKeys> {
|
5
|
+
signer: BIP32Interface;
|
6
|
+
cosigner: BIP32Interface;
|
7
|
+
readonly walletKeys: T;
|
8
|
+
static from(walletKeys: RootWalletKeys, signer: BIP32Interface, cosigner: BIP32Interface): WalletUnspentSigner<RootWalletKeys>;
|
9
|
+
readonly signerIndex: any;
|
10
|
+
readonly cosignerIndex: any;
|
11
|
+
constructor(walletKeys: WalletKeys | Triple<BIP32Interface>, signer: BIP32Interface, cosigner: BIP32Interface);
|
12
|
+
/**
|
13
|
+
* @param chain
|
14
|
+
* @param index
|
15
|
+
* @return WalletUnspentSigner that contains keys for generating output scripts and signatures.
|
16
|
+
*/
|
17
|
+
deriveForChainAndIndex(chain: number, index: number): WalletUnspentSigner<DerivedWalletKeys>;
|
18
|
+
}
|
19
|
+
//# sourceMappingURL=WalletUnspentSigner.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"WalletUnspentSigner.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/WalletUnspentSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAe,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,mBAAmB,CAAC,CAAC,SAAS,UAAU;IAgB1C,MAAM,EAAE,cAAc;IACtB,QAAQ,EAAE,cAAc;IAhBjC,SAAgB,UAAU,EAAE,CAAC,CAAC;IAE9B,MAAM,CAAC,IAAI,CACT,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,cAAc,GACvB,mBAAmB,CAAC,cAAc,CAAC;IAItC,QAAQ,CAAC,WAAW,MAAC;IACrB,QAAQ,CAAC,aAAa,MAAC;gBAGrB,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,EACxC,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,cAAc;IAwBjC;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAAC,iBAAiB,CAAC;CAe7F"}
|