@metamask-previews/keyring-api 21.3.0-8508712 → 21.3.0-ca5bb42
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 +10 -0
- package/README.md +4 -0
- package/dist/api/keyring.cjs +0 -2
- package/dist/api/keyring.cjs.map +1 -1
- package/dist/api/keyring.d.cts.map +1 -1
- package/dist/api/keyring.d.mts.map +1 -1
- package/dist/api/keyring.mjs +0 -2
- package/dist/api/keyring.mjs.map +1 -1
- package/dist/api/v2/index.cjs +1 -0
- package/dist/api/v2/index.cjs.map +1 -1
- package/dist/api/v2/index.d.cts +1 -0
- package/dist/api/v2/index.d.cts.map +1 -1
- package/dist/api/v2/index.d.mts +1 -0
- package/dist/api/v2/index.d.mts.map +1 -1
- package/dist/api/v2/index.mjs +1 -0
- package/dist/api/v2/index.mjs.map +1 -1
- package/dist/api/v2/wrapper/index.cjs +19 -0
- package/dist/api/v2/wrapper/index.cjs.map +1 -0
- package/dist/api/v2/wrapper/index.d.cts +3 -0
- package/dist/api/v2/wrapper/index.d.cts.map +1 -0
- package/dist/api/v2/wrapper/index.d.mts +3 -0
- package/dist/api/v2/wrapper/index.d.mts.map +1 -0
- package/dist/api/v2/wrapper/index.mjs +3 -0
- package/dist/api/v2/wrapper/index.mjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.cjs +135 -0
- package/dist/api/v2/wrapper/keyring-account-registry.cjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.cts +88 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.cts.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.mts +88 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.mts.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.mjs +131 -0
- package/dist/api/v2/wrapper/keyring-account-registry.mjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.cjs +116 -0
- package/dist/api/v2/wrapper/keyring-wrapper.cjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.cts +146 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.cts.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.mts +146 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.mts.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.mjs +112 -0
- package/dist/api/v2/wrapper/keyring-wrapper.mjs.map +1 -0
- package/dist/eth/erc4337/types.d.cts +4 -4
- package/dist/eth/erc4337/types.d.mts +4 -4
- package/dist/eth/index.cjs +2 -0
- package/dist/eth/index.cjs.map +1 -1
- package/dist/eth/index.d.cts +2 -0
- package/dist/eth/index.d.cts.map +1 -1
- package/dist/eth/index.d.mts +2 -0
- package/dist/eth/index.d.mts.map +1 -1
- package/dist/eth/index.mjs +2 -0
- package/dist/eth/index.mjs.map +1 -1
- package/dist/eth/rpc/index.cjs +18 -0
- package/dist/eth/rpc/index.cjs.map +1 -0
- package/dist/eth/rpc/index.d.cts +2 -0
- package/dist/eth/rpc/index.d.cts.map +1 -0
- package/dist/eth/rpc/index.d.mts +2 -0
- package/dist/eth/rpc/index.d.mts.map +1 -0
- package/dist/eth/rpc/index.mjs +2 -0
- package/dist/eth/rpc/index.mjs.map +1 -0
- package/dist/eth/rpc/params.cjs +151 -0
- package/dist/eth/rpc/params.cjs.map +1 -0
- package/dist/eth/rpc/params.d.cts +215 -0
- package/dist/eth/rpc/params.d.cts.map +1 -0
- package/dist/eth/rpc/params.d.mts +215 -0
- package/dist/eth/rpc/params.d.mts.map +1 -0
- package/dist/eth/rpc/params.mjs +148 -0
- package/dist/eth/rpc/params.mjs.map +1 -0
- package/dist/eth/types.cjs.map +1 -1
- package/dist/eth/types.d.cts +5 -5
- package/dist/eth/types.d.cts.map +1 -1
- package/dist/eth/types.d.mts +5 -5
- package/dist/eth/types.d.mts.map +1 -1
- package/dist/eth/types.mjs.map +1 -1
- package/dist/eth/v2/eth-keyring-wrapper.cjs +165 -0
- package/dist/eth/v2/eth-keyring-wrapper.cjs.map +1 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.cts +54 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.cts.map +1 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.mts +54 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.mts.map +1 -0
- package/dist/eth/v2/eth-keyring-wrapper.mjs +161 -0
- package/dist/eth/v2/eth-keyring-wrapper.mjs.map +1 -0
- package/dist/eth/v2/index.cjs +18 -0
- package/dist/eth/v2/index.cjs.map +1 -0
- package/dist/eth/v2/index.d.cts +2 -0
- package/dist/eth/v2/index.d.cts.map +1 -0
- package/dist/eth/v2/index.d.mts +2 -0
- package/dist/eth/v2/index.d.mts.map +1 -0
- package/dist/eth/v2/index.mjs +2 -0
- package/dist/eth/v2/index.mjs.map +1 -0
- package/dist/events.cjs +0 -2
- package/dist/events.cjs.map +1 -1
- package/dist/events.d.cts.map +1 -1
- package/dist/events.d.mts.map +1 -1
- package/dist/events.mjs +0 -2
- package/dist/events.mjs.map +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,112 @@
|
|
|
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 _KeyringWrapper_lock;
|
|
7
|
+
import { Mutex } from "async-mutex";
|
|
8
|
+
import { KeyringAccountRegistry } from "./keyring-account-registry.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* Generic adapter that turns an existing {@link Keyring} implementation into a
|
|
11
|
+
* {@link KeyringV2} instance.
|
|
12
|
+
*
|
|
13
|
+
* Consumers are expected to provide concrete mappings between high-level V2
|
|
14
|
+
* operations and the underlying keyring methods (for example BIP-44 account
|
|
15
|
+
* creation, private-key import, and request handling). This class focuses on
|
|
16
|
+
* the common mechanics required by all adapters: state serialization,
|
|
17
|
+
* account-ID/address mapping and basic account management.
|
|
18
|
+
*/
|
|
19
|
+
export class KeyringWrapper {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
/**
|
|
22
|
+
* Mutex to ensure exclusive access to the inner keyring during
|
|
23
|
+
* operations that mutate its state.
|
|
24
|
+
*/
|
|
25
|
+
_KeyringWrapper_lock.set(this, new Mutex());
|
|
26
|
+
/**
|
|
27
|
+
* Registry for KeyringAccount objects.
|
|
28
|
+
* Provides O(1) lookups by AccountId or address.
|
|
29
|
+
*
|
|
30
|
+
* Subclasses should use this registry when creating accounts and
|
|
31
|
+
* clear/update it when deleting accounts or deserializing state.
|
|
32
|
+
*/
|
|
33
|
+
this.registry = new KeyringAccountRegistry();
|
|
34
|
+
this.inner = options.inner;
|
|
35
|
+
this.type = `${options.type}`;
|
|
36
|
+
this.capabilities = options.capabilities;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Execute an operation with exclusive access to the inner keyring.
|
|
40
|
+
*
|
|
41
|
+
* This method ensures thread-safety for operations that read or mutate
|
|
42
|
+
* the inner keyring state. All operations that modify the keyring
|
|
43
|
+
* (createAccounts, deleteAccount, deserialize) should use this method
|
|
44
|
+
* to prevent race conditions.
|
|
45
|
+
*
|
|
46
|
+
* Within the callback, use `this.inner` to access the inner keyring.
|
|
47
|
+
*
|
|
48
|
+
* @param callback - A function that performs the operation.
|
|
49
|
+
* @returns The result of the callback.
|
|
50
|
+
*/
|
|
51
|
+
async withLock(callback) {
|
|
52
|
+
return __classPrivateFieldGet(this, _KeyringWrapper_lock, "f").runExclusive(callback);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Serialize the underlying keyring state to a JSON-serializable object.
|
|
56
|
+
*
|
|
57
|
+
* This simply delegates to the legacy keyring's {@link Keyring.serialize}
|
|
58
|
+
* implementation.
|
|
59
|
+
*
|
|
60
|
+
* @returns The serialized keyring state.
|
|
61
|
+
*/
|
|
62
|
+
async serialize() {
|
|
63
|
+
return this.inner.serialize();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Hydrate the underlying keyring from a previously serialized state.
|
|
67
|
+
*
|
|
68
|
+
* This clears the registry, delegates to the legacy keyring's
|
|
69
|
+
* {@link Keyring.deserialize} implementation, and rebuilds the registry
|
|
70
|
+
* by calling {@link getAccounts}.
|
|
71
|
+
*
|
|
72
|
+
* @param state - The serialized keyring state.
|
|
73
|
+
*/
|
|
74
|
+
async deserialize(state) {
|
|
75
|
+
await this.withLock(async () => {
|
|
76
|
+
// Clear the registry when deserializing
|
|
77
|
+
this.registry.clear();
|
|
78
|
+
// Deserialize the legacy keyring
|
|
79
|
+
await this.inner.deserialize(state);
|
|
80
|
+
// Rebuild the registry by calling getAccounts().
|
|
81
|
+
// Subclass implementations of getAccounts() should populate the registry
|
|
82
|
+
// as a side effect (see the abstract method's documentation).
|
|
83
|
+
await this.getAccounts();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Look up a single account by its {@link AccountId}.
|
|
88
|
+
*
|
|
89
|
+
* This method first checks the registry for O(1) lookup.
|
|
90
|
+
* If not found, it falls back to calling {@link getAccounts} which
|
|
91
|
+
* should populate the registry as a side effect.
|
|
92
|
+
*
|
|
93
|
+
* @param accountId - The AccountId to look up.
|
|
94
|
+
* @returns The matching KeyringAccount.
|
|
95
|
+
*/
|
|
96
|
+
async getAccount(accountId) {
|
|
97
|
+
let cached = this.registry.get(accountId);
|
|
98
|
+
if (cached) {
|
|
99
|
+
return cached;
|
|
100
|
+
}
|
|
101
|
+
// Prime the registry by calling getAccounts
|
|
102
|
+
await this.getAccounts();
|
|
103
|
+
// Try registry again after priming
|
|
104
|
+
cached = this.registry.get(accountId);
|
|
105
|
+
if (!cached) {
|
|
106
|
+
throw new Error(`Account not found for id: ${accountId}`);
|
|
107
|
+
}
|
|
108
|
+
return cached;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
_KeyringWrapper_lock = new WeakMap();
|
|
112
|
+
//# sourceMappingURL=keyring-wrapper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-wrapper.mjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-wrapper.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAEpC,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AAgCpE;;;;;;;;;GASG;AACH,MAAM,OAAgB,cAAc;IA2BlC,YAAY,OAA4C;QAhBxD;;;WAGG;QACM,+BAAQ,IAAI,KAAK,EAAE,EAAC;QAE7B;;;;;;WAMG;QACgB,aAAQ,GACzB,IAAI,sBAAsB,EAAsB,CAAC;QAGjD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,QAAQ,CACtB,QAA+B;QAE/B,OAAO,uBAAA,IAAI,4BAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC7B,wCAAwC;YACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEtB,iCAAiC;YACjC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEpC,iDAAiD;YACjD,yEAAyE;YACzE,8DAA8D;YAC9D,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAgBD;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,4CAA4C;QAC5C,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAEzB,mCAAmC;QACnC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CA+CF","sourcesContent":["import type { Keyring, AccountId } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { KeyringAccountRegistry } from './keyring-account-registry';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n} from '..';\nimport type { KeyringAccount } from '../../account';\nimport type { KeyringRequest } from '../../request';\nimport type { KeyringV2 } from '../keyring';\nimport type { KeyringCapabilities } from '../keyring-capabilities';\nimport type { KeyringType } from '../keyring-type';\n\n/**\n * Basic options for constructing a {@link KeyringWrapper}.\n */\nexport type KeyringWrapperOptions<InnerKeyring extends Keyring> = {\n /**\n * The underlying \"old\" keyring instance that this wrapper adapts.\n */\n inner: InnerKeyring;\n\n /**\n * The concrete keyring type exposed through the V2 interface.\n */\n type: KeyringType;\n\n /**\n * Capabilities of the underlying keyring.\n */\n capabilities: KeyringCapabilities;\n};\n\n/**\n * Generic adapter that turns an existing {@link Keyring} implementation into a\n * {@link KeyringV2} instance.\n *\n * Consumers are expected to provide concrete mappings between high-level V2\n * operations and the underlying keyring methods (for example BIP-44 account\n * creation, private-key import, and request handling). This class focuses on\n * the common mechanics required by all adapters: state serialization,\n * account-ID/address mapping and basic account management.\n */\nexport abstract class KeyringWrapper<\n InnerKeyring extends Keyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> implements KeyringV2\n{\n readonly type: `${KeyringType}`;\n\n readonly capabilities: KeyringCapabilities;\n\n protected readonly inner: InnerKeyring;\n\n /**\n * Mutex to ensure exclusive access to the inner keyring during\n * operations that mutate its state.\n */\n readonly #lock = new Mutex();\n\n /**\n * Registry for KeyringAccount objects.\n * Provides O(1) lookups by AccountId or address.\n *\n * Subclasses should use this registry when creating accounts and\n * clear/update it when deleting accounts or deserializing state.\n */\n protected readonly registry =\n new KeyringAccountRegistry<KeyringAccountType>();\n\n constructor(options: KeyringWrapperOptions<InnerKeyring>) {\n this.inner = options.inner;\n this.type = `${options.type}`;\n this.capabilities = options.capabilities;\n }\n\n /**\n * Execute an operation with exclusive access to the inner keyring.\n *\n * This method ensures thread-safety for operations that read or mutate\n * the inner keyring state. All operations that modify the keyring\n * (createAccounts, deleteAccount, deserialize) should use this method\n * to prevent race conditions.\n *\n * Within the callback, use `this.inner` to access the inner keyring.\n *\n * @param callback - A function that performs the operation.\n * @returns The result of the callback.\n */\n protected async withLock<Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> {\n return this.#lock.runExclusive(callback);\n }\n\n /**\n * Serialize the underlying keyring state to a JSON-serializable object.\n *\n * This simply delegates to the legacy keyring's {@link Keyring.serialize}\n * implementation.\n *\n * @returns The serialized keyring state.\n */\n async serialize(): Promise<Json> {\n return this.inner.serialize();\n }\n\n /**\n * Hydrate the underlying keyring from a previously serialized state.\n *\n * This clears the registry, delegates to the legacy keyring's\n * {@link Keyring.deserialize} implementation, and rebuilds the registry\n * by calling {@link getAccounts}.\n *\n * @param state - The serialized keyring state.\n */\n async deserialize(state: Json): Promise<void> {\n await this.withLock(async () => {\n // Clear the registry when deserializing\n this.registry.clear();\n\n // Deserialize the legacy keyring\n await this.inner.deserialize(state);\n\n // Rebuild the registry by calling getAccounts().\n // Subclass implementations of getAccounts() should populate the registry\n // as a side effect (see the abstract method's documentation).\n await this.getAccounts();\n });\n }\n\n /**\n * Return all accounts managed by this keyring.\n *\n * Concrete adapters are responsible for mapping the underlying keyring's\n * notion of accounts (typically addresses returned by\n * {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.\n * Implementations should use the configured {@link KeyringAccountRegistry}\n * to establish the account ID/address mapping so that\n * {@link getAccount} works as expected.\n *\n * @returns The list of managed accounts.\n */\n abstract getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Look up a single account by its {@link AccountId}.\n *\n * This method first checks the registry for O(1) lookup.\n * If not found, it falls back to calling {@link getAccounts} which\n * should populate the registry as a side effect.\n *\n * @param accountId - The AccountId to look up.\n * @returns The matching KeyringAccount.\n */\n async getAccount(accountId: AccountId): Promise<KeyringAccount> {\n let cached = this.registry.get(accountId);\n if (cached) {\n return cached;\n }\n\n // Prime the registry by calling getAccounts\n await this.getAccounts();\n\n // Try registry again after priming\n cached = this.registry.get(accountId);\n if (!cached) {\n throw new Error(`Account not found for id: ${accountId}`);\n }\n\n return cached;\n }\n\n /**\n * Create one or more new accounts managed by this keyring.\n *\n * Implementations are responsible for interpreting the\n * {@link CreateAccountOptions} (for example BIP-44 derivation or\n * private-key import) and returning the resulting {@link KeyringAccount}\n * objects. Implementors should also ensure that the registry is updated so\n * that {@link getAccount} works for newly created accounts.\n */\n abstract createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]>;\n\n /**\n * Remove the account associated with the given {@link AccountId} from this\n * keyring.\n *\n * Implementations are expected to translate the ID to an underlying\n * address (typically via the registry) and then invoke the appropriate\n * removal mechanism on the legacy keyring.\n */\n abstract deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Export the secrets associated with the given account in a format\n * described by {@link ExportAccountOptions}.\n *\n * This method is optional, and concrete adapters should only\n * implement it if the underlying keyring supports exporting\n * accounts.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Handle a high-level {@link KeyringRequest} on behalf of this keyring.\n *\n * Concrete adapters are responsible for routing the request's method and\n * parameters to the appropriate legacy keyring APIs (for example signing\n * transactions or decrypting messages) and returning a JSON-serializable\n * result.\n */\n abstract submitRequest(request: KeyringRequest): Promise<Json>;\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import { type Infer } from "@metamask/superstruct";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const EthUserOperationStruct: import("@metamask/superstruct").Struct<{
|
|
8
8
|
nonce: string;
|
|
9
|
-
sender: string
|
|
9
|
+
sender: `0x${string}`;
|
|
10
10
|
initCode: string;
|
|
11
11
|
callData: string;
|
|
12
12
|
callGasLimit: string;
|
|
@@ -17,7 +17,7 @@ export declare const EthUserOperationStruct: import("@metamask/superstruct").Str
|
|
|
17
17
|
paymasterAndData: string;
|
|
18
18
|
signature: string;
|
|
19
19
|
}, {
|
|
20
|
-
sender: import("@metamask/superstruct").Struct
|
|
20
|
+
sender: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
21
21
|
nonce: import("@metamask/superstruct").Struct<string, null>;
|
|
22
22
|
initCode: import("@metamask/superstruct").Struct<string, null>;
|
|
23
23
|
callData: import("@metamask/superstruct").Struct<string, null>;
|
|
@@ -37,12 +37,12 @@ export type EthUserOperation = Infer<typeof EthUserOperationStruct>;
|
|
|
37
37
|
export declare const EthBaseTransactionStruct: import("@metamask/superstruct").Struct<{
|
|
38
38
|
value: string;
|
|
39
39
|
data: string;
|
|
40
|
-
to: string
|
|
40
|
+
to: `0x${string}`;
|
|
41
41
|
}, {
|
|
42
42
|
/**
|
|
43
43
|
* Address of the transaction recipient.
|
|
44
44
|
*/
|
|
45
|
-
to: import("@metamask/superstruct").Struct
|
|
45
|
+
to: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
46
46
|
/**
|
|
47
47
|
* Amount of wei to transfer to the recipient.
|
|
48
48
|
*/
|
|
@@ -6,7 +6,7 @@ import { type Infer } from "@metamask/superstruct";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const EthUserOperationStruct: import("@metamask/superstruct").Struct<{
|
|
8
8
|
nonce: string;
|
|
9
|
-
sender: string
|
|
9
|
+
sender: `0x${string}`;
|
|
10
10
|
initCode: string;
|
|
11
11
|
callData: string;
|
|
12
12
|
callGasLimit: string;
|
|
@@ -17,7 +17,7 @@ export declare const EthUserOperationStruct: import("@metamask/superstruct").Str
|
|
|
17
17
|
paymasterAndData: string;
|
|
18
18
|
signature: string;
|
|
19
19
|
}, {
|
|
20
|
-
sender: import("@metamask/superstruct").Struct
|
|
20
|
+
sender: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
21
21
|
nonce: import("@metamask/superstruct").Struct<string, null>;
|
|
22
22
|
initCode: import("@metamask/superstruct").Struct<string, null>;
|
|
23
23
|
callData: import("@metamask/superstruct").Struct<string, null>;
|
|
@@ -37,12 +37,12 @@ export type EthUserOperation = Infer<typeof EthUserOperationStruct>;
|
|
|
37
37
|
export declare const EthBaseTransactionStruct: import("@metamask/superstruct").Struct<{
|
|
38
38
|
value: string;
|
|
39
39
|
data: string;
|
|
40
|
-
to: string
|
|
40
|
+
to: `0x${string}`;
|
|
41
41
|
}, {
|
|
42
42
|
/**
|
|
43
43
|
* Address of the transaction recipient.
|
|
44
44
|
*/
|
|
45
|
-
to: import("@metamask/superstruct").Struct
|
|
45
|
+
to: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
46
46
|
/**
|
|
47
47
|
* Amount of wei to transfer to the recipient.
|
|
48
48
|
*/
|
package/dist/eth/index.cjs
CHANGED
|
@@ -16,6 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants.cjs"), exports);
|
|
18
18
|
__exportStar(require("./erc4337/index.cjs"), exports);
|
|
19
|
+
__exportStar(require("./rpc/index.cjs"), exports);
|
|
19
20
|
__exportStar(require("./types.cjs"), exports);
|
|
20
21
|
__exportStar(require("./utils.cjs"), exports);
|
|
22
|
+
__exportStar(require("./v2/index.cjs"), exports);
|
|
21
23
|
//# sourceMappingURL=index.cjs.map
|
package/dist/eth/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA4B;AAC5B,sDAA0B;AAC1B,8CAAwB;AACxB,8CAAwB","sourcesContent":["export * from './constants';\nexport * from './erc4337';\nexport * from './types';\nexport * from './utils';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA4B;AAC5B,sDAA0B;AAC1B,kDAAsB;AACtB,8CAAwB;AACxB,8CAAwB;AACxB,iDAAqB","sourcesContent":["export * from './constants';\nexport * from './erc4337';\nexport * from './rpc';\nexport * from './types';\nexport * from './utils';\nexport * from './v2';\n"]}
|
package/dist/eth/index.d.cts
CHANGED
package/dist/eth/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,oCAA0B;AAC1B,4BAAwB;AACxB,4BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,oCAA0B;AAC1B,gCAAsB;AACtB,4BAAwB;AACxB,4BAAwB;AACxB,+BAAqB"}
|
package/dist/eth/index.d.mts
CHANGED
package/dist/eth/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,oCAA0B;AAC1B,4BAAwB;AACxB,4BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,oCAA0B;AAC1B,gCAAsB;AACtB,4BAAwB;AACxB,4BAAwB;AACxB,+BAAqB"}
|
package/dist/eth/index.mjs
CHANGED
package/dist/eth/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,oCAA0B;AAC1B,4BAAwB;AACxB,4BAAwB","sourcesContent":["export * from './constants';\nexport * from './erc4337';\nexport * from './types';\nexport * from './utils';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,oCAA0B;AAC1B,gCAAsB;AACtB,4BAAwB;AACxB,4BAAwB;AACxB,+BAAqB","sourcesContent":["export * from './constants';\nexport * from './erc4337';\nexport * from './rpc';\nexport * from './types';\nexport * from './utils';\nexport * from './v2';\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("./params.cjs"), exports);
|
|
18
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/eth/rpc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAAyB","sourcesContent":["export * from './params';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/eth/rpc/index.ts"],"names":[],"mappings":"AAAA,6BAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/eth/rpc/index.ts"],"names":[],"mappings":"AAAA,6BAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/eth/rpc/index.ts"],"names":[],"mappings":"AAAA,6BAAyB","sourcesContent":["export * from './params';\n"]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Superstruct validation schemas for Ethereum JSON-RPC method parameters.
|
|
4
|
+
*
|
|
5
|
+
* These structs provide runtime validation for the parameters passed to various
|
|
6
|
+
* Ethereum RPC methods. They can be used by keyring implementations to validate
|
|
7
|
+
* incoming requests before processing.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EthGetEncryptionPublicKeyParamsStruct = exports.EthSignEip7702AuthorizationParamsStruct = exports.EthGetAppKeyAddressParamsStruct = exports.EthDecryptParamsStruct = exports.EthSignTypedDataParamsStruct = exports.EthSignTypedDataV1ParamsStruct = exports.EthPersonalSignParamsStruct = exports.EthSignParamsStruct = exports.EthSignTransactionParamsStruct = exports.EthGetEncryptionPublicKeyOptionsStruct = exports.EthEip7702AuthorizationStruct = exports.EthEncryptedDataStruct = exports.EthTypedMessageStruct = exports.EthTypedDataTypesStruct = exports.EthTypedDataV1Struct = exports.EthTransactionDataStruct = void 0;
|
|
11
|
+
const keyring_utils_1 = require("@metamask/keyring-utils");
|
|
12
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
13
|
+
const types_1 = require("../types.cjs");
|
|
14
|
+
/**
|
|
15
|
+
* A struct for validating Ethereum transaction data.
|
|
16
|
+
*
|
|
17
|
+
* This uses `type()` instead of `object()` to allow extra properties,
|
|
18
|
+
* since transaction formats can vary and include additional fields.
|
|
19
|
+
* The actual transaction validation is performed by the transaction library.
|
|
20
|
+
*/
|
|
21
|
+
exports.EthTransactionDataStruct = (0, superstruct_1.type)({
|
|
22
|
+
to: (0, superstruct_1.optional)((0, superstruct_1.nullable)(types_1.EthAddressStruct)),
|
|
23
|
+
from: (0, superstruct_1.optional)(types_1.EthAddressStruct),
|
|
24
|
+
nonce: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
25
|
+
value: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
26
|
+
data: (0, superstruct_1.optional)(types_1.EthBytesStruct),
|
|
27
|
+
gas: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
28
|
+
gasLimit: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
29
|
+
gasPrice: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
30
|
+
maxFeePerGas: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
31
|
+
maxPriorityFeePerGas: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
32
|
+
accessList: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.type)({
|
|
33
|
+
address: types_1.EthAddressStruct,
|
|
34
|
+
storageKeys: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
35
|
+
}))),
|
|
36
|
+
type: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
37
|
+
chainId: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* A struct for TypedDataV1 format (legacy typed data).
|
|
41
|
+
* This is an array of { type, name, value } objects.
|
|
42
|
+
*/
|
|
43
|
+
exports.EthTypedDataV1Struct = (0, superstruct_1.array)((0, keyring_utils_1.object)({
|
|
44
|
+
type: (0, superstruct_1.string)(),
|
|
45
|
+
name: (0, superstruct_1.string)(),
|
|
46
|
+
value: (0, superstruct_1.unknown)(),
|
|
47
|
+
}));
|
|
48
|
+
/**
|
|
49
|
+
* A struct for TypedData types definition.
|
|
50
|
+
* Maps type names to arrays of { name, type } definitions.
|
|
51
|
+
*/
|
|
52
|
+
exports.EthTypedDataTypesStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.array)((0, keyring_utils_1.object)({
|
|
53
|
+
name: (0, superstruct_1.string)(),
|
|
54
|
+
type: (0, superstruct_1.string)(),
|
|
55
|
+
})));
|
|
56
|
+
/**
|
|
57
|
+
* A struct for TypedMessage format (EIP-712 V3/V4).
|
|
58
|
+
* Contains types, domain, primaryType, and message.
|
|
59
|
+
*/
|
|
60
|
+
exports.EthTypedMessageStruct = (0, keyring_utils_1.object)({
|
|
61
|
+
types: exports.EthTypedDataTypesStruct,
|
|
62
|
+
primaryType: (0, superstruct_1.string)(),
|
|
63
|
+
domain: (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.any)()),
|
|
64
|
+
message: (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.any)()),
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* A struct for EIP-1024 encrypted data format (x25519-xsalsa20-poly1305).
|
|
68
|
+
*/
|
|
69
|
+
exports.EthEncryptedDataStruct = (0, keyring_utils_1.object)({
|
|
70
|
+
version: (0, superstruct_1.literal)('x25519-xsalsa20-poly1305'),
|
|
71
|
+
nonce: (0, superstruct_1.string)(),
|
|
72
|
+
ephemPublicKey: (0, superstruct_1.string)(),
|
|
73
|
+
ciphertext: (0, superstruct_1.string)(),
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* A struct for EIP-7702 authorization tuple.
|
|
77
|
+
* Format: [chainId, address, nonce]
|
|
78
|
+
*/
|
|
79
|
+
exports.EthEip7702AuthorizationStruct = (0, superstruct_1.tuple)([
|
|
80
|
+
(0, superstruct_1.number)(), // chainId
|
|
81
|
+
types_1.EthAddressStruct, // address (contract to delegate to)
|
|
82
|
+
(0, superstruct_1.number)(), // nonce
|
|
83
|
+
]);
|
|
84
|
+
/**
|
|
85
|
+
* A struct for getEncryptionPublicKey options.
|
|
86
|
+
*/
|
|
87
|
+
exports.EthGetEncryptionPublicKeyOptionsStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.unknown)());
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// RPC Method Parameter Structs
|
|
90
|
+
// ============================================================================
|
|
91
|
+
/**
|
|
92
|
+
* Parameters for `eth_signTransaction`.
|
|
93
|
+
*/
|
|
94
|
+
exports.EthSignTransactionParamsStruct = (0, superstruct_1.tuple)([exports.EthTransactionDataStruct]);
|
|
95
|
+
/**
|
|
96
|
+
* Parameters for `eth_sign`.
|
|
97
|
+
*/
|
|
98
|
+
exports.EthSignParamsStruct = (0, superstruct_1.tuple)([
|
|
99
|
+
types_1.EthAddressStruct, // address
|
|
100
|
+
types_1.EthBytesStruct, // data (hex-encoded message hash)
|
|
101
|
+
]);
|
|
102
|
+
/**
|
|
103
|
+
* Parameters for `personal_sign`.
|
|
104
|
+
*/
|
|
105
|
+
exports.EthPersonalSignParamsStruct = (0, superstruct_1.union)([
|
|
106
|
+
(0, superstruct_1.tuple)([types_1.EthBytesStruct]), // [data]
|
|
107
|
+
(0, superstruct_1.tuple)([types_1.EthBytesStruct, types_1.EthAddressStruct]), // [data, address]
|
|
108
|
+
]);
|
|
109
|
+
/**
|
|
110
|
+
* Parameters for `eth_signTypedData_v1`.
|
|
111
|
+
*/
|
|
112
|
+
exports.EthSignTypedDataV1ParamsStruct = (0, superstruct_1.tuple)([
|
|
113
|
+
types_1.EthAddressStruct, // address
|
|
114
|
+
exports.EthTypedDataV1Struct, // typed data array
|
|
115
|
+
]);
|
|
116
|
+
/**
|
|
117
|
+
* Parameters for `eth_signTypedData_v3` and `eth_signTypedData_v4`.
|
|
118
|
+
*/
|
|
119
|
+
exports.EthSignTypedDataParamsStruct = (0, superstruct_1.tuple)([
|
|
120
|
+
types_1.EthAddressStruct, // address
|
|
121
|
+
exports.EthTypedMessageStruct, // typed data object
|
|
122
|
+
]);
|
|
123
|
+
/**
|
|
124
|
+
* Parameters for `eth_decrypt`.
|
|
125
|
+
*/
|
|
126
|
+
exports.EthDecryptParamsStruct = (0, superstruct_1.tuple)([exports.EthEncryptedDataStruct]);
|
|
127
|
+
/**
|
|
128
|
+
* Parameters for `eth_getAppKeyAddress`.
|
|
129
|
+
*/
|
|
130
|
+
exports.EthGetAppKeyAddressParamsStruct = (0, superstruct_1.tuple)([
|
|
131
|
+
(0, superstruct_1.string)(), // origin URL
|
|
132
|
+
]);
|
|
133
|
+
/**
|
|
134
|
+
* Parameters for `eth_signEip7702Authorization`.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const params = [[1, '0xContractAddress', 0]];
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
exports.EthSignEip7702AuthorizationParamsStruct = (0, superstruct_1.tuple)([
|
|
142
|
+
exports.EthEip7702AuthorizationStruct,
|
|
143
|
+
]);
|
|
144
|
+
/**
|
|
145
|
+
* Parameters for `eth_getEncryptionPublicKey`.
|
|
146
|
+
*/
|
|
147
|
+
exports.EthGetEncryptionPublicKeyParamsStruct = (0, superstruct_1.tuple)([
|
|
148
|
+
types_1.EthAddressStruct, // address
|
|
149
|
+
(0, superstruct_1.optional)(exports.EthGetEncryptionPublicKeyOptionsStruct), // options
|
|
150
|
+
]);
|
|
151
|
+
//# sourceMappingURL=params.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.cjs","sourceRoot":"","sources":["../../../src/eth/rpc/params.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Superstruct validation schemas for Ethereum JSON-RPC method parameters.\n *\n * These structs provide runtime validation for the parameters passed to various\n * Ethereum RPC methods. They can be used by keyring implementations to validate\n * incoming requests before processing.\n */\n\nimport { object } from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n any,\n array,\n literal,\n nullable,\n number,\n optional,\n record,\n string,\n tuple,\n type,\n union,\n unknown,\n} from '@metamask/superstruct';\n\nimport { EthAddressStruct, EthBytesStruct } from '../types';\n\n/**\n * A struct for validating Ethereum transaction data.\n *\n * This uses `type()` instead of `object()` to allow extra properties,\n * since transaction formats can vary and include additional fields.\n * The actual transaction validation is performed by the transaction library.\n */\nexport const EthTransactionDataStruct = type({\n to: optional(nullable(EthAddressStruct)),\n from: optional(EthAddressStruct),\n nonce: optional(union([string(), number()])),\n value: optional(union([string(), number()])),\n data: optional(EthBytesStruct),\n gas: optional(union([string(), number()])),\n gasLimit: optional(union([string(), number()])),\n gasPrice: optional(union([string(), number()])),\n maxFeePerGas: optional(union([string(), number()])),\n maxPriorityFeePerGas: optional(union([string(), number()])),\n accessList: optional(\n array(\n type({\n address: EthAddressStruct,\n storageKeys: array(string()),\n }),\n ),\n ),\n type: optional(union([string(), number()])),\n chainId: optional(union([string(), number()])),\n});\n\nexport type EthTransactionData = Infer<typeof EthTransactionDataStruct>;\n\n/**\n * A struct for TypedDataV1 format (legacy typed data).\n * This is an array of { type, name, value } objects.\n */\nexport const EthTypedDataV1Struct = array(\n object({\n type: string(),\n name: string(),\n value: unknown(),\n }),\n);\n\nexport type EthTypedDataV1 = Infer<typeof EthTypedDataV1Struct>;\n\n/**\n * A struct for TypedData types definition.\n * Maps type names to arrays of { name, type } definitions.\n */\nexport const EthTypedDataTypesStruct = record(\n string(),\n array(\n object({\n name: string(),\n type: string(),\n }),\n ),\n);\n\nexport type EthTypedDataTypes = Infer<typeof EthTypedDataTypesStruct>;\n\n/**\n * A struct for TypedMessage format (EIP-712 V3/V4).\n * Contains types, domain, primaryType, and message.\n */\nexport const EthTypedMessageStruct = object({\n types: EthTypedDataTypesStruct,\n primaryType: string(),\n domain: record(string(), any()),\n message: record(string(), any()),\n});\n\nexport type EthTypedMessage = Infer<typeof EthTypedMessageStruct>;\n\n/**\n * A struct for EIP-1024 encrypted data format (x25519-xsalsa20-poly1305).\n */\nexport const EthEncryptedDataStruct = object({\n version: literal('x25519-xsalsa20-poly1305'),\n nonce: string(),\n ephemPublicKey: string(),\n ciphertext: string(),\n});\n\nexport type EthEncryptedData = Infer<typeof EthEncryptedDataStruct>;\n\n/**\n * A struct for EIP-7702 authorization tuple.\n * Format: [chainId, address, nonce]\n */\nexport const EthEip7702AuthorizationStruct = tuple([\n number(), // chainId\n EthAddressStruct, // address (contract to delegate to)\n number(), // nonce\n]);\n\nexport type EthEip7702Authorization = Infer<\n typeof EthEip7702AuthorizationStruct\n>;\n\n/**\n * A struct for getEncryptionPublicKey options.\n */\nexport const EthGetEncryptionPublicKeyOptionsStruct = record(\n string(),\n unknown(),\n);\n\n// ============================================================================\n// RPC Method Parameter Structs\n// ============================================================================\n\n/**\n * Parameters for `eth_signTransaction`.\n */\nexport const EthSignTransactionParamsStruct = tuple([EthTransactionDataStruct]);\n\nexport type EthSignTransactionParams = Infer<\n typeof EthSignTransactionParamsStruct\n>;\n\n/**\n * Parameters for `eth_sign`.\n */\nexport const EthSignParamsStruct = tuple([\n EthAddressStruct, // address\n EthBytesStruct, // data (hex-encoded message hash)\n]);\n\nexport type EthSignParams = Infer<typeof EthSignParamsStruct>;\n\n/**\n * Parameters for `personal_sign`.\n */\nexport const EthPersonalSignParamsStruct = union([\n tuple([EthBytesStruct]), // [data]\n tuple([EthBytesStruct, EthAddressStruct]), // [data, address]\n]);\n\nexport type EthPersonalSignParams = Infer<typeof EthPersonalSignParamsStruct>;\n\n/**\n * Parameters for `eth_signTypedData_v1`.\n */\nexport const EthSignTypedDataV1ParamsStruct = tuple([\n EthAddressStruct, // address\n EthTypedDataV1Struct, // typed data array\n]);\n\nexport type EthSignTypedDataV1Params = Infer<\n typeof EthSignTypedDataV1ParamsStruct\n>;\n\n/**\n * Parameters for `eth_signTypedData_v3` and `eth_signTypedData_v4`.\n */\nexport const EthSignTypedDataParamsStruct = tuple([\n EthAddressStruct, // address\n EthTypedMessageStruct, // typed data object\n]);\n\nexport type EthSignTypedDataParams = Infer<typeof EthSignTypedDataParamsStruct>;\n\n/**\n * Parameters for `eth_decrypt`.\n */\nexport const EthDecryptParamsStruct = tuple([EthEncryptedDataStruct]);\n\nexport type EthDecryptParams = Infer<typeof EthDecryptParamsStruct>;\n\n/**\n * Parameters for `eth_getAppKeyAddress`.\n */\nexport const EthGetAppKeyAddressParamsStruct = tuple([\n string(), // origin URL\n]);\n\nexport type EthGetAppKeyAddressParams = Infer<\n typeof EthGetAppKeyAddressParamsStruct\n>;\n\n/**\n * Parameters for `eth_signEip7702Authorization`.\n *\n * @example\n * ```ts\n * const params = [[1, '0xContractAddress', 0]];\n * ```\n */\nexport const EthSignEip7702AuthorizationParamsStruct = tuple([\n EthEip7702AuthorizationStruct,\n]);\n\nexport type EthSignEip7702AuthorizationParams = Infer<\n typeof EthSignEip7702AuthorizationParamsStruct\n>;\n\n/**\n * Parameters for `eth_getEncryptionPublicKey`.\n */\nexport const EthGetEncryptionPublicKeyParamsStruct = tuple([\n EthAddressStruct, // address\n optional(EthGetEncryptionPublicKeyOptionsStruct), // options\n]);\n"]}
|