@metamask/keyring-sdk 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -2
- package/dist/eth/eth-4337-keyring.cjs +3 -0
- package/dist/eth/eth-4337-keyring.cjs.map +1 -0
- package/dist/eth/eth-4337-keyring.d.cts +35 -0
- package/dist/eth/eth-4337-keyring.d.cts.map +1 -0
- package/dist/eth/eth-4337-keyring.d.mts +35 -0
- package/dist/eth/eth-4337-keyring.d.mts.map +1 -0
- package/dist/eth/eth-4337-keyring.mjs +2 -0
- package/dist/eth/eth-4337-keyring.mjs.map +1 -0
- package/dist/eth/index.cjs.map +1 -1
- package/dist/eth/index.d.cts +1 -0
- package/dist/eth/index.d.cts.map +1 -1
- package/dist/eth/index.d.mts +1 -0
- package/dist/eth/index.d.mts.map +1 -1
- package/dist/eth/index.mjs.map +1 -1
- package/dist/v2/eth/eth-keyring-v1-adapter.cjs +320 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.cjs.map +1 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.d.cts +156 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.d.cts.map +1 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.d.mts +156 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.d.mts.map +1 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.mjs +314 -0
- package/dist/v2/eth/eth-keyring-v1-adapter.mjs.map +1 -0
- package/dist/v2/eth/index.cjs +1 -0
- package/dist/v2/eth/index.cjs.map +1 -1
- package/dist/v2/eth/index.d.cts +1 -0
- package/dist/v2/eth/index.d.cts.map +1 -1
- package/dist/v2/eth/index.d.mts +1 -0
- package/dist/v2/eth/index.d.mts.map +1 -1
- package/dist/v2/eth/index.mjs +1 -0
- package/dist/v2/eth/index.mjs.map +1 -1
- package/dist/v2/keyring-v1-adapter.cjs +5 -19
- package/dist/v2/keyring-v1-adapter.cjs.map +1 -1
- package/dist/v2/keyring-v1-adapter.d.cts +1 -1
- package/dist/v2/keyring-v1-adapter.d.cts.map +1 -1
- package/dist/v2/keyring-v1-adapter.d.mts +1 -1
- package/dist/v2/keyring-v1-adapter.d.mts.map +1 -1
- package/dist/v2/keyring-v1-adapter.mjs +5 -19
- package/dist/v2/keyring-v1-adapter.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { TypedTransaction } from "@ethereumjs/tx";
|
|
2
|
+
import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, KeyringExecutionContext } from "@metamask/keyring-api";
|
|
3
|
+
import type { Keyring as KeyringV2 } from "@metamask/keyring-api/v2";
|
|
4
|
+
import type { BaseKeyring, EthKeyring } from "@metamask/keyring-utils";
|
|
5
|
+
import type { Hex } from "@metamask/utils";
|
|
6
|
+
import type { Eth4337Keyring } from "../../eth/index.cjs";
|
|
7
|
+
import { KeyringV1Adapter } from "../keyring-v1-adapter.cjs";
|
|
8
|
+
/**
|
|
9
|
+
* Legacy ETH keyring API surface exposed by {@link EthKeyringV1Adapter}.
|
|
10
|
+
*/
|
|
11
|
+
export type BaseEthKeyring = BaseKeyring & Pick<EthKeyring, 'exportAccount' | 'signMessage' | 'signEip7702Authorization' | 'signPersonalMessage' | 'signTypedData' | 'signTransaction'> & Eth4337Keyring;
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when an account cannot be resolved from the requested address.
|
|
14
|
+
*/
|
|
15
|
+
export declare class EthKeyringV1AccountNotFoundError extends Error {
|
|
16
|
+
readonly address: string;
|
|
17
|
+
constructor(address: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when a resolved account does not support a requested method.
|
|
21
|
+
*/
|
|
22
|
+
export declare class EthKeyringV1MethodNotSupportedError extends Error {
|
|
23
|
+
readonly address: string;
|
|
24
|
+
readonly method: string;
|
|
25
|
+
constructor(method: string, address: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adapts a `KeyringV2` instance to the subset of the legacy ETH keyring API
|
|
29
|
+
* used by existing ETH export and signing flows.
|
|
30
|
+
*
|
|
31
|
+
* The adapter is account-agnostic: each method resolves the requested address
|
|
32
|
+
* against the wrapped v2 keyring's accounts, verifies that the resolved account
|
|
33
|
+
* supports the requested method, then forwards the request through the v2
|
|
34
|
+
* `submitRequest` or `exportAccount` APIs.
|
|
35
|
+
*/
|
|
36
|
+
export declare class EthKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2> extends KeyringV1Adapter<InnerKeyring> implements BaseEthKeyring {
|
|
37
|
+
#private;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the private data associated with the given address so
|
|
40
|
+
* that it may be exported.
|
|
41
|
+
*
|
|
42
|
+
* Used by the UI to export an account.
|
|
43
|
+
*
|
|
44
|
+
* @param address - Address of the account to export.
|
|
45
|
+
* @returns A promise that resolves to the exported private key.
|
|
46
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
47
|
+
* address.
|
|
48
|
+
*/
|
|
49
|
+
exportAccount(address: Hex): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Sign a transaction.
|
|
52
|
+
*
|
|
53
|
+
* @param address - Sender's address.
|
|
54
|
+
* @param transaction - Transaction.
|
|
55
|
+
* @returns A promise that resolves to the signed transaction.
|
|
56
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
57
|
+
* address.
|
|
58
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
59
|
+
* not support transaction signing.
|
|
60
|
+
*/
|
|
61
|
+
signTransaction(address: Hex, transaction: TypedTransaction): Promise<TypedTransaction>;
|
|
62
|
+
/**
|
|
63
|
+
* Sign a message.
|
|
64
|
+
*
|
|
65
|
+
* @param address - Signer's address.
|
|
66
|
+
* @param data - Data to sign.
|
|
67
|
+
* @returns A promise that resolves to the signature.
|
|
68
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
69
|
+
* address.
|
|
70
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
71
|
+
* not support message signing.
|
|
72
|
+
*/
|
|
73
|
+
signMessage(address: Hex, data: string): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Sign an EIP-7702 authorization.
|
|
76
|
+
*
|
|
77
|
+
* @param address - Signer's address.
|
|
78
|
+
* @param authorization - Authorization tuple to sign.
|
|
79
|
+
* @returns A promise that resolves to the signature.
|
|
80
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
81
|
+
* address.
|
|
82
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
83
|
+
* not support EIP-7702 authorization signing.
|
|
84
|
+
*/
|
|
85
|
+
signEip7702Authorization(address: Hex, authorization: [chainId: number, contractAddress: Hex, nonce: number]): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Sign a personal message.
|
|
88
|
+
*
|
|
89
|
+
* Note: KeyringController says this should return a Buffer but it actually
|
|
90
|
+
* expects a string.
|
|
91
|
+
*
|
|
92
|
+
* @param address - Signer's address.
|
|
93
|
+
* @param message - Data to sign.
|
|
94
|
+
* @returns A promise that resolves to the signature.
|
|
95
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
96
|
+
* address.
|
|
97
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
98
|
+
* not support personal message signing.
|
|
99
|
+
*/
|
|
100
|
+
signPersonalMessage(address: Hex, message: Hex): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Sign a typed data message.
|
|
103
|
+
*
|
|
104
|
+
* @param address - Signer's address.
|
|
105
|
+
* @param typedData - Typed data to sign.
|
|
106
|
+
* @param options - Signing options.
|
|
107
|
+
* @param options.version - The typed data version to use.
|
|
108
|
+
* @returns A promise that resolves to the signature.
|
|
109
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
110
|
+
* address.
|
|
111
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
112
|
+
* not support the requested typed data signing method.
|
|
113
|
+
*/
|
|
114
|
+
signTypedData(address: Hex, typedData: unknown[] | Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Convert base transactions to a base UserOperation.
|
|
117
|
+
*
|
|
118
|
+
* @param address - Address of the sender.
|
|
119
|
+
* @param transactions - Base transactions to include in the UserOperation.
|
|
120
|
+
* @param context - Keyring execution context.
|
|
121
|
+
* @returns A pseudo-UserOperation that can be used to construct a real one.
|
|
122
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
123
|
+
* address.
|
|
124
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
125
|
+
* not support UserOperation preparation.
|
|
126
|
+
*/
|
|
127
|
+
prepareUserOperation(address: string, transactions: EthBaseTransaction[], context: KeyringExecutionContext): Promise<EthBaseUserOperation>;
|
|
128
|
+
/**
|
|
129
|
+
* Patches properties of a UserOperation. Currently, only the
|
|
130
|
+
* `paymasterAndData` can be patched.
|
|
131
|
+
*
|
|
132
|
+
* @param address - Address of the sender.
|
|
133
|
+
* @param userOperation - UserOperation to patch.
|
|
134
|
+
* @param context - Keyring execution context.
|
|
135
|
+
* @returns A patch to apply to the UserOperation.
|
|
136
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
137
|
+
* address.
|
|
138
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
139
|
+
* not support UserOperation patching.
|
|
140
|
+
*/
|
|
141
|
+
patchUserOperation(address: string, userOperation: EthUserOperation, context: KeyringExecutionContext): Promise<EthUserOperationPatch>;
|
|
142
|
+
/**
|
|
143
|
+
* Signs a UserOperation.
|
|
144
|
+
*
|
|
145
|
+
* @param address - Address of the sender.
|
|
146
|
+
* @param userOperation - UserOperation to sign.
|
|
147
|
+
* @param context - Keyring execution context.
|
|
148
|
+
* @returns The signature of the UserOperation.
|
|
149
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
150
|
+
* address.
|
|
151
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
152
|
+
* not support UserOperation signing.
|
|
153
|
+
*/
|
|
154
|
+
signUserOperation(address: string, userOperation: EthUserOperation, context: KeyringExecutionContext): Promise<string>;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=eth-keyring-v1-adapter.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-keyring-v1-adapter.d.cts","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-v1-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAWvD,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EAErB,uBAAuB,EAExB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,iCAAiC;AAKrE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,gCAAgC;AAGvE,OAAO,KAAK,EAAE,GAAG,EAAQ,wBAAwB;AASjD,OAAO,KAAK,EAAE,cAAc,EAAE,4BAAkB;AAChD,OAAO,EAAE,gBAAgB,EAAE,kCAA8B;AA8CzD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAEtC,IAAI,CACF,UAAU,EACR,eAAe,GACf,aAAa,GACb,0BAA0B,GAC1B,qBAAqB,GACrB,eAAe,GACf,iBAAiB,CACpB,GACD,cAAc,CAAC;AAEjB;;GAEG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAM5B;AAED;;GAEG;AACH,qBAAa,mCAAoC,SAAQ,KAAK;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAO5C;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAmB,CAAC,YAAY,SAAS,SAAS,GAAG,SAAS,CACzE,SAAQ,gBAAgB,CAAC,YAAY,CACrC,YAAW,cAAc;;IAEzB;;;;;;;;;;OAUG;IACG,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAelD;;;;;;;;;;OAUG;IACG,eAAe,CACnB,OAAO,EAAE,GAAG,EACZ,WAAW,EAAE,gBAAgB,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IAwC5B;;;;;;;;;;OAUG;IACG,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiB9D;;;;;;;;;;OAUG;IACG,wBAAwB,CAC5B,OAAO,EAAE,GAAG,EACZ,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,GACpE,OAAO,CAAC,MAAM,CAAC;IAmBlB;;;;;;;;;;;;;OAaG;IACG,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBtE;;;;;;;;;;;;OAYG;IACG,aAAa,CACjB,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC;IAuBlB;;;;;;;;;;;OAWG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,oBAAoB,CAAC;IAuBhC;;;;;;;;;;;;OAYG;IACG,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,gBAAgB,EAC/B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAiBjC;;;;;;;;;;;OAWG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,gBAAgB,EAC/B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;CAuFnB"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { TypedTransaction } from "@ethereumjs/tx";
|
|
2
|
+
import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, KeyringExecutionContext } from "@metamask/keyring-api";
|
|
3
|
+
import type { Keyring as KeyringV2 } from "@metamask/keyring-api/v2";
|
|
4
|
+
import type { BaseKeyring, EthKeyring } from "@metamask/keyring-utils";
|
|
5
|
+
import type { Hex } from "@metamask/utils";
|
|
6
|
+
import type { Eth4337Keyring } from "../../eth/index.mjs";
|
|
7
|
+
import { KeyringV1Adapter } from "../keyring-v1-adapter.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* Legacy ETH keyring API surface exposed by {@link EthKeyringV1Adapter}.
|
|
10
|
+
*/
|
|
11
|
+
export type BaseEthKeyring = BaseKeyring & Pick<EthKeyring, 'exportAccount' | 'signMessage' | 'signEip7702Authorization' | 'signPersonalMessage' | 'signTypedData' | 'signTransaction'> & Eth4337Keyring;
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when an account cannot be resolved from the requested address.
|
|
14
|
+
*/
|
|
15
|
+
export declare class EthKeyringV1AccountNotFoundError extends Error {
|
|
16
|
+
readonly address: string;
|
|
17
|
+
constructor(address: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when a resolved account does not support a requested method.
|
|
21
|
+
*/
|
|
22
|
+
export declare class EthKeyringV1MethodNotSupportedError extends Error {
|
|
23
|
+
readonly address: string;
|
|
24
|
+
readonly method: string;
|
|
25
|
+
constructor(method: string, address: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adapts a `KeyringV2` instance to the subset of the legacy ETH keyring API
|
|
29
|
+
* used by existing ETH export and signing flows.
|
|
30
|
+
*
|
|
31
|
+
* The adapter is account-agnostic: each method resolves the requested address
|
|
32
|
+
* against the wrapped v2 keyring's accounts, verifies that the resolved account
|
|
33
|
+
* supports the requested method, then forwards the request through the v2
|
|
34
|
+
* `submitRequest` or `exportAccount` APIs.
|
|
35
|
+
*/
|
|
36
|
+
export declare class EthKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2> extends KeyringV1Adapter<InnerKeyring> implements BaseEthKeyring {
|
|
37
|
+
#private;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the private data associated with the given address so
|
|
40
|
+
* that it may be exported.
|
|
41
|
+
*
|
|
42
|
+
* Used by the UI to export an account.
|
|
43
|
+
*
|
|
44
|
+
* @param address - Address of the account to export.
|
|
45
|
+
* @returns A promise that resolves to the exported private key.
|
|
46
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
47
|
+
* address.
|
|
48
|
+
*/
|
|
49
|
+
exportAccount(address: Hex): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Sign a transaction.
|
|
52
|
+
*
|
|
53
|
+
* @param address - Sender's address.
|
|
54
|
+
* @param transaction - Transaction.
|
|
55
|
+
* @returns A promise that resolves to the signed transaction.
|
|
56
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
57
|
+
* address.
|
|
58
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
59
|
+
* not support transaction signing.
|
|
60
|
+
*/
|
|
61
|
+
signTransaction(address: Hex, transaction: TypedTransaction): Promise<TypedTransaction>;
|
|
62
|
+
/**
|
|
63
|
+
* Sign a message.
|
|
64
|
+
*
|
|
65
|
+
* @param address - Signer's address.
|
|
66
|
+
* @param data - Data to sign.
|
|
67
|
+
* @returns A promise that resolves to the signature.
|
|
68
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
69
|
+
* address.
|
|
70
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
71
|
+
* not support message signing.
|
|
72
|
+
*/
|
|
73
|
+
signMessage(address: Hex, data: string): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Sign an EIP-7702 authorization.
|
|
76
|
+
*
|
|
77
|
+
* @param address - Signer's address.
|
|
78
|
+
* @param authorization - Authorization tuple to sign.
|
|
79
|
+
* @returns A promise that resolves to the signature.
|
|
80
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
81
|
+
* address.
|
|
82
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
83
|
+
* not support EIP-7702 authorization signing.
|
|
84
|
+
*/
|
|
85
|
+
signEip7702Authorization(address: Hex, authorization: [chainId: number, contractAddress: Hex, nonce: number]): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Sign a personal message.
|
|
88
|
+
*
|
|
89
|
+
* Note: KeyringController says this should return a Buffer but it actually
|
|
90
|
+
* expects a string.
|
|
91
|
+
*
|
|
92
|
+
* @param address - Signer's address.
|
|
93
|
+
* @param message - Data to sign.
|
|
94
|
+
* @returns A promise that resolves to the signature.
|
|
95
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
96
|
+
* address.
|
|
97
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
98
|
+
* not support personal message signing.
|
|
99
|
+
*/
|
|
100
|
+
signPersonalMessage(address: Hex, message: Hex): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Sign a typed data message.
|
|
103
|
+
*
|
|
104
|
+
* @param address - Signer's address.
|
|
105
|
+
* @param typedData - Typed data to sign.
|
|
106
|
+
* @param options - Signing options.
|
|
107
|
+
* @param options.version - The typed data version to use.
|
|
108
|
+
* @returns A promise that resolves to the signature.
|
|
109
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
110
|
+
* address.
|
|
111
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
112
|
+
* not support the requested typed data signing method.
|
|
113
|
+
*/
|
|
114
|
+
signTypedData(address: Hex, typedData: unknown[] | Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Convert base transactions to a base UserOperation.
|
|
117
|
+
*
|
|
118
|
+
* @param address - Address of the sender.
|
|
119
|
+
* @param transactions - Base transactions to include in the UserOperation.
|
|
120
|
+
* @param context - Keyring execution context.
|
|
121
|
+
* @returns A pseudo-UserOperation that can be used to construct a real one.
|
|
122
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
123
|
+
* address.
|
|
124
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
125
|
+
* not support UserOperation preparation.
|
|
126
|
+
*/
|
|
127
|
+
prepareUserOperation(address: string, transactions: EthBaseTransaction[], context: KeyringExecutionContext): Promise<EthBaseUserOperation>;
|
|
128
|
+
/**
|
|
129
|
+
* Patches properties of a UserOperation. Currently, only the
|
|
130
|
+
* `paymasterAndData` can be patched.
|
|
131
|
+
*
|
|
132
|
+
* @param address - Address of the sender.
|
|
133
|
+
* @param userOperation - UserOperation to patch.
|
|
134
|
+
* @param context - Keyring execution context.
|
|
135
|
+
* @returns A patch to apply to the UserOperation.
|
|
136
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
137
|
+
* address.
|
|
138
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
139
|
+
* not support UserOperation patching.
|
|
140
|
+
*/
|
|
141
|
+
patchUserOperation(address: string, userOperation: EthUserOperation, context: KeyringExecutionContext): Promise<EthUserOperationPatch>;
|
|
142
|
+
/**
|
|
143
|
+
* Signs a UserOperation.
|
|
144
|
+
*
|
|
145
|
+
* @param address - Address of the sender.
|
|
146
|
+
* @param userOperation - UserOperation to sign.
|
|
147
|
+
* @param context - Keyring execution context.
|
|
148
|
+
* @returns The signature of the UserOperation.
|
|
149
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
150
|
+
* address.
|
|
151
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
152
|
+
* not support UserOperation signing.
|
|
153
|
+
*/
|
|
154
|
+
signUserOperation(address: string, userOperation: EthUserOperation, context: KeyringExecutionContext): Promise<string>;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=eth-keyring-v1-adapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-keyring-v1-adapter.d.mts","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-v1-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAWvD,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EAErB,uBAAuB,EAExB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,iCAAiC;AAKrE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,gCAAgC;AAGvE,OAAO,KAAK,EAAE,GAAG,EAAQ,wBAAwB;AASjD,OAAO,KAAK,EAAE,cAAc,EAAE,4BAAkB;AAChD,OAAO,EAAE,gBAAgB,EAAE,kCAA8B;AA8CzD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAEtC,IAAI,CACF,UAAU,EACR,eAAe,GACf,aAAa,GACb,0BAA0B,GAC1B,qBAAqB,GACrB,eAAe,GACf,iBAAiB,CACpB,GACD,cAAc,CAAC;AAEjB;;GAEG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAM5B;AAED;;GAEG;AACH,qBAAa,mCAAoC,SAAQ,KAAK;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAO5C;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAmB,CAAC,YAAY,SAAS,SAAS,GAAG,SAAS,CACzE,SAAQ,gBAAgB,CAAC,YAAY,CACrC,YAAW,cAAc;;IAEzB;;;;;;;;;;OAUG;IACG,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAelD;;;;;;;;;;OAUG;IACG,eAAe,CACnB,OAAO,EAAE,GAAG,EACZ,WAAW,EAAE,gBAAgB,GAC5B,OAAO,CAAC,gBAAgB,CAAC;IAwC5B;;;;;;;;;;OAUG;IACG,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiB9D;;;;;;;;;;OAUG;IACG,wBAAwB,CAC5B,OAAO,EAAE,GAAG,EACZ,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,GACpE,OAAO,CAAC,MAAM,CAAC;IAmBlB;;;;;;;;;;;;;OAaG;IACG,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBtE;;;;;;;;;;;;OAYG;IACG,aAAa,CACjB,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC;IAuBlB;;;;;;;;;;;OAWG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,oBAAoB,CAAC;IAuBhC;;;;;;;;;;;;OAYG;IACG,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,gBAAgB,EAC/B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAiBjC;;;;;;;;;;;OAWG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,gBAAgB,EAC/B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;CAuFnB"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _EthKeyringV1Adapter_instances, _EthKeyringV1Adapter_getAccount, _EthKeyringV1Adapter_getAccountForMethod, _EthKeyringV1Adapter_getSignTypedDataMethod, _EthKeyringV1Adapter_submitRequest;
|
|
7
|
+
import { TransactionFactory } from "@ethereumjs/tx";
|
|
8
|
+
import { normalize as ethNormalize } from "@metamask/eth-sig-util";
|
|
9
|
+
import { EthBaseUserOperationStruct, EthBytesStrictStruct, EthBytesStruct, EthMethod, EthUserOperationPatchStruct } from "@metamask/keyring-api";
|
|
10
|
+
import { AccountExportType, PrivateKeyEncoding } from "@metamask/keyring-api/v2";
|
|
11
|
+
import { strictMask } from "@metamask/keyring-utils";
|
|
12
|
+
import { mask, object } from "@metamask/superstruct";
|
|
13
|
+
import { bigIntToHex, KnownCaipNamespace, remove0x, toCaipChainId } from "@metamask/utils";
|
|
14
|
+
import { v4 as uuid } from "uuid";
|
|
15
|
+
import { KeyringV1Adapter } from "../keyring-v1-adapter.mjs";
|
|
16
|
+
import { EthKeyringMethod } from "./eth-keyring-wrapper.mjs";
|
|
17
|
+
const METAMASK_ORIGIN = 'metamask';
|
|
18
|
+
/**
|
|
19
|
+
* Convert a value to a valid JSON object.
|
|
20
|
+
*
|
|
21
|
+
* The function chains JSON.stringify and JSON.parse to ensure that the result
|
|
22
|
+
* is a valid JSON object.
|
|
23
|
+
*
|
|
24
|
+
* We assume that the input value is JSON-serializable.
|
|
25
|
+
*
|
|
26
|
+
* However, some transformations can occur like: in objects, undefined values
|
|
27
|
+
* are removed, and in arrays, they are replaced with null.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Value to convert to JSON - Assumed to be JSON-serializable.
|
|
30
|
+
* @returns JSON representation of the value.
|
|
31
|
+
*/
|
|
32
|
+
function toJson(value) {
|
|
33
|
+
return JSON.parse(JSON.stringify(value));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert a chain ID (number or hex) to an EIP-155 CAIP chain ID string for keyring request scoping.
|
|
37
|
+
*
|
|
38
|
+
* @param chainId - The chain ID to convert.
|
|
39
|
+
* @returns The EIP-155 CAIP chain ID string.
|
|
40
|
+
*/
|
|
41
|
+
function toEip155Scope(chainId) {
|
|
42
|
+
return toCaipChainId(KnownCaipNamespace.Eip155, BigInt(chainId).toString());
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Error thrown when an account cannot be resolved from the requested address.
|
|
46
|
+
*/
|
|
47
|
+
export class EthKeyringV1AccountNotFoundError extends Error {
|
|
48
|
+
constructor(address) {
|
|
49
|
+
super(`Account not found for address: ${address}`);
|
|
50
|
+
this.name = 'EthKeyringV1AccountNotFoundError';
|
|
51
|
+
this.address = address;
|
|
52
|
+
Object.setPrototypeOf(this, EthKeyringV1AccountNotFoundError.prototype);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Error thrown when a resolved account does not support a requested method.
|
|
57
|
+
*/
|
|
58
|
+
export class EthKeyringV1MethodNotSupportedError extends Error {
|
|
59
|
+
constructor(method, address) {
|
|
60
|
+
super(`Account ${address} does not support method: ${method}`);
|
|
61
|
+
this.name = 'EthKeyringV1MethodNotSupportedError';
|
|
62
|
+
this.address = address;
|
|
63
|
+
this.method = method;
|
|
64
|
+
Object.setPrototypeOf(this, EthKeyringV1MethodNotSupportedError.prototype);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Adapts a `KeyringV2` instance to the subset of the legacy ETH keyring API
|
|
69
|
+
* used by existing ETH export and signing flows.
|
|
70
|
+
*
|
|
71
|
+
* The adapter is account-agnostic: each method resolves the requested address
|
|
72
|
+
* against the wrapped v2 keyring's accounts, verifies that the resolved account
|
|
73
|
+
* supports the requested method, then forwards the request through the v2
|
|
74
|
+
* `submitRequest` or `exportAccount` APIs.
|
|
75
|
+
*/
|
|
76
|
+
export class EthKeyringV1Adapter extends KeyringV1Adapter {
|
|
77
|
+
constructor() {
|
|
78
|
+
super(...arguments);
|
|
79
|
+
_EthKeyringV1Adapter_instances.add(this);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets the private data associated with the given address so
|
|
83
|
+
* that it may be exported.
|
|
84
|
+
*
|
|
85
|
+
* Used by the UI to export an account.
|
|
86
|
+
*
|
|
87
|
+
* @param address - Address of the account to export.
|
|
88
|
+
* @returns A promise that resolves to the exported private key.
|
|
89
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
90
|
+
* address.
|
|
91
|
+
*/
|
|
92
|
+
async exportAccount(address) {
|
|
93
|
+
const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccount).call(this, address);
|
|
94
|
+
if (!this.inner.exportAccount) {
|
|
95
|
+
throw new Error('Keyring does not support exportAccount');
|
|
96
|
+
}
|
|
97
|
+
const exportedAccount = await this.inner.exportAccount(account.id, {
|
|
98
|
+
type: AccountExportType.PrivateKey,
|
|
99
|
+
encoding: PrivateKeyEncoding.Hexadecimal,
|
|
100
|
+
});
|
|
101
|
+
return remove0x(exportedAccount.privateKey);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Sign a transaction.
|
|
105
|
+
*
|
|
106
|
+
* @param address - Sender's address.
|
|
107
|
+
* @param transaction - Transaction.
|
|
108
|
+
* @returns A promise that resolves to the signed transaction.
|
|
109
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
110
|
+
* address.
|
|
111
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
112
|
+
* not support transaction signing.
|
|
113
|
+
*/
|
|
114
|
+
async signTransaction(address, transaction) {
|
|
115
|
+
const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthMethod.SignTransaction);
|
|
116
|
+
const chainId = transaction.common.chainId();
|
|
117
|
+
const tx = toJson({
|
|
118
|
+
...transaction.toJSON(),
|
|
119
|
+
from: normalizedAddress,
|
|
120
|
+
type: `0x${transaction.type.toString(16)}`,
|
|
121
|
+
chainId: bigIntToHex(chainId),
|
|
122
|
+
});
|
|
123
|
+
const signedTx = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthMethod.SignTransaction, toJson([tx]), toEip155Scope(chainId));
|
|
124
|
+
// Only take the signature fields from the keyring response. This prevents
|
|
125
|
+
// the keyring from overwriting the transaction payload we submitted.
|
|
126
|
+
const signature = mask(signedTx, object({
|
|
127
|
+
r: EthBytesStrictStruct,
|
|
128
|
+
s: EthBytesStrictStruct,
|
|
129
|
+
v: EthBytesStrictStruct,
|
|
130
|
+
}));
|
|
131
|
+
return TransactionFactory.fromTxData({
|
|
132
|
+
...tx,
|
|
133
|
+
r: signature.r,
|
|
134
|
+
s: signature.s,
|
|
135
|
+
v: signature.v,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sign a message.
|
|
140
|
+
*
|
|
141
|
+
* @param address - Signer's address.
|
|
142
|
+
* @param data - Data to sign.
|
|
143
|
+
* @returns A promise that resolves to the signature.
|
|
144
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
145
|
+
* address.
|
|
146
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
147
|
+
* not support message signing.
|
|
148
|
+
*/
|
|
149
|
+
async signMessage(address, data) {
|
|
150
|
+
const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthMethod.Sign);
|
|
151
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthMethod.Sign, toJson([normalizedAddress, data]), ''), EthBytesStruct);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sign an EIP-7702 authorization.
|
|
155
|
+
*
|
|
156
|
+
* @param address - Signer's address.
|
|
157
|
+
* @param authorization - Authorization tuple to sign.
|
|
158
|
+
* @returns A promise that resolves to the signature.
|
|
159
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
160
|
+
* address.
|
|
161
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
162
|
+
* not support EIP-7702 authorization signing.
|
|
163
|
+
*/
|
|
164
|
+
async signEip7702Authorization(address, authorization) {
|
|
165
|
+
const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthKeyringMethod.SignEip7702Authorization);
|
|
166
|
+
const [chainId] = authorization;
|
|
167
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthKeyringMethod.SignEip7702Authorization, [authorization], toEip155Scope(chainId)), EthBytesStruct);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Sign a personal message.
|
|
171
|
+
*
|
|
172
|
+
* Note: KeyringController says this should return a Buffer but it actually
|
|
173
|
+
* expects a string.
|
|
174
|
+
*
|
|
175
|
+
* @param address - Signer's address.
|
|
176
|
+
* @param message - Data to sign.
|
|
177
|
+
* @returns A promise that resolves to the signature.
|
|
178
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
179
|
+
* address.
|
|
180
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
181
|
+
* not support personal message signing.
|
|
182
|
+
*/
|
|
183
|
+
async signPersonalMessage(address, message) {
|
|
184
|
+
const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthMethod.PersonalSign);
|
|
185
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthMethod.PersonalSign, toJson([message, normalizedAddress]), ''), EthBytesStruct);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Sign a typed data message.
|
|
189
|
+
*
|
|
190
|
+
* @param address - Signer's address.
|
|
191
|
+
* @param typedData - Typed data to sign.
|
|
192
|
+
* @param options - Signing options.
|
|
193
|
+
* @param options.version - The typed data version to use.
|
|
194
|
+
* @returns A promise that resolves to the signature.
|
|
195
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
196
|
+
* address.
|
|
197
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
198
|
+
* not support the requested typed data signing method.
|
|
199
|
+
*/
|
|
200
|
+
async signTypedData(address, typedData, options) {
|
|
201
|
+
const version = options?.version;
|
|
202
|
+
const method = __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getSignTypedDataMethod).call(this, version);
|
|
203
|
+
const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, method);
|
|
204
|
+
// Extract chain ID as if it was a typed message (as defined by EIP-712), if
|
|
205
|
+
// input is not a typed message, then chain ID will be undefined!
|
|
206
|
+
const chainId = typedData.domain?.chainId;
|
|
207
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, method, toJson([normalizedAddress, typedData]), chainId === undefined ? '' : toEip155Scope(chainId)), EthBytesStruct);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Convert base transactions to a base UserOperation.
|
|
211
|
+
*
|
|
212
|
+
* @param address - Address of the sender.
|
|
213
|
+
* @param transactions - Base transactions to include in the UserOperation.
|
|
214
|
+
* @param context - Keyring execution context.
|
|
215
|
+
* @returns A pseudo-UserOperation that can be used to construct a real one.
|
|
216
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
217
|
+
* address.
|
|
218
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
219
|
+
* not support UserOperation preparation.
|
|
220
|
+
*/
|
|
221
|
+
async prepareUserOperation(address, transactions, context) {
|
|
222
|
+
const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthMethod.PrepareUserOperation);
|
|
223
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthMethod.PrepareUserOperation,
|
|
224
|
+
// NOTE: This is inconsistent with the other methods. We are not wrapping `transactions` in an array.
|
|
225
|
+
// Which means the receiver of the `submitRequest` call would see individual transactions spread as
|
|
226
|
+
// separate params rather than a single transactions array as the first param, which doesn't match
|
|
227
|
+
// the method signature of `prepareUserOperation(address, transactions, context)`.
|
|
228
|
+
// This was already implemented like this in the legacy Snap keyring, so we keep the same logic here
|
|
229
|
+
// too!
|
|
230
|
+
toJson(transactions), toEip155Scope(context.chainId)), EthBaseUserOperationStruct);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Patches properties of a UserOperation. Currently, only the
|
|
234
|
+
* `paymasterAndData` can be patched.
|
|
235
|
+
*
|
|
236
|
+
* @param address - Address of the sender.
|
|
237
|
+
* @param userOperation - UserOperation to patch.
|
|
238
|
+
* @param context - Keyring execution context.
|
|
239
|
+
* @returns A patch to apply to the UserOperation.
|
|
240
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
241
|
+
* address.
|
|
242
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
243
|
+
* not support UserOperation patching.
|
|
244
|
+
*/
|
|
245
|
+
async patchUserOperation(address, userOperation, context) {
|
|
246
|
+
const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthMethod.PatchUserOperation);
|
|
247
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthMethod.PatchUserOperation, toJson([userOperation]), toEip155Scope(context.chainId)), EthUserOperationPatchStruct);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Signs a UserOperation.
|
|
251
|
+
*
|
|
252
|
+
* @param address - Address of the sender.
|
|
253
|
+
* @param userOperation - UserOperation to sign.
|
|
254
|
+
* @param context - Keyring execution context.
|
|
255
|
+
* @returns The signature of the UserOperation.
|
|
256
|
+
* @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
|
|
257
|
+
* address.
|
|
258
|
+
* @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
|
|
259
|
+
* not support UserOperation signing.
|
|
260
|
+
*/
|
|
261
|
+
async signUserOperation(address, userOperation, context) {
|
|
262
|
+
const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, EthMethod.SignUserOperation);
|
|
263
|
+
return strictMask(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, EthMethod.SignUserOperation, toJson([userOperation]), toEip155Scope(context.chainId)), EthBytesStruct);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
_EthKeyringV1Adapter_instances = new WeakSet(), _EthKeyringV1Adapter_getAccount = async function _EthKeyringV1Adapter_getAccount(address) {
|
|
267
|
+
const normalizedAddress = ethNormalize(address);
|
|
268
|
+
const normalizedAddressLowerCase = normalizedAddress?.toLowerCase();
|
|
269
|
+
if (!normalizedAddress || !normalizedAddressLowerCase) {
|
|
270
|
+
throw new EthKeyringV1AccountNotFoundError(address);
|
|
271
|
+
}
|
|
272
|
+
const accounts = await this.inner.getAccounts();
|
|
273
|
+
const account = accounts.find((keyringAccount) => {
|
|
274
|
+
const accountAddress = ethNormalize(keyringAccount.address);
|
|
275
|
+
return accountAddress?.toLowerCase() === normalizedAddressLowerCase;
|
|
276
|
+
});
|
|
277
|
+
if (!account) {
|
|
278
|
+
throw new EthKeyringV1AccountNotFoundError(address);
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
account,
|
|
282
|
+
normalizedAddress: normalizedAddress,
|
|
283
|
+
};
|
|
284
|
+
}, _EthKeyringV1Adapter_getAccountForMethod = async function _EthKeyringV1Adapter_getAccountForMethod(address, method) {
|
|
285
|
+
const resolvedAccount = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccount).call(this, address);
|
|
286
|
+
if (!resolvedAccount.account.methods.includes(method)) {
|
|
287
|
+
throw new EthKeyringV1MethodNotSupportedError(method, address);
|
|
288
|
+
}
|
|
289
|
+
return resolvedAccount;
|
|
290
|
+
}, _EthKeyringV1Adapter_getSignTypedDataMethod = function _EthKeyringV1Adapter_getSignTypedDataMethod(version) {
|
|
291
|
+
switch (version) {
|
|
292
|
+
case 'V3':
|
|
293
|
+
return EthMethod.SignTypedDataV3;
|
|
294
|
+
case 'V4':
|
|
295
|
+
return EthMethod.SignTypedDataV4;
|
|
296
|
+
case 'V1':
|
|
297
|
+
default:
|
|
298
|
+
// Use 'V1' by default to match other keyring implementations. V1 will be
|
|
299
|
+
// used if the version is not specified or not supported.
|
|
300
|
+
return EthMethod.SignTypedDataV1;
|
|
301
|
+
}
|
|
302
|
+
}, _EthKeyringV1Adapter_submitRequest = async function _EthKeyringV1Adapter_submitRequest(account, method, params, scope) {
|
|
303
|
+
return (await this.inner.submitRequest({
|
|
304
|
+
id: uuid(),
|
|
305
|
+
origin: METAMASK_ORIGIN,
|
|
306
|
+
scope,
|
|
307
|
+
account: account.id,
|
|
308
|
+
request: {
|
|
309
|
+
method,
|
|
310
|
+
params,
|
|
311
|
+
},
|
|
312
|
+
}));
|
|
313
|
+
};
|
|
314
|
+
//# sourceMappingURL=eth-keyring-v1-adapter.mjs.map
|