-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api kit] Update delegates endpoint to v2 #804
Merged
leonardotc
merged 20 commits into
development
from
feat/api-kit/update-delegates-endpoint
May 10, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c4d8440
Update api endpoint version
leonardotc 319d739
Api code ready
leonardotc 673a5d1
Encoded delegate
leonardotc 5c68523
Add pad util
leonardotc 1a5e837
Fix tests
leonardotc 98bb327
Merge remote-tracking branch 'origin/development' into feat/api-kit/u…
leonardotc 58c73f4
Fix remaining tests
leonardotc c949a06
Fix more tests
leonardotc 3f7784e
Change function name
leonardotc 813a97f
Moved hex function
leonardotc 3166ed3
Remove the function altogether
leonardotc 61c604e
Merge remote-tracking branch 'origin/development' into feat/api-kit/u…
leonardotc e8584ee
Checkout contract utils
leonardotc 2ccf2ee
Changed usage for new default
leonardotc 3e6049f
Fix failing endpoint tests
leonardotc 5c3b555
Add todo
leonardotc 444f8de
Merge remote-tracking branch 'origin/development' into feat/api-kit/u…
leonardotc 2cc8623
Moved helper function
leonardotc db41198
Moved pad function
leonardotc 1d8e99f
Hot fix
leonardotc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is SafeDelegateResponse right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is the request body which is marked as any on the type.