NodeFactoryIo / filecoin-address

Typescript library for calculating Filecoin address from keys
5 stars 0 forks source link

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

Open zhenkuncua opened 2 years ago

zhenkuncua commented 2 years ago

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

MakMuftic commented 2 years ago

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

zhenkuncua commented 2 years ago

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.