@@ -4,9 +4,6 @@ import { ethers } from 'ethers';
4
4
import * as request from 'supertest' ;
5
5
import { v4 } from 'uuid' ;
6
6
import { AppModule } from '../src/app.module' ;
7
- import { keccak256 } from 'ethers/lib/utils' ;
8
- import * as circomlib from 'circomlibjs' ;
9
- import * as crypto from 'crypto' ;
10
7
import {
11
8
supplierBpiSubjectEcdsaPublicKey ,
12
9
supplierBpiSubjectEcdsaPrivateKey ,
@@ -15,6 +12,11 @@ import {
15
12
internalBpiSubjectEcdsaPublicKey ,
16
13
internalBpiSubjectEcdsaPrivateKey ,
17
14
} from '../src/shared/testing/constants' ;
15
+ import {
16
+ createEddsaPrivateKey ,
17
+ createEddsaPublicKey ,
18
+ createEddsaSignature ,
19
+ } from '../src/shared/testing/utils' ;
18
20
19
21
jest . setTimeout ( 120000 ) ;
20
22
@@ -368,42 +370,3 @@ async function fetchBpiAccount(bpiAccountId: string): Promise<any> {
368
370
369
371
return JSON . parse ( getBpiAccountResponse . text ) ;
370
372
}
371
-
372
- async function createEddsaPrivateKey (
373
- ecdsaPublicKeyOwnerEthereumAccount : string ,
374
- signer : ethers . Wallet ,
375
- ) : Promise < string > {
376
- const message = keccak256 ( ecdsaPublicKeyOwnerEthereumAccount ) ;
377
- const eddsaPrivateKey = await signer . signMessage ( message ) ;
378
-
379
- return eddsaPrivateKey ;
380
- }
381
-
382
- async function createEddsaPublicKey ( eddsaPrivateKey : string ) : Promise < string > {
383
- const eddsa = await circomlib . buildEddsa ( ) ;
384
- const babyJub = await circomlib . buildBabyjub ( ) ;
385
-
386
- const privateKeyBytes = Buffer . from ( eddsaPrivateKey , 'hex' ) ;
387
- const publicKeyPoints = eddsa . prv2pub ( privateKeyBytes ) ;
388
- const eddsaPublicKey = Buffer . from (
389
- babyJub . packPoint ( publicKeyPoints ) ,
390
- ) . toString ( 'hex' ) ;
391
-
392
- return eddsaPublicKey ;
393
- }
394
-
395
- async function createEddsaSignature (
396
- payload : any ,
397
- eddsaPrivateKey : string ,
398
- ) : Promise < string > {
399
- const eddsa = await circomlib . buildEddsa ( ) ;
400
- const hashedPayload = crypto
401
- . createHash ( 'sha256' )
402
- . update ( JSON . stringify ( payload ) )
403
- . digest ( ) ;
404
-
405
- const eddsaSignature = eddsa . signPedersen ( eddsaPrivateKey , hashedPayload ) ;
406
- const packedSignature = eddsa . packSignature ( eddsaSignature ) ;
407
- const signature = Buffer . from ( packedSignature ) . toString ( 'hex' ) ;
408
- return signature ;
409
- }
0 commit comments