Add missing token_id to Note. Temp WalletDb workaround.

This commit is contained in:
narodnik
2022-05-05 10:16:01 +02:00
parent 8d6c696e3a
commit 1f7a11a59d
3 changed files with 10 additions and 3 deletions

View File

@@ -5,14 +5,14 @@ use crate::{
crypto::{
diffie_hellman::{kdf_sapling, sapling_ka_agree},
keypair::{PublicKey, SecretKey},
types::*,
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
},
util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable},
Error, Result,
};
/// Plaintext size is serial + value + token_id + coin_blind + value_blind
pub const NOTE_PLAINTEXT_SIZE: usize = 32 + 8 + 32 + 32 + 32;
pub const NOTE_PLAINTEXT_SIZE: usize = 32 + 8 + 32 + 32 + 32 + 32;
pub const AEAD_TAG_SIZE: usize = 16;
pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE;
@@ -23,6 +23,7 @@ pub struct Note {
pub token_id: DrkTokenId,
pub coin_blind: DrkCoinBlind,
pub value_blind: DrkValueBlind,
pub token_blind: DrkValueBlind,
}
impl Note {
@@ -84,6 +85,7 @@ mod tests {
token_id: DrkTokenId::random(&mut OsRng),
coin_blind: DrkCoinBlind::random(&mut OsRng),
value_blind: DrkValueBlind::random(&mut OsRng),
token_blind: DrkValueBlind::random(&mut OsRng),
};
let keypair = Keypair::random(&mut OsRng);
@@ -92,5 +94,6 @@ mod tests {
let note2 = encrypted_note.decrypt(&keypair.secret).unwrap();
assert_eq!(note.value, note2.value);
assert_eq!(note.token_id, note2.token_id);
assert_eq!(note.token_blind, note2.token_blind);
}
}

View File

@@ -147,6 +147,7 @@ impl TransactionBuilder {
token_id: output.token_id,
coin_blind,
value_blind,
token_blind,
};
let encrypted_note = note.encrypt(&output.public)?;

View File

@@ -271,7 +271,9 @@ impl WalletDb {
let value_bytes: Vec<u8> = row.get("value");
let value = u64::from_le_bytes(value_bytes.try_into().unwrap());
let token_id = deserialize(row.get("drk_address"))?;
let note = Note { serial, value, token_id, coin_blind, value_blind };
// TODO: BUG BUG BUG!!! FIXME
let token_blind = deserialize(row.get("valcom_blind"))?;
let note = Note { serial, value, token_id, coin_blind, value_blind, token_blind };
let secret = deserialize(row.get("secret"))?;
let nullifier = deserialize(row.get("nullifier"))?;
@@ -453,6 +455,7 @@ mod tests {
token_id: *t,
coin_blind: DrkCoinBlind::random(&mut OsRng),
value_blind: DrkValueBlind::random(&mut OsRng),
token_blind: DrkValueBlind::random(&mut OsRng),
};
let coin = Coin(pallas::Base::random(&mut OsRng));