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 @@
|
|
1
|
+
{"version":3,"file":"nonStandardHalfSigned.d.ts","sourceRoot":"","sources":["../../../src/bitgo/nonStandardHalfSigned.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,OAAO,EAAE,MAAM,KAAK,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CAgD3E"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.padInputScript = void 0;
|
4
|
+
const assert = require("assert");
|
5
|
+
const opcodes = require("bitcoin-ops");
|
6
|
+
const __1 = require("../");
|
7
|
+
/**
|
8
|
+
* @param input - Input of non-standard half-signed transaction created with `tx.build()` instead of `tx.buildIncomplete()`.
|
9
|
+
* @param signatureIndex - Position to map the existing signatures to. Other signatures will be padded with OP_0.
|
10
|
+
*/
|
11
|
+
function padInputScript(input, signatureIndex) {
|
12
|
+
if (![0, 1, 2].includes(signatureIndex)) {
|
13
|
+
/* istanbul ignore next */
|
14
|
+
throw new Error(`invalid signature index: must be one of [0, 1, 2]`);
|
15
|
+
}
|
16
|
+
let decompiledSigScript;
|
17
|
+
if (input.witness && input.witness.length > 0) {
|
18
|
+
decompiledSigScript = input.witness;
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
decompiledSigScript = __1.script.decompile(input.script);
|
22
|
+
}
|
23
|
+
// The shape of a non-standard half-signed input is
|
24
|
+
// OP_0 <signature> <p2ms>
|
25
|
+
if (!decompiledSigScript || decompiledSigScript.length !== 3) {
|
26
|
+
/* istanbul ignore next */
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
const [op0, signatureBuffer, sigScript] = decompiledSigScript;
|
30
|
+
if (op0 !== opcodes.OP_0 && !(Buffer.isBuffer(op0) && op0.length === 0)) {
|
31
|
+
/* istanbul ignore next */
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
if (!Buffer.isBuffer(sigScript)) {
|
35
|
+
/* istanbul ignore next */
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
if (__1.classify.output(sigScript) !== __1.classify.types.P2MS) {
|
39
|
+
/* istanbul ignore next */
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const paddedSigScript = [
|
43
|
+
op0,
|
44
|
+
...[0, 1, 2].map((i) => (i === signatureIndex ? signatureBuffer : Buffer.from([]))),
|
45
|
+
sigScript,
|
46
|
+
];
|
47
|
+
if (input.witness.length) {
|
48
|
+
paddedSigScript.forEach((b) => assert(Buffer.isBuffer(b)));
|
49
|
+
input.witness = paddedSigScript;
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
input.script = __1.script.compile(paddedSigScript);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
exports.padInputScript = padInputScript;
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9uU3RhbmRhcmRIYWxmU2lnbmVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2JpdGdvL25vblN0YW5kYXJkSGFsZlNpZ25lZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxpQ0FBaUM7QUFDakMsdUNBQXVDO0FBQ3ZDLDJCQUEyRDtBQUUzRDs7O0dBR0c7QUFDSCxTQUFnQixjQUFjLENBQUMsS0FBYyxFQUFFLGNBQXNCO0lBQ25FLElBQUksQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsUUFBUSxDQUFDLGNBQWMsQ0FBQyxFQUFFO1FBQ3ZDLDBCQUEw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+
import { Network } from '..';
|
4
|
+
import { Triple, Tuple } from './types';
|
5
|
+
export { scriptTypeForChain } from './wallet/chains';
|
6
|
+
export declare const scriptTypeP2shP2pk = "p2shP2pk";
|
7
|
+
export declare type ScriptTypeP2shP2pk = typeof scriptTypeP2shP2pk;
|
8
|
+
export declare const scriptTypes2Of3: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2trMusig2"];
|
9
|
+
export declare type ScriptType2Of3 = typeof scriptTypes2Of3[number];
|
10
|
+
export declare function isScriptType2Of3(t: string): t is ScriptType2Of3;
|
11
|
+
export declare type ScriptType = ScriptTypeP2shP2pk | ScriptType2Of3;
|
12
|
+
/**
|
13
|
+
* @return true iff scriptType requires witness data
|
14
|
+
*/
|
15
|
+
export declare function hasWitnessData(scriptType: ScriptType): scriptType is 'p2shP2wsh' | 'p2wsh' | 'p2tr' | 'p2trMusig2';
|
16
|
+
/**
|
17
|
+
* @param network
|
18
|
+
* @param scriptType
|
19
|
+
* @return true iff script type is supported for network
|
20
|
+
*/
|
21
|
+
export declare function isSupportedScriptType(network: Network, scriptType: ScriptType): boolean;
|
22
|
+
/**
|
23
|
+
* @param t
|
24
|
+
* @return string prevOut as defined in PREVOUT_TYPES (bitcoinjs-lib/.../transaction_builder.js)
|
25
|
+
*/
|
26
|
+
export declare function scriptType2Of3AsPrevOutType(t: ScriptType2Of3): string;
|
27
|
+
export declare type SpendableScript = {
|
28
|
+
scriptPubKey: Buffer;
|
29
|
+
redeemScript?: Buffer;
|
30
|
+
witnessScript?: Buffer;
|
31
|
+
};
|
32
|
+
export declare type SpendScriptP2tr = {
|
33
|
+
controlBlock: Buffer;
|
34
|
+
witnessScript: Buffer;
|
35
|
+
leafVersion: number;
|
36
|
+
leafHash: Buffer;
|
37
|
+
};
|
38
|
+
/**
|
39
|
+
* Tweak data holder for P2tr Musig2 key path.
|
40
|
+
*/
|
41
|
+
export declare type KeyPathP2trMusig2 = {
|
42
|
+
internalPubkey: Buffer;
|
43
|
+
outputPubkey: Buffer;
|
44
|
+
taptreeRoot: Buffer;
|
45
|
+
};
|
46
|
+
/**
|
47
|
+
* Return scripts for p2sh-p2pk (used for BCH/BSV replay protection)
|
48
|
+
* @param pubkey
|
49
|
+
*/
|
50
|
+
export declare function createOutputScriptP2shP2pk(pubkey: Buffer): SpendableScript;
|
51
|
+
/**
|
52
|
+
* Return scripts for 2-of-3 multisig output
|
53
|
+
* @param pubkeys - the key triple for multisig
|
54
|
+
* @param scriptType
|
55
|
+
* @param network - if set, performs sanity check for scriptType support
|
56
|
+
* @returns {{redeemScript, witnessScript, scriptPubKey}}
|
57
|
+
*/
|
58
|
+
export declare function createOutputScript2of3(pubkeys: Buffer[], scriptType: ScriptType2Of3, network?: Network): SpendableScript;
|
59
|
+
export declare function toXOnlyPublicKey(b: Buffer): Buffer;
|
60
|
+
/**
|
61
|
+
* Validates size of the pub key for 32 bytes and returns the same iff true.
|
62
|
+
*/
|
63
|
+
export declare function checkXOnlyPublicKey(b: Buffer): Buffer;
|
64
|
+
/**
|
65
|
+
* Validates size of the pub key for 32 bytes and returns the same iff true.
|
66
|
+
*/
|
67
|
+
export declare function checkPlainPublicKey(b: Buffer): Buffer;
|
68
|
+
export declare function createPaymentP2tr(pubkeys: Triple<Buffer>, redeemIndex?: number | {
|
69
|
+
signer: Buffer;
|
70
|
+
cosigner: Buffer;
|
71
|
+
}): bitcoinjs.Payment;
|
72
|
+
export declare function createPaymentP2trMusig2(pubkeys: Triple<Buffer>, redeemIndex?: number | {
|
73
|
+
signer: Buffer;
|
74
|
+
cosigner: Buffer;
|
75
|
+
}): bitcoinjs.Payment;
|
76
|
+
export declare function getLeafHash(params: bitcoinjs.Payment | {
|
77
|
+
publicKeys: Triple<Buffer>;
|
78
|
+
signer: Buffer;
|
79
|
+
cosigner: Buffer;
|
80
|
+
}): Buffer;
|
81
|
+
export declare function createKeyPathP2trMusig2(pubkeys: Triple<Buffer>): KeyPathP2trMusig2;
|
82
|
+
export declare function createSpendScriptP2tr(pubkeys: Triple<Buffer>, keyCombination: Tuple<Buffer>): SpendScriptP2tr;
|
83
|
+
export declare function createSpendScriptP2trMusig2(pubkeys: Triple<Buffer>, keyCombination: Tuple<Buffer>): SpendScriptP2tr;
|
84
|
+
//# sourceMappingURL=outputScripts.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"outputScripts.d.ts","sourceRoot":"","sources":["../../../src/bitgo/outputScripts.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,SAAS,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,OAAO,EAA0D,MAAM,IAAI,CAAC;AAErF,OAAO,EAAY,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,oBAAY,kBAAkB,GAAG,OAAO,kBAAkB,CAAC;AAE3D,eAAO,MAAM,eAAe,+DAAgE,CAAC;AAC7F,oBAAY,cAAc,GAAG,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5D,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,cAAc,CAE/D;AAED,oBAAY,UAAU,GAAG,kBAAkB,GAAG,cAAc,CAAC;AAE7D;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,CAElH;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAevF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAgBrE;AAED,oBAAY,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,E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O,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC3F,MAAM,CAER;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,iBAAiB,CASlF;AAqCD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,eAAe,CAE7G;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,eAAe,CAEnH"}
|
@@ -0,0 +1,297 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createSpendScriptP2trMusig2 = exports.createSpendScriptP2tr = exports.createKeyPathP2trMusig2 = exports.getLeafHash = exports.createPaymentP2trMusig2 = exports.createPaymentP2tr = exports.checkPlainPublicKey = exports.checkXOnlyPublicKey = exports.toXOnlyPublicKey = exports.createOutputScript2of3 = exports.createOutputScriptP2shP2pk = exports.scriptType2Of3AsPrevOutType = exports.isSupportedScriptType = exports.hasWitnessData = exports.isScriptType2Of3 = exports.scriptTypes2Of3 = exports.scriptTypeP2shP2pk = exports.scriptTypeForChain = void 0;
|
4
|
+
const assert = require("assert");
|
5
|
+
const bitcoinjs = require("bitcoinjs-lib");
|
6
|
+
const __1 = require("..");
|
7
|
+
const types_1 = require("./types");
|
8
|
+
const noble_ecc_1 = require("../noble_ecc");
|
9
|
+
const taproot_1 = require("../taproot");
|
10
|
+
var chains_1 = require("./wallet/chains");
|
11
|
+
Object.defineProperty(exports, "scriptTypeForChain", { enumerable: true, get: function () { return chains_1.scriptTypeForChain; } });
|
12
|
+
exports.scriptTypeP2shP2pk = 'p2shP2pk';
|
13
|
+
exports.scriptTypes2Of3 = ['p2sh', 'p2shP2wsh', 'p2wsh', 'p2tr', 'p2trMusig2'];
|
14
|
+
function isScriptType2Of3(t) {
|
15
|
+
return exports.scriptTypes2Of3.includes(t);
|
16
|
+
}
|
17
|
+
exports.isScriptType2Of3 = isScriptType2Of3;
|
18
|
+
/**
|
19
|
+
* @return true iff scriptType requires witness data
|
20
|
+
*/
|
21
|
+
function hasWitnessData(scriptType) {
|
22
|
+
return ['p2shP2wsh', 'p2wsh', 'p2tr', 'p2trMusig2'].includes(scriptType);
|
23
|
+
}
|
24
|
+
exports.hasWitnessData = hasWitnessData;
|
25
|
+
/**
|
26
|
+
* @param network
|
27
|
+
* @param scriptType
|
28
|
+
* @return true iff script type is supported for network
|
29
|
+
*/
|
30
|
+
function isSupportedScriptType(network, scriptType) {
|
31
|
+
switch (scriptType) {
|
32
|
+
case 'p2sh':
|
33
|
+
case 'p2shP2pk':
|
34
|
+
return true;
|
35
|
+
case 'p2shP2wsh':
|
36
|
+
case 'p2wsh':
|
37
|
+
return __1.supportsSegwit(network);
|
38
|
+
case 'p2tr':
|
39
|
+
case 'p2trMusig2':
|
40
|
+
return __1.supportsTaproot(network);
|
41
|
+
}
|
42
|
+
/* istanbul ignore next */
|
43
|
+
throw new Error(`unexpected script type ${scriptType}`);
|
44
|
+
}
|
45
|
+
exports.isSupportedScriptType = isSupportedScriptType;
|
46
|
+
/**
|
47
|
+
* @param t
|
48
|
+
* @return string prevOut as defined in PREVOUT_TYPES (bitcoinjs-lib/.../transaction_builder.js)
|
49
|
+
*/
|
50
|
+
function scriptType2Of3AsPrevOutType(t) {
|
51
|
+
switch (t) {
|
52
|
+
case 'p2sh':
|
53
|
+
return 'p2sh-p2ms';
|
54
|
+
case 'p2shP2wsh':
|
55
|
+
return 'p2sh-p2wsh-p2ms';
|
56
|
+
case 'p2wsh':
|
57
|
+
return 'p2wsh-p2ms';
|
58
|
+
case 'p2tr':
|
59
|
+
return 'p2tr-p2ns';
|
60
|
+
case 'p2trMusig2':
|
61
|
+
return 'p2tr';
|
62
|
+
}
|
63
|
+
/* istanbul ignore next */
|
64
|
+
throw new Error(`unsupported script type ${t}`);
|
65
|
+
}
|
66
|
+
exports.scriptType2Of3AsPrevOutType = scriptType2Of3AsPrevOutType;
|
67
|
+
/**
|
68
|
+
* Return scripts for p2sh-p2pk (used for BCH/BSV replay protection)
|
69
|
+
* @param pubkey
|
70
|
+
*/
|
71
|
+
function createOutputScriptP2shP2pk(pubkey) {
|
72
|
+
const p2pk = bitcoinjs.payments.p2pk({ pubkey });
|
73
|
+
const p2sh = bitcoinjs.payments.p2sh({ redeem: p2pk });
|
74
|
+
if (!p2sh.output || !p2pk.output) {
|
75
|
+
throw new Error(`invalid state`);
|
76
|
+
}
|
77
|
+
return {
|
78
|
+
scriptPubKey: p2sh.output,
|
79
|
+
redeemScript: p2pk.output,
|
80
|
+
};
|
81
|
+
}
|
82
|
+
exports.createOutputScriptP2shP2pk = createOutputScriptP2shP2pk;
|
83
|
+
/**
|
84
|
+
* Return scripts for 2-of-3 multisig output
|
85
|
+
* @param pubkeys - the key triple for multisig
|
86
|
+
* @param scriptType
|
87
|
+
* @param network - if set, performs sanity check for scriptType support
|
88
|
+
* @returns {{redeemScript, witnessScript, scriptPubKey}}
|
89
|
+
*/
|
90
|
+
function createOutputScript2of3(pubkeys, scriptType, network) {
|
91
|
+
if (network) {
|
92
|
+
if (!isSupportedScriptType(network, scriptType)) {
|
93
|
+
throw new Error(`unsupported script type ${scriptType} for network`);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
if (!types_1.isTriple(pubkeys)) {
|
97
|
+
throw new Error(`must provide pubkey triple`);
|
98
|
+
}
|
99
|
+
pubkeys.forEach((key) => {
|
100
|
+
if (key.length !== 33) {
|
101
|
+
throw new Error(`Unexpected key length ${key.length}. Must use compressed keys.`);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
if (scriptType === 'p2tr' || scriptType === 'p2trMusig2') {
|
105
|
+
// p2tr/p2trMusig2 addresses use a combination of 2 of 2 multisig scripts distinct from
|
106
|
+
// the 2 of 3 multisig used for other script types
|
107
|
+
return createTaprootScript2of3(scriptType, pubkeys);
|
108
|
+
}
|
109
|
+
const script2of3 = bitcoinjs.payments.p2ms({ m: 2, pubkeys });
|
110
|
+
assert(script2of3.output);
|
111
|
+
let scriptPubKey;
|
112
|
+
let redeemScript;
|
113
|
+
let witnessScript;
|
114
|
+
switch (scriptType) {
|
115
|
+
case 'p2sh':
|
116
|
+
redeemScript = script2of3;
|
117
|
+
scriptPubKey = bitcoinjs.payments.p2sh({ redeem: script2of3 });
|
118
|
+
break;
|
119
|
+
case 'p2shP2wsh':
|
120
|
+
witnessScript = script2of3;
|
121
|
+
redeemScript = bitcoinjs.payments.p2wsh({ redeem: script2of3 });
|
122
|
+
scriptPubKey = bitcoinjs.payments.p2sh({ redeem: redeemScript });
|
123
|
+
break;
|
124
|
+
case 'p2wsh':
|
125
|
+
witnessScript = script2of3;
|
126
|
+
scriptPubKey = bitcoinjs.payments.p2wsh({ redeem: witnessScript });
|
127
|
+
break;
|
128
|
+
default:
|
129
|
+
throw new Error(`unknown multisig script type ${scriptType}`);
|
130
|
+
}
|
131
|
+
assert(scriptPubKey);
|
132
|
+
assert(scriptPubKey.output);
|
133
|
+
return {
|
134
|
+
scriptPubKey: scriptPubKey.output,
|
135
|
+
redeemScript: redeemScript === null || redeemScript === void 0 ? void 0 : redeemScript.output,
|
136
|
+
witnessScript: witnessScript === null || witnessScript === void 0 ? void 0 : witnessScript.output,
|
137
|
+
};
|
138
|
+
}
|
139
|
+
exports.createOutputScript2of3 = createOutputScript2of3;
|
140
|
+
function toXOnlyPublicKey(b) {
|
141
|
+
if (b.length === 33) {
|
142
|
+
return b.slice(1);
|
143
|
+
}
|
144
|
+
if (b.length === 32) {
|
145
|
+
return b;
|
146
|
+
}
|
147
|
+
throw new Error(`invalid key size ${b.length}`);
|
148
|
+
}
|
149
|
+
exports.toXOnlyPublicKey = toXOnlyPublicKey;
|
150
|
+
/**
|
151
|
+
* Validates size of the pub key for 32 bytes and returns the same iff true.
|
152
|
+
*/
|
153
|
+
function checkXOnlyPublicKey(b) {
|
154
|
+
if (b.length === 32) {
|
155
|
+
return b;
|
156
|
+
}
|
157
|
+
throw new Error(`invalid key size ${b.length}. Must use x-only key.`);
|
158
|
+
}
|
159
|
+
exports.checkXOnlyPublicKey = checkXOnlyPublicKey;
|
160
|
+
/**
|
161
|
+
* Validates size of the pub key for 32 bytes and returns the same iff true.
|
162
|
+
*/
|
163
|
+
function checkPlainPublicKey(b) {
|
164
|
+
if (b.length === 33) {
|
165
|
+
return b;
|
166
|
+
}
|
167
|
+
throw new Error(`invalid key size ${b.length}. Must use plain keys.`);
|
168
|
+
}
|
169
|
+
exports.checkPlainPublicKey = checkPlainPublicKey;
|
170
|
+
function getTaptreeKeyCombinations(scriptType, keys) {
|
171
|
+
const [userKey, backupKey, bitGoKey] = keys.map((k) => toXOnlyPublicKey(k));
|
172
|
+
return scriptType === 'p2tr'
|
173
|
+
? [
|
174
|
+
[userKey, bitGoKey],
|
175
|
+
[userKey, backupKey],
|
176
|
+
[backupKey, bitGoKey],
|
177
|
+
]
|
178
|
+
: [
|
179
|
+
[userKey, backupKey],
|
180
|
+
[backupKey, bitGoKey],
|
181
|
+
];
|
182
|
+
}
|
183
|
+
function getKeyPathCombination(scriptType, keys) {
|
184
|
+
const sanitizePublicKey = scriptType === 'p2tr' ? toXOnlyPublicKey : checkPlainPublicKey;
|
185
|
+
return [sanitizePublicKey(keys[0]), sanitizePublicKey(keys[2])];
|
186
|
+
}
|
187
|
+
function getRedeemIndex(keyCombinations, signer, cosigner) {
|
188
|
+
signer = toXOnlyPublicKey(signer);
|
189
|
+
cosigner = toXOnlyPublicKey(cosigner);
|
190
|
+
const i = keyCombinations.findIndex(([a, b]) => {
|
191
|
+
if (a.length !== signer.length || b.length !== cosigner.length) {
|
192
|
+
throw new Error(`invalid comparison`);
|
193
|
+
}
|
194
|
+
return (a.equals(signer) && b.equals(cosigner)) || (a.equals(cosigner) && b.equals(signer));
|
195
|
+
});
|
196
|
+
if (0 <= i) {
|
197
|
+
return i;
|
198
|
+
}
|
199
|
+
throw new Error(`could not find singer/cosigner combination`);
|
200
|
+
}
|
201
|
+
function createPaymentP2trCommon(scriptType, pubkeys, redeemIndex) {
|
202
|
+
const keyCombinations2of2 = getTaptreeKeyCombinations(scriptType, pubkeys);
|
203
|
+
if (typeof redeemIndex === 'object') {
|
204
|
+
redeemIndex = getRedeemIndex(keyCombinations2of2, redeemIndex.signer, redeemIndex.cosigner);
|
205
|
+
}
|
206
|
+
const redeems = keyCombinations2of2.map((pubkeys, index) => __1.p2trPayments.p2tr_ns({
|
207
|
+
pubkeys,
|
208
|
+
depth: scriptType === 'p2trMusig2' || index === 0 ? 1 : 2,
|
209
|
+
}, { eccLib: noble_ecc_1.ecc }));
|
210
|
+
return __1.p2trPayments.p2tr({
|
211
|
+
pubkeys: getKeyPathCombination(scriptType, pubkeys),
|
212
|
+
redeems,
|
213
|
+
redeemIndex,
|
214
|
+
}, { eccLib: noble_ecc_1.ecc });
|
215
|
+
}
|
216
|
+
function createPaymentP2tr(pubkeys, redeemIndex) {
|
217
|
+
return createPaymentP2trCommon('p2tr', pubkeys, redeemIndex);
|
218
|
+
}
|
219
|
+
exports.createPaymentP2tr = createPaymentP2tr;
|
220
|
+
function createPaymentP2trMusig2(pubkeys, redeemIndex) {
|
221
|
+
return createPaymentP2trCommon('p2trMusig2', pubkeys, redeemIndex);
|
222
|
+
}
|
223
|
+
exports.createPaymentP2trMusig2 = createPaymentP2trMusig2;
|
224
|
+
function getLeafHashCommon(scriptType, params) {
|
225
|
+
if ('publicKeys' in params) {
|
226
|
+
params = createPaymentP2trCommon(scriptType, params.publicKeys, params);
|
227
|
+
}
|
228
|
+
const { output, controlBlock, redeem } = params;
|
229
|
+
if (!output || !controlBlock || !redeem || !redeem.output) {
|
230
|
+
throw new Error(`invalid state`);
|
231
|
+
}
|
232
|
+
return __1.taproot.getTapleafHash(noble_ecc_1.ecc, controlBlock, redeem.output);
|
233
|
+
}
|
234
|
+
function getLeafHash(params) {
|
235
|
+
return getLeafHashCommon('p2tr', params);
|
236
|
+
}
|
237
|
+
exports.getLeafHash = getLeafHash;
|
238
|
+
function createKeyPathP2trMusig2(pubkeys) {
|
239
|
+
const payment = createPaymentP2trCommon('p2trMusig2', pubkeys);
|
240
|
+
assert(payment.internalPubkey);
|
241
|
+
assert(payment.tapTree);
|
242
|
+
return {
|
243
|
+
internalPubkey: payment.internalPubkey,
|
244
|
+
outputPubkey: taproot_1.getTweakedOutputKey(payment),
|
245
|
+
taptreeRoot: taproot_1.getDepthFirstTaptree(payment.tapTree).root,
|
246
|
+
};
|
247
|
+
}
|
248
|
+
exports.createKeyPathP2trMusig2 = createKeyPathP2trMusig2;
|
249
|
+
function createSpendScriptP2trCommon(scriptType, pubkeys, keyCombination) {
|
250
|
+
const keyCombinations = getTaptreeKeyCombinations(scriptType, pubkeys);
|
251
|
+
const [a, b] = keyCombination.map((k) => toXOnlyPublicKey(k));
|
252
|
+
const redeemIndex = keyCombinations.findIndex(([c, d]) => (a.equals(c) && b.equals(d)) || (a.equals(d) && b.equals(c)));
|
253
|
+
if (redeemIndex < 0) {
|
254
|
+
throw new Error(`could not find redeemIndex for key combination`);
|
255
|
+
}
|
256
|
+
const payment = createPaymentP2trCommon(scriptType, pubkeys, redeemIndex);
|
257
|
+
const { controlBlock } = payment;
|
258
|
+
assert(Buffer.isBuffer(controlBlock));
|
259
|
+
assert(payment.redeem);
|
260
|
+
const leafScript = payment.redeem.output;
|
261
|
+
assert(Buffer.isBuffer(leafScript));
|
262
|
+
const parsedControlBlock = __1.taproot.parseControlBlock(noble_ecc_1.ecc, controlBlock);
|
263
|
+
const { leafVersion } = parsedControlBlock;
|
264
|
+
const leafHash = __1.taproot.getTapleafHash(noble_ecc_1.ecc, parsedControlBlock, leafScript);
|
265
|
+
return {
|
266
|
+
controlBlock,
|
267
|
+
witnessScript: leafScript,
|
268
|
+
leafVersion,
|
269
|
+
leafHash,
|
270
|
+
};
|
271
|
+
}
|
272
|
+
function createSpendScriptP2tr(pubkeys, keyCombination) {
|
273
|
+
return createSpendScriptP2trCommon('p2tr', pubkeys, keyCombination);
|
274
|
+
}
|
275
|
+
exports.createSpendScriptP2tr = createSpendScriptP2tr;
|
276
|
+
function createSpendScriptP2trMusig2(pubkeys, keyCombination) {
|
277
|
+
return createSpendScriptP2trCommon('p2trMusig2', pubkeys, keyCombination);
|
278
|
+
}
|
279
|
+
exports.createSpendScriptP2trMusig2 = createSpendScriptP2trMusig2;
|
280
|
+
/**
|
281
|
+
* Creates and returns a taproot output script using the user+bitgo keys for the aggregate
|
282
|
+
* public key using MuSig2 and a taptree containing either of the following depends on scriptType.
|
283
|
+
* p2tr type: a user+bitgo 2-of-2 script at the first depth level of the tree and user+backup
|
284
|
+
* and bitgo+backup 2-of-2 scripts one level deeper.
|
285
|
+
* p2trMusig2 type: user+backup and bitgo+backup 2-of-2 scripts at the first depth level of the
|
286
|
+
* tree.
|
287
|
+
* @param pubkeys - a pubkey array containing the user key, backup key, and bitgo key in that order
|
288
|
+
* @returns {{scriptPubKey}}
|
289
|
+
*/
|
290
|
+
function createTaprootScript2of3(scriptType, pubkeys) {
|
291
|
+
const { output } = createPaymentP2trCommon(scriptType, pubkeys);
|
292
|
+
assert(Buffer.isBuffer(output));
|
293
|
+
return {
|
294
|
+
scriptPubKey: output,
|
295
|
+
};
|
296
|
+
}
|
297
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0U2NyaXB0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9iaXRnby9vdXRwdXRTY3JpcHRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGlDQUFpQztBQUNqQywyQ0FBMkM7QUFFM0MsMEJBQXFGO0FBRXJGLG1DQUFr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G9mIHRoZSB0cmVlIGFuZCB1c2VyK2JhY2t1cFxuICogYW5kIGJpdGdvK2JhY2t1cCAyLW9mLTIgc2NyaXB0cyBvbmUgbGV2ZWwgZGVlcGVyLlxuICogcDJ0ck11c2lnMiB0eXBlOiB1c2VyK2JhY2t1cCBhbmQgYml0Z28rYmFja3VwIDItb2YtMiBzY3JpcHRzIGF0IHRoZSBmaXJzdCBkZXB0aCBsZXZlbCBvZiB0aGVcbiAqIHRyZWUuXG4gKiBAcGFyYW0gcHVia2V5cyAtIGEgcHVia2V5IGFycmF5IGNvbnRhaW5pbmcgdGhlIHVzZXIga2V5LCBiYWNrdXAga2V5LCBhbmQgYml0Z28ga2V5IGluIHRoYXQgb3JkZXJcbiAqIEByZXR1cm5zIHt7c2NyaXB0UHViS2V5fX1cbiAqL1xuZnVuY3Rpb24gY3JlYXRlVGFwcm9vdFNjcmlwdDJvZjMoc2NyaXB0VHlwZTogJ3AydHInIHwgJ3AydHJNdXNpZzInLCBwdWJrZXlzOiBUcmlwbGU8QnVmZmVyPik6IFNwZW5kYWJsZVNjcmlwdCB7XG4gIGNvbnN0IHsgb3V0cHV0IH0gPSBjcmVhdGVQYXltZW50UDJ0ckNvbW1vbihzY3JpcHRUeXBlLCBwdWJrZXlzKTtcbiAgYXNzZXJ0KEJ1ZmZlci5pc0J1ZmZlcihvdXRwdXQpKTtcbiAgcmV0dXJuIHtcbiAgICBzY3JpcHRQdWJLZXk6IG91dHB1dCxcbiAgfTtcbn1cbiJdfQ==
|
@@ -0,0 +1,92 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { TxInput } from 'bitcoinjs-lib';
|
3
|
+
import { ScriptType, ScriptType2Of3 } from './outputScripts';
|
4
|
+
export declare function isPlaceholderSignature(v: number | Buffer): boolean;
|
5
|
+
/**
|
6
|
+
* @return true iff P2TR script path's control block matches BitGo's need
|
7
|
+
*/
|
8
|
+
export declare function isValidControlBock(controlBlock: Buffer): boolean;
|
9
|
+
/**
|
10
|
+
* @return script path level for P2TR control block
|
11
|
+
*/
|
12
|
+
export declare function calculateScriptPathLevel(controlBlock: Buffer): number;
|
13
|
+
/**
|
14
|
+
* @return leaf version for P2TR control block.
|
15
|
+
*/
|
16
|
+
export declare function getScriptPathLevel(controlBlock: Buffer): number;
|
17
|
+
interface ParsedScript {
|
18
|
+
scriptType: ScriptType;
|
19
|
+
}
|
20
|
+
export declare type ParsedPubScript = ParsedScript;
|
21
|
+
export declare type ParsedSignatureScript = ParsedScript;
|
22
|
+
export interface ParsedSignatureScriptP2shP2pk extends ParsedSignatureScript {
|
23
|
+
scriptType: 'p2shP2pk';
|
24
|
+
publicKeys: [Buffer];
|
25
|
+
signatures: [Buffer];
|
26
|
+
}
|
27
|
+
export interface ParsedPubScriptTaprootScriptPath extends ParsedPubScript {
|
28
|
+
scriptType: 'p2tr';
|
29
|
+
publicKeys: [Buffer, Buffer];
|
30
|
+
pubScript: Buffer;
|
31
|
+
}
|
32
|
+
export interface ParsedPubScript2Of3 extends ParsedPubScript {
|
33
|
+
scriptType: 'p2sh' | 'p2shP2wsh' | 'p2wsh';
|
34
|
+
publicKeys: [Buffer, Buffer, Buffer];
|
35
|
+
pubScript: Buffer;
|
36
|
+
redeemScript: Buffer | undefined;
|
37
|
+
witnessScript: Buffer | undefined;
|
38
|
+
}
|
39
|
+
export interface ParsedSignatureScript2Of3 extends ParsedSignatureScript {
|
40
|
+
scriptType: 'p2sh' | 'p2shP2wsh' | 'p2wsh';
|
41
|
+
publicKeys: [Buffer, Buffer, Buffer];
|
42
|
+
signatures: [Buffer, Buffer] | [Buffer | 0, Buffer | 0, Buffer | 0];
|
43
|
+
pubScript: Buffer;
|
44
|
+
redeemScript: Buffer | undefined;
|
45
|
+
witnessScript: Buffer | undefined;
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Keypath spends only have a single pubkey and single signature
|
49
|
+
*/
|
50
|
+
export interface ParsedSignatureScriptTaprootKeyPath extends ParsedSignatureScript {
|
51
|
+
scriptType: 'p2tr';
|
52
|
+
publicKeys: [Buffer];
|
53
|
+
signatures: [Buffer];
|
54
|
+
pubScript: Buffer;
|
55
|
+
}
|
56
|
+
/**
|
57
|
+
* Taproot Scriptpath spends are more similar to regular p2ms spends and have two public keys and
|
58
|
+
* two signatures
|
59
|
+
*/
|
60
|
+
export interface ParsedSignatureScriptTaprootScriptPath extends ParsedSignatureScript {
|
61
|
+
scriptType: 'p2tr';
|
62
|
+
publicKeys: [Buffer, Buffer];
|
63
|
+
signatures: [Buffer, Buffer];
|
64
|
+
controlBlock: Buffer;
|
65
|
+
leafVersion: number;
|
66
|
+
/** Indicates the level inside the taptree. */
|
67
|
+
scriptPathLevel: number;
|
68
|
+
pubScript: Buffer;
|
69
|
+
}
|
70
|
+
export declare type ParsedSignatureScriptTaproot = ParsedSignatureScriptTaprootKeyPath | ParsedSignatureScriptTaprootScriptPath;
|
71
|
+
export declare type InputPubScript = Buffer;
|
72
|
+
/**
|
73
|
+
* Parse a transaction's signature script to obtain public keys, signatures, the sig script,
|
74
|
+
* and other properties.
|
75
|
+
*
|
76
|
+
* Only supports script types used in BitGo transactions.
|
77
|
+
*
|
78
|
+
* @param input
|
79
|
+
* @returns ParsedSignatureScript
|
80
|
+
*/
|
81
|
+
export declare function parseSignatureScript(input: TxInput): ParsedSignatureScriptP2shP2pk | ParsedSignatureScript2Of3 | ParsedSignatureScriptTaproot;
|
82
|
+
export declare function parseSignatureScript2Of3(input: TxInput): ParsedSignatureScript2Of3 | ParsedSignatureScriptTaproot;
|
83
|
+
/**
|
84
|
+
* @return pubScript (scriptPubKey/redeemScript/witnessScript) is parsed.
|
85
|
+
* P2SH => scriptType, pubScript (redeemScript), redeemScript, public keys
|
86
|
+
* PW2SH => scriptType, pubScript (witnessScript), witnessScript, public keys.
|
87
|
+
* P2SH-PW2SH => scriptType, pubScript (witnessScript), witnessScript, public keys.
|
88
|
+
* P2TR => scriptType, pubScript, controlBlock, scriptPathLevel, leafVersion, pub keys, signatures.
|
89
|
+
*/
|
90
|
+
export declare function parsePubScript(inputPubScript: InputPubScript, scriptType: ScriptType2Of3): ParsedPubScript2Of3 | ParsedPubScriptTaprootScriptPath;
|
91
|
+
export {};
|
92
|
+
//# sourceMappingURL=parseInput.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseInput.d.ts","sourceRoot":"","sources":["../../../src/bitgo/parseInput.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAqB,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAoB,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG/E,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAKlE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAWrE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED,UAAU,YAAY;IACpB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,oBAAY,eAAe,GAAG,YAAY,CAAC;AAC3C,oBAAY,qBAAqB,GAAG,YAAY,CAAC;AAEjD,MAAM,WAAW,6BAA8B,SAAQ,qBAAqB;IAC1E,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;IACrB,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,MAAM,WAAW,gCAAiC,SAAQ,eAAe;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,UAAU,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC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