@account-kit/wallet-client 0.1.0-alpha.2 → 0.1.0-alpha.4
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/dist/esm/capabilities/index.d.ts +5 -2
- package/dist/esm/capabilities/index.js +1 -1
- package/dist/esm/capabilities/index.js.map +1 -1
- package/dist/esm/capabilities/overrides.js +8 -8
- package/dist/esm/capabilities/overrides.js.map +1 -1
- package/dist/esm/capabilities/permissions/index.d.ts +10 -3
- package/dist/esm/capabilities/permissions/index.js +11 -2
- package/dist/esm/capabilities/permissions/index.js.map +1 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +2 -2
- package/dist/esm/capabilities/permissions/mav2.js +9 -1
- package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +57 -3
- package/dist/esm/client/actions/grantPermissions.js +1 -0
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.js +2 -2
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +4 -1
- package/dist/esm/client/actions/signSignatureRequest.js +22 -1
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +13 -19
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/index.d.ts +4 -3
- package/dist/esm/client/index.js +2 -2
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +2 -2
- package/dist/esm/exports/index.js +1 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/isomorphic/actions/createSession.js +25 -7
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.js +35 -12
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +26 -6
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +11 -5
- package/dist/esm/isomorphic/utils/7702.d.ts +11 -0
- package/dist/esm/isomorphic/utils/7702.js +26 -0
- package/dist/esm/isomorphic/utils/7702.js.map +1 -0
- package/dist/esm/isomorphic/utils/createAccount.d.ts +2 -1
- package/dist/esm/isomorphic/utils/createAccount.js +30 -5
- package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
- package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +2 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +17 -5
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
- package/dist/esm/local/client.js +2 -1
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.js +6 -2
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/examples.d.ts +230 -0
- package/dist/esm/rpc/examples.js +314 -0
- package/dist/esm/rpc/examples.js.map +1 -0
- package/dist/esm/rpc/request.d.ts +48 -17
- package/dist/esm/rpc/request.js +53 -14
- package/dist/esm/rpc/request.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +42 -11
- package/dist/esm/schemas.d.ts +29 -7
- package/dist/esm/schemas.js +120 -38
- package/dist/esm/schemas.js.map +1 -1
- package/dist/types/capabilities/index.d.ts +5 -2
- package/dist/types/capabilities/index.d.ts.map +1 -1
- package/dist/types/capabilities/overrides.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/index.d.ts +10 -3
- package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +2 -2
- package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +57 -3
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +4 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +4 -3
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +2 -2
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +11 -5
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +12 -0
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/createAccount.d.ts +2 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +2 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/rpc/examples.d.ts +231 -0
- package/dist/types/rpc/examples.d.ts.map +1 -0
- package/dist/types/rpc/request.d.ts +48 -17
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +42 -11
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +29 -7
- package/dist/types/schemas.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/capabilities/index.ts +5 -8
- package/src/capabilities/overrides.ts +23 -8
- package/src/capabilities/permissions/index.ts +21 -5
- package/src/capabilities/permissions/mav2.ts +12 -2
- package/src/client/actions/grantPermissions.ts +57 -3
- package/src/client/actions/requestAccount.ts +2 -3
- package/src/client/actions/signSignatureRequest.ts +31 -3
- package/src/client/client.e2e-test.ts +14 -21
- package/src/client/index.ts +12 -10
- package/src/exports/index.ts +2 -1
- package/src/isomorphic/actions/createSession.ts +28 -7
- package/src/isomorphic/actions/prepareCalls.ts +38 -11
- package/src/isomorphic/actions/sendPreparedCalls.ts +47 -20
- package/src/isomorphic/utils/7702.ts +58 -0
- package/src/isomorphic/utils/createAccount.ts +38 -6
- package/src/isomorphic/utils/createDummySigner.ts +3 -2
- package/src/isomorphic/utils/parsePermissionsContext.ts +23 -7
- package/src/local/client.ts +2 -3
- package/src/remote/client.ts +12 -2
- package/src/rpc/examples.ts +343 -0
- package/src/rpc/request.ts +75 -26
- package/src/schemas.ts +218 -87
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare const Capabilities: import("@sinclair/typebox").TObject<{
|
|
2
|
-
permissions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
2
|
+
permissions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
3
3
|
context: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
4
|
-
}
|
|
4
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
5
|
+
sessionId: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
6
|
+
signature: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
7
|
+
}>]>>;
|
|
5
8
|
paymasterService: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
6
9
|
policyId: import("@sinclair/typebox").TString;
|
|
7
10
|
}>>;
|
|
@@ -6,5 +6,5 @@ export const Capabilities = Type.Object({
|
|
|
6
6
|
permissions: Type.Optional(PermissionsCapability),
|
|
7
7
|
paymasterService: Type.Optional(PaymasterCapability),
|
|
8
8
|
gasParamsOverride: Type.Optional(GasParamsOverrideCapability),
|
|
9
|
-
}
|
|
9
|
+
});
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/capabilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/capabilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;IACtC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACjD,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IACpD,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC;CAC9D,CAAC,CAAC","sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport { GasParamsOverrideCapability } from \"./overrides.js\";\nimport { PaymasterCapability } from \"./paymaster.js\";\nimport { PermissionsCapability } from \"./permissions/index.js\";\n\nexport const Capabilities = Type.Object({\n permissions: Type.Optional(PermissionsCapability),\n paymasterService: Type.Optional(PaymasterCapability),\n gasParamsOverride: Type.Optional(GasParamsOverrideCapability),\n});\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
import { TypeHex } from "../schemas.js";
|
|
3
|
-
export const Mutliplier = Type.Object({ multiplier: Type.Number() });
|
|
3
|
+
export const Mutliplier = Type.Object({ multiplier: Type.Number() }, { title: "Multiplier" });
|
|
4
4
|
// This is still being defined in https://github.com/ethereum/ERCs/pull/947/files#diff-dab085f963ca621595044bcbc0922705aa38b69f5bf8770dcb3d0496a633efcfR158
|
|
5
5
|
export const GasParamsOverrideCapability = Type.Object({
|
|
6
|
-
preVerificationGas: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
7
|
-
verificationGasLimit: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
8
|
-
callGasLimit: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
9
|
-
paymasterVerificationGasLimit: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
10
|
-
paymasterPostOpGasLimit: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
11
|
-
maxFeePerGas: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
12
|
-
maxPriorityFeePerGas: Type.Optional(Type.Union([TypeHex(), Mutliplier])),
|
|
6
|
+
preVerificationGas: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
7
|
+
verificationGasLimit: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
8
|
+
callGasLimit: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
9
|
+
paymasterVerificationGasLimit: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
10
|
+
paymasterPostOpGasLimit: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
11
|
+
maxFeePerGas: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
12
|
+
maxPriorityFeePerGas: Type.Optional(Type.Union([TypeHex({ title: "Absolute" }), Mutliplier])),
|
|
13
13
|
}, { minProperties: 1 });
|
|
14
14
|
//# sourceMappingURL=overrides.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../../src/capabilities/overrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../../src/capabilities/overrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CACnC,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,EAC7B,EAAE,KAAK,EAAE,YAAY,EAAE,CACxB,CAAC;AAEF,2JAA2J;AAC3J,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC,MAAM,CACpD;IACE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,CAC/B,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;IACD,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CACjC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;IACD,YAAY,EAAE,IAAI,CAAC,QAAQ,CACzB,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;IACD,6BAA6B,EAAE,IAAI,CAAC,QAAQ,CAC1C,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;IACD,uBAAuB,EAAE,IAAI,CAAC,QAAQ,CACpC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;IACD,YAAY,EAAE,IAAI,CAAC,QAAQ,CACzB,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;IACD,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CACjC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CACzD;CACF,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACrB,CAAC","sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport { TypeHex } from \"../schemas.js\";\n\nexport const Mutliplier = Type.Object(\n { multiplier: Type.Number() },\n { title: \"Multiplier\" },\n);\n\n// This is still being defined in https://github.com/ethereum/ERCs/pull/947/files#diff-dab085f963ca621595044bcbc0922705aa38b69f5bf8770dcb3d0496a633efcfR158\nexport const GasParamsOverrideCapability = Type.Object(\n {\n preVerificationGas: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n verificationGasLimit: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n callGasLimit: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n paymasterVerificationGasLimit: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n paymasterPostOpGasLimit: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n maxFeePerGas: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n maxPriorityFeePerGas: Type.Optional(\n Type.Union([TypeHex({ title: \"Absolute\" }), Mutliplier]),\n ),\n },\n { minProperties: 1 },\n);\n"]}
|
|
@@ -84,9 +84,13 @@ export declare const PermissionsArray: import("@sinclair/typebox").TArray<import
|
|
|
84
84
|
export declare const PermissionsContext: TObject<{
|
|
85
85
|
context: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
86
86
|
}>;
|
|
87
|
+
export declare const RemotePermission: TObject<{
|
|
88
|
+
sessionId: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
89
|
+
signature: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
90
|
+
}>;
|
|
87
91
|
export declare const PermissionsData: TObject<{
|
|
88
92
|
chainId: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
89
|
-
expiry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").
|
|
93
|
+
expiry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
90
94
|
key: TObject<{
|
|
91
95
|
type: import("@sinclair/typebox").TUnion<[TLiteral<"secp256k1">, TLiteral<"contract">]>;
|
|
92
96
|
publicKey: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
@@ -133,6 +137,9 @@ export declare const PermissionsData: TObject<{
|
|
|
133
137
|
data: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNever>;
|
|
134
138
|
}>]>>;
|
|
135
139
|
}>;
|
|
136
|
-
export declare const PermissionsCapability: TObject<{
|
|
140
|
+
export declare const PermissionsCapability: import("@sinclair/typebox").TUnion<[TObject<{
|
|
137
141
|
context: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
138
|
-
}
|
|
142
|
+
}>, TObject<{
|
|
143
|
+
sessionId: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
144
|
+
signature: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
|
|
145
|
+
}>]>;
|
|
@@ -7,7 +7,7 @@ data, description) => {
|
|
|
7
7
|
return Type.Transform(Type.Object({
|
|
8
8
|
type: Type.Literal(typeEnum),
|
|
9
9
|
data,
|
|
10
|
-
}, { description }))
|
|
10
|
+
}, { description, title: `${typeString}` }))
|
|
11
11
|
.Decode((value) => ({
|
|
12
12
|
...value,
|
|
13
13
|
type: typeString, // enum → string
|
|
@@ -56,15 +56,24 @@ export const TypePermission = Type.Union([
|
|
|
56
56
|
export const PermissionsArray = Type.Array(TypePermission, { minItems: 1 });
|
|
57
57
|
export const PermissionsContext = Type.Object({
|
|
58
58
|
context: TypeHex(),
|
|
59
|
+
}, {
|
|
60
|
+
title: "Permissions context",
|
|
61
|
+
});
|
|
62
|
+
export const RemotePermission = Type.Object({
|
|
63
|
+
sessionId: TypeHex(),
|
|
64
|
+
signature: TypeHex(),
|
|
65
|
+
}, {
|
|
66
|
+
title: "Remote permission",
|
|
59
67
|
});
|
|
60
68
|
export const PermissionsData = Type.Object({
|
|
61
69
|
chainId: TypeHex(),
|
|
62
|
-
expiry: Type.Optional(Type.
|
|
70
|
+
expiry: Type.Optional(Type.Integer()),
|
|
63
71
|
key: KeySigner,
|
|
64
72
|
permissions: PermissionsArray,
|
|
65
73
|
});
|
|
66
74
|
export const PermissionsCapability = Type.Union([
|
|
67
75
|
PermissionsContext,
|
|
76
|
+
RemotePermission,
|
|
68
77
|
// TODO: support permissions object here instead of only context-encoded permissions
|
|
69
78
|
// PermissionsData,
|
|
70
79
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/capabilities/permissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EACL,IAAI,GAKL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,UAAU,GAAG,CAKjB,UAAuB,EAAE,eAAe;AACxC,QAAqB,EAAE,4BAA4B;AACnD,IAAW,EACX,WAAmB,EACoB,EAAE;IACzC,OAAO,IAAI,CAAC,SAAS,CACnB,IAAI,CAAC,MAAM,CACT;QACE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC5B,IAAI;KACL,EACD,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/capabilities/permissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EACL,IAAI,GAKL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,UAAU,GAAG,CAKjB,UAAuB,EAAE,eAAe;AACxC,QAAqB,EAAE,4BAA4B;AACnD,IAAW,EACX,WAAmB,EACoB,EAAE;IACzC,OAAO,IAAI,CAAC,SAAS,CACnB,IAAI,CAAC,MAAM,CACT;QACE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC5B,IAAI;KACL,EACD,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,UAAU,EAAE,EAAE,CACxC,CACF;SACE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClB,GAAG,KAAK;QACR,IAAI,EAAE,UAAU,EAAE,gBAAgB;KACnC,CAAC,CAAC;SACF,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClB,GAAG,KAAK;QACR,IAAI,EAAE,QAAQ,EAAE,gBAAgB;KACjC,CAAC,CAAU,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,UAAU,CACpC,uBAAuB,EACvB,cAAc,CAAC,qBAAqB,EACpC,IAAI,CAAC,MAAM,CAAC;IACV,SAAS,EAAE,OAAO,EAAE;CACrB,CAAC,EACF,mDAAmD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ionType } from \"@account-kit/smart-contracts/experimental\";\nimport {\n Type,\n type TLiteral,\n type TLiteralValue,\n type TObject,\n type TSchema,\n} from \"@sinclair/typebox\";\nimport { KeySigner, TypeAddress, TypeHex } from \"../../schemas.js\";\n\nconst Permission = <\n TData extends TSchema,\n TLiteralVal extends TLiteralValue,\n TType extends TLiteral<TLiteralVal>,\n>(\n typeString: TLiteralVal, // e.g., \"root\"\n typeEnum: TLiteralVal, // e.g., PermissionType.ROOT\n data: TData,\n description: string,\n): TObject<{ type: TType; data: TData }> => {\n return Type.Transform(\n Type.Object(\n {\n type: Type.Literal(typeEnum),\n data,\n },\n { description, title: `${typeString}` },\n ),\n )\n .Decode((value) => ({\n ...value,\n type: typeString, // enum → string\n }))\n .Encode((value) => ({\n ...value,\n type: typeEnum, // string → enum\n })) as never;\n};\n\nconst NativeTokenTransfer = Permission(\n \"native-token-transfer\",\n PermissionType.NATIVE_TOKEN_TRANSFER,\n Type.Object({\n allowance: TypeHex(),\n }),\n \"allows transfer of native tokens from the account\",\n);\n\nconst Erc20TokenTransfer = Permission(\n \"erc20-token-transfer\",\n PermissionType.ERC20_TOKEN_TRANSFER,\n Type.Object({\n allowance: TypeHex(),\n address: TypeAddress,\n }),\n \"allows transfer or approval of erc20 tokens from the account\",\n);\n\nconst GasLimit = Permission(\n \"gas-limit\",\n PermissionType.GAS_LIMIT,\n Type.Object({\n limit: TypeHex(),\n }),\n \"allows the key to spend gas for UOs\",\n);\n\nconst ContractAccess = Permission(\n \"contract-access\",\n PermissionType.CONTRACT_ACCESS,\n Type.Object({\n address: TypeAddress,\n }),\n \"grants access to all functions in a contract\",\n);\n\nconst AccountFunction = Permission(\n \"account-functions\",\n PermissionType.ACCOUNT_FUNCTIONS,\n Type.Object({\n functions: Type.Array(TypeHex(), { minItems: 1 }),\n }),\n \"grants access to functions in the account\",\n);\n\nconst AllExternalFunctionAccess = Permission(\n \"functions-on-all-contracts\",\n PermissionType.FUNCTIONS_ON_ALL_CONTRACTS,\n Type.Object({\n functions: Type.Array(TypeHex(), { minItems: 1 }),\n }),\n \"access to a function selector in any address or contract\",\n);\n\nconst ContractFunctionAccess = Permission(\n \"functions-on-contract\",\n PermissionType.FUNCTIONS_ON_CONTRACT,\n Type.Object({\n address: TypeAddress,\n functions: Type.Array(TypeHex(), { minItems: 1 }),\n }),\n \"grants access to specified functions on a specific contract\",\n);\n\nconst Root = Permission(\n \"root\",\n PermissionType.ROOT,\n Type.Optional(Type.Never()),\n \"grants full access to everything\",\n);\n\nexport const TypePermission = Type.Union([\n // 7715 permissions\n NativeTokenTransfer,\n Erc20TokenTransfer,\n GasLimit,\n // additional permissions\n ContractAccess,\n AccountFunction,\n AllExternalFunctionAccess,\n ContractFunctionAccess,\n Root,\n]);\n\nexport const PermissionsArray = Type.Array(TypePermission, { minItems: 1 });\n\nexport const PermissionsContext = Type.Object(\n {\n context: TypeHex(),\n },\n {\n title: \"Permissions context\",\n },\n);\n\nexport const RemotePermission = Type.Object(\n {\n sessionId: TypeHex(),\n signature: TypeHex(),\n },\n {\n title: \"Remote permission\",\n },\n);\n\nexport const PermissionsData = Type.Object({\n chainId: TypeHex(),\n expiry: Type.Optional(Type.Integer()),\n key: KeySigner,\n permissions: PermissionsArray,\n});\n\nexport const PermissionsCapability = Type.Union([\n PermissionsContext,\n RemotePermission,\n // TODO: support permissions object here instead of only context-encoded permissions\n // PermissionsData,\n]);\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Static } from "@sinclair/typebox";
|
|
2
2
|
import { type Hex } from "viem";
|
|
3
|
-
import type { PermissionsData } from "./index.ts";
|
|
4
3
|
import type { KeySigner } from "../../schemas.ts";
|
|
4
|
+
import type { PermissionsCapability, PermissionsData } from "./index.ts";
|
|
5
5
|
export declare const SESSION_ID_LENGTH_BYTES = 16;
|
|
6
6
|
export declare const ENTITY_ID_LENGTH_BYTES = 4;
|
|
7
7
|
export declare const PermissionsContextVersion: {
|
|
@@ -30,7 +30,7 @@ type DecodedPermissionsContext = {
|
|
|
30
30
|
isGlobalValidation: boolean;
|
|
31
31
|
});
|
|
32
32
|
export declare const encodePermissionsContext: (context: DecodedPermissionsContext) => Hex;
|
|
33
|
-
export declare const decodePermissionsContext: (
|
|
33
|
+
export declare const decodePermissionsContext: (capability: Static<typeof PermissionsCapability>) => DecodedPermissionsContext;
|
|
34
34
|
export declare const prefixSignatureKeyType: (sig: Hex, type: KeySigner["type"]) => Hex;
|
|
35
35
|
export declare const isGlobalValidation: (data: Pick<Static<typeof PermissionsData>, "permissions">) => boolean;
|
|
36
36
|
export {};
|
|
@@ -31,7 +31,15 @@ export const encodePermissionsContext = (context) => {
|
|
|
31
31
|
return assertNever(context, "Unexpected context version");
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
export const decodePermissionsContext = (
|
|
34
|
+
export const decodePermissionsContext = (capability) => {
|
|
35
|
+
if (!("context" in capability)) {
|
|
36
|
+
return {
|
|
37
|
+
contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
|
|
38
|
+
sessionId: capability.sessionId,
|
|
39
|
+
signature: capability.signature,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const input = capability.context;
|
|
35
43
|
const contextVersion = sliceHex(input, 0, 1);
|
|
36
44
|
switch (contextVersion) {
|
|
37
45
|
case "0x00": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mav2.js","sourceRoot":"","sources":["../../../../src/capabilities/permissions/mav2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAY,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"mav2.js","sourceRoot":"","sources":["../../../../src/capabilities/permissions/mav2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAY,MAAM,MAAM,C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;YACb,OAAO,SAAS,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;QAClC;YACE,OAAO,WAAW,CAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,IAAyD,EAChD,EAAE;IACX,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC,CAAC","sourcesContent":["import { PermissionType } from \"@account-kit/smart-contracts/experimental\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { concatHex, sliceHex, type Hex } from \"viem\";\nimport type { KeySigner } from \"../../schemas.ts\";\nimport { assertNever } from \"../../utils.js\";\nimport type { PermissionsCapability, PermissionsData } from \"./index.ts\";\n\nexport const SESSION_ID_LENGTH_BYTES = 16;\nexport const ENTITY_ID_LENGTH_BYTES = 4;\n\nexport const PermissionsContextVersion = {\n REMOTE_MODE_DEFERRED_ACTION: \"0x00\",\n LOCAL_MODE_DEFERRED_ACTION: \"0x01\",\n NON_DEFERRED_ACTION: \"0x02\",\n} as const;\n\ntype ContextVersionHex =\n (typeof PermissionsContextVersion)[keyof typeof PermissionsContextVersion];\n\ntype DecodedPermissionsContext = {\n contextVersion: keyof typeof PermissionsContextVersion;\n} & (\n | {\n contextVersion: \"REMOTE_MODE_DEFERRED_ACTION\";\n sessionId: Hex;\n signature: Hex;\n deferredAction?: never;\n }\n | {\n contextVersion: \"LOCAL_MODE_DEFERRED_ACTION\";\n deferredAction: Hex;\n sessionId?: never;\n signature?: never;\n }\n | {\n contextVersion: \"NON_DEFERRED_ACTION\";\n deferredAction?: never;\n sessionId?: never;\n signature?: never;\n entityId: Hex;\n isGlobalValidation: boolean;\n }\n);\n\nexport const encodePermissionsContext = (\n context: DecodedPermissionsContext,\n): Hex => {\n switch (context.contextVersion) {\n case \"REMOTE_MODE_DEFERRED_ACTION\":\n return concatHex([\n PermissionsContextVersion.REMOTE_MODE_DEFERRED_ACTION,\n context.sessionId,\n context.signature,\n ]);\n case \"LOCAL_MODE_DEFERRED_ACTION\":\n return concatHex([\n PermissionsContextVersion.LOCAL_MODE_DEFERRED_ACTION,\n context.deferredAction,\n ]);\n case \"NON_DEFERRED_ACTION\":\n return concatHex([\n PermissionsContextVersion.NON_DEFERRED_ACTION,\n context.isGlobalValidation ? \"0x01\" : \"0x00\",\n context.entityId,\n ]);\n default:\n return assertNever(context, \"Unexpected context version\");\n }\n};\n\nexport const decodePermissionsContext = (\n capability: Static<typeof PermissionsCapability>,\n): DecodedPermissionsContext => {\n if (!(\"context\" in capability)) {\n return {\n contextVersion: \"REMOTE_MODE_DEFERRED_ACTION\",\n sessionId: capability.sessionId,\n signature: capability.signature,\n };\n }\n\n const input = capability.context;\n\n const contextVersion = sliceHex(input, 0, 1) as ContextVersionHex;\n switch (contextVersion) {\n case \"0x00\": {\n const sessionId = sliceHex(input, 1, SESSION_ID_LENGTH_BYTES + 1);\n const signature = sliceHex(input, SESSION_ID_LENGTH_BYTES + 1);\n return {\n contextVersion: \"REMOTE_MODE_DEFERRED_ACTION\",\n sessionId,\n signature,\n };\n }\n case \"0x01\": {\n const deferredAction = sliceHex(input, 1);\n return {\n contextVersion: \"LOCAL_MODE_DEFERRED_ACTION\",\n deferredAction,\n };\n }\n case \"0x02\": {\n const isGlobalValidation = sliceHex(input, 1, 2) === \"0x01\";\n const entityId = sliceHex(input, 2, ENTITY_ID_LENGTH_BYTES + 2);\n return {\n contextVersion: \"NON_DEFERRED_ACTION\",\n isGlobalValidation,\n entityId,\n };\n }\n default:\n return assertNever(\n contextVersion,\n `Unexpected context version: ${contextVersion}`,\n );\n }\n};\n\nexport const prefixSignatureKeyType = (\n sig: Hex,\n type: KeySigner[\"type\"],\n): Hex => {\n switch (type) {\n case \"secp256k1\":\n return concatHex([\"0x00\", sig]);\n case \"contract\":\n return concatHex([\"0x01\", sig]);\n default:\n return assertNever(type, \"Unexpected session key type\");\n }\n};\n\nexport const isGlobalValidation = (\n data: Pick<Static<typeof PermissionsData>, \"permissions\">,\n): boolean => {\n return data.permissions.some((p) => p.type === PermissionType.ROOT);\n};\n"]}
|
|
@@ -2,6 +2,8 @@ import { type Address, type Hex, type IsUndefined, type JsonRpcAccount } from "v
|
|
|
2
2
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
3
3
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
4
4
|
import type { CreateSessionParams } from "../../isomorphic/actions/createSession.ts";
|
|
5
|
+
import { TypeEip7702AuthExtendedFields } from "../../schemas.js";
|
|
6
|
+
import type { Static } from "@sinclair/typebox";
|
|
5
7
|
export type GrantPermissionsParams<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined> = Omit<CreateSessionParams, "account" | "chainId"> & (IsUndefined<TAccount> extends true ? {
|
|
6
8
|
account: Address;
|
|
7
9
|
} : {
|
|
@@ -9,6 +11,7 @@ export type GrantPermissionsParams<TAccount extends JsonRpcAccount<Address> | un
|
|
|
9
11
|
});
|
|
10
12
|
export type GrantPermissionsResult = {
|
|
11
13
|
context: Hex;
|
|
14
|
+
signedAuthorization?: Static<typeof TypeEip7702AuthExtendedFields>;
|
|
12
15
|
};
|
|
13
16
|
/**
|
|
14
17
|
* Grants permissions to a smart account by creating a session.
|
|
@@ -25,6 +28,7 @@ export type GrantPermissionsResult = {
|
|
|
25
28
|
* @param {Array} params.permissions - Array of permission objects defining what the session key can do
|
|
26
29
|
* @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier
|
|
27
30
|
* @returns {Hex} result.context - A hex identifier for the granted permissions context
|
|
31
|
+
* @returns {Static<typeof TypeEip7702AuthExtendedFields>} result.signedAuthorization - The EIP-7702 authorization fields, if applicable
|
|
28
32
|
*
|
|
29
33
|
* @example
|
|
30
34
|
* // Create a session key and grant root permissions
|
|
@@ -42,7 +46,7 @@ export type GrantPermissionsResult = {
|
|
|
42
46
|
* });
|
|
43
47
|
*
|
|
44
48
|
* // Use the permissions to prepare a call
|
|
45
|
-
* const
|
|
49
|
+
* const preparedCall = await client.prepareCalls({
|
|
46
50
|
* calls: [{ to: zeroAddress, value: "0x0" }],
|
|
47
51
|
* from: account.address,
|
|
48
52
|
* capabilities: {
|
|
@@ -56,16 +60,66 @@ export type GrantPermissionsResult = {
|
|
|
56
60
|
* // Sign with the session key
|
|
57
61
|
* const signature = await signSignatureRequest(
|
|
58
62
|
* sessionKey,
|
|
59
|
-
*
|
|
63
|
+
* preparedCall.signatureRequest,
|
|
60
64
|
* );
|
|
61
65
|
*
|
|
62
66
|
* // Send the prepared call using the session key
|
|
63
67
|
* const result = await client.sendPreparedCalls({
|
|
64
|
-
* ...
|
|
68
|
+
* ...preparedCall,
|
|
65
69
|
* signature,
|
|
66
70
|
* capabilities: {
|
|
67
71
|
* permissions,
|
|
68
72
|
* },
|
|
69
73
|
* });
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Create a session key and grant root permissions using a 7702 account
|
|
77
|
+
* const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
|
|
78
|
+
* const account = await client.requestAccount({
|
|
79
|
+
* creationHint: {
|
|
80
|
+
* accountType: "7702",
|
|
81
|
+
* }
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* const permissions = await client.grantPermissions({
|
|
85
|
+
* account: account.address,
|
|
86
|
+
* expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
|
|
87
|
+
* key: {
|
|
88
|
+
* publicKey: await sessionKey.getAddress(),
|
|
89
|
+
* type: "secp256k1",
|
|
90
|
+
* },
|
|
91
|
+
* permissions: [{ type: "root" }],
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Use the permissions to prepare a call
|
|
95
|
+
* const preparedCall = await client.prepareCalls({
|
|
96
|
+
* calls: [{ to: zeroAddress, value: "0x0" }],
|
|
97
|
+
* from: account.address,
|
|
98
|
+
* capabilities: {
|
|
99
|
+
* paymasterService: {
|
|
100
|
+
* policyId: "your-paymaster-policy-id",
|
|
101
|
+
* },
|
|
102
|
+
* permissions,
|
|
103
|
+
* },
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // Sign with the session key
|
|
107
|
+
* // If the 7702 account delegation is not yet installed, the result
|
|
108
|
+
* // here will include a `signedAuthorization` field that that
|
|
109
|
+
* // must be included when sending the account's first call.
|
|
110
|
+
* const { signedAuthorization, ...signature} = await signSignatureRequest(
|
|
111
|
+
* sessionKey,
|
|
112
|
+
* preparedCall.signatureRequest,
|
|
113
|
+
* );
|
|
114
|
+
*
|
|
115
|
+
* // Send the prepared call using the session key
|
|
116
|
+
* const result = await client.sendPreparedCalls({
|
|
117
|
+
* ...preparedCall,
|
|
118
|
+
* signature,
|
|
119
|
+
* signedAuthorization,
|
|
120
|
+
* capabilities: {
|
|
121
|
+
* permissions,
|
|
122
|
+
* },
|
|
123
|
+
* });
|
|
70
124
|
*/
|
|
71
125
|
export declare function grantPermissions<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(client: InnerWalletApiClient<TAccount>, signer: SmartAccountSigner, params: GrantPermissionsParams<TAccount>): Promise<GrantPermissionsResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../../src/client/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,GACN,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../../src/client/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,GACN,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAwIjE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4B,EAC5B,MAA0B,EAC1B,MAA8B;IAE9B,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACtC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAC1C,CAAC;IAED,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE;QACrC,GAAG,MAAM;QACT,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;KAChC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type IsUndefined,\n type JsonRpcAccount,\n toHex,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../../types.ts\";\nimport type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { CreateSessionParams } from \"../../isomorphic/actions/createSession.ts\";\nimport { TypeEip7702AuthExtendedFields } from \"../../schemas.js\";\nimport type { Static } from \"@sinclair/typebox\";\n\nexport type GrantPermissionsParams<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n> = Omit<CreateSessionParams, \"account\" | \"chainId\"> &\n (IsUndefined<TAccount> extends true\n ? { account: Address }\n : { account?: never });\n\nexport type GrantPermissionsResult = {\n context: Hex;\n signedAuthorization?: Static<typeof TypeEip7702AuthExtendedFields>;\n};\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SmartAccountSigner} signer - The signer of the smart account\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {Address} [params.account] - The account address (required if client was not initialized with an account)\n * @param {number} params.expiry - Unix timestamp when the permissions expire\n * @param {object} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n * @returns {Hex} result.context - A hex identifier for the granted permissions context\n * @returns {Static<typeof TypeEip7702AuthExtendedFields>} result.signedAuthorization - The EIP-7702 authorization fields, if applicable\n *\n * @example\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCall = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signature = await signSignatureRequest(\n * sessionKey,\n * preparedCall.signatureRequest,\n * );\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...preparedCall,\n * signature,\n * capabilities: {\n * permissions,\n * },\n * });\n *\n * @example\n * // Create a session key and grant root permissions using a 7702 account\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount({\n * creationHint: {\n * accountType: \"7702\",\n * }\n * });\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCall = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * // If the 7702 account delegation is not yet installed, the result\n * // here will include a `signedAuthorization` field that that\n * // must be included when sending the account's first call.\n * const { signedAuthorization, ...signature} = await signSignatureRequest(\n * sessionKey,\n * preparedCall.signatureRequest,\n * );\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...preparedCall,\n * signature,\n * signedAuthorization,\n * capabilities: {\n * permissions,\n * },\n * });\n */\nexport async function grantPermissions<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n>(\n client: InnerWalletApiClient<TAccount>,\n signer: SmartAccountSigner,\n params: GrantPermissionsParams<TAccount>,\n): Promise<GrantPermissionsResult>;\n\nexport async function grantPermissions(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params: GrantPermissionsParams,\n): Promise<GrantPermissionsResult> {\n if (client.account && !params.account) {\n params.account = client.account.address;\n }\n\n return client.grantPermissions(signer, {\n ...params,\n chainId: toHex(client.chain.id),\n });\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {} from "@aa-sdk/core";
|
|
2
2
|
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import deepEqual from "deep-equal";
|
|
4
3
|
import { custom } from "viem";
|
|
5
4
|
import { createAccount } from "../../isomorphic/utils/createAccount.js";
|
|
6
5
|
import { TypeSerializedInitcode } from "../../schemas.js";
|
|
6
|
+
import deepEqual from "deep-equal";
|
|
7
7
|
export async function requestAccount(client, signer, params) {
|
|
8
8
|
const args = (client.account && !params) || params?.accountAddress
|
|
9
9
|
? {
|
|
@@ -27,7 +27,7 @@ export async function requestAccount(client, signer, params) {
|
|
|
27
27
|
params: [args],
|
|
28
28
|
});
|
|
29
29
|
const account = await createAccount({
|
|
30
|
-
accountAddress
|
|
30
|
+
accountAddress,
|
|
31
31
|
counterfactualInfo: Value.Parse(TypeSerializedInitcode, counterfactualInfo),
|
|
32
32
|
chain: client.chain,
|
|
33
33
|
transport: custom(client.transport),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../../src/client/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,
|
|
1
|
+
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../../src/client/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAyC,MAAM,MAAM,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,SAAS,MAAM,YAAY,CAAC;AA8CnC,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA0B,EAC1B,MAA6B;IAE7B,MAAM,IAAI,GACR,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,cAAc;QACnD,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,EAAE,cAAc,IAAI,MAAM,CAAC,OAAQ,CAAC,OAAO;YACjE,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,MAAM;YACT,aAAa,EAAE,MAAM,MAAM,CAAC,UAAU,EAAE;YACxC,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACnD,IACE,aAAa;QACb,CAAC,CAAC,IAAI,CAAC,cAAc;YACnB,aAAa,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,cAAc,CAAC;YACtD,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,OAAO,aAAa,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAClE,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;QAClC,cAAc;QACd,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAC7B,sBAAsB,EACtB,kBAAmB,CACpB;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACnC,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7D,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n type SmartAccountSigner,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport type { Address } from \"abitype\";\nimport { custom, type IsUndefined, type JsonRpcAccount } from \"viem\";\nimport { createAccount } from \"../../isomorphic/utils/createAccount.js\";\nimport type { wallet_requestAccount } from \"../../rpc/request.js\";\nimport { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { InnerWalletApiClient } from \"../../types.js\";\nimport deepEqual from \"deep-equal\";\n\nexport type RequestAccountParams<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n> =\n IsUndefined<TAccount> extends true\n ? Omit<\n Extract<\n Static<typeof wallet_requestAccount>[\"Request\"][\"params\"][0],\n { signerAddress: Address }\n >,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > & { accountAddress?: Address }\n : never;\n\nexport type RequestAccountResult = SmartContractAccount;\n\n/**\n * Requests an account for the provided signer using the wallet API client.\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SmartAccountSigner} signer - The signer that will be associated with the account\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance\n *\n * @example\n * // Request an account with default parameters using a local signer\n * const signer = LocalAccountSigner.privateKeyToAccountSigner(\"0x...\");\n * const account = await client.requestAccount(signer);\n */\nexport function requestAccount<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n>(\n client: InnerWalletApiClient<TAccount>,\n signer: SmartAccountSigner,\n params?: RequestAccountParams<TAccount>,\n): Promise<RequestAccountResult>;\n\nexport async function requestAccount(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n const args =\n (client.account && !params) || params?.accountAddress\n ? {\n accountAddress: params?.accountAddress ?? client.account!.address,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress: await signer.getAddress(),\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal.getAccount();\n if (\n cachedAccount &&\n ((args.accountAddress &&\n cachedAccount.account.address === args.accountAddress) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n return cachedAccount.account;\n }\n\n const { counterfactualInfo, accountAddress } = await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\n\n const account = await createAccount({\n accountAddress,\n counterfactualInfo: Value.Parse(\n TypeSerializedInitcode,\n counterfactualInfo!,\n ),\n chain: client.chain,\n transport: custom(client.transport),\n signer,\n });\n\n client.internal.setAccount({ account, requestParams: args });\n\n return account;\n}\n"]}
|
|
@@ -2,10 +2,12 @@ import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
|
2
2
|
import type { Static } from "@sinclair/typebox";
|
|
3
3
|
import { type Hex } from "viem";
|
|
4
4
|
import { TypeSignatureRequest } from "../../schemas.js";
|
|
5
|
+
import type { Eip7702ExtendedFields } from "@aa-sdk/core";
|
|
5
6
|
export type SignSignatureRequestParams = Static<typeof TypeSignatureRequest>;
|
|
6
7
|
export type SignSignatureRequestResult = {
|
|
7
8
|
type: "ecdsa";
|
|
8
9
|
signature: Hex;
|
|
10
|
+
signedAuthorization?: Eip7702ExtendedFields["eip7702Auth"];
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* Signs a signature request using the provided signer.
|
|
@@ -13,11 +15,12 @@ export type SignSignatureRequestResult = {
|
|
|
13
15
|
*
|
|
14
16
|
* @param {SmartAccountSigner} signer - The signer to use for signing the request
|
|
15
17
|
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
16
|
-
* @param {string} params.type - The type of signature request ('personal_sign' or '
|
|
18
|
+
* @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
|
|
17
19
|
* @param {any} params.data - The data to sign, format depends on the signature type
|
|
18
20
|
* @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
|
|
19
21
|
* @returns {string} result.type - The signature type (currently only 'ecdsa' is supported)
|
|
20
22
|
* @returns {Hex} result.signature - The hex-encoded signature
|
|
23
|
+
* @returns {Eip7702ExtendedFields["eip7702Auth"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable
|
|
21
24
|
*
|
|
22
25
|
* @example
|
|
23
26
|
* // Sign a personal message
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {} from "viem";
|
|
1
|
+
import { toHex } from "viem";
|
|
2
2
|
import { TypeSignatureRequest } from "../../schemas.js";
|
|
3
3
|
import { assertNever } from "../../utils.js";
|
|
4
4
|
export async function signSignatureRequest(signer, params) {
|
|
@@ -7,9 +7,30 @@ export async function signSignatureRequest(signer, params) {
|
|
|
7
7
|
: params.type === "eth_signTypedData_v4"
|
|
8
8
|
? await signer.signTypedData(params.data)
|
|
9
9
|
: assertNever(params, "Unexpected signature request type");
|
|
10
|
+
if (!params.authorizationRequest) {
|
|
11
|
+
return {
|
|
12
|
+
type: "ecdsa",
|
|
13
|
+
signature,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (!signer.signAuthorization) {
|
|
17
|
+
throw new Error("Signer does not implement signAuthorization");
|
|
18
|
+
}
|
|
19
|
+
const authSig = await signer.signAuthorization(params.authorizationRequest);
|
|
20
|
+
const { r, s } = authSig;
|
|
21
|
+
const yParity = toHex(authSig.yParity ?? authSig.v - 27n);
|
|
22
|
+
const signedAuthorization = {
|
|
23
|
+
chainId: toHex(params.authorizationRequest.chainId),
|
|
24
|
+
nonce: toHex(params.authorizationRequest.nonce),
|
|
25
|
+
address: params.authorizationRequest.address,
|
|
26
|
+
r,
|
|
27
|
+
s,
|
|
28
|
+
yParity,
|
|
29
|
+
};
|
|
10
30
|
return {
|
|
11
31
|
type: "ecdsa",
|
|
12
32
|
signature,
|
|
33
|
+
signedAuthorization,
|
|
13
34
|
};
|
|
14
35
|
}
|
|
15
36
|
//# sourceMappingURL=signSignatureRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAgD7C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA0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\";\nimport { type Hex, toHex } from \"viem\";\nimport { TypeSignatureRequest } from \"../../schemas.js\";\nimport { assertNever } from \"../../utils.js\";\nimport type { Eip7702ExtendedFields } from \"@aa-sdk/core\";\n\nexport type SignSignatureRequestParams = Static<typeof TypeSignatureRequest>;\n\nexport type SignSignatureRequestResult = {\n type: \"ecdsa\";\n signature: Hex;\n signedAuthorization?: Eip7702ExtendedFields[\"eip7702Auth\"];\n};\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign and eth_signTypedData_v4.\n *\n * @param {SmartAccountSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {any} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n * @returns {string} result.type - The signature type (currently only 'ecdsa' is supported)\n * @returns {Hex} result.signature - The hex-encoded signature\n * @returns {Eip7702ExtendedFields[\"eip7702Auth\"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable\n *\n * @example\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * @example\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n */\nexport function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult>;\n\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n const signature =\n params.type === \"personal_sign\"\n ? await signer.signMessage(params.data)\n : params.type === \"eth_signTypedData_v4\"\n ? await signer.signTypedData(params.data)\n : assertNever(params, \"Unexpected signature request type\");\n\n if (!params.authorizationRequest) {\n return {\n type: \"ecdsa\" as const,\n signature,\n };\n }\n\n if (!signer.signAuthorization) {\n throw new Error(\"Signer does not implement signAuthorization\");\n }\n\n const authSig = await signer.signAuthorization(params.authorizationRequest);\n const { r, s } = authSig;\n const yParity = toHex(authSig.yParity ?? authSig.v - 27n);\n\n const signedAuthorization = {\n chainId: toHex(params.authorizationRequest.chainId),\n nonce: toHex(params.authorizationRequest.nonce),\n address: params.authorizationRequest.address,\n r,\n s,\n yParity,\n };\n\n return {\n type: \"ecdsa\" as const,\n signature,\n signedAuthorization,\n };\n}\n"]}
|
|
@@ -99,7 +99,7 @@ describe("Client E2E Tests", () => {
|
|
|
99
99
|
});
|
|
100
100
|
it("should successfully send a UO with paymaster", async () => {
|
|
101
101
|
const account = await client.requestAccount();
|
|
102
|
-
const
|
|
102
|
+
const preparedCall = await client.prepareCalls({
|
|
103
103
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
104
104
|
from: account.address,
|
|
105
105
|
capabilities: {
|
|
@@ -108,16 +108,10 @@ describe("Client E2E Tests", () => {
|
|
|
108
108
|
},
|
|
109
109
|
},
|
|
110
110
|
});
|
|
111
|
-
|
|
112
|
-
throw new Error("Invalid signature request type");
|
|
113
|
-
}
|
|
114
|
-
const signature = await signer.signMessage(preparedUO.signatureRequest.data);
|
|
111
|
+
const signature = await client.signSignatureRequest(preparedCall.signatureRequest);
|
|
115
112
|
const result = await client.sendPreparedCalls({
|
|
116
|
-
...
|
|
117
|
-
signature
|
|
118
|
-
type: "ecdsa",
|
|
119
|
-
signature,
|
|
120
|
-
},
|
|
113
|
+
...preparedCall,
|
|
114
|
+
signature,
|
|
121
115
|
});
|
|
122
116
|
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
123
117
|
});
|
|
@@ -133,7 +127,7 @@ describe("Client E2E Tests", () => {
|
|
|
133
127
|
},
|
|
134
128
|
permissions: [{ type: "root" }],
|
|
135
129
|
});
|
|
136
|
-
const
|
|
130
|
+
const preparedCall = await client.prepareCalls({
|
|
137
131
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
138
132
|
from: account.address,
|
|
139
133
|
capabilities: {
|
|
@@ -143,9 +137,9 @@ describe("Client E2E Tests", () => {
|
|
|
143
137
|
permissions,
|
|
144
138
|
},
|
|
145
139
|
});
|
|
146
|
-
const signature = await signSignatureRequest(sessionKey,
|
|
140
|
+
const signature = await signSignatureRequest(sessionKey, preparedCall.signatureRequest);
|
|
147
141
|
const result = await client.sendPreparedCalls({
|
|
148
|
-
...
|
|
142
|
+
...preparedCall,
|
|
149
143
|
signature,
|
|
150
144
|
capabilities: {
|
|
151
145
|
permissions,
|
|
@@ -241,7 +235,7 @@ describe("Client E2E Tests", () => {
|
|
|
241
235
|
});
|
|
242
236
|
it("should successfully send a UO with paymaster", async () => {
|
|
243
237
|
const account = await client.requestAccount();
|
|
244
|
-
const
|
|
238
|
+
const preparedCall = await client.prepareCalls({
|
|
245
239
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
246
240
|
from: account.address,
|
|
247
241
|
capabilities: {
|
|
@@ -250,9 +244,9 @@ describe("Client E2E Tests", () => {
|
|
|
250
244
|
},
|
|
251
245
|
},
|
|
252
246
|
});
|
|
253
|
-
const signature = await client.signSignatureRequest(
|
|
247
|
+
const signature = await client.signSignatureRequest(preparedCall.signatureRequest);
|
|
254
248
|
const result = await client.sendPreparedCalls({
|
|
255
|
-
...
|
|
249
|
+
...preparedCall,
|
|
256
250
|
signature,
|
|
257
251
|
});
|
|
258
252
|
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
@@ -269,7 +263,7 @@ describe("Client E2E Tests", () => {
|
|
|
269
263
|
},
|
|
270
264
|
permissions: [{ type: "root" }],
|
|
271
265
|
});
|
|
272
|
-
const
|
|
266
|
+
const preparedCall = await client.prepareCalls({
|
|
273
267
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
274
268
|
from: account.address,
|
|
275
269
|
capabilities: {
|
|
@@ -279,9 +273,9 @@ describe("Client E2E Tests", () => {
|
|
|
279
273
|
permissions,
|
|
280
274
|
},
|
|
281
275
|
});
|
|
282
|
-
const signature = await signSignatureRequest(sessionKey,
|
|
276
|
+
const signature = await signSignatureRequest(sessionKey, preparedCall.signatureRequest);
|
|
283
277
|
const result = await client.sendPreparedCalls({
|
|
284
|
-
...
|
|
278
|
+
...preparedCall,
|
|
285
279
|
signature,
|
|
286
280
|
capabilities: {
|
|
287
281
|
permissions,
|