File tree 10 files changed +28
-20
lines changed
backend/src/api/resources
ui/components/UserProfile
10 files changed +28
-20
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @clerk/clerk-js " : minor
3
+ " @clerk/backend " : minor
4
+ " @clerk/types " : minor
5
+ ---
6
+
7
+ Use EIP-4361 message spec for Web3 wallets sign in signature requests
Original file line number Diff line number Diff line change @@ -326,6 +326,7 @@ export interface VerificationJSON extends ClerkResourceJSON {
326
326
verified_at_client ?: string ;
327
327
external_verification_redirect_url ?: string | null ;
328
328
nonce ?: string | null ;
329
+ message ?: string | null ;
329
330
}
330
331
331
332
export interface Web3WalletJSON extends ClerkResourceJSON {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export class Verification {
10
10
readonly attempts : number | null = null ,
11
11
readonly expireAt : number | null = null ,
12
12
readonly nonce : string | null = null ,
13
+ readonly message : string | null = null ,
13
14
) { }
14
15
15
16
static fromJSON ( data : VerificationJSON ) : Verification {
Original file line number Diff line number Diff line change @@ -250,14 +250,14 @@ export class SignIn extends BaseResource implements SignInResource {
250
250
251
251
await this . prepareFirstFactor ( web3FirstFactor ) ;
252
252
253
- const { nonce } = this . firstFactorVerification ;
254
- if ( ! nonce ) {
253
+ const { message } = this . firstFactorVerification ;
254
+ if ( ! message ) {
255
255
clerkVerifyWeb3WalletCalledBeforeCreate ( 'SignIn' ) ;
256
256
}
257
257
258
258
let signature : string ;
259
259
try {
260
- signature = await generateSignature ( { identifier, nonce, provider } ) ;
260
+ signature = await generateSignature ( { identifier, nonce : message , provider } ) ;
261
261
} catch ( err ) {
262
262
// There is a chance that as a user when you try to setup and use the Coinbase Wallet with an existing
263
263
// Passkey in order to authenticate, the initial generate signature request to be rejected. For this
@@ -266,7 +266,7 @@ export class SignIn extends BaseResource implements SignInResource {
266
266
// error code 4001 means the user rejected the request
267
267
// Reference: https://docs.cdp.coinbase.com/wallet-sdk/docs/errors
268
268
if ( provider === 'coinbase_wallet' && err . code === 4001 ) {
269
- signature = await generateSignature ( { identifier, nonce, provider } ) ;
269
+ signature = await generateSignature ( { identifier, nonce : message , provider } ) ;
270
270
} else {
271
271
throw err ;
272
272
}
Original file line number Diff line number Diff line change @@ -203,14 +203,14 @@ export class SignUp extends BaseResource implements SignUpResource {
203
203
await this . create ( { web3Wallet, unsafeMetadata } ) ;
204
204
await this . prepareWeb3WalletVerification ( { strategy } ) ;
205
205
206
- const { nonce } = this . verifications . web3Wallet ;
207
- if ( ! nonce ) {
206
+ const { message } = this . verifications . web3Wallet ;
207
+ if ( ! message ) {
208
208
clerkVerifyWeb3WalletCalledBeforeCreate ( 'SignUp' ) ;
209
209
}
210
210
211
211
let signature : string ;
212
212
try {
213
- signature = await generateSignature ( { identifier, nonce, provider } ) ;
213
+ signature = await generateSignature ( { identifier, nonce : message , provider } ) ;
214
214
} catch ( err ) {
215
215
// There is a chance that as a first time visitor when you try to setup and use the
216
216
// Coinbase Wallet from scratch in order to authenticate, the initial generate
@@ -220,7 +220,7 @@ export class SignUp extends BaseResource implements SignUpResource {
220
220
// error code 4001 means the user rejected the request
221
221
// Reference: https://docs.cdp.coinbase.com/wallet-sdk/docs/errors
222
222
if ( provider === 'coinbase_wallet' && err . code === 4001 ) {
223
- signature = await generateSignature ( { identifier, nonce, provider } ) ;
223
+ signature = await generateSignature ( { identifier, nonce : message , provider } ) ;
224
224
} else {
225
225
throw err ;
226
226
}
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export class Verification extends BaseResource implements VerificationResource {
23
23
status : VerificationStatus | null = null ;
24
24
strategy : string | null = null ;
25
25
nonce : string | null = null ;
26
+ message : string | null = null ;
26
27
externalVerificationRedirectURL : URL | null = null ;
27
28
attempts : number | null = null ;
28
29
expireAt : Date | null = null ;
@@ -44,6 +45,7 @@ export class Verification extends BaseResource implements VerificationResource {
44
45
this . verifiedAtClient = data . verified_at_client ;
45
46
this . strategy = data . strategy ;
46
47
this . nonce = data . nonce || null ;
48
+ this . message = data . message || null ;
47
49
if ( data . external_verification_redirect_url ) {
48
50
this . externalVerificationRedirectURL = new URL ( data . external_verification_redirect_url ) ;
49
51
} else {
Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ export const AddWeb3WalletActionMenu = withCardStateProvider(() => {
31
31
32
32
let web3Wallet = await user . createWeb3Wallet ( { web3Wallet : identifier } ) ;
33
33
web3Wallet = await web3Wallet . prepareVerification ( { strategy } ) ;
34
- const nonce = web3Wallet . verification . nonce as string ;
35
- const signature = await generateWeb3Signature ( { identifier, nonce, provider } ) ;
34
+ const message = web3Wallet . verification . message as string ;
35
+ const signature = await generateWeb3Signature ( { identifier, nonce : message , provider } ) ;
36
36
await web3Wallet . attemptVerification ( { signature } ) ;
37
37
card . setIdle ( ) ;
38
38
} catch ( err ) {
Original file line number Diff line number Diff line change @@ -21,9 +21,7 @@ export async function getWeb3Identifier(params: GetWeb3IdentifierParams): Promis
21
21
return ( identifiers && identifiers [ 0 ] ) || '' ;
22
22
}
23
23
24
- type GenerateWeb3SignatureParams = {
25
- identifier : string ;
26
- nonce : string ;
24
+ type GenerateWeb3SignatureParams = GenerateSignatureParams & {
27
25
provider : Web3Provider ;
28
26
} ;
29
27
@@ -55,15 +53,12 @@ type GenerateSignatureParams = {
55
53
nonce : string ;
56
54
} ;
57
55
58
- export async function generateSignatureWithMetamask ( { identifier , nonce } : GenerateSignatureParams ) : Promise < string > {
59
- return await generateWeb3Signature ( { identifier , nonce , provider : 'metamask' } ) ;
56
+ export async function generateSignatureWithMetamask ( params : GenerateSignatureParams ) : Promise < string > {
57
+ return await generateWeb3Signature ( { ... params , provider : 'metamask' } ) ;
60
58
}
61
59
62
- export async function generateSignatureWithCoinbaseWallet ( {
63
- identifier,
64
- nonce,
65
- } : GenerateSignatureParams ) : Promise < string > {
66
- return await generateWeb3Signature ( { identifier, nonce, provider : 'coinbase_wallet' } ) ;
60
+ export async function generateSignatureWithCoinbaseWallet ( params : GenerateSignatureParams ) : Promise < string > {
61
+ return await generateWeb3Signature ( { ...params , provider : 'coinbase_wallet' } ) ;
67
62
}
68
63
69
64
async function getEthereumProvider ( provider : Web3Provider ) {
Original file line number Diff line number Diff line change @@ -261,6 +261,7 @@ export interface VerificationJSON extends ClerkResourceJSON {
261
261
verified_at_client : string ;
262
262
strategy : string ;
263
263
nonce ?: string ;
264
+ message ?: string ;
264
265
external_verification_redirect_url ?: string ;
265
266
attempts : number ;
266
267
expire_at : number ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export interface VerificationResource extends ClerkResource {
8
8
expireAt : Date | null ;
9
9
externalVerificationRedirectURL : URL | null ;
10
10
nonce : string | null ;
11
+ message : string | null ;
11
12
status : VerificationStatus | null ;
12
13
strategy : string | null ;
13
14
verifiedAtClient : string | null ;
You can’t perform that action at this time.
0 commit comments