Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for signed-ietf-json-patch #33

Merged
merged 15 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ base64 = "0.13"
libsecp256k1 = "0.5.0"
signature_bls = "0.30.0"
bls12_381_plus = "0.6"
json-patch = "0.2.6"

[dependencies.p256]
version = "0.9.0"
Expand Down
6 changes: 3 additions & 3 deletions src/bls12381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
didcore::{Config, KeyFormat, JWK},
generate_seed,
traits::{CoreSign, DIDCore, Fingerprint, Generate, ECDH},
Document, Error, KeyMaterial, KeyPair, VerificationMethod,
Document, Error, KeyMaterial, BaseKeyPair, VerificationMethod,
};

pub struct Bls12381KeyPairs {
Expand Down Expand Up @@ -196,9 +196,9 @@ impl ECDH for Bls12381KeyPairs {
}
}

impl From<Bls12381KeyPairs> for KeyPair {
impl From<Bls12381KeyPairs> for BaseKeyPair {
fn from(key_pair: Bls12381KeyPairs) -> Self {
KeyPair::Bls12381G1G2(key_pair)
BaseKeyPair::Bls12381G1G2(key_pair)
}
}

Expand Down
33 changes: 31 additions & 2 deletions src/didcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub const CONFIG_LD_PRIVATE: Config = Config {
serialize_secrets: true,
};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Document {
#[serde(rename = "@context")]
Expand All @@ -42,16 +42,30 @@ pub struct Document {
pub verification_method: Vec<VerificationMethod>,
}

#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
#[derive(Serialize, Deserialize, Debug)]
pub struct IetfJsonPatch {
#[serde(rename = "ietf-json-patch")]
pub value: serde_json::Value,
}

#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
pub struct VerificationMethod {
pub id: String,
#[serde(rename = "type")]
pub key_type: String,
pub controller: String,
#[serde(alias = "publicKeyBase58")]
#[serde(alias = "publicKeyMultibase")]
#[serde(alias = "publicKeyJwk")]
pub public_key: Option<KeyFormat>,
#[serde(alias = "privateKeyBase58")]
#[serde(alias = "privateKeyMultibase")]
#[serde(alias = "privateKeyJwk")]
pub private_key: Option<KeyFormat>,
}

#[derive(Serialize, Debug, Clone, PartialEq, Deserialize)]
#[serde(untagged)]
pub enum KeyFormat {
Base58(String),
Multibase(Vec<u8>),
Expand All @@ -74,6 +88,21 @@ pub struct JWK {
pub d: Option<String>,
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct JWSHeader {
#[serde(rename = "alg")]
pub algorithm: String,
#[serde(rename = "kid", default, skip_serializing_if = "Option::is_none")]
pub key_id: Option<String>,
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct JWS {
pub header: JWSHeader,
pub payload: Vec<u8>,
pub signature: Vec<u8>,
}

impl Serialize for VerificationMethod {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
6 changes: 3 additions & 3 deletions src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
didcore::{Config, Document, KeyFormat, VerificationMethod, JWK},
traits::{DIDCore, Fingerprint, Generate, ECDH},
x25519::X25519KeyPair,
AsymmetricKey, Error, KeyMaterial, KeyPair,
AsymmetricKey, Error, KeyMaterial, BaseKeyPair,
};
use curve25519_dalek::edwards::CompressedEdwardsY;
use ed25519_dalek::*;
Expand Down Expand Up @@ -192,9 +192,9 @@ impl ECDH for Ed25519KeyPair {
}
}

impl From<Ed25519KeyPair> for KeyPair {
impl From<Ed25519KeyPair> for BaseKeyPair {
fn from(key_pair: Ed25519KeyPair) -> Self {
KeyPair::Ed25519(key_pair)
BaseKeyPair::Ed25519(key_pair)
}
}

Expand Down
Loading