@metamask-previews/eth-trezor-keyring 6.0.0-e345222 → 6.0.1-0aca2ee
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 +9 -1
- package/dist/trezor-bridge.cjs.map +1 -1
- package/dist/trezor-bridge.d.cts +5 -4
- package/dist/trezor-bridge.d.cts.map +1 -1
- package/dist/trezor-bridge.d.mts +5 -4
- package/dist/trezor-bridge.d.mts.map +1 -1
- package/dist/trezor-bridge.mjs.map +1 -1
- package/dist/trezor-connect-bridge.cjs.map +1 -1
- package/dist/trezor-connect-bridge.d.cts +2 -3
- package/dist/trezor-connect-bridge.d.cts.map +1 -1
- package/dist/trezor-connect-bridge.d.mts +2 -3
- package/dist/trezor-connect-bridge.d.mts.map +1 -1
- package/dist/trezor-connect-bridge.mjs.map +1 -1
- package/dist/trezor-keyring.mjs +2 -1
- package/dist/trezor-keyring.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.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
|
+
|
|
10
17
|
## [6.0.0]
|
|
11
18
|
|
|
12
19
|
### Added
|
|
@@ -141,7 +148,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
141
148
|
|
|
142
149
|
- Support new versions of ethereumjs/tx ([#88](https://github.com/metamask/eth-trezor-keyring/pull/88))
|
|
143
150
|
|
|
144
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-trezor-keyring@6.0.
|
|
151
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-trezor-keyring@6.0.1...HEAD
|
|
152
|
+
[6.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-trezor-keyring@6.0.0...@metamask/eth-trezor-keyring@6.0.1
|
|
145
153
|
[6.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-trezor-keyring@5.0.0...@metamask/eth-trezor-keyring@6.0.0
|
|
146
154
|
[5.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-trezor-keyring@4.0.0...@metamask/eth-trezor-keyring@5.0.0
|
|
147
155
|
[4.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-trezor-keyring@3.1.3...@metamask/eth-trezor-keyring@4.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-bridge.cjs","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ConnectSettings,\n EthereumSignedTx,\n Manifest,\n PROTO,\n Response,\n Params,\n EthereumSignMessage,\n EthereumSignTransaction,\n EthereumSignTypedDataTypes,\n EthereumSignTypedHash,\n} from '@trezor/connect-web';\n\nexport interface TrezorBridge {\n model?: string;\n\n init(\n settings: {\n manifest: Manifest;\n } & Partial<ConnectSettings>,\n ): Promise<void>;\n\n dispose(): Promise<void>;\n\n
|
|
1
|
+
{"version":3,"file":"trezor-bridge.cjs","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ConnectSettings,\n EthereumSignedTx,\n Manifest,\n PROTO,\n Response,\n Params,\n EthereumSignMessage,\n EthereumSignTransaction,\n EthereumSignTypedDataTypes,\n EthereumSignTypedHash,\n} from '@trezor/connect-web';\n\n// TrezorConnect.getPublicKey has two overloads\n// It is not possible to extract them from the library using utility types\nexport type ExtendedPublicKey = { publicKey: string; chainCode: string };\n\nexport interface TrezorBridge {\n model?: string;\n\n init(\n settings: {\n manifest: Manifest;\n } & Partial<ConnectSettings>,\n ): Promise<void>;\n\n dispose(): Promise<void>;\n\n getPublicKey(params: {\n path: string;\n coin: string;\n }): Response<ExtendedPublicKey>;\n\n ethereumSignTransaction(\n params: Params<EthereumSignTransaction>,\n ): Response<EthereumSignedTx>;\n\n ethereumSignMessage(\n params: Params<EthereumSignMessage>,\n ): Response<PROTO.MessageSignature>;\n\n ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(\n params: Params<EthereumSignTypedHash<T>>,\n ): Response<PROTO.EthereumTypedDataSignature>;\n}\n"]}
|
package/dist/trezor-bridge.d.cts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { ConnectSettings, EthereumSignedTx, Manifest, PROTO, Response, Params, EthereumSignMessage, EthereumSignTransaction, EthereumSignTypedDataTypes, EthereumSignTypedHash } from "@trezor/connect-web";
|
|
2
|
+
export type ExtendedPublicKey = {
|
|
3
|
+
publicKey: string;
|
|
4
|
+
chainCode: string;
|
|
5
|
+
};
|
|
2
6
|
export interface TrezorBridge {
|
|
3
7
|
model?: string;
|
|
4
8
|
init(settings: {
|
|
@@ -8,10 +12,7 @@ export interface TrezorBridge {
|
|
|
8
12
|
getPublicKey(params: {
|
|
9
13
|
path: string;
|
|
10
14
|
coin: string;
|
|
11
|
-
}): Response<
|
|
12
|
-
publicKey: string;
|
|
13
|
-
chainCode: string;
|
|
14
|
-
}>;
|
|
15
|
+
}): Response<ExtendedPublicKey>;
|
|
15
16
|
ethereumSignTransaction(params: Params<EthereumSignTransaction>): Response<EthereumSignedTx>;
|
|
16
17
|
ethereumSignMessage(params: Params<EthereumSignMessage>): Response<PROTO.MessageSignature>;
|
|
17
18
|
ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(params: Params<EthereumSignTypedHash<T>>): Response<PROTO.EthereumTypedDataSignature>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-bridge.d.cts","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAC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,CAAC,CAAC;CAC/C"}
|
package/dist/trezor-bridge.d.mts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { ConnectSettings, EthereumSignedTx, Manifest, PROTO, Response, Params, EthereumSignMessage, EthereumSignTransaction, EthereumSignTypedDataTypes, EthereumSignTypedHash } from "@trezor/connect-web";
|
|
2
|
+
export type ExtendedPublicKey = {
|
|
3
|
+
publicKey: string;
|
|
4
|
+
chainCode: string;
|
|
5
|
+
};
|
|
2
6
|
export interface TrezorBridge {
|
|
3
7
|
model?: string;
|
|
4
8
|
init(settings: {
|
|
@@ -8,10 +12,7 @@ export interface TrezorBridge {
|
|
|
8
12
|
getPublicKey(params: {
|
|
9
13
|
path: string;
|
|
10
14
|
coin: string;
|
|
11
|
-
}): Response<
|
|
12
|
-
publicKey: string;
|
|
13
|
-
chainCode: string;
|
|
14
|
-
}>;
|
|
15
|
+
}): Response<ExtendedPublicKey>;
|
|
15
16
|
ethereumSignTransaction(params: Params<EthereumSignTransaction>): Response<EthereumSignedTx>;
|
|
16
17
|
ethereumSignMessage(params: Params<EthereumSignMessage>): Response<PROTO.MessageSignature>;
|
|
17
18
|
ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(params: Params<EthereumSignTypedHash<T>>): Response<PROTO.EthereumTypedDataSignature>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-bridge.d.mts","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACtB,4BAA4B;
|
|
1
|
+
{"version":3,"file":"trezor-bridge.d.mts","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACtB,4BAA4B;AAI7B,MAAM,MAAM,iBAAiB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,CACF,QAAQ,EAAE;QACR,QAAQ,EAAE,QAAQ,CAAC;KACpB,GAAG,OAAO,CAAC,eAAe,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,YAAY,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAEhC,uBAAuB,CACrB,MAAM,EAAE,MAAM,CAAC,uBAAuB,CAAC,GACtC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE9B,mBAAmB,CACjB,MAAM,EAAE,MAAM,CAAC,mBAAmB,CAAC,GAClC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAEpC,qBAAqB,CAAC,CAAC,SAAS,0BAA0B,EACxD,MAAM,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GACvC,QAAQ,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;CAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-bridge.mjs","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ConnectSettings,\n EthereumSignedTx,\n Manifest,\n PROTO,\n Response,\n Params,\n EthereumSignMessage,\n EthereumSignTransaction,\n EthereumSignTypedDataTypes,\n EthereumSignTypedHash,\n} from '@trezor/connect-web';\n\nexport interface TrezorBridge {\n model?: string;\n\n init(\n settings: {\n manifest: Manifest;\n } & Partial<ConnectSettings>,\n ): Promise<void>;\n\n dispose(): Promise<void>;\n\n
|
|
1
|
+
{"version":3,"file":"trezor-bridge.mjs","sourceRoot":"","sources":["../src/trezor-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ConnectSettings,\n EthereumSignedTx,\n Manifest,\n PROTO,\n Response,\n Params,\n EthereumSignMessage,\n EthereumSignTransaction,\n EthereumSignTypedDataTypes,\n EthereumSignTypedHash,\n} from '@trezor/connect-web';\n\n// TrezorConnect.getPublicKey has two overloads\n// It is not possible to extract them from the library using utility types\nexport type ExtendedPublicKey = { publicKey: string; chainCode: string };\n\nexport interface TrezorBridge {\n model?: string;\n\n init(\n settings: {\n manifest: Manifest;\n } & Partial<ConnectSettings>,\n ): Promise<void>;\n\n dispose(): Promise<void>;\n\n getPublicKey(params: {\n path: string;\n coin: string;\n }): Response<ExtendedPublicKey>;\n\n ethereumSignTransaction(\n params: Params<EthereumSignTransaction>,\n ): Response<EthereumSignedTx>;\n\n ethereumSignMessage(\n params: Params<EthereumSignMessage>,\n ): Response<PROTO.MessageSignature>;\n\n ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(\n params: Params<EthereumSignTypedHash<T>>,\n ): Response<PROTO.EthereumTypedDataSignature>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-connect-bridge.cjs","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"trezor-connect-bridge.cjs","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAA0E;AAgB1E,MAAa,mBAAmB;IAAhC;QAGE,2BAAsB,GAAG,KAAK,CAAC;IAsDjC,CAAC;IApDC,KAAK,CAAC,IAAI,CACR,QAE4B;QAE5B,qBAAa,CAAC,EAAE,CAAC,0BAAY,EAAE,CAAC,KAAK,EAAE,EAAE;;YACvC,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAM,CAAC,OAAO,EAAE,CAAC;gBAClC,OAAO;YACT,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,MAAA,KAAK,CAAC,OAAO,CAAC,QAAQ,0CAAE,KAAK,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,MAAM,qBAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,sDAAsD;QACtD,wEAAwE;QACxE,sHAAsH;QACtH,qBAAa,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,YAAY,CAAC,MAGZ;QACC,OAAO,qBAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,uBAAuB,CACrB,MAAuC;QAEvC,OAAO,qBAAa,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;IAED,mBAAmB,CACjB,MAAmC;QAEnC,OAAO,qBAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,qBAAqB,CACnB,MAAwC;QAExC,OAAO,qBAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;CACF;AAzDD,kDAyDC","sourcesContent":["import TrezorConnect, { DEVICE_EVENT, DEVICE } from '@trezor/connect-web';\nimport type {\n EthereumSignedTx,\n PROTO,\n Response,\n Manifest,\n ConnectSettings,\n EthereumSignTransaction,\n Params,\n EthereumSignMessage,\n EthereumSignTypedDataTypes,\n EthereumSignTypedHash,\n} from '@trezor/connect-web';\n\nimport type { TrezorBridge, ExtendedPublicKey } from './trezor-bridge';\n\nexport class TrezorConnectBridge implements TrezorBridge {\n model?: string;\n\n trezorConnectInitiated = false;\n\n async init(\n settings: {\n manifest: Manifest;\n } & Partial<ConnectSettings>,\n ): Promise<void> {\n TrezorConnect.on(DEVICE_EVENT, (event) => {\n if (event.type !== DEVICE.CONNECT) {\n return;\n }\n this.model = event.payload.features?.model;\n });\n\n if (this.trezorConnectInitiated) {\n return;\n }\n\n await TrezorConnect.init(settings);\n this.trezorConnectInitiated = true;\n }\n\n async dispose(): Promise<void> {\n // This removes the Trezor Connect iframe from the DOM\n // This method is not well documented, but the code it calls can be seen\n // here: https://github.com/trezor/connect/blob/dec4a56af8a65a6059fb5f63fa3c6690d2c37e00/src/js/iframe/builder.js#L181\n TrezorConnect.dispose();\n return Promise.resolve();\n }\n\n getPublicKey(params: {\n path: string;\n coin: string;\n }): Response<ExtendedPublicKey> {\n return TrezorConnect.getPublicKey(params);\n }\n\n ethereumSignTransaction(\n params: Params<EthereumSignTransaction>,\n ): Response<EthereumSignedTx> {\n return TrezorConnect.ethereumSignTransaction(params);\n }\n\n ethereumSignMessage(\n params: Params<EthereumSignMessage>,\n ): Response<PROTO.MessageSignature> {\n return TrezorConnect.ethereumSignMessage(params);\n }\n\n ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(\n params: Params<EthereumSignTypedHash<T>>,\n ): Response<PROTO.EthereumTypedDataSignature> {\n return TrezorConnect.ethereumSignTypedData(params);\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { HDNodeResponse } from "@trezor/connect/lib/types/api/getPublicKey.js";
|
|
2
1
|
import type { EthereumSignedTx, PROTO, Response, Manifest, ConnectSettings, EthereumSignTransaction, Params, EthereumSignMessage, EthereumSignTypedDataTypes, EthereumSignTypedHash } from "@trezor/connect-web";
|
|
3
|
-
import type { TrezorBridge } from "./trezor-bridge.cjs";
|
|
2
|
+
import type { TrezorBridge, ExtendedPublicKey } from "./trezor-bridge.cjs";
|
|
4
3
|
export declare class TrezorConnectBridge implements TrezorBridge {
|
|
5
4
|
model?: string;
|
|
6
5
|
trezorConnectInitiated: boolean;
|
|
@@ -11,7 +10,7 @@ export declare class TrezorConnectBridge implements TrezorBridge {
|
|
|
11
10
|
getPublicKey(params: {
|
|
12
11
|
path: string;
|
|
13
12
|
coin: string;
|
|
14
|
-
}): Response<
|
|
13
|
+
}): Response<ExtendedPublicKey>;
|
|
15
14
|
ethereumSignTransaction(params: Params<EthereumSignTransaction>): Response<EthereumSignedTx>;
|
|
16
15
|
ethereumSignMessage(params: Params<EthereumSignMessage>): Response<PROTO.MessageSignature>;
|
|
17
16
|
ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(params: Params<EthereumSignTypedHash<T>>): Response<PROTO.EthereumTypedDataSignature>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-connect-bridge.d.cts","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trezor-connect-bridge.d.cts","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,MAAM,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,4BAAwB;AAEvE,qBAAa,mBAAoB,YAAW,YAAY;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,sBAAsB,UAAS;IAEzB,IAAI,CACR,QAAQ,EAAE;QACR,QAAQ,EAAE,QAAQ,CAAC;KACpB,GAAG,OAAO,CAAC,eAAe,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC;IAgBV,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B,YAAY,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,QAAQ,CAAC,iBAAiB,CAAC;IAI/B,uBAAuB,CACrB,MAAM,EAAE,MAAM,CAAC,uBAAuB,CAAC,GACtC,QAAQ,CAAC,gBAAgB,CAAC;IAI7B,mBAAmB,CACjB,MAAM,EAAE,MAAM,CAAC,mBAAmB,CAAC,GAClC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAInC,qBAAqB,CAAC,CAAC,SAAS,0BAA0B,EACxD,MAAM,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GACvC,QAAQ,CAAC,KAAK,CAAC,0BAA0B,CAAC;CAG9C"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { HDNodeResponse } from "@trezor/connect/lib/types/api/getPublicKey.js";
|
|
2
1
|
import type { EthereumSignedTx, PROTO, Response, Manifest, ConnectSettings, EthereumSignTransaction, Params, EthereumSignMessage, EthereumSignTypedDataTypes, EthereumSignTypedHash } from "@trezor/connect-web";
|
|
3
|
-
import type { TrezorBridge } from "./trezor-bridge.mjs";
|
|
2
|
+
import type { TrezorBridge, ExtendedPublicKey } from "./trezor-bridge.mjs";
|
|
4
3
|
export declare class TrezorConnectBridge implements TrezorBridge {
|
|
5
4
|
model?: string;
|
|
6
5
|
trezorConnectInitiated: boolean;
|
|
@@ -11,7 +10,7 @@ export declare class TrezorConnectBridge implements TrezorBridge {
|
|
|
11
10
|
getPublicKey(params: {
|
|
12
11
|
path: string;
|
|
13
12
|
coin: string;
|
|
14
|
-
}): Response<
|
|
13
|
+
}): Response<ExtendedPublicKey>;
|
|
15
14
|
ethereumSignTransaction(params: Params<EthereumSignTransaction>): Response<EthereumSignedTx>;
|
|
16
15
|
ethereumSignMessage(params: Params<EthereumSignMessage>): Response<PROTO.MessageSignature>;
|
|
17
16
|
ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(params: Params<EthereumSignTypedHash<T>>): Response<PROTO.EthereumTypedDataSignature>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-connect-bridge.d.mts","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trezor-connect-bridge.d.mts","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,MAAM,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,4BAAwB;AAEvE,qBAAa,mBAAoB,YAAW,YAAY;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,sBAAsB,UAAS;IAEzB,IAAI,CACR,QAAQ,EAAE;QACR,QAAQ,EAAE,QAAQ,CAAC;KACpB,GAAG,OAAO,CAAC,eAAe,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC;IAgBV,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B,YAAY,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,QAAQ,CAAC,iBAAiB,CAAC;IAI/B,uBAAuB,CACrB,MAAM,EAAE,MAAM,CAAC,uBAAuB,CAAC,GACtC,QAAQ,CAAC,gBAAgB,CAAC;IAI7B,mBAAmB,CACjB,MAAM,EAAE,MAAM,CAAC,mBAAmB,CAAC,GAClC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAInC,qBAAqB,CAAC,CAAC,SAAS,0BAA0B,EACxD,MAAM,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GACvC,QAAQ,CAAC,KAAK,CAAC,0BAA0B,CAAC;CAG9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-connect-bridge.mjs","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"trezor-connect-bridge.mjs","sourceRoot":"","sources":["../src/trezor-connect-bridge.ts"],"names":[],"mappings":";;;;;;;;;AAgBA,MAAM,OAAO,mBAAmB;IAAhC;QAGE,2BAAsB,GAAG,KAAK,CAAC;IAsDjC,CAAC;IApDC,KAAK,CAAC,IAAI,CACR,QAE4B;QAE5B,aAAa,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;;YACvC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC;gBAClC,OAAO;YACT,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,MAAA,KAAK,CAAC,OAAO,CAAC,QAAQ,0CAAE,KAAK,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,MAAM,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,sDAAsD;QACtD,wEAAwE;QACxE,sHAAsH;QACtH,aAAa,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,YAAY,CAAC,MAGZ;QACC,OAAO,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,uBAAuB,CACrB,MAAuC;QAEvC,OAAO,aAAa,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;IAED,mBAAmB,CACjB,MAAmC;QAEnC,OAAO,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,qBAAqB,CACnB,MAAwC;QAExC,OAAO,aAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;CACF","sourcesContent":["import TrezorConnect, { DEVICE_EVENT, DEVICE } from '@trezor/connect-web';\nimport type {\n EthereumSignedTx,\n PROTO,\n Response,\n Manifest,\n ConnectSettings,\n EthereumSignTransaction,\n Params,\n EthereumSignMessage,\n EthereumSignTypedDataTypes,\n EthereumSignTypedHash,\n} from '@trezor/connect-web';\n\nimport type { TrezorBridge, ExtendedPublicKey } from './trezor-bridge';\n\nexport class TrezorConnectBridge implements TrezorBridge {\n model?: string;\n\n trezorConnectInitiated = false;\n\n async init(\n settings: {\n manifest: Manifest;\n } & Partial<ConnectSettings>,\n ): Promise<void> {\n TrezorConnect.on(DEVICE_EVENT, (event) => {\n if (event.type !== DEVICE.CONNECT) {\n return;\n }\n this.model = event.payload.features?.model;\n });\n\n if (this.trezorConnectInitiated) {\n return;\n }\n\n await TrezorConnect.init(settings);\n this.trezorConnectInitiated = true;\n }\n\n async dispose(): Promise<void> {\n // This removes the Trezor Connect iframe from the DOM\n // This method is not well documented, but the code it calls can be seen\n // here: https://github.com/trezor/connect/blob/dec4a56af8a65a6059fb5f63fa3c6690d2c37e00/src/js/iframe/builder.js#L181\n TrezorConnect.dispose();\n return Promise.resolve();\n }\n\n getPublicKey(params: {\n path: string;\n coin: string;\n }): Response<ExtendedPublicKey> {\n return TrezorConnect.getPublicKey(params);\n }\n\n ethereumSignTransaction(\n params: Params<EthereumSignTransaction>,\n ): Response<EthereumSignedTx> {\n return TrezorConnect.ethereumSignTransaction(params);\n }\n\n ethereumSignMessage(\n params: Params<EthereumSignMessage>,\n ): Response<PROTO.MessageSignature> {\n return TrezorConnect.ethereumSignMessage(params);\n }\n\n ethereumSignTypedData<T extends EthereumSignTypedDataTypes>(\n params: Params<EthereumSignTypedHash<T>>,\n ): Response<PROTO.EthereumTypedDataSignature> {\n return TrezorConnect.ethereumSignTypedData(params);\n }\n}\n"]}
|
package/dist/trezor-keyring.mjs
CHANGED
|
@@ -12,8 +12,9 @@ function $importDefault(module) {
|
|
|
12
12
|
}
|
|
13
13
|
import { TransactionFactory } from "@ethereumjs/tx";
|
|
14
14
|
import * as ethUtil from "@ethereumjs/util";
|
|
15
|
+
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
15
16
|
import $metamaskethsigutil from "@metamask/eth-sig-util";
|
|
16
|
-
const { TypedMessage,
|
|
17
|
+
const { TypedMessage, MessageTypes } = $metamaskethsigutil;
|
|
17
18
|
import { transformTypedData } from "@trezor/connect-plugin-ethereum";
|
|
18
19
|
import { EventEmitter } from "events";
|
|
19
20
|
import $HDKey from "hdkey";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trezor-keyring.mjs","sourceRoot":"","sources":["../src/trezor-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB;AAEpD,OAAO,KAAK,OAAO,yBAAyB;;;AAM5C,OAAO,EAAE,kBAAkB,EAAE,wCAAwC;AAOrE,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,YAAY,EAAE,4BAAwB;AAE/C,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAC5C,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,MAAM,gBAAgB,GAAG;IACvB,CAAC,YAAY,CAAC,EAAE,IAAI;IACpB,CAAC,aAAa,CAAC,EAAE,IAAI;IACrB,CAAC,mBAAmB,CAAC,EAAE,IAAI;CACnB,CAAC;AAEX,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,KAAK,EAAE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;QACH,CAAC;IACH,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;AACnC,CAAC;AA3eM,kBAAI,GAAW,WAAW,AAAtB,CAAuB","sourcesContent":["import { TransactionFactory } from '@ethereumjs/tx';\nimport type { TypedTransaction, TxData } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport {\n TypedMessage,\n SignTypedDataVersion,\n MessageTypes,\n} from '@metamask/eth-sig-util';\nimport { transformTypedData } from '@trezor/connect-plugin-ethereum';\nimport type {\n EthereumTransactionEIP1559,\n EthereumSignedTx,\n EthereumTransaction,\n} from '@trezor/connect-web';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { TrezorBridge } from './trezor-bridge';\n\nconst hdPathString = `m/44'/60'/0'/0`;\nconst SLIP0044TestnetPath = `m/44'/1'/0'/0`;\nconst legacyMewPath = `m/44'/60'/0'`;\n\nconst ALLOWED_HD_PATHS = {\n [hdPathString]: true,\n [legacyMewPath]: true,\n [SLIP0044TestnetPath]: true,\n} as const;\n\nconst keyringType = 'Trezor Hardware';\nconst pathBase = 'm';\nconst MAX_INDEX = 1000;\nconst DELAY_BETWEEN_POPUPS = 1000;\nexport const TREZOR_CONNECT_MANIFEST = {\n email: 'support@metamask.io',\n appUrl: 'https://metamask.io',\n};\n\nexport type AccountPageEntry = {\n address: string;\n balance: number | null;\n index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport interface TrezorControllerOptions {\n hdPath?: string;\n accounts?: string[];\n page?: number;\n perPage?: number;\n}\n\nexport interface TrezorControllerState {\n hdPath: string;\n accounts: readonly string[];\n page: number;\n paths: Record<string, number>;\n perPage: number;\n unlockedAccount: number;\n}\n\nasync function wait(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\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\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 typeof (tx as OldEthJsTransaction).getChainId === 'function';\n}\n\nexport class TrezorKeyring extends EventEmitter {\n static type: string = keyringType;\n\n readonly type: string = keyringType;\n\n accounts: readonly string[] = [];\n\n hdk: HDKey = new HDKey();\n\n hdPath: string = hdPathString;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n paths: Record<string, number> = {};\n\n bridge: TrezorBridge;\n\n constructor({ bridge }: { bridge: TrezorBridge }) {\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 /**\n * Gets the model, if known.\n * This may be `undefined` if the model hasn't been loaded yet.\n *\n * @returns\n */\n getModel(): string | undefined {\n return this.bridge.model;\n }\n\n async init(): Promise<void> {\n return this.bridge.init({\n manifest: TREZOR_CONNECT_MANIFEST,\n lazyLoad: true,\n });\n }\n\n async destroy(): Promise<void> {\n return this.bridge.dispose();\n }\n\n async serialize(): Promise<TrezorControllerState> {\n return Promise.resolve({\n hdPath: this.hdPath,\n accounts: this.accounts,\n page: this.page,\n paths: this.paths,\n perPage: this.perPage,\n unlockedAccount: this.unlockedAccount,\n });\n }\n\n async deserialize(opts: TrezorControllerOptions = {}): Promise<void> {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.accounts = opts.accounts ?? [];\n this.page = opts.page ?? 0;\n this.perPage = opts.perPage ?? 5;\n return Promise.resolve();\n }\n\n isUnlocked(): boolean {\n return Boolean(this.hdk?.publicKey);\n }\n\n async unlock(): Promise<string> {\n if (this.isUnlocked()) {\n return Promise.resolve('already unlocked');\n }\n return new Promise((resolve, reject) => {\n this.bridge\n .getPublicKey({\n path: this.hdPath,\n coin: 'ETH',\n })\n .then((response) => {\n if (response.success) {\n this.hdk.publicKey = Buffer.from(response.payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(response.payload.chainCode, 'hex');\n resolve('just unlocked');\n } else {\n reject(new Error(response.payload?.error || 'Unknown error'));\n }\n })\n .catch((e) => {\n reject(new Error(e?.toString() || 'Unknown error'));\n });\n });\n }\n\n setAccountToUnlock(index: number | string): void {\n this.unlockedAccount = parseInt(String(index), 10);\n }\n\n async addAccounts(n = 1): Promise<readonly string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then((_) => {\n const from = this.unlockedAccount;\n const to = from + n;\n const newAccounts = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\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((e: Error) => {\n reject(e);\n });\n });\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 #getPage(increment: number): Promise<AccountPage> {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n\n return new Promise((resolve, reject) => {\n this.unlock()\n .then((_) => {\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n const accounts = [];\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 resolve(accounts);\n })\n .catch((e: Error) => {\n reject(e);\n });\n });\n }\n\n async getAccounts(): Promise<string[]> {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string): void {\n if (\n !this.accounts.map((a) => a.toLowerCase()).includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n }\n\n /**\n * Signs a transaction using Trezor.\n *\n * Accepts either an ethereumjs-tx or @ethereumjs/tx transaction, and returns\n * the same type.\n *\n * @param address - Hex string address.\n * @param tx - Instance of either new-style or old-style ethereumjs transaction.\n * @returns The signed transaction, an instance of either new-style or old-style\n * ethereumjs transaction.\n */\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\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 return this.#signTransaction(\n address,\n // @types/ethereumjs-tx and old ethereumjs-tx versions document\n // this function return value as Buffer, but the actual\n // Transaction._chainId will always be a number.\n // See https://github.com/ethereumjs/ethereumjs-tx/blob/v1.3.7/index.js#L126\n tx.getChainId() as unknown as number,\n tx,\n (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 return this.#signTransaction(\n address,\n Number(tx.common.chainId()),\n tx,\n (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\n /**\n *\n * @param address - Hex string address.\n * @param chainId - Chain ID\n * @param tx - Instance of either new-style or old-style ethereumjs transaction.\n * @param handleSigning - Converts signed transaction\n * to the same new-style or old-style ethereumjs-tx.\n * @returns The signed transaction, an instance of either new-style or old-style\n * ethereumjs transaction.\n */\n async #signTransaction<T extends TypedTransaction | OldEthJsTransaction>(\n address: string,\n chainId: number,\n tx: T,\n handleSigning: (tx: EthereumSignedTx) => T,\n ): Promise<T> {\n let transaction: EthereumTransaction | EthereumTransactionEIP1559;\n if (isOldStyleEthereumjsTx(tx)) {\n // legacy transaction from ethereumjs-tx package has no .toJSON() function,\n // so we need to convert to hex-strings manually manually\n transaction = {\n to: this.#normalize(tx.to),\n value: this.#normalize(tx.value),\n data: this.#normalize(tx.data),\n chainId,\n nonce: this.#normalize(tx.nonce),\n gasLimit: this.#normalize(tx.gasLimit),\n gasPrice: this.#normalize(tx.gasPrice),\n };\n } else {\n // new-style transaction from @ethereumjs/tx package\n // we can just copy tx.toJSON() for everything except chainId, which must be a number\n transaction = {\n ...tx.toJSON(),\n chainId,\n to: this.#normalize(ethUtil.toBuffer(tx.to)),\n } as EthereumTransaction | EthereumTransactionEIP1559;\n }\n\n try {\n const status = await this.unlock();\n await wait(status === 'just unlocked' ? DELAY_BETWEEN_POPUPS : 0);\n const response = await this.bridge.ethereumSignTransaction({\n path: this.#pathFromAddress(address),\n transaction,\n });\n if (response.success) {\n const newOrMutatedTx = handleSigning(response.payload);\n\n const addressSignedWith = ethUtil.toChecksumAddress(\n ethUtil.addHexPrefix(\n newOrMutatedTx.getSenderAddress().toString('hex'),\n ),\n );\n const correctAddress = ethUtil.toChecksumAddress(address);\n if (addressSignedWith !== correctAddress) {\n throw new Error(\"signature doesn't match the right address\");\n }\n\n return newOrMutatedTx;\n }\n throw new Error(response.payload?.error || 'Unknown error');\n } catch (e) {\n throw new Error(e?.toString() ?? 'Unknown error');\n }\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 return new Promise((resolve, reject) => {\n this.unlock()\n .then((status) => {\n setTimeout(\n () => {\n this.bridge\n .ethereumSignMessage({\n path: this.#pathFromAddress(withAccount),\n message: ethUtil.stripHexPrefix(message),\n hex: true,\n })\n .then((response) => {\n if (response.success) {\n if (\n response.payload.address !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n reject(\n new Error('signature doesnt match the right address'),\n );\n }\n const signature = `0x${response.payload.signature}`;\n resolve(signature);\n } else {\n reject(\n new Error(response.payload?.error || 'Unknown error'),\n );\n }\n })\n .catch((e) => {\n reject(new Error(e?.toString() || 'Unknown error'));\n });\n // This is necessary to avoid popup collision\n // between the unlock & sign trezor popups\n },\n status === 'just unlocked' ? DELAY_BETWEEN_POPUPS : 0,\n );\n })\n .catch((e) => {\n reject(new Error(e?.toString() || 'Unknown error'));\n });\n });\n }\n\n // EIP-712 Sign Typed Data\n async signTypedData<T extends MessageTypes>(\n address: string,\n data: TypedMessage<T>,\n { version }: { version: SignTypedDataVersion },\n ): Promise<string> {\n const dataWithHashes = transformTypedData(\n data,\n version === SignTypedDataVersion.V4,\n );\n\n // set default values for signTypedData\n // Trezor is stricter than @metamask/eth-sig-util in what it accepts\n const {\n types,\n message = {},\n domain = {},\n primaryType,\n // snake_case since Trezor uses Protobuf naming conventions here\n domain_separator_hash, // eslint-disable-line camelcase\n message_hash, // eslint-disable-line camelcase\n } = dataWithHashes;\n\n // This is necessary to avoid popup collision\n // between the unlock & sign trezor popups\n const status = await this.unlock();\n await wait(status === 'just unlocked' ? DELAY_BETWEEN_POPUPS : 0);\n\n const response = await this.bridge.ethereumSignTypedData({\n path: this.#pathFromAddress(address),\n data: {\n types: { ...types, EIP712Domain: types.EIP712Domain ?? [] },\n message,\n domain,\n primaryType,\n },\n metamask_v4_compat: true, // eslint-disable-line camelcase\n // Trezor 1 only supports blindly signing hashes\n domain_separator_hash, // eslint-disable-line camelcase\n message_hash: message_hash ?? '', // eslint-disable-line camelcase\n });\n\n if (response.success) {\n if (ethUtil.toChecksumAddress(address) !== response.payload.address) {\n throw new Error('signature doesnt match the right address');\n }\n return response.payload.signature;\n }\n\n throw new Error(response.payload?.error || 'Unknown error');\n }\n\n async exportAccount(): Promise<never> {\n return Promise.reject(new Error('Not supported on this device'));\n }\n\n forgetDevice(): void {\n this.accounts = [];\n this.hdk = new HDKey();\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n }\n\n /**\n * Set the HD path to be used by the keyring. Only known supported HD paths are allowed.\n *\n * If the given HD path is already the current HD path, nothing happens. Otherwise the new HD\n * path is set, and the wallet state is completely reset.\n *\n * @throws {Error] Throws if the HD path is not supported.\n *\n * @param hdPath - The HD path to set.\n */\n setHdPath(hdPath: keyof typeof ALLOWED_HD_PATHS): void {\n if (!ALLOWED_HD_PATHS[hdPath]) {\n throw new Error(\n `The setHdPath method does not support setting HD Path to ${hdPath}`,\n );\n }\n\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n this.accounts = [];\n this.page = 0;\n this.perPage = 5;\n this.unlockedAccount = 0;\n this.paths = {};\n }\n this.hdPath = hdPath;\n }\n\n #normalize(buf: Buffer): string {\n return ethUtil.bufferToHex(buf).toString();\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.hdPath}/${index}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"trezor-keyring.mjs","sourceRoot":"","sources":["../src/trezor-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB;AAEpD,OAAO,KAAK,OAAO,yBAAyB;;;;AAM5C,OAAO,EAAE,kBAAkB,EAAE,wCAAwC;AAOrE,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAAO,MAAK,cAAc;;AAE1B,OAAO,EAAE,YAAY,EAAE,4BAAwB;AAE/C,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAC5C,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,MAAM,gBAAgB,GAAG;IACvB,CAAC,YAAY,CAAC,EAAE,IAAI;IACpB,CAAC,aAAa,CAAC,EAAE,IAAI;IACrB,CAAC,mBAAmB,CAAC,EAAE,IAAI;CACnB,CAAC;AAEX,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,KAAK,EAAE,qBAAqB;IAC5B,MAAM,EAAE,qBAAqB;CAC9B,CAAC;AA0BF,KAAK,UAAU,IAAI,CAAC,EAAU;IAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAC7B,EAA0C;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@ethereumjs/tx';\nimport type { TypedTransaction, TxData } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport {\n TypedMessage,\n SignTypedDataVersion,\n MessageTypes,\n} from '@metamask/eth-sig-util';\nimport { transformTypedData } from '@trezor/connect-plugin-ethereum';\nimport type {\n EthereumTransactionEIP1559,\n EthereumSignedTx,\n EthereumTransaction,\n} from '@trezor/connect-web';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { TrezorBridge } from './trezor-bridge';\n\nconst hdPathString = `m/44'/60'/0'/0`;\nconst SLIP0044TestnetPath = `m/44'/1'/0'/0`;\nconst legacyMewPath = `m/44'/60'/0'`;\n\nconst ALLOWED_HD_PATHS = {\n [hdPathString]: true,\n [legacyMewPath]: true,\n [SLIP0044TestnetPath]: true,\n} as const;\n\nconst keyringType = 'Trezor Hardware';\nconst pathBase = 'm';\nconst MAX_INDEX = 1000;\nconst DELAY_BETWEEN_POPUPS = 1000;\nexport const TREZOR_CONNECT_MANIFEST = {\n email: 'support@metamask.io',\n appUrl: 'https://metamask.io',\n};\n\nexport type AccountPageEntry = {\n address: string;\n balance: number | null;\n index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport interface TrezorControllerOptions {\n hdPath?: string;\n accounts?: string[];\n page?: number;\n perPage?: number;\n}\n\nexport interface TrezorControllerState {\n hdPath: string;\n accounts: readonly string[];\n page: number;\n paths: Record<string, number>;\n perPage: number;\n unlockedAccount: number;\n}\n\nasync function wait(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\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\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 typeof (tx as OldEthJsTransaction).getChainId === 'function';\n}\n\nexport class TrezorKeyring extends EventEmitter {\n static type: string = keyringType;\n\n readonly type: string = keyringType;\n\n accounts: readonly string[] = [];\n\n hdk: HDKey = new HDKey();\n\n hdPath: string = hdPathString;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n paths: Record<string, number> = {};\n\n bridge: TrezorBridge;\n\n constructor({ bridge }: { bridge: TrezorBridge }) {\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 /**\n * Gets the model, if known.\n * This may be `undefined` if the model hasn't been loaded yet.\n *\n * @returns\n */\n getModel(): string | undefined {\n return this.bridge.model;\n }\n\n async init(): Promise<void> {\n return this.bridge.init({\n manifest: TREZOR_CONNECT_MANIFEST,\n lazyLoad: true,\n });\n }\n\n async destroy(): Promise<void> {\n return this.bridge.dispose();\n }\n\n async serialize(): Promise<TrezorControllerState> {\n return Promise.resolve({\n hdPath: this.hdPath,\n accounts: this.accounts,\n page: this.page,\n paths: this.paths,\n perPage: this.perPage,\n unlockedAccount: this.unlockedAccount,\n });\n }\n\n async deserialize(opts: TrezorControllerOptions = {}): Promise<void> {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.accounts = opts.accounts ?? [];\n this.page = opts.page ?? 0;\n this.perPage = opts.perPage ?? 5;\n return Promise.resolve();\n }\n\n isUnlocked(): boolean {\n return Boolean(this.hdk?.publicKey);\n }\n\n async unlock(): Promise<string> {\n if (this.isUnlocked()) {\n return Promise.resolve('already unlocked');\n }\n return new Promise((resolve, reject) => {\n this.bridge\n .getPublicKey({\n path: this.hdPath,\n coin: 'ETH',\n })\n .then((response) => {\n if (response.success) {\n this.hdk.publicKey = Buffer.from(response.payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(response.payload.chainCode, 'hex');\n resolve('just unlocked');\n } else {\n reject(new Error(response.payload?.error || 'Unknown error'));\n }\n })\n .catch((e) => {\n reject(new Error(e?.toString() || 'Unknown error'));\n });\n });\n }\n\n setAccountToUnlock(index: number | string): void {\n this.unlockedAccount = parseInt(String(index), 10);\n }\n\n async addAccounts(n = 1): Promise<readonly string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then((_) => {\n const from = this.unlockedAccount;\n const to = from + n;\n const newAccounts = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\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((e: Error) => {\n reject(e);\n });\n });\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 #getPage(increment: number): Promise<AccountPage> {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n\n return new Promise((resolve, reject) => {\n this.unlock()\n .then((_) => {\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n const accounts = [];\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 resolve(accounts);\n })\n .catch((e: Error) => {\n reject(e);\n });\n });\n }\n\n async getAccounts(): Promise<string[]> {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string): void {\n if (\n !this.accounts.map((a) => a.toLowerCase()).includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n }\n\n /**\n * Signs a transaction using Trezor.\n *\n * Accepts either an ethereumjs-tx or @ethereumjs/tx transaction, and returns\n * the same type.\n *\n * @param address - Hex string address.\n * @param tx - Instance of either new-style or old-style ethereumjs transaction.\n * @returns The signed transaction, an instance of either new-style or old-style\n * ethereumjs transaction.\n */\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\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 return this.#signTransaction(\n address,\n // @types/ethereumjs-tx and old ethereumjs-tx versions document\n // this function return value as Buffer, but the actual\n // Transaction._chainId will always be a number.\n // See https://github.com/ethereumjs/ethereumjs-tx/blob/v1.3.7/index.js#L126\n tx.getChainId() as unknown as number,\n tx,\n (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 return this.#signTransaction(\n address,\n Number(tx.common.chainId()),\n tx,\n (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\n /**\n *\n * @param address - Hex string address.\n * @param chainId - Chain ID\n * @param tx - Instance of either new-style or old-style ethereumjs transaction.\n * @param handleSigning - Converts signed transaction\n * to the same new-style or old-style ethereumjs-tx.\n * @returns The signed transaction, an instance of either new-style or old-style\n * ethereumjs transaction.\n */\n async #signTransaction<T extends TypedTransaction | OldEthJsTransaction>(\n address: string,\n chainId: number,\n tx: T,\n handleSigning: (tx: EthereumSignedTx) => T,\n ): Promise<T> {\n let transaction: EthereumTransaction | EthereumTransactionEIP1559;\n if (isOldStyleEthereumjsTx(tx)) {\n // legacy transaction from ethereumjs-tx package has no .toJSON() function,\n // so we need to convert to hex-strings manually manually\n transaction = {\n to: this.#normalize(tx.to),\n value: this.#normalize(tx.value),\n data: this.#normalize(tx.data),\n chainId,\n nonce: this.#normalize(tx.nonce),\n gasLimit: this.#normalize(tx.gasLimit),\n gasPrice: this.#normalize(tx.gasPrice),\n };\n } else {\n // new-style transaction from @ethereumjs/tx package\n // we can just copy tx.toJSON() for everything except chainId, which must be a number\n transaction = {\n ...tx.toJSON(),\n chainId,\n to: this.#normalize(ethUtil.toBuffer(tx.to)),\n } as EthereumTransaction | EthereumTransactionEIP1559;\n }\n\n try {\n const status = await this.unlock();\n await wait(status === 'just unlocked' ? DELAY_BETWEEN_POPUPS : 0);\n const response = await this.bridge.ethereumSignTransaction({\n path: this.#pathFromAddress(address),\n transaction,\n });\n if (response.success) {\n const newOrMutatedTx = handleSigning(response.payload);\n\n const addressSignedWith = ethUtil.toChecksumAddress(\n ethUtil.addHexPrefix(\n newOrMutatedTx.getSenderAddress().toString('hex'),\n ),\n );\n const correctAddress = ethUtil.toChecksumAddress(address);\n if (addressSignedWith !== correctAddress) {\n throw new Error(\"signature doesn't match the right address\");\n }\n\n return newOrMutatedTx;\n }\n throw new Error(response.payload?.error || 'Unknown error');\n } catch (e) {\n throw new Error(e?.toString() ?? 'Unknown error');\n }\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 return new Promise((resolve, reject) => {\n this.unlock()\n .then((status) => {\n setTimeout(\n () => {\n this.bridge\n .ethereumSignMessage({\n path: this.#pathFromAddress(withAccount),\n message: ethUtil.stripHexPrefix(message),\n hex: true,\n })\n .then((response) => {\n if (response.success) {\n if (\n response.payload.address !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n reject(\n new Error('signature doesnt match the right address'),\n );\n }\n const signature = `0x${response.payload.signature}`;\n resolve(signature);\n } else {\n reject(\n new Error(response.payload?.error || 'Unknown error'),\n );\n }\n })\n .catch((e) => {\n reject(new Error(e?.toString() || 'Unknown error'));\n });\n // This is necessary to avoid popup collision\n // between the unlock & sign trezor popups\n },\n status === 'just unlocked' ? DELAY_BETWEEN_POPUPS : 0,\n );\n })\n .catch((e) => {\n reject(new Error(e?.toString() || 'Unknown error'));\n });\n });\n }\n\n // EIP-712 Sign Typed Data\n async signTypedData<T extends MessageTypes>(\n address: string,\n data: TypedMessage<T>,\n { version }: { version: SignTypedDataVersion },\n ): Promise<string> {\n const dataWithHashes = transformTypedData(\n data,\n version === SignTypedDataVersion.V4,\n );\n\n // set default values for signTypedData\n // Trezor is stricter than @metamask/eth-sig-util in what it accepts\n const {\n types,\n message = {},\n domain = {},\n primaryType,\n // snake_case since Trezor uses Protobuf naming conventions here\n domain_separator_hash, // eslint-disable-line camelcase\n message_hash, // eslint-disable-line camelcase\n } = dataWithHashes;\n\n // This is necessary to avoid popup collision\n // between the unlock & sign trezor popups\n const status = await this.unlock();\n await wait(status === 'just unlocked' ? DELAY_BETWEEN_POPUPS : 0);\n\n const response = await this.bridge.ethereumSignTypedData({\n path: this.#pathFromAddress(address),\n data: {\n types: { ...types, EIP712Domain: types.EIP712Domain ?? [] },\n message,\n domain,\n primaryType,\n },\n metamask_v4_compat: true, // eslint-disable-line camelcase\n // Trezor 1 only supports blindly signing hashes\n domain_separator_hash, // eslint-disable-line camelcase\n message_hash: message_hash ?? '', // eslint-disable-line camelcase\n });\n\n if (response.success) {\n if (ethUtil.toChecksumAddress(address) !== response.payload.address) {\n throw new Error('signature doesnt match the right address');\n }\n return response.payload.signature;\n }\n\n throw new Error(response.payload?.error || 'Unknown error');\n }\n\n async exportAccount(): Promise<never> {\n return Promise.reject(new Error('Not supported on this device'));\n }\n\n forgetDevice(): void {\n this.accounts = [];\n this.hdk = new HDKey();\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n }\n\n /**\n * Set the HD path to be used by the keyring. Only known supported HD paths are allowed.\n *\n * If the given HD path is already the current HD path, nothing happens. Otherwise the new HD\n * path is set, and the wallet state is completely reset.\n *\n * @throws {Error] Throws if the HD path is not supported.\n *\n * @param hdPath - The HD path to set.\n */\n setHdPath(hdPath: keyof typeof ALLOWED_HD_PATHS): void {\n if (!ALLOWED_HD_PATHS[hdPath]) {\n throw new Error(\n `The setHdPath method does not support setting HD Path to ${hdPath}`,\n );\n }\n\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n this.accounts = [];\n this.page = 0;\n this.perPage = 5;\n this.unlockedAccount = 0;\n this.paths = {};\n }\n this.hdPath = hdPath;\n }\n\n #normalize(buf: Buffer): string {\n return ethUtil.bufferToHex(buf).toString();\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.hdPath}/${index}`;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/eth-trezor-keyring",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1-0aca2ee",
|
|
4
4
|
"description": "A MetaMask compatible keyring, for trezor hardware wallets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@ethereumjs/tx": "^4.2.0",
|
|
51
51
|
"@ethereumjs/util": "^8.1.0",
|
|
52
|
-
"@metamask/eth-sig-util": "^8.
|
|
52
|
+
"@metamask/eth-sig-util": "^8.1.2",
|
|
53
53
|
"@trezor/connect-plugin-ethereum": "^9.0.3",
|
|
54
54
|
"@trezor/connect-web": "^9.1.11",
|
|
55
55
|
"hdkey": "^2.1.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@lavamoat/allow-scripts": "^3.2.1",
|
|
61
61
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
62
62
|
"@metamask/auto-changelog": "^3.4.4",
|
|
63
|
-
"@ts-bridge/cli": "^0.6.
|
|
63
|
+
"@ts-bridge/cli": "^0.6.1",
|
|
64
64
|
"@types/ethereumjs-tx": "^1.0.1",
|
|
65
65
|
"@types/hdkey": "^2.0.1",
|
|
66
66
|
"@types/jest": "^29.5.12",
|