@ledgerhq/hw-app-btc 6.11.1 → 6.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -48
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +5 -3
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +38 -167
- package/lib/BtcNew.js.map +1 -1
- package/lib/newops/accounttype.d.ts +110 -0
- package/lib/newops/accounttype.d.ts.map +1 -0
- package/lib/newops/accounttype.js +236 -0
- package/lib/newops/accounttype.js.map +1 -0
- package/lib/newops/appClient.js +4 -4
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +14 -9
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkle.js +2 -2
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/psbtExtractor.js +2 -2
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtv2.js +4 -4
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +5 -3
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +41 -170
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts +110 -0
- package/lib-es/newops/accounttype.d.ts.map +1 -0
- package/lib-es/newops/accounttype.js +233 -0
- package/lib-es/newops/accounttype.js.map +1 -0
- package/lib-es/newops/appClient.js +4 -4
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +14 -9
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkle.js +2 -2
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/psbtExtractor.js +2 -2
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtv2.js +4 -4
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/package.json +3 -3
- package/src/Btc.ts +34 -3
- package/src/BtcNew.ts +64 -166
- package/src/newops/accounttype.ts +373 -0
- package/src/newops/appClient.ts +4 -4
- package/src/newops/clientCommands.ts +15 -9
- package/src/newops/merkle.ts +2 -2
- package/src/newops/psbtExtractor.ts +2 -2
- package/src/newops/psbtv2.ts +4 -4
- package/tests/Btc.test.ts +68 -39
- package/tests/newops/BtcNew.test.ts +23 -10
- package/tests/newops/integrationtools.ts +71 -41
- package/tests/newops/merkle.test.ts +1 -1
package/README.md
CHANGED
|
@@ -45,51 +45,58 @@ Ledger Hardware Wallet BTC JavaScript bindings. Also supports many altcoins.
|
|
|
45
45
|
* [Parameters](#parameters-10)
|
|
46
46
|
* [createPaymentTransactionNew](#createpaymenttransactionnew-1)
|
|
47
47
|
* [Parameters](#parameters-11)
|
|
48
|
-
* [outputScriptOf](#outputscriptof)
|
|
49
|
-
* [Parameters](#parameters-12)
|
|
50
|
-
* [getTaprootOutputKey](#gettaprootoutputkey)
|
|
51
|
-
* [Parameters](#parameters-13)
|
|
52
48
|
* [BtcOld](#btcold)
|
|
53
|
-
* [Parameters](#parameters-
|
|
49
|
+
* [Parameters](#parameters-12)
|
|
54
50
|
* [Examples](#examples-7)
|
|
55
51
|
* [getWalletPublicKey](#getwalletpublickey-3)
|
|
56
|
-
* [Parameters](#parameters-
|
|
52
|
+
* [Parameters](#parameters-13)
|
|
57
53
|
* [Examples](#examples-8)
|
|
58
54
|
* [signMessageNew](#signmessagenew-1)
|
|
59
|
-
* [Parameters](#parameters-
|
|
55
|
+
* [Parameters](#parameters-14)
|
|
60
56
|
* [Examples](#examples-9)
|
|
61
57
|
* [createPaymentTransactionNew](#createpaymenttransactionnew-2)
|
|
62
|
-
* [Parameters](#parameters-
|
|
58
|
+
* [Parameters](#parameters-15)
|
|
63
59
|
* [Examples](#examples-10)
|
|
64
60
|
* [signP2SHTransaction](#signp2shtransaction-1)
|
|
65
|
-
* [Parameters](#parameters-
|
|
61
|
+
* [Parameters](#parameters-16)
|
|
66
62
|
* [Examples](#examples-11)
|
|
67
63
|
* [CreateTransactionArg](#createtransactionarg)
|
|
68
64
|
* [Properties](#properties)
|
|
69
65
|
* [AddressFormat](#addressformat)
|
|
66
|
+
* [AccountType](#accounttype)
|
|
67
|
+
* [spendingCondition](#spendingcondition)
|
|
68
|
+
* [Parameters](#parameters-17)
|
|
69
|
+
* [setInput](#setinput)
|
|
70
|
+
* [Parameters](#parameters-18)
|
|
71
|
+
* [setOwnOutput](#setownoutput)
|
|
72
|
+
* [Parameters](#parameters-19)
|
|
73
|
+
* [getDescriptorTemplate](#getdescriptortemplate)
|
|
74
|
+
* [SingleKeyAccount](#singlekeyaccount)
|
|
75
|
+
* [getTaprootOutputKey](#gettaprootoutputkey)
|
|
76
|
+
* [Parameters](#parameters-20)
|
|
70
77
|
* [AppClient](#appclient)
|
|
71
|
-
* [Parameters](#parameters-
|
|
78
|
+
* [Parameters](#parameters-21)
|
|
72
79
|
* [ClientCommandInterpreter](#clientcommandinterpreter)
|
|
73
|
-
* [Parameters](#parameters-
|
|
80
|
+
* [Parameters](#parameters-22)
|
|
74
81
|
* [MerkelizedPsbt](#merkelizedpsbt)
|
|
75
|
-
* [Parameters](#parameters-
|
|
82
|
+
* [Parameters](#parameters-23)
|
|
76
83
|
* [Merkle](#merkle)
|
|
77
|
-
* [Parameters](#parameters-
|
|
84
|
+
* [Parameters](#parameters-24)
|
|
78
85
|
* [MerkleMap](#merklemap)
|
|
79
|
-
* [Parameters](#parameters-
|
|
86
|
+
* [Parameters](#parameters-25)
|
|
80
87
|
* [WalletPolicy](#walletpolicy)
|
|
81
|
-
* [Parameters](#parameters-
|
|
88
|
+
* [Parameters](#parameters-26)
|
|
82
89
|
* [extract](#extract)
|
|
83
|
-
* [Parameters](#parameters-
|
|
90
|
+
* [Parameters](#parameters-27)
|
|
84
91
|
* [finalize](#finalize)
|
|
85
|
-
* [Parameters](#parameters-
|
|
92
|
+
* [Parameters](#parameters-28)
|
|
86
93
|
* [clearFinalizedInput](#clearfinalizedinput)
|
|
87
|
-
* [Parameters](#parameters-
|
|
94
|
+
* [Parameters](#parameters-29)
|
|
88
95
|
* [writePush](#writepush)
|
|
89
|
-
* [Parameters](#parameters-
|
|
96
|
+
* [Parameters](#parameters-30)
|
|
90
97
|
* [PsbtV2](#psbtv2)
|
|
91
98
|
* [serializeTransactionOutputs](#serializetransactionoutputs-1)
|
|
92
|
-
* [Parameters](#parameters-
|
|
99
|
+
* [Parameters](#parameters-31)
|
|
93
100
|
* [Examples](#examples-12)
|
|
94
101
|
* [SignP2SHTransactionArg](#signp2shtransactionarg)
|
|
95
102
|
* [Properties](#properties-1)
|
|
@@ -385,34 +392,6 @@ transaction is returned.
|
|
|
385
392
|
|
|
386
393
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
|
|
387
394
|
|
|
388
|
-
### outputScriptOf
|
|
389
|
-
|
|
390
|
-
Generates a single signature scriptPubKey (output script) from a public key.
|
|
391
|
-
This is done differently depending on account type.
|
|
392
|
-
|
|
393
|
-
If accountType is p2tr, the public key must be a 32 byte x-only taproot
|
|
394
|
-
pubkey, otherwise it's expected to be a 33 byte ecdsa compressed pubkey.
|
|
395
|
-
|
|
396
|
-
#### Parameters
|
|
397
|
-
|
|
398
|
-
* `pubkey` **[Buffer](https://nodejs.org/api/buffer.html)**
|
|
399
|
-
* `accountType` **AccountType**
|
|
400
|
-
|
|
401
|
-
Returns **{script: [Buffer](https://nodejs.org/api/buffer.html), redeemScript: [Buffer](https://nodejs.org/api/buffer.html)?}**
|
|
402
|
-
|
|
403
|
-
### getTaprootOutputKey
|
|
404
|
-
|
|
405
|
-
Calculates a taproot output key from an internal key. This output key will be
|
|
406
|
-
used as witness program in a taproot output. The internal key is tweaked
|
|
407
|
-
according to recommendation in BIP341:
|
|
408
|
-
<https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0>
|
|
409
|
-
|
|
410
|
-
#### Parameters
|
|
411
|
-
|
|
412
|
-
* `internalPubkey` **[Buffer](https://nodejs.org/api/buffer.html)** A 32 byte x-only taproot internal key
|
|
413
|
-
|
|
414
|
-
Returns **[Buffer](https://nodejs.org/api/buffer.html)** The output key
|
|
415
|
-
|
|
416
395
|
### BtcOld
|
|
417
396
|
|
|
418
397
|
Bitcoin API.
|
|
@@ -567,6 +546,85 @@ address format is one of legacy | p2sh | bech32 | cashaddr
|
|
|
567
546
|
|
|
568
547
|
Type: (`"legacy"` | `"p2sh"` | `"bech32"` | `"bech32m"` | `"cashaddr"`)
|
|
569
548
|
|
|
549
|
+
### AccountType
|
|
550
|
+
|
|
551
|
+
Encapsulates differences between account types, for example p2wpkh,
|
|
552
|
+
p2wpkhWrapped, p2tr.
|
|
553
|
+
|
|
554
|
+
#### spendingCondition
|
|
555
|
+
|
|
556
|
+
Generates a scriptPubKey (output script) from a list of public keys. If a
|
|
557
|
+
p2sh redeemScript or a p2wsh witnessScript is needed it will also be set on
|
|
558
|
+
the returned SpendingCondition.
|
|
559
|
+
|
|
560
|
+
The pubkeys are expected to be 33 byte ecdsa compressed pubkeys.
|
|
561
|
+
|
|
562
|
+
##### Parameters
|
|
563
|
+
|
|
564
|
+
* `pubkeys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>**
|
|
565
|
+
|
|
566
|
+
Returns **SpendingCondition**
|
|
567
|
+
|
|
568
|
+
#### setInput
|
|
569
|
+
|
|
570
|
+
Populates the psbt with account type-specific data for an input.
|
|
571
|
+
|
|
572
|
+
##### Parameters
|
|
573
|
+
|
|
574
|
+
* `i` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the input map to populate
|
|
575
|
+
* `inputTx` **([Buffer](https://nodejs.org/api/buffer.html) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** The full transaction containing the spent output. This may
|
|
576
|
+
be omitted for taproot.
|
|
577
|
+
* `spentOutput` **SpentOutput** The amount and spending condition of the spent output
|
|
578
|
+
* `pubkeys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** The 33 byte ecdsa compressed public keys involved in the input
|
|
579
|
+
* `pathElems` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** The paths corresponding to the pubkeys, in same order.
|
|
580
|
+
|
|
581
|
+
Returns **void**
|
|
582
|
+
|
|
583
|
+
#### setOwnOutput
|
|
584
|
+
|
|
585
|
+
Populates the psbt with account type-specific data for an output. This is typically
|
|
586
|
+
done for change outputs and other outputs that goes to the same account as
|
|
587
|
+
being spent from.
|
|
588
|
+
|
|
589
|
+
##### Parameters
|
|
590
|
+
|
|
591
|
+
* `i` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the output map to populate
|
|
592
|
+
* `cond` **SpendingCondition** The spending condition for this output
|
|
593
|
+
* `pubkeys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** The 33 byte ecdsa compressed public keys involved in this output
|
|
594
|
+
* `paths` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** The paths corresponding to the pubkeys, in same order.
|
|
595
|
+
|
|
596
|
+
Returns **void**
|
|
597
|
+
|
|
598
|
+
#### getDescriptorTemplate
|
|
599
|
+
|
|
600
|
+
Returns the descriptor template for this account type. Currently only
|
|
601
|
+
DefaultDescriptorTemplates are allowed, but that might be changed in the
|
|
602
|
+
future. See class WalletPolicy for more information on descriptor
|
|
603
|
+
templates.
|
|
604
|
+
|
|
605
|
+
Returns **DefaultDescriptorTemplate**
|
|
606
|
+
|
|
607
|
+
### SingleKeyAccount
|
|
608
|
+
|
|
609
|
+
**Extends BaseAccount**
|
|
610
|
+
|
|
611
|
+
Superclass for single signature accounts. This will make sure that the pubkey
|
|
612
|
+
arrays and path arrays in the method arguments contains exactly one element
|
|
613
|
+
and calls an abstract method to do the actual work.
|
|
614
|
+
|
|
615
|
+
### getTaprootOutputKey
|
|
616
|
+
|
|
617
|
+
Calculates a taproot output key from an internal key. This output key will be
|
|
618
|
+
used as witness program in a taproot output. The internal key is tweaked
|
|
619
|
+
according to recommendation in BIP341:
|
|
620
|
+
<https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0>
|
|
621
|
+
|
|
622
|
+
#### Parameters
|
|
623
|
+
|
|
624
|
+
* `internalPubkey` **[Buffer](https://nodejs.org/api/buffer.html)** A 32 byte x-only taproot internal key
|
|
625
|
+
|
|
626
|
+
Returns **[Buffer](https://nodejs.org/api/buffer.html)** The output key
|
|
627
|
+
|
|
570
628
|
### AppClient
|
|
571
629
|
|
|
572
630
|
This class encapsulates the APDU protocol documented at
|
package/lib/Btc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Btc.d.ts","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAEpD,OAAO,MAAyB,MAAM,UAAU,CAAC;AACjD,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,KAAK,EAAE,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AAW,GAAG,MAAM;IAInD,eAAe,CACb,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,EACxB,WAAW,GAAE,KAAK,CAAC,MAAM,CAAM,GAC9B,OAAO,CAAC,MAAM,CAAC;IASlB,qBAAqB,CACnB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,EACxB,WAAW,GAAE,KAAK,CAAC,MAAM,CAAM,GAC9B,MAAM;IAUT,OAAO,CAAC,SAAS,CAAgC;YACnC,cAAc;YAQd,gBAAgB;IAU9B,SAAS,CAAC,GAAG,IAAI,MAAM;IAIvB,SAAS,CAAC,GAAG,IAAI,MAAM;CAGxB"}
|
package/lib/Btc.js
CHANGED
|
@@ -164,6 +164,7 @@ var Btc = /** @class */ (function () {
|
|
|
164
164
|
options.format != "bech32m" &&
|
|
165
165
|
(!options.verify || options.verify == false) &&
|
|
166
166
|
!isPathNormal(path)) {
|
|
167
|
+
console.warn("WARNING: Using deprecated device protocol to get the public key because\n \n * a non-standard path is requested, and\n * verify flag is false\n \n The new protocol only allows export of non-standard paths if the \n verify flag is true. Standard paths are (currently):\n\n M/44'/(1|0)'/X'\n M/49'/(1|0)'/X'\n M/84'/(1|0)'/X'\n M/86'/(1|0)'/X'\n M/48'/(1|0)'/X'/Y'\n\n followed by \"\", \"(0|1)\", or \"(0|1)/b\", where a and b are \n non-hardened. For example, the following paths are standard\n \n M/48'/1'/99'/7'\n M/86'/1'/99'/0\n M/48'/0'/99'/7'/1/17\n\n The following paths are non-standard\n\n M/48'/0'/99' // Not deepest hardened path\n M/48'/0'/99'/7'/1/17/2 // Too many non-hardened derivation steps\n M/199'/0'/1'/0/88 // Not a known purpose 199\n M/86'/1'/99'/2 // Change path item must be 0 or 1\n\n This compatibility safeguard will be removed in the future.\n Please consider calling Btc.getWalletXpub() instead.");
|
|
167
168
|
return _this.old().getWalletPublicKey(path, options);
|
|
168
169
|
}
|
|
169
170
|
else {
|
|
@@ -325,14 +326,15 @@ function isPathNormal(path) {
|
|
|
325
326
|
//path is not deepest hardened node of a standard path or deeper, use BtcOld
|
|
326
327
|
var h = 0x80000000;
|
|
327
328
|
var pathElems = (0, bip32_1.pathStringToArray)(path);
|
|
328
|
-
var hard = function (n) { return n
|
|
329
|
+
var hard = function (n) { return n >= h; };
|
|
329
330
|
var soft = function (n) { return !n || n < h; };
|
|
331
|
+
var change = function (n) { return !n || n == 0 || n == 1; };
|
|
330
332
|
if (pathElems.length >= 3 &&
|
|
331
333
|
pathElems.length <= 5 &&
|
|
332
334
|
[44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
|
|
333
335
|
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
334
336
|
hard(pathElems[2]) &&
|
|
335
|
-
|
|
337
|
+
change(pathElems[3]) &&
|
|
336
338
|
soft(pathElems[4])) {
|
|
337
339
|
return true;
|
|
338
340
|
}
|
|
@@ -342,7 +344,7 @@ function isPathNormal(path) {
|
|
|
342
344
|
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
343
345
|
hard(pathElems[2]) &&
|
|
344
346
|
hard(pathElems[3]) &&
|
|
345
|
-
|
|
347
|
+
change(pathElems[4]) &&
|
|
346
348
|
soft(pathElems[5])) {
|
|
347
349
|
return true;
|
|
348
350
|
}
|
package/lib/Btc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAA4C;AAC5C,iDAAiD;AACjD,oDAA8B;AAE9B,uDAAsD;AACtD,qDAAoD;AACpD,iEAAgE;AAEhE,gDAA+C;AAC/C,+DAAqE;AAErE,uDAAsD;AAGtD;;;;;;GAMG;AAEH;IAGE,aAAY,SAAoB,EAAE,WAAmB;QAAnB,4BAAA,EAAA,mBAAmB;
|
|
1
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AC,CAAC,CAAC,EAAjB,CAAiB,CAAC;QAC/D,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IACD,IACE,SAAS,CAAC,MAAM,IAAI,CAAC;QACrB,SAAS,CAAC,MAAM,IAAI,CAAC;QACrB,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC;QACtB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/BtcNew.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAczD,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAKnE;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,aAAa,CAAC,EAClB,IAAI,EACJ,WAAW,GACZ,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnB;;;;;;OAMG;IACG,kBAAkB,CACtB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,aAAa,CAAC;KACxB,GACA,OAAO,CAAC;QACT,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAsBF;;;;;;;;;;;;;;OAcG;YACW,gBAAgB;IAyB9B;;;;;;;OAOG;IACG,2BAA2B,CAC/B,GAAG,EAAE,oBAAoB,GACxB,OAAO,CAAC,MAAM,CAAC;IAiHlB;;;;;;;OAOG;YACW,cAAc;IAsB5B;;;;OAIG;YACW,QAAQ;IAmDtB;;;;;;;;OAQG;YACW,QAAQ;CA6BvB"}
|
package/lib/BtcNew.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -56,8 +45,7 @@ var semver_1 = __importDefault(require("semver"));
|
|
|
56
45
|
var tiny_secp256k1_1 = require("tiny-secp256k1");
|
|
57
46
|
var bip32_1 = require("./bip32");
|
|
58
47
|
var buffertools_1 = require("./buffertools");
|
|
59
|
-
var
|
|
60
|
-
var hashPublicKey_1 = require("./hashPublicKey");
|
|
48
|
+
var accounttype_1 = require("./newops/accounttype");
|
|
61
49
|
var policy_1 = require("./newops/policy");
|
|
62
50
|
var psbtExtractor_1 = require("./newops/psbtExtractor");
|
|
63
51
|
var psbtFinalizer_1 = require("./newops/psbtFinalizer");
|
|
@@ -155,7 +143,7 @@ var BtcNew = /** @class */ (function () {
|
|
|
155
143
|
case 1:
|
|
156
144
|
xpub = _c.sent();
|
|
157
145
|
display = (_a = opts === null || opts === void 0 ? void 0 : opts.verify) !== null && _a !== void 0 ? _a : false;
|
|
158
|
-
return [4 /*yield*/, this.getWalletAddress(pathElements,
|
|
146
|
+
return [4 /*yield*/, this.getWalletAddress(pathElements, descrTemplFrom((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : "legacy"), display)];
|
|
159
147
|
case 2:
|
|
160
148
|
address = _c.sent();
|
|
161
149
|
components = (0, bip32_1.getXpubComponents)(xpub);
|
|
@@ -184,7 +172,7 @@ var BtcNew = /** @class */ (function () {
|
|
|
184
172
|
* way to get the address from the device. In this case we have to create it
|
|
185
173
|
* ourselves, but we don't at this time, and instead return an empty ("") address.
|
|
186
174
|
*/
|
|
187
|
-
BtcNew.prototype.getWalletAddress = function (pathElements,
|
|
175
|
+
BtcNew.prototype.getWalletAddress = function (pathElements, descrTempl, display) {
|
|
188
176
|
return __awaiter(this, void 0, void 0, function () {
|
|
189
177
|
var accountPath, accountXpub, masterFingerprint, policy, changeAndIndex;
|
|
190
178
|
return __generator(this, function (_a) {
|
|
@@ -200,7 +188,7 @@ var BtcNew = /** @class */ (function () {
|
|
|
200
188
|
return [4 /*yield*/, this.client.getMasterFingerprint()];
|
|
201
189
|
case 2:
|
|
202
190
|
masterFingerprint = _a.sent();
|
|
203
|
-
policy = new policy_1.WalletPolicy(
|
|
191
|
+
policy = new policy_1.WalletPolicy(descrTempl, (0, policy_1.createKey)(masterFingerprint, accountPath, accountXpub));
|
|
204
192
|
changeAndIndex = pathElements.slice(-2, pathElements.length);
|
|
205
193
|
return [2 /*return*/, this.client.getWalletAddress(policy, Buffer.alloc(32, 0), changeAndIndex[0], changeAndIndex[1], display)];
|
|
206
194
|
}
|
|
@@ -217,7 +205,7 @@ var BtcNew = /** @class */ (function () {
|
|
|
217
205
|
*/
|
|
218
206
|
BtcNew.prototype.createPaymentTransactionNew = function (arg) {
|
|
219
207
|
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
-
var inputCount, psbt, accountType, notifyCount, progress,
|
|
208
|
+
var inputCount, psbt, masterFp, accountType, notifyCount, progress, accountXpub, accountPath, i, pathElems, outputsConcat, outputsBufferReader, outputCount, changeData, changeFound, i, amount, outputScript, isChange, changePath, pubkey, key, p, firstSigned, progressCallback, serializedTx;
|
|
221
209
|
return __generator(this, function (_a) {
|
|
222
210
|
switch (_a.label) {
|
|
223
211
|
case 0:
|
|
@@ -226,8 +214,11 @@ var BtcNew = /** @class */ (function () {
|
|
|
226
214
|
throw Error("No inputs");
|
|
227
215
|
}
|
|
228
216
|
psbt = new psbtv2_1.PsbtV2();
|
|
229
|
-
|
|
230
|
-
|
|
217
|
+
return [4 /*yield*/, this.client.getMasterFingerprint()];
|
|
218
|
+
case 1:
|
|
219
|
+
masterFp = _a.sent();
|
|
220
|
+
accountType = accountTypeFromArg(arg, psbt, masterFp);
|
|
221
|
+
if (arg.lockTime != undefined) {
|
|
231
222
|
// The signer will assume locktime 0 if unset
|
|
232
223
|
psbt.setGlobalFallbackLocktime(arg.lockTime);
|
|
233
224
|
}
|
|
@@ -244,9 +235,6 @@ var BtcNew = /** @class */ (function () {
|
|
|
244
235
|
progress: ++notifyCount / (2 * inputCount)
|
|
245
236
|
});
|
|
246
237
|
};
|
|
247
|
-
return [4 /*yield*/, this.client.getMasterFingerprint()];
|
|
248
|
-
case 1:
|
|
249
|
-
masterFp = _a.sent();
|
|
250
238
|
accountXpub = "";
|
|
251
239
|
accountPath = [];
|
|
252
240
|
i = 0;
|
|
@@ -284,33 +272,20 @@ var BtcNew = /** @class */ (function () {
|
|
|
284
272
|
outputScript = outputsBufferReader.readVarSlice();
|
|
285
273
|
psbt.setOutputAmount(i, amount);
|
|
286
274
|
psbt.setOutputScript(i, outputScript);
|
|
287
|
-
isChange = changeData && outputScript.equals(changeData === null || changeData === void 0 ? void 0 : changeData.
|
|
275
|
+
isChange = changeData && outputScript.equals(changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey);
|
|
288
276
|
if (isChange) {
|
|
289
277
|
changeFound = true;
|
|
290
278
|
changePath = (0, bip32_1.pathStringToArray)(arg.changePath);
|
|
291
279
|
pubkey = changeData.pubkey;
|
|
292
|
-
|
|
293
|
-
psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
|
|
294
|
-
}
|
|
295
|
-
else if (accountType == AccountType.p2wpkh) {
|
|
296
|
-
psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
|
|
297
|
-
}
|
|
298
|
-
else if (accountType == AccountType.p2wpkhWrapped) {
|
|
299
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
300
|
-
psbt.setOutputRedeemScript(i, changeData.redeemScript);
|
|
301
|
-
psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
|
|
302
|
-
}
|
|
303
|
-
else if (accountType == AccountType.p2tr) {
|
|
304
|
-
psbt.setOutputTapBip32Derivation(i, pubkey, [], masterFp, changePath);
|
|
305
|
-
}
|
|
280
|
+
accountType.setOwnOutput(i, changeData.cond, [pubkey], [changePath]);
|
|
306
281
|
}
|
|
307
282
|
}
|
|
308
283
|
if (!changeFound) {
|
|
309
284
|
throw new Error("Change script not found among outputs! " +
|
|
310
|
-
(changeData === null || changeData === void 0 ? void 0 : changeData.
|
|
285
|
+
(changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey.toString("hex")));
|
|
311
286
|
}
|
|
312
287
|
key = (0, policy_1.createKey)(masterFp, accountPath, accountXpub);
|
|
313
|
-
p = new policy_1.WalletPolicy(accountType, key);
|
|
288
|
+
p = new policy_1.WalletPolicy(accountType.getDescriptorTemplate(), key);
|
|
314
289
|
// This is cheating, because it's not actually requested on the
|
|
315
290
|
// device yet, but it will be, soonish.
|
|
316
291
|
if (arg.onDeviceSignatureRequested)
|
|
@@ -343,7 +318,7 @@ var BtcNew = /** @class */ (function () {
|
|
|
343
318
|
*/
|
|
344
319
|
BtcNew.prototype.outputScriptAt = function (accountPath, accountType, path) {
|
|
345
320
|
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
var pathElems, i, xpub, pubkey,
|
|
321
|
+
var pathElems, i, xpub, pubkey, cond;
|
|
347
322
|
return __generator(this, function (_a) {
|
|
348
323
|
switch (_a.label) {
|
|
349
324
|
case 0:
|
|
@@ -361,11 +336,8 @@ var BtcNew = /** @class */ (function () {
|
|
|
361
336
|
case 1:
|
|
362
337
|
xpub = _a.sent();
|
|
363
338
|
pubkey = (0, bip32_1.pubkeyFromXpub)(xpub);
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
script = outputScriptOf(pubkey, accountType);
|
|
368
|
-
return [2 /*return*/, __assign(__assign({}, script), { pubkey: pubkey })];
|
|
339
|
+
cond = accountType.spendingCondition([pubkey]);
|
|
340
|
+
return [2 /*return*/, { cond: cond, pubkey: pubkey }];
|
|
369
341
|
}
|
|
370
342
|
});
|
|
371
343
|
});
|
|
@@ -377,18 +349,18 @@ var BtcNew = /** @class */ (function () {
|
|
|
377
349
|
*/
|
|
378
350
|
BtcNew.prototype.setInput = function (psbt, i, input, pathElements, accountType, masterFP, sigHashType) {
|
|
379
351
|
return __awaiter(this, void 0, void 0, function () {
|
|
380
|
-
var inputTx, spentOutputIndex, redeemScript, sequence, inputTxBuffer, inputTxid, xpubBase58, pubkey,
|
|
352
|
+
var inputTx, spentOutputIndex, redeemScript, sequence, inputTxBuffer, inputTxid, xpubBase58, pubkey, spentTxOutput, spendCondition, spentOutput;
|
|
381
353
|
return __generator(this, function (_a) {
|
|
382
354
|
switch (_a.label) {
|
|
383
355
|
case 0:
|
|
384
356
|
inputTx = input[0];
|
|
385
357
|
spentOutputIndex = input[1];
|
|
386
|
-
redeemScript = input[2];
|
|
358
|
+
redeemScript = input[2] ? Buffer.from(input[2], "hex") : undefined;
|
|
387
359
|
sequence = input[3];
|
|
388
|
-
if (sequence) {
|
|
360
|
+
if (sequence != undefined) {
|
|
389
361
|
psbt.setInputSequence(i, sequence);
|
|
390
362
|
}
|
|
391
|
-
if (sigHashType) {
|
|
363
|
+
if (sigHashType != undefined) {
|
|
392
364
|
psbt.setInputSighashType(i, sigHashType);
|
|
393
365
|
}
|
|
394
366
|
inputTxBuffer = (0, serializeTransaction_1.serializeTransaction)(inputTx, true);
|
|
@@ -399,33 +371,13 @@ var BtcNew = /** @class */ (function () {
|
|
|
399
371
|
pubkey = (0, bip32_1.pubkeyFromXpub)(xpubBase58);
|
|
400
372
|
if (!inputTx.outputs)
|
|
401
373
|
throw Error("Missing outputs array in transaction to sign");
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
|
|
410
|
-
psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
|
|
411
|
-
}
|
|
412
|
-
else if (accountType == AccountType.p2wpkhWrapped) {
|
|
413
|
-
psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
|
|
414
|
-
psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
|
|
415
|
-
if (redeemScript) {
|
|
416
|
-
// At what point might a user set the redeemScript on its own?
|
|
417
|
-
psbt.setInputRedeemScript(i, Buffer.from(redeemScript, "hex"));
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
psbt.setInputRedeemScript(i, createRedeemScript(pubkey));
|
|
421
|
-
}
|
|
422
|
-
psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
|
|
423
|
-
}
|
|
424
|
-
else if (accountType == AccountType.p2tr) {
|
|
425
|
-
xonly = pubkey.slice(1);
|
|
426
|
-
psbt.setInputTapBip32Derivation(i, xonly, [], masterFP, pathElements);
|
|
427
|
-
psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
|
|
428
|
-
}
|
|
374
|
+
spentTxOutput = inputTx.outputs[spentOutputIndex];
|
|
375
|
+
spendCondition = {
|
|
376
|
+
scriptPubKey: spentTxOutput.script,
|
|
377
|
+
redeemScript: redeemScript
|
|
378
|
+
};
|
|
379
|
+
spentOutput = { cond: spendCondition, amount: spentTxOutput.amount };
|
|
380
|
+
accountType.setInput(i, inputTxBuffer, spentOutput, [pubkey], [pathElements]);
|
|
429
381
|
psbt.setInputPreviousTxId(i, inputTxid);
|
|
430
382
|
psbt.setInputOutputIndex(i, spentOutputIndex);
|
|
431
383
|
return [2 /*return*/];
|
|
@@ -476,105 +428,24 @@ var BtcNew = /** @class */ (function () {
|
|
|
476
428
|
return BtcNew;
|
|
477
429
|
}());
|
|
478
430
|
exports["default"] = BtcNew;
|
|
479
|
-
|
|
480
|
-
(function (AccountType) {
|
|
481
|
-
AccountType["p2pkh"] = "pkh(@0)";
|
|
482
|
-
AccountType["p2wpkh"] = "wpkh(@0)";
|
|
483
|
-
AccountType["p2wpkhWrapped"] = "sh(wpkh(@0))";
|
|
484
|
-
AccountType["p2tr"] = "tr(@0)";
|
|
485
|
-
})(AccountType || (AccountType = {}));
|
|
486
|
-
function createRedeemScript(pubkey) {
|
|
487
|
-
var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
|
|
488
|
-
return Buffer.concat([Buffer.from("0014", "hex"), pubkeyHash]);
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Generates a single signature scriptPubKey (output script) from a public key.
|
|
492
|
-
* This is done differently depending on account type.
|
|
493
|
-
*
|
|
494
|
-
* If accountType is p2tr, the public key must be a 32 byte x-only taproot
|
|
495
|
-
* pubkey, otherwise it's expected to be a 33 byte ecdsa compressed pubkey.
|
|
496
|
-
*/
|
|
497
|
-
function outputScriptOf(pubkey, accountType) {
|
|
498
|
-
var buf = new buffertools_1.BufferWriter();
|
|
499
|
-
var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
|
|
500
|
-
var redeemScript;
|
|
501
|
-
if (accountType == AccountType.p2pkh) {
|
|
502
|
-
buf.writeSlice(Buffer.of(constants_1.OP_DUP, constants_1.OP_HASH160, constants_1.HASH_SIZE));
|
|
503
|
-
buf.writeSlice(pubkeyHash);
|
|
504
|
-
buf.writeSlice(Buffer.of(constants_1.OP_EQUALVERIFY, constants_1.OP_CHECKSIG));
|
|
505
|
-
}
|
|
506
|
-
else if (accountType == AccountType.p2wpkhWrapped) {
|
|
507
|
-
redeemScript = createRedeemScript(pubkey);
|
|
508
|
-
var scriptHash = (0, hashPublicKey_1.hashPublicKey)(redeemScript);
|
|
509
|
-
buf.writeSlice(Buffer.of(constants_1.OP_HASH160, constants_1.HASH_SIZE));
|
|
510
|
-
buf.writeSlice(scriptHash);
|
|
511
|
-
buf.writeUInt8(constants_1.OP_EQUAL);
|
|
512
|
-
}
|
|
513
|
-
else if (accountType == AccountType.p2wpkh) {
|
|
514
|
-
buf.writeSlice(Buffer.of(0, constants_1.HASH_SIZE));
|
|
515
|
-
buf.writeSlice(pubkeyHash);
|
|
516
|
-
}
|
|
517
|
-
else if (accountType == AccountType.p2tr) {
|
|
518
|
-
var outputKey = getTaprootOutputKey(pubkey);
|
|
519
|
-
buf.writeSlice(Buffer.of(0x51, 32)); // push1, pubkeylen
|
|
520
|
-
buf.writeSlice(outputKey);
|
|
521
|
-
}
|
|
522
|
-
return { script: buf.buffer(), redeemScript: redeemScript };
|
|
523
|
-
}
|
|
524
|
-
function accountTypeFrom(addressFormat) {
|
|
431
|
+
function descrTemplFrom(addressFormat) {
|
|
525
432
|
if (addressFormat == "legacy")
|
|
526
|
-
return
|
|
433
|
+
return "pkh(@0)";
|
|
527
434
|
if (addressFormat == "p2sh")
|
|
528
|
-
return
|
|
435
|
+
return "sh(wpkh(@0))";
|
|
529
436
|
if (addressFormat == "bech32")
|
|
530
|
-
return
|
|
437
|
+
return "wpkh(@0)";
|
|
531
438
|
if (addressFormat == "bech32m")
|
|
532
|
-
return
|
|
439
|
+
return "tr(@0)";
|
|
533
440
|
throw new Error("Unsupported address format " + addressFormat);
|
|
534
441
|
}
|
|
535
|
-
function accountTypeFromArg(arg) {
|
|
442
|
+
function accountTypeFromArg(arg, psbt, masterFp) {
|
|
536
443
|
if (arg.additionals.includes("bech32m"))
|
|
537
|
-
return
|
|
444
|
+
return new accounttype_1.p2tr(psbt, masterFp);
|
|
538
445
|
if (arg.additionals.includes("bech32"))
|
|
539
|
-
return
|
|
446
|
+
return new accounttype_1.p2wpkh(psbt, masterFp);
|
|
540
447
|
if (arg.segwit)
|
|
541
|
-
return
|
|
542
|
-
return
|
|
543
|
-
}
|
|
544
|
-
/*
|
|
545
|
-
The following two functions are copied from wallet-btc and adapted.
|
|
546
|
-
They should be moved to a library to avoid code reuse.
|
|
547
|
-
*/
|
|
548
|
-
function hashTapTweak(x) {
|
|
549
|
-
// hash_tag(x) = SHA256(SHA256(tag) || SHA256(tag) || x), see BIP340
|
|
550
|
-
// See https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification
|
|
551
|
-
var h = bitcoinjs_lib_1.crypto.sha256(Buffer.from("TapTweak", "utf-8"));
|
|
552
|
-
return bitcoinjs_lib_1.crypto.sha256(Buffer.concat([h, h, x]));
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Calculates a taproot output key from an internal key. This output key will be
|
|
556
|
-
* used as witness program in a taproot output. The internal key is tweaked
|
|
557
|
-
* according to recommendation in BIP341:
|
|
558
|
-
* https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0
|
|
559
|
-
*
|
|
560
|
-
* @param internalPubkey A 32 byte x-only taproot internal key
|
|
561
|
-
* @returns The output key
|
|
562
|
-
*/
|
|
563
|
-
function getTaprootOutputKey(internalPubkey) {
|
|
564
|
-
if (internalPubkey.length != 32) {
|
|
565
|
-
throw new Error("Expected 32 byte pubkey. Got " + internalPubkey.length);
|
|
566
|
-
}
|
|
567
|
-
// A BIP32 derived key can be converted to a schnorr pubkey by dropping
|
|
568
|
-
// the first byte, which represent the oddness/evenness. In schnorr all
|
|
569
|
-
// pubkeys are even.
|
|
570
|
-
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-conversion
|
|
571
|
-
var evenEcdsaPubkey = Buffer.concat([Buffer.of(0x02), internalPubkey]);
|
|
572
|
-
var tweak = hashTapTweak(internalPubkey);
|
|
573
|
-
// Q = P + int(hash_TapTweak(bytes(P)))G
|
|
574
|
-
var outputEcdsaKey = Buffer.from((0, tiny_secp256k1_1.pointAddScalar)(evenEcdsaPubkey, tweak));
|
|
575
|
-
// Convert to schnorr.
|
|
576
|
-
var outputSchnorrKey = outputEcdsaKey.slice(1);
|
|
577
|
-
// Create address
|
|
578
|
-
return outputSchnorrKey;
|
|
448
|
+
return new accounttype_1.p2wpkhWrapped(psbt, masterFp);
|
|
449
|
+
return new accounttype_1.p2pkh(psbt, masterFp);
|
|
579
450
|
}
|
|
580
451
|
//# sourceMappingURL=BtcNew.js.map
|