Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53249f51b8 | ||
|
|
4883106c3d | ||
|
|
b3f60da550 | ||
|
|
644f32dfaa | ||
|
|
bf4c6b497f | ||
|
|
a74ac0a0f9 | ||
|
|
6701f7420f | ||
|
|
8e43a2d105 | ||
|
|
9560301883 | ||
|
|
889bd36432 | ||
|
|
e310a63059 | ||
|
|
98082774f7 | ||
|
|
4d680f4b0c | ||
|
|
ff7c086b5b | ||
|
|
63b38c56ff | ||
|
|
8be38e40a1 | ||
|
|
9eb2f14dee | ||
|
|
733d7c1948 | ||
|
|
08ac55d7cd | ||
|
|
e2f5a85d14 | ||
|
|
77289d0ec0 | ||
|
|
29406a0010 | ||
|
|
006d55f5c1 | ||
|
|
650a3ca4a8 | ||
|
|
d3c8112f66 | ||
|
|
8880e8fa8c | ||
|
|
481f7f6ee0 | ||
|
|
a4cefa4bfc | ||
|
|
7ef169585f | ||
|
|
134b8c3b9f | ||
|
|
1158551b9e | ||
|
|
4c2521bc21 | ||
|
|
993e45d148 | ||
|
|
14a0c3f18b | ||
|
|
9fa71647c1 | ||
|
|
cac98aac03 | ||
|
|
48158927e1 | ||
|
|
51082373e6 | ||
|
|
bf80f76173 | ||
|
|
474e98b6d1 | ||
|
|
07317b8840 | ||
|
|
2e46b688cf | ||
|
|
c87cf8c655 | ||
|
|
9eabf95fc0 | ||
|
|
11ab3a4f6b | ||
|
|
0ba57b26d1 | ||
|
|
36c2389985 | ||
|
|
93d5041e8f | ||
|
|
f4d933936e | ||
|
|
2cdaf71c4b | ||
|
|
6982380aff | ||
|
|
2cc2c4d415 | ||
|
|
da38e0f890 | ||
|
|
c7c1723914 | ||
|
|
15e85bf4b9 | ||
|
|
e7771b02a4 | ||
|
|
9a5d2e00be | ||
|
|
5f36b23dfc | ||
|
|
921659981d | ||
|
|
1bcafead57 | ||
|
|
9b29d33d87 | ||
|
|
ecce4a22f7 | ||
|
|
22d471d5fc | ||
|
|
4df1a67be4 | ||
|
|
497b97ad4e | ||
|
|
9177b24d5b | ||
|
|
88556d6a75 | ||
|
|
c8dfeaad5b | ||
|
|
69190b0395 | ||
|
|
e61cd53e08 | ||
|
|
26b0630cd3 | ||
|
|
e09c604c26 | ||
|
|
7983a12121 | ||
|
|
0e070c6142 | ||
|
|
e30a10a4b5 | ||
|
|
c3a073a952 |
+2
-1
@@ -17,4 +17,5 @@
|
||||
|
||||
7.0.2
|
||||
7.0.3
|
||||
7.1.2
|
||||
7.1.2
|
||||
7.8.2
|
||||
@@ -13,6 +13,7 @@ jobs:
|
||||
CI_LOG: 123
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn build
|
||||
yarn networks:crosscheck
|
||||
|
||||
- name: issue
|
||||
|
||||
@@ -1,5 +1,66 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 7.8.2 Nov 7, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Expose internal `isArray` check
|
||||
- Move `object{Property, Properties}` from api repo
|
||||
|
||||
|
||||
## 7.8.1 Nov 6, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Added Acala genesisHash (Thanks to https://github.com/qwer951123)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `objectClear` and `objectSpread` utility functions
|
||||
- Add `lazyMethod` & `lazyMethods` utility functions
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
|
||||
|
||||
## 7.7.1 Oct 31, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add Genshiro support (Thanks to https://github.com/Overseven)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `arrayZip` to combine a key + value array into entries-like
|
||||
- Assert `chainCode` inputs to `derive*`, protecting against misuse
|
||||
- Adjust testnet detection in `@polkadot/networks`
|
||||
- Adjust base library usage of `for` vs `reduce/map`
|
||||
- Bump Ledger libraries to latest versions
|
||||
|
||||
|
||||
## 7.6.1 Oct 23, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Update `xxhash*` to only use `Uint8Array` internally, no `Buffer`
|
||||
- Adjust `isAscii` to check against original string codepoints (when provided)
|
||||
- Adjust networks to sync with `paritytech/ss58-registry`
|
||||
- Dedupe internal sr25519/ed25519 derivation functions
|
||||
- Bump Ledger libraries to latest versions
|
||||
|
||||
|
||||
## 7.5.1 Oct 16, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Fix comment on `blake2AsU8a` (Thanks to https://github.com/tomokazukozuma)
|
||||
- Update Ethereum derivation process (Thanks to https://github.com/joelamouche)
|
||||
|
||||
Changes:
|
||||
|
||||
- Derivation paths now caters for > `MAX_SAFE_INTEGER` unsigned values
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
- Update ss58 registry handling (both previous and current versions)
|
||||
|
||||
|
||||
## 7.4.1 Sep 17, 2021
|
||||
|
||||
Changes:
|
||||
@@ -9,6 +70,7 @@ Changes:
|
||||
- Adjust `isHex` return to `0x${string}` under TypeScript
|
||||
- Adjust shared repo Jest config
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
- Cleanup rollup build where `x-global` yields undefined
|
||||
|
||||
|
||||
## 7.3.1 Aug 28, 2021
|
||||
|
||||
+18
-12
@@ -1,34 +1,40 @@
|
||||
{
|
||||
"repository": "https://github.com/polkadot-js/common",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common#readme",
|
||||
"license": "Apache-2",
|
||||
"packageManager": "yarn@3.0.1",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "7.8.2",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-ts",
|
||||
"build:release": "polkadot-ci-ghact-build",
|
||||
"build:rollup": "polkadot-exec-rollup --config",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"networks:crosscheck": "polkadot-dev-run-test packages/networks/src/crosscheck",
|
||||
"networks:sync": "node packages/networks/scripts/fromSubstrate.mjs",
|
||||
"networks:sync": "yarn build && node packages/networks/scripts/fromSubstrate.mjs",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck --testPathIgnorePatterns toMiniSecretCmp",
|
||||
"test:mnemonicCmp": "polkadot-dev-run-test packages/util-crypto/src/mnemonic/toMiniSecretCmp.spec.ts",
|
||||
"test:one": "polkadot-dev-run-test --runInBand"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.15.5",
|
||||
"@polkadot/dev": "^0.62.67",
|
||||
"@polkadot/ts": "^0.4.8",
|
||||
"@babel/core": "^7.16.0",
|
||||
"@polkadot/dev": "^0.63.27",
|
||||
"@polkadot/ts": "^0.4.13",
|
||||
"@types/ed2curve": "^0.2.2",
|
||||
"@types/jest": "^27.0.1"
|
||||
"@types/jest": "^27.0.2"
|
||||
},
|
||||
"version": "7.4.1",
|
||||
"packageManager": "yarn@3.0.1"
|
||||
"resolutions": {
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
{
|
||||
"name": "@polkadot/hw-ledger-transports",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"main": "node.js",
|
||||
"browser": "browser.js",
|
||||
"react-native": "react-native.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/hw-ledger-transports#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/hw-ledger-transports",
|
||||
"repository": {
|
||||
"directory": "packages/hw-ledger-transports",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@ledgerhq/hw-transport": "^6.7.0",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.7.0",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.7.0"
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@ledgerhq/hw-transport": "^6.11.2",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.11.2",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.11.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.7.0"
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.11.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.8.2' };
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
{
|
||||
"name": "@polkadot/hw-ledger",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/hw-ledger#readme",
|
||||
"license": "Apache-2.0",
|
||||
"main": "index.js",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/hw-ledger",
|
||||
"repository": {
|
||||
"directory": "packages/hw-ledger",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/hw-ledger-transports": "7.4.1",
|
||||
"@polkadot/util": "7.4.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/hw-ledger-transports": "7.8.2",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@zondax/ledger-substrate": "^0.18.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type Transport from '@ledgerhq/hw-transport';
|
||||
import type { SubstrateApp } from '@zondax/ledger-substrate';
|
||||
|
||||
import { newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newStatemineApp } from '@zondax/ledger-substrate';
|
||||
import { newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newStatemineApp } from '@zondax/ledger-substrate';
|
||||
|
||||
// These match up with the keys of the knownLedger object in the @polkadot/networks/defaults.ts
|
||||
export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp> = {
|
||||
@@ -12,6 +12,7 @@ export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp>
|
||||
'dock-mainnet': newDockApp,
|
||||
edgeware: newEdgewareApp,
|
||||
equilibrium: newEquilibriumApp,
|
||||
genshiro: newGenshiroApp,
|
||||
kusama: newKusamaApp,
|
||||
'nodle-chain': newNodleApp,
|
||||
polkadot: newPolkadotApp,
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.8.2' };
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
export type LedgerTypes = 'hid' | 'u2f' | 'webusb';
|
||||
|
||||
export interface AccountOptions {
|
||||
@@ -15,7 +17,7 @@ export interface LedgerAddress {
|
||||
}
|
||||
|
||||
export interface LedgerSignature {
|
||||
signature: string;
|
||||
signature: HexString;
|
||||
}
|
||||
|
||||
export interface LedgerVersion {
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
{
|
||||
"name": "@polkadot/keyring",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"description": "Keyring management",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "Keyring management",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||
"license": "Apache-2.0",
|
||||
"main": "index.js",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/keyring",
|
||||
"repository": {
|
||||
"directory": "packages/keyring",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"repository": "github:polkadot-js/common",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/util": "7.4.1",
|
||||
"@polkadot/util-crypto": "7.4.1"
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/util-crypto": "7.8.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "7.4.1",
|
||||
"@polkadot/util-crypto": "7.4.1"
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/util-crypto": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('keypair', (): void => {
|
||||
it('allows adding from JSON', (): void => {
|
||||
expect(
|
||||
keyring.addFromJson(
|
||||
JSON.parse('{"address":"5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua","encoded":"0xb4a14995d25ab609f3686e9fa45f1fb237cd833f33f00d4b12c51858ca070d96972e47d73aae5eeb0fc06f923826cf0943fdb02c2c2ee30ef52a7912663053940d1da4da66b3a3f520ae07422c1c94b2d95690fca9d1f4a997623bb2923a8833280e19e7f72c3c5cfa343974e60e2b3dc53b404fdaf330756daad5e4e3","encoding":{"content":"pkcs8","type":"xsalsa20-poly1305","version":"0"},"meta":{"isTesting":true,"name":"alice"}}')
|
||||
JSON.parse('{"address":"5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua","encoded":"0xb4a14995d25ab609f3686e9fa45f1fb237cd833f33f00d4b12c51858ca070d96972e47d73aae5eeb0fc06f923826cf0943fdb02c2c2ee30ef52a7912663053940d1da4da66b3a3f520ae07422c1c94b2d95690fca9d1f4a997623bb2923a8833280e19e7f72c3c5cfa343974e60e2b3dc53b404fdaf330756daad5e4e3","encoding":{"content":"pkcs8","type":"xsalsa20-poly1305","version":"0"},"meta":{"isTesting":true,"name":"alice"}}') as KeyringPair$Json
|
||||
).publicKey
|
||||
).toEqual(
|
||||
new Uint8Array([209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79])
|
||||
@@ -121,6 +121,18 @@ describe('keypair', (): void => {
|
||||
).toEqual('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
|
||||
});
|
||||
|
||||
it('creates with integer derivations', (): void => {
|
||||
// MAX_SAFE_INTEGER
|
||||
expect(
|
||||
keyring.createFromUri('//9007199254740991').address
|
||||
).toEqual('5CDsyNZyqxLpHnTvknr68anUcYoBFjZbFKiEJJf4prB75Uog');
|
||||
|
||||
// MAX_SAFE_INTEGER + extra digits
|
||||
expect(
|
||||
keyring.createFromUri('//900719925474099999').address
|
||||
).toEqual('5GHj2D7RG2m2DXYwGSDpXwuuxn53G987i7p2EQVDqP4NYu4q');
|
||||
});
|
||||
|
||||
it('creates via dev seed (2-byte encoding)', (): void => {
|
||||
keyring.setSS58Format(252);
|
||||
|
||||
@@ -160,7 +172,7 @@ describe('keypair', (): void => {
|
||||
it('allows adding from JSON', (): void => {
|
||||
expect(
|
||||
keyring.addFromJson(
|
||||
JSON.parse('{"address":"5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua","encoded":"0xb4a14995d25ab609f3686e9fa45f1fb237cd833f33f00d4b12c51858ca070d96972e47d73aae5eeb0fc06f923826cf0943fdb02c2c2ee30ef52a7912663053940d1da4da66b3a3f520ae07422c1c94b2d95690fca9d1f4a997623bb2923a8833280e19e7f72c3c5cfa343974e60e2b3dc53b404fdaf330756daad5e4e3","encoding":{"content":"pkcs8","type":"xsalsa20-poly1305","version":"0"},"meta":{"isTesting":true,"name":"alice"}}')
|
||||
JSON.parse('{"address":"5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua","encoded":"0xb4a14995d25ab609f3686e9fa45f1fb237cd833f33f00d4b12c51858ca070d96972e47d73aae5eeb0fc06f923826cf0943fdb02c2c2ee30ef52a7912663053940d1da4da66b3a3f520ae07422c1c94b2d95690fca9d1f4a997623bb2923a8833280e19e7f72c3c5cfa343974e60e2b3dc53b404fdaf330756daad5e4e3","encoding":{"content":"pkcs8","type":"xsalsa20-poly1305","version":"0"},"meta":{"isTesting":true,"name":"alice"}}') as KeyringPair$Json
|
||||
).publicKey
|
||||
).toEqual(
|
||||
new Uint8Array([209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79])
|
||||
@@ -239,7 +251,7 @@ describe('keypair', (): void => {
|
||||
it('allows adding from JSON', (): void => {
|
||||
expect(
|
||||
keyring.addFromJson(
|
||||
JSON.parse('{"address":"5DzMsaYFhmpRdErWrP6K6PD7UXzYoeETToSBUrZSvxasqWRz","encoded":"0xa192d39b42bc1601bf61df31039a554228593fadf870bc837b658a5114627aca199fff596260c95fe8994c66a47636cf0270aa08f402ba5541038753960d00e6c3af5e239ec58fb1eef3db7d6bc266f4853bdfe4ed17122d9092d879014d53980d2ee57f6f55a88c38836447d8645008e8815379626addc8f81f80cd49a2","encoding":{"content":"pkcs8","type":"xsalsa20-poly1305","version":"2"},"meta":{}}')
|
||||
JSON.parse('{"address":"5DzMsaYFhmpRdErWrP6K6PD7UXzYoeETToSBUrZSvxasqWRz","encoded":"0xa192d39b42bc1601bf61df31039a554228593fadf870bc837b658a5114627aca199fff596260c95fe8994c66a47636cf0270aa08f402ba5541038753960d00e6c3af5e239ec58fb1eef3db7d6bc266f4853bdfe4ed17122d9092d879014d53980d2ee57f6f55a88c38836447d8645008e8815379626addc8f81f80cd49a2","encoding":{"content":"pkcs8","type":"xsalsa20-poly1305","version":"2"},"meta":{}}') as KeyringPair$Json
|
||||
).address
|
||||
).toEqual('5DzMsaYFhmpRdErWrP6K6PD7UXzYoeETToSBUrZSvxasqWRz');
|
||||
});
|
||||
@@ -247,7 +259,7 @@ describe('keypair', (): void => {
|
||||
it('allows creation from JSON', (): void => {
|
||||
keyring.setSS58Format(2);
|
||||
const pair = keyring.createFromJson(
|
||||
JSON.parse('{"address":"0x02fde629668eb2bcc7d748f40a7e597f7c7b363498ff3db31f03ce4854937883ad","encoded":"qIhAhKqtf2iyEoWEr8nmBdksSI8EHHCpgJHToqd6Pl8AgAAAAQAAAAgAAADDZ//fj/BRRj+0+bl1KAlYgoPJp6nEUwiw0fVqO2BW4mjEgQ+iWwJEgDf1JUtecbzOlfhTXBzqX/dIYzLgUADrF4EFEPpboCWiU1iN7W/3DM1cOTRVvTGcbdIqW//z3axhz961qzeJVUIFgllwGe/euLUPIlKbIkiN/CsRYdQ=","encoding":{"content":["pkcs8","ecdsa"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{"genesisHash":"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","name":"ecdsa","tags":[],"whenCreated":1600925898271}}')
|
||||
JSON.parse('{"address":"0x02fde629668eb2bcc7d748f40a7e597f7c7b363498ff3db31f03ce4854937883ad","encoded":"qIhAhKqtf2iyEoWEr8nmBdksSI8EHHCpgJHToqd6Pl8AgAAAAQAAAAgAAADDZ//fj/BRRj+0+bl1KAlYgoPJp6nEUwiw0fVqO2BW4mjEgQ+iWwJEgDf1JUtecbzOlfhTXBzqX/dIYzLgUADrF4EFEPpboCWiU1iN7W/3DM1cOTRVvTGcbdIqW//z3axhz961qzeJVUIFgllwGe/euLUPIlKbIkiN/CsRYdQ=","encoding":{"content":["pkcs8","ecdsa"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{"genesisHash":"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","name":"ecdsa","tags":[],"whenCreated":1600925898271}}') as KeyringPair$Json
|
||||
);
|
||||
|
||||
expect(pair.address).toEqual('DHL8HKFuTTR55JzzLmkJRCAfPBbuevKaT9cXikxbEV97Ko8');
|
||||
@@ -256,7 +268,7 @@ describe('keypair', (): void => {
|
||||
|
||||
it('fails toJson() when password is incorrect', (): void => {
|
||||
const pair = keyring.createFromJson(
|
||||
JSON.parse('{"address":"0x02fde629668eb2bcc7d748f40a7e597f7c7b363498ff3db31f03ce4854937883ad","encoded":"qIhAhKqtf2iyEoWEr8nmBdksSI8EHHCpgJHToqd6Pl8AgAAAAQAAAAgAAADDZ//fj/BRRj+0+bl1KAlYgoPJp6nEUwiw0fVqO2BW4mjEgQ+iWwJEgDf1JUtecbzOlfhTXBzqX/dIYzLgUADrF4EFEPpboCWiU1iN7W/3DM1cOTRVvTGcbdIqW//z3axhz961qzeJVUIFgllwGe/euLUPIlKbIkiN/CsRYdQ=","encoding":{"content":["pkcs8","ecdsa"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{"genesisHash":"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","name":"ecdsa","tags":[],"whenCreated":1600925898271}}')
|
||||
JSON.parse('{"address":"0x02fde629668eb2bcc7d748f40a7e597f7c7b363498ff3db31f03ce4854937883ad","encoded":"qIhAhKqtf2iyEoWEr8nmBdksSI8EHHCpgJHToqd6Pl8AgAAAAQAAAAgAAADDZ//fj/BRRj+0+bl1KAlYgoPJp6nEUwiw0fVqO2BW4mjEgQ+iWwJEgDf1JUtecbzOlfhTXBzqX/dIYzLgUADrF4EFEPpboCWiU1iN7W/3DM1cOTRVvTGcbdIqW//z3axhz961qzeJVUIFgllwGe/euLUPIlKbIkiN/CsRYdQ=","encoding":{"content":["pkcs8","ecdsa"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{"genesisHash":"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","name":"ecdsa","tags":[],"whenCreated":1600925898271}}') as KeyringPair$Json
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -266,7 +278,7 @@ describe('keypair', (): void => {
|
||||
|
||||
it('pass toJson() when password is correct', (): void => {
|
||||
const pair = keyring.createFromJson(
|
||||
JSON.parse('{"address":"0x02fde629668eb2bcc7d748f40a7e597f7c7b363498ff3db31f03ce4854937883ad","encoded":"qIhAhKqtf2iyEoWEr8nmBdksSI8EHHCpgJHToqd6Pl8AgAAAAQAAAAgAAADDZ//fj/BRRj+0+bl1KAlYgoPJp6nEUwiw0fVqO2BW4mjEgQ+iWwJEgDf1JUtecbzOlfhTXBzqX/dIYzLgUADrF4EFEPpboCWiU1iN7W/3DM1cOTRVvTGcbdIqW//z3axhz961qzeJVUIFgllwGe/euLUPIlKbIkiN/CsRYdQ=","encoding":{"content":["pkcs8","ecdsa"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{"genesisHash":"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","name":"ecdsa","tags":[],"whenCreated":1600925898271}}')
|
||||
JSON.parse('{"address":"0x02fde629668eb2bcc7d748f40a7e597f7c7b363498ff3db31f03ce4854937883ad","encoded":"qIhAhKqtf2iyEoWEr8nmBdksSI8EHHCpgJHToqd6Pl8AgAAAAQAAAAgAAADDZ//fj/BRRj+0+bl1KAlYgoPJp6nEUwiw0fVqO2BW4mjEgQ+iWwJEgDf1JUtecbzOlfhTXBzqX/dIYzLgUADrF4EFEPpboCWiU1iN7W/3DM1cOTRVvTGcbdIqW//z3axhz961qzeJVUIFgllwGe/euLUPIlKbIkiN/CsRYdQ=","encoding":{"content":["pkcs8","ecdsa"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{"genesisHash":"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","name":"ecdsa","tags":[],"whenCreated":1600925898271}}') as KeyringPair$Json
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -393,7 +405,7 @@ describe('keypair', (): void => {
|
||||
|
||||
it('allows adding from JSON', (): void => {
|
||||
const pair = keyring.addFromJson(
|
||||
JSON.parse('{"address":"KWCv1L3QX9LDPwY4VzvLmarEmXjVJidUzZcinvVnmxAJJCBou","encoded":"U8qFEaghhmNV2PgFhjqzmhyUy37Ok7abfFU2MNsBd0sAgAAAAQAAAAgAAAA3+NniKogzNphiMNueB1X0sGA07B6CaXWfpXPx45iSXoTTprwzU5mOoSqUWO0GKHROI72LN+uJ8Yfv6Ll6JOOV3VPKfoVoFmYm+zDrrMPa0gk5E5kUuSijxADcE6zUrliPVr0Ix/qaghu5SJ7RtWDQLBf4Hp86SJ8Gg6gTSSk=","encoding":{"content":["pkcs8","ethereum"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{}}')
|
||||
JSON.parse('{"address":"KWCv1L3QX9LDPwY4VzvLmarEmXjVJidUzZcinvVnmxAJJCBou","encoded":"U8qFEaghhmNV2PgFhjqzmhyUy37Ok7abfFU2MNsBd0sAgAAAAQAAAAgAAAA3+NniKogzNphiMNueB1X0sGA07B6CaXWfpXPx45iSXoTTprwzU5mOoSqUWO0GKHROI72LN+uJ8Yfv6Ll6JOOV3VPKfoVoFmYm+zDrrMPa0gk5E5kUuSijxADcE6zUrliPVr0Ix/qaghu5SJ7RtWDQLBf4Hp86SJ8Gg6gTSSk=","encoding":{"content":["pkcs8","ethereum"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{}}') as KeyringPair$Json
|
||||
);
|
||||
|
||||
expect(pair.publicKey).toEqual(hexToU8a('0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077'));
|
||||
@@ -410,7 +422,7 @@ describe('keypair', (): void => {
|
||||
const MESSAGE = stringToU8a('just some test message');
|
||||
const signer = keyring.createFromUri(PHRASE);
|
||||
const verifier = keyring.addFromJson(
|
||||
JSON.parse('{"address":"KWCv1L3QX9LDPwY4VzvLmarEmXjVJidUzZcinvVnmxAJJCBou","encoded":"U8qFEaghhmNV2PgFhjqzmhyUy37Ok7abfFU2MNsBd0sAgAAAAQAAAAgAAAA3+NniKogzNphiMNueB1X0sGA07B6CaXWfpXPx45iSXoTTprwzU5mOoSqUWO0GKHROI72LN+uJ8Yfv6Ll6JOOV3VPKfoVoFmYm+zDrrMPa0gk5E5kUuSijxADcE6zUrliPVr0Ix/qaghu5SJ7RtWDQLBf4Hp86SJ8Gg6gTSSk=","encoding":{"content":["pkcs8","ethereum"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{}}')
|
||||
JSON.parse('{"address":"KWCv1L3QX9LDPwY4VzvLmarEmXjVJidUzZcinvVnmxAJJCBou","encoded":"U8qFEaghhmNV2PgFhjqzmhyUy37Ok7abfFU2MNsBd0sAgAAAAQAAAAgAAAA3+NniKogzNphiMNueB1X0sGA07B6CaXWfpXPx45iSXoTTprwzU5mOoSqUWO0GKHROI72LN+uJ8Yfv6Ll6JOOV3VPKfoVoFmYm+zDrrMPa0gk5E5kUuSijxADcE6zUrliPVr0Ix/qaghu5SJ7RtWDQLBf4Hp86SJ8Gg6gTSSk=","encoding":{"content":["pkcs8","ethereum"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{}}') as KeyringPair$Json
|
||||
);
|
||||
|
||||
const signature = signer.sign(MESSAGE);
|
||||
@@ -427,7 +439,7 @@ describe('keypair', (): void => {
|
||||
const MESSAGE = stringToU8a('just some test message');
|
||||
const signer = keyring.createFromUri(PHRASE);
|
||||
const verifier = keyring.addFromJson(
|
||||
JSON.parse('{"address":"KWCv1L3QX9LDPwY4VzvLmarEmXjVJidUzZcinvVnmxAJJCBou","encoded":"U8qFEaghhmNV2PgFhjqzmhyUy37Ok7abfFU2MNsBd0sAgAAAAQAAAAgAAAA3+NniKogzNphiMNueB1X0sGA07B6CaXWfpXPx45iSXoTTprwzU5mOoSqUWO0GKHROI72LN+uJ8Yfv6Ll6JOOV3VPKfoVoFmYm+zDrrMPa0gk5E5kUuSijxADcE6zUrliPVr0Ix/qaghu5SJ7RtWDQLBf4Hp86SJ8Gg6gTSSk=","encoding":{"content":["pkcs8","ethereum"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{}}')
|
||||
JSON.parse('{"address":"KWCv1L3QX9LDPwY4VzvLmarEmXjVJidUzZcinvVnmxAJJCBou","encoded":"U8qFEaghhmNV2PgFhjqzmhyUy37Ok7abfFU2MNsBd0sAgAAAAQAAAAgAAAA3+NniKogzNphiMNueB1X0sGA07B6CaXWfpXPx45iSXoTTprwzU5mOoSqUWO0GKHROI72LN+uJ8Yfv6Ll6JOOV3VPKfoVoFmYm+zDrrMPa0gk5E5kUuSijxADcE6zUrliPVr0Ix/qaghu5SJ7RtWDQLBf4Hp86SJ8Gg6gTSSk=","encoding":{"content":["pkcs8","ethereum"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"meta":{}}') as KeyringPair$Json
|
||||
);
|
||||
|
||||
const signature = signer.sign(MESSAGE, { withType: true });
|
||||
@@ -496,7 +508,7 @@ describe('keypair', (): void => {
|
||||
});
|
||||
|
||||
it('can decode from a version 2 JSON file', (): void => {
|
||||
const pair = keyring.addFromJson(JSON.parse(PAIR));
|
||||
const pair = keyring.addFromJson(JSON.parse(PAIR) as KeyringPair$Json);
|
||||
|
||||
pair.decodePkcs8(PASS2);
|
||||
|
||||
@@ -526,7 +538,7 @@ describe('keypair', (): void => {
|
||||
});
|
||||
|
||||
it('can decode from a version 3 JSON file', (): void => {
|
||||
const pair = keyring.addFromJson(JSON.parse(PAIR));
|
||||
const pair = keyring.addFromJson(JSON.parse(PAIR) as KeyringPair$Json);
|
||||
|
||||
pair.decodePkcs8(PASS3);
|
||||
|
||||
@@ -545,7 +557,7 @@ describe('keypair', (): void => {
|
||||
});
|
||||
|
||||
it('can decode from a version 3 JSON file', (): void => {
|
||||
const pair = keyring.addFromJson(JSON.parse(PAIR));
|
||||
const pair = keyring.addFromJson(JSON.parse(PAIR) as KeyringPair$Json);
|
||||
|
||||
pair.decodePkcs8(PASS3);
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ const keypairFromSeed = {
|
||||
sr25519: (seed: Uint8Array): Keypair => schnorrkelFromSeed(seed)
|
||||
};
|
||||
|
||||
function pairToPublic ({ publicKey }: KeyringPair): Uint8Array {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* # @polkadot/keyring
|
||||
*
|
||||
@@ -235,7 +239,7 @@ export class Keyring implements KeyringInstance {
|
||||
return this.type === 'ethereum'
|
||||
? ethereumEncode(address)
|
||||
: encodeAddress(address, isUndefined(ss58Format) ? this.#ss58 : ss58Format);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @name getPair
|
||||
@@ -262,11 +266,7 @@ export class Keyring implements KeyringInstance {
|
||||
* @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
public getPublicKeys (): Uint8Array[] {
|
||||
return this.#pairs
|
||||
.all()
|
||||
.map(({ publicKey }): Uint8Array =>
|
||||
publicKey
|
||||
);
|
||||
return this.#pairs.all().map(pairToPublic);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '7.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '7.8.2' };
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { EncryptedJsonEncoding, Keypair, KeypairType } from '@polkadot/util
|
||||
import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta, SignOptions } from '../types';
|
||||
import type { PairInfo } from './types';
|
||||
|
||||
import { assert, u8aConcat, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a, convertPublicKeyToCurve25519, convertSecretKeyToCurve25519, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, naclKeypairFromSeed as naclFromSeed, naclOpen, naclSeal, naclSign, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVrfSign, schnorrkelVrfVerify, secp256k1Compress, secp256k1Expand, secp256k1KeypairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify } from '@polkadot/util-crypto';
|
||||
|
||||
import { decodePair } from './decode';
|
||||
@@ -48,9 +48,8 @@ const TYPE_ADDRESS = {
|
||||
sr25519: (p: Uint8Array) => p
|
||||
};
|
||||
|
||||
// Not 100% correct, since it can be a Uint8Array, but an invalid one - just say "undefined" is anything non-valid
|
||||
function isLocked (secretKey?: Uint8Array): secretKey is undefined {
|
||||
return !secretKey || secretKey.length === 0 || secretKey.every((b) => b === 0);
|
||||
return !secretKey || u8aEmpty(secretKey);
|
||||
}
|
||||
|
||||
function vrfHash (proof: Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array {
|
||||
@@ -182,7 +181,7 @@ export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: P
|
||||
secretKey = new Uint8Array();
|
||||
},
|
||||
setMeta: (additional: KeyringPair$Meta): void => {
|
||||
meta = { ...meta, ...additional };
|
||||
meta = objectSpread({}, meta, additional);
|
||||
},
|
||||
sign: (message: HexString | string | Uint8Array, options: SignOptions = {}): Uint8Array => {
|
||||
assert(!isLocked(secretKey), 'Cannot sign with a locked key pair');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import type { KeyringPair$Json, KeyringPair$Meta } from '../types';
|
||||
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
import { jsonEncryptFormat } from '@polkadot/util-crypto';
|
||||
|
||||
interface PairStateJson {
|
||||
@@ -12,9 +13,8 @@ interface PairStateJson {
|
||||
}
|
||||
|
||||
export function pairToJson (type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
|
||||
return {
|
||||
...jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted),
|
||||
return objectSpread({}, jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
|
||||
address,
|
||||
meta
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
|
||||
// From https://github.com/paritytech/substrate/wiki/Secret-URI-Test-Vectors
|
||||
|
||||
import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
import Keyring from '.';
|
||||
|
||||
const PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
||||
const ETHEREUM_PHRASE = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
|
||||
|
||||
const TESTS = {
|
||||
ecdsa: [
|
||||
@@ -22,7 +25,17 @@ const TESTS = {
|
||||
{
|
||||
pk: '0x0381351b1b46d2602b0992bb5d5531f9c1696b0812feb2534b6884adc47e2e1d8b',
|
||||
ss: '0x31ea8795EE32D782C8ff41a5C68Dcbf0F5B27f6d',
|
||||
uri: "seed sock milk update focus rotate barely fade car face mechanic mercy/m/44'/60'/0'/0/0"
|
||||
uri: `${ETHEREUM_PHRASE}/m/44'/60'/0'/0/0`
|
||||
},
|
||||
{
|
||||
pk: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
||||
ss: '0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac',
|
||||
uri: `${PHRASE}/m/44'/60'/0'/0/0`
|
||||
},
|
||||
{
|
||||
pk: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
||||
ss: '0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0',
|
||||
uri: `${PHRASE}/m/44'/60'/0'/0/1`
|
||||
}
|
||||
],
|
||||
sr25519: [
|
||||
@@ -75,17 +88,17 @@ const TESTS = {
|
||||
};
|
||||
|
||||
describe('keyring.addFromUri', (): void => {
|
||||
const keyring = new Keyring({ type: 'sr25519' });
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
await cryptoWaitReady();
|
||||
});
|
||||
|
||||
Object.entries(TESTS).forEach(([type, tests]): void => {
|
||||
const keyring = new Keyring({ type: type as KeypairType });
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
await cryptoWaitReady();
|
||||
});
|
||||
|
||||
describe(type, (): void => {
|
||||
tests.forEach(({ pk, ss, uri }): void => {
|
||||
it(`creates ${uri}`, (): void => {
|
||||
const pair = keyring.addFromUri(uri, {}, type as 'sr25519');
|
||||
const pair = keyring.addFromUri(uri, {}, type as KeypairType);
|
||||
|
||||
expect(u8aToHex(pair.publicKey)).toEqual(pk);
|
||||
expect(pair.address).toEqual(ss);
|
||||
|
||||
@@ -12,7 +12,7 @@ import { createPair } from './pair';
|
||||
interface PairDef {
|
||||
name?: string;
|
||||
publicKey: Uint8Array;
|
||||
seed: string;
|
||||
seed?: string;
|
||||
secretKey?: Uint8Array;
|
||||
type: KeypairType
|
||||
}
|
||||
@@ -77,42 +77,36 @@ export const PAIRSETHEREUM: PairDef[] = [
|
||||
name: 'Alith',
|
||||
publicKey: hexToU8a('0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f'),
|
||||
secretKey: hexToU8a('0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133'), // nosemgrep
|
||||
seed: "m/44'/40'/0'/0",
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Baltathar',
|
||||
publicKey: hexToU8a('0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518'),
|
||||
secretKey: hexToU8a('0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b'), // nosemgrep
|
||||
seed: "m/44'/40'/0'/0",
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Charleth',
|
||||
publicKey: hexToU8a('0x0234637bdc0e89b5d46543bcbf8edff329d2702bc995e27e9af4b1ba009a3c2a5e'),
|
||||
secretKey: hexToU8a('0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b'), // nosemgrep
|
||||
seed: "m/44'/40'/0'/0",
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Dorothy',
|
||||
publicKey: hexToU8a('0x02a00d60b2b408c2a14c5d70cdd2c205db8985ef737a7e55ad20ea32cc9e7c417c'),
|
||||
secretKey: hexToU8a('0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68'), // nosemgrep
|
||||
seed: "m/44'/40'/0'/0",
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Ethan',
|
||||
publicKey: hexToU8a('0x025cdc005b752651cd3f728fb9192182acb3a9c89e19072cbd5b03f3ee1f1b3ffa'),
|
||||
secretKey: hexToU8a('0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4'), // nosemgrep
|
||||
seed: "m/44'/40'/0'/0",
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Faith',
|
||||
publicKey: hexToU8a('0x037964b6c9d546da4646ada28a99e34acaa1d14e7aba861a9055f9bd200c8abf74'),
|
||||
secretKey: hexToU8a('0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df'), // nosemgrep
|
||||
seed: "m/44'/40'/0'/0",
|
||||
type: 'ethereum'
|
||||
}
|
||||
];
|
||||
@@ -127,12 +121,16 @@ export function createTestKeyring (options: KeyringOptions = {}, isDerived = tru
|
||||
const keyring = new Keyring(options);
|
||||
const pairs: PairDef[] = (options.type && options.type === 'ethereum') ? PAIRSETHEREUM : PAIRSSR25519;
|
||||
|
||||
pairs.forEach(({ name, publicKey, secretKey, seed, type }): void => {
|
||||
for (const { name, publicKey, secretKey, seed, type } of pairs) {
|
||||
if (!name && !seed) {
|
||||
throw new Error('Testing pair should have either a name or a seed');
|
||||
}
|
||||
|
||||
const meta = {
|
||||
isTesting: true,
|
||||
name: name || seed.replace('//', '_').toLowerCase()
|
||||
name: name || (seed && seed.replace('//', '_').toLowerCase())
|
||||
};
|
||||
const pair = !isDerived && !name
|
||||
const pair = !isDerived && !name && seed
|
||||
? keyring.addFromUri(seed, meta, options.type)
|
||||
: keyring.addPair(
|
||||
createPair({ toSS58: keyring.encodeAddress, type }, { publicKey, secretKey }, meta)
|
||||
@@ -141,7 +139,7 @@ export function createTestKeyring (options: KeyringOptions = {}, isDerived = tru
|
||||
pair.lock = (): void => {
|
||||
// we don't have lock/unlock functionality here
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return keyring;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,9 @@ export function createTestPairs (options?: KeyringOptions, isDerived = true): Te
|
||||
const pairs = keyring.getPairs();
|
||||
const map: TestKeyringMap = { nobody: nobody() };
|
||||
|
||||
return pairs.reduce((result, pair): TestKeyringMap => {
|
||||
const { name } = pair.meta;
|
||||
for (const p of pairs) {
|
||||
map[p.meta.name as string] = p;
|
||||
}
|
||||
|
||||
result[name as string] = pair;
|
||||
|
||||
return result;
|
||||
}, map);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
{
|
||||
"name": "@polkadot/networks",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "A list of all available Substrate networks and their applicable prefixes",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"repository": "github:polkadot-js/common",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/networks#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/networks",
|
||||
"repository": {
|
||||
"directory": "packages/networks",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4"
|
||||
"@babel/runtime": "^7.16.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "7.4.1",
|
||||
"@polkadot/x-fetch": "7.4.1"
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/x-fetch": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,27 @@
|
||||
import fs from 'fs';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const SUBSTRATE_REGISTRY = 'https://raw.githubusercontent.com/paritytech/substrate/master/ss58-registry.json';
|
||||
import { substrateRegistry } from '../build/defaults.js';
|
||||
|
||||
function outputField (v) {
|
||||
const substrateRegistryRepo = substrateRegistry
|
||||
.replace('raw.githubusercontent.com', 'github.com')
|
||||
.split('main')[0];
|
||||
|
||||
function outputField (k, v) {
|
||||
if (typeof v === 'string') {
|
||||
return `'${v}'`;
|
||||
} else if (Array.isArray(v)) {
|
||||
return `[${v.map((v) => outputField(v)).join(', ')}]`;
|
||||
// new format is [] to indicate optionality
|
||||
return (['decimals', 'symbols'].includes(k) && !v.length)
|
||||
? null
|
||||
: `[${v.map((v) => outputField(k, v)).join(', ')}]`;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
async function getSubstrateRegistry () {
|
||||
const original = await fetch(SUBSTRATE_REGISTRY);
|
||||
const original = await fetch(substrateRegistry);
|
||||
const json = await original.json();
|
||||
|
||||
return json.registry
|
||||
@@ -25,7 +32,7 @@ async function getSubstrateRegistry () {
|
||||
` {\n${Object
|
||||
.entries(e)
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([k, v]) => ` ${k}: ${outputField(v)}`)
|
||||
.map(([k, v]) => ` ${k}: ${outputField(k, v)}`)
|
||||
.join(',\n')}\n }`
|
||||
)
|
||||
.join(',\n');
|
||||
@@ -36,11 +43,17 @@ getSubstrateRegistry()
|
||||
fs.writeFileSync('packages/networks/src/substrate.ts', `// Copyright 2017-2021 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//
|
||||
// Auto-generated by yarn networks:sync (via scripts/fromSubstrate.mjs)
|
||||
//
|
||||
// Do not edit, rather
|
||||
// - make a PR to the upstream registry as per ${SUBSTRATE_REGISTRY}
|
||||
// - yarn networks:sync
|
||||
// This file should never be edited manually. Rather the process is as follow -
|
||||
//
|
||||
// - make a PR to the upstream registry found at ${substrateRegistryRepo}
|
||||
// - ensure the PR gets merged
|
||||
// - yarn networks:sync in this repo to sync
|
||||
//
|
||||
// Any manual changes to this file will make CI cron checks fail and will be
|
||||
// lost when the registry is updated alongside the above sync.
|
||||
//
|
||||
|
||||
import type { KnownSubstrate } from './types';
|
||||
|
||||
@@ -8,10 +8,10 @@ import fs from 'fs';
|
||||
import { stringify } from '@polkadot/util';
|
||||
import { fetch } from '@polkadot/x-fetch';
|
||||
|
||||
import { substrateRegistry } from './defaults';
|
||||
import { allNetworks } from './';
|
||||
|
||||
const OUTPUT = './.github/ss58-check.md';
|
||||
const SUBSTRATE_REGISTRY = 'https://raw.githubusercontent.com/paritytech/substrate/master/ss58-registry.json';
|
||||
|
||||
function assertAndLog (check: boolean, error: string): void {
|
||||
if (!check) {
|
||||
@@ -28,7 +28,7 @@ describe('check latest Substrate ss58 registry', (): void => {
|
||||
let original: Ss58Registry;
|
||||
|
||||
beforeAll(async (): Promise<void> => {
|
||||
original = (await (await fetch(SUBSTRATE_REGISTRY)).json()) as Ss58Registry;
|
||||
original = (await (await fetch(substrateRegistry)).json()) as Ss58Registry;
|
||||
});
|
||||
|
||||
it('has the same number as the original', (): void => {
|
||||
@@ -60,7 +60,11 @@ describe('check latest Substrate ss58 registry', (): void => {
|
||||
return [
|
||||
`${n.displayName} (${n.prefix})`,
|
||||
other
|
||||
? fields.filter((f) => stringify(n[f]) !== stringify(other[f]))
|
||||
? fields.filter((f) =>
|
||||
['decimals', 'symbols'].includes(f)
|
||||
? stringify(n[f] || []) !== stringify(other[f] || [])
|
||||
: stringify(n[f]) !== stringify(other[f])
|
||||
)
|
||||
: []
|
||||
];
|
||||
})
|
||||
|
||||
@@ -3,11 +3,16 @@
|
||||
|
||||
import type { KnownGenesis, KnownIcon, KnownLedger, KnownTestnet } from './types';
|
||||
|
||||
export const substrateRegistry = 'https://raw.githubusercontent.com/paritytech/ss58-registry/main/ss58-registry.json';
|
||||
|
||||
// NOTE: In the case where the network was hard-spooned and multiple genesisHashes
|
||||
// are provided, it needs to be in reverse order, i.e. most-recent first, oldest
|
||||
// last. This make lookups for the current a simple genesisHash[0]
|
||||
// (See Kusama as an example)
|
||||
export const knownGenesis: KnownGenesis = {
|
||||
acala: [
|
||||
'0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c'
|
||||
],
|
||||
bifrost: [
|
||||
'0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed'
|
||||
],
|
||||
@@ -23,6 +28,9 @@ export const knownGenesis: KnownGenesis = {
|
||||
equilibrium: [
|
||||
'0x6f1a800de3daff7f5e037ddf66ab22ce03ab91874debeddb1086f5f7dbd48925'
|
||||
],
|
||||
genshiro: [
|
||||
'0x9b8cefc0eb5c568b527998bdd76c184e2b76ae561be76e4667072230217ea243'
|
||||
],
|
||||
hydradx: [
|
||||
'0xd2a620c27ec5cbc5621ff9a522689895074f7cca0d08e7134a7804e1a3ba86fc', // Snakenet Gen3-1
|
||||
'0x10af6e84234477d84dc572bac0789813b254aa490767ed06fb9591191d1073f9', // Snakenet Gen3
|
||||
@@ -81,6 +89,7 @@ export const knownLedger: KnownLedger = {
|
||||
'dock-mainnet': 0x00000252,
|
||||
edgeware: 0x0000020b,
|
||||
equilibrium: 0x05f5e0fd,
|
||||
genshiro: 0x05f5e0fc,
|
||||
kusama: 0x000001b2,
|
||||
'nodle-chain': 0x000003eb,
|
||||
polkadot: 0x00000162,
|
||||
@@ -90,6 +99,8 @@ export const knownLedger: KnownLedger = {
|
||||
|
||||
// testnets should not allow selection
|
||||
export const knownTestnet: KnownTestnet = {
|
||||
'': true, // this is the default non-network entry
|
||||
'cess-testnet': true,
|
||||
'dock-testnet': true,
|
||||
jupiter: true,
|
||||
'mathchain-testnet': true,
|
||||
|
||||
@@ -1,43 +1,64 @@
|
||||
// Copyright 2017-2021 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Network, SubstrateNetwork } from './types';
|
||||
import type { KnownSubstrate, Network, SubstrateNetwork } from './types';
|
||||
|
||||
import { knownGenesis, knownIcon, knownLedger, knownTestnet } from './defaults';
|
||||
import { knownSubstrate } from './substrate';
|
||||
|
||||
// These are known prefixes that are not sorted
|
||||
const UNSORTED = [0, 2, 42];
|
||||
const TESTNETS = ['testnet'];
|
||||
|
||||
export const allNetworks = knownSubstrate.map((o): SubstrateNetwork => {
|
||||
function toExpanded (o: KnownSubstrate): SubstrateNetwork {
|
||||
const network = o.network || '';
|
||||
const nameParts = network.replace(/_/g, '-').split('-');
|
||||
const n = o as SubstrateNetwork;
|
||||
|
||||
// ledger additions
|
||||
n.slip44 = knownLedger[network];
|
||||
n.hasLedgerSupport = !!n.slip44;
|
||||
|
||||
// general items
|
||||
n.genesisHash = knownGenesis[network] || [];
|
||||
n.icon = knownIcon[network] || 'substrate';
|
||||
n.isIgnored = !network || !!knownTestnet[network] || network.startsWith('reserved');
|
||||
|
||||
// filtering
|
||||
n.isTestnet = !!knownTestnet[network] || TESTNETS.includes(nameParts[nameParts.length - 1]);
|
||||
n.isIgnored = n.isTestnet || (!(o.standardAccount && o.decimals && o.symbols) && o.prefix !== 42);
|
||||
|
||||
return n;
|
||||
});
|
||||
}
|
||||
|
||||
function filterSelectable ({ genesisHash, prefix }: Network): boolean {
|
||||
return !!genesisHash.length || prefix === 42;
|
||||
}
|
||||
|
||||
function filterAvailable (n: SubstrateNetwork): n is Network {
|
||||
return !n.isIgnored && !!n.network;
|
||||
}
|
||||
|
||||
function sortNetworks (a: Network, b: Network): number {
|
||||
const isUnSortedA = UNSORTED.includes(a.prefix);
|
||||
const isUnSortedB = UNSORTED.includes(b.prefix);
|
||||
|
||||
return isUnSortedA === isUnSortedB
|
||||
? 0
|
||||
: isUnSortedA
|
||||
? -1
|
||||
: isUnSortedB
|
||||
? 1
|
||||
: a.displayName.localeCompare(b.displayName);
|
||||
}
|
||||
|
||||
// This is all the Substrate networks with our additional information
|
||||
export const allNetworks = knownSubstrate.map(toExpanded);
|
||||
|
||||
// The list of available/claimed prefixes
|
||||
// - no testnets
|
||||
// - we only include those where we have a standardAccount
|
||||
// - sort by name, however we keep 0, 2, 42 first in the list
|
||||
export const availableNetworks = allNetworks
|
||||
.filter((n): n is Network => !n.isIgnored && !!n.network)
|
||||
.sort((a, b) =>
|
||||
UNSORTED.includes(a.prefix) === UNSORTED.includes(b.prefix)
|
||||
? 0
|
||||
: UNSORTED.includes(a.prefix)
|
||||
? -1
|
||||
: UNSORTED.includes(b.prefix)
|
||||
? 1
|
||||
: a.displayName.localeCompare(b.displayName)
|
||||
);
|
||||
export const availableNetworks = allNetworks.filter(filterAvailable).sort(sortNetworks);
|
||||
|
||||
// A filtered list of those chains we have details about (genesisHashes)
|
||||
export const selectableNetworks = availableNetworks.filter((n) => n.genesisHash.length || n.prefix === 42);
|
||||
export const selectableNetworks = availableNetworks.filter(filterSelectable);
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '7.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '7.8.2' };
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
// Copyright 2017-2021 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//
|
||||
// Auto-generated by yarn networks:sync (via scripts/fromSubstrate.mjs)
|
||||
//
|
||||
// Do not edit, rather
|
||||
// - make a PR to the upstream registry as per https://raw.githubusercontent.com/paritytech/substrate/master/ss58-registry.json
|
||||
// - yarn networks:sync
|
||||
// This file should never be edited manually. Rather the process is as follow -
|
||||
//
|
||||
// - make a PR to the upstream registry found at https://github.com/paritytech/ss58-registry/
|
||||
// - ensure the PR gets merged
|
||||
// - yarn networks:sync in this repo to sync
|
||||
//
|
||||
// Any manual changes to this file will make CI cron checks fail and will be
|
||||
// lost when the registry is updated alongside the above sync.
|
||||
//
|
||||
|
||||
import type { KnownSubstrate } from './types';
|
||||
@@ -23,9 +29,9 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Bare 32-bit Schnorr/Ristretto (S/R 25519) public key.',
|
||||
network: null,
|
||||
network: 'BareSr25519',
|
||||
prefix: 1,
|
||||
standardAccount: null,
|
||||
standardAccount: 'Sr25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
@@ -41,9 +47,9 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Bare 32-bit Ed25519 public key.',
|
||||
network: null,
|
||||
network: 'BareEd25519',
|
||||
prefix: 3,
|
||||
standardAccount: null,
|
||||
standardAccount: 'Ed25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
@@ -264,13 +270,13 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Dhiway CORD Network',
|
||||
decimals: [12, 12],
|
||||
displayName: 'CORD Network',
|
||||
network: 'cord',
|
||||
prefix: 29,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['DCU'],
|
||||
website: 'https://dhiway.com/'
|
||||
symbols: ['DHI', 'WAY'],
|
||||
website: 'https://cord.network/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
@@ -387,14 +393,14 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
prefix: 42,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: 'https://substrate.dev/'
|
||||
website: 'https://substrate.io/'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Bare 32-bit ECDSA SECP-256k1 public key.',
|
||||
network: null,
|
||||
network: 'BareSecp256k1',
|
||||
prefix: 43,
|
||||
standardAccount: null,
|
||||
standardAccount: 'secp256k1',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
@@ -533,6 +539,15 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
symbols: ['KMA'],
|
||||
website: 'https://manta.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Polkadex Mainnet',
|
||||
network: 'polkadex',
|
||||
prefix: 88,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PDEX'],
|
||||
website: 'https://polkadex.trade'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'PolkaSmith Canary Network',
|
||||
@@ -614,6 +629,24 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
symbols: ['NET'],
|
||||
website: 'https://social.network'
|
||||
},
|
||||
{
|
||||
decimals: [15],
|
||||
displayName: 'QUARTZ by UNIQUE',
|
||||
network: 'quartz_mainnet',
|
||||
prefix: 255,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['QTZ'],
|
||||
website: 'https://unique.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Pioneer Network by Bit.Country',
|
||||
network: 'pioneer_network',
|
||||
prefix: 268,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['NEER'],
|
||||
website: 'https://bit.country'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Moonbeam',
|
||||
@@ -640,5 +673,32 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
standardAccount: '*25519',
|
||||
symbols: ['BSX'],
|
||||
website: 'https://bsx.fi'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'CESS Testnet',
|
||||
network: 'cess-testnet',
|
||||
prefix: 10042,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['TCESS'],
|
||||
website: 'https://cess.cloud'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'CESS',
|
||||
network: 'cess',
|
||||
prefix: 10043,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CESS'],
|
||||
website: 'https://cess.cloud'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Automata ContextFree',
|
||||
network: 'contextfree',
|
||||
prefix: 11820,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CTX'],
|
||||
website: 'https://ata.network'
|
||||
}
|
||||
];
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface KnownSubstrate {
|
||||
displayName: string;
|
||||
network: string | null;
|
||||
prefix: number;
|
||||
standardAccount: '*25519' | 'secp256k1' | null;
|
||||
standardAccount: '*25519' | 'Ed25519' | 'Sr25519' | 'secp256k1' | null;
|
||||
symbols: string[] | null;
|
||||
website: string | null;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ export interface SubstrateNetwork extends KnownSubstrate {
|
||||
hasLedgerSupport: boolean;
|
||||
icon: Icon;
|
||||
isIgnored: boolean;
|
||||
isTestnet: boolean;
|
||||
slip44?: number | null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,36 @@
|
||||
{
|
||||
"name": "@polkadot/util-crypto",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "A collection of useful crypto utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/util-crypto",
|
||||
"repository": {
|
||||
"directory": "packages/util-crypto",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./cryptoInit.js",
|
||||
"./cryptoInit.cjs",
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/networks": "7.4.1",
|
||||
"@polkadot/util": "7.4.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/networks": "7.8.2",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/wasm-crypto": "^4.2.1",
|
||||
"@polkadot/x-randomvalues": "7.4.1",
|
||||
"base-x": "^3.0.8",
|
||||
"@polkadot/x-randomvalues": "7.8.2",
|
||||
"base-x": "^3.0.9",
|
||||
"base64-js": "^1.5.1",
|
||||
"blakejs": "^1.1.1",
|
||||
"bn.js": "^4.12.0",
|
||||
@@ -42,11 +46,11 @@
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"@types/create-hash": "^1.2.2",
|
||||
"@types/elliptic": "^6.4.13",
|
||||
"@types/elliptic": "^6.4.14",
|
||||
"@types/scryptsy": "^2.0.0",
|
||||
"@types/xxhashjs": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "7.4.1"
|
||||
"@polkadot/util": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Network } from '@polkadot/networks/types';
|
||||
|
||||
import { availableNetworks } from '../networks';
|
||||
|
||||
function networkToPrefix ({ prefix }: Network): number {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
export const defaults = {
|
||||
allowedDecodedLengths: [1, 2, 4, 8, 32, 33],
|
||||
// publicKey has prefix + 2 checksum bytes, short only prefix + 1 checksum byte
|
||||
allowedEncodedLengths: [3, 4, 6, 10, 35, 36, 37, 38],
|
||||
allowedPrefix: availableNetworks.map(({ prefix }) => prefix),
|
||||
allowedPrefix: availableNetworks.map(networkToPrefix),
|
||||
prefix: 42
|
||||
};
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { DeriveJunction } from '../key/DeriveJunction';
|
||||
import type { Prefix } from './types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { keyExtractPath } from '../key';
|
||||
import { DeriveJunction } from '../key/DeriveJunction';
|
||||
import { schnorrkelDerivePublic } from '../schnorrkel';
|
||||
import { decodeAddress } from './decode';
|
||||
import { encodeAddress } from './encode';
|
||||
|
||||
function filterHard ({ isHard }: DeriveJunction): boolean {
|
||||
return isHard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name deriveAddress
|
||||
* @summary Creates a sr25519 derived address from the supplied and path.
|
||||
@@ -21,9 +25,13 @@ import { encodeAddress } from './encode';
|
||||
export function deriveAddress (who: HexString | Uint8Array | string, suri: string, ss58Format?: Prefix): string {
|
||||
const { path } = keyExtractPath(suri);
|
||||
|
||||
assert(path.length && !path.some((path) => path.isHard), 'Expected suri to contain a combination of non-hard paths');
|
||||
assert(path.length && !path.every(filterHard), 'Expected suri to contain a combination of non-hard paths');
|
||||
|
||||
return encodeAddress(path.reduce((publicKey: Uint8Array, path: DeriveJunction): Uint8Array => {
|
||||
return schnorrkelDerivePublic(publicKey, path.chainCode);
|
||||
}, decodeAddress(who)), ss58Format);
|
||||
let publicKey = decodeAddress(who);
|
||||
|
||||
for (const { chainCode } of path) {
|
||||
publicKey = schnorrkelDerivePublic(publicKey, chainCode);
|
||||
}
|
||||
|
||||
return encodeAddress(publicKey, ss58Format);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { HexString } from '@polkadot/util/types';
|
||||
import { bnToU8a, compactToU8a, stringToU8a, u8aConcat, u8aSorted } from '@polkadot/util';
|
||||
|
||||
import { blake2AsU8a } from '../blake2/asU8a';
|
||||
import { decodeAddress } from './decode';
|
||||
import { addressToU8a } from './util';
|
||||
|
||||
const PREFIX = stringToU8a('modlpy/utilisuba');
|
||||
|
||||
@@ -16,7 +16,7 @@ export function createKeyMulti (who: (HexString | Uint8Array | string)[], thresh
|
||||
u8aConcat(
|
||||
PREFIX,
|
||||
compactToU8a(who.length),
|
||||
...u8aSorted(who.map((who) => decodeAddress(who))),
|
||||
...u8aSorted(who.map(addressToU8a)),
|
||||
bnToU8a(threshold, { bitLength: 16, isLe: true })
|
||||
)
|
||||
);
|
||||
|
||||
@@ -6,11 +6,13 @@ import type { Prefix } from './types';
|
||||
|
||||
import { u8aSorted } from '@polkadot/util';
|
||||
|
||||
import { decodeAddress } from './decode';
|
||||
import { encodeAddress } from './encode';
|
||||
import { addressToU8a } from './util';
|
||||
|
||||
export function sortAddresses (addresses: (HexString | Uint8Array | string)[], ss58Format?: Prefix): string[] {
|
||||
const u8aToAddress = (u8a: Uint8Array) => encodeAddress(u8a, ss58Format);
|
||||
|
||||
return u8aSorted(
|
||||
addresses.map((who) => decodeAddress(who))
|
||||
).map((u8a) => encodeAddress(u8a, ss58Format));
|
||||
addresses.map(addressToU8a)
|
||||
).map(u8aToAddress);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { decodeAddress } from './decode';
|
||||
|
||||
export function addressToU8a (who: string | Uint8Array): Uint8Array {
|
||||
return decodeAddress(who);
|
||||
}
|
||||
@@ -9,13 +9,11 @@ import { BASE32_ALPHABET, BITS_PER_CHAR } from './bs32';
|
||||
import { base32Validate } from './validate';
|
||||
|
||||
// Build the character lookup table:
|
||||
const LOOKUP = BASE32_ALPHABET
|
||||
.split('')
|
||||
.reduce((lookup: Record<string, number>, char: string, index: number): Record<string, number> => {
|
||||
lookup[char] = index;
|
||||
const LOOKUP = BASE32_ALPHABET.split('').reduce<Record<string, number>>((lookup, a, i) => {
|
||||
lookup[a] = i;
|
||||
|
||||
return lookup;
|
||||
}, {});
|
||||
return lookup;
|
||||
}, {});
|
||||
|
||||
/** @internal */
|
||||
function decode (output: Uint8Array, input: string, offset: number): [Uint8Array, number, number] {
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { validateChars } from '../base58/validate';
|
||||
import { createValidateFn } from '../base58/validate';
|
||||
import { BASE32_ALPHABET } from './bs32';
|
||||
|
||||
const BASE_CONFIG = { alphabet: BASE32_ALPHABET, ipfsChar: 'b', type: 'base32' };
|
||||
|
||||
/**
|
||||
* @name base32Validate
|
||||
* @summary Validates a base32 value.
|
||||
* @description
|
||||
* Validates that the supplied value is valid base32
|
||||
*/
|
||||
export function base32Validate (value?: string | null, ipfsCompat?: boolean): value is string {
|
||||
return validateChars(BASE_CONFIG, value, ipfsCompat);
|
||||
}
|
||||
export const base32Validate = createValidateFn({ alphabet: BASE32_ALPHABET, ipfsChar: 'b', type: 'base32' });
|
||||
|
||||
@@ -11,17 +11,17 @@ interface CheckConfig {
|
||||
type: string;
|
||||
}
|
||||
|
||||
const BASE_CONFIG = { alphabet: BASE58_ALPHABET, ipfsChar: 'z', type: 'base58' };
|
||||
export function createValidateFn ({ alphabet, ipfsChar, type }: CheckConfig): (value?: unknown, ipfsCompat?: boolean) => value is string {
|
||||
return (value?: unknown, ipfsCompat?: boolean): value is string => {
|
||||
assert(value && typeof value === 'string', () => `Expected non-null, non-empty ${type} string input`);
|
||||
assert(!ipfsCompat || value[0] === ipfsChar, () => `Expected ${type} to start with '${ipfsChar}'`);
|
||||
|
||||
export function validateChars ({ alphabet, ipfsChar, type }: CheckConfig, value?: unknown, ipfsCompat?: boolean): true {
|
||||
assert(value && typeof value === 'string', () => `Expected non-null, non-empty ${type} string input`);
|
||||
assert(!ipfsCompat || value[0] === ipfsChar, () => `Expected ${type} to start with '${ipfsChar}'`);
|
||||
for (let i = (ipfsCompat ? 1 : 0); i < value.length; i++) {
|
||||
assert(alphabet.includes(value[i]), () => `Invalid ${type} character "${value[i]}" (0x${value.charCodeAt(i).toString(16)}) at index ${i}`);
|
||||
}
|
||||
|
||||
for (let i = (ipfsCompat ? 1 : 0); i < value.length; i++) {
|
||||
assert(alphabet.includes(value[i]), () => `Invalid ${type} character "${value[i]}" (0x${value.charCodeAt(i).toString(16)}) at index ${i}`);
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,6 +30,4 @@ export function validateChars ({ alphabet, ipfsChar, type }: CheckConfig, value?
|
||||
* @description
|
||||
* Validates that the supplied value is valid base58
|
||||
*/
|
||||
export function base58Validate (value?: string | null, ipfsCompat?: boolean): value is string {
|
||||
return validateChars(BASE_CONFIG, value, ipfsCompat);
|
||||
}
|
||||
export const base58Validate = createValidateFn({ alphabet: BASE58_ALPHABET, ipfsChar: 'z', type: 'base58' });
|
||||
|
||||
@@ -19,7 +19,7 @@ import { blake2b, isReady } from '@polkadot/wasm-crypto';
|
||||
* ```javascript
|
||||
* import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa53, 0xf98, 0x1c, 0x4d, 0x0d]
|
||||
* 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 {
|
||||
|
||||
@@ -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 hd = createCoded(I.slice(0, 32), I.slice(32));
|
||||
let hd = createCoded(I.slice(0, 32), I.slice(32));
|
||||
|
||||
if (!path || path === 'm' || path === 'M' || path === "m'" || path === "M'") {
|
||||
return hd;
|
||||
@@ -52,16 +52,15 @@ export function hdEthereum (seed: Uint8Array, path = ''): Keypair {
|
||||
|
||||
assert(hdValidatePath(path), 'Invalid derivation path');
|
||||
|
||||
return path
|
||||
.split('/')
|
||||
.slice(1)
|
||||
.reduce((hd: CodedKeypair, c): CodedKeypair =>
|
||||
deriveChild(
|
||||
hd, parseInt(c, 10) + (
|
||||
(c.length > 1) && c.endsWith("'")
|
||||
? HARDENED
|
||||
: 0
|
||||
)
|
||||
), hd
|
||||
);
|
||||
const parts = path.split('/').slice(1);
|
||||
|
||||
for (const p of parts) {
|
||||
hd = deriveChild(hd, parseInt(p, 10) + (
|
||||
(p.length > 1) && p.endsWith("'")
|
||||
? HARDENED
|
||||
: 0
|
||||
));
|
||||
}
|
||||
|
||||
return hd;
|
||||
}
|
||||
|
||||
@@ -12,27 +12,28 @@ import { ledgerDerivePrivate } from './derivePrivate';
|
||||
import { ledgerMaster } from './master';
|
||||
|
||||
export function hdLedger (_mnemonic: string, path: string): Keypair {
|
||||
const parts = _mnemonic
|
||||
const words = _mnemonic
|
||||
.split(' ')
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s);
|
||||
|
||||
assert([12, 24, 25].includes(parts.length), 'Expected a mnemonic with 24 words (or 25 including a password)');
|
||||
assert([12, 24, 25].includes(words.length), 'Expected a mnemonic with 24 words (or 25 including a password)');
|
||||
|
||||
const [mnemonic, password] = parts.length === 25
|
||||
? [parts.slice(0, 24).join(' '), parts[24]]
|
||||
: [parts.join(' '), ''];
|
||||
const [mnemonic, password] = words.length === 25
|
||||
? [words.slice(0, 24).join(' '), words[24]]
|
||||
: [words.join(' '), ''];
|
||||
|
||||
assert(mnemonicValidate(mnemonic), 'Invalid mnemonic passed to ledger derivation');
|
||||
assert(hdValidatePath(path), 'Invalid derivation path');
|
||||
|
||||
return naclKeypairFromSeed(
|
||||
path
|
||||
.split('/')
|
||||
.slice(1)
|
||||
.map((n) => parseInt(n.replace(/'$/, ''), 10))
|
||||
.map((n) => (n < HARDENED) ? (n + HARDENED) : n)
|
||||
.reduce((x, n) => ledgerDerivePrivate(x, n), ledgerMaster(mnemonic, password))
|
||||
.slice(0, 32)
|
||||
);
|
||||
const parts = path.split('/').slice(1);
|
||||
let seed = ledgerMaster(mnemonic, password);
|
||||
|
||||
for (const p of parts) {
|
||||
const n = parseInt(p.replace(/'$/, ''), 10);
|
||||
|
||||
seed = ledgerDerivePrivate(seed, (n < HARDENED) ? (n + HARDENED) : n);
|
||||
}
|
||||
|
||||
return naclKeypairFromSeed(seed.slice(0, 32));
|
||||
}
|
||||
|
||||
@@ -10,9 +10,15 @@ export function hdValidatePath (path: string): boolean {
|
||||
|
||||
const parts = path.split('/').slice(1);
|
||||
|
||||
return parts.every((n) => /^\d+'?$/.test(n)) && (
|
||||
!parts
|
||||
.map((n) => parseInt(n.replace(/'$/, ''), 10))
|
||||
.some((n) => isNaN(n) || (n >= HARDENED) || (n < 0))
|
||||
);
|
||||
for (const p of parts) {
|
||||
const n = /^\d+'?$/.test(p)
|
||||
? parseInt(p.replace(/'$/, ''), 10)
|
||||
: Number.NaN;
|
||||
|
||||
if (isNaN(n) || (n >= HARDENED) || (n < 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { BN, bnToHex, compactAddLength, hexToU8a, isBigInt, isBn, isHex, isNumber, isString, stringToU8a } from '@polkadot/util';
|
||||
import { BN, bnToU8a, compactAddLength, hexToU8a, isBigInt, isBn, isHex, isNumber, isString, stringToU8a } from '@polkadot/util';
|
||||
|
||||
import { blake2AsU8a } from '../blake2/asU8a';
|
||||
|
||||
@@ -28,7 +28,7 @@ export class DeriveJunction {
|
||||
|
||||
result.soft(
|
||||
RE_NUMBER.test(code)
|
||||
? parseInt(code, 10)
|
||||
? new BN(code, 10)
|
||||
: code
|
||||
);
|
||||
|
||||
@@ -61,7 +61,7 @@ export class DeriveJunction {
|
||||
|
||||
public soft (value: HexString | number | string | bigint | BN | Uint8Array): DeriveJunction {
|
||||
if (isNumber(value) || isBn(value) || isBigInt(value)) {
|
||||
return this.soft(bnToHex(value, BN_OPTIONS));
|
||||
return this.soft(bnToU8a(value, BN_OPTIONS));
|
||||
} else if (isHex(value)) {
|
||||
return this.soft(hexToU8a(value));
|
||||
} else if (isString(value)) {
|
||||
|
||||
@@ -23,9 +23,9 @@ export function keyExtractPath (derivePath: string): ExtractResult {
|
||||
if (parts) {
|
||||
constructed = parts.join('');
|
||||
|
||||
parts.forEach((value: string): void => {
|
||||
path.push(DeriveJunction.from(value.substr(1)));
|
||||
});
|
||||
for (const p of parts) {
|
||||
path.push(DeriveJunction.from(p.substr(1)));
|
||||
}
|
||||
}
|
||||
|
||||
assert(constructed === derivePath, () => `Re-constructed path "${constructed}" does not match input`);
|
||||
|
||||
@@ -18,8 +18,11 @@ const generators = {
|
||||
|
||||
export function keyFromPath (pair: Keypair, path: DeriveJunction[], type: KeypairType): Keypair {
|
||||
const keyHdkd = generators[type];
|
||||
let result = pair;
|
||||
|
||||
return path.reduce((pair, junction): Keypair => {
|
||||
return keyHdkd(pair, junction);
|
||||
}, pair);
|
||||
for (const junction of path) {
|
||||
result = keyHdkd(result, junction);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Keypair } from '../types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { DeriveJunction } from './DeriveJunction';
|
||||
|
||||
export function createSeedDeriveFn (fromSeed: (seed: Uint8Array) => Keypair, derive: (seed: Uint8Array, chainCode: Uint8Array) => Uint8Array): (keypair: Keypair, junction: DeriveJunction) => Keypair {
|
||||
return (keypair: Keypair, { chainCode, isHard }: DeriveJunction): Keypair => {
|
||||
assert(isHard, 'A soft key was found in the path and is not supported');
|
||||
|
||||
return fromSeed(
|
||||
derive(keypair.secretKey.subarray(0, 32), chainCode)
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -1,18 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Keypair } from '../types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { secp256k1DeriveHard } from '../secp256k1/deriveHard';
|
||||
import { secp256k1KeypairFromSeed } from '../secp256k1/keypair/fromSeed';
|
||||
import { DeriveJunction } from './DeriveJunction';
|
||||
import { createSeedDeriveFn } from './hdkdDerive';
|
||||
|
||||
export function keyHdkdEcdsa (keypair: Keypair, { chainCode, isHard }: DeriveJunction): Keypair {
|
||||
assert(isHard, 'A soft key was found in the path (and is unsupported)');
|
||||
|
||||
return secp256k1KeypairFromSeed(
|
||||
secp256k1DeriveHard(keypair.secretKey.subarray(0, 32), chainCode)
|
||||
);
|
||||
}
|
||||
export const keyHdkdEcdsa = createSeedDeriveFn(secp256k1KeypairFromSeed, secp256k1DeriveHard);
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Keypair } from '../types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { naclDeriveHard } from '../nacl/deriveHard';
|
||||
import { naclKeypairFromSeed } from '../nacl/keypair/fromSeed';
|
||||
import { DeriveJunction } from './DeriveJunction';
|
||||
import { createSeedDeriveFn } from './hdkdDerive';
|
||||
|
||||
export function keyHdkdEd25519 (keypair: Keypair, { chainCode, isHard }: DeriveJunction): Keypair {
|
||||
assert(isHard, 'A soft key was found in the path (and is unsupported)');
|
||||
|
||||
return naclKeypairFromSeed(
|
||||
naclDeriveHard(keypair.secretKey.subarray(0, 32), chainCode)
|
||||
);
|
||||
}
|
||||
export const keyHdkdEd25519 = createSeedDeriveFn(naclKeypairFromSeed, naclDeriveHard);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { compactAddLength, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
import { assert, compactAddLength, isU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { blake2AsU8a } from '../blake2/asU8a';
|
||||
|
||||
const HDKD = compactAddLength(stringToU8a('Ed25519HDKD'));
|
||||
|
||||
export function naclDeriveHard (seed: Uint8Array, chainCode: Uint8Array): Uint8Array {
|
||||
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
|
||||
|
||||
return blake2AsU8a(
|
||||
u8aConcat(HDKD, seed, chainCode)
|
||||
);
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.8.2' };
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Keypair } from '../types';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
import { sr25519DeriveKeypairHard, sr25519DeriveKeypairSoft } from '@polkadot/wasm-crypto';
|
||||
import { assert, isU8a } from '@polkadot/util';
|
||||
|
||||
import { schnorrkelKeypairFromU8a } from './keypair/fromU8a';
|
||||
import { schnorrkelKeypairToU8a } from './keypair/toU8a';
|
||||
|
||||
export function schnorrkelDerive (keypair: Keypair, chainCode: HexString | Uint8Array | string, isHard: boolean): Keypair {
|
||||
return schnorrkelKeypairFromU8a(
|
||||
(isHard
|
||||
? sr25519DeriveKeypairHard
|
||||
: sr25519DeriveKeypairSoft
|
||||
)(
|
||||
schnorrkelKeypairToU8a(keypair),
|
||||
u8aToU8a(chainCode)
|
||||
)
|
||||
);
|
||||
export function createDeriveFn (derive: (pair: Uint8Array, cc: Uint8Array) => Uint8Array): (keypair: Keypair, chainCode: Uint8Array) => Keypair {
|
||||
return (keypair: Keypair, chainCode: Uint8Array): Keypair => {
|
||||
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
|
||||
|
||||
return schnorrkelKeypairFromU8a(
|
||||
derive(schnorrkelKeypairToU8a(keypair), chainCode)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Keypair } from '../types';
|
||||
import { sr25519DeriveKeypairHard } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { schnorrkelDerive } from './derive';
|
||||
import { createDeriveFn } from './derive';
|
||||
|
||||
export function schnorrkelDeriveHard (keypair: Keypair, chainCode: HexString | Uint8Array | string): Keypair {
|
||||
return schnorrkelDerive(keypair, chainCode, true);
|
||||
}
|
||||
export const schnorrkelDeriveHard = createDeriveFn(sr25519DeriveKeypairHard);
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { assert, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { sr25519DerivePublicSoft } from '@polkadot/wasm-crypto';
|
||||
|
||||
export function schnorrkelDerivePublic (publicKey: HexString | Uint8Array | string, chainCode: HexString | Uint8Array | string): Uint8Array {
|
||||
export function schnorrkelDerivePublic (publicKey: HexString | Uint8Array | string, chainCode: Uint8Array): Uint8Array {
|
||||
const publicKeyU8a = u8aToU8a(publicKey);
|
||||
|
||||
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
|
||||
assert(publicKeyU8a.length === 32, () => `Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
|
||||
|
||||
return sr25519DerivePublicSoft(publicKeyU8a, u8aToU8a(chainCode));
|
||||
return sr25519DerivePublicSoft(publicKeyU8a, chainCode);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Keypair } from '../types';
|
||||
import { sr25519DeriveKeypairSoft } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { schnorrkelDerive } from './derive';
|
||||
import { createDeriveFn } from './derive';
|
||||
|
||||
export function schnorrkelDeriveSoft (keypair: Keypair, chainCode: HexString | Uint8Array | string): Keypair {
|
||||
return schnorrkelDerive(keypair, chainCode, false);
|
||||
}
|
||||
export const schnorrkelDeriveSoft = createDeriveFn(sr25519DeriveKeypairSoft);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { compactAddLength, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
import { assert, compactAddLength, isU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { blake2AsU8a } from '../blake2/asU8a';
|
||||
|
||||
const HDKD = compactAddLength(stringToU8a('Secp256k1HDKD'));
|
||||
|
||||
export function secp256k1DeriveHard (seed: Uint8Array, chainCode: Uint8Array): Uint8Array {
|
||||
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
|
||||
|
||||
// NOTE This is specific to the Substrate HDD derivation, so always use the blake2 hasher
|
||||
return blake2AsU8a(u8aConcat(HDKD, seed, chainCode), 256);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { secp256k1 } from './secp256k1';
|
||||
*/
|
||||
export function secp256k1Recover (message: Uint8Array, signature: Uint8Array, recovery: number): Uint8Array {
|
||||
return new Uint8Array(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
||||
secp256k1
|
||||
.recoverPubKey(message, { r: signature.slice(0, 32), s: signature.slice(32, 64) }, recovery)
|
||||
.encode(null, true)
|
||||
|
||||
@@ -21,7 +21,7 @@ export function secp256k1Verify (message: HexString | Uint8Array | string, signa
|
||||
assert(u8a.length === 65, `Expected signature with 65 bytes, ${u8a.length} found instead`);
|
||||
|
||||
const publicKey = new Uint8Array(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
||||
secp256k1
|
||||
.recoverPubKey(
|
||||
secp256k1Hasher(hashType, message),
|
||||
|
||||
@@ -24,16 +24,17 @@ import xxhash64AsBn from './xxhash64/asBn';
|
||||
*/
|
||||
export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bitLength = 64, onlyJs = false): Uint8Array {
|
||||
const iterations = Math.ceil(bitLength / 64);
|
||||
const u8a = u8aToU8a(data);
|
||||
|
||||
if (isReady() && !onlyJs) {
|
||||
return twox(u8aToU8a(data), iterations);
|
||||
return twox(u8a, iterations);
|
||||
}
|
||||
|
||||
const u8a = new Uint8Array(Math.ceil(bitLength / 8));
|
||||
const result = new Uint8Array(Math.ceil(bitLength / 8));
|
||||
|
||||
for (let seed = 0; seed < iterations; seed++) {
|
||||
u8a.set(xxhash64AsBn(data, seed).toArray('le', 8), seed * 8);
|
||||
result.set(xxhash64AsBn(u8a, seed).toArray('le', 8), seed * 8);
|
||||
}
|
||||
|
||||
return u8a;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,11 @@
|
||||
|
||||
import xx from 'xxhashjs';
|
||||
|
||||
import { isBuffer, isString, u8aToBuffer } from '@polkadot/util';
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
|
||||
export default function xxhash64AsValue (data: Buffer | Uint8Array | string, seed: number): number {
|
||||
if (isBuffer(data) || isString(data)) {
|
||||
return xx.h64(data, seed);
|
||||
}
|
||||
|
||||
return xx.h64(
|
||||
u8aToBuffer(data),
|
||||
u8aToU8a(data).buffer,
|
||||
seed
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
declare module 'xxhashjs' {
|
||||
export interface HashInterface {
|
||||
(data: string | Buffer, seed: number): number;
|
||||
(data: string | Buffer | ArrayBuffer, seed: number): number;
|
||||
}
|
||||
|
||||
const h64: HashInterface;
|
||||
|
||||
+21
-17
@@ -1,27 +1,31 @@
|
||||
{
|
||||
"name": "@polkadot/util",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "A collection of useful utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/util",
|
||||
"repository": {
|
||||
"directory": "packages/util",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-textdecoder": "7.4.1",
|
||||
"@polkadot/x-textencoder": "7.4.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-textdecoder": "7.8.2",
|
||||
"@polkadot/x-textencoder": "7.8.2",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.12.0",
|
||||
"camelcase": "^6.2.0",
|
||||
|
||||
@@ -20,15 +20,19 @@
|
||||
*/
|
||||
export function arrayFlatten <T> (arrays: T[][]): T[] {
|
||||
// pre-allocate based on the combined size
|
||||
const output = new Array<T>(arrays.reduce((length, array) => length + array.length, 0));
|
||||
let size = 0;
|
||||
|
||||
for (const a of arrays) {
|
||||
size += a.length;
|
||||
}
|
||||
|
||||
const output = new Array<T>(size);
|
||||
let index = -1;
|
||||
|
||||
for (let a = 0; a < arrays.length; a++) {
|
||||
const array = arrays[a];
|
||||
|
||||
for (const a of arrays) {
|
||||
// instead of pushing, we just set the entries
|
||||
for (let e = 0; e < array.length; e++) {
|
||||
output[++index] = array[e];
|
||||
for (let e = 0; e < a.length; e++) {
|
||||
output[++index] = a[e];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,3 +10,4 @@ export { arrayFilter } from './filter';
|
||||
export { arrayFlatten } from './flatten';
|
||||
export { arrayRange } from './range';
|
||||
export { arrayShuffle } from './shuffle';
|
||||
export { arrayZip } from './zip';
|
||||
|
||||
@@ -21,5 +21,11 @@ import { assert } from '../assert';
|
||||
export function arrayRange (size: number, startAt = 0): number[] {
|
||||
assert(size > 0, 'Expected non-zero, positive number as a range size');
|
||||
|
||||
return new Array(size).fill(0).map((_, i) => i + startAt);
|
||||
const result = new Array<number>(size).fill(0);
|
||||
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
result[i] = i + startAt;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { arrayZip } from '.';
|
||||
|
||||
describe('arrayZip', (): void => {
|
||||
it('zips a simple one', (): void => {
|
||||
expect(
|
||||
arrayZip(['a', 'b', 'c'], [1, 2, 3])
|
||||
).toEqual([['a', 1], ['b', 2], ['c', 3]]);
|
||||
});
|
||||
|
||||
it('zips where values > keys', (): void => {
|
||||
expect(
|
||||
arrayZip(['a', 'b', 'c'], [1, 2, 3, 4])
|
||||
).toEqual([['a', 1], ['b', 2], ['c', 3]]);
|
||||
});
|
||||
|
||||
it('zips where values < keys', (): void => {
|
||||
expect(
|
||||
arrayZip(['a', 'b', 'c'], [1, 2])
|
||||
).toEqual([['a', 1], ['b', 2], ['c', undefined]]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function arrayZip <K, V> (keys: K[], values: V[]): [K, V][] {
|
||||
const result = new Array<[K, V]>(keys.length);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
result[i] = [keys[i], values[i]];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -9,4 +9,10 @@ describe('bnMax', (): void => {
|
||||
bnMax(new BN(1), new BN(2), new BN(3))
|
||||
).toEqual(new BN(3));
|
||||
});
|
||||
|
||||
it('finds BN maximum', (): void => {
|
||||
expect(
|
||||
bnMax(new BN(2), new BN(3), new BN(1))
|
||||
).toEqual(new BN(3));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BN, bnMin } from '.';
|
||||
describe('bnMin', (): void => {
|
||||
it('finds BN minimum', (): void => {
|
||||
expect(
|
||||
bnMin(new BN(1), new BN(2), new BN(3))
|
||||
bnMin(new BN(2), new BN(1), new BN(3))
|
||||
).toEqual(new BN(1));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { HexString, ToBn, ToBnOptions } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { u8aToHex } from '../u8a';
|
||||
import { bnToU8a } from './toU8a';
|
||||
|
||||
@@ -36,14 +37,14 @@ function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number
|
||||
return ZERO_STR;
|
||||
}
|
||||
|
||||
const _options = {
|
||||
isLe: false,
|
||||
isNegative: false,
|
||||
// Backwards-compatibility
|
||||
...(isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1)
|
||||
};
|
||||
|
||||
return u8aToHex(bnToU8a(value, _options));
|
||||
return u8aToHex(
|
||||
bnToU8a(value, objectSpread(
|
||||
{ isLe: false, isNegative: false },
|
||||
isNumber(arg1)
|
||||
? { bitLength: arg1, isLe: arg2 }
|
||||
: arg1
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
export { bnToHex };
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ToBn, ToBnOptions } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { bnToBn } from './toBn';
|
||||
|
||||
interface Options extends ToBnOptions {
|
||||
@@ -43,12 +44,12 @@ function createValue (valueBn: BN, byteLength: number, { isLe, isNegative }: Opt
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, options?: Options): Uint8Array;
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, bitLength?: number, isLe?: boolean): Uint8Array;
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, arg1: number | Options = { bitLength: -1, isLe: true, isNegative: false }, arg2?: boolean): Uint8Array {
|
||||
const options: Options = {
|
||||
bitLength: -1,
|
||||
isLe: true,
|
||||
isNegative: false,
|
||||
...isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1
|
||||
};
|
||||
const options: Options = objectSpread(
|
||||
{ bitLength: -1, isLe: true, isNegative: false },
|
||||
isNumber(arg1)
|
||||
? { bitLength: arg1, isLe: arg2 }
|
||||
: arg1
|
||||
);
|
||||
|
||||
const valueBn = bnToBn(value);
|
||||
const byteLength = options.bitLength === -1
|
||||
|
||||
@@ -7,5 +7,11 @@ import { BN } from './bn';
|
||||
export function checkMaxMin (type: 'max' | 'min', items: BN[]): BN {
|
||||
assert(items.length >= 1, 'Must provide one or more BN arguments');
|
||||
|
||||
return items.reduce<BN>((a, v) => BN[type](a, v), items[0]);
|
||||
let result = items[0];
|
||||
|
||||
for (const v of items) {
|
||||
result = BN[type](result, v);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,11 @@ export * from './extractTime';
|
||||
export * from './format';
|
||||
export * from './hex';
|
||||
export * from './is';
|
||||
export * from './lazy';
|
||||
export * from './logger';
|
||||
export * from './memoize';
|
||||
export * from './number';
|
||||
export * from './object';
|
||||
export * from './promisify';
|
||||
export * from './string';
|
||||
export * from './stringify';
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import type { Time } from './types';
|
||||
|
||||
import { objectSpread } from './object/spread';
|
||||
|
||||
const HRS = 60 * 60;
|
||||
const DAY = HRS * 24;
|
||||
|
||||
@@ -21,12 +23,12 @@ function addTime (a: Time, b: Time): Time {
|
||||
};
|
||||
}
|
||||
|
||||
const ZERO = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
||||
const ZERO: Time = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
||||
|
||||
function extractDays (milliseconds: number, hrs: number): Time {
|
||||
const days = Math.floor(hrs / 24);
|
||||
|
||||
return addTime({ ...ZERO, days }, extractTime(milliseconds - (days * DAY * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { days }), extractTime(milliseconds - (days * DAY * 1000)));
|
||||
}
|
||||
|
||||
function extractHrs (milliseconds: number, mins: number): Time {
|
||||
@@ -35,7 +37,7 @@ function extractHrs (milliseconds: number, mins: number): Time {
|
||||
if (hrs < 24) {
|
||||
const hours = Math.floor(hrs);
|
||||
|
||||
return addTime({ ...ZERO, hours }, extractTime(milliseconds - (hours * HRS * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { hours }), extractTime(milliseconds - (hours * HRS * 1000)));
|
||||
}
|
||||
|
||||
return extractDays(milliseconds, hrs);
|
||||
@@ -47,7 +49,7 @@ function extractMins (milliseconds: number, secs: number): Time {
|
||||
if (mins < 60) {
|
||||
const minutes = Math.floor(mins);
|
||||
|
||||
return addTime({ ...ZERO, minutes }, extractTime(milliseconds - (minutes * 60 * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { minutes }), extractTime(milliseconds - (minutes * 60 * 1000)));
|
||||
}
|
||||
|
||||
return extractHrs(milliseconds, mins);
|
||||
@@ -59,7 +61,7 @@ function extractSecs (milliseconds: number): Time {
|
||||
if (secs < 60) {
|
||||
const seconds = Math.floor(secs);
|
||||
|
||||
return addTime({ ...ZERO, seconds }, extractTime(milliseconds - (seconds * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { seconds }), extractTime(milliseconds - (seconds * 1000)));
|
||||
}
|
||||
|
||||
return extractMins(milliseconds, secs);
|
||||
@@ -81,7 +83,7 @@ export function extractTime (milliseconds?: number): Time {
|
||||
if (!milliseconds) {
|
||||
return ZERO;
|
||||
} else if (milliseconds < 1000) {
|
||||
return { ...ZERO, milliseconds };
|
||||
return objectSpread({}, ZERO, { milliseconds });
|
||||
}
|
||||
|
||||
return extractSecs(milliseconds);
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('hexHasPrefix', (): void => {
|
||||
|
||||
it('returns false when non-string value supplied', (): void => {
|
||||
expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument
|
||||
hexHasPrefix(false as any)
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ToBnOptions } from '../types';
|
||||
|
||||
import { BN } from '../bn/bn';
|
||||
import { isBoolean } from '../is/boolean';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { hexStripPrefix } from './stripPrefix';
|
||||
|
||||
function reverse (value: string): string {
|
||||
@@ -36,16 +37,12 @@ export function hexToBn (value?: string | null, options: ToBnOptions | boolean =
|
||||
return new BN(0);
|
||||
}
|
||||
|
||||
const _options: ToBnOptions = {
|
||||
isLe: false,
|
||||
isNegative: false,
|
||||
// Backwards-compatibility
|
||||
...(
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
: options
|
||||
)
|
||||
};
|
||||
const _options: ToBnOptions = objectSpread(
|
||||
{ isLe: false, isNegative: false },
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
: options
|
||||
);
|
||||
const _value = hexStripPrefix(value);
|
||||
|
||||
// FIXME: Use BN's 3rd argument `isLe` once this issue is fixed
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* @name isArray
|
||||
* @summary Tests for a Array instance.
|
||||
*/
|
||||
export function isArray <T> (value: unknown): value is Array<T> {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
@@ -8,6 +8,10 @@ describe('isAscii', (): void => {
|
||||
expect(isAscii('Hello\tWorld!\n\rTesting')).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on an non-ascii string', (): void => {
|
||||
expect(isAscii('你好,世界')).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns true for ASCII bytes', (): void => {
|
||||
expect(isAscii(new Uint8Array([0x31, 0x32, 0x20, 10]))).toEqual(true);
|
||||
});
|
||||
@@ -27,4 +31,8 @@ describe('isAscii', (): void => {
|
||||
it('returns false for non-printable characters', (): void => {
|
||||
expect(isAscii(new Uint8Array([5]))).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false for hex input, non-ascii', (): void => {
|
||||
expect(isAscii('0x010203')).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,10 +4,24 @@
|
||||
import type { U8aLike } from '../types';
|
||||
|
||||
import { u8aToU8a } from '../u8a/toU8a';
|
||||
import { isHex } from './hex';
|
||||
import { isString } from './string';
|
||||
|
||||
const FORMAT = [9, 10, 13];
|
||||
|
||||
/** @internal */
|
||||
function getCharCode0 (s: string): number {
|
||||
return s.charCodeAt(0);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function isAsciiByte (b: number): boolean {
|
||||
return (b < 127) && (
|
||||
(b >= 32) ||
|
||||
FORMAT.includes(b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name isAscii
|
||||
* @summary Tests if the input is printable ASCII
|
||||
@@ -15,7 +29,15 @@ const FORMAT = [9, 10, 13];
|
||||
* Checks to see if the input string or Uint8Array is printable ASCII, 32-127 + formatters
|
||||
*/
|
||||
export function isAscii (value?: U8aLike | null): boolean {
|
||||
return value
|
||||
? !u8aToU8a(value).some((byte) => (byte >= 127) || (byte < 32 && !FORMAT.includes(byte)))
|
||||
: isString(value);
|
||||
const isStringIn = isString(value);
|
||||
|
||||
if (value) {
|
||||
return (
|
||||
isStringIn && !isHex(value)
|
||||
? value.toString().split('').map(getCharCode0)
|
||||
: u8aToU8a(value)
|
||||
).every(isAsciiByte);
|
||||
}
|
||||
|
||||
return isStringIn;
|
||||
}
|
||||
|
||||
@@ -17,5 +17,10 @@ interface Compact<T> {
|
||||
* @summary Tests for SCALE-Compact-like object instance.
|
||||
*/
|
||||
export function isCompact <T> (value: unknown): value is Compact<T> {
|
||||
return isFunction((value as Compact<T>).toBigInt) && isFunction((value as Compact<T>).toBn) && isFunction((value as Compact<T>).toNumber) && isFunction((value as Compact<T>).unwrap);
|
||||
return (
|
||||
isFunction((value as Compact<T>).toBigInt) &&
|
||||
isFunction((value as Compact<T>).toBn) &&
|
||||
isFunction((value as Compact<T>).toNumber) &&
|
||||
isFunction((value as Compact<T>).unwrap)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isInstanceOf } from './instanceOf';
|
||||
|
||||
/**
|
||||
* @name isError
|
||||
* @summary Tests for a `Error` object instance.
|
||||
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
|
||||
* ```
|
||||
*/
|
||||
export function isError (value: unknown): value is Error {
|
||||
return isInstanceOf(value, Error);
|
||||
return value instanceof Error;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
/**
|
||||
* @summary Type checking utilities
|
||||
*/
|
||||
export { isArray } from './array';
|
||||
export { isAscii } from './ascii';
|
||||
export { isBigInt } from './bigInt';
|
||||
export { isBn } from './bn';
|
||||
|
||||
@@ -5,8 +5,7 @@ import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
|
||||
interface Observable {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
next: (...params: any[]) => any;
|
||||
next: (...params: unknown[]) => unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,5 +23,8 @@ interface Observable {
|
||||
* ```
|
||||
*/
|
||||
export function isObservable (value: unknown): value is Observable {
|
||||
return isObject(value) && isFunction((value as Observable).next);
|
||||
return (
|
||||
isObject(value) &&
|
||||
isFunction((value as Observable).next)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isInstanceOf } from './instanceOf';
|
||||
|
||||
/**
|
||||
* @name isU8a
|
||||
* @summary Tests for a `Uint8Array` object instance.
|
||||
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
|
||||
* ```
|
||||
*/
|
||||
export function isU8a (value?: unknown): value is Uint8Array {
|
||||
return isInstanceOf(value, Uint8Array);
|
||||
return value instanceof Uint8Array;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isUndefined } from './is/undefined';
|
||||
|
||||
type AnyFn = (...args: unknown[]) => unknown;
|
||||
|
||||
type WithToString = { toString: () => string };
|
||||
|
||||
export function lazyMethod <T, K> (result: Record<string, T> | AnyFn, item: K, creator: (d: K) => T, getName?: (d: K) => string): void {
|
||||
const name = getName
|
||||
? getName(item)
|
||||
: (item as WithToString).toString();
|
||||
let value: T | undefined;
|
||||
|
||||
Object.defineProperty(result, name, {
|
||||
// This allows for re-configuration with the embedded defineProperty below
|
||||
// and ensures that on tested browsers and Node, it _will_ be redefined
|
||||
// and thus short-circuited for future access
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
|
||||
// Use a function here, we don't want to capture the outer this, i.e.
|
||||
// don't use arrow functions in this context since we have a this inside
|
||||
get: function (): T {
|
||||
// This check should _always_ be false and unneeded, since we override
|
||||
// with a value below ... however we ensure we are quire vigilant against
|
||||
// all environment failures, so we are rather be safe than sorry
|
||||
if (isUndefined(value)) {
|
||||
value = creator(item);
|
||||
|
||||
try {
|
||||
// re-define the property as a value, next time around this
|
||||
// getter will only return the computed value
|
||||
Object.defineProperty(this, name, { value });
|
||||
} catch {
|
||||
// ignore any errors, since this _should_ not happen due to
|
||||
// the "configurable" property above. But if it ever does
|
||||
// from here-on we will be the cached value the next time
|
||||
// around (with a very slight dip in performance)
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function lazyMethods <T, K> (result: Record<string, T>, items: K[], creator: (v: K) => T, getName?: (m: K) => string): Record<string, T> {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
lazyMethod(result, items[i], creator, getName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+60
-31
@@ -24,11 +24,13 @@ const logTo = {
|
||||
|
||||
function formatOther (value: unknown): unknown {
|
||||
if (value && isObject(value) && value.constructor === Object) {
|
||||
return Object.keys(value).reduce((result: Record<string, unknown>, key): Record<string, unknown> => {
|
||||
result[key] = loggerFormat(value[key]);
|
||||
const result: Record<string, unknown> = {};
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
for (const k of Object.keys(value)) {
|
||||
result[k] = loggerFormat(value[k]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -46,6 +48,20 @@ export function loggerFormat (value: unknown): unknown {
|
||||
return formatOther(value);
|
||||
}
|
||||
|
||||
function formatWithLength (maxLength: number): (v: unknown) => unknown {
|
||||
return (v: unknown): unknown => {
|
||||
if (maxLength <= 0) {
|
||||
return v;
|
||||
}
|
||||
|
||||
const r = `${v as string}`;
|
||||
|
||||
return r.length < maxLength
|
||||
? v
|
||||
: `${r.substr(0, maxLength)} ...`;
|
||||
};
|
||||
}
|
||||
|
||||
function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1): void {
|
||||
if (values.length === 1 && isFunction(values[0])) {
|
||||
const fnResult = values[0]() as unknown;
|
||||
@@ -58,17 +74,7 @@ function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1):
|
||||
type,
|
||||
...values
|
||||
.map(loggerFormat)
|
||||
.map((v) => {
|
||||
if (maxSize <= 0) {
|
||||
return v;
|
||||
}
|
||||
|
||||
const r = `${v as string}`;
|
||||
|
||||
return r.length < maxSize
|
||||
? v
|
||||
: `${r.substr(0, maxSize)} ...`;
|
||||
})
|
||||
.map(formatWithLength(maxSize))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,27 +82,50 @@ function noop (): void {
|
||||
// noop
|
||||
}
|
||||
|
||||
function isDebugOn (e: string, type: string): boolean {
|
||||
return !!e && (
|
||||
e === '*' ||
|
||||
type === e ||
|
||||
(
|
||||
e.endsWith('*') &&
|
||||
type.startsWith(e.slice(0, -1))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function isDebugOff (e: string, type: string): boolean {
|
||||
return !!e && (
|
||||
e.startsWith('-') &&
|
||||
(
|
||||
type === e.slice(1) ||
|
||||
(
|
||||
e.endsWith('*') &&
|
||||
type.startsWith(e.slice(1, -1))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function getDebugFlag (env: string[], type: string): boolean {
|
||||
let flag = false;
|
||||
|
||||
for (const e of env) {
|
||||
if (isDebugOn(e, type)) {
|
||||
flag = true;
|
||||
} else if (isDebugOff(e, type)) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
function parseEnv (type: string): [boolean, number] {
|
||||
const env = (typeof process === 'object' ? process : {}).env || {};
|
||||
const maxSize = parseInt(env.DEBUG_MAX || '-1', 10);
|
||||
|
||||
let isDebugOn = false;
|
||||
|
||||
(env.DEBUG || '')
|
||||
.toLowerCase()
|
||||
.split(',')
|
||||
.forEach((e) => {
|
||||
if (!!e && (e === '*' || type === e || (e.endsWith('*') && type.startsWith(e.slice(0, -1))))) {
|
||||
isDebugOn = true;
|
||||
}
|
||||
|
||||
if (!!e && e.startsWith('-') && (type === e.slice(1) || (e.endsWith('*') && type.startsWith(e.slice(1, -1))))) {
|
||||
isDebugOn = false;
|
||||
}
|
||||
});
|
||||
|
||||
return [
|
||||
isDebugOn,
|
||||
getDebugFlag((env.DEBUG || '').toLowerCase().split(','), type),
|
||||
isNaN(maxSize)
|
||||
? -1
|
||||
: maxSize
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { objectClear } from '.';
|
||||
|
||||
describe('objectClear', (): void => {
|
||||
it('clears an object', (): void => {
|
||||
expect(
|
||||
objectClear({ a: 1, b: 2, c: { d: 3, e: 4 } })
|
||||
).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function objectClear <T> (value: Record<string, T>): Record<string, T> {
|
||||
const keys = Object.keys(value);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
delete value[keys[i]];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { objectSpread } from './spread';
|
||||
|
||||
export function objectCopy <T extends object> (source: T): T {
|
||||
return objectSpread({}, source);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { objectClear } from './clear';
|
||||
export { objectCopy } from './copy';
|
||||
export { objectProperty, objectProperties } from './property';
|
||||
export { objectSpread } from './spread';
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isUndefined } from '../is/undefined';
|
||||
|
||||
export function objectProperty (that: object, key: string, getter: (k: string) => unknown): void {
|
||||
// We use both the hasOwnProperty as well as isUndefined checks here, since it may be set
|
||||
// in inherited classes and _Own_ properties refers to the class only, not only parents
|
||||
if (!Object.prototype.hasOwnProperty.call(that, key) && isUndefined((that as Record<string, unknown>)[key])) {
|
||||
const get = () => getter(key);
|
||||
|
||||
Object.defineProperty(that, key, { enumerable: true, get });
|
||||
}
|
||||
}
|
||||
|
||||
export function objectProperties (that: object, keys: string[], getter: (k: string, i: number) => unknown): void {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
objectProperty(that, keys[i], (k) => getter(k, i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { objectSpread } from '.';
|
||||
|
||||
describe('objectSpread', (): void => {
|
||||
it('spreads an object from multiple sources', (): void => {
|
||||
expect(
|
||||
objectSpread({ a: 1 }, { b: 2 }, { a: 2, c: { d: 3, e: 4 } })
|
||||
).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } });
|
||||
});
|
||||
|
||||
it('spreads an object from multiple sources (with null & undefined)', (): void => {
|
||||
expect(
|
||||
objectSpread({ a: 1 }, null, { b: 2 }, undefined, { a: 2, c: { d: 3, e: 4 } })
|
||||
).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function objectSpread <T extends object> (dest: object, ...sources: (object | undefined | null)[]): T {
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const src = sources[i];
|
||||
|
||||
if (src) {
|
||||
const keys = Object.keys(src);
|
||||
|
||||
for (let j = 0; j < keys.length; j++) {
|
||||
const key = keys[j];
|
||||
|
||||
(dest as Record<string, unknown>)[key] = (src as Record<string, unknown>)[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dest as T;
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', version: '7.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/util', version: '7.8.2' };
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
import { isBigInt } from './is/bigInt';
|
||||
|
||||
export function stringify (args: unknown, space?: string | number): string {
|
||||
return JSON.stringify(
|
||||
args,
|
||||
(_, value: unknown) =>
|
||||
isBigInt(value)
|
||||
? value.toString()
|
||||
: value,
|
||||
space
|
||||
);
|
||||
/** @internal */
|
||||
function replacer (_: unknown, v: unknown): unknown {
|
||||
return isBigInt(v)
|
||||
? v.toString()
|
||||
: v;
|
||||
}
|
||||
|
||||
export function stringify (args: unknown, space?: string | number): string {
|
||||
return JSON.stringify(args, replacer, space);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
function isByteZero (v: number): boolean {
|
||||
return !v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name u8aEmpty
|
||||
* @summary Tests for a `Uint8Array` for emptyness
|
||||
@@ -8,5 +12,5 @@
|
||||
* Checks to see if the input `Uint8Array` has zero length or contains all 0 values.
|
||||
*/
|
||||
export function u8aEmpty (value: Uint8Array): boolean {
|
||||
return value.length === 0 || value.every((v) => !v);
|
||||
return value.length === 0 || value.every(isByteZero);
|
||||
}
|
||||
|
||||
@@ -44,30 +44,36 @@ function getEntry (name: string): VersionPath[] {
|
||||
}
|
||||
|
||||
function getVersionLength (all: { version: string }[]): number {
|
||||
return all.reduce((max, { version }) => Math.max(max, version.length), 0);
|
||||
let length = 0;
|
||||
|
||||
for (const { version } of all) {
|
||||
length = Math.max(length, version.length);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function flattenInfos (all: PackageJson[]): string {
|
||||
const verLength = getVersionLength(all);
|
||||
const stringify = ({ name, version }: PackageJson) =>
|
||||
`\t${version.padEnd(verLength)}\t${name}`;
|
||||
|
||||
return all
|
||||
.map(({ name, version }) => `\t${version.padEnd(verLength)}\t${name}`)
|
||||
.join('\n');
|
||||
return all.map(stringify).join('\n');
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function flattenVersions (entry: VersionPath[]): string {
|
||||
const all = entry.map((version: VersionPath | string): VersionPath =>
|
||||
const toPath = (version: VersionPath | string): VersionPath =>
|
||||
isString(version)
|
||||
? { version }
|
||||
: version
|
||||
);
|
||||
: version;
|
||||
const all = entry.map(toPath);
|
||||
const verLength = getVersionLength(all);
|
||||
const stringify = ({ path, version }: VersionPath) =>
|
||||
`\t${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`;
|
||||
|
||||
return all
|
||||
.map(({ path, version }) => `\t${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`)
|
||||
.join('\n');
|
||||
return all.map(stringify).join('\n');
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
{
|
||||
"name": "@polkadot/x-bundle",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "A bundler helper",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-bundle#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/x-bundle",
|
||||
"repository": {
|
||||
"directory": "packages/x-bundle",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/util": "7.4.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/util": "7.8.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.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.8.2' };
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
{
|
||||
"name": "@polkadot/x-fetch",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "A cross-environment fetch replacement",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-fetch#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/x-fetch",
|
||||
"repository": {
|
||||
"directory": "packages/x-fetch",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-global": "7.4.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-global": "7.8.2",
|
||||
"@types/node-fetch": "^2.5.12",
|
||||
"node-fetch": "^2.6.2"
|
||||
"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.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.8.2' };
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
{
|
||||
"name": "@polkadot/x-global",
|
||||
"version": "7.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"contributors": [],
|
||||
"description": "A cross-environment global replacement",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-global#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/x-global",
|
||||
"repository": {
|
||||
"directory": "packages/x-global",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4"
|
||||
"@babel/runtime": "^7.16.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
type GlobalThis = typeof globalThis;
|
||||
|
||||
function evaluateThis (fn: (code: string) => unknown): GlobalThis {
|
||||
return fn('return this') as GlobalThis;
|
||||
}
|
||||
|
||||
export const xglobal = (
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
@@ -12,5 +18,5 @@ export const xglobal = (
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: this as unknown as (Window & typeof globalThis)
|
||||
: evaluateThis(Function)
|
||||
);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user