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,84 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { BIP32Interface } from 'bip32';
|
3
|
+
import { TxOutput } from 'bitcoinjs-lib';
|
4
|
+
import { UtxoTransaction } from './UtxoTransaction';
|
5
|
+
import { UtxoTransactionBuilder } from './UtxoTransactionBuilder';
|
6
|
+
import { ScriptType2Of3 } from './outputScripts';
|
7
|
+
import { Triple } from './types';
|
8
|
+
import { Network } from '../networks';
|
9
|
+
/**
|
10
|
+
* Constraints for signature verifications.
|
11
|
+
* Parameters are conjunctive: if multiple parameters are set, a verification for an individual
|
12
|
+
* signature must satisfy all of them.
|
13
|
+
*/
|
14
|
+
export declare type VerificationSettings = {
|
15
|
+
/**
|
16
|
+
* The index of the signature to verify. Only iterates over non-empty signatures.
|
17
|
+
*/
|
18
|
+
signatureIndex?: number;
|
19
|
+
/**
|
20
|
+
* The public key to verify.
|
21
|
+
*/
|
22
|
+
publicKey?: Buffer;
|
23
|
+
};
|
24
|
+
/**
|
25
|
+
* Result for a individual signature verification
|
26
|
+
*/
|
27
|
+
export declare type SignatureVerification = {
|
28
|
+
/** Set to the public key that signed for the signature */
|
29
|
+
signedBy: Buffer;
|
30
|
+
/** Set to the signature buffer */
|
31
|
+
signature: Buffer;
|
32
|
+
} | {
|
33
|
+
signedBy: undefined;
|
34
|
+
signature: undefined;
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* @deprecated - use {@see verifySignaturesWithPublicKeys} instead
|
38
|
+
* Get signature verifications for multsig transaction
|
39
|
+
* @param transaction
|
40
|
+
* @param inputIndex
|
41
|
+
* @param amount - must be set for segwit transactions and BIP143 transactions
|
42
|
+
* @param verificationSettings
|
43
|
+
* @param prevOutputs - must be set for p2tr transactions
|
44
|
+
* @returns SignatureVerification[] - in order of parsed non-empty signatures
|
45
|
+
*/
|
46
|
+
export declare function getSignatureVerifications<TNumber extends number | bigint>(transaction: UtxoTransaction<TNumber>, inputIndex: number, amount: TNumber, verificationSettings?: VerificationSettings, prevOutputs?: TxOutput<TNumber>[]): SignatureVerification[];
|
47
|
+
/**
|
48
|
+
* @deprecated use {@see verifySignatureWithPublicKeys} instead
|
49
|
+
* @param transaction
|
50
|
+
* @param inputIndex
|
51
|
+
* @param amount
|
52
|
+
* @param verificationSettings - if publicKey is specified, returns true iff any signature is signed by publicKey.
|
53
|
+
* @param prevOutputs - must be set for p2tr transactions
|
54
|
+
*/
|
55
|
+
export declare function verifySignature<TNumber extends number | bigint>(transaction: UtxoTransaction<TNumber>, inputIndex: number, amount: TNumber, verificationSettings?: VerificationSettings, prevOutputs?: TxOutput<TNumber>[]): boolean;
|
56
|
+
/**
|
57
|
+
* @param transaction
|
58
|
+
* @param inputIndex
|
59
|
+
* @param prevOutputs
|
60
|
+
* @param publicKeys
|
61
|
+
* @return array with signature corresponding to n-th key, undefined if no match found
|
62
|
+
*/
|
63
|
+
export declare function getSignaturesWithPublicKeys<TNumber extends number | bigint>(transaction: UtxoTransaction<TNumber>, inputIndex: number, prevOutputs: TxOutput<TNumber>[], publicKeys: Buffer[]): Array<Buffer | undefined>;
|
64
|
+
/**
|
65
|
+
* @param transaction
|
66
|
+
* @param inputIndex
|
67
|
+
* @param prevOutputs - transaction outputs for inputs
|
68
|
+
* @param publicKeys - public keys to check signatures for
|
69
|
+
* @return array of booleans indicating a valid signature for every pubkey in _publicKeys_
|
70
|
+
*/
|
71
|
+
export declare function verifySignatureWithPublicKeys<TNumber extends number | bigint>(transaction: UtxoTransaction<TNumber>, inputIndex: number, prevOutputs: TxOutput<TNumber>[], publicKeys: Buffer[]): boolean[];
|
72
|
+
/**
|
73
|
+
* Wrapper for {@see verifySignatureWithPublicKeys} for single pubkey
|
74
|
+
* @param transaction
|
75
|
+
* @param inputIndex
|
76
|
+
* @param prevOutputs
|
77
|
+
* @param publicKey
|
78
|
+
* @return true iff signature is valid
|
79
|
+
*/
|
80
|
+
export declare function verifySignatureWithPublicKey<TNumber extends number | bigint>(transaction: UtxoTransaction<TNumber>, inputIndex: number, prevOutputs: TxOutput<TNumber>[], publicKey: Buffer): boolean;
|
81
|
+
export declare function getDefaultSigHash(network: Network, scriptType?: ScriptType2Of3): number;
|
82
|
+
export declare function signInputP2shP2pk<TNumber extends number | bigint>(txBuilder: UtxoTransactionBuilder<TNumber>, vin: number, keyPair: BIP32Interface): void;
|
83
|
+
export declare function signInput2Of3<TNumber extends number | bigint>(txBuilder: UtxoTransactionBuilder<TNumber>, vin: number, scriptType: ScriptType2Of3, pubkeys: Triple<Buffer>, keyPair: BIP32Interface, cosigner: Buffer, amount: TNumber): void;
|
84
|
+
//# sourceMappingURL=signature.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/bitgo/signature.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAwB,QAAQ,EAAmB,MAAM,eAAe,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAIL,cAAc,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAc,OAAO,EAAY,MAAM,aAAa,CAAC;AAI5D;;;;GAIG;AACH,oBAAY,oBAAoB,GAAG;IACjC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,oBAAY,qBAAqB,GAC7B;IACE,0DAA0D;IAC1D,QAAQ,EAAE,MA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AAgB,4BAA4B,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC1E,WAAW,EAAE,eAAe,CAAC,OAAO,CAAC,EACrC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,EAChC,SAAS,EAAE,MAAM,GAChB,OAAO,CAET;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,CAUvF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/D,SAAS,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAC1C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,cAAc,GACtB,IAAI,CAcN;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC3D,SAAS,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAC1C,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EACvB,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,IAAI,CAwBN"}
|
@@ -0,0 +1,222 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.signInput2Of3 = exports.signInputP2shP2pk = exports.getDefaultSigHash = exports.verifySignatureWithPublicKey = exports.verifySignatureWithPublicKeys = exports.getSignaturesWithPublicKeys = exports.verifySignature = exports.getSignatureVerifications = void 0;
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
5
|
+
const UtxoTransaction_1 = require("./UtxoTransaction");
|
6
|
+
const outputScripts_1 = require("./outputScripts");
|
7
|
+
const networks_1 = require("../networks");
|
8
|
+
const noble_ecc_1 = require("../noble_ecc");
|
9
|
+
const parseInput_1 = require("./parseInput");
|
10
|
+
/**
|
11
|
+
* @deprecated - use {@see verifySignaturesWithPublicKeys} instead
|
12
|
+
* Get signature verifications for multsig transaction
|
13
|
+
* @param transaction
|
14
|
+
* @param inputIndex
|
15
|
+
* @param amount - must be set for segwit transactions and BIP143 transactions
|
16
|
+
* @param verificationSettings
|
17
|
+
* @param prevOutputs - must be set for p2tr transactions
|
18
|
+
* @returns SignatureVerification[] - in order of parsed non-empty signatures
|
19
|
+
*/
|
20
|
+
function getSignatureVerifications(transaction, inputIndex, amount, verificationSettings = {}, prevOutputs) {
|
21
|
+
/* istanbul ignore next */
|
22
|
+
if (!transaction.ins) {
|
23
|
+
throw new Error(`invalid transaction`);
|
24
|
+
}
|
25
|
+
const input = transaction.ins[inputIndex];
|
26
|
+
/* istanbul ignore next */
|
27
|
+
if (!input) {
|
28
|
+
throw new Error(`no input at index ${inputIndex}`);
|
29
|
+
}
|
30
|
+
if ((!input.script || input.script.length === 0) && input.witness.length === 0) {
|
31
|
+
// Unsigned input: no signatures.
|
32
|
+
return [];
|
33
|
+
}
|
34
|
+
const parsedScript = parseInput_1.parseSignatureScript2Of3(input);
|
35
|
+
const signatures = parsedScript.signatures
|
36
|
+
.filter((s) => s && s.length)
|
37
|
+
.filter((s, i) => verificationSettings.signatureIndex === undefined || verificationSettings.signatureIndex === i);
|
38
|
+
const publicKeys = parsedScript.publicKeys.filter((buf) => verificationSettings.publicKey === undefined ||
|
39
|
+
verificationSettings.publicKey.equals(buf) ||
|
40
|
+
verificationSettings.publicKey.slice(1).equals(buf));
|
41
|
+
return signatures.map((signatureBuffer) => {
|
42
|
+
if (signatureBuffer === 0 || signatureBuffer.length === 0) {
|
43
|
+
return { signedBy: undefined, signature: undefined };
|
44
|
+
}
|
45
|
+
let hashType = bitcoinjs_lib_1.Transaction.SIGHASH_DEFAULT;
|
46
|
+
if (signatureBuffer.length === 65) {
|
47
|
+
hashType = signatureBuffer[signatureBuffer.length - 1];
|
48
|
+
signatureBuffer = signatureBuffer.slice(0, -1);
|
49
|
+
}
|
50
|
+
if (parsedScript.scriptType === 'p2tr') {
|
51
|
+
if (verificationSettings.signatureIndex !== undefined) {
|
52
|
+
throw new Error(`signatureIndex parameter not supported for p2tr`);
|
53
|
+
}
|
54
|
+
if (!prevOutputs) {
|
55
|
+
throw new Error(`prevOutputs not set`);
|
56
|
+
}
|
57
|
+
if (prevOutputs.length !== transaction.ins.length) {
|
58
|
+
throw new Error(`prevOutputs length ${prevOutputs.length}, expected ${transaction.ins.length}`);
|
59
|
+
}
|
60
|
+
if (!('controlBlock' in parsedScript)) {
|
61
|
+
throw new Error('expected controlBlock');
|
62
|
+
}
|
63
|
+
const { controlBlock, pubScript } = parsedScript;
|
64
|
+
const leafHash = bitcoinjs_lib_1.taproot.getTapleafHash(noble_ecc_1.ecc, controlBlock, pubScript);
|
65
|
+
const signatureHash = transaction.hashForWitnessV1(inputIndex, prevOutputs.map(({ script }) => script), prevOutputs.map(({ value }) => value), hashType, leafHash);
|
66
|
+
const signedBy = publicKeys.filter((k) => Buffer.isBuffer(signatureBuffer) && noble_ecc_1.ecc.verifySchnorr(signatureHash, k, signatureBuffer));
|
67
|
+
if (signedBy.length === 0) {
|
68
|
+
return { signedBy: undefined, signature: undefined };
|
69
|
+
}
|
70
|
+
if (signedBy.length === 1) {
|
71
|
+
return { signedBy: signedBy[0], signature: signatureBuffer };
|
72
|
+
}
|
73
|
+
throw new Error(`illegal state: signed by multiple public keys`);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
// slice the last byte from the signature hash input because it's the hash type
|
77
|
+
const { signature, hashType } = bitcoinjs_lib_1.ScriptSignature.decode(signatureBuffer);
|
78
|
+
const transactionHash = parsedScript.scriptType === 'p2shP2wsh' || parsedScript.scriptType === 'p2wsh'
|
79
|
+
? transaction.hashForWitnessV0(inputIndex, parsedScript.pubScript, amount, hashType)
|
80
|
+
: transaction.hashForSignatureByNetwork(inputIndex, parsedScript.pubScript, amount, hashType);
|
81
|
+
const signedBy = publicKeys.filter((publicKey) => noble_ecc_1.ecc.verify(transactionHash, publicKey, signature,
|
82
|
+
/*
|
83
|
+
Strict verification (require lower-S value), as required by BIP-0146
|
84
|
+
https://github.com/bitcoin/bips/blob/master/bip-0146.mediawiki
|
85
|
+
https://github.com/bitcoin-core/secp256k1/blob/ac83be33/include/secp256k1.h#L478-L508
|
86
|
+
https://github.com/bitcoinjs/tiny-secp256k1/blob/v1.1.6/js.js#L231-L233
|
87
|
+
*/
|
88
|
+
true));
|
89
|
+
if (signedBy.length === 0) {
|
90
|
+
return { signedBy: undefined, signature: undefined };
|
91
|
+
}
|
92
|
+
if (signedBy.length === 1) {
|
93
|
+
return { signedBy: signedBy[0], signature: signatureBuffer };
|
94
|
+
}
|
95
|
+
throw new Error(`illegal state: signed by multiple public keys`);
|
96
|
+
}
|
97
|
+
});
|
98
|
+
}
|
99
|
+
exports.getSignatureVerifications = getSignatureVerifications;
|
100
|
+
/**
|
101
|
+
* @deprecated use {@see verifySignatureWithPublicKeys} instead
|
102
|
+
* @param transaction
|
103
|
+
* @param inputIndex
|
104
|
+
* @param amount
|
105
|
+
* @param verificationSettings - if publicKey is specified, returns true iff any signature is signed by publicKey.
|
106
|
+
* @param prevOutputs - must be set for p2tr transactions
|
107
|
+
*/
|
108
|
+
function verifySignature(transaction, inputIndex, amount, verificationSettings = {}, prevOutputs) {
|
109
|
+
const signatureVerifications = getSignatureVerifications(transaction, inputIndex, amount, verificationSettings, prevOutputs).filter((v) =>
|
110
|
+
// If no publicKey is set in verificationSettings, all signatures must be valid.
|
111
|
+
// Otherwise, a single valid signature by the specified pubkey is sufficient.
|
112
|
+
verificationSettings.publicKey === undefined ||
|
113
|
+
(v.signedBy !== undefined &&
|
114
|
+
(verificationSettings.publicKey.equals(v.signedBy) ||
|
115
|
+
verificationSettings.publicKey.slice(1).equals(v.signedBy))));
|
116
|
+
return signatureVerifications.length > 0 && signatureVerifications.every((v) => v.signedBy !== undefined);
|
117
|
+
}
|
118
|
+
exports.verifySignature = verifySignature;
|
119
|
+
/**
|
120
|
+
* @param v
|
121
|
+
* @param publicKey
|
122
|
+
* @return true iff signature is by publicKey (or xonly variant of publicKey)
|
123
|
+
*/
|
124
|
+
function isSignatureByPublicKey(v, publicKey) {
|
125
|
+
return (!!v.signedBy &&
|
126
|
+
(v.signedBy.equals(publicKey) ||
|
127
|
+
/* for p2tr signatures, we pass the pubkey in 33-byte format recover it from the signature in 32-byte format */
|
128
|
+
(publicKey.length === 33 && isSignatureByPublicKey(v, publicKey.slice(1)))));
|
129
|
+
}
|
130
|
+
/**
|
131
|
+
* @param transaction
|
132
|
+
* @param inputIndex
|
133
|
+
* @param prevOutputs
|
134
|
+
* @param publicKeys
|
135
|
+
* @return array with signature corresponding to n-th key, undefined if no match found
|
136
|
+
*/
|
137
|
+
function getSignaturesWithPublicKeys(transaction, inputIndex, prevOutputs, publicKeys) {
|
138
|
+
if (transaction.ins.length !== prevOutputs.length) {
|
139
|
+
throw new Error(`input length must match prevOutputs length`);
|
140
|
+
}
|
141
|
+
const signatureVerifications = getSignatureVerifications(transaction, inputIndex, prevOutputs[inputIndex].value, {}, prevOutputs);
|
142
|
+
return publicKeys.map((publicKey) => {
|
143
|
+
const v = signatureVerifications.find((v) => isSignatureByPublicKey(v, publicKey));
|
144
|
+
return v ? v.signature : undefined;
|
145
|
+
});
|
146
|
+
}
|
147
|
+
exports.getSignaturesWithPublicKeys = getSignaturesWithPublicKeys;
|
148
|
+
/**
|
149
|
+
* @param transaction
|
150
|
+
* @param inputIndex
|
151
|
+
* @param prevOutputs - transaction outputs for inputs
|
152
|
+
* @param publicKeys - public keys to check signatures for
|
153
|
+
* @return array of booleans indicating a valid signature for every pubkey in _publicKeys_
|
154
|
+
*/
|
155
|
+
function verifySignatureWithPublicKeys(transaction, inputIndex, prevOutputs, publicKeys) {
|
156
|
+
return getSignaturesWithPublicKeys(transaction, inputIndex, prevOutputs, publicKeys).map((s) => s !== undefined);
|
157
|
+
}
|
158
|
+
exports.verifySignatureWithPublicKeys = verifySignatureWithPublicKeys;
|
159
|
+
/**
|
160
|
+
* Wrapper for {@see verifySignatureWithPublicKeys} for single pubkey
|
161
|
+
* @param transaction
|
162
|
+
* @param inputIndex
|
163
|
+
* @param prevOutputs
|
164
|
+
* @param publicKey
|
165
|
+
* @return true iff signature is valid
|
166
|
+
*/
|
167
|
+
function verifySignatureWithPublicKey(transaction, inputIndex, prevOutputs, publicKey) {
|
168
|
+
return verifySignatureWithPublicKeys(transaction, inputIndex, prevOutputs, [publicKey])[0];
|
169
|
+
}
|
170
|
+
exports.verifySignatureWithPublicKey = verifySignatureWithPublicKey;
|
171
|
+
function getDefaultSigHash(network, scriptType) {
|
172
|
+
switch (networks_1.getMainnet(network)) {
|
173
|
+
case networks_1.networks.bitcoincash:
|
174
|
+
case networks_1.networks.bitcoinsv:
|
175
|
+
case networks_1.networks.bitcoingold:
|
176
|
+
case networks_1.networks.ecash:
|
177
|
+
return bitcoinjs_lib_1.Transaction.SIGHASH_ALL | UtxoTransaction_1.UtxoTransaction.SIGHASH_FORKID;
|
178
|
+
default:
|
179
|
+
return scriptType === 'p2tr' ? bitcoinjs_lib_1.Transaction.SIGHASH_DEFAULT : bitcoinjs_lib_1.Transaction.SIGHASH_ALL;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
exports.getDefaultSigHash = getDefaultSigHash;
|
183
|
+
function signInputP2shP2pk(txBuilder, vin, keyPair) {
|
184
|
+
const prevOutScriptType = 'p2sh-p2pk';
|
185
|
+
const { redeemScript, witnessScript } = outputScripts_1.createOutputScriptP2shP2pk(keyPair.publicKey);
|
186
|
+
keyPair.network = txBuilder.network;
|
187
|
+
txBuilder.sign({
|
188
|
+
vin,
|
189
|
+
prevOutScriptType,
|
190
|
+
keyPair,
|
191
|
+
hashType: getDefaultSigHash(txBuilder.network),
|
192
|
+
redeemScript,
|
193
|
+
witnessScript,
|
194
|
+
witnessValue: undefined,
|
195
|
+
});
|
196
|
+
}
|
197
|
+
exports.signInputP2shP2pk = signInputP2shP2pk;
|
198
|
+
function signInput2Of3(txBuilder, vin, scriptType, pubkeys, keyPair, cosigner, amount) {
|
199
|
+
let controlBlock;
|
200
|
+
let redeemScript;
|
201
|
+
let witnessScript;
|
202
|
+
const prevOutScriptType = outputScripts_1.scriptType2Of3AsPrevOutType(scriptType);
|
203
|
+
if (scriptType === 'p2tr') {
|
204
|
+
({ witnessScript, controlBlock } = outputScripts_1.createSpendScriptP2tr(pubkeys, [keyPair.publicKey, cosigner]));
|
205
|
+
}
|
206
|
+
else {
|
207
|
+
({ redeemScript, witnessScript } = outputScripts_1.createOutputScript2of3(pubkeys, scriptType));
|
208
|
+
}
|
209
|
+
keyPair.network = txBuilder.network;
|
210
|
+
txBuilder.sign({
|
211
|
+
vin,
|
212
|
+
prevOutScriptType,
|
213
|
+
keyPair,
|
214
|
+
hashType: getDefaultSigHash(txBuilder.network, scriptType),
|
215
|
+
redeemScript,
|
216
|
+
witnessScript,
|
217
|
+
witnessValue: amount,
|
218
|
+
controlBlock,
|
219
|
+
});
|
220
|
+
}
|
221
|
+
exports.signInput2Of3 = signInput2Of3;
|
222
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2lnbmF0dXJlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2JpdGdvL3NpZ25hdHVyZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSxpREFBZ0Y7QUFFaEYsdURBQW9EO0FBRXBELG1EQU15QjtBQUV6QiwwQ0FBNEQ7QUFDNUQsNENBQTZDO0FBQzdDLDZDQUF3RDtBQThCeEQ7Ozs7Ozs7OztHQVNHO0FBQ0gsU0FBZ0IseUJBQXlCLENBQ3ZDLFdBQXFDLEVBQ3JDLFVBQWtCLEVBQ2xCLE1BQWUsRUFDZix1QkFBNkMsRUFBRSxFQUMvQyxXQUFpQztJQUVqQywwQkFBMEI7SUFDMUIsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHL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ICAoeyByZWRlZW1TY3JpcHQsIHdpdG5lc3NTY3JpcHQgfSA9IGNyZWF0ZU91dHB1dFNjcmlwdDJvZjMocHVia2V5cywgc2NyaXB0VHlwZSkpO1xuICB9XG5cbiAga2V5UGFpci5uZXR3b3JrID0gdHhCdWlsZGVyLm5ldHdvcms7XG5cbiAgdHhCdWlsZGVyLnNpZ24oe1xuICAgIHZpbixcbiAgICBwcmV2T3V0U2NyaXB0VHlwZSxcbiAgICBrZXlQYWlyLFxuICAgIGhhc2hUeXBlOiBnZXREZWZhdWx0U2lnSGFzaCh0eEJ1aWxkZXIubmV0d29yayBhcyBOZXR3b3JrLCBzY3JpcHRUeXBlKSxcbiAgICByZWRlZW1TY3JpcHQsXG4gICAgd2l0bmVzc1NjcmlwdCxcbiAgICB3aXRuZXNzVmFsdWU6IGFtb3VudCxcbiAgICBjb250cm9sQmxvY2ssXG4gIH0pO1xufVxuIl19
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Convert input to bigint or number.
|
3
|
+
* Throws error if input cannot be converted to a safe integer number.
|
4
|
+
* @param value - input value
|
5
|
+
* @param amountType - desired output type
|
6
|
+
* @return value converted to amountType
|
7
|
+
*/
|
8
|
+
export declare function toTNumber<TNumber extends number | bigint>(value: number | bigint | string, amountType: 'number' | 'bigint'): TNumber;
|
9
|
+
//# sourceMappingURL=tnumber.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tnumber.d.ts","sourceRoot":"","sources":["../../../src/bitgo/tnumber.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EACvD,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAC/B,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAC9B,OAAO,CAkBT"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.toTNumber = void 0;
|
4
|
+
/**
|
5
|
+
* Convert input to bigint or number.
|
6
|
+
* Throws error if input cannot be converted to a safe integer number.
|
7
|
+
* @param value - input value
|
8
|
+
* @param amountType - desired output type
|
9
|
+
* @return value converted to amountType
|
10
|
+
*/
|
11
|
+
function toTNumber(value, amountType) {
|
12
|
+
if (typeof value === amountType) {
|
13
|
+
return value;
|
14
|
+
}
|
15
|
+
if (value === undefined) {
|
16
|
+
throw new Error('input value cannot be undefined');
|
17
|
+
}
|
18
|
+
if (amountType === 'number') {
|
19
|
+
const numberValue = Number(value);
|
20
|
+
if (!Number.isSafeInteger(numberValue)) {
|
21
|
+
throw new Error('input value cannot be converted to safe integer number');
|
22
|
+
}
|
23
|
+
return Number(value);
|
24
|
+
}
|
25
|
+
if (amountType === 'bigint') {
|
26
|
+
return BigInt(value);
|
27
|
+
}
|
28
|
+
throw new Error('amountType must be either "number" or "bigint"');
|
29
|
+
}
|
30
|
+
exports.toTNumber = toTNumber;
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG51bWJlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9iaXRnby90bnVtYmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7Ozs7R0FNRztBQUNILFNBQWdCLFNBQVMsQ0FDdkIsS0FBK0IsRUFDL0IsVUFBK0I7SUFFL0IsSUFBSSxPQUFPLEtBQUssS0FBSyxVQUFVLEVBQUU7UUFDL0IsT0FBTyxLQUFnQixDQUFDO0tBQ3pCO0lBQ0QsSUFBSSxLQUFLLEtBQUssU0FBUyxFQUFFO1FBQ3ZCLE1BQU0sSUFBSSxLQUFLLENBQUMsaUNBQWlDLENBQUMsQ0FBQztLQUNwRDtJQUNELElBQUksVUFBVSxLQUFLLFFBQVEsRUFBRTtRQUMzQixNQUFNLFdBQVcsR0FBRyx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ge1xuICAgIHRocm93IG5ldyBFcnJvcignaW5wdXQgdmFsdWUgY2Fubm90IGJlIHVuZGVmaW5lZCcpO1xuICB9XG4gIGlmIChhbW91bnRUeXBlID09PSAnbnVtYmVyJykge1xuICAgIGNvbnN0IG51bWJlclZhbHVlID0gTnVtYmVyKHZhbHVlKTtcbiAgICBpZiAoIU51bWJlci5pc1NhZmVJbnRlZ2VyKG51bWJlclZhbHVlKSkge1xuICAgICAgdGhyb3cgbmV3IEVycm9yKCdpbnB1dCB2YWx1ZSBjYW5ub3QgYmUgY29udmVydGVkIHRvIHNhZmUgaW50ZWdlciBudW1iZXInKTtcbiAgICB9XG4gICAgcmV0dXJuIE51bWJlcih2YWx1ZSkgYXMgVE51bWJlcjtcbiAgfVxuICBpZiAoYW1vdW50VHlwZSA9PT0gJ2JpZ2ludCcpIHtcbiAgICByZXR1cm4gQmlnSW50KHZhbHVlKSBhcyBUTnVtYmVyO1xuICB9XG4gIHRocm93IG5ldyBFcnJvcignYW1vdW50VHlwZSBtdXN0IGJlIGVpdGhlciBcIm51bWJlclwiIG9yIFwiYmlnaW50XCInKTtcbn1cbiJdfQ==
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { TxOutput } from 'bitcoinjs-lib';
|
3
|
+
import { Network } from '../networks';
|
4
|
+
import { UtxoPsbt, PsbtOpts } from './UtxoPsbt';
|
5
|
+
import { UtxoTransaction } from './UtxoTransaction';
|
6
|
+
import { UtxoTransactionBuilder } from './UtxoTransactionBuilder';
|
7
|
+
export declare function createTransactionFromBuffer<TNumber extends number | bigint = number>(buf: Buffer, network: Network, { version, amountType }?: {
|
8
|
+
version?: number;
|
9
|
+
amountType?: 'number' | 'bigint';
|
10
|
+
}, deprecatedAmountType?: 'number' | 'bigint'): UtxoTransaction<TNumber>;
|
11
|
+
export declare function createPsbtFromBuffer(buf: Buffer, network: Network, bip32PathsAbsolute?: boolean): UtxoPsbt;
|
12
|
+
export declare function createPsbtFromHex(hex: string, network: Network, bip32PathsAbsolute?: boolean): UtxoPsbt;
|
13
|
+
export declare function createPsbtFromTransaction(tx: UtxoTransaction<bigint>, prevOuts: TxOutput<bigint>[]): UtxoPsbt;
|
14
|
+
export declare function createTransactionFromHex<TNumber extends number | bigint = number>(hex: string, network: Network, amountType?: 'number' | 'bigint'): UtxoTransaction<TNumber>;
|
15
|
+
export declare function getDefaultTransactionVersion(network: Network): number;
|
16
|
+
export declare function setTransactionBuilderDefaults<TNumber extends number | bigint>(txb: UtxoTransactionBuilder<TNumber>, network: Network, { version }?: {
|
17
|
+
version?: number;
|
18
|
+
}): void;
|
19
|
+
export declare function setPsbtDefaults(psbt: UtxoPsbt, network: Network, { version }?: {
|
20
|
+
version?: number;
|
21
|
+
}): void;
|
22
|
+
export declare function createPsbtForNetwork(psbtOpts: PsbtOpts, { version }?: {
|
23
|
+
version?: number;
|
24
|
+
}): UtxoPsbt;
|
25
|
+
export declare function createTransactionBuilderForNetwork<TNumber extends number | bigint = number>(network: Network, { version }?: {
|
26
|
+
version?: number;
|
27
|
+
}): UtxoTransactionBuilder<TNumber>;
|
28
|
+
export declare function createTransactionBuilderFromTransaction<TNumber extends number | bigint>(tx: UtxoTransaction<TNumber>, prevOutputs?: TxOutput<TNumber>[]): UtxoTransactionBuilder<TNumber>;
|
29
|
+
//# sourceMappingURL=transaction.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/bitgo/transaction.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAY,OAAO,EAAc,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAYlE,wBAAgB,2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