v0.2.5-pre.005
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-wallet-lib/src/wire.rs
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
//! Strict native `.kspwallet` V1 wire envelope.
|
||||
|
||||
@@ -105,6 +105,17 @@ pub struct WalletKdfParametersV1 {
|
||||
}
|
||||
|
||||
impl WalletKdfParametersV1 {
|
||||
pub(crate) fn new_creation(salt: std::vec::Vec<u8>) -> Self {
|
||||
return Self {
|
||||
algorithm: WalletKdfAlgorithmV1::Argon2id,
|
||||
version: crate::KSPWALLET_V1_ARGON2_VERSION,
|
||||
memory_kib: crate::KSPWALLET_V1_DEFAULT_ARGON2_MEMORY_KIB,
|
||||
iterations: crate::KSPWALLET_V1_DEFAULT_ARGON2_ITERATIONS,
|
||||
parallelism: crate::KSPWALLET_V1_DEFAULT_ARGON2_PARALLELISM,
|
||||
salt,
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the KDF algorithm.
|
||||
#[must_use]
|
||||
pub const fn algorithm(&self) -> WalletKdfAlgorithmV1 {
|
||||
@@ -165,6 +176,10 @@ pub struct WalletKeyWrapV1 {
|
||||
}
|
||||
|
||||
impl WalletKeyWrapV1 {
|
||||
pub(crate) fn new(nonce: [u8; crate::KSPWALLET_V1_XCHACHA_NONCE_BYTES], ciphertext: std::vec::Vec<u8>) -> Self {
|
||||
return Self { algorithm: WalletAeadAlgorithmV1::XChaCha20Poly1305, nonce, ciphertext };
|
||||
}
|
||||
|
||||
/// Returns the wrapping AEAD algorithm.
|
||||
#[must_use]
|
||||
pub const fn algorithm(&self) -> WalletAeadAlgorithmV1 {
|
||||
@@ -205,6 +220,10 @@ pub struct WalletKeySlotV1 {
|
||||
}
|
||||
|
||||
impl WalletKeySlotV1 {
|
||||
pub(crate) fn new(slot_id: [u8; crate::KSPWALLET_V1_SLOT_ID_BYTES], role: WalletKeySlotRoleV1, kdf: WalletKdfParametersV1, wrap: WalletKeyWrapV1) -> Self {
|
||||
return Self { slot_id, role, kdf, wrap };
|
||||
}
|
||||
|
||||
/// Returns the stable 16-byte slot identifier.
|
||||
#[must_use]
|
||||
pub const fn slot_id(&self) -> &[u8; crate::KSPWALLET_V1_SLOT_ID_BYTES] {
|
||||
@@ -250,6 +269,14 @@ pub struct WalletViewDescriptorV1 {
|
||||
}
|
||||
|
||||
impl WalletViewDescriptorV1 {
|
||||
pub(crate) const fn disabled() -> Self {
|
||||
return Self { enabled: false, slot_id: std::option::Option::None };
|
||||
}
|
||||
|
||||
pub(crate) const fn enabled(slot_id: [u8; crate::KSPWALLET_V1_SLOT_ID_BYTES]) -> Self {
|
||||
return Self { enabled: true, slot_id: std::option::Option::Some(slot_id) };
|
||||
}
|
||||
|
||||
/// Reports whether a VIEW slot is enabled.
|
||||
#[must_use]
|
||||
pub const fn enabled(&self) -> bool {
|
||||
@@ -274,6 +301,16 @@ pub struct WalletEncryptedCompartmentV1 {
|
||||
}
|
||||
|
||||
impl WalletEncryptedCompartmentV1 {
|
||||
pub(crate) fn new(kind: WalletCompartmentKindV1, nonce: [u8; crate::KSPWALLET_V1_XCHACHA_NONCE_BYTES], ciphertext: std::vec::Vec<u8>) -> Self {
|
||||
return Self {
|
||||
kind,
|
||||
payload_version: crate::KSPWALLET_V1_INITIAL_PAYLOAD_VERSION,
|
||||
algorithm: WalletAeadAlgorithmV1::XChaCha20Poly1305,
|
||||
nonce,
|
||||
ciphertext,
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the compartment kind.
|
||||
#[must_use]
|
||||
pub const fn kind(&self) -> WalletCompartmentKindV1 {
|
||||
@@ -326,6 +363,10 @@ pub struct WalletStateSignatureV1 {
|
||||
}
|
||||
|
||||
impl WalletStateSignatureV1 {
|
||||
pub(crate) const fn new(signature: [u8; crate::KSPWALLET_V1_ED25519_SIGNATURE_BYTES]) -> Self {
|
||||
return Self { algorithm: WalletStateSignatureAlgorithmV1::Ed25519, signature };
|
||||
}
|
||||
|
||||
/// Returns the state-signature algorithm.
|
||||
#[must_use]
|
||||
pub const fn algorithm(&self) -> WalletStateSignatureAlgorithmV1 {
|
||||
@@ -363,6 +404,28 @@ pub struct KspWalletEnvelopeV1 {
|
||||
}
|
||||
|
||||
impl KspWalletEnvelopeV1 {
|
||||
pub(crate) fn new_internal(
|
||||
owner_auth_public_key: [u8; crate::KSPWALLET_V1_ED25519_PUBLIC_KEY_BYTES],
|
||||
view_descriptor: WalletViewDescriptorV1,
|
||||
owner_slot: WalletKeySlotV1,
|
||||
view_slot: std::option::Option<WalletKeySlotV1>,
|
||||
owner_control: WalletEncryptedCompartmentV1,
|
||||
metadata: WalletEncryptedCompartmentV1,
|
||||
secret: WalletEncryptedCompartmentV1,
|
||||
state_signature: WalletStateSignatureV1,
|
||||
) -> Self {
|
||||
return Self {
|
||||
owner_auth_public_key,
|
||||
view_descriptor,
|
||||
owner_slot,
|
||||
view_slot,
|
||||
owner_control,
|
||||
metadata,
|
||||
secret,
|
||||
state_signature,
|
||||
};
|
||||
}
|
||||
|
||||
/// Parses and semantically validates one complete `.kspwallet` V1 JSON document.
|
||||
///
|
||||
/// This function validates only the V1 wire grammar, identifiers, canonical Base64url representation, structural bounds and key-slot invariants.
|
||||
|
||||
Reference in New Issue
Block a user