@metamask-previews/keyring-sdk 1.1.0-018fb62
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 +28 -0
- package/README.md +47 -0
- package/dist/eth/eth-keyring-wrapper.cjs +164 -0
- package/dist/eth/eth-keyring-wrapper.cjs.map +1 -0
- package/dist/eth/eth-keyring-wrapper.d.cts +53 -0
- package/dist/eth/eth-keyring-wrapper.d.cts.map +1 -0
- package/dist/eth/eth-keyring-wrapper.d.mts +53 -0
- package/dist/eth/eth-keyring-wrapper.d.mts.map +1 -0
- package/dist/eth/eth-keyring-wrapper.mjs +160 -0
- package/dist/eth/eth-keyring-wrapper.mjs.map +1 -0
- package/dist/eth/index.cjs +18 -0
- package/dist/eth/index.cjs.map +1 -0
- package/dist/eth/index.d.cts +2 -0
- package/dist/eth/index.d.cts.map +1 -0
- package/dist/eth/index.d.mts +2 -0
- package/dist/eth/index.d.mts.map +1 -0
- package/dist/eth/index.mjs +2 -0
- package/dist/eth/index.mjs.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/dist/keyring-account-registry.cjs +135 -0
- package/dist/keyring-account-registry.cjs.map +1 -0
- package/dist/keyring-account-registry.d.cts +88 -0
- package/dist/keyring-account-registry.d.cts.map +1 -0
- package/dist/keyring-account-registry.d.mts +88 -0
- package/dist/keyring-account-registry.d.mts.map +1 -0
- package/dist/keyring-account-registry.mjs +131 -0
- package/dist/keyring-account-registry.mjs.map +1 -0
- package/dist/keyring-wrapper.cjs +134 -0
- package/dist/keyring-wrapper.cjs.map +1 -0
- package/dist/keyring-wrapper.d.cts +149 -0
- package/dist/keyring-wrapper.d.cts.map +1 -0
- package/dist/keyring-wrapper.d.mts +149 -0
- package/dist/keyring-wrapper.d.mts.map +1 -0
- package/dist/keyring-wrapper.mjs +130 -0
- package/dist/keyring-wrapper.mjs.map +1 -0
- package/dist/mnemonic.cjs +20 -0
- package/dist/mnemonic.cjs.map +1 -0
- package/dist/mnemonic.d.cts +8 -0
- package/dist/mnemonic.d.cts.map +1 -0
- package/dist/mnemonic.d.mts +8 -0
- package/dist/mnemonic.d.mts.map +1 -0
- package/dist/mnemonic.mjs +17 -0
- package/dist/mnemonic.mjs.map +1 -0
- package/package.json +95 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `encodeMnemonic` ([#495](https://github.com/MetaMask/accounts/pull/495))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Bump `@metamask/utils` from `^11.1.0` to `^11.10.0` ([#489](https://github.com/MetaMask/accounts/pull/489))
|
|
19
|
+
|
|
20
|
+
## [1.0.0]
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478)), ([#482](https://github.com/MetaMask/accounts/pull/482))
|
|
25
|
+
|
|
26
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.1.0...HEAD
|
|
27
|
+
[1.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.0.0...@metamask/keyring-sdk@1.1.0
|
|
28
|
+
[1.0.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/keyring-sdk@1.0.0
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# MetaMask Keyring SDK
|
|
2
|
+
|
|
3
|
+
This package contains the heavy runtime dependencies related to the `@metamask/keyring-api` package
|
|
4
|
+
to keep it as a lightweight API surface (types, structs, interfaces).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
yarn add @metamask/keyring-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
or
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @metamask/keyring-sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { EthKeyringWrapper, EthKeyringMethod } from '@metamask/keyring-sdk';
|
|
22
|
+
import { EthMethod, KeyringType } from '@metamask/keyring-api';
|
|
23
|
+
|
|
24
|
+
export class MyKeyringV2 extends EthKeyringWrapper<MyLegacyKeyring> {
|
|
25
|
+
constructor(inner: MyLegacyKeyring) {
|
|
26
|
+
super({
|
|
27
|
+
type: KeyringType.Hd,
|
|
28
|
+
inner,
|
|
29
|
+
capabilities: { scopes: ['eip155:1'] },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getAccounts() {
|
|
34
|
+
/* ... */
|
|
35
|
+
}
|
|
36
|
+
async createAccounts(options) {
|
|
37
|
+
/* ... */
|
|
38
|
+
}
|
|
39
|
+
async deleteAccount(accountId) {
|
|
40
|
+
/* ... */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Contributing
|
|
46
|
+
|
|
47
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/accounts#readme).
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EthKeyringWrapper = exports.EthKeyringMethod = void 0;
|
|
4
|
+
const tx_1 = require("@ethereumjs/tx");
|
|
5
|
+
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
6
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
7
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
9
|
+
const keyring_wrapper_1 = require("../keyring-wrapper.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
|
|
12
|
+
* These are primarily encryption and utility methods.
|
|
13
|
+
*/
|
|
14
|
+
var EthKeyringMethod;
|
|
15
|
+
(function (EthKeyringMethod) {
|
|
16
|
+
EthKeyringMethod["Decrypt"] = "eth_decrypt";
|
|
17
|
+
EthKeyringMethod["GetEncryptionPublicKey"] = "eth_getEncryptionPublicKey";
|
|
18
|
+
EthKeyringMethod["GetAppKeyAddress"] = "eth_getAppKeyAddress";
|
|
19
|
+
EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
|
|
20
|
+
})(EthKeyringMethod || (exports.EthKeyringMethod = EthKeyringMethod = {}));
|
|
21
|
+
/**
|
|
22
|
+
* Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
|
|
23
|
+
*
|
|
24
|
+
* This class provides common functionality for all Ethereum keyrings including:
|
|
25
|
+
* - Request handling for standard Ethereum signing methods
|
|
26
|
+
* - Helper methods for Hex address conversion
|
|
27
|
+
*
|
|
28
|
+
* Subclasses must implement:
|
|
29
|
+
* - `getAccounts()`: Return all managed accounts
|
|
30
|
+
* - `createAccounts()`: Create new accounts based on options
|
|
31
|
+
* - `deleteAccount()`: Remove an account from the keyring
|
|
32
|
+
* - `exportAccount()` (optional): Export private key in specified format
|
|
33
|
+
*/
|
|
34
|
+
class EthKeyringWrapper extends keyring_wrapper_1.KeyringWrapper {
|
|
35
|
+
/**
|
|
36
|
+
* Helper method to safely cast a KeyringAccount address to Hex type.
|
|
37
|
+
* The KeyringAccount.address is typed as string, but for Ethereum accounts
|
|
38
|
+
* it should always be a valid Hex address.
|
|
39
|
+
*
|
|
40
|
+
* @param address - The address from a KeyringAccount.
|
|
41
|
+
* @returns The address as Hex type.
|
|
42
|
+
*/
|
|
43
|
+
toHexAddress(address) {
|
|
44
|
+
return (0, utils_1.add0x)(address);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Handle an Ethereum signing request.
|
|
48
|
+
*
|
|
49
|
+
* Routes the request to the appropriate legacy keyring method based on
|
|
50
|
+
* the RPC method name.
|
|
51
|
+
*
|
|
52
|
+
* @param request - The keyring request containing method and params.
|
|
53
|
+
* @returns The result of the signing operation.
|
|
54
|
+
*/
|
|
55
|
+
async submitRequest(request) {
|
|
56
|
+
const { method, params } = request.request;
|
|
57
|
+
const { address, methods } = await this.getAccount(request.account);
|
|
58
|
+
const hexAddress = this.toHexAddress(address);
|
|
59
|
+
// Validate account can handle the method
|
|
60
|
+
if (!methods.includes(method)) {
|
|
61
|
+
throw new Error(`Account ${request.account} cannot handle method: ${method}`);
|
|
62
|
+
}
|
|
63
|
+
switch (method) {
|
|
64
|
+
case `${keyring_api_1.EthMethod.SignTransaction}`: {
|
|
65
|
+
if (!this.inner.signTransaction) {
|
|
66
|
+
throw new Error('Keyring does not support signTransaction');
|
|
67
|
+
}
|
|
68
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthSignTransactionParamsStruct);
|
|
69
|
+
const [txData] = params;
|
|
70
|
+
// Convert validated transaction data to TypedTransaction
|
|
71
|
+
// TODO: Improve typing to ensure txData matches TypedTxData
|
|
72
|
+
const tx = tx_1.TransactionFactory.fromTxData(txData);
|
|
73
|
+
// Note: Bigints are not directly representable in JSON
|
|
74
|
+
return (await this.inner.signTransaction(hexAddress, tx)); // FIXME: Should return type be unknown?
|
|
75
|
+
}
|
|
76
|
+
case `${keyring_api_1.EthMethod.Sign}`: {
|
|
77
|
+
if (!this.inner.signMessage) {
|
|
78
|
+
throw new Error('Keyring does not support signMessage');
|
|
79
|
+
}
|
|
80
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthSignParamsStruct);
|
|
81
|
+
const [, data] = params;
|
|
82
|
+
return this.inner.signMessage(hexAddress, data);
|
|
83
|
+
}
|
|
84
|
+
case `${keyring_api_1.EthMethod.PersonalSign}`: {
|
|
85
|
+
if (!this.inner.signPersonalMessage) {
|
|
86
|
+
throw new Error('Keyring does not support signPersonalMessage');
|
|
87
|
+
}
|
|
88
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthPersonalSignParamsStruct);
|
|
89
|
+
const [data] = params;
|
|
90
|
+
return this.inner.signPersonalMessage(hexAddress, data);
|
|
91
|
+
}
|
|
92
|
+
case `${keyring_api_1.EthMethod.SignTypedDataV1}`: {
|
|
93
|
+
if (!this.inner.signTypedData) {
|
|
94
|
+
throw new Error('Keyring does not support signTypedData');
|
|
95
|
+
}
|
|
96
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthSignTypedDataV1ParamsStruct);
|
|
97
|
+
const [, data] = params;
|
|
98
|
+
return this.inner.signTypedData(hexAddress, data, {
|
|
99
|
+
version: eth_sig_util_1.SignTypedDataVersion.V1,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
case `${keyring_api_1.EthMethod.SignTypedDataV3}`: {
|
|
103
|
+
if (!this.inner.signTypedData) {
|
|
104
|
+
throw new Error('Keyring does not support signTypedData');
|
|
105
|
+
}
|
|
106
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthSignTypedDataParamsStruct);
|
|
107
|
+
const [, data] = params;
|
|
108
|
+
return this.inner.signTypedData(hexAddress,
|
|
109
|
+
// TODO: Improve typing to ensure data matches MessageTypes
|
|
110
|
+
data, {
|
|
111
|
+
version: eth_sig_util_1.SignTypedDataVersion.V3,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
case `${keyring_api_1.EthMethod.SignTypedDataV4}`: {
|
|
115
|
+
if (!this.inner.signTypedData) {
|
|
116
|
+
throw new Error('Keyring does not support signTypedData');
|
|
117
|
+
}
|
|
118
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthSignTypedDataParamsStruct);
|
|
119
|
+
const [, data] = params;
|
|
120
|
+
return this.inner.signTypedData(hexAddress,
|
|
121
|
+
// TODO: Improve typing to ensure data matches MessageTypes
|
|
122
|
+
data, {
|
|
123
|
+
version: eth_sig_util_1.SignTypedDataVersion.V4,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
case `${EthKeyringMethod.Decrypt}`: {
|
|
127
|
+
if (!this.inner.decryptMessage) {
|
|
128
|
+
throw new Error('Keyring does not support decryptMessage');
|
|
129
|
+
}
|
|
130
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthDecryptParamsStruct);
|
|
131
|
+
const [encryptedData] = params;
|
|
132
|
+
return this.inner.decryptMessage(hexAddress, encryptedData);
|
|
133
|
+
}
|
|
134
|
+
case `${EthKeyringMethod.GetEncryptionPublicKey}`: {
|
|
135
|
+
if (!this.inner.getEncryptionPublicKey) {
|
|
136
|
+
throw new Error('Keyring does not support getEncryptionPublicKey');
|
|
137
|
+
}
|
|
138
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthGetEncryptionPublicKeyParamsStruct);
|
|
139
|
+
const [, options] = params;
|
|
140
|
+
return this.inner.getEncryptionPublicKey(hexAddress, options);
|
|
141
|
+
}
|
|
142
|
+
case `${EthKeyringMethod.GetAppKeyAddress}`: {
|
|
143
|
+
if (!this.inner.getAppKeyAddress) {
|
|
144
|
+
throw new Error('Keyring does not support getAppKeyAddress');
|
|
145
|
+
}
|
|
146
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthGetAppKeyAddressParamsStruct);
|
|
147
|
+
const [origin] = params;
|
|
148
|
+
return this.inner.getAppKeyAddress(hexAddress, origin);
|
|
149
|
+
}
|
|
150
|
+
case `${EthKeyringMethod.SignEip7702Authorization}`: {
|
|
151
|
+
if (!this.inner.signEip7702Authorization) {
|
|
152
|
+
throw new Error('Keyring does not support signEip7702Authorization');
|
|
153
|
+
}
|
|
154
|
+
(0, superstruct_1.assert)(params, keyring_api_1.EthSignEip7702AuthorizationParamsStruct);
|
|
155
|
+
const [authorization] = params;
|
|
156
|
+
return this.inner.signEip7702Authorization(hexAddress, authorization);
|
|
157
|
+
}
|
|
158
|
+
default:
|
|
159
|
+
throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.EthKeyringWrapper = EthKeyringWrapper;
|
|
164
|
+
//# sourceMappingURL=eth-keyring-wrapper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-keyring-wrapper.cjs","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":";;;AAAA,uCAAsE;AAEtE,yDAA8D;AAE9D,uDAW+B;AAE/B,uDAA+C;AAC/C,2CAA6D;AAE7D,4DAAgF;AAEhF;;;GAGG;AACH,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,2CAAuB,CAAA;IACvB,yEAAqD,CAAA;IACrD,6DAAyC,CAAA;IACzC,6EAAyD,CAAA;AAC3D,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAQD;;;;;;;;;;;;GAYG;AACH,MAAsB,iBAGpB,SAAQ,gCAAgD;IACxD;;;;;;;OAOG;IACO,YAAY,CAAC,OAAe;QACpC,OAAO,IAAA,aAAK,EAAC,OAAO,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAE3C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,UAA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AG,MAAM,CAAC;gBAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YAChE,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACjC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC/D,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,6CAA+B,CAAC,CAAC;gBAChD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;gBACxB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACzD,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,qDAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AA5JD,8CA4JC","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n EthMethod,\n} from '@metamask/keyring-api';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport { KeyringWrapper, type KeyringWrapperOptions } from '../keyring-wrapper';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an EthKeyringWrapper.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> =\n KeyringWrapperOptions<InnerKeyring>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
|
|
2
|
+
import type { EthKeyring } from "@metamask/keyring-utils";
|
|
3
|
+
import { type Hex, type Json } from "@metamask/utils";
|
|
4
|
+
import { KeyringWrapper, type KeyringWrapperOptions } from "../keyring-wrapper.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
|
|
7
|
+
* These are primarily encryption and utility methods.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum EthKeyringMethod {
|
|
10
|
+
Decrypt = "eth_decrypt",
|
|
11
|
+
GetEncryptionPublicKey = "eth_getEncryptionPublicKey",
|
|
12
|
+
GetAppKeyAddress = "eth_getAppKeyAddress",
|
|
13
|
+
SignEip7702Authorization = "eth_signEip7702Authorization"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Options for constructing an EthKeyringWrapper.
|
|
17
|
+
*/
|
|
18
|
+
export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = KeyringWrapperOptions<InnerKeyring>;
|
|
19
|
+
/**
|
|
20
|
+
* Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
|
|
21
|
+
*
|
|
22
|
+
* This class provides common functionality for all Ethereum keyrings including:
|
|
23
|
+
* - Request handling for standard Ethereum signing methods
|
|
24
|
+
* - Helper methods for Hex address conversion
|
|
25
|
+
*
|
|
26
|
+
* Subclasses must implement:
|
|
27
|
+
* - `getAccounts()`: Return all managed accounts
|
|
28
|
+
* - `createAccounts()`: Create new accounts based on options
|
|
29
|
+
* - `deleteAccount()`: Remove an account from the keyring
|
|
30
|
+
* - `exportAccount()` (optional): Export private key in specified format
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class EthKeyringWrapper<InnerKeyring extends EthKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {
|
|
33
|
+
/**
|
|
34
|
+
* Helper method to safely cast a KeyringAccount address to Hex type.
|
|
35
|
+
* The KeyringAccount.address is typed as string, but for Ethereum accounts
|
|
36
|
+
* it should always be a valid Hex address.
|
|
37
|
+
*
|
|
38
|
+
* @param address - The address from a KeyringAccount.
|
|
39
|
+
* @returns The address as Hex type.
|
|
40
|
+
*/
|
|
41
|
+
protected toHexAddress(address: string): Hex;
|
|
42
|
+
/**
|
|
43
|
+
* Handle an Ethereum signing request.
|
|
44
|
+
*
|
|
45
|
+
* Routes the request to the appropriate legacy keyring method based on
|
|
46
|
+
* the RPC method name.
|
|
47
|
+
*
|
|
48
|
+
* @param request - The keyring request containing method and params.
|
|
49
|
+
* @returns The result of the signing operation.
|
|
50
|
+
*/
|
|
51
|
+
submitRequest(request: KeyringRequest): Promise<Json>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=eth-keyring-wrapper.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-keyring-wrapper.d.cts","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAa5E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAE7D,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,+BAA2B;AAEhF;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAClE,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;IACxD;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
|
|
2
|
+
import type { EthKeyring } from "@metamask/keyring-utils";
|
|
3
|
+
import { type Hex, type Json } from "@metamask/utils";
|
|
4
|
+
import { KeyringWrapper, type KeyringWrapperOptions } from "../keyring-wrapper.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
|
|
7
|
+
* These are primarily encryption and utility methods.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum EthKeyringMethod {
|
|
10
|
+
Decrypt = "eth_decrypt",
|
|
11
|
+
GetEncryptionPublicKey = "eth_getEncryptionPublicKey",
|
|
12
|
+
GetAppKeyAddress = "eth_getAppKeyAddress",
|
|
13
|
+
SignEip7702Authorization = "eth_signEip7702Authorization"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Options for constructing an EthKeyringWrapper.
|
|
17
|
+
*/
|
|
18
|
+
export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = KeyringWrapperOptions<InnerKeyring>;
|
|
19
|
+
/**
|
|
20
|
+
* Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
|
|
21
|
+
*
|
|
22
|
+
* This class provides common functionality for all Ethereum keyrings including:
|
|
23
|
+
* - Request handling for standard Ethereum signing methods
|
|
24
|
+
* - Helper methods for Hex address conversion
|
|
25
|
+
*
|
|
26
|
+
* Subclasses must implement:
|
|
27
|
+
* - `getAccounts()`: Return all managed accounts
|
|
28
|
+
* - `createAccounts()`: Create new accounts based on options
|
|
29
|
+
* - `deleteAccount()`: Remove an account from the keyring
|
|
30
|
+
* - `exportAccount()` (optional): Export private key in specified format
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class EthKeyringWrapper<InnerKeyring extends EthKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {
|
|
33
|
+
/**
|
|
34
|
+
* Helper method to safely cast a KeyringAccount address to Hex type.
|
|
35
|
+
* The KeyringAccount.address is typed as string, but for Ethereum accounts
|
|
36
|
+
* it should always be a valid Hex address.
|
|
37
|
+
*
|
|
38
|
+
* @param address - The address from a KeyringAccount.
|
|
39
|
+
* @returns The address as Hex type.
|
|
40
|
+
*/
|
|
41
|
+
protected toHexAddress(address: string): Hex;
|
|
42
|
+
/**
|
|
43
|
+
* Handle an Ethereum signing request.
|
|
44
|
+
*
|
|
45
|
+
* Routes the request to the appropriate legacy keyring method based on
|
|
46
|
+
* the RPC method name.
|
|
47
|
+
*
|
|
48
|
+
* @param request - The keyring request containing method and params.
|
|
49
|
+
* @returns The result of the signing operation.
|
|
50
|
+
*/
|
|
51
|
+
submitRequest(request: KeyringRequest): Promise<Json>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=eth-keyring-wrapper.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-keyring-wrapper.d.mts","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAa5E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAE7D,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,+BAA2B;AAEhF;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAClE,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;IACxD;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { TransactionFactory } from "@ethereumjs/tx";
|
|
2
|
+
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
3
|
+
import { EthDecryptParamsStruct, EthGetAppKeyAddressParamsStruct, EthGetEncryptionPublicKeyParamsStruct, EthPersonalSignParamsStruct, EthSignEip7702AuthorizationParamsStruct, EthSignParamsStruct, EthSignTransactionParamsStruct, EthSignTypedDataParamsStruct, EthSignTypedDataV1ParamsStruct, EthMethod } from "@metamask/keyring-api";
|
|
4
|
+
import { assert } from "@metamask/superstruct";
|
|
5
|
+
import { add0x } from "@metamask/utils";
|
|
6
|
+
import { KeyringWrapper } from "../keyring-wrapper.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
|
|
9
|
+
* These are primarily encryption and utility methods.
|
|
10
|
+
*/
|
|
11
|
+
export var EthKeyringMethod;
|
|
12
|
+
(function (EthKeyringMethod) {
|
|
13
|
+
EthKeyringMethod["Decrypt"] = "eth_decrypt";
|
|
14
|
+
EthKeyringMethod["GetEncryptionPublicKey"] = "eth_getEncryptionPublicKey";
|
|
15
|
+
EthKeyringMethod["GetAppKeyAddress"] = "eth_getAppKeyAddress";
|
|
16
|
+
EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
|
|
17
|
+
})(EthKeyringMethod || (EthKeyringMethod = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
|
|
20
|
+
*
|
|
21
|
+
* This class provides common functionality for all Ethereum keyrings including:
|
|
22
|
+
* - Request handling for standard Ethereum signing methods
|
|
23
|
+
* - Helper methods for Hex address conversion
|
|
24
|
+
*
|
|
25
|
+
* Subclasses must implement:
|
|
26
|
+
* - `getAccounts()`: Return all managed accounts
|
|
27
|
+
* - `createAccounts()`: Create new accounts based on options
|
|
28
|
+
* - `deleteAccount()`: Remove an account from the keyring
|
|
29
|
+
* - `exportAccount()` (optional): Export private key in specified format
|
|
30
|
+
*/
|
|
31
|
+
export class EthKeyringWrapper extends KeyringWrapper {
|
|
32
|
+
/**
|
|
33
|
+
* Helper method to safely cast a KeyringAccount address to Hex type.
|
|
34
|
+
* The KeyringAccount.address is typed as string, but for Ethereum accounts
|
|
35
|
+
* it should always be a valid Hex address.
|
|
36
|
+
*
|
|
37
|
+
* @param address - The address from a KeyringAccount.
|
|
38
|
+
* @returns The address as Hex type.
|
|
39
|
+
*/
|
|
40
|
+
toHexAddress(address) {
|
|
41
|
+
return add0x(address);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Handle an Ethereum signing request.
|
|
45
|
+
*
|
|
46
|
+
* Routes the request to the appropriate legacy keyring method based on
|
|
47
|
+
* the RPC method name.
|
|
48
|
+
*
|
|
49
|
+
* @param request - The keyring request containing method and params.
|
|
50
|
+
* @returns The result of the signing operation.
|
|
51
|
+
*/
|
|
52
|
+
async submitRequest(request) {
|
|
53
|
+
const { method, params } = request.request;
|
|
54
|
+
const { address, methods } = await this.getAccount(request.account);
|
|
55
|
+
const hexAddress = this.toHexAddress(address);
|
|
56
|
+
// Validate account can handle the method
|
|
57
|
+
if (!methods.includes(method)) {
|
|
58
|
+
throw new Error(`Account ${request.account} cannot handle method: ${method}`);
|
|
59
|
+
}
|
|
60
|
+
switch (method) {
|
|
61
|
+
case `${EthMethod.SignTransaction}`: {
|
|
62
|
+
if (!this.inner.signTransaction) {
|
|
63
|
+
throw new Error('Keyring does not support signTransaction');
|
|
64
|
+
}
|
|
65
|
+
assert(params, EthSignTransactionParamsStruct);
|
|
66
|
+
const [txData] = params;
|
|
67
|
+
// Convert validated transaction data to TypedTransaction
|
|
68
|
+
// TODO: Improve typing to ensure txData matches TypedTxData
|
|
69
|
+
const tx = TransactionFactory.fromTxData(txData);
|
|
70
|
+
// Note: Bigints are not directly representable in JSON
|
|
71
|
+
return (await this.inner.signTransaction(hexAddress, tx)); // FIXME: Should return type be unknown?
|
|
72
|
+
}
|
|
73
|
+
case `${EthMethod.Sign}`: {
|
|
74
|
+
if (!this.inner.signMessage) {
|
|
75
|
+
throw new Error('Keyring does not support signMessage');
|
|
76
|
+
}
|
|
77
|
+
assert(params, EthSignParamsStruct);
|
|
78
|
+
const [, data] = params;
|
|
79
|
+
return this.inner.signMessage(hexAddress, data);
|
|
80
|
+
}
|
|
81
|
+
case `${EthMethod.PersonalSign}`: {
|
|
82
|
+
if (!this.inner.signPersonalMessage) {
|
|
83
|
+
throw new Error('Keyring does not support signPersonalMessage');
|
|
84
|
+
}
|
|
85
|
+
assert(params, EthPersonalSignParamsStruct);
|
|
86
|
+
const [data] = params;
|
|
87
|
+
return this.inner.signPersonalMessage(hexAddress, data);
|
|
88
|
+
}
|
|
89
|
+
case `${EthMethod.SignTypedDataV1}`: {
|
|
90
|
+
if (!this.inner.signTypedData) {
|
|
91
|
+
throw new Error('Keyring does not support signTypedData');
|
|
92
|
+
}
|
|
93
|
+
assert(params, EthSignTypedDataV1ParamsStruct);
|
|
94
|
+
const [, data] = params;
|
|
95
|
+
return this.inner.signTypedData(hexAddress, data, {
|
|
96
|
+
version: SignTypedDataVersion.V1,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
case `${EthMethod.SignTypedDataV3}`: {
|
|
100
|
+
if (!this.inner.signTypedData) {
|
|
101
|
+
throw new Error('Keyring does not support signTypedData');
|
|
102
|
+
}
|
|
103
|
+
assert(params, EthSignTypedDataParamsStruct);
|
|
104
|
+
const [, data] = params;
|
|
105
|
+
return this.inner.signTypedData(hexAddress,
|
|
106
|
+
// TODO: Improve typing to ensure data matches MessageTypes
|
|
107
|
+
data, {
|
|
108
|
+
version: SignTypedDataVersion.V3,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
case `${EthMethod.SignTypedDataV4}`: {
|
|
112
|
+
if (!this.inner.signTypedData) {
|
|
113
|
+
throw new Error('Keyring does not support signTypedData');
|
|
114
|
+
}
|
|
115
|
+
assert(params, EthSignTypedDataParamsStruct);
|
|
116
|
+
const [, data] = params;
|
|
117
|
+
return this.inner.signTypedData(hexAddress,
|
|
118
|
+
// TODO: Improve typing to ensure data matches MessageTypes
|
|
119
|
+
data, {
|
|
120
|
+
version: SignTypedDataVersion.V4,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
case `${EthKeyringMethod.Decrypt}`: {
|
|
124
|
+
if (!this.inner.decryptMessage) {
|
|
125
|
+
throw new Error('Keyring does not support decryptMessage');
|
|
126
|
+
}
|
|
127
|
+
assert(params, EthDecryptParamsStruct);
|
|
128
|
+
const [encryptedData] = params;
|
|
129
|
+
return this.inner.decryptMessage(hexAddress, encryptedData);
|
|
130
|
+
}
|
|
131
|
+
case `${EthKeyringMethod.GetEncryptionPublicKey}`: {
|
|
132
|
+
if (!this.inner.getEncryptionPublicKey) {
|
|
133
|
+
throw new Error('Keyring does not support getEncryptionPublicKey');
|
|
134
|
+
}
|
|
135
|
+
assert(params, EthGetEncryptionPublicKeyParamsStruct);
|
|
136
|
+
const [, options] = params;
|
|
137
|
+
return this.inner.getEncryptionPublicKey(hexAddress, options);
|
|
138
|
+
}
|
|
139
|
+
case `${EthKeyringMethod.GetAppKeyAddress}`: {
|
|
140
|
+
if (!this.inner.getAppKeyAddress) {
|
|
141
|
+
throw new Error('Keyring does not support getAppKeyAddress');
|
|
142
|
+
}
|
|
143
|
+
assert(params, EthGetAppKeyAddressParamsStruct);
|
|
144
|
+
const [origin] = params;
|
|
145
|
+
return this.inner.getAppKeyAddress(hexAddress, origin);
|
|
146
|
+
}
|
|
147
|
+
case `${EthKeyringMethod.SignEip7702Authorization}`: {
|
|
148
|
+
if (!this.inner.signEip7702Authorization) {
|
|
149
|
+
throw new Error('Keyring does not support signEip7702Authorization');
|
|
150
|
+
}
|
|
151
|
+
assert(params, EthSignEip7702AuthorizationParamsStruct);
|
|
152
|
+
const [authorization] = params;
|
|
153
|
+
return this.inner.signEip7702Authorization(hexAddress, authorization);
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=eth-keyring-wrapper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-keyring-wrapper.mjs","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAoB,uBAAuB;AAEtE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAE9D,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,qCAAqC,EACrC,2BAA2B,EAC3B,uCAAuC,EACvC,mBAAmB,EACnB,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,SAAS,EACV,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAC/C,OAAO,EAAE,KAAK,EAAuB,wBAAwB;AAE7D,OAAO,EAAE,cAAc,EAA8B,+BAA2B;AAEhF;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,2CAAuB,CAAA;IACvB,yEAAqD,CAAA;IACrD,6DAAyC,CAAA;IACzC,6EAAyD,CAAA;AAC3D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BACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n EthMethod,\n} from '@metamask/keyring-api';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport { KeyringWrapper, type KeyringWrapperOptions } from '../keyring-wrapper';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an EthKeyringWrapper.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> =\n KeyringWrapperOptions<InnerKeyring>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./eth-keyring-wrapper.cjs"), exports);
|
|
18
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAsC","sourcesContent":["export * from './eth-keyring-wrapper';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC","sourcesContent":["export * from './eth-keyring-wrapper';\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./keyring-wrapper.cjs"), exports);
|
|
18
|
+
__exportStar(require("./keyring-account-registry.cjs"), exports);
|
|
19
|
+
__exportStar(require("./mnemonic.cjs"), exports);
|
|
20
|
+
__exportStar(require("./eth/index.cjs"), exports);
|
|
21
|
+
//# sourceMappingURL=index.cjs.map
|