@wishknish/knishio-client-ts 0.9.2 → 0.9.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/dist/index.cjs +29 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +3314 -334
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/Wallet.ts +21 -2
- package/src/libraries/array.ts +6 -4
- package/src/libraries/strings.ts +12 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wishknish/knishio-client-ts",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"productName": "Knish.IO TypeScript SDK Client",
|
|
5
5
|
"description": "TypeScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs with enhanced type safety.",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
package/src/core/Wallet.ts
CHANGED
|
@@ -608,11 +608,30 @@ export default class Wallet {
|
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
serializeKey(key: Uint8Array): string {
|
|
611
|
-
|
|
611
|
+
if (typeof Buffer !== 'undefined') {
|
|
612
|
+
return Buffer.from(key).toString('base64')
|
|
613
|
+
}
|
|
614
|
+
// A single String.fromCharCode(...key) spread overflows the call stack once the
|
|
615
|
+
// payload exceeds the engine's argument limit (~64K), so convert in chunks.
|
|
616
|
+
let binary = ''
|
|
617
|
+
const CHUNK_SIZE = 0x8000
|
|
618
|
+
for (let i = 0; i < key.length; i += CHUNK_SIZE) {
|
|
619
|
+
binary += String.fromCharCode(...key.subarray(i, i + CHUNK_SIZE))
|
|
620
|
+
}
|
|
621
|
+
return btoa(binary)
|
|
612
622
|
}
|
|
613
623
|
|
|
614
624
|
deserializeKey(serializedKey: string): Uint8Array {
|
|
625
|
+
if (typeof Buffer !== 'undefined') {
|
|
626
|
+
return new Uint8Array(Buffer.from(serializedKey, 'base64'))
|
|
627
|
+
}
|
|
628
|
+
// Spreading the binary string ([...str]) allocates one single-char string per
|
|
629
|
+
// byte — prohibitive for multi-MB payloads. Index directly instead.
|
|
615
630
|
const binaryString = atob(serializedKey)
|
|
616
|
-
|
|
631
|
+
const bytes = new Uint8Array(binaryString.length)
|
|
632
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
633
|
+
bytes[i] = binaryString.charCodeAt(i)
|
|
634
|
+
}
|
|
635
|
+
return bytes
|
|
617
636
|
}
|
|
618
637
|
}
|
package/src/libraries/array.ts
CHANGED
|
@@ -57,11 +57,13 @@ export function deepCloning<T>(
|
|
|
57
57
|
* Used for batch processing operations
|
|
58
58
|
*/
|
|
59
59
|
export function chunkArray<T>(arr: T[], size: number): T[][] {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
// Iterative: the previous recursive form (`concat` + `slice(size)` per level) blew
|
|
61
|
+
// the call stack and allocated O(n^2) once arr grew past a few thousand elements.
|
|
62
|
+
const chunks: T[][] = []
|
|
63
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
64
|
+
chunks.push(arr.slice(i, i + size))
|
|
62
65
|
}
|
|
63
|
-
|
|
64
|
-
return [arr.slice(0, size)].concat(chunkArray(arr.slice(size), size))
|
|
66
|
+
return chunks
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
package/src/libraries/strings.ts
CHANGED
|
@@ -220,15 +220,20 @@ export function hexToBase64(hexString: string): string {
|
|
|
220
220
|
|
|
221
221
|
// Convert hex to bytes
|
|
222
222
|
const bytes = hexStringToBuffer(cleanHex)
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
if (typeof
|
|
226
|
-
// Browser environment
|
|
227
|
-
return btoa(String.fromCharCode(...bytes))
|
|
228
|
-
} else {
|
|
229
|
-
// Node.js environment or manual conversion
|
|
223
|
+
|
|
224
|
+
// Buffer fast path (Node). Byte-identical to the btoa encoding below.
|
|
225
|
+
if (typeof Buffer !== 'undefined') {
|
|
230
226
|
return Buffer.from(bytes).toString('base64')
|
|
231
227
|
}
|
|
228
|
+
// Browser fallback: a single String.fromCharCode(...bytes) spread overflows the
|
|
229
|
+
// call stack once the payload exceeds the engine's argument limit (~64K), so
|
|
230
|
+
// convert in chunks.
|
|
231
|
+
let binary = ''
|
|
232
|
+
const CHUNK_SIZE = 0x8000
|
|
233
|
+
for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {
|
|
234
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK_SIZE))
|
|
235
|
+
}
|
|
236
|
+
return btoa(binary)
|
|
232
237
|
} catch (error) {
|
|
233
238
|
throw new Error(`Failed to convert hex to base64: ${error instanceof Error ? error.message : String(error)}`)
|
|
234
239
|
}
|