@metamask/smart-accounts-kit 1.1.0 → 1.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 +11 -1
- package/README.md +34 -2
- package/dist/actions/index.cjs +5 -5
- package/dist/actions/index.mjs +4 -4
- package/dist/{smartAccountsEnvironment-BIcho7e0.d.cts → caveats-CQbtzOKm.d.ts} +9 -2
- package/dist/{smartAccountsEnvironment-Bso0CIWt.d.ts → caveats-Cey0wm33.d.cts} +9 -2
- package/dist/{chunk-UUOH2WAW.cjs → chunk-3SHZ7PV2.cjs} +12 -12
- package/dist/{chunk-UUOH2WAW.cjs.map → chunk-3SHZ7PV2.cjs.map} +1 -1
- package/dist/{chunk-TPBFVDVM.mjs → chunk-4QXIOE7F.mjs} +8 -6
- package/dist/chunk-4QXIOE7F.mjs.map +1 -0
- package/dist/{chunk-NOCLGZGB.mjs → chunk-734MOPHR.mjs} +63 -5
- package/dist/chunk-734MOPHR.mjs.map +1 -0
- package/dist/{chunk-YDLLC6PP.cjs → chunk-7BEEGBA2.cjs} +519 -16
- package/dist/chunk-7BEEGBA2.cjs.map +1 -0
- package/dist/{chunk-45GHWVQA.mjs → chunk-G7VZ7E6W.mjs} +4 -4
- package/dist/{chunk-F2RG26RH.cjs → chunk-HFRQNSZE.cjs} +105 -105
- package/dist/{chunk-F2RG26RH.cjs.map → chunk-HFRQNSZE.cjs.map} +1 -1
- package/dist/{chunk-YSBBRLMT.mjs → chunk-L5DLMBDC.mjs} +5 -5
- package/dist/{chunk-VLKX4BR6.cjs → chunk-MOHCTPYQ.cjs} +8 -6
- package/dist/chunk-MOHCTPYQ.cjs.map +1 -0
- package/dist/{chunk-QMRKCB7T.cjs → chunk-T4IAMAB2.cjs} +102 -44
- package/dist/chunk-T4IAMAB2.cjs.map +1 -0
- package/dist/{chunk-BYWRJGSK.cjs → chunk-UB2FLPP3.cjs} +16 -16
- package/dist/{chunk-BYWRJGSK.cjs.map → chunk-UB2FLPP3.cjs.map} +1 -1
- package/dist/{chunk-23YXLKTX.cjs → chunk-UZO5OYCD.cjs} +14 -14
- package/dist/{chunk-23YXLKTX.cjs.map → chunk-UZO5OYCD.cjs.map} +1 -1
- package/dist/{chunk-YTELOQ4I.mjs → chunk-VJXM3LWA.mjs} +2 -2
- package/dist/{chunk-WV2R7BXP.mjs → chunk-YTNCEXUX.mjs} +3 -3
- package/dist/{chunk-C5ZEEH2Z.mjs → chunk-ZA2XYCVX.mjs} +517 -14
- package/dist/chunk-ZA2XYCVX.mjs.map +1 -0
- package/dist/contracts/index.cjs +6 -6
- package/dist/contracts/index.d.cts +2 -2
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.mjs +5 -5
- package/dist/{delegation-DgmIOh21.d.ts → delegation-Bx4FEAIU.d.ts} +1 -1
- package/dist/{delegation-Ci3me5Rg.d.cts → delegation-KbWHzRxV.d.cts} +1 -1
- package/dist/experimental/index.cjs +36 -4
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/index.d.cts +4 -1
- package/dist/experimental/index.d.ts +4 -1
- package/dist/experimental/index.mjs +35 -3
- package/dist/experimental/index.mjs.map +1 -1
- package/dist/{index-UF6eCzBC.d.ts → index-D2THBlfm.d.ts} +1 -1
- package/dist/{index-CSjEW7MJ.d.cts → index-DE87r5KY.d.cts} +1 -1
- package/dist/index.cjs +33 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -9
- package/dist/index.d.ts +7 -9
- package/dist/index.mjs +24 -8
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.cjs +7 -5
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.mjs +6 -4
- package/package.json +5 -4
- package/dist/chunk-C5ZEEH2Z.mjs.map +0 -1
- package/dist/chunk-NOCLGZGB.mjs.map +0 -1
- package/dist/chunk-QMRKCB7T.cjs.map +0 -1
- package/dist/chunk-TPBFVDVM.mjs.map +0 -1
- package/dist/chunk-VLKX4BR6.cjs.map +0 -1
- package/dist/chunk-YDLLC6PP.cjs.map +0 -1
- /package/dist/{chunk-45GHWVQA.mjs.map → chunk-G7VZ7E6W.mjs.map} +0 -0
- /package/dist/{chunk-YSBBRLMT.mjs.map → chunk-L5DLMBDC.mjs.map} +0 -0
- /package/dist/{chunk-YTELOQ4I.mjs.map → chunk-VJXM3LWA.mjs.map} +0 -0
- /package/dist/{chunk-WV2R7BXP.mjs.map → chunk-YTNCEXUX.mjs.map} +0 -0
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
var _chunk7BEEGBA2cjs = require('../chunk-7BEEGBA2.cjs');
|
|
4
5
|
|
|
5
6
|
// src/experimental/delegationStorage.ts
|
|
6
7
|
var _viem = require('viem');
|
|
8
|
+
var DelegationStorageEnvironment = {
|
|
9
|
+
dev: { apiUrl: "https://passkeys.dev-api.cx.metamask.io" },
|
|
10
|
+
prod: { apiUrl: "https://passkeys.api.cx.metamask.io" }
|
|
11
|
+
};
|
|
12
|
+
function getDelegationStorageEnvironment(apiUrl) {
|
|
13
|
+
const matchingEnvironment = Object.entries(DelegationStorageEnvironment).find(
|
|
14
|
+
([_, env]) => env.apiUrl === apiUrl
|
|
15
|
+
);
|
|
16
|
+
return matchingEnvironment ? matchingEnvironment[0] : "custom";
|
|
17
|
+
}
|
|
7
18
|
var DelegationStorageClient = class {
|
|
8
19
|
#apiVersionPrefix = "api/v0";
|
|
9
20
|
#config;
|
|
@@ -11,6 +22,12 @@ var DelegationStorageClient = class {
|
|
|
11
22
|
#apiUrl;
|
|
12
23
|
constructor(config) {
|
|
13
24
|
const { apiUrl } = config.environment;
|
|
25
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
26
|
+
"experimental.DelegationStorageClient.constructor",
|
|
27
|
+
{
|
|
28
|
+
environment: getDelegationStorageEnvironment(apiUrl)
|
|
29
|
+
}
|
|
30
|
+
);
|
|
14
31
|
if (apiUrl.endsWith(this.#apiVersionPrefix)) {
|
|
15
32
|
this.#apiUrl = apiUrl;
|
|
16
33
|
} else {
|
|
@@ -51,7 +68,13 @@ var DelegationStorageClient = class {
|
|
|
51
68
|
* is not found.
|
|
52
69
|
*/
|
|
53
70
|
async getDelegationChain(leafDelegationOrDelegationHash) {
|
|
54
|
-
|
|
71
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
72
|
+
"experimental.DelegationStorageClient.getDelegationChain",
|
|
73
|
+
{
|
|
74
|
+
inputKind: typeof leafDelegationOrDelegationHash === "string" ? "hash" : "delegation"
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
const leafDelegationHash = typeof leafDelegationOrDelegationHash === "string" ? leafDelegationOrDelegationHash : _chunk7BEEGBA2cjs.hashDelegation.call(void 0, leafDelegationOrDelegationHash);
|
|
55
78
|
const response = await this.#fetcher(
|
|
56
79
|
`${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,
|
|
57
80
|
{
|
|
@@ -81,6 +104,10 @@ var DelegationStorageClient = class {
|
|
|
81
104
|
* empty array if the delegations are not found.
|
|
82
105
|
*/
|
|
83
106
|
async fetchDelegations(deleGatorAddress, filterMode = "RECEIVED" /* Received */) {
|
|
107
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
108
|
+
"experimental.DelegationStorageClient.fetchDelegations",
|
|
109
|
+
{ filterMode }
|
|
110
|
+
);
|
|
84
111
|
const response = await this.#fetcher(
|
|
85
112
|
`${this.#apiUrl}/delegation/accounts/${deleGatorAddress}?filter=${filterMode}`,
|
|
86
113
|
{
|
|
@@ -104,10 +131,14 @@ var DelegationStorageClient = class {
|
|
|
104
131
|
* @returns A promise that resolves to the delegation hash indicating successful storage.
|
|
105
132
|
*/
|
|
106
133
|
async storeDelegation(delegation) {
|
|
134
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
135
|
+
"experimental.DelegationStorageClient.storeDelegation",
|
|
136
|
+
{ caveatCount: delegation.caveats.length }
|
|
137
|
+
);
|
|
107
138
|
if (!delegation.signature || delegation.signature === "0x") {
|
|
108
139
|
throw new Error("Delegation must be signed to be stored");
|
|
109
140
|
}
|
|
110
|
-
const delegationHash =
|
|
141
|
+
const delegationHash = _chunk7BEEGBA2cjs.hashDelegation.call(void 0, delegation);
|
|
111
142
|
const body = JSON.stringify(
|
|
112
143
|
{
|
|
113
144
|
...delegation,
|
|
@@ -139,5 +170,6 @@ var DelegationStorageClient = class {
|
|
|
139
170
|
};
|
|
140
171
|
|
|
141
172
|
|
|
142
|
-
|
|
173
|
+
|
|
174
|
+
exports.DelegationStorageClient = DelegationStorageClient; exports.DelegationStorageEnvironment = DelegationStorageEnvironment;
|
|
143
175
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/experimental/index.cjs","../../src/experimental/delegationStorage.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACA;ACJA,4BAAgC;AA6CzB,IAAM,wBAAA,EAAN,MAA8B;AAAA,EAC1B,CAAA,iBAAA,EAAoB,QAAA;AAAA,EAEpB,CAAA,MAAA;AAAA,EAEA,CAAA,OAAA;AAAA,EAEA,CAA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AClB,IAAA;AAEM,IAAA;AAEY,IAAA;AAChB,MAAA;AACK,QAAA;AACQ,QAAA;AACb,MAAA;AAEE,MAAA;AAGF,MAAA;AACF,IAAA;AAEiB,IAAA;AACP,MAAA;AACC,MAAA;AACP,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACA,MAAA;AACD,IAAA;AAEK,IAAA;AAGS,IAAA;AACG,MAAA;AAClB,IAAA;AAEiB,IAAA;AACL,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AACF;ADzEsB;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/experimental/index.cjs","sourcesContent":[null,"import { type Hex, toHex } from 'viem';\n\nimport { hashDelegation } from '../delegation';\nimport type { Delegation } from '../types';\n\ntype ErrorResponse = {\n error: string;\n data?: any;\n};\n\nexport type APIStoreDelegationResponse = {\n delegationHash: Hex;\n};\n\n/**\n * Represents the allowed filters when querying the data store for delegations.\n */\nexport enum DelegationStoreFilter {\n Given = 'GIVEN',\n Received = 'RECEIVED',\n All = 'ALL',\n}\n\n/**\n * Public Delegation Storage Service environments. To be used in the\n * DeleGationStorageService config.\n */\nexport const DelegationStorageEnvironment: {\n [K in 'dev' | 'prod']: Environment;\n} = {\n dev: { apiUrl: 'https://passkeys.dev-api.cx.metamask.io' },\n prod: { apiUrl: 'https://passkeys.api.cx.metamask.io' },\n};\n\nexport type Environment = {\n apiUrl: string;\n};\n\nexport type DelegationStorageConfig = {\n apiKey: string;\n apiKeyId: string;\n environment: Environment;\n fetcher?: typeof fetch;\n};\n\nexport class DelegationStorageClient {\n readonly #apiVersionPrefix = 'api/v0';\n\n readonly #config: DelegationStorageConfig;\n\n readonly #fetcher: typeof fetch;\n\n readonly #apiUrl: string;\n\n constructor(config: DelegationStorageConfig) {\n const { apiUrl } = config.environment;\n\n if (apiUrl.endsWith(this.#apiVersionPrefix)) {\n this.#apiUrl = apiUrl;\n } else {\n const separator = apiUrl.endsWith('/') ? '' : '/';\n this.#apiUrl = `${apiUrl}${separator}${this.#apiVersionPrefix}`;\n }\n this.#fetcher = this.#initializeFetcher(config);\n this.#config = config;\n }\n\n /**\n * Initializes the fetch function for HTTP requests.\n *\n * - Uses `config.fetcher` if provided.\n * - Falls back to global `fetch` if available.\n * - Throws an error if no fetch function is available.\n *\n * @param config - Configuration object that may include a custom fetch function.\n * @returns The fetch function to be used for HTTP requests.\n * @throws Error if no fetch function is available in the environment.\n */\n #initializeFetcher(config: DelegationStorageConfig): typeof fetch {\n if (config.fetcher) {\n return config.fetcher;\n } else if (typeof globalThis?.fetch === 'function') {\n return globalThis.fetch.bind(globalThis);\n }\n throw new Error(\n 'Fetch API is not available in this environment. Please provide a fetch function in the config.',\n );\n }\n\n /**\n * Fetches the delegation chain from the Delegation Storage Service, ending with\n * the specified leaf delegation.\n *\n * @param leafDelegationOrDelegationHash - The leaf delegation, or the hash\n * of the leaf delegation.\n * @returns A promise that resolves to the delegation chain - empty array if the delegation\n * is not found.\n */\n async getDelegationChain(\n leafDelegationOrDelegationHash: Hex | Delegation,\n ): Promise<Delegation[]> {\n const leafDelegationHash =\n typeof leafDelegationOrDelegationHash === 'string'\n ? leafDelegationOrDelegationHash\n : hashDelegation(leafDelegationOrDelegationHash);\n\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(\n `Failed to fetch delegation chain: ${responseData.error}`,\n );\n }\n\n return responseData;\n }\n\n /**\n * Fetches the delegations from the Delegation Storage Service, either `Received`\n * by, or `Given` by, (or both: `All`) the specified deleGatorAddress. Defaults\n * to `Received`.\n *\n * @param deleGatorAddress - The deleGatorAddress to retrieve the delegations for.\n * @param filterMode - The DelegationStoreFilter mode - defaults to Received.\n * @returns A promise that resolves to the list of delegations received by the deleGatorAddress,\n * empty array if the delegations are not found.\n */\n async fetchDelegations(\n deleGatorAddress: Hex,\n filterMode = DelegationStoreFilter.Received,\n ): Promise<Delegation[]> {\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/accounts/${deleGatorAddress}?filter=${filterMode}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(`Failed to fetch delegations: ${responseData.error}`);\n }\n\n return responseData;\n }\n\n /**\n * Stores the specified delegation in the Delegation Storage Service.\n *\n * @param delegation - The delegation to store.\n * @returns A promise that resolves to the delegation hash indicating successful storage.\n */\n async storeDelegation(delegation: Delegation): Promise<Hex> {\n if (!delegation.signature || delegation.signature === '0x') {\n throw new Error('Delegation must be signed to be stored');\n }\n\n const delegationHash = hashDelegation(delegation);\n\n const body = JSON.stringify(\n {\n ...delegation,\n metadata: [],\n },\n (_, value: any) =>\n typeof value === 'bigint' || typeof value === 'number'\n ? toHex(value)\n : value,\n 2,\n );\n\n const response = await this.#fetcher(`${this.#apiUrl}/delegation/store`, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n 'Content-Type': 'application/json',\n },\n body,\n });\n\n const responseData: APIStoreDelegationResponse | ErrorResponse =\n await response.json();\n\n if ('error' in responseData) {\n throw new Error(responseData.error);\n }\n\n if (responseData.delegationHash !== delegationHash) {\n throw new Error(\n 'Failed to store the Delegation, the hash returned from the MM delegation storage API does not match the hash of the delegation',\n );\n }\n\n return responseData.delegationHash;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/experimental/index.cjs","../../src/experimental/delegationStorage.ts"],"names":[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F,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AACF;ADpFsB;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/experimental/index.cjs","sourcesContent":[null,"import { type Hex, toHex } from 'viem';\n\nimport { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport { hashDelegation } from '../delegation';\nimport type { Delegation } from '../types';\n\ntype ErrorResponse = {\n error: string;\n data?: any;\n};\n\nexport type APIStoreDelegationResponse = {\n delegationHash: Hex;\n};\n\n/**\n * Represents the allowed filters when querying the data store for delegations.\n */\nexport enum DelegationStoreFilter {\n Given = 'GIVEN',\n Received = 'RECEIVED',\n All = 'ALL',\n}\n\n/**\n * Public Delegation Storage Service environments. To be used in the\n * DeleGationStorageService config.\n */\nexport const DelegationStorageEnvironment: {\n [K in 'dev' | 'prod']: Environment;\n} = {\n dev: { apiUrl: 'https://passkeys.dev-api.cx.metamask.io' },\n prod: { apiUrl: 'https://passkeys.api.cx.metamask.io' },\n};\n\n/**\n * Returns the DelegationStorageEnvironment ('dev' or 'prod') for a given apiUrl,\n * or 'custom' if the apiUrl does not match a known environment.\n *\n * @param apiUrl - The API URL to check.\n * @returns The environment key ('dev' or 'prod'), or 'custom'.\n */\nfunction getDelegationStorageEnvironment(\n apiUrl: string,\n): 'dev' | 'prod' | 'custom' {\n const matchingEnvironment = Object.entries(DelegationStorageEnvironment).find(\n ([_, env]) => env.apiUrl === apiUrl,\n ) as [keyof typeof DelegationStorageEnvironment, Environment] | undefined;\n\n return matchingEnvironment ? matchingEnvironment[0] : 'custom';\n}\n\nexport type Environment = {\n apiUrl: string;\n};\n\nexport type DelegationStorageConfig = {\n apiKey: string;\n apiKeyId: string;\n environment: Environment;\n fetcher?: typeof fetch;\n};\n\nexport class DelegationStorageClient {\n readonly #apiVersionPrefix = 'api/v0';\n\n readonly #config: DelegationStorageConfig;\n\n readonly #fetcher: typeof fetch;\n\n readonly #apiUrl: string;\n\n constructor(config: DelegationStorageConfig) {\n const { apiUrl } = config.environment;\n\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.constructor',\n {\n environment: getDelegationStorageEnvironment(apiUrl),\n },\n );\n\n if (apiUrl.endsWith(this.#apiVersionPrefix)) {\n this.#apiUrl = apiUrl;\n } else {\n const separator = apiUrl.endsWith('/') ? '' : '/';\n this.#apiUrl = `${apiUrl}${separator}${this.#apiVersionPrefix}`;\n }\n this.#fetcher = this.#initializeFetcher(config);\n this.#config = config;\n }\n\n /**\n * Initializes the fetch function for HTTP requests.\n *\n * - Uses `config.fetcher` if provided.\n * - Falls back to global `fetch` if available.\n * - Throws an error if no fetch function is available.\n *\n * @param config - Configuration object that may include a custom fetch function.\n * @returns The fetch function to be used for HTTP requests.\n * @throws Error if no fetch function is available in the environment.\n */\n #initializeFetcher(config: DelegationStorageConfig): typeof fetch {\n if (config.fetcher) {\n return config.fetcher;\n } else if (typeof globalThis?.fetch === 'function') {\n return globalThis.fetch.bind(globalThis);\n }\n throw new Error(\n 'Fetch API is not available in this environment. Please provide a fetch function in the config.',\n );\n }\n\n /**\n * Fetches the delegation chain from the Delegation Storage Service, ending with\n * the specified leaf delegation.\n *\n * @param leafDelegationOrDelegationHash - The leaf delegation, or the hash\n * of the leaf delegation.\n * @returns A promise that resolves to the delegation chain - empty array if the delegation\n * is not found.\n */\n async getDelegationChain(\n leafDelegationOrDelegationHash: Hex | Delegation,\n ): Promise<Delegation[]> {\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.getDelegationChain',\n {\n inputKind:\n typeof leafDelegationOrDelegationHash === 'string'\n ? 'hash'\n : 'delegation',\n },\n );\n const leafDelegationHash =\n typeof leafDelegationOrDelegationHash === 'string'\n ? leafDelegationOrDelegationHash\n : hashDelegation(leafDelegationOrDelegationHash);\n\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(\n `Failed to fetch delegation chain: ${responseData.error}`,\n );\n }\n\n return responseData;\n }\n\n /**\n * Fetches the delegations from the Delegation Storage Service, either `Received`\n * by, or `Given` by, (or both: `All`) the specified deleGatorAddress. Defaults\n * to `Received`.\n *\n * @param deleGatorAddress - The deleGatorAddress to retrieve the delegations for.\n * @param filterMode - The DelegationStoreFilter mode - defaults to Received.\n * @returns A promise that resolves to the list of delegations received by the deleGatorAddress,\n * empty array if the delegations are not found.\n */\n async fetchDelegations(\n deleGatorAddress: Hex,\n filterMode = DelegationStoreFilter.Received,\n ): Promise<Delegation[]> {\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.fetchDelegations',\n { filterMode },\n );\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/accounts/${deleGatorAddress}?filter=${filterMode}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(`Failed to fetch delegations: ${responseData.error}`);\n }\n\n return responseData;\n }\n\n /**\n * Stores the specified delegation in the Delegation Storage Service.\n *\n * @param delegation - The delegation to store.\n * @returns A promise that resolves to the delegation hash indicating successful storage.\n */\n async storeDelegation(delegation: Delegation): Promise<Hex> {\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.storeDelegation',\n { caveatCount: delegation.caveats.length },\n );\n if (!delegation.signature || delegation.signature === '0x') {\n throw new Error('Delegation must be signed to be stored');\n }\n\n const delegationHash = hashDelegation(delegation);\n\n const body = JSON.stringify(\n {\n ...delegation,\n metadata: [],\n },\n (_, value: any) =>\n typeof value === 'bigint' || typeof value === 'number'\n ? toHex(value)\n : value,\n 2,\n );\n\n const response = await this.#fetcher(`${this.#apiUrl}/delegation/store`, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n 'Content-Type': 'application/json',\n },\n body,\n });\n\n const responseData: APIStoreDelegationResponse | ErrorResponse =\n await response.json();\n\n if ('error' in responseData) {\n throw new Error(responseData.error);\n }\n\n if (responseData.delegationHash !== delegationHash) {\n throw new Error(\n 'Failed to store the Delegation, the hash returned from the MM delegation storage API does not match the hash of the delegation',\n );\n }\n\n return responseData.delegationHash;\n }\n}\n"]}
|
|
@@ -9,6 +9,9 @@ declare enum DelegationStoreFilter {
|
|
|
9
9
|
Received = "RECEIVED",
|
|
10
10
|
All = "ALL"
|
|
11
11
|
}
|
|
12
|
+
declare const DelegationStorageEnvironment: {
|
|
13
|
+
[K in 'dev' | 'prod']: Environment;
|
|
14
|
+
};
|
|
12
15
|
type Environment = {
|
|
13
16
|
apiUrl: string;
|
|
14
17
|
};
|
|
@@ -26,4 +29,4 @@ declare class DelegationStorageClient {
|
|
|
26
29
|
storeDelegation(delegation: Delegation): Promise<Hex>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
export { DelegationStorageClient, type DelegationStorageConfig, DelegationStoreFilter, type Environment };
|
|
32
|
+
export { DelegationStorageClient, type DelegationStorageConfig, DelegationStorageEnvironment, DelegationStoreFilter, type Environment };
|
|
@@ -9,6 +9,9 @@ declare enum DelegationStoreFilter {
|
|
|
9
9
|
Received = "RECEIVED",
|
|
10
10
|
All = "ALL"
|
|
11
11
|
}
|
|
12
|
+
declare const DelegationStorageEnvironment: {
|
|
13
|
+
[K in 'dev' | 'prod']: Environment;
|
|
14
|
+
};
|
|
12
15
|
type Environment = {
|
|
13
16
|
apiUrl: string;
|
|
14
17
|
};
|
|
@@ -26,4 +29,4 @@ declare class DelegationStorageClient {
|
|
|
26
29
|
storeDelegation(delegation: Delegation): Promise<Hex>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
export { DelegationStorageClient, type DelegationStorageConfig, DelegationStoreFilter, type Environment };
|
|
32
|
+
export { DelegationStorageClient, type DelegationStorageConfig, DelegationStorageEnvironment, DelegationStoreFilter, type Environment };
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
hashDelegation
|
|
3
|
-
|
|
2
|
+
hashDelegation,
|
|
3
|
+
trackSmartAccountsKitFunctionCall
|
|
4
|
+
} from "../chunk-ZA2XYCVX.mjs";
|
|
4
5
|
|
|
5
6
|
// src/experimental/delegationStorage.ts
|
|
6
7
|
import { toHex } from "viem";
|
|
8
|
+
var DelegationStorageEnvironment = {
|
|
9
|
+
dev: { apiUrl: "https://passkeys.dev-api.cx.metamask.io" },
|
|
10
|
+
prod: { apiUrl: "https://passkeys.api.cx.metamask.io" }
|
|
11
|
+
};
|
|
12
|
+
function getDelegationStorageEnvironment(apiUrl) {
|
|
13
|
+
const matchingEnvironment = Object.entries(DelegationStorageEnvironment).find(
|
|
14
|
+
([_, env]) => env.apiUrl === apiUrl
|
|
15
|
+
);
|
|
16
|
+
return matchingEnvironment ? matchingEnvironment[0] : "custom";
|
|
17
|
+
}
|
|
7
18
|
var DelegationStorageClient = class {
|
|
8
19
|
#apiVersionPrefix = "api/v0";
|
|
9
20
|
#config;
|
|
@@ -11,6 +22,12 @@ var DelegationStorageClient = class {
|
|
|
11
22
|
#apiUrl;
|
|
12
23
|
constructor(config) {
|
|
13
24
|
const { apiUrl } = config.environment;
|
|
25
|
+
trackSmartAccountsKitFunctionCall(
|
|
26
|
+
"experimental.DelegationStorageClient.constructor",
|
|
27
|
+
{
|
|
28
|
+
environment: getDelegationStorageEnvironment(apiUrl)
|
|
29
|
+
}
|
|
30
|
+
);
|
|
14
31
|
if (apiUrl.endsWith(this.#apiVersionPrefix)) {
|
|
15
32
|
this.#apiUrl = apiUrl;
|
|
16
33
|
} else {
|
|
@@ -51,6 +68,12 @@ var DelegationStorageClient = class {
|
|
|
51
68
|
* is not found.
|
|
52
69
|
*/
|
|
53
70
|
async getDelegationChain(leafDelegationOrDelegationHash) {
|
|
71
|
+
trackSmartAccountsKitFunctionCall(
|
|
72
|
+
"experimental.DelegationStorageClient.getDelegationChain",
|
|
73
|
+
{
|
|
74
|
+
inputKind: typeof leafDelegationOrDelegationHash === "string" ? "hash" : "delegation"
|
|
75
|
+
}
|
|
76
|
+
);
|
|
54
77
|
const leafDelegationHash = typeof leafDelegationOrDelegationHash === "string" ? leafDelegationOrDelegationHash : hashDelegation(leafDelegationOrDelegationHash);
|
|
55
78
|
const response = await this.#fetcher(
|
|
56
79
|
`${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,
|
|
@@ -81,6 +104,10 @@ var DelegationStorageClient = class {
|
|
|
81
104
|
* empty array if the delegations are not found.
|
|
82
105
|
*/
|
|
83
106
|
async fetchDelegations(deleGatorAddress, filterMode = "RECEIVED" /* Received */) {
|
|
107
|
+
trackSmartAccountsKitFunctionCall(
|
|
108
|
+
"experimental.DelegationStorageClient.fetchDelegations",
|
|
109
|
+
{ filterMode }
|
|
110
|
+
);
|
|
84
111
|
const response = await this.#fetcher(
|
|
85
112
|
`${this.#apiUrl}/delegation/accounts/${deleGatorAddress}?filter=${filterMode}`,
|
|
86
113
|
{
|
|
@@ -104,6 +131,10 @@ var DelegationStorageClient = class {
|
|
|
104
131
|
* @returns A promise that resolves to the delegation hash indicating successful storage.
|
|
105
132
|
*/
|
|
106
133
|
async storeDelegation(delegation) {
|
|
134
|
+
trackSmartAccountsKitFunctionCall(
|
|
135
|
+
"experimental.DelegationStorageClient.storeDelegation",
|
|
136
|
+
{ caveatCount: delegation.caveats.length }
|
|
137
|
+
);
|
|
107
138
|
if (!delegation.signature || delegation.signature === "0x") {
|
|
108
139
|
throw new Error("Delegation must be signed to be stored");
|
|
109
140
|
}
|
|
@@ -138,6 +169,7 @@ var DelegationStorageClient = class {
|
|
|
138
169
|
}
|
|
139
170
|
};
|
|
140
171
|
export {
|
|
141
|
-
DelegationStorageClient
|
|
172
|
+
DelegationStorageClient,
|
|
173
|
+
DelegationStorageEnvironment
|
|
142
174
|
};
|
|
143
175
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/experimental/delegationStorage.ts"],"sourcesContent":["import { type Hex, toHex } from 'viem';\n\nimport { hashDelegation } from '../delegation';\nimport type { Delegation } from '../types';\n\ntype ErrorResponse = {\n error: string;\n data?: any;\n};\n\nexport type APIStoreDelegationResponse = {\n delegationHash: Hex;\n};\n\n/**\n * Represents the allowed filters when querying the data store for delegations.\n */\nexport enum DelegationStoreFilter {\n Given = 'GIVEN',\n Received = 'RECEIVED',\n All = 'ALL',\n}\n\n/**\n * Public Delegation Storage Service environments. To be used in the\n * DeleGationStorageService config.\n */\nexport const DelegationStorageEnvironment: {\n [K in 'dev' | 'prod']: Environment;\n} = {\n dev: { apiUrl: 'https://passkeys.dev-api.cx.metamask.io' },\n prod: { apiUrl: 'https://passkeys.api.cx.metamask.io' },\n};\n\nexport type Environment = {\n apiUrl: string;\n};\n\nexport type DelegationStorageConfig = {\n apiKey: string;\n apiKeyId: string;\n environment: Environment;\n fetcher?: typeof fetch;\n};\n\nexport class DelegationStorageClient {\n readonly #apiVersionPrefix = 'api/v0';\n\n readonly #config: DelegationStorageConfig;\n\n readonly #fetcher: typeof fetch;\n\n readonly #apiUrl: string;\n\n constructor(config: DelegationStorageConfig) {\n const { apiUrl } = config.environment;\n\n if (apiUrl.endsWith(this.#apiVersionPrefix)) {\n this.#apiUrl = apiUrl;\n } else {\n const separator = apiUrl.endsWith('/') ? '' : '/';\n this.#apiUrl = `${apiUrl}${separator}${this.#apiVersionPrefix}`;\n }\n this.#fetcher = this.#initializeFetcher(config);\n this.#config = config;\n }\n\n /**\n * Initializes the fetch function for HTTP requests.\n *\n * - Uses `config.fetcher` if provided.\n * - Falls back to global `fetch` if available.\n * - Throws an error if no fetch function is available.\n *\n * @param config - Configuration object that may include a custom fetch function.\n * @returns The fetch function to be used for HTTP requests.\n * @throws Error if no fetch function is available in the environment.\n */\n #initializeFetcher(config: DelegationStorageConfig): typeof fetch {\n if (config.fetcher) {\n return config.fetcher;\n } else if (typeof globalThis?.fetch === 'function') {\n return globalThis.fetch.bind(globalThis);\n }\n throw new Error(\n 'Fetch API is not available in this environment. Please provide a fetch function in the config.',\n );\n }\n\n /**\n * Fetches the delegation chain from the Delegation Storage Service, ending with\n * the specified leaf delegation.\n *\n * @param leafDelegationOrDelegationHash - The leaf delegation, or the hash\n * of the leaf delegation.\n * @returns A promise that resolves to the delegation chain - empty array if the delegation\n * is not found.\n */\n async getDelegationChain(\n leafDelegationOrDelegationHash: Hex | Delegation,\n ): Promise<Delegation[]> {\n const leafDelegationHash =\n typeof leafDelegationOrDelegationHash === 'string'\n ? leafDelegationOrDelegationHash\n : hashDelegation(leafDelegationOrDelegationHash);\n\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(\n `Failed to fetch delegation chain: ${responseData.error}`,\n );\n }\n\n return responseData;\n }\n\n /**\n * Fetches the delegations from the Delegation Storage Service, either `Received`\n * by, or `Given` by, (or both: `All`) the specified deleGatorAddress. Defaults\n * to `Received`.\n *\n * @param deleGatorAddress - The deleGatorAddress to retrieve the delegations for.\n * @param filterMode - The DelegationStoreFilter mode - defaults to Received.\n * @returns A promise that resolves to the list of delegations received by the deleGatorAddress,\n * empty array if the delegations are not found.\n */\n async fetchDelegations(\n deleGatorAddress: Hex,\n filterMode = DelegationStoreFilter.Received,\n ): Promise<Delegation[]> {\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/accounts/${deleGatorAddress}?filter=${filterMode}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(`Failed to fetch delegations: ${responseData.error}`);\n }\n\n return responseData;\n }\n\n /**\n * Stores the specified delegation in the Delegation Storage Service.\n *\n * @param delegation - The delegation to store.\n * @returns A promise that resolves to the delegation hash indicating successful storage.\n */\n async storeDelegation(delegation: Delegation): Promise<Hex> {\n if (!delegation.signature || delegation.signature === '0x') {\n throw new Error('Delegation must be signed to be stored');\n }\n\n const delegationHash = hashDelegation(delegation);\n\n const body = JSON.stringify(\n {\n ...delegation,\n metadata: [],\n },\n (_, value: any) =>\n typeof value === 'bigint' || typeof value === 'number'\n ? toHex(value)\n : value,\n 2,\n );\n\n const response = await this.#fetcher(`${this.#apiUrl}/delegation/store`, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n 'Content-Type': 'application/json',\n },\n body,\n });\n\n const responseData: APIStoreDelegationResponse | ErrorResponse =\n await response.json();\n\n if ('error' in responseData) {\n throw new Error(responseData.error);\n }\n\n if (responseData.delegationHash !== delegationHash) {\n throw new Error(\n 'Failed to store the Delegation, the hash returned from the MM delegation storage API does not match the hash of the delegation',\n );\n }\n\n return responseData.delegationHash;\n }\n}\n"],"mappings":";;;;;AAAA,SAAmB,aAAa;AA6CzB,IAAM,0BAAN,MAA8B;AAAA,EAC1B,oBAAoB;AAAA,EAEpB;AAAA,EAEA;AAAA,EAEA;AAAA,EAET,YAAY,QAAiC;AAC3C,UAAM,EAAE,OAAO,IAAI,OAAO;AAE1B,QAAI,OAAO,SAAS,KAAK,iBAAiB,GAAG;AAC3C,WAAK,UAAU;AAAA,IACjB,OAAO;AACL,YAAM,YAAY,OAAO,SAAS,GAAG,IAAI,KAAK;AAC9C,WAAK,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,iBAAiB;AAAA,IAC/D;AACA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,IACF;AAEA,UAAM,eAA6C,MAAM,SAAS,KAAK;AAEvE,QAAI,WAAW,cAAc;AAC3B,YAAM,IAAI,MAAM,gCAAgC,aAAa,KAAK,EAAE;AAAA,IACtE;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAAgB,YAAsC;AAC1D,QAAI,CAAC,WAAW,aAAa,WAAW,cAAc,MAAM;AAC1D,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAEA,UAAM,iBAAiB,eAAe,UAAU;AAEhD,UAAM,OAAO,KAAK;AAAA,MAChB;AAAA,QACE,GAAG;AAAA,QACH,UAAU,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,UACF,OAAO,UAAU,YAAY,OAAO,UAAU,WAC1C,MAAM,KAAK,IACX;AAAA,MACN;AAAA,IACF;AAEA,UAAM,WAAW,MAAM,KAAK,SAAS,GAAG,KAAK,OAAO,qBAAqB;AAAA,MACvE,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,eAAe,UAAU,KAAK,QAAQ,MAAM;AAAA,QAC5C,gBAAgB,KAAK,QAAQ;AAAA,QAC7B,gBAAgB;AAAA,MAClB;AAAA,MACA;AAAA,IACF,CAAC;AAED,UAAM,eACJ,MAAM,SAAS,KAAK;AAEtB,QAAI,WAAW,cAAc;AAC3B,YAAM,IAAI,MAAM,aAAa,KAAK;AAAA,IACpC;AAEA,QAAI,aAAa,mBAAmB,gBAAgB;AAClD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,aAAa;AAAA,EACtB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/experimental/delegationStorage.ts"],"sourcesContent":["import { type Hex, toHex } from 'viem';\n\nimport { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport { hashDelegation } from '../delegation';\nimport type { Delegation } from '../types';\n\ntype ErrorResponse = {\n error: string;\n data?: any;\n};\n\nexport type APIStoreDelegationResponse = {\n delegationHash: Hex;\n};\n\n/**\n * Represents the allowed filters when querying the data store for delegations.\n */\nexport enum DelegationStoreFilter {\n Given = 'GIVEN',\n Received = 'RECEIVED',\n All = 'ALL',\n}\n\n/**\n * Public Delegation Storage Service environments. To be used in the\n * DeleGationStorageService config.\n */\nexport const DelegationStorageEnvironment: {\n [K in 'dev' | 'prod']: Environment;\n} = {\n dev: { apiUrl: 'https://passkeys.dev-api.cx.metamask.io' },\n prod: { apiUrl: 'https://passkeys.api.cx.metamask.io' },\n};\n\n/**\n * Returns the DelegationStorageEnvironment ('dev' or 'prod') for a given apiUrl,\n * or 'custom' if the apiUrl does not match a known environment.\n *\n * @param apiUrl - The API URL to check.\n * @returns The environment key ('dev' or 'prod'), or 'custom'.\n */\nfunction getDelegationStorageEnvironment(\n apiUrl: string,\n): 'dev' | 'prod' | 'custom' {\n const matchingEnvironment = Object.entries(DelegationStorageEnvironment).find(\n ([_, env]) => env.apiUrl === apiUrl,\n ) as [keyof typeof DelegationStorageEnvironment, Environment] | undefined;\n\n return matchingEnvironment ? matchingEnvironment[0] : 'custom';\n}\n\nexport type Environment = {\n apiUrl: string;\n};\n\nexport type DelegationStorageConfig = {\n apiKey: string;\n apiKeyId: string;\n environment: Environment;\n fetcher?: typeof fetch;\n};\n\nexport class DelegationStorageClient {\n readonly #apiVersionPrefix = 'api/v0';\n\n readonly #config: DelegationStorageConfig;\n\n readonly #fetcher: typeof fetch;\n\n readonly #apiUrl: string;\n\n constructor(config: DelegationStorageConfig) {\n const { apiUrl } = config.environment;\n\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.constructor',\n {\n environment: getDelegationStorageEnvironment(apiUrl),\n },\n );\n\n if (apiUrl.endsWith(this.#apiVersionPrefix)) {\n this.#apiUrl = apiUrl;\n } else {\n const separator = apiUrl.endsWith('/') ? '' : '/';\n this.#apiUrl = `${apiUrl}${separator}${this.#apiVersionPrefix}`;\n }\n this.#fetcher = this.#initializeFetcher(config);\n this.#config = config;\n }\n\n /**\n * Initializes the fetch function for HTTP requests.\n *\n * - Uses `config.fetcher` if provided.\n * - Falls back to global `fetch` if available.\n * - Throws an error if no fetch function is available.\n *\n * @param config - Configuration object that may include a custom fetch function.\n * @returns The fetch function to be used for HTTP requests.\n * @throws Error if no fetch function is available in the environment.\n */\n #initializeFetcher(config: DelegationStorageConfig): typeof fetch {\n if (config.fetcher) {\n return config.fetcher;\n } else if (typeof globalThis?.fetch === 'function') {\n return globalThis.fetch.bind(globalThis);\n }\n throw new Error(\n 'Fetch API is not available in this environment. Please provide a fetch function in the config.',\n );\n }\n\n /**\n * Fetches the delegation chain from the Delegation Storage Service, ending with\n * the specified leaf delegation.\n *\n * @param leafDelegationOrDelegationHash - The leaf delegation, or the hash\n * of the leaf delegation.\n * @returns A promise that resolves to the delegation chain - empty array if the delegation\n * is not found.\n */\n async getDelegationChain(\n leafDelegationOrDelegationHash: Hex | Delegation,\n ): Promise<Delegation[]> {\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.getDelegationChain',\n {\n inputKind:\n typeof leafDelegationOrDelegationHash === 'string'\n ? 'hash'\n : 'delegation',\n },\n );\n const leafDelegationHash =\n typeof leafDelegationOrDelegationHash === 'string'\n ? leafDelegationOrDelegationHash\n : hashDelegation(leafDelegationOrDelegationHash);\n\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(\n `Failed to fetch delegation chain: ${responseData.error}`,\n );\n }\n\n return responseData;\n }\n\n /**\n * Fetches the delegations from the Delegation Storage Service, either `Received`\n * by, or `Given` by, (or both: `All`) the specified deleGatorAddress. Defaults\n * to `Received`.\n *\n * @param deleGatorAddress - The deleGatorAddress to retrieve the delegations for.\n * @param filterMode - The DelegationStoreFilter mode - defaults to Received.\n * @returns A promise that resolves to the list of delegations received by the deleGatorAddress,\n * empty array if the delegations are not found.\n */\n async fetchDelegations(\n deleGatorAddress: Hex,\n filterMode = DelegationStoreFilter.Received,\n ): Promise<Delegation[]> {\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.fetchDelegations',\n { filterMode },\n );\n const response = await this.#fetcher(\n `${this.#apiUrl}/delegation/accounts/${deleGatorAddress}?filter=${filterMode}`,\n {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n },\n },\n );\n\n const responseData: Delegation[] | ErrorResponse = await response.json();\n\n if ('error' in responseData) {\n throw new Error(`Failed to fetch delegations: ${responseData.error}`);\n }\n\n return responseData;\n }\n\n /**\n * Stores the specified delegation in the Delegation Storage Service.\n *\n * @param delegation - The delegation to store.\n * @returns A promise that resolves to the delegation hash indicating successful storage.\n */\n async storeDelegation(delegation: Delegation): Promise<Hex> {\n trackSmartAccountsKitFunctionCall(\n 'experimental.DelegationStorageClient.storeDelegation',\n { caveatCount: delegation.caveats.length },\n );\n if (!delegation.signature || delegation.signature === '0x') {\n throw new Error('Delegation must be signed to be stored');\n }\n\n const delegationHash = hashDelegation(delegation);\n\n const body = JSON.stringify(\n {\n ...delegation,\n metadata: [],\n },\n (_, value: any) =>\n typeof value === 'bigint' || typeof value === 'number'\n ? toHex(value)\n : value,\n 2,\n );\n\n const response = await this.#fetcher(`${this.#apiUrl}/delegation/store`, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${this.#config.apiKey}`,\n 'x-api-key-id': this.#config.apiKeyId,\n 'Content-Type': 'application/json',\n },\n body,\n });\n\n const responseData: APIStoreDelegationResponse | ErrorResponse =\n await response.json();\n\n if ('error' in responseData) {\n throw new Error(responseData.error);\n }\n\n if (responseData.delegationHash !== delegationHash) {\n throw new Error(\n 'Failed to store the Delegation, the hash returned from the MM delegation storage API does not match the hash of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AAA,IAC3C;AACA,QAAI,CAAC,WAAW,aAAa,WAAW,cAAc,MAAM;AAC1D,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAEA,UAAM,iBAAiB,eAAe,UAAU;AAEhD,UAAM,OAAO,KAAK;AAAA,MAChB;AAAA,QACE,GAAG;AAAA,QACH,UAAU,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,UACF,OAAO,UAAU,YAAY,OAAO,UAAU,WAC1C,MAAM,KAAK,IACX;AAAA,MACN;AAAA,IACF;AAEA,UAAM,WAAW,MAAM,KAAK,SAAS,GAAG,KAAK,OAAO,qBAAqB;AAAA,MACvE,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,eAAe,UAAU,KAAK,QAAQ,MAAM;AAAA,QAC5C,gBAAgB,KAAK,QAAQ;AAAA,QAC7B,gBAAgB;AAAA,MAClB;AAAA,MACA;AAAA,IACF,CAAC;AAED,UAAM,eACJ,MAAM,SAAS,KAAK;AAEtB,QAAI,WAAW,cAAc;AAC3B,YAAM,IAAI,MAAM,aAAa,KAAK;AAAA,IACpC;AAEA,QAAI,aAAa,mBAAmB,gBAAgB;AAClD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,aAAa;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ANY_BENEFICIARY, ROOT_AUTHORITY } from '@metamask/delegation-core';
|
|
2
2
|
import * as viem from 'viem';
|
|
3
3
|
import { Client, Transport, Chain, Account, Address, Hex } from 'viem';
|
|
4
|
-
import { m as DelegationStruct, E as ExecutionMode, d as ExecutionStruct } from './delegation-
|
|
4
|
+
import { m as DelegationStruct, E as ExecutionMode, d as ExecutionStruct } from './delegation-Bx4FEAIU.js';
|
|
5
5
|
import { D as Delegation, P as PermissionContext } from './types-BWaH4KH1.js';
|
|
6
6
|
|
|
7
7
|
declare const NAME$1 = "DelegationManager";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ANY_BENEFICIARY, ROOT_AUTHORITY } from '@metamask/delegation-core';
|
|
2
2
|
import * as viem from 'viem';
|
|
3
3
|
import { Client, Transport, Chain, Account, Address, Hex } from 'viem';
|
|
4
|
-
import { m as DelegationStruct, E as ExecutionMode, d as ExecutionStruct } from './delegation-
|
|
4
|
+
import { m as DelegationStruct, E as ExecutionMode, d as ExecutionStruct } from './delegation-KbWHzRxV.cjs';
|
|
5
5
|
import { D as Delegation, P as PermissionContext } from './types-BWaH4KH1.cjs';
|
|
6
6
|
|
|
7
7
|
declare const NAME$1 = "DelegationManager";
|
package/dist/index.cjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkT4IAMAB2cjs = require('./chunk-T4IAMAB2.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
require('./chunk-
|
|
8
|
+
var _chunkHFRQNSZEcjs = require('./chunk-HFRQNSZE.cjs');
|
|
9
|
+
require('./chunk-3SHZ7PV2.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkUB2FLPP3cjs = require('./chunk-UB2FLPP3.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
var _chunkSOFB2MXGcjs = require('./chunk-SOFB2MXG.cjs');
|
|
22
|
-
require('./chunk-
|
|
22
|
+
require('./chunk-UZO5OYCD.cjs');
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _chunkMOHCTPYQcjs = require('./chunk-MOHCTPYQ.cjs');
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
@@ -38,7 +38,8 @@ var _chunkVLKX4BR6cjs = require('./chunk-VLKX4BR6.cjs');
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
var _chunk7BEEGBA2cjs = require('./chunk-7BEEGBA2.cjs');
|
|
42
43
|
|
|
43
44
|
// src/toMetaMaskSmartAccount.ts
|
|
44
45
|
|
|
@@ -61,6 +62,9 @@ var signatureTypes = ["ECDSA"];
|
|
|
61
62
|
var aggregateSignature = ({
|
|
62
63
|
signatures
|
|
63
64
|
}) => {
|
|
65
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0, "aggregateSignature", {
|
|
66
|
+
signatureCount: signatures.length
|
|
67
|
+
});
|
|
64
68
|
if (signatures.length === 0) {
|
|
65
69
|
return "0x";
|
|
66
70
|
}
|
|
@@ -114,7 +118,7 @@ var resolveHybridSigner = (config) => {
|
|
|
114
118
|
if (webAuthnAccount.type !== "webAuthn") {
|
|
115
119
|
throw new Error("Account is not a webAuthn account");
|
|
116
120
|
}
|
|
117
|
-
const encodeSignature = (result) =>
|
|
121
|
+
const encodeSignature = (result) => _chunkUB2FLPP3cjs.encodeDeleGatorSignature.call(void 0,
|
|
118
122
|
keyId,
|
|
119
123
|
result.signature,
|
|
120
124
|
result.webauthn.clientDataJSON,
|
|
@@ -122,7 +126,7 @@ var resolveHybridSigner = (config) => {
|
|
|
122
126
|
);
|
|
123
127
|
const signMessage = async (args) => webAuthnAccount.signMessage(args).then(encodeSignature);
|
|
124
128
|
const signTypedData = async (typedDataDefinition) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);
|
|
125
|
-
const getStubSignature = async () =>
|
|
129
|
+
const getStubSignature = async () => _chunkUB2FLPP3cjs.createDummyWebAuthnSignature.call(void 0, keyId);
|
|
126
130
|
return {
|
|
127
131
|
signMessage,
|
|
128
132
|
signTypedData,
|
|
@@ -233,6 +237,12 @@ async function toMetaMaskSmartAccount(params) {
|
|
|
233
237
|
implementation,
|
|
234
238
|
nonceKeyManager
|
|
235
239
|
} = params;
|
|
240
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0, "toMetaMaskSmartAccount", {
|
|
241
|
+
implementation,
|
|
242
|
+
hasAddress: params.address !== void 0,
|
|
243
|
+
hasEnvironment: params.environment !== void 0,
|
|
244
|
+
chainId: _nullishCoalesce(_optionalChain([chain, 'optionalAccess', _ => _.id]), () => ( null))
|
|
245
|
+
});
|
|
236
246
|
if (!chain) {
|
|
237
247
|
throw new Error("Chain not specified");
|
|
238
248
|
}
|
|
@@ -249,7 +259,7 @@ async function toMetaMaskSmartAccount(params) {
|
|
|
249
259
|
if (implementation === "Stateless7702" /* Stateless7702 */) {
|
|
250
260
|
throw new Error("Stateless7702 does not support counterfactual accounts");
|
|
251
261
|
}
|
|
252
|
-
const accountData = await
|
|
262
|
+
const accountData = await _chunkUB2FLPP3cjs.getCounterfactualAccountData.call(void 0, {
|
|
253
263
|
factory: environment.SimpleFactory,
|
|
254
264
|
implementations: environment.implementations,
|
|
255
265
|
implementation,
|
|
@@ -296,7 +306,7 @@ async function toMetaMaskSmartAccount(params) {
|
|
|
296
306
|
);
|
|
297
307
|
}
|
|
298
308
|
const { delegation, chainId } = delegationParams;
|
|
299
|
-
const delegationStruct =
|
|
309
|
+
const delegationStruct = _chunk7BEEGBA2cjs.toDelegationStruct.call(void 0, {
|
|
300
310
|
...delegation,
|
|
301
311
|
signature: "0x"
|
|
302
312
|
});
|
|
@@ -307,7 +317,7 @@ async function toMetaMaskSmartAccount(params) {
|
|
|
307
317
|
version: "1",
|
|
308
318
|
verifyingContract: environment.DelegationManager
|
|
309
319
|
},
|
|
310
|
-
types:
|
|
320
|
+
types: _chunk7BEEGBA2cjs.SIGNABLE_DELEGATION_TYPED_DATA,
|
|
311
321
|
primaryType: "Delegation",
|
|
312
322
|
message: delegationStruct
|
|
313
323
|
});
|
|
@@ -339,7 +349,7 @@ async function toMetaMaskSmartAccount(params) {
|
|
|
339
349
|
return signature;
|
|
340
350
|
};
|
|
341
351
|
const getAddress = async () => address;
|
|
342
|
-
const encodeCalls = async (calls) =>
|
|
352
|
+
const encodeCalls = async (calls) => _chunkUB2FLPP3cjs.encodeCallsForCaller.call(void 0, address, calls);
|
|
343
353
|
const signerMethods = _nullishCoalesce(signer, () => ( {
|
|
344
354
|
signMessage: async () => {
|
|
345
355
|
throw new Error(
|
|
@@ -373,7 +383,7 @@ async function toMetaMaskSmartAccount(params) {
|
|
|
373
383
|
if (implementation === "Stateless7702" /* Stateless7702 */) {
|
|
374
384
|
return {
|
|
375
385
|
...smartAccount,
|
|
376
|
-
isDeployed: async () =>
|
|
386
|
+
isDeployed: async () => _chunkT4IAMAB2cjs.isValid7702Implementation.call(void 0, {
|
|
377
387
|
client,
|
|
378
388
|
accountAddress: address,
|
|
379
389
|
environment
|
|
@@ -388,7 +398,10 @@ function createCaveatEnforcerClient({
|
|
|
388
398
|
client,
|
|
389
399
|
environment
|
|
390
400
|
}) {
|
|
391
|
-
|
|
401
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0, "createCaveatEnforcerClient", {
|
|
402
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _2 => _2.chain, 'optionalAccess', _3 => _3.id]), () => ( null))
|
|
403
|
+
});
|
|
404
|
+
return client.extend(_chunkT4IAMAB2cjs.caveatEnforcerActions.call(void 0, { environment }));
|
|
392
405
|
}
|
|
393
406
|
|
|
394
407
|
// src/actions/infuraBundlerClient.ts
|
|
@@ -416,6 +429,9 @@ var infuraBundlerActions = () => (client) => ({
|
|
|
416
429
|
}
|
|
417
430
|
});
|
|
418
431
|
function createInfuraBundlerClient(config) {
|
|
432
|
+
_chunk7BEEGBA2cjs.trackSmartAccountsKitFunctionCall.call(void 0, "createInfuraBundlerClient", {
|
|
433
|
+
chainId: _nullishCoalesce(_optionalChain([config, 'access', _4 => _4.chain, 'optionalAccess', _5 => _5.id]), () => ( null))
|
|
434
|
+
});
|
|
419
435
|
const baseBundlerClient = _accountabstraction.createBundlerClient.call(void 0, config);
|
|
420
436
|
return baseBundlerClient.extend(
|
|
421
437
|
infuraBundlerActions()
|
|
@@ -444,5 +460,5 @@ function createInfuraBundlerClient(config) {
|
|
|
444
460
|
|
|
445
461
|
|
|
446
462
|
|
|
447
|
-
exports.ANY_BENEFICIARY =
|
|
463
|
+
exports.ANY_BENEFICIARY = _chunk7BEEGBA2cjs.ANY_BENEFICIARY; exports.BalanceChangeType = _chunk7BEEGBA2cjs.BalanceChangeType; exports.CaveatType = _chunk7BEEGBA2cjs.CaveatType; exports.ExecutionMode = _chunkMOHCTPYQcjs.ExecutionMode; exports.Implementation = _chunk7BEEGBA2cjs.Implementation; exports.PREFERRED_VERSION = _chunkSOFB2MXGcjs.PREFERRED_VERSION; exports.ROOT_AUTHORITY = _chunk7BEEGBA2cjs.ROOT_AUTHORITY; exports.ScopeType = _chunk7BEEGBA2cjs.ScopeType; exports.TransferWindow = _chunk7BEEGBA2cjs.TransferWindow; exports.actions = _chunkT4IAMAB2cjs.actions_exports; exports.aggregateSignature = aggregateSignature; exports.contracts = _chunkHFRQNSZEcjs.contracts_exports; exports.createCaveat = _chunk7BEEGBA2cjs.createCaveat; exports.createCaveatEnforcerClient = createCaveatEnforcerClient; exports.createDelegation = _chunk7BEEGBA2cjs.createDelegation; exports.createExecution = _chunkMOHCTPYQcjs.createExecution; exports.createInfuraBundlerClient = createInfuraBundlerClient; exports.createOpenDelegation = _chunk7BEEGBA2cjs.createOpenDelegation; exports.getSmartAccountsEnvironment = _chunkSOFB2MXGcjs.getSmartAccountsEnvironment; exports.signDelegation = _chunk7BEEGBA2cjs.signDelegation; exports.signUserOperation = _chunkSOFB2MXGcjs.signUserOperation; exports.toMetaMaskSmartAccount = toMetaMaskSmartAccount;
|
|
448
464
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","../src/toMetaMaskSmartAccount.ts","../src/signer.ts","../src/signatures.ts","../src/actions/caveatEnforcerClient.ts","../src/actions/infuraBundlerClient.ts"],"names":["signTypedData","signMessage","getStubSignature","signUserOperation","signDelegation"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC1CA;AACE;AACA;AACA;AAAA,2DACK;AAEP;AACE;AACA;AACA;AAAA,8DACK;AD2CP;AACA;AEtDA,4BAAuB;AFwDvB;AACA;AGxDA;AAEA,IAAM,eAAA,EAAiB,CAAC,OAAO,CAAA;AAoBxB,IAAM,mBAAA,EAAqB,CAAC;AAAA,EACjC;AACF,CAAA,EAAA,GAEW;AACT,EAAA,GAAA,CAAI,UAAA,CAAW,OAAA,IAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,IAAA;AAAA,EACT;AAE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AAED,MAAA;AACE,QAAA;AACgB,QAAA;AAChB,QAAA;AACD,MAAA;AACL,IAAA;AACF,EAAA;AAGO,EAAA;AACT;ADkJsD;AACA;AIjWpD;AACA,EAAA;AACA,EAAA;AAIqD;AACR,EAAA;AAC/C;AJgWsD;AACA;AKxYtD;AACE;AAIK;AAyCiD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYmB,EAAA;AACjD,IAAA;AAOa,IAAA;AACzB,MAAA;AACC,MAAA;AACV,IAAA;AACH,EAAA;AACF;AA0DqD;AAEC,EAAA;AAG3B,EAAA;AACF,IAAA;AACvB,EAAA;AACF;AL6RsD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","sourcesContent":[null,"import {\n EIP7702StatelessDeleGator,\n HybridDeleGator,\n MultiSigDeleGator,\n} from '@metamask/delegation-abis';\nimport { type Address, type Hex } from 'viem';\nimport {\n entryPoint07Abi,\n toPackedUserOperation,\n toSmartAccount,\n} from 'viem/account-abstraction';\n\nimport { isValid7702Implementation } from './actions/isValid7702Implementation';\nimport { Implementation } from './constants';\nimport { getCounterfactualAccountData } from './counterfactualAccountData';\nimport {\n SIGNABLE_DELEGATION_TYPED_DATA,\n toDelegationStruct,\n} from './delegation';\nimport { encodeCallsForCaller } from './encodeCalls';\nimport { resolveSigner } from './signer';\nimport { getSmartAccountsEnvironment } from './smartAccountsEnvironment';\nimport type {\n Call,\n ToMetaMaskSmartAccountParameters,\n ToMetaMaskSmartAccountReturnType,\n SignDelegationParams,\n SignUserOperationParams,\n AbiByImplementation,\n} from './types';\nimport { SIGNABLE_USER_OP_TYPED_DATA } from './userOp';\n\nconst ENTRYPOINT_VERSION = '0.7' as const;\n\n/**\n * Creates a MetaMask DeleGator smart account instance.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @param params - The parameters for creating the smart account.\n * @returns A promise that resolves to a MetaMaskSmartAccount instance.\n * @description\n * This function sets up a MetaMask DeleGator smart account with the specified implementation.\n * It handles both deployed accounts, and counterfactual accounts.\n * A caller may specify a SmartAccountsEnvironment, otherwise the environment will be inferred from the chain.\n */\nexport async function toMetaMaskSmartAccount<\n TImplementation extends Implementation,\n>(\n params: ToMetaMaskSmartAccountParameters<TImplementation>,\n): Promise<ToMetaMaskSmartAccountReturnType<TImplementation>> {\n const {\n client,\n client: { chain },\n implementation,\n nonceKeyManager,\n } = params;\n\n if (!chain) {\n throw new Error('Chain not specified');\n }\n\n const signer = resolveSigner({\n implementation,\n signer: params.signer,\n });\n\n const environment =\n params.environment ?? getSmartAccountsEnvironment(chain.id);\n\n let address: Address, factoryData: Hex | undefined;\n\n if (params.address) {\n factoryData = undefined;\n address = params.address;\n } else {\n if (implementation === Implementation.Stateless7702) {\n throw new Error('Stateless7702 does not support counterfactual accounts');\n }\n\n const accountData = await getCounterfactualAccountData({\n factory: environment.SimpleFactory,\n implementations: environment.implementations,\n implementation,\n deployParams: params.deployParams,\n deploySalt: params.deploySalt,\n });\n\n address = accountData.address;\n factoryData = accountData.factoryData;\n }\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: environment.EntryPoint,\n version: ENTRYPOINT_VERSION,\n } as const;\n\n const { abi, contractName } = {\n [Implementation.Hybrid]: {\n contractName: 'HybridDeleGator',\n abi: HybridDeleGator,\n },\n [Implementation.MultiSig]: {\n contractName: 'MultiSigDeleGator',\n abi: MultiSigDeleGator,\n },\n [Implementation.Stateless7702]: {\n contractName: 'EIP7702StatelessDeleGator',\n abi: EIP7702StatelessDeleGator,\n },\n }[implementation] as {\n contractName: string;\n abi: AbiByImplementation[TImplementation];\n };\n\n const getFactoryArgs = async () => {\n if (factoryData === undefined) {\n throw new Error(\n 'Deploy params were not provided, so factory args cannot be inferred',\n );\n }\n return {\n factoryData,\n factory: environment.SimpleFactory,\n };\n };\n\n const signDelegation = async (delegationParams: SignDelegationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign delegation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { delegation, chainId } = delegationParams;\n\n const delegationStruct = toDelegationStruct({\n ...delegation,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: 'DelegationManager',\n version: '1',\n verifyingContract: environment.DelegationManager,\n },\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n message: delegationStruct,\n });\n\n return signature;\n };\n\n const signUserOperation = async (userOpParams: SignUserOperationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign user operation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { chainId } = userOpParams;\n\n const packedUserOp = toPackedUserOperation({\n sender: address,\n ...userOpParams,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: contractName,\n version: '1',\n verifyingContract: address,\n },\n types: SIGNABLE_USER_OP_TYPED_DATA,\n primaryType: 'PackedUserOperation',\n message: { ...packedUserOp, entryPoint: entryPoint.address },\n });\n\n return signature;\n };\n\n const getAddress = async () => address;\n\n const encodeCalls = async (calls: readonly Call[]) =>\n encodeCallsForCaller(address, calls);\n\n const signerMethods = signer ?? {\n signMessage: async () => {\n throw new Error(\n 'Cannot sign message: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n signTypedData: async () => {\n throw new Error(\n 'Cannot sign typed data: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n getStubSignature: async () => {\n throw new Error(\n 'Cannot get stub signature: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n };\n\n const smartAccount = await toSmartAccount({\n abi,\n client,\n entryPoint,\n environment,\n getAddress,\n getFactoryArgs,\n encodeCalls,\n signUserOperation,\n signDelegation,\n nonceKeyManager,\n ...signerMethods,\n });\n\n // Override isDeployed only for EIP-7702 implementation to check proper delegation code\n if (implementation === Implementation.Stateless7702) {\n return {\n ...smartAccount,\n isDeployed: async () =>\n isValid7702Implementation({\n client,\n accountAddress: address,\n environment,\n }),\n };\n }\n\n // For other implementations, use the default isDeployed behavior\n return smartAccount;\n}\n","import { concat } from 'viem';\nimport type {\n Address,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from 'viem';\nimport type { WebAuthnAccount } from 'viem/account-abstraction';\n\nimport { Implementation } from './constants';\nimport { aggregateSignature } from './signatures';\nimport type {\n AccountSignerConfig,\n HybridSignerConfig,\n InternalSigner,\n MultiSigSignerConfig,\n SignerConfigByImplementation,\n Stateless7702SignerConfig,\n WalletSignerConfig,\n} from './types';\nimport {\n createDummyWebAuthnSignature,\n encodeDeleGatorSignature,\n} from './webAuthn';\n\n// A valid ECDSA signature, this must be able to ecrecover an address, otherwise the contracts will revert in isValidSignature\nconst EOA_STUB_SIGNATURE =\n '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000011b' as const;\n\nconst resolveSignerFromWalletConfig = (\n config: WalletSignerConfig,\n): InternalSigner => {\n return {\n signMessage: config.walletClient.signMessage,\n signTypedData: async (typedData) => {\n // todo: figure out this type so that we don't need the type assertion\n return config.walletClient.signTypedData(typedData as any);\n },\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveSignerFromAccountConfig = (config: AccountSignerConfig) => {\n return {\n signMessage: config.account.signMessage,\n signTypedData: config.account.signTypedData,\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveHybridSigner = (config: HybridSignerConfig): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n const { keyId, webAuthnAccount } = config;\n\n if (webAuthnAccount.type !== 'webAuthn') {\n throw new Error('Account is not a webAuthn account');\n }\n\n const encodeSignature = (\n result: Awaited<ReturnType<WebAuthnAccount['signMessage']>>,\n ) =>\n encodeDeleGatorSignature(\n keyId,\n result.signature,\n result.webauthn.clientDataJSON,\n result.webauthn.authenticatorData,\n );\n\n const signMessage = async (args: { message: SignableMessage }) =>\n webAuthnAccount.signMessage(args).then(encodeSignature);\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);\n\n const getStubSignature = async () => createDummyWebAuthnSignature(keyId);\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveMultiSigSigner = (\n config: MultiSigSignerConfig,\n): InternalSigner => {\n const resolvedSigners = config.map((signer) => {\n let individualSignMessage: InternalSigner['signMessage'];\n let individualSignTypedData: InternalSigner['signTypedData'];\n let address: Address;\n if ('walletClient' in signer) {\n const { signMessage, signTypedData } =\n resolveSignerFromWalletConfig(signer);\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.walletClient.account.address;\n } else {\n const { signMessage, signTypedData } =\n resolveSignerFromAccountConfig(signer);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.account.address;\n }\n return {\n address,\n individualSignMessage,\n individualSignTypedData,\n };\n });\n\n const signMessage = async (args: { message: SignableMessage }) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignMessage, address }) => ({\n signature: await individualSignMessage(args),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignTypedData, address }) => ({\n signature: await individualSignTypedData(typedDataDefinition),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const getStubSignature = async () =>\n concat(resolvedSigners.map(() => EOA_STUB_SIGNATURE));\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveStateless7702Signer = (\n config: Stateless7702SignerConfig,\n): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n\n throw new Error('Invalid signer config');\n};\n\n/**\n * Resolve a signer from a configuration object.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null {\n const { implementation, signer } = config;\n\n if (!signer) {\n return null;\n }\n\n if (implementation === Implementation.Hybrid) {\n return resolveHybridSigner(signer as HybridSignerConfig);\n } else if (implementation === Implementation.MultiSig) {\n return resolveMultiSigSigner(signer as MultiSigSignerConfig);\n } else if (implementation === Implementation.Stateless7702) {\n return resolveStateless7702Signer(signer as Stateless7702SignerConfig);\n }\n throw new Error(`Implementation type '${implementation}' not supported`);\n}\n","import type { Address, Hex } from 'viem';\nimport { concat } from 'viem';\n\nconst signatureTypes = ['ECDSA'] as const;\n\nexport type SignatureType = (typeof signatureTypes)[number];\n\n/**\n * Represents a partial signature that can be aggregated with others.\n */\nexport type PartialSignature = {\n signer: Address;\n signature: Hex;\n type: SignatureType;\n};\n\n/**\n * Aggregates signatures into a single signature as expected by the MultiSig implementation.\n *\n * @param params - The parameters for signature aggregation.\n * @param params.signatures - The array of partial signatures to aggregate.\n * @returns The aggregated signature.\n */\nexport const aggregateSignature = ({\n signatures,\n}: {\n signatures: PartialSignature[];\n}): Hex => {\n if (signatures.length === 0) {\n return '0x';\n }\n\n for (const { type } of signatures) {\n if (!signatureTypes.includes(type)) {\n throw new Error(`Invalid signature type: ${type}`);\n }\n }\n\n // Sort signatures by signer address as required by MultiSig implementation\n const sortedSignatures = [...signatures].sort((a, b) =>\n a.signer.localeCompare(b.signer),\n );\n\n // Concatenate all signatures\n return concat(sortedSignatures.map(({ signature }) => signature));\n};\n\n/**\n * Type definition for the aggregateSignature function parameters.\n */\nexport type AggregateSignatureParams = {\n signatures: PartialSignature[];\n};\n","import type { Client, Transport, Chain, Account } from 'viem';\n\nimport type { SmartAccountsEnvironment } from '../types';\nimport {\n caveatEnforcerActions,\n type CaveatEnforcerParams,\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\n/**\n * Type for client extended with caveat enforcer actions.\n */\nexport type CaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n> = Client<TTransport, TChain, TAccount> &\n ReturnType<ReturnType<typeof caveatEnforcerActions>>;\n\n/**\n * Create a viem client extended with caveat enforcer actions.\n *\n * @param params - The parameters object.\n * @param params.client - The viem client.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns The extended client with caveat enforcer actions.\n */\nexport function createCaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n>({\n client,\n environment,\n}: {\n client: Client<TTransport, TChain, TAccount>;\n environment: SmartAccountsEnvironment;\n}): CaveatEnforcerClient<TTransport, TChain, TAccount> {\n return client.extend(caveatEnforcerActions({ environment }));\n}\n\n// Re-export types for convenience\nexport type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };\n","import type { Transport, Chain, Hex, Client, Account } from 'viem';\nimport {\n createBundlerClient,\n type BundlerClient,\n type BundlerClientConfig,\n type SmartAccount,\n} from 'viem/account-abstraction';\n\n/**\n * Gas price tiers returned by pimlico_getUserOperationGasPrice\n */\nexport type GasPriceTier = {\n /** Maximum fee per gas in hex format */\n maxFeePerGas: Hex;\n /** Maximum priority fee per gas in hex format */\n maxPriorityFeePerGas: Hex;\n};\n\n/**\n * Response from pimlico_getUserOperationGasPrice RPC method\n */\nexport type UserOperationGasPriceResponse = {\n /** Slow gas price tier */\n slow: GasPriceTier;\n /** Standard gas price tier */\n standard: GasPriceTier;\n /** Fast gas price tier */\n fast: GasPriceTier;\n};\n\n/**\n * Pimlico bundler schema for type-safe RPC method calls\n */\n/* eslint-disable @typescript-eslint/naming-convention */\ntype PimlicoBundlerSchema = [\n {\n Method: 'pimlico_getUserOperationGasPrice';\n Parameters: [];\n ReturnType: UserOperationGasPriceResponse;\n },\n];\n\n/**\n * Infura bundler actions for extending bundler clients.\n *\n * @returns A function that takes a client and returns the client extension with Infura bundler actions.\n */\nconst infuraBundlerActions = () => (client: Client) => ({\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n * @example\n * ```typescript\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * console.log(gasPrices.standard.maxFeePerGas);\n * ```\n */\n async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> {\n const pimlicoClient = client as Client<\n Transport,\n Chain | undefined,\n Account | undefined,\n PimlicoBundlerSchema\n >;\n\n return await pimlicoClient.request({\n method: 'pimlico_getUserOperationGasPrice',\n params: [],\n });\n },\n});\n\n/**\n * Type for bundler client extended with Infura bundler actions.\n */\nexport type InfuraBundlerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = BundlerClient<TTransport, TChain, TAccount> & {\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n */\n getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse>;\n};\n\n/**\n * Creates an Infura bundler client extended with Infura bundler actions.\n *\n * This is a wrapper around viem's createBundlerClient that extends it with\n * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's\n * bundler infrastructure via Infura's proxy.\n *\n * @param config - Configuration for the bundler client.\n * @returns Extended bundler client with Infura bundler actions.\n * @example\n * ```typescript\n * import { createPublicClient, http } from 'viem';\n * import { sepolia } from 'viem/chains';\n * import { createInfuraBundlerClient } from '@metamask/smart-accounts-kit';\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * });\n *\n * const bundlerClient = createInfuraBundlerClient({\n * client: publicClient,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * chain: sepolia,\n * });\n *\n * // Use standard bundler methods\n * const userOpHash = await bundlerClient.sendUserOperation({...});\n *\n * // Use Infura specific methods\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * ```\n */\nexport function createInfuraBundlerClient<\n TTransport extends Transport,\n TChain extends Chain | undefined = undefined,\n TAccount extends SmartAccount | undefined = undefined,\n>(\n config: BundlerClientConfig<TTransport, TChain, TAccount>,\n): InfuraBundlerClient<TTransport, TChain, TAccount> {\n // Create the base bundler client using viem's function\n const baseBundlerClient = createBundlerClient(config);\n\n // Extend the client with Infura bundler actions\n return baseBundlerClient.extend(\n infuraBundlerActions(),\n ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","../src/toMetaMaskSmartAccount.ts","../src/signer.ts","../src/signatures.ts","../src/actions/caveatEnforcerClient.ts","../src/actions/infuraBundlerClient.ts"],"names":["signTypedData","signMessage","getStubSignature","signUserOperation","signDelegation"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC3CA;AACE;AACA;AACA;AAAA,2DACK;AAEP;AACE;AACA;AACA;AAAA,8DACK;AD4CP;AACA;AEv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A;AACT,EAAA;AAE+B,EAAA;AAG7B,EAAA;AAE8B,EAAA;AACL,IAAA;AACb,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AAC2B,IAAA;AACf,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AAC8B,IAAA;AAClB,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AACF,EAAA;AAE0C,EAAA;AACxC,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACAG,IAAAA;AACAC,IAAAA;AACA,IAAA;AACG,IAAA;AACJ,EAAA;AAGG,EAAA;AACK,IAAA;AACF,MAAA;AAED,MAAA;AACE,QAAA;AACgB,QAAA;AAChB,QAAA;AACD,MAAA;AACL,IAAA;AACF,EAAA;AAGO,EAAA;AACT;ADoJsD;AACA;AI1WpD;AACA,EAAA;AACA,EAAA;AAIqD;AACnB,EAAA;AACH,IAAA;AAC9B,EAAA;AAE4C,EAAA;AAC/C;AJwWsD;AACA;AKrZtD;AACE;AAIK;AA2CiD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYmB,EAAA;AACjD,IAAA;AAOa,IAAA;AACzB,MAAA;AACC,MAAA;AACV,IAAA;AACH,EAAA;AACF;AA0DqD;AACjB,EAAA;AACH,IAAA;AAC9B,EAAA;AAEmD,EAAA;AAG3B,EAAA;AACF,IAAA;AACvB,EAAA;AACF;ALwSsD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","sourcesContent":[null,"import {\n EIP7702StatelessDeleGator,\n HybridDeleGator,\n MultiSigDeleGator,\n} from '@metamask/delegation-abis';\nimport { type Address, type Hex } from 'viem';\nimport {\n entryPoint07Abi,\n toPackedUserOperation,\n toSmartAccount,\n} from 'viem/account-abstraction';\n\nimport { isValid7702Implementation } from './actions/isValid7702Implementation';\nimport { trackSmartAccountsKitFunctionCall } from './analytics';\nimport { Implementation } from './constants';\nimport { getCounterfactualAccountData } from './counterfactualAccountData';\nimport {\n SIGNABLE_DELEGATION_TYPED_DATA,\n toDelegationStruct,\n} from './delegation';\nimport { encodeCallsForCaller } from './encodeCalls';\nimport { resolveSigner } from './signer';\nimport { getSmartAccountsEnvironment } from './smartAccountsEnvironment';\nimport type {\n Call,\n ToMetaMaskSmartAccountParameters,\n ToMetaMaskSmartAccountReturnType,\n SignDelegationParams,\n SignUserOperationParams,\n AbiByImplementation,\n} from './types';\nimport { SIGNABLE_USER_OP_TYPED_DATA } from './userOp';\n\nconst ENTRYPOINT_VERSION = '0.7' as const;\n\n/**\n * Creates a MetaMask DeleGator smart account instance.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @param params - The parameters for creating the smart account.\n * @returns A promise that resolves to a MetaMaskSmartAccount instance.\n * @description\n * This function sets up a MetaMask DeleGator smart account with the specified implementation.\n * It handles both deployed accounts, and counterfactual accounts.\n * A caller may specify a SmartAccountsEnvironment, otherwise the environment will be inferred from the chain.\n */\nexport async function toMetaMaskSmartAccount<\n TImplementation extends Implementation,\n>(\n params: ToMetaMaskSmartAccountParameters<TImplementation>,\n): Promise<ToMetaMaskSmartAccountReturnType<TImplementation>> {\n const {\n client,\n client: { chain },\n implementation,\n nonceKeyManager,\n } = params;\n\n trackSmartAccountsKitFunctionCall('toMetaMaskSmartAccount', {\n implementation,\n hasAddress: params.address !== undefined,\n hasEnvironment: params.environment !== undefined,\n chainId: chain?.id ?? null,\n });\n\n if (!chain) {\n throw new Error('Chain not specified');\n }\n\n const signer = resolveSigner({\n implementation,\n signer: params.signer,\n });\n\n const environment =\n params.environment ?? getSmartAccountsEnvironment(chain.id);\n\n let address: Address, factoryData: Hex | undefined;\n\n if (params.address) {\n factoryData = undefined;\n address = params.address;\n } else {\n if (implementation === Implementation.Stateless7702) {\n throw new Error('Stateless7702 does not support counterfactual accounts');\n }\n\n const accountData = await getCounterfactualAccountData({\n factory: environment.SimpleFactory,\n implementations: environment.implementations,\n implementation,\n deployParams: params.deployParams,\n deploySalt: params.deploySalt,\n });\n\n address = accountData.address;\n factoryData = accountData.factoryData;\n }\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: environment.EntryPoint,\n version: ENTRYPOINT_VERSION,\n } as const;\n\n const { abi, contractName } = {\n [Implementation.Hybrid]: {\n contractName: 'HybridDeleGator',\n abi: HybridDeleGator,\n },\n [Implementation.MultiSig]: {\n contractName: 'MultiSigDeleGator',\n abi: MultiSigDeleGator,\n },\n [Implementation.Stateless7702]: {\n contractName: 'EIP7702StatelessDeleGator',\n abi: EIP7702StatelessDeleGator,\n },\n }[implementation] as {\n contractName: string;\n abi: AbiByImplementation[TImplementation];\n };\n\n const getFactoryArgs = async () => {\n if (factoryData === undefined) {\n throw new Error(\n 'Deploy params were not provided, so factory args cannot be inferred',\n );\n }\n return {\n factoryData,\n factory: environment.SimpleFactory,\n };\n };\n\n const signDelegation = async (delegationParams: SignDelegationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign delegation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { delegation, chainId } = delegationParams;\n\n const delegationStruct = toDelegationStruct({\n ...delegation,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: 'DelegationManager',\n version: '1',\n verifyingContract: environment.DelegationManager,\n },\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n message: delegationStruct,\n });\n\n return signature;\n };\n\n const signUserOperation = async (userOpParams: SignUserOperationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign user operation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { chainId } = userOpParams;\n\n const packedUserOp = toPackedUserOperation({\n sender: address,\n ...userOpParams,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: contractName,\n version: '1',\n verifyingContract: address,\n },\n types: SIGNABLE_USER_OP_TYPED_DATA,\n primaryType: 'PackedUserOperation',\n message: { ...packedUserOp, entryPoint: entryPoint.address },\n });\n\n return signature;\n };\n\n const getAddress = async () => address;\n\n const encodeCalls = async (calls: readonly Call[]) =>\n encodeCallsForCaller(address, calls);\n\n const signerMethods = signer ?? {\n signMessage: async () => {\n throw new Error(\n 'Cannot sign message: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n signTypedData: async () => {\n throw new Error(\n 'Cannot sign typed data: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n getStubSignature: async () => {\n throw new Error(\n 'Cannot get stub signature: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n };\n\n const smartAccount = await toSmartAccount({\n abi,\n client,\n entryPoint,\n environment,\n getAddress,\n getFactoryArgs,\n encodeCalls,\n signUserOperation,\n signDelegation,\n nonceKeyManager,\n ...signerMethods,\n });\n\n // Override isDeployed only for EIP-7702 implementation to check proper delegation code\n if (implementation === Implementation.Stateless7702) {\n return {\n ...smartAccount,\n isDeployed: async () =>\n isValid7702Implementation({\n client,\n accountAddress: address,\n environment,\n }),\n };\n }\n\n // For other implementations, use the default isDeployed behavior\n return smartAccount;\n}\n","import { concat } from 'viem';\nimport type {\n Address,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from 'viem';\nimport type { WebAuthnAccount } from 'viem/account-abstraction';\n\nimport { Implementation } from './constants';\nimport { aggregateSignature } from './signatures';\nimport type {\n AccountSignerConfig,\n HybridSignerConfig,\n InternalSigner,\n MultiSigSignerConfig,\n SignerConfigByImplementation,\n Stateless7702SignerConfig,\n WalletSignerConfig,\n} from './types';\nimport {\n createDummyWebAuthnSignature,\n encodeDeleGatorSignature,\n} from './webAuthn';\n\n// A valid ECDSA signature, this must be able to ecrecover an address, otherwise the contracts will revert in isValidSignature\nconst EOA_STUB_SIGNATURE =\n '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000011b' as const;\n\nconst resolveSignerFromWalletConfig = (\n config: WalletSignerConfig,\n): InternalSigner => {\n return {\n signMessage: config.walletClient.signMessage,\n signTypedData: async (typedData) => {\n // todo: figure out this type so that we don't need the type assertion\n return config.walletClient.signTypedData(typedData as any);\n },\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveSignerFromAccountConfig = (config: AccountSignerConfig) => {\n return {\n signMessage: config.account.signMessage,\n signTypedData: config.account.signTypedData,\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveHybridSigner = (config: HybridSignerConfig): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n const { keyId, webAuthnAccount } = config;\n\n if (webAuthnAccount.type !== 'webAuthn') {\n throw new Error('Account is not a webAuthn account');\n }\n\n const encodeSignature = (\n result: Awaited<ReturnType<WebAuthnAccount['signMessage']>>,\n ) =>\n encodeDeleGatorSignature(\n keyId,\n result.signature,\n result.webauthn.clientDataJSON,\n result.webauthn.authenticatorData,\n );\n\n const signMessage = async (args: { message: SignableMessage }) =>\n webAuthnAccount.signMessage(args).then(encodeSignature);\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);\n\n const getStubSignature = async () => createDummyWebAuthnSignature(keyId);\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveMultiSigSigner = (\n config: MultiSigSignerConfig,\n): InternalSigner => {\n const resolvedSigners = config.map((signer) => {\n let individualSignMessage: InternalSigner['signMessage'];\n let individualSignTypedData: InternalSigner['signTypedData'];\n let address: Address;\n if ('walletClient' in signer) {\n const { signMessage, signTypedData } =\n resolveSignerFromWalletConfig(signer);\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.walletClient.account.address;\n } else {\n const { signMessage, signTypedData } =\n resolveSignerFromAccountConfig(signer);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.account.address;\n }\n return {\n address,\n individualSignMessage,\n individualSignTypedData,\n };\n });\n\n const signMessage = async (args: { message: SignableMessage }) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignMessage, address }) => ({\n signature: await individualSignMessage(args),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignTypedData, address }) => ({\n signature: await individualSignTypedData(typedDataDefinition),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const getStubSignature = async () =>\n concat(resolvedSigners.map(() => EOA_STUB_SIGNATURE));\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveStateless7702Signer = (\n config: Stateless7702SignerConfig,\n): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n\n throw new Error('Invalid signer config');\n};\n\n/**\n * Resolve a signer from a configuration object.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null {\n const { implementation, signer } = config;\n\n if (!signer) {\n return null;\n }\n\n if (implementation === Implementation.Hybrid) {\n return resolveHybridSigner(signer as HybridSignerConfig);\n } else if (implementation === Implementation.MultiSig) {\n return resolveMultiSigSigner(signer as MultiSigSignerConfig);\n } else if (implementation === Implementation.Stateless7702) {\n return resolveStateless7702Signer(signer as Stateless7702SignerConfig);\n }\n throw new Error(`Implementation type '${implementation}' not supported`);\n}\n","import type { Address, Hex } from 'viem';\nimport { concat } from 'viem';\n\nimport { trackSmartAccountsKitFunctionCall } from './analytics';\n\nconst signatureTypes = ['ECDSA'] as const;\n\nexport type SignatureType = (typeof signatureTypes)[number];\n\n/**\n * Represents a partial signature that can be aggregated with others.\n */\nexport type PartialSignature = {\n signer: Address;\n signature: Hex;\n type: SignatureType;\n};\n\n/**\n * Aggregates signatures into a single signature as expected by the MultiSig implementation.\n *\n * @param params - The parameters for signature aggregation.\n * @param params.signatures - The array of partial signatures to aggregate.\n * @returns The aggregated signature.\n */\nexport const aggregateSignature = ({\n signatures,\n}: {\n signatures: PartialSignature[];\n}): Hex => {\n trackSmartAccountsKitFunctionCall('aggregateSignature', {\n signatureCount: signatures.length,\n });\n\n if (signatures.length === 0) {\n return '0x';\n }\n\n for (const { type } of signatures) {\n if (!signatureTypes.includes(type)) {\n throw new Error(`Invalid signature type: ${type}`);\n }\n }\n\n // Sort signatures by signer address as required by MultiSig implementation\n const sortedSignatures = [...signatures].sort((a, b) =>\n a.signer.localeCompare(b.signer),\n );\n\n // Concatenate all signatures\n return concat(sortedSignatures.map(({ signature }) => signature));\n};\n\n/**\n * Type definition for the aggregateSignature function parameters.\n */\nexport type AggregateSignatureParams = {\n signatures: PartialSignature[];\n};\n","import type { Client, Transport, Chain, Account } from 'viem';\n\nimport { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport type { SmartAccountsEnvironment } from '../types';\nimport {\n caveatEnforcerActions,\n type CaveatEnforcerParams,\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\n/**\n * Type for client extended with caveat enforcer actions.\n */\nexport type CaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n> = Client<TTransport, TChain, TAccount> &\n ReturnType<ReturnType<typeof caveatEnforcerActions>>;\n\n/**\n * Create a viem client extended with caveat enforcer actions.\n *\n * @param params - The parameters object.\n * @param params.client - The viem client.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns The extended client with caveat enforcer actions.\n */\nexport function createCaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n>({\n client,\n environment,\n}: {\n client: Client<TTransport, TChain, TAccount>;\n environment: SmartAccountsEnvironment;\n}): CaveatEnforcerClient<TTransport, TChain, TAccount> {\n trackSmartAccountsKitFunctionCall('createCaveatEnforcerClient', {\n chainId: client.chain?.id ?? null,\n });\n\n return client.extend(caveatEnforcerActions({ environment }));\n}\n\n// Re-export types for convenience\nexport type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };\n","import type { Transport, Chain, Hex, Client, Account } from 'viem';\nimport {\n createBundlerClient,\n type BundlerClient,\n type BundlerClientConfig,\n type SmartAccount,\n} from 'viem/account-abstraction';\n\nimport { trackSmartAccountsKitFunctionCall } from '../analytics';\n\n/**\n * Gas price tiers returned by pimlico_getUserOperationGasPrice\n */\nexport type GasPriceTier = {\n /** Maximum fee per gas in hex format */\n maxFeePerGas: Hex;\n /** Maximum priority fee per gas in hex format */\n maxPriorityFeePerGas: Hex;\n};\n\n/**\n * Response from pimlico_getUserOperationGasPrice RPC method\n */\nexport type UserOperationGasPriceResponse = {\n /** Slow gas price tier */\n slow: GasPriceTier;\n /** Standard gas price tier */\n standard: GasPriceTier;\n /** Fast gas price tier */\n fast: GasPriceTier;\n};\n\n/**\n * Pimlico bundler schema for type-safe RPC method calls\n */\n/* eslint-disable @typescript-eslint/naming-convention */\ntype PimlicoBundlerSchema = [\n {\n Method: 'pimlico_getUserOperationGasPrice';\n Parameters: [];\n ReturnType: UserOperationGasPriceResponse;\n },\n];\n\n/**\n * Infura bundler actions for extending bundler clients.\n *\n * @returns A function that takes a client and returns the client extension with Infura bundler actions.\n */\nconst infuraBundlerActions = () => (client: Client) => ({\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n * @example\n * ```typescript\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * console.log(gasPrices.standard.maxFeePerGas);\n * ```\n */\n async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> {\n const pimlicoClient = client as Client<\n Transport,\n Chain | undefined,\n Account | undefined,\n PimlicoBundlerSchema\n >;\n\n return await pimlicoClient.request({\n method: 'pimlico_getUserOperationGasPrice',\n params: [],\n });\n },\n});\n\n/**\n * Type for bundler client extended with Infura bundler actions.\n */\nexport type InfuraBundlerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = BundlerClient<TTransport, TChain, TAccount> & {\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n */\n getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse>;\n};\n\n/**\n * Creates an Infura bundler client extended with Infura bundler actions.\n *\n * This is a wrapper around viem's createBundlerClient that extends it with\n * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's\n * bundler infrastructure via Infura's proxy.\n *\n * @param config - Configuration for the bundler client.\n * @returns Extended bundler client with Infura bundler actions.\n * @example\n * ```typescript\n * import { createPublicClient, http } from 'viem';\n * import { sepolia } from 'viem/chains';\n * import { createInfuraBundlerClient } from '@metamask/smart-accounts-kit';\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * });\n *\n * const bundlerClient = createInfuraBundlerClient({\n * client: publicClient,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * chain: sepolia,\n * });\n *\n * // Use standard bundler methods\n * const userOpHash = await bundlerClient.sendUserOperation({...});\n *\n * // Use Infura specific methods\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * ```\n */\nexport function createInfuraBundlerClient<\n TTransport extends Transport,\n TChain extends Chain | undefined = undefined,\n TAccount extends SmartAccount | undefined = undefined,\n>(\n config: BundlerClientConfig<TTransport, TChain, TAccount>,\n): InfuraBundlerClient<TTransport, TChain, TAccount> {\n trackSmartAccountsKitFunctionCall('createInfuraBundlerClient', {\n chainId: config.chain?.id ?? null,\n });\n // Create the base bundler client using viem's function\n const baseBundlerClient = createBundlerClient(config);\n\n // Extend the client with Infura bundler actions\n return baseBundlerClient.extend(\n infuraBundlerActions(),\n ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>;\n}\n"]}
|