@exodus/bytes 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/array.js +1 -1
- package/base32.js +1 -3
- package/base58check.d.ts +2 -2
- package/base58check.js +6 -7
- package/fallback/_utils.js +1 -1
- package/fallback/latin1.js +1 -19
- package/fallback/platform.browser.js +2 -2
- package/fallback/platform.native.js +25 -0
- package/fallback/utf16.js +3 -3
- package/package.json +7 -4
- package/single-byte.js +4 -4
- package/single-byte.node.js +4 -4
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ Applications (including React Native apps) are advised to load either `@exodus/b
|
|
|
120
120
|
|
|
121
121
|
If you don't need support for legacy multi-byte encodings.
|
|
122
122
|
|
|
123
|
-
Reduces the bundle size
|
|
123
|
+
Reduces the bundle size ~12x, while still keeping `utf-8`, `utf-16le`, `utf-16be` and all single-byte encodings specified by the spec.
|
|
124
124
|
The only difference is support for legacy multi-byte encodings.
|
|
125
125
|
|
|
126
126
|
See [the list of encodings](https://encoding.spec.whatwg.org/#names-and-labels).
|
|
@@ -256,7 +256,7 @@ Prefer using strict throwing methods for cryptography applications._
|
|
|
256
256
|
|
|
257
257
|
Throws on non-even byte length.
|
|
258
258
|
|
|
259
|
-
### @exodus/bytes/single-byte.js
|
|
259
|
+
### @exodus/bytes/single-byte.js <sub></sub>
|
|
260
260
|
|
|
261
261
|
Decode / encode the legacy single-byte encodings according to the
|
|
262
262
|
[Encoding standard](https://encoding.spec.whatwg.org/)
|
|
@@ -377,7 +377,7 @@ Same as:
|
|
|
377
377
|
const windows1252fromString = createSinglebyteEncoder('windows-1252', { mode: 'fatal' })
|
|
378
378
|
```
|
|
379
379
|
|
|
380
|
-
### @exodus/bytes/multi-byte.js
|
|
380
|
+
### @exodus/bytes/multi-byte.js <sub></sub>
|
|
381
381
|
|
|
382
382
|
Decode / encode the legacy multi-byte encodings according to the
|
|
383
383
|
[Encoding standard](https://encoding.spec.whatwg.org/)
|
|
@@ -419,7 +419,7 @@ Returns a function `encode(string)` that encodes a string to bytes.
|
|
|
419
419
|
In `'fatal'` mode (default), will throw on non well-formed strings or any codepoints which could
|
|
420
420
|
not be encoded in the target encoding.
|
|
421
421
|
|
|
422
|
-
### @exodus/bytes/bigint.js
|
|
422
|
+
### @exodus/bytes/bigint.js <sub></sub>
|
|
423
423
|
|
|
424
424
|
Convert between BigInt and Uint8Array
|
|
425
425
|
|
|
@@ -441,7 +441,7 @@ Convert a Uint8Array or Buffer to a BigInt
|
|
|
441
441
|
|
|
442
442
|
The bytes are interpreted as a big-endian unsigned integer.
|
|
443
443
|
|
|
444
|
-
### @exodus/bytes/hex.js
|
|
444
|
+
### @exodus/bytes/hex.js <sub></sub>
|
|
445
445
|
|
|
446
446
|
Implements Base16 from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)
|
|
447
447
|
(no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).
|
|
@@ -460,7 +460,7 @@ Unlike `Buffer.from()`, throws on invalid input
|
|
|
460
460
|
|
|
461
461
|
Encode a `Uint8Array` to a lowercase hex string
|
|
462
462
|
|
|
463
|
-
### @exodus/bytes/base64.js
|
|
463
|
+
### @exodus/bytes/base64.js <sub></sub>
|
|
464
464
|
|
|
465
465
|
Implements base64 and base64url from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)
|
|
466
466
|
(no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).
|
|
@@ -497,7 +497,7 @@ Encode a `Uint8Array` to a base64 string (RFC 4648)
|
|
|
497
497
|
|
|
498
498
|
Encode a `Uint8Array` to a base64url string (RFC 4648)
|
|
499
499
|
|
|
500
|
-
### @exodus/bytes/base32.js
|
|
500
|
+
### @exodus/bytes/base32.js <sub></sub>
|
|
501
501
|
|
|
502
502
|
Implements base32 and base32hex from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)
|
|
503
503
|
(no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).
|
|
@@ -527,7 +527,7 @@ Encode a `Uint8Array` to a base32 string (RFC 4648)
|
|
|
527
527
|
|
|
528
528
|
Encode a `Uint8Array` to a base32hex string (RFC 4648)
|
|
529
529
|
|
|
530
|
-
### @exodus/bytes/bech32.js
|
|
530
|
+
### @exodus/bytes/bech32.js <sub></sub>
|
|
531
531
|
|
|
532
532
|
Implements bech32 and bech32m from
|
|
533
533
|
[BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification)
|
|
@@ -561,7 +561,7 @@ Decode a bech32m string to bytes
|
|
|
561
561
|
|
|
562
562
|
Encode bytes to a bech32m string
|
|
563
563
|
|
|
564
|
-
### @exodus/bytes/base58.js
|
|
564
|
+
### @exodus/bytes/base58.js <sub></sub>
|
|
565
565
|
|
|
566
566
|
Implements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding.
|
|
567
567
|
|
|
@@ -596,7 +596,7 @@ Encode a `Uint8Array` to a base58 string using XRP alphabet
|
|
|
596
596
|
|
|
597
597
|
Uses the XRP variant base58 alphabet
|
|
598
598
|
|
|
599
|
-
### @exodus/bytes/base58check.js
|
|
599
|
+
### @exodus/bytes/base58check.js <sub></sub>
|
|
600
600
|
|
|
601
601
|
Implements [base58check](https://en.bitcoin.it/wiki/Base58Check_encoding) encoding.
|
|
602
602
|
|
|
@@ -636,7 +636,7 @@ Uses double SHA-256 for checksum calculation
|
|
|
636
636
|
|
|
637
637
|
Create a base58check encoder/decoder with custom hash functions
|
|
638
638
|
|
|
639
|
-
### @exodus/bytes/wif.js
|
|
639
|
+
### @exodus/bytes/wif.js <sub></sub>
|
|
640
640
|
|
|
641
641
|
Wallet Import Format (WIF) encoding and decoding.
|
|
642
642
|
|
|
@@ -675,7 +675,7 @@ Encode WIF data to a WIF string
|
|
|
675
675
|
|
|
676
676
|
Encode WIF data to a WIF string (synchronous)
|
|
677
677
|
|
|
678
|
-
### @exodus/bytes/array.js
|
|
678
|
+
### @exodus/bytes/array.js <sub></sub>
|
|
679
679
|
|
|
680
680
|
TypedArray utils and conversions.
|
|
681
681
|
|
|
@@ -805,7 +805,7 @@ new TextDecoder(getBOMEncoding(input) ?? fallbackEncoding).decode(input)
|
|
|
805
805
|
|
|
806
806
|
The exact same exports as `@exodus/bytes/encoding.js` are also exported as
|
|
807
807
|
`@exodus/bytes/encoding-lite.js`, with the difference that the lite version does not load
|
|
808
|
-
multi-byte `TextDecoder` encodings by default to reduce bundle size
|
|
808
|
+
multi-byte `TextDecoder` encodings by default to reduce bundle size ~12x.
|
|
809
809
|
|
|
810
810
|
```js
|
|
811
811
|
import { TextDecoder, TextEncoder } from '@exodus/bytes/encoding-lite.js'
|
|
@@ -881,7 +881,7 @@ do not provide sufficiently complete / non-buggy `TextDecoder` APIs.
|
|
|
881
881
|
> but they are fixing them and the expected update window is short.\
|
|
882
882
|
> If you want to circumvent browser bugs, use full `@exodus/bytes/encoding.js` import.
|
|
883
883
|
|
|
884
|
-
### @exodus/bytes/whatwg.js
|
|
884
|
+
### @exodus/bytes/whatwg.js <sub></sub>
|
|
885
885
|
|
|
886
886
|
WHATWG helpers
|
|
887
887
|
|
package/array.js
CHANGED
package/base32.js
CHANGED
|
@@ -7,8 +7,6 @@ import * as js from './fallback/base32.js'
|
|
|
7
7
|
|
|
8
8
|
// 8 chars per 5 bytes
|
|
9
9
|
|
|
10
|
-
const { E_PADDING } = js
|
|
11
|
-
|
|
12
10
|
export const toBase32 = (arr, { padding = false } = {}) => js.toBase32(arr, false, padding)
|
|
13
11
|
export const toBase32hex = (arr, { padding = false } = {}) => js.toBase32(arr, true, padding)
|
|
14
12
|
|
|
@@ -30,7 +28,7 @@ function fromBase32common(str, isBase32Hex, padding, format, rest) {
|
|
|
30
28
|
if (rest !== null) assertEmptyRest(rest)
|
|
31
29
|
|
|
32
30
|
if (padding === true) {
|
|
33
|
-
if (str.length % 8 !== 0) throw new SyntaxError(E_PADDING)
|
|
31
|
+
if (str.length % 8 !== 0) throw new SyntaxError(js.E_PADDING)
|
|
34
32
|
} else if (padding === false) {
|
|
35
33
|
if (str.endsWith('=')) throw new SyntaxError('Did not expect padding in base32 input')
|
|
36
34
|
} else if (padding !== 'both') {
|
package/base58check.d.ts
CHANGED
|
@@ -81,8 +81,8 @@ export interface Base58CheckSync extends Base58CheckAsync {
|
|
|
81
81
|
* @param hashAlgoSync - Optional sync hash function
|
|
82
82
|
* @returns Base58Check encoder/decoder instance
|
|
83
83
|
*/
|
|
84
|
-
export function makeBase58check(hashAlgo: HashFunction, hashAlgoSync
|
|
85
|
-
export function makeBase58check(hashAlgo: HashFunction): Base58CheckAsync;
|
|
84
|
+
export function makeBase58check(hashAlgo: HashFunction | HashFunctionSync, hashAlgoSync: HashFunctionSync): Base58CheckSync;
|
|
85
|
+
export function makeBase58check(hashAlgo: HashFunction | HashFunctionSync, hashAlgoSync?: undefined): Base58CheckAsync;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Encode bytes to base58check string asynchronously
|
package/base58check.js
CHANGED
|
@@ -8,12 +8,11 @@ import { makeBase58check } from './fallback/base58check.js'
|
|
|
8
8
|
|
|
9
9
|
const hash256sync = (x) => sha256(sha256(x))
|
|
10
10
|
const hash256 = hash256sync // See note at the top
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
|
|
12
|
+
const b58c = /* @__PURE__ */ makeBase58check(hash256, hash256sync)
|
|
13
|
+
export const toBase58check = /* @__PURE__ */ (() => b58c.encode)()
|
|
14
|
+
export const fromBase58check = /* @__PURE__ */ (() => b58c.decode)()
|
|
15
|
+
export const toBase58checkSync = /* @__PURE__ */ (() => b58c.encodeSync)()
|
|
16
|
+
export const fromBase58checkSync = /* @__PURE__ */ (() => b58c.decodeSync)()
|
|
17
17
|
|
|
18
18
|
export { makeBase58check } from './fallback/base58check.js'
|
|
19
|
-
export { toBase58check, fromBase58check, toBase58checkSync, fromBase58checkSync }
|
package/fallback/_utils.js
CHANGED
package/fallback/latin1.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
nativeDecoder,
|
|
4
4
|
nativeDecoderLatin1,
|
|
5
5
|
nativeBuffer,
|
|
6
|
+
encodeCharcodes,
|
|
6
7
|
isHermes,
|
|
7
8
|
isDeno,
|
|
8
9
|
isLE,
|
|
@@ -107,25 +108,6 @@ export const decodeAscii = nativeBuffer
|
|
|
107
108
|
|
|
108
109
|
/* eslint-disable @exodus/mutable/no-param-reassign-prop-only */
|
|
109
110
|
|
|
110
|
-
export const encodeCharcodes = isHermes
|
|
111
|
-
? (str, arr) => {
|
|
112
|
-
const length = str.length
|
|
113
|
-
if (length > 64) {
|
|
114
|
-
const at = str.charCodeAt.bind(str) // faster on strings from ~64 chars on Hermes, but can be 10x slower on e.g. JSC
|
|
115
|
-
for (let i = 0; i < length; i++) arr[i] = at(i)
|
|
116
|
-
} else {
|
|
117
|
-
for (let i = 0; i < length; i++) arr[i] = str.charCodeAt(i)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return arr
|
|
121
|
-
}
|
|
122
|
-
: (str, arr) => {
|
|
123
|
-
const length = str.length
|
|
124
|
-
// Can be optimized with unrolling, but this is not used on non-Hermes atm
|
|
125
|
-
for (let i = 0; i < length; i++) arr[i] = str.charCodeAt(i)
|
|
126
|
-
return arr
|
|
127
|
-
}
|
|
128
|
-
|
|
129
111
|
export function encodeAsciiPrefix(x, s) {
|
|
130
112
|
let i = 0
|
|
131
113
|
for (const len3 = s.length - 3; i < len3; i += 4) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { decodePartAddition as decodePart } from './platform.native.js'
|
|
2
2
|
|
|
3
|
+
export { isLE, encodeCharcodesPure as encodeCharcodes } from './platform.native.js'
|
|
4
|
+
|
|
3
5
|
export const nativeBuffer = null
|
|
4
6
|
export const isHermes = false
|
|
5
7
|
export const isDeno = false
|
|
@@ -8,8 +10,6 @@ export const nativeDecoder = /* @__PURE__ */ (() => new TextDecoder('utf-8', { i
|
|
|
8
10
|
export const nativeDecoderLatin1 = /* @__PURE__ */ (() =>
|
|
9
11
|
new TextDecoder('latin1', { ignoreBOM: true }))()
|
|
10
12
|
|
|
11
|
-
export { isLE } from './platform.native.js'
|
|
12
|
-
|
|
13
13
|
export function decode2string(arr, start, end, m) {
|
|
14
14
|
if (end - start > 30_000) {
|
|
15
15
|
// Limit concatenation to avoid excessive GC
|
|
@@ -95,3 +95,28 @@ export function decode2string(arr, start, end, m) {
|
|
|
95
95
|
|
|
96
96
|
return decodePart(arr, start, end, m)
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
/* eslint-disable @exodus/mutable/no-param-reassign-prop-only */
|
|
100
|
+
|
|
101
|
+
function encodeCharcodesHermes(str, arr) {
|
|
102
|
+
const length = str.length
|
|
103
|
+
if (length > 64) {
|
|
104
|
+
const at = str.charCodeAt.bind(str) // faster on strings from ~64 chars on Hermes, but can be 10x slower on e.g. JSC
|
|
105
|
+
for (let i = 0; i < length; i++) arr[i] = at(i)
|
|
106
|
+
} else {
|
|
107
|
+
for (let i = 0; i < length; i++) arr[i] = str.charCodeAt(i)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return arr
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function encodeCharcodesPure(str, arr) {
|
|
114
|
+
const length = str.length
|
|
115
|
+
// Can be optimized with unrolling, but this is not used on non-Hermes atm
|
|
116
|
+
for (let i = 0; i < length; i++) arr[i] = str.charCodeAt(i)
|
|
117
|
+
return arr
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* eslint-enable @exodus/mutable/no-param-reassign-prop-only */
|
|
121
|
+
|
|
122
|
+
export const encodeCharcodes = isHermes ? encodeCharcodesHermes : encodeCharcodesPure
|
package/fallback/utf16.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { decodeUCS2
|
|
1
|
+
import { decodeUCS2 } from './latin1.js'
|
|
2
2
|
import { assertU8, E_STRING, E_STRICT_UNICODE } from './_utils.js'
|
|
3
|
-
import { nativeDecoder, isLE } from './platform.js'
|
|
3
|
+
import { nativeDecoder, isLE, encodeCharcodes } from './platform.js'
|
|
4
4
|
|
|
5
5
|
export const E_STRICT = 'Input is not well-formed utf16'
|
|
6
|
-
const isWellFormedStr = String.prototype.isWellFormed
|
|
6
|
+
const isWellFormedStr = /* @__PURE__ */ (() => String.prototype.isWellFormed)()
|
|
7
7
|
const toWellFormedStr = /* @__PURE__ */ (() => String.prototype.toWellFormed)()
|
|
8
8
|
|
|
9
9
|
const replacementCodepoint = 0xff_fd
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bytes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Various operations on Uint8Array data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"encoding",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test:chrome:puppeteer": "exodus-test --engine=chrome:puppeteer",
|
|
41
41
|
"test:chromium:playwright": "exodus-test --engine=chromium:playwright",
|
|
42
42
|
"test:webkit:playwright": "exodus-test --engine=webkit:playwright",
|
|
43
|
-
"test:firefox:puppeteer": "exodus-test --engine=firefox:puppeteer",
|
|
44
|
-
"test:firefox:playwright": "exodus-test --engine=firefox:playwright",
|
|
43
|
+
"test:firefox:puppeteer": "exodus-test --engine=firefox:puppeteer --testTimeout=60000",
|
|
44
|
+
"test:firefox:playwright": "exodus-test --engine=firefox:playwright --testTimeout=60000",
|
|
45
45
|
"test:servo:bundle": "exodus-test --engine=servo:bundle",
|
|
46
46
|
"test": "exodus-test",
|
|
47
47
|
"size": "esbuild --minify --bundle",
|
|
@@ -237,6 +237,9 @@
|
|
|
237
237
|
"./fallback/platform.js": "./fallback/platform.native.js",
|
|
238
238
|
"./fallback/utf8.auto.js": "./fallback/utf8.auto.native.js"
|
|
239
239
|
},
|
|
240
|
+
"sideEffects": [
|
|
241
|
+
"./encoding.js"
|
|
242
|
+
],
|
|
240
243
|
"peerDependencies": {
|
|
241
244
|
"@noble/hashes": "^1.8.0 || ^2.0.0"
|
|
242
245
|
},
|
|
@@ -288,7 +291,7 @@
|
|
|
288
291
|
"utf8": "^3.0.0",
|
|
289
292
|
"web-streams-polyfill": "^4.2.0",
|
|
290
293
|
"wif": "^5.0.0",
|
|
291
|
-
"workerd": "^1.
|
|
294
|
+
"workerd": "^1.20260210.0"
|
|
292
295
|
},
|
|
293
296
|
"prettier": "@exodus/prettier",
|
|
294
297
|
"packageManager": "pnpm@10.12.1+sha256.889bac470ec93ccc3764488a19d6ba8f9c648ad5e50a9a6e4be3768a5de387a3"
|
package/single-byte.js
CHANGED
|
@@ -129,7 +129,7 @@ export function createSinglebyteEncoder(encoding, { mode = 'fatal' } = {}) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
export const latin1toString = createSinglebyteDecoder('iso-8859-1')
|
|
133
|
-
export const latin1fromString = createSinglebyteEncoder('iso-8859-1')
|
|
134
|
-
export const windows1252toString = createSinglebyteDecoder('windows-1252')
|
|
135
|
-
export const windows1252fromString = createSinglebyteEncoder('windows-1252')
|
|
132
|
+
export const latin1toString = /* @__PURE__ */ createSinglebyteDecoder('iso-8859-1')
|
|
133
|
+
export const latin1fromString = /* @__PURE__ */ createSinglebyteEncoder('iso-8859-1')
|
|
134
|
+
export const windows1252toString = /* @__PURE__ */ createSinglebyteDecoder('windows-1252')
|
|
135
|
+
export const windows1252fromString = /* @__PURE__ */ createSinglebyteEncoder('windows-1252')
|
package/single-byte.node.js
CHANGED
|
@@ -114,7 +114,7 @@ export function createSinglebyteEncoder(encoding, { mode = 'fatal' } = {}) {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
export const latin1toString = createSinglebyteDecoder('iso-8859-1')
|
|
118
|
-
export const latin1fromString = createSinglebyteEncoder('iso-8859-1')
|
|
119
|
-
export const windows1252toString = createSinglebyteDecoder('windows-1252')
|
|
120
|
-
export const windows1252fromString = createSinglebyteEncoder('windows-1252')
|
|
117
|
+
export const latin1toString = /* @__PURE__ */ createSinglebyteDecoder('iso-8859-1')
|
|
118
|
+
export const latin1fromString = /* @__PURE__ */ createSinglebyteEncoder('iso-8859-1')
|
|
119
|
+
export const windows1252toString = /* @__PURE__ */ createSinglebyteDecoder('windows-1252')
|
|
120
|
+
export const windows1252fromString = /* @__PURE__ */ createSinglebyteEncoder('windows-1252')
|