HeliosLang/compiler

WalletEmulator is generating same Address on each call

gavinharris-dev opened this issue ยท 2 comments

Hi! ๐Ÿ‘‹

When trying to generate multiple Wallets with the WalletEmulator I noticed that the Addresses were always the same. It looks like the logic used to try populating the Private Key always returns an array of 36 empty slots.

Here is the diff that solved my problem:

diff --git a/node_modules/@hyperionbt/helios/helios.js b/node_modules/@hyperionbt/helios/helios.js
index 9156227..30baf15 100644
--- a/node_modules/@hyperionbt/helios/helios.js
+++ b/node_modules/@hyperionbt/helios/helios.js

@@ -37767,7 +37767,7 @@ export class WalletEmulator {
      * @returns {number[]} - Ed25519 private key is 32 bytes long
      */
     static genPrivateKey(random) {
-        return (new Array(32)).map(() => random()%256);
+        return Array.from({length: 32}, () => Math.floor(random() * 256));
     }
 
     /**

This issue body was partially generated by patch-package.

I learned something new about Javascript: map() over an array containing only undefined does nothing.

v0.13.3 contains a fix (I ended up using a simple for-loop)

Awesome! Iโ€™ll check it out!