@@ -14,9 +14,8 @@ const TORUS_TEST_VERIFIER = "torus-test-health";
14
14
const TORUS_TEST_AGGREGATE_VERIFIER = "torus-aggregate-sapphire-mainnet" ;
15
15
const HashEnabledVerifier = "torus-test-verifierid-hash" ;
16
16
const TORUS_EXTENDED_VERIFIER_EMAIL = "[email protected] " ;
17
- const TORUS_IMPORT_EMAIL = "[email protected] " ;
18
17
19
- describe ( "torus utils sapphire mainnet" , function ( ) {
18
+ describe . only ( "torus utils sapphire mainnet" , function ( ) {
20
19
let torus : TorusUtils ;
21
20
let TORUS_NODE_MANAGER : NodeManager ;
22
21
@@ -50,15 +49,15 @@ describe("torus utils sapphire mainnet", function () {
50
49
X : "56e803db7710adbfe0ecca35bc6a3ad27e966df142e157e76e492773c88e8433" ,
51
50
Y : "f4168594c1126ca731756dd480f992ee73b0834ba4b787dd892a9211165f50a3" ,
52
51
} ,
53
- nonce : new BN ( "f3ba568eeeaca5c285b25878a067fd85b1720b94f9099591d4274dc0a8cada9b " , "hex" ) ,
52
+ nonce : new BN ( "0 " , "hex" ) ,
54
53
upgraded : false ,
55
54
typeOfUser : "v2" ,
56
55
} ,
57
56
nodesData : result . nodesData ,
58
57
} ) ;
59
58
} ) ;
60
59
61
- it . skip ( "should be able to import a key for a new user" , async function ( ) {
60
+ it ( "should be able to import a key for a new user" , async function ( ) {
62
61
const email = faker . internet . email ( ) ;
63
62
const token = generateIdToken ( email , "ES256" ) ;
64
63
const ec = new EC ( "secp256k1" ) ;
@@ -77,29 +76,33 @@ describe("torus utils sapphire mainnet", function () {
77
76
privHex
78
77
) ;
79
78
expect ( result . finalKeyData . privKey ) . to . be . equal ( privHex ) ;
80
- } ) ;
81
- it . skip ( "should be able to import a key for a existing user" , async function ( ) {
82
- let verifierDetails = { verifier : TORUS_TEST_VERIFIER , verifierId : TORUS_IMPORT_EMAIL } ;
83
- const nodeDetails = await TORUS_NODE_MANAGER . getNodeDetails ( verifierDetails ) ;
84
- const torusNodeEndpoints = nodeDetails . torusNodeSSSEndpoints ;
85
- const token = generateIdToken ( TORUS_IMPORT_EMAIL , "ES256" ) ;
86
- const ec = new EC ( "secp256k1" ) ;
87
79
88
- const privKeyBuffer = generatePrivateKey ( ec , Buffer ) ;
89
- const privHex = privKeyBuffer . toString ( "hex" ) ;
90
- const result1 = await torus . importPrivateKey (
80
+ const { finalKeyData } = await torus . getPublicAddress ( torusNodeEndpoints , nodeDetails . torusNodePub , {
81
+ verifier : TORUS_TEST_VERIFIER ,
82
+ verifierId : email ,
83
+ } ) ;
84
+ expect ( result . finalKeyData . evmAddress ) . to . be . equal ( finalKeyData . evmAddress ) ;
85
+
86
+ const privKeyBufferNew = generatePrivateKey ( ec , Buffer ) ;
87
+ const privHexNew = privKeyBufferNew . toString ( "hex" ) ;
88
+ const tokenNew = generateIdToken ( email , "ES256" ) ;
89
+
90
+ const resultNew = await torus . importPrivateKey (
91
91
torusNodeEndpoints ,
92
92
nodeDetails . torusIndexes ,
93
93
nodeDetails . torusNodePub ,
94
94
TORUS_TEST_VERIFIER ,
95
- { verifier_id : TORUS_IMPORT_EMAIL } ,
96
- token ,
97
- privHex
95
+ { verifier_id : email } ,
96
+ tokenNew ,
97
+ privHexNew
98
98
) ;
99
- expect ( result1 . finalKeyData . privKey ) . to . be . equal ( privHex ) ;
100
- verifierDetails = { verifier : TORUS_TEST_VERIFIER , verifierId : TORUS_IMPORT_EMAIL } ;
101
- const result2 = await torus . getPublicAddress ( torusNodeEndpoints , nodeDetails . torusNodePub , verifierDetails ) ;
102
- expect ( result1 . finalKeyData . evmAddress ) . to . be . equal ( result2 . finalKeyData . evmAddress ) ;
99
+ expect ( resultNew . finalKeyData . privKey ) . to . be . equal ( privHexNew ) ;
100
+
101
+ const { finalKeyData : finalKeyDataNew } = await torus . getPublicAddress ( torusNodeEndpoints , nodeDetails . torusNodePub , {
102
+ verifier : TORUS_TEST_VERIFIER ,
103
+ verifierId : email ,
104
+ } ) ;
105
+ expect ( resultNew . finalKeyData . evmAddress ) . to . be . equal ( finalKeyDataNew . evmAddress ) ;
103
106
} ) ;
104
107
105
108
it ( "should be able to key assign" , async function ( ) {
@@ -208,7 +211,7 @@ describe("torus utils sapphire mainnet", function () {
208
211
X : "498ed301af25a3b7136f478fa58677c79a6d6fe965bc13002a6f459b896313bd" ,
209
212
Y : "d6feb9a1e0d6d0627fbb1ce75682bc09ab4cf0e2da4f0f7fcac0ba9d07596c8f" ,
210
213
} ,
211
- nonce : new BN ( "3c2b6ba5b54ca0ba4ae978eb48429a84c47b7b3e526b35e7d46dd716887f52bf " , "hex" ) ,
214
+ nonce : new BN ( "0 " , "hex" ) ,
212
215
upgraded : false ,
213
216
typeOfUser : "v2" ,
214
217
} ,
@@ -238,7 +241,7 @@ describe("torus utils sapphire mainnet", function () {
238
241
X : "498ed301af25a3b7136f478fa58677c79a6d6fe965bc13002a6f459b896313bd" ,
239
242
Y : "d6feb9a1e0d6d0627fbb1ce75682bc09ab4cf0e2da4f0f7fcac0ba9d07596c8f" ,
240
243
} ,
241
- nonce : new BN ( "3c2b6ba5b54ca0ba4ae978eb48429a84c47b7b3e526b35e7d46dd716887f52bf " , "hex" ) ,
244
+ nonce : new BN ( "0 " , "hex" ) ,
242
245
upgraded : false ,
243
246
typeOfUser : "v2" ,
244
247
} ,
@@ -357,4 +360,33 @@ describe("torus utils sapphire mainnet", function () {
357
360
expect ( result . metadata . nonce ) . to . not . equal ( null ) ;
358
361
expect ( result . metadata . upgraded ) . to . equal ( false ) ;
359
362
} ) ;
363
+
364
+ it ( "should be able to update the `sessionTime` of the token signature data" , async function ( ) {
365
+ const email = faker . internet . email ( ) ;
366
+ const token = generateIdToken ( TORUS_TEST_EMAIL , "ES256" ) ;
367
+
368
+ const nodeDetails = await TORUS_NODE_MANAGER . getNodeDetails ( { verifier : TORUS_TEST_AGGREGATE_VERIFIER , verifierId : email } ) ;
369
+ const torusNodeEndpoints = nodeDetails . torusNodeSSSEndpoints ;
370
+ torusNodeEndpoints [ 1 ] = "https://example.com" ;
371
+
372
+ const customSessionTime = 3600 ;
373
+ TorusUtils . setSessionTime ( customSessionTime ) ; // 1hr
374
+
375
+ const result = await torus . retrieveShares (
376
+ torusNodeEndpoints ,
377
+ nodeDetails . torusIndexes ,
378
+ TORUS_TEST_VERIFIER ,
379
+ { verifier_id : TORUS_TEST_EMAIL } ,
380
+ token ,
381
+ nodeDetails . torusNodePub
382
+ ) ;
383
+
384
+ const signatures = result . sessionData . sessionTokenData . map ( ( s ) => ( { data : s . token , sig : s . signature } ) ) ;
385
+
386
+ const parsedSigsData = signatures . map ( ( s ) => JSON . parse ( atob ( s . data ) ) ) ;
387
+ parsedSigsData . forEach ( ( ps ) => {
388
+ const sessionTime = ps . exp - Math . floor ( Date . now ( ) / 1000 ) ;
389
+ expect ( sessionTime ) . eql ( customSessionTime ) ;
390
+ } ) ;
391
+ } ) ;
360
392
} ) ;
0 commit comments