Skip to content

Commit c1771a9

Browse files
committed
docs(logic): clarify bech32_address/2 predicate limitations (HD derivation)
1 parent cfde952 commit c1771a9

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

docs/predicate/bech32_address_2.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ sidebar_position: 9
77

88
## Description
99

10-
`bech32_address/2` is a predicate that convert a [bech32](<https://docs.cosmos.network/main/build/spec/addresses/bech32#hrp-table>) encoded string into [base64](<https://fr.wikipedia.org/wiki/Base64>) bytes and give the address prefix, or convert a prefix \(HRP\) and [base64](<https://fr.wikipedia.org/wiki/Base64>) encoded bytes to [bech32](<https://docs.cosmos.network/main/build/spec/addresses/bech32#hrp-table>) encoded string.
10+
`bech32_address/2` is a predicate that converts a Bech32\-encoded string into a prefix \(HRP\) and Base64\-encoded bytes, or constructs a Bech32\-encoded string from a prefix and Base64 bytes.
11+
12+
This predicate handles Bech32 address encoding and decoding as per the Cosmos specification. In the Cosmos ecosystem, most chains \(e.g., Cosmos Hub, Akash\) share the BIP\-44 coin type 118', allowing HRP conversion \(e.g., 'cosmos' to 'akash'\) to produce valid addresses from the same underlying key.
1113

1214
## Signature
1315

@@ -18,8 +20,22 @@ bech32_address(+Address, -Bech32) is det
1820

1921
where:
2022

21-
- Address is a pair of the HRP \(Human\-Readable Part\) which holds the address prefix and a list of numbers ranging from 0 to 255 that represent the base64 encoded bech32 address string.
22-
- Bech32 is an Atom or string representing the bech32 encoded string address
23+
- Address: A pair \`HRP\-Base64Bytes\`, where: HRP is an atom representing the Human\-Readable Part \(e.g., 'cosmos', 'akash', 'axone', 'bitsong'\), and Base64Bytes is a list of integers \(0\-255\) representing the Base64\-encoded bytes of the address.
24+
- Bech32: An atom or string representing the Bech32\-encoded address \(e.g., 'cosmos17sc02mcgjzdv5l4jwnzffxw7g60y5ta4pggcp4'\).
25+
26+
## Limitations
27+
28+
Conversion between HRPs is only valid for chains sharing the same BIP\-44 coin type \(e.g., 118'\). For chains with distinct coin types \(e.g., Secret: 529', Bitsong: 639'\), this predicate cannot derive the correct address from another chain’s Bech32 string.
29+
30+
## References
31+
32+
- [Bech32 on Cosmos](<https://docs.cosmos.network/main/build/spec/addresses/bech32>)
33+
34+
- [Base64 Encoding](<https://fr.wikipedia.org/wiki/Base64>)
35+
36+
- [Cosmos Chain Registry](<https://github.com/cosmos/chain-registry>)
37+
38+
- [BIP 44](<https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki>)
2339

2440
## Examples
2541

x/logic/predicate/address.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,44 @@ import (
88
"github.com/axone-protocol/axoned/v11/x/logic/prolog"
99
)
1010

11-
// Bech32Address is a predicate that convert a [bech32] encoded string into [base64] bytes and give the address prefix,
12-
// or convert a prefix (HRP) and [base64] encoded bytes to [bech32] encoded string.
11+
// Bech32Address is a predicate that converts a Bech32-encoded string into a prefix (HRP) and Base64-encoded bytes,
12+
// or constructs a Bech32-encoded string from a prefix and Base64 bytes.
13+
//
14+
// This predicate handles Bech32 address encoding and decoding as per the Cosmos specification. In the Cosmos ecosystem,
15+
// most chains (e.g., Cosmos Hub, Akash) share the BIP-44 coin type 118', allowing HRP conversion (e.g., 'cosmos' to 'akash')
16+
// to produce valid addresses from the same underlying key.
1317
//
1418
// # Signature
1519
//
1620
// bech32_address(-Address, +Bech32) is det
1721
// bech32_address(+Address, -Bech32) is det
1822
//
1923
// where:
20-
// - Address is a pair of the HRP (Human-Readable Part) which holds the address prefix and a list of numbers
21-
// ranging from 0 to 255 that represent the base64 encoded bech32 address string.
22-
// - Bech32 is an Atom or string representing the bech32 encoded string address
2324
//
24-
// [bech32]: https://docs.cosmos.network/main/build/spec/addresses/bech32#hrp-table
25-
// [base64]: https://fr.wikipedia.org/wiki/Base64
25+
// - Address: A pair `HRP-Base64Bytes`, where: HRP is an atom representing the Human-Readable Part (e.g., 'cosmos', 'akash', 'axone', 'bitsong'),
26+
// and Base64Bytes is a list of integers (0-255) representing the Base64-encoded bytes of the address.
27+
// - Bech32: An atom or string representing the Bech32-encoded address (e.g., 'cosmos17sc02mcgjzdv5l4jwnzffxw7g60y5ta4pggcp4').
28+
//
29+
// # Limitations
30+
//
31+
// Conversion between HRPs is only valid for chains sharing the same BIP-44 coin type (e.g., 118'). For chains with
32+
// distinct coin types (e.g., Secret: 529', Bitsong: 639'), this predicate cannot derive the correct address from another
33+
// chain’s Bech32 string.
34+
//
35+
// # References
36+
//
37+
// - [Bech32 on Cosmos]
38+
//
39+
// - [Base64 Encoding]
40+
//
41+
// - [Cosmos Chain Registry]
42+
//
43+
// - [BIP 44]
44+
//
45+
// [Bech32 on Cosmos]: https://docs.cosmos.network/main/build/spec/addresses/bech32
46+
// [Base64 Encoding]: https://fr.wikipedia.org/wiki/Base64
47+
// [Cosmos Chain Registry]: https://github.com/cosmos/chain-registry
48+
// [BIP 44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
2649
func Bech32Address(_ *engine.VM, address, bech32 engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise {
2750
forwardConverter := func(value []engine.Term, _ engine.Term, env *engine.Env) ([]engine.Term, error) {
2851
hrpTerm, dataTerm, err := prolog.AssertPair(value[0], env)

0 commit comments

Comments
 (0)