@exodus/bytes 1.15.0 → 1.15.1

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/assert.js CHANGED
@@ -8,7 +8,7 @@ const makeMessage = (name, extra) => `Expected${name ? ` ${name} to be` : ''} an
8
8
  const TypedArray = Object.getPrototypeOf(Uint8Array)
9
9
 
10
10
  export function assertTypedArray(arr) {
11
- if (arr instanceof TypedArray) return
11
+ if (arr && arr instanceof TypedArray) return
12
12
  throw new TypeError('Expected a TypedArray instance')
13
13
  }
14
14
 
package/base58.js CHANGED
@@ -162,7 +162,7 @@ function fromBase58core(str, alphabet, codes, format = 'uint8') {
162
162
 
163
163
  while (x) {
164
164
  let y = Number(x & _0xffffffffn)
165
- x >>= 32n
165
+ x >>= _32n
166
166
  res[--at] = y & 0xff
167
167
  y >>>= 8
168
168
  if (!x && !y) break
package/base64.js CHANGED
@@ -74,6 +74,7 @@ export function fromBase64url(str, options) {
74
74
 
75
75
  // By default accepts both padded and non-padded variants, base64 or base64url
76
76
  export function fromBase64any(str, { format = 'uint8', padding = 'both', ...rest } = {}) {
77
+ if (typeof str !== 'string') throw new TypeError(E_STRING)
77
78
  const isBase64url = !str.includes('+') && !str.includes('/') // likely to fail fast, as most input is non-url, also double scan is faster than regex
78
79
  return fromBase64common(str, isBase64url, padding, format, rest)
79
80
  }
@@ -7,7 +7,8 @@ export function assert(condition, msg) {
7
7
  }
8
8
 
9
9
  export function assertU8(arg) {
10
- if (!(arg instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array')
10
+ if (arg && arg instanceof Uint8Array) return
11
+ throw new TypeError('Expected an Uint8Array')
11
12
  }
12
13
 
13
14
  // On arrays in heap (<= 64) it's cheaper to copy into a pooled buffer than lazy-create the ArrayBuffer storage
@@ -47,7 +48,9 @@ export function fromBuffer(arr, format) {
47
48
 
48
49
  return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength)
49
50
  case 'arraybuffer':
50
- return fromBuffer(arr, 'uint8').buffer
51
+ return arr.buffer.byteLength === arr.byteLength
52
+ ? arr.buffer
53
+ : arr.buffer.slice(arr.byteOffset, arr.byteOffset + arr.byteLength)
51
54
  case 'buffer':
52
55
  if (arr.constructor !== Buffer) throw new Error('Unexpected')
53
56
  return arr
package/fallback/hex.js CHANGED
@@ -73,7 +73,7 @@ export function fromHex(str) {
73
73
  }
74
74
  }
75
75
 
76
- const codes = encodeAscii(str, E_HEX)
76
+ const codes = encodeAscii(str, E_HEX) // aligned
77
77
  const codes16 = new Uint16Array(codes.buffer, codes.byteOffset, codes.byteLength / 2)
78
78
  let i = 0
79
79
  for (const last3 = length - 3; i < last3; i += 4) {
@@ -140,6 +140,7 @@ export const encodeAscii = useEncodeInto
140
140
  : nativeBuffer
141
141
  ? (str, ERR) => {
142
142
  // TextEncoder is slow on Node.js 24 / 25 (was ok on 22)
143
+ // Node.js Buffer.from always returns 8-byte aligned allocations, this is safe for e.g. conversion to Uint32Array
143
144
  const codes = nativeBuffer.from(str, 'utf8') // ascii/latin1 coerces, we need to check
144
145
  if (codes.length !== str.length) throw new SyntaxError(ERR) // non-ascii
145
146
  return new Uint8Array(codes.buffer, codes.byteOffset, codes.byteLength)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bytes",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "Various operations on Uint8Array data",
5
5
  "keywords": [
6
6
  "encoding",