Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
], async function (ctx, args) {
if (!_.has(args, 'url')) {
throw new Error('http:' + method.toLowerCase() + ' needs a url string')
}
if (!ktypes.isString(args.url)) {
throw new TypeError('http:' + method.toLowerCase() + ' was given ' + ktypes.toString(args.url) + ' instead of a url string')
}
if (_.has(args, 'autosend')) {
const event = cleanEvent(args.autosend)
httpBase(method, ctx, args)
.then(r => {
core.signalEvent(Object.assign({}, event, {
attrs: Object.assign({}, event.attrs, r)
}))
})
.catch(err => {
ctx.log('error', err + '')// TODO better handling
})
return
}
var isBlank = function(str){
return !ktypes.isString(str) || str.trim().length === 0;
};
], async (ctx, args) => {
const chann = await core.db.getChannelSecrets(args.eci)
const keys = {
public: bs58.decode(chann.sovrin.indyPublic),
public58: chann.sovrin.indyPublic,
private: bs58.decode(chann.sovrin.secret.indyPrivate)
}
const wrapper = ktypes.isString(args.message)
? JSON.parse(args.message)
: args.message
const recipsOuter = JSON.parse(b64decStr(wrapper.protected))
const recipient = recipsOuter.recipients.find(r => {
return r.header.kid === keys.public58
})
if (!recipient) {
throw new Error('No corresponding recipient key found')
}
let pk = sodium.crypto_sign_ed25519_pk_to_curve25519(keys.public)
let sk = sodium.crypto_sign_ed25519_sk_to_curve25519(keys.private)
let encrytpedKey = b64dec(recipient.encrypted_key)
let nonce = recipient.header.iv ? b64dec(recipient.header.iv) : null
let encSender = recipient.header.sender ? b64dec(recipient.header.sender) : null
let picoId = picoArgOrCtxPico('uninstallRuleset', ctx, args)
picoId = await core.db.assertPicoID(picoId)
let ridIsString = ktypes.isString(args.rid)
if (!ridIsString && !ktypes.isArray(args.rid)) {
throw new TypeError('engine:uninstallRuleset was given ' + ktypes.toString(args.rid) + ' instead of a rid string or array')
}
if (ridIsString) {
await core.uninstallRuleset(picoId, args.rid)
return
}
let rids = _.uniq(args.rid)
for (let rid of rids) {
if (!ktypes.isString(rid)) {
throw new TypeError('engine:uninstallRuleset was given a rid array containing a non-string (' + ktypes.toString(rid) + ')')
}
}
for (let rid of rids) {
await core.uninstallRuleset(picoId, rid)
}
}),
], async function (ctx, args) {
if (!_.has(args, 'eci')) {
throw new Error('engine:removeChannel needs an eci string')
}
if (!ktypes.isString(args.eci)) {
throw new TypeError('engine:removeChannel was given ' + ktypes.toString(args.eci) + ' instead of an eci string')
}
try {
await core.db.removeChannel(args.eci)
return true
} catch (err) {
if (err && err.notFound) return false
throw err
}
}),
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: []
}
}
], async function (ctx, args) {
if (!_.has(args, 'rid')) {
throw new Error('engine:unregisterRuleset needs a rid string or array')
}
if (ktypes.isString(args.rid)) {
await core.unregisterRuleset(args.rid)
return
}
if (!ktypes.isArray(args.rid)) {
throw new TypeError('engine:unregisterRuleset was given ' + ktypes.toString(args.rid) + ' instead of a rid string or array')
}
let rids = _.uniq(args.rid)
for (let rid of rids) {
if (!ktypes.isString(rid)) {
throw new TypeError('engine:unregisterRuleset was given a rid array containing a non-string (' + ktypes.toString(rid) + ')')
}
}
for (let rid of rids) {
}
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))
], async function (ctx, args) {
let picoId = picoArgOrCtxPico('newChannel', ctx, args)
let policyId = ADMIN_POLICY_ID
if (_.has(args, 'policy_id')) {
if (!ktypes.isString(args.policy_id)) {
throw new TypeError('engine:newChannel argument `policy_id` should be String but was ' + ktypes.typeOf(args.policy_id))
}
policyId = args.policy_id
}
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)
let picoArgOrCtxPico = function (fnName, ctx, args, key) {
key = key || 'pico_id'
let picoId = _.has(args, key) ? args[key] : ctx.pico_id
if (!ktypes.isString(picoId)) {
throw new TypeError('engine:' + fnName + ' was given ' + ktypes.toString(args.eci) + ' instead of a ' + key + ' string')
}
return picoId
}