Doesn't decode bech32 Bitcoin addresses.
stl1988 opened this issue · comments
stl1988 commented
It always says "Error: Excessive padding: 5 (max 4 allowed)" I think this shouldn't happen.
Alex Ostrovski commented
Thanks for the report! Indeed, bech32.decode()
does not support Bitcoin addresses out of the box (it's geared towards generic Bech32-encoded data). There is need for a bit more legwork, as can be seen in test vectors:
function decodeBitcoinAddress(address) {
const decoded = bech32.decodeTo5BitArray(address);
return {
prefix: decoded.prefix, // should equal `bc` or `tb` for valid addresses
version: decoded.data[0], // should equal 0 for currently supported addresses
script: bech32.from5BitArray(decoded.data.subarray(1)), // should have length 20 or 32
};
}
I'll add decodeBitcoinAddress
/ encodeBitcoinAddress
to the library.