Socket
Socket
Sign inDemoInstall

@celo/base

Package Overview
Dependencies
Maintainers
8
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@celo/base - npm Package Compare versions

Comparing version 6.0.0 to 6.0.1-beta.0

2

lib/account.d.ts

@@ -18,3 +18,3 @@ /// <reference types="node" />

}
export declare type RandomNumberGenerator = (size: number, callback: (err: Error | null, buf: Buffer) => void) => void;
export type RandomNumberGenerator = (size: number, callback: (err: Error | null, buf: Buffer) => void) => void;
export interface Bip39 {

@@ -21,0 +21,0 @@ mnemonicToSeedSync: (mnemonic: string, password?: string) => Buffer;

@@ -9,3 +9,3 @@ "use strict";

MnemonicStrength[MnemonicStrength["s256_24words"] = 256] = "s256_24words";
})(MnemonicStrength = exports.MnemonicStrength || (exports.MnemonicStrength = {}));
})(MnemonicStrength || (exports.MnemonicStrength = MnemonicStrength = {}));
var MnemonicLanguages;

@@ -22,3 +22,3 @@ (function (MnemonicLanguages) {

MnemonicLanguages[MnemonicLanguages["portuguese"] = 8] = "portuguese";
})(MnemonicLanguages = exports.MnemonicLanguages || (exports.MnemonicLanguages = {}));
})(MnemonicLanguages || (exports.MnemonicLanguages = MnemonicLanguages = {}));
//# sourceMappingURL=account.js.map
/// <reference types="node" />
export declare type Address = string;
export declare type StrongAddress = `0x${string}`;
export type Address = string;
export type StrongAddress = `0x${string}`;
export declare const eqAddress: (a: Address, b: Address) => boolean;
export declare const normalizeAddress: (a: Address) => string;
export declare const isNullAddress: (a: Address) => boolean;
export declare const normalizeAddressWith0x: (a: Address) => string;
export declare const normalizeAddressWith0x: (a: Address) => `0x${string}`;
export declare const trimLeading0x: (input: string) => string;

@@ -9,0 +9,0 @@ export declare const ensureLeading0x: (input: string) => StrongAddress;

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapAddressListDataOnto = exports.mapAddressListOnto = exports.findAddressIndex = exports.NULL_ADDRESS = exports.bufferToHex = exports.hexToBuffer = exports.isHexString = exports.getAddressChunks = exports.ensureLeading0x = exports.trimLeading0x = exports.normalizeAddressWith0x = exports.isNullAddress = exports.normalizeAddress = exports.eqAddress = void 0;
var HEX_REGEX = /^0x[0-9A-F]*$/i;
var eqAddress = function (a, b) { return (0, exports.normalizeAddress)(a) === (0, exports.normalizeAddress)(b); };
const HEX_REGEX = /^0x[0-9A-F]*$/i;
const eqAddress = (a, b) => (0, exports.normalizeAddress)(a) === (0, exports.normalizeAddress)(b);
exports.eqAddress = eqAddress;
var normalizeAddress = function (a) { return (0, exports.trimLeading0x)(a).toLowerCase(); };
const normalizeAddress = (a) => (0, exports.trimLeading0x)(a).toLowerCase();
exports.normalizeAddress = normalizeAddress;
var isNullAddress = function (a) { return (0, exports.normalizeAddress)(a) === (0, exports.normalizeAddress)(exports.NULL_ADDRESS); };
const isNullAddress = (a) => (0, exports.normalizeAddress)(a) === (0, exports.normalizeAddress)(exports.NULL_ADDRESS);
exports.isNullAddress = isNullAddress;
var normalizeAddressWith0x = function (a) { return (0, exports.ensureLeading0x)(a).toLowerCase(); };
const normalizeAddressWith0x = (a) => (0, exports.ensureLeading0x)(a).toLowerCase();
exports.normalizeAddressWith0x = normalizeAddressWith0x;
var trimLeading0x = function (input) { return (input.startsWith('0x') ? input.slice(2) : input); };
const trimLeading0x = (input) => (input.startsWith('0x') ? input.slice(2) : input);
exports.trimLeading0x = trimLeading0x;
var ensureLeading0x = function (input) {
return input.startsWith('0x') ? input : "0x".concat(input);
};
const ensureLeading0x = (input) => input.startsWith('0x') ? input : `0x${input}`;
exports.ensureLeading0x = ensureLeading0x;
// Turns '0xce10ce10ce10ce10ce10ce10ce10ce10ce10ce10'
// into ['ce10','ce10','ce10','ce10','ce10','ce10','ce10','ce10','ce10','ce10']
var getAddressChunks = function (input) {
return (0, exports.trimLeading0x)(input).match(/.{1,4}/g) || [];
};
const getAddressChunks = (input) => (0, exports.trimLeading0x)(input).match(/.{1,4}/g) || [];
exports.getAddressChunks = getAddressChunks;
var isHexString = function (input) { return HEX_REGEX.test(input); };
const isHexString = (input) => HEX_REGEX.test(input);
exports.isHexString = isHexString;
var hexToBuffer = function (input) { return Buffer.from((0, exports.trimLeading0x)(input), 'hex'); };
const hexToBuffer = (input) => Buffer.from((0, exports.trimLeading0x)(input), 'hex');
exports.hexToBuffer = hexToBuffer;
var bufferToHex = function (buf) { return (0, exports.ensureLeading0x)(buf.toString('hex')); };
const bufferToHex = (buf) => (0, exports.ensureLeading0x)(buf.toString('hex'));
exports.bufferToHex = bufferToHex;
exports.NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
var findAddressIndex = function (address, addresses) {
return addresses.findIndex(function (x) { return (0, exports.eqAddress)(x, address); });
};
const findAddressIndex = (address, addresses) => addresses.findIndex((x) => (0, exports.eqAddress)(x, address));
exports.findAddressIndex = findAddressIndex;
// Returns an array of indices mapping the entries of oldAddress[] to newAddress[]
var mapAddressListOnto = function (oldAddress, newAddress) {
var oldAddressIndex = oldAddress.map(function (x, index) { return ({ address: (0, exports.normalizeAddress)(x), index: index }); });
var newAddressIndex = newAddress.map(function (x, index) { return ({ address: (0, exports.normalizeAddress)(x), index: index }); });
oldAddressIndex.sort(function (a, b) { return a.address.localeCompare(b.address); });
newAddressIndex.sort(function (a, b) { return a.address.localeCompare(b.address); });
var res = __spreadArray([], Array(oldAddress.length).fill(-1), true);
for (var i = 0, j = 0; i < oldAddress.length && j < newAddress.length;) {
var cmp = oldAddressIndex[i].address.localeCompare(newAddressIndex[j].address);
const mapAddressListOnto = (oldAddress, newAddress) => {
const oldAddressIndex = oldAddress.map((x, index) => ({ address: (0, exports.normalizeAddress)(x), index }));
const newAddressIndex = newAddress.map((x, index) => ({ address: (0, exports.normalizeAddress)(x), index }));
oldAddressIndex.sort((a, b) => a.address.localeCompare(b.address));
newAddressIndex.sort((a, b) => a.address.localeCompare(b.address));
const res = [...Array(oldAddress.length).fill(-1)];
for (let i = 0, j = 0; i < oldAddress.length && j < newAddress.length;) {
const cmp = oldAddressIndex[i].address.localeCompare(newAddressIndex[j].address);
if (cmp < 0) {

@@ -73,8 +58,8 @@ i++;

function mapAddressListDataOnto(data, oldAddress, newAddress, initialValue) {
var res = __spreadArray([], Array(oldAddress.length).fill(initialValue), true);
const res = [...Array(oldAddress.length).fill(initialValue)];
if (data.length === 0) {
return res;
}
var addressIndexMap = (0, exports.mapAddressListOnto)(oldAddress, newAddress);
for (var i = 0; i < addressIndexMap.length; i++) {
const addressIndexMap = (0, exports.mapAddressListOnto)(oldAddress, newAddress);
for (let i = 0; i < addressIndexMap.length; i++) {
if (addressIndexMap[i] >= 0) {

@@ -81,0 +66,0 @@ res[addressIndexMap[i]] = data[i];

import { Logger } from './logger';
/** Sleep for a number of milliseconds */
export declare function sleep(ms: number): Promise<void>;
declare type InFunction<T extends any[], U> = (...params: T) => Promise<U>;
type InFunction<T extends any[], U> = (...params: T) => Promise<U>;
export declare const retryAsync: <T extends any[], U>(inFunction: InFunction<T, U>, tries: number, params: T, delay?: number, logger?: Logger | null) => Promise<U>;

@@ -6,0 +6,0 @@ export declare const retryAsyncWithBackOff: <T extends any[], U>(inFunction: InFunction<T, U>, tries: number, params: T, delay?: number, factor?: number, logger?: Logger | null) => Promise<U>;

@@ -11,35 +11,8 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.timeout = exports.concurrentValuesMap = exports.concurrentMap = exports.retryAsyncWithBackOffAndTimeout = exports.selectiveRetryAsyncWithBackOff = exports.retryAsyncWithBackOff = exports.retryAsync = exports.sleep = void 0;
var TAG = 'utils/src/async';
const TAG = 'utils/src/async';
/** Sleep for a number of milliseconds */
function sleep(ms) {
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
return new Promise((resolve) => setTimeout(resolve, ms));
}

@@ -49,80 +22,39 @@ exports.sleep = sleep;

// if all the tries fail it raises the last thrown exeption
var retryAsync = function (inFunction, tries, params, delay, logger) {
if (delay === void 0) { delay = 100; }
if (logger === void 0) { logger = null; }
return __awaiter(void 0, void 0, void 0, function () {
var saveError, i, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < tries)) return [3 /*break*/, 7];
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 6]);
return [4 /*yield*/, inFunction.apply(void 0, params)];
case 3:
// it awaits otherwise it'd always do all the retries
return [2 /*return*/, _a.sent()];
case 4:
error_1 = _a.sent();
return [4 /*yield*/, sleep(delay)];
case 5:
_a.sent();
saveError = error_1;
if (logger) {
logger("".concat(TAG, "/@retryAsync, Failed to execute function on try #").concat(i, ":"), error_1);
}
return [3 /*break*/, 6];
case 6:
i++;
return [3 /*break*/, 1];
case 7: throw saveError;
const retryAsync = (inFunction, tries, params, delay = 100, logger = null) => __awaiter(void 0, void 0, void 0, function* () {
let saveError;
for (let i = 0; i < tries; i++) {
try {
// it awaits otherwise it'd always do all the retries
return yield inFunction(...params);
}
catch (error) {
yield sleep(delay);
saveError = error;
if (logger) {
logger(`${TAG}/@retryAsync, Failed to execute function on try #${i}:`, error);
}
});
});
};
}
}
throw saveError;
});
exports.retryAsync = retryAsync;
// Retries an async function when it raises an exeption
// if all the tries fail it raises the last thrown exeption
var retryAsyncWithBackOff = function (inFunction, tries, params, delay, factor, logger) {
if (delay === void 0) { delay = 100; }
if (factor === void 0) { factor = 1.5; }
if (logger === void 0) { logger = null; }
return __awaiter(void 0, void 0, void 0, function () {
var saveError, i, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < tries)) return [3 /*break*/, 7];
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 6]);
return [4 /*yield*/, inFunction.apply(void 0, params)];
case 3:
// it awaits otherwise it'd always do all the retries
return [2 /*return*/, _a.sent()];
case 4:
error_2 = _a.sent();
return [4 /*yield*/, sleep(Math.pow(factor, i) * delay)];
case 5:
_a.sent();
saveError = error_2;
if (logger) {
logger("".concat(TAG, "/@retryAsync, Failed to execute function on try #").concat(i), error_2);
}
return [3 /*break*/, 6];
case 6:
i++;
return [3 /*break*/, 1];
case 7: throw saveError;
const retryAsyncWithBackOff = (inFunction, tries, params, delay = 100, factor = 1.5, logger = null) => __awaiter(void 0, void 0, void 0, function* () {
let saveError;
for (let i = 0; i < tries; i++) {
try {
// it awaits otherwise it'd always do all the retries
return yield inFunction(...params);
}
catch (error) {
yield sleep(Math.pow(factor, i) * delay);
saveError = error;
if (logger) {
logger(`${TAG}/@retryAsync, Failed to execute function on try #${i}`, error);
}
});
});
};
}
}
throw saveError;
});
exports.retryAsyncWithBackOff = retryAsyncWithBackOff;

@@ -132,46 +64,24 @@ // Retries an async function when it raises an exeption

// throws automatically on specified errors
var selectiveRetryAsyncWithBackOff = function (inFunction, tries, dontRetry, params, delay, factor, logger) {
if (delay === void 0) { delay = 100; }
if (factor === void 0) { factor = 1.5; }
if (logger === void 0) { logger = null; }
return __awaiter(void 0, void 0, void 0, function () {
var saveError, i, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < tries)) return [3 /*break*/, 8];
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
return [4 /*yield*/, inFunction.apply(void 0, params)];
case 3:
// it awaits otherwise it'd always do all the retries
return [2 /*return*/, _a.sent()];
case 4:
error_3 = _a.sent();
if (dontRetry.some(function (msg) { return error_3.message.includes(msg); })) {
throw error_3;
}
saveError = error_3;
if (logger) {
logger("".concat(TAG, "/@retryAsync, Failed to execute function on try #").concat(i), error_3);
}
return [3 /*break*/, 5];
case 5:
if (!(i < tries - 1)) return [3 /*break*/, 7];
return [4 /*yield*/, sleep(Math.pow(factor, i) * delay)];
case 6:
_a.sent();
_a.label = 7;
case 7:
i++;
return [3 /*break*/, 1];
case 8: throw saveError;
const selectiveRetryAsyncWithBackOff = (inFunction, tries, dontRetry, params, delay = 100, factor = 1.5, logger = null) => __awaiter(void 0, void 0, void 0, function* () {
let saveError;
for (let i = 0; i < tries; i++) {
try {
// it awaits otherwise it'd always do all the retries
return yield inFunction(...params);
}
catch (error) {
if (dontRetry.some((msg) => error.message.includes(msg))) {
throw error;
}
});
});
};
saveError = error;
if (logger) {
logger(`${TAG}/@retryAsync, Failed to execute function on try #${i}`, error);
}
}
if (i < tries - 1) {
yield sleep(Math.pow(factor, i) * delay);
}
}
throw saveError;
});
exports.selectiveRetryAsyncWithBackOff = selectiveRetryAsyncWithBackOff;

@@ -181,13 +91,5 @@ // Retries an async function when it raises an exeption

// if all the tries fail it raises the last thrown exeption
var retryAsyncWithBackOffAndTimeout = function (inFunction, tries, params, delayMs, factor, timeoutMs, logger) {
if (delayMs === void 0) { delayMs = 100; }
if (factor === void 0) { factor = 1.5; }
if (timeoutMs === void 0) { timeoutMs = 2000; }
if (logger === void 0) { logger = null; }
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, exports.timeout)(exports.retryAsyncWithBackOff, [inFunction, tries, params, delayMs, factor, logger], timeoutMs, new Error("Timed out after ".concat(timeoutMs, "ms")), "".concat(TAG, "/@retryAsyncWithBackOffAndTimeout, Timed out after ").concat(timeoutMs, "ms"), logger)];
});
});
};
const retryAsyncWithBackOffAndTimeout = (inFunction, tries, params, delayMs = 100, factor = 1.5, timeoutMs = 2000, logger = null) => __awaiter(void 0, void 0, void 0, function* () {
return (0, exports.timeout)(exports.retryAsyncWithBackOff, [inFunction, tries, params, delayMs, factor, logger], timeoutMs, new Error(`Timed out after ${timeoutMs}ms`), `${TAG}/@retryAsyncWithBackOffAndTimeout, Timed out after ${timeoutMs}ms`, logger);
});
exports.retryAsyncWithBackOffAndTimeout = retryAsyncWithBackOffAndTimeout;

@@ -202,38 +104,11 @@ /**

function concurrentMap(concurrency, xs, mapFn) {
return __awaiter(this, void 0, void 0, function () {
var res, _loop_1, i;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
res = [];
_loop_1 = function (i) {
var remaining, sliceSize, slice, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
remaining = xs.length - i;
sliceSize = Math.min(remaining, concurrency);
slice = xs.slice(i, i + sliceSize);
_c = (_b = res).concat;
return [4 /*yield*/, Promise.all(slice.map(function (elem, index) { return mapFn(elem, i + index); }))];
case 1:
res = _c.apply(_b, [_d.sent()]);
return [2 /*return*/];
}
});
};
i = 0;
_a.label = 1;
case 1:
if (!(i < xs.length)) return [3 /*break*/, 4];
return [5 /*yield**/, _loop_1(i)];
case 2:
_a.sent();
_a.label = 3;
case 3:
i += concurrency;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, res];
}
});
return __awaiter(this, void 0, void 0, function* () {
let res = [];
for (let i = 0; i < xs.length; i += concurrency) {
const remaining = xs.length - i;
const sliceSize = Math.min(remaining, concurrency);
const slice = xs.slice(i, i + sliceSize);
res = res.concat(yield Promise.all(slice.map((elem, index) => mapFn(elem, i + index))));
}
return res;
});

@@ -250,19 +125,11 @@ }

function concurrentValuesMap(concurrency, x, mapFn) {
return __awaiter(this, void 0, void 0, function () {
var xk, xv, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
xk = Object.keys(x);
xv = [];
xk.forEach(function (k) { return xv.push(x[k]); });
return [4 /*yield*/, concurrentMap(concurrency, xv, function (val, idx) { return mapFn(val, xk[idx]); })];
case 1:
res = _a.sent();
return [2 /*return*/, res.reduce(function (output, value, index) {
output[xk[index]] = value;
return output;
}, {})];
}
});
return __awaiter(this, void 0, void 0, function* () {
const xk = Object.keys(x);
const xv = [];
xk.forEach((k) => xv.push(x[k]));
const res = yield concurrentMap(concurrency, xv, (val, idx) => mapFn(val, xk[idx]));
return res.reduce((output, value, index) => {
output[xk[index]] = value;
return output;
}, {});
});

@@ -279,12 +146,10 @@ }

*/
var timeout = function (inFunction, params, timeoutMs, timeoutError, timeoutLogMsg, logger) {
if (timeoutLogMsg === void 0) { timeoutLogMsg = null; }
if (logger === void 0) { logger = null; }
var timer;
const timeout = (inFunction, params, timeoutMs, timeoutError, timeoutLogMsg = null, logger = null) => {
let timer;
return Promise.race([
inFunction.apply(void 0, params),
new Promise(function (_resolve, reject) {
timer = setTimeout(function () {
inFunction(...params),
new Promise((_resolve, reject) => {
timer = setTimeout(() => {
if (logger) {
logger(timeoutLogMsg || "".concat(TAG, "/@timeout Timed out after ").concat(timeoutMs, "ms"));
logger(timeoutLogMsg || `${TAG}/@timeout Timed out after ${timeoutMs}ms`);
}

@@ -294,3 +159,3 @@ reject(timeoutError);

}),
]).finally(function () {
]).finally(() => {
clearTimeout(timer);

@@ -297,0 +162,0 @@ });

@@ -6,3 +6,3 @@ export declare function zip<A, B, C>(fn: (a: A, b: B) => C, as: A[], bs: B[]): C[];

export declare function intersection<T>(arrays: T[][]): T[];
export declare type Comparator<T> = (a: T, b: T) => boolean;
export type Comparator<T> = (a: T, b: T) => boolean;
export interface AddressListItem<T> {

@@ -12,11 +12,11 @@ address: string;

}
export declare function linkedListChange<T>(sortedList: Array<AddressListItem<T>>, change: AddressListItem<T>, comparator: Comparator<T>): {
export declare function linkedListChange<T>(sortedList: AddressListItem<T>[], change: AddressListItem<T>, comparator: Comparator<T>): {
lesser: string;
greater: string;
list: Array<AddressListItem<T>>;
list: AddressListItem<T>[];
};
export declare function linkedListChanges<T>(sortedList: Array<AddressListItem<T>>, changeList: Array<AddressListItem<T>>, comparator: Comparator<T>): {
export declare function linkedListChanges<T>(sortedList: AddressListItem<T>[], changeList: AddressListItem<T>[], comparator: Comparator<T>): {
lessers: string[];
greaters: string[];
list: Array<AddressListItem<T>>;
list: AddressListItem<T>[];
};
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.linkedListChanges = exports.linkedListChange = exports.intersection = exports.notEmpty = exports.zeroRange = exports.zip3 = exports.zip = void 0;
var address_1 = require("./address");
const address_1 = require("./address");
function zip(fn, as, bs) {
var len = Math.min(as.length, bs.length);
var res = [];
for (var i = 0; i < len; i++) {
const len = Math.min(as.length, bs.length);
const res = [];
for (let i = 0; i < len; i++) {
res.push(fn(as[i], bs[i]));

@@ -24,5 +15,5 @@ }

function zip3(as, bs, cs) {
var len = Math.min(as.length, bs.length, cs.length);
var res = [];
for (var i = 0; i < len; i++) {
const len = Math.min(as.length, bs.length, cs.length);
const res = [];
for (let i = 0; i < len; i++) {
res.push([as[i], bs[i], cs[i]]);

@@ -46,12 +37,8 @@ }

}
var sets = arrays.map(function (array) { return new Set(array); });
var res = [];
var _loop_1 = function (elem) {
if (sets.every(function (set) { return set.has(elem); })) {
const sets = arrays.map((array) => new Set(array));
const res = [];
for (const elem of arrays[0]) {
if (sets.every((set) => set.has(elem))) {
res.push(elem);
}
};
for (var _i = 0, _a = arrays[0]; _i < _a.length; _i++) {
var elem = _a[_i];
_loop_1(elem);
}

@@ -62,3 +49,3 @@ return res;

function upsert(sortedList, change, comparator) {
var oldIdx = sortedList.findIndex(function (a) { return (0, address_1.eqAddress)(a.address, change.address); });
const oldIdx = sortedList.findIndex((a) => (0, address_1.eqAddress)(a.address, change.address));
if (oldIdx === -1) {

@@ -68,3 +55,3 @@ throw new Error('');

sortedList.splice(oldIdx, 1);
var newIdx = sortedList.findIndex(function (a) { return comparator(a.value, change.value); });
const newIdx = sortedList.findIndex((a) => comparator(a.value, change.value));
if (newIdx === -1) {

@@ -81,26 +68,25 @@ sortedList.push(change);

function _linkedListChange(sortedList, change, comparator) {
var idx = upsert(sortedList, change, comparator);
var greater = idx === 0 ? address_1.NULL_ADDRESS : sortedList[idx - 1].address;
var lesser = idx === sortedList.length - 1 ? address_1.NULL_ADDRESS : sortedList[idx + 1].address;
return { lesser: lesser, greater: greater };
const idx = upsert(sortedList, change, comparator);
const greater = idx === 0 ? address_1.NULL_ADDRESS : sortedList[idx - 1].address;
const lesser = idx === sortedList.length - 1 ? address_1.NULL_ADDRESS : sortedList[idx + 1].address;
return { lesser, greater };
}
function linkedListChange(sortedList, change, comparator) {
var list = sortedList.concat();
var _a = _linkedListChange(list, change, comparator), lesser = _a.lesser, greater = _a.greater;
return { lesser: lesser, greater: greater, list: list };
const list = sortedList.concat();
const { lesser, greater } = _linkedListChange(list, change, comparator);
return { lesser, greater, list };
}
exports.linkedListChange = linkedListChange;
function linkedListChanges(sortedList, changeList, comparator) {
var listClone = __spreadArray([], sortedList, true);
var lessers = [];
var greaters = [];
for (var _i = 0, changeList_1 = changeList; _i < changeList_1.length; _i++) {
var it_1 = changeList_1[_i];
var _a = _linkedListChange(listClone, it_1, comparator), lesser = _a.lesser, greater = _a.greater;
const listClone = [...sortedList];
const lessers = [];
const greaters = [];
for (const it of changeList) {
const { lesser, greater } = _linkedListChange(listClone, it, comparator);
lessers.push(lesser);
greaters.push(greater);
}
return { lessers: lessers, greaters: greaters, list: listClone };
return { lessers, greaters, list: listClone };
}
exports.linkedListChanges = linkedListChanges;
//# sourceMappingURL=collections.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isContact = exports.getContactPhoneNumber = void 0;
var getContactPhoneNumber = function (contact) {
const getContactPhoneNumber = (contact) => {
if (!contact) {

@@ -6,0 +6,0 @@ throw new Error('Invalid contact');

@@ -15,3 +15,3 @@ /** @deprecated use StableToken and Token */

}
export declare type CeloTokenType = StableToken | Token;
export type CeloTokenType = StableToken | Token;
interface Currency {

@@ -22,3 +22,3 @@ symbol: string;

}
declare type CurrencyObject = {
type CurrencyObject = {
[key in CURRENCY_ENUM]: Currency;

@@ -25,0 +25,0 @@ };

"use strict";
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,3 +10,3 @@ exports.currencyToShortMap = exports.SHORT_CURRENCIES = exports.resolveCurrency = exports.CURRENCIES = exports.Token = exports.StableToken = exports.CURRENCY_ENUM = void 0;

CURRENCY_ENUM["EURO"] = "Celo Euro";
})(CURRENCY_ENUM = exports.CURRENCY_ENUM || (exports.CURRENCY_ENUM = {}));
})(CURRENCY_ENUM || (exports.CURRENCY_ENUM = CURRENCY_ENUM = {}));
var StableToken;

@@ -18,10 +17,10 @@ (function (StableToken) {

StableToken["cREAL"] = "cREAL";
})(StableToken = exports.StableToken || (exports.StableToken = {}));
})(StableToken || (exports.StableToken = StableToken = {}));
var Token;
(function (Token) {
Token["CELO"] = "CELO";
})(Token = exports.Token || (exports.Token = {}));
})(Token || (exports.Token = Token = {}));
/** @deprecated */
exports.CURRENCIES = (_a = {},
_a[CURRENCY_ENUM.GOLD] = {
exports.CURRENCIES = {
[CURRENCY_ENUM.GOLD]: {
symbol: '',

@@ -31,3 +30,3 @@ code: 'cGLD',

},
_a[CURRENCY_ENUM.DOLLAR] = {
[CURRENCY_ENUM.DOLLAR]: {
symbol: '$',

@@ -37,3 +36,3 @@ code: 'cUSD',

},
_a[CURRENCY_ENUM.EURO] = {
[CURRENCY_ENUM.EURO]: {
symbol: '€',

@@ -43,4 +42,4 @@ code: 'cEUR',

},
_a);
var resolveCurrency = function (label) {
};
const resolveCurrency = (label) => {
if (label && label.toLowerCase().includes('dollar')) {

@@ -67,9 +66,9 @@ return CURRENCY_ENUM.DOLLAR;

SHORT_CURRENCIES["EURO"] = "euro";
})(SHORT_CURRENCIES = exports.SHORT_CURRENCIES || (exports.SHORT_CURRENCIES = {}));
})(SHORT_CURRENCIES || (exports.SHORT_CURRENCIES = SHORT_CURRENCIES = {}));
/** @deprecated use StableToken and Token */
exports.currencyToShortMap = (_b = {},
_b[CURRENCY_ENUM.DOLLAR] = SHORT_CURRENCIES.DOLLAR,
_b[CURRENCY_ENUM.GOLD] = SHORT_CURRENCIES.GOLD,
_b[CURRENCY_ENUM.EURO] = SHORT_CURRENCIES.EURO,
_b);
exports.currencyToShortMap = {
[CURRENCY_ENUM.DOLLAR]: SHORT_CURRENCIES.DOLLAR,
[CURRENCY_ENUM.GOLD]: SHORT_CURRENCIES.GOLD,
[CURRENCY_ENUM.EURO]: SHORT_CURRENCIES.EURO,
};
//# sourceMappingURL=currencies.js.map

@@ -8,3 +8,3 @@ "use strict";

// by Error: multiple times
var errorMsg = error.message || error.name || 'unknown';
let errorMsg = error.message || error.name || 'unknown';
errorMsg = errorMsg.replace(/Error:/g, '');

@@ -11,0 +11,0 @@ if (error.stack) {

@@ -6,48 +6,38 @@ "use strict";

/** @internal */
var Future = /** @class */ (function () {
function Future() {
var _this = this;
class Future {
constructor() {
this._finished = false;
this._error = null;
this.promise = new Promise(function (resolve, reject) {
_this._resolve = resolve;
_this._reject = reject;
this.promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
}
Object.defineProperty(Future.prototype, "finished", {
get: function () {
return this._finished;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Future.prototype, "error", {
get: function () {
return this._error;
},
enumerable: false,
configurable: true
});
Future.prototype.resolve = function (value) {
get finished() {
return this._finished;
}
get error() {
return this._error;
}
resolve(value) {
this._finished = true;
this._error = null;
this._resolve(value);
};
Future.prototype.reject = function (error) {
}
reject(error) {
this._finished = true;
this._error = error;
this._reject(error);
};
Future.prototype.wait = function () {
}
wait() {
return this.promise;
};
Future.prototype.asPromise = function () {
}
asPromise() {
return this.promise;
};
return Future;
}());
}
}
exports.Future = Future;
/** @internal */
function toFuture(p) {
var future = new Future();
const future = new Future();
return pipeToFuture(p, future);

@@ -54,0 +44,0 @@ }

@@ -10,3 +10,3 @@ "use strict";

ValidatorKind["Phone"] = "phone";
})(ValidatorKind = exports.ValidatorKind || (exports.ValidatorKind = {}));
})(ValidatorKind || (exports.ValidatorKind = ValidatorKind = {}));
function validateInteger(input) {

@@ -16,6 +16,5 @@ return input.replace(/[^0-9]/g, '');

exports.validateInteger = validateInteger;
function validateDecimal(input, decimalSeparator) {
if (decimalSeparator === void 0) { decimalSeparator = '.'; }
var regex = decimalSeparator === ',' ? /[^0-9,]/g : /[^0-9.]/g;
var cleanedArray = input.replace(regex, '').split(decimalSeparator);
function validateDecimal(input, decimalSeparator = '.') {
const regex = decimalSeparator === ',' ? /[^0-9,]/g : /[^0-9.]/g;
const cleanedArray = input.replace(regex, '').split(decimalSeparator);
if (cleanedArray.length <= 1) {

@@ -22,0 +21,0 @@ // Empty string or no decimals

@@ -7,4 +7,4 @@ "use strict";

/** @internal */
var isValidUrl = function (url) { return exports.URL_REGEX.test(url); };
const isValidUrl = (url) => exports.URL_REGEX.test(url);
exports.isValidUrl = isValidUrl;
//# sourceMappingURL=io.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lock = void 0;
var events_1 = require("events");
const events_1 = require("events");
var LockEvent;

@@ -12,4 +12,4 @@ (function (LockEvent) {

// This lock is non-reentrant, and attempting to acquire it while holding the lock will result in a deadlock.
var Lock = /** @class */ (function () {
function Lock() {
class Lock {
constructor() {
this.locked = false;

@@ -20,3 +20,3 @@ this.emitter = new events_1.EventEmitter();

// @returns {boolean} True if the lock was acquired.
Lock.prototype.tryAcquire = function () {
tryAcquire() {
if (!this.locked) {

@@ -27,9 +27,8 @@ this.locked = true;

return false;
};
}
// Acquire the lock, blocking until the lock is available.
Lock.prototype.acquire = function () {
var _this = this;
return new Promise(function (resolve, reject) {
acquire() {
return new Promise((resolve, reject) => {
// Attempt to grab the lock without waiting.
if (_this.tryAcquire()) {
if (this.tryAcquire()) {
resolve();

@@ -39,6 +38,6 @@ return;

// Wait for an event emitted when releasing the lock.
var callback = function () {
const callback = () => {
try {
if (_this.tryAcquire()) {
_this.emitter.removeListener(LockEvent.Unlock, callback);
if (this.tryAcquire()) {
this.emitter.removeListener(LockEvent.Unlock, callback);
resolve();

@@ -51,8 +50,8 @@ }

};
_this.emitter.on(LockEvent.Unlock, callback);
this.emitter.on(LockEvent.Unlock, callback);
});
};
}
// Release the lock such that another caller can acquire it.
// If not locked, calling this method has no effect.
Lock.prototype.release = function () {
release() {
if (this.locked) {

@@ -62,6 +61,5 @@ this.locked = false;

}
};
return Lock;
}());
}
}
exports.Lock = Lock;
//# sourceMappingURL=lock.js.map

@@ -1,2 +0,2 @@

export declare type Logger = (...args: any[]) => void;
export type Logger = (...args: any[]) => void;
/** @internal */

@@ -3,0 +3,0 @@ export declare const noopLogger: Logger;

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.consoleLogger = exports.prefixLogger = exports.noopLogger = void 0;
/** @internal */
var noopLogger = function () {
/*noop*/
const noopLogger = () => {
/* noop*/
};
exports.noopLogger = noopLogger;
/** @internal */
var prefixLogger = function (prefix, logger) {
if (logger === exports.noopLogger) {
return exports.noopLogger;
}
else {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return logger.apply(void 0, __spreadArray(["".concat(prefix, ":: ")], args, false));
};
}
const prefixLogger = (prefix, logger) => {
return logger === exports.noopLogger ? exports.noopLogger : (...args) => logger(`${prefix}:: `, ...args);
};

@@ -33,0 +13,0 @@ exports.prefixLogger = prefixLogger;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseSolidityStringArray = exports.stringToBoolean = void 0;
var stringToBoolean = function (inputString) {
var lowercasedInput = inputString.toLowerCase().trim();
const stringToBoolean = (inputString) => {
const lowercasedInput = inputString.toLowerCase().trim();
if (lowercasedInput === 'true') {

@@ -12,3 +12,3 @@ return true;

}
throw new Error("Unable to parse '".concat(inputString, "' as boolean"));
throw new Error(`Unable to parse '${inputString}' as boolean`);
};

@@ -22,13 +22,13 @@ exports.stringToBoolean = stringToBoolean;

*/
var parseSolidityStringArray = function (stringLengths, data) {
const parseSolidityStringArray = (stringLengths, data) => {
if (data === null) {
data = '0x';
}
var ret = [];
var offset = 0;
const ret = [];
let offset = 0;
// @ts-ignore
var rawData = Buffer.from(data.slice(2), 'hex');
// tslint:disable-next-line:prefer-for-of
for (var i = 0; i < stringLengths.length; i++) {
var string = rawData.toString('utf-8', offset, offset + stringLengths[i]);
const rawData = Buffer.from(data.slice(2), 'hex');
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < stringLengths.length; i++) {
const string = rawData.toString('utf-8', offset, offset + stringLengths[i]);
offset += stringLengths[i];

@@ -35,0 +35,0 @@ ret.push(string);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PhoneNumberBase = exports.anonymizedPhone = exports.isE164Number = void 0;
var E164_REGEX = /^\+[1-9][0-9]{1,14}$/;
const E164_REGEX = /^\+[1-9][0-9]{1,14}$/;
function isE164Number(phoneNumber) {

@@ -14,4 +14,4 @@ return E164_REGEX.test(phoneNumber);

exports.PhoneNumberBase = {
isE164Number: isE164Number,
isE164Number,
};
//# sourceMappingURL=phoneNumbers.js.map

@@ -9,3 +9,3 @@ export interface OkResult<TResult> {

}
export declare type Result<TResult, TError extends Error> = OkResult<TResult> | ErrorResult<TError>;
export type Result<TResult, TError extends Error> = OkResult<TResult> | ErrorResult<TError>;
export declare const Ok: <TResult>(result: TResult) => OkResult<TResult>;

@@ -12,0 +12,0 @@ export declare const Err: <TError extends Error>(error: TError) => ErrorResult<TError>;

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -26,40 +11,13 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isErr = exports.isOk = exports.parseJsonAsResult = exports.JSONParseError = exports.JSONParseErrorType = exports.RootError = exports.makeAsyncThrowable = exports.makeThrowable = exports.throwIfError = exports.Err = exports.Ok = void 0;
var Ok = function (result) { return ({
const Ok = (result) => ({
ok: true,
result: result,
}); };
result,
});
exports.Ok = Ok;
var Err = function (error) { return ({
const Err = (error) => ({
ok: false,
error: error,
}); };
error,
});
exports.Err = Err;

@@ -77,58 +35,31 @@ function throwIfError(result, errorModifier) {

function makeThrowable(f, errorModifier) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return throwIfError(f.apply(void 0, args), errorModifier);
};
return (...args) => throwIfError(f(...args), errorModifier);
}
exports.makeThrowable = makeThrowable;
function makeAsyncThrowable(f, errorModifier) {
var _this = this;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return __awaiter(_this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, f.apply(void 0, args)];
case 1:
result = _a.sent();
return [2 /*return*/, throwIfError(result, errorModifier)];
}
});
});
};
return (...args) => __awaiter(this, void 0, void 0, function* () {
const result = yield f(...args);
return throwIfError(result, errorModifier);
});
}
exports.makeAsyncThrowable = makeAsyncThrowable;
var RootError = /** @class */ (function (_super) {
__extends(RootError, _super);
function RootError(errorType) {
var _this = _super.call(this) || this;
_this.errorType = errorType;
class RootError extends Error {
constructor(errorType) {
super();
this.errorType = errorType;
// @ts-ignore
if (errorType.toString) {
// @ts-ignore
_this.name = errorType.toString();
this.name = errorType.toString();
}
return _this;
}
return RootError;
}(Error));
}
exports.RootError = RootError;
exports.JSONParseErrorType = 'JsonParseError';
// tslint:disable-next-line:max-classes-per-file
var JSONParseError = /** @class */ (function (_super) {
__extends(JSONParseError, _super);
function JSONParseError(error) {
var _this = _super.call(this, exports.JSONParseErrorType) || this;
_this.error = error;
return _this;
class JSONParseError extends RootError {
constructor(error) {
super(exports.JSONParseErrorType);
this.error = error;
}
return JSONParseError;
}(RootError));
}
exports.JSONParseError = JSONParseError;

@@ -135,0 +66,0 @@ function parseJsonAsResult(data) {

@@ -11,29 +11,2 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -44,9 +17,6 @@ exports.SignatureBase = exports.serializeSignature = exports.NativeSigner = exports.POP_SIZE = void 0;

function NativeSigner(signFn, signer) {
var _this = this;
return {
sign: function (message) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, signFn(message, signer)];
});
}); },
sign: (message) => __awaiter(this, void 0, void 0, function* () {
return signFn(message, signer);
}),
};

@@ -56,5 +26,5 @@ }

function serializeSignature(signature) {
var serializedV = signature.v.toString(16);
var serializedR = signature.r.slice(2);
var serializedS = signature.s.slice(2);
const serializedV = signature.v.toString(16);
const serializedR = signature.r.slice(2);
const serializedS = signature.s.slice(2);
return '0x' + serializedV + serializedR + serializedS;

@@ -64,5 +34,5 @@ }

exports.SignatureBase = {
NativeSigner: NativeSigner,
serializeSignature: serializeSignature,
NativeSigner,
serializeSignature,
};
//# sourceMappingURL=signatureUtils.js.map

@@ -5,3 +5,3 @@ "use strict";

function appendPath(baseUrl, path) {
var lastChar = baseUrl[baseUrl.length - 1];
const lastChar = baseUrl[baseUrl.length - 1];
if (lastChar === '/') {

@@ -19,5 +19,5 @@ return baseUrl + path;

exports.StringBase = {
appendPath: appendPath,
normalizeAccents: normalizeAccents,
appendPath,
normalizeAccents,
};
//# sourceMappingURL=string.js.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -22,33 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryObtainValueWithRetries = exports.conditionWatcher = exports.repeatTask = void 0;
var future_1 = require("./future");
var logger_1 = require("./logger");
const future_1 = require("./future");
const logger_1 = require("./logger");
/**

@@ -59,9 +21,4 @@ * Given task options, creates the task logger

*/
var createTaskLogger = function (opts) {
if (opts.logger) {
return (0, logger_1.prefixLogger)(opts.name, opts.logger);
}
else {
return logger_1.noopLogger;
}
const createTaskLogger = (opts) => {
return opts.logger ? (0, logger_1.prefixLogger)(opts.name, opts.logger) : logger_1.noopLogger;
};

@@ -74,41 +31,28 @@ /**

function repeatTask(opts, fn) {
var _this = this;
var logger = createTaskLogger(opts);
var isActive = true;
var ctx = {
const logger = createTaskLogger(opts);
let isActive = true;
const ctx = {
executionNumber: 0,
stopTask: function () {
stopTask: () => {
isActive = false;
},
};
var loop = function () { return __awaiter(_this, void 0, void 0, function () {
var err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!isActive) {
return [2 /*return*/];
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, 4, 5]);
ctx.executionNumber++;
return [4 /*yield*/, fn(ctx)];
case 2:
_a.sent();
return [3 /*break*/, 5];
case 3:
err_1 = _a.sent();
logger("Failed with error: ".concat(err_1.message));
logger(err_1);
return [3 /*break*/, 5];
case 4:
if (isActive) {
setTimeout(loop, opts.timeInBetweenMS);
}
return [7 /*endfinally*/];
case 5: return [2 /*return*/];
const loop = () => __awaiter(this, void 0, void 0, function* () {
if (!isActive) {
return;
}
try {
ctx.executionNumber++;
yield fn(ctx);
}
catch (err) {
logger(`Failed with error: ${err.message}`);
logger(err);
}
finally {
if (isActive) {
setTimeout(loop, opts.timeInBetweenMS);
}
});
}); };
}
});
if (opts.initialDelayMS != null) {

@@ -118,10 +62,7 @@ setTimeout(loop, opts.initialDelayMS);

else {
// tslint:disable-next-line: no-floating-promises
loop();
void loop();
}
return {
stop: ctx.stopTask,
isRunning: function () {
return isActive;
},
isRunning: () => isActive,
};

@@ -131,52 +72,32 @@ }

function conditionWatcher(opts) {
var _this = this;
return repeatTask(opts, function (ctx) { return __awaiter(_this, void 0, void 0, function () {
var val;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, opts.pollCondition()];
case 1:
val = _a.sent();
if (!val) return [3 /*break*/, 3];
ctx.stopTask();
return [4 /*yield*/, opts.onSuccess()];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
}); });
return repeatTask(opts, (ctx) => __awaiter(this, void 0, void 0, function* () {
const val = yield opts.pollCondition();
if (val) {
ctx.stopTask();
yield opts.onSuccess();
}
}));
}
exports.conditionWatcher = conditionWatcher;
function tryObtainValueWithRetries(opts) {
var _this = this;
var futureValue = new future_1.Future();
var task = repeatTask(opts, function (ctx) { return __awaiter(_this, void 0, void 0, function () {
var val;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(ctx.executionNumber > opts.maxAttemps)) return [3 /*break*/, 1];
ctx.stopTask();
futureValue.reject(new Error('Max Retries & no value'));
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, opts.tryGetValue()];
case 2:
val = _a.sent();
if (val != null) {
futureValue.resolve(val);
ctx.stopTask();
}
_a.label = 3;
case 3: return [2 /*return*/];
const futureValue = new future_1.Future();
const task = repeatTask(opts, (ctx) => __awaiter(this, void 0, void 0, function* () {
if (ctx.executionNumber > opts.maxAttemps) {
ctx.stopTask();
futureValue.reject(new Error('Max Retries & no value'));
}
else {
const val = yield opts.tryGetValue();
if (val != null) {
futureValue.resolve(val);
ctx.stopTask();
}
});
}); });
return __assign(__assign({}, task), { stop: function () {
}
}));
return Object.assign(Object.assign({}, task), { stop: () => {
task.stop();
futureValue.reject(new Error('Cancelled'));
}, onValue: function () { return futureValue.asPromise(); } });
}, onValue: () => futureValue.asPromise() });
}
exports.tryObtainValueWithRetries = tryObtainValueWithRetries;
//# sourceMappingURL=task.js.map
{
"name": "@celo/base",
"version": "6.0.0",
"version": "6.0.1-beta.0",
"description": "Celo base common utils, no dependencies",

@@ -11,11 +11,11 @@ "author": "Celo",

"homepage": "https://celo-sdk-docs.readthedocs.io/en/latest/base",
"repository": "https://github.com/celo-org/celo-monorepo/tree/master/packages/sdk/base",
"repository": "https://github.com/celo-org/developer-tooling/tree/master/packages/sdk/base",
"scripts": {
"prepublishOnly": "yarn build",
"build": "tsc -b .",
"clean": "tsc -b . --clean",
"docs": "typedoc",
"test": "jest --runInBand --ci",
"test:verbose": "jest --verbose",
"lint": "tslint -c tslint.json --project ."
"build": "yarn run --top-level tsc -b .",
"clean": "yarn run --top-level tsc -b . --clean",
"docs": "yarn run --top-level typedoc",
"test": "yarn run --top-level jest --runInBand --ci",
"test:verbose": "yarn run --top-level jest --verbose",
"lint": "yarn run --top-level eslint -c .eslintrc.js "
},

@@ -25,3 +25,2 @@ "files": [

],
"dependencies": {},
"devDependencies": {

@@ -31,4 +30,4 @@ "@celo/typescript": "0.0.1",

"elliptic": "^6.5.4",
"web3-utils": "1.10.0"
"web3-utils": "1.10.4"
}
}
}

@@ -6,3 +6,22 @@

## How we work
We are a GitHub-first team, which means we have a strong preference for communicating via GitHub.
Please use GitHub to:
🐞 [File a bug report](https://github.com/celo-org/developer-tooling/issues/new/choose)
💬 [Ask a question](https://github.com/celo-org/developer-tooling/discussions)
✨ [Suggest a feature](httpsi//github.com/celo-org/developer-tooling/issues/new/choose)
🧑‍💻 [Contribute!](/CONTRIBUTING.md)
🚔 [Report a security vulnerability](https://github.com/celo-org/developer-tooling/issues/new/choose)
> [!TIP]
>
> Please avoid messaging us via Slack, Telegram, or email. We are more likely to respond to you on
> GitHub than if you message us anywhere else. We actively monitor GitHub, and will get back to you shortly 🌟
## Notable Types

@@ -9,0 +28,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc