Skip to content

Decoding pubkey addresses #1000

@dakk

Description

@dakk

I was trying to get an address from an outputscript using address.fromOutputScript; but when I try it with a pubkey script (OP_DATA() + OP_CHECKSIG), the library fails with the error:

02397df78c9c3fecbcbcee12025230fc4b30e6e617f5fc9c10513eebd0cf4b327d OP_CHECKSIG has no matching Address

Inspecting the library code I found the problem here:

function fromOutputScript (outputScript, network) {
the pubkey template is not used. I know that pubkey addresses are deprecated, but they are used on coinbase transactions. How should I do to decode these type of addresses?

My solution is this, but it seems too tricky:

let s = bitcoinjs.script.pubKey.output.decode(txout.script);
s = bitcoinjs.crypto.sha256(s);
s = bitcoinjs.crypto.ripemd160(s);
spendableby = bitcoinjs.address.toBase58Check(bitcoinjs.script.compile(s), _network.pubKeyHash);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions