-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: payment key shelley address and add test for registration chain
Signed-off-by: bkioshn <[email protected]>
- Loading branch information
Showing
4 changed files
with
180 additions
and
27 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
rust/rbac-registration/src/registration/cardano/cip19_shelley_addr.rs
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! CIP-0019 Shelley Addresses | ||
//! there are currently 8 types of Shelley addresses | ||
//! Header type Payment Part Delegation Part | ||
//! (0) `PaymentKeyHash` `StakeKeyHash` | ||
//! (1) `ScriptHash` `StakeKeyHash` | ||
//! (2) `PaymentKeyHash` `ScriptHash` | ||
//! (3) `ScriptHash` `ScriptHash` | ||
//! (4) `PaymentKeyHash` `Pointer` | ||
//! (5) `ScriptHash` `Pointer` | ||
//! (6) `PaymentKeyHash` ø | ||
//! (7) `ScriptHash` ø | ||
use pallas::codec::utils::Bytes; | ||
|
||
/// CIP-0019 Shelley Addresses (only support type 0 - 5) | ||
#[derive(PartialEq, Clone, Eq, Hash)] | ||
pub struct Cip19ShelleyAddrs([u8; 57]); | ||
|
||
impl From<[u8; 57]> for Cip19ShelleyAddrs { | ||
fn from(bytes: [u8; 57]) -> Self { | ||
Cip19ShelleyAddrs(bytes) | ||
} | ||
} | ||
|
||
impl Default for Cip19ShelleyAddrs { | ||
fn default() -> Self { | ||
Self([0; 57]) | ||
} | ||
} | ||
|
||
impl TryFrom<Bytes> for Cip19ShelleyAddrs { | ||
type Error = &'static str; | ||
|
||
fn try_from(bytes: Bytes) -> Result<Self, Self::Error> { | ||
let byte_vec: Vec<u8> = bytes.into(); | ||
|
||
if byte_vec.len() != 57 { | ||
return Err("Invalid length for Ed25519 public key: expected 57 bytes."); | ||
} | ||
|
||
let byte_array: [u8; 57] = byte_vec | ||
.try_into() | ||
.map_err(|_| "Failed to convert Vec<u8> to [u8; 32]")?; | ||
|
||
Ok(Cip19ShelleyAddrs::from(byte_array)) | ||
} | ||
} | ||
|
||
impl From<Cip19ShelleyAddrs> for Bytes { | ||
fn from(val: Cip19ShelleyAddrs) -> Self { | ||
let vec: Vec<u8> = val.0.to_vec(); | ||
Bytes::from(vec) | ||
} | ||
} |
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.