@@ -451,28 +451,16 @@ export async function retrieveOrImportShare(params: {
451451 nodeSigs . map ( ( x ) => x && x . pub_key_x ) ,
452452 halfThreshold
453453 ) ;
454- } else if ( ! checkCommitment && finalImportedShares . length > 0 ) {
455- // in case not allowed to override existing key for import request
456- // check if key exists
457- if ( ! overrideExistingKey ) {
458- const keyLookupResult = await VerifierLookupRequest ( { endpoints, verifier, verifierId : verifierParams . verifier_id , keyType } ) ;
459- if (
460- keyLookupResult . errorResult &&
461- ! ( keyLookupResult . errorResult ?. data as string ) ?. includes ( "Verifier + VerifierID has not yet been assigned" )
462- ) {
463- throw new Error (
464- `node results do not match at first lookup ${ JSON . stringify ( keyLookupResult . keyResult || { } ) } , ${ JSON . stringify ( keyLookupResult . errorResult || { } ) } `
465- ) ;
466- }
467- if ( keyLookupResult . keyResult ?. keys ?. length > 0 ) {
468- isExistingKey = ! ! keyLookupResult . keyResult . keys [ 0 ] ;
469- }
470- }
471454 }
455+ let isImportingShares = false ;
456+
472457 const promiseArrRequest = [ ] ;
473458
474- const canImportedShares = overrideExistingKey || ( ! useDkg && ! isExistingKey ) ;
475- if ( canImportedShares ) {
459+ // if dkg is not used, we need to get existing key or import new shares from client
460+ const getExistingKeyOrImportNewShares = ! useDkg ;
461+ if ( overrideExistingKey ) {
462+ console . log ( "importing new shares" ) ;
463+ isImportingShares = true ;
476464 const proxyEndpointNum = getProxyCoordinatorEndpointIndex ( endpoints , verifier , verifierParams . verifier_id ) ;
477465 const items : Record < string , unknown > [ ] = [ ] ;
478466 for ( let i = 0 ; i < endpoints . length ; i += 1 ) {
@@ -515,7 +503,55 @@ export async function retrieveOrImportShare(params: {
515503 { logTracingHeader : config . logRequestTracing }
516504 ) . catch ( ( err ) => log . error ( "share req" , err ) ) ;
517505 promiseArrRequest . push ( p ) ;
506+ } else if ( getExistingKeyOrImportNewShares ) {
507+ console . log ( "importing new shares or fetch existing key" ) ;
508+
509+ isImportingShares = true ;
510+ const proxyEndpointNum = getProxyCoordinatorEndpointIndex ( endpoints , verifier , verifierParams . verifier_id ) ;
511+ const items : Record < string , unknown > [ ] = [ ] ;
512+ for ( let i = 0 ; i < endpoints . length ; i += 1 ) {
513+ const importedShare = finalImportedShares [ i ] ;
514+ if ( ! importedShare ) {
515+ throw new Error ( `invalid imported share at index ${ i } ` ) ;
516+ }
517+ items . push ( {
518+ ...verifierParams ,
519+ idtoken : idToken ,
520+ nodesignatures : nodeSigs ,
521+ verifieridentifier : verifier ,
522+ pub_key_x : importedShare . oauth_pub_key_x ,
523+ pub_key_y : importedShare . oauth_pub_key_y ,
524+ signing_pub_key_x : importedShare . signing_pub_key_x ,
525+ signing_pub_key_y : importedShare . signing_pub_key_y ,
526+ encrypted_share : importedShare . encrypted_share ,
527+ encrypted_share_metadata : importedShare . encrypted_share_metadata ,
528+ node_index : importedShare . node_index ,
529+ key_type : importedShare . key_type ,
530+ nonce_data : importedShare . nonce_data ,
531+ nonce_signature : importedShare . nonce_signature ,
532+ sss_endpoint : endpoints [ i ] ,
533+ ...extraParams ,
534+ } ) ;
535+ }
536+ const p = post < JRPCResponse < ImportShareRequestResult [ ] > > (
537+ endpoints [ proxyEndpointNum ] ,
538+ generateJsonRPCObject ( JRPC_METHODS . GET_KEY_OR_IMPORT_SHARES , {
539+ encrypted : "yes" ,
540+ use_temp : true ,
541+ verifieridentifier : verifier ,
542+ distributed_metadata : true ,
543+ temppubx : nodeSigs . length === 0 && ! checkCommitment ? sessionPubX : "" , // send session pub key x only if node signatures are not available (Ie. in non commitment flow)
544+ temppuby : nodeSigs . length === 0 && ! checkCommitment ? sessionPubY : "" , // send session pub key y only if node signatures are not available (Ie. in non commitment flow)
545+ item : items ,
546+ key_type : keyType ,
547+ one_key_flow : true ,
548+ } ) ,
549+ { } ,
550+ { logTracingHeader : config . logRequestTracing }
551+ ) . catch ( ( err ) => log . error ( "share req" , err ) ) ;
552+ promiseArrRequest . push ( p ) ;
518553 } else {
554+ console . log ( "fetch existing shares or assign new key with dkg" ) ;
519555 for ( let i = 0 ; i < endpoints . length ; i += 1 ) {
520556 const p = post < JRPCResponse < ShareRequestResult > > (
521557 endpoints [ i ] ,
@@ -610,7 +646,7 @@ export async function retrieveOrImportShare(params: {
610646 }
611647 } ) ;
612648
613- const thresholdReqCount = canImportedShares ? endpoints . length : halfThreshold ;
649+ const thresholdReqCount = isImportingShares && ! isExistingKey ? endpoints . length : halfThreshold ;
614650 // optimistically run lagrange interpolation once threshold number of shares have been received
615651 // this is matched against the user public key to ensure that shares are consistent
616652 // Note: no need of thresholdMetadataNonce for extended_verifier_id key
0 commit comments