@@ -8,6 +8,7 @@ import { IdentitySigner } from '../../identity/signer.js'
88import { IdentityHandler } from './identity.js'
99import { Kinds } from '../types/signer.js'
1010import type { NavigationLike , WdkEnv } from '../../env.js'
11+ import type { CommitAuthArgs } from '../../dbs/auth-commitments.js'
1112
1213export class AuthCodeHandler extends IdentityHandler implements Handler {
1314 protected redirectUri : string = ''
@@ -39,19 +40,23 @@ export class AuthCodeHandler extends IdentityHandler implements Handler {
3940 this . redirectUri = redirectUri
4041 }
4142
42- public async commitAuth ( target : string , isSignUp : boolean , state ?: string , signer ?: string ) {
43- if ( ! state ) {
44- state = Hex . fromBytes ( Bytes . random ( 32 ) )
45- }
43+ public async commitAuth ( target : string , args : CommitAuthArgs ) {
44+ const state = args . state ?? Hex . fromBytes ( Bytes . random ( 32 ) )
4645
47- await this . commitments . set ( {
46+ const base = {
4847 id : state ,
49- kind : this . signupKind ,
50- signer,
48+ kind : this . signupKind as Db . AuthCommitment [ 'kind' ] ,
5149 target,
5250 metadata : { } ,
53- isSignUp,
54- } )
51+ }
52+
53+ if ( args . type === 'reauth' ) {
54+ await this . commitments . set ( { ...base , type : 'reauth' , signer : args . signer } )
55+ } else if ( args . type === 'add-signer' ) {
56+ await this . commitments . set ( { ...base , type : 'add-signer' , wallet : args . wallet } )
57+ } else {
58+ await this . commitments . set ( { ...base , type : 'auth' } )
59+ }
5560
5661 const searchParams = this . serializeQuery ( {
5762 client_id : this . audience ,
@@ -69,7 +74,7 @@ export class AuthCodeHandler extends IdentityHandler implements Handler {
6974 code : string ,
7075 ) : Promise < [ IdentitySigner , { [ key : string ] : string } ] > {
7176 let challenge = new Identity . AuthCodeChallenge ( this . issuer , this . audience , this . redirectUri , code )
72- if ( commitment . signer ) {
77+ if ( commitment . type === 'reauth' ) {
7378 challenge = challenge . withSigner ( { address : commitment . signer , keyType : Identity . KeyType . Ethereum_Secp256k1 } )
7479 }
7580 await this . nitroCommitVerifier ( challenge )
@@ -103,7 +108,11 @@ export class AuthCodeHandler extends IdentityHandler implements Handler {
103108 message : 'request-redirect' ,
104109 handle : async ( ) => {
105110 const navigation = this . getNavigation ( )
106- const url = await this . commitAuth ( navigation . getPathname ( ) , false , request . id , address )
111+ const url = await this . commitAuth ( navigation . getPathname ( ) , {
112+ type : 'reauth' ,
113+ state : request . id ,
114+ signer : address ,
115+ } )
107116 navigation . redirect ( url )
108117 return true
109118 } ,
0 commit comments