utxo-lib 1.0.8 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. package/README.md +19 -16
  2. package/dist/src/address.d.ts.map +1 -1
  3. package/dist/src/address.js +11 -1
  4. package/dist/src/addressFormat.d.ts +1 -1
  5. package/dist/src/addressFormat.d.ts.map +1 -1
  6. package/dist/src/addressFormat.js +1 -1
  7. package/dist/src/base_crypto.d.ts +14 -0
  8. package/dist/src/base_crypto.d.ts.map +1 -0
  9. package/dist/src/base_crypto.js +215 -0
  10. package/dist/src/bitgo/Musig2.d.ts +115 -17
  11. package/dist/src/bitgo/Musig2.d.ts.map +1 -1
  12. package/dist/src/bitgo/Musig2.js +283 -101
  13. package/dist/src/bitgo/PsbtUtil.d.ts +59 -0
  14. package/dist/src/bitgo/PsbtUtil.d.ts.map +1 -0
  15. package/dist/src/bitgo/PsbtUtil.js +91 -0
  16. package/dist/src/bitgo/UtxoPsbt.d.ts +180 -47
  17. package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -1
  18. package/dist/src/bitgo/UtxoPsbt.js +657 -121
  19. package/dist/src/bitgo/UtxoTransaction.js +2 -2
  20. package/dist/src/bitgo/bitcoincash/address.js +2 -2
  21. package/dist/src/bitgo/index.d.ts +11 -0
  22. package/dist/src/bitgo/index.d.ts.map +1 -1
  23. package/dist/src/bitgo/index.js +6 -2
  24. package/dist/src/bitgo/legacysafe/index.d.ts +15 -0
  25. package/dist/src/bitgo/legacysafe/index.d.ts.map +1 -0
  26. package/dist/src/bitgo/legacysafe/index.js +61 -0
  27. package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts +10 -0
  28. package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts.map +1 -0
  29. package/dist/src/bitgo/litecoin/LitecoinPsbt.js +17 -0
  30. package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts +16 -0
  31. package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts.map +1 -0
  32. package/dist/src/bitgo/litecoin/LitecoinTransaction.js +46 -0
  33. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts +10 -0
  34. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts.map +1 -0
  35. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.js +15 -0
  36. package/dist/src/bitgo/litecoin/index.d.ts +4 -0
  37. package/dist/src/bitgo/litecoin/index.d.ts.map +1 -0
  38. package/dist/src/bitgo/litecoin/index.js +16 -0
  39. package/dist/src/bitgo/outputScripts.d.ts +3 -1
  40. package/dist/src/bitgo/outputScripts.d.ts.map +1 -1
  41. package/dist/src/bitgo/outputScripts.js +20 -12
  42. package/dist/src/bitgo/parseInput.d.ts +49 -20
  43. package/dist/src/bitgo/parseInput.d.ts.map +1 -1
  44. package/dist/src/bitgo/parseInput.js +110 -26
  45. package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -1
  46. package/dist/src/bitgo/psbt/fromHalfSigned.js +9 -6
  47. package/dist/src/bitgo/psbt/scriptTypes.js +3 -3
  48. package/dist/src/bitgo/signature.d.ts +3 -3
  49. package/dist/src/bitgo/signature.d.ts.map +1 -1
  50. package/dist/src/bitgo/signature.js +48 -16
  51. package/dist/src/bitgo/transaction.d.ts +18 -3
  52. package/dist/src/bitgo/transaction.d.ts.map +1 -1
  53. package/dist/src/bitgo/transaction.js +28 -15
  54. package/dist/src/bitgo/types.d.ts +2 -0
  55. package/dist/src/bitgo/types.d.ts.map +1 -1
  56. package/dist/src/bitgo/types.js +1 -1
  57. package/dist/src/bitgo/wallet/Psbt.d.ts +104 -12
  58. package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -1
  59. package/dist/src/bitgo/wallet/Psbt.js +285 -70
  60. package/dist/src/bitgo/wallet/Unspent.d.ts +28 -0
  61. package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -1
  62. package/dist/src/bitgo/wallet/Unspent.js +172 -68
  63. package/dist/src/bitgo/wallet/WalletOutput.d.ts +17 -1
  64. package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -1
  65. package/dist/src/bitgo/wallet/WalletOutput.js +64 -23
  66. package/dist/src/bitgo/wallet/chains.d.ts +2 -2
  67. package/dist/src/bitgo/wallet/chains.d.ts.map +1 -1
  68. package/dist/src/bitgo/wallet/chains.js +1 -1
  69. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +0 -1
  70. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -1
  71. package/dist/src/bitgo/zcash/ZcashPsbt.js +7 -16
  72. package/dist/src/bitgo/zcash/ZcashTransaction.js +2 -2
  73. package/dist/src/musig.d.ts +390 -0
  74. package/dist/src/musig.d.ts.map +1 -0
  75. package/dist/src/musig.js +447 -0
  76. package/dist/src/networks.d.ts +1 -2
  77. package/dist/src/networks.d.ts.map +1 -1
  78. package/dist/src/networks.js +22 -29
  79. package/dist/src/noble_ecc.d.ts +1 -1
  80. package/dist/src/noble_ecc.d.ts.map +1 -1
  81. package/dist/src/noble_ecc.js +11 -7
  82. package/dist/src/payments/p2tr.d.ts.map +1 -1
  83. package/dist/src/payments/p2tr.js +21 -19
  84. package/dist/src/payments/p2tr_ns.js +2 -3
  85. package/dist/src/taproot.d.ts +16 -0
  86. package/dist/src/taproot.d.ts.map +1 -1
  87. package/dist/src/taproot.js +45 -4
  88. package/dist/src/testutil/index.d.ts +2 -0
  89. package/dist/src/testutil/index.d.ts.map +1 -1
  90. package/dist/src/testutil/index.js +3 -1
  91. package/dist/src/testutil/keys.d.ts +3 -0
  92. package/dist/src/testutil/keys.d.ts.map +1 -1
  93. package/dist/src/testutil/keys.js +17 -2
  94. package/dist/src/testutil/mock.d.ts +1 -1
  95. package/dist/src/testutil/mock.d.ts.map +1 -1
  96. package/dist/src/testutil/mock.js +12 -4
  97. package/dist/src/testutil/psbt.d.ts +89 -0
  98. package/dist/src/testutil/psbt.d.ts.map +1 -0
  99. package/dist/src/testutil/psbt.js +150 -0
  100. package/dist/src/testutil/transaction.d.ts +70 -0
  101. package/dist/src/testutil/transaction.d.ts.map +1 -0
  102. package/dist/src/testutil/transaction.js +107 -0
  103. package/dist/src/transaction_builder.js +2 -2
  104. package/package.json +6 -7
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyFullySignedSignatures = exports.constructPsbt = exports.signAllPsbtInputs = exports.signPsbtInput = exports.getSigners = exports.toUnspent = exports.outputScriptTypes = exports.inputScriptTypes = void 0;
4
+ const assert = require("assert");
5
+ const outputScripts_1 = require("../bitgo/outputScripts");
6
+ const bitgo_1 = require("../bitgo");
7
+ const mock_1 = require("./mock");
8
+ const address_1 = require("../address");
9
+ /**
10
+ * array of supported input script types.
11
+ * use p2trMusig2 for p2trMusig2 script path.
12
+ * use taprootKeyPathSpend for p2trMusig2 key path.
13
+ */
14
+ exports.inputScriptTypes = [...outputScripts_1.scriptTypes2Of3, 'taprootKeyPathSpend', outputScripts_1.scriptTypeP2shP2pk];
15
+ /**
16
+ * array of supported output script types.
17
+ */
18
+ exports.outputScriptTypes = outputScripts_1.scriptTypes2Of3;
19
+ /**
20
+ * create unspent object from input script type, index, network and root wallet key.
21
+ */
22
+ function toUnspent(input, index, network, rootWalletKeys) {
23
+ if (input.scriptType === 'p2shP2pk') {
24
+ return mock_1.mockReplayProtectionUnspent(network, input.value, { key: rootWalletKeys['user'], vout: index });
25
+ }
26
+ else {
27
+ const chain = bitgo_1.getInternalChainCode(input.scriptType === 'taprootKeyPathSpend' ? 'p2trMusig2' : input.scriptType);
28
+ return mock_1.mockWalletUnspent(network, input.value, {
29
+ chain,
30
+ vout: index,
31
+ keys: rootWalletKeys,
32
+ index,
33
+ });
34
+ }
35
+ }
36
+ exports.toUnspent = toUnspent;
37
+ /**
38
+ * returns signer and cosigner names for InputScriptType.
39
+ * user and undefined as signer and cosigner respectively for p2shP2pk.
40
+ * user and backup as signer and cosigner respectively for p2trMusig2.
41
+ * user and bitgo as signer and cosigner respectively for other input script types.
42
+ */
43
+ function getSigners(inputType) {
44
+ return {
45
+ signerName: 'user',
46
+ cosignerName: inputType === 'p2shP2pk' ? undefined : inputType === 'p2trMusig2' ? 'backup' : 'bitgo',
47
+ };
48
+ }
49
+ exports.getSigners = getSigners;
50
+ /**
51
+ * signs with first or second signature for single input.
52
+ * p2shP2pk is signed only with first sign.
53
+ */
54
+ function signPsbtInput(psbt, input, inputIndex, rootWalletKeys, sign, params) {
55
+ const { signers, deterministic } = params ?? {};
56
+ const { signerName, cosignerName } = signers ? signers : getSigners(input.scriptType);
57
+ if (sign === 'halfsigned') {
58
+ if (input.scriptType === 'p2shP2pk') {
59
+ psbt.signInput(inputIndex, rootWalletKeys[signerName]);
60
+ }
61
+ else {
62
+ psbt.signInputHD(inputIndex, rootWalletKeys[signerName]);
63
+ }
64
+ }
65
+ if (sign === 'fullsigned' && cosignerName && input.scriptType !== 'p2shP2pk') {
66
+ psbt.signInputHD(inputIndex, rootWalletKeys[cosignerName], { deterministic });
67
+ }
68
+ }
69
+ exports.signPsbtInput = signPsbtInput;
70
+ /**
71
+ * signs with first or second signature for all inputs.
72
+ * p2shP2pk is signed only with first sign.
73
+ */
74
+ function signAllPsbtInputs(psbt, inputs, rootWalletKeys, sign, params) {
75
+ const { signers, deterministic } = params ?? {};
76
+ inputs.forEach((input, inputIndex) => {
77
+ signPsbtInput(psbt, input, inputIndex, rootWalletKeys, sign, { signers, deterministic });
78
+ });
79
+ }
80
+ exports.signAllPsbtInputs = signAllPsbtInputs;
81
+ /**
82
+ * construct psbt for given inputs, outputs, network and root wallet keys.
83
+ */
84
+ function constructPsbt(inputs, outputs, network, rootWalletKeys, sign, params) {
85
+ const { signers, deterministic } = params ?? {};
86
+ const totalInputAmount = inputs.reduce((sum, input) => sum + input.value, BigInt(0));
87
+ const outputInputAmount = outputs.reduce((sum, output) => sum + output.value, BigInt(0));
88
+ assert(totalInputAmount >= outputInputAmount, 'total output can not exceed total input');
89
+ assert(!outputs.some((o) => (o.scriptType && o.address) || (!o.scriptType && !o.address)), 'only either output script type or address should be provided');
90
+ const psbt = bitgo_1.createPsbtForNetwork({ network });
91
+ const unspents = inputs.map((input, i) => toUnspent(input, i, network, rootWalletKeys));
92
+ unspents.forEach((u, i) => {
93
+ const { signerName, cosignerName } = signers ? signers : getSigners(inputs[i].scriptType);
94
+ if (bitgo_1.isWalletUnspent(u) && cosignerName) {
95
+ bitgo_1.addWalletUnspentToPsbt(psbt, u, rootWalletKeys, signerName, cosignerName);
96
+ }
97
+ else {
98
+ const { redeemScript } = outputScripts_1.createOutputScriptP2shP2pk(rootWalletKeys[signerName].publicKey);
99
+ assert(redeemScript);
100
+ bitgo_1.addReplayProtectionUnspentToPsbt(psbt, u, redeemScript);
101
+ }
102
+ });
103
+ outputs.forEach((output, i) => {
104
+ if (output.scriptType) {
105
+ bitgo_1.addWalletOutputToPsbt(psbt, rootWalletKeys, output.isInternalAddress ? bitgo_1.getInternalChainCode(output.scriptType) : bitgo_1.getExternalChainCode(output.scriptType), i, output.value);
106
+ }
107
+ else if (output.address) {
108
+ const { address, value } = output;
109
+ psbt.addOutput({ script: address_1.toOutputScript(address, network), value });
110
+ }
111
+ });
112
+ if (sign === 'unsigned') {
113
+ return psbt;
114
+ }
115
+ psbt.setAllInputsMusig2NonceHD(rootWalletKeys['user']);
116
+ psbt.setAllInputsMusig2NonceHD(rootWalletKeys['bitgo'], { deterministic });
117
+ signAllPsbtInputs(psbt, inputs, rootWalletKeys, 'halfsigned', { signers });
118
+ if (sign === 'fullsigned') {
119
+ signAllPsbtInputs(psbt, inputs, rootWalletKeys, sign, { signers, deterministic });
120
+ }
121
+ return psbt;
122
+ }
123
+ exports.constructPsbt = constructPsbt;
124
+ /**
125
+ * Verifies signatures of fully signed tx (with taproot key path support).
126
+ * NOTE: taproot key path tx can only be built and signed with PSBT.
127
+ */
128
+ function verifyFullySignedSignatures(tx, unspents, walletKeys, signer, cosigner) {
129
+ const prevOutputs = unspents.map((u) => bitgo_1.toOutput(u, tx.network));
130
+ return unspents.every((u, index) => {
131
+ if (bitgo_1.parseSignatureScript2Of3(tx.ins[index]).scriptType === 'taprootKeyPathSpend') {
132
+ const result = bitgo_1.getSignatureVerifications(tx, index, u.value, undefined, prevOutputs);
133
+ return result.length === 1 && result[0].signature;
134
+ }
135
+ else {
136
+ const result = bitgo_1.verifySignatureWithUnspent(tx, index, unspents, walletKeys);
137
+ if ((signer === 'user' && cosigner === 'bitgo') || (signer === 'bitgo' && cosigner === 'user')) {
138
+ return result[0] && !result[1] && result[2];
139
+ }
140
+ else if ((signer === 'user' && cosigner === 'backup') || (signer === 'backup' && cosigner === 'user')) {
141
+ return result[0] && result[1] && !result[2];
142
+ }
143
+ else {
144
+ return !result[0] && result[1] && result[2];
145
+ }
146
+ }
147
+ });
148
+ }
149
+ exports.verifyFullySignedSignatures = verifyFullySignedSignatures;
150
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHNidC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90ZXN0dXRpbC9wc2J0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGlDQUFpQztBQUVqQywwREFNZ0M7QUFDaEMsb0NBaUJrQjtBQUVsQixpQ0FBd0U7QUFDeEUsd0NBQTRDO0FBNkI1Qzs7OztHQUlHO0FBQ1UsUUFBQSxnQkFBZ0IsR0FBRyxDQUFDLEdBQUcsK0JBQWUsRUFBRSxxQkFBcUIsRUFBRSxrQ0FBa0IsQ0FBVSxDQUFDO0FBRXpHOztHQUVHO0FBQ1UsUUFBQSxpQkFBaUIsR0FBRywrQkFBZSxDQUFDO0FBRWpEOztHQUVHO0FBQ0gsU0FBZ0IsU0FBUyxDQUN2QixLQUFZLEVBQ1osS0FBYSxFQUNiLE9BQWdCLEVBQ2hCLGNBQThCO0lBRTlCLElBQUksS0FBSyxDQUFDLFVBQVUsS0FBSyxVQUFVLEVBQUU7UUFDbkMsT0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lmxlbmd0aCA9PT0gMSAmJiByZXN1bHRbMF0uc2lnbmF0dXJlO1xuICAgIH0gZWxzZSB7XG4gICAgICBjb25zdCByZXN1bHQgPSB2ZXJpZnlTaWduYXR1cmVXaXRoVW5zcGVudCh0eCwgaW5kZXgsIHVuc3BlbnRzLCB3YWxsZXRLZXlzKTtcbiAgICAgIGlmICgoc2lnbmVyID09PSAndXNlcicgJiYgY29zaWduZXIgPT09ICdiaXRnbycpIHx8IChzaWduZXIgPT09ICdiaXRnbycgJiYgY29zaWduZXIgPT09ICd1c2VyJykpIHtcbiAgICAgICAgcmV0dXJuIHJlc3VsdFswXSAmJiAhcmVzdWx0WzFdICYmIHJlc3VsdFsyXTtcbiAgICAgIH0gZWxzZSBpZiAoKHNpZ25lciA9PT0gJ3VzZXInICYmIGNvc2lnbmVyID09PSAnYmFja3VwJykgfHwgKHNpZ25lciA9PT0gJ2JhY2t1cCcgJiYgY29zaWduZXIgPT09ICd1c2VyJykpIHtcbiAgICAgICAgcmV0dXJuIHJlc3VsdFswXSAmJiByZXN1bHRbMV0gJiYgIXJlc3VsdFsyXTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHJldHVybiAhcmVzdWx0WzBdICYmIHJlc3VsdFsxXSAmJiByZXN1bHRbMl07XG4gICAgICB9XG4gICAgfVxuICB9KTtcbn1cbiJdfQ==
@@ -0,0 +1,70 @@
1
+ import { ScriptType, ScriptType2Of3 } from '../bitgo/outputScripts';
2
+ import { KeyName, RootWalletKeys, Unspent, UtxoTransactionBuilder } from '../bitgo';
3
+ import { Network } from '../networks';
4
+ /**
5
+ * input script type and value.
6
+ */
7
+ export declare type TxnInputScriptType = Exclude<ScriptType, 'p2trMusig2'>;
8
+ export declare type TxnOutputScriptType = ScriptType2Of3;
9
+ /**
10
+ * output script type and value
11
+ */
12
+ export interface TxnInput<TNumber extends number | bigint> {
13
+ scriptType: TxnInputScriptType;
14
+ value: TNumber;
15
+ }
16
+ /**
17
+ * should set either address or scriptType, never both.
18
+ * set isInternalAddress=true for internal output address
19
+ */
20
+ export interface TxnOutput<TNumber extends number | bigint> {
21
+ address?: string;
22
+ scriptType?: TxnOutputScriptType;
23
+ value: TNumber;
24
+ isInternalAddress?: boolean;
25
+ }
26
+ /**
27
+ * array of supported input script types.
28
+ */
29
+ export declare const txnInputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2shP2pk"];
30
+ /**
31
+ * array of supported output script types.
32
+ */
33
+ export declare const txnOutputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2trMusig2"];
34
+ /**
35
+ * create unspent object from input script type, index, network and root wallet key.
36
+ */
37
+ export declare function toTxnUnspent<TNumber extends number | bigint>(input: TxnInput<TNumber>, index: number, network: Network, rootWalletKeys: RootWalletKeys): Unspent<TNumber>;
38
+ /**
39
+ * returns signer and cosigner names for TxnInputScriptType.
40
+ * user and undefined as signer and cosigner respectively for p2shP2pk.
41
+ * user and bitgo as signer and cosigner respectively for other input script types.
42
+ */
43
+ export declare function getTxnSigners(inputType: TxnInputScriptType): {
44
+ signerName: KeyName;
45
+ cosignerName?: KeyName;
46
+ };
47
+ /**
48
+ * signs with first or second signature for single input.
49
+ * p2shP2pk is signed only with first sign.
50
+ */
51
+ export declare function signTxnInput<TNumber extends number | bigint>(txb: UtxoTransactionBuilder<TNumber>, input: TxnInput<TNumber>, inputIndex: number, rootWalletKeys: RootWalletKeys, sign: 'halfsigned' | 'fullsigned', signers?: {
52
+ signerName: KeyName;
53
+ cosignerName?: KeyName;
54
+ }): void;
55
+ /**
56
+ * signs with first or second signature for all inputs.
57
+ * p2shP2pk is signed only with first sign.
58
+ */
59
+ export declare function signAllTxnInputs<TNumber extends number | bigint>(txb: UtxoTransactionBuilder<TNumber>, inputs: TxnInput<TNumber>[], rootWalletKeys: RootWalletKeys, sign: 'halfsigned' | 'fullsigned', signers?: {
60
+ signerName: KeyName;
61
+ cosignerName?: KeyName;
62
+ }): void;
63
+ /**
64
+ * construct transaction for given inputs, outputs, network and root wallet keys.
65
+ */
66
+ export declare function constructTxnBuilder<TNumber extends number | bigint>(inputs: TxnInput<TNumber>[], outputs: TxnOutput<TNumber>[], network: Network, rootWalletKeys: RootWalletKeys, sign: 'unsigned' | 'halfsigned' | 'fullsigned', signers?: {
67
+ signerName: KeyName;
68
+ cosignerName?: KeyName;
69
+ }): UtxoTransactionBuilder<TNumber>;
70
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/testutil/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAuC,MAAM,wBAAwB,CAAC;AACzG,OAAO,EAGL,OAAO,EAEP,cAAc,EACd,OAAO,EACP,sBAAsB,EAOvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;GAEG;AACH,oBAAY,kBAAkB,GAAG,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACnE,oBAAY,mBAAmB,GAAG,cAAc,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACvD,UAAU,EAAE,kBAAkB,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,6DAAsE,CAAC;AAEvG;;GAEG;AACH,eAAO,MAAM,oBAAoB,+DAAkB,CAAC;AAEpD;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,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AC9B,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,YAAY,EAC9C,OAAO,CAAC,EAAE;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,sBAAsB,CAAC,OAAO,CAAC,CA2CjC"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructTxnBuilder = exports.signAllTxnInputs = exports.signTxnInput = exports.getTxnSigners = exports.toTxnUnspent = exports.txnOutputScriptTypes = exports.txnInputScriptTypes = void 0;
4
+ const assert = require("assert");
5
+ const outputScripts_1 = require("../bitgo/outputScripts");
6
+ const bitgo_1 = require("../bitgo");
7
+ const mock_1 = require("./mock");
8
+ /**
9
+ * array of supported input script types.
10
+ */
11
+ exports.txnInputScriptTypes = ['p2sh', 'p2shP2wsh', 'p2wsh', 'p2tr', outputScripts_1.scriptTypeP2shP2pk];
12
+ /**
13
+ * array of supported output script types.
14
+ */
15
+ exports.txnOutputScriptTypes = outputScripts_1.scriptTypes2Of3;
16
+ /**
17
+ * create unspent object from input script type, index, network and root wallet key.
18
+ */
19
+ function toTxnUnspent(input, index, network, rootWalletKeys) {
20
+ if (input.scriptType === 'p2shP2pk') {
21
+ return mock_1.mockReplayProtectionUnspent(network, input.value, { key: rootWalletKeys['user'], vout: index });
22
+ }
23
+ else {
24
+ return mock_1.mockWalletUnspent(network, input.value, {
25
+ chain: bitgo_1.getInternalChainCode(input.scriptType),
26
+ vout: index,
27
+ keys: rootWalletKeys,
28
+ index,
29
+ });
30
+ }
31
+ }
32
+ exports.toTxnUnspent = toTxnUnspent;
33
+ /**
34
+ * returns signer and cosigner names for TxnInputScriptType.
35
+ * user and undefined as signer and cosigner respectively for p2shP2pk.
36
+ * user and bitgo as signer and cosigner respectively for other input script types.
37
+ */
38
+ function getTxnSigners(inputType) {
39
+ return {
40
+ signerName: 'user',
41
+ cosignerName: inputType === 'p2shP2pk' ? undefined : 'bitgo',
42
+ };
43
+ }
44
+ exports.getTxnSigners = getTxnSigners;
45
+ /**
46
+ * signs with first or second signature for single input.
47
+ * p2shP2pk is signed only with first sign.
48
+ */
49
+ function signTxnInput(txb, input, inputIndex, rootWalletKeys, sign, signers) {
50
+ const { signerName, cosignerName } = signers ? signers : getTxnSigners(input.scriptType);
51
+ const unspent = toTxnUnspent(input, inputIndex, txb.network, rootWalletKeys);
52
+ if (sign === 'halfsigned') {
53
+ if (input.scriptType === 'p2shP2pk') {
54
+ bitgo_1.signInputP2shP2pk(txb, inputIndex, rootWalletKeys[signerName]);
55
+ }
56
+ else if (bitgo_1.isWalletUnspent(unspent) && cosignerName) {
57
+ bitgo_1.signInputWithUnspent(txb, inputIndex, unspent, bitgo_1.WalletUnspentSigner.from(rootWalletKeys, rootWalletKeys[signerName], rootWalletKeys[cosignerName]));
58
+ }
59
+ }
60
+ if (bitgo_1.isWalletUnspent(unspent) && sign === 'fullsigned' && cosignerName) {
61
+ bitgo_1.signInputWithUnspent(txb, inputIndex, unspent, bitgo_1.WalletUnspentSigner.from(rootWalletKeys, rootWalletKeys[cosignerName], rootWalletKeys[signerName]));
62
+ }
63
+ }
64
+ exports.signTxnInput = signTxnInput;
65
+ /**
66
+ * signs with first or second signature for all inputs.
67
+ * p2shP2pk is signed only with first sign.
68
+ */
69
+ function signAllTxnInputs(txb, inputs, rootWalletKeys, sign, signers) {
70
+ inputs.forEach((input, index) => {
71
+ signTxnInput(txb, input, index, rootWalletKeys, sign, signers);
72
+ });
73
+ }
74
+ exports.signAllTxnInputs = signAllTxnInputs;
75
+ /**
76
+ * construct transaction for given inputs, outputs, network and root wallet keys.
77
+ */
78
+ function constructTxnBuilder(inputs, outputs, network, rootWalletKeys, sign, signers) {
79
+ const totalInputAmount = inputs.reduce((sum, input) => sum + BigInt(input.value), BigInt(0));
80
+ const outputInputAmount = outputs.reduce((sum, output) => sum + BigInt(output.value), BigInt(0));
81
+ assert(totalInputAmount >= outputInputAmount, 'total output can not exceed total input');
82
+ assert(!outputs.some((o) => (o.scriptType && o.address) || (!o.scriptType && !o.address)), 'only either output script type or address should be provided');
83
+ const txb = bitgo_1.createTransactionBuilderForNetwork(network);
84
+ const unspents = inputs.map((input, i) => toTxnUnspent(input, i, network, rootWalletKeys));
85
+ unspents.forEach((u, i) => {
86
+ bitgo_1.addToTransactionBuilder(txb, u);
87
+ });
88
+ outputs.forEach((output, i) => {
89
+ const address = output.scriptType
90
+ ? bitgo_1.getWalletAddress(rootWalletKeys, output.isInternalAddress ? bitgo_1.getInternalChainCode(output.scriptType) : bitgo_1.getExternalChainCode(output.scriptType), i, network)
91
+ : output.address;
92
+ if (!address) {
93
+ throw new Error('address is missing');
94
+ }
95
+ txb.addOutput(address, output.value);
96
+ });
97
+ if (sign === 'unsigned') {
98
+ return txb;
99
+ }
100
+ signAllTxnInputs(txb, inputs, rootWalletKeys, 'halfsigned', signers);
101
+ if (sign === 'fullsigned') {
102
+ signAllTxnInputs(txb, inputs, rootWalletKeys, sign, signers);
103
+ }
104
+ return txb;
105
+ }
106
+ exports.constructTxnBuilder = constructTxnBuilder;
107
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNhY3Rpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdGVzdHV0aWwvdHJhbnNhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsaUNBQWlDO0FBRWpDLDBEQUF5RztBQUN6RyxvQ0Fja0I7QUFFbEIsaUNBQXdFO0FBMkJ4RTs7R0FFRztBQUNVLFFBQUEsbUJBQW1CLEdBQUcsQ0FBQyxNQUFNLEVBQUUsV0FBVyxFQUFFLE9BQU8sRUFBRSxNQUFNLEVBQUUsa0NBQWtCLENBQVUsQ0FBQztBQUV2Rzs7R0FFRztBQUNVLFFBQUEsb0JBQW9CLEdBQUcsK0JBQWUsQ0FBQztBQUVw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