@prosopo/account 0.3.42 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/dist/error.cjs +3 -3
- package/dist/cjs/common/dist/locales/en.json.cjs +2 -1
- package/dist/cjs/util/dist/at.cjs +22 -0
- package/dist/cjs/util/dist/canvas.cjs +41 -41
- package/dist/cjs/util/dist/checks.cjs +10 -0
- package/dist/cjs/util/dist/choice.cjs +19 -0
- package/dist/cjs/util/dist/get.cjs +10 -0
- package/dist/cjs/util/dist/hex.cjs +11 -0
- package/dist/cjs/util/dist/index.cjs +16 -8
- package/dist/cjs/util/dist/merge.cjs +58 -0
- package/dist/cjs/util/dist/permutations.cjs +26 -0
- package/dist/cjs/util/dist/util.cjs +4 -143
- package/package.json +8 -8
|
@@ -83,10 +83,10 @@ class ProsopoDatasetError extends ProsopoBaseError {
|
|
|
83
83
|
class ProsopoApiError extends ProsopoBaseError {
|
|
84
84
|
constructor(error, options) {
|
|
85
85
|
const errorName = options?.name || "ProsopoApiError";
|
|
86
|
-
const
|
|
87
|
-
options = { ...options, name: errorName, context: { ...options?.context,
|
|
86
|
+
const code = options?.context?.code || 500;
|
|
87
|
+
options = { ...options, name: errorName, context: { ...options?.context, code } };
|
|
88
88
|
super(error, options);
|
|
89
|
-
this.code =
|
|
89
|
+
this.code = code;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
exports.ProsopoApiError = ProsopoApiError;
|
|
@@ -118,7 +118,8 @@ const CAPTCHA = {
|
|
|
118
118
|
INVALID_DATASET_CONTENT_ID: "Invalid dataset content id",
|
|
119
119
|
DAPP_USER_SOLUTION_NOT_FOUND: "Dapp user solution not found",
|
|
120
120
|
INVALID_PROVIDER_URL: "Invalid provider url",
|
|
121
|
-
NO_CAPTCHA: "No captcha found"
|
|
121
|
+
NO_CAPTCHA: "No captcha found",
|
|
122
|
+
INVALID_TOKEN: "Invalid token"
|
|
122
123
|
};
|
|
123
124
|
const API = {
|
|
124
125
|
BODY_UNDEFINED: "Body must be defined in API POST call",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function at(items, index, options) {
|
|
4
|
+
if (items.length === 0) {
|
|
5
|
+
throw new Error("Array is empty");
|
|
6
|
+
}
|
|
7
|
+
if (!options?.noWrap) {
|
|
8
|
+
if (index > 0) {
|
|
9
|
+
index = index % items.length;
|
|
10
|
+
} else {
|
|
11
|
+
index = Math.ceil(Math.abs(index) / items.length) * items.length + index;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (index >= items.length) {
|
|
15
|
+
throw new Error(`Index ${index} larger than array length ${items.length}`);
|
|
16
|
+
}
|
|
17
|
+
if (index < 0) {
|
|
18
|
+
throw new Error(`Index ${index} smaller than 0`);
|
|
19
|
+
}
|
|
20
|
+
return items[index];
|
|
21
|
+
}
|
|
22
|
+
exports.at = at;
|
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
require("./index.cjs");
|
|
4
|
-
const
|
|
4
|
+
const at = require("./at.cjs");
|
|
5
5
|
function x64Add(m, n) {
|
|
6
|
-
m = [
|
|
7
|
-
n = [
|
|
6
|
+
m = [at.at(m, 0) >>> 16, at.at(m, 0) & 65535, at.at(m, 1) >>> 16, at.at(m, 1) & 65535];
|
|
7
|
+
n = [at.at(n, 0) >>> 16, at.at(n, 0) & 65535, at.at(n, 1) >>> 16, at.at(n, 1) & 65535];
|
|
8
8
|
const o = [0, 0, 0, 0];
|
|
9
|
-
o[3] +=
|
|
10
|
-
o[2] +=
|
|
9
|
+
o[3] += at.at(m, 3) + at.at(n, 3);
|
|
10
|
+
o[2] += at.at(o, 3) >>> 16;
|
|
11
11
|
o[3] &= 65535;
|
|
12
|
-
o[2] +=
|
|
13
|
-
o[1] +=
|
|
12
|
+
o[2] += at.at(m, 2) + at.at(n, 2);
|
|
13
|
+
o[1] += at.at(o, 2) >>> 16;
|
|
14
14
|
o[2] &= 65535;
|
|
15
|
-
o[1] +=
|
|
16
|
-
o[0] +=
|
|
15
|
+
o[1] += at.at(m, 1) + at.at(n, 1);
|
|
16
|
+
o[0] += at.at(o, 1) >>> 16;
|
|
17
17
|
o[1] &= 65535;
|
|
18
|
-
o[0] +=
|
|
18
|
+
o[0] += at.at(m, 0) + at.at(n, 0);
|
|
19
19
|
o[0] &= 65535;
|
|
20
|
-
return [
|
|
20
|
+
return [at.at(o, 0) << 16 | at.at(o, 1), at.at(o, 2) << 16 | at.at(o, 3)];
|
|
21
21
|
}
|
|
22
22
|
function x64Multiply(m, n) {
|
|
23
|
-
m = [
|
|
24
|
-
n = [
|
|
23
|
+
m = [at.at(m, 0) >>> 16, at.at(m, 0) & 65535, at.at(m, 1) >>> 16, at.at(m, 1) & 65535];
|
|
24
|
+
n = [at.at(n, 0) >>> 16, at.at(n, 0) & 65535, at.at(n, 1) >>> 16, at.at(n, 1) & 65535];
|
|
25
25
|
const o = [0, 0, 0, 0];
|
|
26
|
-
o[3] +=
|
|
27
|
-
o[2] +=
|
|
26
|
+
o[3] += at.at(m, 3) * at.at(n, 3);
|
|
27
|
+
o[2] += at.at(o, 3) >>> 16;
|
|
28
28
|
o[3] &= 65535;
|
|
29
|
-
o[2] +=
|
|
30
|
-
o[1] +=
|
|
29
|
+
o[2] += at.at(m, 2) * at.at(n, 3);
|
|
30
|
+
o[1] += at.at(o, 2) >>> 16;
|
|
31
31
|
o[2] &= 65535;
|
|
32
|
-
o[2] +=
|
|
33
|
-
o[1] +=
|
|
32
|
+
o[2] += at.at(m, 3) * at.at(n, 2);
|
|
33
|
+
o[1] += at.at(o, 2) >>> 16;
|
|
34
34
|
o[2] &= 65535;
|
|
35
|
-
o[1] +=
|
|
36
|
-
o[0] +=
|
|
35
|
+
o[1] += at.at(m, 1) * at.at(n, 3);
|
|
36
|
+
o[0] += at.at(o, 1) >>> 16;
|
|
37
37
|
o[1] &= 65535;
|
|
38
|
-
o[1] +=
|
|
39
|
-
o[0] +=
|
|
38
|
+
o[1] += at.at(m, 2) * at.at(n, 2);
|
|
39
|
+
o[0] += at.at(o, 1) >>> 16;
|
|
40
40
|
o[1] &= 65535;
|
|
41
|
-
o[1] +=
|
|
42
|
-
o[0] +=
|
|
41
|
+
o[1] += at.at(m, 3) * at.at(n, 1);
|
|
42
|
+
o[0] += at.at(o, 1) >>> 16;
|
|
43
43
|
o[1] &= 65535;
|
|
44
|
-
o[0] +=
|
|
44
|
+
o[0] += at.at(m, 0) * at.at(n, 3) + at.at(m, 1) * at.at(n, 2) + at.at(m, 2) * at.at(n, 1) + at.at(m, 3) * at.at(n, 0);
|
|
45
45
|
o[0] &= 65535;
|
|
46
|
-
return [
|
|
46
|
+
return [at.at(o, 0) << 16 | at.at(o, 1), at.at(o, 2) << 16 | at.at(o, 3)];
|
|
47
47
|
}
|
|
48
48
|
function x64Rotl(m, n) {
|
|
49
49
|
n %= 64;
|
|
50
50
|
if (n === 32) {
|
|
51
|
-
return [
|
|
51
|
+
return [at.at(m, 1), at.at(m, 0)];
|
|
52
52
|
} else if (n < 32) {
|
|
53
|
-
return [
|
|
53
|
+
return [at.at(m, 0) << n | at.at(m, 1) >>> 32 - n, at.at(m, 1) << n | at.at(m, 0) >>> 32 - n];
|
|
54
54
|
} else {
|
|
55
55
|
n -= 32;
|
|
56
|
-
return [
|
|
56
|
+
return [at.at(m, 1) << n | at.at(m, 0) >>> 32 - n, at.at(m, 0) << n | at.at(m, 1) >>> 32 - n];
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function x64LeftShift(m, n) {
|
|
@@ -61,20 +61,20 @@ function x64LeftShift(m, n) {
|
|
|
61
61
|
if (n === 0) {
|
|
62
62
|
return m;
|
|
63
63
|
} else if (n < 32) {
|
|
64
|
-
return [
|
|
64
|
+
return [at.at(m, 0) << n | at.at(m, 1) >>> 32 - n, at.at(m, 1) << n];
|
|
65
65
|
} else {
|
|
66
|
-
return [
|
|
66
|
+
return [at.at(m, 1) << n - 32, 0];
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
function x64Xor(m, n) {
|
|
70
|
-
return [
|
|
70
|
+
return [at.at(m, 0) ^ at.at(n, 0), at.at(m, 1) ^ at.at(n, 1)];
|
|
71
71
|
}
|
|
72
72
|
function x64Fmix(h) {
|
|
73
|
-
h = x64Xor(h, [0,
|
|
73
|
+
h = x64Xor(h, [0, at.at(h, 0) >>> 1]);
|
|
74
74
|
h = x64Multiply(h, [4283543511, 3981806797]);
|
|
75
|
-
h = x64Xor(h, [0,
|
|
75
|
+
h = x64Xor(h, [0, at.at(h, 0) >>> 1]);
|
|
76
76
|
h = x64Multiply(h, [3301882366, 444984403]);
|
|
77
|
-
h = x64Xor(h, [0,
|
|
77
|
+
h = x64Xor(h, [0, at.at(h, 0) >>> 1]);
|
|
78
78
|
return h;
|
|
79
79
|
}
|
|
80
80
|
function x64hash128(key, seed) {
|
|
@@ -177,7 +177,7 @@ function x64hash128(key, seed) {
|
|
|
177
177
|
h2 = x64Fmix(h2);
|
|
178
178
|
h1 = x64Add(h1, h2);
|
|
179
179
|
h2 = x64Add(h2, h1);
|
|
180
|
-
return ("00000000" + (
|
|
180
|
+
return ("00000000" + (at.at(h1, 0) >>> 0).toString(16)).slice(-8) + ("00000000" + (at.at(h1, 1) >>> 0).toString(16)).slice(-8) + ("00000000" + (at.at(h2, 0) >>> 0).toString(16)).slice(-8) + ("00000000" + (at.at(h2, 1) >>> 0).toString(16)).slice(-8);
|
|
181
181
|
}
|
|
182
182
|
function picassoCanvas(roundNumber, seed, params) {
|
|
183
183
|
const { area, offsetParameter, multiplier, fontSizeFactor, maxShadowBlur } = params;
|
|
@@ -202,8 +202,8 @@ function picassoCanvas(roundNumber, seed, params) {
|
|
|
202
202
|
}
|
|
203
203
|
function addRandomCanvasGradient(prng, context, area2) {
|
|
204
204
|
const canvasGradient = context.createRadialGradient(adaptRandomNumberToContext(prng.getNext(), area2.width, void 0), adaptRandomNumberToContext(prng.getNext(), area2.height, void 0), adaptRandomNumberToContext(prng.getNext(), area2.width, void 0), adaptRandomNumberToContext(prng.getNext(), area2.width, void 0), adaptRandomNumberToContext(prng.getNext(), area2.height, void 0), adaptRandomNumberToContext(prng.getNext(), area2.width, void 0));
|
|
205
|
-
canvasGradient.addColorStop(0,
|
|
206
|
-
canvasGradient.addColorStop(1,
|
|
205
|
+
canvasGradient.addColorStop(0, at.at(colors, adaptRandomNumberToContext(prng.getNext(), colors.length, void 0)));
|
|
206
|
+
canvasGradient.addColorStop(1, at.at(colors, adaptRandomNumberToContext(prng.getNext(), colors.length, void 0)));
|
|
207
207
|
context.fillStyle = canvasGradient;
|
|
208
208
|
}
|
|
209
209
|
function generateRandomWord(prng, wordLength) {
|
|
@@ -312,8 +312,8 @@ function picassoCanvas(roundNumber, seed, params) {
|
|
|
312
312
|
for (let i = 0; i < roundNumber; i++) {
|
|
313
313
|
addRandomCanvasGradient(prng, context, area);
|
|
314
314
|
context.shadowBlur = adaptRandomNumberToContext(prng.getNext(), maxShadowBlur, void 0);
|
|
315
|
-
context.shadowColor =
|
|
316
|
-
const randomPrimitive =
|
|
315
|
+
context.shadowColor = at.at(colors, adaptRandomNumberToContext(prng.getNext(), colors.length, void 0));
|
|
316
|
+
const randomPrimitive = at.at(primitives, adaptRandomNumberToContext(prng.getNext(), primitives.length, void 0));
|
|
317
317
|
randomPrimitive(prng, context, area);
|
|
318
318
|
context.fill();
|
|
319
319
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const isArray = (value) => {
|
|
4
|
+
return Array.isArray(value) && value !== null;
|
|
5
|
+
};
|
|
6
|
+
const isObject = (value) => {
|
|
7
|
+
return value instanceof Object && !isArray(value);
|
|
8
|
+
};
|
|
9
|
+
exports.isArray = isArray;
|
|
10
|
+
exports.isObject = isObject;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function choice(items, n, random, options) {
|
|
4
|
+
if (n > items.length) {
|
|
5
|
+
throw new Error(`Cannot choose ${n} items from array of length ${items.length}`);
|
|
6
|
+
}
|
|
7
|
+
const result = [];
|
|
8
|
+
const indices = [];
|
|
9
|
+
for (let i = 0; i < n; i++) {
|
|
10
|
+
let index;
|
|
11
|
+
do {
|
|
12
|
+
index = Math.floor(Math.abs(random()) * items.length) % items.length;
|
|
13
|
+
} while (options?.withReplacement === false && indices.includes(index));
|
|
14
|
+
indices.push(index);
|
|
15
|
+
result.push(items[index]);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
exports.choice = choice;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function get(obj, key, required = true) {
|
|
4
|
+
const value = obj[key];
|
|
5
|
+
if (required && value === void 0) {
|
|
6
|
+
throw new Error(`Object has no property '${String(key)}': ${JSON.stringify(obj, null, 2)}`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
exports.get = get;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const checks = require("./checks.cjs");
|
|
4
|
+
const util = require("@polkadot/util");
|
|
5
|
+
const hashToHex = (hash) => {
|
|
6
|
+
if (checks.isArray(hash)) {
|
|
7
|
+
return util.u8aToHex(new Uint8Array(hash));
|
|
8
|
+
}
|
|
9
|
+
return hash.toString();
|
|
10
|
+
};
|
|
11
|
+
exports.hashToHex = hashToHex;
|
|
@@ -8,17 +8,17 @@ const canvas = require("./canvas.cjs");
|
|
|
8
8
|
const solverService = require("./solverService.cjs");
|
|
9
9
|
const table = require("./table.cjs");
|
|
10
10
|
const url = require("./url.cjs");
|
|
11
|
+
const at = require("./at.cjs");
|
|
12
|
+
const get = require("./get.cjs");
|
|
13
|
+
const merge = require("./merge.cjs");
|
|
14
|
+
const choice = require("./choice.cjs");
|
|
15
|
+
const permutations = require("./permutations.cjs");
|
|
11
16
|
const version = require("./version.cjs");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.
|
|
17
|
+
const hex = require("./hex.cjs");
|
|
18
|
+
const checks = require("./checks.cjs");
|
|
19
|
+
exports.flatten = util.flatten;
|
|
15
20
|
exports.getCurrentFileDirectory = util.getCurrentFileDirectory;
|
|
16
|
-
exports.hashToHex = util.hashToHex;
|
|
17
|
-
exports.isArray = util.isArray;
|
|
18
|
-
exports.isObject = util.isObject;
|
|
19
21
|
exports.kebabCase = util.kebabCase;
|
|
20
|
-
exports.merge = util.merge;
|
|
21
|
-
exports.permutations = util.permutations;
|
|
22
22
|
exports.sleep = util.sleep;
|
|
23
23
|
exports.ofLen = ofLen.ofLen;
|
|
24
24
|
exports.lodash = lodash.lodash;
|
|
@@ -30,4 +30,12 @@ exports.picassoCanvas = canvas.picassoCanvas;
|
|
|
30
30
|
exports.solvePoW = solverService.solvePoW;
|
|
31
31
|
exports.consoleTableWithWrapping = table.consoleTableWithWrapping;
|
|
32
32
|
exports.getURLProtocol = url.getURLProtocol;
|
|
33
|
+
exports.at = at.at;
|
|
34
|
+
exports.get = get.get;
|
|
35
|
+
exports.merge = merge.merge;
|
|
36
|
+
exports.choice = choice.choice;
|
|
37
|
+
exports.permutations = permutations.permutations;
|
|
33
38
|
exports.version = version.version;
|
|
39
|
+
exports.hashToHex = hex.hashToHex;
|
|
40
|
+
exports.isArray = checks.isArray;
|
|
41
|
+
exports.isObject = checks.isObject;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const checks = require("./checks.cjs");
|
|
4
|
+
function merge(dest, src, options) {
|
|
5
|
+
const atomicArrays = options?.atomicArrays;
|
|
6
|
+
const queue = [
|
|
7
|
+
{
|
|
8
|
+
src,
|
|
9
|
+
dest
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
while (queue.length > 0) {
|
|
13
|
+
const task = queue.pop();
|
|
14
|
+
if (task === void 0) {
|
|
15
|
+
throw new Error("queue is empty");
|
|
16
|
+
}
|
|
17
|
+
if (checks.isArray(task.dest)) {
|
|
18
|
+
const src2 = task.src;
|
|
19
|
+
const dest2 = task.dest;
|
|
20
|
+
if (atomicArrays) {
|
|
21
|
+
while (dest2.length > src2.length) {
|
|
22
|
+
dest2.pop();
|
|
23
|
+
}
|
|
24
|
+
for (let i = 0; i < src2.length; i++) {
|
|
25
|
+
dest2[i] = src2[i];
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
for (let i = 0; i < src2.length; i++) {
|
|
29
|
+
if (checks.isArray(dest2[i]) && checks.isArray(src2[i]) || checks.isObject(dest2[i]) && checks.isObject(src2[i])) {
|
|
30
|
+
queue.push({
|
|
31
|
+
src: src2[i],
|
|
32
|
+
dest: dest2[i]
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
dest2[i] = src2[i];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} else if (checks.isObject(task.dest)) {
|
|
40
|
+
const src2 = task.src;
|
|
41
|
+
const destAny = task.dest;
|
|
42
|
+
for (const [key, value] of Object.entries(src2)) {
|
|
43
|
+
if (checks.isArray(value) && checks.isArray(destAny[key]) || checks.isObject(value) && checks.isObject(destAny[key])) {
|
|
44
|
+
queue.push({
|
|
45
|
+
src: value,
|
|
46
|
+
dest: destAny[key]
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
destAny[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error(`cannot handle type in queue: ${typeof task.dest}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return dest;
|
|
57
|
+
}
|
|
58
|
+
exports.merge = merge;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function* permutations(bins, options) {
|
|
4
|
+
if (options?.includeEmpty) {
|
|
5
|
+
yield [];
|
|
6
|
+
}
|
|
7
|
+
if (bins.length === 0) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const arr = Array.from({ length: bins.length }, () => 0);
|
|
11
|
+
let i = arr.length - 1;
|
|
12
|
+
while (true) {
|
|
13
|
+
yield [...arr];
|
|
14
|
+
arr[i]++;
|
|
15
|
+
while (arr[i] === bins[i]) {
|
|
16
|
+
arr[i] = 0;
|
|
17
|
+
i--;
|
|
18
|
+
if (i < 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
arr[i]++;
|
|
22
|
+
}
|
|
23
|
+
i = arr.length - 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.permutations = permutations;
|
|
@@ -1,161 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const util = require("@polkadot/util");
|
|
4
3
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
-
function* permutations(bins, options) {
|
|
6
|
-
if (options?.includeEmpty) {
|
|
7
|
-
yield [];
|
|
8
|
-
}
|
|
9
|
-
if (bins.length === 0) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const arr = Array.from({ length: bins.length }, () => 0);
|
|
13
|
-
let i = arr.length - 1;
|
|
14
|
-
while (true) {
|
|
15
|
-
yield [...arr];
|
|
16
|
-
arr[i]++;
|
|
17
|
-
while (arr[i] === bins[i]) {
|
|
18
|
-
arr[i] = 0;
|
|
19
|
-
i--;
|
|
20
|
-
if (i < 0) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
arr[i]++;
|
|
24
|
-
}
|
|
25
|
-
i = arr.length - 1;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function get(obj, key, required = true) {
|
|
29
|
-
const value = obj[key];
|
|
30
|
-
if (required && value === void 0) {
|
|
31
|
-
throw new Error(`Object has no property '${String(key)}': ${JSON.stringify(obj, null, 2)}`);
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
function at(items, index, options) {
|
|
36
|
-
if (items.length === 0) {
|
|
37
|
-
throw new Error("Array is empty");
|
|
38
|
-
}
|
|
39
|
-
if (!options?.noWrap) {
|
|
40
|
-
if (index > 0) {
|
|
41
|
-
index = index % items.length;
|
|
42
|
-
} else {
|
|
43
|
-
index = Math.ceil(Math.abs(index) / items.length) * items.length + index;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (index >= items.length) {
|
|
47
|
-
throw new Error(`Index ${index} larger than array length ${items.length}`);
|
|
48
|
-
}
|
|
49
|
-
if (index < 0) {
|
|
50
|
-
throw new Error(`Index ${index} smaller than 0`);
|
|
51
|
-
}
|
|
52
|
-
return items[index];
|
|
53
|
-
}
|
|
54
|
-
function choice(items, n, random, options) {
|
|
55
|
-
if (n > items.length) {
|
|
56
|
-
throw new Error(`Cannot choose ${n} items from array of length ${items.length}`);
|
|
57
|
-
}
|
|
58
|
-
const result = [];
|
|
59
|
-
const indices = [];
|
|
60
|
-
for (let i = 0; i < n; i++) {
|
|
61
|
-
let index;
|
|
62
|
-
do {
|
|
63
|
-
index = Math.floor(Math.abs(random()) * items.length) % items.length;
|
|
64
|
-
} while (options?.withReplacement === false && indices.includes(index));
|
|
65
|
-
indices.push(index);
|
|
66
|
-
result.push(items[index]);
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
4
|
function getCurrentFileDirectory(url) {
|
|
71
5
|
return new URL(url).pathname.split("/").slice(0, -1).join("/");
|
|
72
6
|
}
|
|
73
|
-
const
|
|
7
|
+
const flatten = (obj, prefix = "") => {
|
|
74
8
|
const flattenedObj = {};
|
|
75
9
|
for (const [key, value] of Object.entries(obj)) {
|
|
76
10
|
if (value instanceof Object) {
|
|
77
|
-
Object.assign(flattenedObj,
|
|
11
|
+
Object.assign(flattenedObj, flatten(value, prefix + key + "."));
|
|
78
12
|
} else {
|
|
79
|
-
flattenedObj[prefix +
|
|
13
|
+
flattenedObj[prefix + key] = value;
|
|
80
14
|
}
|
|
81
15
|
}
|
|
82
16
|
return flattenedObj;
|
|
83
17
|
};
|
|
84
18
|
const kebabCase = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
85
|
-
|
|
86
|
-
const atomicArrays = options?.atomicArrays;
|
|
87
|
-
const queue = [
|
|
88
|
-
{
|
|
89
|
-
src,
|
|
90
|
-
dest
|
|
91
|
-
}
|
|
92
|
-
];
|
|
93
|
-
while (queue.length > 0) {
|
|
94
|
-
const task = queue.pop();
|
|
95
|
-
if (task === void 0) {
|
|
96
|
-
throw new Error("queue is empty");
|
|
97
|
-
}
|
|
98
|
-
if (isArray(task.dest)) {
|
|
99
|
-
const src2 = task.src;
|
|
100
|
-
const dest2 = task.dest;
|
|
101
|
-
if (atomicArrays) {
|
|
102
|
-
while (dest2.length > src2.length) {
|
|
103
|
-
dest2.pop();
|
|
104
|
-
}
|
|
105
|
-
for (let i = 0; i < src2.length; i++) {
|
|
106
|
-
dest2[i] = src2[i];
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
for (let i = 0; i < src2.length; i++) {
|
|
110
|
-
if (isArray(dest2[i]) && isArray(src2[i]) || isObject(dest2[i]) && isObject(src2[i])) {
|
|
111
|
-
queue.push({
|
|
112
|
-
src: src2[i],
|
|
113
|
-
dest: dest2[i]
|
|
114
|
-
});
|
|
115
|
-
} else {
|
|
116
|
-
dest2[i] = src2[i];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} else if (isObject(task.dest)) {
|
|
121
|
-
const src2 = task.src;
|
|
122
|
-
const destAny = task.dest;
|
|
123
|
-
for (const [key, value] of Object.entries(src2)) {
|
|
124
|
-
if (isArray(value) && isArray(destAny[key]) || isObject(value) && isObject(destAny[key])) {
|
|
125
|
-
queue.push({
|
|
126
|
-
src: value,
|
|
127
|
-
dest: destAny[key]
|
|
128
|
-
});
|
|
129
|
-
} else {
|
|
130
|
-
destAny[key] = value;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
throw new Error(`cannot handle type in queue: ${typeof task.dest}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return dest;
|
|
138
|
-
}
|
|
139
|
-
const isArray = (value) => {
|
|
140
|
-
return Array.isArray(value);
|
|
141
|
-
};
|
|
142
|
-
const isObject = (value) => {
|
|
143
|
-
return value instanceof Object && !isArray(value);
|
|
144
|
-
};
|
|
145
|
-
const hashToHex = (hash) => {
|
|
146
|
-
if (isArray(hash)) {
|
|
147
|
-
return util.u8aToHex(new Uint8Array(hash));
|
|
148
|
-
}
|
|
149
|
-
return hash.toString();
|
|
150
|
-
};
|
|
151
|
-
exports.at = at;
|
|
152
|
-
exports.flattenObj = flattenObj;
|
|
153
|
-
exports.get = get;
|
|
19
|
+
exports.flatten = flatten;
|
|
154
20
|
exports.getCurrentFileDirectory = getCurrentFileDirectory;
|
|
155
|
-
exports.hashToHex = hashToHex;
|
|
156
|
-
exports.isArray = isArray;
|
|
157
|
-
exports.isObject = isObject;
|
|
158
21
|
exports.kebabCase = kebabCase;
|
|
159
|
-
exports.merge = merge;
|
|
160
|
-
exports.permutations = permutations;
|
|
161
22
|
exports.sleep = sleep;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/account",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Services and Utils for Prosopo account gen and management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=20",
|
|
9
9
|
"npm": ">=9"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"clean": "tsc --build --clean",
|
|
20
20
|
"build": "tsc --build --verbose tsconfig.json",
|
|
21
21
|
"build:cjs": "npx vite --config vite.cjs.config.ts build",
|
|
22
|
-
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore --quiet",
|
|
22
|
+
"eslint": "npx eslint . --cache --cache-location ../../node_modules/.cache/eslint/.eslintcache --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore --quiet",
|
|
23
23
|
"eslint:fix": "npm run eslint -- --fix",
|
|
24
|
-
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
|
|
24
|
+
"prettier": "npx prettier . --cache --cache-location ../../node_modules/.cache/prettier/.prettiercache --check --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
|
|
25
25
|
"prettier:fix": "npm run prettier -- --write",
|
|
26
26
|
"lint": "npm run eslint && npm run prettier",
|
|
27
27
|
"lint:fix": "npm run eslint:fix && npm run prettier:fix"
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"@polkadot/rpc-provider": "10.13.1",
|
|
48
48
|
"@polkadot/util": "12.6.2",
|
|
49
49
|
"@polkadot/util-crypto": "12.6.2",
|
|
50
|
-
"@prosopo/common": "0.
|
|
51
|
-
"@prosopo/types": "0.
|
|
52
|
-
"@prosopo/util": "0.
|
|
50
|
+
"@prosopo/common": "1.0.2",
|
|
51
|
+
"@prosopo/types": "1.0.2",
|
|
52
|
+
"@prosopo/util": "1.0.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@prosopo/config": "0.
|
|
55
|
+
"@prosopo/config": "1.0.2",
|
|
56
56
|
"tslib": "2.6.2",
|
|
57
57
|
"typescript": "5.1.6"
|
|
58
58
|
},
|