wif icon indicating copy to clipboard operation
wif copied to clipboard

Wif behaving differently when being used in Electron Application Production

Open Taha-daboussi opened this issue 1 year ago • 1 comments

So am using "ecpair" library to get ECPairFactory and then using @bitcoinerlab/secp256k1 as the ecc interface so I can import Bitcoin taproot private key. When running this code in development it worked perfectly , but when I built it into my Electron application I ran into 1 problem getting an error of " expected buffer , received Uint8Array " after debugging the code I found out where the issue was

in the node_moules/wif/index.js function decodeRaw

image

for some reason returning two different values if production or development . was able to fix this (not really a fix )

by doing this in the "decode" function

function decode (string, version) {
  const data = decodeRaw(bs58check.decode(string), version) 
  if(data.privateKey instanceof Uint8Array ){
    const uint8Array = new Uint8Array(Object.keys(data.privateKey).map(key => data.privateKey[key]));
// Convert Uint8Array to Buffer
    const buffer = Buffer.from(uint8Array);
    data.privateKey = buffer
  }
  return data
}

Please let me know if there is any other solution other my temp fix

Taha-daboussi avatar Mar 28 '24 12:03 Taha-daboussi

This sounds like an Electron issue. Electron treating Uint8Array as interchangeable with Buffer is probably not a good idea. I'm not sure why Electron would do such a thing.

I assume their production settings cause something to get changed, or maybe it's the bundler's problem.

junderw avatar Mar 28 '24 13:03 junderw