From fbd50226fe85d2290f09e31d24f551de9831bfad Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Tue, 28 Jan 2025 17:33:47 +0100 Subject: [PATCH] wip --- src/allowEip712Signature.ts | 9 +++++-- src/const.ts | 4 --- src/encodeTypedData.ts | 2 +- src/scopeTypedData.ts | 54 +++++++++++++++++-------------------- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/allowEip712Signature.ts b/src/allowEip712Signature.ts index 1877558..3247143 100644 --- a/src/allowEip712Signature.ts +++ b/src/allowEip712Signature.ts @@ -3,9 +3,10 @@ import { ParamType } from "ethers"; import { Prettify, TypedData, TypedDataDomain } from "viem"; import { FunctionPermissionCoerced, Scoping, c } from "zodiac-roles-sdk"; -import { EIP_712_SIGNER_ADDRESS, SIGN_FUNCTION_SELECTOR, TYPED_VALUE_TUPLE } from "./const"; +import { EIP_712_SIGNER_ADDRESS } from "./const"; import { scopeTypedData } from "./scopeTypedData"; import { asAbiType } from "./utils"; +import { encodeTypes } from "./encodeTypedData"; type AllowEip712SignatureParameters< typedData extends TypedData | Record = TypedData, @@ -68,10 +69,14 @@ export const allowEip712Signature = ({ return encodeAbiParameters([abiParam], [value]); }; -const encodeTypes = ({ types, primaryType }: { types: TypedData; primaryType: string }): Type[] => { +export const encodeTypes = ({ types, primaryType }: { types: TypedData; primaryType: string }): Type[] => { const { EIP712Domain: _0, [primaryType]: _1, ...rest } = types; const orderedTypeKeys = ["EIP712Domain", primaryType, ...Object.keys(rest)]; diff --git a/src/scopeTypedData.ts b/src/scopeTypedData.ts index f229bd2..925b4ad 100644 --- a/src/scopeTypedData.ts +++ b/src/scopeTypedData.ts @@ -2,11 +2,11 @@ import { ParamType } from "ethers"; import { TypedData } from "viem"; import { Condition, Operator, ParameterType, c } from "zodiac-roles-sdk"; -import { TYPED_VALUE_TUPLE, TYPED_VALUE_TUPLE_ARRAY } from "./const"; -import { DataType } from "./types"; -import { encodeStructType, isAtomic } from "./utils"; - -/** Maps over a condition structure formulated to scope the typed data object, turning it into a condition structure scoping the corresponding TypedValue encoding */ +/** + * Maps over a condition structure formulated to scope the typed data object, + * turning it into a condition structure scoping the recursively ABI encoded value as sent to the contract. + * Once the contract can decode directly from calldata, we should be able to send the original conditions structure so this function will be obsolete. + **/ export const scopeTypedData = ({ condition, types, @@ -42,12 +42,15 @@ export const scopeTypedData = ({ } const elementType = type.split("[")[0]; - return { - ...condition, - children: condition.children?.map((child) => - scopeTypedData({ condition: child, types, type: elementType, scopeSignature }), - ), - }; + return c.abiEncodedMatches( + [ + { + ...condition, + children: condition.children?.map((child) => scopeTypedData({ condition: child, types, type: elementType })), + }, + ], + ["bytes[]"], + )(ParamType.from("bytes")); } // struct @@ -61,25 +64,18 @@ export const scopeTypedData = ({ } const structFields = types[type]; - return c.matches({ - dataType: DataType.Struct, - value: c.abiEncodedMatches( - [ - structFields.map(({ type }, index) => - condition.children && !!condition.children[index] - ? scopeTypedData({ condition: condition.children[index], types, type }) - : undefined, - ), - ], - [TYPED_VALUE_TUPLE_ARRAY], - ), - structSignature: scopeSignature ? encodeStructType({ types, primaryType: type }) : undefined, - })(ParamType.from(TYPED_VALUE_TUPLE)); + return c.abiEncodedMatches( + [ + structFields.map(({ type }, index) => + condition.children && !!condition.children[index] + ? scopeTypedData({ condition: condition.children[index], types, type }) + : undefined, + ), + ], + ["bytes[]"], + )(ParamType.from("bytes")); } // basic types - return c.matches({ - dataType: isAtomic(type) ? DataType.Atomic : DataType.Dynamic, - value: c.abiEncodedMatches([condition], [type]), - })(ParamType.from(TYPED_VALUE_TUPLE)); + return c.abiEncodedMatches([condition], [type])(ParamType.from("bytes")); };