Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
// target not found
if(!found) {
const err = new Error('Not Found');
err.httpStatusCode = 404;
err.status = 404;
throw err;
}
const context = [
constants.DID_CONTEXT_URL,
constants.VERES_ONE_CONTEXT_URL
];
// frame target
const framed = await jsonld.frame(
filtered, {'@context': context, id: target}, {embed: '@always'});
return Object.assign({'@context': context}, framed['@graph'][0]);
}
return new Promise((resolve, reject) => {
jsonld.frame(ntdoc, frame, (error, framedJson) => {
if (error) {
reject(error)
}
try {
// error in transformWork will end up in Promise.catch and return 500
const work = transformWork(framedJson[ '@graph' ][ 0 ])
resolve(work)
} catch (error) {
reject(error)
}
})
})
}
};
if(proofPurpose === 'publicKey') {
// direct access to public keys
frame.publicKey = {'@embed': '@never'};
} else {
// indirect access to public keys via application suites
frame[proofPurpose] = {
'@embed': '@always',
publicKey: {'@embed': '@never'}
};
}
const opts = {};
if(options.documentLoader) {
opts.documentLoader = options.documentLoader;
}
const framed = await jsonld.frame(owners, frame, opts);
return framed['@graph'];
}
export const frame = async (input: object, frame: object, options: object = {}): Promise => {
// @ts-ignore
return jsonld.frame(input, frame, options);
};
// backwards compatibility support for `creator`
const {creator} = proof;
verificationMethod = creator;
}
if(typeof verificationMethod === 'object') {
verificationMethod = verificationMethod.id;
}
if(!verificationMethod) {
throw new Error('No "verificationMethod" or "creator" found in proof.');
}
// Note: `expansionMap` is intentionally not passed; we can safely drop
// properties here and must allow for it
const {'@graph': [framed]} = await jsonld.frame(verificationMethod, {
'@context': constants.SECURITY_CONTEXT_URL,
'@embed': '@always',
id: verificationMethod
}, {documentLoader, compactToRelative: false});
if(!framed) {
throw new Error(`Verification method ${verificationMethod} not found.`);
}
// ensure verification method has not been revoked
if(framed.revoked !== undefined) {
throw new Error('The verification method has been revoked.');
}
return framed;
}
// `CryptographicKey` used here for backwards compatibility
let requiredKeyType = 'CryptographicKey';
if(options.keyType) {
requiredKeyType = options.keyType;
}
const frame = {
'@context': constants.SECURITY_CONTEXT_URL,
type: requiredKeyType,
owner: {'@embed': '@never'}
};
const opts = {};
if(options.documentLoader) {
opts.documentLoader = options.documentLoader;
}
const framed = await jsonld.frame(key, frame, opts);
// FIXME: improve validation
if(!framed['@graph'][0]) {
throw new Error(`The public key is not a "${requiredKeyType}".`);
}
if(!framed['@graph'][0].owner) {
throw new Error('The public key has no specified owner.');
}
framed['@graph'][0]['@context'] = framed['@context'];
return framed['@graph'][0];
}
* frame() test
*/
jsonld.frame(doc, frame, (err, res) => {
log(res);
});
jsonld.frame(doc, frame, {embed: "@last", explicit: false}, (err, res) => {
log(res);
});
jsonld.frame(doc, frame)
.then((res) => {
log(res);
});
jsonld.frame(doc, frame, {requireAll: true})
.then((res) => {
log(res);
});
/**
* normalize() test
*/
jsonld.normalize(doc, (err, res) => {
log(res);
});
jsonld.normalize(doc, {algorithm: 'URDNA2015', expansion: false}, (err, res) => {
log(res);
});
jsonld.normalize(doc)
log(res);
});
jsonld.flatten(doc, context, {base: baseUrl})
.then((res) => {
log(res);
});
/**
* frame() test
*/
jsonld.frame(doc, frame, (err, res) => {
log(res);
});
jsonld.frame(doc, frame, {embed: "@last", explicit: false}, (err, res) => {
log(res);
});
jsonld.frame(doc, frame)
.then((res) => {
log(res);
});
jsonld.frame(doc, frame, {requireAll: true})
.then((res) => {
log(res);
});
/**
* normalize() test
*/
.then(json => jsonld.frame(json, studioFrame, { embed: '@always' }))
.then(frame => frame['@graph'][0])
fetchExpandedTriples(iri, function(err, expanded) {
if (err || expanded === null) {
return callback(err, expanded);
}
jsonld.frame(expanded[iri], frame, function(err, framed) {
if (err || expanded === null) {
return callback(err, framed);
}
jsonld.compact(framed, context, options, callback);
});
});
};