@ledgerhq/hw-app-btc 9.0.1-nightly.0 → 9.1.0-next.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 +15 -2
- package/README.md +33 -111
- package/lib/Btc.d.ts +12 -11
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +47 -143
- 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/getAppAndVersion.d.ts +1 -0
- package/lib/getAppAndVersion.d.ts.map +1 -1
- package/lib/getAppAndVersion.js +21 -1
- package/lib/getAppAndVersion.js.map +1 -1
- package/lib-es/Btc.d.ts +12 -11
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +47 -120
- 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/lib-es/getAppAndVersion.d.ts +1 -0
- package/lib-es/getAppAndVersion.d.ts.map +1 -1
- package/lib-es/getAppAndVersion.js +19 -0
- package/lib-es/getAppAndVersion.js.map +1 -1
- package/package.json +4 -4
- package/src/Btc.ts +54 -146
- package/src/BtcNew.ts +60 -15
- package/src/BtcOld.ts +4 -59
- package/src/getAppAndVersion.ts +12 -0
- package/tests/{Btc.test.ts → Btc.test.ts.disabled} +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 → trustedInputs.test.ts.disabled} +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,GA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buffer;
|
|
7
7
|
};
|
|
8
8
|
export declare const getAppAndVersion: (transport: Transport) => Promise<AppAndVersion>;
|
|
9
|
+
export declare const checkIsBtcLegacy: (transport: Transport) => Promise<boolean>;
|
|
9
10
|
//# sourceMappingURL=getAppAndVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAppAndVersion.d.ts","sourceRoot":"","sources":["../src/getAppAndVersion.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAChB,SAAS,KACnB,QAAQ,aAAa,CAgBvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"getAppAndVersion.d.ts","sourceRoot":"","sources":["../src/getAppAndVersion.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAChB,SAAS,KACnB,QAAQ,aAAa,CAgBvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAChB,SAAS,KACnB,QAAQ,OAAO,CAQjB,CAAC"}
|
package/lib/getAppAndVersion.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
exports.__esModule = true;
|
|
42
|
-
exports.getAppAndVersion = void 0;
|
|
42
|
+
exports.checkIsBtcLegacy = exports.getAppAndVersion = void 0;
|
|
43
43
|
var invariant_1 = __importDefault(require("invariant"));
|
|
44
44
|
var getAppAndVersion = function (transport) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
45
|
var r, i, format, nameLength, name, versionLength, version, flagLength, flags;
|
|
@@ -66,4 +66,24 @@ var getAppAndVersion = function (transport) { return __awaiter(void 0, void 0, v
|
|
|
66
66
|
});
|
|
67
67
|
}); };
|
|
68
68
|
exports.getAppAndVersion = getAppAndVersion;
|
|
69
|
+
var checkIsBtcLegacy = function (transport) { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
var e_1;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
_a.trys.push([0, 2, , 3]);
|
|
75
|
+
// Call old btc API, it will throw an exception with new btc app. It is a workaround to differentiate new/old btc nano app
|
|
76
|
+
return [4 /*yield*/, transport.send(0xe0, 0xc4, 0, 0)];
|
|
77
|
+
case 1:
|
|
78
|
+
// Call old btc API, it will throw an exception with new btc app. It is a workaround to differentiate new/old btc nano app
|
|
79
|
+
_a.sent();
|
|
80
|
+
return [3 /*break*/, 3];
|
|
81
|
+
case 2:
|
|
82
|
+
e_1 = _a.sent();
|
|
83
|
+
return [2 /*return*/, false];
|
|
84
|
+
case 3: return [2 /*return*/, true];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); };
|
|
88
|
+
exports.checkIsBtcLegacy = checkIsBtcLegacy;
|
|
69
89
|
//# sourceMappingURL=getAppAndVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAppAndVersion.js","sourceRoot":"","sources":["../src/getAppAndVersion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAkC;AAS3B,IAAM,gBAAgB,GAAG,UAC9B,SAAoB;;;;oBAEV,qBAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAA;;gB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,CAAC;gBACtB,IAAA,sBAAS,EAAC,MAAM,KAAK,CAAC,EAAE,wCAAwC,CAAC,CAAC;gBAC5D,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACvD,aAAa,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACvB,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBAC7D,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC;gBAC5C,sBAAO;wBACL,IAAI,MAAA;wBACJ,OAAO,SAAA;wBACP,KAAK,OAAA;qBACN,EAAC;;;KACH,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B;AAEK,IAAM,gBAAgB,GAAG,UAC9B,SAAoB;;;;;;gBAGlB,0HAA0H;gBAC1H,qBAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAA;;gBADtC,0HAA0H;gBAC1H,SAAsC,CAAC;;;;gBAEvC,sBAAO,KAAK,EAAC;oBAEf,sBAAO,IAAI,EAAC;;;KACb,CAAC;AAVW,QAAA,gBAAgB,oBAU3B"}
|
package/lib-es/Btc.d.ts
CHANGED
|
@@ -12,11 +12,16 @@ export type { AddressFormat };
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
15
|
-
* const btc = new Btc(transport)
|
|
15
|
+
* const btc = new Btc({ transport, currency: "bitcoin" });
|
|
16
16
|
*/
|
|
17
17
|
export default class Btc {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
private _transport;
|
|
19
|
+
private _impl;
|
|
20
|
+
constructor({ transport, scrambleKey, currency, }: {
|
|
21
|
+
transport: Transport;
|
|
22
|
+
scrambleKey?: string;
|
|
23
|
+
currency?: string;
|
|
24
|
+
});
|
|
20
25
|
/**
|
|
21
26
|
* Get an XPUB with a ledger device
|
|
22
27
|
* @param arg derivation parameter
|
|
@@ -61,13 +66,13 @@ export default class Btc {
|
|
|
61
66
|
/**
|
|
62
67
|
* 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
68
|
* @example
|
|
64
|
-
btc.
|
|
69
|
+
btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
65
70
|
var v = result['v'] + 27 + 4;
|
|
66
71
|
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
67
72
|
console.log("Signature : " + signature);
|
|
68
73
|
}).catch(function(ex) {console.log(ex);});
|
|
69
74
|
*/
|
|
70
|
-
|
|
75
|
+
signMessage(path: string, messageHex: string): Promise<{
|
|
71
76
|
v: number;
|
|
72
77
|
r: string;
|
|
73
78
|
s: string;
|
|
@@ -105,7 +110,7 @@ export default class Btc {
|
|
|
105
110
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
106
111
|
}).then(res => ...);
|
|
107
112
|
*/
|
|
108
|
-
|
|
113
|
+
createPaymentTransaction(arg: CreateTransactionArg): Promise<string>;
|
|
109
114
|
/**
|
|
110
115
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
111
116
|
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
@@ -140,10 +145,6 @@ export default class Btc {
|
|
|
140
145
|
serializeTransactionOutputs(t: Transaction): Buffer;
|
|
141
146
|
getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>;
|
|
142
147
|
getTrustedInputBIP143(indexLookup: number, transaction: Transaction, additionals?: Array<string>): string;
|
|
143
|
-
|
|
144
|
-
private getCorrectImpl;
|
|
145
|
-
private inferCorrectImpl;
|
|
146
|
-
protected old(): BtcOld;
|
|
147
|
-
protected new(): BtcNew;
|
|
148
|
+
changeImplIfNecessary(): Promise<BtcOld | BtcNew>;
|
|
148
149
|
}
|
|
149
150
|
//# 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;AACpD,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,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;AAK9B;;;;;;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,QAAQ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AE,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;IASH,qBAAqB,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;CAUxD"}
|
package/lib-es/Btc.js
CHANGED
|
@@ -34,37 +34,43 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import
|
|
38
|
-
import BtcNew, { canSupportApp } from "./BtcNew";
|
|
37
|
+
import BtcNew from "./BtcNew";
|
|
39
38
|
import BtcOld from "./BtcOld";
|
|
40
|
-
import { getAppAndVersion } from "./getAppAndVersion";
|
|
41
39
|
import { getTrustedInput } from "./getTrustedInput";
|
|
42
40
|
import { getTrustedInputBIP143 } from "./getTrustedInputBIP143";
|
|
43
41
|
import { AppClient } from "./newops/appClient";
|
|
44
42
|
import { serializeTransactionOutputs } from "./serializeTransaction";
|
|
45
43
|
import { splitTransaction } from "./splitTransaction";
|
|
44
|
+
import { signP2SHTransaction } from "./signP2SHTransaction";
|
|
45
|
+
import { signMessage } from "./signMessage";
|
|
46
|
+
import { checkIsBtcLegacy, getAppAndVersion } from "./getAppAndVersion";
|
|
46
47
|
/**
|
|
47
48
|
* Bitcoin API.
|
|
48
49
|
*
|
|
49
50
|
* @example
|
|
50
51
|
* import Btc from "@ledgerhq/hw-app-btc";
|
|
51
|
-
* const btc = new Btc(transport)
|
|
52
|
+
* const btc = new Btc({ transport, currency: "bitcoin" });
|
|
52
53
|
*/
|
|
53
54
|
var Btc = /** @class */ (function () {
|
|
54
|
-
function Btc(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
this.transport = transport;
|
|
59
|
-
transport.decorateAppAPIMethods(this, [
|
|
55
|
+
function Btc(_a) {
|
|
56
|
+
var transport = _a.transport, _b = _a.scrambleKey, scrambleKey = _b === void 0 ? "BTC" : _b, _c = _a.currency, currency = _c === void 0 ? "bitcoin" : _c;
|
|
57
|
+
this._transport = transport;
|
|
58
|
+
this._transport.decorateAppAPIMethods(this, [
|
|
60
59
|
"getWalletXpub",
|
|
61
60
|
"getWalletPublicKey",
|
|
62
61
|
"signP2SHTransaction",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
62
|
+
"signMessage",
|
|
63
|
+
"createPaymentTransaction",
|
|
65
64
|
"getTrustedInput",
|
|
66
65
|
"getTrustedInputBIP143",
|
|
67
66
|
], scrambleKey);
|
|
67
|
+
// new APDU (nano app API) for bitcoin and old APDU for altcoin
|
|
68
|
+
if (currency === "bitcoin" || currency === "bitcoin_testnet") {
|
|
69
|
+
this._impl = new BtcNew(new AppClient(this._transport));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this._impl = new BtcOld(this._transport);
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
/**
|
|
70
76
|
* Get an XPUB with a ledger device
|
|
@@ -74,7 +80,9 @@ var Btc = /** @class */ (function () {
|
|
|
74
80
|
* @returns XPUB of the account
|
|
75
81
|
*/
|
|
76
82
|
Btc.prototype.getWalletXpub = function (arg) {
|
|
77
|
-
return this.
|
|
83
|
+
return this.changeImplIfNecessary().then(function (impl) {
|
|
84
|
+
return impl.getWalletXpub(arg);
|
|
85
|
+
});
|
|
78
86
|
};
|
|
79
87
|
/**
|
|
80
88
|
* @param path a BIP 32 path
|
|
@@ -99,7 +107,6 @@ var Btc = /** @class */ (function () {
|
|
|
99
107
|
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
100
108
|
*/
|
|
101
109
|
Btc.prototype.getWalletPublicKey = function (path, opts) {
|
|
102
|
-
var _this = this;
|
|
103
110
|
var options;
|
|
104
111
|
if (arguments.length > 2 || typeof opts === "boolean") {
|
|
105
112
|
console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
|
|
@@ -112,53 +119,24 @@ var Btc = /** @class */ (function () {
|
|
|
112
119
|
else {
|
|
113
120
|
options = opts || {};
|
|
114
121
|
}
|
|
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
|
-
}
|
|
122
|
+
return this.changeImplIfNecessary().then(function (impl) {
|
|
123
|
+
return impl.getWalletPublicKey(path, options);
|
|
149
124
|
});
|
|
150
125
|
};
|
|
151
126
|
/**
|
|
152
127
|
* 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
128
|
* @example
|
|
154
|
-
btc.
|
|
129
|
+
btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
155
130
|
var v = result['v'] + 27 + 4;
|
|
156
131
|
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
157
132
|
console.log("Signature : " + signature);
|
|
158
133
|
}).catch(function(ex) {console.log(ex);});
|
|
159
134
|
*/
|
|
160
|
-
Btc.prototype.
|
|
161
|
-
return this.
|
|
135
|
+
Btc.prototype.signMessage = function (path, messageHex) {
|
|
136
|
+
return signMessage(this._transport, {
|
|
137
|
+
path: path,
|
|
138
|
+
messageHex: messageHex
|
|
139
|
+
});
|
|
162
140
|
};
|
|
163
141
|
/**
|
|
164
142
|
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
@@ -193,12 +171,12 @@ var Btc = /** @class */ (function () {
|
|
|
193
171
|
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
194
172
|
}).then(res => ...);
|
|
195
173
|
*/
|
|
196
|
-
Btc.prototype.
|
|
174
|
+
Btc.prototype.createPaymentTransaction = function (arg) {
|
|
197
175
|
if (arguments.length > 1) {
|
|
198
|
-
|
|
176
|
+
throw new Error("@ledgerhq/hw-app-btc: createPaymentTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
199
177
|
}
|
|
200
|
-
return this.
|
|
201
|
-
return impl.
|
|
178
|
+
return this.changeImplIfNecessary().then(function (impl) {
|
|
179
|
+
return impl.createPaymentTransaction(arg);
|
|
202
180
|
});
|
|
203
181
|
};
|
|
204
182
|
/**
|
|
@@ -221,7 +199,7 @@ var Btc = /** @class */ (function () {
|
|
|
221
199
|
}).then(result => ...);
|
|
222
200
|
*/
|
|
223
201
|
Btc.prototype.signP2SHTransaction = function (arg) {
|
|
224
|
-
return this.
|
|
202
|
+
return signP2SHTransaction(this._transport, arg);
|
|
225
203
|
};
|
|
226
204
|
/**
|
|
227
205
|
* 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 +223,34 @@ var Btc = /** @class */ (function () {
|
|
|
245
223
|
};
|
|
246
224
|
Btc.prototype.getTrustedInput = function (indexLookup, transaction, additionals) {
|
|
247
225
|
if (additionals === void 0) { additionals = []; }
|
|
248
|
-
return getTrustedInput(this.
|
|
226
|
+
return getTrustedInput(this._transport, indexLookup, transaction, additionals);
|
|
249
227
|
};
|
|
250
228
|
Btc.prototype.getTrustedInputBIP143 = function (indexLookup, transaction, additionals) {
|
|
251
229
|
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
|
-
});
|
|
230
|
+
return getTrustedInputBIP143(this._transport, indexLookup, transaction, additionals);
|
|
271
231
|
};
|
|
272
|
-
Btc.prototype.
|
|
232
|
+
Btc.prototype.changeImplIfNecessary = function () {
|
|
273
233
|
return __awaiter(this, void 0, void 0, function () {
|
|
274
|
-
var appAndVersion,
|
|
234
|
+
var appAndVersion, isBtcLegacy;
|
|
275
235
|
return __generator(this, function (_a) {
|
|
276
236
|
switch (_a.label) {
|
|
277
|
-
case 0: return [4 /*yield*/, getAppAndVersion(this.
|
|
237
|
+
case 0: return [4 /*yield*/, getAppAndVersion(this._transport)];
|
|
278
238
|
case 1:
|
|
279
239
|
appAndVersion = _a.sent();
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
240
|
+
if (!(appAndVersion.name === "Exchange" && this._impl instanceof BtcNew)) return [3 /*break*/, 3];
|
|
241
|
+
return [4 /*yield*/, checkIsBtcLegacy(this._transport)];
|
|
242
|
+
case 2:
|
|
243
|
+
isBtcLegacy = _a.sent();
|
|
244
|
+
if (isBtcLegacy) {
|
|
245
|
+
this._impl = new BtcOld(this._transport);
|
|
283
246
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
return [2 /*return*/];
|
|
247
|
+
_a.label = 3;
|
|
248
|
+
case 3: return [2 /*return*/, this._impl];
|
|
288
249
|
}
|
|
289
250
|
});
|
|
290
251
|
});
|
|
291
252
|
};
|
|
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));
|
|
297
|
-
};
|
|
298
253
|
return Btc;
|
|
299
254
|
}());
|
|
300
255
|
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
256
|
//# 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,
|
|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AAa,GAAG,SAAuC;6BACzD,CAAA,aAAa,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,KAAK,YAAY,MAAM,CAAA,EAAjE,wBAAiE;wBAC/C,qBAAM,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAA;;wBAArD,WAAW,GAAG,SAAuC;wBAC3D,IAAI,WAAW,EAAE;4BACf,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;yBAC1C;;4BAEH,sBAAO,IAAI,CAAC,KAAK,EAAC;;;;KACnB;IACH,UAAC;AAAD,CAAC,AA/PD,IA+PC"}
|
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"}
|