diff --git a/fastpay_core/src/base_types.rs b/fastpay_core/src/base_types.rs index 06ed22584c14c..efe47490eb40d 100644 --- a/fastpay_core/src/base_types.rs +++ b/fastpay_core/src/base_types.rs @@ -37,29 +37,29 @@ pub struct UserData(pub Option<[u8; 32]>); pub struct SecretKey(dalek::Keypair); #[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash, Serialize, Deserialize)] -pub struct EdPublicKeyBytes(pub [u8; dalek::PUBLIC_KEY_LENGTH]); +pub struct PublicKeyBytes(pub [u8; dalek::PUBLIC_KEY_LENGTH]); -pub type PrimaryAddress = EdPublicKeyBytes; -pub type FastPayAddress = EdPublicKeyBytes; -pub type AuthorityName = EdPublicKeyBytes; +pub type PrimaryAddress = PublicKeyBytes; +pub type FastPayAddress = PublicKeyBytes; +pub type AuthorityName = PublicKeyBytes; pub fn get_key_pair() -> (FastPayAddress, SecretKey) { let mut csprng = OsRng; let keypair = dalek::Keypair::generate(&mut csprng); ( - EdPublicKeyBytes(keypair.public.to_bytes()), + PublicKeyBytes(keypair.public.to_bytes()), SecretKey(keypair), ) } -pub fn address_as_base64(key: &EdPublicKeyBytes, serializer: S) -> Result +pub fn address_as_base64(key: &PublicKeyBytes, serializer: S) -> Result where S: serde::ser::Serializer, { serializer.serialize_str(&encode_address(key)) } -pub fn address_from_base64<'de, D>(deserializer: D) -> Result +pub fn address_from_base64<'de, D>(deserializer: D) -> Result where D: serde::de::Deserializer<'de>, { @@ -68,21 +68,21 @@ where Ok(value) } -pub fn encode_address(key: &EdPublicKeyBytes) -> String { +pub fn encode_address(key: &PublicKeyBytes) -> String { base64::encode(&key.0[..]) } -pub fn decode_address(s: &str) -> Result { +pub fn decode_address(s: &str) -> Result { let value = base64::decode(s)?; let mut address = [0u8; dalek::PUBLIC_KEY_LENGTH]; address.copy_from_slice(&value[..dalek::PUBLIC_KEY_LENGTH]); - Ok(EdPublicKeyBytes(address)) + Ok(PublicKeyBytes(address)) } #[cfg(test)] pub fn dbg_addr(name: u8) -> FastPayAddress { let addr = [name; dalek::PUBLIC_KEY_LENGTH]; - EdPublicKeyBytes(addr) + PublicKeyBytes(addr) } #[derive(Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] @@ -114,7 +114,8 @@ impl<'de> Deserialize<'de> for SecretKey { { let s = String::deserialize(deserializer)?; let value = base64::decode(&s).map_err(|err| serde::de::Error::custom(err.to_string()))?; - let key = dalek::Keypair::from_bytes(&value).map_err(|err| serde::de::Error::custom(err.to_string()))?; + let key = dalek::Keypair::from_bytes(&value) + .map_err(|err| serde::de::Error::custom(err.to_string()))?; Ok(SecretKey(key)) } } @@ -127,7 +128,7 @@ impl std::fmt::Debug for Signature { } } -impl std::fmt::Debug for EdPublicKeyBytes { +impl std::fmt::Debug for PublicKeyBytes { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { let s = base64::encode(&self.0); write!(f, "{}", s)?; @@ -274,7 +275,7 @@ pub trait Digestible { #[cfg(test)] impl Digestible for [u8; 5] { fn digest(self: &[u8; 5]) -> [u8; 32] { - use ed25519_dalek::Digest; + use dalek::Digest; let mut h = dalek::Sha512::new(); let mut hash = [0u8; 64]; diff --git a/fastpay_core/tests/staged/fastpay.yaml b/fastpay_core/tests/staged/fastpay.yaml index e245b8ee2c250..c031f6d031704 100644 --- a/fastpay_core/tests/staged/fastpay.yaml +++ b/fastpay_core/tests/staged/fastpay.yaml @@ -2,7 +2,7 @@ AccountInfoRequest: STRUCT: - sender: - TYPENAME: EdPublicKeyBytes + TYPENAME: PublicKeyBytes - request_sequence_number: OPTION: TYPENAME: SequenceNumber @@ -11,7 +11,7 @@ AccountInfoRequest: AccountInfoResponse: STRUCT: - sender: - TYPENAME: EdPublicKeyBytes + TYPENAME: PublicKeyBytes - balance: TYPENAME: Balance - next_sequence_number: @@ -30,11 +30,11 @@ Address: 0: Primary: NEWTYPE: - TYPENAME: EdPublicKeyBytes + TYPENAME: PublicKeyBytes 1: FastPay: NEWTYPE: - TYPENAME: EdPublicKeyBytes + TYPENAME: PublicKeyBytes Amount: NEWTYPESTRUCT: U64 Balance: @@ -46,13 +46,8 @@ CertifiedTransferOrder: - signatures: SEQ: TUPLE: - - TYPENAME: EdPublicKeyBytes + - TYPENAME: PublicKeyBytes - TYPENAME: Signature -EdPublicKeyBytes: - NEWTYPESTRUCT: - TUPLEARRAY: - CONTENT: U8 - SIZE: 32 FastPayError: ENUM: 0: @@ -120,6 +115,11 @@ FastPayError: ClientIoError: STRUCT: - error: STR +PublicKeyBytes: + NEWTYPESTRUCT: + TUPLEARRAY: + CONTENT: U8 + SIZE: 32 SequenceNumber: NEWTYPESTRUCT: U64 SerializedMessage: @@ -162,13 +162,13 @@ SignedTransferOrder: - value: TYPENAME: TransferOrder - authority: - TYPENAME: EdPublicKeyBytes + TYPENAME: PublicKeyBytes - signature: TYPENAME: Signature Transfer: STRUCT: - sender: - TYPENAME: EdPublicKeyBytes + TYPENAME: PublicKeyBytes - recipient: TYPENAME: Address - amount: