keep outgoing slatepacks readable

This commit is contained in:
wiesche
2026-09-07 22:54:00 +02:00
parent 9ee74a8c30
commit 9ac678291a
5 changed files with 19 additions and 8 deletions
+1 -1
View File
@@ -2345,7 +2345,7 @@ where
/// * `keychain_mask` - Wallet secret mask to XOR against the stored wallet seed before using, if
/// * `sender_index` - If Some(n), the index along the derivation path to include as the sender
/// * `recipients` - Optional recipients for which to encrypt the slatepack's payload (i.e. the
/// slate). If an empty vec, the payload will remain unencrypted
/// slate). The sender is also able to decrypt it. If empty, the payload remains unencrypted
///
/// # Returns
/// * Ok with a String representing an armored slatepack if successful
-1
View File
@@ -721,7 +721,6 @@ where
Some(a) => vec![a],
None => vec![],
};
// TODO: what is sender_index?
message = api.create_slatepack_message(m, &slate, Some(0), recipients)?;
// Trim the \n at the end.
let len_withoutcrlf = message.trim_end().len();
+10 -3
View File
@@ -594,10 +594,17 @@ fn slatepack_api_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
..Default::default()
};
let slate = api.init_send_tx(m, args)?;
// create an encrypted slatepack (just encrypted for self)
let enc_addr = api.get_slatepack_address(m, 0)?;
let slatepack = api.create_slatepack_message(m, &slate, Some(0), vec![enc_addr])?;
let recipient_key = edDalekSecretKey::from_bytes(&[1u8; 32]);
let recipient = SlatepackAddress::new(&edDalekPublicKey::from(&recipient_key));
let slatepack = api.create_slatepack_message(m, &slate, Some(0), vec![recipient])?;
println!("{}", slatepack);
let recipient_packer = Slatepacker::new(SlatepackerArgs {
sender: None,
recipients: vec![],
dec_key: Some(&recipient_key),
});
let recipient_copy = recipient_packer.deser_slatepack(slatepack.as_bytes(), true)?;
recipient_packer.get_slate(&recipient_copy)?;
let slatepack_raw = api.decode_slatepack_message(m, slatepack.clone(), vec![0])?;
println!("{}", slatepack_raw);
let decoded_slate = api.slate_from_slatepack_message(m, slatepack, vec![0])?;
+8 -1
View File
@@ -148,7 +148,7 @@ pub fn create_slatepack_message<'a, L, C, K>(
keychain_mask: Option<&SecretKey>,
slate: &Slate,
sender_index: Option<u32>,
recipients: Vec<SlatepackAddress>,
mut recipients: Vec<SlatepackAddress>,
) -> Result<String, Error>
where
L: WalletLCProvider<'a, C, K>,
@@ -159,6 +159,13 @@ where
Some(i) => Some(get_slatepack_address(wallet_inst, keychain_mask, i)?),
None => None,
};
if !recipients.is_empty() {
if let Some(sender) = &sender {
if !recipients.contains(sender) {
recipients.push(sender.clone());
}
}
}
let packer = Slatepacker::new(SlatepackerArgs {
sender,
recipients,
-2
View File
@@ -44,8 +44,6 @@ Separating side effects until the 'save_step' part would make these functions mu
- Expose the kernel feature constants from `grin_core` and reuse them here.
- Move payment-proof creation and verification onto `Slate` so it can also be used
outside contracts and is versioned with the slate format.
- Choose the sender derivation path explicitly and keep encrypted outgoing files
identifiable locally.
- Add contract history, lookup and transport.
- Decide whether the foreign JSON-RPC API should expose `new` and `sign`.
- Add full API and RPC examples once the contract interface is stable.