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

Could not add additional field into "credentialSubject" when issuing credential #385

Closed
Lisbet111111 opened this issue Apr 24, 2024 · 1 comment

Comments

@Lisbet111111
Copy link

Lisbet111111 commented Apr 24, 2024

Test code(refer to lib/java/test/com/spruceid/DIDKitTest.java) as below:

String jwk = DIDKit.generateEd25519Key();
String method = "key";
String did = DIDKit.keyToDID(method, jwk);
String verificationMethod = DIDKit.keyToVerificationMethod(method, jwk);
String hash = "9c71f81d0375bca3ebb3b2a234f8ba27af968b8f362725a40c4a49ea1de26b56";
String credential = "{"
  + "   \"@context\": \"https://www.w3.org/2018/credentials/v1\","
  + "   \"id\": \"http://example.org/credentials/3731\","
  + "   \"type\": [\"VerifiableCredential\"],"
  + "   \"issuer\": \"" + did + "\","
  + "   \"issuanceDate\": \"2020-08-19T21:41:50Z\","
  + "   \"credentialSubject\": {"
  + "       \"id\": \"did:example:d23dd687a7dc6787646f2eb98d0\","
  + "       \"hash\": \"" + hash + "\""
  + "   }"
  + "}";
                    
String vcOptions = "{"
  + "  \"proofPurpose\": \"assertionMethod\","
  + "  \"verificationMethod\": \"" + verificationMethod + "\""
  + "}";
String vc = DIDKit.issueCredential(credential, vcOptions, jwk);

=============================================================

Expect to add additional field "hash" and some other custom fields into "credentialSubject", but met below exception,
QA.1: could you have a look about how to fix this exception and issue credential successfully?
and confirmed it's ok to issue credential after delete the "hash" field from "credentialSubject".
QA.2: Above exception message can NOT be found in the code from "https://github.com/spruceid/ssi", why?

DIDKitException: Expansion failed: Expansion failed: Key expansion failed


Thanks a lot!!

@sbihel
Copy link
Member

sbihel commented Apr 30, 2024

All fields in a Verifiable Credential must be defined in the context. Here's an (untested) example:

{
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    {
      "hash": "https://example.com#hash"
    }
  ]
}

@sbihel sbihel closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants