-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Adds signAuthorization
method for EIP-7702
#407
base: main
Are you sure you want to change the base?
Conversation
5c46e25
to
bb5e268
Compare
bb5e268
to
b50bc64
Compare
* @property contractAddress - The address of the contract being authorized. | ||
* @property nonce - The nonce of the signing account (at the time of submission). | ||
*/ | ||
export type Authorization = [ |
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.
Minor, could Authorization
be or become too generic a term in the context of signing?
Should we call this something like EIP7702Authorization
?
Maybe 7702
as the filename?
* @param authorization - The authorization object to validate. | ||
* @throws {Error} If the authorization object or any of its required parameters are missing. | ||
*/ | ||
function validateAuthorization(authorization: Authorization) { |
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.
Minor, non-exported functions at the bottom of the file to highlight what is used externally?
|
||
const [chainId, contractAddress, nonce] = authorization; | ||
|
||
if (isNullish(chainId)) { |
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.
Do we definitely want to support / encourage cross-chain authorizations via the 0
chain ID?
Could we also validate it's not zero at this package level?
* @param options.authorization - The authorization data to sign. | ||
* @returns The '0x'-prefixed hex encoded signature. | ||
*/ | ||
export function signAuthorization({ |
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.
Minor, maybe sign7702Authorization
and the same format for the other functions?
Just to add more clarity if we get other types of authorization in future?
'hex', | ||
); | ||
|
||
const expectedSignature = |
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.
Minor, capitals and underscores for constants so EXPECTED_SIGNATURE
etc?
|
||
describe('signAuthorization', () => { | ||
describe('signAuthorization()', () => { | ||
it('should produce the correct signature', () => { |
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.
Minor, should
is redundant in test names? produces the correct signature
for example.
allZeroValues: [0, '0x0000000000000000000000000000000000000000', 0], | ||
} as { [key: string]: Authorization }; | ||
|
||
for (const [label, authorization] of Object.entries(testCases)) { |
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.
Minor, could also use a it.each
.
EIP-7702 defines a new struct
Authorization
which represents authority to set a pointer to a contract address at an EOA - effectively making the EOA perform as a smart contract.This change adds methods to hash and sign authorizations, and to recover signer address.
Although the EIP defines the signed authorization as
[chain_id, address, nonce, y_parity, r, s]
, the utility method returns the signature as a standardr|s|v
signature for consistency with other signing methods.See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7702.md for details