Decoding pubkey addresses
See original GitHub issueI 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: https://github.com/bitcoinjs/bitcoinjs-lib/blob/413495b101e6dec80b4a310a52ab1a28cd9f7bec/src/address.js#L51 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);
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
4. Keys, Addresses - Mastering Bitcoin, 2nd Edition [Book]
We will review the various encoding formats used to represent private and ... The relationship between private key, public key, and bitcoin address...
Read more >Address - Learn Me A Bitcoin
Decoded : When someone creates a locking script from this address, they just decode the base58 to retrieve the hash160 inside it, then...
Read more >What are public keys, private keys and wallet addresses?
Understanding addresses, public keys, and private keys is critical to understanding how cryptocurrencies work. A wallet address is a randomly generated set ...
Read more >Is it possible to get the public key of a bitcoin address I do not ...
You can retrieve the public key from address with the reference client using the validateaddress RPC call (or in the debug window of...
Read more >How public and private key encryption works - PreVeil
In public key cryptography, every public key matches to only one private key. Together, they are used to encrypt and decrypt messages. If...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
<>
represents data or script{}
represents data that must prefixed by OP_PUSHDATA[]
represents multiple{}
Standard Scripts
PubKey (pay-to-pubkey / P2PK)
PubKeyHash (pay-to-pubkeyhash / P2PKH)
ScriptHash (pay-to-scripthash / P2SH)
MultiSig (pay-to-multisig / P2MS)
Witness PubKeyHash (pay-to-witness-pubkeyhash / P2WPKH)
Witness ScriptHash (pay-to-witness-scripthash / P2WSH)
Non-standard Scripts
OP_RETURN
Anyone-can-spend
Transaction-puzzle
Ref https://gist.github.com/dcousens/1d8c24d01e3f34bee453
ok got it