Skip to content

Commit

Permalink
fix(api-kit): update delegate address type (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
dasanra authored Jun 21, 2024
1 parent 5176837 commit 64c0fcf
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions packages/api-kit/src/utils/signDelegate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { Signer } from 'ethers'

// TODO: remove this function in favor of viem#pad
function padHex(
hex: string,
{ dir = 'left', size = 32 }: { dir?: string; size?: number } = {}
): string {
if (size === null) return hex
const result = hex.replace('0x', '')
if (result.length > size * 2) throw new Error(`Size (${result.length}) exceeds padding size.`)

return `0x${result[dir === 'right' ? 'padEnd' : 'padStart'](size * 2, '0')}`
}

export async function signDelegate(signer: Signer, delegateAddress: string, chainId: bigint) {
const domain = {
name: 'Safe Transaction Service',
Expand All @@ -21,13 +9,12 @@ export async function signDelegate(signer: Signer, delegateAddress: string, chai

const types = {
Delegate: [
{ name: 'delegateAddress', type: 'bytes32' },
{ name: 'delegateAddress', type: 'address' },
{ name: 'totp', type: 'uint256' }
]
}

const totp = Math.floor(Date.now() / 1000 / 3600)
const paddedAddress = padHex(delegateAddress, { size: 32, dir: 'right' })

return await signer.signTypedData(domain, types, { delegateAddress: paddedAddress, totp })
return signer.signTypedData(domain, types, { delegateAddress, totp })
}

0 comments on commit 64c0fcf

Please sign in to comment.