Skip to content

Commit d960128

Browse files
hw-{ledger, ledger-transports}, keyring, networks, util, util-crypto, x-{bigint, fetch, global, randomvalues, textdecoder, textencoder, ws} 13.4.1
1 parent 9d2b6d5 commit d960128

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+109
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions

hw-ledger-transports/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

hw-ledger/Ledger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { SubstrateApp } from 'https://esm.sh/@zondax/[email protected]';
35
import type { TransportDef, TransportType } from 'https://deno.land/x/polkadot/hw-ledger-transports/types.ts';

hw-ledger/LedgerGeneric.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { TransportDef, TransportType } from 'https://deno.land/x/polkadot/hw-ledger-transports/types.ts';
35
import type { AccountOptionsGeneric, LedgerAddress, LedgerSignature, LedgerVersion } from './types.ts';

hw-ledger/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/hw-ledger', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/hw-ledger', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

hw-ledger/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { HexString } from 'https://deno.land/x/polkadot/util/types.ts';
35

keyring/keyring.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ export class Keyring implements KeyringInstance {
119119
* of an account backup), and then generates a keyring pair from it that it passes to
120120
* `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
121121
*/
122-
public addFromMnemonic (mnemonic: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type): KeyringPair {
123-
return this.addFromUri(mnemonic, meta, type);
122+
public addFromMnemonic (mnemonic: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[]): KeyringPair {
123+
return this.addFromUri(mnemonic, meta, type, wordlist);
124124
}
125125

126126
/**
@@ -151,9 +151,9 @@ export class Keyring implements KeyringInstance {
151151
* @summary Creates an account via an suri
152152
* @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
153153
*/
154-
public addFromUri (suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type): KeyringPair {
154+
public addFromUri (suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[]): KeyringPair {
155155
return this.addPair(
156-
this.createFromUri(suri, meta, type)
156+
this.createFromUri(suri, meta, type, wordlist)
157157
);
158158
}
159159

@@ -201,7 +201,7 @@ export class Keyring implements KeyringInstance {
201201
* @summary Creates a Keypair from an suri
202202
* @description This creates a pair from the suri, but does not add it to the keyring
203203
*/
204-
public createFromUri (_suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type): KeyringPair {
204+
public createFromUri (_suri: string, meta: KeyringPair$Meta = {}, type: KeypairType = this.type, wordlist?: string[]): KeyringPair {
205205
// here we only aut-add the dev phrase if we have a hard-derived path
206206
const suri = _suri.startsWith('//')
207207
? `${DEV_PHRASE}${_suri}`
@@ -218,7 +218,7 @@ export class Keyring implements KeyringInstance {
218218
if ([12, 15, 18, 21, 24].includes(parts.length)) {
219219
seed = type === 'ethereum'
220220
? mnemonicToLegacySeed(phrase, '', false, 64)
221-
: mnemonicToMiniSecret(phrase, password);
221+
: mnemonicToMiniSecret(phrase, password, wordlist);
222222
} else {
223223
if (phrase.length > 32) {
224224
throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');

keyring/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/keyring', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/keyring', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

keyring/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ export interface KeyringInstance {
114114
addPair (pair: KeyringPair): KeyringPair;
115115
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
116116
addFromJson (pair: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
117-
addFromMnemonic (mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
117+
addFromMnemonic (mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
118118
addFromPair (pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair
119119
addFromSeed (seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
120-
addFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
120+
addFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
121121
createFromJson (json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
122122
createFromPair (pair: Keypair, meta: KeyringPair$Meta, type: KeypairType): KeyringPair
123-
createFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
123+
createFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
124124
getPair (address: string | Uint8Array): KeyringPair;
125125
getPairs (): KeyringPair[];
126126
getPublicKeys (): Uint8Array[];

networks/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/networks', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/networks', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

util-crypto/hd/ethereum/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { Keypair } from '../../types.ts';
35

util-crypto/keccak/asU8a.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from 'https://esm.sh/@noble/[email protected]/sha3.js';
35

util-crypto/key/extractSuri.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ export interface ExtractResult {
1010
phrase: string;
1111
}
1212

13-
const RE_CAPTURE = /^(\w+( \w+)*)((\/\/?[^/]+)*)(\/\/\/(.*))?$/;
13+
const RE_CAPTURE = /^((0x[a-fA-F0-9]+|[\p{L}\d]+(?: [\p{L}\d]+)*))((\/\/?[^/]+)*)(\/\/\/(.*))?$/u;
1414

1515
/**
1616
* @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed).
1717
*/
1818
export function keyExtractSuri (suri: string): ExtractResult {
19+
// Normalize Unicode to NFC to avoid accent-related mismatches
20+
const normalizedSuri = suri.normalize('NFC');
21+
1922
// eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
20-
const matches = suri.match(RE_CAPTURE);
23+
const matches = normalizedSuri.match(RE_CAPTURE);
2124

2225
if (matches === null) {
2326
throw new Error('Unable to match provided value to a secret URI');

util-crypto/mnemonic/bip39.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24

35
import { stringToU8a, u8aToU8a } from 'https://deno.land/x/polkadot/util/mod.ts';

util-crypto/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/util-crypto', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/util-crypto', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

util-crypto/signature/verify.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ const VERIFIERS_ECDSA: Verifier[] = [
2929

3030
const VERIFIERS: Verifier[] = [
3131
['ed25519', ed25519Verify],
32-
['sr25519', sr25519Verify],
33-
...VERIFIERS_ECDSA
32+
['sr25519', sr25519Verify]
3433
];
3534

36-
const CRYPTO_TYPES: ('ed25519' | 'sr25519' | 'ecdsa')[] = ['ed25519', 'sr25519', 'ecdsa'];
37-
38-
function verifyDetect (result: VerifyResult, { message, publicKey, signature }: VerifyInput, verifiers = VERIFIERS): VerifyResult {
35+
function verifyDetect (result: VerifyResult, { message, publicKey, signature }: VerifyInput, verifiers = [...VERIFIERS, ...VERIFIERS_ECDSA]): VerifyResult {
3936
result.isValid = verifiers.some(([crypto, verify]): boolean => {
4037
try {
4138
if (verify(message, signature, publicKey)) {
@@ -54,25 +51,29 @@ function verifyDetect (result: VerifyResult, { message, publicKey, signature }:
5451
}
5552

5653
function verifyMultisig (result: VerifyResult, { message, publicKey, signature }: VerifyInput): VerifyResult {
57-
if (![0, 1, 2].includes(signature[0])) {
54+
if (![0, 1, 2].includes(signature[0]) || ![65, 66].includes(signature.length)) {
5855
throw new Error(`Unknown crypto type, expected signature prefix [0..2], found ${signature[0]}`);
5956
}
6057

61-
const type = CRYPTO_TYPES[signature[0]] || 'none';
62-
63-
result.crypto = type;
64-
65-
try {
66-
result.isValid = {
67-
ecdsa: () => verifyDetect(result, { message, publicKey, signature: signature.subarray(1) }, VERIFIERS_ECDSA).isValid,
68-
ed25519: () => ed25519Verify(message, signature.subarray(1), publicKey),
69-
none: () => {
70-
throw Error('no verify for `none` crypto type');
71-
},
72-
sr25519: () => sr25519Verify(message, signature.subarray(1), publicKey)
73-
}[type]();
74-
} catch {
75-
// ignore, result.isValid still set to false
58+
// If the signature is 66 bytes it must be an ecdsa signature
59+
// containing: prefix [1 byte] + signature [65] bytes.
60+
// Remove the and then verify
61+
if (signature.length === 66) {
62+
result = verifyDetect(result, { message, publicKey, signature: signature.subarray(1) }, VERIFIERS_ECDSA);
63+
} else {
64+
// The signature contains 65 bytes which is either
65+
// - A ed25519 or sr25519 signature [1 byte prefix + 64 bytes]
66+
// - An ecdsa signature [65 bytes]
67+
result = verifyDetect(result, { message, publicKey, signature: signature.subarray(1) }, VERIFIERS);
68+
69+
if (!result.isValid) {
70+
result = verifyDetect(result, { message, publicKey, signature }, VERIFIERS_ECDSA);
71+
}
72+
73+
// If both failed, explicitly set crypto to 'none'
74+
if (!result.isValid) {
75+
result.crypto = 'none';
76+
}
7677
}
7778

7879
return result;

util-crypto/xxhash/asU8a.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import { hasBigInt, u8aToU8a } from 'https://deno.land/x/polkadot/util/mod.ts';
35
import { isReady, twox } from 'https://deno.land/x/polkadot/wasm-crypto/mod.ts';

util/buffer/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
/**
35
* @summary Utility methods to convert to and from `Buffer` objects

util/buffer/toU8a.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
/**
35
* @name bufferToU8a

util/has.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { BufferClass } from './types.ts';
35

util/hex/toNumber.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import { hexToBn } from './toBn.ts';
35

util/hex/toU8aBuffer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
/**
35
* @name hexToU8a

util/is/buffer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { BufferClass, BufferObject } from '../types.ts';
35

util/is/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
/**
35
* @summary Type checking utilities

util/logger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { Logger } from './types.ts';
35

util/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/util', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/util', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

util/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { BN } from './bn/bn.ts';
35

util/u8a/concatBuffer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { U8aLike } from '../types.ts';
35

util/u8a/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
/**
35
* @summary Utility methods to convert to and from `Uint8Array` objects

util/u8a/toBuffer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { BufferClass, BufferObject } from '../types.ts';
35

util/u8a/toHexBuffer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { HexString } from '../types.ts';
35

util/u8a/toU8a.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import type { U8aLike } from '../types.ts';
35

x-bigint/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-bigint', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-bigint', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

x-fetch/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-fetch', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-fetch', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

x-global/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
export { packageInfo } from './packageInfo.ts';
35

x-global/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-global', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-global', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

x-randomvalues/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-randomvalues', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-randomvalues', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

x-textdecoder/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-textdecoder', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-textdecoder', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

x-textencoder/node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from 'node:buffer';
2+
13

24
import util from 'node:util';
35

x-textencoder/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-textencoder', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-textencoder', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

x-ws/node.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@ import { extractGlobal } from 'https://deno.land/x/polkadot/x-global/mod.ts';
55

66
export { packageInfo } from './packageInfo.ts';
77

8-
export const WebSocket = /*#__PURE__*/ extractGlobal('WebSocket', ws);
8+
/**
9+
* The built-in `globalThis.WebSocket` in Node.js 22+ does not provide
10+
* detailed error messages (e.g., `ECONNREFUSED` or `ETIMEDOUT`), making
11+
* it difficult to implement proper reconnection logic.
12+
*
13+
* To avoid these issues, we explicitly use the `ws` library in Node.js 22+
14+
* while still preserving support for the browser WebSocket API in browser environments.
15+
*
16+
* Related Issue: https://github.com/polkadot-js/common/issues/1975
17+
*/
18+
const isNode22 = typeof process !== 'undefined' && parseInt(process.versions?.node?.split('.')[0] || '0', 10) >= 22;
19+
20+
export const WebSocket = isNode22 ? ws : /*#__PURE__*/ extractGlobal('WebSocket', ws);

x-ws/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/x-ws', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.3.1' };
3+
export const packageInfo = { name: '@polkadot/x-ws', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.4.1' };

0 commit comments

Comments
 (0)