@talismn/scale 0.0.0-pr997-20230922064047 → 0.0.0-pr997-20231115151657
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/CHANGELOG.md +7 -1
- package/dist/declarations/src/capi/crypto/index.d.ts +1 -0
- package/dist/declarations/src/capi/crypto/util/index.d.ts +4 -0
- package/dist/declarations/src/capi/crypto/util/nosimd.d.ts +19 -0
- package/dist/declarations/src/capi/crypto/util/simd.d.ts +1 -0
- package/dist/nosimd-20b5b0ca.esm.js +45 -0
- package/dist/nosimd-3e5ed5a9.cjs.prod.js +48 -0
- package/dist/nosimd-61fc593c.cjs.dev.js +48 -0
- package/dist/simd-133b8f48.cjs.prod.js +14 -0
- package/dist/simd-2ddb8d7c.cjs.dev.js +14 -0
- package/dist/simd-b794dbff.esm.js +1 -0
- package/dist/talismn-scale.cjs.dev.js +68 -10
- package/dist/talismn-scale.cjs.prod.js +68 -10
- package/dist/talismn-scale.esm.js +64 -7
- package/package.json +12 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
# @talismn/scale
|
|
2
2
|
|
|
3
|
-
## 0.0.0-pr997-
|
|
3
|
+
## 0.0.0-pr997-20231115151657
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- c4d59671: bump typescript version
|
|
7
8
|
- 5aadf998: feat: native token balances on custom networks
|
|
9
|
+
- a6c1b2ae: fix: workaround for devices with no wasm simd support
|
|
10
|
+
- Updated dependencies [372f9951]
|
|
11
|
+
- Updated dependencies [c4d59671]
|
|
12
|
+
- Updated dependencies [e0eb84ad]
|
|
13
|
+
- @talismn/util@0.0.0-pr997-20231115151657
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Hasher } from "wat-the-crypto/types/common/hasher";
|
|
2
|
+
export declare class Xxhash implements Hasher {
|
|
3
|
+
rounds: number;
|
|
4
|
+
input: Uint8Array;
|
|
5
|
+
constructor(rounds: number);
|
|
6
|
+
update(input: Uint8Array): void;
|
|
7
|
+
digest(): Uint8Array;
|
|
8
|
+
digestInto(digest: Uint8Array): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class Blake2b implements Hasher {
|
|
12
|
+
digestSize: number;
|
|
13
|
+
input: Uint8Array;
|
|
14
|
+
constructor(digestSize?: number);
|
|
15
|
+
update(input: Uint8Array): void;
|
|
16
|
+
digest(): Uint8Array;
|
|
17
|
+
digestInto(digest: Uint8Array): void;
|
|
18
|
+
dispose(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Blake2b, Xxhash } from "wat-the-crypto";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { xxhashAsU8a, blake2AsU8a } from '@polkadot/util-crypto';
|
|
2
|
+
|
|
3
|
+
class Xxhash {
|
|
4
|
+
input = new Uint8Array();
|
|
5
|
+
constructor(rounds) {
|
|
6
|
+
this.rounds = rounds;
|
|
7
|
+
}
|
|
8
|
+
update(input) {
|
|
9
|
+
this.input = input;
|
|
10
|
+
}
|
|
11
|
+
digest() {
|
|
12
|
+
return xxhashAsU8a(this.input, this.rounds * 64);
|
|
13
|
+
}
|
|
14
|
+
digestInto(digest) {
|
|
15
|
+
// TODO: Test that this correctly mutates the input var to be the value of the digest
|
|
16
|
+
digest.set(this.digest());
|
|
17
|
+
}
|
|
18
|
+
dispose() {
|
|
19
|
+
this.input = new Uint8Array();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class Blake2b {
|
|
23
|
+
input = new Uint8Array();
|
|
24
|
+
|
|
25
|
+
// digestSize defaults to 64
|
|
26
|
+
// https://github.com/paritytech/wat-the-crypto/blob/a96745c57f597b35fe1461d0e643a34ba5e7bd85/blake2b/blake2b.ts#L31
|
|
27
|
+
constructor(digestSize = 64) {
|
|
28
|
+
this.digestSize = digestSize;
|
|
29
|
+
}
|
|
30
|
+
update(input) {
|
|
31
|
+
this.input = input;
|
|
32
|
+
}
|
|
33
|
+
digest() {
|
|
34
|
+
return blake2AsU8a(this.input, this.digestSize * 8);
|
|
35
|
+
}
|
|
36
|
+
digestInto(digest) {
|
|
37
|
+
// TODO: Test that this correctly mutates the input var to be the value of the digest
|
|
38
|
+
digest.set(this.digest());
|
|
39
|
+
}
|
|
40
|
+
dispose() {
|
|
41
|
+
this.input = new Uint8Array();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { Blake2b, Xxhash };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utilCrypto = require('@polkadot/util-crypto');
|
|
4
|
+
|
|
5
|
+
class Xxhash {
|
|
6
|
+
input = new Uint8Array();
|
|
7
|
+
constructor(rounds) {
|
|
8
|
+
this.rounds = rounds;
|
|
9
|
+
}
|
|
10
|
+
update(input) {
|
|
11
|
+
this.input = input;
|
|
12
|
+
}
|
|
13
|
+
digest() {
|
|
14
|
+
return utilCrypto.xxhashAsU8a(this.input, this.rounds * 64);
|
|
15
|
+
}
|
|
16
|
+
digestInto(digest) {
|
|
17
|
+
// TODO: Test that this correctly mutates the input var to be the value of the digest
|
|
18
|
+
digest.set(this.digest());
|
|
19
|
+
}
|
|
20
|
+
dispose() {
|
|
21
|
+
this.input = new Uint8Array();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class Blake2b {
|
|
25
|
+
input = new Uint8Array();
|
|
26
|
+
|
|
27
|
+
// digestSize defaults to 64
|
|
28
|
+
// https://github.com/paritytech/wat-the-crypto/blob/a96745c57f597b35fe1461d0e643a34ba5e7bd85/blake2b/blake2b.ts#L31
|
|
29
|
+
constructor(digestSize = 64) {
|
|
30
|
+
this.digestSize = digestSize;
|
|
31
|
+
}
|
|
32
|
+
update(input) {
|
|
33
|
+
this.input = input;
|
|
34
|
+
}
|
|
35
|
+
digest() {
|
|
36
|
+
return utilCrypto.blake2AsU8a(this.input, this.digestSize * 8);
|
|
37
|
+
}
|
|
38
|
+
digestInto(digest) {
|
|
39
|
+
// TODO: Test that this correctly mutates the input var to be the value of the digest
|
|
40
|
+
digest.set(this.digest());
|
|
41
|
+
}
|
|
42
|
+
dispose() {
|
|
43
|
+
this.input = new Uint8Array();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.Blake2b = Blake2b;
|
|
48
|
+
exports.Xxhash = Xxhash;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utilCrypto = require('@polkadot/util-crypto');
|
|
4
|
+
|
|
5
|
+
class Xxhash {
|
|
6
|
+
input = new Uint8Array();
|
|
7
|
+
constructor(rounds) {
|
|
8
|
+
this.rounds = rounds;
|
|
9
|
+
}
|
|
10
|
+
update(input) {
|
|
11
|
+
this.input = input;
|
|
12
|
+
}
|
|
13
|
+
digest() {
|
|
14
|
+
return utilCrypto.xxhashAsU8a(this.input, this.rounds * 64);
|
|
15
|
+
}
|
|
16
|
+
digestInto(digest) {
|
|
17
|
+
// TODO: Test that this correctly mutates the input var to be the value of the digest
|
|
18
|
+
digest.set(this.digest());
|
|
19
|
+
}
|
|
20
|
+
dispose() {
|
|
21
|
+
this.input = new Uint8Array();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class Blake2b {
|
|
25
|
+
input = new Uint8Array();
|
|
26
|
+
|
|
27
|
+
// digestSize defaults to 64
|
|
28
|
+
// https://github.com/paritytech/wat-the-crypto/blob/a96745c57f597b35fe1461d0e643a34ba5e7bd85/blake2b/blake2b.ts#L31
|
|
29
|
+
constructor(digestSize = 64) {
|
|
30
|
+
this.digestSize = digestSize;
|
|
31
|
+
}
|
|
32
|
+
update(input) {
|
|
33
|
+
this.input = input;
|
|
34
|
+
}
|
|
35
|
+
digest() {
|
|
36
|
+
return utilCrypto.blake2AsU8a(this.input, this.digestSize * 8);
|
|
37
|
+
}
|
|
38
|
+
digestInto(digest) {
|
|
39
|
+
// TODO: Test that this correctly mutates the input var to be the value of the digest
|
|
40
|
+
digest.set(this.digest());
|
|
41
|
+
}
|
|
42
|
+
dispose() {
|
|
43
|
+
this.input = new Uint8Array();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.Blake2b = Blake2b;
|
|
48
|
+
exports.Xxhash = Xxhash;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var watTheCrypto = require('wat-the-crypto');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, 'Blake2b', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return watTheCrypto.Blake2b; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, 'Xxhash', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return watTheCrypto.Xxhash; }
|
|
14
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var watTheCrypto = require('wat-the-crypto');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, 'Blake2b', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return watTheCrypto.Blake2b; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, 'Xxhash', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return watTheCrypto.Xxhash; }
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Blake2b, Xxhash } from 'wat-the-crypto';
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var util = require('@talismn/util');
|
|
6
|
+
var wasmFeatureDetect = require('wasm-feature-detect');
|
|
6
7
|
var $ = require('@talismn/subshape-fork');
|
|
7
8
|
var anylogger = require('anylogger');
|
|
8
9
|
|
|
@@ -29,6 +30,56 @@ function _interopNamespace(e) {
|
|
|
29
30
|
var $__namespace = /*#__PURE__*/_interopNamespace($);
|
|
30
31
|
var anylogger__default = /*#__PURE__*/_interopDefault(anylogger);
|
|
31
32
|
|
|
33
|
+
//
|
|
34
|
+
// The simd variants of these hash fns are faster, but some devices don't support them.
|
|
35
|
+
//
|
|
36
|
+
// This file re-exports the faster fns from `./simd` for devices which support them,
|
|
37
|
+
// and falls back to `./nosimd` re-exports for devices which do not.
|
|
38
|
+
//
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
let Blake2b;
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
let Xxhash;
|
|
43
|
+
let readyPromise = null;
|
|
44
|
+
const watCryptoWaitReady = async () => {
|
|
45
|
+
// if this is the second/third/etc time we've called watCryptoWaitReady,
|
|
46
|
+
// then get a reference to the existing promise and wait for it to resolve/reject
|
|
47
|
+
if (readyPromise !== null) return await readyPromise;
|
|
48
|
+
|
|
49
|
+
// if this is the first time we've called watCryptoWaitReady,
|
|
50
|
+
// then create and return a new promise
|
|
51
|
+
const deferred = util.Deferred();
|
|
52
|
+
readyPromise = deferred.promise
|
|
53
|
+
|
|
54
|
+
// spawn a task to initialize the fns and resolve the readyPromise
|
|
55
|
+
;
|
|
56
|
+
(async () => {
|
|
57
|
+
try {
|
|
58
|
+
// initialize simd or nosimd, based on wasm feature detection
|
|
59
|
+
if (await wasmFeatureDetect.simd()) {
|
|
60
|
+
// system supports wasm simd
|
|
61
|
+
const imported = await Promise.resolve().then(function () { return require('./simd-2ddb8d7c.cjs.dev.js'); });
|
|
62
|
+
Blake2b = imported.Blake2b;
|
|
63
|
+
Xxhash = imported.Xxhash;
|
|
64
|
+
} else {
|
|
65
|
+
// system does not support wasm simd
|
|
66
|
+
const imported = await Promise.resolve().then(function () { return require('./nosimd-61fc593c.cjs.dev.js'); });
|
|
67
|
+
Blake2b = imported.Blake2b;
|
|
68
|
+
Xxhash = imported.Xxhash;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// feature detection and loading complete
|
|
72
|
+
deferred.resolve();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// feature detection and loading failed
|
|
75
|
+
deferred.reject(error);
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
// wait for the promise to resolve/reject
|
|
80
|
+
return await readyPromise;
|
|
81
|
+
};
|
|
82
|
+
|
|
32
83
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
33
84
|
// This module is browser compatible.
|
|
34
85
|
|
|
@@ -199,7 +250,7 @@ function encodeRaw(prefix, payload, checksumLength) {
|
|
|
199
250
|
checksumLength ??= DEFAULT_PAYLOAD_CHECKSUM_LENGTHS[payload.length];
|
|
200
251
|
if (!checksumLength) throw new InvalidPayloadLengthError();
|
|
201
252
|
const prefixBytes = prefix < 64 ? Uint8Array.of(prefix) : Uint8Array.of((prefix & 0b0000_0000_1111_1100) >> 2 | 0b0100_0000, prefix >> 8 | (prefix & 0b0000_0000_0000_0011) << 6);
|
|
202
|
-
const hasher = new
|
|
253
|
+
const hasher = new Blake2b();
|
|
203
254
|
hasher.update(SS58PRE);
|
|
204
255
|
hasher.update(prefixBytes);
|
|
205
256
|
hasher.update(payload);
|
|
@@ -223,7 +274,7 @@ function decodeRaw(address) {
|
|
|
223
274
|
if (!checksumLength) throw new InvalidAddressLengthError();
|
|
224
275
|
const prefixLength = address[0] & 0b0100_0000 ? 2 : 1;
|
|
225
276
|
const prefix = prefixLength === 1 ? address[0] : (address[0] & 0b0011_1111) << 2 | address[1] >> 6 | (address[1] & 0b0011_1111) << 8;
|
|
226
|
-
const hasher = new
|
|
277
|
+
const hasher = new Blake2b();
|
|
227
278
|
hasher.update(SS58PRE);
|
|
228
279
|
hasher.update(address.subarray(0, address.length - checksumLength));
|
|
229
280
|
const digest = hasher.digest();
|
|
@@ -361,7 +412,7 @@ class Blake2Hasher extends Hasher {
|
|
|
361
412
|
this.digestLength = size / 8;
|
|
362
413
|
}
|
|
363
414
|
create() {
|
|
364
|
-
return new
|
|
415
|
+
return new Blake2b(this.digestLength);
|
|
365
416
|
}
|
|
366
417
|
}
|
|
367
418
|
class IdentityHasher extends Hasher {
|
|
@@ -388,7 +439,7 @@ class TwoxHasher extends Hasher {
|
|
|
388
439
|
this.rounds = size / 64;
|
|
389
440
|
}
|
|
390
441
|
create() {
|
|
391
|
-
return new
|
|
442
|
+
return new Xxhash(this.rounds);
|
|
392
443
|
}
|
|
393
444
|
}
|
|
394
445
|
const blake2_64 = new Blake2Hasher(64, false);
|
|
@@ -1258,7 +1309,7 @@ class SignerError extends Error {
|
|
|
1258
1309
|
|
|
1259
1310
|
var packageJson = {
|
|
1260
1311
|
name: "@talismn/scale",
|
|
1261
|
-
version: "0.0.0-pr997-
|
|
1312
|
+
version: "0.0.0-pr997-20231115151657",
|
|
1262
1313
|
author: "Talisman",
|
|
1263
1314
|
homepage: "https://talisman.xyz",
|
|
1264
1315
|
license: "GPL-3.0-or-later",
|
|
@@ -1285,17 +1336,23 @@ var packageJson = {
|
|
|
1285
1336
|
},
|
|
1286
1337
|
dependencies: {
|
|
1287
1338
|
"@talismn/subshape-fork": "^0.0.1",
|
|
1339
|
+
"@talismn/util": "workspace:*",
|
|
1288
1340
|
anylogger: "^1.0.11",
|
|
1341
|
+
"wasm-feature-detect": "^1.6.0",
|
|
1289
1342
|
"wat-the-crypto": "^0.0.3"
|
|
1290
1343
|
},
|
|
1291
1344
|
devDependencies: {
|
|
1345
|
+
"@polkadot/util-crypto": "^11.1.1",
|
|
1292
1346
|
"@talismn/eslint-config": "workspace:*",
|
|
1293
1347
|
"@talismn/tsconfig": "workspace:*",
|
|
1294
1348
|
"@types/jest": "^27.5.1",
|
|
1295
|
-
eslint: "^8.
|
|
1296
|
-
jest: "^
|
|
1297
|
-
"ts-jest": "^
|
|
1298
|
-
typescript: "^
|
|
1349
|
+
eslint: "^8.52.0",
|
|
1350
|
+
jest: "^29.7",
|
|
1351
|
+
"ts-jest": "^29.1.1",
|
|
1352
|
+
typescript: "^5.2.2"
|
|
1353
|
+
},
|
|
1354
|
+
peerDependencies: {
|
|
1355
|
+
"@polkadot/util-crypto": "^11.x"
|
|
1299
1356
|
},
|
|
1300
1357
|
eslintConfig: {
|
|
1301
1358
|
root: true,
|
|
@@ -1448,3 +1505,4 @@ exports.transformTys = transformTys;
|
|
|
1448
1505
|
exports.twox128 = twox128;
|
|
1449
1506
|
exports.twox256 = twox256;
|
|
1450
1507
|
exports.twox64Concat = twox64Concat;
|
|
1508
|
+
exports.watCryptoWaitReady = watCryptoWaitReady;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var util = require('@talismn/util');
|
|
6
|
+
var wasmFeatureDetect = require('wasm-feature-detect');
|
|
6
7
|
var $ = require('@talismn/subshape-fork');
|
|
7
8
|
var anylogger = require('anylogger');
|
|
8
9
|
|
|
@@ -29,6 +30,56 @@ function _interopNamespace(e) {
|
|
|
29
30
|
var $__namespace = /*#__PURE__*/_interopNamespace($);
|
|
30
31
|
var anylogger__default = /*#__PURE__*/_interopDefault(anylogger);
|
|
31
32
|
|
|
33
|
+
//
|
|
34
|
+
// The simd variants of these hash fns are faster, but some devices don't support them.
|
|
35
|
+
//
|
|
36
|
+
// This file re-exports the faster fns from `./simd` for devices which support them,
|
|
37
|
+
// and falls back to `./nosimd` re-exports for devices which do not.
|
|
38
|
+
//
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
let Blake2b;
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
let Xxhash;
|
|
43
|
+
let readyPromise = null;
|
|
44
|
+
const watCryptoWaitReady = async () => {
|
|
45
|
+
// if this is the second/third/etc time we've called watCryptoWaitReady,
|
|
46
|
+
// then get a reference to the existing promise and wait for it to resolve/reject
|
|
47
|
+
if (readyPromise !== null) return await readyPromise;
|
|
48
|
+
|
|
49
|
+
// if this is the first time we've called watCryptoWaitReady,
|
|
50
|
+
// then create and return a new promise
|
|
51
|
+
const deferred = util.Deferred();
|
|
52
|
+
readyPromise = deferred.promise
|
|
53
|
+
|
|
54
|
+
// spawn a task to initialize the fns and resolve the readyPromise
|
|
55
|
+
;
|
|
56
|
+
(async () => {
|
|
57
|
+
try {
|
|
58
|
+
// initialize simd or nosimd, based on wasm feature detection
|
|
59
|
+
if (await wasmFeatureDetect.simd()) {
|
|
60
|
+
// system supports wasm simd
|
|
61
|
+
const imported = await Promise.resolve().then(function () { return require('./simd-133b8f48.cjs.prod.js'); });
|
|
62
|
+
Blake2b = imported.Blake2b;
|
|
63
|
+
Xxhash = imported.Xxhash;
|
|
64
|
+
} else {
|
|
65
|
+
// system does not support wasm simd
|
|
66
|
+
const imported = await Promise.resolve().then(function () { return require('./nosimd-3e5ed5a9.cjs.prod.js'); });
|
|
67
|
+
Blake2b = imported.Blake2b;
|
|
68
|
+
Xxhash = imported.Xxhash;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// feature detection and loading complete
|
|
72
|
+
deferred.resolve();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// feature detection and loading failed
|
|
75
|
+
deferred.reject(error);
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
// wait for the promise to resolve/reject
|
|
80
|
+
return await readyPromise;
|
|
81
|
+
};
|
|
82
|
+
|
|
32
83
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
33
84
|
// This module is browser compatible.
|
|
34
85
|
|
|
@@ -199,7 +250,7 @@ function encodeRaw(prefix, payload, checksumLength) {
|
|
|
199
250
|
checksumLength ??= DEFAULT_PAYLOAD_CHECKSUM_LENGTHS[payload.length];
|
|
200
251
|
if (!checksumLength) throw new InvalidPayloadLengthError();
|
|
201
252
|
const prefixBytes = prefix < 64 ? Uint8Array.of(prefix) : Uint8Array.of((prefix & 0b0000_0000_1111_1100) >> 2 | 0b0100_0000, prefix >> 8 | (prefix & 0b0000_0000_0000_0011) << 6);
|
|
202
|
-
const hasher = new
|
|
253
|
+
const hasher = new Blake2b();
|
|
203
254
|
hasher.update(SS58PRE);
|
|
204
255
|
hasher.update(prefixBytes);
|
|
205
256
|
hasher.update(payload);
|
|
@@ -223,7 +274,7 @@ function decodeRaw(address) {
|
|
|
223
274
|
if (!checksumLength) throw new InvalidAddressLengthError();
|
|
224
275
|
const prefixLength = address[0] & 0b0100_0000 ? 2 : 1;
|
|
225
276
|
const prefix = prefixLength === 1 ? address[0] : (address[0] & 0b0011_1111) << 2 | address[1] >> 6 | (address[1] & 0b0011_1111) << 8;
|
|
226
|
-
const hasher = new
|
|
277
|
+
const hasher = new Blake2b();
|
|
227
278
|
hasher.update(SS58PRE);
|
|
228
279
|
hasher.update(address.subarray(0, address.length - checksumLength));
|
|
229
280
|
const digest = hasher.digest();
|
|
@@ -361,7 +412,7 @@ class Blake2Hasher extends Hasher {
|
|
|
361
412
|
this.digestLength = size / 8;
|
|
362
413
|
}
|
|
363
414
|
create() {
|
|
364
|
-
return new
|
|
415
|
+
return new Blake2b(this.digestLength);
|
|
365
416
|
}
|
|
366
417
|
}
|
|
367
418
|
class IdentityHasher extends Hasher {
|
|
@@ -388,7 +439,7 @@ class TwoxHasher extends Hasher {
|
|
|
388
439
|
this.rounds = size / 64;
|
|
389
440
|
}
|
|
390
441
|
create() {
|
|
391
|
-
return new
|
|
442
|
+
return new Xxhash(this.rounds);
|
|
392
443
|
}
|
|
393
444
|
}
|
|
394
445
|
const blake2_64 = new Blake2Hasher(64, false);
|
|
@@ -1258,7 +1309,7 @@ class SignerError extends Error {
|
|
|
1258
1309
|
|
|
1259
1310
|
var packageJson = {
|
|
1260
1311
|
name: "@talismn/scale",
|
|
1261
|
-
version: "0.0.0-pr997-
|
|
1312
|
+
version: "0.0.0-pr997-20231115151657",
|
|
1262
1313
|
author: "Talisman",
|
|
1263
1314
|
homepage: "https://talisman.xyz",
|
|
1264
1315
|
license: "GPL-3.0-or-later",
|
|
@@ -1285,17 +1336,23 @@ var packageJson = {
|
|
|
1285
1336
|
},
|
|
1286
1337
|
dependencies: {
|
|
1287
1338
|
"@talismn/subshape-fork": "^0.0.1",
|
|
1339
|
+
"@talismn/util": "workspace:*",
|
|
1288
1340
|
anylogger: "^1.0.11",
|
|
1341
|
+
"wasm-feature-detect": "^1.6.0",
|
|
1289
1342
|
"wat-the-crypto": "^0.0.3"
|
|
1290
1343
|
},
|
|
1291
1344
|
devDependencies: {
|
|
1345
|
+
"@polkadot/util-crypto": "^11.1.1",
|
|
1292
1346
|
"@talismn/eslint-config": "workspace:*",
|
|
1293
1347
|
"@talismn/tsconfig": "workspace:*",
|
|
1294
1348
|
"@types/jest": "^27.5.1",
|
|
1295
|
-
eslint: "^8.
|
|
1296
|
-
jest: "^
|
|
1297
|
-
"ts-jest": "^
|
|
1298
|
-
typescript: "^
|
|
1349
|
+
eslint: "^8.52.0",
|
|
1350
|
+
jest: "^29.7",
|
|
1351
|
+
"ts-jest": "^29.1.1",
|
|
1352
|
+
typescript: "^5.2.2"
|
|
1353
|
+
},
|
|
1354
|
+
peerDependencies: {
|
|
1355
|
+
"@polkadot/util-crypto": "^11.x"
|
|
1299
1356
|
},
|
|
1300
1357
|
eslintConfig: {
|
|
1301
1358
|
root: true,
|
|
@@ -1448,3 +1505,4 @@ exports.transformTys = transformTys;
|
|
|
1448
1505
|
exports.twox128 = twox128;
|
|
1449
1506
|
exports.twox256 = twox256;
|
|
1450
1507
|
exports.twox64Concat = twox64Concat;
|
|
1508
|
+
exports.watCryptoWaitReady = watCryptoWaitReady;
|
|
@@ -1,8 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Deferred } from '@talismn/util';
|
|
2
|
+
import { simd } from 'wasm-feature-detect';
|
|
2
3
|
import * as $ from '@talismn/subshape-fork';
|
|
3
4
|
import { EncodeBuffer } from '@talismn/subshape-fork';
|
|
4
5
|
import anylogger from 'anylogger';
|
|
5
6
|
|
|
7
|
+
//
|
|
8
|
+
// The simd variants of these hash fns are faster, but some devices don't support them.
|
|
9
|
+
//
|
|
10
|
+
// This file re-exports the faster fns from `./simd` for devices which support them,
|
|
11
|
+
// and falls back to `./nosimd` re-exports for devices which do not.
|
|
12
|
+
//
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
let Blake2b;
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
let Xxhash;
|
|
17
|
+
let readyPromise = null;
|
|
18
|
+
const watCryptoWaitReady = async () => {
|
|
19
|
+
// if this is the second/third/etc time we've called watCryptoWaitReady,
|
|
20
|
+
// then get a reference to the existing promise and wait for it to resolve/reject
|
|
21
|
+
if (readyPromise !== null) return await readyPromise;
|
|
22
|
+
|
|
23
|
+
// if this is the first time we've called watCryptoWaitReady,
|
|
24
|
+
// then create and return a new promise
|
|
25
|
+
const deferred = Deferred();
|
|
26
|
+
readyPromise = deferred.promise
|
|
27
|
+
|
|
28
|
+
// spawn a task to initialize the fns and resolve the readyPromise
|
|
29
|
+
;
|
|
30
|
+
(async () => {
|
|
31
|
+
try {
|
|
32
|
+
// initialize simd or nosimd, based on wasm feature detection
|
|
33
|
+
if (await simd()) {
|
|
34
|
+
// system supports wasm simd
|
|
35
|
+
const imported = await import('./simd-b794dbff.esm.js');
|
|
36
|
+
Blake2b = imported.Blake2b;
|
|
37
|
+
Xxhash = imported.Xxhash;
|
|
38
|
+
} else {
|
|
39
|
+
// system does not support wasm simd
|
|
40
|
+
const imported = await import('./nosimd-20b5b0ca.esm.js');
|
|
41
|
+
Blake2b = imported.Blake2b;
|
|
42
|
+
Xxhash = imported.Xxhash;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// feature detection and loading complete
|
|
46
|
+
deferred.resolve();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
// feature detection and loading failed
|
|
49
|
+
deferred.reject(error);
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
|
|
53
|
+
// wait for the promise to resolve/reject
|
|
54
|
+
return await readyPromise;
|
|
55
|
+
};
|
|
56
|
+
|
|
6
57
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
7
58
|
// This module is browser compatible.
|
|
8
59
|
|
|
@@ -1232,7 +1283,7 @@ class SignerError extends Error {
|
|
|
1232
1283
|
|
|
1233
1284
|
var packageJson = {
|
|
1234
1285
|
name: "@talismn/scale",
|
|
1235
|
-
version: "0.0.0-pr997-
|
|
1286
|
+
version: "0.0.0-pr997-20231115151657",
|
|
1236
1287
|
author: "Talisman",
|
|
1237
1288
|
homepage: "https://talisman.xyz",
|
|
1238
1289
|
license: "GPL-3.0-or-later",
|
|
@@ -1259,17 +1310,23 @@ var packageJson = {
|
|
|
1259
1310
|
},
|
|
1260
1311
|
dependencies: {
|
|
1261
1312
|
"@talismn/subshape-fork": "^0.0.1",
|
|
1313
|
+
"@talismn/util": "workspace:*",
|
|
1262
1314
|
anylogger: "^1.0.11",
|
|
1315
|
+
"wasm-feature-detect": "^1.6.0",
|
|
1263
1316
|
"wat-the-crypto": "^0.0.3"
|
|
1264
1317
|
},
|
|
1265
1318
|
devDependencies: {
|
|
1319
|
+
"@polkadot/util-crypto": "^11.1.1",
|
|
1266
1320
|
"@talismn/eslint-config": "workspace:*",
|
|
1267
1321
|
"@talismn/tsconfig": "workspace:*",
|
|
1268
1322
|
"@types/jest": "^27.5.1",
|
|
1269
|
-
eslint: "^8.
|
|
1270
|
-
jest: "^
|
|
1271
|
-
"ts-jest": "^
|
|
1272
|
-
typescript: "^
|
|
1323
|
+
eslint: "^8.52.0",
|
|
1324
|
+
jest: "^29.7",
|
|
1325
|
+
"ts-jest": "^29.1.1",
|
|
1326
|
+
typescript: "^5.2.2"
|
|
1327
|
+
},
|
|
1328
|
+
peerDependencies: {
|
|
1329
|
+
"@polkadot/util-crypto": "^11.x"
|
|
1273
1330
|
},
|
|
1274
1331
|
eslintConfig: {
|
|
1275
1332
|
root: true,
|
|
@@ -1378,4 +1435,4 @@ addedTypes = new Set()) => {
|
|
|
1378
1435
|
}
|
|
1379
1436
|
};
|
|
1380
1437
|
|
|
1381
|
-
export { $emptyKey, $era, $extrinsic, $field, $hash, $metadataV14, $null, $partialEmptyKey, $partialMultiKey, $partialSingleKey, $primitiveKind, $storageKey, $ty, $tyDef, $tyId, Blake2Hasher, DecodeNonTransparentKeyError, Era, Hasher, IdentityHasher, SignerError, TwoxHasher, addDependentTypes, blake2_128, blake2_128Concat, blake2_256, blake2_512, blake2_64, decodeMetadata, filterMetadataPalletsAndItems, getOrInit, identity, normalizeDocs, normalizeIdent, normalizePackageName, normalizeTypeName, normalizeVariableName, ss58, stringifyKey, stringifyPropertyAccess, transformMetadata as transformMetadataV14, transformTys, twox128, twox256, twox64Concat };
|
|
1438
|
+
export { $emptyKey, $era, $extrinsic, $field, $hash, $metadataV14, $null, $partialEmptyKey, $partialMultiKey, $partialSingleKey, $primitiveKind, $storageKey, $ty, $tyDef, $tyId, Blake2Hasher, DecodeNonTransparentKeyError, Era, Hasher, IdentityHasher, SignerError, TwoxHasher, addDependentTypes, blake2_128, blake2_128Concat, blake2_256, blake2_512, blake2_64, decodeMetadata, filterMetadataPalletsAndItems, getOrInit, identity, normalizeDocs, normalizeIdent, normalizePackageName, normalizeTypeName, normalizeVariableName, ss58, stringifyKey, stringifyPropertyAccess, transformMetadata as transformMetadataV14, transformTys, twox128, twox256, twox64Concat, watCryptoWaitReady };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/scale",
|
|
3
|
-
"version": "0.0.0-pr997-
|
|
3
|
+
"version": "0.0.0-pr997-20231115151657",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -27,17 +27,23 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@talismn/subshape-fork": "^0.0.1",
|
|
30
|
+
"@talismn/util": "0.0.0-pr997-20231115151657",
|
|
30
31
|
"anylogger": "^1.0.11",
|
|
32
|
+
"wasm-feature-detect": "^1.6.0",
|
|
31
33
|
"wat-the-crypto": "^0.0.3"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"@
|
|
36
|
+
"@polkadot/util-crypto": "^11.1.1",
|
|
37
|
+
"@talismn/eslint-config": "0.0.0-pr997-20231115151657",
|
|
35
38
|
"@talismn/tsconfig": "0.0.2",
|
|
36
39
|
"@types/jest": "^27.5.1",
|
|
37
|
-
"eslint": "^8.
|
|
38
|
-
"jest": "^
|
|
39
|
-
"ts-jest": "^
|
|
40
|
-
"typescript": "^
|
|
40
|
+
"eslint": "^8.52.0",
|
|
41
|
+
"jest": "^29.7",
|
|
42
|
+
"ts-jest": "^29.1.1",
|
|
43
|
+
"typescript": "^5.2.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@polkadot/util-crypto": "^11.x"
|
|
41
47
|
},
|
|
42
48
|
"eslintConfig": {
|
|
43
49
|
"root": true,
|