digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Invalid JSON-LD syntax; "@value" value must not be an object or an array. #392

Closed OR13 closed 4 years ago

OR13 commented 4 years ago
let object ={

 "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020#publicKeyJwk": {
        "type": "@json",
        "@value": {
          "crv": "secp256k1",
          "kid": "JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw",
          "kty": "EC",
          "x": "dWCvM4fTdeM0KmloF57zxtBPXTOythHPMm1HCLrdd3A",
          "y": "36uMVGM7hnw-N6GnjFcihWE3SkrhMLzzLCdPMXPEXlA"
        }
      }

}
const compacted = await jsonld.compact(
        object,
        "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020"
      );

Is it not possible to compact something that uses @json ?

OR13 commented 4 years ago

I am getting:

{
      "id": "did:example:123#vm-1",
      "type": "sec:EcdsaSecp256k1RecoveryMethod2020",
      "controller": {
        "id": "did:example:123",
        "assertionMethod": [
          "did:example:123#vm-1"
        ],
        "publicKey": "did:example:123#vm-1"
      },
      "sec:privateKeyJwk": {
        "type": "@json",
        "@value": {
          "crv": "secp256k1",
          "d": "rhYFsBPF9q3-uZThy7B3c4LDF_8wnozFUAEm5LLC4Zw",
          "kid": "JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw",
          "kty": "EC",
          "x": "dWCvM4fTdeM0KmloF57zxtBPXTOythHPMm1HCLrdd3A",
          "y": "36uMVGM7hnw-N6GnjFcihWE3SkrhMLzzLCdPMXPEXlA"
        }
      },
      "sec:publicKeyJwk": {
        "type": "@json",
        "@value": {
          "crv": "secp256k1",
          "kid": "JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw",
          "kty": "EC",
          "x": "dWCvM4fTdeM0KmloF57zxtBPXTOythHPMm1HCLrdd3A",
          "y": "36uMVGM7hnw-N6GnjFcihWE3SkrhMLzzLCdPMXPEXlA"
        }
      }
    }

I want something more like....

{
      "id": "did:example:123#vm-1",
      "controller": "did:example:123",
      "type": "EcdsaSecp256k1RecoveryMethod2020",
      "publicKeyJwk": {
        "crv": "secp256k1",
        "kid": "JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw",
        "kty": "EC",
        "x": "dWCvM4fTdeM0KmloF57zxtBPXTOythHPMm1HCLrdd3A",
        "y": "36uMVGM7hnw-N6GnjFcihWE3SkrhMLzzLCdPMXPEXlA"
      },
      "privateKeyJwk": {
        "crv": "secp256k1",
        "d": "rhYFsBPF9q3-uZThy7B3c4LDF_8wnozFUAEm5LLC4Zw",
        "kid": "JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw",
        "kty": "EC",
        "x": "dWCvM4fTdeM0KmloF57zxtBPXTOythHPMm1HCLrdd3A",
        "y": "36uMVGM7hnw-N6GnjFcihWE3SkrhMLzzLCdPMXPEXlA"
      }
    },
OR13 commented 4 years ago

Pretty sure this is the problem: https://github.com/digitalbazaar/jsonld-signatures/blob/master/lib/suites/LinkedDataSignature.js#L233

OR13 commented 4 years ago
// Note: `expansionMap` is intentionally not passed; we can safely drop
    // properties here and must allow for it
    const {'@graph': [framed]} = await jsonld.frame(verificationMethod, {
      '@context': constants.SECURITY_CONTEXT_URL,
      '@embed': '@always',
      id: verificationMethod
    }, {documentLoader, compactToRelative: false});
    if(!framed) {
      throw new Error(`Verification method ${verificationMethod} not found.`);
    }

    // ensure verification method has not been revoked
    if(framed.revoked !== undefined) {
      throw new Error('The verification method has been revoked.');
    }

    return framed;

by setting the @context in the frame... doesn't this pretty much prevent extension of linked data signatures that use getVerificationMethod but don't have types defined in the hardcoded security context?

OR13 commented 4 years ago

I figured out why... its because of the use of frame with a hard coded context that only supports w3id.org/security/v2...