Skip to content

Commit

Permalink
addes hash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Konrad authored and Alessandro Konrad committed Sep 14, 2021
1 parent 6238440 commit b513b9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rust/src/plutus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ impl PlutusData {
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct PlutusList(Vec<PlutusData>);

to_from_bytes!(PlutusList);

#[wasm_bindgen]
impl PlutusList {
pub fn new() -> Self {
Expand Down
24 changes: 24 additions & 0 deletions rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,30 @@ pub fn hash_auxiliary_data(auxiliary_data: &AuxiliaryData) -> AuxiliaryDataHash
pub fn hash_transaction(tx_body: &TransactionBody) -> TransactionHash {
TransactionHash::from(crypto::blake2b256(tx_body.to_bytes().as_ref()))
}
#[wasm_bindgen]
pub fn hash_plutus_data(plutus_data: &PlutusData) -> DataHash {
DataHash::from(blake2b256(&plutus_data.to_bytes()))
}
#[wasm_bindgen]
pub fn hash_script_data(redeemers: &Redeemers, cost_model: &CostModel, datums: Option<&PlutusList>) -> ScriptDataHash {
/*
; script data format:
; [ redeemers | datums | language views ]
; The redeemers are exactly the data present in the transaction witness set.
; Similarly for the datums, if present. If no datums are provided, the middle
; field is an empty string.
*/
let mut buf = Vec::new();
buf.extend(redeemers.to_bytes());
if let Some(d) = &datums {
buf.extend(d.to_bytes());
} else {
let empty_string = "";
buf.extend(empty_string.as_bytes());
}
buf.extend(cost_model.to_bytes());
ScriptDataHash::from(blake2b256(&buf))
}

// wasm-bindgen can't accept Option without clearing memory, so we avoid exposing this in WASM
pub fn internal_get_implicit_input(
Expand Down

0 comments on commit b513b9d

Please sign in to comment.