@metamask/smart-accounts-kit 0.4.0-beta.0 → 0.4.0-beta.2
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 +49 -1
- package/dist/actions/index.cjs +5 -5
- package/dist/actions/index.d.cts +2 -2
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.mjs +4 -4
- package/dist/{chunk-S2Q5ZC64.cjs → chunk-23YXLKTX.cjs} +58 -59
- package/dist/chunk-23YXLKTX.cjs.map +1 -0
- package/dist/{chunk-W6ZI7GWI.mjs → chunk-33AMUJBJ.mjs} +49 -52
- package/dist/chunk-33AMUJBJ.mjs.map +1 -0
- package/dist/{chunk-TEH426Y4.mjs → chunk-C5ZEEH2Z.mjs} +283 -184
- package/dist/chunk-C5ZEEH2Z.mjs.map +1 -0
- package/dist/{chunk-NTZ57GNF.cjs → chunk-DLD377CN.cjs} +17 -33
- package/dist/chunk-DLD377CN.cjs.map +1 -0
- package/dist/{chunk-5BYJZGRI.mjs → chunk-NOCLGZGB.mjs} +174 -129
- package/dist/chunk-NOCLGZGB.mjs.map +1 -0
- package/dist/{chunk-EHIZB5U7.mjs → chunk-QCULIK3O.mjs} +211 -97
- package/dist/chunk-QCULIK3O.mjs.map +1 -0
- package/dist/{chunk-YWRHYLKB.cjs → chunk-QMRKCB7T.cjs} +204 -159
- package/dist/chunk-QMRKCB7T.cjs.map +1 -0
- package/dist/{chunk-TXN7GX6Y.cjs → chunk-SOFB2MXG.cjs} +207 -93
- package/dist/chunk-SOFB2MXG.cjs.map +1 -0
- package/dist/{chunk-RAXFJGCS.cjs → chunk-UUOH2WAW.cjs} +19 -19
- package/dist/chunk-UUOH2WAW.cjs.map +1 -0
- package/dist/{chunk-AUCZDOTJ.mjs → chunk-WPVSFOQM.mjs} +11 -27
- package/dist/chunk-WPVSFOQM.mjs.map +1 -0
- package/dist/{chunk-4A5RMDDC.mjs → chunk-WV2R7BXP.mjs} +49 -50
- package/dist/chunk-WV2R7BXP.mjs.map +1 -0
- package/dist/{chunk-YTGYVHDF.cjs → chunk-XN36L4RX.cjs} +144 -147
- package/dist/chunk-XN36L4RX.cjs.map +1 -0
- package/dist/{chunk-MIP7KJYH.cjs → chunk-YDLLC6PP.cjs} +252 -153
- package/dist/chunk-YDLLC6PP.cjs.map +1 -0
- package/dist/{chunk-DPWYECSV.mjs → chunk-YTELOQ4I.mjs} +9 -9
- package/dist/chunk-YTELOQ4I.mjs.map +1 -0
- package/dist/contracts/index.cjs +5 -5
- package/dist/contracts/index.d.cts +3 -3
- package/dist/contracts/index.d.ts +3 -3
- package/dist/contracts/index.mjs +4 -4
- package/dist/{delegation-DHjM_pVa.d.ts → delegation-DGUfyX-C.d.ts} +52 -26
- package/dist/{delegation-BnhAvKt4.d.cts → delegation-D_TY-tAq.d.cts} +52 -26
- package/dist/experimental/index.cjs +4 -4
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/index.d.cts +1 -1
- package/dist/experimental/index.d.ts +1 -1
- package/dist/experimental/index.mjs +5 -5
- package/dist/experimental/index.mjs.map +1 -1
- package/dist/{index-CX3hrztI.d.cts → index-B9bsjGqI.d.ts} +240 -38
- package/dist/{index-D04LO0vH.d.cts → index-CZes99jV.d.cts} +95 -62
- package/dist/{index-i8cod4JY.d.ts → index-DvcKJcXi.d.cts} +240 -38
- package/dist/{index-BlgCQ80b.d.ts → index-FpCh2419.d.ts} +95 -62
- package/dist/index.cjs +26 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -11
- package/dist/index.d.ts +9 -11
- package/dist/index.mjs +17 -15
- package/dist/index.mjs.map +1 -1
- package/dist/{smartAccountsEnvironment-SVknZ_3f.d.cts → smartAccountsEnvironment-BU8kjlEv.d.cts} +1 -1
- package/dist/{smartAccountsEnvironment-BOhrxEnt.d.ts → smartAccountsEnvironment-egxuflDO.d.ts} +1 -1
- package/dist/{types-Bwksz_U6.d.ts → types-BLYWtcR3.d.cts} +49 -31
- package/dist/{types-Bwksz_U6.d.cts → types-BLYWtcR3.d.ts} +49 -31
- package/dist/utils/index.cjs +7 -5
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +3 -4
- package/dist/utils/index.d.ts +3 -4
- package/dist/utils/index.mjs +12 -10
- package/package.json +6 -11
- package/dist/chunk-4A5RMDDC.mjs.map +0 -1
- package/dist/chunk-5BYJZGRI.mjs.map +0 -1
- package/dist/chunk-AUCZDOTJ.mjs.map +0 -1
- package/dist/chunk-DPWYECSV.mjs.map +0 -1
- package/dist/chunk-EHIZB5U7.mjs.map +0 -1
- package/dist/chunk-MIP7KJYH.cjs.map +0 -1
- package/dist/chunk-NTZ57GNF.cjs.map +0 -1
- package/dist/chunk-RAXFJGCS.cjs.map +0 -1
- package/dist/chunk-S2Q5ZC64.cjs.map +0 -1
- package/dist/chunk-TEH426Y4.mjs.map +0 -1
- package/dist/chunk-TXN7GX6Y.cjs.map +0 -1
- package/dist/chunk-W6ZI7GWI.mjs.map +0 -1
- package/dist/chunk-YTGYVHDF.cjs.map +0 -1
- package/dist/chunk-YWRHYLKB.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hex, AbiFunction, Address, AbiParameter, TypedData } from 'viem';
|
|
2
|
-
import { S as SmartAccountsEnvironment, C as Caveat, k as
|
|
2
|
+
import { S as SmartAccountsEnvironment, C as Caveat, k as CaveatType, j as ScopeType, D as Delegation, P as PermissionContext } from './types-BLYWtcR3.js';
|
|
3
3
|
|
|
4
4
|
type AllowedCalldataBuilderConfig = {
|
|
5
5
|
startIndex: number;
|
|
@@ -76,7 +76,6 @@ type Erc20BalanceChangeBuilderConfig = {
|
|
|
76
76
|
};
|
|
77
77
|
declare const erc20BalanceChangeBuilder: (environment: SmartAccountsEnvironment, config: Erc20BalanceChangeBuilderConfig) => Caveat;
|
|
78
78
|
|
|
79
|
-
declare const erc20PeriodTransfer = "erc20PeriodTransfer";
|
|
80
79
|
type Erc20PeriodTransferBuilderConfig = {
|
|
81
80
|
tokenAddress: Address;
|
|
82
81
|
periodAmount: bigint;
|
|
@@ -85,7 +84,6 @@ type Erc20PeriodTransferBuilderConfig = {
|
|
|
85
84
|
};
|
|
86
85
|
declare const erc20PeriodTransferBuilder: (environment: SmartAccountsEnvironment, config: Erc20PeriodTransferBuilderConfig) => Caveat;
|
|
87
86
|
|
|
88
|
-
declare const erc20Streaming = "erc20Streaming";
|
|
89
87
|
type Erc20StreamingBuilderConfig = {
|
|
90
88
|
tokenAddress: Address;
|
|
91
89
|
initialAmount: bigint;
|
|
@@ -95,7 +93,6 @@ type Erc20StreamingBuilderConfig = {
|
|
|
95
93
|
};
|
|
96
94
|
declare const erc20StreamingBuilder: (environment: SmartAccountsEnvironment, config: Erc20StreamingBuilderConfig) => Caveat;
|
|
97
95
|
|
|
98
|
-
declare const erc20TransferAmount = "erc20TransferAmount";
|
|
99
96
|
type Erc20TransferAmountBuilderConfig = {
|
|
100
97
|
tokenAddress: Address;
|
|
101
98
|
maxAmount: bigint;
|
|
@@ -110,13 +107,34 @@ type Erc721BalanceChangeBuilderConfig = {
|
|
|
110
107
|
};
|
|
111
108
|
declare const erc721BalanceChangeBuilder: (environment: SmartAccountsEnvironment, config: Erc721BalanceChangeBuilderConfig) => Caveat;
|
|
112
109
|
|
|
113
|
-
declare const erc721Transfer = "erc721Transfer";
|
|
114
110
|
type Erc721TransferBuilderConfig = {
|
|
115
111
|
tokenAddress: Address;
|
|
116
112
|
tokenId: bigint;
|
|
117
113
|
};
|
|
118
114
|
declare const erc721TransferBuilder: (environment: SmartAccountsEnvironment, config: Erc721TransferBuilderConfig) => Caveat;
|
|
119
115
|
|
|
116
|
+
type ExecutionStruct = {
|
|
117
|
+
target: Address;
|
|
118
|
+
value: bigint;
|
|
119
|
+
callData: Hex;
|
|
120
|
+
};
|
|
121
|
+
type CreateExecutionArgs = {
|
|
122
|
+
target: Address;
|
|
123
|
+
value?: bigint;
|
|
124
|
+
callData?: Hex;
|
|
125
|
+
};
|
|
126
|
+
declare const createExecution: ({ target, value, callData, }: CreateExecutionArgs) => ExecutionStruct;
|
|
127
|
+
declare enum ExecutionMode {
|
|
128
|
+
SingleDefault = "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
129
|
+
SingleTry = "0x0001000000000000000000000000000000000000000000000000000000000000",
|
|
130
|
+
BatchDefault = "0x0100000000000000000000000000000000000000000000000000000000000000",
|
|
131
|
+
BatchTry = "0x0101000000000000000000000000000000000000000000000000000000000000"
|
|
132
|
+
}
|
|
133
|
+
declare const encodeSingleExecution: (execution: ExecutionStruct) => Hex;
|
|
134
|
+
declare const encodeBatchExecution: (executions: ExecutionStruct[]) => Hex;
|
|
135
|
+
declare const encodeExecutionCalldata: (executions: ExecutionStruct[]) => Hex;
|
|
136
|
+
declare const encodeExecutionCalldatas: (executionsBatch: ExecutionStruct[][]) => Hex[];
|
|
137
|
+
|
|
120
138
|
type ExactCalldataBatchBuilderConfig = {
|
|
121
139
|
executions: ExecutionStruct[];
|
|
122
140
|
};
|
|
@@ -171,7 +189,6 @@ type NativeTokenPaymentBuilderConfig = {
|
|
|
171
189
|
};
|
|
172
190
|
declare const nativeTokenPaymentBuilder: (environment: SmartAccountsEnvironment, config: NativeTokenPaymentBuilderConfig) => Caveat;
|
|
173
191
|
|
|
174
|
-
declare const nativeTokenPeriodTransfer = "nativeTokenPeriodTransfer";
|
|
175
192
|
type NativeTokenPeriodTransferBuilderConfig = {
|
|
176
193
|
periodAmount: bigint;
|
|
177
194
|
periodDuration: number;
|
|
@@ -179,7 +196,6 @@ type NativeTokenPeriodTransferBuilderConfig = {
|
|
|
179
196
|
};
|
|
180
197
|
declare const nativeTokenPeriodTransferBuilder: (environment: SmartAccountsEnvironment, config: NativeTokenPeriodTransferBuilderConfig) => Caveat;
|
|
181
198
|
|
|
182
|
-
declare const nativeTokenStreaming = "nativeTokenStreaming";
|
|
183
199
|
type NativeTokenStreamingBuilderConfig = {
|
|
184
200
|
initialAmount: bigint;
|
|
185
201
|
maxAmount: bigint;
|
|
@@ -188,7 +204,6 @@ type NativeTokenStreamingBuilderConfig = {
|
|
|
188
204
|
};
|
|
189
205
|
declare const nativeTokenStreamingBuilder: (environment: SmartAccountsEnvironment, config: NativeTokenStreamingBuilderConfig) => Caveat;
|
|
190
206
|
|
|
191
|
-
declare const nativeTokenTransferAmount = "nativeTokenTransferAmount";
|
|
192
207
|
type NativeTokenTransferAmountBuilderConfig = {
|
|
193
208
|
maxAmount: bigint;
|
|
194
209
|
};
|
|
@@ -199,7 +214,6 @@ type NonceBuilderConfig = {
|
|
|
199
214
|
};
|
|
200
215
|
declare const nonceBuilder: (environment: SmartAccountsEnvironment, config: NonceBuilderConfig) => Caveat;
|
|
201
216
|
|
|
202
|
-
declare const ownershipTransfer = "ownershipTransfer";
|
|
203
217
|
type OwnershipTransferBuilderConfig = {
|
|
204
218
|
contractAddress: Address;
|
|
205
219
|
};
|
|
@@ -230,7 +244,7 @@ type ValueLteBuilderConfig = {
|
|
|
230
244
|
};
|
|
231
245
|
declare const valueLteBuilder: (environment: SmartAccountsEnvironment, config: ValueLteBuilderConfig) => Caveat;
|
|
232
246
|
|
|
233
|
-
type
|
|
247
|
+
type CoreCaveatMapByString = {
|
|
234
248
|
allowedMethods: typeof allowedMethodsBuilder;
|
|
235
249
|
allowedTargets: typeof allowedTargetsBuilder;
|
|
236
250
|
deployed: typeof deployedBuilder;
|
|
@@ -263,6 +277,9 @@ type CoreCaveatMap = {
|
|
|
263
277
|
multiTokenPeriod: typeof multiTokenPeriodBuilder;
|
|
264
278
|
ownershipTransfer: typeof ownershipTransferBuilder;
|
|
265
279
|
};
|
|
280
|
+
type CoreCaveatMap = CoreCaveatMapByString & {
|
|
281
|
+
[K in CaveatType as `${K}`]: CoreCaveatMapByString[`${K}`];
|
|
282
|
+
};
|
|
266
283
|
type CoreCaveatBuilder = CaveatBuilder<CoreCaveatMap>;
|
|
267
284
|
type ExtractCaveatMapType<TCaveatBuilder extends CaveatBuilder<any>> = TCaveatBuilder extends CaveatBuilder<infer TCaveatMap> ? TCaveatMap : never;
|
|
268
285
|
type CaveatConfiguration<TCaveatBuilder extends CaveatBuilder<any>, CaveatMap = ExtractCaveatMapType<TCaveatBuilder>> = CaveatMap extends Record<string, (...args: any[]) => any> ? {
|
|
@@ -274,24 +291,24 @@ type CoreCaveatConfiguration = CaveatConfiguration<CoreCaveatBuilder>;
|
|
|
274
291
|
declare const createCaveatBuilder: (environment: SmartAccountsEnvironment, config?: CaveatBuilderConfig) => CoreCaveatBuilder;
|
|
275
292
|
|
|
276
293
|
type Erc20PeriodicScopeConfig = {
|
|
277
|
-
type:
|
|
294
|
+
type: ScopeType.Erc20PeriodTransfer;
|
|
278
295
|
} & Erc20PeriodTransferBuilderConfig;
|
|
279
296
|
|
|
280
297
|
type Erc20StreamingScopeConfig = {
|
|
281
|
-
type:
|
|
298
|
+
type: ScopeType.Erc20Streaming;
|
|
282
299
|
} & Erc20StreamingBuilderConfig;
|
|
283
300
|
|
|
284
301
|
type Erc20TransferScopeConfig = {
|
|
285
|
-
type:
|
|
302
|
+
type: ScopeType.Erc20TransferAmount;
|
|
286
303
|
} & Erc20TransferAmountBuilderConfig;
|
|
287
304
|
|
|
288
305
|
type Erc721ScopeBaseConfig = {
|
|
289
|
-
type:
|
|
306
|
+
type: ScopeType.Erc721Transfer;
|
|
290
307
|
};
|
|
291
308
|
type Erc721ScopeConfig = Erc721ScopeBaseConfig & Erc721TransferBuilderConfig;
|
|
292
309
|
|
|
293
310
|
type FunctionCallScopeBaseConfig = {
|
|
294
|
-
type:
|
|
311
|
+
type: ScopeType.FunctionCall;
|
|
295
312
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
296
313
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
297
314
|
valueLte?: ValueLteBuilderConfig;
|
|
@@ -299,29 +316,37 @@ type FunctionCallScopeBaseConfig = {
|
|
|
299
316
|
type FunctionCallScopeConfig = FunctionCallScopeBaseConfig & AllowedTargetsBuilderConfig & AllowedMethodsBuilderConfig;
|
|
300
317
|
|
|
301
318
|
type NativeTokenPeriodicScopeConfig = {
|
|
302
|
-
type:
|
|
319
|
+
type: ScopeType.NativeTokenPeriodTransfer;
|
|
303
320
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
304
321
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
305
322
|
} & NativeTokenPeriodTransferBuilderConfig;
|
|
306
323
|
|
|
307
324
|
type NativeTokenStreamingScopeConfig = {
|
|
308
|
-
type:
|
|
325
|
+
type: ScopeType.NativeTokenStreaming;
|
|
309
326
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
310
327
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
311
328
|
} & NativeTokenStreamingBuilderConfig;
|
|
312
329
|
|
|
313
330
|
type NativeTokenTransferScopeConfig = {
|
|
314
|
-
type:
|
|
331
|
+
type: ScopeType.NativeTokenTransferAmount;
|
|
315
332
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
316
333
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
317
334
|
} & NativeTokenTransferAmountBuilderConfig;
|
|
318
335
|
|
|
319
336
|
type OwnershipScopeBaseConfig = {
|
|
320
|
-
type:
|
|
337
|
+
type: ScopeType.OwnershipTransfer;
|
|
321
338
|
};
|
|
322
339
|
type OwnershipScopeConfig = OwnershipScopeBaseConfig & OwnershipTransferBuilderConfig;
|
|
323
340
|
|
|
324
|
-
type
|
|
341
|
+
type ConvertScopeConfigsToInputs<T extends {
|
|
342
|
+
type: ScopeType;
|
|
343
|
+
}> = T extends {
|
|
344
|
+
type: ScopeType;
|
|
345
|
+
} ? Omit<T, 'type'> & {
|
|
346
|
+
type: T['type'] | `${T['type']}`;
|
|
347
|
+
} : never;
|
|
348
|
+
type ScopeConfigBase = Erc20TransferScopeConfig | Erc20StreamingScopeConfig | Erc20PeriodicScopeConfig | NativeTokenTransferScopeConfig | NativeTokenStreamingScopeConfig | NativeTokenPeriodicScopeConfig | Erc721ScopeConfig | OwnershipScopeConfig | FunctionCallScopeConfig;
|
|
349
|
+
type ScopeConfig = ConvertScopeConfigsToInputs<ScopeConfigBase>;
|
|
325
350
|
|
|
326
351
|
type Caveats = CaveatBuilder | (Caveat | CoreCaveatConfiguration)[];
|
|
327
352
|
|
|
@@ -342,13 +367,14 @@ declare const toDelegation: (delegationStruct: DelegationStruct) => Delegation;
|
|
|
342
367
|
type DelegationStruct = Omit<Delegation, 'salt'> & {
|
|
343
368
|
salt: bigint;
|
|
344
369
|
};
|
|
345
|
-
declare const encodeDelegations: (delegations:
|
|
346
|
-
declare const
|
|
347
|
-
declare const decodeDelegations: (
|
|
348
|
-
declare const
|
|
370
|
+
declare const encodeDelegations: (delegations: PermissionContext) => Hex;
|
|
371
|
+
declare const encodeDelegation: (delegation: Delegation) => Hex;
|
|
372
|
+
declare const decodeDelegations: (delegations: PermissionContext) => Delegation[];
|
|
373
|
+
declare const decodeDelegation: (encoded: Hex) => Delegation;
|
|
349
374
|
declare const SIGNABLE_DELEGATION_TYPED_DATA: TypedData;
|
|
350
375
|
declare const DELEGATION_ARRAY_ABI_TYPE: AbiParameter;
|
|
351
|
-
declare const
|
|
376
|
+
declare const DELEGATION_ABI_TYPE: AbiParameter;
|
|
377
|
+
declare const hashDelegation: (input: Delegation) => Hex;
|
|
352
378
|
type BaseCreateDelegationOptions = {
|
|
353
379
|
environment: SmartAccountsEnvironment;
|
|
354
380
|
scope: ScopeConfig;
|
|
@@ -373,4 +399,4 @@ declare const signDelegation: ({ privateKey, delegation, delegationManager, chai
|
|
|
373
399
|
allowInsecureUnrestrictedDelegation?: boolean;
|
|
374
400
|
}) => Promise<`0x${string}`>;
|
|
375
401
|
|
|
376
|
-
export { BalanceChangeType as B, type CreateDelegationOptions as C, DELEGATION_ARRAY_ABI_TYPE as D, SIGNABLE_DELEGATION_TYPED_DATA as S, createOpenDelegation as a, type CreateOpenDelegationOptions as b, createDelegation as c,
|
|
402
|
+
export { BalanceChangeType as B, type CreateDelegationOptions as C, DELEGATION_ARRAY_ABI_TYPE as D, ExecutionMode as E, SIGNABLE_DELEGATION_TYPED_DATA as S, createOpenDelegation as a, type CreateOpenDelegationOptions as b, createDelegation as c, createExecution as d, type ExecutionStruct as e, type CreateExecutionArgs as f, type Caveats as g, encodeDelegations as h, decodeDelegations as i, encodeDelegation as j, decodeDelegation as k, toDelegation as l, DELEGATION_ABI_TYPE as m, DELEGATION_ABI_TYPE_COMPONENTS as n, hashDelegation as o, type DelegationStruct as p, encodeExecutionCalldata as q, encodeExecutionCalldatas as r, signDelegation as s, toDelegationStruct as t, encodeSingleExecution as u, encodeBatchExecution as v, type CoreCaveatBuilder as w, type CaveatBuilderConfig as x, createCaveatBuilder as y, CaveatBuilder as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hex, AbiFunction, Address, AbiParameter, TypedData } from 'viem';
|
|
2
|
-
import { S as SmartAccountsEnvironment, C as Caveat, k as
|
|
2
|
+
import { S as SmartAccountsEnvironment, C as Caveat, k as CaveatType, j as ScopeType, D as Delegation, P as PermissionContext } from './types-BLYWtcR3.cjs';
|
|
3
3
|
|
|
4
4
|
type AllowedCalldataBuilderConfig = {
|
|
5
5
|
startIndex: number;
|
|
@@ -76,7 +76,6 @@ type Erc20BalanceChangeBuilderConfig = {
|
|
|
76
76
|
};
|
|
77
77
|
declare const erc20BalanceChangeBuilder: (environment: SmartAccountsEnvironment, config: Erc20BalanceChangeBuilderConfig) => Caveat;
|
|
78
78
|
|
|
79
|
-
declare const erc20PeriodTransfer = "erc20PeriodTransfer";
|
|
80
79
|
type Erc20PeriodTransferBuilderConfig = {
|
|
81
80
|
tokenAddress: Address;
|
|
82
81
|
periodAmount: bigint;
|
|
@@ -85,7 +84,6 @@ type Erc20PeriodTransferBuilderConfig = {
|
|
|
85
84
|
};
|
|
86
85
|
declare const erc20PeriodTransferBuilder: (environment: SmartAccountsEnvironment, config: Erc20PeriodTransferBuilderConfig) => Caveat;
|
|
87
86
|
|
|
88
|
-
declare const erc20Streaming = "erc20Streaming";
|
|
89
87
|
type Erc20StreamingBuilderConfig = {
|
|
90
88
|
tokenAddress: Address;
|
|
91
89
|
initialAmount: bigint;
|
|
@@ -95,7 +93,6 @@ type Erc20StreamingBuilderConfig = {
|
|
|
95
93
|
};
|
|
96
94
|
declare const erc20StreamingBuilder: (environment: SmartAccountsEnvironment, config: Erc20StreamingBuilderConfig) => Caveat;
|
|
97
95
|
|
|
98
|
-
declare const erc20TransferAmount = "erc20TransferAmount";
|
|
99
96
|
type Erc20TransferAmountBuilderConfig = {
|
|
100
97
|
tokenAddress: Address;
|
|
101
98
|
maxAmount: bigint;
|
|
@@ -110,13 +107,34 @@ type Erc721BalanceChangeBuilderConfig = {
|
|
|
110
107
|
};
|
|
111
108
|
declare const erc721BalanceChangeBuilder: (environment: SmartAccountsEnvironment, config: Erc721BalanceChangeBuilderConfig) => Caveat;
|
|
112
109
|
|
|
113
|
-
declare const erc721Transfer = "erc721Transfer";
|
|
114
110
|
type Erc721TransferBuilderConfig = {
|
|
115
111
|
tokenAddress: Address;
|
|
116
112
|
tokenId: bigint;
|
|
117
113
|
};
|
|
118
114
|
declare const erc721TransferBuilder: (environment: SmartAccountsEnvironment, config: Erc721TransferBuilderConfig) => Caveat;
|
|
119
115
|
|
|
116
|
+
type ExecutionStruct = {
|
|
117
|
+
target: Address;
|
|
118
|
+
value: bigint;
|
|
119
|
+
callData: Hex;
|
|
120
|
+
};
|
|
121
|
+
type CreateExecutionArgs = {
|
|
122
|
+
target: Address;
|
|
123
|
+
value?: bigint;
|
|
124
|
+
callData?: Hex;
|
|
125
|
+
};
|
|
126
|
+
declare const createExecution: ({ target, value, callData, }: CreateExecutionArgs) => ExecutionStruct;
|
|
127
|
+
declare enum ExecutionMode {
|
|
128
|
+
SingleDefault = "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
129
|
+
SingleTry = "0x0001000000000000000000000000000000000000000000000000000000000000",
|
|
130
|
+
BatchDefault = "0x0100000000000000000000000000000000000000000000000000000000000000",
|
|
131
|
+
BatchTry = "0x0101000000000000000000000000000000000000000000000000000000000000"
|
|
132
|
+
}
|
|
133
|
+
declare const encodeSingleExecution: (execution: ExecutionStruct) => Hex;
|
|
134
|
+
declare const encodeBatchExecution: (executions: ExecutionStruct[]) => Hex;
|
|
135
|
+
declare const encodeExecutionCalldata: (executions: ExecutionStruct[]) => Hex;
|
|
136
|
+
declare const encodeExecutionCalldatas: (executionsBatch: ExecutionStruct[][]) => Hex[];
|
|
137
|
+
|
|
120
138
|
type ExactCalldataBatchBuilderConfig = {
|
|
121
139
|
executions: ExecutionStruct[];
|
|
122
140
|
};
|
|
@@ -171,7 +189,6 @@ type NativeTokenPaymentBuilderConfig = {
|
|
|
171
189
|
};
|
|
172
190
|
declare const nativeTokenPaymentBuilder: (environment: SmartAccountsEnvironment, config: NativeTokenPaymentBuilderConfig) => Caveat;
|
|
173
191
|
|
|
174
|
-
declare const nativeTokenPeriodTransfer = "nativeTokenPeriodTransfer";
|
|
175
192
|
type NativeTokenPeriodTransferBuilderConfig = {
|
|
176
193
|
periodAmount: bigint;
|
|
177
194
|
periodDuration: number;
|
|
@@ -179,7 +196,6 @@ type NativeTokenPeriodTransferBuilderConfig = {
|
|
|
179
196
|
};
|
|
180
197
|
declare const nativeTokenPeriodTransferBuilder: (environment: SmartAccountsEnvironment, config: NativeTokenPeriodTransferBuilderConfig) => Caveat;
|
|
181
198
|
|
|
182
|
-
declare const nativeTokenStreaming = "nativeTokenStreaming";
|
|
183
199
|
type NativeTokenStreamingBuilderConfig = {
|
|
184
200
|
initialAmount: bigint;
|
|
185
201
|
maxAmount: bigint;
|
|
@@ -188,7 +204,6 @@ type NativeTokenStreamingBuilderConfig = {
|
|
|
188
204
|
};
|
|
189
205
|
declare const nativeTokenStreamingBuilder: (environment: SmartAccountsEnvironment, config: NativeTokenStreamingBuilderConfig) => Caveat;
|
|
190
206
|
|
|
191
|
-
declare const nativeTokenTransferAmount = "nativeTokenTransferAmount";
|
|
192
207
|
type NativeTokenTransferAmountBuilderConfig = {
|
|
193
208
|
maxAmount: bigint;
|
|
194
209
|
};
|
|
@@ -199,7 +214,6 @@ type NonceBuilderConfig = {
|
|
|
199
214
|
};
|
|
200
215
|
declare const nonceBuilder: (environment: SmartAccountsEnvironment, config: NonceBuilderConfig) => Caveat;
|
|
201
216
|
|
|
202
|
-
declare const ownershipTransfer = "ownershipTransfer";
|
|
203
217
|
type OwnershipTransferBuilderConfig = {
|
|
204
218
|
contractAddress: Address;
|
|
205
219
|
};
|
|
@@ -230,7 +244,7 @@ type ValueLteBuilderConfig = {
|
|
|
230
244
|
};
|
|
231
245
|
declare const valueLteBuilder: (environment: SmartAccountsEnvironment, config: ValueLteBuilderConfig) => Caveat;
|
|
232
246
|
|
|
233
|
-
type
|
|
247
|
+
type CoreCaveatMapByString = {
|
|
234
248
|
allowedMethods: typeof allowedMethodsBuilder;
|
|
235
249
|
allowedTargets: typeof allowedTargetsBuilder;
|
|
236
250
|
deployed: typeof deployedBuilder;
|
|
@@ -263,6 +277,9 @@ type CoreCaveatMap = {
|
|
|
263
277
|
multiTokenPeriod: typeof multiTokenPeriodBuilder;
|
|
264
278
|
ownershipTransfer: typeof ownershipTransferBuilder;
|
|
265
279
|
};
|
|
280
|
+
type CoreCaveatMap = CoreCaveatMapByString & {
|
|
281
|
+
[K in CaveatType as `${K}`]: CoreCaveatMapByString[`${K}`];
|
|
282
|
+
};
|
|
266
283
|
type CoreCaveatBuilder = CaveatBuilder<CoreCaveatMap>;
|
|
267
284
|
type ExtractCaveatMapType<TCaveatBuilder extends CaveatBuilder<any>> = TCaveatBuilder extends CaveatBuilder<infer TCaveatMap> ? TCaveatMap : never;
|
|
268
285
|
type CaveatConfiguration<TCaveatBuilder extends CaveatBuilder<any>, CaveatMap = ExtractCaveatMapType<TCaveatBuilder>> = CaveatMap extends Record<string, (...args: any[]) => any> ? {
|
|
@@ -274,24 +291,24 @@ type CoreCaveatConfiguration = CaveatConfiguration<CoreCaveatBuilder>;
|
|
|
274
291
|
declare const createCaveatBuilder: (environment: SmartAccountsEnvironment, config?: CaveatBuilderConfig) => CoreCaveatBuilder;
|
|
275
292
|
|
|
276
293
|
type Erc20PeriodicScopeConfig = {
|
|
277
|
-
type:
|
|
294
|
+
type: ScopeType.Erc20PeriodTransfer;
|
|
278
295
|
} & Erc20PeriodTransferBuilderConfig;
|
|
279
296
|
|
|
280
297
|
type Erc20StreamingScopeConfig = {
|
|
281
|
-
type:
|
|
298
|
+
type: ScopeType.Erc20Streaming;
|
|
282
299
|
} & Erc20StreamingBuilderConfig;
|
|
283
300
|
|
|
284
301
|
type Erc20TransferScopeConfig = {
|
|
285
|
-
type:
|
|
302
|
+
type: ScopeType.Erc20TransferAmount;
|
|
286
303
|
} & Erc20TransferAmountBuilderConfig;
|
|
287
304
|
|
|
288
305
|
type Erc721ScopeBaseConfig = {
|
|
289
|
-
type:
|
|
306
|
+
type: ScopeType.Erc721Transfer;
|
|
290
307
|
};
|
|
291
308
|
type Erc721ScopeConfig = Erc721ScopeBaseConfig & Erc721TransferBuilderConfig;
|
|
292
309
|
|
|
293
310
|
type FunctionCallScopeBaseConfig = {
|
|
294
|
-
type:
|
|
311
|
+
type: ScopeType.FunctionCall;
|
|
295
312
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
296
313
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
297
314
|
valueLte?: ValueLteBuilderConfig;
|
|
@@ -299,29 +316,37 @@ type FunctionCallScopeBaseConfig = {
|
|
|
299
316
|
type FunctionCallScopeConfig = FunctionCallScopeBaseConfig & AllowedTargetsBuilderConfig & AllowedMethodsBuilderConfig;
|
|
300
317
|
|
|
301
318
|
type NativeTokenPeriodicScopeConfig = {
|
|
302
|
-
type:
|
|
319
|
+
type: ScopeType.NativeTokenPeriodTransfer;
|
|
303
320
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
304
321
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
305
322
|
} & NativeTokenPeriodTransferBuilderConfig;
|
|
306
323
|
|
|
307
324
|
type NativeTokenStreamingScopeConfig = {
|
|
308
|
-
type:
|
|
325
|
+
type: ScopeType.NativeTokenStreaming;
|
|
309
326
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
310
327
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
311
328
|
} & NativeTokenStreamingBuilderConfig;
|
|
312
329
|
|
|
313
330
|
type NativeTokenTransferScopeConfig = {
|
|
314
|
-
type:
|
|
331
|
+
type: ScopeType.NativeTokenTransferAmount;
|
|
315
332
|
allowedCalldata?: AllowedCalldataBuilderConfig[];
|
|
316
333
|
exactCalldata?: ExactCalldataBuilderConfig;
|
|
317
334
|
} & NativeTokenTransferAmountBuilderConfig;
|
|
318
335
|
|
|
319
336
|
type OwnershipScopeBaseConfig = {
|
|
320
|
-
type:
|
|
337
|
+
type: ScopeType.OwnershipTransfer;
|
|
321
338
|
};
|
|
322
339
|
type OwnershipScopeConfig = OwnershipScopeBaseConfig & OwnershipTransferBuilderConfig;
|
|
323
340
|
|
|
324
|
-
type
|
|
341
|
+
type ConvertScopeConfigsToInputs<T extends {
|
|
342
|
+
type: ScopeType;
|
|
343
|
+
}> = T extends {
|
|
344
|
+
type: ScopeType;
|
|
345
|
+
} ? Omit<T, 'type'> & {
|
|
346
|
+
type: T['type'] | `${T['type']}`;
|
|
347
|
+
} : never;
|
|
348
|
+
type ScopeConfigBase = Erc20TransferScopeConfig | Erc20StreamingScopeConfig | Erc20PeriodicScopeConfig | NativeTokenTransferScopeConfig | NativeTokenStreamingScopeConfig | NativeTokenPeriodicScopeConfig | Erc721ScopeConfig | OwnershipScopeConfig | FunctionCallScopeConfig;
|
|
349
|
+
type ScopeConfig = ConvertScopeConfigsToInputs<ScopeConfigBase>;
|
|
325
350
|
|
|
326
351
|
type Caveats = CaveatBuilder | (Caveat | CoreCaveatConfiguration)[];
|
|
327
352
|
|
|
@@ -342,13 +367,14 @@ declare const toDelegation: (delegationStruct: DelegationStruct) => Delegation;
|
|
|
342
367
|
type DelegationStruct = Omit<Delegation, 'salt'> & {
|
|
343
368
|
salt: bigint;
|
|
344
369
|
};
|
|
345
|
-
declare const encodeDelegations: (delegations:
|
|
346
|
-
declare const
|
|
347
|
-
declare const decodeDelegations: (
|
|
348
|
-
declare const
|
|
370
|
+
declare const encodeDelegations: (delegations: PermissionContext) => Hex;
|
|
371
|
+
declare const encodeDelegation: (delegation: Delegation) => Hex;
|
|
372
|
+
declare const decodeDelegations: (delegations: PermissionContext) => Delegation[];
|
|
373
|
+
declare const decodeDelegation: (encoded: Hex) => Delegation;
|
|
349
374
|
declare const SIGNABLE_DELEGATION_TYPED_DATA: TypedData;
|
|
350
375
|
declare const DELEGATION_ARRAY_ABI_TYPE: AbiParameter;
|
|
351
|
-
declare const
|
|
376
|
+
declare const DELEGATION_ABI_TYPE: AbiParameter;
|
|
377
|
+
declare const hashDelegation: (input: Delegation) => Hex;
|
|
352
378
|
type BaseCreateDelegationOptions = {
|
|
353
379
|
environment: SmartAccountsEnvironment;
|
|
354
380
|
scope: ScopeConfig;
|
|
@@ -373,4 +399,4 @@ declare const signDelegation: ({ privateKey, delegation, delegationManager, chai
|
|
|
373
399
|
allowInsecureUnrestrictedDelegation?: boolean;
|
|
374
400
|
}) => Promise<`0x${string}`>;
|
|
375
401
|
|
|
376
|
-
export { BalanceChangeType as B, type CreateDelegationOptions as C, DELEGATION_ARRAY_ABI_TYPE as D, SIGNABLE_DELEGATION_TYPED_DATA as S, createOpenDelegation as a, type CreateOpenDelegationOptions as b, createDelegation as c,
|
|
402
|
+
export { BalanceChangeType as B, type CreateDelegationOptions as C, DELEGATION_ARRAY_ABI_TYPE as D, ExecutionMode as E, SIGNABLE_DELEGATION_TYPED_DATA as S, createOpenDelegation as a, type CreateOpenDelegationOptions as b, createDelegation as c, createExecution as d, type ExecutionStruct as e, type CreateExecutionArgs as f, type Caveats as g, encodeDelegations as h, decodeDelegations as i, encodeDelegation as j, decodeDelegation as k, toDelegation as l, DELEGATION_ABI_TYPE as m, DELEGATION_ABI_TYPE_COMPONENTS as n, hashDelegation as o, type DelegationStruct as p, encodeExecutionCalldata as q, encodeExecutionCalldatas as r, signDelegation as s, toDelegationStruct as t, encodeSingleExecution as u, encodeBatchExecution as v, type CoreCaveatBuilder as w, type CaveatBuilderConfig as x, createCaveatBuilder as y, CaveatBuilder as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
-
var
|
|
3
|
+
var _chunkYDLLC6PPcjs = require('../chunk-YDLLC6PP.cjs');
|
|
4
4
|
|
|
5
5
|
// src/experimental/delegationStorage.ts
|
|
6
6
|
var _viem = require('viem');
|
|
@@ -51,7 +51,7 @@ var DelegationStorageClient = class {
|
|
|
51
51
|
* is not found.
|
|
52
52
|
*/
|
|
53
53
|
async getDelegationChain(leafDelegationOrDelegationHash) {
|
|
54
|
-
const leafDelegationHash = typeof leafDelegationOrDelegationHash === "string" ? leafDelegationOrDelegationHash :
|
|
54
|
+
const leafDelegationHash = typeof leafDelegationOrDelegationHash === "string" ? leafDelegationOrDelegationHash : _chunkYDLLC6PPcjs.hashDelegation.call(void 0, leafDelegationOrDelegationHash);
|
|
55
55
|
const response = await this.#fetcher(
|
|
56
56
|
`${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,
|
|
57
57
|
{
|
|
@@ -107,7 +107,7 @@ var DelegationStorageClient = class {
|
|
|
107
107
|
if (!delegation.signature || delegation.signature === "0x") {
|
|
108
108
|
throw new Error("Delegation must be signed to be stored");
|
|
109
109
|
}
|
|
110
|
-
const delegationHash =
|
|
110
|
+
const delegationHash = _chunkYDLLC6PPcjs.hashDelegation.call(void 0, delegation);
|
|
111
111
|
const body = JSON.stringify(
|
|
112
112
|
{
|
|
113
113
|
...delegation,
|
|
@@ -130,7 +130,7 @@ var DelegationStorageClient = class {
|
|
|
130
130
|
throw new Error(responseData.error);
|
|
131
131
|
}
|
|
132
132
|
if (responseData.delegationHash !== delegationHash) {
|
|
133
|
-
throw Error(
|
|
133
|
+
throw new Error(
|
|
134
134
|
"Failed to store the Delegation, the hash returned from the MM delegation storage API does not match the hash of the delegation"
|
|
135
135
|
);
|
|
136
136
|
}
|
|
@@ -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,CAAA,MAAA;AAAA,EAET,WAAA,CAAY,MAAA,EAAiC;AAC3C,IAAA,MAAM,EAAE,OAAO,EAAA,EAAI,MAAA,CAAO,WAAA;AAE1B,IAAA,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,IAAA,CAAK,CAAA,gBAAiB,CAAA,EAAG;AAC3C,MAAA,IAAA,CAAK,CAAA,OAAA,EAAU,MAAA;AAAA,IACjB,EAAA,KAAO;AACL,MAAA,MAAM,UAAA,EAAY,MAAA,CAAO,QAAA,CAAS,GAAG,EAAA,EAAI,GAAA,EAAK,GAAA;AAC9C,MAAA,IAAA,CAAK,CAAA,OAAA,EAAU,CAAA,EAAA;AACjB,IAAA;AACgB,IAAA;AACD,IAAA;AACjB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAamB,EAAA;AACN,IAAA;AACK,MAAA;AACE,IAAA;AACT,MAAA;AACT,IAAA;AACU,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWM,EAAA;AAGE,IAAA;AAKW,IAAA;AACA,MAAA;AACf,MAAA;AACU,QAAA;AACC,QAAA;AACP,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AAEM,IAAA;AAES,IAAA;AACH,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYM,EAAA;AAIa,IAAA;AACA,MAAA;AACf,MAAA;AACU,QAAA;AACC,QAAA;AACP,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AAEM,IAAA;AAES,IAAA;AACG,MAAA;AAClB,IAAA;AAEO,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQM,EAAA;AACY,IAAA;AACE,MAAA;AAClB,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;
|
|
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,CAAA,MAAA;AAAA,EAET,WAAA,CAAY,MAAA,EAAiC;AAC3C,IAAA,MAAM,EAAE,OAAO,EAAA,EAAI,MAAA,CAAO,WAAA;AAE1B,IAAA,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,IAAA,CAAK,CAAA,gBAAiB,CAAA,EAAG;AAC3C,MAAA,IAAA,CAAK,CAAA,OAAA,EAAU,MAAA;AAAA,IACjB,EAAA,KAAO;AACL,MAAA,MAAM,UAAA,EAAY,MAAA,CAAO,QAAA,CAAS,GAAG,EAAA,EAAI,GAAA,EAAK,GAAA;AAC9C,MAAA,IAAA,CAAK,CAAA,OAAA,EAAU,CAAA,EAAA;AACjB,IAAA;AACgB,IAAA;AACD,IAAA;AACjB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAamB,EAAA;AACN,IAAA;AACK,MAAA;AACE,IAAA;AACT,MAAA;AACT,IAAA;AACU,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWM,EAAA;AAGE,IAAA;AAKW,IAAA;AACA,MAAA;AACf,MAAA;AACU,QAAA;AACC,QAAA;AACP,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AAEM,IAAA;AAES,IAAA;AACH,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYM,EAAA;AAIa,IAAA;AACA,MAAA;AACf,MAAA;AACU,QAAA;AACC,QAAA;AACP,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AAEM,IAAA;AAES,IAAA;AACG,MAAA;AAClB,IAAA;AAEO,IAAA;AACT,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQM,EAAA;AACY,IAAA;AACE,MAAA;AAClB,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,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
hashDelegation
|
|
3
|
+
} from "../chunk-C5ZEEH2Z.mjs";
|
|
4
4
|
|
|
5
5
|
// src/experimental/delegationStorage.ts
|
|
6
6
|
import { toHex } from "viem";
|
|
@@ -51,7 +51,7 @@ var DelegationStorageClient = class {
|
|
|
51
51
|
* is not found.
|
|
52
52
|
*/
|
|
53
53
|
async getDelegationChain(leafDelegationOrDelegationHash) {
|
|
54
|
-
const leafDelegationHash = typeof leafDelegationOrDelegationHash === "string" ? leafDelegationOrDelegationHash :
|
|
54
|
+
const leafDelegationHash = typeof leafDelegationOrDelegationHash === "string" ? leafDelegationOrDelegationHash : hashDelegation(leafDelegationOrDelegationHash);
|
|
55
55
|
const response = await this.#fetcher(
|
|
56
56
|
`${this.#apiUrl}/delegation/chain/${leafDelegationHash}`,
|
|
57
57
|
{
|
|
@@ -107,7 +107,7 @@ var DelegationStorageClient = class {
|
|
|
107
107
|
if (!delegation.signature || delegation.signature === "0x") {
|
|
108
108
|
throw new Error("Delegation must be signed to be stored");
|
|
109
109
|
}
|
|
110
|
-
const delegationHash =
|
|
110
|
+
const delegationHash = hashDelegation(delegation);
|
|
111
111
|
const body = JSON.stringify(
|
|
112
112
|
{
|
|
113
113
|
...delegation,
|
|
@@ -130,7 +130,7 @@ var DelegationStorageClient = class {
|
|
|
130
130
|
throw new Error(responseData.error);
|
|
131
131
|
}
|
|
132
132
|
if (responseData.delegationHash !== delegationHash) {
|
|
133
|
-
throw Error(
|
|
133
|
+
throw new Error(
|
|
134
134
|
"Failed to store the Delegation, the hash returned from the MM delegation storage API does not match the hash of the delegation"
|
|
135
135
|
);
|
|
136
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/experimental/delegationStorage.ts"],"sourcesContent":["import { type Hex, toHex } from 'viem';\n\nimport {
|
|
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":"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","names":[]}
|