Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, function(err){
if(err) return callback(err);
var root = {
type: ktypes.typeOf(val)
};
switch(root.type){
case "Null":
root.value = null;
break;
case "Function":
case "Action":
root.type = "String";
root.value = ktypes.toString(val);
break;
case "Map":
case "Array":
_.each(val, function(v, k){
ops.push({
type: "put",
key: key_prefix.concat(["value", k]),
value: v,
});
});
// this `value` helps _.set in the toObj db dump set the right type
root.value = root.type === "Array" ? [] : {};
break;
default:
root.value = val;
}
if (!_.has(args, 'name')) {
throw new Error('engine:newChannel needs a name string')
}
if (!_.has(args, 'type')) {
throw new Error('engine:newChannel needs a type string')
}
picoId = await core.db.assertPicoID(picoId)
policyId = await core.db.assertPolicyID(policyId)
return core.db.newChannel({
pico_id: picoId,
name: ktypes.toString(args.name),
type: ktypes.toString(args.type),
policy_id: policyId
})
}),
], async (ctx, args) => {
const message = ktypes.toString(args.message)
let sender
if (args.fromECI) {
const fromChann = await core.db.getChannelSecrets(args.fromECI)
sender = {}
sender.vk = fromChann.sovrin.indyPublic
const privateKey = bs58.decode(fromChann.sovrin.secret.indyPrivate)
sender.sk = sodium.crypto_sign_ed25519_sk_to_curve25519(privateKey)
}
const cek = sodium.crypto_secretstream_xchacha20poly1305_keygen()
const recipients = args.toPublicKeys.map(targetVKey => {
if (typeof targetVKey === 'string') {
targetVKey = bs58.decode(targetVKey)
}
var normalizeId = function (domain, id) {
if (domain !== 'ent' && domain !== 'app') {
return ktypes.toString(id)
}
if (_.has(id, 'key') && ktypes.isString(id.key)) {
return {
var_name: id.key,
query: ktypes.isArray(id.path)
? id.path
: [id.path]
}
}
return {
var_name: ktypes.toString(id),
query: []
}
}
decryptChannelMessage: function(eci, encryptedMessage, nonce, otherPublicKey, callback) {
eci = ktypes.toString(eci);
encryptedMessage = ktypes.toString(encryptedMessage);
nonce = ktypes.toString(nonce);
otherPublicKey = ktypes.toString(otherPublicKey);
ldb.get(["channel", eci], function (err, channel) {
if (err) {
if (err.notFound) {
err = new levelup.errors.NotFoundError("ECI not found: " + eci);
err.notFound = true;
}
callback(err);
return;
}
var decryptedMessage;
try {
var sharedSecret = channel.sovrin.sharedSecret;
if (!sharedSecret) {
var privateKey = channel.sovrin.secret.encryptionPrivateKey;
if (ridIsString) {
return install(args.rid)
}
let rids = _.uniq(args.rid)
for (let rid of rids) {
if (!ktypes.isString(rid)) {
throw new TypeError('engine:installRuleset was given a rid array containing a non-string (' + ktypes.toString(rid) + ')')
}
}
return Promise.all(_.map(rids, install))
}
if (!ktypes.isString(args.url)) {
throw new TypeError('engine:installRuleset was given ' + ktypes.toString(args.url) + ' instead of a url string')
}
let uri = ktypes.isString(args.base)
? urllib.resolve(args.base, args.url)
: args.url
let results = await core.db.findRulesetsByURL(uri)
let rids = _.uniq(_.map(results, 'rid'))
if (_.size(rids) === 0) {
let data = await core.registerRulesetURL(uri)
return install(data.rid)
}
if (_.size(rids) !== 1) {
throw new Error('More than one rid found for the given url: ' + rids.join(' , '))
}
return install(_.head(rids))
}),
], function (ctx, args) {
if (!_.has(args, 'name')) {
throw new Error('send_directive needs a name string')
}
if (!ktypes.isString(args.name)) {
throw new TypeError('send_directive was given ' + ktypes.toString(args.name) + ' instead of a name string')
}
if (!_.has(args, 'options')) {
args.options = {}
} else if (!ktypes.isMap(args.options)) {
throw new TypeError('send_directive was given ' + ktypes.toString(args.options) + ' instead of an options map')
}
return ctx.addActionResponse(ctx, 'directive', {
name: args.name,
options: args.options
})
})
assertPolicyID: function(id, callback){
id = ktypes.toString(id);
ldb.get(["policy", id], function(err){
if(err && err.notFound){
err = new levelup.errors.NotFoundError("Policy not found: " + id);
err.notFound = true;
}
callback(err, err ? null : id);
});
},