Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/src/record-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ class NetworkRecordProvider implements RecordProvider {
const recordsPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, ["credits.aleo"], microcredits, maxAmount, searchParameters.nonces, this.account.privateKey());
return recordsPts.map((record) => ({
owner: record.owner().toString(),
programName: 'credits.aleo',
recordName: 'credits',
recordPlaintext: record.toString(),
program_name: 'credits.aleo',
record_name: 'credits',
record_plaintext: record.toString(),
}));
}

Expand Down
21 changes: 20 additions & 1 deletion wasm/src/record/record_plaintext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::{
CurrentNetwork,
FieldNative,
IdentifierNative,
LiteralNative,
PlaintextEntryNative,
PlaintextNative,
ProgramIDNative,
Expand Down Expand Up @@ -108,7 +109,11 @@ impl RecordPlaintext {
pub fn owner(&self) -> Result<Address, String> {
match self.0.owner() {
Owner::<CurrentNetwork, PlaintextNative>::Public(owner) => Ok(Address::from(*owner)),
_ => Err("Record is not public".to_string()),
// For decrypted records, extract the address from the plaintext literal
Owner::<CurrentNetwork, PlaintextNative>::Private(plaintext) => match plaintext {
PlaintextNative::Literal(LiteralNative::Address(address), _) => Ok(Address::from(*address)),
_ => Err("Private owner is not an address literal".to_string()),
},
}
}

Expand Down Expand Up @@ -469,6 +474,20 @@ mod tests {
assert!(RecordPlaintext::from_string(invalid_bech32).is_err());
}

#[wasm_bindgen_test]
fn test_owner_with_private_visibility() {
let record = RecordPlaintext::from_string(CREDITS_RECORD).unwrap();
let owner = record.owner().unwrap();
assert_eq!(owner.to_string(), "aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3");
}

#[wasm_bindgen_test]
fn test_owner_with_private_visibility_battleship() {
let record = RecordPlaintext::from_string(BATTLESHIP_RECORD).unwrap();
let owner = record.owner().unwrap();
assert_eq!(owner.to_string(), "aleo1kh5t7m30djl0ecdn4f5vuzp7dx0tcwh7ncquqjkm4matj2p2zqpqm6at48");
}

#[wasm_bindgen_test]
fn test_record_decrypt_record_sender_ciphertext() {
// Get the private key corresponding to the record.
Expand Down