Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat: createKey (#37)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored Mar 28, 2022
1 parent 9b76d86 commit f6be52d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions android/src/main/java/com/reactlibrary/IndySdkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion ios/IndySdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions ios/IndySdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ const indy = {

// crypto

async createKey(wh: WalletHandle, key: Object): Promise<string> {
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<Buffer> {
if (Platform.OS === 'ios') {
return IndySdk.cryptoAnonCrypt(messageRaw, recipientVk)
Expand Down

0 comments on commit f6be52d

Please sign in to comment.