x-bigint package (#1274)

* x-bigint package

* x-bigint in has*

* 8.0.6-8

* Adjust

* Adjust

* jest config

* Adjust

* Remove commented code

* Update README

* CHANGELOG
This commit is contained in:
Jaco
2021-12-02 07:29:44 +02:00
committed by GitHub
parent 4a69486993
commit b1f9c37f6a
29 changed files with 183 additions and 137 deletions
+2
View File
@@ -8,6 +8,8 @@ Contributed:
Changes:
- Adjust `isBigInt` to not do `instanceof` check
- Use `@polkadot/x-bigint` for `BigInt` constructor
- Ensure consequtive capitals in `stringCamelCase` are lowercased
+1 -1
View File
@@ -13,8 +13,8 @@ module.exports = Object.assign({}, config, {
'@polkadot/util-(crypto)(.*)$': '<rootDir>/packages/util-$1/src/$2',
// eslint-disable-next-line sort-keys
'@polkadot/util(.*)$': '<rootDir>/packages/util/src/$1',
'@polkadot/x-(bigint|global)(.*)$': '<rootDir>/packages/x-$1/src/$2',
'@polkadot/x-(fetch|randomvalues|textdecoder|textencoder|ws)(.*)$': '<rootDir>/packages/x-$1/src/node',
'@polkadot/x-global(.*)$': '<rootDir>/packages/x-global/src/$1',
'@polkadot/x-noble-hashes(.*)$': '<rootDir>/packages/x-noble-hashes/src/$1'
}
});
+1
View File
@@ -34,6 +34,7 @@
"@polkadot/networks": "8.0.6-8",
"@polkadot/util": "8.0.6-8",
"@polkadot/wasm-crypto": "^4.4.1",
"@polkadot/x-bigint": "8.0.6-8",
"@polkadot/x-noble-hashes": "8.0.6-8",
"@polkadot/x-randomvalues": "8.0.6-8",
"bn.js": "^4.12.0",
-7
View File
@@ -1,15 +1,8 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// import { xglobal } from '@polkadot/x-global';
import { cryptoWaitReady } from './crypto';
// This would not be a great idea since it would poluse the global namespace
// if (typeof BigInt !== 'function' || typeof BigInt.asIntN !== 'function') {
// (xglobal as Record<string, unknown>).BigInt = () => Number.NaN;
// }
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
+25 -24
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { _0n, _1n, _n } from '@polkadot/util';
import { _0n, _1n } from '@polkadot/util';
import { BigInt } from '@polkadot/x-bigint';
// Adapted from https://github.com/pierrec/js-xxhash/blob/0504e76f3d31a21ae8528a7f590c7289c9e431d2/lib/xxhash64.js
//
@@ -26,29 +27,29 @@ interface State {
v4: bigint;
}
const P64_1 = _n('11400714785074694791');
const P64_2 = _n('14029467366897019727');
const P64_3 = _n('1609587929392839161');
const P64_4 = _n('9650029242287828579');
const P64_5 = _n('2870177450012600261');
const P64_1 = BigInt('11400714785074694791');
const P64_2 = BigInt('14029467366897019727');
const P64_3 = BigInt('1609587929392839161');
const P64_4 = BigInt('9650029242287828579');
const P64_5 = BigInt('2870177450012600261');
// mask for a u64, all bits set
const U64 = _n('0xffffffffffffffff');
const U64 = BigInt('0xffffffffffffffff');
// various constants
const _7n = _n(7);
const _11n = _n(11);
const _12n = _n(12);
const _16n = _n(16);
const _18n = _n(18);
const _23n = _n(23);
const _27n = _n(27);
const _29n = _n(29);
const _31n = _n(31);
const _32n = _n(32);
const _33n = _n(33);
const _64n = _n(64);
const _256n = _n(256);
const _7n = BigInt(7);
const _11n = BigInt(11);
const _12n = BigInt(12);
const _16n = BigInt(16);
const _18n = BigInt(18);
const _23n = BigInt(23);
const _27n = BigInt(27);
const _29n = BigInt(29);
const _31n = BigInt(31);
const _32n = BigInt(32);
const _33n = BigInt(33);
const _64n = BigInt(64);
const _256n = BigInt(256);
function rotl (a: bigint, b: bigint): bigint {
const c = a & U64;
@@ -61,7 +62,7 @@ function fromU8a (u8a: Uint8Array, p: number, count: 2 | 4): bigint {
let offset = 0;
for (let i = 0; i < count; i++, offset += 2) {
bigints[i] = _n(u8a[p + offset] | (u8a[p + 1 + offset] << 8));
bigints[i] = BigInt(u8a[p + offset] | (u8a[p + 1 + offset] << 8));
}
let result = _0n;
@@ -86,7 +87,7 @@ function toU8a (h64: bigint): Uint8Array {
}
function state (initSeed: bigint | number): State {
const seed = _n(initSeed);
const seed = BigInt(initSeed);
return {
seed,
@@ -133,7 +134,7 @@ function init (state: State, input: Uint8Array): State {
export function xxhash64 (input: Uint8Array, initSeed: bigint | number): Uint8Array {
const { seed, u8a, u8asize, v1, v2, v3, v4 } = init(state(initSeed), input);
let p = 0;
let h64 = U64 & (_n(input.length) + (
let h64 = U64 & (BigInt(input.length) + (
input.length >= 32
? (((((((((rotl(v1, _1n) + rotl(v2, _7n) + rotl(v3, _12n) + rotl(v4, _18n)) ^ (P64_1 * rotl(v1 * P64_2, _31n))) * P64_1 + P64_4) ^ (P64_1 * rotl(v2 * P64_2, _31n))) * P64_1 + P64_4) ^ (P64_1 * rotl(v3 * P64_2, _31n))) * P64_1 + P64_4) ^ (P64_1 * rotl(v4 * P64_2, _31n))) * P64_1 + P64_4)
: (seed + P64_5)
@@ -150,7 +151,7 @@ export function xxhash64 (input: Uint8Array, initSeed: bigint | number): Uint8Ar
}
while (p < u8asize) {
h64 = U64 & (P64_1 * rotl(h64 ^ (P64_5 * _n(u8a[p++])), _11n));
h64 = U64 & (P64_1 * rotl(h64 ^ (P64_5 * BigInt(u8a[p++])), _11n));
}
h64 = U64 & (P64_2 * (h64 ^ (h64 >> _33n)));
+1
View File
@@ -38,6 +38,7 @@
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.16.3",
"@polkadot/x-bigint": "8.0.6-8",
"@polkadot/x-global": "8.0.6-8",
"@polkadot/x-textdecoder": "8.0.6-8",
"@polkadot/x-textencoder": "8.0.6-8",
+6 -18
View File
@@ -1,43 +1,31 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { xglobal } from '@polkadot/x-global';
import { hasBigInt } from '../has';
/**
* @name _n
* @description Creates a new instance of BigInt in environments that do support it
*/
export function _n (n: string | number | bigint | boolean): bigint {
return hasBigInt
? xglobal.BigInt(n)
: Number.NaN as unknown as bigint;
}
import { BigInt } from '@polkadot/x-bigint';
/**
* @name _0n
* @summary BigInt constant for 0.
*/
export const _0n = _n(0);
export const _0n = BigInt(0);
/**
* @name _1n
* @summary BigInt constant for 1.
*/
export const _1n = _n(1);
export const _1n = BigInt(1);
/**
* @name _1Mn
* @summary BigInt constant for 1,000,000.
*/
export const _1Mn = _n(1_000_000);
export const _1Mn = BigInt(1_000_000);
/**
* @name _1Bn
* @summary BigInt constant for 1,000,000,000.
*/
export const _1Bn = _n(1_000_000_000);
export const _1Bn = BigInt(1_000_000_000);
/**
* @name _1Qn
@@ -49,4 +37,4 @@ export const _1Qn = _1Bn * _1Bn;
* @name _2pow53n
* @summary BigInt constant for MAX_SAFE_INTEGER
*/
export const _2pow53n = _n(Number.MAX_SAFE_INTEGER);
export const _2pow53n = BigInt(Number.MAX_SAFE_INTEGER);
+4 -2
View File
@@ -4,11 +4,13 @@
import type { BN } from '../bn';
import type { ToBigInt, ToBn } from '../types';
import { BigInt } from '@polkadot/x-bigint';
import { assert } from '../assert';
import { _0n, _1n, _2pow53n, _n } from './consts';
import { _0n, _1n, _2pow53n } from './consts';
import { nToBigInt } from './toBigInt';
const _sqrt2pow53n = _n(94906265);
const _sqrt2pow53n = BigInt(94906265);
/**
* @name nSqrt
+6 -5
View File
@@ -4,7 +4,8 @@
import type { BN } from '../bn/bn';
import type { HexString, ToBigInt, ToBn } from '../types';
import { _n } from '../bi/consts';
import { BigInt } from '@polkadot/x-bigint';
import { hexToBigInt } from '../hex/toBigInt';
import { isBn } from '../is/bn';
import { isHex } from '../is/hex';
@@ -19,14 +20,14 @@ export function nToBigInt <ExtToBn extends ToBigInt | ToBn> (value?: HexString |
return typeof value === 'bigint'
? value
: !value
? _n(0)
? BigInt(0)
: isHex(value)
? hexToBigInt(value.toString())
: isBn(value)
? _n(value.toString())
? BigInt(value.toString())
: isToBigInt(value)
? value.toBigInt()
: isToBn(value)
? _n(value.toBn().toString())
: _n(value);
? BigInt(value.toBn().toString())
: BigInt(value);
}
+5 -3
View File
@@ -4,16 +4,18 @@
import type { BN } from '../bn/bn';
import type { ToBigInt, ToBn, ToBnOptions } from '../types';
import { BigInt } from '@polkadot/x-bigint';
import { objectSpread } from '../object/spread';
import { _0n, _1n, _n } from './consts';
import { _0n, _1n } from './consts';
import { nToBigInt } from './toBigInt';
interface Options extends ToBnOptions {
bitLength?: number;
}
const DIV = _n(256);
const NEG_MASK = _n(0xff);
const DIV = BigInt(256);
const NEG_MASK = BigInt(0xff);
function createEmpty ({ bitLength = 0 }: Options): Uint8Array {
return bitLength === -1
+2 -2
View File
@@ -1,9 +1,9 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { xglobal } from '@polkadot/x-global';
import { BigInt } from '@polkadot/x-bigint';
export const hasBigInt = typeof xglobal.BigInt === 'function' && typeof xglobal.BigInt.asIntN === 'function';
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
export const hasBuffer = typeof Buffer !== 'undefined';
export const hasDirname = typeof __dirname !== 'undefined';
export const hasProcess = typeof process === 'object';
+3 -2
View File
@@ -3,7 +3,8 @@
import type { ToBnOptions } from '../types';
import { _n } from '../bi/consts';
import { BigInt } from '@polkadot/x-bigint';
import { objectSpread } from '../object/spread';
import { u8aToBigInt } from '../u8a/toBigInt';
import { hexToU8a } from './toU8a';
@@ -14,7 +15,7 @@ import { hexToU8a } from './toU8a';
*/
export function hexToBigInt (value?: string | null, options: ToBnOptions = {}): bigint {
if (!value || value === '0x') {
return _n(0);
return BigInt(0);
}
return u8aToBigInt(
+9 -7
View File
@@ -3,11 +3,13 @@
import type { ToBnOptions } from '../types';
import { _1n, _n } from '../bi/consts';
import { BigInt } from '@polkadot/x-bigint';
import { _1n } from '../bi/consts';
import { objectSpread } from '../object/spread';
const U8_MAX = _n(256);
const U16_MAX = _n(256 * 256);
const U8_MAX = BigInt(256);
const U16_MAX = BigInt(256 * 256);
function xor (input: Uint8Array): Uint8Array {
const result = new Uint8Array(input.length);
@@ -31,14 +33,14 @@ function toBigInt (input: Uint8Array): bigint {
const dvI = new DataView(input.buffer, input.byteOffset);
const mod = input.length % 2;
const length = input.length - mod;
let result = _n(0);
let result = BigInt(0);
for (let i = 0; i < length; i += 2) {
result = (result * U16_MAX) + _n(dvI.getUint16(i));
result = (result * U16_MAX) + BigInt(dvI.getUint16(i));
}
if (mod) {
result = (result * U8_MAX) + _n(dvI.getUint8(length));
result = (result * U8_MAX) + BigInt(dvI.getUint8(length));
}
return result;
@@ -50,7 +52,7 @@ function toBigInt (input: Uint8Array): bigint {
*/
export function u8aToBigInt (value: Uint8Array, options: ToBnOptions = {}): bigint {
if (!value || !value.length) {
return _n(0);
return BigInt(0);
}
const { isLe, isNegative }: ToBnOptions = objectSpread({ isLe: true, isNegative: false }, options);
+3
View File
@@ -0,0 +1,3 @@
# @polkadot/x-bigint
A cross-environment BigInt.
+25
View File
@@ -0,0 +1,25 @@
{
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A cross-environment BigInt replacement",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-bigint#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-bigint",
"repository": {
"directory": "packages/x-bigint",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "8.0.6-8",
"dependencies": {
"@babel/runtime": "^7.16.3",
"@polkadot/x-global": "8.0.6-8"
}
}
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2017-2021 @polkadot/x-ws authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { xglobal } from '@polkadot/x-global';
export { packageInfo } from './packageInfo';
export const BigInt: BigIntConstructor = typeof xglobal.BigInt === 'function' && typeof xglobal.BigInt.asIntN === 'function'
? xglobal.BigInt
: (() => Number.NaN) as unknown as BigIntConstructor;
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/x-bigint authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-bigint', version: '8.0.6-8' };
+8 -1
View File
@@ -17,5 +17,12 @@
},
"sideEffects": false,
"type": "module",
"version": "8.0.6-8"
"version": "8.0.6-8",
"browser": {
"crypto": false
},
"dependencies": {
"@babel/runtime": "^7.16.3",
"@polkadot/x-bigint": "8.0.6-8"
}
}
+5 -4
View File
@@ -1,9 +1,10 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { _n, Hash, createView, Input, toBytes } from './utils';
import { BigInt } from '@polkadot/x-bigint';
import { Hash, createView, Input, toBytes } from './utils';
const _32n = _n(32);
const _u32_max = _n(0xffffffff);
const _32n = BigInt(32);
const _u32_max = BigInt(0xffffffff);
// Polyfill for Safari 14
function setBigUint64(view: DataView, byteOffset: number, value: bigint, isLE: boolean): void {
@@ -90,7 +91,7 @@ export abstract class SHA2<T extends SHA2<T>> extends Hash<T> {
// NOTE: sha512 requires length to be 128bit integer, but length in JS will overflow before that
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
// So we just write lowest 64bit of that value.
setBigUint64(view, blockLen - 8, _n(this.length * 8), isLE);
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
this.process(view, 0);
const oview = createView(out);
this.get().forEach((v, i) => oview.setUint32(4 * i, v, isLE));
+4 -4
View File
@@ -1,10 +1,10 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { _n } from './utils';
import { BigInt } from '@polkadot/x-bigint';
const U32_MASK64 = _n(2 ** 32 - 1);
const U32_MASK64 = BigInt(2 ** 32 - 1);
const _32n = _n(32);
const _32n = BigInt(32);
export function fromBig(n: bigint, le = false) {
if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
@@ -20,7 +20,7 @@ export function split(lst: bigint[], le = false) {
return [Ah, Al];
}
export const toBig = (h: number, l: number) => (_n(h >>> 0) << _32n) | _n(l >>> 0);
export const toBig = (h: number, l: number) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
// for Shift in [0, 32)
export const shrSH = (h: number, l: number, s: number) => h >>> s;
export const shrSL = (h: number, l: number, s: number) => (h << (32 - s)) | (l >>> s);
+3 -2
View File
@@ -1,8 +1,9 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { BigInt } from '@polkadot/x-bigint';
import * as blake2 from './_blake2';
import * as u64 from './_u64';
import { _n, toBytes, u32, wrapConstructorWithOpts } from './utils';
import { toBytes, u32, wrapConstructorWithOpts } from './utils';
// Same as SHA-512 but LE
// prettier-ignore
@@ -143,7 +144,7 @@ class BLAKE2b extends blake2.BLAKE2<BLAKE2b> {
protected compress(msg: Uint32Array, offset: number, isLast: boolean) {
this.get().forEach((v, i) => (BUF[i] = v)); // First half from state.
BUF.set(IV, 16); // Second half from IV.
let { h, l } = u64.fromBig(_n(this.length));
let { h, l } = u64.fromBig(BigInt(this.length));
BUF[24] = IV[8] ^ l; // Low word of the offset.
BUF[25] = IV[9] ^ h; // High word.
// Invert all bits for last block
+3 -2
View File
@@ -1,8 +1,9 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { BigInt } from '@polkadot/x-bigint';
import * as u64 from './_u64';
import * as blake2 from './_blake2';
import { _n, rotr, toBytes, wrapConstructorWithOpts, u32 } from './utils';
import { rotr, toBytes, wrapConstructorWithOpts, u32 } from './utils';
// Initial state:
// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19)
@@ -106,7 +107,7 @@ class BLAKE2s extends blake2.BLAKE2<BLAKE2s> {
this.v7 = v7 | 0;
}
protected compress(msg: Uint32Array, offset: number, isLast: boolean) {
const { h, l } = u64.fromBig(_n(this.length));
const { h, l } = u64.fromBig(BigInt(this.length));
// prettier-ignore
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } =
compress(
+4 -3
View File
@@ -1,9 +1,10 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { BigInt } from '@polkadot/x-bigint';
import * as u64 from './_u64';
import * as blake2 from './_blake2';
import * as blake2s from './blake2s';
import { _n, Input, u8, u32, toBytes, wrapConstructorWithOpts, assertNumber, HashXOF } from './utils';
import { Input, u8, u32, toBytes, wrapConstructorWithOpts, assertNumber, HashXOF } from './utils';
// Flag bitset
enum Flags {
@@ -84,7 +85,7 @@ class BLAKE3 extends blake2.BLAKE2<BLAKE3> implements HashXOF<BLAKE3> {
protected set() {}
private b2Compress(counter: number, flags: number, buf: Uint32Array, bufPos: number = 0) {
const { state, pos } = this;
const { h, l } = u64.fromBig(_n(counter), true);
const { h, l } = u64.fromBig(BigInt(counter), true);
// prettier-ignore
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } =
blake2s.compress(
@@ -160,7 +161,7 @@ class BLAKE3 extends blake2.BLAKE2<BLAKE3> implements HashXOF<BLAKE3> {
// Same as b2Compress, but doesn't modify state and returns 16 u32 array (instead of 8)
private b2CompressOut() {
const { state, pos, flags, buffer32, bufferOut32 } = this;
const { h, l } = u64.fromBig(_n(this.chunkOut++));
const { h, l } = u64.fromBig(BigInt(this.chunkOut++));
// prettier-ignore
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } =
blake2s.compress(
+8 -8
View File
@@ -1,8 +1,8 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { BigInt } from '@polkadot/x-bigint';
import * as u64 from './_u64';
import {
_n,
Hash,
u32,
Input,
@@ -13,12 +13,12 @@ import {
HashXOF,
} from './utils';
const _0n = _n(0);
const _1n = _n(1);
const _2n = _n(2);
const _7n = _n(7);
const _256n = _n(256);
const _0x71n = _n(0x71);
const _0n = BigInt(0);
const _1n = BigInt(1);
const _2n = BigInt(2);
const _7n = BigInt(7);
const _256n = BigInt(256);
const _0x71n = BigInt(0x71);
// Various per round constants calculations
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA]: [number[], number[], bigint[]] = [[], [], []];
@@ -32,7 +32,7 @@ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
let t = _0n;
for (let j = 0; j < 7; j++) {
R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
if (R & _2n) t ^= _1n << ((_1n << _n(j)) - _1n);
if (R & _2n) t ^= _1n << ((_1n << BigInt(j)) - _1n);
}
_SHA3_IOTA.push(t);
}
+23 -22
View File
@@ -1,33 +1,34 @@
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
// https://github.com/paulmillr/noble-hashes/pull/13
import { BigInt } from '@polkadot/x-bigint';
import { SHA2 } from './_sha2';
import * as u64 from './_u64';
import { _n, wrapConstructor } from './utils';
import { wrapConstructor } from './utils';
// Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
// prettier-ignore
const [SHA512_Kh, SHA512_Kl] = u64.split([
_n('0x428a2f98d728ae22'), _n('0x7137449123ef65cd'), _n('0xb5c0fbcfec4d3b2f'), _n('0xe9b5dba58189dbbc'),
_n('0x3956c25bf348b538'), _n('0x59f111f1b605d019'), _n('0x923f82a4af194f9b'), _n('0xab1c5ed5da6d8118'),
_n('0xd807aa98a3030242'), _n('0x12835b0145706fbe'), _n('0x243185be4ee4b28c'), _n('0x550c7dc3d5ffb4e2'),
_n('0x72be5d74f27b896f'), _n('0x80deb1fe3b1696b1'), _n('0x9bdc06a725c71235'), _n('0xc19bf174cf692694'),
_n('0xe49b69c19ef14ad2'), _n('0xefbe4786384f25e3'), _n('0x0fc19dc68b8cd5b5'), _n('0x240ca1cc77ac9c65'),
_n('0x2de92c6f592b0275'), _n('0x4a7484aa6ea6e483'), _n('0x5cb0a9dcbd41fbd4'), _n('0x76f988da831153b5'),
_n('0x983e5152ee66dfab'), _n('0xa831c66d2db43210'), _n('0xb00327c898fb213f'), _n('0xbf597fc7beef0ee4'),
_n('0xc6e00bf33da88fc2'), _n('0xd5a79147930aa725'), _n('0x06ca6351e003826f'), _n('0x142929670a0e6e70'),
_n('0x27b70a8546d22ffc'), _n('0x2e1b21385c26c926'), _n('0x4d2c6dfc5ac42aed'), _n('0x53380d139d95b3df'),
_n('0x650a73548baf63de'), _n('0x766a0abb3c77b2a8'), _n('0x81c2c92e47edaee6'), _n('0x92722c851482353b'),
_n('0xa2bfe8a14cf10364'), _n('0xa81a664bbc423001'), _n('0xc24b8b70d0f89791'), _n('0xc76c51a30654be30'),
_n('0xd192e819d6ef5218'), _n('0xd69906245565a910'), _n('0xf40e35855771202a'), _n('0x106aa07032bbd1b8'),
_n('0x19a4c116b8d2d0c8'), _n('0x1e376c085141ab53'), _n('0x2748774cdf8eeb99'), _n('0x34b0bcb5e19b48a8'),
_n('0x391c0cb3c5c95a63'), _n('0x4ed8aa4ae3418acb'), _n('0x5b9cca4f7763e373'), _n('0x682e6ff3d6b2b8a3'),
_n('0x748f82ee5defb2fc'), _n('0x78a5636f43172f60'), _n('0x84c87814a1f0ab72'), _n('0x8cc702081a6439ec'),
_n('0x90befffa23631e28'), _n('0xa4506cebde82bde9'), _n('0xbef9a3f7b2c67915'), _n('0xc67178f2e372532b'),
_n('0xca273eceea26619c'), _n('0xd186b8c721c0c207'), _n('0xeada7dd6cde0eb1e'), _n('0xf57d4f7fee6ed178'),
_n('0x06f067aa72176fba'), _n('0x0a637dc5a2c898a6'), _n('0x113f9804bef90dae'), _n('0x1b710b35131c471b'),
_n('0x28db77f523047d84'), _n('0x32caab7b40c72493'), _n('0x3c9ebe0a15c9bebc'), _n('0x431d67c49c100d4c'),
_n('0x4cc5d4becb3e42b6'), _n('0x597f299cfc657e2a'), _n('0x5fcb6fab3ad6faec'), _n('0x6c44198c4a475817')
]);
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
'0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
'0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
'0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
'0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
'0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
'0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
'0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
'0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
'0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
'0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
'0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
'0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
'0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
'0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
'0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
'0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
'0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
'0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
].map((n) => BigInt(n)));
// Temporary buffer, not used to store anything between runs
const SHA512_W_H = new Uint32Array(80);
-19
View File
@@ -5,25 +5,6 @@
export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
Uint16Array | Int16Array | Uint32Array | Int32Array;
const xglobal = (
typeof globalThis !== 'undefined'
? globalThis
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: this as unknown as typeof globalThis
);
// helper to protect against older bundlers
export function _n (n: string | number | bigint | boolean): bigint {
return typeof xglobal.BigInt === 'function' && typeof xglobal.BigInt.asIntN === 'function'
? xglobal.BigInt(n)
: Number.NaN as unknown as bigint;
}
// Cast array to different type
export const u8 = (arr: TypedArray) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
export const u32 = (arr: TypedArray) =>
+1 -1
View File
@@ -16,7 +16,7 @@ const external = [
...pkgs
];
const entries = ['hw-ledger-transports', 'networks', 'x-fetch', 'x-global', 'x-noble-hashes', 'x-randomvalues', 'x-textdecoder', 'x-textencoder', 'x-ws'].reduce((all, p) => ({
const entries = ['hw-ledger-transports', 'networks', 'x-bigint', 'x-fetch', 'x-global', 'x-noble-hashes', 'x-randomvalues', 'x-textdecoder', 'x-textencoder', 'x-ws'].reduce((all, p) => ({
...all,
[`@polkadot/${p}`]: path.resolve(process.cwd(), `packages/${p}/build`)
}), {});
+1
View File
@@ -20,6 +20,7 @@
"@polkadot/util": [ "packages/util/src" ],
"@polkadot/util/*": [ "packages/util/src/*" ],
"@polkadot/x-bundle/*": [ "packages/x-bundle/src/*" ],
"@polkadot/x-bigint": [ "packages/x-bigint/src" ],
"@polkadot/x-fetch": [ "packages/x-fetch/src/browser" ],
"@polkadot/x-global": [ "packages/x-global/src" ],
"@polkadot/x-noble-hashes/*": [ "packages/x-noble-hashes/src/*" ],
+14
View File
@@ -2095,6 +2095,7 @@ __metadata:
"@polkadot/networks": 8.0.6-8
"@polkadot/util": 8.0.6-8
"@polkadot/wasm-crypto": ^4.4.1
"@polkadot/x-bigint": 8.0.6-8
"@polkadot/x-noble-hashes": 8.0.6-8
"@polkadot/x-randomvalues": 8.0.6-8
"@types/bn.js": ^4.11.6
@@ -2115,6 +2116,7 @@ __metadata:
resolution: "@polkadot/util@workspace:packages/util"
dependencies:
"@babel/runtime": ^7.16.3
"@polkadot/x-bigint": 8.0.6-8
"@polkadot/x-global": 8.0.6-8
"@polkadot/x-textdecoder": 8.0.6-8
"@polkadot/x-textencoder": 8.0.6-8
@@ -2156,6 +2158,15 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/x-bigint@8.0.6-8, @polkadot/x-bigint@workspace:packages/x-bigint":
version: 0.0.0-use.local
resolution: "@polkadot/x-bigint@workspace:packages/x-bigint"
dependencies:
"@babel/runtime": ^7.16.3
"@polkadot/x-global": 8.0.6-8
languageName: unknown
linkType: soft
"@polkadot/x-bundle@workspace:packages/x-bundle":
version: 0.0.0-use.local
resolution: "@polkadot/x-bundle@workspace:packages/x-bundle"
@@ -2188,6 +2199,9 @@ __metadata:
"@polkadot/x-noble-hashes@8.0.6-8, @polkadot/x-noble-hashes@workspace:packages/x-noble-hashes":
version: 0.0.0-use.local
resolution: "@polkadot/x-noble-hashes@workspace:packages/x-noble-hashes"
dependencies:
"@babel/runtime": ^7.16.3
"@polkadot/x-bigint": 8.0.6-8
languageName: unknown
linkType: soft