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

Public Key Missing During W3C JsonLd Credential Signing #2059

Open
rodmenm opened this issue Oct 17, 2024 · 0 comments
Open

Public Key Missing During W3C JsonLd Credential Signing #2059

rodmenm opened this issue Oct 17, 2024 · 0 comments

Comments

@rodmenm
Copy link

rodmenm commented Oct 17, 2024

I'm encountering an issue where the publicKey field is not processed correctly during the signing of a W3C JSON-LD Credential. The signing process fails with an error indicating that the verification method is missing the publicKeyBase58. Below are the logs and relevant code snippets:

Error Logs:

Error signing credential: CredoError: verification method is missing publicKeyBase58
    at getKeyFromEd25519VerificationKey2018 (/home/ubu/Escritorio/Workeito/node_modules/@credo-ts/core/src/modules/dids/domain/verificationMethod/Ed25519VerificationKey2018.ts:42:2)
    at Object.getKeyFromVerificationMethod (/home/ubu/Escritorio/Workeito/node_modules/@credo-ts/core/src/modules/dids/domain/key-type/ed25519.ts:36:50)
    at getKeyFromVerificationMethod (/home/ubu/Escritorio/Workeito/node_modules/@credo-ts/core/src/modules/dids/domain/key-type/keyDidMapping.ts:101:17)
    at W3cJsonLdCredentialService.getPublicKeyFromVerificationMethod (/home/ubu/Escritorio/Workeito/node_modules/@credo-ts/core/src/modules/vc/data-integrity/W3cJsonLdCredentialService.ts:346:45)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at W3cJsonLdCredentialService.signCredential (/home/ubu/Escritorio/Workeito/node_modules/@credo-ts/core/src/modules/vc/data-integrity/W3cJsonLdCredentialService.ts:57:24)
    at W3cCredentialService.signCredential (/home/ubu/Escritorio/Workeito/node_modules/@credo-ts/core/src/modules/vc/W3cCredentialService.ts:65:22)
    at isscred (/home/ubu/Escritorio/Workeito/src/App/controllers/maincontroller.ts:140:7) {
  [cause]: undefined
}
DEBUG: Closing wallet Issuer_Wallet

Code for Signing the Credential:

const signCredentialOptions: W3cJsonLdSignCredentialOptions = {
  format: ClaimFormat.LdpVc,
  credential: credential,
  verificationMethod: dids[0].didDocument!.verificationMethod![0].id,
  proofType: 'DataIntegrityProof',
  proofPurpose: 'VerificationMethod',
  created: new Date().toISOString(),
};

await w3cCredentialServ
  .signCredential(User.context, signCredentialOptions)
  .then((signedCredential) => {
    console.log('Credential signed successfully:', signedCredential);
    res.send(signedCredential);
  })
  .catch((error) => {
    console.error('Error signing credential:', error);
  });

Verification Method:

{
  "id": "did:web:localhost%3A5000:entity#z6Mku12qrBKWcBtkDwFxFc5Uc3ZcrCpuQMVVJmb3n3J8it9S",
  "type": "Ed25519VerificationKey2018",
  "controller": "did:web:localhost%3A5000:entity",
  "publicKeyBase58": "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"
}

Even though the publicKey is present in the input DID document, it seems to be missing when the signing function attempts to retrieve it. The issue arises in the following function where it fails to retrieve the public key:

async getPublicKeyFromVerificationMethod(agentContext, verificationMethod) {
  const documentLoader = this.w3cCredentialsModuleConfig.documentLoader(agentContext);
  const verificationMethodObject = await documentLoader(verificationMethod);
  const verificationMethodClass = utils_1.JsonTransformer.fromJSON(
    verificationMethodObject.document, 
    dids_1.VerificationMethod
  );
  const key = key_type_1.getKeyFromVerificationMethod(verificationMethodClass);
  return key;
}

Here is the value of verificationMethodObject when running this function, and as you can see, the publicKey is missing:

{
  "@context": "https://w3id.org/did/v1",
  "id": "did:web:localhost%3A5000:entity#z6Mku12qrBKWcBtkDwFxFc5Uc3ZcrCpuQMVVJmb3n3J8it9S",
  "type": "Ed25519VerificationKey2018",
  "controller": "did:web:localhost%3A5000:entity"
}

Expected Behavior:

The publicKey should be included in the verification method object and used in the signing process.

Actual Behavior:

The publicKey is missing, which causes the signing process to fail with the error message: verification method is missing publicKeyBase58.

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

1 participant