-
Notifications
You must be signed in to change notification settings - Fork 23
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
Validate user-provided AuthSignature
#537
Validate user-provided AuthSignature
#537
Conversation
bbfae8c
to
5dd8396
Compare
776a065
to
e8649d8
Compare
e8649d8
to
85cd025
Compare
4eea8e7
to
5a4d072
Compare
85cd025
to
3fdf1d9
Compare
3fdf1d9
to
be42ddc
Compare
@@ -36,11 +38,24 @@ export class LocalStorage { | |||
: new BrowserStorage(); | |||
} | |||
|
|||
getItem(key: string): string | null { | |||
return this.storage.getItem(key); | |||
public getAuthSignature(key: string): AuthSignature | null { |
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.
Looks great
packages/shared/src/schemas.ts
Outdated
import { z } from 'zod'; | ||
|
||
export const ETH_ADDRESS_REGEXP = new RegExp('^0x[a-fA-F0-9]{40}$'); | ||
export const EthAddressSchema = z.string().regex(ETH_ADDRESS_REGEXP); |
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.
Should we go a step further and validate the address with ethers and a zod .refine
?
packages/taco-auth/src/storage.ts
Outdated
} | ||
|
||
setItem(key: string, value: string): void { | ||
this.storage.setItem(key, value); | ||
public static toJson(signature: AuthSignature): string { |
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.
Not a blocker but it's a bit weird that json<=>authsignature conversion methods are part of the storage interface
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.
LGTM! 👌
packages/test-utils/src/utils.ts
Outdated
@@ -53,8 +53,8 @@ export const fromBytes = (bytes: Uint8Array): string => | |||
|
|||
export const fakePorterUri = 'https://_this_should_crash.com/'; | |||
|
|||
const makeFakeProvider = (timestamp: number, blockNumber: number) => { | |||
const block = { timestamp }; | |||
const makeFakeProvider = (timestamp: number, blockNumber: number, blockHash: string) => { |
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.
Not relevant for this PR, but shouldn't the code formatter split this line in several ones?
const makeFakeProvider = (timestamp: number, blockNumber: number, blockHash: string) => { | |
const makeFakeProvider = ( | |
timestamp: number, | |
blockNumber: number, | |
blockHash: string, | |
) => { |
|
||
export type EIP4361TypedData = string; | ||
|
||
export const EIP4361TypedDataSchema = z.string(); |
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.
Should we use zod refine
here as well? You can try calling the SiweMessage
constructor as part of the refine function to ensure that the string can be parsed properly.
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.
Addressed here: f9e2030
(#527)
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.
🎸
Type of PR:
Required reviews:
What this does:
AuthSignature
validation withzod
taco-auth
to prevent circular-dependency issues that breakzod
Issues fixed/closed:
Why it's needed:
Notes for reviewers: