Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Compile Contracts
var compiledContracts = compileContracts( config.working_dir, json.files );
// pick the contracts specified in the json
json.contracts = _.pick( compiledContracts, json.contracts );
// transform json to internal
delete json.files;
delete json.ignore;
json.pv = config.version;
var valide = tv4.validate( json, require('../specs/ipfs_' + config.ipfs_version + '.json') );
if( !valide ) {
console.log('ERROR'.red + ': Could not create package. Please report this!:\n'+tv4.error.message);
process.exit();
}
var jsonHash = addJsonToIPFS( json );
// TODO - Check if cliet has funds to publish the package
// web3.eth.estimateGas({
// to: address,
// data:
// });
//
// Inform the user about the gas price
if( config.cli )
console.log('brace yourself, gas will be spend!');
client.request = (options = {}) => {
const valid = tv4.validate(options, requestSchema);
if (!valid) return Promise.reject(tv4.error);
let uri = `${client.endpoint}/${client.apiVersion}${client.pathPrefix}${options.path}`;
// Replace unicode encodings.
uri = uri.replace(///g, '/');
options.headers = options.headers || {};
if (typeof client.token === 'string' && client.token.length) {
options.headers['X-Vault-Token'] = options.headers['X-Vault-Token'] || client.token;
}
options.uri = uri;
debug(options.method, uri);
if (options.json) debug(options.json);
return requestPromise(options).then(client.handleVaultResponse);
};
function validateActivityStream(msg) {
// TODO figure out a way to allow for special objects from platforms, without
// ignoring failed activity stream schema checks
if (! tv4.validate(msg, SockethubSchemas.ActivityStream)) {
return tv4.getSchema(`http://sockethub.org/schemas/v0/context/${msg.context}/messages`);
}
return true;
}
return function(data) {
return tv4.validate(data, schema);
};
};
function validateActivityObject(msg) {
return tv4.validate({ object: msg }, SockethubSchemas.ActivityObject);
}
function jsonValidate(value, schema, detailedErrorMessage) {
if (tv4.validate(value, schema)) {
return true;
}
else if (detailedErrorMessage) {
throw syntaxError('%s \nData path: "%s" \nSchema path: "%s"\n',
tv4.error.message, tv4.error.dataPath, tv4.error.schemaPath);
}
else {
throw syntaxError(tv4.error.message);
}
}
testThrows(function () { tv4.validate("I'm not a schema!", undefined); }, "Cannot read property '$ref' of undefined");
}
function validateCredentials(msg, schema) {
return tv4.validate(msg, schema);
}
export function castGeojson(format, value) {
if (!lodash.isObject(value)) {
if (!lodash.isString(value)) {
return ERROR;
}
try {
value = JSON.parse(value);
} catch (error) {
return ERROR;
}
}
if (format === "default") {
try {
const valid = tv4.validate(value, profile);
if (!valid) {
return ERROR;
}
} catch (error) {
return ERROR;
}
} else if (format === "topojson") {
if (!lodash.isPlainObject(value)) {
return ERROR;
}
}
return value;
}
return schemas.find(schema => tv4.validate(cleanData, schema))
}