rework decode_slatepack function to accept decryption key indices (#445)

This commit is contained in:
Yeastplume
2020-06-15 14:39:52 +01:00
committed by GitHub
parent d9c6bd89e2
commit 040b28f35a
5 changed files with 72 additions and 16 deletions
+15 -5
View File
@@ -2117,13 +2117,16 @@ where
}
/// Decode an armored slatepack, returning a Slatepack object that can be
/// viewed, manipulated, output as json, etc
/// viewed, manipulated, output as json, etc. The resulting slatepack will be
/// decrypted by this wallet if possible
///
/// # Arguments
///
/// * `keychain_mask` - Wallet secret mask to XOR against the stored wallet seed before using
/// * `slatepack` - A string representing an armored slatepack
/// * `decrypt` - If true and the slatepack message content is encrypted, attempt to decrypt
/// * `secret_indices` - Indices along this wallet's deriviation path with which to attempt
/// decryption. If this wallet can't decrypt this slatepack, the payload of the returned
/// Slatepack will remain encrypted.
///
/// # Returns
/// * Ok with a [Slatepack](../grin_wallet_libwallet/slatepack/types/struct.Slatepack.html) if successful
@@ -2143,18 +2146,25 @@ where
/// # let slatepack_string = String::from("");
/// // .. receive a slatepack from somewhere
/// let res = api_owner.decode_slatepack_message(
/// None,
/// slatepack_string,
/// false,
/// vec![0, 1, 2],
/// );
///
/// ```
pub fn decode_slatepack_message(
&self,
keychain_mask: Option<&SecretKey>,
slatepack: String,
decrypt: bool,
secret_indices: Vec<u32>,
) -> Result<Slatepack, Error> {
owner::decode_slatepack_message(slatepack, decrypt)
owner::decode_slatepack_message(
self.wallet_inst.clone(),
keychain_mask,
slatepack,
secret_indices,
)
}
// PAYMENT PROOFS
+14 -5
View File
@@ -1577,8 +1577,9 @@ pub trait OwnerRpc {
"jsonrpc": "2.0",
"method": "decode_slatepack_message",
"params": {
"message": "BEGINSLATEPACK. t9EcGgrKr1GFCQB SK2jPCxME6Hgpqx bntpQm3zKFycoPY nW4UeoL4KQ7ExNK At6EQsvpz6MjUs8 6WG8KHEbMfqufJQ ZJTw2gkcdJmJjiJ f29oGgYqqXDZox4 ujPSjrtoxCN4h3e i1sZ8dYsm3dPeXL 7VQLsYNjAefciqj ZJXPm4Pqd7VDdd4 okGBGBu3YJvYzT6 arAxeCEx66us31h AJLcDweFwyWBkW5 J1DLiYAjt5ftFTo CjpfW9KjiLq2LM5 jepXWEHJPSDAYVK 4macDZUhRbJiG6E hrQcPrJBVC716mb Hw5E1PFrE6on5wq oEmrS4j9vaB5nw8 Z9ZyXvPc2LN7tER yt6pSHZeY9EpYdY zv4bthzfRfF8ePT TMeMpV2gpgyRXQa CPD2TR. ENDSLATEPACK.\n",
"decrypt" : false
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"secret_indices": [0],
"message": "BEGINSLATEPACK. t9EcGgrKr1GFCQB SK2jPCxME6Hgpqx bntpQm3zKFycoPY nW4UeoL4KQ7ExNK At6EQsvpz6MjUs8 6WG8KHEbMfqufJQ ZJTw2gkcdJmJjiJ f29oGgYqqXDZox4 ujPSjrtoxCN4h3e i1sZ8dYsm3dPeXL 7VQLsYNjAefciqj ZJXPm4Pqd7VDdd4 okGBGBu3YJvYzT6 arAxeCEx66us31h AJLcDweFwyWBkW5 J1DLiYAjt5ftFTo CjpfW9KjiLq2LM5 jepXWEHJPSDAYVK 4macDZUhRbJiG6E hrQcPrJBVC716mb Hw5E1PFrE6on5wq oEmrS4j9vaB5nw8 Z9ZyXvPc2LN7tER yt6pSHZeY9EpYdY zv4bthzfRfF8ePT TMeMpV2gpgyRXQa CPD2TR. ENDSLATEPACK.\n"
},
"id": 1
}
@@ -1604,8 +1605,9 @@ pub trait OwnerRpc {
fn decode_slatepack_message(
&self,
token: Token,
message: String,
decrypt: bool,
secret_indices: Vec<u32>,
) -> Result<Slatepack, ErrorKind>;
/**
@@ -2077,10 +2079,17 @@ where
fn decode_slatepack_message(
&self,
token: Token,
message: String,
decrypt: bool,
secret_indices: Vec<u32>,
) -> Result<Slatepack, ErrorKind> {
Owner::decode_slatepack_message(self, message, decrypt).map_err(|e| e.kind())
Owner::decode_slatepack_message(
self,
(&token.keychain_mask).as_ref(),
message,
secret_indices,
)
.map_err(|e| e.kind())
}
fn retrieve_payment_proof(