Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39937bed29 | ||
|
|
3519d21d8e | ||
|
|
8b4dc01ae4 | ||
|
|
bb73f7ae41 | ||
|
|
e6a0f1e2fd | ||
|
|
e8af9b5a1e | ||
|
|
1606dfd9ca | ||
|
|
2fcf59eeb0 |
+2
-1
@@ -18,4 +18,5 @@
|
||||
7.0.2
|
||||
7.0.3
|
||||
7.1.2
|
||||
7.8.2
|
||||
7.8.2
|
||||
7.9.2
|
||||
@@ -1,5 +1,13 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 7.9.2 Nov 22, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix TS compiled definitions for `base*` types
|
||||
- Provide JS/Wasm interfaces for `hmacShaAsU8a`
|
||||
|
||||
|
||||
## 7.9.1 Nov 21, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.9.2' };
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/hw-ledger-transports": "7.9.1",
|
||||
"@polkadot/util": "7.9.1",
|
||||
"@polkadot/hw-ledger-transports": "7.9.2",
|
||||
"@polkadot/util": "7.9.2",
|
||||
"@zondax/ledger-substrate": "^0.18.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.9.2' };
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/util": "7.9.1",
|
||||
"@polkadot/util-crypto": "7.9.1"
|
||||
"@polkadot/util": "7.9.2",
|
||||
"@polkadot/util-crypto": "7.9.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "7.9.1",
|
||||
"@polkadot/util-crypto": "7.9.1"
|
||||
"@polkadot/util": "7.9.2",
|
||||
"@polkadot/util-crypto": "7.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '7.9.2' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "7.9.1",
|
||||
"@polkadot/x-fetch": "7.9.1"
|
||||
"@polkadot/util": "7.9.2",
|
||||
"@polkadot/x-fetch": "7.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '7.9.2' };
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/networks": "7.9.1",
|
||||
"@polkadot/util": "7.9.1",
|
||||
"@polkadot/wasm-crypto": "^4.3.1",
|
||||
"@polkadot/x-randomvalues": "7.9.1",
|
||||
"@polkadot/networks": "7.9.2",
|
||||
"@polkadot/util": "7.9.2",
|
||||
"@polkadot/wasm-crypto": "^4.4.1",
|
||||
"@polkadot/x-randomvalues": "7.9.2",
|
||||
"blakejs": "^1.1.1",
|
||||
"bn.js": "^4.12.0",
|
||||
"create-hash": "^1.2.0",
|
||||
@@ -51,6 +51,6 @@
|
||||
"@types/xxhashjs": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "7.9.1"
|
||||
"@polkadot/util": "7.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { U8aLike } from '@polkadot/util/types';
|
||||
|
||||
import { assert, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
// NOTE: Work around a TS issue. These are re-defined like in @polkadot/util/types
|
||||
// since without it the import
|
||||
//
|
||||
// import type { U8aLike } from '@polkadot/util/types';
|
||||
//
|
||||
// ends up in the build-generated code as
|
||||
//
|
||||
// import("../../../util/src/types").U8aLike
|
||||
//
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type U8aLike = number[] | Buffer | Uint8Array | string | String;
|
||||
|
||||
interface Coder {
|
||||
decode: (value: string) => Uint8Array;
|
||||
encode: (value: Uint8Array) => string;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { blake2AsU8a } from './asU8a';
|
||||
|
||||
/**
|
||||
* @name blake2AsHex
|
||||
* @summary Creates a blake2b hex from the input.
|
||||
* @description
|
||||
* From a `Uint8Array` input, create the blake2b and return the result as a hex string with the specified `bitLength`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { blake2AsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* blake2AsHex('abc'); // => 0xba80a53f981c4d0d
|
||||
* ```
|
||||
*/
|
||||
export function blake2AsHex (data: HexString | Uint8Array | string, bitLength = 256, key?: Uint8Array | null, onlyJs = false): HexString {
|
||||
return u8aToHex(
|
||||
blake2AsU8a(data, bitLength, key, onlyJs)
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import type { HexString } from '@polkadot/util/types';
|
||||
import js from 'blakejs';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { blake2b, isReady } from '@polkadot/wasm-crypto';
|
||||
import { blake2b } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createAsHex, isWasmOnly } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name blake2AsU8a
|
||||
@@ -22,11 +24,17 @@ import { blake2b, isReady } from '@polkadot/wasm-crypto';
|
||||
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d]
|
||||
* ```
|
||||
*/
|
||||
export function blake2AsU8a (data: HexString | Uint8Array | string, bitLength = 256, key?: Uint8Array | null, onlyJs = false): Uint8Array {
|
||||
export function blake2AsU8a (data: HexString | Uint8Array | string, bitLength = 256, key?: Uint8Array | null, onlyJs?: boolean): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
const u8a = u8aToU8a(data);
|
||||
|
||||
return isReady() && !onlyJs
|
||||
return isWasmOnly(onlyJs)
|
||||
? blake2b(u8a, u8aToU8a(key), byteLength)
|
||||
: js.blake2b(u8a, key || undefined, byteLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name blake2AsHex
|
||||
* @description Creates a blake2b hex from the input.
|
||||
*/
|
||||
export const blake2AsHex = createAsHex(blake2AsU8a);
|
||||
|
||||
@@ -5,5 +5,4 @@
|
||||
* @summary Create blake2b values with specified bitlengths
|
||||
*/
|
||||
|
||||
export { blake2AsHex } from './asHex';
|
||||
export { blake2AsU8a } from './asU8a';
|
||||
export { blake2AsHex, blake2AsU8a } from './asU8a';
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Keypair } from '../../types';
|
||||
import { assert, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { BN_BE_32_OPTS } from '../../bn';
|
||||
import { hmacSha512 } from '../../hmac';
|
||||
import { hmacShaAsU8a } from '../../hmac';
|
||||
import { secp256k1KeypairFromSeed, secp256k1PrivateKeyTweakAdd } from '../../secp256k1';
|
||||
import { HARDENED, hdValidatePath } from '../validatePath';
|
||||
|
||||
@@ -31,7 +31,7 @@ function deriveChild (hd: CodedKeypair, index: number): CodedKeypair {
|
||||
: u8aConcat(hd.publicKey, indexBuffer);
|
||||
|
||||
try {
|
||||
const I = hmacSha512(hd.chainCode, data);
|
||||
const I = hmacShaAsU8a(hd.chainCode, data, 512);
|
||||
|
||||
return createCoded(
|
||||
secp256k1PrivateKeyTweakAdd(hd.secretKey, I.slice(0, 32)),
|
||||
@@ -44,7 +44,7 @@ function deriveChild (hd: CodedKeypair, index: number): CodedKeypair {
|
||||
}
|
||||
|
||||
export function hdEthereum (seed: Uint8Array, path = ''): Keypair {
|
||||
const I = hmacSha512(MASTER_SECRET, seed);
|
||||
const I = hmacShaAsU8a(MASTER_SECRET, seed, 512);
|
||||
let hd = createCoded(I.slice(0, 32), I.slice(32));
|
||||
|
||||
if (!path || path === 'm' || path === 'M' || path === "m'" || path === "M'") {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { BN_EIGHT, bnToU8a, u8aConcat, u8aToBn } from '@polkadot/util';
|
||||
|
||||
import { BN_LE_32_OPTS, BN_LE_512_OPTS, BN_LE_OPTS } from '../../bn';
|
||||
import { hmacSha512 } from '../../hmac';
|
||||
import { hmacShaAsU8a } from '../../hmac';
|
||||
|
||||
// performs hard-only derivation on the xprv
|
||||
export function ledgerDerivePrivate (xprv: Uint8Array, index: number): Uint8Array {
|
||||
@@ -12,7 +12,7 @@ export function ledgerDerivePrivate (xprv: Uint8Array, index: number): Uint8Arra
|
||||
const kr = xprv.subarray(32, 64);
|
||||
const cc = xprv.subarray(64, 96);
|
||||
const data = u8aConcat([0], kl, kr, bnToU8a(index, BN_LE_32_OPTS));
|
||||
const z = hmacSha512(cc, data);
|
||||
const z = hmacShaAsU8a(cc, data, 512);
|
||||
|
||||
data[0] = 0x01;
|
||||
|
||||
@@ -29,6 +29,6 @@ export function ledgerDerivePrivate (xprv: Uint8Array, index: number): Uint8Arra
|
||||
),
|
||||
BN_LE_512_OPTS
|
||||
).subarray(0, 32),
|
||||
hmacSha512(cc, data).subarray(32, 64)
|
||||
hmacShaAsU8a(cc, data, 512).subarray(32, 64)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { hmacSha256, hmacSha512 } from '../../hmac';
|
||||
import { hmacShaAsU8a } from '../../hmac';
|
||||
import { mnemonicToSeedSync } from '../../mnemonic/bip39';
|
||||
|
||||
const ED25519_CRYPTO = 'ed25519 seed';
|
||||
@@ -11,11 +11,11 @@ const ED25519_CRYPTO = 'ed25519 seed';
|
||||
// gets an xprv from a mnemonic
|
||||
export function ledgerMaster (mnemonic: string, password?: string): Uint8Array {
|
||||
const seed = mnemonicToSeedSync(mnemonic, password);
|
||||
const chainCode = hmacSha256(ED25519_CRYPTO, new Uint8Array([1, ...seed]));
|
||||
const chainCode = hmacShaAsU8a(ED25519_CRYPTO, new Uint8Array([1, ...seed]), 256);
|
||||
let priv;
|
||||
|
||||
while (!priv || (priv[31] & 0b0010_0000)) {
|
||||
priv = hmacSha512(ED25519_CRYPTO, priv || seed);
|
||||
priv = hmacShaAsU8a(ED25519_CRYPTO, priv || seed, 512);
|
||||
}
|
||||
|
||||
priv[0] &= 0b1111_1000;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
import { isReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function createAsHex <T extends (...args: any[]) => Uint8Array> (fn: T): (...args: Parameters<T>) => HexString {
|
||||
return (...args: Parameters<T>): HexString =>
|
||||
u8aToHex(fn(...args));
|
||||
}
|
||||
|
||||
export function createBitHasher <T> (bitLength: T, fn: (data: HexString | Buffer | Uint8Array | string, bitLength: T, onlyJs?: boolean) => Uint8Array): (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean) => Uint8Array {
|
||||
return (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean): Uint8Array =>
|
||||
fn(data, bitLength, onlyJs);
|
||||
}
|
||||
|
||||
export function isWasmOnly (onlyJs?: boolean): boolean {
|
||||
return isReady() && !onlyJs;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { hmacSha256 } from './sha256';
|
||||
export { hmacSha512 } from './sha512';
|
||||
export { hmacShaAsU8a, hmacSha256AsU8a, hmacSha512AsU8a } from './shaAsU8a';
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import hash from 'hash.js';
|
||||
|
||||
export function hmacSha (key: Uint8Array | string, data: Uint8Array, is512: boolean): Uint8Array {
|
||||
return Uint8Array.from(
|
||||
hash
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
.hmac(is512 ? hash.sha512 : hash.sha256, key)
|
||||
.update(data)
|
||||
.digest());
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { stringToU8a, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { hmacSha256 } from '.';
|
||||
|
||||
describe('hmacSha256', (): void => {
|
||||
it('has a known output', (): void => {
|
||||
const key = stringToU8a('secret');
|
||||
const data = stringToU8a('some message');
|
||||
|
||||
expect(
|
||||
u8aToHex(
|
||||
hmacSha256(key, data)
|
||||
)
|
||||
).toEqual(
|
||||
'0xf28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { hmacSha } from './sha';
|
||||
|
||||
export function hmacSha256 (key: Uint8Array | string, data: Uint8Array): Uint8Array {
|
||||
return hmacSha(key, data, false);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { stringToU8a, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { hmacSha512 } from '.';
|
||||
|
||||
describe('hmacSha512', (): void => {
|
||||
it('has a known output', (): void => {
|
||||
const key = stringToU8a('secret');
|
||||
const data = stringToU8a('some message');
|
||||
|
||||
expect(
|
||||
u8aToHex(
|
||||
hmacSha512(key, data)
|
||||
)
|
||||
).toEqual(
|
||||
'0x295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { hmacSha } from './sha';
|
||||
|
||||
export function hmacSha512 (key: Uint8Array | string, data: Uint8Array): Uint8Array {
|
||||
return hmacSha(key, data, true);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { hexToU8a, stringToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceTest } from '../../test/performance';
|
||||
import { hmacShaAsU8a } from '.';
|
||||
|
||||
describe('hmacShaAsU8a', (): void => {
|
||||
beforeEach(async (): Promise<void> => {
|
||||
await waitReady();
|
||||
});
|
||||
|
||||
const key = stringToU8a('secret');
|
||||
const data = stringToU8a('some message');
|
||||
const output = {
|
||||
256: hexToU8a(
|
||||
'0xf28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7'
|
||||
),
|
||||
512: hexToU8a(
|
||||
'0x295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841'
|
||||
)
|
||||
};
|
||||
|
||||
describe.each([256, 512] as (256 | 512)[])('bitLength=$p', (bitLength): void => {
|
||||
describe.each([false, true])('onlyJs=%p', (onlyJs): void => {
|
||||
it('returns an hex representation (string)', (): void => {
|
||||
expect(
|
||||
hmacShaAsU8a(key, data, bitLength, onlyJs)
|
||||
).toEqual(output[bitLength]);
|
||||
});
|
||||
});
|
||||
|
||||
performanceTest(`hmacShaAsU8a, bitLength=${bitLength}`, 16000, (input, onlyJs) =>
|
||||
hmacShaAsU8a(input, input, bitLength, onlyJs)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import hash from 'hash.js';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { hmacSha256, hmacSha512 } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
|
||||
type HashFn = (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array;
|
||||
|
||||
function createSha (bitLength: 256 | 512 = 256): HashFn {
|
||||
return (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean): Uint8Array =>
|
||||
hmacShaAsU8a(key, data, bitLength, onlyJs);
|
||||
}
|
||||
|
||||
export function hmacShaAsU8a (key: Uint8Array | string, data: Uint8Array, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array {
|
||||
const is256 = bitLength === 256;
|
||||
const u8aKey = u8aToU8a(key);
|
||||
|
||||
return isWasmOnly(onlyJs)
|
||||
? is256
|
||||
? hmacSha256(u8aKey, data)
|
||||
: hmacSha512(u8aKey, data)
|
||||
: new Uint8Array(
|
||||
is256
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
? hash.hmac(hash.sha256, u8aKey).update(data).digest()
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
: hash.hmac(hash.sha512, u8aKey).update(data).digest()
|
||||
);
|
||||
}
|
||||
|
||||
export const hmacSha256AsU8a = createSha(256);
|
||||
export const hmacSha512AsU8a = createSha(512);
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { keccakAsU8a } from './asU8a';
|
||||
|
||||
/**
|
||||
* @name keccakAsHex
|
||||
* @summary Creates a keccak hex string from the input.
|
||||
* @description
|
||||
* From either a `string` or a `Buffer` input, create the keccak and return the result as a `0x` prefixed hex string.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { keccakAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* keccakAsHex('123'); // => 0x...
|
||||
* ```
|
||||
*/
|
||||
export function keccakAsHex (value: HexString | Buffer | Uint8Array | string, bitLength?: 256 | 512): HexString {
|
||||
return u8aToHex(
|
||||
keccakAsU8a(value, bitLength)
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import type { HexString } from '@polkadot/util/types';
|
||||
import js from 'js-sha3';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, keccak256, keccak512 } from '@polkadot/wasm-crypto';
|
||||
import { keccak256, keccak512 } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createAsHex, createBitHasher, isWasmOnly } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name keccakAsU8a
|
||||
@@ -22,11 +24,11 @@ import { isReady, keccak256, keccak512 } from '@polkadot/wasm-crypto';
|
||||
* keccakAsU8a('123'); // => Uint8Array
|
||||
* ```
|
||||
*/
|
||||
export function keccakAsU8a (value: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs = false): Uint8Array {
|
||||
export function keccakAsU8a (value: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array {
|
||||
const is256 = bitLength === 256;
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
return isReady() && !onlyJs
|
||||
return isWasmOnly(onlyJs)
|
||||
? is256
|
||||
? keccak256(u8a)
|
||||
: keccak512(u8a)
|
||||
@@ -36,3 +38,21 @@ export function keccakAsU8a (value: HexString | Buffer | Uint8Array | string, bi
|
||||
: js.keccak512.update(u8a).arrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name keccak256AsU8a
|
||||
* @description Creates a keccak256 Uint8Array from the input.
|
||||
*/
|
||||
export const keccak256AsU8a = createBitHasher(256, keccakAsU8a);
|
||||
|
||||
/**
|
||||
* @name keccak512AsU8a
|
||||
* @description Creates a keccak512 Uint8Array from the input.
|
||||
*/
|
||||
export const keccak512AsU8a = createBitHasher(512, keccakAsU8a);
|
||||
|
||||
/**
|
||||
* @name keccakAsHex
|
||||
* @description Creates a keccak hex string from the input.
|
||||
*/
|
||||
export const keccakAsHex = createAsHex(keccakAsU8a);
|
||||
|
||||
@@ -5,5 +5,4 @@
|
||||
* @summary Create Keccak256/512 values as hex & Uint8Array output
|
||||
*/
|
||||
|
||||
export { keccakAsHex } from './asHex';
|
||||
export { keccakAsU8a } from './asU8a';
|
||||
export { keccakAsHex, keccakAsU8a, keccak256AsU8a, keccak512AsU8a } from './asU8a';
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { bip39Generate, isReady } from '@polkadot/wasm-crypto';
|
||||
import { bip39Generate } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { generateMnemonic } from './bip39';
|
||||
|
||||
export type WordCount = 12 | 15 | 18 | 21 | 24;
|
||||
@@ -28,8 +29,8 @@ const STRENGTH_MAP = {
|
||||
* const mnemonic = mnemonicGenerate(); // => string
|
||||
* ```
|
||||
*/
|
||||
export function mnemonicGenerate (numWords: WordCount = 12, onlyJs = false): string {
|
||||
return isReady() && !onlyJs
|
||||
export function mnemonicGenerate (numWords: WordCount = 12, onlyJs?: boolean): string {
|
||||
return isWasmOnly(onlyJs)
|
||||
? bip39Generate(numWords)
|
||||
: generateMnemonic(STRENGTH_MAP[numWords]);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { bip39ToEntropy, isReady } from '@polkadot/wasm-crypto';
|
||||
import { bip39ToEntropy } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { mnemonicToEntropy as jsToEntropy } from './bip39';
|
||||
|
||||
export function mnemonicToEntropy (mnemonic: string, onlyJs = false): Uint8Array {
|
||||
return isReady() && !onlyJs
|
||||
export function mnemonicToEntropy (mnemonic: string, onlyJs?: boolean): Uint8Array {
|
||||
return isWasmOnly(onlyJs)
|
||||
? bip39ToEntropy(mnemonic)
|
||||
: jsToEntropy(mnemonic);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
import { bip39ToSeed, isReady } from '@polkadot/wasm-crypto';
|
||||
import { bip39ToSeed } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { mnemonicToSeedSync } from './bip39';
|
||||
import { mnemonicValidate } from './validate';
|
||||
|
||||
@@ -24,12 +25,12 @@ import { mnemonicValidate } from './validate';
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export function mnemonicToLegacySeed (mnemonic: string, password = '', onlyJs = false, byteLength: 32 | 64 = 32): Uint8Array {
|
||||
export function mnemonicToLegacySeed (mnemonic: string, password = '', onlyJs?: boolean, byteLength: 32 | 64 = 32): Uint8Array {
|
||||
assert(mnemonicValidate(mnemonic), 'Invalid bip39 mnemonic specified');
|
||||
assert([32, 64].includes(byteLength), () => `Invalid seed length ${byteLength}, expected 32 or 64`);
|
||||
|
||||
if (byteLength === 32) {
|
||||
return isReady() && !onlyJs
|
||||
return isWasmOnly(onlyJs)
|
||||
? bip39ToSeed(mnemonic, password)
|
||||
: mnemonicToSeedSync(mnemonic, password).subarray(0, 32);
|
||||
} else if (byteLength === 64) {
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert, stringToU8a } from '@polkadot/util';
|
||||
import { bip39ToMiniSecret, isReady } from '@polkadot/wasm-crypto';
|
||||
import { bip39ToMiniSecret } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { pbkdf2Encode } from '../pbkdf2';
|
||||
import { mnemonicToEntropy } from './toEntropy';
|
||||
import { mnemonicValidate } from './validate';
|
||||
|
||||
export function mnemonicToMiniSecret (mnemonic: string, password = '', onlyJs = false): Uint8Array {
|
||||
export function mnemonicToMiniSecret (mnemonic: string, password = '', onlyJs?: boolean): Uint8Array {
|
||||
assert(mnemonicValidate(mnemonic), 'Invalid bip39 mnemonic specified');
|
||||
|
||||
if (isReady() && !onlyJs) {
|
||||
if (isWasmOnly(onlyJs)) {
|
||||
return bip39ToMiniSecret(mnemonic, password);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { bip39Validate, isReady } from '@polkadot/wasm-crypto';
|
||||
import { bip39Validate } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { validateMnemonic } from './bip39';
|
||||
|
||||
/**
|
||||
@@ -18,8 +19,8 @@ import { validateMnemonic } from './bip39';
|
||||
* const isValidMnemonic = mnemonicValidate(mnemonic); // => boolean
|
||||
* ```
|
||||
*/
|
||||
export function mnemonicValidate (mnemonic: string, onlyJs = false): boolean {
|
||||
return isReady() && !onlyJs
|
||||
export function mnemonicValidate (mnemonic: string, onlyJs?: boolean): boolean {
|
||||
return isWasmOnly(onlyJs)
|
||||
? bip39Validate(mnemonic)
|
||||
: validateMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import { ed25519KeypairFromSeed, isReady } from '@polkadot/wasm-crypto';
|
||||
* naclKeypairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
|
||||
* ```
|
||||
*/
|
||||
export function naclKeypairFromSeed (seed: Uint8Array, onlyJs = false): Keypair {
|
||||
export function naclKeypairFromSeed (seed: Uint8Array, onlyJs?: boolean): Keypair {
|
||||
if (!onlyJs && isReady()) {
|
||||
const full = ed25519KeypairFromSeed(seed);
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import type { Keypair } from '../types';
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
import { assert, u8aToU8a } from '@polkadot/util';
|
||||
import { ed25519Sign, isReady } from '@polkadot/wasm-crypto';
|
||||
import { ed25519Sign } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name naclSign
|
||||
@@ -23,12 +25,12 @@ import { ed25519Sign, isReady } from '@polkadot/wasm-crypto';
|
||||
* naclSign([...], [...]); // => [...]
|
||||
* ```
|
||||
*/
|
||||
export function naclSign (message: HexString | Uint8Array | string, { publicKey, secretKey }: Partial<Keypair>, onlyJs = false): Uint8Array {
|
||||
export function naclSign (message: HexString | Uint8Array | string, { publicKey, secretKey }: Partial<Keypair>, onlyJs?: boolean): Uint8Array {
|
||||
assert(secretKey, 'Expected a valid secretKey');
|
||||
|
||||
const messageU8a = u8aToU8a(message);
|
||||
|
||||
return isReady() && !onlyJs
|
||||
return isWasmOnly(onlyJs)
|
||||
? ed25519Sign(publicKey as Uint8Array, secretKey.subarray(0, 32), messageU8a)
|
||||
: nacl.sign.detached(messageU8a, secretKey);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import type { HexString } from '@polkadot/util/types';
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
import { assert, u8aToU8a } from '@polkadot/util';
|
||||
import { ed25519Verify, isReady } from '@polkadot/wasm-crypto';
|
||||
import { ed25519Verify } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name naclSign
|
||||
@@ -22,7 +24,7 @@ import { ed25519Verify, isReady } from '@polkadot/wasm-crypto';
|
||||
* naclVerify([...], [...], [...]); // => true/false
|
||||
* ```
|
||||
*/
|
||||
export function naclVerify (message: HexString | Uint8Array | string, signature: HexString | Uint8Array | string, publicKey: HexString | Uint8Array | string, onlyJs = false): boolean {
|
||||
export function naclVerify (message: HexString | Uint8Array | string, signature: HexString | Uint8Array | string, publicKey: HexString | Uint8Array | string, onlyJs?: boolean): boolean {
|
||||
const messageU8a = u8aToU8a(message);
|
||||
const publicKeyU8a = u8aToU8a(publicKey);
|
||||
const signatureU8a = u8aToU8a(signature);
|
||||
@@ -30,7 +32,7 @@ export function naclVerify (message: HexString | Uint8Array | string, signature:
|
||||
assert(publicKeyU8a.length === 32, () => `Invalid publicKey, received ${publicKeyU8a.length}, expected 32`);
|
||||
assert(signatureU8a.length === 64, () => `Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
|
||||
|
||||
return isReady() && !onlyJs
|
||||
return isWasmOnly(onlyJs)
|
||||
? ed25519Verify(signatureU8a, messageU8a, publicKeyU8a)
|
||||
: nacl.sign.detached.verify(messageU8a, signatureU8a, publicKeyU8a);
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.9.2' };
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, pbkdf2 } from '@polkadot/wasm-crypto';
|
||||
import { pbkdf2 } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
import { pbkdf2Sync } from './pbkdf2';
|
||||
|
||||
@@ -15,12 +16,12 @@ interface Result {
|
||||
salt: Uint8Array;
|
||||
}
|
||||
|
||||
export function pbkdf2Encode (passphrase?: HexString | Buffer | Uint8Array | string, salt: Buffer | Uint8Array = randomAsU8a(), rounds = 2048, onlyJs = false): Result {
|
||||
export function pbkdf2Encode (passphrase?: HexString | Buffer | Uint8Array | string, salt: Buffer | Uint8Array = randomAsU8a(), rounds = 2048, onlyJs?: boolean): Result {
|
||||
const u8aPass = u8aToU8a(passphrase);
|
||||
const u8aSalt = u8aToU8a(salt);
|
||||
|
||||
return {
|
||||
password: isReady() && !onlyJs
|
||||
password: isWasmOnly(onlyJs)
|
||||
? pbkdf2(u8aPass, u8aSalt, rounds)
|
||||
: pbkdf2Sync(u8aPass, u8aSalt, rounds),
|
||||
rounds,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { bnToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { BN_BE_32_OPTS } from '../bn';
|
||||
import { hmacSha512 } from '../hmac';
|
||||
import { hmacShaAsU8a } from '../hmac';
|
||||
|
||||
export function pbkdf2Sync (password: Uint8Array, salt: Uint8Array, rounds: number, len = 64): Uint8Array {
|
||||
let out = new Uint8Array();
|
||||
@@ -17,12 +17,12 @@ export function pbkdf2Sync (password: Uint8Array, salt: Uint8Array, rounds: numb
|
||||
num++;
|
||||
block.set(bnToU8a(num, BN_BE_32_OPTS), salt.length);
|
||||
|
||||
let prev = hmacSha512(password, block);
|
||||
let prev = hmacShaAsU8a(password, block, 512);
|
||||
const md = prev;
|
||||
let i = 0;
|
||||
|
||||
while (++i < rounds) {
|
||||
prev = hmacSha512(password, prev);
|
||||
prev = hmacShaAsU8a(password, prev, 512);
|
||||
|
||||
let j = -1;
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { randomAsU8a } from './asU8a';
|
||||
|
||||
/**
|
||||
* @name randomAsHex
|
||||
* @summary Creates a hex string filled with random bytes.
|
||||
* @description
|
||||
* Returns a hex string with the specified (optional) length filled with random bytes.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { randomAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* randomAsHex(); // => 0x...
|
||||
* ```
|
||||
*/
|
||||
export function randomAsHex (length = 32): HexString {
|
||||
return u8aToHex(
|
||||
randomAsU8a(length)
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { BN, hexToBn } from '@polkadot/util';
|
||||
|
||||
import { randomAsHex } from './asHex';
|
||||
import { randomAsHex } from './asU8a';
|
||||
|
||||
const BN_53 = new BN(0b11111111111111111111111111111111111111111111111111111);
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||
|
||||
import { createAsHex } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name randomAsU8a
|
||||
* @summary Creates a Uint8Array filled with random bytes.
|
||||
@@ -20,3 +22,9 @@ import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||
export function randomAsU8a (length = 32): Uint8Array {
|
||||
return getRandomValues(new Uint8Array(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name randomAsHex
|
||||
* @description Creates a hex string filled with random bytes.
|
||||
*/
|
||||
export const randomAsHex = createAsHex(randomAsU8a);
|
||||
|
||||
@@ -5,6 +5,5 @@
|
||||
* @summary Returns a sequence of secure random bytes in a variety of formats
|
||||
*/
|
||||
|
||||
export { randomAsHex } from './asHex';
|
||||
export { randomAsNumber } from './asNumber';
|
||||
export { randomAsU8a } from './asU8a';
|
||||
export { randomAsHex, randomAsU8a } from './asU8a';
|
||||
|
||||
@@ -7,8 +7,9 @@ import type { Params } from './types';
|
||||
import scryptsy from 'scryptsy';
|
||||
|
||||
import { bufferToU8a, u8aToBuffer, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, scrypt } from '@polkadot/wasm-crypto';
|
||||
import { scrypt } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { isWasmOnly } from '../helpers';
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
import { DEFAULT_PARAMS } from './defaults';
|
||||
|
||||
@@ -18,10 +19,10 @@ interface Result {
|
||||
salt: Uint8Array;
|
||||
}
|
||||
|
||||
export function scryptEncode (passphrase?: HexString | Uint8Array | string, salt = randomAsU8a(), params = DEFAULT_PARAMS, onlyJs = false): Result {
|
||||
export function scryptEncode (passphrase?: HexString | Uint8Array | string, salt = randomAsU8a(), params = DEFAULT_PARAMS, onlyJs?: boolean): Result {
|
||||
const u8a = u8aToU8a(passphrase);
|
||||
|
||||
const password = isReady() && !onlyJs
|
||||
const password = isWasmOnly(onlyJs)
|
||||
? scrypt(u8a, salt, Math.log2(params.N), params.r, params.p)
|
||||
: bufferToU8a(
|
||||
scryptsy(u8aToBuffer(u8a), u8aToBuffer(salt), params.N, params.r, params.p, 64)
|
||||
|
||||
@@ -6,17 +6,19 @@ import type { HexString } from '@polkadot/util/types';
|
||||
import hash from 'hash.js';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, sha256, sha512 } from '@polkadot/wasm-crypto';
|
||||
import { sha256, sha512 } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createBitHasher, isWasmOnly } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name shaAsU8a
|
||||
* @summary Creates a sha Uint8Array from the input.
|
||||
*/
|
||||
export function shaAsU8a (value: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs = false): Uint8Array {
|
||||
export function shaAsU8a (value: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array {
|
||||
const is256 = bitLength === 256;
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
return isReady() && !onlyJs
|
||||
return isWasmOnly(onlyJs)
|
||||
? is256
|
||||
? sha256(u8a)
|
||||
: sha512(u8a)
|
||||
@@ -26,3 +28,6 @@ export function shaAsU8a (value: HexString | Buffer | Uint8Array | string, bitLe
|
||||
: hash.sha512().update(u8a).digest()
|
||||
);
|
||||
}
|
||||
|
||||
export const sha256AsU8a = createBitHasher(256, shaAsU8a);
|
||||
export const sha512AsU8a = createBitHasher(512, shaAsU8a);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { shaAsU8a } from './asU8a';
|
||||
|
||||
/**
|
||||
* @name sha256AsU8a
|
||||
* @summary Creates a sha256 Uint8Array from the input.
|
||||
*/
|
||||
export function sha256AsU8a (value: HexString | Buffer | Uint8Array | string, onlyJs = false): Uint8Array {
|
||||
return shaAsU8a(value, 256, onlyJs);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { shaAsU8a } from './asU8a';
|
||||
|
||||
/**
|
||||
* @name sha512AsU8a
|
||||
* @summary Creates a sha256 Uint8Array from the input.
|
||||
*/
|
||||
export function sha512AsU8a (value: HexString | Buffer | Uint8Array | string, onlyJs = false): Uint8Array {
|
||||
return shaAsU8a(value, 512, onlyJs);
|
||||
}
|
||||
@@ -5,6 +5,4 @@
|
||||
* @summary Implements Sha-256/512 hashing functions for a variety of input and outputs
|
||||
*/
|
||||
|
||||
export { shaAsU8a } from './asU8a';
|
||||
export { sha256AsU8a } from './asU8a256';
|
||||
export { sha512AsU8a } from './asU8a512';
|
||||
export { shaAsU8a, sha256AsU8a, sha512AsU8a } from './asU8a';
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { xxhashAsU8a } from './asU8a';
|
||||
|
||||
/**
|
||||
* @name xxhashAsHex
|
||||
* @summary Creates a xxhash64 hex from the input.
|
||||
* @description
|
||||
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with the specified `bitLength`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { xxhashAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* xxhashAsHex('abc'); // => 0x44bc2cf5ad770999
|
||||
* ```
|
||||
*/
|
||||
export function xxhashAsHex (data: HexString | Buffer | Uint8Array | string, bitLength = 64): HexString {
|
||||
return u8aToHex(
|
||||
xxhashAsU8a(data, bitLength)
|
||||
);
|
||||
}
|
||||
@@ -4,8 +4,9 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, twox } from '@polkadot/wasm-crypto';
|
||||
import { twox } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createAsHex, isWasmOnly } from '../helpers';
|
||||
import xxhash64AsBn from './xxhash64/asBn';
|
||||
|
||||
/**
|
||||
@@ -22,11 +23,11 @@ import xxhash64AsBn from './xxhash64/asBn';
|
||||
* xxhashAsU8a('abc'); // => 0x44bc2cf5ad770999
|
||||
* ```
|
||||
*/
|
||||
export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bitLength = 64, onlyJs = false): Uint8Array {
|
||||
export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bitLength = 64, onlyJs?: boolean): Uint8Array {
|
||||
const iterations = Math.ceil(bitLength / 64);
|
||||
const u8a = u8aToU8a(data);
|
||||
|
||||
if (isReady() && !onlyJs) {
|
||||
if (isWasmOnly(onlyJs)) {
|
||||
return twox(u8a, iterations);
|
||||
}
|
||||
|
||||
@@ -38,3 +39,9 @@ export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bit
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name xxhashAsHex
|
||||
* @description Creates a xxhash64 hex from the input.
|
||||
*/
|
||||
export const xxhashAsHex = createAsHex(xxhashAsU8a);
|
||||
|
||||
@@ -5,5 +5,4 @@
|
||||
* @summary Create xxhash64 values with specified bitlengths
|
||||
*/
|
||||
|
||||
export { xxhashAsHex } from './asHex';
|
||||
export { xxhashAsU8a } from './asU8a';
|
||||
export { xxhashAsHex, xxhashAsU8a } from './asU8a';
|
||||
|
||||
@@ -40,12 +40,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-textdecoder": "7.9.1",
|
||||
"@polkadot/x-textencoder": "7.9.1",
|
||||
"@polkadot/x-textdecoder": "7.9.2",
|
||||
"@polkadot/x-textencoder": "7.9.2",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.12.0",
|
||||
"camelcase": "^6.2.1",
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/util', version: '7.9.2' };
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/util": "7.9.1",
|
||||
"@polkadot/util": "7.9.2",
|
||||
"buffer-es6": "^4.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.9.2' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-global": "7.9.1",
|
||||
"@polkadot/x-global": "7.9.2",
|
||||
"@types/node-fetch": "^2.5.12",
|
||||
"node-fetch": "^2.6.6"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.9.2' };
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-global', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-global', version: '7.9.2' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-global": "7.9.1"
|
||||
"@polkadot/x-global": "7.9.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-native": "^0.66.5"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.9.2' };
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-global": "7.9.1"
|
||||
"@polkadot/x-global": "7.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.9.2' };
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-global": "7.9.1"
|
||||
"@polkadot/x-global": "7.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.9.2' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.9.1",
|
||||
"version": "7.9.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-global": "7.9.1",
|
||||
"@polkadot/x-global": "7.9.2",
|
||||
"@types/websocket": "^1.0.4",
|
||||
"websocket": "^1.0.34"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-ws', version: '7.9.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-ws', version: '7.9.2' };
|
||||
|
||||
@@ -2021,7 +2021,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/hw-ledger-transports@7.9.1, @polkadot/hw-ledger-transports@workspace:packages/hw-ledger-transports":
|
||||
"@polkadot/hw-ledger-transports@7.9.2, @polkadot/hw-ledger-transports@workspace:packages/hw-ledger-transports":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/hw-ledger-transports@workspace:packages/hw-ledger-transports"
|
||||
dependencies:
|
||||
@@ -2041,8 +2041,8 @@ __metadata:
|
||||
resolution: "@polkadot/hw-ledger@workspace:packages/hw-ledger"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/hw-ledger-transports": 7.9.1
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/hw-ledger-transports": 7.9.2
|
||||
"@polkadot/util": 7.9.2
|
||||
"@zondax/ledger-substrate": ^0.18.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -2052,21 +2052,21 @@ __metadata:
|
||||
resolution: "@polkadot/keyring@workspace:packages/keyring"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/util-crypto": 7.9.1
|
||||
"@polkadot/util": 7.9.2
|
||||
"@polkadot/util-crypto": 7.9.2
|
||||
peerDependencies:
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/util-crypto": 7.9.1
|
||||
"@polkadot/util": 7.9.2
|
||||
"@polkadot/util-crypto": 7.9.2
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/networks@7.9.1, @polkadot/networks@workspace:packages/networks":
|
||||
"@polkadot/networks@7.9.2, @polkadot/networks@workspace:packages/networks":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/networks@workspace:packages/networks"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/x-fetch": 7.9.1
|
||||
"@polkadot/util": 7.9.2
|
||||
"@polkadot/x-fetch": 7.9.2
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -2079,15 +2079,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/util-crypto@7.9.1, @polkadot/util-crypto@workspace:packages/util-crypto":
|
||||
"@polkadot/util-crypto@7.9.2, @polkadot/util-crypto@workspace:packages/util-crypto":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/util-crypto@workspace:packages/util-crypto"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/networks": 7.9.1
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/wasm-crypto": ^4.3.1
|
||||
"@polkadot/x-randomvalues": 7.9.1
|
||||
"@polkadot/networks": 7.9.2
|
||||
"@polkadot/util": 7.9.2
|
||||
"@polkadot/wasm-crypto": ^4.4.1
|
||||
"@polkadot/x-randomvalues": 7.9.2
|
||||
"@types/bn.js": ^4.11.6
|
||||
"@types/create-hash": ^1.2.2
|
||||
"@types/ed2curve": ^0.2.2
|
||||
@@ -2106,17 +2106,17 @@ __metadata:
|
||||
tweetnacl: ^1.0.3
|
||||
xxhashjs: ^0.2.2
|
||||
peerDependencies:
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/util": 7.9.2
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/util@7.9.1, @polkadot/util@workspace:packages/util":
|
||||
"@polkadot/util@7.9.2, @polkadot/util@workspace:packages/util":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/util@workspace:packages/util"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/x-textdecoder": 7.9.1
|
||||
"@polkadot/x-textencoder": 7.9.1
|
||||
"@polkadot/x-textdecoder": 7.9.2
|
||||
"@polkadot/x-textencoder": 7.9.2
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^4.12.0
|
||||
camelcase: ^6.2.1
|
||||
@@ -2124,35 +2124,35 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/wasm-crypto-asmjs@npm:^4.3.1":
|
||||
version: 4.3.1
|
||||
resolution: "@polkadot/wasm-crypto-asmjs@npm:4.3.1"
|
||||
"@polkadot/wasm-crypto-asmjs@npm:^4.4.1":
|
||||
version: 4.4.1
|
||||
resolution: "@polkadot/wasm-crypto-asmjs@npm:4.4.1"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
checksum: 145bff607c0a1da592d9945a902d5ea2373487a14149ed7fb940151c6977660c935d67bf90e06ea39affe3d72e4483a1b66d758447385039b41f45935db8e66a
|
||||
checksum: 3df73641ec52d69e91be56f6010db0960556ee26ea2a43586d0dd1a2b7ec483b6bea1c7b1cf6aa6b16a88f771d3ba55b38e1b685a9d9b9a18b861de6b1e837b7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/wasm-crypto-wasm@npm:^4.3.1":
|
||||
version: 4.3.1
|
||||
resolution: "@polkadot/wasm-crypto-wasm@npm:4.3.1"
|
||||
"@polkadot/wasm-crypto-wasm@npm:^4.4.1":
|
||||
version: 4.4.1
|
||||
resolution: "@polkadot/wasm-crypto-wasm@npm:4.4.1"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
checksum: e06c91e267790e100f5c36ff39bc226323cfc19600920ee2dff77e38251b28c8010d4b58372aaaffb60a5611dfc9b904e36c87ace2a40cf1bbee8446ff7282b5
|
||||
checksum: 315696bfe78e45ef46e6f484b59eeb29afea68f635bec2916123bdba2a414c6ba557d7c8eb547c4541d663580c41ae925e839ba80a7c7f25e5ceaf53de780e15
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/wasm-crypto@npm:^4.3.1":
|
||||
version: 4.3.1
|
||||
resolution: "@polkadot/wasm-crypto@npm:4.3.1"
|
||||
"@polkadot/wasm-crypto@npm:^4.4.1":
|
||||
version: 4.4.1
|
||||
resolution: "@polkadot/wasm-crypto@npm:4.4.1"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/wasm-crypto-asmjs": ^4.3.1
|
||||
"@polkadot/wasm-crypto-wasm": ^4.3.1
|
||||
"@polkadot/wasm-crypto-asmjs": ^4.4.1
|
||||
"@polkadot/wasm-crypto-wasm": ^4.4.1
|
||||
peerDependencies:
|
||||
"@polkadot/util": "*"
|
||||
"@polkadot/x-randomvalues": "*"
|
||||
checksum: 76bf64f148b3c8fb32a57ffdd982f88901d6aa17beb685fe79f7a3a0268202cce9da72659539964882c325eef3b04ab01e847f0090c064f412a09a2fb81399de
|
||||
checksum: 853d4e4cf291de73830cb7398f3fdcdbdb277b98f8c66f7f8555fe10e75cdfed2669df2201c361ef7a7a5972d92bc594777e08ac138660512c10c7fbf51dd920
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2161,23 +2161,23 @@ __metadata:
|
||||
resolution: "@polkadot/x-bundle@workspace:packages/x-bundle"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/util": 7.9.1
|
||||
"@polkadot/util": 7.9.2
|
||||
buffer-es6: ^4.9.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/x-fetch@7.9.1, @polkadot/x-fetch@workspace:packages/x-fetch":
|
||||
"@polkadot/x-fetch@7.9.2, @polkadot/x-fetch@workspace:packages/x-fetch":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/x-fetch@workspace:packages/x-fetch"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/x-global": 7.9.1
|
||||
"@polkadot/x-global": 7.9.2
|
||||
"@types/node-fetch": ^2.5.12
|
||||
node-fetch: ^2.6.6
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/x-global@7.9.1, @polkadot/x-global@workspace:packages/x-global":
|
||||
"@polkadot/x-global@7.9.2, @polkadot/x-global@workspace:packages/x-global":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/x-global@workspace:packages/x-global"
|
||||
dependencies:
|
||||
@@ -2185,31 +2185,31 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/x-randomvalues@7.9.1, @polkadot/x-randomvalues@workspace:packages/x-randomvalues":
|
||||
"@polkadot/x-randomvalues@7.9.2, @polkadot/x-randomvalues@workspace:packages/x-randomvalues":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/x-randomvalues@workspace:packages/x-randomvalues"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/x-global": 7.9.1
|
||||
"@polkadot/x-global": 7.9.2
|
||||
"@types/react-native": ^0.66.5
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/x-textdecoder@7.9.1, @polkadot/x-textdecoder@workspace:packages/x-textdecoder":
|
||||
"@polkadot/x-textdecoder@7.9.2, @polkadot/x-textdecoder@workspace:packages/x-textdecoder":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/x-textdecoder@workspace:packages/x-textdecoder"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/x-global": 7.9.1
|
||||
"@polkadot/x-global": 7.9.2
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/x-textencoder@7.9.1, @polkadot/x-textencoder@workspace:packages/x-textencoder":
|
||||
"@polkadot/x-textencoder@7.9.2, @polkadot/x-textencoder@workspace:packages/x-textencoder":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/x-textencoder@workspace:packages/x-textencoder"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/x-global": 7.9.1
|
||||
"@polkadot/x-global": 7.9.2
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -2218,7 +2218,7 @@ __metadata:
|
||||
resolution: "@polkadot/x-ws@workspace:packages/x-ws"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.3
|
||||
"@polkadot/x-global": 7.9.1
|
||||
"@polkadot/x-global": 7.9.2
|
||||
"@types/websocket": ^1.0.4
|
||||
websocket: ^1.0.34
|
||||
languageName: unknown
|
||||
|
||||
Reference in New Issue
Block a user