@ledgerhq/hw-app-btc 9.0.0-nightly.4 → 9.0.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +5 -21
- package/README.md +111 -33
- package/lib/Btc.d.ts +13 -11
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +191 -31
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +4 -2
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +13 -54
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.d.ts +37 -2
- package/lib/BtcOld.d.ts.map +1 -1
- package/lib/BtcOld.js +45 -3
- package/lib/BtcOld.js.map +1 -1
- package/lib-es/Btc.d.ts +13 -11
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +168 -31
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +4 -2
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +8 -54
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.d.ts +37 -2
- package/lib-es/BtcOld.d.ts.map +1 -1
- package/lib-es/BtcOld.js +45 -3
- package/lib-es/BtcOld.js.map +1 -1
- package/package.json +4 -4
- package/src/Btc.ts +151 -41
- package/src/BtcNew.ts +15 -60
- package/src/BtcOld.ts +59 -4
- package/tests/Btc.test.ts +132 -16
- package/tests/newops/BtcNew.test.ts +5 -0
- package/tests/newops/integrationtools.ts +4 -4
- package/tests/parseTx.test.ts +1 -1
- package/tests/trustedInputs.test.ts +8 -6
package/lib/BtcOld.js
CHANGED
|
@@ -55,13 +55,15 @@ var ripemd160_1 = __importDefault(require("ripemd160"));
|
|
|
55
55
|
var sha_js_1 = __importDefault(require("sha.js"));
|
|
56
56
|
var createTransaction_1 = require("./createTransaction");
|
|
57
57
|
var getWalletPublicKey_1 = require("./getWalletPublicKey");
|
|
58
|
+
var signMessage_1 = require("./signMessage");
|
|
59
|
+
var signP2SHTransaction_1 = require("./signP2SHTransaction");
|
|
58
60
|
var bip32_1 = require("./bip32");
|
|
59
61
|
/**
|
|
60
62
|
* Bitcoin API.
|
|
61
63
|
*
|
|
62
64
|
* @example
|
|
63
65
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
64
|
-
* const btc = new Btc(
|
|
66
|
+
* const btc = new Btc(transport)
|
|
65
67
|
*/
|
|
66
68
|
var BtcOld = /** @class */ (function () {
|
|
67
69
|
function BtcOld(transport) {
|
|
@@ -137,6 +139,21 @@ var BtcOld = /** @class */ (function () {
|
|
|
137
139
|
}
|
|
138
140
|
return (0, getWalletPublicKey_1.getWalletPublicKey)(this.transport, __assign(__assign({}, opts), { path: path }));
|
|
139
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
|
144
|
+
* @example
|
|
145
|
+
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
146
|
+
var v = result['v'] + 27 + 4;
|
|
147
|
+
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
148
|
+
console.log("Signature : " + signature);
|
|
149
|
+
}).catch(function(ex) {console.log(ex);});
|
|
150
|
+
*/
|
|
151
|
+
BtcOld.prototype.signMessageNew = function (path, messageHex) {
|
|
152
|
+
return (0, signMessage_1.signMessage)(this.transport, {
|
|
153
|
+
path: path,
|
|
154
|
+
messageHex: messageHex
|
|
155
|
+
});
|
|
156
|
+
};
|
|
140
157
|
/**
|
|
141
158
|
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
142
159
|
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
@@ -169,12 +186,37 @@ var BtcOld = /** @class */ (function () {
|
|
|
169
186
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
170
187
|
}).then(res => ...);
|
|
171
188
|
*/
|
|
172
|
-
BtcOld.prototype.
|
|
189
|
+
BtcOld.prototype.createPaymentTransactionNew = function (arg) {
|
|
173
190
|
if (arguments.length > 1) {
|
|
174
|
-
|
|
191
|
+
console.warn("@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.");
|
|
175
192
|
}
|
|
176
193
|
return (0, createTransaction_1.createTransaction)(this.transport, arg);
|
|
177
194
|
};
|
|
195
|
+
/**
|
|
196
|
+
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
197
|
+
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
198
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
199
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
200
|
+
* * redeem script is the mandatory redeem script associated to the current P2SH input
|
|
201
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
202
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
203
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
204
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
205
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
206
|
+
* @return the signed transaction ready to be broadcast
|
|
207
|
+
* @example
|
|
208
|
+
btc.signP2SHTransaction({
|
|
209
|
+
inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
|
|
210
|
+
associatedKeysets: ["0'/0/0"],
|
|
211
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
212
|
+
}).then(result => ...);
|
|
213
|
+
*/
|
|
214
|
+
BtcOld.prototype.signP2SHTransaction = function (arg) {
|
|
215
|
+
if (arguments.length > 1) {
|
|
216
|
+
console.warn("@ledgerhq/hw-app-btc: signP2SHTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
217
|
+
}
|
|
218
|
+
return (0, signP2SHTransaction_1.signP2SHTransaction)(this.transport, arg);
|
|
219
|
+
};
|
|
178
220
|
return BtcOld;
|
|
179
221
|
}());
|
|
180
222
|
exports["default"] = BtcOld;
|
package/lib/BtcOld.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcOld.js","sourceRoot":"","sources":["../src/BtcOld.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,wDAAkC;AAClC,kDAAyB;AAGzB,yDAAwD;AAExD,2DAA0D;AAC1D,iCAA+D;AAG/D;;;;;;GAMG;AAEH;IACE,gBAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QAEhC,qBAAgB,GAAG,EAAE,CAAC;IAFa,CAAC;IAG9B,6BAAY,GAA1B,UAA2B,IAAY;;;;;;wBACrC,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;4BAAE,sBAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAC;wBACxD,qBAAM,IAAA,uCAAkB,EAAC,IAAI,CAAC,SAAS,EAAE;gCACnD,IAAI,MAAA;6BACL,CAAC,EAAA;;wBAFI,GAAG,GAAG,SAEV;wBACF,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;wBAClC,sBAAO,GAAG,EAAC;;;;KACZ;IAEK,8BAAa,GAAnB,UAAoB,EAMnB;YALC,IAAI,UAAA,EACJ,WAAW,iBAAA;;;;;;wBAKL,YAAY,GAAG,IAAA,yBAAiB,EAAC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ACvD,OAAO,iBAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,MAAM,CAAC,MAAuB;IACrC,OAAO,IAAA,mBAAG,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;AAC/C,CAAC;AACD,SAAS,OAAO,CAAC,MAAuB;IACtC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAChC,CAAC;AACD,SAAS,SAAS,CAAC,MAAuB;IACxC,OAAO,IAAI,sBAAS,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;AACjD,CAAC;AACD,SAAS,OAAO,CAAC,MAAuB;IACtC,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
package/lib-es/Btc.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import BtcNew from "./BtcNew";
|
|
4
|
+
import BtcOld from "./BtcOld";
|
|
3
5
|
import type { CreateTransactionArg } from "./createTransaction";
|
|
4
6
|
import type { AddressFormat } from "./getWalletPublicKey";
|
|
5
7
|
import type { SignP2SHTransactionArg } from "./signP2SHTransaction";
|
|
@@ -10,16 +12,11 @@ export type { AddressFormat };
|
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
12
14
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
13
|
-
* const btc = new Btc(
|
|
15
|
+
* const btc = new Btc(transport)
|
|
14
16
|
*/
|
|
15
17
|
export default class Btc {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
constructor({ transport, scrambleKey, currency, }: {
|
|
19
|
-
transport: Transport;
|
|
20
|
-
scrambleKey?: string;
|
|
21
|
-
currency?: string;
|
|
22
|
-
});
|
|
18
|
+
transport: Transport;
|
|
19
|
+
constructor(transport: Transport, scrambleKey?: string);
|
|
23
20
|
/**
|
|
24
21
|
* Get an XPUB with a ledger device
|
|
25
22
|
* @param arg derivation parameter
|
|
@@ -64,13 +61,13 @@ export default class Btc {
|
|
|
64
61
|
/**
|
|
65
62
|
* You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
|
66
63
|
* @example
|
|
67
|
-
btc.
|
|
64
|
+
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
68
65
|
var v = result['v'] + 27 + 4;
|
|
69
66
|
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
70
67
|
console.log("Signature : " + signature);
|
|
71
68
|
}).catch(function(ex) {console.log(ex);});
|
|
72
69
|
*/
|
|
73
|
-
|
|
70
|
+
signMessageNew(path: string, messageHex: string): Promise<{
|
|
74
71
|
v: number;
|
|
75
72
|
r: string;
|
|
76
73
|
s: string;
|
|
@@ -108,7 +105,7 @@ export default class Btc {
|
|
|
108
105
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
109
106
|
}).then(res => ...);
|
|
110
107
|
*/
|
|
111
|
-
|
|
108
|
+
createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
|
|
112
109
|
/**
|
|
113
110
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
114
111
|
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
@@ -143,5 +140,10 @@ export default class Btc {
|
|
|
143
140
|
serializeTransactionOutputs(t: Transaction): Buffer;
|
|
144
141
|
getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>;
|
|
145
142
|
getTrustedInputBIP143(indexLookup: number, transaction: Transaction, additionals?: Array<string>): string;
|
|
143
|
+
private _lazyImpl;
|
|
144
|
+
private getCorrectImpl;
|
|
145
|
+
private inferCorrectImpl;
|
|
146
|
+
protected old(): BtcOld;
|
|
147
|
+
protected new(): BtcNew;
|
|
146
148
|
}
|
|
147
149
|
//# sourceMappingURL=Btc.d.ts.map
|
package/lib-es/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;
|
|
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,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAQ;IAiBrD;;;;;;OAMG;IACH,aAAa,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1E;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,kBAAkB,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAA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|
package/lib-es/Btc.js
CHANGED
|
@@ -1,39 +1,70 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { pathStringToArray } from "./bip32";
|
|
38
|
+
import BtcNew, { canSupportApp } from "./BtcNew";
|
|
2
39
|
import BtcOld from "./BtcOld";
|
|
40
|
+
import { getAppAndVersion } from "./getAppAndVersion";
|
|
3
41
|
import { getTrustedInput } from "./getTrustedInput";
|
|
4
42
|
import { getTrustedInputBIP143 } from "./getTrustedInputBIP143";
|
|
5
43
|
import { AppClient } from "./newops/appClient";
|
|
6
44
|
import { serializeTransactionOutputs } from "./serializeTransaction";
|
|
7
45
|
import { splitTransaction } from "./splitTransaction";
|
|
8
|
-
import { signP2SHTransaction } from "./signP2SHTransaction";
|
|
9
|
-
import { signMessage } from "./signMessage";
|
|
10
46
|
/**
|
|
11
47
|
* Bitcoin API.
|
|
12
48
|
*
|
|
13
49
|
* @example
|
|
14
50
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
15
|
-
* const btc = new Btc(
|
|
51
|
+
* const btc = new Btc(transport)
|
|
16
52
|
*/
|
|
17
53
|
var Btc = /** @class */ (function () {
|
|
18
|
-
function Btc(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.
|
|
54
|
+
function Btc(transport, scrambleKey) {
|
|
55
|
+
if (scrambleKey === void 0) { scrambleKey = "BTC"; }
|
|
56
|
+
// cache the underlying implementation (only once)
|
|
57
|
+
this._lazyImpl = null;
|
|
58
|
+
this.transport = transport;
|
|
59
|
+
transport.decorateAppAPIMethods(this, [
|
|
22
60
|
"getWalletXpub",
|
|
23
61
|
"getWalletPublicKey",
|
|
24
62
|
"signP2SHTransaction",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
63
|
+
"signMessageNew",
|
|
64
|
+
"createPaymentTransactionNew",
|
|
27
65
|
"getTrustedInput",
|
|
28
66
|
"getTrustedInputBIP143",
|
|
29
67
|
], scrambleKey);
|
|
30
|
-
// new APDU (nano app API) for bitcoin and old APDU for altcoin
|
|
31
|
-
if (currency === "bitcoin" || currency === "bitcoin_testnet") {
|
|
32
|
-
this._impl = new BtcNew(new AppClient(this._transport));
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this._impl = new BtcOld(this._transport);
|
|
36
|
-
}
|
|
37
68
|
}
|
|
38
69
|
/**
|
|
39
70
|
* Get an XPUB with a ledger device
|
|
@@ -43,7 +74,7 @@ var Btc = /** @class */ (function () {
|
|
|
43
74
|
* @returns XPUB of the account
|
|
44
75
|
*/
|
|
45
76
|
Btc.prototype.getWalletXpub = function (arg) {
|
|
46
|
-
return this.
|
|
77
|
+
return this.getCorrectImpl().then(function (impl) { return impl.getWalletXpub(arg); });
|
|
47
78
|
};
|
|
48
79
|
/**
|
|
49
80
|
* @param path a BIP 32 path
|
|
@@ -68,6 +99,7 @@ var Btc = /** @class */ (function () {
|
|
|
68
99
|
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
69
100
|
*/
|
|
70
101
|
Btc.prototype.getWalletPublicKey = function (path, opts) {
|
|
102
|
+
var _this = this;
|
|
71
103
|
var options;
|
|
72
104
|
if (arguments.length > 2 || typeof opts === "boolean") {
|
|
73
105
|
console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
|
|
@@ -80,22 +112,53 @@ var Btc = /** @class */ (function () {
|
|
|
80
112
|
else {
|
|
81
113
|
options = opts || {};
|
|
82
114
|
}
|
|
83
|
-
return this.
|
|
115
|
+
return this.getCorrectImpl().then(function (impl) {
|
|
116
|
+
/**
|
|
117
|
+
* Definition: A "normal path" is a prefix of a standard path where all
|
|
118
|
+
* the hardened steps of the standard path are included. For example, the
|
|
119
|
+
* paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
|
|
120
|
+
* is not. m/'199/1'/17'/0/1 is not a normal path either.
|
|
121
|
+
*
|
|
122
|
+
* There's a compatiblity issue between old and new app: When exporting
|
|
123
|
+
* the key of a non-normal path with verify=false, the new app would
|
|
124
|
+
* return an error, whereas the old app would return the key.
|
|
125
|
+
*
|
|
126
|
+
* See
|
|
127
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey
|
|
128
|
+
*
|
|
129
|
+
* If format bech32m is used, we'll not use old, because it doesn't
|
|
130
|
+
* support it.
|
|
131
|
+
*
|
|
132
|
+
* When to use new (given the app supports it)
|
|
133
|
+
* * format is bech32m or
|
|
134
|
+
* * path is normal or
|
|
135
|
+
* * verify is true
|
|
136
|
+
*
|
|
137
|
+
* Otherwise use old.
|
|
138
|
+
*/
|
|
139
|
+
if (impl instanceof BtcNew &&
|
|
140
|
+
options.format != "bech32m" &&
|
|
141
|
+
(!options.verify || options.verify == false) &&
|
|
142
|
+
!isPathNormal(path)) {
|
|
143
|
+
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.");
|
|
144
|
+
return _this.old().getWalletPublicKey(path, options);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return impl.getWalletPublicKey(path, options);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
84
150
|
};
|
|
85
151
|
/**
|
|
86
152
|
* You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
|
87
153
|
* @example
|
|
88
|
-
btc.
|
|
154
|
+
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
89
155
|
var v = result['v'] + 27 + 4;
|
|
90
156
|
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
91
157
|
console.log("Signature : " + signature);
|
|
92
158
|
}).catch(function(ex) {console.log(ex);});
|
|
93
159
|
*/
|
|
94
|
-
Btc.prototype.
|
|
95
|
-
return
|
|
96
|
-
path: path,
|
|
97
|
-
messageHex: messageHex
|
|
98
|
-
});
|
|
160
|
+
Btc.prototype.signMessageNew = function (path, messageHex) {
|
|
161
|
+
return this.old().signMessageNew(path, messageHex);
|
|
99
162
|
};
|
|
100
163
|
/**
|
|
101
164
|
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
@@ -130,11 +193,13 @@ var Btc = /** @class */ (function () {
|
|
|
130
193
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
131
194
|
}).then(res => ...);
|
|
132
195
|
*/
|
|
133
|
-
Btc.prototype.
|
|
196
|
+
Btc.prototype.createPaymentTransactionNew = function (arg) {
|
|
134
197
|
if (arguments.length > 1) {
|
|
135
|
-
|
|
198
|
+
console.warn("@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.");
|
|
136
199
|
}
|
|
137
|
-
return this.
|
|
200
|
+
return this.getCorrectImpl().then(function (impl) {
|
|
201
|
+
return impl.createPaymentTransactionNew(arg);
|
|
202
|
+
});
|
|
138
203
|
};
|
|
139
204
|
/**
|
|
140
205
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
@@ -156,7 +221,7 @@ var Btc = /** @class */ (function () {
|
|
|
156
221
|
}).then(result => ...);
|
|
157
222
|
*/
|
|
158
223
|
Btc.prototype.signP2SHTransaction = function (arg) {
|
|
159
|
-
return signP2SHTransaction(
|
|
224
|
+
return this.old().signP2SHTransaction(arg);
|
|
160
225
|
};
|
|
161
226
|
/**
|
|
162
227
|
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.
|
|
@@ -180,13 +245,85 @@ var Btc = /** @class */ (function () {
|
|
|
180
245
|
};
|
|
181
246
|
Btc.prototype.getTrustedInput = function (indexLookup, transaction, additionals) {
|
|
182
247
|
if (additionals === void 0) { additionals = []; }
|
|
183
|
-
return getTrustedInput(this.
|
|
248
|
+
return getTrustedInput(this.transport, indexLookup, transaction, additionals);
|
|
184
249
|
};
|
|
185
250
|
Btc.prototype.getTrustedInputBIP143 = function (indexLookup, transaction, additionals) {
|
|
186
251
|
if (additionals === void 0) { additionals = []; }
|
|
187
|
-
return getTrustedInputBIP143(this.
|
|
252
|
+
return getTrustedInputBIP143(this.transport, indexLookup, transaction, additionals);
|
|
253
|
+
};
|
|
254
|
+
Btc.prototype.getCorrectImpl = function () {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
+
var _lazyImpl, impl;
|
|
257
|
+
return __generator(this, function (_a) {
|
|
258
|
+
switch (_a.label) {
|
|
259
|
+
case 0:
|
|
260
|
+
_lazyImpl = this._lazyImpl;
|
|
261
|
+
if (_lazyImpl)
|
|
262
|
+
return [2 /*return*/, _lazyImpl];
|
|
263
|
+
return [4 /*yield*/, this.inferCorrectImpl()];
|
|
264
|
+
case 1:
|
|
265
|
+
impl = _a.sent();
|
|
266
|
+
this._lazyImpl = impl;
|
|
267
|
+
return [2 /*return*/, impl];
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
Btc.prototype.inferCorrectImpl = function () {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
274
|
+
var appAndVersion, canUseNewImplementation;
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
switch (_a.label) {
|
|
277
|
+
case 0: return [4 /*yield*/, getAppAndVersion(this.transport)];
|
|
278
|
+
case 1:
|
|
279
|
+
appAndVersion = _a.sent();
|
|
280
|
+
canUseNewImplementation = canSupportApp(appAndVersion);
|
|
281
|
+
if (!canUseNewImplementation) {
|
|
282
|
+
return [2 /*return*/, this.old()];
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
return [2 /*return*/, this["new"]()];
|
|
286
|
+
}
|
|
287
|
+
return [2 /*return*/];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
Btc.prototype.old = function () {
|
|
293
|
+
return new BtcOld(this.transport);
|
|
294
|
+
};
|
|
295
|
+
Btc.prototype["new"] = function () {
|
|
296
|
+
return new BtcNew(new AppClient(this.transport));
|
|
188
297
|
};
|
|
189
298
|
return Btc;
|
|
190
299
|
}());
|
|
191
300
|
export default Btc;
|
|
301
|
+
function isPathNormal(path) {
|
|
302
|
+
//path is not deepest hardened node of a standard path or deeper, use BtcOld
|
|
303
|
+
var h = 0x80000000;
|
|
304
|
+
var pathElems = pathStringToArray(path);
|
|
305
|
+
var hard = function (n) { return n >= h; };
|
|
306
|
+
var soft = function (n) { return !n || n < h; };
|
|
307
|
+
var change = function (n) { return !n || n == 0 || n == 1; };
|
|
308
|
+
if (pathElems.length >= 3 &&
|
|
309
|
+
pathElems.length <= 5 &&
|
|
310
|
+
[44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
|
|
311
|
+
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
312
|
+
hard(pathElems[2]) &&
|
|
313
|
+
change(pathElems[3]) &&
|
|
314
|
+
soft(pathElems[4])) {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
if (pathElems.length >= 4 &&
|
|
318
|
+
pathElems.length <= 6 &&
|
|
319
|
+
48 + h == pathElems[0] &&
|
|
320
|
+
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
321
|
+
hard(pathElems[2]) &&
|
|
322
|
+
hard(pathElems[3]) &&
|
|
323
|
+
change(pathElems[4]) &&
|
|
324
|
+
soft(pathElems[5])) {
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
192
329
|
//# sourceMappingURL=Btc.js.map
|
package/lib-es/Btc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,MAAM,EAAE,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC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AC,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-es/BtcNew.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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";
|
|
5
|
+
export declare function canSupportApp(appAndVersion: AppAndVersion): boolean;
|
|
4
6
|
/**
|
|
5
7
|
* This class implements the same interface as BtcOld (formerly
|
|
6
8
|
* named Btc), but interacts with Bitcoin hardware app version 2+
|
|
@@ -83,14 +85,14 @@ export default class BtcNew {
|
|
|
83
85
|
*/
|
|
84
86
|
private getWalletAddress;
|
|
85
87
|
/**
|
|
86
|
-
* Build and sign a transaction. See Btc.
|
|
88
|
+
* Build and sign a transaction. See Btc.createPaymentTransactionNew for
|
|
87
89
|
* details on how to use this method.
|
|
88
90
|
*
|
|
89
91
|
* This method will convert the legacy arguments, CreateTransactionArg, into
|
|
90
92
|
* a psbt which is finally signed and finalized, and the extracted fully signed
|
|
91
93
|
* transaction is returned.
|
|
92
94
|
*/
|
|
93
|
-
|
|
95
|
+
createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
|
|
94
96
|
/**
|
|
95
97
|
* Calculates an output script along with public key and possible redeemScript
|
|
96
98
|
* from a path and accountType. The accountPath must be a prefix of path.
|
package/lib-es/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-es/BtcNew.js
CHANGED
|
@@ -35,6 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import { crypto } from "bitcoinjs-lib";
|
|
38
|
+
import semver from "semver";
|
|
38
39
|
import { pointCompress } from "tiny-secp256k1";
|
|
39
40
|
import { getXpubComponents, hardenedPathOf, pathArrayToString, pathStringToArray, pubkeyFromXpub, } from "./bip32";
|
|
40
41
|
import { BufferReader } from "./buffertools";
|
|
@@ -44,6 +45,11 @@ import { extract } from "./newops/psbtExtractor";
|
|
|
44
45
|
import { finalize } from "./newops/psbtFinalizer";
|
|
45
46
|
import { psbtIn, PsbtV2 } from "./newops/psbtv2";
|
|
46
47
|
import { serializeTransaction } from "./serializeTransaction";
|
|
48
|
+
var newSupportedApps = ["Bitcoin", "Bitcoin Test"];
|
|
49
|
+
export function canSupportApp(appAndVersion) {
|
|
50
|
+
return (newSupportedApps.includes(appAndVersion.name) &&
|
|
51
|
+
semver.major(appAndVersion.version) >= 2);
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* This class implements the same interface as BtcOld (formerly
|
|
49
55
|
* named Btc), but interacts with Bitcoin hardware app version 2+
|
|
@@ -125,9 +131,6 @@ var BtcNew = /** @class */ (function () {
|
|
|
125
131
|
return __generator(this, function (_c) {
|
|
126
132
|
switch (_c.label) {
|
|
127
133
|
case 0:
|
|
128
|
-
if (!isPathNormal(path)) {
|
|
129
|
-
throw Error("non-standard path: ".concat(path));
|
|
130
|
-
}
|
|
131
134
|
pathElements = pathStringToArray(path);
|
|
132
135
|
return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
|
|
133
136
|
case 1:
|
|
@@ -186,14 +189,14 @@ var BtcNew = /** @class */ (function () {
|
|
|
186
189
|
});
|
|
187
190
|
};
|
|
188
191
|
/**
|
|
189
|
-
* Build and sign a transaction. See Btc.
|
|
192
|
+
* Build and sign a transaction. See Btc.createPaymentTransactionNew for
|
|
190
193
|
* details on how to use this method.
|
|
191
194
|
*
|
|
192
195
|
* This method will convert the legacy arguments, CreateTransactionArg, into
|
|
193
196
|
* a psbt which is finally signed and finalized, and the extracted fully signed
|
|
194
197
|
* transaction is returned.
|
|
195
198
|
*/
|
|
196
|
-
BtcNew.prototype.
|
|
199
|
+
BtcNew.prototype.createPaymentTransactionNew = function (arg) {
|
|
197
200
|
return __awaiter(this, void 0, void 0, function () {
|
|
198
201
|
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;
|
|
199
202
|
return __generator(this, function (_a) {
|
|
@@ -438,53 +441,4 @@ function accountTypeFromArg(arg, psbt, masterFp) {
|
|
|
438
441
|
return new p2wpkhWrapped(psbt, masterFp);
|
|
439
442
|
return new p2pkh(psbt, masterFp);
|
|
440
443
|
}
|
|
441
|
-
/*
|
|
442
|
-
The new protocol only allows standard path.
|
|
443
|
-
Standard paths are (currently):
|
|
444
|
-
M/44'/(1|0)'/X'
|
|
445
|
-
M/49'/(1|0)'/X'
|
|
446
|
-
M/84'/(1|0)'/X'
|
|
447
|
-
M/86'/(1|0)'/X'
|
|
448
|
-
M/48'/(1|0)'/X'/Y'
|
|
449
|
-
followed by "", "(0|1)", or "(0|1)/b", where a and b are
|
|
450
|
-
non-hardened. For example, the following paths are standard
|
|
451
|
-
M/48'/1'/99'/7'
|
|
452
|
-
M/86'/1'/99'/0
|
|
453
|
-
M/48'/0'/99'/7'/1/17
|
|
454
|
-
The following paths are non-standard
|
|
455
|
-
M/48'/0'/99' // Not deepest hardened path
|
|
456
|
-
M/48'/0'/99'/7'/1/17/2 // Too many non-hardened derivation steps
|
|
457
|
-
M/199'/0'/1'/0/88 // Not a known purpose 199
|
|
458
|
-
M/86'/1'/99'/2 // Change path item must be 0 or 1
|
|
459
|
-
*/
|
|
460
|
-
function isPathNormal(path) {
|
|
461
|
-
//path is not deepest hardened node of a standard path or deeper, use BtcOld
|
|
462
|
-
var h = 0x80000000; //HARDENED from bip32
|
|
463
|
-
var pathElems = pathStringToArray(path);
|
|
464
|
-
var hard = function (n) { return n >= h; };
|
|
465
|
-
var soft = function (n) { return n === undefined || n < h; };
|
|
466
|
-
var change = function (n) {
|
|
467
|
-
return n === undefined || n === 0 || n === 1;
|
|
468
|
-
};
|
|
469
|
-
if (pathElems.length >= 3 &&
|
|
470
|
-
pathElems.length <= 5 &&
|
|
471
|
-
[44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
|
|
472
|
-
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
473
|
-
hard(pathElems[2]) &&
|
|
474
|
-
change(pathElems[3]) &&
|
|
475
|
-
soft(pathElems[4])) {
|
|
476
|
-
return true;
|
|
477
|
-
}
|
|
478
|
-
if (pathElems.length >= 4 &&
|
|
479
|
-
pathElems.length <= 6 &&
|
|
480
|
-
48 + h == pathElems[0] &&
|
|
481
|
-
[0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
|
|
482
|
-
hard(pathElems[2]) &&
|
|
483
|
-
hard(pathElems[3]) &&
|
|
484
|
-
change(pathElems[4]) &&
|
|
485
|
-
soft(pathElems[5])) {
|
|
486
|
-
return true;
|
|
487
|
-
}
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
444
|
//# sourceMappingURL=BtcNew.js.map
|