This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
forked from nucypher/taco-web
-
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(auth): validate user-provided auth signature
- Loading branch information
1 parent
4eea8e7
commit 85cd025
Showing
21 changed files
with
244 additions
and
117 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
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,4 @@ | ||
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); |
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
19 changes: 7 additions & 12 deletions
19
packages/taco-auth/src/types.ts → packages/taco-auth/src/auth-provider.ts
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,19 @@ | ||
import { EthAddressSchema } from '@nucypher/shared'; | ||
import { z } from 'zod'; | ||
|
||
import { EIP4361_AUTH_METHOD, EIP712_AUTH_METHOD } from './auth-provider'; | ||
import { EIP4361TypedDataSchema, EIP712TypedDataSchema } from './providers'; | ||
|
||
|
||
export const authSignatureSchema = z.object({ | ||
signature: z.string(), | ||
address: EthAddressSchema, | ||
scheme: z.enum([EIP712_AUTH_METHOD, EIP4361_AUTH_METHOD]), | ||
typedData: z.union([ | ||
EIP4361TypedDataSchema, | ||
// TODO(#536): Remove post EIP712 deprecation | ||
EIP712TypedDataSchema, | ||
]), | ||
}); | ||
|
||
export type AuthSignature = z.infer<typeof authSignatureSchema>; |
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import {ethers} from "ethers"; | ||
import { ethers } from 'ethers'; | ||
|
||
import { EIP4361AuthProvider, EIP4361AuthProviderParams } from './providers/eip4361'; | ||
import { EIP712AuthProvider } from './providers/eip712'; | ||
import { AuthProviders, EIP4361_AUTH_METHOD, EIP712_AUTH_METHOD } from './types'; | ||
import { AuthProviders, EIP4361_AUTH_METHOD, EIP712_AUTH_METHOD } from './auth-provider'; | ||
import { | ||
EIP4361AuthProvider, | ||
EIP4361AuthProviderParams, | ||
EIP712AuthProvider, | ||
} from './providers'; | ||
|
||
export const makeAuthProviders = ( | ||
provider: ethers.providers.Provider, | ||
signer?: ethers.Signer, | ||
siweDefaultParams?: EIP4361AuthProviderParams | ||
siweDefaultParams?: EIP4361AuthProviderParams, | ||
): AuthProviders => { | ||
return { | ||
[EIP712_AUTH_METHOD]: signer ? new EIP712AuthProvider(provider, signer) : undefined, | ||
[EIP4361_AUTH_METHOD]: signer ? new EIP4361AuthProvider(provider, signer, siweDefaultParams) : undefined | ||
[EIP4361_AUTH_METHOD]: signer ? new EIP4361AuthProvider(provider, signer, siweDefaultParams) : undefined, | ||
} as AuthProviders; | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './providers/eip4361'; | ||
export * from './providers/eip712'; | ||
export * from './types'; | ||
export * from './providers'; | ||
export * from './helper'; | ||
export * from './auth-sig'; | ||
export * from './auth-provider'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,2 @@ | ||
import { EIP4361_AUTH_METHOD, EIP712_AUTH_METHOD } from '../types'; | ||
|
||
import { EIP4361AuthProvider, EIP4361TypedData } from './eip4361'; | ||
import { EIP712AuthProvider, EIP712TypedData } from './eip712'; | ||
|
||
export interface AuthSignatureProvider { | ||
getOrCreateAuthSignature(): Promise<AuthSignature>; | ||
} | ||
|
||
export type AuthProviders = { | ||
[EIP712_AUTH_METHOD]?: EIP712AuthProvider; | ||
[EIP4361_AUTH_METHOD]?: EIP4361AuthProvider; | ||
// Fallback to satisfy type checking | ||
[key: string]: AuthProvider | undefined; | ||
}; | ||
|
||
export interface AuthSignature { | ||
signature: string; | ||
address: string; | ||
scheme: 'EIP712' | 'EIP4361'; | ||
typedData: EIP712TypedData | EIP4361TypedData; | ||
} | ||
|
||
// Add other providers here | ||
export type AuthProvider = AuthSignatureProvider; | ||
export * from './eip712'; | ||
export * from './eip4361'; |
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.