@spirobel/monero-wallet-api 0.2.0 → 0.3.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/README.md +3 -3
- package/dist/api.d.ts +25 -96
- package/dist/api.js +23 -175
- package/dist/io/BunFileInterface.d.ts +32 -0
- package/dist/io/atomicWrite.d.ts +2 -0
- package/dist/io/atomicWrite.js +10 -0
- package/dist/io/extension.d.ts +18 -0
- package/dist/io/extension.js +11 -0
- package/dist/io/indexedDB.d.ts +45 -0
- package/dist/io/indexedDB.js +221 -0
- package/dist/io/readDir.d.ts +1 -0
- package/dist/io/readDir.js +7 -0
- package/dist/io/sleep.d.ts +1 -0
- package/dist/io/sleep.js +1 -0
- package/dist/keypairs-seeds/keypairs.d.ts +29 -0
- package/dist/keypairs-seeds/keypairs.js +207 -0
- package/dist/keypairs-seeds/writeKeypairs.d.ts +12 -0
- package/dist/keypairs-seeds/writeKeypairs.js +78 -0
- package/dist/node-interaction/binaryEndpoints.d.ts +59 -14
- package/dist/node-interaction/binaryEndpoints.js +110 -54
- package/dist/node-interaction/jsonEndpoints.d.ts +249 -187
- package/dist/node-interaction/jsonEndpoints.js +287 -0
- package/dist/node-interaction/nodeUrl.d.ts +129 -0
- package/dist/node-interaction/nodeUrl.js +113 -0
- package/dist/scanning-syncing/backgroundWorker.d.ts +6 -0
- package/dist/scanning-syncing/backgroundWorker.js +56 -0
- package/dist/scanning-syncing/connectionStatus.d.ts +15 -0
- package/dist/scanning-syncing/connectionStatus.js +35 -0
- package/dist/scanning-syncing/openWallet.d.ts +28 -0
- package/dist/scanning-syncing/openWallet.js +57 -0
- package/dist/scanning-syncing/scanSettings.d.ts +96 -0
- package/dist/scanning-syncing/scanSettings.js +240 -0
- package/dist/scanning-syncing/scanresult/computeKeyImage.d.ts +3 -0
- package/dist/scanning-syncing/scanresult/computeKeyImage.js +21 -0
- package/dist/scanning-syncing/scanresult/getBlocksbinBuffer.d.ts +28 -0
- package/dist/scanning-syncing/scanresult/getBlocksbinBuffer.js +52 -0
- package/dist/scanning-syncing/scanresult/reorg.d.ts +14 -0
- package/dist/scanning-syncing/scanresult/reorg.js +78 -0
- package/dist/scanning-syncing/scanresult/scanCache.d.ts +84 -0
- package/dist/scanning-syncing/scanresult/scanCache.js +134 -0
- package/dist/scanning-syncing/scanresult/scanCacheOpened.d.ts +149 -0
- package/dist/scanning-syncing/scanresult/scanCacheOpened.js +648 -0
- package/dist/scanning-syncing/scanresult/scanResult.d.ts +64 -0
- package/dist/scanning-syncing/scanresult/scanResult.js +213 -0
- package/dist/scanning-syncing/scanresult/scanStats.d.ts +60 -0
- package/dist/scanning-syncing/scanresult/scanStats.js +273 -0
- package/dist/scanning-syncing/worker-entrypoints/worker.d.ts +1 -0
- package/dist/scanning-syncing/worker-entrypoints/worker.js +8 -0
- package/dist/scanning-syncing/worker-mains/worker.d.ts +1 -0
- package/dist/scanning-syncing/worker-mains/worker.js +7 -0
- package/dist/send-functionality/conversion.d.ts +4 -0
- package/dist/send-functionality/conversion.js +75 -0
- package/dist/send-functionality/inputSelection.d.ts +13 -0
- package/dist/send-functionality/inputSelection.js +8 -0
- package/dist/send-functionality/transactionBuilding.d.ts +51 -0
- package/dist/send-functionality/transactionBuilding.js +111 -0
- package/dist/tools/monero-tools.d.ts +46 -0
- package/dist/tools/monero-tools.js +165 -0
- package/dist/viewpair/ViewPair.d.ts +157 -0
- package/dist/viewpair/ViewPair.js +346 -0
- package/dist/wasm-processing/wasi.js +1 -2
- package/dist/wasm-processing/wasmFile.d.ts +1 -1
- package/dist/wasm-processing/wasmFile.js +2 -2
- package/dist/wasm-processing/wasmProcessor.d.ts +16 -4
- package/dist/wasm-processing/wasmProcessor.js +23 -7
- package/package.json +29 -6
- package/dist/testscrap.js +0 -36
- /package/dist/{testscrap.d.ts → io/BunFileInterface.js} +0 -0
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import type { ScanResult } from "../scanning-syncing/scanresult/scanResult";
|
|
1
2
|
import type { WasmProcessor } from "../wasm-processing/wasmProcessor";
|
|
2
3
|
export type GetBlocksBinRequest = {
|
|
3
|
-
requested_info?: "BLOCKS_ONLY" | "BLOCKS_AND_POOL" | "POOL_ONLY";
|
|
4
|
-
|
|
4
|
+
requested_info?: "BLOCKS_ONLY" | "BLOCKS_AND_POOL" | "POOL_ONLY" | number;
|
|
5
|
+
block_ids?: string[];
|
|
6
|
+
start_height?: number;
|
|
5
7
|
prune?: boolean;
|
|
6
8
|
no_miner_tx?: boolean;
|
|
7
9
|
pool_info_since?: number;
|
|
8
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* array of output indices to fetch
|
|
13
|
+
*/
|
|
14
|
+
export type GetOutsBinRequest = number[];
|
|
9
15
|
export type PoolInfo = {};
|
|
10
16
|
export type Transaction = {};
|
|
11
17
|
export type Block = {
|
|
@@ -32,41 +38,80 @@ export type GetBlocksBinResponse = {
|
|
|
32
38
|
pool_info: "None" | PoolInfo;
|
|
33
39
|
new_height: number;
|
|
34
40
|
};
|
|
41
|
+
export type GetOutsBinResponse = {
|
|
42
|
+
status: "OK";
|
|
43
|
+
untrusted: boolean;
|
|
44
|
+
credits: number;
|
|
45
|
+
top_hash: string;
|
|
46
|
+
outs: Array<{
|
|
47
|
+
key: number[];
|
|
48
|
+
mask: number[];
|
|
49
|
+
unlocked: boolean;
|
|
50
|
+
height: number;
|
|
51
|
+
txid: number[];
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
35
54
|
export type Status = "OK" | "BUSY" | "NOT MINING" | "PAYMENT REQUIRED" | "Failed." | string;
|
|
36
55
|
export type GetBlocksResultMeta = {
|
|
37
56
|
new_height: number;
|
|
38
57
|
daemon_height: number;
|
|
39
58
|
status: Status;
|
|
40
59
|
primary_address: "parsing-monerod-response-without-wallet" | "error-address-not-set" | string;
|
|
60
|
+
block_infos: BlockInfo[];
|
|
61
|
+
};
|
|
62
|
+
export type BlockInfo = {
|
|
63
|
+
block_timestamp: number;
|
|
64
|
+
block_height: number;
|
|
65
|
+
block_hash: string;
|
|
41
66
|
};
|
|
42
67
|
export type Output = {
|
|
43
|
-
amount:
|
|
68
|
+
amount: bigint;
|
|
44
69
|
block_height: number;
|
|
70
|
+
block_timestamp: number;
|
|
45
71
|
index_in_transaction: number;
|
|
46
72
|
index_on_blockchain: number;
|
|
47
73
|
payment_id: number;
|
|
48
74
|
stealth_address: string;
|
|
49
75
|
tx_hash: string;
|
|
76
|
+
is_miner_tx: boolean;
|
|
50
77
|
primary_address: string;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
78
|
+
subaddress_index: number | null;
|
|
79
|
+
serialized: string;
|
|
80
|
+
spent_relative_index?: number;
|
|
81
|
+
spent_in_tx_hash?: string;
|
|
82
|
+
spent_block_height?: number;
|
|
83
|
+
spent_block_timestamp?: number;
|
|
84
|
+
burned?: number;
|
|
56
85
|
};
|
|
57
86
|
export type ErrorResponse = {
|
|
58
87
|
error: string;
|
|
59
88
|
};
|
|
89
|
+
interface HasNodeUrl {
|
|
90
|
+
node_url: string;
|
|
91
|
+
}
|
|
60
92
|
export type GetBlocksBinMetaCallback = (meta: GetBlocksResultMeta) => void;
|
|
93
|
+
export declare const MAINNET_GENESIS_BLOCK_HASH = "418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3";
|
|
94
|
+
export declare const STAGENET_GENESIS_BLOCK_HASH = "76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb";
|
|
61
95
|
/**
|
|
62
96
|
* This function creates a binary request to the get_blocks.bin endpoint of the Monerod node.
|
|
63
97
|
* @param processor it uses the wasm module to build the request and parse the response.
|
|
64
98
|
* @param params params that will be turned into epee (moner lib that does binary serialization)
|
|
65
99
|
* @returns a Uint8Array that can be used to make a fetch request to the get_blocks.bin endpoint.
|
|
66
100
|
*/
|
|
67
|
-
export declare function getBlocksBinMakeRequest<T extends WasmProcessor>(processor: T, params: GetBlocksBinRequest): Uint8Array
|
|
68
|
-
export declare function getBlocksBinExecuteRequest<T extends WasmProcessor>(processor: T, params: GetBlocksBinRequest): Promise<Uint8Array
|
|
69
|
-
export declare function getBlocksBinScanResponse<T extends WasmProcessor>(processor: T, getBlocksBinResponseBuffer: Uint8Array, metaCallBack?: GetBlocksBinMetaCallback): Promise<ScanResult | ErrorResponse>;
|
|
70
|
-
export declare function getBlocksBinScan<T extends WasmProcessor>(processor: T, params: GetBlocksBinRequest, metaCallBack?: GetBlocksBinMetaCallback): Promise<ScanResult | ErrorResponse>;
|
|
71
|
-
export declare function getBlocksBinJson<T extends WasmProcessor>(processor: T, params: GetBlocksBinRequest): Promise<GetBlocksBinResponse | ErrorResponse>;
|
|
72
|
-
|
|
101
|
+
export declare function getBlocksBinMakeRequest<T extends WasmProcessor>(processor: T, params: GetBlocksBinRequest): Uint8Array<ArrayBufferLike>;
|
|
102
|
+
export declare function getBlocksBinExecuteRequest<T extends WasmProcessor & HasNodeUrl>(processor: T, params: GetBlocksBinRequest, stopSync?: AbortSignal): Promise<Uint8Array<ArrayBufferLike>>;
|
|
103
|
+
export declare function getBlocksBinScanResponse<T extends WasmProcessor>(processor: T, getBlocksBinResponseBuffer: Uint8Array, metaCallBack?: GetBlocksBinMetaCallback): Promise<ScanResult | ErrorResponse | undefined>;
|
|
104
|
+
export declare function getBlocksBinScan<T extends WasmProcessor & HasNodeUrl>(processor: T, params: GetBlocksBinRequest, metaCallBack?: GetBlocksBinMetaCallback, stopSync?: AbortSignal): Promise<ScanResult | ErrorResponse | undefined>;
|
|
105
|
+
export declare function getBlocksBinJson<T extends WasmProcessor & HasNodeUrl>(processor: T, params: GetBlocksBinRequest): Promise<GetBlocksBinResponse | ErrorResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* throws error on failure to create request
|
|
108
|
+
* @param processor wasmprocessor
|
|
109
|
+
* @param getouts_request_indices output indices to request
|
|
110
|
+
* @returns array with epee serialized get_outs.bin request arguments
|
|
111
|
+
*/
|
|
112
|
+
export declare function getOutsBinMakeRequest<T extends WasmProcessor>(processor: T, getouts_request_indices: GetOutsBinRequest): Uint8Array;
|
|
113
|
+
export type GetOutsResponseBuffer = Uint8Array;
|
|
114
|
+
export declare function getOutsBinExecuteRequest<T extends WasmProcessor & HasNodeUrl>(processor: T, params: GetOutsBinRequest): Promise<GetOutsResponseBuffer>;
|
|
115
|
+
export declare function getOutsBinJson<T extends WasmProcessor & HasNodeUrl>(processor: T, params: GetOutsBinRequest): Promise<GetOutsBinResponse>;
|
|
116
|
+
export declare function binaryFetchRequest(url: string, body: Uint8Array, stopSync?: AbortSignal): Promise<Uint8Array>;
|
|
117
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export const MAINNET_GENESIS_BLOCK_HASH = "418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3";
|
|
2
|
+
export const STAGENET_GENESIS_BLOCK_HASH = "76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb";
|
|
1
3
|
/**
|
|
2
4
|
* This function creates a binary request to the get_blocks.bin endpoint of the Monerod node.
|
|
3
5
|
* @param processor it uses the wasm module to build the request and parse the response.
|
|
@@ -12,33 +14,40 @@ export function getBlocksBinMakeRequest(processor, params) {
|
|
|
12
14
|
// BLOCKS_AND_POOL = 1,
|
|
13
15
|
// POOL_ONLY = 2
|
|
14
16
|
// };
|
|
15
|
-
let requested_info = 0;
|
|
16
17
|
if (params.requested_info === "BLOCKS_AND_POOL") {
|
|
17
|
-
requested_info = 1;
|
|
18
|
+
params.requested_info = 1;
|
|
18
19
|
}
|
|
19
20
|
else if (params.requested_info === "POOL_ONLY") {
|
|
20
|
-
requested_info = 2;
|
|
21
|
+
params.requested_info = 2;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
prune_num = 0;
|
|
25
|
-
}
|
|
26
|
-
let no_miner_tx_num = 0;
|
|
27
|
-
if (params.no_miner_tx) {
|
|
28
|
-
no_miner_tx_num = 1;
|
|
23
|
+
else {
|
|
24
|
+
params.requested_info = 0;
|
|
29
25
|
}
|
|
26
|
+
if (params.prune === undefined)
|
|
27
|
+
params.prune = true; // prune default true, our scan function expects pruned transactions
|
|
28
|
+
const json_params = JSON.stringify(params);
|
|
30
29
|
let getBlocksRequestArray;
|
|
30
|
+
processor.writeToWasmMemory = (ptr, len) => {
|
|
31
|
+
processor.writeString(ptr, len, json_params);
|
|
32
|
+
};
|
|
31
33
|
processor.readFromWasmMemory = (ptr, len) => {
|
|
32
34
|
getBlocksRequestArray = processor.readArray(ptr, len);
|
|
33
35
|
};
|
|
36
|
+
let error = null;
|
|
37
|
+
processor.readErrorFromWasmMemory = (ptr, len) => {
|
|
38
|
+
error = JSON.parse(processor.readString(ptr, len));
|
|
39
|
+
};
|
|
34
40
|
//@ts-ignore
|
|
35
|
-
processor.tinywasi.instance.exports.build_getblocksbin_request(
|
|
36
|
-
|
|
41
|
+
processor.tinywasi.instance.exports.build_getblocksbin_request(json_params.length);
|
|
42
|
+
if (!getBlocksRequestArray)
|
|
43
|
+
// written in build_getblocksbin_request call to readFromWasmMemory
|
|
44
|
+
throw error || new Error("failed to build get_blocks.bin request");
|
|
45
|
+
return getBlocksRequestArray;
|
|
37
46
|
}
|
|
38
|
-
export async function getBlocksBinExecuteRequest(processor, params) {
|
|
47
|
+
export async function getBlocksBinExecuteRequest(processor, params, stopSync) {
|
|
39
48
|
const getBlocksRequestArray = getBlocksBinMakeRequest(processor, params);
|
|
40
|
-
const getBlocksBinResponseBuffer = await binaryFetchRequest(processor.node_url + "/getblocks.bin", getBlocksRequestArray // written in build_getblocksbin_request call to readFromWasmMemory
|
|
41
|
-
);
|
|
49
|
+
const getBlocksBinResponseBuffer = await binaryFetchRequest(processor.node_url + "/getblocks.bin", getBlocksRequestArray, // written in build_getblocksbin_request call to readFromWasmMemory
|
|
50
|
+
stopSync);
|
|
42
51
|
return getBlocksBinResponseBuffer;
|
|
43
52
|
}
|
|
44
53
|
export async function getBlocksBinScanResponse(processor, getBlocksBinResponseBuffer, metaCallBack) {
|
|
@@ -52,10 +61,16 @@ export async function getBlocksBinScanResponse(processor, getBlocksBinResponseBu
|
|
|
52
61
|
if (metaCallBack)
|
|
53
62
|
metaCallBack(resultMeta);
|
|
54
63
|
processor.readFromWasmMemory = (ptr, len) => {
|
|
55
|
-
result = JSON.parse(processor.readString(ptr, len))
|
|
64
|
+
result = JSON.parse(processor.readString(ptr, len), (key, value) => {
|
|
65
|
+
if (key === "amount")
|
|
66
|
+
return BigInt(value);
|
|
67
|
+
return value;
|
|
68
|
+
});
|
|
56
69
|
if (!("error" in result)) {
|
|
57
70
|
result.new_height = resultMeta.new_height;
|
|
58
71
|
result.primary_address = resultMeta.primary_address;
|
|
72
|
+
result.block_infos = resultMeta.block_infos;
|
|
73
|
+
result.daemon_height = resultMeta.daemon_height;
|
|
59
74
|
}
|
|
60
75
|
};
|
|
61
76
|
};
|
|
@@ -63,41 +78,13 @@ export async function getBlocksBinScanResponse(processor, getBlocksBinResponseBu
|
|
|
63
78
|
processor.tinywasi.instance.exports.scan_blocks_with_get_blocks_bin(getBlocksBinResponseBuffer.length);
|
|
64
79
|
return result; //result written in scan_blocks_with_get_blocks_bin
|
|
65
80
|
}
|
|
66
|
-
export async function getBlocksBinScan(processor, params, metaCallBack) {
|
|
67
|
-
const getBlocksBinResponseBuffer = await getBlocksBinExecuteRequest(processor, params);
|
|
81
|
+
export async function getBlocksBinScan(processor, params, metaCallBack, stopSync) {
|
|
82
|
+
const getBlocksBinResponseBuffer = await getBlocksBinExecuteRequest(processor, params, stopSync);
|
|
68
83
|
return getBlocksBinScanResponse(processor, getBlocksBinResponseBuffer, metaCallBack);
|
|
69
84
|
}
|
|
70
85
|
export async function getBlocksBinJson(processor, params) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// {
|
|
74
|
-
// BLOCKS_ONLY = 0,
|
|
75
|
-
// BLOCKS_AND_POOL = 1,
|
|
76
|
-
// POOL_ONLY = 2
|
|
77
|
-
// };
|
|
78
|
-
let requested_info = 0;
|
|
79
|
-
if (params.requested_info === "BLOCKS_AND_POOL") {
|
|
80
|
-
requested_info = 1;
|
|
81
|
-
}
|
|
82
|
-
else if (params.requested_info === "POOL_ONLY") {
|
|
83
|
-
requested_info = 2;
|
|
84
|
-
}
|
|
85
|
-
let prune_num = 1;
|
|
86
|
-
if (params.prune === false) {
|
|
87
|
-
prune_num = 0;
|
|
88
|
-
}
|
|
89
|
-
let no_miner_tx_num = 0;
|
|
90
|
-
if (params.no_miner_tx) {
|
|
91
|
-
no_miner_tx_num = 1;
|
|
92
|
-
}
|
|
93
|
-
let getBlocksArray;
|
|
94
|
-
processor.readFromWasmMemory = (ptr, len) => {
|
|
95
|
-
getBlocksArray = processor.readArray(ptr, len);
|
|
96
|
-
};
|
|
97
|
-
//@ts-ignore
|
|
98
|
-
processor.tinywasi.instance.exports.build_getblocksbin_request(requested_info, BigInt(params.start_height), prune_num, no_miner_tx_num, BigInt(params.pool_info_since || 0));
|
|
99
|
-
const getBlocksBinResponseBuffer = await binaryFetchRequest(processor.node_url + "/getblocks.bin", getBlocksArray // written in build_getblocksbin_request call to readFromWasmMemory
|
|
100
|
-
);
|
|
86
|
+
const getBlocksRequestArray = getBlocksBinMakeRequest(processor, params);
|
|
87
|
+
const getBlocksBinResponseBuffer = await binaryFetchRequest(processor.node_url + "/getblocks.bin", getBlocksRequestArray);
|
|
101
88
|
processor.writeToWasmMemory = (ptr, len) => {
|
|
102
89
|
processor.writeArray(ptr, len, getBlocksBinResponseBuffer);
|
|
103
90
|
};
|
|
@@ -116,12 +103,81 @@ export async function getBlocksBinJson(processor, params) {
|
|
|
116
103
|
processor.tinywasi.instance.exports.convert_get_blocks_bin_response_to_json(getBlocksBinResponseBuffer.length);
|
|
117
104
|
return result; //result written in convert_get_blocks_bin_response_to_json
|
|
118
105
|
}
|
|
119
|
-
|
|
106
|
+
/**
|
|
107
|
+
* throws error on failure to create request
|
|
108
|
+
* @param processor wasmprocessor
|
|
109
|
+
* @param getouts_request_indices output indices to request
|
|
110
|
+
* @returns array with epee serialized get_outs.bin request arguments
|
|
111
|
+
*/
|
|
112
|
+
export function getOutsBinMakeRequest(processor, getouts_request_indices) {
|
|
113
|
+
let getOutsArray = undefined; // return value
|
|
114
|
+
const getouts_json = JSON.stringify(getouts_request_indices); // argument
|
|
115
|
+
processor.readFromWasmMemory = (ptr, len) => {
|
|
116
|
+
// read result
|
|
117
|
+
getOutsArray = processor.readArray(ptr, len);
|
|
118
|
+
};
|
|
119
|
+
processor.writeToWasmMemory = (ptr, len) => {
|
|
120
|
+
// write argument
|
|
121
|
+
processor.writeString(ptr, len, getouts_json);
|
|
122
|
+
};
|
|
123
|
+
//@ts-ignore
|
|
124
|
+
processor.tinywasi.instance.exports.build_getoutsbin_request(getouts_json.length);
|
|
125
|
+
if (!getOutsArray) {
|
|
126
|
+
throw new Error("Failed to build get_outs.bin request");
|
|
127
|
+
}
|
|
128
|
+
return getOutsArray; // written in build_getblocksbin_request call to readFromWasmMemory
|
|
129
|
+
}
|
|
130
|
+
export async function getOutsBinExecuteRequest(processor, params) {
|
|
131
|
+
const getOutsRequestArray = getOutsBinMakeRequest(processor, params);
|
|
132
|
+
const getOutsBinResponseBuffer = await binaryFetchRequest(processor.node_url + "/get_outs.bin", getOutsRequestArray);
|
|
133
|
+
return getOutsBinResponseBuffer;
|
|
134
|
+
}
|
|
135
|
+
export async function getOutsBinJson(processor, params) {
|
|
136
|
+
const getOutsBinResponseBuffer = await getOutsBinExecuteRequest(processor, params);
|
|
137
|
+
processor.writeToWasmMemory = (ptr, len) => {
|
|
138
|
+
processor.writeArray(ptr, len, getOutsBinResponseBuffer);
|
|
139
|
+
};
|
|
140
|
+
let result;
|
|
141
|
+
processor.readFromWasmMemory = (ptr, len) => {
|
|
142
|
+
result = JSON.parse(processor.readString(ptr, len));
|
|
143
|
+
};
|
|
144
|
+
//@ts-ignore
|
|
145
|
+
processor.tinywasi.instance.exports.convert_get_outs_bin_response_to_json(getOutsBinResponseBuffer.length);
|
|
146
|
+
if (!result) {
|
|
147
|
+
throw new Error("Failed to parse get_outs.bin response");
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
export async function binaryFetchRequest(url, body, stopSync) {
|
|
120
152
|
const response = await fetch(url, {
|
|
121
|
-
body,
|
|
153
|
+
body: body,
|
|
122
154
|
method: "POST",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
155
|
+
signal: stopSync,
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok)
|
|
158
|
+
throw new Error(`HTTP ${response.status}`);
|
|
159
|
+
const reader = response.body.getReader();
|
|
160
|
+
const chunks = [];
|
|
161
|
+
let totalBytes = 0;
|
|
162
|
+
const MAX_SIZE = 125829120; // 120MB
|
|
163
|
+
try {
|
|
164
|
+
while (true) {
|
|
165
|
+
const { done, value } = await reader.read();
|
|
166
|
+
if (done)
|
|
167
|
+
break;
|
|
168
|
+
totalBytes += value.length;
|
|
169
|
+
if (totalBytes > MAX_SIZE)
|
|
170
|
+
throw new Error(`Response exceeds 120MB (${totalBytes} bytes)`);
|
|
171
|
+
chunks.push(value);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (readError) {
|
|
175
|
+
console.error("Reader error:", readError, "Partial bytes:", totalBytes);
|
|
176
|
+
// Eat the error - continue to return partial data
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
reader.releaseLock();
|
|
180
|
+
}
|
|
181
|
+
// Always return what we got (even if partial)
|
|
182
|
+
return Uint8Array.from(chunks.reduce((acc, chunk) => [...acc, ...chunk], []));
|
|
127
183
|
}
|