forked from safe-global/safe-core-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api kit) Update delegates endpoint to v2 (safe-global#804)
* Update api endpoint version
- Loading branch information
1 parent
9caadb3
commit 8cf4bf8
Showing
6 changed files
with
79 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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', | ||
version: '1.0', | ||
chainId: chainId | ||
} | ||
|
||
const types = { | ||
Delegate: [ | ||
{ name: 'delegateAddress', type: 'bytes32' }, | ||
{ 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 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters