@zerodev/permissions 5.3.2-alpha-0 → 5.3.2-alpha-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_cjs/constants.js +2 -3
- package/_cjs/constants.js.map +1 -1
- package/_cjs/deserializePermissionAccount.js.map +1 -1
- package/_cjs/policies/callPolicyUtils.js +8 -24
- package/_cjs/policies/callPolicyUtils.js.map +1 -1
- package/_cjs/policies/toCallPolicy.js +2 -1
- package/_cjs/policies/toCallPolicy.js.map +1 -1
- package/_cjs/policies/types.js +0 -1
- package/_cjs/policies/types.js.map +1 -1
- package/_cjs/signers/index.js +3 -3
- package/_cjs/signers/index.js.map +1 -1
- package/_cjs/signers/toWebAuthnSigner.js +60 -74
- package/_cjs/signers/toWebAuthnSigner.js.map +1 -1
- package/_esm/constants.js +1 -8
- package/_esm/constants.js.map +1 -1
- package/_esm/deserializePermissionAccount.js.map +1 -1
- package/_esm/policies/callPolicyUtils.js +8 -24
- package/_esm/policies/callPolicyUtils.js.map +1 -1
- package/_esm/policies/toCallPolicy.js +2 -1
- package/_esm/policies/toCallPolicy.js.map +1 -1
- package/_esm/policies/types.js +0 -1
- 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 +72 -88
- package/_esm/signers/toWebAuthnSigner.js.map +1 -1
- package/_types/constants.d.ts +1 -8
- package/_types/constants.d.ts.map +1 -1
- package/_types/deserializePermissionAccount.d.ts.map +1 -1
- package/_types/policies/callPolicyUtils.d.ts +1 -1
- package/_types/policies/callPolicyUtils.d.ts.map +1 -1
- package/_types/policies/toCallPolicy.d.ts.map +1 -1
- package/_types/policies/types.d.ts +6 -12
- 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 +2 -3
- package/_types/signers/toWebAuthnSigner.d.ts.map +1 -1
- package/_types/types.d.ts +1 -1
- package/_types/types.d.ts.map +1 -1
- package/constants.ts +1 -10
- package/deserializePermissionAccount.ts +4 -1
- package/package.json +15 -1
- package/policies/callPolicyUtils.ts +16 -32
- package/policies/toCallPolicy.ts +2 -1
- package/policies/types.ts +17 -31
- package/signers/index.ts +1 -1
- package/signers/toWebAuthnSigner.ts +99 -115
- package/types.ts +1 -1
- package/_cjs/signers/toWebAuthnKey.js +0 -101
- package/_cjs/signers/toWebAuthnKey.js.map +0 -1
- package/_cjs/signers/webAuthnUtils.js +0 -45
- package/_cjs/signers/webAuthnUtils.js.map +0 -1
- package/_esm/signers/toWebAuthnKey.js +0 -110
- package/_esm/signers/toWebAuthnKey.js.map +0 -1
- package/_esm/signers/webAuthnUtils.js +0 -41
- package/_esm/signers/webAuthnUtils.js.map +0 -1
- package/_types/signers/toWebAuthnKey.d.ts +0 -17
- package/_types/signers/toWebAuthnKey.d.ts.map +0 -1
- package/_types/signers/webAuthnUtils.d.ts +0 -13
- package/_types/signers/webAuthnUtils.d.ts.map +0 -1
- package/signers/toWebAuthnKey.ts +0 -163
- package/signers/webAuthnUtils.ts +0 -54
|
@@ -1,99 +1,79 @@
|
|
|
1
|
+
import { b64ToBytes, base64FromUint8Array, findQuoteIndices, hexStringToUint8Array, isRIP7212SupportedNetwork, parseAndNormalizeSig, uint8ArrayToHexString } from "@zerodev/webauthn-key";
|
|
1
2
|
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts";
|
|
2
3
|
import { getTypesForEIP712Domain, hashTypedData, validateTypedData } from "viem";
|
|
3
4
|
import { encodeAbiParameters } from "viem";
|
|
4
5
|
import { toAccount } from "viem/accounts";
|
|
5
|
-
import { getChainId } from "viem/actions";
|
|
6
|
+
import { getChainId, signMessage } from "viem/actions";
|
|
6
7
|
import { WEBAUTHN_SIGNER_CONTRACT } from "../constants.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const userId = sessionStorage.getItem("userId");
|
|
35
|
-
// initiate signing
|
|
36
|
-
const signInitiateResponse = await fetch(`${passkeyServerUrl}/sign-initiate`, {
|
|
37
|
-
method: "POST",
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
body: JSON.stringify({ data: formattedMessage, userId }),
|
|
40
|
-
credentials: "include"
|
|
41
|
-
});
|
|
42
|
-
const signInitiateResult = await signInitiateResponse.json();
|
|
43
|
-
// prepare assertion options
|
|
44
|
-
const assertionOptions = {
|
|
45
|
-
challenge: signInitiateResult.challenge,
|
|
46
|
-
allowCredentials: signInitiateResult.allowCredentials,
|
|
47
|
-
userVerification: "required"
|
|
48
|
-
};
|
|
49
|
-
// start authentication (signing)
|
|
50
|
-
const { startAuthentication } = await import("@simplewebauthn/browser");
|
|
51
|
-
const cred = await startAuthentication(assertionOptions);
|
|
52
|
-
// verify signature from server
|
|
53
|
-
const verifyResponse = await fetch(`${passkeyServerUrl}/sign-verify`, {
|
|
54
|
-
method: "POST",
|
|
55
|
-
headers: { "Content-Type": "application/json" },
|
|
56
|
-
body: JSON.stringify({ cred, userId }),
|
|
57
|
-
credentials: "include"
|
|
58
|
-
});
|
|
59
|
-
const verifyResult = await verifyResponse.json();
|
|
60
|
-
if (!verifyResult.success) {
|
|
61
|
-
throw new Error("Signature not verified");
|
|
62
|
-
}
|
|
63
|
-
// get authenticator data
|
|
64
|
-
const authenticatorData = verifyResult.authenticatorData;
|
|
65
|
-
const authenticatorDataHex = uint8ArrayToHexString(b64ToBytes(authenticatorData));
|
|
66
|
-
// get client data JSON
|
|
67
|
-
const clientDataJSON = atob(cred.response.clientDataJSON);
|
|
68
|
-
// get challenge and response type location
|
|
69
|
-
const { beforeType } = findQuoteIndices(clientDataJSON);
|
|
70
|
-
// get signature r,s
|
|
71
|
-
const signature = verifyResult.signature;
|
|
72
|
-
const signatureHex = uint8ArrayToHexString(b64ToBytes(signature));
|
|
73
|
-
const { r, s } = parseAndNormalizeSig(signatureHex);
|
|
74
|
-
// encode signature
|
|
75
|
-
const encodedSignature = encodeAbiParameters([
|
|
76
|
-
{ name: "authenticatorData", type: "bytes" },
|
|
77
|
-
{ name: "clientDataJSON", type: "string" },
|
|
78
|
-
{ name: "responseTypeLocation", type: "uint256" },
|
|
79
|
-
{ name: "r", type: "uint256" },
|
|
80
|
-
{ name: "s", type: "uint256" },
|
|
81
|
-
{ name: "usePrecompiled", type: "bool" }
|
|
82
|
-
], [
|
|
83
|
-
authenticatorDataHex,
|
|
84
|
-
clientDataJSON,
|
|
85
|
-
beforeType,
|
|
86
|
-
BigInt(r),
|
|
87
|
-
BigInt(s),
|
|
88
|
-
isRIP7212SupportedNetwork(chainId)
|
|
89
|
-
]);
|
|
90
|
-
return encodedSignature;
|
|
8
|
+
const signMessageUsingWebAuthn = async (message, chainId, allowCredentials) => {
|
|
9
|
+
let messageContent;
|
|
10
|
+
if (typeof message === "string") {
|
|
11
|
+
// message is a string
|
|
12
|
+
messageContent = message;
|
|
13
|
+
}
|
|
14
|
+
else if ("raw" in message && typeof message.raw === "string") {
|
|
15
|
+
// message.raw is a Hex string
|
|
16
|
+
messageContent = message.raw;
|
|
17
|
+
}
|
|
18
|
+
else if ("raw" in message && message.raw instanceof Uint8Array) {
|
|
19
|
+
// message.raw is a ByteArray
|
|
20
|
+
messageContent = message.raw.toString();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error("Unsupported message format");
|
|
24
|
+
}
|
|
25
|
+
// remove 0x prefix if present
|
|
26
|
+
const formattedMessage = messageContent.startsWith("0x")
|
|
27
|
+
? messageContent.slice(2)
|
|
28
|
+
: messageContent;
|
|
29
|
+
const challenge = base64FromUint8Array(hexStringToUint8Array(formattedMessage), true);
|
|
30
|
+
// prepare assertion options
|
|
31
|
+
const assertionOptions = {
|
|
32
|
+
challenge,
|
|
33
|
+
allowCredentials,
|
|
34
|
+
userVerification: "required"
|
|
91
35
|
};
|
|
36
|
+
// start authentication (signing)
|
|
37
|
+
const { startAuthentication } = await import("@simplewebauthn/browser");
|
|
38
|
+
const cred = await startAuthentication(assertionOptions);
|
|
39
|
+
// get authenticator data
|
|
40
|
+
const { authenticatorData } = cred.response;
|
|
41
|
+
const authenticatorDataHex = uint8ArrayToHexString(b64ToBytes(authenticatorData));
|
|
42
|
+
// get client data JSON
|
|
43
|
+
const clientDataJSON = atob(cred.response.clientDataJSON);
|
|
44
|
+
// get challenge and response type location
|
|
45
|
+
const { beforeType } = findQuoteIndices(clientDataJSON);
|
|
46
|
+
// get signature r,s
|
|
47
|
+
const { signature } = cred.response;
|
|
48
|
+
const signatureHex = uint8ArrayToHexString(b64ToBytes(signature));
|
|
49
|
+
const { r, s } = parseAndNormalizeSig(signatureHex);
|
|
50
|
+
// encode signature
|
|
51
|
+
const encodedSignature = encodeAbiParameters([
|
|
52
|
+
{ name: "authenticatorData", type: "bytes" },
|
|
53
|
+
{ name: "clientDataJSON", type: "string" },
|
|
54
|
+
{ name: "responseTypeLocation", type: "uint256" },
|
|
55
|
+
{ name: "r", type: "uint256" },
|
|
56
|
+
{ name: "s", type: "uint256" },
|
|
57
|
+
{ name: "usePrecompiled", type: "bool" }
|
|
58
|
+
], [
|
|
59
|
+
authenticatorDataHex,
|
|
60
|
+
clientDataJSON,
|
|
61
|
+
beforeType,
|
|
62
|
+
BigInt(r),
|
|
63
|
+
BigInt(s),
|
|
64
|
+
isRIP7212SupportedNetwork(chainId)
|
|
65
|
+
]);
|
|
66
|
+
return encodedSignature;
|
|
67
|
+
};
|
|
68
|
+
export const toWebAuthnSigner = async (client, { signerContractAddress = WEBAUTHN_SIGNER_CONTRACT, webAuthnKey }) => {
|
|
69
|
+
const chainId = await getChainId(client);
|
|
92
70
|
const account = toAccount({
|
|
93
71
|
// note that this address will be overwritten by actual address
|
|
94
72
|
address: "0x0000000000000000000000000000000000000000",
|
|
95
73
|
async signMessage({ message }) {
|
|
96
|
-
return signMessageUsingWebAuthn(message
|
|
74
|
+
return signMessageUsingWebAuthn(message, chainId, [
|
|
75
|
+
{ id: webAuthnKey.authenticatorId, type: "public-key" }
|
|
76
|
+
]);
|
|
97
77
|
},
|
|
98
78
|
async signTransaction(_, __) {
|
|
99
79
|
throw new SignTransactionNotSupportedBySmartAccount();
|
|
@@ -106,7 +86,11 @@ export const toWebAuthnSigner = async (client, { signerContractAddress = WEBAUTH
|
|
|
106
86
|
};
|
|
107
87
|
validateTypedData({ domain, message, primaryType, types });
|
|
108
88
|
const hash = hashTypedData(typedData);
|
|
109
|
-
|
|
89
|
+
const signature = await signMessage(client, {
|
|
90
|
+
account,
|
|
91
|
+
message: hash
|
|
92
|
+
});
|
|
93
|
+
return signature;
|
|
110
94
|
}
|
|
111
95
|
});
|
|
112
96
|
return {
|
|
@@ -138,7 +122,7 @@ export const toWebAuthnSigner = async (client, { signerContractAddress = WEBAUTH
|
|
|
138
122
|
{ name: "usePrecompiled", type: "bool" }
|
|
139
123
|
], [
|
|
140
124
|
"0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97631d00000000",
|
|
141
|
-
'{"type":"webauthn.get","challenge":"tbxXNFS9X_4Byr1cMwqKrIGB-_30a0QhZ6y7ucM0BOE","origin":"http://localhost:3000","crossOrigin":false}',
|
|
125
|
+
'{"type":"webauthn.get","challenge":"tbxXNFS9X_4Byr1cMwqKrIGB-_30a0QhZ6y7ucM0BOE","origin":"http://localhost:3000","crossOrigin":false, "other_keys_can_be_added_here":"do not compare clientDataJSON against a template. See https://goo.gl/yabPex"}',
|
|
142
126
|
1n,
|
|
143
127
|
44941127272049826721201904734628716258498742255959991581049806490182030242267n,
|
|
144
128
|
9910254599581058084911561569808925251374718953855182016200087235935345969636n,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toWebAuthnSigner.js","sourceRoot":"","sources":["../../signers/toWebAuthnSigner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yCAAyC,EAAE,MAAM,yBAAyB,CAAA;AACnF,OAAO,EAOH,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACpB,MAAM,MAAM,CAAA;AACb,OAAO,EAAwB,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"toWebAuthnSigner.js","sourceRoot":"","sources":["../../signers/toWebAuthnSigner.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,UAAU,EACV,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACxB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,yCAAyC,EAAE,MAAM,yBAAyB,CAAA;AACnF,OAAO,EAOH,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACpB,MAAM,MAAM,CAAA;AACb,OAAO,EAAwB,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAO1D,MAAM,wBAAwB,GAAG,KAAK,EAClC,OAAwB,EACxB,OAAe,EACf,gBAA4E,EAC9E,EAAE;IACA,IAAI,cAAsB,CAAA;IAC1B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,sBAAsB;QACtB,cAAc,GAA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,IAAI,EAAE;gBACxD,WAAW,CAAC,mBAAmB;aAClC,CACJ,CAAA;QACL,CAAC;QACD,iBAAiB,EAAE,GAAG,EAAE;YACpB,OAAO,mBAAmB,CACtB;gBACI,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE;gBAC5C,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC1C,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,SAAS,EAAE;gBACjD,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC9B,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC9B,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE;aAC3C,EACD;gBACI,8EAA8E;gBAC9E,sPAAsP;gBACtP,EAAE;gBACF,8EAA8E;gBAC9E,6EAA6E;gBAC7E,KAAK;aACR,CACJ,CAAA;QACL,CAAC;KACJ,CAAA;AACL,CAAC,CAAA"}
|
package/_types/constants.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
export declare const ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
|
|
2
2
|
export declare const WEBAUTHN_SIGNER_CONTRACT = "0x8AA55d4BfAE101609078681A69B5bc3181516612";
|
|
3
|
-
export declare const
|
|
4
|
-
/**
|
|
5
|
-
* @dev CALL_POLICY_CONTRACT_V5_3_2 updates
|
|
6
|
-
* - Added ONE_OF condition
|
|
7
|
-
* - Added native ETH transfer support
|
|
8
|
-
* - Added `zeroAddress` target address support, which means you can approve any contracts with specific selector. (e.g. approve any ERC20 transfer)
|
|
9
|
-
*/
|
|
10
|
-
export declare const CALL_POLICY_CONTRACT_V5_3_2 = "0x09dc5ca0d9e5bd4330b45b40585126519d82b6cc";
|
|
3
|
+
export declare const CALL_POLICY_CONTRACT = "0xe4Fec84B7B002273ecC86baa65a831ddB92d30a8";
|
|
11
4
|
export declare const GAS_POLICY_CONTRACT = "0xaeFC5AbC67FfD258abD0A3E54f65E70326F84b23";
|
|
12
5
|
export declare const RATE_LIMIT_POLICY_CONTRACT = "0xf63d4139B25c836334edD76641356c6b74C86873";
|
|
13
6
|
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,wBAAwB,+CACW,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,wBAAwB,+CACW,CAAA;AAChD,eAAO,MAAM,oBAAoB,+CAA+C,CAAA;AAChF,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializePermissionAccount.d.ts","sourceRoot":"","sources":["../deserializePermissionAccount.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACpB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"deserializePermissionAccount.d.ts","sourceRoot":"","sources":["../deserializePermissionAccount.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACpB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAczD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C,eAAO,MAAM,4BAA4B,6RAQL,MAAM,kBACtB,aAAa,uFAqDhC,CAAA;AAED,eAAO,MAAM,sBAAsB,WAAkB,MAAM,oBAiB1D,CAAA;AAED,eAAO,MAAM,wBAAwB,aACvB,GAAG,iBACE,mBAAmB;;;CAqCrC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Abi, type Hex } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import type { GeneratePermissionFromArgsParameters, PermissionCore } from "./types.js";
|
|
3
3
|
export declare function getPermissionFromABI<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string>({ abi, args, functionName }: GeneratePermissionFromArgsParameters<TAbi, TFunctionName>): Pick<PermissionCore, "selector" | "rules">;
|
|
4
4
|
export declare const encodePermissionData: (permission: PermissionCore | PermissionCore[]) => 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,EAGR,KAAK,GAAG,EAOX,MAAM,MAAM,CAAA;AACb,OAAO,
|
|
1
|
+
{"version":3,"file":"callPolicyUtils.d.ts","sourceRoot":"","sources":["../../policies/callPolicyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,GAAG,EAGR,KAAK,GAAG,EAOX,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAER,oCAAoC,EAEpC,cAAc,EACjB,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,EACf,EAAE,oCAAoC,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,IAAI,CAC/D,cAAc,EACd,UAAU,GAAG,OAAO,CACvB,CAwCA;AAED,eAAO,MAAM,oBAAoB,eACjB,cAAc,GAAG,cAAc,EAAE,KAC9C,GAgDF,CAAA"}
|
|
@@ -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,MAAM,MAAM,CAAA;AAI/B,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAKvD,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAEtD,MAAM,MAAM,gBAAgB,CACxB,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EACrC,aAAa,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,IACjD,YAAY,GAAG;IACf,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,aAAoC,EACpC,UAA2C,EAC3C,WAAgB,EACnB,EAAE,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,MAAM,CAuChD"}
|
|
@@ -11,13 +11,12 @@ 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
|
|
15
|
-
ONE_OF = 6
|
|
14
|
+
NOT_EQUAL = 5
|
|
16
15
|
}
|
|
17
16
|
export interface ParamRule {
|
|
18
17
|
condition: ParamCondition;
|
|
19
18
|
offset: number;
|
|
20
|
-
|
|
19
|
+
param: Hex;
|
|
21
20
|
}
|
|
22
21
|
export type PermissionCore = {
|
|
23
22
|
callType?: CallType;
|
|
@@ -41,15 +40,11 @@ export type Permission<TAbi extends Abi | readonly unknown[], TFunctionName exte
|
|
|
41
40
|
} & GetFunctionArgs<TAbi, TFunctionName> : _FunctionName extends string ? {
|
|
42
41
|
abi?: [Narrow<TAbi[number]>];
|
|
43
42
|
} & 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
|
-
};
|
|
51
43
|
export type CombinedArgs<TAbiParameters extends readonly AbiParameter[], TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = {
|
|
52
|
-
[K in keyof TAbiParameters]:
|
|
44
|
+
[K in keyof TAbiParameters]: {
|
|
45
|
+
condition: ParamCondition;
|
|
46
|
+
value: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind>;
|
|
47
|
+
} | null;
|
|
53
48
|
};
|
|
54
49
|
export type GeneratePermissionFromArgsParameters<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string, _FunctionName = TAbi extends Abi ? InferFunctionName<TAbi, TFunctionName> : never> = {
|
|
55
50
|
functionName?: _FunctionName;
|
|
@@ -58,5 +53,4 @@ export type GeneratePermissionFromArgsParameters<TAbi extends Abi | readonly unk
|
|
|
58
53
|
} & GetFunctionArgs<TAbi, TFunctionName> : _FunctionName extends string ? {
|
|
59
54
|
abi: [Narrow<TAbi[number]>];
|
|
60
55
|
} & GetFunctionArgs<TAbi, _FunctionName> : never);
|
|
61
|
-
export {};
|
|
62
56
|
//# 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":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAC1E,OAAO,KAAK,EACR,GAAG,EACH,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,2BAA2B,E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B,SAAS,EAAE,cAAc,CAAA;QACzB,KAAK,EAAE,2BAA2B,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAA;KAC3E,GAAG,IAAI;CACX,CAAA;AAED,MAAM,MAAM,oCAAoC,CAC5C,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EACrC,aAAa,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,EACjD,aAAa,GAAG,IAAI,SAAS,GAAG,GAC1B,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,GACtC,KAAK,IACX;IACA,YAAY,CAAC,EAAE,aAAa,CAAA;CAC/B,GAAG,CAAC,aAAa,SAAS,MAAM,GAC3B;IAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;CAAE,GAAG,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,GAC5D,aAAa,SAAS,MAAM,GAC1B;IAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,GACtE,KAAK,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { toECDSASigner, type ECDSAModularSignerParams } from "./toECDSASigner.js";
|
|
2
2
|
export { toWebAuthnSigner, type WebAuthnModularSignerParams } from "./toWebAuthnSigner.js";
|
|
3
|
-
export { WebAuthnMode, toWebAuthnKey } from "
|
|
3
|
+
export { WebAuthnMode, toWebAuthnKey } from "@zerodev/webauthn-key";
|
|
4
4
|
export { toSignerId } from "./utils/toSignerId.js";
|
|
5
5
|
export { toEmptyECDSASigner } from "./toEmptyECDSASigner.js";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,EACnC,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,
|
|
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,EACnC,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,9 +1,8 @@
|
|
|
1
|
+
import type { WebAuthnKey } from "@zerodev/webauthn-key";
|
|
1
2
|
import { type Chain, type Client, type Transport } from "viem";
|
|
2
3
|
import type { ModularSigner, ModularSignerParams } from "../types.js";
|
|
3
|
-
import type { WebAuthnKey } from "./toWebAuthnKey.js";
|
|
4
4
|
export type WebAuthnModularSignerParams = ModularSignerParams & {
|
|
5
|
-
passkeyServerUrl: string;
|
|
6
5
|
webAuthnKey: WebAuthnKey;
|
|
7
6
|
};
|
|
8
|
-
export declare const toWebAuthnSigner: <TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined>(client: Client<TTransport, TChain, undefined>, { signerContractAddress,
|
|
7
|
+
export declare const toWebAuthnSigner: <TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined>(client: Client<TTransport, TChain, undefined>, { signerContractAddress, webAuthnKey }: WebAuthnModularSignerParams) => Promise<ModularSigner>;
|
|
9
8
|
//# sourceMappingURL=toWebAuthnSigner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toWebAuthnSigner.d.ts","sourceRoot":"","sources":["../../signers/toWebAuthnSigner.ts"],"names":[],"mappings":"
|
|
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;AAKb,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAErE,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,GAAG;IAC5D,WAAW,EAAE,WAAW,CAAA;CAC3B,CAAA;AAiFD,eAAO,MAAM,gBAAgB,0LAQtB,2BAA2B,KAC/B,QAAQ,aAAa,CAkFvB,CAAA"}
|
package/_types/types.d.ts
CHANGED
package/_types/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EACR,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EACR,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,qBAAqB,EACxB,MAAM,qBAAqB,CAAA;AAE5B,MAAM,MAAM,gBAAgB,CAAC,UAAU,SAAS,UAAU,IAAI,eAAe,CACzE,UAAU,EACV,qBA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IAC5C,eAAe,CAAC,EAAE,GAAG,CAAA;IACrB,UAAU,CAAC,EAAE,GAAG,CAAA;CACnB,CAAA"}
|
package/constants.ts
CHANGED
|
@@ -2,16 +2,7 @@ export const ECDSA_SIGNER_CONTRACT =
|
|
|
2
2
|
"0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF"
|
|
3
3
|
export const WEBAUTHN_SIGNER_CONTRACT =
|
|
4
4
|
"0x8AA55d4BfAE101609078681A69B5bc3181516612"
|
|
5
|
-
export const
|
|
6
|
-
"0xe4Fec84B7B002273ecC86baa65a831ddB92d30a8"
|
|
7
|
-
/**
|
|
8
|
-
* @dev CALL_POLICY_CONTRACT_V5_3_2 updates
|
|
9
|
-
* - Added ONE_OF condition
|
|
10
|
-
* - Added native ETH transfer support
|
|
11
|
-
* - Added `zeroAddress` target address support, which means you can approve any contracts with specific selector. (e.g. approve any ERC20 transfer)
|
|
12
|
-
*/
|
|
13
|
-
export const CALL_POLICY_CONTRACT_V5_3_2 =
|
|
14
|
-
"0x09dc5ca0d9e5bd4330b45b40585126519d82b6cc" // TODO: need to confirm the address after review
|
|
5
|
+
export const CALL_POLICY_CONTRACT = "0xe4Fec84B7B002273ecC86baa65a831ddB92d30a8"
|
|
15
6
|
export const GAS_POLICY_CONTRACT = "0xaeFC5AbC67FfD258abD0A3E54f65E70326F84b23"
|
|
16
7
|
export const RATE_LIMIT_POLICY_CONTRACT =
|
|
17
8
|
"0xf63d4139B25c836334edD76641356c6b74C86873"
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
ValidatorInitData
|
|
12
12
|
} from "@zerodev/sdk/types"
|
|
13
13
|
import { getEntryPointVersion } from "permissionless"
|
|
14
|
+
import type { SmartAccountSigner } from "permissionless/accounts"
|
|
14
15
|
import type { EntryPoint } from "permissionless/types"
|
|
15
16
|
import type { Chain, Client, Hex, Transport } from "viem"
|
|
16
17
|
import { decodeFunctionData } from "viem"
|
|
@@ -52,7 +53,9 @@ export const deserializePermissionAccount = async <
|
|
|
52
53
|
let signer: ModularSigner
|
|
53
54
|
if (params.privateKey)
|
|
54
55
|
signer = toECDSASigner({
|
|
55
|
-
signer: privateKeyToAccount(
|
|
56
|
+
signer: privateKeyToAccount(
|
|
57
|
+
params.privateKey
|
|
58
|
+
) as SmartAccountSigner<"privateKey", `0x${string}`>
|
|
56
59
|
})
|
|
57
60
|
else if (modularSigner) signer = modularSigner
|
|
58
61
|
else throw new Error("No signer or serialized sessionKey provided")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodev/permissions",
|
|
3
|
-
"version": "5.3.2-alpha-
|
|
3
|
+
"version": "5.3.2-alpha-2",
|
|
4
4
|
"author": "ZeroDev",
|
|
5
5
|
"main": "./_cjs/index.js",
|
|
6
6
|
"module": "./_esm/index.js",
|
|
@@ -51,6 +51,19 @@
|
|
|
51
51
|
"default": "./_cjs/signers/index.js"
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
|
+
"typesVersions": {
|
|
55
|
+
"*": {
|
|
56
|
+
"policies": [
|
|
57
|
+
"./_types/policies/index.d.ts"
|
|
58
|
+
],
|
|
59
|
+
"signers": [
|
|
60
|
+
"./_types/signers/index.d.ts"
|
|
61
|
+
],
|
|
62
|
+
"types": [
|
|
63
|
+
"./_types/types/index.d.ts"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
},
|
|
54
67
|
"dependencies": {
|
|
55
68
|
"merkletreejs": "^0.3.11",
|
|
56
69
|
"@simplewebauthn/browser": "^9.0.1"
|
|
@@ -58,6 +71,7 @@
|
|
|
58
71
|
"peerDependencies": {
|
|
59
72
|
"viem": "^2.16.3",
|
|
60
73
|
"@zerodev/sdk": "^5.2.13",
|
|
74
|
+
"@zerodev/webauthn-key": "^5.3.0",
|
|
61
75
|
"permissionless": "^0.1.18"
|
|
62
76
|
}
|
|
63
77
|
}
|
|
@@ -10,12 +10,11 @@ import {
|
|
|
10
10
|
toFunctionSelector,
|
|
11
11
|
toHex
|
|
12
12
|
} from "viem"
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
type PermissionCore
|
|
13
|
+
import type {
|
|
14
|
+
CombinedArgs,
|
|
15
|
+
GeneratePermissionFromArgsParameters,
|
|
16
|
+
ParamRule,
|
|
17
|
+
PermissionCore
|
|
19
18
|
} from "./types.js"
|
|
20
19
|
|
|
21
20
|
export function getPermissionFromABI<
|
|
@@ -47,36 +46,21 @@ export function getPermissionFromABI<
|
|
|
47
46
|
let paramRules: ParamRule[] = []
|
|
48
47
|
if (args && Array.isArray(args)) {
|
|
49
48
|
paramRules = (args as CombinedArgs<AbiFunction["inputs"]>)
|
|
50
|
-
.map(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
params = arg.value.map((value) =>
|
|
55
|
-
pad(
|
|
56
|
-
isHex(value)
|
|
57
|
-
? value
|
|
58
|
-
: toHex(value as Parameters<typeof toHex>[0]),
|
|
59
|
-
{ size: 32 }
|
|
60
|
-
)
|
|
61
|
-
)
|
|
62
|
-
} else {
|
|
63
|
-
params = [
|
|
64
|
-
pad(
|
|
49
|
+
.map(
|
|
50
|
+
(arg, i) =>
|
|
51
|
+
arg && {
|
|
52
|
+
param: pad(
|
|
65
53
|
isHex(arg.value)
|
|
66
54
|
? arg.value
|
|
67
55
|
: toHex(
|
|
68
56
|
arg.value as Parameters<typeof toHex>[0]
|
|
69
57
|
),
|
|
70
58
|
{ size: 32 }
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
offset: i * 32,
|
|
77
|
-
condition: arg.condition
|
|
78
|
-
}
|
|
79
|
-
})
|
|
59
|
+
),
|
|
60
|
+
offset: i * 32,
|
|
61
|
+
condition: arg.condition
|
|
62
|
+
}
|
|
63
|
+
)
|
|
80
64
|
.filter((rule) => rule) as ParamRule[]
|
|
81
65
|
}
|
|
82
66
|
return {
|
|
@@ -120,8 +104,8 @@ export const encodePermissionData = (
|
|
|
120
104
|
},
|
|
121
105
|
|
|
122
106
|
{
|
|
123
|
-
name: "
|
|
124
|
-
type: "bytes32
|
|
107
|
+
name: "param",
|
|
108
|
+
type: "bytes32"
|
|
125
109
|
}
|
|
126
110
|
],
|
|
127
111
|
name: "rules",
|
package/policies/toCallPolicy.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Abi } from "viem"
|
|
2
2
|
import { concatHex, pad } from "viem"
|
|
3
3
|
import { PolicyFlags } from "../constants.js"
|
|
4
|
+
import { CALL_POLICY_CONTRACT } from "../constants.js"
|
|
4
5
|
import type { Policy, PolicyParams } from "../types.js"
|
|
5
6
|
import {
|
|
6
7
|
encodePermissionData,
|
|
@@ -19,7 +20,7 @@ export function toCallPolicy<
|
|
|
19
20
|
TAbi extends Abi | readonly unknown[],
|
|
20
21
|
TFunctionName extends string | undefined = string
|
|
21
22
|
>({
|
|
22
|
-
policyAddress,
|
|
23
|
+
policyAddress = CALL_POLICY_CONTRACT,
|
|
23
24
|
policyFlag = PolicyFlags.FOR_ALL_VALIDATION,
|
|
24
25
|
permissions = []
|
|
25
26
|
}: CallPolicyParams<TAbi, TFunctionName>): Policy {
|
package/policies/types.ts
CHANGED
|
@@ -23,14 +23,13 @@ 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
|
|
27
|
-
ONE_OF = 6
|
|
26
|
+
NOT_EQUAL = 5
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export interface ParamRule {
|
|
31
30
|
condition: ParamCondition
|
|
32
31
|
offset: number
|
|
33
|
-
|
|
32
|
+
param: Hex
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
export type PermissionCore = {
|
|
@@ -72,10 +71,10 @@ export type GetFunctionArgs<
|
|
|
72
71
|
args?: readonly unknown[]
|
|
73
72
|
}
|
|
74
73
|
: TArgs extends readonly []
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
? { args?: never }
|
|
75
|
+
: {
|
|
76
|
+
args?: TArgs
|
|
77
|
+
}
|
|
79
78
|
|
|
80
79
|
export type Permission<
|
|
81
80
|
TAbi extends Abi | readonly unknown[],
|
|
@@ -88,33 +87,20 @@ export type Permission<
|
|
|
88
87
|
} & (TFunctionName extends string
|
|
89
88
|
? { abi?: Narrow<TAbi> } & GetFunctionArgs<TAbi, TFunctionName>
|
|
90
89
|
: _FunctionName extends string
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
}
|
|
90
|
+
? { abi?: [Narrow<TAbi[number]>] } & GetFunctionArgs<
|
|
91
|
+
TAbi,
|
|
92
|
+
_FunctionName
|
|
93
|
+
>
|
|
94
|
+
: never)
|
|
109
95
|
|
|
110
96
|
export type CombinedArgs<
|
|
111
97
|
TAbiParameters extends readonly AbiParameter[],
|
|
112
98
|
TAbiParameterKind extends AbiParameterKind = AbiParameterKind
|
|
113
99
|
> = {
|
|
114
|
-
[K in keyof TAbiParameters]:
|
|
115
|
-
|
|
116
|
-
TAbiParameterKind
|
|
117
|
-
|
|
100
|
+
[K in keyof TAbiParameters]: {
|
|
101
|
+
condition: ParamCondition
|
|
102
|
+
value: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind>
|
|
103
|
+
} | null
|
|
118
104
|
}
|
|
119
105
|
|
|
120
106
|
export type GeneratePermissionFromArgsParameters<
|
|
@@ -128,5 +114,5 @@ export type GeneratePermissionFromArgsParameters<
|
|
|
128
114
|
} & (TFunctionName extends string
|
|
129
115
|
? { abi: Narrow<TAbi> } & GetFunctionArgs<TAbi, TFunctionName>
|
|
130
116
|
: _FunctionName extends string
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
? { abi: [Narrow<TAbi[number]>] } & GetFunctionArgs<TAbi, _FunctionName>
|
|
118
|
+
: never)
|