@zerodev/permissions 5.3.2 → 5.4.1
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/constants.js +5 -3
- package/_cjs/constants.js.map +1 -1
- package/_cjs/policies/callPolicyUtils.js +41 -10
- package/_cjs/policies/callPolicyUtils.js.map +1 -1
- package/_cjs/policies/index.js +2 -1
- package/_cjs/policies/index.js.map +1 -1
- package/_cjs/policies/toCallPolicy.js +24 -6
- package/_cjs/policies/toCallPolicy.js.map +1 -1
- package/_cjs/policies/types.js +1 -0
- package/_cjs/policies/types.js.map +1 -1
- package/_cjs/signers/index.js +2 -1
- package/_cjs/signers/index.js.map +1 -1
- package/_cjs/signers/toWebAuthnSigner.js +20 -3
- package/_cjs/signers/toWebAuthnSigner.js.map +1 -1
- package/_esm/constants.js +14 -2
- package/_esm/constants.js.map +1 -1
- package/_esm/policies/callPolicyUtils.js +41 -10
- package/_esm/policies/callPolicyUtils.js.map +1 -1
- package/_esm/policies/index.js +1 -1
- package/_esm/policies/index.js.map +1 -1
- package/_esm/policies/toCallPolicy.js +23 -6
- package/_esm/policies/toCallPolicy.js.map +1 -1
- package/_esm/policies/types.js +1 -0
- package/_esm/policies/types.js.map +1 -1
- package/_esm/signers/index.js +1 -1
- package/_esm/signers/index.js.map +1 -1
- package/_esm/signers/toWebAuthnSigner.js +19 -3
- package/_esm/signers/toWebAuthnSigner.js.map +1 -1
- package/_types/constants.d.ts +14 -2
- package/_types/constants.d.ts.map +1 -1
- package/_types/policies/callPolicyUtils.d.ts +4 -4
- package/_types/policies/callPolicyUtils.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 +8 -2
- package/_types/policies/toCallPolicy.d.ts.map +1 -1
- package/_types/policies/types.d.ts +15 -6
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/signers/index.d.ts +1 -1
- package/_types/signers/index.d.ts.map +1 -1
- package/_types/signers/toWebAuthnSigner.d.ts +8 -2
- package/_types/signers/toWebAuthnSigner.d.ts.map +1 -1
- package/constants.ts +18 -2
- package/package.json +1 -1
- package/policies/callPolicyUtils.ts +60 -16
- package/policies/index.ts +5 -1
- package/policies/toCallPolicy.ts +37 -7
- package/policies/types.ts +27 -6
- package/signers/index.ts +2 -1
- package/signers/toWebAuthnSigner.ts +33 -4
package/_types/constants.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export declare const ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
2
|
+
export declare const WEBAUTHN_SIGNER_CONTRACT_V0_0_1 = "0x8AA55d4BfAE101609078681A69B5bc3181516612";
|
|
3
|
+
/**
|
|
4
|
+
* @dev WEBAUTHN_SIGNER_CONTRACT_V0_0_2 updates
|
|
5
|
+
* - Fixed checkSignature issue
|
|
6
|
+
*/
|
|
7
|
+
export declare const WEBAUTHN_SIGNER_CONTRACT_V0_0_2 = "0x58625164e306242c7613223bDeb68fbe11300606";
|
|
8
|
+
export declare const CALL_POLICY_CONTRACT_V0_0_1 = "0xe4Fec84B7B002273ecC86baa65a831ddB92d30a8";
|
|
9
|
+
/**
|
|
10
|
+
* @dev CALL_POLICY_CONTRACT_V0_0_2 updates
|
|
11
|
+
* - Added ONE_OF condition
|
|
12
|
+
* - Added native ETH transfer support
|
|
13
|
+
* - Added `zeroAddress` target address support, which means you can approve any contracts with specific selector. (e.g. approve any ERC20 transfer)
|
|
14
|
+
*/
|
|
15
|
+
export declare const CALL_POLICY_CONTRACT_V0_0_2 = "0x67Fa43ca2D689beA4d10b9F2C96828828A2Ab275";
|
|
4
16
|
export declare const GAS_POLICY_CONTRACT = "0xaeFC5AbC67FfD258abD0A3E54f65E70326F84b23";
|
|
5
17
|
export declare const RATE_LIMIT_POLICY_CONTRACT = "0xf63d4139B25c836334edD76641356c6b74C86873";
|
|
6
18
|
export declare const SIGNATURE_POLICY_CONTRACT = "0xF6A936c88D97E6fad13b98d2FD731Ff17eeD591d";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,+CACc,CAAA;AAChD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,+CACc,CAAA;AAChD,eAAO,MAAM,+BAA+B,+CACI,CAAA;AAChD;;;GAGG;AACH,eAAO,MAAM,+BAA+B,+CACI,CAAA;AAEhD,eAAO,MAAM,2BAA2B,+CACQ,CAAA;AAChD;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,+CACQ,CAAA;AAChD,eAAO,MAAM,mBAAmB,+CAA+C,CAAA;AAC/E,eAAO,MAAM,0BAA0B,+CACS,CAAA;AAChD,eAAO,MAAM,yBAAyB,+CACU,CAAA;AAChD,eAAO,MAAM,oBAAoB,+CAA+C,CAAA;AAChF,eAAO,MAAM,yBAAyB,+CACU,CAAA;AAEhD,oBAAY,WAAW;IACnB,kBAAkB,WAAW;IAC7B,uBAAuB,WAAW;IAClC,oBAAoB,WAAW;CAClC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Abi, type Hex } from "viem";
|
|
2
|
-
import type
|
|
3
|
-
export declare function getPermissionFromABI<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string>({ abi, args, functionName }:
|
|
4
|
-
export declare const encodePermissionData: (permission: PermissionCore | PermissionCore[]) => Hex;
|
|
1
|
+
import { type Abi, type Address, type Hex } from "viem";
|
|
2
|
+
import { type GeneratePermissionWithPolicyAddressParameters, type PermissionCore } from "./types.js";
|
|
3
|
+
export declare function getPermissionFromABI<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string>({ abi, args, functionName, policyAddress }: GeneratePermissionWithPolicyAddressParameters<TAbi, TFunctionName>): Pick<PermissionCore, "selector" | "rules">;
|
|
4
|
+
export declare const encodePermissionData: (permission: PermissionCore | PermissionCore[], policyAddress: Address) => Hex;
|
|
5
5
|
//# sourceMappingURL=callPolicyUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callPolicyUtils.d.ts","sourceRoot":"","sources":["../../policies/callPolicyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"callPolicyUtils.d.ts","sourceRoot":"","sources":["../../policies/callPolicyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,GAAG,EAER,KAAK,OAAO,EAEZ,KAAK,GAAG,EAOX,MAAM,MAAM,CAAA;AAKb,OAAO,EAEH,KAAK,6CAA6C,EAGlD,KAAK,cAAc,EACtB,MAAM,YAAY,CAAA;AAEnB,wBAAgB,oBAAoB,CAChC,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EACrC,aAAa,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,EACnD,EACE,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,aAAa,EAChB,EAAE,6CAA6C,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,IAAI,CACxE,cAAc,EACd,UAAU,GAAG,OAAO,CACvB,CA0EA;AAED,eAAO,MAAM,oBAAoB,eACjB,cAAc,GAAG,cAAc,EAAE,iBAC9B,OAAO,KACvB,GAkDF,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { toGasPolicy, type GasPolicyParams } from "./toGasPolicy.js";
|
|
2
2
|
export { toSignatureCallerPolicy, type SignatureCallerPolicyParams } from "./toSignatureCallerPolicy.js";
|
|
3
3
|
export { toRateLimitPolicy, type RateLimitPolicyParams } from "./toRateLimitPolicy.js";
|
|
4
|
-
export { toCallPolicy, type CallPolicyParams } from "./toCallPolicy.js";
|
|
4
|
+
export { toCallPolicy, type CallPolicyParams, CallPolicyVersion } from "./toCallPolicy.js";
|
|
5
5
|
export { toPolicyId } from "./utils/toPolicyId.js";
|
|
6
6
|
export { toSudoPolicy, type SudoPolicyParams } from "./toSudoPolicy.js";
|
|
7
7
|
export { CallType, ParamCondition } from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../policies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EACH,uBAAuB,EACvB,KAAK,2BAA2B,EACnC,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACH,iBAAiB,EACjB,KAAK,qBAAqB,EAC7B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../policies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EACH,uBAAuB,EACvB,KAAK,2BAA2B,EACnC,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACH,iBAAiB,EACjB,KAAK,qBAAqB,EAC7B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACH,YAAY,EACZ,KAAK,gBAAgB,EACrB,iBAAiB,EACpB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EACH,iBAAiB,EACjB,KAAK,qBAAqB,EAC7B,MAAM,wBAAwB,CAAA"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type { Abi } from "viem";
|
|
1
|
+
import type { Abi, Address } from "viem";
|
|
2
2
|
import type { Policy, PolicyParams } from "../types.js";
|
|
3
3
|
import { type Permission } from "./types.js";
|
|
4
|
+
export declare enum CallPolicyVersion {
|
|
5
|
+
V0_0_1 = "0.0.1",
|
|
6
|
+
V0_0_2 = "0.0.2"
|
|
7
|
+
}
|
|
8
|
+
export declare const getCallPolicyAddress: (policyVersion: CallPolicyVersion, policyAddress?: Address) => Address;
|
|
4
9
|
export type CallPolicyParams<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string> = PolicyParams & {
|
|
10
|
+
policyVersion: CallPolicyVersion;
|
|
5
11
|
permissions?: Permission<TAbi, TFunctionName>[];
|
|
6
12
|
};
|
|
7
|
-
export declare function toCallPolicy<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string>({ policyAddress, policyFlag, permissions }: CallPolicyParams<TAbi, TFunctionName>): Policy;
|
|
13
|
+
export declare function toCallPolicy<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string>({ policyAddress, policyFlag, policyVersion, permissions }: CallPolicyParams<TAbi, TFunctionName>): Policy;
|
|
8
14
|
//# sourceMappingURL=toCallPolicy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toCallPolicy.d.ts","sourceRoot":"","sources":["../../policies/toCallPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"toCallPolicy.d.ts","sourceRoot":"","sources":["../../policies/toCallPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAOxC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAKvD,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAEtD,oBAAY,iBAAiB;IACzB,MAAM,UAAU;IAChB,MAAM,UAAU;CACnB;AAED,eAAO,MAAM,oBAAoB,kBACd,iBAAiB,kBAChB,OAAO,KACxB,OAQF,CAAA;AAED,MAAM,MAAM,gBAAgB,CACxB,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EACrC,aAAa,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,IACjD,YAAY,GAAG;IACf,aAAa,EAAE,iBAAiB,CAAA;IAChC,WAAW,CAAC,EAAE,UAAU,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,CAAA;CAClD,CAAA;AAED,wBAAgB,YAAY,CACxB,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EACrC,aAAa,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,EACnD,EACE,aAAa,EACb,UAA2C,EAC3C,aAAa,EACb,WAAgB,EACnB,EAAE,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,MAAM,CA8ChD"}
|
|
@@ -11,12 +11,13 @@ export declare enum ParamCondition {
|
|
|
11
11
|
LESS_THAN = 2,
|
|
12
12
|
GREATER_THAN_OR_EQUAL = 3,
|
|
13
13
|
LESS_THAN_OR_EQUAL = 4,
|
|
14
|
-
NOT_EQUAL = 5
|
|
14
|
+
NOT_EQUAL = 5,
|
|
15
|
+
ONE_OF = 6
|
|
15
16
|
}
|
|
16
17
|
export interface ParamRule {
|
|
17
18
|
condition: ParamCondition;
|
|
18
19
|
offset: number;
|
|
19
|
-
|
|
20
|
+
params: Hex | Hex[];
|
|
20
21
|
}
|
|
21
22
|
export type PermissionCore = {
|
|
22
23
|
callType?: CallType;
|
|
@@ -40,11 +41,18 @@ export type Permission<TAbi extends Abi | readonly unknown[], TFunctionName exte
|
|
|
40
41
|
} & GetFunctionArgs<TAbi, TFunctionName> : _FunctionName extends string ? {
|
|
41
42
|
abi?: [Narrow<TAbi[number]>];
|
|
42
43
|
} & GetFunctionArgs<TAbi, _FunctionName> : never);
|
|
44
|
+
type ConditionValue<TAbiParameter extends AbiParameter, TAbiParameterKind extends AbiParameterKind> = {
|
|
45
|
+
condition: ParamCondition.ONE_OF;
|
|
46
|
+
value: AbiParameterToPrimitiveType<TAbiParameter, TAbiParameterKind>[];
|
|
47
|
+
} | {
|
|
48
|
+
condition: Exclude<ParamCondition, ParamCondition.ONE_OF>;
|
|
49
|
+
value: AbiParameterToPrimitiveType<TAbiParameter, TAbiParameterKind>;
|
|
50
|
+
};
|
|
43
51
|
export type CombinedArgs<TAbiParameters extends readonly AbiParameter[], TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = {
|
|
44
|
-
[K in keyof TAbiParameters]:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
[K in keyof TAbiParameters]: ConditionValue<TAbiParameters[K], TAbiParameterKind> | null;
|
|
53
|
+
};
|
|
54
|
+
export type GeneratePermissionWithPolicyAddressParameters<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string> = GeneratePermissionFromArgsParameters<TAbi, TFunctionName> & {
|
|
55
|
+
policyAddress: Address;
|
|
48
56
|
};
|
|
49
57
|
export type GeneratePermissionFromArgsParameters<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string, _FunctionName = TAbi extends Abi ? InferFunctionName<TAbi, TFunctionName> : never> = {
|
|
50
58
|
functionName?: _FunctionName;
|
|
@@ -53,4 +61,5 @@ export type GeneratePermissionFromArgsParameters<TAbi extends Abi | readonly unk
|
|
|
53
61
|
} & GetFunctionArgs<TAbi, TFunctionName> : _FunctionName extends string ? {
|
|
54
62
|
abi: [Narrow<TAbi[number]>];
|
|
55
63
|
} & GetFunctionArgs<TAbi, _FunctionName> : never);
|
|
64
|
+
export {};
|
|
56
65
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../policies/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAC1E,OAAO,KAAK,EACR,GAAG,EACH,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,2BAA2B,EAC3B,kBAAkB,EAClB,OAAO,EACP,GAAG,EACH,MAAM,EACT,MAAM,MAAM,CAAA;AAEb,oBAAY,QAAQ;IAChB,IAAI,SAAS;IACb,UAAU,SAAS;IACnB,aAAa,SAAS;CACzB;AAED,oBAAY,cAAc;IACtB,KAAK,IAAI;IACT,YAAY,IAAI;IAChB,SAAS,IAAI;IACb,qBAAqB,IAAI;IACzB,kBAAkB,IAAI;IACtB,SAAS,IAAI;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../policies/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { toECDSASigner, type ECDSAModularSignerParams } from "./toECDSASigner.js";
|
|
2
|
-
export { toWebAuthnSigner, type WebAuthnModularSignerParams } from "./toWebAuthnSigner.js";
|
|
2
|
+
export { toWebAuthnSigner, type WebAuthnModularSignerParams, WebAuthnSignerVersion } from "./toWebAuthnSigner.js";
|
|
3
3
|
export { WebAuthnMode, toWebAuthnKey } from "@zerodev/webauthn-key";
|
|
4
4
|
export { toSignerId } from "./utils/toSignerId.js";
|
|
5
5
|
export { toEmptyECDSASigner } from "./toEmptyECDSASigner.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../signers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,KAAK,wBAAwB,EAChC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACH,gBAAgB,EAChB,KAAK,2BAA2B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../signers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,KAAK,wBAAwB,EAChC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACH,gBAAgB,EAChB,KAAK,2BAA2B,EAChC,qBAAqB,EACxB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { WebAuthnKey } from "@zerodev/webauthn-key";
|
|
2
|
-
import { type Chain, type Client, type Transport } from "viem";
|
|
2
|
+
import { type Address, type Chain, type Client, type Transport } from "viem";
|
|
3
3
|
import type { ModularSigner, ModularSignerParams } from "../types.js";
|
|
4
|
+
export declare enum WebAuthnSignerVersion {
|
|
5
|
+
V0_0_1 = "0.0.1",
|
|
6
|
+
V0_0_2 = "0.0.2"
|
|
7
|
+
}
|
|
4
8
|
export type WebAuthnModularSignerParams = ModularSignerParams & {
|
|
5
9
|
webAuthnKey: WebAuthnKey;
|
|
10
|
+
webAuthnSignerVersion: WebAuthnSignerVersion;
|
|
6
11
|
};
|
|
7
|
-
export declare const
|
|
12
|
+
export declare const getWebAuthnSignerAddress: (webAuthnSignerVersion: WebAuthnSignerVersion, webAuthnSignerAddress?: Address) => Address;
|
|
13
|
+
export declare const toWebAuthnSigner: <TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined>(client: Client<TTransport, TChain, undefined>, { signerContractAddress, webAuthnKey, webAuthnSignerVersion }: WebAuthnModularSignerParams) => Promise<ModularSigner>;
|
|
8
14
|
//# sourceMappingURL=toWebAuthnSigner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toWebAuthnSigner.d.ts","sourceRoot":"","sources":["../../signers/toWebAuthnSigner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAYxD,OAAO,EACH,KAAK,KAAK,EACV,KAAK,MAAM,EAGX,KAAK,SAAS,EAKjB,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"toWebAuthnSigner.d.ts","sourceRoot":"","sources":["../../signers/toWebAuthnSigner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAYxD,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EAGX,KAAK,SAAS,EAKjB,MAAM,MAAM,CAAA;AAQb,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAErE,oBAAY,qBAAqB;IAC7B,MAAM,UAAU;IAChB,MAAM,UAAU;CACnB;AAED,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,GAAG;IAC5D,WAAW,EAAE,WAAW,CAAA;IACxB,qBAAqB,EAAE,qBAAqB,CAAA;CAC/C,CAAA;AAiFD,eAAO,MAAM,wBAAwB,0BACV,qBAAqB,0BACpB,OAAO,KAChC,OAQF,CAAA;AAED,eAAO,MAAM,gBAAgB,iNAStB,2BAA2B,KAC/B,QAAQ,aAAa,CAuFvB,CAAA"}
|
package/constants.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
export const ECDSA_SIGNER_CONTRACT =
|
|
2
2
|
"0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF"
|
|
3
|
-
export const
|
|
3
|
+
export const WEBAUTHN_SIGNER_CONTRACT_V0_0_1 =
|
|
4
4
|
"0x8AA55d4BfAE101609078681A69B5bc3181516612"
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @dev WEBAUTHN_SIGNER_CONTRACT_V0_0_2 updates
|
|
7
|
+
* - Fixed checkSignature issue
|
|
8
|
+
*/
|
|
9
|
+
export const WEBAUTHN_SIGNER_CONTRACT_V0_0_2 =
|
|
10
|
+
"0x58625164e306242c7613223bDeb68fbe11300606"
|
|
11
|
+
|
|
12
|
+
export const CALL_POLICY_CONTRACT_V0_0_1 =
|
|
13
|
+
"0xe4Fec84B7B002273ecC86baa65a831ddB92d30a8"
|
|
14
|
+
/**
|
|
15
|
+
* @dev CALL_POLICY_CONTRACT_V0_0_2 updates
|
|
16
|
+
* - Added ONE_OF condition
|
|
17
|
+
* - Added native ETH transfer support
|
|
18
|
+
* - Added `zeroAddress` target address support, which means you can approve any contracts with specific selector. (e.g. approve any ERC20 transfer)
|
|
19
|
+
*/
|
|
20
|
+
export const CALL_POLICY_CONTRACT_V0_0_2 =
|
|
21
|
+
"0x67Fa43ca2D689beA4d10b9F2C96828828A2Ab275"
|
|
6
22
|
export const GAS_POLICY_CONTRACT = "0xaeFC5AbC67FfD258abD0A3E54f65E70326F84b23"
|
|
7
23
|
export const RATE_LIMIT_POLICY_CONTRACT =
|
|
8
24
|
"0xf63d4139B25c836334edD76641356c6b74C86873"
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Abi,
|
|
3
3
|
type AbiFunction,
|
|
4
|
+
type Address,
|
|
4
5
|
type GetAbiItemParameters,
|
|
5
6
|
type Hex,
|
|
6
7
|
encodeAbiParameters,
|
|
@@ -10,11 +11,16 @@ import {
|
|
|
10
11
|
toFunctionSelector,
|
|
11
12
|
toHex
|
|
12
13
|
} from "viem"
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import {
|
|
15
|
+
CALL_POLICY_CONTRACT_V0_0_1,
|
|
16
|
+
CALL_POLICY_CONTRACT_V0_0_2
|
|
17
|
+
} from "../constants.js"
|
|
18
|
+
import {
|
|
19
|
+
type CombinedArgs,
|
|
20
|
+
type GeneratePermissionWithPolicyAddressParameters,
|
|
21
|
+
ParamCondition,
|
|
22
|
+
type ParamRule,
|
|
23
|
+
type PermissionCore
|
|
18
24
|
} from "./types.js"
|
|
19
25
|
|
|
20
26
|
export function getPermissionFromABI<
|
|
@@ -23,8 +29,9 @@ export function getPermissionFromABI<
|
|
|
23
29
|
>({
|
|
24
30
|
abi,
|
|
25
31
|
args,
|
|
26
|
-
functionName
|
|
27
|
-
|
|
32
|
+
functionName,
|
|
33
|
+
policyAddress
|
|
34
|
+
}: GeneratePermissionWithPolicyAddressParameters<TAbi, TFunctionName>): Pick<
|
|
28
35
|
PermissionCore,
|
|
29
36
|
"selector" | "rules"
|
|
30
37
|
> {
|
|
@@ -46,10 +53,16 @@ export function getPermissionFromABI<
|
|
|
46
53
|
let paramRules: ParamRule[] = []
|
|
47
54
|
if (args && Array.isArray(args)) {
|
|
48
55
|
paramRules = (args as CombinedArgs<AbiFunction["inputs"]>)
|
|
49
|
-
.map(
|
|
50
|
-
(arg
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
.map((arg, i) => {
|
|
57
|
+
if (!arg) return null
|
|
58
|
+
if (policyAddress === CALL_POLICY_CONTRACT_V0_0_1) {
|
|
59
|
+
if (arg.condition === ParamCondition.ONE_OF) {
|
|
60
|
+
throw Error(
|
|
61
|
+
"The ONE_OF condition is only supported from CALL_POLICY_CONTRACT_V0_0_2 onwards. Please use CALL_POLICY_CONTRACT_V0_0_2 or a later version."
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
params: pad(
|
|
53
66
|
isHex(arg.value)
|
|
54
67
|
? arg.value
|
|
55
68
|
: toHex(
|
|
@@ -60,7 +73,35 @@ export function getPermissionFromABI<
|
|
|
60
73
|
offset: i * 32,
|
|
61
74
|
condition: arg.condition
|
|
62
75
|
}
|
|
63
|
-
|
|
76
|
+
}
|
|
77
|
+
let params: Hex[]
|
|
78
|
+
if (arg.condition === ParamCondition.ONE_OF) {
|
|
79
|
+
params = arg.value.map((value) =>
|
|
80
|
+
pad(
|
|
81
|
+
isHex(value)
|
|
82
|
+
? value
|
|
83
|
+
: toHex(value as Parameters<typeof toHex>[0]),
|
|
84
|
+
{ size: 32 }
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
} else {
|
|
88
|
+
params = [
|
|
89
|
+
pad(
|
|
90
|
+
isHex(arg.value)
|
|
91
|
+
? arg.value
|
|
92
|
+
: toHex(
|
|
93
|
+
arg.value as Parameters<typeof toHex>[0]
|
|
94
|
+
),
|
|
95
|
+
{ size: 32 }
|
|
96
|
+
)
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
params,
|
|
101
|
+
offset: i * 32,
|
|
102
|
+
condition: arg.condition
|
|
103
|
+
}
|
|
104
|
+
})
|
|
64
105
|
.filter((rule) => rule) as ParamRule[]
|
|
65
106
|
}
|
|
66
107
|
return {
|
|
@@ -70,7 +111,8 @@ export function getPermissionFromABI<
|
|
|
70
111
|
}
|
|
71
112
|
|
|
72
113
|
export const encodePermissionData = (
|
|
73
|
-
permission: PermissionCore | PermissionCore[]
|
|
114
|
+
permission: PermissionCore | PermissionCore[],
|
|
115
|
+
policyAddress: Address
|
|
74
116
|
): Hex => {
|
|
75
117
|
const permissionParam = {
|
|
76
118
|
components: [
|
|
@@ -102,10 +144,12 @@ export const encodePermissionData = (
|
|
|
102
144
|
name: "offset",
|
|
103
145
|
type: "uint64"
|
|
104
146
|
},
|
|
105
|
-
|
|
106
147
|
{
|
|
107
|
-
name: "
|
|
108
|
-
type:
|
|
148
|
+
name: "params",
|
|
149
|
+
type:
|
|
150
|
+
policyAddress === CALL_POLICY_CONTRACT_V0_0_2
|
|
151
|
+
? "bytes32[]"
|
|
152
|
+
: "bytes32"
|
|
109
153
|
}
|
|
110
154
|
],
|
|
111
155
|
name: "rules",
|
package/policies/index.ts
CHANGED
|
@@ -7,7 +7,11 @@ export {
|
|
|
7
7
|
toRateLimitPolicy,
|
|
8
8
|
type RateLimitPolicyParams
|
|
9
9
|
} from "./toRateLimitPolicy.js"
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
toCallPolicy,
|
|
12
|
+
type CallPolicyParams,
|
|
13
|
+
CallPolicyVersion
|
|
14
|
+
} from "./toCallPolicy.js"
|
|
11
15
|
export { toPolicyId } from "./utils/toPolicyId.js"
|
|
12
16
|
export { toSudoPolicy, type SudoPolicyParams } from "./toSudoPolicy.js"
|
|
13
17
|
export { CallType, ParamCondition } from "./types.js"
|
package/policies/toCallPolicy.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { Abi } from "viem"
|
|
1
|
+
import type { Abi, Address } from "viem"
|
|
2
2
|
import { concatHex, pad } from "viem"
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
CALL_POLICY_CONTRACT_V0_0_1,
|
|
5
|
+
CALL_POLICY_CONTRACT_V0_0_2,
|
|
6
|
+
PolicyFlags
|
|
7
|
+
} from "../constants.js"
|
|
5
8
|
import type { Policy, PolicyParams } from "../types.js"
|
|
6
9
|
import {
|
|
7
10
|
encodePermissionData,
|
|
@@ -9,10 +12,29 @@ import {
|
|
|
9
12
|
} from "./callPolicyUtils.js"
|
|
10
13
|
import { CallType, type Permission } from "./types.js"
|
|
11
14
|
|
|
15
|
+
export enum CallPolicyVersion {
|
|
16
|
+
V0_0_1 = "0.0.1",
|
|
17
|
+
V0_0_2 = "0.0.2"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getCallPolicyAddress = (
|
|
21
|
+
policyVersion: CallPolicyVersion,
|
|
22
|
+
policyAddress?: Address
|
|
23
|
+
): Address => {
|
|
24
|
+
if (policyAddress) return policyAddress
|
|
25
|
+
switch (policyVersion) {
|
|
26
|
+
case CallPolicyVersion.V0_0_1:
|
|
27
|
+
return CALL_POLICY_CONTRACT_V0_0_1
|
|
28
|
+
case CallPolicyVersion.V0_0_2:
|
|
29
|
+
return CALL_POLICY_CONTRACT_V0_0_2
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
export type CallPolicyParams<
|
|
13
34
|
TAbi extends Abi | readonly unknown[],
|
|
14
35
|
TFunctionName extends string | undefined = string
|
|
15
36
|
> = PolicyParams & {
|
|
37
|
+
policyVersion: CallPolicyVersion
|
|
16
38
|
permissions?: Permission<TAbi, TFunctionName>[]
|
|
17
39
|
}
|
|
18
40
|
|
|
@@ -20,15 +42,19 @@ export function toCallPolicy<
|
|
|
20
42
|
TAbi extends Abi | readonly unknown[],
|
|
21
43
|
TFunctionName extends string | undefined = string
|
|
22
44
|
>({
|
|
23
|
-
policyAddress
|
|
45
|
+
policyAddress,
|
|
24
46
|
policyFlag = PolicyFlags.FOR_ALL_VALIDATION,
|
|
47
|
+
policyVersion,
|
|
25
48
|
permissions = []
|
|
26
49
|
}: CallPolicyParams<TAbi, TFunctionName>): Policy {
|
|
50
|
+
const callPolicyAddress = getCallPolicyAddress(policyVersion, policyAddress)
|
|
51
|
+
|
|
27
52
|
const generatedPermissionParams = permissions?.map((perm) =>
|
|
28
53
|
getPermissionFromABI({
|
|
29
54
|
abi: perm.abi as Abi,
|
|
30
55
|
functionName: perm.functionName as string,
|
|
31
|
-
args: perm.args as []
|
|
56
|
+
args: perm.args as [],
|
|
57
|
+
policyAddress: callPolicyAddress
|
|
32
58
|
})
|
|
33
59
|
)
|
|
34
60
|
|
|
@@ -44,17 +70,21 @@ export function toCallPolicy<
|
|
|
44
70
|
rules: perm.rules ?? generatedPermissionParams?.[index]?.rules ?? []
|
|
45
71
|
})) ?? []
|
|
46
72
|
|
|
47
|
-
const encodedPermissionData = encodePermissionData(
|
|
73
|
+
const encodedPermissionData = encodePermissionData(
|
|
74
|
+
permissions,
|
|
75
|
+
callPolicyAddress
|
|
76
|
+
)
|
|
48
77
|
|
|
49
78
|
return {
|
|
50
79
|
getPolicyData: () => {
|
|
51
80
|
return encodedPermissionData
|
|
52
81
|
},
|
|
53
82
|
getPolicyInfoInBytes: () => {
|
|
54
|
-
return concatHex([policyFlag,
|
|
83
|
+
return concatHex([policyFlag, callPolicyAddress])
|
|
55
84
|
},
|
|
56
85
|
policyParams: {
|
|
57
86
|
type: "call",
|
|
87
|
+
policyVersion,
|
|
58
88
|
policyAddress,
|
|
59
89
|
policyFlag,
|
|
60
90
|
permissions
|
package/policies/types.ts
CHANGED
|
@@ -23,13 +23,14 @@ export enum ParamCondition {
|
|
|
23
23
|
LESS_THAN = 2,
|
|
24
24
|
GREATER_THAN_OR_EQUAL = 3,
|
|
25
25
|
LESS_THAN_OR_EQUAL = 4,
|
|
26
|
-
NOT_EQUAL = 5
|
|
26
|
+
NOT_EQUAL = 5,
|
|
27
|
+
ONE_OF = 6
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export interface ParamRule {
|
|
30
31
|
condition: ParamCondition
|
|
31
32
|
offset: number
|
|
32
|
-
|
|
33
|
+
params: Hex | Hex[]
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export type PermissionCore = {
|
|
@@ -93,14 +94,34 @@ export type Permission<
|
|
|
93
94
|
>
|
|
94
95
|
: never)
|
|
95
96
|
|
|
97
|
+
type ConditionValue<
|
|
98
|
+
TAbiParameter extends AbiParameter,
|
|
99
|
+
TAbiParameterKind extends AbiParameterKind
|
|
100
|
+
> =
|
|
101
|
+
| {
|
|
102
|
+
condition: ParamCondition.ONE_OF
|
|
103
|
+
value: AbiParameterToPrimitiveType<TAbiParameter, TAbiParameterKind>[]
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
condition: Exclude<ParamCondition, ParamCondition.ONE_OF>
|
|
107
|
+
value: AbiParameterToPrimitiveType<TAbiParameter, TAbiParameterKind>
|
|
108
|
+
}
|
|
109
|
+
|
|
96
110
|
export type CombinedArgs<
|
|
97
111
|
TAbiParameters extends readonly AbiParameter[],
|
|
98
112
|
TAbiParameterKind extends AbiParameterKind = AbiParameterKind
|
|
99
113
|
> = {
|
|
100
|
-
[K in keyof TAbiParameters]:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
[K in keyof TAbiParameters]: ConditionValue<
|
|
115
|
+
TAbiParameters[K],
|
|
116
|
+
TAbiParameterKind
|
|
117
|
+
> | null
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type GeneratePermissionWithPolicyAddressParameters<
|
|
121
|
+
TAbi extends Abi | readonly unknown[],
|
|
122
|
+
TFunctionName extends string | undefined = string
|
|
123
|
+
> = GeneratePermissionFromArgsParameters<TAbi, TFunctionName> & {
|
|
124
|
+
policyAddress: Address
|
|
104
125
|
}
|
|
105
126
|
|
|
106
127
|
export type GeneratePermissionFromArgsParameters<
|
package/signers/index.ts
CHANGED
|
@@ -4,7 +4,8 @@ export {
|
|
|
4
4
|
} from "./toECDSASigner.js"
|
|
5
5
|
export {
|
|
6
6
|
toWebAuthnSigner,
|
|
7
|
-
type WebAuthnModularSignerParams
|
|
7
|
+
type WebAuthnModularSignerParams,
|
|
8
|
+
WebAuthnSignerVersion
|
|
8
9
|
} from "./toWebAuthnSigner.js"
|
|
9
10
|
export { WebAuthnMode, toWebAuthnKey } from "@zerodev/webauthn-key"
|
|
10
11
|
export { toSignerId } from "./utils/toSignerId.js"
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import type { TypedData } from "abitype"
|
|
13
13
|
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
|
|
14
14
|
import {
|
|
15
|
+
type Address,
|
|
15
16
|
type Chain,
|
|
16
17
|
type Client,
|
|
17
18
|
type LocalAccount,
|
|
@@ -25,11 +26,20 @@ import {
|
|
|
25
26
|
import { type SignableMessage, encodeAbiParameters } from "viem"
|
|
26
27
|
import { toAccount } from "viem/accounts"
|
|
27
28
|
import { getChainId, signMessage } from "viem/actions"
|
|
28
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
WEBAUTHN_SIGNER_CONTRACT_V0_0_1,
|
|
31
|
+
WEBAUTHN_SIGNER_CONTRACT_V0_0_2
|
|
32
|
+
} from "../constants.js"
|
|
29
33
|
import type { ModularSigner, ModularSignerParams } from "../types.js"
|
|
30
34
|
|
|
35
|
+
export enum WebAuthnSignerVersion {
|
|
36
|
+
V0_0_1 = "0.0.1",
|
|
37
|
+
V0_0_2 = "0.0.2"
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
export type WebAuthnModularSignerParams = ModularSignerParams & {
|
|
32
41
|
webAuthnKey: WebAuthnKey
|
|
42
|
+
webAuthnSignerVersion: WebAuthnSignerVersion
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
const signMessageUsingWebAuthn = async (
|
|
@@ -111,16 +121,35 @@ const signMessageUsingWebAuthn = async (
|
|
|
111
121
|
return encodedSignature
|
|
112
122
|
}
|
|
113
123
|
|
|
124
|
+
export const getWebAuthnSignerAddress = (
|
|
125
|
+
webAuthnSignerVersion: WebAuthnSignerVersion,
|
|
126
|
+
webAuthnSignerAddress?: Address
|
|
127
|
+
): Address => {
|
|
128
|
+
if (webAuthnSignerAddress) return webAuthnSignerAddress
|
|
129
|
+
switch (webAuthnSignerVersion) {
|
|
130
|
+
case WebAuthnSignerVersion.V0_0_1:
|
|
131
|
+
return WEBAUTHN_SIGNER_CONTRACT_V0_0_1
|
|
132
|
+
case WebAuthnSignerVersion.V0_0_2:
|
|
133
|
+
return WEBAUTHN_SIGNER_CONTRACT_V0_0_2
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
114
137
|
export const toWebAuthnSigner = async <
|
|
115
138
|
TTransport extends Transport = Transport,
|
|
116
139
|
TChain extends Chain | undefined = Chain | undefined
|
|
117
140
|
>(
|
|
118
141
|
client: Client<TTransport, TChain, undefined>,
|
|
119
142
|
{
|
|
120
|
-
signerContractAddress
|
|
121
|
-
webAuthnKey
|
|
143
|
+
signerContractAddress,
|
|
144
|
+
webAuthnKey,
|
|
145
|
+
webAuthnSignerVersion
|
|
122
146
|
}: WebAuthnModularSignerParams
|
|
123
147
|
): Promise<ModularSigner> => {
|
|
148
|
+
const webAuthnSignerAddress = getWebAuthnSignerAddress(
|
|
149
|
+
webAuthnSignerVersion,
|
|
150
|
+
signerContractAddress
|
|
151
|
+
)
|
|
152
|
+
|
|
124
153
|
const chainId = await getChainId(client)
|
|
125
154
|
|
|
126
155
|
const account: LocalAccount = toAccount({
|
|
@@ -161,7 +190,7 @@ export const toWebAuthnSigner = async <
|
|
|
161
190
|
|
|
162
191
|
return {
|
|
163
192
|
account,
|
|
164
|
-
signerContractAddress,
|
|
193
|
+
signerContractAddress: webAuthnSignerAddress,
|
|
165
194
|
getSignerData: () => {
|
|
166
195
|
return encodeAbiParameters(
|
|
167
196
|
[
|