1
1
import CommonSources
2
2
import FetchNodeDetails
3
3
import Foundation
4
+ @testable import tkey_mpc_swift
4
5
import TorusUtils
5
6
import XCTest
6
- @testable import tkey_mpc_swift
7
7
8
8
final class integrationTests : XCTestCase {
9
9
func test_TssModule( ) async throws {
@@ -21,11 +21,14 @@ final class integrationTests: XCTestCase {
21
21
let idToken = try generateIdToken ( email: TORUS_TEST_EMAIL)
22
22
let verifierParams = VerifierParams ( verifier_id: TORUS_TEST_EMAIL)
23
23
let retrievedShare = try await torusUtils. retrieveShares ( endpoints: nodeDetail. torusNodeEndpoints, torusNodePubs: nodeDetail. torusNodePub, indexes: nodeDetail. torusIndexes, verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: idToken)
24
- let signature = retrievedShare. sessionData? . sessionTokenData
25
- let signatures = signature!. compactMap { item in
26
- item? . signature
24
+
25
+ let signature_collection = retrievedShare. sessionData!. sessionTokenData. map { token in
26
+ [ " data " : Data ( hex: token!. token) . base64EncodedString ( ) ,
27
+ " sig " : token!. signature]
27
28
}
28
29
30
+ let sigs : [ String ] = try signature_collection. map { String ( decoding: try JSONSerialization . data ( withJSONObject: $0) , as: UTF8 . self) }
31
+
29
32
let postbox_key = try ! PrivateKey . generate ( )
30
33
let storage_layer = try ! StorageLayer ( enable_logging: true , host_url: " https://metadata.tor.us " , server_time_offset: 2 )
31
34
let service_provider = try ! ServiceProvider ( enable_logging: true , postbox_key: postbox_key. hex, useTss: true , verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, nodeDetails: nodeDetail)
@@ -47,7 +50,7 @@ final class integrationTests: XCTestCase {
47
50
let factorKey = try PrivateKey . generate ( )
48
51
let factorPub = try factorKey. toPublic ( )
49
52
try TssModule . backup_share_with_factor_key ( threshold_key: threshold, shareIndex: shareIndex. hex, factorKey: factorKey. hex)
50
-
53
+
51
54
try await TssModule . create_tagged_tss_share ( threshold_key: threshold, tss_tag: tssTag, deviceTssShare: nil , factorPub: factorPub, deviceTssIndex: 2 , nodeDetails: nodeDetail, torusUtils: torusUtils)
52
55
53
56
let ( tss_index, tss_share) = try await TssModule . get_tss_share ( threshold_key: threshold, tss_tag: tssTag, factorKey: factorKey. hex)
@@ -57,7 +60,7 @@ final class integrationTests: XCTestCase {
57
60
let newFactorKey = try PrivateKey . generate ( )
58
61
let newFactorPub = try newFactorKey. toPublic ( )
59
62
// 2/2 -> 2/3 tss
60
- try await TssModule . generate_tss_share ( threshold_key: threshold, tss_tag: tssTag, input_tss_share: tss_share, tss_input_index: Int32 ( tss_index) !, auth_signatures: signatures , new_factor_pub: newFactorPub, new_tss_index: 3 , nodeDetails: nodeDetail, torusUtils: torusUtils)
63
+ try await TssModule . generate_tss_share ( threshold_key: threshold, tss_tag: tssTag, input_tss_share: tss_share, tss_input_index: Int32 ( tss_index) !, auth_signatures: sigs , new_factor_pub: newFactorPub, new_tss_index: 3 , nodeDetails: nodeDetail, torusUtils: torusUtils)
61
64
let ( tss_index3, tss_share3) = try await TssModule . get_tss_share ( threshold_key: threshold, tss_tag: tssTag, factorKey: newFactorKey. hex)
62
65
63
66
let ( _, tss_share_updated) = try await TssModule . get_tss_share ( threshold_key: threshold, tss_tag: tssTag, factorKey: factorKey. hex)
@@ -74,7 +77,7 @@ final class integrationTests: XCTestCase {
74
77
manual_sync: false
75
78
)
76
79
_ = try ! await threshold2. initialize ( )
77
-
80
+
78
81
try await threshold2. input_factor_key ( factorKey: factorKey. hex)
79
82
_ = try ! await threshold2. reconstruct ( )
80
83
@@ -91,7 +94,7 @@ final class integrationTests: XCTestCase {
91
94
XCTAssertEqual ( tss_index3, tss_index2_3)
92
95
93
96
// 2/3 -> 2/2 tss
94
- try await TssModule . delete_tss_share ( threshold_key: threshold, tss_tag: tssTag, input_tss_share: tss_share3, tss_input_index: Int32 ( tss_index3) !, auth_signatures: signatures , delete_factor_pub: newFactorPub, nodeDetails: nodeDetail, torusUtils: torusUtils)
97
+ try await TssModule . delete_tss_share ( threshold_key: threshold, tss_tag: tssTag, input_tss_share: tss_share3, tss_input_index: Int32 ( tss_index3) !, auth_signatures: sigs , delete_factor_pub: newFactorPub, nodeDetails: nodeDetail, torusUtils: torusUtils)
95
98
// XCTAssertThrowsError( try await TssModule.get_tss_share(threshold_key: threshold, tss_tag: tssTag, factorKey: newFactorKey.hex) )
96
99
97
100
let ( tss_index_updated2, tss_share_updated2) = try await TssModule . get_tss_share ( threshold_key: threshold, tss_tag: tssTag, factorKey: factorKey. hex)
@@ -101,10 +104,10 @@ final class integrationTests: XCTestCase {
101
104
XCTAssertNotEqual ( tss_share_updated, tss_share_updated2)
102
105
103
106
// 2/2 -> 2/3 tss
104
- try await TssModule . add_factor_pub ( threshold_key: threshold, tss_tag: tssTag, factor_key: factorKey. hex, auth_signatures: signatures , new_factor_pub: newFactorPub, new_tss_index: 3 , nodeDetails: nodeDetail, torusUtils: torusUtils)
107
+ try await TssModule . add_factor_pub ( threshold_key: threshold, tss_tag: tssTag, factor_key: factorKey. hex, auth_signatures: sigs , new_factor_pub: newFactorPub, new_tss_index: 3 , nodeDetails: nodeDetail, torusUtils: torusUtils)
105
108
106
109
// 2/3 -> 2/2 tss
107
- try await TssModule . delete_factor_pub ( threshold_key: threshold, tss_tag: tssTag, factor_key: factorKey. hex, auth_signatures: signatures , delete_factor_pub: newFactorPub, nodeDetails: nodeDetail, torusUtils: torusUtils)
110
+ try await TssModule . delete_factor_pub ( threshold_key: threshold, tss_tag: tssTag, factor_key: factorKey. hex, auth_signatures: sigs , delete_factor_pub: newFactorPub, nodeDetails: nodeDetail, torusUtils: torusUtils)
108
111
}
109
112
110
113
func test_TssModule_multi_tag( ) async throws {
@@ -125,12 +128,14 @@ final class integrationTests: XCTestCase {
125
128
let idToken = try generateIdToken ( email: TORUS_TEST_EMAIL)
126
129
let verifierParams = VerifierParams ( verifier_id: TORUS_TEST_EMAIL)
127
130
let retrievedShare = try await torusUtils. retrieveShares ( endpoints: nodeDetail. torusNodeSSSEndpoints, torusNodePubs: nodeDetail. torusNodePub, indexes: nodeDetail. torusIndexes, verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: idToken)
128
- print ( retrievedShare )
129
- let signature = retrievedShare. sessionData!. sessionTokenData
130
- let signatures = signature . compactMap { item in
131
- item ? . signature
131
+
132
+ let signature_collection = retrievedShare. sessionData!. sessionTokenData. map { token in
133
+ [ " data " : Data ( hex : token! . token ) . base64EncodedString ( ) ,
134
+ " sig " : token! . signature]
132
135
}
133
136
137
+ let sigs : [ String ] = try signature_collection. map { String ( decoding: try JSONSerialization . data ( withJSONObject: $0) , as: UTF8 . self) }
138
+
134
139
let postbox_key = try ! PrivateKey . generate ( )
135
140
let storage_layer = try ! StorageLayer ( enable_logging: true , host_url: " https://metadata.tor.us " , server_time_offset: 2 )
136
141
let service_provider = try ! ServiceProvider ( enable_logging: true , postbox_key: postbox_key. hex, useTss: true , verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, nodeDetails: nodeDetail)
@@ -191,7 +196,7 @@ final class integrationTests: XCTestCase {
191
196
192
197
newFactorKeys. append ( newFactorKey)
193
198
newFactorPubs. append ( newFactorPub)
194
- try await TssModule . add_factor_pub ( threshold_key: threshold, tss_tag: tag, factor_key: factorKeys [ index] . hex, auth_signatures: signatures , new_factor_pub: newFactorPub, new_tss_index: 3 , nodeDetails: nodeDetail, torusUtils: torusUtils)
199
+ try await TssModule . add_factor_pub ( threshold_key: threshold, tss_tag: tag, factor_key: factorKeys [ index] . hex, auth_signatures: sigs , new_factor_pub: newFactorPub, new_tss_index: 3 , nodeDetails: nodeDetail, torusUtils: torusUtils)
195
200
196
201
try await threshold. sync_local_metadata_transistions ( )
197
202
@@ -258,7 +263,7 @@ final class integrationTests: XCTestCase {
258
263
259
264
newFactorKeys2. append ( newFactorKey2)
260
265
newFactorPubs2. append ( newFactorPub2)
261
- try await TssModule . delete_factor_pub ( threshold_key: threshold, tss_tag: tag, factor_key: newFactorKeys [ index] . hex, auth_signatures: signatures , delete_factor_pub: newFactorPubs [ index] , nodeDetails: nodeDetail, torusUtils: torusUtils)
266
+ try await TssModule . delete_factor_pub ( threshold_key: threshold, tss_tag: tag, factor_key: newFactorKeys [ index] . hex, auth_signatures: sigs , delete_factor_pub: newFactorPubs [ index] , nodeDetails: nodeDetail, torusUtils: torusUtils)
262
267
}
263
268
try await threshold. sync_local_metadata_transistions ( )
264
269
print ( try threshold. get_all_tss_tags ( ) )
0 commit comments