@ledgerhq/hw-app-btc 8.1.2-nightly.1 → 9.0.0-nightly.2
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 +6 -0
- package/README.md +33 -111
- package/lib/Btc.d.ts +11 -13
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +31 -191
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +2 -4
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +54 -13
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.d.ts +2 -37
- package/lib/BtcOld.d.ts.map +1 -1
- package/lib/BtcOld.js +3 -45
- package/lib/BtcOld.js.map +1 -1
- package/lib-es/Btc.d.ts +11 -13
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +31 -168
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +2 -4
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +54 -8
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.d.ts +2 -37
- package/lib-es/BtcOld.d.ts.map +1 -1
- package/lib-es/BtcOld.js +3 -45
- package/lib-es/BtcOld.js.map +1 -1
- package/package.json +1 -1
- package/src/Btc.ts +41 -151
- package/src/BtcNew.ts +60 -15
- package/src/BtcOld.ts +4 -59
- package/tests/Btc.test.ts +16 -132
- package/tests/newops/BtcNew.test.ts +0 -5
- package/tests/newops/integrationtools.ts +4 -4
- package/tests/parseTx.test.ts +1 -1
- package/tests/trustedInputs.test.ts +6 -8
package/lib/BtcOld.js
CHANGED
|
@@ -55,15 +55,13 @@ 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");
|
|
60
58
|
var bip32_1 = require("./bip32");
|
|
61
59
|
/**
|
|
62
60
|
* Bitcoin API.
|
|
63
61
|
*
|
|
64
62
|
* @example
|
|
65
63
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
66
|
-
* const btc = new Btc(transport)
|
|
64
|
+
* const btc = new Btc({ transport, currency: "zcash" });
|
|
67
65
|
*/
|
|
68
66
|
var BtcOld = /** @class */ (function () {
|
|
69
67
|
function BtcOld(transport) {
|
|
@@ -139,21 +137,6 @@ var BtcOld = /** @class */ (function () {
|
|
|
139
137
|
}
|
|
140
138
|
return (0, getWalletPublicKey_1.getWalletPublicKey)(this.transport, __assign(__assign({}, opts), { path: path }));
|
|
141
139
|
};
|
|
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
|
-
};
|
|
157
140
|
/**
|
|
158
141
|
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
159
142
|
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
@@ -186,37 +169,12 @@ var BtcOld = /** @class */ (function () {
|
|
|
186
169
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
187
170
|
}).then(res => ...);
|
|
188
171
|
*/
|
|
189
|
-
BtcOld.prototype.
|
|
172
|
+
BtcOld.prototype.createPaymentTransaction = function (arg) {
|
|
190
173
|
if (arguments.length > 1) {
|
|
191
|
-
|
|
174
|
+
throw new Error("@ledgerhq/hw-app-btc: createPaymentTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
192
175
|
}
|
|
193
176
|
return (0, createTransaction_1.createTransaction)(this.transport, arg);
|
|
194
177
|
};
|
|
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
|
-
};
|
|
220
178
|
return BtcOld;
|
|
221
179
|
}());
|
|
222
180
|
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,
|
|
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;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M,CAAC;QACrC,gBAAgB,CAAC,OAAO,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;QACpB,iBAAiB;QACjB,WAAW;QACX,SAAS;QACT,MAAM;KACP,CAAC,CAAC;IACH,IAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvD,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,7 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
-
import BtcNew from "./BtcNew";
|
|
4
|
-
import BtcOld from "./BtcOld";
|
|
5
3
|
import type { CreateTransactionArg } from "./createTransaction";
|
|
6
4
|
import type { AddressFormat } from "./getWalletPublicKey";
|
|
7
5
|
import type { SignP2SHTransactionArg } from "./signP2SHTransaction";
|
|
@@ -12,11 +10,16 @@ export type { AddressFormat };
|
|
|
12
10
|
*
|
|
13
11
|
* @example
|
|
14
12
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
15
|
-
* const btc = new Btc(transport)
|
|
13
|
+
* const btc = new Btc({ transport, currency: "bitcoin" });
|
|
16
14
|
*/
|
|
17
15
|
export default class Btc {
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
private _transport;
|
|
17
|
+
private _impl;
|
|
18
|
+
constructor({ transport, scrambleKey, currency, }: {
|
|
19
|
+
transport: Transport;
|
|
20
|
+
scrambleKey?: string;
|
|
21
|
+
currency?: string;
|
|
22
|
+
});
|
|
20
23
|
/**
|
|
21
24
|
* Get an XPUB with a ledger device
|
|
22
25
|
* @param arg derivation parameter
|
|
@@ -61,13 +64,13 @@ export default class Btc {
|
|
|
61
64
|
/**
|
|
62
65
|
* 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.
|
|
63
66
|
* @example
|
|
64
|
-
btc.
|
|
67
|
+
btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
65
68
|
var v = result['v'] + 27 + 4;
|
|
66
69
|
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
67
70
|
console.log("Signature : " + signature);
|
|
68
71
|
}).catch(function(ex) {console.log(ex);});
|
|
69
72
|
*/
|
|
70
|
-
|
|
73
|
+
signMessage(path: string, messageHex: string): Promise<{
|
|
71
74
|
v: number;
|
|
72
75
|
r: string;
|
|
73
76
|
s: string;
|
|
@@ -105,7 +108,7 @@ export default class Btc {
|
|
|
105
108
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
106
109
|
}).then(res => ...);
|
|
107
110
|
*/
|
|
108
|
-
|
|
111
|
+
createPaymentTransaction(arg: CreateTransactionArg): Promise<string>;
|
|
109
112
|
/**
|
|
110
113
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
111
114
|
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
@@ -140,10 +143,5 @@ export default class Btc {
|
|
|
140
143
|
serializeTransactionOutputs(t: Transaction): Buffer;
|
|
141
144
|
getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>;
|
|
142
145
|
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;
|
|
148
146
|
}
|
|
149
147
|
//# 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;AAGpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,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;AAI9B;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,KAAK,CAAkB;gBAEnB,EACV,SAAS,EACT,WAAmB,EACnB,QAAoB,GACrB,EAAE;QACD,SAAS,EAAE,SAAS,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,Q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,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;CAQV"}
|
package/lib-es/Btc.js
CHANGED
|
@@ -1,70 +1,39 @@
|
|
|
1
|
-
|
|
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";
|
|
1
|
+
import BtcNew from "./BtcNew";
|
|
39
2
|
import BtcOld from "./BtcOld";
|
|
40
|
-
import { getAppAndVersion } from "./getAppAndVersion";
|
|
41
3
|
import { getTrustedInput } from "./getTrustedInput";
|
|
42
4
|
import { getTrustedInputBIP143 } from "./getTrustedInputBIP143";
|
|
43
5
|
import { AppClient } from "./newops/appClient";
|
|
44
6
|
import { serializeTransactionOutputs } from "./serializeTransaction";
|
|
45
7
|
import { splitTransaction } from "./splitTransaction";
|
|
8
|
+
import { signP2SHTransaction } from "./signP2SHTransaction";
|
|
9
|
+
import { signMessage } from "./signMessage";
|
|
46
10
|
/**
|
|
47
11
|
* Bitcoin API.
|
|
48
12
|
*
|
|
49
13
|
* @example
|
|
50
14
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
51
|
-
* const btc = new Btc(transport)
|
|
15
|
+
* const btc = new Btc({ transport, currency: "bitcoin" });
|
|
52
16
|
*/
|
|
53
17
|
var Btc = /** @class */ (function () {
|
|
54
|
-
function Btc(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
this.transport = transport;
|
|
59
|
-
transport.decorateAppAPIMethods(this, [
|
|
18
|
+
function Btc(_a) {
|
|
19
|
+
var transport = _a.transport, _b = _a.scrambleKey, scrambleKey = _b === void 0 ? "BTC" : _b, _c = _a.currency, currency = _c === void 0 ? "bitcoin" : _c;
|
|
20
|
+
this._transport = transport;
|
|
21
|
+
this._transport.decorateAppAPIMethods(this, [
|
|
60
22
|
"getWalletXpub",
|
|
61
23
|
"getWalletPublicKey",
|
|
62
24
|
"signP2SHTransaction",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
25
|
+
"signMessage",
|
|
26
|
+
"createPaymentTransaction",
|
|
65
27
|
"getTrustedInput",
|
|
66
28
|
"getTrustedInputBIP143",
|
|
67
29
|
], 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
|
+
}
|
|
68
37
|
}
|
|
69
38
|
/**
|
|
70
39
|
* Get an XPUB with a ledger device
|
|
@@ -74,7 +43,7 @@ var Btc = /** @class */ (function () {
|
|
|
74
43
|
* @returns XPUB of the account
|
|
75
44
|
*/
|
|
76
45
|
Btc.prototype.getWalletXpub = function (arg) {
|
|
77
|
-
return this.
|
|
46
|
+
return this._impl.getWalletXpub(arg);
|
|
78
47
|
};
|
|
79
48
|
/**
|
|
80
49
|
* @param path a BIP 32 path
|
|
@@ -99,7 +68,6 @@ var Btc = /** @class */ (function () {
|
|
|
99
68
|
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
100
69
|
*/
|
|
101
70
|
Btc.prototype.getWalletPublicKey = function (path, opts) {
|
|
102
|
-
var _this = this;
|
|
103
71
|
var options;
|
|
104
72
|
if (arguments.length > 2 || typeof opts === "boolean") {
|
|
105
73
|
console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
|
|
@@ -112,53 +80,22 @@ var Btc = /** @class */ (function () {
|
|
|
112
80
|
else {
|
|
113
81
|
options = opts || {};
|
|
114
82
|
}
|
|
115
|
-
return this.
|
|
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
|
-
});
|
|
83
|
+
return this._impl.getWalletPublicKey(path, options);
|
|
150
84
|
};
|
|
151
85
|
/**
|
|
152
86
|
* 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.
|
|
153
87
|
* @example
|
|
154
|
-
btc.
|
|
88
|
+
btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
155
89
|
var v = result['v'] + 27 + 4;
|
|
156
90
|
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
157
91
|
console.log("Signature : " + signature);
|
|
158
92
|
}).catch(function(ex) {console.log(ex);});
|
|
159
93
|
*/
|
|
160
|
-
Btc.prototype.
|
|
161
|
-
return this.
|
|
94
|
+
Btc.prototype.signMessage = function (path, messageHex) {
|
|
95
|
+
return signMessage(this._transport, {
|
|
96
|
+
path: path,
|
|
97
|
+
messageHex: messageHex
|
|
98
|
+
});
|
|
162
99
|
};
|
|
163
100
|
/**
|
|
164
101
|
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
@@ -193,13 +130,11 @@ var Btc = /** @class */ (function () {
|
|
|
193
130
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
194
131
|
}).then(res => ...);
|
|
195
132
|
*/
|
|
196
|
-
Btc.prototype.
|
|
133
|
+
Btc.prototype.createPaymentTransaction = function (arg) {
|
|
197
134
|
if (arguments.length > 1) {
|
|
198
|
-
|
|
135
|
+
throw new Error("@ledgerhq/hw-app-btc: createPaymentTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
199
136
|
}
|
|
200
|
-
return this.
|
|
201
|
-
return impl.createPaymentTransactionNew(arg);
|
|
202
|
-
});
|
|
137
|
+
return this._impl.createPaymentTransaction(arg);
|
|
203
138
|
};
|
|
204
139
|
/**
|
|
205
140
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
@@ -221,7 +156,7 @@ var Btc = /** @class */ (function () {
|
|
|
221
156
|
}).then(result => ...);
|
|
222
157
|
*/
|
|
223
158
|
Btc.prototype.signP2SHTransaction = function (arg) {
|
|
224
|
-
return this.
|
|
159
|
+
return signP2SHTransaction(this._transport, arg);
|
|
225
160
|
};
|
|
226
161
|
/**
|
|
227
162
|
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.
|
|
@@ -245,85 +180,13 @@ var Btc = /** @class */ (function () {
|
|
|
245
180
|
};
|
|
246
181
|
Btc.prototype.getTrustedInput = function (indexLookup, transaction, additionals) {
|
|
247
182
|
if (additionals === void 0) { additionals = []; }
|
|
248
|
-
return getTrustedInput(this.
|
|
183
|
+
return getTrustedInput(this._transport, indexLookup, transaction, additionals);
|
|
249
184
|
};
|
|
250
185
|
Btc.prototype.getTrustedInputBIP143 = function (indexLookup, transaction, additionals) {
|
|
251
186
|
if (additionals === void 0) { additionals = []; }
|
|
252
|
-
return getTrustedInputBIP143(this.
|
|
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));
|
|
187
|
+
return getTrustedInputBIP143(this._transport, indexLookup, transaction, additionals);
|
|
297
188
|
};
|
|
298
189
|
return Btc;
|
|
299
190
|
}());
|
|
300
191
|
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
|
-
}
|
|
329
192
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,C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,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,CACZ,CAAC;IACJ,CAAC;IAED;;;;MAIE;IACF,yCAA2B,GAA3B,UAA4B,CAAc;QACxC,OAAO,2BAA2B,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,6BAAe,GAAf,UACE,WAAmB,EACnB,WAAwB,EACxB,WAA+B;QAA/B,4BAAA,EAAA,gBAA+B;QAE/B,OAAO,eAAe,CACpB,IAAI,CAAC,UAAU,EACf,WAAW,EACX,WAAW,EACX,WAAW,CACZ,CAAC;IACJ,CAAC;IAED,mCAAqB,GAArB,UACE,WAAmB,EACnB,WAAwB,EACxB,WAA+B;QAA/B,4BAAA,EAAA,gBAA+B;QAE/B,OAAO,qBAAqB,CAC1B,IAAI,CAAC,UAAU,EACf,WAAW,EACX,WAAW,EACX,WAAW,CACZ,CAAC;IACJ,CAAC;IACH,UAAC;AAAD,CAAC,AA9OD,IA8OC"}
|
package/lib-es/BtcNew.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { CreateTransactionArg } from "./createTransaction";
|
|
2
|
-
import { AppAndVersion } from "./getAppAndVersion";
|
|
3
2
|
import type { AddressFormat } from "./getWalletPublicKey";
|
|
4
3
|
import { AppClient as Client } from "./newops/appClient";
|
|
5
|
-
export declare function canSupportApp(appAndVersion: AppAndVersion): boolean;
|
|
6
4
|
/**
|
|
7
5
|
* This class implements the same interface as BtcOld (formerly
|
|
8
6
|
* named Btc), but interacts with Bitcoin hardware app version 2+
|
|
@@ -85,14 +83,14 @@ export default class BtcNew {
|
|
|
85
83
|
*/
|
|
86
84
|
private getWalletAddress;
|
|
87
85
|
/**
|
|
88
|
-
* Build and sign a transaction. See Btc.
|
|
86
|
+
* Build and sign a transaction. See Btc.createPaymentTransaction for
|
|
89
87
|
* details on how to use this method.
|
|
90
88
|
*
|
|
91
89
|
* This method will convert the legacy arguments, CreateTransactionArg, into
|
|
92
90
|
* a psbt which is finally signed and finalized, and the extracted fully signed
|
|
93
91
|
* transaction is returned.
|
|
94
92
|
*/
|
|
95
|
-
|
|
93
|
+
createPaymentTransaction(arg: CreateTransactionArg): Promise<string>;
|
|
96
94
|
/**
|
|
97
95
|
* Calculates an output script along with public key and possible redeemScript
|
|
98
96
|
* 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":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAYzD;;;;;;;;;;;;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;IAyBF;;;;;;;;;;;;;;OAcG;YACW,gBAAgB;IAyB9B;;;;;;;OAOG;IACG,wBAAwB,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;IAiH1E;;;;;;;OAOG;YACW,cAAc;IAsB5B;;;;OAIG;YACW,QAAQ;IAmDtB;;;;;;;;OAQG;YACW,QAAQ;CA6BvB"}
|
package/lib-es/BtcNew.js
CHANGED
|
@@ -35,7 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import { crypto } from "bitcoinjs-lib";
|
|
38
|
-
import semver from "semver";
|
|
39
38
|
import { pointCompress } from "tiny-secp256k1";
|
|
40
39
|
import { getXpubComponents, hardenedPathOf, pathArrayToString, pathStringToArray, pubkeyFromXpub, } from "./bip32";
|
|
41
40
|
import { BufferReader } from "./buffertools";
|
|
@@ -45,11 +44,6 @@ import { extract } from "./newops/psbtExtractor";
|
|
|
45
44
|
import { finalize } from "./newops/psbtFinalizer";
|
|
46
45
|
import { psbtIn, PsbtV2 } from "./newops/psbtv2";
|
|
47
46
|
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
|
-
}
|
|
53
47
|
/**
|
|
54
48
|
* This class implements the same interface as BtcOld (formerly
|
|
55
49
|
* named Btc), but interacts with Bitcoin hardware app version 2+
|
|
@@ -131,6 +125,9 @@ var BtcNew = /** @class */ (function () {
|
|
|
131
125
|
return __generator(this, function (_c) {
|
|
132
126
|
switch (_c.label) {
|
|
133
127
|
case 0:
|
|
128
|
+
if (!isPathNormal(path)) {
|
|
129
|
+
throw Error("non-standard path: ".concat(path));
|
|
130
|
+
}
|
|
134
131
|
pathElements = pathStringToArray(path);
|
|
135
132
|
return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
|
|
136
133
|
case 1:
|
|
@@ -189,14 +186,14 @@ var BtcNew = /** @class */ (function () {
|
|
|
189
186
|
});
|
|
190
187
|
};
|
|
191
188
|
/**
|
|
192
|
-
* Build and sign a transaction. See Btc.
|
|
189
|
+
* Build and sign a transaction. See Btc.createPaymentTransaction for
|
|
193
190
|
* details on how to use this method.
|
|
194
191
|
*
|
|
195
192
|
* This method will convert the legacy arguments, CreateTransactionArg, into
|
|
196
193
|
* a psbt which is finally signed and finalized, and the extracted fully signed
|
|
197
194
|
* transaction is returned.
|
|
198
195
|
*/
|
|
199
|
-
BtcNew.prototype.
|
|
196
|
+
BtcNew.prototype.createPaymentTransaction = function (arg) {
|
|
200
197
|
return __awaiter(this, void 0, void 0, function () {
|
|
201
198
|
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;
|
|
202
199
|
return __generator(this, function (_a) {
|
|
@@ -441,4 +438,53 @@ function accountTypeFromArg(arg, psbt, masterFp) {
|
|
|
441
438
|
return new p2wpkhWrapped(psbt, masterFp);
|
|
442
439
|
return new p2pkh(psbt, masterFp);
|
|
443
440
|
}
|
|
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
|
+
}
|
|
444
490
|
//# sourceMappingURL=BtcNew.js.map
|