9
9
addSessionKeyBlob , // <- version corrigée ci-dessus
10
10
WalletEventCallback ,
11
11
walletContractName ,
12
- build_check_jwt_blob ,
13
12
} from "../types/wallet" ; // ajuste le chemin si besoin
14
13
15
14
import { BlobTransaction } from "hyli" ; // ajuste le chemin si besoin
@@ -18,11 +17,8 @@ import { IndexerService } from "../services/IndexerService";
18
17
import { sessionKeyService } from "../services/SessionKeyService" ;
19
18
20
19
import * as WalletOperations from "../services/WalletOperations" ;
21
- import { Barretenberg , Fr } from "@aztec/bb.js" ;
22
- import { bytesToBigInt , extractClaimsFromJwt , JWTCircuitHelper , register_contract } from "../utils/jwt" ;
23
- import { fetchGooglePublicKey } from "../utils/google" ;
24
- import { circuit } from "../utils/jwt_circuit" ;
25
- import { Blob } from "hyli" ;
20
+ import { check_jwt } from "hyli-noir" ;
21
+ import { fetchGooglePublicKeys } from "../utils/google" ;
26
22
27
23
export interface GoogleAuthCredentials {
28
24
username : string ; // requis par AuthCredentials
@@ -167,14 +163,14 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
167
163
168
164
onWalletEvent ?.( { account, type : "checking_password" , message : "Verifying Google identity…" } ) ;
169
165
170
- const jwtBlobData = await this . buildCheckJwtBlob ( credentials . googleToken , onError ) ;
166
+ const { keys } = await fetchGooglePublicKeys ( ) ;
167
+
168
+ const jwtBlobData = await check_jwt . build_blob_from_jwt ( credentials . googleToken , keys ) ;
171
169
172
170
if ( jwtBlobData instanceof Error ) {
173
171
return { success : false , error : jwtBlobData . message } ;
174
172
}
175
173
176
- console . log ( "Blob0 data (stored_hash):" , jwtBlobData . blob . data ) ;
177
-
178
174
const blob1 = verifyIdentityBlob ( username , jwtBlobData . nonce ) ;
179
175
180
176
const blobTx : BlobTransaction = {
@@ -190,7 +186,7 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
190
186
blobTx . blobs . push ( addSessionKeyBlob ( username , newSessionKey . publicKey , expiration , whitelist ) ) ;
191
187
}
192
188
193
- await register_contract ( nodeService . client , circuit as any ) ;
189
+ await check_jwt . register_contract ( nodeService . client ) ;
194
190
195
191
onWalletEvent ?.( { account, type : "sending_blob" , message : `Sending blob transaction` } ) ;
196
192
// Skipped, to make sure we send the proof alongside.
@@ -207,17 +203,15 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
207
203
onWalletEvent ?.( { account, type : "custom" , message : `Generating proof of jwt` } ) ;
208
204
209
205
// Generate proof using JWT circuit
210
- const proof_tx = await JWTCircuitHelper . generateProofTx ( {
211
- identity : account ,
212
- stored_hash : jwtBlobData . blob . data ,
213
- tx : txHash ,
214
- blob_index : 0 ,
215
- tx_blob_count : 2 ,
216
- idToken : credentials . googleToken ,
217
- jwtPubkey : jwtBlobData . pubkey ,
218
- } ) ;
219
-
220
- console . log ( "Generated JWT proof:" , proof_tx ) ;
206
+ const proof_tx = await check_jwt . build_proof_transaction (
207
+ account ,
208
+ jwtBlobData . blob . data ,
209
+ txHash ,
210
+ 0 ,
211
+ 2 ,
212
+ credentials . googleToken ,
213
+ jwtBlobData . pubkey ,
214
+ ) ;
221
215
222
216
await nodeService . client . sendProofTx ( proof_tx ) ;
223
217
@@ -243,47 +237,6 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
243
237
}
244
238
}
245
239
246
- async buildCheckJwtBlob (
247
- googleToken : string ,
248
- onError ?: ( error : Error ) => void ,
249
- ) : Promise < { blob : Blob ; nonce : number ; mail_hash : Fr ; pubkey : JsonWebKey } | Error > {
250
- const { email, nonce, kid } = extractClaimsFromJwt ( googleToken ) ;
251
-
252
- if ( ! email || ! nonce || ! kid ) {
253
- const error = "Invalid Google token: missing email, nonce, or kid" ;
254
- onError ?.( new Error ( error ) ) ;
255
- return new Error ( error ) ;
256
- }
257
-
258
- // Get Google pubkey
259
- const googleJWTPubkey = await fetchGooglePublicKey ( kid ) ;
260
-
261
- let mail_hash : Fr = Fr . ZERO ;
262
-
263
- console . log ( "Computing mail_hash for email" , email ) ;
264
- const bb = await Barretenberg . new ( ) ;
265
- console . log ( "selected_mail" , email ) ;
266
- console . log ( "email byte array" , new TextEncoder ( ) . encode ( email ) ) ;
267
- console . log ( "email bigint:" , bytesToBigInt ( new TextEncoder ( ) . encode ( email ) ) ) ;
268
- mail_hash = await bb . poseidon2Hash ( [ new Fr ( bytesToBigInt ( new TextEncoder ( ) . encode ( email ) ) ) ] ) . catch ( ( err ) => {
269
- console . error ( "Error computing poseidon hash:" , err ) ;
270
- throw err ;
271
- } ) ;
272
-
273
- console . log ( "Computed mail_hash:" , mail_hash ) ;
274
- console . log ( "mail_hash as bigint:" , bytesToBigInt ( mail_hash . value ) ) ;
275
- console . log ( "mail_hash as hex:" , mail_hash . toString ( ) ) ;
276
-
277
- // Generate proof using JWT circuit
278
-
279
- return {
280
- nonce : parseInt ( nonce , 10 ) ,
281
- mail_hash,
282
- pubkey : googleJWTPubkey ,
283
- blob : build_check_jwt_blob ( mail_hash . value , nonce , googleJWTPubkey . n as string ) as Blob ,
284
- } ;
285
- }
286
-
287
240
async register ( params : RegisterAccountParams < GoogleAuthCredentials > ) : Promise < AuthResult > {
288
241
console . log ( "[Hyli][Google] register() called" ) ;
289
242
const nodeService = NodeService . getInstance ( ) ;
@@ -318,7 +271,9 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
318
271
} ;
319
272
}
320
273
321
- const jwtBlobData = await this . buildCheckJwtBlob ( googleToken , onError ) ;
274
+ const { keys } = await fetchGooglePublicKeys ( ) ;
275
+
276
+ const jwtBlobData = await check_jwt . build_blob_from_jwt ( googleToken , keys ) ;
322
277
323
278
if ( jwtBlobData instanceof Error ) {
324
279
return { success : false , error : jwtBlobData . message } ;
@@ -330,7 +285,7 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
330
285
username ,
331
286
jwtBlobData . nonce ,
332
287
"" ,
333
- { Jwt : { hash : Array . from ( jwtBlobData . mail_hash . value ) } } ,
288
+ { Jwt : { hash : jwtBlobData . mail_hash } } ,
334
289
inviteCode ,
335
290
) ;
336
291
@@ -347,7 +302,7 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
347
302
blobTx . blobs . push ( addSessionKeyBlob ( username , newSessionKey . publicKey , expiration , whitelist ) ) ;
348
303
}
349
304
350
- await register_contract ( nodeService . client , circuit as any ) ;
305
+ await check_jwt . register_contract ( nodeService . client ) ;
351
306
352
307
onWalletEvent ?.( { account : identity , type : "sending_blob" , message : `Sending blob transaction` } ) ;
353
308
// Skipped, to make sure we send the proof alongside.
@@ -364,17 +319,15 @@ export class GoogleAuthProvider implements AuthProvider<GoogleAuthCredentials> {
364
319
onWalletEvent ?.( { account : identity , type : "custom" , message : `Generating proof of jwt` } ) ;
365
320
366
321
// Generate proof using JWT circuit
367
- const proof_tx = await JWTCircuitHelper . generateProofTx ( {
322
+ const proof_tx = await check_jwt . build_proof_transaction (
368
323
identity ,
369
- stored_hash : jwtBlobData . blob . data ,
370
- tx : txHash ,
371
- blob_index : 0 ,
372
- tx_blob_count : 3 ,
373
- idToken : googleToken ,
374
- jwtPubkey : jwtBlobData . pubkey ,
375
- } ) ;
376
-
377
- console . log ( "Generated JWT proof:" , proof_tx ) ;
324
+ jwtBlobData . blob . data ,
325
+ txHash ,
326
+ 0 ,
327
+ 3 ,
328
+ googleToken ,
329
+ jwtBlobData . pubkey ,
330
+ ) ;
378
331
379
332
await nodeService . client . sendProofTx ( proof_tx ) ;
380
333
0 commit comments