Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ zkryptium = "0.2.2" # BBS
log = "0.4.21"
async-std = "1.9"
async-trait = "0.1.68"
thiserror = "1.0.40"
thiserror = "2.0"
chrono = "0.4.24"
iref = "3.2.2"
static-iref = "3.0"
Expand Down
1 change: 1 addition & 0 deletions crates/claims/crates/data-integrity/core/src/hashing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(deprecated)] // TODO upgrade `digest` crate when possible.
use digest::{
consts::{U32, U48},
generic_array::{ArrayLength, GenericArray},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl StandardCryptographicSuite for EcdsaSecp256k1RecoverySignature2020 {

type ProofOptions = ();

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl StandardCryptographicSuite for AleoSignature2021 {

type ProofOptions = ();

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl StandardCryptographicSuite for Eip712Signature2021 {

type ProofOptions = ();

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl StandardCryptographicSuite for EthereumPersonalSignature2021 {

type ProofOptions = ();

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl StandardCryptographicSuite for EthereumPersonalSignature2021v0_1 {

type ProofOptions = ();

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl StandardCryptographicSuite for SolanaSignature2021 {

type ProofOptions = ();

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Options {
}

impl RecoverPublicJwk for Options {
fn public_jwk(&self) -> Cow<JWK> {
fn public_jwk(&self) -> Cow<'_, JWK> {
Cow::Borrowed(&self.public_key_jwk)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl StandardCryptographicSuite for Ed25519BLAKE2BDigestSize20Base58CheckEncoded

type ProofOptions = Options;

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl StandardCryptographicSuite for P256BLAKE2BDigestSize20Base58CheckEncodedSig

type ProofOptions = Options;

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl StandardCryptographicSuite for TezosJcsSignature2021 {

type ProofOptions = Options;

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl StandardCryptographicSuite for TezosSignature2021 {

type ProofOptions = Options;

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::Other(Self::NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl StandardCryptographicSuite for Bbs2023 {

type SignatureAlgorithm = Bbs2023SignatureAlgorithm;

fn type_(&self) -> TypeRef {
fn type_(&self) -> TypeRef<'_> {
TypeRef::DataIntegrityProof(CryptosuiteStr::new("bbs-2023").unwrap())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ pub struct JsonCredential {
}

impl JsonLdObject for JsonCredential {
fn json_ld_context(&self) -> Option<Cow<ssi_json_ld::syntax::Context>> {
fn json_ld_context(&self) -> Option<Cow<'_, ssi_json_ld::syntax::Context>> {
Some(Cow::Borrowed(&self.context))
}
}

impl JsonLdNodeObject for JsonCredential {
fn json_ld_type(&self) -> JsonLdTypes {
fn json_ld_type(&self) -> JsonLdTypes<'_> {
JsonLdTypes::new(&[], Cow::Borrowed(&self.types))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/claims/crates/jws/src/compact/url_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<'a> PartialEq<&'a Jws> for String {
/// don't know if it is URL-safe.
/// Use [`JwsVec`](crate::JwsVec) if you don't have any expectations about the
/// encoding.
#[derive(Clone, serde::Serialize)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)]
#[serde(transparent)]
pub struct JwsBuf(String);

Expand Down
1 change: 1 addition & 0 deletions crates/claims/crates/jws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ pub fn recover(algorithm: Algorithm, data: &[u8], signature: &[u8]) -> Result<JW
let rec_id =
k256::ecdsa::RecoveryId::try_from(signature[64]).map_err(ssi_jwk::Error::from)?;
let hash = ssi_crypto::hashes::sha256::sha256(data);
#[allow(deprecated)] // TODO upgrade `digest` crate when possible.
let digest = k256::elliptic_curve::FieldBytes::<k256::Secp256k1>::from_slice(&hash);
let recovered_key = VerifyingKey::recover_from_prehash(digest, &sig, rec_id)
.map_err(ssi_jwk::Error::from)?;
Expand Down
46 changes: 44 additions & 2 deletions crates/claims/crates/jws/src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ssi_claims_core::SignatureError;
use ssi_jwk::{Algorithm, JWK};
use std::borrow::Cow;
use std::{borrow::Cow, rc::Rc, sync::Arc};

use crate::{DecodedJws, DecodedSigningBytes, Header, JwsBuf, JwsSignature};

Expand Down Expand Up @@ -134,7 +134,7 @@ pub trait JwsSigner {
}
}

impl<T: JwsSigner> JwsSigner for &T {
impl<T: ?Sized + JwsSigner> JwsSigner for &T {
async fn fetch_info(&self) -> Result<JwsSignerInfo, SignatureError> {
T::fetch_info(*self).await
}
Expand All @@ -148,6 +148,48 @@ impl<T: JwsSigner> JwsSigner for &T {
}
}

impl<T: JwsSigner> JwsSigner for Box<T> {
async fn fetch_info(&self) -> Result<JwsSignerInfo, SignatureError> {
T::fetch_info(self).await
}

async fn sign_bytes(&self, signing_bytes: &[u8]) -> Result<Vec<u8>, SignatureError> {
T::sign_bytes(self, signing_bytes).await
}

async fn sign(&self, payload: impl JwsPayload) -> Result<JwsBuf, SignatureError> {
T::sign(self, payload).await
}
}

impl<T: JwsSigner> JwsSigner for Rc<T> {
async fn fetch_info(&self) -> Result<JwsSignerInfo, SignatureError> {
T::fetch_info(self).await
}

async fn sign_bytes(&self, signing_bytes: &[u8]) -> Result<Vec<u8>, SignatureError> {
T::sign_bytes(self, signing_bytes).await
}

async fn sign(&self, payload: impl JwsPayload) -> Result<JwsBuf, SignatureError> {
T::sign(self, payload).await
}
}

impl<T: JwsSigner> JwsSigner for Arc<T> {
async fn fetch_info(&self) -> Result<JwsSignerInfo, SignatureError> {
T::fetch_info(self).await
}

async fn sign_bytes(&self, signing_bytes: &[u8]) -> Result<Vec<u8>, SignatureError> {
T::sign_bytes(self, signing_bytes).await
}

async fn sign(&self, payload: impl JwsPayload) -> Result<JwsBuf, SignatureError> {
T::sign(self, payload).await
}
}

impl<T: JwsSigner + Clone> JwsSigner for Cow<'_, T> {
async fn fetch_info(&self) -> Result<JwsSignerInfo, SignatureError> {
T::fetch_info(self.as_ref()).await
Expand Down
2 changes: 1 addition & 1 deletion crates/claims/crates/jwt/src/claims/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod tests {
}
}

fn try_get<C: Claim>(&self) -> Result<Option<Cow<C>>, InvalidClaimValue> {
fn try_get<C: Claim>(&self) -> Result<Option<Cow<'_, C>>, InvalidClaimValue> {
match_claim_type! {
match C {
CustomClaim => {
Expand Down
6 changes: 3 additions & 3 deletions crates/claims/crates/vc/examples/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub struct Credential {
}

impl ssi_json_ld::JsonLdObject for Credential {
fn json_ld_context(&self) -> Option<Cow<ssi_json_ld::syntax::Context>> {
fn json_ld_context(&self) -> Option<Cow<'_, ssi_json_ld::syntax::Context>> {
Some(Cow::Borrowed(self.context.as_ref()))
}
}

impl ssi_json_ld::JsonLdNodeObject for Credential {
fn json_ld_type(&self) -> ssi_json_ld::JsonLdTypes {
fn json_ld_type(&self) -> ssi_json_ld::JsonLdTypes<'_> {
self.type_.to_json_ld_types()
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ impl VerificationMethodResolver for Keyring {
_issuer: Option<&Iri>,
method: Option<ReferenceOrOwnedRef<'_, Ed25519VerificationKey2020>>,
_options: ssi_verification_methods::ResolutionOptions,
) -> Result<Cow<Ed25519VerificationKey2020>, VerificationMethodResolutionError> {
) -> Result<Cow<'_, Ed25519VerificationKey2020>, VerificationMethodResolutionError> {
match method {
Some(ReferenceOrOwnedRef::Owned(_key)) => {
// If we get here, this means the VC embeds the public key used
Expand Down
123 changes: 61 additions & 62 deletions crates/crypto/src/signatures/bbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,67 @@
//!
//! [BBS curves]: https://datatracker.ietf.org/doc/html/draft-yonezawa-pairing-friendly-curves#section-4.2.2
//! [BBS+]: https://mattrglobal.github.io/bbs-signatures-spec/
// This shows how the generators are created with nothing up my sleeve values
// ```ignore
// const PREHASH: &'static [u8] = b"To be, or not to be- that is the question:
// Whether 'tis nobler in the mind to suffer
// The slings and arrows of outrageous fortune
// Or to take arms against a sea of troubles,
// And by opposing end them. To die- to sleep-
// No more; and by a sleep to say we end
// The heartache, and the thousand natural shocks
// That flesh is heir to. 'Tis a consummation
// Devoutly to be wish'd. To die- to sleep.
// To sleep- perchance to dream: ay, there's the rub!
// For in that sleep of death what dreams may come
// When we have shuffled off this mortal coil,
// Must give us pause. There's the respect
// That makes calamity of so long life.
// For who would bear the whips and scorns of time,
// Th' oppressor's wrong, the proud man's contumely,
// The pangs of despis'd love, the law's delay,
// The insolence of office, and the spurns
// That patient merit of th' unworthy takes,
// When he himself might his quietus make
// With a bare bodkin? Who would these fardels bear,
// To grunt and sweat under a weary life,
// But that the dread of something after death-
// The undiscover'd country, from whose bourn
// No traveller returns- puzzles the will,
// And makes us rather bear those ills we have
// Than fly to others that we know not of?
// Thus conscience does make cowards of us all,
// And thus the native hue of resolution
// Is sicklied o'er with the pale cast of thought,
// And enterprises of great pith and moment
// With this regard their currents turn awry
// And lose the name of action.- Soft you now!
// The fair Ophelia!- Nymph, in thy orisons
// Be all my sins rememb'red.";
// const DST_G1: &'static [u8] = b"BLS12381G1_XMD:BLAKE2B_SSWU_RO_BLS_SIGNATURES:1_0_0";
// const DST_G2: &'static [u8] = b"BLS12381G2_XMD:BLAKE2B_SSWU_RO_BLS_SIGNATURES:1_0_0";
//
// use pairing_plus::{
// bls12_381::{G1, G2},
// hash_to_field::{BaseFromRO, ExpandMsgXmd},
// hash_to_curve::HashToCurve,
// serdes::SerDes,
// CurveProjective,
// };
// fn main() {
// let g1 = <G1 as HashToCurve<ExpandMsgXmd<blake2_old::Blake2b>>>::hash_to_curve(PREHASH, DST_G1);
// let g2 = <G2 as HashToCurve<ExpandMsgXmd<blake2_old::Blake2b>>>::hash_to_curve(PREHASH, DST_G2);
//
// let mut g1_bytes = Vec::new();
// let mut g2_bytes = Vec::new();
//
// g1.serialize(&mut g1_bytes, true).unwrap();
// g2.serialize(&mut g2_bytes, true).unwrap();
//
// assert_eq!(g1_bytes.as_slice(), ssi::bbs::BLINDING_G1);
// assert_eq!(g2_bytes.as_slice(), ssi::bbs::BLINDING_G2);
// }
// ```
use bbs::prelude::*;
use pairing_plus::{
bls12_381::{Bls12, Fr, G1, G2},
Expand All @@ -21,68 +82,6 @@ use std::fmt::Formatter;
use thiserror::Error;
use zeroize::Zeroize;

/// This shows how the generators are created with nothing up my sleeve values
/// ```ignore
/// const PREHASH: &'static [u8] = b"To be, or not to be- that is the question:
/// Whether 'tis nobler in the mind to suffer
/// The slings and arrows of outrageous fortune
/// Or to take arms against a sea of troubles,
/// And by opposing end them. To die- to sleep-
/// No more; and by a sleep to say we end
/// The heartache, and the thousand natural shocks
/// That flesh is heir to. 'Tis a consummation
/// Devoutly to be wish'd. To die- to sleep.
/// To sleep- perchance to dream: ay, there's the rub!
/// For in that sleep of death what dreams may come
/// When we have shuffled off this mortal coil,
/// Must give us pause. There's the respect
/// That makes calamity of so long life.
/// For who would bear the whips and scorns of time,
/// Th' oppressor's wrong, the proud man's contumely,
/// The pangs of despis'd love, the law's delay,
/// The insolence of office, and the spurns
/// That patient merit of th' unworthy takes,
/// When he himself might his quietus make
/// With a bare bodkin? Who would these fardels bear,
/// To grunt and sweat under a weary life,
/// But that the dread of something after death-
/// The undiscover'd country, from whose bourn
/// No traveller returns- puzzles the will,
/// And makes us rather bear those ills we have
/// Than fly to others that we know not of?
/// Thus conscience does make cowards of us all,
/// And thus the native hue of resolution
/// Is sicklied o'er with the pale cast of thought,
/// And enterprises of great pith and moment
/// With this regard their currents turn awry
/// And lose the name of action.- Soft you now!
/// The fair Ophelia!- Nymph, in thy orisons
/// Be all my sins rememb'red.";
/// const DST_G1: &'static [u8] = b"BLS12381G1_XMD:BLAKE2B_SSWU_RO_BLS_SIGNATURES:1_0_0";
/// const DST_G2: &'static [u8] = b"BLS12381G2_XMD:BLAKE2B_SSWU_RO_BLS_SIGNATURES:1_0_0";
///
/// use pairing_plus::{
/// bls12_381::{G1, G2},
/// hash_to_field::{BaseFromRO, ExpandMsgXmd},
/// hash_to_curve::HashToCurve,
/// serdes::SerDes,
/// CurveProjective,
/// };
/// fn main() {
/// let g1 = <G1 as HashToCurve<ExpandMsgXmd<blake2_old::Blake2b>>>::hash_to_curve(PREHASH, DST_G1);
/// let g2 = <G2 as HashToCurve<ExpandMsgXmd<blake2_old::Blake2b>>>::hash_to_curve(PREHASH, DST_G2);
///
/// let mut g1_bytes = Vec::new();
/// let mut g2_bytes = Vec::new();
///
/// g1.serialize(&mut g1_bytes, true).unwrap();
/// g2.serialize(&mut g2_bytes, true).unwrap();
///
/// assert_eq!(g1_bytes.as_slice(), ssi::bbs::BLINDING_G1);
/// assert_eq!(g2_bytes.as_slice(), ssi::bbs::BLINDING_G2);
/// }
/// ```

pub const BLINDING_G1: &[u8] = &[
185, 201, 5, 142, 138, 68, 184, 112, 20, 249, 139, 228, 225, 129, 141, 183, 24, 248, 178, 213,
16, 31, 200, 158, 105, 131, 98, 95, 50, 31, 20, 184, 77, 124, 246, 225, 85, 0, 73, 135, 162,
Expand Down
Loading