import { Ed25519VerificationKey2020 } from "@digitalbazaar/ed25519-verification-key-2020";
import { Ed25519Signature2020 } from "@digitalbazaar/ed25519-signature-2020";
import jsonSigs from "jsonld-signatures";
import jsonld from "jsonld";
import { CryptoLD } from "crypto-ld";
(async () => {
const cryptoLd = new CryptoLD();
cryptoLd.use(Ed25519VerificationKey2020);
cryptoLd.use(Ed25519Signature2020);
const edKeyPair = await cryptoLd.generate({
type: "Ed25519VerificationKey2020",
controller: "https://w3id.org/security/v2",
id: "did:asd:tanjin#z6MknpatYMfHz3di8zdbHcWZfBHz4VDNfvmDD27Uf5eqZ6Aq",
controller: "https://example.com/i/carol",
});
const keypair = edKeyPair.export({
publicKey: true,
privateKeyBase58: true,
controller: true,
});
const { AuthenticationProofPurpose } = jsonSigs.purposes;
const purpose = new AuthenticationProofPurpose({
challenge: "ABC",
domain: "http://localhost:3000",
});
const doc = {
"@context": ["https://schema.org"],
"@type": "https://schema.org/Person",
name: "Tanjin Alam",
url: "https://vishwas.netlify.app/",
image:
"https://asdf.com",
description:
"Tanjin Alam is a software developer. He is trying to learning cryptography",
birthdate: "1996-11-16",
jobTitle: "Software Engineer",
};
const signed_doc = await jsonSigs.sign(doc, {
documentLoader: jsonld.documentLoaders.node(),
suite: new Ed25519Signature2020({
key: edKeyPair,
}),
purpose,
});
console.log("signed_doc", signed_doc);
const purposesss = new AuthenticationProofPurpose({
edKeyPair,
challenge: "ABC",
domain: "http://localhost:3000",
});
const verficiaiton = await jsonSigs.verify(signed_doc, {
purpose: purposesss,
suite: new Ed25519Signature2020({
key: edKeyPair,
}),
});
console.log("verficiaiton", verficiaiton);
})();
from the first console i am getting following output
signed_doc {
'@context': [
'https://schema.org',
'https://w3id.org/security/suites/ed25519-2020/v1'
],
'@type': 'https://schema.org/Person',
name: 'Tanjin Alam',
url: 'https://vishwas.netlify.app/',
image: 'https://asdf.com',
description: 'Tanjin Alam is a software developer. He is trying to learning cryptography',
birthdate: '1996-11-16',
jobTitle: 'Software Engineer',
proof: {
type: 'Ed25519Signature2020',
created: '2023-06-28T17:35:54Z',
verificationMethod: 'did:asd:tanjin#z6MknpatYMfHz3di8zdbHcWZfBHz4VDNfvmDD27Uf5eqZ6Aq',
proofPurpose: 'authentication',
challenge: 'ABC',
domain: 'http://localhost:3000',
proofValue: 'z3r8zfvUDiJVmvg3SvpmdZyGj1bujXkvhXiEc8XEbfyGXAa7W42q5aeHPMZeuWv2jf6UWapp9he6rnmHxdwibx4bA'
}
}
which seems okay but when i am trying to verify the proof i am having following error
verficiaiton {
verified: false,
results: [
{
proof: [Object],
verified: false,
verificationMethod: undefined,
error: [JsonLdError]
}
],
error: VerificationError: Verification error(s).
at Object.verify (/Users/piash/Desktop/Blockchain-Research/did-backend/node_modules/jsonld-signatures/lib/jsonld-signatures.js:180:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///Users/piash/Desktop/Blockchain-Research/did-backend/index.js:54:24 {
errors: [ [JsonLdError] ]
}
}