Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alternative address prefixes in bip122 blockchain account ids #206

Merged

Conversation

clehner
Copy link
Contributor

@clehner clehner commented Nov 19, 2021

A Bitcoin address in Base58Check encoding has a version byte prefix that indicates the type or use of the address. Bitcoin mainnet uses a zero byte, but test networks and forks or alternative networks typically use different version bytes.

Here are a few values of version bytes for addresses:

Hex Network Reference
0x00 Bitcoin https://github.com/bitcoin/bitcoin/blob/fe03f7a37fd0ef05149161f6b95a25493e1fe38f/src/chainparams.cpp#L131
0x6f Bitcoin test https://github.com/bitcoin/bitcoin/blob/fe03f7a37fd0ef05149161f6b95a25493e1fe38f/src/chainparams.cpp#L238
0x30 Litecoin https://github.com/litecoin-project/litecoin/blob/fa0cdba24a0818c4a7206f282c86f0eac6767e72/src/chainparams.cpp#L128
0x0e Feathercoin https://github.com/FeatherCoin/Feathercoin/blob/8dad11707024149029bb9bfdd7bc5e10385e0e77/src/chainparams.cpp#L126
0x1e Dogecoin https://github.com/dogecoin/dogecoin/blob/31afd133119dd2e15862d46530cb99424cf564b0/src/chainparams.cpp#L167
0x71 Dogecoin test https://github.com/dogecoin/dogecoin/blob/31afd133119dd2e15862d46530cb99424cf564b0/src/chainparams.cpp#L325

More info:

This PR updates this implementation to allow using version bytes other than 0x00, to allow for non-Bitcoin-mainnet addresses.
Essentially it ignores the version byte during verification by passing it through from the address that is being verified against.
The previous behavior was to always use 0x00, meaning that Bitcoin mainnet address format would need to be used even for testnet and forks/altnets.

If it is desired to verify consistency between the CAIP-4 reference (BIP122 chain ID) and the address byte (e.g. so that an address with the Bitcoin mainnet prefix could only be used with the Bitcoin mainnet chain ID), the byte could instead be looked up from a mapping of known chain ids to version bytes.

These changes do not affect the validity of signature in relation to public keys, only the allowed formats of the account ids (which are hashes of public keys).

Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic, thank you for the contribution!

@mirceanis mirceanis merged commit 2087995 into decentralized-identity:master Nov 19, 2021
uport-automation-bot pushed a commit that referenced this pull request Nov 19, 2021
# [5.12.0](5.11.1...5.12.0) (2021-11-19)

### Features

* allow alternative Bitcoin address prefixes ([#206](#206)) ([2087995](2087995))
@uport-automation-bot
Copy link
Collaborator

🎉 This PR is included in version 5.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@clehner clehner deleted the feat/bip122-versions branch December 1, 2021 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants