From f6be52dcda3e156ab7b926a288b4cb092157d675 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht <61358536+blu3beri@users.noreply.github.com> Date: Mon, 28 Mar 2022 14:47:01 +0200 Subject: [PATCH] feat: createKey (#37) Signed-off-by: Berend Sliedrecht --- .../main/java/com/reactlibrary/IndySdkModule.java | 12 ++++++++++++ ios/IndySdk.m | 10 +++++++++- ios/IndySdk.swift | 7 +++++++ src/index.js | 7 +++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/reactlibrary/IndySdkModule.java b/android/src/main/java/com/reactlibrary/IndySdkModule.java index fb4bcbb..5203144 100644 --- a/android/src/main/java/com/reactlibrary/IndySdkModule.java +++ b/android/src/main/java/com/reactlibrary/IndySdkModule.java @@ -278,6 +278,18 @@ private byte[] readableArrayToBuffer(ReadableArray arr) { return buffer; } + @ReactMethod + public void createKey(int walletHandle, String key, Promise promise) { + try { + Wallet wallet = walletMap.get(walletHandle); + String verkey = Crypto.createKey(wallet, key).get(); + promise.resolve(verkey); + } catch (Exception e) { + IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e); + promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e); + } + } + @ReactMethod public void cryptoAnonCrypt(String theirKey, ReadableArray message, Promise promise) { try { diff --git a/ios/IndySdk.m b/ios/IndySdk.m index 4f89494..a0167a6 100644 --- a/ios/IndySdk.m +++ b/ios/IndySdk.m @@ -93,6 +93,11 @@ @interface RCT_EXTERN_MODULE(IndySdk, NSObject) rejecter:(RCTPromiseRejectBlock)reject) // crypto +RCT_EXTERN_METHOD(createKey: (NSString *)key + walletHandle:(nonnull NSNumber *)walletHandle + resolver:(RCTPromiseResolveBlock)resolve + rejecter:(RCTPromiseRejectBlock)reject) + RCT_EXTERN_METHOD(cryptoAnonCrypt: (NSString *)message theirKey:(NSString *)theirKey resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) @@ -101,7 +106,10 @@ @interface RCT_EXTERN_MODULE(IndySdk, NSObject) resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -RCT_EXTERN_METHOD(cryptoAuthCrypt: (NSString *)message myKey:(NSString *)myKey theirKey:(NSString *)theirKey walletHandle:(nonnull NSNumber *)walletHandle +RCT_EXTERN_METHOD(cryptoAuthCrypt: (NSString *)message + myKey:(NSString *)myKey + theirKey:(NSString *)theirKey + walletHandle:(nonnull NSNumber *)walletHandle resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) diff --git a/ios/IndySdk.swift b/ios/IndySdk.swift index 695017d..fdcfedb 100644 --- a/ios/IndySdk.swift +++ b/ios/IndySdk.swift @@ -165,6 +165,13 @@ class IndySdk : NSObject { } // crypto + + @objc func createKey(_ key: String, walletHandle: NSNumber, + resolver resolve: @escaping RCTPromiseResolveBlock, + rejecter reject: @escaping RCTPromiseRejectBlock) -> Void { + let whNumber:Int32 = Int32(truncating:walletHandle) + IndyCrypto.createKey(key, walletHandle: whNumber, completion: completionWithString(resolve, reject)) + } @objc func cryptoAnonCrypt(_ message: String, theirKey: String!, resolver resolve: @escaping RCTPromiseResolveBlock, diff --git a/src/index.js b/src/index.js index 6c1bea1..67ec784 100644 --- a/src/index.js +++ b/src/index.js @@ -381,6 +381,13 @@ const indy = { // crypto + async createKey(wh: WalletHandle, key: Object): Promise { + if (Platform.OS === 'ios') { + return IndySdk.createKey(JSON.stringify(key), wh) + } + return IndySdk.createKey(wh, JSON.stringify(key)) + }, + async cryptoAnonCrypt(recipientVk: Verkey, messageRaw: Buffer): Promise { if (Platform.OS === 'ios') { return IndySdk.cryptoAnonCrypt(messageRaw, recipientVk)