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

Use EcdsaSecp256k1RecoveryMethod2020 v2 context #414

Merged
merged 2 commits into from
Mar 31, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions contexts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ pub const SECURITY_V2: &str = include_str!("../w3id-security-v2.jsonld");
pub const DID_V1: &str = include_str!("../w3c-did-v1.jsonld");
/// <https://w3id.org/did-resolution/v1>
pub const DID_RESOLUTION_V1: &str = include_str!("../w3c-did-resolution-v1.jsonld");
#[deprecated(note = "Use W3ID_ESRS2020_V2 instead")]
/// <https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld>
pub const DIF_ESRS2020: &str = include_str!("../dif-lds-ecdsa-secp256k1-recovery2020-0.0.jsonld");
/// <https://w3id.org/security/suites/secp256k1recovery-2020/v2>
pub const W3ID_ESRS2020_V2: &str = include_str!("../w3id-secp256k1recovery2020-v2.jsonld");
/// <https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json>
pub const LDS_JWS2020_V1: &str = include_str!("../lds-jws2020-v1.jsonld");
/// <https://w3id.org/security/suites/jws-2020/v1>
Expand All @@ -36,6 +39,7 @@ pub const TRACEABILITY_V1: &str = include_str!("../w3c-ccg-traceability-v1.jsonl
/// <https://w3id.org/vc-revocation-list-2020/v1>
pub const REVOCATION_LIST_2020_V1: &str = include_str!("../w3id-vc-revocation-list-2020-v1.jsonld");
/// <https://demo.spruceid.com/EcdsaSecp256k1RecoverySignature2020/esrs2020-extra-0.0.jsonld>
#[deprecated(note = "Use W3ID_ESRS2020_V2 instead")]
pub const ESRS2020_EXTRA: &str = include_str!("../esrs2020-extra-0.0.jsonld");
/// <https://w3id.org/security/bbs/v1>
pub const BBS_V1: &str = include_str!("../bbs-v1.jsonld");
Expand Down
87 changes: 87 additions & 0 deletions contexts/w3id-secp256k1recovery2020-v2.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"@context": {
"id": "@id",
"type": "@type",
"@protected": true,
"proof": {
"@id": "https://w3id.org/security#proof",
"@type": "@id",
"@container": "@graph"
},
"EcdsaSecp256k1RecoveryMethod2020": {
"@id": "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020#EcdsaSecp256k1RecoveryMethod2020",
"@context": {
"@protected": true,
"id": "@id",
"type": "@type",
"controller": {
"@id": "https://w3id.org/security#controller",
"@type": "@id"
},
"blockchainAccountId": "https://w3id.org/security#blockchainAccountId",
"publicKeyJwk": {
"@id": "https://w3id.org/security#publicKeyJwk",
"@type": "@json"
}
}
},
"EcdsaSecp256k1RecoverySignature2020": {
"@id": "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020#EcdsaSecp256k1RecoverySignature2020",
"@context": {
"@protected": true,
"id": "@id",
"type": "@type",
"challenge": "https://w3id.org/security#challenge",
"created": {
"@id": "http://purl.org/dc/terms/created",
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"domain": "https://w3id.org/security#domain",
"expires": {
"@id": "https://w3id.org/security#expiration",
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"jws": "https://w3id.org/security#jws",
"nonce": "https://w3id.org/security#nonce",
"proofPurpose": {
"@id": "https://w3id.org/security#proofPurpose",
"@type": "@vocab",
"@context": {
"@protected": true,
"id": "@id",
"type": "@type",
"assertionMethod": {
"@id": "https://w3id.org/security#assertionMethod",
"@type": "@id",
"@container": "@set"
},
"authentication": {
"@id": "https://w3id.org/security#authenticationMethod",
"@type": "@id",
"@container": "@set"
},
"capabilityInvocation": {
"@id": "https://w3id.org/security#capabilityInvocationMethod",
"@type": "@id",
"@container": "@set"
},
"capabilityDelegation": {
"@id": "https://w3id.org/security#capabilityDelegationMethod",
"@type": "@id",
"@container": "@set"
},
"keyAgreement": {
"@id": "https://w3id.org/security#keyAgreementMethod",
"@type": "@id",
"@container": "@set"
}
}
},
"verificationMethod": {
"@id": "https://w3id.org/security#verificationMethod",
"@type": "@id"
}
}
}
}
}
18 changes: 18 additions & 0 deletions src/jsonld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ pub const DID_V1_CONTEXT_NO_WWW: &str = "https://w3.org/ns/did/v1";
pub const W3ID_DID_V1_CONTEXT: &str = "https://w3id.org/did/v1";
pub const DID_RESOLUTION_V1_CONTEXT: &str = "https://w3id.org/did-resolution/v1";
pub const DIF_ESRS2020_CONTEXT: &str = "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld";
#[deprecated(note = "Use W3ID_ESRS2020_V2_CONTEXT instead")]
pub const ESRS2020_EXTRA_CONTEXT: &str =
"https://demo.spruceid.com/EcdsaSecp256k1RecoverySignature2020/esrs2020-extra-0.0.jsonld";
pub const W3ID_ESRS2020_V2_CONTEXT: &str =
"https://w3id.org/security/suites/secp256k1recovery-2020/v2";
pub const LDS_JWS2020_V1_CONTEXT: &str =
"https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json";
pub const W3ID_JWS2020_V1_CONTEXT: &str = "https://w3id.org/security/suites/jws-2020/v1";
Expand Down Expand Up @@ -192,15 +195,27 @@ lazy_static! {
let iri = Iri::new(DID_RESOLUTION_V1_CONTEXT).unwrap();
RemoteDocument::new(doc, iri)
};
/// Deprecated in favor of W3ID_ESRS2020_V2_CONTEXT_DOCUMENT
pub static ref DIF_ESRS2020_CONTEXT_DOCUMENT: RemoteDocument<JsonValue> = {
#[allow(deprecated)]
let jsonld = ssi_contexts::DIF_ESRS2020;
let doc = json::parse(jsonld).unwrap();
#[allow(deprecated)]
let iri = Iri::new(DIF_ESRS2020_CONTEXT).unwrap();
RemoteDocument::new(doc, iri)
};
pub static ref W3ID_ESRS2020_V2_CONTEXT_DOCUMENT: RemoteDocument<JsonValue> = {
let jsonld = ssi_contexts::W3ID_ESRS2020_V2;
let doc = json::parse(jsonld).unwrap();
let iri = Iri::new(W3ID_ESRS2020_V2_CONTEXT).unwrap();
RemoteDocument::new(doc, iri)
};
/// Deprecated in favor of W3ID_ESRS2020_V2_CONTEXT_DOCUMENT
pub static ref ESRS2020_EXTRA_CONTEXT_DOCUMENT: RemoteDocument<JsonValue> = {
#[allow(deprecated)]
let jsonld = ssi_contexts::ESRS2020_EXTRA;
let doc = json::parse(jsonld).unwrap();
#[allow(deprecated)]
let iri = Iri::new(ESRS2020_EXTRA_CONTEXT).unwrap();
RemoteDocument::new(doc, iri)
};
Expand Down Expand Up @@ -312,7 +327,10 @@ impl Loader for StaticLoader {
Ok(DID_V1_CONTEXT_DOCUMENT.clone())
}
DID_RESOLUTION_V1_CONTEXT => Ok(DID_RESOLUTION_V1_CONTEXT_DOCUMENT.clone()),
#[allow(deprecated)]
DIF_ESRS2020_CONTEXT => Ok(DIF_ESRS2020_CONTEXT_DOCUMENT.clone()),
W3ID_ESRS2020_V2_CONTEXT => Ok(W3ID_ESRS2020_V2_CONTEXT_DOCUMENT.clone()),
#[allow(deprecated)]
ESRS2020_EXTRA_CONTEXT => Ok(ESRS2020_EXTRA_CONTEXT_DOCUMENT.clone()),
LDS_JWS2020_V1_CONTEXT => Ok(LDS_JWS2020_V1_CONTEXT_DOCUMENT.clone()),
W3ID_JWS2020_V1_CONTEXT => Ok(W3ID_JWS2020_V1_CONTEXT_DOCUMENT.clone()),
Expand Down
22 changes: 13 additions & 9 deletions src/ldp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,13 @@ impl ProofSuite for EcdsaSecp256k1RecoverySignature2020 {
return Err(Error::AlgorithmMismatch);
}
}
let has_context = document_has_context(document, crate::jsonld::W3ID_ESRS2020_V2_CONTEXT)?;
let proof = Proof {
context: serde_json::json!([
crate::jsonld::DIF_ESRS2020_CONTEXT,
crate::jsonld::ESRS2020_EXTRA_CONTEXT,
]),
context: if has_context {
Value::Null
} else {
serde_json::json!([crate::jsonld::W3ID_ESRS2020_V2_CONTEXT])
},
..Proof::new("EcdsaSecp256k1RecoverySignature2020")
.with_options(options)
.with_properties(extra_proof_properties)
Expand All @@ -927,11 +929,13 @@ impl ProofSuite for EcdsaSecp256k1RecoverySignature2020 {
_public_key: &JWK,
extra_proof_properties: Option<Map<String, Value>>,
) -> Result<ProofPreparation, Error> {
let has_context = document_has_context(document, crate::jsonld::W3ID_ESRS2020_V2_CONTEXT)?;
let proof = Proof {
context: serde_json::json!([
crate::jsonld::DIF_ESRS2020_CONTEXT,
crate::jsonld::ESRS2020_EXTRA_CONTEXT,
]),
context: if has_context {
Value::Null
} else {
serde_json::json!([crate::jsonld::W3ID_ESRS2020_V2_CONTEXT])
},
..Proof::new("EcdsaSecp256k1RecoverySignature2020")
.with_options(options)
.with_properties(extra_proof_properties)
Expand Down Expand Up @@ -2569,7 +2573,7 @@ mod tests {
.unwrap();
assert!(warnings.is_empty());
}
assert_eq!(n_proofs, 3);
assert_eq!(n_proofs, 4);
}

#[async_std::test]
Expand Down
25 changes: 23 additions & 2 deletions tests/esrs2020-did.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,37 @@
"controller": "did:example:123",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"blockchainAccountId": "eip155:1:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74"
},
{
"id": "did:example:123#vm-4",
"controller": "did:example:123",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"blockchainAccountId": "eip155:1:0xa136D6b820E41858b57b0136514e75f4174ceA5f",
"privateKeyHex": "0b622f72d0cb4f6d7eebfb9d97375aec891c9836fcf813310069cfffdc7811d6"
}
],
"authentication": [
"did:example:123#vm-1",
"did:example:123#vm-2",
"did:example:123#vm-3"
"did:example:123#vm-3",
"did:example:123#vm-4"
],
"assertionMethod": [
"did:example:123#vm-1",
"did:example:123#vm-2",
"did:example:123#vm-3"
"did:example:123#vm-3",
"did:example:123#vm-4"
],
"capabilityDelegation": [
"did:example:123#vm-1",
"did:example:123#vm-2",
"did:example:123#vm-3",
"did:example:123#vm-4"
],
"capabilityInvocation": [
"did:example:123#vm-1",
"did:example:123#vm-2",
"did:example:123#vm-3",
"did:example:123#vm-4"
]
}
10 changes: 8 additions & 2 deletions tests/esrs2020-vc.jsonld
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld",
"https://demo.spruceid.com/EcdsaSecp256k1RecoverySignature2020/esrs2020-extra-0.0.jsonld",
"https://w3id.org/security/suites/secp256k1recovery-2020/v2",
{
"@version": 1.1,
"@protected": true,
Expand Down Expand Up @@ -113,6 +112,13 @@
"verificationMethod": "did:example:123#vm-3",
"proofPurpose": "assertionMethod",
"jws": "eyJhbGciOiJFUzI1NkstUiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..wt1hzqcSx654YaqdCx-6bp6_bkzMbjZc9-071-SRsJsQfUvG_U9ZBWUoCvEtv68Kas10AIvFU6siKw8XZi7knwE"
},
{
"type": "EcdsaSecp256k1RecoverySignature2020",
"created": "2021-12-17T22:36:55Z",
"verificationMethod": "did:example:123#vm-4",
"proofPurpose": "assertionMethod",
"jws": "eyJhbGciOiJFUzI1NkstUiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..fWzq2GBZQBPPyZZfbDCVYz3TI0s0RivTuNakTDyJaAN77i3esHOvzXPSZsy45_zbW3ANSdck_d1bauA94CdQ3AE"
}
]
}