Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if(options.import) {
await _import(options, privateDidDocument);
} else {
console.log(JSON.stringify(privateDidDocument, null, 2));
}
*/
// get config
const release = await _config._lockConfig(options);
const config = await _config._loadConfig(options);
// set explicit notes
const notes = {};
if(options.name) {
logger._debug(options, 'adding "name" note');
jsonld.addValue(notes, 'name', options.name);
}
if(options.description) {
logger._debug(options, 'adding "description" note');
jsonld.addValue(notes, 'description', options.description);
}
// check if ok to set auto notes
if(options.notes) {
if(jsonld.hasValue(config, 'urn:did-client:notes:auto', 'created')) {
jsonld.addValue(notes, 'created', new Date().toISOString());
}
}
await release();
await helpers._notesAddMany(didDocument.id, notes, options);
logger._log(options, 'Local DID generation successful.');
}
*/
// get config
const release = await _config._lockConfig(options);
const config = await _config._loadConfig(options);
// set explicit notes
const notes = {};
if(options.name) {
logger._debug(options, 'adding "name" note');
jsonld.addValue(notes, 'name', options.name);
}
if(options.description) {
logger._debug(options, 'adding "description" note');
jsonld.addValue(notes, 'description', options.description);
}
// check if ok to set auto notes
if(options.notes) {
if(jsonld.hasValue(config, 'urn:did-client:notes:auto', 'created')) {
jsonld.addValue(notes, 'created', new Date().toISOString());
}
}
await release();
await helpers._notesAddMany(didDocument.id, notes, options);
logger._log(options, 'Local DID generation successful.');
if(options.register) {
await _send({options, didDocument, v1/* , privateDidDocument*/});
} else {
logger._log(
};
}
// account for type-scoped `proof` definition by getting document types
const {types, alias} = await _getTypeInfo(
{document, documentLoader, expansionMap});
expandedProof['@type'] = types;
const ctx = jsonld.getValues(document, '@context');
const compactProof = await jsonld.compact(
expandedProof, ctx,
{documentLoader, expansionMap, compactToRelative: false});
delete compactProof[alias];
delete compactProof['@context'];
// add proof to document
const key = Object.keys(compactProof)[0];
jsonld.addValue(document, key, compactProof[key]);
} else {
// in-place restore any existing proofs
/*if(existingProofs) {
document[proofProperty] = existingProofs;
}*/
// add new proof
delete proof['@context'];
jsonld.addValue(document, proofProperty, proof);
}
return document;
}
const config = await _config._loadConfig(options);
// set explicit notes
const notes = {};
if(options.name) {
logger._debug(options, 'adding "name" note');
jsonld.addValue(notes, 'name', options.name);
}
if(options.description) {
logger._debug(options, 'adding "description" note');
jsonld.addValue(notes, 'description', options.description);
}
// check if ok to set auto notes
if(options.notes) {
if(jsonld.hasValue(config, 'urn:did-client:notes:auto', 'created')) {
jsonld.addValue(notes, 'created', new Date().toISOString());
}
}
await release();
await helpers._notesAddMany(didDocument.id, notes, options);
logger._log(options, 'Local DID generation successful.');
if(options.register) {
await _send({options, didDocument, v1/* , privateDidDocument*/});
} else {
logger._log(
options, 'To register the DID globally, use the `register` command.');
}
};
expandedProof, ctx,
{documentLoader, expansionMap, compactToRelative: false});
delete compactProof[alias];
delete compactProof['@context'];
// add proof to document
const key = Object.keys(compactProof)[0];
jsonld.addValue(document, key, compactProof[key]);
} else {
// in-place restore any existing proofs
/*if(existingProofs) {
document[proofProperty] = existingProofs;
}*/
// add new proof
delete proof['@context'];
jsonld.addValue(document, proofProperty, proof);
}
return document;
}
options.add || options.remove ||
options.set || options.delete)) {
throw new Error('readonly mode: specify DID or use --all');
}
if(options.clear) {
delete config.dids[did];
store = true;
}
const target = config.dids[did] = config.dids[did] || {};
if(options.add) {
if(options.add[0] === 'id' || options.add[0] === '@id') {
throw new Error('Can not add "id"');
}
jsonld.addValue(
target, options.add[0], options.add[1], {allowDuplicate: false});
store = true;
}
if(options.remove) {
if(options.remove[0] === 'id' || options.remove[0] === '@id') {
throw new Error('Can not remove "id"');
}
jsonld.removeValue(target, options.remove[0], options.remove[1]);
store = true;
}
if(options.get) {
if(options.get in target) {
_showNote(did, target, options.get, options);
}
}
if(options.set) {
triples.forEach(function(triple) {
var sub = map[triple.subject];
if (!sub) {
sub = jsonldResource(triple.subject);
map[triple.subject] = sub;
resources.push(sub);
}
var object;
if ((N3.Util.isUri(triple.object) || N3.Util.isBlank(triple.object)) && !map[triple.object]) {
object = jsonldResource(triple.object);
}
if (triple.predicate === rdf.type) {
jsonld.addValue(sub, '@type', triple.object, { propertyIsArray: true });
return;
}
object = jsonldObject(triple.object);
jsonld.addValue(sub, triple.predicate, object, { propertyIsArray: true });
});
api._notesAddMany = async (did, properties, options) => {
if(Object.keys(properties).length === 0) {
return;
}
const release = await _config._lockConfig(options);
const config = await _config._loadConfig(options);
for(const property of Object.keys(properties)) {
const target = config.dids[did] = config.dids[did] || {};
if(property === 'id' || property === '@id') {
throw new Error('Can not set "id"');
}
jsonld.addValue(
target, property, properties[property], {allowDuplicate: false});
}
await _config._storeConfig(config, options);
return await release();
};
map[triple.subject] = sub;
resources.push(sub);
}
var object;
if ((N3.Util.isUri(triple.object) || N3.Util.isBlank(triple.object)) && !map[triple.object]) {
object = jsonldResource(triple.object);
}
if (triple.predicate === rdf.type) {
jsonld.addValue(sub, '@type', triple.object, { propertyIsArray: true });
return;
}
object = jsonldObject(triple.object);
jsonld.addValue(sub, triple.predicate, object, { propertyIsArray: true });
});