Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// setup JSON-LD library to use
const jsonld = require('jsonld')();
// Use the local Veres One context...
const _orig_doc_loader = jsonld.documentLoader;
jsonld.documentLoader = function(url, callback) {
if (url == 'https://w3id.org/veres-one/v1') {
return callback(null,
{contextUrl: null,
documentUrl: url,
document: v1_context});
} else {
return _orig_doc_loader(url, callback);
}
};
jsigs.use('jsonld', jsonld);
equihashSigs.use('jsonld', jsonld);
const api = {};
module.exports = api;
api.create = options => {
let did = 'did:v1:testnet:' + (options.did || uuid());
let hostname = 'testnet.veres.one';
if(options.mode === 'dev') {
hostname = 'veres.one.local:42443';
request = request.defaults({json: true, strictSSL: false});
} else if(options.mode === 'live') {
did = 'did:v1:' + (options.did || uuid());
hostname = 'veres.one';
}
const jsonld = v1.injector.use('jsonld');
const documentLoader = jsonld.documentLoader;
jsonld.documentLoader = async url => {
if(url in VeresOne.contexts) {
return {
contextUrl: null,
documentUrl: url,
document: VeresOne.contexts[url]
};
}
return documentLoader(url);
};
v1.injector.use('jsonld', jsonld);
const jsigs = require('jsonld-signatures');
jsigs.use('jsonld', jsonld);
const eproofs = require('equihash-signature');
eproofs.install(jsigs);
v1.injector.use('jsonld-signatures', jsigs);
v1.keyStore = Store.using('mock');
v1.didStore = Store.using('mock');
v1.metaStore = Store.using('mock');
});