-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core, proto)!: add bech32m addresses (#1124)
## Summary Adds bech32m addresses. ## Background bech32m encoded addresses are the de-facto standard in cosmos. By using a `"astria"` prefix (in the human readable prefix, bech32 HRP sense) we align astria with the rest of the cosmos ecosystem. ## Changes - Add a field `bech32m` to `astria.primitive.v1.Address` - Deprecate `astria.primitive.v1.Address.inner` - Change `std::fmt::Display for Address` to use bech32m encoding - Serialize `Address` in terms of its protobuf-json mapping - Update the `Address:try_from_raw` constructor to allow ingesting protobufs that have their `inner` or `bech32m` or populated. `inner` and `bech32m` are mutually exclusive, only one may be set. - Protobufs with `inner` set are assumed to have prefix `"astria"`. - Introduce an `AddressBuilder` type state builder that requires both a prefix and array/byte slice be set. - Update all services to the new way of constructing addresses, but with the prefix `"astria"` set everywhere - Add a `SignedTransaction::address` method that constructs an address from the verification key and the `chain_id` stored in the unsigned transaction's `transaction_params::chain_id`. - Provide a builder for `TransactionParams` enforcing that chain IDs are have hrp compatible names. ## Testing - update snapshot tests for address-as-json serialization - add unit tests: - addresses with only bytes are accepted - addresses with only bech32m are accepted - addresses with both bytes and bech32m are are rejected - protobufs created from the common `Address` type only have `bech32m` populated - various tests to assert `Address` invariants (mainly maximum length of prefix + fixed-size address always being encodeable to a string) - updated all tests that somehow make use of addresses (mainly sequencer, bridge-withdrawer, composer) ## Breaking Changelist This patch is marked breaking because the sequencer snapshot tests are triggered. They all contain actions that themselves contain protobuf address. This patch is backward but not forward compatible. ## Related Issues closes #943
- Loading branch information
1 parent
b52a824
commit ab8705f
Showing
55 changed files
with
1,298 additions
and
681 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
use astria_core::primitive::v1::{ | ||
Address, | ||
AddressError, | ||
}; | ||
|
||
pub mod cli; | ||
pub mod commands; | ||
pub mod types; | ||
|
||
const ADDRESS_PREFIX: &str = "astria"; | ||
|
||
/// Constructs an [`Address`] prefixed by `"astria"`. | ||
pub(crate) fn astria_address(array: [u8; astria_core::primitive::v1::ADDRESS_LEN]) -> Address { | ||
Address::builder() | ||
.array(array) | ||
.prefix(ADDRESS_PREFIX) | ||
.try_build() | ||
.unwrap() | ||
} | ||
|
||
/// Tries to construct an [`Address`] prefixed by `"astria"` from a byte slice. | ||
/// | ||
/// # Errors | ||
/// Fails if the slice does not contain 20 bytes. | ||
pub(crate) fn try_astria_address(slice: &[u8]) -> Result<Address, AddressError> { | ||
Address::builder() | ||
.slice(slice) | ||
.prefix(ADDRESS_PREFIX) | ||
.try_build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.