Skip to content

Commit c7f6c4d

Browse files
authored
Merge pull request #102 from KeystoneHQ/update
feat: modify zcash account structure
2 parents abaf493 + 96feeb0 commit c7f6c4d

File tree

6 files changed

+22
-166
lines changed

6 files changed

+22
-166
lines changed

libs/ur-registry-ffi/src/zcash/zcash_accounts.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,10 @@ impl From<ur_registry::zcash::zcash_accounts::ZcashAccounts> for ZcashAccounts {
2323
}
2424
}
2525

26-
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
27-
struct ZcashTransparentAccount {
28-
path: String,
29-
xpub: String,
30-
}
31-
32-
impl From<CryptoHDKey> for ZcashTransparentAccount {
33-
fn from(value: CryptoHDKey) -> Self {
34-
Self {
35-
path: value.get_origin().unwrap().get_path().unwrap(),
36-
xpub: value.get_bip32_key(),
37-
}
38-
}
39-
}
40-
41-
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
42-
struct ZcashShieldedAccount {
43-
path: String,
44-
fvk: String,
45-
}
46-
47-
impl From<ur_registry::zcash::zcash_full_viewing_key::ZcashFullViewingKey>
48-
for ZcashShieldedAccount
49-
{
50-
fn from(value: ur_registry::zcash::zcash_full_viewing_key::ZcashFullViewingKey) -> Self {
51-
Self {
52-
path: value.get_key_path().get_path().unwrap(),
53-
fvk: hex::encode(value.get_key_data()),
54-
}
55-
}
56-
}
57-
5826
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
5927
struct ZcashUnifiedAccount {
60-
transparent: Option<ZcashTransparentAccount>,
61-
orchard: ZcashShieldedAccount,
28+
ufvk: String,
29+
index: u32,
6230
name: Option<String>,
6331
}
6432

@@ -69,8 +37,8 @@ impl From<ur_registry::zcash::zcash_unified_full_viewing_key::ZcashUnifiedFullVi
6937
value: ur_registry::zcash::zcash_unified_full_viewing_key::ZcashUnifiedFullViewingKey,
7038
) -> Self {
7139
Self {
72-
transparent: value.get_transparent().map(|account| account.into()),
73-
orchard: value.get_orchard().into(),
40+
ufvk: value.get_ufvk(),
41+
index: value.get_index(),
7442
name: value.get_name(),
7543
}
7644
}

libs/ur-registry/src/macros_impl.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use crate::sui::{sui_sign_hash_request::SuiSignHashRequest, sui_sign_request::Su
4343
use crate::sui::sui_signature::SuiSignature;
4444
use crate::ton::{ton_sign_request::TonSignRequest, ton_signature::TonSignature};
4545
use crate::zcash::zcash_accounts::ZcashAccounts;
46-
use crate::zcash::zcash_full_viewing_key::ZcashFullViewingKey;
4746
use crate::zcash::zcash_pczt::ZcashPczt;
4847
use crate::zcash::zcash_unified_full_viewing_key::ZcashUnifiedFullViewingKey;
4948
use crate::{impl_cbor_bytes, impl_ur_try_from_cbor_bytes, impl_ur_try_into_cbor_bytes};
@@ -100,7 +99,6 @@ impl_cbor_bytes!(
10099
BtcSignRequest,
101100
BtcSignature,
102101
ZcashAccounts,
103-
ZcashFullViewingKey,
104102
ZcashUnifiedFullViewingKey,
105103
ZcashPczt,
106104
);

libs/ur-registry/src/zcash/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub mod zcash_accounts;
2-
pub mod zcash_full_viewing_key;
32
pub mod zcash_unified_full_viewing_key;
43
pub mod zcash_pczt;

libs/ur-registry/src/zcash/zcash_accounts.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
use alloc::{
2-
format,
3-
string::{String, ToString},
4-
vec::Vec,
5-
};
1+
use alloc::{string::ToString, vec::Vec};
62
use minicbor::data::{Int, Tag};
73

84
use crate::{
95
cbor::{cbor_array, cbor_map},
10-
crypto_key_path::CryptoKeyPath,
116
impl_template_struct,
12-
registry_types::{
13-
RegistryType, CRYPTO_KEYPATH, TON_SIGN_REQUEST, UUID, ZCASH_ACCOUNTS,
14-
ZCASH_UNIFIED_FULL_VIEWING_KEY,
15-
},
7+
registry_types::{RegistryType, ZCASH_ACCOUNTS, ZCASH_UNIFIED_FULL_VIEWING_KEY},
168
traits::{MapSize, RegistryItem},
17-
types::{Bytes, Fingerprint},
9+
types::Bytes,
1810
};
1911

2012
use super::zcash_unified_full_viewing_key::ZcashUnifiedFullViewingKey;

libs/ur-registry/src/zcash/zcash_full_viewing_key.rs

Lines changed: 0 additions & 78 deletions
This file was deleted.

libs/ur-registry/src/zcash/zcash_unified_full_viewing_key.rs

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
1-
use alloc::{
2-
format,
3-
string::{String, ToString},
4-
};
5-
use minicbor::data::{Int, Tag};
1+
use alloc::string::{String, ToString};
2+
use minicbor::data::Int;
63

74
use crate::{
85
cbor::cbor_map,
9-
crypto_hd_key::CryptoHDKey,
10-
crypto_key_path::CryptoKeyPath,
116
impl_template_struct,
12-
registry_types::{
13-
RegistryType, CRYPTO_HDKEY, CRYPTO_KEYPATH, ZCASH_FULL_VIEWING_KEY,
14-
ZCASH_UNIFIED_FULL_VIEWING_KEY,
15-
},
7+
registry_types::{RegistryType, ZCASH_UNIFIED_FULL_VIEWING_KEY},
168
traits::{MapSize, RegistryItem},
17-
types::Bytes,
189
};
1910

20-
use super::zcash_full_viewing_key::ZcashFullViewingKey;
21-
22-
const TRANSPARENT: u8 = 1;
23-
const ORCHARD: u8 = 2;
11+
const UFVK: u8 = 1;
12+
const INDEX: u8 = 2;
2413
const NAME: u8 = 3;
2514

2615
impl_template_struct!(ZcashUnifiedFullViewingKey {
27-
transparent: Option<CryptoHDKey>,
28-
orchard: ZcashFullViewingKey,
16+
ufvk: String,
17+
index: u32,
2918
name: Option<String>
3019
});
3120

3221
impl MapSize for ZcashUnifiedFullViewingKey {
3322
fn map_size(&self) -> u64 {
34-
let mut size = 1;
35-
if self.transparent.is_some() {
36-
size += 1;
37-
}
23+
let mut size = 2;
3824
if self.name.is_some() {
3925
size += 1;
4026
}
@@ -56,18 +42,11 @@ impl<C> minicbor::Encode<C> for ZcashUnifiedFullViewingKey {
5642
) -> Result<(), minicbor::encode::Error<W::Error>> {
5743
e.map(self.map_size())?;
5844

59-
if let Some(transparent) = &self.transparent {
60-
e.int(Int::from(TRANSPARENT))?
61-
.tag(Tag::Unassigned(CRYPTO_HDKEY.get_tag()))?;
62-
CryptoHDKey::encode(transparent, e, _ctx);
63-
}
64-
65-
e.int(Int::from(ORCHARD))?
66-
.tag(Tag::Unassigned(ZCASH_FULL_VIEWING_KEY.get_tag()))?;
67-
ZcashFullViewingKey::encode(&self.orchard, e, _ctx);
45+
e.int(Int::from(UFVK))?.str(&self.ufvk)?;
46+
e.int(Int::from(INDEX))?.u32(self.index)?;
6847

6948
if let Some(name) = &self.name {
70-
e.int(Int::from(NAME))?.str(name);
49+
e.int(Int::from(NAME))?.str(name)?;
7150
}
7251

7352
Ok(())
@@ -81,13 +60,11 @@ impl<'b, C> minicbor::Decode<'b, C> for ZcashUnifiedFullViewingKey {
8160
let key =
8261
u8::try_from(key).map_err(|e| minicbor::decode::Error::message(e.to_string()))?;
8362
match key {
84-
TRANSPARENT => {
85-
d.tag()?;
86-
obj.transparent = Some(CryptoHDKey::decode(d, ctx)?);
63+
UFVK => {
64+
obj.ufvk = d.str()?.to_string();
8765
}
88-
ORCHARD => {
89-
d.tag()?;
90-
obj.orchard = ZcashFullViewingKey::decode(d, ctx)?;
66+
INDEX => {
67+
obj.index = d.u32()?;
9168
}
9269
NAME => {
9370
obj.name = Some(d.str()?.to_string());

0 commit comments

Comments
 (0)