-
Notifications
You must be signed in to change notification settings - Fork 51
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
Ensure README code examples are all runnable #185
Comments
Because I am new and wanted to explore the options, I started with the first README example: import vc from '@digitalbazaar/vc';
// Required to set up a suite instance with private key
import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020';
import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020';
const keyPair = await Ed25519VerificationKey2020.generate();
const suite = new Ed25519Signature2020({key: keyPair}); The first error was, that import * as vc from '@digitalbazaar/vc';
// [...] Then to create my first VC, I used the code below: // Sample unsigned credential
const credential = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"id": "https://example.com/credentials/1872",
"type": ["VerifiableCredential", "AlumniCredential"],
"issuer": "https://example.edu/issuers/565049",
"issuanceDate": "2010-01-01T19:23:24Z",
"credentialSubject": {
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
"alumniOf": "Example University"
}
};
const signedVC = await vc.issue({credential, suite, documentLoader});
console.log(JSON.stringify(signedVC, null, 2)); The problem with that was the const contexts = Object.create(null);
async function documentLoader(url) {
if (!contexts[url]) {
try {
const response = await fetch(url)
const document = await response.json()
if (!document['@context']) throw new Error('invalid ContextDocument')
contexts[url] = document
} catch (err) {
console.error(err)
return defaultDocumentLoader(url)
}
}
return { documentUrl: url, document: contexts[url] }
} After all this, I still got the following error: TypeError: "suite.verificationMethod" property is required.
at Module.issue (file:///./node_modules/@digitalbazaar/vc/lib/index.js:123:11)
at <anonymous> (./temp-sample.ts:44:27) To just see a first result, I added the following before issuing the VC: suite.verificationMethod = () => true; This is obviously not the way it is meant to be, but I could also not find any documentation of the |
Related to this are recent updates to an example script to issue and verify a VC and VP: #162. |
This will likely include removing and clarifying that when suites are passed for verification, they should not include key pairs (unless key-pinning is desired, which is an advanced case). Similarly, the examples should pass
signer
APIs (created viakeypair.signer()
, etc.) instead of passing key pairs for signing directly to encourage this pattern as it supports hiding / not exposing secret key material better.The text was updated successfully, but these errors were encountered: