Skip to content

Commit

Permalink
Merge pull request #38 from tkey/feat/delete_1_of_1
Browse files Browse the repository at this point in the history
feat: delete_1_of_1
  • Loading branch information
metalurgical committed Aug 14, 2023
2 parents 3cb2d89 + 7f9212d commit 873a0bc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
33 changes: 25 additions & 8 deletions Sources/ThresholdKey/ThresholdKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public class ThresholdKey {
return Metadata.init(pointer: result!)
}

private func initialize(import_share: String?, input: ShareStore?, never_initialize_new_key: Bool?, include_local_metadata_transitions: Bool?, completion: @escaping (Result<KeyDetails, Error>) -> Void ) {
private func initialize(import_key: String?, input: ShareStore?, never_initialize_new_key: Bool?, include_local_metadata_transitions: Bool?, delete_1_of_1 : Bool = false, completion: @escaping (Result<KeyDetails, Error>) -> Void ) {
tkeyQueue.async {
do {
var errorCode: Int32 = -1
var sharePointer: UnsafeMutablePointer<Int8>?
if import_share != nil {
sharePointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: import_share!).utf8String)
var importKeyPointer: UnsafeMutablePointer<Int8>?
if import_key != nil {
importKeyPointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: import_key!).utf8String)
}

var storePtr: OpaquePointer?
Expand All @@ -96,7 +96,7 @@ public class ThresholdKey {
let includeLocalMetadataTransitions = include_local_metadata_transitions ?? false

let curvePointer = UnsafeMutablePointer<Int8>(mutating: NSString(string: self.curveN).utf8String)
let ptr = withUnsafeMutablePointer(to: &errorCode, { error in threshold_key_initialize(self.pointer, sharePointer, storePtr, neverInitializeNewKey, includeLocalMetadataTransitions, curvePointer, error)})
let ptr = withUnsafeMutablePointer(to: &errorCode, { error in threshold_key_initialize(self.pointer, importKeyPointer, storePtr, neverInitializeNewKey, includeLocalMetadataTransitions, delete_1_of_1, curvePointer, error)})
guard errorCode == 0 else {
throw RuntimeError("Error in ThresholdKey Initialize")
}
Expand All @@ -111,18 +111,18 @@ public class ThresholdKey {
/// Initializes a `ThresholdKey` object.
///
/// - Parameters:
/// - import_share: Share to be imported, optional.
/// - import_key: key to be imported, optional.
/// - input: `ShareStore` to be used, optional.
/// - never_initialize_new_key: Do not initialize a new tKey if an existing one is found.
/// - include_local_matadata_transitions: Proritize existing metadata transitions over cloud fetched transitions.
///
/// - Returns: `KeyDetails`
///
/// - Throws: `RuntimeError`, indicates invalid parameters.
public func initialize(import_share: String? = nil, input: ShareStore? = nil, never_initialize_new_key: Bool? = nil, include_local_metadata_transitions: Bool? = nil) async throws -> KeyDetails {
public func initialize(import_key: String? = nil, input: ShareStore? = nil, never_initialize_new_key: Bool? = nil, include_local_metadata_transitions: Bool? = nil, delete_1_of_1 : Bool = false) async throws -> KeyDetails {
return try await withCheckedThrowingContinuation {
continuation in
self.initialize(import_share: import_share, input: input, never_initialize_new_key: never_initialize_new_key, include_local_metadata_transitions: include_local_metadata_transitions) {
self.initialize(import_key: import_key, input: input, never_initialize_new_key: never_initialize_new_key, include_local_metadata_transitions: include_local_metadata_transitions, delete_1_of_1: delete_1_of_1) {
result in
switch result {
case .success(let result):
Expand Down Expand Up @@ -586,6 +586,23 @@ public class ThresholdKey {
return LocalMetadataTransitions.init(pointer: result!)
}

/// Returns add metadata transitions , need sync localmetadata transistion to update server data
///
/// - Returns:
///
/// - Throws: `RuntimeError`, indicates invalid parameters or invalid `ThresholdKey`.
public func add_local_metadata_transitions( input_json: String, private_key: String ) throws {
var errorCode: Int32 = -1

let curve = UnsafeMutablePointer<Int8>(mutating: (curveN as NSString).utf8String)
let input = UnsafeMutablePointer<Int8>(mutating: (input_json as NSString).utf8String)
let privateKey = UnsafeMutablePointer<Int8>(mutating: (private_key as NSString).utf8String)
withUnsafeMutablePointer(to: &errorCode, { error in threshold_key_add_local_metadata_transitions(pointer, input, privateKey, curve, error)})
guard errorCode == 0 else {
throw RuntimeError("Error in ThresholdKey get_local_metadata_transitions")
}
}

/// Returns the tKey store for a module.
///
/// - Parameters:
Expand Down
4 changes: 3 additions & 1 deletion Sources/libtkey/include/tkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
struct ServiceProvider* service_provider(bool enable_logging, char* postbox_key, char* curve_n, int* error_code);
void service_provider_free(struct ServiceProvider* prt);
struct FFIThresholdKey* threshold_key(struct Metadata* metadata, struct ShareStorePolyIDShareIndexMap* shares, struct FFIStorageLayer* storage_layer, struct ServiceProvider* service_provider, struct LocalMetadataTransitions* local_metadata_transitions, struct Metadata* last_fetch_cloud_metadata, bool enable_logging, bool manual_sync, int* error_code);
struct KeyDetails* threshold_key_initialize(struct FFIThresholdKey* threshold_key, char* import_share, struct ShareStore* input, bool never_initialize_new_key, bool include_local_metadata_transitions, char* curve_n, int* error_code);
struct KeyDetails* threshold_key_initialize(struct FFIThresholdKey* threshold_key, char* import_share, struct ShareStore* input, bool never_initialize_new_key, bool include_local_metadata_transitions, bool delete_1_of_1, char* curve_n, int* error_code);
struct KeyDetails* threshold_key_get_key_details(struct FFIThresholdKey* threshold_key, int* error_code);
struct KeyReconstructionDetails* threshold_key_reconstruct(struct FFIThresholdKey* threshold_key, char* curve_n, int* error_code);
void threshold_key_free(struct FFIThresholdKey* ptr);
Expand All @@ -87,6 +87,8 @@
char* threshold_key_encrypt(struct FFIThresholdKey* threshold_key, char* data, char* curve_n, int* error_code);
char* threshold_key_decrypt(struct FFIThresholdKey* threshold_key, char* data, int* error_code);
struct LocalMetadataTransitions* threshold_key_get_local_metadata_transitions(struct FFIThresholdKey* threshold_key, int* error_code);
void threshold_key_add_local_metadata_transitions(struct FFIThresholdKey* threshold_key, char* input_json, char* private_key, char* curve_n, int* error_code);

struct Polynomial* threshold_key_reconstruct_latest_poly(struct FFIThresholdKey *threshold_key, char* curve_n, int* error_code);
struct Metadata* threshold_key_get_last_fetched_cloud_metadata(struct FFIThresholdKey* threshold_key, int* error_code);
void threshold_key_sync_local_metadata_transitions(struct FFIThresholdKey *threshold_key, char* curve_n, int* error_code);
Expand Down
Loading

0 comments on commit 873a0bc

Please sign in to comment.