decentralized-identity / did-key.rs

Rust implementation of the did:key method
Apache License 2.0
47 stars 24 forks source link

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

Closed allibell closed 2 years ago

allibell commented 2 years ago

From #8: implement support per the IETF JSON patch DID extension. This enables us to modify/patch DID documents using JWS payloads.

Notes

Tests new chunky unit tests. snipped output from test_json_patch_demo:

--- snip ---
// DID doc before the patch:
{
  "@context": "https://www.w3.org/ns/did/v1",
  "id": "did:key:z6MkeqkjQXF9LDEVXLZB7GSpThb5FmGGvUxhhAM2nSMzLX7h",
--- snip ---
  "capabilityDelegation": [
    "did:key:z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL#z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL"
  ],
  "capabilityInvocation": [
    "did:key:z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL#z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL"
  ],
--- snip ---

// DID doc after the patch:
// (note it is identical except it has the appended capabilityDelegation and capabilityInvocation)
{
  "@context": "https://www.w3.org/ns/did/v1",
  "id": "did:key:z6MkeqkjQXF9LDEVXLZB7GSpThb5FmGGvUxhhAM2nSMzLX7h",
--- snip ---
  "capabilityDelegation": [
    "did:key:z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL#z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL",
    "did:key:z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL#z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL"
  ],
  "capabilityInvocation": [
    "did:key:z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL#z6MkqhoqdLucQT6ybuFYX5zTkeooAEQbbyRqT1NVfz3wAeyL",
    "did:key:z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL#z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL"
  ],
--- snip ---

full output: https://pastebin.com/HNSDybQz

Follow-ups

allibell commented 2 years ago

as discussed, retitled BaseKeyPair->KeyPair and KeyPair->PatchedKeyPair. This makes it clearer what the wrapper struct is for. it also has the nice effects of 1) making this PR smaller and 2) reducing breaking changes for people relying on KeyPair object internals. tests still happy.