Skip to content

Commit

Permalink
Show license hash after issuing license
Browse files Browse the repository at this point in the history
possibility of entering license to use

Showing if license is owned

listing licenses for specific user

Issuing particular request

Fixed the secondary flow

Performing setup only once
  • Loading branch information
miloszm committed Nov 9, 2023
1 parent ff6688d commit a4d0996
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 102 deletions.
5 changes: 3 additions & 2 deletions integration-tests/tests/citadel/int_test_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ async fn issue_license(
GAS_PRICE,
);

license_issuer
let (tx_id, _) = license_issuer
.issue_license(rng, &request, &reference_lp.ssk_lp)
.await
.await?;
Ok(tx_id)
}

/// Calculates and verified proof, sends proof along with public parameters
Expand Down
1 change: 1 addition & 0 deletions license-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rand = "0.8"
dusk-bytes = "0.1"
blake3 = "1.3"
tracing = "0.1"
sha3 = "0.10"

[dev-dependencies]
tokio = { version = "1.15", features = ["rt-multi-thread", "time", "fs", "macros"] }
6 changes: 3 additions & 3 deletions license-provider/src/license_issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ impl LicenseIssuer {
rng: &mut R,
request: &Request,
ssk_lp: &SecretSpendKey,
) -> Result<BlsScalar, Error> {
) -> Result<(BlsScalar, Vec<u8>), Error> {
let attr = JubJubScalar::from(USER_ATTRIBUTES);
let license = License::new(&attr, ssk_lp, request, rng);
let license_blob = rkyv::to_bytes::<_, MAX_LICENSE_SIZE>(&license)
.expect("License should serialize correctly")
.to_vec();
let lpk = JubJubAffine::from(license.lsa.pk_r().as_ref());
let license_hash = sponge::hash(&[lpk.get_u(), lpk.get_v()]);
let tuple = (license_blob, license_hash);
let tuple = (license_blob.clone(), license_hash);
trace!(
"sending issue license with license blob size={}",
tuple.0.len()
Expand All @@ -76,6 +76,6 @@ impl LicenseIssuer {
.await?;
let client = RuskHttpClient::new(self.config.rusk_address.clone());
TxAwaiter::wait_for(&client, tx_id).await?;
Ok(tx_id)
Ok((tx_id, license_blob))
}
}
29 changes: 29 additions & 0 deletions license-provider/src/reference_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use blake3::OUT_LEN;
use dusk_bytes::DeserializableSlice;
use dusk_pki::{PublicSpendKey, SecretSpendKey, ViewKey};
use moat_core::{Error, JsonLoader, RequestScanner, MAX_REQUEST_SIZE};
use rkyv::ser::serializers::AllocSerializer;
use sha3::{Digest, Sha3_256};
use std::collections::BTreeSet;
use std::path::Path;
use wallet_accessor::BlockchainAccessConfig;
Expand Down Expand Up @@ -136,6 +138,16 @@ impl ReferenceLP {
})
}

pub fn get_request(&mut self, request_hash: &String) -> Option<Request> {
for (index, request) in self.requests_to_process.iter().enumerate() {
if Self::to_hash_hex(request) == *request_hash {
self.requests_hashes.remove(&Self::hash_request(request));
return Some(self.requests_to_process.remove(index));
}
}
None
}

fn hash_request(request: &Request) -> [u8; OUT_LEN] {
*blake3::hash(
rkyv::to_bytes::<_, MAX_REQUEST_SIZE>(request)
Expand All @@ -144,4 +156,21 @@ impl ReferenceLP {
)
.as_bytes()
}

fn to_hash_hex<T>(object: &T) -> String
where
T: rkyv::Serialize<AllocSerializer<16386>>,
{
let blob = rkyv::to_bytes::<_, 16386>(object)
.expect("type should serialize correctly")
.to_vec();
Self::blob_to_hash_hex(blob.as_slice())
}

fn blob_to_hash_hex(blob: &[u8]) -> String {
let mut hasher = Sha3_256::new();
hasher.update(blob);
let result = hasher.finalize();
hex::encode(result)
}
}
2 changes: 1 addition & 1 deletion moat-cli/request2.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"user_ssk": "c6afd78c8b3902b474d4c0972b62888e4b880dccf8da68e86266fefa45ee7505926f06ab82ac200995f1239d518fdb74903f225f4460d8db62f2449f6d4dc402",
"user_ssk": "45654c72b065e143645ae5877524b96126c222005a8d6a1eca24c99627a45803a48481395dabdbe33cec4f89b36878b3c2f638c9796e34cffac0a02f27c21702",
"provider_psk": "29c4336ef24e585f4506e32e269c5363a71f7dcd74586b210c56e569ad2644e832c785f102dd3c985c705008ec188be819bac85b65c9f70decb9adcf4a72cc43"
}
Loading

0 comments on commit a4d0996

Please sign in to comment.