Skip to content

Commit afd10e6

Browse files
Merge pull request #13 from tkey/alpha
Release 1.1.0
2 parents d702d61 + 6c0fd93 commit afd10e6

File tree

11 files changed

+187
-118
lines changed

11 files changed

+187
-118
lines changed

.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
on:
22
push:
33
branches:
4-
- master
5-
- v2
4+
- main
5+
- alpha
66
pull_request:
77
types:
88
- opened

.github/workflows/pr.yaml

-19
This file was deleted.

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
dependencies: [
1818
// Dependencies declare other packages that this package depends on.
1919
// .package(url: /* package url */, from: "1.0.0"),
20-
.package(name: "TorusUtils", url: "https://github.com/torusresearch/torus-utils-swift" , branch: "alpha"),
20+
.package(name: "TorusUtils", url: "https://github.com/torusresearch/torus-utils-swift" , from: "6.0.1"),
2121
// dev dependencies only
2222
.package(name:"CryptoSwift", url: "https://github.com/krzyzanowskim/CryptoSwift.git",from: "1.5.1"),
2323
.package(name:"jwt-kit", url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),

Sources/ThresholdKey/Modules/TssModule.swift

+135-22
Large diffs are not rendered by default.

Sources/ThresholdKey/StorageLayer.swift

-24
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ import Foundation
33
import lib
44
#endif
55

6-
/*
7-
extension NSMutableData {
8-
func appendString(_ string: String) {
9-
if let data = string.data(using: .utf8) {
10-
append(data)
11-
}
12-
}
13-
}
14-
*/
156

167
public final class StorageLayer {
178
private(set) var pointer: OpaquePointer?
@@ -21,21 +12,6 @@ public final class StorageLayer {
2112
// on entry for the callback
2213
private var obj_ref: UnsafeMutableRawPointer?
2314

24-
/* for multipart form data
25-
static func createMultipartBody(data: Data, boundary: String, file: String) -> Data {
26-
let body = NSMutableData()
27-
let lineBreak = "\r\n"
28-
let boundaryPrefix = "--\(boundary)\r\n"
29-
body.appendString(boundaryPrefix)
30-
body.appendString("Content-Disposition: form-data; name=\"\(file)\"\r\n")
31-
body.appendString("Content-Type: \("application/json;charset=utf-8")\r\n\r\n")
32-
body.append(data)
33-
body.appendString("\r\n")
34-
body.appendString("--\(boundary)--\(lineBreak)")
35-
return body as Data
36-
}
37-
*/
38-
3915
private static func percentEscapeString( string: String ) -> String {
4016
var characterSet = CharacterSet.alphanumerics
4117
characterSet.insert(charactersIn: "-.* ")

Sources/ThresholdKey/ThresholdKey.swift

+47-48
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,16 @@ public class ThresholdKey {
8484
return Metadata(pointer: result!)
8585
}
8686

87-
private func initialize(import_share: String?, input: ShareStore?, never_initialize_new_key: Bool?, include_local_metadata_transitions: Bool?, use_tss: Bool = false, device_tss_share: String?, device_tss_index: Int32?, tss_factor_pub: KeyPoint?, completion: @escaping (Result<KeyDetails, Error>) -> Void) {
87+
private func initialize(import_metdata_key: String?, input: ShareStore?, never_initialize_new_key: Bool?, include_local_metadata_transitions: Bool?, completion: @escaping (Result<KeyDetails, Error>) -> Void) {
8888
tkeyQueue.async {
8989
do {
9090
var errorCode: Int32 = -1
91-
var sharePointer: UnsafeMutablePointer<Int8>?
92-
var tssDeviceSharePointer: UnsafeMutablePointer<Int8>?
93-
var tssFactorPubPointer: OpaquePointer?
94-
var device_index: Int32 = device_tss_index ?? 2
95-
if import_share != nil {
96-
sharePointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: import_share!).utf8String)
97-
}
98-
99-
if device_tss_share != nil {
100-
tssDeviceSharePointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: device_tss_share!).utf8String)
101-
}
102-
103-
if tss_factor_pub != nil {
104-
tssFactorPubPointer = tss_factor_pub!.pointer
91+
var keyPointer: UnsafeMutablePointer<Int8>?
92+
var device_index: Int32 = 2
93+
let useTss = false
94+
95+
if import_metdata_key != nil {
96+
keyPointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: import_metdata_key!).utf8String)
10597
}
10698

10799
var storePtr: OpaquePointer?
@@ -114,7 +106,7 @@ public class ThresholdKey {
114106

115107
let curvePointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: self.curveN).utf8String)
116108
let ptr = withUnsafeMutablePointer(to: &device_index, { tssDeviceIndexPointer in withUnsafeMutablePointer(to: &errorCode, { error in
117-
threshold_key_initialize(self.pointer, sharePointer, storePtr, neverInitializeNewKey, includeLocalMetadataTransitions, curvePointer, use_tss, tssDeviceSharePointer, tssDeviceIndexPointer, tssFactorPubPointer, error) }) })
109+
threshold_key_initialize(self.pointer, keyPointer, storePtr, neverInitializeNewKey, includeLocalMetadataTransitions, false, curvePointer, useTss, nil, tssDeviceIndexPointer, nil, error) }) })
118110
guard errorCode == 0 else {
119111
throw RuntimeError("Error in ThresholdKey Initialize")
120112
}
@@ -129,22 +121,18 @@ public class ThresholdKey {
129121
/// Initializes a `ThresholdKey` object.
130122
///
131123
/// - Parameters:
132-
/// - import_share: Share to be imported, optional.
124+
/// - import_metdata_key: Metadata key to be imported, optional.
133125
/// - input: `ShareStore` to be used, optional.
134126
/// - never_initialize_new_key: Do not initialize a new tKey if an existing one is found.
135127
/// - include_local_matadata_transitions: Proritize existing metadata transitions over cloud fetched transitions.
136-
/// - use_tss: Whether TSS is used or not.
137-
/// - device_tss_share: Device share for TSS, optional
138-
/// - device_tss_index: Device index for TSS, optional
139-
/// - tss_factor_pub: Factor Key for TSS, optional
140128
///
141129
/// - Returns: `KeyDetails`
142130
///
143131
/// - Throws: `RuntimeError`, indicates invalid parameters.
144-
public func initialize(import_share: String? = nil, input: ShareStore? = nil, never_initialize_new_key: Bool? = nil, include_local_metadata_transitions: Bool? = nil, use_tss: Bool = false, device_tss_share: String? = nil, device_tss_index: Int32? = nil, tss_factor_pub: KeyPoint? = nil) async throws -> KeyDetails {
132+
public func initialize(import_metdata_key: String? = nil, input: ShareStore? = nil, never_initialize_new_key: Bool? = nil, include_local_metadata_transitions: Bool? = nil ) async throws -> KeyDetails {
145133
return try await withCheckedThrowingContinuation {
146134
continuation in
147-
self.initialize(import_share: import_share, input: input, never_initialize_new_key: never_initialize_new_key, include_local_metadata_transitions: include_local_metadata_transitions, use_tss: use_tss, device_tss_share: device_tss_share, device_tss_index: device_tss_index, tss_factor_pub: tss_factor_pub) {
135+
self.initialize(import_metdata_key: import_metdata_key, input: input, never_initialize_new_key: never_initialize_new_key, include_local_metadata_transitions: include_local_metadata_transitions ) {
148136
result in
149137
switch result {
150138
case let .success(result):
@@ -174,7 +162,9 @@ public class ThresholdKey {
174162
}
175163
}
176164

177-
/// Reconstructs the private key, this assumes that the number of shares inserted into the `ThrehsoldKey` are equal or greater than the threshold.
165+
/// Reconstructs the private key, this assumes that the number of shares inserted into the `ThresholdKey` are equal or greater than the threshold.
166+
///
167+
/// - Returns: `KeyReconstructionDetails`
178168
///
179169
/// - Throws: `RuntimeError`.
180170
public func reconstruct() async throws -> KeyReconstructionDetails {
@@ -227,18 +217,15 @@ public class ThresholdKey {
227217
return ShareStoreArray(pointer: result!)
228218
}
229219

230-
private func generate_new_share(use_tss: Bool = false, tss_options: TssOptions? = nil, completion: @escaping (Result<GenerateShareStoreResult, Error>) -> Void) {
220+
private func generate_new_share(completion: @escaping (Result<GenerateShareStoreResult, Error>) -> Void) {
231221
tkeyQueue.async {
232222
do {
233-
var options: OpaquePointer?
234-
if tss_options != nil {
235-
options = tss_options!.pointer
236-
}
223+
let useTss = false
237224

238225
var errorCode: Int32 = -1
239226
let curvePointer = UnsafeMutablePointer<Int8>(mutating: (self.curveN as NSString).utf8String)
240227
let ptr = withUnsafeMutablePointer(to: &errorCode, { error in
241-
threshold_key_generate_share(self.pointer, curvePointer, use_tss, options, error)
228+
threshold_key_generate_share(self.pointer, curvePointer, useTss, nil, error)
242229
})
243230
guard errorCode == 0 else {
244231
throw RuntimeError("Error in ThresholdKey generate_new_share")
@@ -254,16 +241,12 @@ public class ThresholdKey {
254241

255242
/// Generates a new share.
256243
///
257-
/// - Parameters:
258-
/// - use_tss: Whether TSS should be used or not..
259-
/// - tss_options: TSS options that should be used for TSS.
260-
///
261-
/// - Returns: `GenerateShareStoreArray`
244+
/// - Returns: `GenerateShareStoreResult`
262245
///
263246
/// - Throws: `RuntimeError`, indicates invalid `ThresholdKey`.
264-
public func generate_new_share(use_tss: Bool = false, tss_options: TssOptions? = nil) async throws -> GenerateShareStoreResult {
247+
public func generate_new_share() async throws -> GenerateShareStoreResult {
265248
return try await withCheckedThrowingContinuation {
266-
continuation in self.generate_new_share(use_tss: use_tss, tss_options: tss_options) {
249+
continuation in self.generate_new_share() {
267250
result in
268251
switch result {
269252
case let .success(result):
@@ -275,18 +258,17 @@ public class ThresholdKey {
275258
}
276259
}
277260

278-
private func delete_share(share_index: String, use_tss: Bool = false, tss_options: TssOptions? = nil, completion: @escaping (Result<Void, Error>) -> Void) {
261+
private func delete_share(share_index: String, completion: @escaping (Result<Void, Error>) -> Void) {
279262
tkeyQueue.async {
280263
do {
281264
var errorCode: Int32 = -1
282265
let curvePointer = UnsafeMutablePointer<Int8>(mutating: (self.curveN as NSString).utf8String)
283266
let shareIndexPointer = UnsafeMutablePointer<Int8>(mutating: (share_index as NSString).utf8String)
284-
var options: OpaquePointer?
285-
if tss_options != nil {
286-
options = tss_options!.pointer
287-
}
267+
268+
let useTss = false
269+
288270
withUnsafeMutablePointer(to: &errorCode, { error in
289-
threshold_key_delete_share(self.pointer, shareIndexPointer, curvePointer, use_tss, options, error)
271+
threshold_key_delete_share(self.pointer, shareIndexPointer, curvePointer, useTss, nil, error)
290272
})
291273
guard errorCode == 0 else {
292274
throw RuntimeError("Error in Threshold while Deleting share")
@@ -301,10 +283,8 @@ public class ThresholdKey {
301283
/// Deletes a share at the specified index. Caution is advised to not try delete a share that would prevent the total number of shares being below the threshold.
302284
/// - Parameters:
303285
/// - share_index: Share index to be deleted.
304-
/// - use_tss: Whether TSS should be used or not..
305-
/// - tss_options: TSS options that should be used for TSS.
306286
/// - Throws: `RuntimeError`, indicates invalid share index or invalid `ThresholdKey`.
307-
public func delete_share(share_index: String, use_tss: Bool = false, tss_options: TssOptions? = nil) async throws {
287+
public func delete_share(share_index: String) async throws {
308288
return try await withCheckedThrowingContinuation {
309289
continuation in
310290
self.delete_share(share_index: share_index) {
@@ -576,7 +556,7 @@ public class ThresholdKey {
576556

577557
/// Retrieves all share indexes for a `ThresholdKey`.
578558
///
579-
/// - Returns: Array of `String`
559+
/// - Returns: Array of String
580560
///
581561
/// - Throws: `RuntimeError`, indicates invalid `ThresholdKey`.
582562
public func get_shares_indexes() throws -> [String] {
@@ -1067,6 +1047,14 @@ public class ThresholdKey {
10671047
}
10681048
}
10691049

1050+
/// Function to assign a public key to the service provider, used only for TSS
1051+
///
1052+
/// - Parameters:
1053+
/// - tag: The tss tag
1054+
/// - nonce: The tss nonce
1055+
/// - public_key: The pulic key to be assigned
1056+
///
1057+
/// - Throws: `RuntimeError`, indicates invalid parameters or invalid `ThresholdKey`.
10701058
public func service_provider_assign_public_key(tag: String, nonce: String, public_key: String) throws {
10711059
var errorCode: Int32 = -1
10721060
let tagPointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: tag).utf8String)
@@ -1078,6 +1066,12 @@ public class ThresholdKey {
10781066
}
10791067
}
10801068

1069+
1070+
/// Function to get all tss tags
1071+
///
1072+
/// - Returns: Array of String
1073+
///
1074+
/// - Throws: `RuntimeError`, indicates invalid parameters or invalid `ThresholdKey`.
10811075
public func get_all_tss_tags() throws -> [String] {
10821076
var errorCode: Int32 = -1
10831077

@@ -1097,7 +1091,12 @@ public class ThresholdKey {
10971091

10981092
return result_vec
10991093
}
1100-
1094+
1095+
/// Function to get extended verifier id
1096+
///
1097+
/// - Returns: String
1098+
///
1099+
/// - Throws: `RuntimeError`, indicates invalid parameters or invalid `ThresholdKey`.
11011100
public func get_extended_verifier_id() throws -> String {
11021101
var errorCode: Int32 = -1
11031102

0 commit comments

Comments
 (0)