feat(wasm): clone getters (#600)

* feat(wasm): clone getters

* fix(wasm): get rid of move semantics and implement Clone

* disable test feature
This commit is contained in:
sinu.eth
2024-10-01 07:17:48 -07:00
committed by GitHub
parent 6ed3337739
commit b76b8314ad
11 changed files with 42 additions and 19 deletions

View File

@@ -117,7 +117,7 @@ rand_chacha = { version = "0.3" }
rand_core = { version = "0.6" }
regex = { version = "1.10" }
ring = { version = "0.17" }
rs_merkle = { git = "https://github.com/tlsnotary/rs-merkle.git", rev = "7fb354c" }
rs_merkle = { git = "https://github.com/tlsnotary/rs-merkle.git", rev = "85f3e82" }
rstest = { version = "0.17" }
rustls = { version = "0.21" }
rustls-pemfile = { version = "1.0" }

View File

@@ -12,7 +12,7 @@ use crate::{
};
/// Proof of an attestation.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttestationProof {
signature: Signature,
header: Header,
@@ -71,7 +71,7 @@ impl AttestationProof {
}
/// Proof of an attestation body.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct BodyProof {
body: Body,
proof: MerkleProof,

View File

@@ -12,7 +12,7 @@ use crate::{
};
/// TLS server identity proof.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerIdentityProof {
name: ServerName,
opening: ServerCertOpening,

View File

@@ -16,7 +16,7 @@ impl MerkleError {
}
}
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub(crate) struct MerkleProof {
alg: HashAlgId,
tree_len: usize,
@@ -74,7 +74,7 @@ impl rs_merkle::Hasher for RsMerkleHasher<'_> {
}
}
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub(crate) struct MerkleTree {
alg: HashAlgId,
tree: rs_merkle::MerkleTree<Hash>,

View File

@@ -12,7 +12,7 @@ use crate::{
};
/// A verifiable presentation.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Presentation {
attestation: AttestationProof,
identity: Option<ServerIdentityProof>,

View File

@@ -9,7 +9,7 @@ use crate::{
};
/// Secret data of an [`Attestation`](crate::attestation::Attestation).
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Secrets {
pub(crate) server_name: ServerName,
pub(crate) server_cert_opening: ServerCertOpening,

View File

@@ -16,7 +16,7 @@ use crate::{
};
/// An opening of a leaf in the encoding tree.
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub(super) struct Opening {
pub(super) direction: Direction,
pub(super) seq: Subsequence,
@@ -26,7 +26,7 @@ pub(super) struct Opening {
opaque_debug::implement!(Opening);
/// An encoding proof.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EncodingProof {
pub(super) inclusion_proof: MerkleProof,
pub(super) openings: HashMap<usize, Opening>,

View File

@@ -52,7 +52,7 @@ impl EncodingLeaf {
}
/// A merkle tree of transcript encodings.
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct EncodingTree {
/// Merkle tree of the commitments.
tree: MerkleTree,

View File

@@ -19,7 +19,7 @@ use crate::{
};
/// Proof of the contents of a transcript.
#[derive(Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct TranscriptProof {
encoding_proof: Option<EncodingProof>,
hash_proofs: Vec<PlaintextHashProof>,

View File

@@ -11,8 +11,11 @@ use tlsn_verifier::{Verifier, VerifierConfig};
use wasm_bindgen::prelude::*;
use crate::{
build_presentation,
prover::JsProver,
types::{Commit, HttpRequest, Method, Reveal},
types::{
Attestation, Commit, HttpRequest, Method, NotarizationOutput, Presentation, Reveal, Secrets,
},
verifier::JsVerifier,
};
@@ -122,13 +125,32 @@ pub async fn test_notarize() -> Result<(), JsValue> {
let _ = prover.transcript()?;
prover
let NotarizationOutput {
attestation,
secrets,
} = prover
.notarize(Commit {
sent: vec![0..10],
recv: vec![0..10],
})
.await?;
let attestation = Attestation::deserialize(attestation.serialize())?;
let secrets = Secrets::deserialize(secrets.serialize())?;
let presentation = build_presentation(
&attestation,
&secrets,
Reveal {
sent: vec![(0..10)],
recv: vec![(0..10)],
},
)?;
let presentation = Presentation::deserialize(presentation.serialize())?;
let _ = presentation.verify()?;
Ok(())
}

View File

@@ -179,7 +179,7 @@ pub enum KeyType {
P256,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[wasm_bindgen]
#[serde(transparent)]
pub struct Attestation(pub(crate) tlsn_core::attestation::Attestation);
@@ -207,7 +207,7 @@ impl From<tlsn_core::attestation::Attestation> for Attestation {
}
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[wasm_bindgen]
#[serde(transparent)]
pub struct Secrets(pub(crate) tlsn_core::Secrets);
@@ -244,10 +244,11 @@ pub struct Presentation(tlsn_core::presentation::Presentation);
#[wasm_bindgen]
impl Presentation {
/// Verifies the presentation.
pub fn verify(self) -> Result<PresentationOutput, JsError> {
pub fn verify(&self) -> Result<PresentationOutput, JsError> {
let provider = CryptoProvider::default();
self.0
.clone()
.verify(&provider)
.map(PresentationOutput::from)
.map_err(JsError::from)
@@ -288,8 +289,8 @@ impl From<tlsn_core::presentation::PresentationOutput> for PresentationOutput {
}
}
#[derive(Debug, Tsify, Serialize)]
#[tsify(into_wasm_abi)]
#[derive(Debug, Serialize)]
#[wasm_bindgen(getter_with_clone)]
pub struct NotarizationOutput {
pub attestation: Attestation,
pub secrets: Secrets,