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

keygen generates keypair with private key length of 31 bytes #9

Open
zhenkuncua opened this issue Nov 30, 2021 · 2 comments
Open

keygen generates keypair with private key length of 31 bytes #9

zhenkuncua opened this issue Nov 30, 2021 · 2 comments

Comments

@zhenkuncua
Copy link

hi, on occasions, the library generates keys with 31 bytes, but filecoin expects a 32 byte private key.

@MakMuftic
Copy link
Member

Hi @zhenkuncua, can you provide me with more context or a way to reproduce this behavior?

@zhenkuncua
Copy link
Author

zhenkuncua commented Dec 1, 2021

hi @MakMuftic ,

this is the code used:

const bip39=require("bip39");
const keygen = require("@nodefactory/filecoin-address");

function newAddr(){
   const mnemonic = bip39.generateMnemonic();	
   const key = bip39.mnemonicToSeedSync(mnemonic);
   const keypair= keygen.keyPairFromSeed(key,"f");
   return {
       address: keypair.address,
       private: {"Type":"secp256k1","PrivateKey":Buffer.from(keypair.privateKey,'HEX').toString('BASE64')}
   }     
 }

this is one of the invalid outputs:

{"address":"f1twfcpb5abskwqghpdpazrxvdbktmbexwuczfucy","private"{"Type":"secp256k1","PrivateKey":"qocfoZepRwo6QzCjFJoEaEyd6eGYfBI3civ0NcZ96Q=="}}

the issue cannot be replicated consistently, but within 4000 generations, I've encountered 6 cases. I'm still trying to replicate the problem but the code has been running for 24 hours already but has not yet found another case yet.

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