cafe-utility 24.0.1 → 25.0.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/index.d.ts +8 -8
- package/index.js +26 -18
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -492,10 +492,10 @@ declare function isPng(bytes: Uint8Array): boolean;
|
|
|
492
492
|
declare function isJpg(bytes: Uint8Array): boolean;
|
|
493
493
|
declare function isWebp(bytes: Uint8Array): boolean;
|
|
494
494
|
declare function isImage(bytes: Uint8Array): boolean;
|
|
495
|
-
declare function
|
|
496
|
-
declare function
|
|
497
|
-
declare function
|
|
498
|
-
declare function
|
|
495
|
+
declare function numberToUint256(number: bigint, endian: 'LE' | 'BE'): Uint8Array;
|
|
496
|
+
declare function uint256ToNumber(bytes: Uint8Array, endian: 'LE' | 'BE'): bigint;
|
|
497
|
+
declare function numberToUint64(number: number, endian: 'LE' | 'BE'): Uint8Array;
|
|
498
|
+
declare function uint64ToNumber(bytes: Uint8Array, endian: 'LE' | 'BE'): number;
|
|
499
499
|
interface Uint8ArrayIO {
|
|
500
500
|
max: () => number;
|
|
501
501
|
}
|
|
@@ -592,10 +592,10 @@ export declare const Binary: {
|
|
|
592
592
|
merkleStart: typeof merkleStart;
|
|
593
593
|
merkleAppend: typeof merkleAppend;
|
|
594
594
|
merkleFinalize: typeof merkleFinalize;
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
595
|
+
numberToUint64: typeof numberToUint64;
|
|
596
|
+
uint64ToNumber: typeof uint64ToNumber;
|
|
597
|
+
numberToUint256: typeof numberToUint256;
|
|
598
|
+
uint256ToNumber: typeof uint256ToNumber;
|
|
599
599
|
};
|
|
600
600
|
export declare const Random: {
|
|
601
601
|
intBetween: typeof intBetween;
|
package/index.js
CHANGED
|
@@ -2076,21 +2076,29 @@ function isWebp(n) {
|
|
|
2076
2076
|
function isImage(n) {
|
|
2077
2077
|
return isPng(n) || isJpg(n) || isWebp(n)
|
|
2078
2078
|
}
|
|
2079
|
-
function
|
|
2080
|
-
const
|
|
2081
|
-
|
|
2079
|
+
function numberToUint256(n, e) {
|
|
2080
|
+
const r = new Uint8Array(32)
|
|
2081
|
+
let o = n
|
|
2082
|
+
if (e === 'LE') for (let i = 0; i < 32; i++) return (r[i] = Number(o & BigInt(255))), (o >>= BigInt(8)), r
|
|
2083
|
+
for (let i = 32 - 1; i >= 0; i--) (r[i] = Number(o & BigInt(255))), (o >>= BigInt(8))
|
|
2084
|
+
return r
|
|
2082
2085
|
}
|
|
2083
|
-
function
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
+
function uint256ToNumber(n, e) {
|
|
2087
|
+
let r = BigInt(0)
|
|
2088
|
+
if (e === 'LE') {
|
|
2089
|
+
for (let o = 32 - 1; o >= 0; o--) r = (r << BigInt(8)) | BigInt(n[o])
|
|
2090
|
+
return r
|
|
2091
|
+
}
|
|
2092
|
+
for (let o = 0; o < 32; o++) r = (r << BigInt(8)) | BigInt(n[o])
|
|
2093
|
+
return r
|
|
2086
2094
|
}
|
|
2087
|
-
function
|
|
2088
|
-
const
|
|
2089
|
-
return new DataView(
|
|
2095
|
+
function numberToUint64(n, e) {
|
|
2096
|
+
const t = new ArrayBuffer(8)
|
|
2097
|
+
return new DataView(t).setBigUint64(0, BigInt(n), e === 'LE'), new Uint8Array(t)
|
|
2090
2098
|
}
|
|
2091
|
-
function
|
|
2092
|
-
const
|
|
2093
|
-
return Number(
|
|
2099
|
+
function uint64ToNumber(n, e) {
|
|
2100
|
+
const t = new DataView(n.buffer)
|
|
2101
|
+
return Number(t.getBigUint64(0, e === 'LE'))
|
|
2094
2102
|
}
|
|
2095
2103
|
class Uint8ArrayReader {
|
|
2096
2104
|
constructor(e) {
|
|
@@ -2121,11 +2129,11 @@ class Chunk {
|
|
|
2121
2129
|
;(this.span = r), (this.writer = new Uint8ArrayWriter(new Uint8Array(e))), (this.hashFn = t)
|
|
2122
2130
|
}
|
|
2123
2131
|
build() {
|
|
2124
|
-
return concatBytes(
|
|
2132
|
+
return concatBytes(numberToUint64(this.span, 'LE'), this.writer.buffer)
|
|
2125
2133
|
}
|
|
2126
2134
|
hash() {
|
|
2127
2135
|
const e = log2Reduce(partition(this.writer.buffer, 32), this.hashFn)
|
|
2128
|
-
return this.hashFn(
|
|
2136
|
+
return this.hashFn(numberToUint64(this.span, 'LE'), e)
|
|
2129
2137
|
}
|
|
2130
2138
|
}
|
|
2131
2139
|
function merkleStart(n, e) {
|
|
@@ -2462,10 +2470,10 @@ class AsyncQueue {
|
|
|
2462
2470
|
merkleStart,
|
|
2463
2471
|
merkleAppend,
|
|
2464
2472
|
merkleFinalize,
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2473
|
+
numberToUint64,
|
|
2474
|
+
uint64ToNumber,
|
|
2475
|
+
numberToUint256,
|
|
2476
|
+
uint256ToNumber
|
|
2469
2477
|
}),
|
|
2470
2478
|
(exports.Random = {
|
|
2471
2479
|
intBetween,
|