Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sign: ['ledgerEvent', (results, callback) => {
const privateKeyPem =
pki.privateKeyToPem(results.generateKeyPair.privateKey);
// sign the DID Document
jsigs.sign(results.ledgerEvent, {
algorithm: 'LinkedDataSignature2015',
privateKeyPem: privateKeyPem,
creator: did + '/keys/1'
}, (err, result) => {
if(err) {
return callback(err);
}
callback(null, result);
});
}],
postDidDocument: ['pow', 'sign', (results, callback) => {
const documentLoader = options.documentLoader || defaultDocumentLoader;
const {controller, domain} = options;
const purpose = options.purpose || new CredentialIssuancePurpose({
controller,
domain
});
// run common credential checks
const {credential} = options;
if(!credential) {
throw new TypeError('"credential" property is required for issuing.');
}
_checkCredential(credential);
return jsigs.sign(credential, {purpose, documentLoader, ...options});
}
async function _generateCredential() {
const mockCredential = jsonld.clone(mockData.credentials.alpha);
const {authenticationKey, documentLoader} = await _generateDid();
const {Ed25519Signature2018} = jsigs.suites;
const {AuthenticationProofPurpose} = jsigs.purposes;
testLoader.addLoader(documentLoader);
const credential = await jsigs.sign(mockCredential, {
compactProof: false,
documentLoader: testLoader.documentLoader.bind(testLoader),
suite: new Ed25519Signature2018({key: authenticationKey}),
purpose: new AuthenticationProofPurpose({
challenge: 'challengeString'
})
});
return {credential, documentLoader};
}
async function _generatePresentation({challenge, domain}) {
const mockPresentation = jsonld.clone(mockData.presentations.alpha);
const {authenticationKey, documentLoader: dlp} = await _generateDid();
testLoader.addLoader(dlp);
const {Ed25519Signature2018} = jsigs.suites;
const {AuthenticationProofPurpose} = jsigs.purposes;
const {credential, documentLoader: dlc} = await _generateCredential();
testLoader.addLoader(dlc);
mockPresentation.verifiableCredential.push(credential);
const presentation = await jsigs.sign(mockPresentation, {
compactProof: false,
documentLoader: testLoader.documentLoader.bind(testLoader),
suite: new Ed25519Signature2018({key: authenticationKey}),
purpose: new AuthenticationProofPurpose({challenge, domain})
});
return {presentation};
}
for(const c of presentation.verifiableCredential) {
const credential = JSON.parse(JSON.stringify(c));
credential['@context'] = presentation['@context'];
_checkCredential(credential);
}
const documentLoader = options.documentLoader || defaultDocumentLoader;
const {controller, domain, challenge} = options;
const purpose = options.purpose || new CredentialIssuancePurpose({
controller,
domain,
challenge
});
return jsigs.sign(presentation, {purpose, documentLoader, ...options});
}