@@ -139,7 +139,6 @@ export async function retrieveOrImportShare(params: {
139
139
} ) : Promise < TorusKey > {
140
140
const {
141
141
legacyMetadataHost,
142
- serverTimeOffset,
143
142
enableOneKey,
144
143
ecCurve,
145
144
allowHost,
@@ -317,7 +316,14 @@ export async function retrieveOrImportShare(params: {
317
316
let thresholdNonceData : GetOrSetNonceResult ;
318
317
return Some <
319
318
void | JRPCResponse < ShareRequestResult > ,
320
- | { privateKey : BN ; sessionTokenData : SessionToken [ ] ; thresholdNonceData : GetOrSetNonceResult ; nodeIndexes : BN [ ] ; isNewKey : boolean }
319
+ | {
320
+ privateKey : BN ;
321
+ sessionTokenData : SessionToken [ ] ;
322
+ thresholdNonceData : GetOrSetNonceResult ;
323
+ nodeIndexes : BN [ ] ;
324
+ isNewKey : boolean ;
325
+ serverTimeOffsetResponse ?: number ;
326
+ }
321
327
| undefined
322
328
> ( promiseArrRequest , async ( shareResponses , sharedState ) => {
323
329
// check if threshold number of nodes have returned the same user public key
@@ -377,6 +383,7 @@ export async function retrieveOrImportShare(params: {
377
383
const nodeIndexes : BN [ ] = [ ] ;
378
384
const sessionTokenData : SessionToken [ ] = [ ] ;
379
385
const isNewKeyResponses : string [ ] = [ ] ;
386
+ const serverTimeOffsetResponses : string [ ] = [ ] ;
380
387
381
388
for ( let i = 0 ; i < completedRequests . length ; i += 1 ) {
382
389
const currentShareResponse = completedRequests [ i ] as JRPCResponse < ShareRequestResult > ;
@@ -387,9 +394,11 @@ export async function retrieveOrImportShare(params: {
387
394
session_token_sig_metadata : sessionTokenSigMetadata ,
388
395
keys,
389
396
is_new_key : isNewKey ,
397
+ server_time_offset : serverTimeOffset ,
390
398
} = currentShareResponse . result ;
391
399
392
400
isNewKeyResponses . push ( isNewKey ) ;
401
+ serverTimeOffsetResponses . push ( serverTimeOffset ) ;
393
402
394
403
if ( sessionTokenSigs ?. length > 0 ) {
395
404
// decrypt sessionSig if enc metadata is sent
@@ -513,13 +522,24 @@ export async function retrieveOrImportShare(params: {
513
522
}
514
523
const thresholdIsNewKey = thresholdSame ( isNewKeyResponses , ~ ~ ( endpoints . length / 2 ) + 1 ) ;
515
524
516
- return { privateKey, sessionTokenData, thresholdNonceData, nodeIndexes, isNewKey : thresholdIsNewKey === "true" } ;
525
+ // Convert each string timestamp to a number
526
+ const epochTimes = serverTimeOffsetResponses . map ( ( timestamp ) => parseInt ( timestamp , 10 ) ) ;
527
+
528
+ // console.log(epochTimes); // Output: 1709299134
529
+ return {
530
+ privateKey,
531
+ sessionTokenData,
532
+ thresholdNonceData,
533
+ nodeIndexes,
534
+ isNewKey : thresholdIsNewKey === "true" ,
535
+ serverTimeOffsetResponse : Math . max ( ...epochTimes ) ,
536
+ } ;
517
537
}
518
538
throw new Error ( "Invalid" ) ;
519
539
} ) ;
520
540
} )
521
541
. then ( async ( res ) => {
522
- const { privateKey, sessionTokenData, thresholdNonceData, nodeIndexes, isNewKey } = res ;
542
+ const { privateKey, sessionTokenData, thresholdNonceData, nodeIndexes, isNewKey, serverTimeOffsetResponse } = res ;
523
543
let nonceResult = thresholdNonceData ;
524
544
if ( ! privateKey ) throw new Error ( "Invalid private key returned" ) ;
525
545
const oAuthKey = privateKey ;
@@ -538,7 +558,8 @@ export async function retrieveOrImportShare(params: {
538
558
finalPubKey = ecCurve . keyFromPublic ( { x : oAuthPubkeyX , y : oAuthPubkeyY } ) . getPublic ( ) ;
539
559
} else if ( LEGACY_NETWORKS_ROUTE_MAP [ network as TORUS_LEGACY_NETWORK_TYPE ] ) {
540
560
if ( enableOneKey ) {
541
- nonceResult = await getOrSetNonce ( legacyMetadataHost , ecCurve , serverTimeOffset , oAuthPubkeyX , oAuthPubkeyY , oAuthKey , ! isNewKey ) ;
561
+ const serverTimeOffsetValue = this . serverTimeOffset || serverTimeOffsetResponse ;
562
+ nonceResult = await getOrSetNonce ( legacyMetadataHost , ecCurve , serverTimeOffsetValue , oAuthPubkeyX , oAuthPubkeyY , oAuthKey , ! isNewKey ) ;
542
563
metadataNonce = new BN ( nonceResult . nonce || "0" , 16 ) ;
543
564
typeOfUser = nonceResult . typeOfUser ;
544
565
if ( typeOfUser === "v2" ) {
0 commit comments