Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private key from entropy cannot be created without a password #112

Open
trimixlover opened this issue Sep 18, 2024 · 1 comment
Open

Private key from entropy cannot be created without a password #112

trimixlover opened this issue Sep 18, 2024 · 1 comment

Comments

@trimixlover
Copy link

trimixlover commented Sep 18, 2024

What we witnessed is that when bip32PrivateKeyFromBip39Entropy is called with "" (empty string) for passphrase it is interpreted as null value when passing to ios and android bindings and because of that it errors out. To mitigate that issue, what we did is, we applied the following patch:

diff --git a/node_modules/@emurgo/csl-mobile-bridge/android/src/main/java/io/emurgo/rnhaskellshelley/HaskellShelleyModule.java b/node_modules/@emurgo/csl-mobile-bridge/android/src/main/java/io/emurgo/rnhaskellshelley/HaskellShelleyModule.java
index c2916a5..dd51e9e 100644
--- a/node_modules/@emurgo/csl-mobile-bridge/android/src/main/java/io/emurgo/rnhaskellshelley/HaskellShelleyModule.java
+++ b/node_modules/@emurgo/csl-mobile-bridge/android/src/main/java/io/emurgo/rnhaskellshelley/HaskellShelleyModule.java
@@ -1130,6 +1130,10 @@ public class HaskellShelleyModule extends ReactContextBaseJavaModule {
 
     @ReactMethod
     public final void csl_bridge_bip32PrivateKeyFromBip39Entropy(String entropy, String password, Promise promise) {
+        if (password  == null) {
+            password = ""
+        }
+
         Native.I
             .csl_bridge_bip32PrivateKeyFromBip39Entropy(Base64.decode(entropy, Base64.DEFAULT), Base64.decode(password, Base64.DEFAULT))
             .map(RPtr::toJs)
diff --git a/node_modules/@emurgo/csl-mobile-bridge/ios/HaskellShelley.m b/node_modules/@emurgo/csl-mobile-bridge/ios/HaskellShelley.m
index 0097431..6c3bc75 100644
--- a/node_modules/@emurgo/csl-mobile-bridge/ios/HaskellShelley.m
+++ b/node_modules/@emurgo/csl-mobile-bridge/ios/HaskellShelley.m
@@ -1589,8 +1589,13 @@ + (void)csl_bridge_initialize
     }] exec:selfPtr andResolve:resolve orReject:reject];
 }
 
-RCT_EXPORT_METHOD(csl_bridge_bip32PrivateKeyFromBip39Entropy:(nonnull NSString *)entropyVal withPassword:(nonnull NSString *)passwordVal withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
+RCT_EXPORT_METHOD(csl_bridge_bip32PrivateKeyFromBip39Entropy:(nonnull NSString *)entropyVal withPassword:(nullable NSString *)passwordVal withResolve:(RCTPromiseResolveBlock)resolve andReject:(RCTPromiseRejectBlock)reject)
 {
+    // Set passwordVal to an empty string if it's null
+    if (passwordVal == nil) {
+        passwordVal = @"";
+    }
+
     [[CSLCSafeOperation new:^NSString*(NSArray* params, CharPtr* error) {
         RPtr result;
         NSData* dataEntropy = [NSData fromBase64:[params objectAtIndex:0]];

To reproduce the issue, there is not much you need to do. Just execute this piece of code:

Bip32PrivateKey.from_bip39_entropy(
        Buffer.from(mnemonicToEntropy(mnemonic), "hex"),
        Buffer.from(""))

Hope this helps. Also if you feel like there is blunder in usage and that this is in fact not an issue, please let me know.

@lisicky
Copy link
Contributor

lisicky commented Sep 26, 2024

Hi @trimixlover! Could you try to pass Uint8Array.from([]) instead Buffer.from("") ? By default it should not to produce "null" on empty byte array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants