-
Notifications
You must be signed in to change notification settings - Fork 22
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
EIP1271 Support #617
Open
derekpierre
wants to merge
10
commits into
nucypher:epic-v0.6.x
Choose a base branch
from
derekpierre:eip1271-support
base: epic-v0.6.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
EIP1271 Support #617
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
da59608
Implement EIP1271Provider and authentication signature.
derekpierre 3520710
Add EIP1271AuthProvider functionality to the ConditionContext.
derekpierre b83ddfc
Add tests for EIP1271AuthProvider and authentication signature genera…
derekpierre 21ca011
Move authentication provider tests around within context tests to be …
derekpierre b507f29
Ensure that AuthSignature types are exported.
derekpierre 9b4a1d6
feat: update auth provider type validation
theref acaade3
Apply PR suggestion to simplify AuthProviderType
theref db87517
Add bogus provider for failure testing
theref 6307d7c
Fix fakeAuthProvider to implement AuthProvider properly
theref b84e8eb
Fix linting errors.
derekpierre 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { EthAddressSchema } from '@nucypher/shared'; | ||
import { z } from 'zod'; | ||
|
||
import { | ||
EIP4361_AUTH_METHOD, | ||
EIP4361TypedDataSchema, | ||
} from './providers/eip4361/common'; | ||
import { EIP1271AuthSignature } from './providers/eip1271/auth'; | ||
import { EIP4361AuthSignature } from './providers/eip4361/auth'; | ||
|
||
export const authSignatureSchema = z.object({ | ||
export const baseAuthSignatureSchema = z.object({ | ||
signature: z.string(), | ||
address: EthAddressSchema, | ||
scheme: z.enum([EIP4361_AUTH_METHOD]), | ||
typedData: EIP4361TypedDataSchema, | ||
scheme: z.string(), | ||
typedData: z.unknown(), | ||
}); | ||
|
||
export type AuthSignature = z.infer<typeof authSignatureSchema>; | ||
export type AuthSignature = EIP4361AuthSignature | EIP1271AuthSignature; |
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,17 @@ | ||
import { z } from 'zod'; | ||
|
||
import { baseAuthSignatureSchema } from '../../auth-sig'; | ||
|
||
export const EIP1271_AUTH_METHOD = 'EIP1271'; | ||
|
||
export const EIP1271TypedDataSchema = z.object({ | ||
chain: z.number().int().nonnegative(), | ||
dataHash: z.string().startsWith('0x'), // hex string | ||
}); | ||
|
||
export const eip1271AuthSignatureSchema = baseAuthSignatureSchema.extend({ | ||
scheme: z.literal(EIP1271_AUTH_METHOD), | ||
typedData: EIP1271TypedDataSchema, | ||
}); | ||
|
||
export type EIP1271AuthSignature = z.infer<typeof eip1271AuthSignatureSchema>; |
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,22 @@ | ||
import { EIP1271_AUTH_METHOD, EIP1271AuthSignature } from './auth'; | ||
|
||
export class EIP1271AuthProvider { | ||
constructor( | ||
public readonly contractAddress: string, | ||
public readonly chain: number, | ||
public readonly dataHash: string, | ||
public readonly signature: string, | ||
) {} | ||
|
||
public async getOrCreateAuthSignature(): Promise<EIP1271AuthSignature> { | ||
return { | ||
signature: this.signature, | ||
address: this.contractAddress, | ||
scheme: EIP1271_AUTH_METHOD, | ||
typedData: { | ||
chain: this.chain, | ||
dataHash: this.dataHash, | ||
}, | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
// TODO: should we export with package names? | ||
export { EIP1271AuthSignature } from './eip1271/auth'; | ||
export * from './eip1271/eip1271'; | ||
export { EIP4361AuthSignature } from './eip4361/auth'; | ||
export * from './eip4361/eip4361'; | ||
export * from './eip4361/external-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
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.
Maybe I'm missing something, but the function name (
getOrCREATEAuthSignature()
) makes me think that the function is able to create a newEIP1271AuthProvider
object, but this is not correct, right? This function will be called only for already created objects. Should we rename it?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.
It's the flip. AuthProviders implement the function
getOrCreateAuthSignature()
. The AuthProvider is specified as a parameter to the ConditionContext, which then uses it to generate an AuthSignature via thegetOrCreateAuthSignature()
function.So for EIP1271 as an example the code looks like the following:
This conditionContext can then provide the auth signature data needed for proving ownership using the auth provider - see https://github.com/derekpierre/taco-web/blob/eip1271-support/packages/taco/src/conditions/context/context.ts#L116.
The
getOrCreateAuthSignature()
was named (perhaps incorrectly so) as such because it may not actually create the object because the auth signature object could be cached. For example, EIP4361 caches the auth signature after first creating it for 2 hours and doesn't need to create it again within that 2 hours i.e. subsequet calls togetOrCreateAuthSignature
simply uses the cached object if called again within that 2-hour window. That being said, perhaps the name is too tied to implementation. we can always rename it togetAuthSignature()
or something else ... although let's do that in a different PR ...?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.
Got it!
|
Yes, something to consider, but in a different PR.
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.
Filed #621