cafe-utility 24.0.1 → 25.1.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 +14 -8
- package/index.js +41 -18
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -492,10 +492,13 @@ 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
|
+
declare function numberToUint8(number: number): Uint8Array;
|
|
500
|
+
declare function uint8ToNumber(bytes: Uint8Array): number;
|
|
501
|
+
declare function sliceBytes(bytes: Uint8Array, lengths: number[]): Uint8Array[];
|
|
499
502
|
interface Uint8ArrayIO {
|
|
500
503
|
max: () => number;
|
|
501
504
|
}
|
|
@@ -592,10 +595,13 @@ export declare const Binary: {
|
|
|
592
595
|
merkleStart: typeof merkleStart;
|
|
593
596
|
merkleAppend: typeof merkleAppend;
|
|
594
597
|
merkleFinalize: typeof merkleFinalize;
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
598
|
+
numberToUint64: typeof numberToUint64;
|
|
599
|
+
uint64ToNumber: typeof uint64ToNumber;
|
|
600
|
+
numberToUint256: typeof numberToUint256;
|
|
601
|
+
uint256ToNumber: typeof uint256ToNumber;
|
|
602
|
+
numberToUint8: typeof numberToUint8;
|
|
603
|
+
uint8ToNumber: typeof uint8ToNumber;
|
|
604
|
+
sliceBytes: typeof sliceBytes;
|
|
599
605
|
};
|
|
600
606
|
export declare const Random: {
|
|
601
607
|
intBetween: typeof intBetween;
|
package/index.js
CHANGED
|
@@ -2076,21 +2076,41 @@ 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
|
|
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
|
|
2094
|
+
}
|
|
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)
|
|
2082
2098
|
}
|
|
2083
|
-
function
|
|
2084
|
-
const
|
|
2085
|
-
return Number(
|
|
2099
|
+
function uint64ToNumber(n, e) {
|
|
2100
|
+
const t = new DataView(n.buffer)
|
|
2101
|
+
return Number(t.getBigUint64(0, e === 'LE'))
|
|
2086
2102
|
}
|
|
2087
|
-
function
|
|
2088
|
-
|
|
2089
|
-
return new DataView(e).setBigUint64(0, BigInt(n), !1), new Uint8Array(e)
|
|
2103
|
+
function numberToUint8(n) {
|
|
2104
|
+
return new Uint8Array([n])
|
|
2090
2105
|
}
|
|
2091
|
-
function
|
|
2092
|
-
|
|
2093
|
-
|
|
2106
|
+
function uint8ToNumber(n) {
|
|
2107
|
+
return n[0]
|
|
2108
|
+
}
|
|
2109
|
+
function sliceBytes(n, e) {
|
|
2110
|
+
const t = []
|
|
2111
|
+
let r = 0
|
|
2112
|
+
for (const o of e) t.push(n.subarray(r, r + o)), (r += o)
|
|
2113
|
+
return t
|
|
2094
2114
|
}
|
|
2095
2115
|
class Uint8ArrayReader {
|
|
2096
2116
|
constructor(e) {
|
|
@@ -2121,11 +2141,11 @@ class Chunk {
|
|
|
2121
2141
|
;(this.span = r), (this.writer = new Uint8ArrayWriter(new Uint8Array(e))), (this.hashFn = t)
|
|
2122
2142
|
}
|
|
2123
2143
|
build() {
|
|
2124
|
-
return concatBytes(
|
|
2144
|
+
return concatBytes(numberToUint64(this.span, 'LE'), this.writer.buffer)
|
|
2125
2145
|
}
|
|
2126
2146
|
hash() {
|
|
2127
2147
|
const e = log2Reduce(partition(this.writer.buffer, 32), this.hashFn)
|
|
2128
|
-
return this.hashFn(
|
|
2148
|
+
return this.hashFn(numberToUint64(this.span, 'LE'), e)
|
|
2129
2149
|
}
|
|
2130
2150
|
}
|
|
2131
2151
|
function merkleStart(n, e) {
|
|
@@ -2462,10 +2482,13 @@ class AsyncQueue {
|
|
|
2462
2482
|
merkleStart,
|
|
2463
2483
|
merkleAppend,
|
|
2464
2484
|
merkleFinalize,
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2485
|
+
numberToUint64,
|
|
2486
|
+
uint64ToNumber,
|
|
2487
|
+
numberToUint256,
|
|
2488
|
+
uint256ToNumber,
|
|
2489
|
+
numberToUint8,
|
|
2490
|
+
uint8ToNumber,
|
|
2491
|
+
sliceBytes
|
|
2469
2492
|
}),
|
|
2470
2493
|
(exports.Random = {
|
|
2471
2494
|
intBetween,
|