@ledgerhq/hw-app-btc 6.10.0 → 6.12.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 +384 -60
- package/lib/Btc.d.ts +9 -6
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +73 -8
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +79 -32
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +168 -207
- 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 +233 -0
- package/lib/newops/accounttype.js.map +1 -0
- package/lib/newops/appClient.d.ts +6 -2
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/appClient.js +8 -4
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts +18 -2
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +34 -12
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.d.ts +11 -0
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib/newops/merkelizedPsbt.js +11 -0
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.d.ts +5 -0
- package/lib/newops/merkle.d.ts.map +1 -1
- package/lib/newops/merkle.js +5 -0
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.d.ts +10 -0
- package/lib/newops/merkleMap.d.ts.map +1 -1
- package/lib/newops/merkleMap.js +10 -0
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts +8 -0
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +9 -1
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.d.ts +6 -0
- package/lib/newops/psbtExtractor.d.ts.map +1 -1
- package/lib/newops/psbtExtractor.js +6 -0
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtFinalizer.d.ts +11 -1
- package/lib/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib/newops/psbtFinalizer.js +26 -1
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/newops/psbtv2.d.ts +22 -2
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +33 -8
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib-es/Btc.d.ts +9 -6
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +73 -8
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +79 -32
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +170 -209
- 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 +230 -0
- package/lib-es/newops/accounttype.js.map +1 -0
- package/lib-es/newops/appClient.d.ts +6 -2
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/appClient.js +8 -4
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts +18 -2
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +34 -12
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts +11 -0
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +11 -0
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.d.ts +5 -0
- package/lib-es/newops/merkle.d.ts.map +1 -1
- package/lib-es/newops/merkle.js +5 -0
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.d.ts +10 -0
- package/lib-es/newops/merkleMap.d.ts.map +1 -1
- package/lib-es/newops/merkleMap.js +10 -0
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts +8 -0
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +10 -2
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.d.ts +6 -0
- package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
- package/lib-es/newops/psbtExtractor.js +6 -0
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.d.ts +11 -1
- package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib-es/newops/psbtFinalizer.js +26 -1
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts +22 -2
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +33 -8
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/package.json +3 -3
- package/src/Btc.ts +111 -9
- package/src/BtcNew.ts +204 -209
- package/src/newops/accounttype.ts +370 -0
- package/src/newops/appClient.ts +12 -4
- package/src/newops/clientCommands.ts +34 -12
- package/src/newops/merkelizedPsbt.ts +11 -0
- package/src/newops/merkle.ts +5 -0
- package/src/newops/merkleMap.ts +10 -0
- package/src/newops/policy.ts +10 -2
- package/src/newops/psbtExtractor.ts +6 -0
- package/src/newops/psbtFinalizer.ts +26 -1
- package/src/newops/psbtv2.ts +34 -14
- package/tests/Btc.test.ts +89 -0
- package/tests/newops/BtcNew.test.ts +48 -21
- package/tests/newops/integrationtools.ts +47 -36
- package/tests/newops/testtx.ts +0 -55
package/lib/Btc.js
CHANGED
|
@@ -58,6 +58,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
58
58
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
59
59
|
};
|
|
60
60
|
exports.__esModule = true;
|
|
61
|
+
var bip32_1 = require("./bip32");
|
|
61
62
|
var BtcNew_1 = __importStar(require("./BtcNew"));
|
|
62
63
|
var BtcOld_1 = __importDefault(require("./BtcOld"));
|
|
63
64
|
var getAppAndVersion_1 = require("./getAppAndVersion");
|
|
@@ -113,7 +114,7 @@ var Btc = /** @class */ (function () {
|
|
|
113
114
|
*
|
|
114
115
|
* - p2sh format with 49' paths
|
|
115
116
|
*
|
|
116
|
-
* - bech32 format with
|
|
117
|
+
* - bech32 format with 84' paths
|
|
117
118
|
*
|
|
118
119
|
* - cashaddr in case of Bitcoin Cash
|
|
119
120
|
*
|
|
@@ -122,6 +123,7 @@ var Btc = /** @class */ (function () {
|
|
|
122
123
|
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
123
124
|
*/
|
|
124
125
|
Btc.prototype.getWalletPublicKey = function (path, opts) {
|
|
126
|
+
var _this = this;
|
|
125
127
|
var options;
|
|
126
128
|
if (arguments.length > 2 || typeof opts === "boolean") {
|
|
127
129
|
console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
|
|
@@ -135,7 +137,39 @@ var Btc = /** @class */ (function () {
|
|
|
135
137
|
options = opts || {};
|
|
136
138
|
}
|
|
137
139
|
return this.getCorrectImpl().then(function (impl) {
|
|
138
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Definition: A "normal path" is a prefix of a standard path where all
|
|
142
|
+
* the hardened steps of the standard path are included. For example, the
|
|
143
|
+
* paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
|
|
144
|
+
* is not. m/'199/1'/17'/0/1 is not a normal path either.
|
|
145
|
+
*
|
|
146
|
+
* There's a compatiblity issue between old and new app: When exporting
|
|
147
|
+
* the key of a non-normal path with verify=false, the new app would
|
|
148
|
+
* return an error, whereas the old app would return the key.
|
|
149
|
+
*
|
|
150
|
+
* See
|
|
151
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey
|
|
152
|
+
*
|
|
153
|
+
* If format bech32m is used, we'll not use old, because it doesn't
|
|
154
|
+
* support it.
|
|
155
|
+
*
|
|
156
|
+
* When to use new (given the app supports it)
|
|
157
|
+
* * format is bech32m or
|
|
158
|
+
* * path is normal or
|
|
159
|
+
* * verify is true
|
|
160
|
+
*
|
|
161
|
+
* Otherwise use old.
|
|
162
|
+
*/
|
|
163
|
+
if (impl instanceof BtcNew_1["default"] &&
|
|
164
|
+
options.format != "bech32m" &&
|
|
165
|
+
(!options.verify || options.verify == false) &&
|
|
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.");
|
|
168
|
+
return _this.old().getWalletPublicKey(path, options);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
return impl.getWalletPublicKey(path, options);
|
|
172
|
+
}
|
|
139
173
|
});
|
|
140
174
|
};
|
|
141
175
|
/**
|
|
@@ -160,21 +194,21 @@ var Btc = /** @class */ (function () {
|
|
|
160
194
|
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
161
195
|
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
162
196
|
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
163
|
-
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
197
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
|
|
164
198
|
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
165
199
|
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
166
|
-
* @param segwit is an optional boolean indicating wether to use segwit or not
|
|
200
|
+
* @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
|
|
167
201
|
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
168
202
|
* @param additionals list of additionnal options
|
|
169
203
|
*
|
|
170
204
|
* - "bech32" for spending native segwit outputs
|
|
171
|
-
* - "bech32m" for spending
|
|
205
|
+
* - "bech32m" for spending segwit v1+ outputs
|
|
172
206
|
* - "abc" for bch
|
|
173
207
|
* - "gold" for btg
|
|
174
208
|
* - "bipxxx" for using BIPxxx
|
|
175
209
|
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
176
210
|
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
177
|
-
* @param useTrustedInputForSegwit trust inputs for segwit transactions
|
|
211
|
+
* @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
|
|
178
212
|
* @return the signed transaction ready to be broadcast
|
|
179
213
|
* @example
|
|
180
214
|
btc.createTransaction({
|
|
@@ -269,10 +303,10 @@ var Btc = /** @class */ (function () {
|
|
|
269
303
|
appAndVersion = _a.sent();
|
|
270
304
|
canUseNewImplementation = (0, BtcNew_1.canSupportApp)(appAndVersion);
|
|
271
305
|
if (!canUseNewImplementation) {
|
|
272
|
-
return [2 /*return*/,
|
|
306
|
+
return [2 /*return*/, this.old()];
|
|
273
307
|
}
|
|
274
308
|
else {
|
|
275
|
-
return [2 /*return*/,
|
|
309
|
+
return [2 /*return*/, this["new"]()];
|
|
276
310
|
}
|
|
277
311
|
return [2 /*return*/];
|
|
278
312
|
}
|
|
@@ -282,7 +316,38 @@ var Btc = /** @class */ (function () {
|
|
|
282
316
|
Btc.prototype.old = function () {
|
|
283
317
|
return new BtcOld_1["default"](this.transport);
|
|
284
318
|
};
|
|
319
|
+
Btc.prototype["new"] = function () {
|
|
320
|
+
return new BtcNew_1["default"](new appClient_1.AppClient(this.transport));
|
|
321
|
+
};
|
|
285
322
|
return Btc;
|
|
286
323
|
}());
|
|
287
324
|
exports["default"] = Btc;
|
|
325
|
+
function isPathNormal(path) {
|
|
326
|
+
//path is not deepest hardened node of a standard path or deeper, use BtcOld
|
|
327
|
+
var h = 0x80000000;
|
|
328
|
+
var pathElems = (0, bip32_1.pathStringToArray)(path);
|
|
329
|
+
var hard = function (n) { return n >= h; };
|
|
330
|
+
var soft = function (n) { return !n || n < h; };
|
|
331
|
+
var change = function (n) { return !n || n == 0 || n == 1; };
|
|
332
|
+
if (pathElems.length >= 3 &&
|
|
333
|
+
pathElems.length <= 5 &&
|
|
334
|
+
[44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
|
|
335
|
+
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
336
|
+
hard(pathElems[2]) &&
|
|
337
|
+
change(pathElems[3]) &&
|
|
338
|
+
soft(pathElems[4])) {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
if (pathElems.length >= 4 &&
|
|
342
|
+
pathElems.length <= 6 &&
|
|
343
|
+
48 + h == pathElems[0] &&
|
|
344
|
+
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
345
|
+
hard(pathElems[2]) &&
|
|
346
|
+
hard(pathElems[3]) &&
|
|
347
|
+
change(pathElems[4]) &&
|
|
348
|
+
soft(pathElems[5])) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
288
353
|
//# sourceMappingURL=Btc.js.map
|
package/lib/Btc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,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
|
+
{"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;QA4RrD,kDAAkD;QAC1C,cAAS,GAA2B,IAAI,CAAC;QA5R/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,SAAS,CAAC,qBAAqB,CAC7B,IAAI,EACJ;YACE,eAAe;YACf,oBAAoB;YACpB,qBAAqB;YACrB,gBAAgB;YAChB,6BAA6B;YAC7B,iBAAiB;YACjB,uBAAuB;SACxB,EACD,WAAW,CACZ,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,2BAAa,GAAb,UAAc,GAA0C;QACtD,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAvB,CAAuB,CAAC,CAAC;IACvE,CAAC;IAED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AAC,CAAC,CAAC,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/BtcNew.d.ts
CHANGED
|
@@ -1,15 +1,65 @@
|
|
|
1
1
|
import type { CreateTransactionArg } from "./createTransaction";
|
|
2
|
+
import { AppAndVersion } from "./getAppAndVersion";
|
|
2
3
|
import type { AddressFormat } from "./getWalletPublicKey";
|
|
3
4
|
import { AppClient as Client } from "./newops/appClient";
|
|
4
|
-
import { AppAndVersion } from "./getAppAndVersion";
|
|
5
5
|
export declare function canSupportApp(appAndVersion: AppAndVersion): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* This class implements the same interface as BtcOld (formerly
|
|
8
|
+
* named Btc), but interacts with Bitcoin hardware app version 2+
|
|
9
|
+
* which uses a totally new APDU protocol. This new
|
|
10
|
+
* protocol is documented at
|
|
11
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
|
|
12
|
+
*
|
|
13
|
+
* Since the interface must remain compatible with BtcOld, the methods
|
|
14
|
+
* of this class are quite clunky, because it needs to adapt legacy
|
|
15
|
+
* input data into the PSBT process. In the future, a new interface should
|
|
16
|
+
* be developed that exposes PSBT to the outer world, which would render
|
|
17
|
+
* a much cleaner implementation.
|
|
18
|
+
*/
|
|
6
19
|
export default class BtcNew {
|
|
7
20
|
private client;
|
|
8
21
|
constructor(client: Client);
|
|
22
|
+
/**
|
|
23
|
+
* This is a new method that allow users to get an xpub at a standard path.
|
|
24
|
+
* Standard paths are described at
|
|
25
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description
|
|
26
|
+
*
|
|
27
|
+
* This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
|
|
28
|
+
* M/44'/N'/x'/**
|
|
29
|
+
* M/48'/N'/x'/y'/**
|
|
30
|
+
* M/49'/N'/x'/**
|
|
31
|
+
* M/84'/N'/x'/**
|
|
32
|
+
* M/86'/N'/x'/**
|
|
33
|
+
*
|
|
34
|
+
* The method was added because of added security in the hardware app v2+. The
|
|
35
|
+
* new hardware app will allow export of any xpub up to and including the
|
|
36
|
+
* deepest hardened key of standard derivation paths, whereas the old app
|
|
37
|
+
* would allow export of any key.
|
|
38
|
+
*
|
|
39
|
+
* This caused an issue for callers of this class, who only had
|
|
40
|
+
* getWalletPublicKey() to call which means they have to constuct xpub
|
|
41
|
+
* themselves:
|
|
42
|
+
*
|
|
43
|
+
* Suppose a user of this class wants to create an account xpub on a standard
|
|
44
|
+
* path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
|
|
45
|
+
* by requesting the parent key M/44'/0'. The new app won't allow that, because
|
|
46
|
+
* it only allows exporting deepest level hardened path. So the options are to
|
|
47
|
+
* allow requesting M/44'/0' from the app, or to add a new function
|
|
48
|
+
* "getWalletXpub".
|
|
49
|
+
*
|
|
50
|
+
* We opted for adding a new function, which can greatly simplify client code.
|
|
51
|
+
*/
|
|
9
52
|
getWalletXpub({ path, xpubVersion, }: {
|
|
10
53
|
path: string;
|
|
11
54
|
xpubVersion: number;
|
|
12
55
|
}): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* This method returns a public key, a bitcoin address, and and a chaincode
|
|
58
|
+
* for a specific derivation path.
|
|
59
|
+
*
|
|
60
|
+
* Limitation: If the path is not a leaf node of a standard path, the address
|
|
61
|
+
* will be the empty string "", see this.getWalletAddress() for details.
|
|
62
|
+
*/
|
|
13
63
|
getWalletPublicKey(path: string, opts?: {
|
|
14
64
|
verify?: boolean;
|
|
15
65
|
format?: AddressFormat;
|
|
@@ -27,7 +77,7 @@ export default class BtcNew {
|
|
|
27
77
|
*
|
|
28
78
|
* If display is false we *could* generate the address ourselves, but chose to
|
|
29
79
|
* get it from the device to save development time. However, it shouldn't take
|
|
30
|
-
*
|
|
80
|
+
* too much time to implement local address generation.
|
|
31
81
|
*
|
|
32
82
|
* Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
|
|
33
83
|
* way to get the address from the device. In this case we have to create it
|
|
@@ -35,41 +85,38 @@ export default class BtcNew {
|
|
|
35
85
|
*/
|
|
36
86
|
private getWalletAddress;
|
|
37
87
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* * transaction is the previously computed transaction object for this UTXO
|
|
42
|
-
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
43
|
-
* * redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
44
|
-
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
45
|
-
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
46
|
-
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
47
|
-
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
|
|
48
|
-
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
49
|
-
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
50
|
-
* @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
|
|
51
|
-
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
52
|
-
* @param additionals list of additionnal options
|
|
88
|
+
* Build and sign a transaction. See Btc.createPaymentTransactionNew for
|
|
89
|
+
* details on how to use this method.
|
|
53
90
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* - "gold" for btg
|
|
58
|
-
* - "bipxxx" for using BIPxxx
|
|
59
|
-
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
60
|
-
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
61
|
-
* @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
|
|
62
|
-
* @return the signed transaction ready to be broadcast
|
|
63
|
-
* @example
|
|
64
|
-
btc.createTransaction({
|
|
65
|
-
inputs: [ [tx1, 1] ],
|
|
66
|
-
associatedKeysets: ["0'/0/0"],
|
|
67
|
-
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
68
|
-
}).then(res => ...);
|
|
91
|
+
* This method will convert the legacy arguments, CreateTransactionArg, into
|
|
92
|
+
* a psbt which is finally signed and finalized, and the extracted fully signed
|
|
93
|
+
* transaction is returned.
|
|
69
94
|
*/
|
|
70
95
|
createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Calculates an output script along with public key and possible redeemScript
|
|
98
|
+
* from a path and accountType. The accountPath must be a prefix of path.
|
|
99
|
+
*
|
|
100
|
+
* @returns an object with output script (property "script"), redeemScript (if
|
|
101
|
+
* wrapped p2wpkh), and pubkey at provided path. The values of these three
|
|
102
|
+
* properties depend on the accountType used.
|
|
103
|
+
*/
|
|
71
104
|
private outputScriptAt;
|
|
105
|
+
/**
|
|
106
|
+
* Adds relevant data about an input to the psbt. This includes sequence,
|
|
107
|
+
* previous txid, output index, spent UTXO, redeem script for wrapped p2wpkh,
|
|
108
|
+
* public key and its derivation path.
|
|
109
|
+
*/
|
|
72
110
|
private setInput;
|
|
111
|
+
/**
|
|
112
|
+
* This implements the "Signer" role of the BIP370 transaction signing
|
|
113
|
+
* process.
|
|
114
|
+
*
|
|
115
|
+
* It ssks the hardware device to sign the a psbt using the specified wallet
|
|
116
|
+
* policy. This method assumes BIP32 derived keys are used for all inputs, see
|
|
117
|
+
* comment in-line. The signatures returned from the hardware device is added
|
|
118
|
+
* to the appropriate input fields of the PSBT.
|
|
119
|
+
*/
|
|
73
120
|
private signPsbt;
|
|
74
121
|
}
|
|
75
122
|
//# sourceMappingURL=BtcNew.d.ts.map
|
package/lib/BtcNew.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":"AAWA,OAAO,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