-
Notifications
You must be signed in to change notification settings - Fork 398
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
Implement EIP-4361 support with SIWS message handling and verification #1918
Open
Bewinxed
wants to merge
10
commits into
supabase:master
Choose a base branch
from
Bewinxed:master
base: master
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
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e42bb2
feat: implement EIP-4361 support with SIWS message handling and verif…
Bewinxed fd8b16d
refactor: migrate SIWS utilities to web3/solana and remove deprecated…
Bewinxed 6e4c871
refactor: consolidate Ethereum signature verification into crypto pac…
Bewinxed 118eba4
refactor: migrate Solana utilities to a dedicated package and remove …
Bewinxed d8cdba4
feat: add domain validation for SIWS messages and refactor domain che…
Bewinxed 311291a
refactor: rename EIP-4361 references to Web3 and update related confi…
Bewinxed 0e96f8a
refactor: enhance SIWS error handling with structured error types and…
Bewinxed 54fdc0a
- streamline error messages & moved them to unified package.
Bewinxed efb21e7
- adjusted verification for some siws parameters.
Bewinxed 15cbbe7
refactor(api): change HTTP method for nonce endpoint to POST for secu…
Bewinxed 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,75 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/ed25519" | ||
"crypto/rand" | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/btcsuite/btcutil/base58" | ||
siws "github.com/supabase/auth/internal/utilities/siws" | ||
) | ||
|
||
func LogSIWSExample() { | ||
// Configuration | ||
domain := "localhost:9999" | ||
statement := "Sign in with your Solana account" | ||
version := "1" | ||
chain := "solana:mainnet" | ||
|
||
// Generate keys | ||
pubKey, privKey, err := ed25519.GenerateKey(rand.Reader) | ||
if err != nil { | ||
fmt.Println("Error generating keys:", err) | ||
return | ||
} | ||
pubKeyBase58 := base58.Encode(pubKey) | ||
|
||
// Generate nonce | ||
nonce, err := siws.GenerateNonce() | ||
if err != nil { | ||
fmt.Println("Error generating nonce:", err) | ||
return | ||
} | ||
|
||
// Create SIWS message | ||
msg := siws.SIWSMessage{ | ||
Domain: domain, | ||
Address: pubKeyBase58, | ||
Statement: statement, | ||
URI: "https://example.com", | ||
Version: version, | ||
Nonce: nonce, | ||
IssuedAt: time.Now().UTC(), | ||
} | ||
|
||
rawMessage := siws.ConstructMessage(msg) | ||
|
||
// Sign the message | ||
signature := ed25519.Sign(privKey, []byte(rawMessage)) | ||
signatureBase64 := base64.StdEncoding.EncodeToString(signature) | ||
|
||
// Generate JSON payload | ||
payload := map[string]string{ | ||
"grant_type": "eip4361", | ||
"message": rawMessage, | ||
"signature": signatureBase64, | ||
"address": pubKeyBase58, | ||
"chain": chain, | ||
} | ||
|
||
payloadJSON, err := json.Marshal(payload) | ||
if err != nil { | ||
fmt.Println("Error generating payload JSON:", err) | ||
return | ||
} | ||
|
||
// Print JavaScript fetch code | ||
fmt.Println(string(payloadJSON)) | ||
} | ||
|
||
// func main() { | ||
// LogSIWSExample() | ||
// } |
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.
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.
^ref to comment about nonce generation varying across implementation