cafe-utility 33.3.1 → 33.3.3
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/index.d.ts +1 -1
- package/index.js +5 -5
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -611,7 +611,7 @@ declare function numberToUint64(number: bigint, endian: 'LE' | 'BE'): Uint8Array
|
|
|
611
611
|
declare function uint64ToNumber(bytes: Uint8Array, endian: 'LE' | 'BE'): bigint
|
|
612
612
|
declare function numberToUint256(number: bigint, endian: 'LE' | 'BE'): Uint8Array
|
|
613
613
|
declare function uint256ToNumber(bytes: Uint8Array, endian: 'LE' | 'BE'): bigint
|
|
614
|
-
declare function sliceBytes(bytes: Uint8Array, lengths: number[]): Uint8Array[]
|
|
614
|
+
declare function sliceBytes(bytes: Uint8Array, lengths: number[]): Uint8Array<ArrayBufferLike>[]
|
|
615
615
|
declare function partition(bytes: Uint8Array, size: number): Uint8Array[]
|
|
616
616
|
declare function keccak256(bytes: Uint8Array): Uint8Array
|
|
617
617
|
declare function sha3_256(bytes: Uint8Array): Uint8Array
|
package/index.js
CHANGED
|
@@ -401,8 +401,8 @@ function asString(n, e) {
|
|
|
401
401
|
}
|
|
402
402
|
function asHexString(n, e) {
|
|
403
403
|
if (!isHexString(n)) throw new TypeError(`Expected hex string${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
|
|
404
|
-
if (e?.strictPrefix && !n.startsWith('0x')) throw new TypeError(`Expected hex string with 0x prefix${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
|
|
405
|
-
const t = n.replace(/^0x
|
|
404
|
+
if (e?.strictPrefix && !n.startsWith('0x') && !n.startsWith('0X')) throw new TypeError(`Expected hex string with 0x prefix${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
|
|
405
|
+
const t = n.replace(/^0x/i, '')
|
|
406
406
|
if (t.length % 2 !== 0 && !e?.uneven) throw RangeError(`Expected even number of hex digits${e?.name ? ` for ${e.name}` : ''}; got: ` + n)
|
|
407
407
|
if (e && e.byteLength && t.length !== e.byteLength * 2) throw RangeError(`Expected hex string${e?.name ? ` for ${e.name}` : ''} of byte length ${e.byteLength}; got: ` + t)
|
|
408
408
|
return `0x${t}`
|
|
@@ -430,7 +430,7 @@ function asNumber(n, e) {
|
|
|
430
430
|
return e && checkLimits(t, e), t
|
|
431
431
|
}
|
|
432
432
|
function asInteger(n, e) {
|
|
433
|
-
return asNumber(n, e)
|
|
433
|
+
return Math.trunc(asNumber(n, e))
|
|
434
434
|
}
|
|
435
435
|
function asBoolean(n, e) {
|
|
436
436
|
if (n === 'true') return !0
|
|
@@ -2050,13 +2050,13 @@ function numberToUint256(n, e) {
|
|
|
2050
2050
|
for (let i = 0; i < 32; i++) (r[i] = Number(o & 0xffn)), (o >>= 8n)
|
|
2051
2051
|
return r
|
|
2052
2052
|
}
|
|
2053
|
-
for (let i =
|
|
2053
|
+
for (let i = 31; i >= 0; i--) (r[i] = Number(o & 0xffn)), (o >>= 8n)
|
|
2054
2054
|
return r
|
|
2055
2055
|
}
|
|
2056
2056
|
function uint256ToNumber(n, e) {
|
|
2057
2057
|
let r = 0n
|
|
2058
2058
|
if (e === 'LE') {
|
|
2059
|
-
for (let o =
|
|
2059
|
+
for (let o = 31; o >= 0; o--) r = (r << 8n) | BigInt(n[o])
|
|
2060
2060
|
return r
|
|
2061
2061
|
}
|
|
2062
2062
|
for (let o = 0; o < 32; o++) r = (r << 8n) | BigInt(n[o])
|