@prosopo/account 1.0.1 → 2.0.0
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 +20 -16
- package/dist/cjs/common/dist/hash.cjs +1 -1
- package/dist/cjs/common/dist/i18n.cjs +3 -3
- package/dist/cjs/common/dist/locales/en.json.cjs +2 -1
- package/dist/cjs/common/dist/logger.cjs +23 -11
- package/dist/cjs/common/dist/node/UrlConverter.cjs +15 -7
- package/dist/cjs/common/dist/utils.cjs +4 -2
- package/dist/cjs/detector/src/index.cjs +4586 -0
- package/dist/cjs/extension/ExtensionWeb2.cjs +30 -30
- package/dist/cjs/extension/ExtensionWeb3.cjs +5 -3
- package/dist/cjs/util/dist/at.cjs +25 -0
- package/dist/cjs/util/dist/canvas.cjs +52 -46
- 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 +46 -0
- package/dist/cjs/util/dist/index.cjs +17 -8
- package/dist/cjs/util/dist/merge.cjs +58 -0
- package/dist/cjs/util/dist/ofLen.cjs +1 -1
- package/dist/cjs/util/dist/permutations.cjs +26 -0
- package/dist/cjs/util/dist/table.cjs +2 -2
- package/dist/cjs/util/dist/util.cjs +4 -143
- package/dist/extension/Extension.d.ts +1 -1
- package/dist/extension/Extension.d.ts.map +1 -1
- package/dist/extension/Extension.js.map +1 -1
- package/dist/extension/ExtensionWeb2.d.ts +4 -5
- package/dist/extension/ExtensionWeb2.d.ts.map +1 -1
- package/dist/extension/ExtensionWeb2.js +27 -36
- package/dist/extension/ExtensionWeb2.js.map +1 -1
- package/dist/extension/ExtensionWeb3.d.ts +2 -2
- package/dist/extension/ExtensionWeb3.d.ts.map +1 -1
- package/dist/extension/ExtensionWeb3.js +8 -6
- package/dist/extension/ExtensionWeb3.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +53 -58
- package/vite.cjs.config.ts +3 -3
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Api = require("@polkadot/api/promise/Api");
|
|
4
|
-
const Extension = require("./Extension.cjs");
|
|
5
|
-
const keyring = require("@polkadot/keyring");
|
|
6
|
-
require("../common/dist/index.cjs");
|
|
7
3
|
const Signer = require("@polkadot/extension-base/page/Signer");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
4
|
+
const keyring = require("@polkadot/keyring");
|
|
5
|
+
const utilCrypto = require("@polkadot/util-crypto");
|
|
10
6
|
const bip39 = require("@polkadot/util-crypto/mnemonic/bip39");
|
|
11
|
-
const fingerprintjs = require("@fingerprintjs/fingerprintjs");
|
|
12
|
-
require("../util/dist/index.cjs");
|
|
13
7
|
const string = require("@polkadot/util/string");
|
|
14
8
|
const u8a = require("@polkadot/util/u8a");
|
|
9
|
+
require("../common/dist/index.cjs");
|
|
10
|
+
const index = require("../detector/src/index.cjs");
|
|
11
|
+
require("../util/dist/index.cjs");
|
|
12
|
+
const Extension = require("./Extension.cjs");
|
|
15
13
|
const error = require("../common/dist/error.cjs");
|
|
16
14
|
const version = require("../util/dist/version.cjs");
|
|
17
15
|
const canvas = require("../util/dist/canvas.cjs");
|
|
@@ -23,16 +21,16 @@ class ExtensionWeb2 extends Extension.Extension {
|
|
|
23
21
|
const network = config.networks[config.defaultNetwork];
|
|
24
22
|
if (!network) {
|
|
25
23
|
throw new error.ProsopoEnvError("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
26
|
-
context: {
|
|
24
|
+
context: {
|
|
25
|
+
error: `No network found for environment ${config.defaultEnvironment}`
|
|
26
|
+
}
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
return network;
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
async getAccount(config) {
|
|
33
|
-
const
|
|
34
|
-
const wsProvider = new ws.WsProvider(network.endpoint);
|
|
35
|
-
const account = await this.createAccount(wsProvider);
|
|
33
|
+
const account = await this.createAccount(config);
|
|
36
34
|
const extension = await this.createExtension(account);
|
|
37
35
|
return {
|
|
38
36
|
account,
|
|
@@ -67,7 +65,8 @@ class ExtensionWeb2 extends Extension.Extension {
|
|
|
67
65
|
signer
|
|
68
66
|
};
|
|
69
67
|
}
|
|
70
|
-
async createAccount(
|
|
68
|
+
async createAccount(config) {
|
|
69
|
+
await utilCrypto.cryptoWaitReady();
|
|
71
70
|
const params = {
|
|
72
71
|
area: { width: 300, height: 300 },
|
|
73
72
|
offsetParameter: 2001000001,
|
|
@@ -77,29 +76,30 @@ class ExtensionWeb2 extends Extension.Extension {
|
|
|
77
76
|
numberOfRounds: 5,
|
|
78
77
|
seed: 42
|
|
79
78
|
};
|
|
80
|
-
const browserEntropy = await
|
|
81
|
-
const canvasEntropy = canvas.picassoCanvas(
|
|
82
|
-
|
|
79
|
+
const browserEntropy = await index.getFingerprint();
|
|
80
|
+
const canvasEntropy = canvas.picassoCanvas(
|
|
81
|
+
params.numberOfRounds,
|
|
82
|
+
params.seed,
|
|
83
|
+
params
|
|
84
|
+
);
|
|
85
|
+
const entropy = hash.hexHash(
|
|
86
|
+
[canvasEntropy, browserEntropy].join(""),
|
|
87
|
+
128
|
|
88
|
+
).slice(2);
|
|
83
89
|
const u8Entropy = string.stringToU8a(entropy);
|
|
84
90
|
const mnemonic = bip39.entropyToMnemonic(u8Entropy);
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
91
|
+
const type = "sr25519";
|
|
92
|
+
const keyring$1 = new keyring.Keyring({
|
|
93
|
+
type,
|
|
94
|
+
ss58Format: config.networks[config.defaultNetwork].ss58Format
|
|
95
|
+
});
|
|
88
96
|
const keypair = keyring$1.addFromMnemonic(mnemonic);
|
|
89
|
-
const address
|
|
97
|
+
const address = keypair.address;
|
|
90
98
|
return {
|
|
91
|
-
address
|
|
92
|
-
|
|
93
|
-
name: address$1,
|
|
99
|
+
address,
|
|
100
|
+
name: address,
|
|
94
101
|
keypair
|
|
95
102
|
};
|
|
96
103
|
}
|
|
97
|
-
async getFingerprint() {
|
|
98
|
-
const fpPromise = fingerprintjs.load();
|
|
99
|
-
const fp = await fpPromise;
|
|
100
|
-
const result = await fp.get();
|
|
101
|
-
const { screenFrame, ...componentsReduced } = result.components;
|
|
102
|
-
return fingerprintjs.hashComponents(componentsReduced);
|
|
103
|
-
}
|
|
104
104
|
}
|
|
105
105
|
exports.ExtensionWeb2 = ExtensionWeb2;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Extension = require("./Extension.cjs");
|
|
4
|
-
require("../common/dist/index.cjs");
|
|
5
3
|
const extensionDapp = require("@polkadot/extension-dapp");
|
|
4
|
+
require("../common/dist/index.cjs");
|
|
5
|
+
const Extension = require("./Extension.cjs");
|
|
6
6
|
const error = require("../common/dist/error.cjs");
|
|
7
7
|
class ExtensionWeb3 extends Extension.Extension {
|
|
8
8
|
async getAccount(config) {
|
|
9
9
|
const { dappName, userAccountAddress: address } = config;
|
|
10
10
|
if (!address) {
|
|
11
|
-
throw new error.ProsopoError("WIDGET.NO_ACCOUNTS_FOUND", {
|
|
11
|
+
throw new error.ProsopoError("WIDGET.NO_ACCOUNTS_FOUND", {
|
|
12
|
+
context: { error: "No account address provided" }
|
|
13
|
+
});
|
|
12
14
|
}
|
|
13
15
|
const extensions = await extensionDapp.web3Enable(dappName);
|
|
14
16
|
if (extensions.length === 0) {
|
|
@@ -0,0 +1,25 @@
|
|
|
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 (!Number.isFinite(index)) {
|
|
8
|
+
throw new Error(`Index ${index} is not a finite number`);
|
|
9
|
+
}
|
|
10
|
+
if (!options?.noWrap) {
|
|
11
|
+
if (index > 0) {
|
|
12
|
+
index = index % items.length;
|
|
13
|
+
} else {
|
|
14
|
+
index = Math.ceil(Math.abs(index) / items.length) * items.length + index;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (index >= items.length) {
|
|
18
|
+
throw new Error(`Index ${index} larger than array length ${items.length}`);
|
|
19
|
+
}
|
|
20
|
+
if (index < 0) {
|
|
21
|
+
throw new Error(`Index ${index} smaller than 0`);
|
|
22
|
+
}
|
|
23
|
+
return items[index];
|
|
24
|
+
}
|
|
25
|
+
exports.at = at;
|
|
@@ -1,80 +1,86 @@
|
|
|
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 [
|
|
52
|
-
} else if (n < 32) {
|
|
53
|
-
return [util.at(m, 0) << n | util.at(m, 1) >>> 32 - n, util.at(m, 1) << n | util.at(m, 0) >>> 32 - n];
|
|
54
|
-
} else {
|
|
55
|
-
n -= 32;
|
|
56
|
-
return [util.at(m, 1) << n | util.at(m, 0) >>> 32 - n, util.at(m, 0) << n | util.at(m, 1) >>> 32 - n];
|
|
51
|
+
return [at.at(m, 1), at.at(m, 0)];
|
|
57
52
|
}
|
|
53
|
+
if (n < 32) {
|
|
54
|
+
return [
|
|
55
|
+
at.at(m, 0) << n | at.at(m, 1) >>> 32 - n,
|
|
56
|
+
at.at(m, 1) << n | at.at(m, 0) >>> 32 - n
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
n -= 32;
|
|
60
|
+
return [
|
|
61
|
+
at.at(m, 1) << n | at.at(m, 0) >>> 32 - n,
|
|
62
|
+
at.at(m, 0) << n | at.at(m, 1) >>> 32 - n
|
|
63
|
+
];
|
|
58
64
|
}
|
|
59
65
|
function x64LeftShift(m, n) {
|
|
60
66
|
n %= 64;
|
|
61
67
|
if (n === 0) {
|
|
62
68
|
return m;
|
|
63
|
-
} else if (n < 32) {
|
|
64
|
-
return [util.at(m, 0) << n | util.at(m, 1) >>> 32 - n, util.at(m, 1) << n];
|
|
65
|
-
} else {
|
|
66
|
-
return [util.at(m, 1) << n - 32, 0];
|
|
67
69
|
}
|
|
70
|
+
if (n < 32) {
|
|
71
|
+
return [at.at(m, 0) << n | at.at(m, 1) >>> 32 - n, at.at(m, 1) << n];
|
|
72
|
+
}
|
|
73
|
+
return [at.at(m, 1) << n - 32, 0];
|
|
68
74
|
}
|
|
69
75
|
function x64Xor(m, n) {
|
|
70
|
-
return [
|
|
76
|
+
return [at.at(m, 0) ^ at.at(n, 0), at.at(m, 1) ^ at.at(n, 1)];
|
|
71
77
|
}
|
|
72
78
|
function x64Fmix(h) {
|
|
73
|
-
h = x64Xor(h, [0,
|
|
79
|
+
h = x64Xor(h, [0, at.at(h, 0) >>> 1]);
|
|
74
80
|
h = x64Multiply(h, [4283543511, 3981806797]);
|
|
75
|
-
h = x64Xor(h, [0,
|
|
81
|
+
h = x64Xor(h, [0, at.at(h, 0) >>> 1]);
|
|
76
82
|
h = x64Multiply(h, [3301882366, 444984403]);
|
|
77
|
-
h = x64Xor(h, [0,
|
|
83
|
+
h = x64Xor(h, [0, at.at(h, 0) >>> 1]);
|
|
78
84
|
return h;
|
|
79
85
|
}
|
|
80
86
|
function x64hash128(key, seed) {
|
|
@@ -177,7 +183,7 @@ function x64hash128(key, seed) {
|
|
|
177
183
|
h2 = x64Fmix(h2);
|
|
178
184
|
h1 = x64Add(h1, h2);
|
|
179
185
|
h2 = x64Add(h2, h1);
|
|
180
|
-
return
|
|
186
|
+
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
187
|
}
|
|
182
188
|
function picassoCanvas(roundNumber, seed, params) {
|
|
183
189
|
const { area, offsetParameter, multiplier, fontSizeFactor, maxShadowBlur } = params;
|
|
@@ -202,8 +208,8 @@ function picassoCanvas(roundNumber, seed, params) {
|
|
|
202
208
|
}
|
|
203
209
|
function addRandomCanvasGradient(prng, context, area2) {
|
|
204
210
|
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,
|
|
211
|
+
canvasGradient.addColorStop(0, at.at(colors, adaptRandomNumberToContext(prng.getNext(), colors.length, void 0)));
|
|
212
|
+
canvasGradient.addColorStop(1, at.at(colors, adaptRandomNumberToContext(prng.getNext(), colors.length, void 0)));
|
|
207
213
|
context.fillStyle = canvasGradient;
|
|
208
214
|
}
|
|
209
215
|
function generateRandomWord(prng, wordLength) {
|
|
@@ -312,8 +318,8 @@ function picassoCanvas(roundNumber, seed, params) {
|
|
|
312
318
|
for (let i = 0; i < roundNumber; i++) {
|
|
313
319
|
addRandomCanvasGradient(prng, context, area);
|
|
314
320
|
context.shadowBlur = adaptRandomNumberToContext(prng.getNext(), maxShadowBlur, void 0);
|
|
315
|
-
context.shadowColor =
|
|
316
|
-
const randomPrimitive =
|
|
321
|
+
context.shadowColor = at.at(colors, adaptRandomNumberToContext(prng.getNext(), colors.length, void 0));
|
|
322
|
+
const randomPrimitive = at.at(primitives, adaptRandomNumberToContext(prng.getNext(), primitives.length, void 0));
|
|
317
323
|
randomPrimitive(prng, context, area);
|
|
318
324
|
context.fill();
|
|
319
325
|
}
|
|
@@ -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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const checks = require("./checks.cjs");
|
|
4
|
+
const U8 = new Array(256);
|
|
5
|
+
const U16 = new Array(256 * 256);
|
|
6
|
+
for (let n = 0; n < 256; n++) {
|
|
7
|
+
U8[n] = n.toString(16).padStart(2, "0");
|
|
8
|
+
}
|
|
9
|
+
for (let i = 0; i < 256; i++) {
|
|
10
|
+
const s = i << 8;
|
|
11
|
+
for (let j = 0; j < 256; j++) {
|
|
12
|
+
U16[s | j] = U8[i] + U8[j];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function hex(value, result) {
|
|
16
|
+
const mod = value.length % 2 | 0;
|
|
17
|
+
const length = value.length - mod | 0;
|
|
18
|
+
for (let i = 0; i < length; i += 2) {
|
|
19
|
+
result += U16[value[i] << 8 | value[i + 1]];
|
|
20
|
+
}
|
|
21
|
+
if (mod) {
|
|
22
|
+
result += U8[value[length] | 0];
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function u8aToHex(value, bitLength = -1, isPrefixed = true) {
|
|
27
|
+
const empty = isPrefixed ? "0x" : "";
|
|
28
|
+
if (!value?.length) {
|
|
29
|
+
return empty;
|
|
30
|
+
}
|
|
31
|
+
if (bitLength > 0) {
|
|
32
|
+
const length = Math.ceil(bitLength / 8);
|
|
33
|
+
if (value.length > length) {
|
|
34
|
+
return `${hex(value.subarray(0, length / 2), empty)}…${hex(value.subarray(value.length - length / 2), "")}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return hex(value, empty);
|
|
38
|
+
}
|
|
39
|
+
const hashToHex = (hash) => {
|
|
40
|
+
if (checks.isArray(hash)) {
|
|
41
|
+
return u8aToHex(new Uint8Array(hash));
|
|
42
|
+
}
|
|
43
|
+
return hash.toString();
|
|
44
|
+
};
|
|
45
|
+
exports.hashToHex = hashToHex;
|
|
46
|
+
exports.u8aToHex = u8aToHex;
|
|
@@ -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,13 @@ 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.u8aToHex = hex.u8aToHex;
|
|
41
|
+
exports.isArray = checks.isArray;
|
|
42
|
+
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;
|
|
@@ -9,10 +9,10 @@ function wrapItemToMultipleRows(item, maxCellWidth) {
|
|
|
9
9
|
}
|
|
10
10
|
const itemRow = {};
|
|
11
11
|
const remaining = {};
|
|
12
|
-
|
|
12
|
+
for (const [key, value] of Object.entries(item)) {
|
|
13
13
|
itemRow[key] = value?.slice ? value.slice(0, maxCellWidth) : value;
|
|
14
14
|
remaining[key] = value?.slice ? value.slice(maxCellWidth) : value;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
return [itemRow, ...wrapItemToMultipleRows(remaining, maxCellWidth)];
|
|
17
17
|
}
|
|
18
18
|
function consoleTableWithWrapping(data, maxColWidth = 90) {
|