@metamask/eth-ledger-bridge-keyring 7.0.0 → 8.0.1
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/CHANGELOG.md +17 -1
- package/dist/ledger-bridge.cjs +1 -0
- package/dist/ledger-bridge.cjs.map +1 -1
- package/dist/ledger-bridge.d.cts +2 -2
- package/dist/ledger-bridge.d.cts.map +1 -1
- package/dist/ledger-bridge.d.mts +2 -2
- package/dist/ledger-bridge.d.mts.map +1 -1
- package/dist/ledger-bridge.mjs +2 -1
- package/dist/ledger-bridge.mjs.map +1 -1
- package/dist/ledger-keyring.cjs +21 -5
- package/dist/ledger-keyring.cjs.map +1 -1
- package/dist/ledger-keyring.d.cts.map +1 -1
- package/dist/ledger-keyring.d.mts.map +1 -1
- package/dist/ledger-keyring.mjs +22 -7
- package/dist/ledger-keyring.mjs.map +1 -1
- package/dist/ledger-mobile-bridge.cjs +8 -10
- package/dist/ledger-mobile-bridge.cjs.map +1 -1
- package/dist/ledger-mobile-bridge.d.cts +2 -3
- package/dist/ledger-mobile-bridge.d.cts.map +1 -1
- package/dist/ledger-mobile-bridge.d.mts +2 -3
- package/dist/ledger-mobile-bridge.d.mts.map +1 -1
- package/dist/ledger-mobile-bridge.mjs +8 -14
- package/dist/ledger-mobile-bridge.mjs.map +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [8.0.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Use `ts-bridge/cli@0.6.1` ([#118](https://github.com/MetaMask/accounts/pull/118))
|
|
15
|
+
- This new version fixes a bug with CJS re-exports.
|
|
16
|
+
|
|
17
|
+
## [8.0.0]
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **BREAKING:** Enable Ledger clear signing ([#99](https://github.com/MetaMask/accounts/pull/99))
|
|
22
|
+
- The `LedgerSignTypedDataParams` type now requires a new `message` field which replaces the `domainSeparatorHex` and `hashStructMessage}Hex` fields.
|
|
23
|
+
|
|
10
24
|
## [7.0.0]
|
|
11
25
|
|
|
12
26
|
### Added
|
|
@@ -216,7 +230,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
216
230
|
|
|
217
231
|
- Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
|
|
218
232
|
|
|
219
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@
|
|
233
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.1...HEAD
|
|
234
|
+
[8.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@8.0.0...@metamask/eth-ledger-bridge-keyring@8.0.1
|
|
235
|
+
[8.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@7.0.0...@metamask/eth-ledger-bridge-keyring@8.0.0
|
|
220
236
|
[7.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@6.0.0...@metamask/eth-ledger-bridge-keyring@7.0.0
|
|
221
237
|
[6.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@5.0.1...@metamask/eth-ledger-bridge-keyring@6.0.0
|
|
222
238
|
[5.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@5.0.0...@metamask/eth-ledger-bridge-keyring@5.0.1
|
package/dist/ledger-bridge.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.cjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n
|
|
1
|
+
{"version":3,"file":"ledger-bridge.cjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":";;AAEA,qDAAqD","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\nimport { EIP712Message } from '@ledgerhq/types-live';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n message: EIP712Message;\n};\nexport type LedgerSignTypedDataResponse = Awaited<\n ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>\n>;\n\nexport type LedgerBridgeOptions = Record<string, unknown>;\n\nexport type LedgerBridge<T extends LedgerBridgeOptions> = {\n isDeviceConnected: boolean;\n\n init(): Promise<void>;\n\n destroy(): Promise<void>;\n\n /**\n * Method to get the current configuration of the ledger bridge keyring.\n */\n getOptions(): Promise<T>;\n\n /**\n * Method to set the current configuration of the ledger bridge keyring.\n *\n * @param opts - An object contains configuration of the bridge.\n */\n setOptions(opts: T): Promise<void>;\n\n attemptMakeApp(): Promise<boolean>;\n\n updateTransportMethod(transportType: string | Transport): Promise<boolean>;\n\n getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;\n\n deviceSignTransaction(\n params: LedgerSignTransactionParams,\n ): Promise<LedgerSignTransactionResponse>;\n\n deviceSignMessage(\n params: LedgerSignMessageParams,\n ): Promise<LedgerSignMessageResponse>;\n\n deviceSignTypedData(\n params: LedgerSignTypedDataParams,\n ): Promise<LedgerSignTypedDataResponse>;\n};\n"]}
|
package/dist/ledger-bridge.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type LedgerHwAppEth from "@ledgerhq/hw-app-eth";
|
|
2
2
|
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import { EIP712Message } from "@ledgerhq/types-live";
|
|
3
4
|
export type GetPublicKeyParams = {
|
|
4
5
|
hdPath: string;
|
|
5
6
|
};
|
|
@@ -16,8 +17,7 @@ export type LedgerSignMessageParams = {
|
|
|
16
17
|
export type LedgerSignMessageResponse = Awaited<ReturnType<LedgerHwAppEth['signPersonalMessage']>>;
|
|
17
18
|
export type LedgerSignTypedDataParams = {
|
|
18
19
|
hdPath: string;
|
|
19
|
-
|
|
20
|
-
hashStructMessageHex: string;
|
|
20
|
+
message: EIP712Message;
|
|
21
21
|
};
|
|
22
22
|
export type LedgerSignTypedDataResponse = Awaited<ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>>;
|
|
23
23
|
export type LedgerBridgeOptions = Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,6BAA6B;AACvD,OAAO,KAAK,SAAS,+BAA+B;
|
|
1
|
+
{"version":3,"file":"ledger-bridge.d.cts","source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I,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzB;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnC,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE,qBAAqB,CACnB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAE1C,iBAAiB,CACf,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC,mBAAmB,CACjB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,2BAA2B,CAAC,CAAC;CACzC,CAAC"}
|
package/dist/ledger-bridge.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type LedgerHwAppEth from "@ledgerhq/hw-app-eth";
|
|
2
2
|
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import { EIP712Message } from "@ledgerhq/types-live";
|
|
3
4
|
export type GetPublicKeyParams = {
|
|
4
5
|
hdPath: string;
|
|
5
6
|
};
|
|
@@ -16,8 +17,7 @@ export type LedgerSignMessageParams = {
|
|
|
16
17
|
export type LedgerSignMessageResponse = Awaited<ReturnType<LedgerHwAppEth['signPersonalMessage']>>;
|
|
17
18
|
export type LedgerSignTypedDataParams = {
|
|
18
19
|
hdPath: string;
|
|
19
|
-
|
|
20
|
-
hashStructMessageHex: string;
|
|
20
|
+
message: EIP712Message;
|
|
21
21
|
};
|
|
22
22
|
export type LedgerSignTypedDataResponse = Awaited<ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>>;
|
|
23
23
|
export type LedgerBridgeOptions = Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,6BAA6B;AACvD,OAAO,KAAK,SAAS,+BAA+B;
|
|
1
|
+
{"version":3,"file":"ledger-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,6BAA6B;AACvD,OAAO,KAAK,SAAS,+BAA+B;AACpD,OAAO,EAAE,aAAa,EAAE,6BAA6B;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AACpD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACxC,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CACzC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AACzE,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAC9C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1E,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,UAAU,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC,CAClD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG,OAAO,CAC/C,UAAU,CAAC,cAAc,CAAC,yBAAyB,CAAC,CAAC,CACtD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAAI;IACxD,iBAAiB,EAAE,OAAO,CAAC;IAE3B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzB;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnC,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE,qBAAqB,CACnB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAE1C,iBAAiB,CACf,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC,mBAAmB,CACjB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,2BAA2B,CAAC,CAAC;CACzC,CAAC"}
|
package/dist/ledger-bridge.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.mjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n
|
|
1
|
+
{"version":3,"file":"ledger-bridge.mjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\nimport { EIP712Message } from '@ledgerhq/types-live';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n message: EIP712Message;\n};\nexport type LedgerSignTypedDataResponse = Awaited<\n ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>\n>;\n\nexport type LedgerBridgeOptions = Record<string, unknown>;\n\nexport type LedgerBridge<T extends LedgerBridgeOptions> = {\n isDeviceConnected: boolean;\n\n init(): Promise<void>;\n\n destroy(): Promise<void>;\n\n /**\n * Method to get the current configuration of the ledger bridge keyring.\n */\n getOptions(): Promise<T>;\n\n /**\n * Method to set the current configuration of the ledger bridge keyring.\n *\n * @param opts - An object contains configuration of the bridge.\n */\n setOptions(opts: T): Promise<void>;\n\n attemptMakeApp(): Promise<boolean>;\n\n updateTransportMethod(transportType: string | Transport): Promise<boolean>;\n\n getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;\n\n deviceSignTransaction(\n params: LedgerSignTransactionParams,\n ): Promise<LedgerSignTransactionResponse>;\n\n deviceSignMessage(\n params: LedgerSignMessageParams,\n ): Promise<LedgerSignMessageResponse>;\n\n deviceSignTypedData(\n params: LedgerSignTypedDataParams,\n ): Promise<LedgerSignTypedDataResponse>;\n};\n"]}
|
package/dist/ledger-keyring.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
30
30
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
|
-
var _LedgerKeyring_instances, _LedgerKeyring_migrateAccountDetails, _LedgerKeyring_signTransaction, _LedgerKeyring_getPage, _LedgerKeyring_getAccountsBIP44, _LedgerKeyring_getAccountsLegacy, _LedgerKeyring_addressFromIndex, _LedgerKeyring_pathFromAddress, _LedgerKeyring_getPathForIndex, _LedgerKeyring_isLedgerLiveHdPath, _LedgerKeyring_toLedgerPath, _LedgerKeyring_hasPreviousTransactions, _LedgerKeyring_getApiUrl;
|
|
33
|
+
var _LedgerKeyring_instances, _LedgerKeyring_migrateAccountDetails, _LedgerKeyring_signTransaction, _LedgerKeyring_convertSaltIfAny, _LedgerKeyring_getPage, _LedgerKeyring_getAccountsBIP44, _LedgerKeyring_getAccountsLegacy, _LedgerKeyring_addressFromIndex, _LedgerKeyring_pathFromAddress, _LedgerKeyring_getPathForIndex, _LedgerKeyring_isLedgerLiveHdPath, _LedgerKeyring_toLedgerPath, _LedgerKeyring_hasPreviousTransactions, _LedgerKeyring_getApiUrl;
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.LedgerKeyring = void 0;
|
|
36
36
|
const rlp_1 = require("@ethereumjs/rlp");
|
|
@@ -341,8 +341,6 @@ class LedgerKeyring extends events_1.EventEmitter {
|
|
|
341
341
|
throw new Error('Ledger: Only version 4 of typed data signing is supported');
|
|
342
342
|
}
|
|
343
343
|
const { domain, types, primaryType, message } = eth_sig_util_1.TypedDataUtils.sanitizeData(data);
|
|
344
|
-
const domainSeparatorHex = eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', domain, types, eth_sig_util_1.SignTypedDataVersion.V4).toString('hex');
|
|
345
|
-
const hashStructMessageHex = eth_sig_util_1.TypedDataUtils.hashStruct(primaryType.toString(), message, types, eth_sig_util_1.SignTypedDataVersion.V4).toString('hex');
|
|
346
344
|
const hdPath = await this.unlockAccountByAddress(withAccount);
|
|
347
345
|
if (!hdPath) {
|
|
348
346
|
throw new Error('Ledger: Unknown error while signing message');
|
|
@@ -351,8 +349,18 @@ class LedgerKeyring extends events_1.EventEmitter {
|
|
|
351
349
|
try {
|
|
352
350
|
payload = await this.bridge.deviceSignTypedData({
|
|
353
351
|
hdPath,
|
|
354
|
-
|
|
355
|
-
|
|
352
|
+
message: {
|
|
353
|
+
domain: {
|
|
354
|
+
name: domain.name,
|
|
355
|
+
chainId: domain.chainId,
|
|
356
|
+
version: domain.version,
|
|
357
|
+
verifyingContract: domain.verifyingContract,
|
|
358
|
+
salt: __classPrivateFieldGet(this, _LedgerKeyring_instances, "m", _LedgerKeyring_convertSaltIfAny).call(this, domain.salt),
|
|
359
|
+
},
|
|
360
|
+
types,
|
|
361
|
+
primaryType: primaryType.toString(),
|
|
362
|
+
message,
|
|
363
|
+
},
|
|
356
364
|
});
|
|
357
365
|
}
|
|
358
366
|
catch (error) {
|
|
@@ -435,6 +443,14 @@ _LedgerKeyring_instances = new WeakSet(), _LedgerKeyring_migrateAccountDetails =
|
|
|
435
443
|
return newOrMutatedTx;
|
|
436
444
|
}
|
|
437
445
|
throw new Error('Ledger: The transaction signature is not valid');
|
|
446
|
+
}, _LedgerKeyring_convertSaltIfAny = function _LedgerKeyring_convertSaltIfAny(salt) {
|
|
447
|
+
if (!salt) {
|
|
448
|
+
return undefined;
|
|
449
|
+
}
|
|
450
|
+
// We convert this to a plain string to avoid encoding issue on the
|
|
451
|
+
// mobile side (to avoid using `TextDecoder`).
|
|
452
|
+
const saltBytes = new Uint8Array(salt);
|
|
453
|
+
return String.fromCharCode(...saltBytes);
|
|
438
454
|
}, _LedgerKeyring_getPage =
|
|
439
455
|
/* PRIVATE METHODS */
|
|
440
456
|
async function _LedgerKeyring_getPage(increment) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.cjs","sourceRoot":"","sources":["../src/ledger-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAsC;AACtC,uCAA8E;AAC9E,0DAA4C;AAE5C,yDAKgC;AAChC,mCAAgC;AAEhC,mCAAsC;AACtC,kDAA0B;AAE1B,uDAAoE;AACpE,qEAAmE;AAEnE,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,YAAY,GAAG,GAAG,QAAQ,aAAa,CAAC;AAC9C,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,+GAA+G;AAC/G,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,IAAK,cAKJ;AALD,WAAK,cAAc;IACjB,8DAA4C,CAAA;IAC5C,0DAAwC,CAAA;IACxC,8DAA4C,CAAA;IAC5C,sDAAoC,CAAA;AACtC,CAAC,EALI,cAAc,KAAd,cAAc,QAKlB;AA6BD;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAC7B,EAA0C;IAE1C,OAAO,YAAY,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC,UAAU,KAAK,UAAU,CAAC;AACnE,CAAC;AAED,MAAa,aAAc,SAAQ,qBAAY;IA6B7C,YAAY,EAAE,MAAM,EAAiD;QACnE,KAAK,EAAE,CAAC;;QA3BV,aAAQ,GAAG,EAAE,CAAC;QAEL,SAAI,GAAW,WAAW,CAAC;QAEpC,SAAI,GAAG,CAAC,CAAC;QAET,YAAO,GAAG,CAAC,CAAC;QAEZ,oBAAe,GAAG,CAAC,CAAC;QAEpB,aAAQ,GAAsB,EAAE,CAAC;QAEjC,mBAAc,GAAmC,EAAE,CAAC;QAEpD,QAAG,GAAG,IAAI,eAAK,E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AAI,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC5C,CAAC,qEAEa,IAAY;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC,2CAED,KAAK,iDAA0B,OAAe;IAC5C,MAAM,MAAM,GAAG,uBAAA,IAAI,0DAAW,MAAf,IAAI,CAAa,CAAC;IACjC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CACjC,GAAG,MAAM,6CAA6C,OAAO,6BAA6B,CAC3F,CAAC;IACF,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7C,OAAO,cAAc,CAAC,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3E,CAAC;IAGC,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC;AAplBM,kBAAI,GAAW,WAAW,AAAtB,CAAuB","sourcesContent":["import { RLP } from '@ethereumjs/rlp';\nimport { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport {\n recoverPersonalSignature,\n recoverTypedSignature,\n SignTypedDataVersion,\n TypedDataUtils,\n} from '@metamask/eth-sig-util';\nimport { Buffer } from 'buffer';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { LedgerBridge, LedgerBridgeOptions } from './ledger-bridge';\nimport { LedgerIframeBridgeOptions } from './ledger-iframe-bridge';\n\nconst pathBase = 'm';\nconst hdPathString = `${pathBase}/44'/60'/0'`;\nconst keyringType = 'Ledger Hardware';\n\n// This number causes one of our failing tests to run very slowly, as the for loop needs to iterate 1000 times.\nconst MAX_INDEX = 1000;\n\nenum NetworkApiUrls {\n Ropsten = 'https://api-ropsten.etherscan.io',\n Kovan = 'https://api-kovan.etherscan.io',\n Rinkeby = 'https://api-rinkeby.etherscan.io',\n Mainnet = `https://api.etherscan.io`,\n}\n\ntype SignTransactionPayload = Awaited<\n ReturnType<LedgerBridge<LedgerIframeBridgeOptions>['deviceSignTransaction']>\n>;\n\nexport type AccountPageEntry = {\n address: string;\n balance: number | null;\n index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport type AccountDetails = {\n index?: number;\n bip44?: boolean;\n hdPath?: string;\n};\n\nexport type LedgerBridgeKeyringOptions = {\n hdPath: string;\n accounts: readonly string[];\n deviceId: string;\n accountDetails: Readonly<Record<string, AccountDetails>>;\n accountIndexes: Readonly<Record<string, number>>;\n implementFullBIP44: boolean;\n};\n\n/**\n * Check if the given transaction is made with ethereumjs-tx or @ethereumjs/tx\n *\n * Transactions built with older versions of ethereumjs-tx have a\n * getChainId method that newer versions do not.\n * Older versions are mutable\n * while newer versions default to being immutable.\n * Expected shape and type\n * of data for v, r and s differ (Buffer (old) vs BN (new)).\n *\n * @param tx - Transaction to check, instance of either ethereumjs-tx or @ethereumjs/tx.\n * @returns Returns `true` if tx is an old-style ethereumjs-tx transaction.\n */\nfunction isOldStyleEthereumjsTx(\n tx: TypedTransaction | OldEthJsTransaction,\n): tx is OldEthJsTransaction {\n return 'getChainId' in tx && typeof tx.getChainId === 'function';\n}\n\nexport class LedgerKeyring extends EventEmitter {\n static type: string = keyringType;\n\n deviceId = '';\n\n readonly type: string = keyringType;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n accounts: readonly string[] = [];\n\n accountDetails: Record<string, AccountDetails> = {};\n\n hdk = new HDKey();\n\n hdPath = hdPathString;\n\n paths: Record<string, number> = {};\n\n network: NetworkApiUrls = NetworkApiUrls.Mainnet;\n\n implementFullBIP44 = false;\n\n bridge: LedgerBridge<LedgerBridgeOptions>;\n\n constructor({ bridge }: { bridge: LedgerBridge<LedgerBridgeOptions> }) {\n super();\n\n if (!bridge) {\n throw new Error('Bridge is a required dependency for the keyring');\n }\n\n this.bridge = bridge;\n }\n\n async init(): Promise<void> {\n return this.bridge.init();\n }\n\n async destroy(): Promise<void> {\n return this.bridge.destroy();\n }\n\n async serialize(): Promise<\n Partial<LedgerBridgeKeyringOptions> // Maybe we should have a proper \"state\" type here instead of using this \"options\" type.\n > {\n return {\n hdPath: this.hdPath,\n accounts: this.accounts,\n deviceId: this.deviceId,\n accountDetails: this.accountDetails,\n implementFullBIP44: false,\n };\n }\n\n async deserialize(\n opts: Partial<LedgerBridgeKeyringOptions> = {}, // Same question here?\n ): Promise<void> {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.accounts = opts.accounts ?? [];\n this.deviceId = opts.deviceId ?? '';\n this.accountDetails = opts.accountDetails ?? {};\n\n if (!opts.accountDetails) {\n this.#migrateAccountDetails(opts);\n }\n\n this.implementFullBIP44 = opts.implementFullBIP44 ?? false;\n\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // Remove accounts that don't have corresponding account details\n this.accounts = this.accounts.filter((account) =>\n keys.has(ethUtil.toChecksumAddress(account)),\n );\n\n return Promise.resolve();\n }\n\n public setDeviceId(deviceId: string): void {\n this.deviceId = deviceId;\n }\n\n public getDeviceId(): string {\n return this.deviceId;\n }\n\n #migrateAccountDetails(opts: Partial<LedgerBridgeKeyringOptions>): void {\n if (this.#isLedgerLiveHdPath() && opts.accountIndexes) {\n for (const [account, index] of Object.entries(opts.accountIndexes)) {\n this.accountDetails[account] = {\n bip44: true,\n hdPath: this.#getPathForIndex(index),\n };\n }\n }\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // try to migrate non-LedgerLive accounts too\n if (!this.#isLedgerLiveHdPath()) {\n this.accounts.forEach((account) => {\n const key = ethUtil.toChecksumAddress(account);\n\n if (!keys.has(key)) {\n this.accountDetails[key] = {\n bip44: false,\n hdPath: this.#pathFromAddress(account),\n };\n }\n });\n }\n }\n\n isUnlocked(): boolean {\n return Boolean(this.hdk.publicKey);\n }\n\n isConnected(): boolean {\n return this.bridge.isDeviceConnected;\n }\n\n setAccountToUnlock(index: number): void {\n this.unlockedAccount = index;\n }\n\n setHdPath(hdPath: string): void {\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n }\n this.hdPath = hdPath;\n }\n\n async unlock(hdPath?: string, updateHdk = true): Promise<string> {\n if (this.isUnlocked() && !hdPath) {\n return 'already unlocked';\n }\n const path = hdPath ? this.#toLedgerPath(hdPath) : this.hdPath;\n\n let payload;\n try {\n payload = await this.bridge.getPublicKey({\n hdPath: path,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger Ethereum app closed. Open it to unlock.');\n }\n\n if (updateHdk && payload.chainCode) {\n this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex');\n }\n\n return payload.address;\n }\n\n async addAccounts(amount = 1): Promise<string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then(async (_) => {\n const from = this.unlockedAccount;\n const to = from + amount;\n const newAccounts: string[] = [];\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n let address;\n if (this.#isLedgerLiveHdPath()) {\n address = await this.unlock(path);\n } else {\n address = this.#addressFromIndex(pathBase, i);\n }\n\n this.accountDetails[ethUtil.toChecksumAddress(address)] = {\n // TODO: consider renaming this property, as the current name is misleading\n // It's currently used to represent whether an account uses the Ledger Live path.\n bip44: this.#isLedgerLiveHdPath(),\n hdPath: path,\n };\n\n if (!this.accounts.includes(address)) {\n this.accounts = [...this.accounts, address];\n newAccounts.push(address);\n }\n this.page = 0;\n }\n resolve(newAccounts);\n })\n .catch(reject);\n });\n }\n\n getName(): string {\n return keyringType;\n }\n\n async getFirstPage(): Promise<AccountPage> {\n this.page = 0;\n return this.#getPage(1);\n }\n\n async getNextPage(): Promise<AccountPage> {\n return this.#getPage(1);\n }\n\n async getPreviousPage(): Promise<AccountPage> {\n return this.#getPage(-1);\n }\n\n async getAccounts(): Promise<string[]> {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string): void {\n const filteredAccounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n\n if (filteredAccounts.length === this.accounts.length) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = filteredAccounts;\n delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n }\n\n async attemptMakeApp(): Promise<boolean> {\n return this.bridge.attemptMakeApp();\n }\n\n async updateTransportMethod(transportType: string): Promise<boolean> {\n return this.bridge.updateTransportMethod(transportType);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n let rawTxHex;\n // transactions built with older versions of ethereumjs-tx have a\n // getChainId method that newer versions do not. Older versions are mutable\n // while newer versions default to being immutable. Expected shape and type\n // of data for v, r and s differ (Buffer (old) vs BN (new))\n if (isOldStyleEthereumjsTx(tx)) {\n // In this version of ethereumjs-tx we must add the chainId in hex format\n // to the initial v value. The chainId must be included in the serialized\n // transaction which is only communicated to ethereumjs-tx in this\n // value. In newer versions the chainId is communicated via the 'Common'\n // object.\n // @ts-expect-error tx.v should be a Buffer, but we are assigning a string\n tx.v = ethUtil.bufferToHex(tx.getChainId());\n // @ts-expect-error tx.r should be a Buffer, but we are assigning a string\n tx.r = '0x00';\n // @ts-expect-error tx.s should be a Buffer, but we are assigning a string\n tx.s = '0x00';\n\n rawTxHex = tx.serialize().toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n tx.v = Buffer.from(payload.v, 'hex');\n tx.r = Buffer.from(payload.r, 'hex');\n tx.s = Buffer.from(payload.s, 'hex');\n return tx;\n });\n }\n\n // The below `encode` call is only necessary for legacy transactions, as `getMessageToSign`\n // calls `rlp.encode` internally for non-legacy transactions. As per the \"Transaction Execution\"\n // section of the ethereum yellow paper, transactions need to be \"well-formed RLP, with no additional\n // trailing bytes\".\n\n // Note also that `getMessageToSign` will return valid RLP for all transaction types, whereas the\n // `serialize` method will not for any transaction type except legacy. This is because `serialize` includes\n // empty r, s and v values in the encoded rlp. This is why we use `getMessageToSign` here instead of `serialize`.\n const messageToSign = tx.getMessageToSign(false);\n\n rawTxHex = Buffer.isBuffer(messageToSign)\n ? messageToSign.toString('hex')\n : Buffer.from(RLP.encode(messageToSign)).toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n // Because tx will be immutable, first get a plain javascript object that\n // represents the transaction. Using txData here as it aligns with the\n // nomenclature of ethereumjs/tx.\n const txData: TxData = tx.toJSON();\n // The fromTxData utility expects a type to support transactions with a type other than 0\n txData.type = tx.type;\n // The fromTxData utility expects v,r and s to be hex prefixed\n txData.v = ethUtil.addHexPrefix(payload.v);\n txData.r = ethUtil.addHexPrefix(payload.r);\n txData.s = ethUtil.addHexPrefix(payload.s);\n // Adopt the 'common' option from the original transaction and set the\n // returned object to be frozen if the original is frozen.\n return TransactionFactory.fromTxData(txData, {\n common: tx.common,\n freeze: Object.isFrozen(tx),\n });\n });\n }\n\n async #signTransaction(\n address: string,\n rawTxHex: string,\n handleSigning: (\n payload: SignTransactionPayload,\n ) => TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n const hdPath = await this.unlockAccountByAddress(address);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing transaction');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTransaction({\n tx: rawTxHex,\n hdPath,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing transaction');\n }\n\n const newOrMutatedTx = handleSigning(payload);\n const valid = newOrMutatedTx.verifySignature();\n if (valid) {\n return newOrMutatedTx;\n }\n throw new Error('Ledger: The transaction signature is not valid');\n }\n\n async signMessage(withAccount: string, data: string): Promise<string> {\n return this.signPersonalMessage(withAccount, data);\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n withAccount: string,\n message: string,\n ): Promise<string> {\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignMessage({\n hdPath,\n message: ethUtil.stripHexPrefix(message),\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let modifiedV = parseInt(String(payload.v), 10).toString(16);\n if (modifiedV.length < 2) {\n modifiedV = `0${modifiedV}`;\n }\n\n const signature = `0x${payload.r}${payload.s}${modifiedV}`;\n const addressSignedWith = recoverPersonalSignature({\n data: message,\n signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n async unlockAccountByAddress(address: string): Promise<string | undefined> {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n const accountDetails = this.accountDetails[checksummedAddress];\n if (!accountDetails) {\n throw new Error(\n `Ledger: Account for address '${checksummedAddress}' not found`,\n );\n }\n const { hdPath } = accountDetails;\n const unlockedAddress = await this.unlock(hdPath, false);\n\n // unlock resolves to the address for the given hdPath as reported by the ledger device\n // if that address is not the requested address, then this account belongs to a different device or seed\n if (unlockedAddress.toLowerCase() !== address.toLowerCase()) {\n throw new Error(\n `Ledger: Account ${address} does not belong to the connected device`,\n );\n }\n return hdPath;\n }\n\n async signTypedData<T extends MessageTypes>(\n withAccount: string,\n data: TypedMessage<T>,\n options: { version?: string } = {},\n ): Promise<string> {\n const isV4 = options.version === 'V4';\n if (!isV4) {\n throw new Error(\n 'Ledger: Only version 4 of typed data signing is supported',\n );\n }\n\n const { domain, types, primaryType, message } =\n TypedDataUtils.sanitizeData(data);\n const domainSeparatorHex = TypedDataUtils.hashStruct(\n 'EIP712Domain',\n domain,\n types,\n SignTypedDataVersion.V4,\n ).toString('hex');\n const hashStructMessageHex = TypedDataUtils.hashStruct(\n primaryType.toString(),\n message,\n types,\n SignTypedDataVersion.V4,\n ).toString('hex');\n\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTypedData({\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = recoverTypedSignature({\n data,\n signature,\n version: SignTypedDataVersion.V4,\n });\n\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n exportAccount(): void {\n throw new Error('Not supported on this device');\n }\n\n forgetDevice(): void {\n this.deviceId = '';\n this.accounts = [];\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n this.accountDetails = {};\n this.hdk = new HDKey();\n }\n\n /* PRIVATE METHODS */\n async #getPage(increment: number): Promise<AccountPage> {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n await this.unlock();\n let accounts;\n if (this.#isLedgerLiveHdPath()) {\n accounts = await this.#getAccountsBIP44(from, to);\n } else {\n accounts = this.#getAccountsLegacy(from, to);\n }\n return accounts;\n }\n\n async #getAccountsBIP44(from: number, to: number): Promise<AccountPage> {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n const address = await this.unlock(path);\n const valid = this.implementFullBIP44\n ? await this.#hasPreviousTransactions(address)\n : true;\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n\n // PER BIP44\n // \"Software should prevent a creation of an account if\n // a previous account does not have a transaction history\n // (meaning none of its addresses have been used before).\"\n if (!valid) {\n break;\n }\n }\n return accounts;\n }\n\n #getAccountsLegacy(from: number, to: number): AccountPage {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n this.paths[ethUtil.toChecksumAddress(address)] = i;\n }\n return accounts;\n }\n\n #addressFromIndex(basePath: string, i: number): string {\n const dkey = this.hdk.derive(`${basePath}/${i}`);\n const address = ethUtil\n .publicToAddress(dkey.publicKey, true)\n .toString('hex');\n return ethUtil.toChecksumAddress(`0x${address}`);\n }\n\n #pathFromAddress(address: string): string {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n let index = this.paths[checksummedAddress];\n if (typeof index === 'undefined') {\n for (let i = 0; i < MAX_INDEX; i++) {\n if (checksummedAddress === this.#addressFromIndex(pathBase, i)) {\n index = i;\n break;\n }\n }\n }\n\n if (typeof index === 'undefined') {\n throw new Error('Unknown address');\n }\n return this.#getPathForIndex(index);\n }\n\n #getPathForIndex(index: number): string {\n // Check if the path is BIP 44 (Ledger Live)\n return this.#isLedgerLiveHdPath()\n ? `m/44'/60'/${index}'/0/0`\n : `${this.hdPath}/${index}`;\n }\n\n #isLedgerLiveHdPath(): boolean {\n return this.hdPath === `m/44'/60'/0'/0/0`;\n }\n\n #toLedgerPath(path: string): string {\n return path.toString().replace('m/', '');\n }\n\n async #hasPreviousTransactions(address: string): Promise<boolean> {\n const apiUrl = this.#getApiUrl();\n const response = await window.fetch(\n `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`,\n );\n const parsedResponse = await response.json();\n return parsedResponse.status !== '0' && parsedResponse.result.length > 0;\n }\n\n #getApiUrl(): NetworkApiUrls {\n return this.network;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-keyring.cjs","sourceRoot":"","sources":["../src/ledger-keyring.ts"],"names":[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MAAM,IAAI,KAAK,EAAE,CAAC;AAChC,CAAC;IAGC,OAAO,IAAI,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC5C,CAAC,qEAEa,IAAY;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC,2CAED,KAAK,iDAA0B,OAAe;IAC5C,MAAM,MAAM,GAAG,uBAAA,IAAI,0DAAW,MAAf,IAAI,CAAa,CAAC;IACjC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CACjC,GAAG,MAAM,6CAA6C,OAAO,6BAA6B,CAC3F,CAAC;IACF,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7C,OAAO,cAAc,CAAC,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3E,CAAC;IAGC,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC;AA7lBM,kBAAI,GAAW,WAAW,AAAtB,CAAuB","sourcesContent":["import { RLP } from '@ethereumjs/rlp';\nimport { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport {\n recoverPersonalSignature,\n recoverTypedSignature,\n SignTypedDataVersion,\n TypedDataUtils,\n} from '@metamask/eth-sig-util';\nimport { Buffer } from 'buffer';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { LedgerBridge, LedgerBridgeOptions } from './ledger-bridge';\nimport { LedgerIframeBridgeOptions } from './ledger-iframe-bridge';\n\nconst pathBase = 'm';\nconst hdPathString = `${pathBase}/44'/60'/0'`;\nconst keyringType = 'Ledger Hardware';\n\n// This number causes one of our failing tests to run very slowly, as the for loop needs to iterate 1000 times.\nconst MAX_INDEX = 1000;\n\nenum NetworkApiUrls {\n Ropsten = 'https://api-ropsten.etherscan.io',\n Kovan = 'https://api-kovan.etherscan.io',\n Rinkeby = 'https://api-rinkeby.etherscan.io',\n Mainnet = `https://api.etherscan.io`,\n}\n\ntype SignTransactionPayload = Awaited<\n ReturnType<LedgerBridge<LedgerIframeBridgeOptions>['deviceSignTransaction']>\n>;\n\nexport type AccountPageEntry = {\n address: string;\n balance: number | null;\n index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport type AccountDetails = {\n index?: number;\n bip44?: boolean;\n hdPath?: string;\n};\n\nexport type LedgerBridgeKeyringOptions = {\n hdPath: string;\n accounts: readonly string[];\n deviceId: string;\n accountDetails: Readonly<Record<string, AccountDetails>>;\n accountIndexes: Readonly<Record<string, number>>;\n implementFullBIP44: boolean;\n};\n\n/**\n * Check if the given transaction is made with ethereumjs-tx or @ethereumjs/tx\n *\n * Transactions built with older versions of ethereumjs-tx have a\n * getChainId method that newer versions do not.\n * Older versions are mutable\n * while newer versions default to being immutable.\n * Expected shape and type\n * of data for v, r and s differ (Buffer (old) vs BN (new)).\n *\n * @param tx - Transaction to check, instance of either ethereumjs-tx or @ethereumjs/tx.\n * @returns Returns `true` if tx is an old-style ethereumjs-tx transaction.\n */\nfunction isOldStyleEthereumjsTx(\n tx: TypedTransaction | OldEthJsTransaction,\n): tx is OldEthJsTransaction {\n return 'getChainId' in tx && typeof tx.getChainId === 'function';\n}\n\nexport class LedgerKeyring extends EventEmitter {\n static type: string = keyringType;\n\n deviceId = '';\n\n readonly type: string = keyringType;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n accounts: readonly string[] = [];\n\n accountDetails: Record<string, AccountDetails> = {};\n\n hdk = new HDKey();\n\n hdPath = hdPathString;\n\n paths: Record<string, number> = {};\n\n network: NetworkApiUrls = NetworkApiUrls.Mainnet;\n\n implementFullBIP44 = false;\n\n bridge: LedgerBridge<LedgerBridgeOptions>;\n\n constructor({ bridge }: { bridge: LedgerBridge<LedgerBridgeOptions> }) {\n super();\n\n if (!bridge) {\n throw new Error('Bridge is a required dependency for the keyring');\n }\n\n this.bridge = bridge;\n }\n\n async init(): Promise<void> {\n return this.bridge.init();\n }\n\n async destroy(): Promise<void> {\n return this.bridge.destroy();\n }\n\n async serialize(): Promise<\n Partial<LedgerBridgeKeyringOptions> // Maybe we should have a proper \"state\" type here instead of using this \"options\" type.\n > {\n return {\n hdPath: this.hdPath,\n accounts: this.accounts,\n deviceId: this.deviceId,\n accountDetails: this.accountDetails,\n implementFullBIP44: false,\n };\n }\n\n async deserialize(\n opts: Partial<LedgerBridgeKeyringOptions> = {}, // Same question here?\n ): Promise<void> {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.accounts = opts.accounts ?? [];\n this.deviceId = opts.deviceId ?? '';\n this.accountDetails = opts.accountDetails ?? {};\n\n if (!opts.accountDetails) {\n this.#migrateAccountDetails(opts);\n }\n\n this.implementFullBIP44 = opts.implementFullBIP44 ?? false;\n\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // Remove accounts that don't have corresponding account details\n this.accounts = this.accounts.filter((account) =>\n keys.has(ethUtil.toChecksumAddress(account)),\n );\n\n return Promise.resolve();\n }\n\n public setDeviceId(deviceId: string): void {\n this.deviceId = deviceId;\n }\n\n public getDeviceId(): string {\n return this.deviceId;\n }\n\n #migrateAccountDetails(opts: Partial<LedgerBridgeKeyringOptions>): void {\n if (this.#isLedgerLiveHdPath() && opts.accountIndexes) {\n for (const [account, index] of Object.entries(opts.accountIndexes)) {\n this.accountDetails[account] = {\n bip44: true,\n hdPath: this.#getPathForIndex(index),\n };\n }\n }\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // try to migrate non-LedgerLive accounts too\n if (!this.#isLedgerLiveHdPath()) {\n this.accounts.forEach((account) => {\n const key = ethUtil.toChecksumAddress(account);\n\n if (!keys.has(key)) {\n this.accountDetails[key] = {\n bip44: false,\n hdPath: this.#pathFromAddress(account),\n };\n }\n });\n }\n }\n\n isUnlocked(): boolean {\n return Boolean(this.hdk.publicKey);\n }\n\n isConnected(): boolean {\n return this.bridge.isDeviceConnected;\n }\n\n setAccountToUnlock(index: number): void {\n this.unlockedAccount = index;\n }\n\n setHdPath(hdPath: string): void {\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n }\n this.hdPath = hdPath;\n }\n\n async unlock(hdPath?: string, updateHdk = true): Promise<string> {\n if (this.isUnlocked() && !hdPath) {\n return 'already unlocked';\n }\n const path = hdPath ? this.#toLedgerPath(hdPath) : this.hdPath;\n\n let payload;\n try {\n payload = await this.bridge.getPublicKey({\n hdPath: path,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger Ethereum app closed. Open it to unlock.');\n }\n\n if (updateHdk && payload.chainCode) {\n this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex');\n }\n\n return payload.address;\n }\n\n async addAccounts(amount = 1): Promise<string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then(async (_) => {\n const from = this.unlockedAccount;\n const to = from + amount;\n const newAccounts: string[] = [];\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n let address;\n if (this.#isLedgerLiveHdPath()) {\n address = await this.unlock(path);\n } else {\n address = this.#addressFromIndex(pathBase, i);\n }\n\n this.accountDetails[ethUtil.toChecksumAddress(address)] = {\n // TODO: consider renaming this property, as the current name is misleading\n // It's currently used to represent whether an account uses the Ledger Live path.\n bip44: this.#isLedgerLiveHdPath(),\n hdPath: path,\n };\n\n if (!this.accounts.includes(address)) {\n this.accounts = [...this.accounts, address];\n newAccounts.push(address);\n }\n this.page = 0;\n }\n resolve(newAccounts);\n })\n .catch(reject);\n });\n }\n\n getName(): string {\n return keyringType;\n }\n\n async getFirstPage(): Promise<AccountPage> {\n this.page = 0;\n return this.#getPage(1);\n }\n\n async getNextPage(): Promise<AccountPage> {\n return this.#getPage(1);\n }\n\n async getPreviousPage(): Promise<AccountPage> {\n return this.#getPage(-1);\n }\n\n async getAccounts(): Promise<string[]> {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string): void {\n const filteredAccounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n\n if (filteredAccounts.length === this.accounts.length) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = filteredAccounts;\n delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n }\n\n async attemptMakeApp(): Promise<boolean> {\n return this.bridge.attemptMakeApp();\n }\n\n async updateTransportMethod(transportType: string): Promise<boolean> {\n return this.bridge.updateTransportMethod(transportType);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n let rawTxHex;\n // transactions built with older versions of ethereumjs-tx have a\n // getChainId method that newer versions do not. Older versions are mutable\n // while newer versions default to being immutable. Expected shape and type\n // of data for v, r and s differ (Buffer (old) vs BN (new))\n if (isOldStyleEthereumjsTx(tx)) {\n // In this version of ethereumjs-tx we must add the chainId in hex format\n // to the initial v value. The chainId must be included in the serialized\n // transaction which is only communicated to ethereumjs-tx in this\n // value. In newer versions the chainId is communicated via the 'Common'\n // object.\n // @ts-expect-error tx.v should be a Buffer, but we are assigning a string\n tx.v = ethUtil.bufferToHex(tx.getChainId());\n // @ts-expect-error tx.r should be a Buffer, but we are assigning a string\n tx.r = '0x00';\n // @ts-expect-error tx.s should be a Buffer, but we are assigning a string\n tx.s = '0x00';\n\n rawTxHex = tx.serialize().toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n tx.v = Buffer.from(payload.v, 'hex');\n tx.r = Buffer.from(payload.r, 'hex');\n tx.s = Buffer.from(payload.s, 'hex');\n return tx;\n });\n }\n\n // The below `encode` call is only necessary for legacy transactions, as `getMessageToSign`\n // calls `rlp.encode` internally for non-legacy transactions. As per the \"Transaction Execution\"\n // section of the ethereum yellow paper, transactions need to be \"well-formed RLP, with no additional\n // trailing bytes\".\n\n // Note also that `getMessageToSign` will return valid RLP for all transaction types, whereas the\n // `serialize` method will not for any transaction type except legacy. This is because `serialize` includes\n // empty r, s and v values in the encoded rlp. This is why we use `getMessageToSign` here instead of `serialize`.\n const messageToSign = tx.getMessageToSign(false);\n\n rawTxHex = Buffer.isBuffer(messageToSign)\n ? messageToSign.toString('hex')\n : Buffer.from(RLP.encode(messageToSign)).toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n // Because tx will be immutable, first get a plain javascript object that\n // represents the transaction. Using txData here as it aligns with the\n // nomenclature of ethereumjs/tx.\n const txData: TxData = tx.toJSON();\n // The fromTxData utility expects a type to support transactions with a type other than 0\n txData.type = tx.type;\n // The fromTxData utility expects v,r and s to be hex prefixed\n txData.v = ethUtil.addHexPrefix(payload.v);\n txData.r = ethUtil.addHexPrefix(payload.r);\n txData.s = ethUtil.addHexPrefix(payload.s);\n // Adopt the 'common' option from the original transaction and set the\n // returned object to be frozen if the original is frozen.\n return TransactionFactory.fromTxData(txData, {\n common: tx.common,\n freeze: Object.isFrozen(tx),\n });\n });\n }\n\n async #signTransaction(\n address: string,\n rawTxHex: string,\n handleSigning: (\n payload: SignTransactionPayload,\n ) => TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n const hdPath = await this.unlockAccountByAddress(address);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing transaction');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTransaction({\n tx: rawTxHex,\n hdPath,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing transaction');\n }\n\n const newOrMutatedTx = handleSigning(payload);\n const valid = newOrMutatedTx.verifySignature();\n if (valid) {\n return newOrMutatedTx;\n }\n throw new Error('Ledger: The transaction signature is not valid');\n }\n\n async signMessage(withAccount: string, data: string): Promise<string> {\n return this.signPersonalMessage(withAccount, data);\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n withAccount: string,\n message: string,\n ): Promise<string> {\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignMessage({\n hdPath,\n message: ethUtil.stripHexPrefix(message),\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let modifiedV = parseInt(String(payload.v), 10).toString(16);\n if (modifiedV.length < 2) {\n modifiedV = `0${modifiedV}`;\n }\n\n const signature = `0x${payload.r}${payload.s}${modifiedV}`;\n const addressSignedWith = recoverPersonalSignature({\n data: message,\n signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n async unlockAccountByAddress(address: string): Promise<string | undefined> {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n const accountDetails = this.accountDetails[checksummedAddress];\n if (!accountDetails) {\n throw new Error(\n `Ledger: Account for address '${checksummedAddress}' not found`,\n );\n }\n const { hdPath } = accountDetails;\n const unlockedAddress = await this.unlock(hdPath, false);\n\n // unlock resolves to the address for the given hdPath as reported by the ledger device\n // if that address is not the requested address, then this account belongs to a different device or seed\n if (unlockedAddress.toLowerCase() !== address.toLowerCase()) {\n throw new Error(\n `Ledger: Account ${address} does not belong to the connected device`,\n );\n }\n return hdPath;\n }\n\n async signTypedData<T extends MessageTypes>(\n withAccount: string,\n data: TypedMessage<T>,\n options: { version?: string } = {},\n ): Promise<string> {\n const isV4 = options.version === 'V4';\n if (!isV4) {\n throw new Error(\n 'Ledger: Only version 4 of typed data signing is supported',\n );\n }\n\n const { domain, types, primaryType, message } =\n TypedDataUtils.sanitizeData(data);\n\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTypedData({\n hdPath,\n message: {\n domain: {\n name: domain.name,\n chainId: domain.chainId,\n version: domain.version,\n verifyingContract: domain.verifyingContract,\n salt: this.#convertSaltIfAny(domain.salt),\n },\n types,\n primaryType: primaryType.toString(),\n message,\n },\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = recoverTypedSignature({\n data,\n signature,\n version: SignTypedDataVersion.V4,\n });\n\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n exportAccount(): void {\n throw new Error('Not supported on this device');\n }\n\n forgetDevice(): void {\n this.deviceId = '';\n this.accounts = [];\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n this.accountDetails = {};\n this.hdk = new HDKey();\n }\n\n #convertSaltIfAny(salt: ArrayBuffer | undefined): string | undefined {\n if (!salt) {\n return undefined;\n }\n\n // We convert this to a plain string to avoid encoding issue on the\n // mobile side (to avoid using `TextDecoder`).\n const saltBytes = new Uint8Array(salt);\n return String.fromCharCode(...saltBytes);\n }\n\n /* PRIVATE METHODS */\n async #getPage(increment: number): Promise<AccountPage> {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n await this.unlock();\n let accounts;\n if (this.#isLedgerLiveHdPath()) {\n accounts = await this.#getAccountsBIP44(from, to);\n } else {\n accounts = this.#getAccountsLegacy(from, to);\n }\n return accounts;\n }\n\n async #getAccountsBIP44(from: number, to: number): Promise<AccountPage> {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n const address = await this.unlock(path);\n const valid = this.implementFullBIP44\n ? await this.#hasPreviousTransactions(address)\n : true;\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n\n // PER BIP44\n // \"Software should prevent a creation of an account if\n // a previous account does not have a transaction history\n // (meaning none of its addresses have been used before).\"\n if (!valid) {\n break;\n }\n }\n return accounts;\n }\n\n #getAccountsLegacy(from: number, to: number): AccountPage {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n this.paths[ethUtil.toChecksumAddress(address)] = i;\n }\n return accounts;\n }\n\n #addressFromIndex(basePath: string, i: number): string {\n const dkey = this.hdk.derive(`${basePath}/${i}`);\n const address = ethUtil\n .publicToAddress(dkey.publicKey, true)\n .toString('hex');\n return ethUtil.toChecksumAddress(`0x${address}`);\n }\n\n #pathFromAddress(address: string): string {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n let index = this.paths[checksummedAddress];\n if (typeof index === 'undefined') {\n for (let i = 0; i < MAX_INDEX; i++) {\n if (checksummedAddress === this.#addressFromIndex(pathBase, i)) {\n index = i;\n break;\n }\n }\n }\n\n if (typeof index === 'undefined') {\n throw new Error('Unknown address');\n }\n return this.#getPathForIndex(index);\n }\n\n #getPathForIndex(index: number): string {\n // Check if the path is BIP 44 (Ledger Live)\n return this.#isLedgerLiveHdPath()\n ? `m/44'/60'/${index}'/0/0`\n : `${this.hdPath}/${index}`;\n }\n\n #isLedgerLiveHdPath(): boolean {\n return this.hdPath === `m/44'/60'/0'/0/0`;\n }\n\n #toLedgerPath(path: string): string {\n return path.toString().replace('m/', '');\n }\n\n async #hasPreviousTransactions(address: string): Promise<boolean> {\n const apiUrl = this.#getApiUrl();\n const response = await window.fetch(\n `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`,\n );\n const parsedResponse = await response.json();\n return parsedResponse.status !== '0' && parsedResponse.result.length > 0;\n }\n\n #getApiUrl(): NetworkApiUrls {\n return this.network;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.d.cts","sourceRoot":"","sources":["../src/ledger-keyring.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,gBAAgB,EAAE,uBAAuB;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,+BAA+B;AAQzE,OAAO,KAAK,mBAAmB,sBAAsB;AACrD,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAAO,KAAK,cAAc;AAE1B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,4BAAwB;AAUpE,aAAK,cAAc;IACjB,OAAO,qCAAqC;IAC5C,KAAK,mCAAmC;IACxC,OAAO,qCAAqC;IAC5C,OAAO,6BAA6B;CACrC;AAMD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,gBAAgB,EAAE,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IACzD,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,kBAAkB,EAAE,OAAO,CAAC;CA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this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _LedgerKeyring_instances, _LedgerKeyring_migrateAccountDetails, _LedgerKeyring_signTransaction, _LedgerKeyring_getPage, _LedgerKeyring_getAccountsBIP44, _LedgerKeyring_getAccountsLegacy, _LedgerKeyring_addressFromIndex, _LedgerKeyring_pathFromAddress, _LedgerKeyring_getPathForIndex, _LedgerKeyring_isLedgerLiveHdPath, _LedgerKeyring_toLedgerPath, _LedgerKeyring_hasPreviousTransactions, _LedgerKeyring_getApiUrl;
|
|
6
|
+
var _LedgerKeyring_instances, _LedgerKeyring_migrateAccountDetails, _LedgerKeyring_signTransaction, _LedgerKeyring_convertSaltIfAny, _LedgerKeyring_getPage, _LedgerKeyring_getAccountsBIP44, _LedgerKeyring_getAccountsLegacy, _LedgerKeyring_addressFromIndex, _LedgerKeyring_pathFromAddress, _LedgerKeyring_getPathForIndex, _LedgerKeyring_isLedgerLiveHdPath, _LedgerKeyring_toLedgerPath, _LedgerKeyring_hasPreviousTransactions, _LedgerKeyring_getApiUrl;
|
|
7
7
|
function $importDefault(module) {
|
|
8
8
|
if (module?.__esModule) {
|
|
9
9
|
return module.default;
|
|
@@ -15,8 +15,7 @@ import { TransactionFactory } from "@ethereumjs/tx";
|
|
|
15
15
|
import $ethereumjstx from "@ethereumjs/tx";
|
|
16
16
|
const { TxData, TypedTransaction } = $ethereumjstx;
|
|
17
17
|
import * as ethUtil from "@ethereumjs/util";
|
|
18
|
-
import
|
|
19
|
-
const { recoverPersonalSignature, recoverTypedSignature, SignTypedDataVersion, TypedDataUtils } = $metamaskethsigutil;
|
|
18
|
+
import { recoverPersonalSignature, recoverTypedSignature, SignTypedDataVersion, TypedDataUtils } from "@metamask/eth-sig-util";
|
|
20
19
|
import { Buffer } from "buffer";
|
|
21
20
|
import { EventEmitter } from "events";
|
|
22
21
|
import $HDKey from "hdkey";
|
|
@@ -322,8 +321,6 @@ export class LedgerKeyring extends EventEmitter {
|
|
|
322
321
|
throw new Error('Ledger: Only version 4 of typed data signing is supported');
|
|
323
322
|
}
|
|
324
323
|
const { domain, types, primaryType, message } = TypedDataUtils.sanitizeData(data);
|
|
325
|
-
const domainSeparatorHex = TypedDataUtils.hashStruct('EIP712Domain', domain, types, SignTypedDataVersion.V4).toString('hex');
|
|
326
|
-
const hashStructMessageHex = TypedDataUtils.hashStruct(primaryType.toString(), message, types, SignTypedDataVersion.V4).toString('hex');
|
|
327
324
|
const hdPath = await this.unlockAccountByAddress(withAccount);
|
|
328
325
|
if (!hdPath) {
|
|
329
326
|
throw new Error('Ledger: Unknown error while signing message');
|
|
@@ -332,8 +329,18 @@ export class LedgerKeyring extends EventEmitter {
|
|
|
332
329
|
try {
|
|
333
330
|
payload = await this.bridge.deviceSignTypedData({
|
|
334
331
|
hdPath,
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
message: {
|
|
333
|
+
domain: {
|
|
334
|
+
name: domain.name,
|
|
335
|
+
chainId: domain.chainId,
|
|
336
|
+
version: domain.version,
|
|
337
|
+
verifyingContract: domain.verifyingContract,
|
|
338
|
+
salt: __classPrivateFieldGet(this, _LedgerKeyring_instances, "m", _LedgerKeyring_convertSaltIfAny).call(this, domain.salt),
|
|
339
|
+
},
|
|
340
|
+
types,
|
|
341
|
+
primaryType: primaryType.toString(),
|
|
342
|
+
message,
|
|
343
|
+
},
|
|
337
344
|
});
|
|
338
345
|
}
|
|
339
346
|
catch (error) {
|
|
@@ -415,6 +422,14 @@ _LedgerKeyring_instances = new WeakSet(), _LedgerKeyring_migrateAccountDetails =
|
|
|
415
422
|
return newOrMutatedTx;
|
|
416
423
|
}
|
|
417
424
|
throw new Error('Ledger: The transaction signature is not valid');
|
|
425
|
+
}, _LedgerKeyring_convertSaltIfAny = function _LedgerKeyring_convertSaltIfAny(salt) {
|
|
426
|
+
if (!salt) {
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
// We convert this to a plain string to avoid encoding issue on the
|
|
430
|
+
// mobile side (to avoid using `TextDecoder`).
|
|
431
|
+
const saltBytes = new Uint8Array(salt);
|
|
432
|
+
return String.fromCharCode(...saltBytes);
|
|
418
433
|
}, _LedgerKeyring_getPage =
|
|
419
434
|
/* PRIVATE METHODS */
|
|
420
435
|
async function _LedgerKeyring_getPage(increment) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.mjs","sourceRoot":"","sources":["../src/ledger-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,wBAAwB;;;;AAEtC,OAAO,KAAK,OAAO,yBAAyB;;;AAQ5C,OAAO,EAAE,MAAM,EAAE,eAAe;AAEhC,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,4BAAwB;AACpE,OAAO,EAAE,yBAAyB,EAAE,mCAA+B;AAEnE,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,YAAY,GAAG,GAAG,QAAQ,aAAa,CAAC;AAC9C,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,+GAA+G;AAC/G,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,IAAK,cAKJ;AALD,WAAK,cAAc;IACjB,8DAA4C,CAAA;IAC5C,0DAAwC,CAAA;IACxC,8DAA4C,CAAA;IAC5C,sDAAoC,CAAA;AACtC,CAAC,EALI,cAAc,KAAd,cAAc,QAKlB;AA6BD;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAC7B,EAA0C;IAE1C,OAAO,YAAY,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC,UAAU,KAAK,UAAU,CAAC;AACnE,CAAC;AAED,MAAM,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IACrC,CAAC;IACD,OAAO,uBAAA,IAAI,gEAAiB,MAArB,IAAI,EAAkB,KAAK,CAAC,CAAC;AACtC,CAAC,2EAEgB,KAAa;IAC5B,4CAA4C;IAC5C,OAAO,uBAAA,IAAI,mEAAoB,MAAxB,IAAI,CAAsB;QAC/B,CAAC,CAAC,aAAa,KAAK,OAAO;QAC3B,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;AAChC,CAAC;IAGC,OAAO,IAAI,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC5C,CAAC,qEAEa,IAAY;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC,2CAED,KAAK,iDAA0B,OAAe;IAC5C,MAAM,MAAM,GAAG,uBAAA,IAAI,0DAAW,MAAf,IAAI,CAAa,CAAC;IACjC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CACjC,GAAG,MAAM,6CAA6C,OAAO,6BAA6B,CAC3F,CAAC;IACF,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7C,OAAO,cAAc,CAAC,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3E,CAAC;IAGC,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC;AAplBM,kBAAI,GAAW,WAAW,AAAtB,CAAuB","sourcesContent":["import { RLP } from '@ethereumjs/rlp';\nimport { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport {\n recoverPersonalSignature,\n recoverTypedSignature,\n SignTypedDataVersion,\n TypedDataUtils,\n} from '@metamask/eth-sig-util';\nimport { Buffer } from 'buffer';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { LedgerBridge, LedgerBridgeOptions } from './ledger-bridge';\nimport { LedgerIframeBridgeOptions } from './ledger-iframe-bridge';\n\nconst pathBase = 'm';\nconst hdPathString = `${pathBase}/44'/60'/0'`;\nconst keyringType = 'Ledger Hardware';\n\n// This number causes one of our failing tests to run very slowly, as the for loop needs to iterate 1000 times.\nconst MAX_INDEX = 1000;\n\nenum NetworkApiUrls {\n Ropsten = 'https://api-ropsten.etherscan.io',\n Kovan = 'https://api-kovan.etherscan.io',\n Rinkeby = 'https://api-rinkeby.etherscan.io',\n Mainnet = `https://api.etherscan.io`,\n}\n\ntype SignTransactionPayload = Awaited<\n ReturnType<LedgerBridge<LedgerIframeBridgeOptions>['deviceSignTransaction']>\n>;\n\nexport type AccountPageEntry = {\n address: string;\n balance: number | null;\n index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport type AccountDetails = {\n index?: number;\n bip44?: boolean;\n hdPath?: string;\n};\n\nexport type LedgerBridgeKeyringOptions = {\n hdPath: string;\n accounts: readonly string[];\n deviceId: string;\n accountDetails: Readonly<Record<string, AccountDetails>>;\n accountIndexes: Readonly<Record<string, number>>;\n implementFullBIP44: boolean;\n};\n\n/**\n * Check if the given transaction is made with ethereumjs-tx or @ethereumjs/tx\n *\n * Transactions built with older versions of ethereumjs-tx have a\n * getChainId method that newer versions do not.\n * Older versions are mutable\n * while newer versions default to being immutable.\n * Expected shape and type\n * of data for v, r and s differ (Buffer (old) vs BN (new)).\n *\n * @param tx - Transaction to check, instance of either ethereumjs-tx or @ethereumjs/tx.\n * @returns Returns `true` if tx is an old-style ethereumjs-tx transaction.\n */\nfunction isOldStyleEthereumjsTx(\n tx: TypedTransaction | OldEthJsTransaction,\n): tx is OldEthJsTransaction {\n return 'getChainId' in tx && typeof tx.getChainId === 'function';\n}\n\nexport class LedgerKeyring extends EventEmitter {\n static type: string = keyringType;\n\n deviceId = '';\n\n readonly type: string = keyringType;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n accounts: readonly string[] = [];\n\n accountDetails: Record<string, AccountDetails> = {};\n\n hdk = new HDKey();\n\n hdPath = hdPathString;\n\n paths: Record<string, number> = {};\n\n network: NetworkApiUrls = NetworkApiUrls.Mainnet;\n\n implementFullBIP44 = false;\n\n bridge: LedgerBridge<LedgerBridgeOptions>;\n\n constructor({ bridge }: { bridge: LedgerBridge<LedgerBridgeOptions> }) {\n super();\n\n if (!bridge) {\n throw new Error('Bridge is a required dependency for the keyring');\n }\n\n this.bridge = bridge;\n }\n\n async init(): Promise<void> {\n return this.bridge.init();\n }\n\n async destroy(): Promise<void> {\n return this.bridge.destroy();\n }\n\n async serialize(): Promise<\n Partial<LedgerBridgeKeyringOptions> // Maybe we should have a proper \"state\" type here instead of using this \"options\" type.\n > {\n return {\n hdPath: this.hdPath,\n accounts: this.accounts,\n deviceId: this.deviceId,\n accountDetails: this.accountDetails,\n implementFullBIP44: false,\n };\n }\n\n async deserialize(\n opts: Partial<LedgerBridgeKeyringOptions> = {}, // Same question here?\n ): Promise<void> {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.accounts = opts.accounts ?? [];\n this.deviceId = opts.deviceId ?? '';\n this.accountDetails = opts.accountDetails ?? {};\n\n if (!opts.accountDetails) {\n this.#migrateAccountDetails(opts);\n }\n\n this.implementFullBIP44 = opts.implementFullBIP44 ?? false;\n\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // Remove accounts that don't have corresponding account details\n this.accounts = this.accounts.filter((account) =>\n keys.has(ethUtil.toChecksumAddress(account)),\n );\n\n return Promise.resolve();\n }\n\n public setDeviceId(deviceId: string): void {\n this.deviceId = deviceId;\n }\n\n public getDeviceId(): string {\n return this.deviceId;\n }\n\n #migrateAccountDetails(opts: Partial<LedgerBridgeKeyringOptions>): void {\n if (this.#isLedgerLiveHdPath() && opts.accountIndexes) {\n for (const [account, index] of Object.entries(opts.accountIndexes)) {\n this.accountDetails[account] = {\n bip44: true,\n hdPath: this.#getPathForIndex(index),\n };\n }\n }\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // try to migrate non-LedgerLive accounts too\n if (!this.#isLedgerLiveHdPath()) {\n this.accounts.forEach((account) => {\n const key = ethUtil.toChecksumAddress(account);\n\n if (!keys.has(key)) {\n this.accountDetails[key] = {\n bip44: false,\n hdPath: this.#pathFromAddress(account),\n };\n }\n });\n }\n }\n\n isUnlocked(): boolean {\n return Boolean(this.hdk.publicKey);\n }\n\n isConnected(): boolean {\n return this.bridge.isDeviceConnected;\n }\n\n setAccountToUnlock(index: number): void {\n this.unlockedAccount = index;\n }\n\n setHdPath(hdPath: string): void {\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n }\n this.hdPath = hdPath;\n }\n\n async unlock(hdPath?: string, updateHdk = true): Promise<string> {\n if (this.isUnlocked() && !hdPath) {\n return 'already unlocked';\n }\n const path = hdPath ? this.#toLedgerPath(hdPath) : this.hdPath;\n\n let payload;\n try {\n payload = await this.bridge.getPublicKey({\n hdPath: path,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger Ethereum app closed. Open it to unlock.');\n }\n\n if (updateHdk && payload.chainCode) {\n this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex');\n }\n\n return payload.address;\n }\n\n async addAccounts(amount = 1): Promise<string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then(async (_) => {\n const from = this.unlockedAccount;\n const to = from + amount;\n const newAccounts: string[] = [];\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n let address;\n if (this.#isLedgerLiveHdPath()) {\n address = await this.unlock(path);\n } else {\n address = this.#addressFromIndex(pathBase, i);\n }\n\n this.accountDetails[ethUtil.toChecksumAddress(address)] = {\n // TODO: consider renaming this property, as the current name is misleading\n // It's currently used to represent whether an account uses the Ledger Live path.\n bip44: this.#isLedgerLiveHdPath(),\n hdPath: path,\n };\n\n if (!this.accounts.includes(address)) {\n this.accounts = [...this.accounts, address];\n newAccounts.push(address);\n }\n this.page = 0;\n }\n resolve(newAccounts);\n })\n .catch(reject);\n });\n }\n\n getName(): string {\n return keyringType;\n }\n\n async getFirstPage(): Promise<AccountPage> {\n this.page = 0;\n return this.#getPage(1);\n }\n\n async getNextPage(): Promise<AccountPage> {\n return this.#getPage(1);\n }\n\n async getPreviousPage(): Promise<AccountPage> {\n return this.#getPage(-1);\n }\n\n async getAccounts(): Promise<string[]> {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string): void {\n const filteredAccounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n\n if (filteredAccounts.length === this.accounts.length) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = filteredAccounts;\n delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n }\n\n async attemptMakeApp(): Promise<boolean> {\n return this.bridge.attemptMakeApp();\n }\n\n async updateTransportMethod(transportType: string): Promise<boolean> {\n return this.bridge.updateTransportMethod(transportType);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n let rawTxHex;\n // transactions built with older versions of ethereumjs-tx have a\n // getChainId method that newer versions do not. Older versions are mutable\n // while newer versions default to being immutable. Expected shape and type\n // of data for v, r and s differ (Buffer (old) vs BN (new))\n if (isOldStyleEthereumjsTx(tx)) {\n // In this version of ethereumjs-tx we must add the chainId in hex format\n // to the initial v value. The chainId must be included in the serialized\n // transaction which is only communicated to ethereumjs-tx in this\n // value. In newer versions the chainId is communicated via the 'Common'\n // object.\n // @ts-expect-error tx.v should be a Buffer, but we are assigning a string\n tx.v = ethUtil.bufferToHex(tx.getChainId());\n // @ts-expect-error tx.r should be a Buffer, but we are assigning a string\n tx.r = '0x00';\n // @ts-expect-error tx.s should be a Buffer, but we are assigning a string\n tx.s = '0x00';\n\n rawTxHex = tx.serialize().toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n tx.v = Buffer.from(payload.v, 'hex');\n tx.r = Buffer.from(payload.r, 'hex');\n tx.s = Buffer.from(payload.s, 'hex');\n return tx;\n });\n }\n\n // The below `encode` call is only necessary for legacy transactions, as `getMessageToSign`\n // calls `rlp.encode` internally for non-legacy transactions. As per the \"Transaction Execution\"\n // section of the ethereum yellow paper, transactions need to be \"well-formed RLP, with no additional\n // trailing bytes\".\n\n // Note also that `getMessageToSign` will return valid RLP for all transaction types, whereas the\n // `serialize` method will not for any transaction type except legacy. This is because `serialize` includes\n // empty r, s and v values in the encoded rlp. This is why we use `getMessageToSign` here instead of `serialize`.\n const messageToSign = tx.getMessageToSign(false);\n\n rawTxHex = Buffer.isBuffer(messageToSign)\n ? messageToSign.toString('hex')\n : Buffer.from(RLP.encode(messageToSign)).toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n // Because tx will be immutable, first get a plain javascript object that\n // represents the transaction. Using txData here as it aligns with the\n // nomenclature of ethereumjs/tx.\n const txData: TxData = tx.toJSON();\n // The fromTxData utility expects a type to support transactions with a type other than 0\n txData.type = tx.type;\n // The fromTxData utility expects v,r and s to be hex prefixed\n txData.v = ethUtil.addHexPrefix(payload.v);\n txData.r = ethUtil.addHexPrefix(payload.r);\n txData.s = ethUtil.addHexPrefix(payload.s);\n // Adopt the 'common' option from the original transaction and set the\n // returned object to be frozen if the original is frozen.\n return TransactionFactory.fromTxData(txData, {\n common: tx.common,\n freeze: Object.isFrozen(tx),\n });\n });\n }\n\n async #signTransaction(\n address: string,\n rawTxHex: string,\n handleSigning: (\n payload: SignTransactionPayload,\n ) => TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n const hdPath = await this.unlockAccountByAddress(address);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing transaction');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTransaction({\n tx: rawTxHex,\n hdPath,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing transaction');\n }\n\n const newOrMutatedTx = handleSigning(payload);\n const valid = newOrMutatedTx.verifySignature();\n if (valid) {\n return newOrMutatedTx;\n }\n throw new Error('Ledger: The transaction signature is not valid');\n }\n\n async signMessage(withAccount: string, data: string): Promise<string> {\n return this.signPersonalMessage(withAccount, data);\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n withAccount: string,\n message: string,\n ): Promise<string> {\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignMessage({\n hdPath,\n message: ethUtil.stripHexPrefix(message),\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let modifiedV = parseInt(String(payload.v), 10).toString(16);\n if (modifiedV.length < 2) {\n modifiedV = `0${modifiedV}`;\n }\n\n const signature = `0x${payload.r}${payload.s}${modifiedV}`;\n const addressSignedWith = recoverPersonalSignature({\n data: message,\n signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n async unlockAccountByAddress(address: string): Promise<string | undefined> {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n const accountDetails = this.accountDetails[checksummedAddress];\n if (!accountDetails) {\n throw new Error(\n `Ledger: Account for address '${checksummedAddress}' not found`,\n );\n }\n const { hdPath } = accountDetails;\n const unlockedAddress = await this.unlock(hdPath, false);\n\n // unlock resolves to the address for the given hdPath as reported by the ledger device\n // if that address is not the requested address, then this account belongs to a different device or seed\n if (unlockedAddress.toLowerCase() !== address.toLowerCase()) {\n throw new Error(\n `Ledger: Account ${address} does not belong to the connected device`,\n );\n }\n return hdPath;\n }\n\n async signTypedData<T extends MessageTypes>(\n withAccount: string,\n data: TypedMessage<T>,\n options: { version?: string } = {},\n ): Promise<string> {\n const isV4 = options.version === 'V4';\n if (!isV4) {\n throw new Error(\n 'Ledger: Only version 4 of typed data signing is supported',\n );\n }\n\n const { domain, types, primaryType, message } =\n TypedDataUtils.sanitizeData(data);\n const domainSeparatorHex = TypedDataUtils.hashStruct(\n 'EIP712Domain',\n domain,\n types,\n SignTypedDataVersion.V4,\n ).toString('hex');\n const hashStructMessageHex = TypedDataUtils.hashStruct(\n primaryType.toString(),\n message,\n types,\n SignTypedDataVersion.V4,\n ).toString('hex');\n\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTypedData({\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = recoverTypedSignature({\n data,\n signature,\n version: SignTypedDataVersion.V4,\n });\n\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n exportAccount(): void {\n throw new Error('Not supported on this device');\n }\n\n forgetDevice(): void {\n this.deviceId = '';\n this.accounts = [];\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n this.accountDetails = {};\n this.hdk = new HDKey();\n }\n\n /* PRIVATE METHODS */\n async #getPage(increment: number): Promise<AccountPage> {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n await this.unlock();\n let accounts;\n if (this.#isLedgerLiveHdPath()) {\n accounts = await this.#getAccountsBIP44(from, to);\n } else {\n accounts = this.#getAccountsLegacy(from, to);\n }\n return accounts;\n }\n\n async #getAccountsBIP44(from: number, to: number): Promise<AccountPage> {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n const address = await this.unlock(path);\n const valid = this.implementFullBIP44\n ? await this.#hasPreviousTransactions(address)\n : true;\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n\n // PER BIP44\n // \"Software should prevent a creation of an account if\n // a previous account does not have a transaction history\n // (meaning none of its addresses have been used before).\"\n if (!valid) {\n break;\n }\n }\n return accounts;\n }\n\n #getAccountsLegacy(from: number, to: number): AccountPage {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n this.paths[ethUtil.toChecksumAddress(address)] = i;\n }\n return accounts;\n }\n\n #addressFromIndex(basePath: string, i: number): string {\n const dkey = this.hdk.derive(`${basePath}/${i}`);\n const address = ethUtil\n .publicToAddress(dkey.publicKey, true)\n .toString('hex');\n return ethUtil.toChecksumAddress(`0x${address}`);\n }\n\n #pathFromAddress(address: string): string {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n let index = this.paths[checksummedAddress];\n if (typeof index === 'undefined') {\n for (let i = 0; i < MAX_INDEX; i++) {\n if (checksummedAddress === this.#addressFromIndex(pathBase, i)) {\n index = i;\n break;\n }\n }\n }\n\n if (typeof index === 'undefined') {\n throw new Error('Unknown address');\n }\n return this.#getPathForIndex(index);\n }\n\n #getPathForIndex(index: number): string {\n // Check if the path is BIP 44 (Ledger Live)\n return this.#isLedgerLiveHdPath()\n ? `m/44'/60'/${index}'/0/0`\n : `${this.hdPath}/${index}`;\n }\n\n #isLedgerLiveHdPath(): boolean {\n return this.hdPath === `m/44'/60'/0'/0/0`;\n }\n\n #toLedgerPath(path: string): string {\n return path.toString().replace('m/', '');\n }\n\n async #hasPreviousTransactions(address: string): Promise<boolean> {\n const apiUrl = this.#getApiUrl();\n const response = await window.fetch(\n `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`,\n );\n const parsedResponse = await response.json();\n return parsedResponse.status !== '0' && parsedResponse.result.length > 0;\n }\n\n #getApiUrl(): NetworkApiUrls {\n return this.network;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-keyring.mjs","sourceRoot":"","sources":["../src/ledger-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,wBAAwB;;;;AAEtC,OAAO,KAAK,OAAO,yBAAyB;AAE5C,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACf,+BAA+B;AAChC,OAAO,EAAE,MAAM,EAAE,eAAe;AAEhC,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,4BAAwB;AACpE,OAAO,EAAE,yBAAyB,EAAE,mCAA+B;AAEnE,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,YAAY,GAAG,GAAG,QAAQ,aAAa,CAAC;AAC9C,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,+GAA+G;AAC/G,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,IAAK,cAKJ;AALD,WAAK,cAAc;IACjB,8DAA4C,CAAA;IAC5C,0DAAwC,CAAA;IACxC,8DAA4C,CAAA;IAC5C,sDAAoC,CAAA;AACtC,CAAC,EALI,cAAc,KAAd,cAAc,QAKlB;AA6BD;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAC7B,EAA0C;IAE1C,OAAO,YAAY,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC,UAAU,KAAK,UAAU,CAAC;AACnE,CAAC;AAED,MAAM,OAAO,aAAc,SAAQ,YAAY;IA6B7C,YAAY,EAAE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nimport * as ethUtil from '@ethereumjs/util';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport {\n recoverPersonalSignature,\n recoverTypedSignature,\n SignTypedDataVersion,\n TypedDataUtils,\n} from '@metamask/eth-sig-util';\nimport { Buffer } from 'buffer';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { LedgerBridge, LedgerBridgeOptions } from './ledger-bridge';\nimport { LedgerIframeBridgeOptions } from './ledger-iframe-bridge';\n\nconst pathBase = 'm';\nconst hdPathString = `${pathBase}/44'/60'/0'`;\nconst keyringType = 'Ledger Hardware';\n\n// This number causes one of our failing tests to run very slowly, as the for loop needs to iterate 1000 times.\nconst MAX_INDEX = 1000;\n\nenum NetworkApiUrls {\n Ropsten = 'https://api-ropsten.etherscan.io',\n Kovan = 'https://api-kovan.etherscan.io',\n Rinkeby = 'https://api-rinkeby.etherscan.io',\n Mainnet = `https://api.etherscan.io`,\n}\n\ntype SignTransactionPayload = Awaited<\n ReturnType<LedgerBridge<LedgerIframeBridgeOptions>['deviceSignTransaction']>\n>;\n\nexport type AccountPageEntry = {\n address: string;\n balance: number | null;\n index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport type AccountDetails = {\n index?: number;\n bip44?: boolean;\n hdPath?: string;\n};\n\nexport type LedgerBridgeKeyringOptions = {\n hdPath: string;\n accounts: readonly string[];\n deviceId: string;\n accountDetails: Readonly<Record<string, AccountDetails>>;\n accountIndexes: Readonly<Record<string, number>>;\n implementFullBIP44: boolean;\n};\n\n/**\n * Check if the given transaction is made with ethereumjs-tx or @ethereumjs/tx\n *\n * Transactions built with older versions of ethereumjs-tx have a\n * getChainId method that newer versions do not.\n * Older versions are mutable\n * while newer versions default to being immutable.\n * Expected shape and type\n * of data for v, r and s differ (Buffer (old) vs BN (new)).\n *\n * @param tx - Transaction to check, instance of either ethereumjs-tx or @ethereumjs/tx.\n * @returns Returns `true` if tx is an old-style ethereumjs-tx transaction.\n */\nfunction isOldStyleEthereumjsTx(\n tx: TypedTransaction | OldEthJsTransaction,\n): tx is OldEthJsTransaction {\n return 'getChainId' in tx && typeof tx.getChainId === 'function';\n}\n\nexport class LedgerKeyring extends EventEmitter {\n static type: string = keyringType;\n\n deviceId = '';\n\n readonly type: string = keyringType;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n accounts: readonly string[] = [];\n\n accountDetails: Record<string, AccountDetails> = {};\n\n hdk = new HDKey();\n\n hdPath = hdPathString;\n\n paths: Record<string, number> = {};\n\n network: NetworkApiUrls = NetworkApiUrls.Mainnet;\n\n implementFullBIP44 = false;\n\n bridge: LedgerBridge<LedgerBridgeOptions>;\n\n constructor({ bridge }: { bridge: LedgerBridge<LedgerBridgeOptions> }) {\n super();\n\n if (!bridge) {\n throw new Error('Bridge is a required dependency for the keyring');\n }\n\n this.bridge = bridge;\n }\n\n async init(): Promise<void> {\n return this.bridge.init();\n }\n\n async destroy(): Promise<void> {\n return this.bridge.destroy();\n }\n\n async serialize(): Promise<\n Partial<LedgerBridgeKeyringOptions> // Maybe we should have a proper \"state\" type here instead of using this \"options\" type.\n > {\n return {\n hdPath: this.hdPath,\n accounts: this.accounts,\n deviceId: this.deviceId,\n accountDetails: this.accountDetails,\n implementFullBIP44: false,\n };\n }\n\n async deserialize(\n opts: Partial<LedgerBridgeKeyringOptions> = {}, // Same question here?\n ): Promise<void> {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.accounts = opts.accounts ?? [];\n this.deviceId = opts.deviceId ?? '';\n this.accountDetails = opts.accountDetails ?? {};\n\n if (!opts.accountDetails) {\n this.#migrateAccountDetails(opts);\n }\n\n this.implementFullBIP44 = opts.implementFullBIP44 ?? false;\n\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // Remove accounts that don't have corresponding account details\n this.accounts = this.accounts.filter((account) =>\n keys.has(ethUtil.toChecksumAddress(account)),\n );\n\n return Promise.resolve();\n }\n\n public setDeviceId(deviceId: string): void {\n this.deviceId = deviceId;\n }\n\n public getDeviceId(): string {\n return this.deviceId;\n }\n\n #migrateAccountDetails(opts: Partial<LedgerBridgeKeyringOptions>): void {\n if (this.#isLedgerLiveHdPath() && opts.accountIndexes) {\n for (const [account, index] of Object.entries(opts.accountIndexes)) {\n this.accountDetails[account] = {\n bip44: true,\n hdPath: this.#getPathForIndex(index),\n };\n }\n }\n const keys = new Set<string>(Object.keys(this.accountDetails));\n // try to migrate non-LedgerLive accounts too\n if (!this.#isLedgerLiveHdPath()) {\n this.accounts.forEach((account) => {\n const key = ethUtil.toChecksumAddress(account);\n\n if (!keys.has(key)) {\n this.accountDetails[key] = {\n bip44: false,\n hdPath: this.#pathFromAddress(account),\n };\n }\n });\n }\n }\n\n isUnlocked(): boolean {\n return Boolean(this.hdk.publicKey);\n }\n\n isConnected(): boolean {\n return this.bridge.isDeviceConnected;\n }\n\n setAccountToUnlock(index: number): void {\n this.unlockedAccount = index;\n }\n\n setHdPath(hdPath: string): void {\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n }\n this.hdPath = hdPath;\n }\n\n async unlock(hdPath?: string, updateHdk = true): Promise<string> {\n if (this.isUnlocked() && !hdPath) {\n return 'already unlocked';\n }\n const path = hdPath ? this.#toLedgerPath(hdPath) : this.hdPath;\n\n let payload;\n try {\n payload = await this.bridge.getPublicKey({\n hdPath: path,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger Ethereum app closed. Open it to unlock.');\n }\n\n if (updateHdk && payload.chainCode) {\n this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex');\n }\n\n return payload.address;\n }\n\n async addAccounts(amount = 1): Promise<string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then(async (_) => {\n const from = this.unlockedAccount;\n const to = from + amount;\n const newAccounts: string[] = [];\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n let address;\n if (this.#isLedgerLiveHdPath()) {\n address = await this.unlock(path);\n } else {\n address = this.#addressFromIndex(pathBase, i);\n }\n\n this.accountDetails[ethUtil.toChecksumAddress(address)] = {\n // TODO: consider renaming this property, as the current name is misleading\n // It's currently used to represent whether an account uses the Ledger Live path.\n bip44: this.#isLedgerLiveHdPath(),\n hdPath: path,\n };\n\n if (!this.accounts.includes(address)) {\n this.accounts = [...this.accounts, address];\n newAccounts.push(address);\n }\n this.page = 0;\n }\n resolve(newAccounts);\n })\n .catch(reject);\n });\n }\n\n getName(): string {\n return keyringType;\n }\n\n async getFirstPage(): Promise<AccountPage> {\n this.page = 0;\n return this.#getPage(1);\n }\n\n async getNextPage(): Promise<AccountPage> {\n return this.#getPage(1);\n }\n\n async getPreviousPage(): Promise<AccountPage> {\n return this.#getPage(-1);\n }\n\n async getAccounts(): Promise<string[]> {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string): void {\n const filteredAccounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n\n if (filteredAccounts.length === this.accounts.length) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = filteredAccounts;\n delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n }\n\n async attemptMakeApp(): Promise<boolean> {\n return this.bridge.attemptMakeApp();\n }\n\n async updateTransportMethod(transportType: string): Promise<boolean> {\n return this.bridge.updateTransportMethod(transportType);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n let rawTxHex;\n // transactions built with older versions of ethereumjs-tx have a\n // getChainId method that newer versions do not. Older versions are mutable\n // while newer versions default to being immutable. Expected shape and type\n // of data for v, r and s differ (Buffer (old) vs BN (new))\n if (isOldStyleEthereumjsTx(tx)) {\n // In this version of ethereumjs-tx we must add the chainId in hex format\n // to the initial v value. The chainId must be included in the serialized\n // transaction which is only communicated to ethereumjs-tx in this\n // value. In newer versions the chainId is communicated via the 'Common'\n // object.\n // @ts-expect-error tx.v should be a Buffer, but we are assigning a string\n tx.v = ethUtil.bufferToHex(tx.getChainId());\n // @ts-expect-error tx.r should be a Buffer, but we are assigning a string\n tx.r = '0x00';\n // @ts-expect-error tx.s should be a Buffer, but we are assigning a string\n tx.s = '0x00';\n\n rawTxHex = tx.serialize().toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n tx.v = Buffer.from(payload.v, 'hex');\n tx.r = Buffer.from(payload.r, 'hex');\n tx.s = Buffer.from(payload.s, 'hex');\n return tx;\n });\n }\n\n // The below `encode` call is only necessary for legacy transactions, as `getMessageToSign`\n // calls `rlp.encode` internally for non-legacy transactions. As per the \"Transaction Execution\"\n // section of the ethereum yellow paper, transactions need to be \"well-formed RLP, with no additional\n // trailing bytes\".\n\n // Note also that `getMessageToSign` will return valid RLP for all transaction types, whereas the\n // `serialize` method will not for any transaction type except legacy. This is because `serialize` includes\n // empty r, s and v values in the encoded rlp. This is why we use `getMessageToSign` here instead of `serialize`.\n const messageToSign = tx.getMessageToSign(false);\n\n rawTxHex = Buffer.isBuffer(messageToSign)\n ? messageToSign.toString('hex')\n : Buffer.from(RLP.encode(messageToSign)).toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n // Because tx will be immutable, first get a plain javascript object that\n // represents the transaction. Using txData here as it aligns with the\n // nomenclature of ethereumjs/tx.\n const txData: TxData = tx.toJSON();\n // The fromTxData utility expects a type to support transactions with a type other than 0\n txData.type = tx.type;\n // The fromTxData utility expects v,r and s to be hex prefixed\n txData.v = ethUtil.addHexPrefix(payload.v);\n txData.r = ethUtil.addHexPrefix(payload.r);\n txData.s = ethUtil.addHexPrefix(payload.s);\n // Adopt the 'common' option from the original transaction and set the\n // returned object to be frozen if the original is frozen.\n return TransactionFactory.fromTxData(txData, {\n common: tx.common,\n freeze: Object.isFrozen(tx),\n });\n });\n }\n\n async #signTransaction(\n address: string,\n rawTxHex: string,\n handleSigning: (\n payload: SignTransactionPayload,\n ) => TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n const hdPath = await this.unlockAccountByAddress(address);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing transaction');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTransaction({\n tx: rawTxHex,\n hdPath,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing transaction');\n }\n\n const newOrMutatedTx = handleSigning(payload);\n const valid = newOrMutatedTx.verifySignature();\n if (valid) {\n return newOrMutatedTx;\n }\n throw new Error('Ledger: The transaction signature is not valid');\n }\n\n async signMessage(withAccount: string, data: string): Promise<string> {\n return this.signPersonalMessage(withAccount, data);\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n withAccount: string,\n message: string,\n ): Promise<string> {\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignMessage({\n hdPath,\n message: ethUtil.stripHexPrefix(message),\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let modifiedV = parseInt(String(payload.v), 10).toString(16);\n if (modifiedV.length < 2) {\n modifiedV = `0${modifiedV}`;\n }\n\n const signature = `0x${payload.r}${payload.s}${modifiedV}`;\n const addressSignedWith = recoverPersonalSignature({\n data: message,\n signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n async unlockAccountByAddress(address: string): Promise<string | undefined> {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n const accountDetails = this.accountDetails[checksummedAddress];\n if (!accountDetails) {\n throw new Error(\n `Ledger: Account for address '${checksummedAddress}' not found`,\n );\n }\n const { hdPath } = accountDetails;\n const unlockedAddress = await this.unlock(hdPath, false);\n\n // unlock resolves to the address for the given hdPath as reported by the ledger device\n // if that address is not the requested address, then this account belongs to a different device or seed\n if (unlockedAddress.toLowerCase() !== address.toLowerCase()) {\n throw new Error(\n `Ledger: Account ${address} does not belong to the connected device`,\n );\n }\n return hdPath;\n }\n\n async signTypedData<T extends MessageTypes>(\n withAccount: string,\n data: TypedMessage<T>,\n options: { version?: string } = {},\n ): Promise<string> {\n const isV4 = options.version === 'V4';\n if (!isV4) {\n throw new Error(\n 'Ledger: Only version 4 of typed data signing is supported',\n );\n }\n\n const { domain, types, primaryType, message } =\n TypedDataUtils.sanitizeData(data);\n\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTypedData({\n hdPath,\n message: {\n domain: {\n name: domain.name,\n chainId: domain.chainId,\n version: domain.version,\n verifyingContract: domain.verifyingContract,\n salt: this.#convertSaltIfAny(domain.salt),\n },\n types,\n primaryType: primaryType.toString(),\n message,\n },\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = recoverTypedSignature({\n data,\n signature,\n version: SignTypedDataVersion.V4,\n });\n\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n exportAccount(): void {\n throw new Error('Not supported on this device');\n }\n\n forgetDevice(): void {\n this.deviceId = '';\n this.accounts = [];\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n this.accountDetails = {};\n this.hdk = new HDKey();\n }\n\n #convertSaltIfAny(salt: ArrayBuffer | undefined): string | undefined {\n if (!salt) {\n return undefined;\n }\n\n // We convert this to a plain string to avoid encoding issue on the\n // mobile side (to avoid using `TextDecoder`).\n const saltBytes = new Uint8Array(salt);\n return String.fromCharCode(...saltBytes);\n }\n\n /* PRIVATE METHODS */\n async #getPage(increment: number): Promise<AccountPage> {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n await this.unlock();\n let accounts;\n if (this.#isLedgerLiveHdPath()) {\n accounts = await this.#getAccountsBIP44(from, to);\n } else {\n accounts = this.#getAccountsLegacy(from, to);\n }\n return accounts;\n }\n\n async #getAccountsBIP44(from: number, to: number): Promise<AccountPage> {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n const address = await this.unlock(path);\n const valid = this.implementFullBIP44\n ? await this.#hasPreviousTransactions(address)\n : true;\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n\n // PER BIP44\n // \"Software should prevent a creation of an account if\n // a previous account does not have a transaction history\n // (meaning none of its addresses have been used before).\"\n if (!valid) {\n break;\n }\n }\n return accounts;\n }\n\n #getAccountsLegacy(from: number, to: number): AccountPage {\n const accounts: AccountPage = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n this.paths[ethUtil.toChecksumAddress(address)] = i;\n }\n return accounts;\n }\n\n #addressFromIndex(basePath: string, i: number): string {\n const dkey = this.hdk.derive(`${basePath}/${i}`);\n const address = ethUtil\n .publicToAddress(dkey.publicKey, true)\n .toString('hex');\n return ethUtil.toChecksumAddress(`0x${address}`);\n }\n\n #pathFromAddress(address: string): string {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n let index = this.paths[checksummedAddress];\n if (typeof index === 'undefined') {\n for (let i = 0; i < MAX_INDEX; i++) {\n if (checksummedAddress === this.#addressFromIndex(pathBase, i)) {\n index = i;\n break;\n }\n }\n }\n\n if (typeof index === 'undefined') {\n throw new Error('Unknown address');\n }\n return this.#getPathForIndex(index);\n }\n\n #getPathForIndex(index: number): string {\n // Check if the path is BIP 44 (Ledger Live)\n return this.#isLedgerLiveHdPath()\n ? `m/44'/60'/${index}'/0/0`\n : `${this.hdPath}/${index}`;\n }\n\n #isLedgerLiveHdPath(): boolean {\n return this.hdPath === `m/44'/60'/0'/0/0`;\n }\n\n #toLedgerPath(path: string): string {\n return path.toString().replace('m/', '');\n }\n\n async #hasPreviousTransactions(address: string): Promise<boolean> {\n const apiUrl = this.#getApiUrl();\n const response = await window.fetch(\n `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`,\n );\n const parsedResponse = await response.json();\n return parsedResponse.status !== '0' && parsedResponse.result.length > 0;\n }\n\n #getApiUrl(): NetworkApiUrls {\n return this.network;\n }\n}\n"]}
|
|
@@ -10,13 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
13
|
var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
15
|
exports.LedgerMobileBridge = void 0;
|
|
19
|
-
const ledger_1 = __importDefault(require("@ledgerhq/hw-app-eth/lib/services/ledger/index.js"));
|
|
20
16
|
const ledger_bridge_1 = require("./ledger-bridge.cjs");
|
|
21
17
|
const ledger_hw_app_1 = require("./ledger-hw-app.cjs");
|
|
22
18
|
const ledger_transport_middleware_1 = require("./ledger-transport-middleware.cjs");
|
|
@@ -74,12 +70,11 @@ class LedgerMobileBridge {
|
|
|
74
70
|
*
|
|
75
71
|
* @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.
|
|
76
72
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
77
|
-
* @param params.
|
|
78
|
-
* @param params.hashStructMessageHex - The hashed struct message.
|
|
73
|
+
* @param params.message - The EIP712 message to sign.
|
|
79
74
|
* @returns Retrieve v, r, s from the signed message.
|
|
80
75
|
*/
|
|
81
|
-
async deviceSignTypedData({ hdPath,
|
|
82
|
-
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).
|
|
76
|
+
async deviceSignTypedData({ hdPath, message, }) {
|
|
77
|
+
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).signEIP712Message(hdPath, message);
|
|
83
78
|
}
|
|
84
79
|
/**
|
|
85
80
|
* Method to sign a transaction
|
|
@@ -91,8 +86,11 @@ class LedgerMobileBridge {
|
|
|
91
86
|
* @returns Retrieve v, r, s from the signed transaction.
|
|
92
87
|
*/
|
|
93
88
|
async deviceSignTransaction({ tx, hdPath, }) {
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).clearSignTransaction(hdPath, tx, {
|
|
90
|
+
externalPlugins: true,
|
|
91
|
+
erc20: true,
|
|
92
|
+
nft: true,
|
|
93
|
+
});
|
|
96
94
|
}
|
|
97
95
|
/**
|
|
98
96
|
* Method to retrieve the ethereum address for a given BIP 32 path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.cjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file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AAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;CAsBF;AAnMD,gDAmMC;;IAdG,IAAI,uBAAA,IAAI,+CAAqB,EAAE,CAAC;QAC9B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;IACnC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;IAQC,OAAO,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,SAAS,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\n\nimport {\n GetPublicKeyParams,\n GetPublicKeyResponse,\n LedgerBridge,\n LedgerSignMessageParams,\n LedgerSignMessageResponse,\n LedgerSignTransactionParams,\n LedgerSignTransactionResponse,\n LedgerSignTypedDataParams,\n LedgerSignTypedDataResponse,\n} from './ledger-bridge';\nimport { MetaMaskLedgerHwAppEth } from './ledger-hw-app';\nimport { TransportMiddleware } from './ledger-transport-middleware';\nimport {\n GetAppNameAndVersionResponse,\n LedgerMobileBridgeOptions,\n} from './type';\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\n getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;\n openEthApp(): Promise<void>;\n closeApps(): Promise<void>;\n};\n\n/**\n * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.\n */\nexport class LedgerMobileBridge implements MobileBridge {\n readonly #transportMiddleware?: TransportMiddleware;\n\n #opts: LedgerMobileBridgeOptions;\n\n isDeviceConnected = false;\n\n constructor(\n transportMiddleware: TransportMiddleware,\n opts: LedgerMobileBridgeOptions = {},\n ) {\n this.#opts = opts;\n this.#transportMiddleware = transportMiddleware;\n }\n\n /**\n * Method to initializes the keyring.\n * Mobile ledger doesnt not require init.\n *\n * @returns A promise that will resolve once the bridge is initialized.\n */\n async init(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Method to destroy the keyring.\n * It will dispose the transportmiddleware and set isDeviceConnected to false.\n */\n async destroy(): Promise<void> {\n try {\n await this.#getTransportMiddleWare().dispose();\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The EIP712 message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n message,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712Message(hdPath, message);\n }\n\n /**\n * Method to sign a transaction\n * Sending the hexadecimal transaction message to the device and returning the signed transaction.\n *\n * @param params - An object contains tx, hdPath.\n * @param params.tx - The raw ethereum transaction in hexadecimal to sign.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns Retrieve v, r, s from the signed transaction.\n */\n async deviceSignTransaction({\n tx,\n hdPath,\n }: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse> {\n return this.#getEthApp().clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20: true,\n nft: true,\n });\n }\n\n /**\n * Method to retrieve the ethereum address for a given BIP 32 path.\n *\n * @param params - An object contains hdPath.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns An object contains publicKey, address and chainCode.\n */\n async getPublicKey({\n hdPath,\n }: GetPublicKeyParams): Promise<GetPublicKeyResponse> {\n return await this.#getEthApp().getAddress(hdPath, false, true);\n }\n\n /**\n * Method to retrieve the current configuration.\n *\n * @returns Retrieve current configuration.\n */\n async getOptions(): Promise<LedgerMobileBridgeOptions> {\n return this.#opts;\n }\n\n /**\n * Method to set the current configuration.\n *\n * @param opts - An configuration object.\n */\n async setOptions(opts: LedgerMobileBridgeOptions): Promise<void> {\n this.#opts = opts;\n }\n\n /**\n * Method to set the transport object to communicate with the device.\n *\n * @param transport - The communication interface with the Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb).\n * @returns Retrieve boolean.\n */\n async updateTransportMethod(transport: Transport): Promise<boolean> {\n if (!transport.deviceModel) {\n throw new Error('Property `deviceModel` is not defined in `transport`.');\n }\n if (!transport.deviceModel.id) {\n throw new Error(\n 'Property `deviceModel.id` is not defined in `transport`.',\n );\n }\n this.#getTransportMiddleWare().setTransport(transport);\n this.isDeviceConnected = true;\n return Promise.resolve(true);\n }\n\n /**\n * Method to init eth app object on ledger device.\n * This method is not supported on mobile.\n */\n async attemptMakeApp(): Promise<boolean> {\n throw new Error('Method not supported.');\n }\n\n /**\n * Method to open ethereum application on ledger device.\n *\n */\n async openEthApp(): Promise<void> {\n await this.#getEthApp().openEthApp();\n }\n\n /**\n * Method to close all running application on ledger device.\n *\n */\n async closeApps(): Promise<void> {\n await this.#getEthApp().closeApps();\n }\n\n /**\n * Method to retrieve the name and version of the running application in ledger device.\n *\n * @returns An object contains appName and version.\n */\n async getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse> {\n return this.#getEthApp().getAppNameAndVersion();\n }\n\n /**\n * Method to retrieve the transport middleWare object.\n *\n * @returns The TransportMiddleware object.\n */\n #getTransportMiddleWare(): TransportMiddleware {\n if (this.#transportMiddleware) {\n return this.#transportMiddleware;\n }\n throw new Error('Instance `transportMiddleware` is not initialized.');\n }\n\n /**\n * Method to retrieve the ledger Eth App object.\n *\n * @returns The ledger Eth App object.\n */\n #getEthApp(): MetaMaskLedgerHwAppEth {\n return this.#getTransportMiddleWare().getEthApp();\n }\n}\n"]}
|
|
@@ -42,11 +42,10 @@ export declare class LedgerMobileBridge implements MobileBridge {
|
|
|
42
42
|
*
|
|
43
43
|
* @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.
|
|
44
44
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
45
|
-
* @param params.
|
|
46
|
-
* @param params.hashStructMessageHex - The hashed struct message.
|
|
45
|
+
* @param params.message - The EIP712 message to sign.
|
|
47
46
|
* @returns Retrieve v, r, s from the signed message.
|
|
48
47
|
*/
|
|
49
|
-
deviceSignTypedData({ hdPath,
|
|
48
|
+
deviceSignTypedData({ hdPath, message, }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse>;
|
|
50
49
|
/**
|
|
51
50
|
* Method to sign a transaction
|
|
52
51
|
* Sending the hexadecimal transaction message to the device and returning the signed transaction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,+BAA+B;AAEpD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5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AO,CAAC,OAAO,CAAC;IAcnE;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;OAIG;IACG,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;CAwBpE"}
|
|
@@ -42,11 +42,10 @@ export declare class LedgerMobileBridge implements MobileBridge {
|
|
|
42
42
|
*
|
|
43
43
|
* @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.
|
|
44
44
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
45
|
-
* @param params.
|
|
46
|
-
* @param params.hashStructMessageHex - The hashed struct message.
|
|
45
|
+
* @param params.message - The EIP712 message to sign.
|
|
47
46
|
* @returns Retrieve v, r, s from the signed message.
|
|
48
47
|
*/
|
|
49
|
-
deviceSignTypedData({ hdPath,
|
|
48
|
+
deviceSignTypedData({ hdPath, message, }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse>;
|
|
50
49
|
/**
|
|
51
50
|
* Method to sign a transaction
|
|
52
51
|
* Sending the hexadecimal transaction message to the device and returning the signed transaction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,+BAA+B;AAEpD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AAEzB,OAAO,EAAE,mBAAmB,EAAE,0CAAsC;AACpE,OAA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AC,OAAO,CAAC;IAIxC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;OAIG;IACG,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;CAwBpE"}
|
|
@@ -10,14 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
|
|
13
|
-
function $importDefault(module) {
|
|
14
|
-
if (module?.__esModule) {
|
|
15
|
-
return module.default;
|
|
16
|
-
}
|
|
17
|
-
return module;
|
|
18
|
-
}
|
|
19
|
-
import $ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger/index.js";
|
|
20
|
-
const ledgerService = $importDefault($ledgerService);
|
|
21
13
|
import { GetPublicKeyParams, GetPublicKeyResponse, LedgerBridge, LedgerSignMessageParams, LedgerSignMessageResponse, LedgerSignTransactionParams, LedgerSignTransactionResponse, LedgerSignTypedDataParams, LedgerSignTypedDataResponse } from "./ledger-bridge.mjs";
|
|
22
14
|
import { MetaMaskLedgerHwAppEth } from "./ledger-hw-app.mjs";
|
|
23
15
|
import { TransportMiddleware } from "./ledger-transport-middleware.mjs";
|
|
@@ -75,12 +67,11 @@ export class LedgerMobileBridge {
|
|
|
75
67
|
*
|
|
76
68
|
* @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.
|
|
77
69
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
78
|
-
* @param params.
|
|
79
|
-
* @param params.hashStructMessageHex - The hashed struct message.
|
|
70
|
+
* @param params.message - The EIP712 message to sign.
|
|
80
71
|
* @returns Retrieve v, r, s from the signed message.
|
|
81
72
|
*/
|
|
82
|
-
async deviceSignTypedData({ hdPath,
|
|
83
|
-
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).
|
|
73
|
+
async deviceSignTypedData({ hdPath, message, }) {
|
|
74
|
+
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).signEIP712Message(hdPath, message);
|
|
84
75
|
}
|
|
85
76
|
/**
|
|
86
77
|
* Method to sign a transaction
|
|
@@ -92,8 +83,11 @@ export class LedgerMobileBridge {
|
|
|
92
83
|
* @returns Retrieve v, r, s from the signed transaction.
|
|
93
84
|
*/
|
|
94
85
|
async deviceSignTransaction({ tx, hdPath, }) {
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).clearSignTransaction(hdPath, tx, {
|
|
87
|
+
externalPlugins: true,
|
|
88
|
+
erc20: true,
|
|
89
|
+
nft: true,
|
|
90
|
+
});
|
|
97
91
|
}
|
|
98
92
|
/**
|
|
99
93
|
* Method to retrieve the ethereum address for a given BIP 32 path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.mjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,cAAa,0DAAiD;;AAGrE,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AACzB,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AACzD,OAAO,EAAE,mBAAmB,EAAE,0CAAsC;AACpE,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EAC1B,mBAAe;AAShB;;GAEG;AACH,MAAM,OA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SAAS;QACb,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;CAsBF;;IAdG,IAAI,uBAAA,IAAI,+CAAqB,EAAE,CAAC;QAC9B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;IACnC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;IAQC,OAAO,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,SAAS,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import ledgerService from '@ledgerhq/hw-app-eth/lib/services/ledger';\nimport type Transport from '@ledgerhq/hw-transport';\n\nimport {\n GetPublicKeyParams,\n GetPublicKeyResponse,\n LedgerBridge,\n LedgerSignMessageParams,\n LedgerSignMessageResponse,\n LedgerSignTransactionParams,\n LedgerSignTransactionResponse,\n LedgerSignTypedDataParams,\n LedgerSignTypedDataResponse,\n} from './ledger-bridge';\nimport { MetaMaskLedgerHwAppEth } from './ledger-hw-app';\nimport { TransportMiddleware } from './ledger-transport-middleware';\nimport {\n GetAppNameAndVersionResponse,\n LedgerMobileBridgeOptions,\n} from './type';\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\n getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;\n openEthApp(): Promise<void>;\n closeApps(): Promise<void>;\n};\n\n/**\n * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.\n */\nexport class LedgerMobileBridge implements MobileBridge {\n readonly #transportMiddleware?: TransportMiddleware;\n\n #opts: LedgerMobileBridgeOptions;\n\n isDeviceConnected = false;\n\n constructor(\n transportMiddleware: TransportMiddleware,\n opts: LedgerMobileBridgeOptions = {},\n ) {\n this.#opts = opts;\n this.#transportMiddleware = transportMiddleware;\n }\n\n /**\n * Method to initializes the keyring.\n * Mobile ledger doesnt not require init.\n *\n * @returns A promise that will resolve once the bridge is initialized.\n */\n async init(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Method to destroy the keyring.\n * It will dispose the transportmiddleware and set isDeviceConnected to false.\n */\n async destroy(): Promise<void> {\n try {\n await this.#getTransportMiddleWare().dispose();\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.domainSeparatorHex - The domain separator.\n * @param params.hashStructMessageHex - The hashed struct message.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712HashedMessage(\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n );\n }\n\n /**\n * Method to sign a transaction\n * Sending the hexadecimal transaction message to the device and returning the signed transaction.\n *\n * @param params - An object contains tx, hdPath.\n * @param params.tx - The raw ethereum transaction in hexadecimal to sign.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns Retrieve v, r, s from the signed transaction.\n */\n async deviceSignTransaction({\n tx,\n hdPath,\n }: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse> {\n const resolution = await ledgerService.resolveTransaction(tx, {}, {});\n return this.#getEthApp().signTransaction(hdPath, tx, resolution);\n }\n\n /**\n * Method to retrieve the ethereum address for a given BIP 32 path.\n *\n * @param params - An object contains hdPath.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns An object contains publicKey, address and chainCode.\n */\n async getPublicKey({\n hdPath,\n }: GetPublicKeyParams): Promise<GetPublicKeyResponse> {\n return await this.#getEthApp().getAddress(hdPath, false, true);\n }\n\n /**\n * Method to retrieve the current configuration.\n *\n * @returns Retrieve current configuration.\n */\n async getOptions(): Promise<LedgerMobileBridgeOptions> {\n return this.#opts;\n }\n\n /**\n * Method to set the current configuration.\n *\n * @param opts - An configuration object.\n */\n async setOptions(opts: LedgerMobileBridgeOptions): Promise<void> {\n this.#opts = opts;\n }\n\n /**\n * Method to set the transport object to communicate with the device.\n *\n * @param transport - The communication interface with the Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb).\n * @returns Retrieve boolean.\n */\n async updateTransportMethod(transport: Transport): Promise<boolean> {\n if (!transport.deviceModel) {\n throw new Error('Property `deviceModel` is not defined in `transport`.');\n }\n if (!transport.deviceModel.id) {\n throw new Error(\n 'Property `deviceModel.id` is not defined in `transport`.',\n );\n }\n this.#getTransportMiddleWare().setTransport(transport);\n this.isDeviceConnected = true;\n return Promise.resolve(true);\n }\n\n /**\n * Method to init eth app object on ledger device.\n * This method is not supported on mobile.\n */\n async attemptMakeApp(): Promise<boolean> {\n throw new Error('Method not supported.');\n }\n\n /**\n * Method to open ethereum application on ledger device.\n *\n */\n async openEthApp(): Promise<void> {\n await this.#getEthApp().openEthApp();\n }\n\n /**\n * Method to close all running application on ledger device.\n *\n */\n async closeApps(): Promise<void> {\n await this.#getEthApp().closeApps();\n }\n\n /**\n * Method to retrieve the name and version of the running application in ledger device.\n *\n * @returns An object contains appName and version.\n */\n async getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse> {\n return this.#getEthApp().getAppNameAndVersion();\n }\n\n /**\n * Method to retrieve the transport middleWare object.\n *\n * @returns The TransportMiddleware object.\n */\n #getTransportMiddleWare(): TransportMiddleware {\n if (this.#transportMiddleware) {\n return this.#transportMiddleware;\n }\n throw new Error('Instance `transportMiddleware` is not initialized.');\n }\n\n /**\n * Method to retrieve the ledger Eth App object.\n *\n * @returns The ledger Eth App object.\n */\n #getEthApp(): MetaMaskLedgerHwAppEth {\n return this.#getTransportMiddleWare().getEthApp();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.mjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AACzB,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AACzD,OAAO,EAAE,mBAAmB,EAAE,0CAAsC;AACpE,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EAC1B,mBAAe;AAShB;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC;YACH,MAAM,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,OAAO,EAAE,CAAC;QACjD,CAAC;QAA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{\n GetPublicKeyParams,\n GetPublicKeyResponse,\n LedgerBridge,\n LedgerSignMessageParams,\n LedgerSignMessageResponse,\n LedgerSignTransactionParams,\n LedgerSignTransactionResponse,\n LedgerSignTypedDataParams,\n LedgerSignTypedDataResponse,\n} from './ledger-bridge';\nimport { MetaMaskLedgerHwAppEth } from './ledger-hw-app';\nimport { TransportMiddleware } from './ledger-transport-middleware';\nimport {\n GetAppNameAndVersionResponse,\n LedgerMobileBridgeOptions,\n} from './type';\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\n getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;\n openEthApp(): Promise<void>;\n closeApps(): Promise<void>;\n};\n\n/**\n * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.\n */\nexport class LedgerMobileBridge implements MobileBridge {\n readonly #transportMiddleware?: TransportMiddleware;\n\n #opts: LedgerMobileBridgeOptions;\n\n isDeviceConnected = false;\n\n constructor(\n transportMiddleware: TransportMiddleware,\n opts: LedgerMobileBridgeOptions = {},\n ) {\n this.#opts = opts;\n this.#transportMiddleware = transportMiddleware;\n }\n\n /**\n * Method to initializes the keyring.\n * Mobile ledger doesnt not require init.\n *\n * @returns A promise that will resolve once the bridge is initialized.\n */\n async init(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Method to destroy the keyring.\n * It will dispose the transportmiddleware and set isDeviceConnected to false.\n */\n async destroy(): Promise<void> {\n try {\n await this.#getTransportMiddleWare().dispose();\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The EIP712 message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n message,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712Message(hdPath, message);\n }\n\n /**\n * Method to sign a transaction\n * Sending the hexadecimal transaction message to the device and returning the signed transaction.\n *\n * @param params - An object contains tx, hdPath.\n * @param params.tx - The raw ethereum transaction in hexadecimal to sign.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns Retrieve v, r, s from the signed transaction.\n */\n async deviceSignTransaction({\n tx,\n hdPath,\n }: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse> {\n return this.#getEthApp().clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20: true,\n nft: true,\n });\n }\n\n /**\n * Method to retrieve the ethereum address for a given BIP 32 path.\n *\n * @param params - An object contains hdPath.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns An object contains publicKey, address and chainCode.\n */\n async getPublicKey({\n hdPath,\n }: GetPublicKeyParams): Promise<GetPublicKeyResponse> {\n return await this.#getEthApp().getAddress(hdPath, false, true);\n }\n\n /**\n * Method to retrieve the current configuration.\n *\n * @returns Retrieve current configuration.\n */\n async getOptions(): Promise<LedgerMobileBridgeOptions> {\n return this.#opts;\n }\n\n /**\n * Method to set the current configuration.\n *\n * @param opts - An configuration object.\n */\n async setOptions(opts: LedgerMobileBridgeOptions): Promise<void> {\n this.#opts = opts;\n }\n\n /**\n * Method to set the transport object to communicate with the device.\n *\n * @param transport - The communication interface with the Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb).\n * @returns Retrieve boolean.\n */\n async updateTransportMethod(transport: Transport): Promise<boolean> {\n if (!transport.deviceModel) {\n throw new Error('Property `deviceModel` is not defined in `transport`.');\n }\n if (!transport.deviceModel.id) {\n throw new Error(\n 'Property `deviceModel.id` is not defined in `transport`.',\n );\n }\n this.#getTransportMiddleWare().setTransport(transport);\n this.isDeviceConnected = true;\n return Promise.resolve(true);\n }\n\n /**\n * Method to init eth app object on ledger device.\n * This method is not supported on mobile.\n */\n async attemptMakeApp(): Promise<boolean> {\n throw new Error('Method not supported.');\n }\n\n /**\n * Method to open ethereum application on ledger device.\n *\n */\n async openEthApp(): Promise<void> {\n await this.#getEthApp().openEthApp();\n }\n\n /**\n * Method to close all running application on ledger device.\n *\n */\n async closeApps(): Promise<void> {\n await this.#getEthApp().closeApps();\n }\n\n /**\n * Method to retrieve the name and version of the running application in ledger device.\n *\n * @returns An object contains appName and version.\n */\n async getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse> {\n return this.#getEthApp().getAppNameAndVersion();\n }\n\n /**\n * Method to retrieve the transport middleWare object.\n *\n * @returns The TransportMiddleware object.\n */\n #getTransportMiddleWare(): TransportMiddleware {\n if (this.#transportMiddleware) {\n return this.#transportMiddleware;\n }\n throw new Error('Instance `transportMiddleware` is not initialized.');\n }\n\n /**\n * Method to retrieve the ledger Eth App object.\n *\n * @returns The ledger Eth App object.\n */\n #getEthApp(): MetaMaskLedgerHwAppEth {\n return this.#getTransportMiddleWare().getEthApp();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/eth-ledger-bridge-keyring",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "A MetaMask compatible keyring, for ledger hardware wallets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -61,9 +61,10 @@
|
|
|
61
61
|
"@ledgerhq/hw-transport": "^6.31.3",
|
|
62
62
|
"@ledgerhq/types-cryptoassets": "^7.15.1",
|
|
63
63
|
"@ledgerhq/types-devices": "^6.25.3",
|
|
64
|
+
"@ledgerhq/types-live": "^6.52.0",
|
|
64
65
|
"@metamask/auto-changelog": "^3.4.4",
|
|
65
|
-
"@metamask/utils": "^9.
|
|
66
|
-
"@ts-bridge/cli": "^0.6.
|
|
66
|
+
"@metamask/utils": "^9.3.0",
|
|
67
|
+
"@ts-bridge/cli": "^0.6.1",
|
|
67
68
|
"@types/ethereumjs-tx": "^1.0.1",
|
|
68
69
|
"@types/hdkey": "^2.0.1",
|
|
69
70
|
"@types/jest": "^29.5.12",
|