Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
ukstv committed Nov 24, 2023
1 parent baedcdb commit 18173a5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/varsig/src/canons/eip712.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ interface Eip712Domain {
verifyingContract: string
}

type IpldNode = Record<string, any> & { _sig: Uint8Array }
type IpldNode = Record<string, any>
type IpldNodeSigned = IpldNode & { _sig: Uint8Array }

interface Eip712TypeField {
name: string
Expand Down Expand Up @@ -243,7 +244,13 @@ function extractSignature(signature: string | SignatureComponents) {
}
}

export function fromEip712({ types, domain, primaryType, message, signature }: Eip712): IpldNode {
export function fromEip712({
types,
domain,
primaryType,
message,
signature,
}: Eip712): IpldNodeSigned {
const metadata = JSON.stringify([compressTypes(types), primaryType, compressDomain(domain)])
const metadataBytes = uint8arrays.fromString(metadata)
const metadataLength = varintes.encode(metadataBytes.length)[0]
Expand All @@ -264,7 +271,7 @@ export function fromEip712({ types, domain, primaryType, message, signature }: E
if (!message) throw new Error(`Message is required`)
const node = messageToIpld(message, types, primaryType)
node._sig = varsig
return node
return node as IpldNodeSigned
}

export function fromEip712A({ types, domain, primaryType, message }: Omit<Eip712, 'signature'>): {
Expand Down Expand Up @@ -296,8 +303,7 @@ function messageToIpld(
): IpldNode {
const node = {}
for (const [key, value] of Object.entries(message)) {
// @ts-ignore
const type = types[primaryType].find(({ name }) => name === key).type
const type = types[primaryType].find(({ name }) => name === key)?.type
if (!type) throw new Error(`Type for ${key} not found`)
if (type.startsWith('bytes')) {
// @ts-ignore
Expand Down

0 comments on commit 18173a5

Please sign in to comment.