Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async request(data) {
ow(data, 'data', ow.object);
const body = {
...data,
// TODO: When https://github.com/artemii235/SuperNET/issues/298 is fixed, rename `userpass` to `rpc_password` and also reduce the places we pass around `seedPhrase`.
userpass: this.rpcPassword,
};
let result;
try {
let requestTime;
const response = await this.queue.add(() => {
requestTime = Date.now();
return fetch(this.endpoint, {
method: 'post',
async function encrypt({
url, blockSize, logMode = 'full', plaintext: _plaintext, makeFinalRequest = true, lastCiphertextBlock, ...args
}: EncryptOptions) {
ow(_plaintext, 'plaintext', ow.buffer)
ow(lastCiphertextBlock, ow.optional.buffer)
if (lastCiphertextBlock && lastCiphertextBlock.length !== blockSize) throw TypeError('Invalid `lastCiphertextBlock`, should have length equal to `blockSize`')
const plaintext = addPadding(_plaintext, blockSize)
const blockCount = (plaintext.length / blockSize) + 1
const totalSize = blockCount * blockSize
const foundBytes = Buffer.alloc(totalSize) // ciphertext bytes
const interBytes = Buffer.alloc(totalSize - blockSize)
const foundOffsets: Set = new Set()
if (lastCiphertextBlock) {
lastCiphertextBlock.copy(foundBytes, foundBytes.length - blockSize)
}
if (['full', 'minimal'].includes(logMode)) logStart({ blockCount, totalSize })
function buildProjection(fields) {
ow(fields, ow.optional.object);
if (fields === undefined) {
return undefined;
}
const projection = {};
function build(rootFields, rootPath) {
// Always include '_type' and '_id'
rootFields = {_type: true, _id: true, ...rootFields};
for (const [name, fields] of Object.entries(rootFields)) {
const path = [...rootPath, name];
if (typeof fields === 'object') {
build(fields, path);
} else if (fields) {
export const saveGIF = async (frames, filename, opts) => {
ow(frames, ow.array.label('frames'))
ow(filename, ow.string.label('filename').nonEmpty)
ow(opts, ow.object.label('opts').plain.nonEmpty)
const {
// gif output options
gifski = {
fps: 10,
quality: 80,
fast: false
}
} = opts
const params = [
'-o', filename,
'--fps', gifski.fps,
gifski.fast && '--fast',
'--quality', gifski.quality,
const pictures = async (id: number) => {
try {
ow(id, ow.number.positive);
const { body } = await queue.add(
async () => await api(`/person/${id}/pictures`, {})
);
return body;
} catch (error) {
Logger.error(error);
}
};
ow.optional.object.is(value => {
const predicateEntries = Object.entries(predicateSchema)
for (const [key, predicate] of predicateEntries) {
try {
ow(value[key], predicate)
} catch (error) {
return false
}
}
return true
})
static __extractKey(key) {
ow(key, ow.object);
const names = Object.keys(key);
if (names.length !== 1) {
throw new Error(
`A key must be an object composed of one unique field (key: ${JSON.stringify(key)})`
);
}
const name = names[0];
const isUnique = name === 'id' || this.prototype.$getField(name).$isUnique();
if (!isUnique) {
throw new Error(`A key name must correspond to a unique field (name: '${name}')`);
}
async orderBook(baseCurrency, quoteCurrency) {
ow(baseCurrency, 'baseCurrency', symbolPredicate);
ow(quoteCurrency, 'quoteCurrency', symbolPredicate);
const response = await this.request({
method: 'orderbook',
base: baseCurrency,
rel: quoteCurrency,
});
const formatOrders = orders => orders
.map(order => ({
address: order.address,
depth: order.depth,
price: Number(order.price),
maxVolume: order.maxvolume,
zCredits: order.zcredits,
}));