Skip to content

Commit

Permalink
Rename to wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 committed Oct 5, 2023
1 parent d770829 commit 5f2a279
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 78 deletions.
4 changes: 2 additions & 2 deletions crates/core/component/chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use note_source::{NoteSource, SpendInfo};
pub mod test_keys {
use once_cell::sync::Lazy;
use penumbra_keys::{
keys::{AccountGroupId, SpendKey},
keys::{SpendKey, Wallet},
Address, FullViewingKey,
};

Expand Down Expand Up @@ -57,7 +57,7 @@ pub mod test_keys {
pub static FULL_VIEWING_KEY: Lazy<FullViewingKey> =
Lazy::new(|| SPEND_KEY.full_viewing_key().clone());

pub static ACCOUNT_ID: Lazy<AccountGroupId> = Lazy::new(|| FULL_VIEWING_KEY.account_group_id());
pub static ACCOUNT_ID: Lazy<Wallet> = Lazy::new(|| FULL_VIEWING_KEY.account_group_id());
}

// Located here at the bottom of the dep tree for convenience
Expand Down
4 changes: 2 additions & 2 deletions crates/core/keys/src/address/view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use penumbra_proto::{penumbra::core::keys::v1alpha1 as pb, DomainType, TypeUrl};
use serde::{Deserialize, Serialize};

use crate::keys::{AccountGroupId, AddressIndex};
use crate::keys::{AddressIndex, Wallet};

use super::Address;

Expand All @@ -19,7 +19,7 @@ pub enum AddressView {
Visible {
address: Address,
index: AddressIndex,
account_group_id: AccountGroupId,
account_group_id: Wallet,
},
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub use spend::{SpendKey, SpendKeyBytes, SPENDKEY_LEN_BYTES};
mod bip44;
pub use bip44::Bip44Path;

mod account_group;
pub use account_group::AccountGroupId;
mod wallet;
pub use wallet::Wallet;

mod fvk;
mod ivk;
Expand Down
8 changes: 4 additions & 4 deletions crates/core/keys/src/keys/fvk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use penumbra_proto::{
penumbra::core::keys::v1alpha1 as pb, serializers::bech32str, DomainType, TypeUrl,
};

use crate::keys::account_group::AccountGroupId;
use crate::keys::wallet::Wallet;
use crate::{
fmd, ka, prf,
rdsa::{SpendAuth, VerificationKey},
Expand Down Expand Up @@ -124,8 +124,8 @@ impl FullViewingKey {
&self.ak
}

/// Hashes the full viewing key into an [`AccountGroupId`].
pub fn account_group_id(&self) -> AccountGroupId {
/// Hashes the full viewing key into an [`Wallet`].
pub fn account_group_id(&self) -> Wallet {
let hash_result = hash_2(
&ACCOUNT_ID_DOMAIN_SEP,
(
Expand All @@ -136,7 +136,7 @@ impl FullViewingKey {
let hash = hash_result.to_bytes()[..32]
.try_into()
.expect("hash is 32 bytes");
AccountGroupId(hash)
Wallet(hash)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use penumbra_proto::{penumbra::core::keys::v1alpha1 as pb, serializers::bech32st
/// The hash of a full viewing key, used as an account identifier.
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(try_from = "pb::AccountGroupId", into = "pb::AccountGroupId")]
pub struct AccountGroupId(pub [u8; 32]);
pub struct Wallet(pub [u8; 32]);

impl TryFrom<v1alpha1::AccountGroupId> for AccountGroupId {
impl TryFrom<v1alpha1::AccountGroupId> for Wallet {
type Error = anyhow::Error;

fn try_from(value: v1alpha1::AccountGroupId) -> Result<Self, Self::Error> {
Ok(AccountGroupId(
Ok(Wallet(
value
.inner
.try_into()
Expand All @@ -21,25 +21,25 @@ impl TryFrom<v1alpha1::AccountGroupId> for AccountGroupId {
}
}

impl From<AccountGroupId> for v1alpha1::AccountGroupId {
fn from(value: AccountGroupId) -> v1alpha1::AccountGroupId {
impl From<Wallet> for v1alpha1::AccountGroupId {
fn from(value: Wallet) -> v1alpha1::AccountGroupId {
v1alpha1::AccountGroupId {
inner: value.0.to_vec(),
}
}
}

impl std::fmt::Debug for AccountGroupId {
impl std::fmt::Debug for Wallet {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
<Self as std::fmt::Display>::fmt(self, f)
}
}

impl std::fmt::Display for AccountGroupId {
impl std::fmt::Display for Wallet {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&bech32str::encode(
&self.0,
bech32str::account_group_id::BECH32_PREFIX,
bech32str::wallet::BECH32_PREFIX,
bech32str::Bech32m,
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use penumbra_keys::keys::{SeedPhrase, SpendKey};
use penumbra_proto::serializers::bech32str;

#[test]
fn account_group_id_to_bech32() {
fn wallet_to_bech32() {
let seed = SeedPhrase::from_str("comfort ten front cycle churn burger oak absent rice ice urge result art couple benefit cabbage frequent obscure hurry trick segment cool job debate").unwrap();
let spend_key = SpendKey::from_seed_phrase_bip39(seed, 0);
let fvk = spend_key.full_viewing_key();
let account_group_id = fvk.account_group_id();
let actual_bech32_str = account_group_id.to_string();
let wallet = fvk.account_group_id();
let actual_bech32_str = wallet.to_string();

let expected_bech32_str =
"penumbraaccountgroupid15r7q7qsf3hhsgj0g530n7ng9acdacmmx9ajknjz38dyt90u9gcgs767wla"
Expand All @@ -22,10 +22,10 @@ fn account_group_id_to_bech32() {
// Decoding returns original inner vec
let inner_bytes = bech32str::decode(
&expected_bech32_str,
bech32str::account_group_id::BECH32_PREFIX,
bech32str::wallet::BECH32_PREFIX,
bech32str::Bech32m,
)
.unwrap();

assert_eq!(account_group_id.0, inner_bytes.as_slice());
assert_eq!(wallet.0, inner_bytes.as_slice());
}
4 changes: 2 additions & 2 deletions crates/custody/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use penumbra_keys::keys::AccountGroupId;
use penumbra_keys::keys::Wallet;
use penumbra_proto::{custody::v1alpha1 as pb, DomainType, TypeUrl};
use penumbra_transaction::plan::TransactionPlan;

Expand All @@ -10,7 +10,7 @@ pub struct AuthorizeRequest {
/// The transaction plan to authorize.
pub plan: TransactionPlan,
/// Identifies the FVK (and hence the spend authorization key) to use for signing.
pub account_group_id: Option<AccountGroupId>,
pub account_group_id: Option<Wallet>,
/// Optionally, pre-authorization data, if required by the custodian.
pub pre_authorizations: Vec<PreAuthorization>,
}
Expand Down
10 changes: 5 additions & 5 deletions crates/proto/src/serializers/bech32str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,25 @@ pub mod full_viewing_key {
}
}

pub mod account_group_id {
pub mod wallet {
use super::*;

/// The Bech32 prefix used for account group ids.
pub const BECH32_PREFIX: &str = "penumbraaccountgroupid";
/// The Bech32 prefix used for wallets
pub const BECH32_PREFIX: &str = "penumbrawallet";

pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where
D: Deserializer<'de>,
{
deserialize_bech32(deserializer, BECH32_PREFIX, Variant::Bech32m)
deserialize_bech32(deserializer, BECH32_PREFIX, Bech32m)
}

pub fn serialize<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<[u8]>,
{
serialize_bech32(value, serializer, BECH32_PREFIX, Variant::Bech32m)
serialize_bech32(value, serializer, BECH32_PREFIX, Bech32m)
}
}

Expand Down
38 changes: 19 additions & 19 deletions crates/view/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use penumbra_dex::{
TradingPair,
};
use penumbra_keys::{
keys::{AccountGroupId, AddressIndex},
keys::{AddressIndex, Wallet},
Address,
};
use penumbra_num::Amount;
Expand Down Expand Up @@ -46,13 +46,13 @@ pub trait ViewClient {
/// Get the current status of chain sync.
fn status(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
) -> Pin<Box<dyn Future<Output = Result<pb::StatusResponse>> + Send + 'static>>;

/// Stream status updates on chain sync until it completes.
fn status_stream(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
) -> Pin<
Box<
dyn Future<
Expand Down Expand Up @@ -98,29 +98,29 @@ pub trait ViewClient {
/// Queries for a specific note by commitment, returning immediately if it is not found.
fn note_by_commitment(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
note_commitment: note::StateCommitment,
) -> Pin<Box<dyn Future<Output = Result<SpendableNoteRecord>> + Send + 'static>>;

/// Queries for a specific swap by commitment, returning immediately if it is not found.
fn swap_by_commitment(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
swap_commitment: penumbra_tct::StateCommitment,
) -> Pin<Box<dyn Future<Output = Result<SwapRecord>> + Send + 'static>>;

/// Queries for a specific nullifier's status, returning immediately if it is not found.
fn nullifier_status(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
nullifier: Nullifier,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'static>>;

/// Waits for a specific nullifier to be detected, returning immediately if it is already
/// present, but waiting otherwise.
fn await_nullifier(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
nullifier: Nullifier,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;

Expand All @@ -129,7 +129,7 @@ pub trait ViewClient {
/// This is useful for waiting for a note to be detected by the view service.
fn await_note_by_commitment(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
note_commitment: note::StateCommitment,
) -> Pin<Box<dyn Future<Output = Result<SpendableNoteRecord>> + Send + 'static>>;

Expand All @@ -141,7 +141,7 @@ pub trait ViewClient {
/// service could have advanced the state commitment tree state between queries).
fn witness(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
plan: &TransactionPlan,
) -> Pin<Box<dyn Future<Output = Result<WitnessData>> + Send + 'static>>;

Expand Down Expand Up @@ -185,7 +185,7 @@ pub trait ViewClient {
#[instrument(skip(self, account_group_id))]
fn unspent_notes_by_address_and_asset(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
) -> Pin<
Box<
dyn Future<
Expand Down Expand Up @@ -226,7 +226,7 @@ pub trait ViewClient {
#[instrument(skip(self, account_group_id))]
fn unspent_notes_by_asset_and_address(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
) -> Pin<
Box<
dyn Future<
Expand Down Expand Up @@ -291,7 +291,7 @@ where
{
fn status(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
) -> Pin<Box<dyn Future<Output = Result<pb::StatusResponse>> + Send + 'static>> {
let mut self2 = self.clone();
async move {
Expand All @@ -306,7 +306,7 @@ where

fn status_stream(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
) -> Pin<
Box<
dyn Future<
Expand Down Expand Up @@ -425,7 +425,7 @@ where

fn note_by_commitment(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
note_commitment: note::StateCommitment,
) -> Pin<Box<dyn Future<Output = Result<SpendableNoteRecord>> + Send + 'static>> {
let mut self2 = self.clone();
Expand Down Expand Up @@ -491,7 +491,7 @@ where

fn swap_by_commitment(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
swap_commitment: penumbra_tct::StateCommitment,
) -> Pin<Box<dyn Future<Output = Result<SwapRecord>> + Send + 'static>> {
let mut self2 = self.clone();
Expand Down Expand Up @@ -519,7 +519,7 @@ where
/// This is useful for waiting for a note to be detected by the view service.
fn await_note_by_commitment(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
note_commitment: note::StateCommitment,
) -> Pin<Box<dyn Future<Output = Result<SpendableNoteRecord>> + Send + 'static>> {
let mut self2 = self.clone();
Expand All @@ -544,7 +544,7 @@ where
/// Queries for a specific nullifier's status, returning immediately if it is not found.
fn nullifier_status(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
nullifier: Nullifier,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'static>> {
let mut self2 = self.clone();
Expand All @@ -566,7 +566,7 @@ where
/// present, but waiting otherwise.
fn await_nullifier(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
nullifier: Nullifier,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>> {
let mut self2 = self.clone();
Expand All @@ -587,7 +587,7 @@ where

fn witness(
&mut self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
plan: &TransactionPlan,
) -> Pin<Box<dyn Future<Output = Result<WitnessData>> + Send + 'static>> {
// TODO: delete this code and move it into the view service.
Expand Down
6 changes: 3 additions & 3 deletions crates/view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use penumbra_governance::{
};
use penumbra_ibc::{IbcAction, Ics20Withdrawal};
use penumbra_keys::{
keys::{AccountGroupId, AddressIndex},
keys::{AddressIndex, Wallet},
Address,
};
use penumbra_num::Amount;
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<R: RngCore + CryptoRng> Planner<R> {
/// Get all the note requests necessary to fulfill the current [`Balance`].
pub fn notes_requests(
&self,
account_group_id: AccountGroupId,
account_group_id: Wallet,
source: AddressIndex,
) -> (Vec<NotesRequest>, Vec<NotesForVotingRequest>) {
(
Expand Down Expand Up @@ -425,7 +425,7 @@ impl<R: RngCore + CryptoRng> Planner<R> {
pub async fn plan<V: ViewClient>(
&mut self,
view: &mut V,
account_group_id: AccountGroupId,
account_group_id: Wallet,
source: AddressIndex,
) -> anyhow::Result<TransactionPlan> {
// Gather all the information needed from the view service
Expand Down
Loading

0 comments on commit 5f2a279

Please sign in to comment.