@zerodev/permissions 5.2.1-alpha.1 → 5.2.1-alpha.11
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/_cjs/deserializePermissionAccount.js +11 -8
- package/_cjs/deserializePermissionAccount.js.map +1 -1
- package/_cjs/policies/index.js +4 -1
- package/_cjs/policies/index.js.map +1 -1
- package/_cjs/policies/toCallPolicy.js +1 -1
- package/_cjs/policies/toCallPolicy.js.map +1 -1
- package/_cjs/policies/toGasPolicy.js +1 -1
- package/_cjs/policies/toGasPolicy.js.map +1 -1
- package/_cjs/policies/toRateLimitPolicy.js +1 -1
- package/_cjs/policies/toRateLimitPolicy.js.map +1 -1
- package/_cjs/policies/toSignatureCallerPolicy.js +1 -1
- package/_cjs/policies/toSignatureCallerPolicy.js.map +1 -1
- package/_cjs/policies/toSudoPolicy.js +1 -1
- package/_cjs/policies/toSudoPolicy.js.map +1 -1
- package/_cjs/signers/index.js +3 -1
- package/_cjs/signers/index.js.map +1 -1
- package/_cjs/signers/toEmptyECDSASigner.js +30 -0
- package/_cjs/signers/toEmptyECDSASigner.js.map +1 -0
- package/_cjs/signers/toWebAuthnPubKey.js +4 -3
- package/_cjs/signers/toWebAuthnPubKey.js.map +1 -1
- package/_cjs/signers/toWebAuthnSigner.js +2 -2
- package/_cjs/signers/toWebAuthnSigner.js.map +1 -1
- package/_cjs/toPermissionValidator.js +13 -9
- package/_cjs/toPermissionValidator.js.map +1 -1
- package/_esm/deserializePermissionAccount.js +13 -10
- package/_esm/deserializePermissionAccount.js.map +1 -1
- package/_esm/policies/index.js +1 -1
- package/_esm/policies/index.js.map +1 -1
- package/_esm/policies/toCallPolicy.js +1 -1
- package/_esm/policies/toCallPolicy.js.map +1 -1
- package/_esm/policies/toGasPolicy.js +1 -1
- package/_esm/policies/toGasPolicy.js.map +1 -1
- package/_esm/policies/toRateLimitPolicy.js +1 -1
- package/_esm/policies/toRateLimitPolicy.js.map +1 -1
- package/_esm/policies/toSignatureCallerPolicy.js +1 -1
- package/_esm/policies/toSignatureCallerPolicy.js.map +1 -1
- package/_esm/policies/toSudoPolicy.js +1 -1
- package/_esm/policies/toSudoPolicy.js.map +1 -1
- package/_esm/signers/index.js +1 -0
- package/_esm/signers/index.js.map +1 -1
- package/_esm/signers/toEmptyECDSASigner.js +27 -0
- package/_esm/signers/toEmptyECDSASigner.js.map +1 -0
- package/_esm/signers/toWebAuthnPubKey.js +2 -1
- package/_esm/signers/toWebAuthnPubKey.js.map +1 -1
- package/_esm/signers/toWebAuthnSigner.js +1 -1
- package/_esm/signers/toWebAuthnSigner.js.map +1 -1
- package/_esm/toPermissionValidator.js +14 -10
- package/_esm/toPermissionValidator.js.map +1 -1
- package/_types/deserializePermissionAccount.d.ts +1 -1
- package/_types/deserializePermissionAccount.d.ts.map +1 -1
- package/_types/policies/index.d.ts +1 -1
- package/_types/policies/index.d.ts.map +1 -1
- package/_types/policies/toCallPolicy.d.ts +1 -1
- package/_types/policies/toCallPolicy.d.ts.map +1 -1
- package/_types/policies/toGasPolicy.d.ts +2 -2
- package/_types/policies/toGasPolicy.d.ts.map +1 -1
- package/_types/policies/toRateLimitPolicy.d.ts +1 -1
- package/_types/policies/toRateLimitPolicy.d.ts.map +1 -1
- package/_types/policies/toSignatureCallerPolicy.d.ts +1 -1
- package/_types/policies/toSignatureCallerPolicy.d.ts.map +1 -1
- package/_types/policies/toSudoPolicy.d.ts +1 -1
- package/_types/policies/toSudoPolicy.d.ts.map +1 -1
- package/_types/signers/index.d.ts +1 -0
- package/_types/signers/index.d.ts.map +1 -1
- package/_types/signers/toEmptyECDSASigner.d.ts +4 -0
- package/_types/signers/toEmptyECDSASigner.d.ts.map +1 -0
- package/_types/signers/toWebAuthnPubKey.d.ts.map +1 -1
- package/_types/signers/toWebAuthnSigner.d.ts.map +1 -1
- package/_types/toPermissionValidator.d.ts.map +1 -1
- package/_types/types.d.ts +2 -2
- package/_types/types.d.ts.map +1 -1
- package/deserializePermissionAccount.ts +19 -11
- package/package.json +3 -3
- package/policies/index.ts +1 -1
- package/policies/toCallPolicy.ts +2 -2
- package/policies/toGasPolicy.ts +4 -4
- package/policies/toRateLimitPolicy.ts +2 -2
- package/policies/toSignatureCallerPolicy.ts +2 -2
- package/policies/toSudoPolicy.ts +2 -2
- package/signers/index.ts +1 -0
- package/signers/toEmptyECDSASigner.ts +34 -0
- package/signers/toWebAuthnPubKey.ts +2 -1
- package/signers/toWebAuthnSigner.ts +2 -1
- package/toPermissionValidator.ts +19 -11
- package/types.ts +2 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { constants } from "@zerodev/sdk"
|
|
2
|
+
import type { TypedData } from "abitype"
|
|
3
|
+
import { type Address, type TypedDataDefinition } from "viem"
|
|
4
|
+
import { toAccount } from "viem/accounts"
|
|
5
|
+
import { ECDSA_SIGNER_CONTRACT } from "../constants.js"
|
|
6
|
+
import type { ModularSigner } from "../types.js"
|
|
7
|
+
|
|
8
|
+
export function toEmptyECDSASigner(address: Address): ModularSigner {
|
|
9
|
+
const account = toAccount({
|
|
10
|
+
address,
|
|
11
|
+
async signMessage() {
|
|
12
|
+
throw new Error("Method not supported")
|
|
13
|
+
},
|
|
14
|
+
async signTransaction(_, __) {
|
|
15
|
+
throw new Error("Method not supported")
|
|
16
|
+
},
|
|
17
|
+
async signTypedData<
|
|
18
|
+
const TTypedData extends TypedData | Record<string, unknown>,
|
|
19
|
+
TPrimaryType extends
|
|
20
|
+
| keyof TTypedData
|
|
21
|
+
| "EIP712Domain" = keyof TTypedData
|
|
22
|
+
>(_typedData: TypedDataDefinition<TTypedData, TPrimaryType>) {
|
|
23
|
+
throw new Error("Method not supported")
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
return {
|
|
27
|
+
account,
|
|
28
|
+
signerContractAddress: ECDSA_SIGNER_CONTRACT,
|
|
29
|
+
getSignerData: () => {
|
|
30
|
+
return address
|
|
31
|
+
},
|
|
32
|
+
getDummySignature: () => constants.DUMMY_ECDSA_SIG
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Buffer } from "buffer"
|
|
2
|
-
import { startAuthentication, startRegistration } from "@simplewebauthn/browser"
|
|
3
2
|
import { type Hex, keccak256 } from "viem"
|
|
4
3
|
import { type WebAuthnKey } from "./toWebAuthnSigner.js"
|
|
5
4
|
import { b64ToBytes, uint8ArrayToHexString } from "./webAuthnUtils.js"
|
|
@@ -33,6 +32,7 @@ export const toWebAuthnPubKey = async ({
|
|
|
33
32
|
const loginOptions = await loginOptionsResponse.json()
|
|
34
33
|
|
|
35
34
|
// Start authentication (login)
|
|
35
|
+
const { startAuthentication } = await import("@simplewebauthn/browser")
|
|
36
36
|
const loginCred = await startAuthentication(loginOptions)
|
|
37
37
|
|
|
38
38
|
// get authenticatorIdHash
|
|
@@ -88,6 +88,7 @@ export const toWebAuthnPubKey = async ({
|
|
|
88
88
|
sessionStorage.setItem("userId", registerOptions.userId)
|
|
89
89
|
|
|
90
90
|
// Start registration
|
|
91
|
+
const { startRegistration } = await import("@simplewebauthn/browser")
|
|
91
92
|
const registerCred = await startRegistration(registerOptions.options)
|
|
92
93
|
|
|
93
94
|
// get authenticatorIdHash
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { startAuthentication } from "@simplewebauthn/browser"
|
|
2
1
|
import type { PublicKeyCredentialRequestOptionsJSON } from "@simplewebauthn/typescript-types"
|
|
3
2
|
import type { TypedData } from "abitype"
|
|
4
3
|
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
|
|
@@ -112,6 +111,8 @@ export const toWebAuthnSigner = async <
|
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
// start authentication (signing)
|
|
114
|
+
|
|
115
|
+
const { startAuthentication } = await import("@simplewebauthn/browser")
|
|
115
116
|
const cred = await startAuthentication(assertionOptions)
|
|
116
117
|
|
|
117
118
|
// verify signature from server
|
package/toPermissionValidator.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { KernelV3AccountAbi } from "@zerodev/sdk"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getAction,
|
|
4
|
+
getEntryPointVersion,
|
|
5
|
+
getUserOperationHash
|
|
6
|
+
} from "permissionless"
|
|
3
7
|
import type { EntryPoint } from "permissionless/types/entrypoint"
|
|
4
8
|
import {
|
|
5
9
|
type Address,
|
|
@@ -38,6 +42,11 @@ export async function toPermissionValidator<
|
|
|
38
42
|
}: PermissionPluginParams
|
|
39
43
|
): Promise<PermissionPlugin<entryPoint>> {
|
|
40
44
|
const chainId = await getChainId(client)
|
|
45
|
+
const entryPointVersion = getEntryPointVersion(entryPointAddress)
|
|
46
|
+
|
|
47
|
+
if (entryPointVersion !== "v0.7") {
|
|
48
|
+
throw new Error("Only EntryPoint 0.7 is supported")
|
|
49
|
+
}
|
|
41
50
|
|
|
42
51
|
const getEnableData = async (
|
|
43
52
|
_kernelAccountAddress?: Address
|
|
@@ -49,13 +58,13 @@ export async function toPermissionValidator<
|
|
|
49
58
|
...policies.map((policy) =>
|
|
50
59
|
concat([
|
|
51
60
|
policy.getPolicyInfoInBytes(),
|
|
52
|
-
policy.getPolicyData(
|
|
61
|
+
policy.getPolicyData()
|
|
53
62
|
])
|
|
54
63
|
),
|
|
55
64
|
concat([
|
|
56
65
|
flag,
|
|
57
66
|
signer.signerContractAddress,
|
|
58
|
-
signer.getSignerData(
|
|
67
|
+
signer.getSignerData()
|
|
59
68
|
])
|
|
60
69
|
]
|
|
61
70
|
]
|
|
@@ -68,7 +77,7 @@ export async function toPermissionValidator<
|
|
|
68
77
|
[{ name: "policyAndSignerData", type: "bytes[]" }],
|
|
69
78
|
[[toPolicyId(policies), flag, toSignerId(signer)]]
|
|
70
79
|
)
|
|
71
|
-
return slice(keccak256(pIdData), 0,
|
|
80
|
+
return slice(keccak256(pIdData), 0, 4)
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
return {
|
|
@@ -77,11 +86,7 @@ export async function toPermissionValidator<
|
|
|
77
86
|
address: zeroAddress,
|
|
78
87
|
source: "PermissionValidator",
|
|
79
88
|
getEnableData,
|
|
80
|
-
getIdentifier:
|
|
81
|
-
pad(getPermissionId(), {
|
|
82
|
-
size: 20,
|
|
83
|
-
dir: "right"
|
|
84
|
-
}),
|
|
89
|
+
getIdentifier: getPermissionId,
|
|
85
90
|
|
|
86
91
|
signMessage: async ({ message }) => {
|
|
87
92
|
return concat([
|
|
@@ -100,7 +105,7 @@ export async function toPermissionValidator<
|
|
|
100
105
|
const userOpHash = getUserOperationHash({
|
|
101
106
|
userOperation: { ...userOperation, signature: "0x" },
|
|
102
107
|
entryPoint: entryPointAddress,
|
|
103
|
-
chainId
|
|
108
|
+
chainId
|
|
104
109
|
})
|
|
105
110
|
|
|
106
111
|
const signature = await signer.account.signMessage({
|
|
@@ -109,7 +114,10 @@ export async function toPermissionValidator<
|
|
|
109
114
|
return concat(["0xff", signature])
|
|
110
115
|
},
|
|
111
116
|
|
|
112
|
-
getNonceKey
|
|
117
|
+
async getNonceKey(_accountAddress?: Address, customNonceKey?: bigint) {
|
|
118
|
+
if (customNonceKey) {
|
|
119
|
+
return customNonceKey
|
|
120
|
+
}
|
|
113
121
|
return 0n
|
|
114
122
|
},
|
|
115
123
|
|
package/types.ts
CHANGED
|
@@ -29,12 +29,12 @@ export type PolicyParams = {
|
|
|
29
29
|
export type ModularSigner = {
|
|
30
30
|
account: LocalAccount
|
|
31
31
|
signerContractAddress: Address
|
|
32
|
-
getSignerData: (
|
|
32
|
+
getSignerData: () => Hex
|
|
33
33
|
getDummySignature: () => Hex
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export type Policy = {
|
|
37
|
-
getPolicyData: (
|
|
37
|
+
getPolicyData: () => Hex
|
|
38
38
|
getPolicyInfoInBytes: () => Hex
|
|
39
39
|
// return params directly to serialize/deserialize Policy
|
|
40
40
|
policyParams:
|