@@ -17,20 +17,25 @@ import {
1717} from "./database" ;
1818
1919export const getRegistrationOptions = async (
20- ephemeralWalletAddress : string
20+ userName : string ,
21+ jwtPubKey : string
2122) : Promise < PublicKeyCredentialCreationOptionsJSON > => {
22- const challenge = await bcrypt . hash ( ephemeralWalletAddress , 10 ) ;
23+ const userID = isoUint8Array . fromASCIIString ( await bcrypt . hash ( jwtPubKey , 0 ) ) ;
24+ const challenge = await bcrypt . hash ( jwtPubKey , 10 ) ;
2325
26+ // Generate registration options:
27+ // challenge: JWT public key hashed
28+ // userID: JWT public key hashed
29+ // userName: string like user_xxxx
2430 const registrationOptionsParameters : GenerateRegistrationOptionsOpts = {
2531 rpName : "Passkeys TACo PoC" ,
2632 rpID : "localhost" ,
27- userName : ephemeralWalletAddress , // to be shown in passkey popup
28- userID : isoUint8Array . fromASCIIString ( ephemeralWalletAddress ) ,
29- challenge : isoUint8Array . fromASCIIString ( challenge ) ,
30- userDisplayName : ephemeralWalletAddress ,
33+ userName : userName , // to be shown in passkey popup
34+ userID : userID ,
35+ challenge : challenge ,
3136 timeout : 60000 ,
3237 // excludeCredentials: [],
33- supportedAlgorithmIDs : [ - 7 , - 257 ] ,
38+ supportedAlgorithmIDs : [ - 7 , - 257 ] , // ES256, RS256
3439 } ;
3540
3641 const registrationOptions = await generateRegistrationOptions (
@@ -44,7 +49,8 @@ export const getRegistrationOptions = async (
4449} ;
4550
4651export const verifyRegistration = async (
47- ephemeralWalletAddress : string ,
52+ userName : string ,
53+ jwtPubKey : string ,
4854 registrationResponse : RegistrationResponseJSON
4955) : Promise < VerifiedRegistrationResponse > => {
5056 const db = await getOrCreateDatabase ( ) ;
@@ -55,18 +61,18 @@ export const verifyRegistration = async (
5561 throw new Error ( "Invalid credentials" ) ;
5662 }
5763
58- const challenge = db . registrationOptions [ ephemeralWalletAddress ] . challenge ;
64+ const dbChallenge = db . registrationOptions [ userName ] . challenge ;
5965
60- if ( ! challenge ) {
66+ if ( ! dbChallenge ) {
6167 throw new Error (
6268 "No challenge found for this ephemeral wallet address in DB"
6369 ) ;
6470 }
6571
66- // Check the ephemeral wallet address provided againt the challenge in DB
72+ // Check the JWT public key provided against the challenge in DB
6773 const challengeCheck = await bcrypt . compare (
68- ephemeralWalletAddress ,
69- isoBase64URL . toUTF8String ( challenge )
74+ jwtPubKey ,
75+ isoBase64URL . toUTF8String ( dbChallenge )
7076 ) ;
7177 if ( ! challengeCheck ) {
7278 throw new Error ( "Challenge verification failed" ) ;
@@ -75,7 +81,7 @@ export const verifyRegistration = async (
7581 try {
7682 verificationResponse = await verifyRegistrationResponse ( {
7783 response : registrationResponse ,
78- expectedChallenge : challenge ,
84+ expectedChallenge : dbChallenge ,
7985 expectedOrigin : "http://localhost:3000" ,
8086 expectedRPID : "localhost" ,
8187 } ) ;
@@ -88,7 +94,7 @@ export const verifyRegistration = async (
8894 throw new Error ( "Registration verification failed" ) ;
8995 }
9096
91- removeRegistrationOptions ( ephemeralWalletAddress ) ;
97+ removeRegistrationOptions ( userName ) ;
9298
9399 return verificationResponse ;
94100} ;
0 commit comments