@spirobel/monero-wallet-api 0.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/README.md +55 -0
- package/dist/api.d.ts +55 -0
- package/dist/api.js +103 -0
- package/dist/cli.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -0
- package/dist/node-interaction/binaryEndpoints.d.ts +60 -0
- package/dist/node-interaction/binaryEndpoints.js +109 -0
- package/dist/node-interaction/jsonEndpoints.d.ts +281 -0
- package/dist/node-interaction/jsonEndpoints.js +82 -0
- package/dist/wasi.d.ts +26 -0
- package/dist/wasi.js +174 -0
- package/dist/wasm-processing/wasi.d.ts +26 -0
- package/dist/wasm-processing/wasi.js +174 -0
- package/dist/wasm-processing/wasmFile.d.ts +1 -0
- package/dist/wasm-processing/wasmFile.js +3 -0
- package/dist/wasm-processing/wasmProcessor.d.ts +78 -0
- package/dist/wasm-processing/wasmProcessor.js +116 -0
- package/dist/wasmFile.d.ts +1 -0
- package/dist/wasmFile.js +8 -0
- package/package.json +30 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const GetInfoResponseSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
5
|
+
result: z.ZodObject<{
|
|
6
|
+
adjusted_time: z.ZodNumber;
|
|
7
|
+
alt_blocks_count: z.ZodNumber;
|
|
8
|
+
block_size_limit: z.ZodNumber;
|
|
9
|
+
block_size_median: z.ZodNumber;
|
|
10
|
+
block_weight_limit: z.ZodNumber;
|
|
11
|
+
block_weight_median: z.ZodNumber;
|
|
12
|
+
bootstrap_daemon_address: z.ZodString;
|
|
13
|
+
busy_syncing: z.ZodBoolean;
|
|
14
|
+
credits: z.ZodNumber;
|
|
15
|
+
cumulative_difficulty: z.ZodNumber;
|
|
16
|
+
cumulative_difficulty_top64: z.ZodNumber;
|
|
17
|
+
database_size: z.ZodNumber;
|
|
18
|
+
difficulty: z.ZodNumber;
|
|
19
|
+
difficulty_top64: z.ZodNumber;
|
|
20
|
+
free_space: z.ZodNumber;
|
|
21
|
+
grey_peerlist_size: z.ZodNumber;
|
|
22
|
+
height: z.ZodNumber;
|
|
23
|
+
height_without_bootstrap: z.ZodNumber;
|
|
24
|
+
incoming_connections_count: z.ZodNumber;
|
|
25
|
+
mainnet: z.ZodBoolean;
|
|
26
|
+
nettype: z.ZodString;
|
|
27
|
+
offline: z.ZodBoolean;
|
|
28
|
+
outgoing_connections_count: z.ZodNumber;
|
|
29
|
+
restricted: z.ZodBoolean;
|
|
30
|
+
rpc_connections_count: z.ZodNumber;
|
|
31
|
+
stagenet: z.ZodBoolean;
|
|
32
|
+
start_time: z.ZodNumber;
|
|
33
|
+
status: z.ZodString;
|
|
34
|
+
synchronized: z.ZodBoolean;
|
|
35
|
+
target: z.ZodNumber;
|
|
36
|
+
target_height: z.ZodNumber;
|
|
37
|
+
testnet: z.ZodBoolean;
|
|
38
|
+
top_block_hash: z.ZodString;
|
|
39
|
+
top_hash: z.ZodString;
|
|
40
|
+
tx_count: z.ZodNumber;
|
|
41
|
+
tx_pool_size: z.ZodNumber;
|
|
42
|
+
untrusted: z.ZodBoolean;
|
|
43
|
+
update_available: z.ZodBoolean;
|
|
44
|
+
version: z.ZodString;
|
|
45
|
+
was_bootstrap_ever_used: z.ZodBoolean;
|
|
46
|
+
white_peerlist_size: z.ZodNumber;
|
|
47
|
+
wide_cumulative_difficulty: z.ZodString;
|
|
48
|
+
wide_difficulty: z.ZodString;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
status: string;
|
|
51
|
+
adjusted_time: number;
|
|
52
|
+
alt_blocks_count: number;
|
|
53
|
+
block_size_limit: number;
|
|
54
|
+
block_size_median: number;
|
|
55
|
+
block_weight_limit: number;
|
|
56
|
+
block_weight_median: number;
|
|
57
|
+
bootstrap_daemon_address: string;
|
|
58
|
+
busy_syncing: boolean;
|
|
59
|
+
credits: number;
|
|
60
|
+
cumulative_difficulty: number;
|
|
61
|
+
cumulative_difficulty_top64: number;
|
|
62
|
+
database_size: number;
|
|
63
|
+
difficulty: number;
|
|
64
|
+
difficulty_top64: number;
|
|
65
|
+
free_space: number;
|
|
66
|
+
grey_peerlist_size: number;
|
|
67
|
+
height: number;
|
|
68
|
+
height_without_bootstrap: number;
|
|
69
|
+
incoming_connections_count: number;
|
|
70
|
+
mainnet: boolean;
|
|
71
|
+
nettype: string;
|
|
72
|
+
offline: boolean;
|
|
73
|
+
outgoing_connections_count: number;
|
|
74
|
+
restricted: boolean;
|
|
75
|
+
rpc_connections_count: number;
|
|
76
|
+
stagenet: boolean;
|
|
77
|
+
start_time: number;
|
|
78
|
+
synchronized: boolean;
|
|
79
|
+
target: number;
|
|
80
|
+
target_height: number;
|
|
81
|
+
testnet: boolean;
|
|
82
|
+
top_block_hash: string;
|
|
83
|
+
top_hash: string;
|
|
84
|
+
tx_count: number;
|
|
85
|
+
tx_pool_size: number;
|
|
86
|
+
untrusted: boolean;
|
|
87
|
+
update_available: boolean;
|
|
88
|
+
version: string;
|
|
89
|
+
was_bootstrap_ever_used: boolean;
|
|
90
|
+
white_peerlist_size: number;
|
|
91
|
+
wide_cumulative_difficulty: string;
|
|
92
|
+
wide_difficulty: string;
|
|
93
|
+
}, {
|
|
94
|
+
status: string;
|
|
95
|
+
adjusted_time: number;
|
|
96
|
+
alt_blocks_count: number;
|
|
97
|
+
block_size_limit: number;
|
|
98
|
+
block_size_median: number;
|
|
99
|
+
block_weight_limit: number;
|
|
100
|
+
block_weight_median: number;
|
|
101
|
+
bootstrap_daemon_address: string;
|
|
102
|
+
busy_syncing: boolean;
|
|
103
|
+
credits: number;
|
|
104
|
+
cumulative_difficulty: number;
|
|
105
|
+
cumulative_difficulty_top64: number;
|
|
106
|
+
database_size: number;
|
|
107
|
+
difficulty: number;
|
|
108
|
+
difficulty_top64: number;
|
|
109
|
+
free_space: number;
|
|
110
|
+
grey_peerlist_size: number;
|
|
111
|
+
height: number;
|
|
112
|
+
height_without_bootstrap: number;
|
|
113
|
+
incoming_connections_count: number;
|
|
114
|
+
mainnet: boolean;
|
|
115
|
+
nettype: string;
|
|
116
|
+
offline: boolean;
|
|
117
|
+
outgoing_connections_count: number;
|
|
118
|
+
restricted: boolean;
|
|
119
|
+
rpc_connections_count: number;
|
|
120
|
+
stagenet: boolean;
|
|
121
|
+
start_time: number;
|
|
122
|
+
synchronized: boolean;
|
|
123
|
+
target: number;
|
|
124
|
+
target_height: number;
|
|
125
|
+
testnet: boolean;
|
|
126
|
+
top_block_hash: string;
|
|
127
|
+
top_hash: string;
|
|
128
|
+
tx_count: number;
|
|
129
|
+
tx_pool_size: number;
|
|
130
|
+
untrusted: boolean;
|
|
131
|
+
update_available: boolean;
|
|
132
|
+
version: string;
|
|
133
|
+
was_bootstrap_ever_used: boolean;
|
|
134
|
+
white_peerlist_size: number;
|
|
135
|
+
wide_cumulative_difficulty: string;
|
|
136
|
+
wide_difficulty: string;
|
|
137
|
+
}>;
|
|
138
|
+
}, "strip", z.ZodTypeAny, {
|
|
139
|
+
id: string;
|
|
140
|
+
jsonrpc: "2.0";
|
|
141
|
+
result: {
|
|
142
|
+
status: string;
|
|
143
|
+
adjusted_time: number;
|
|
144
|
+
alt_blocks_count: number;
|
|
145
|
+
block_size_limit: number;
|
|
146
|
+
block_size_median: number;
|
|
147
|
+
block_weight_limit: number;
|
|
148
|
+
block_weight_median: number;
|
|
149
|
+
bootstrap_daemon_address: string;
|
|
150
|
+
busy_syncing: boolean;
|
|
151
|
+
credits: number;
|
|
152
|
+
cumulative_difficulty: number;
|
|
153
|
+
cumulative_difficulty_top64: number;
|
|
154
|
+
database_size: number;
|
|
155
|
+
difficulty: number;
|
|
156
|
+
difficulty_top64: number;
|
|
157
|
+
free_space: number;
|
|
158
|
+
grey_peerlist_size: number;
|
|
159
|
+
height: number;
|
|
160
|
+
height_without_bootstrap: number;
|
|
161
|
+
incoming_connections_count: number;
|
|
162
|
+
mainnet: boolean;
|
|
163
|
+
nettype: string;
|
|
164
|
+
offline: boolean;
|
|
165
|
+
outgoing_connections_count: number;
|
|
166
|
+
restricted: boolean;
|
|
167
|
+
rpc_connections_count: number;
|
|
168
|
+
stagenet: boolean;
|
|
169
|
+
start_time: number;
|
|
170
|
+
synchronized: boolean;
|
|
171
|
+
target: number;
|
|
172
|
+
target_height: number;
|
|
173
|
+
testnet: boolean;
|
|
174
|
+
top_block_hash: string;
|
|
175
|
+
top_hash: string;
|
|
176
|
+
tx_count: number;
|
|
177
|
+
tx_pool_size: number;
|
|
178
|
+
untrusted: boolean;
|
|
179
|
+
update_available: boolean;
|
|
180
|
+
version: string;
|
|
181
|
+
was_bootstrap_ever_used: boolean;
|
|
182
|
+
white_peerlist_size: number;
|
|
183
|
+
wide_cumulative_difficulty: string;
|
|
184
|
+
wide_difficulty: string;
|
|
185
|
+
};
|
|
186
|
+
}, {
|
|
187
|
+
id: string;
|
|
188
|
+
jsonrpc: "2.0";
|
|
189
|
+
result: {
|
|
190
|
+
status: string;
|
|
191
|
+
adjusted_time: number;
|
|
192
|
+
alt_blocks_count: number;
|
|
193
|
+
block_size_limit: number;
|
|
194
|
+
block_size_median: number;
|
|
195
|
+
block_weight_limit: number;
|
|
196
|
+
block_weight_median: number;
|
|
197
|
+
bootstrap_daemon_address: string;
|
|
198
|
+
busy_syncing: boolean;
|
|
199
|
+
credits: number;
|
|
200
|
+
cumulative_difficulty: number;
|
|
201
|
+
cumulative_difficulty_top64: number;
|
|
202
|
+
database_size: number;
|
|
203
|
+
difficulty: number;
|
|
204
|
+
difficulty_top64: number;
|
|
205
|
+
free_space: number;
|
|
206
|
+
grey_peerlist_size: number;
|
|
207
|
+
height: number;
|
|
208
|
+
height_without_bootstrap: number;
|
|
209
|
+
incoming_connections_count: number;
|
|
210
|
+
mainnet: boolean;
|
|
211
|
+
nettype: string;
|
|
212
|
+
offline: boolean;
|
|
213
|
+
outgoing_connections_count: number;
|
|
214
|
+
restricted: boolean;
|
|
215
|
+
rpc_connections_count: number;
|
|
216
|
+
stagenet: boolean;
|
|
217
|
+
start_time: number;
|
|
218
|
+
synchronized: boolean;
|
|
219
|
+
target: number;
|
|
220
|
+
target_height: number;
|
|
221
|
+
testnet: boolean;
|
|
222
|
+
top_block_hash: string;
|
|
223
|
+
top_hash: string;
|
|
224
|
+
tx_count: number;
|
|
225
|
+
tx_pool_size: number;
|
|
226
|
+
untrusted: boolean;
|
|
227
|
+
update_available: boolean;
|
|
228
|
+
version: string;
|
|
229
|
+
was_bootstrap_ever_used: boolean;
|
|
230
|
+
white_peerlist_size: number;
|
|
231
|
+
wide_cumulative_difficulty: string;
|
|
232
|
+
wide_difficulty: string;
|
|
233
|
+
};
|
|
234
|
+
}>;
|
|
235
|
+
export type GetInfoResponse = z.infer<typeof GetInfoResponseSchema>;
|
|
236
|
+
export declare function parseGetInfoResponse(data: unknown): GetInfoResponse | null;
|
|
237
|
+
export declare function get_info(NODE_URL: string): Promise<{
|
|
238
|
+
status: string;
|
|
239
|
+
adjusted_time: number;
|
|
240
|
+
alt_blocks_count: number;
|
|
241
|
+
block_size_limit: number;
|
|
242
|
+
block_size_median: number;
|
|
243
|
+
block_weight_limit: number;
|
|
244
|
+
block_weight_median: number;
|
|
245
|
+
bootstrap_daemon_address: string;
|
|
246
|
+
busy_syncing: boolean;
|
|
247
|
+
credits: number;
|
|
248
|
+
cumulative_difficulty: number;
|
|
249
|
+
cumulative_difficulty_top64: number;
|
|
250
|
+
database_size: number;
|
|
251
|
+
difficulty: number;
|
|
252
|
+
difficulty_top64: number;
|
|
253
|
+
free_space: number;
|
|
254
|
+
grey_peerlist_size: number;
|
|
255
|
+
height: number;
|
|
256
|
+
height_without_bootstrap: number;
|
|
257
|
+
incoming_connections_count: number;
|
|
258
|
+
mainnet: boolean;
|
|
259
|
+
nettype: string;
|
|
260
|
+
offline: boolean;
|
|
261
|
+
outgoing_connections_count: number;
|
|
262
|
+
restricted: boolean;
|
|
263
|
+
rpc_connections_count: number;
|
|
264
|
+
stagenet: boolean;
|
|
265
|
+
start_time: number;
|
|
266
|
+
synchronized: boolean;
|
|
267
|
+
target: number;
|
|
268
|
+
target_height: number;
|
|
269
|
+
testnet: boolean;
|
|
270
|
+
top_block_hash: string;
|
|
271
|
+
top_hash: string;
|
|
272
|
+
tx_count: number;
|
|
273
|
+
tx_pool_size: number;
|
|
274
|
+
untrusted: boolean;
|
|
275
|
+
update_available: boolean;
|
|
276
|
+
version: string;
|
|
277
|
+
was_bootstrap_ever_used: boolean;
|
|
278
|
+
white_peerlist_size: number;
|
|
279
|
+
wide_cumulative_difficulty: string;
|
|
280
|
+
wide_difficulty: string;
|
|
281
|
+
}>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const GetInfoResponseSchema = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
jsonrpc: z.literal("2.0"),
|
|
5
|
+
result: z.object({
|
|
6
|
+
adjusted_time: z.number(),
|
|
7
|
+
alt_blocks_count: z.number(),
|
|
8
|
+
block_size_limit: z.number(),
|
|
9
|
+
block_size_median: z.number(),
|
|
10
|
+
block_weight_limit: z.number(),
|
|
11
|
+
block_weight_median: z.number(),
|
|
12
|
+
bootstrap_daemon_address: z.string(),
|
|
13
|
+
busy_syncing: z.boolean(),
|
|
14
|
+
credits: z.number(),
|
|
15
|
+
cumulative_difficulty: z.number(),
|
|
16
|
+
cumulative_difficulty_top64: z.number(),
|
|
17
|
+
database_size: z.number(),
|
|
18
|
+
difficulty: z.number(),
|
|
19
|
+
difficulty_top64: z.number(),
|
|
20
|
+
free_space: z.number(),
|
|
21
|
+
grey_peerlist_size: z.number(),
|
|
22
|
+
height: z.number(),
|
|
23
|
+
height_without_bootstrap: z.number(),
|
|
24
|
+
incoming_connections_count: z.number(),
|
|
25
|
+
mainnet: z.boolean(),
|
|
26
|
+
nettype: z.string(),
|
|
27
|
+
offline: z.boolean(),
|
|
28
|
+
outgoing_connections_count: z.number(),
|
|
29
|
+
restricted: z.boolean(),
|
|
30
|
+
rpc_connections_count: z.number(),
|
|
31
|
+
stagenet: z.boolean(),
|
|
32
|
+
start_time: z.number(),
|
|
33
|
+
status: z.string(),
|
|
34
|
+
synchronized: z.boolean(),
|
|
35
|
+
target: z.number(),
|
|
36
|
+
target_height: z.number(),
|
|
37
|
+
testnet: z.boolean(),
|
|
38
|
+
top_block_hash: z.string(),
|
|
39
|
+
top_hash: z.string(),
|
|
40
|
+
tx_count: z.number(),
|
|
41
|
+
tx_pool_size: z.number(),
|
|
42
|
+
untrusted: z.boolean(),
|
|
43
|
+
update_available: z.boolean(),
|
|
44
|
+
version: z.string(),
|
|
45
|
+
was_bootstrap_ever_used: z.boolean(),
|
|
46
|
+
white_peerlist_size: z.number(),
|
|
47
|
+
wide_cumulative_difficulty: z.string(),
|
|
48
|
+
wide_difficulty: z.string(),
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
export function parseGetInfoResponse(data) {
|
|
52
|
+
const result = GetInfoResponseSchema.safeParse(data);
|
|
53
|
+
if (result.success) {
|
|
54
|
+
return result.data;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.error("Validation failed:", result.error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function get_info(NODE_URL) {
|
|
62
|
+
const getInfoResponse = await fetch(NODE_URL + "/json_rpc", {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
jsonrpc: "2.0",
|
|
69
|
+
id: "0",
|
|
70
|
+
method: "get_info",
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
if (!getInfoResponse.ok) {
|
|
74
|
+
throw new Error(`Failed to get info: ${getInfoResponse.statusText}`);
|
|
75
|
+
}
|
|
76
|
+
const getInfoResult = await getInfoResponse.json();
|
|
77
|
+
const parsedResult = parseGetInfoResponse(getInfoResult);
|
|
78
|
+
if (parsedResult === null || !parsedResult.result?.height) {
|
|
79
|
+
throw new Error("Failed to get height from get_info result");
|
|
80
|
+
}
|
|
81
|
+
return parsedResult.result;
|
|
82
|
+
}
|
package/dist/wasi.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class TinyWASI {
|
|
2
|
+
private instance?;
|
|
3
|
+
private WASI_ERRNO_SUCCESS;
|
|
4
|
+
private WASI_ERRNO_BADF;
|
|
5
|
+
private WASI_ERRNO_NOSYS;
|
|
6
|
+
private WASI_ERRNO_INVAL;
|
|
7
|
+
private WASI_FILETYPE_CHARACTER_DEVICE;
|
|
8
|
+
private WASI_RIGHTS_FD_SYNC;
|
|
9
|
+
private WASI_RIGHTS_FD_WRITE;
|
|
10
|
+
private WASI_RIGHTS_FD_FILESTAT_GET;
|
|
11
|
+
private WASI_FDFLAGS_APPEND;
|
|
12
|
+
private nameSpaces;
|
|
13
|
+
constructor(trace?: boolean);
|
|
14
|
+
initialize(instance: WebAssembly.Instance): void;
|
|
15
|
+
get imports(): WebAssembly.Imports;
|
|
16
|
+
getMemory(): WebAssembly.Memory;
|
|
17
|
+
getDataView(): DataView;
|
|
18
|
+
private trace;
|
|
19
|
+
private nosys;
|
|
20
|
+
private clock_res_get;
|
|
21
|
+
private clock_time_get;
|
|
22
|
+
private fd_fdstat_get;
|
|
23
|
+
private fd_write;
|
|
24
|
+
private random_get;
|
|
25
|
+
private environ_sizes_get;
|
|
26
|
+
}
|
package/dist/wasi.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
|
+
//vendored from https://github.com/qrdate/tinywasi/blob/main/src/TinyWASI.ts
|
|
3
|
+
export class TinyWASI {
|
|
4
|
+
instance = undefined;
|
|
5
|
+
WASI_ERRNO_SUCCESS = 0;
|
|
6
|
+
WASI_ERRNO_BADF = 8;
|
|
7
|
+
WASI_ERRNO_NOSYS = 52;
|
|
8
|
+
WASI_ERRNO_INVAL = 28;
|
|
9
|
+
WASI_FILETYPE_CHARACTER_DEVICE = 2;
|
|
10
|
+
WASI_RIGHTS_FD_SYNC = 1 << 4;
|
|
11
|
+
WASI_RIGHTS_FD_WRITE = 1 << 6;
|
|
12
|
+
WASI_RIGHTS_FD_FILESTAT_GET = 1 << 21;
|
|
13
|
+
WASI_FDFLAGS_APPEND = 1 << 0;
|
|
14
|
+
nameSpaces = {
|
|
15
|
+
wasi_snapshot_preview1: {
|
|
16
|
+
args_get: undefined, // ((param i32 i32) (result i32))
|
|
17
|
+
args_sizes_get: undefined, // ((param i32 i32) (result i32))
|
|
18
|
+
clock_res_get: this.clock_res_get, // ((param i32 i32) (result i32))
|
|
19
|
+
clock_time_get: this.clock_time_get, // ((param i32 i64 i32) (result i32))
|
|
20
|
+
environ_get: undefined, // ((param i32 i32) (result i32))
|
|
21
|
+
environ_sizes_get: this.environ_sizes_get, // ((param i32 i32) (result i32))
|
|
22
|
+
fd_advise: undefined, // ((param i32 i64 i64 i32) (result i32))
|
|
23
|
+
fd_allocate: undefined, // ((param i32 i64 i64) (result i32))
|
|
24
|
+
fd_close: undefined, // ((param i32) (result i32))
|
|
25
|
+
fd_datasync: undefined, // ((param i32) (result i32))
|
|
26
|
+
fd_fdstat_get: this.fd_fdstat_get, // ((param i32 i32) (result i32))
|
|
27
|
+
fd_fdstat_set_flags: undefined, // ((param i32 i32) (result i32))
|
|
28
|
+
fd_fdstat_set_rights: undefined, // ((param i32 i64 i64) (result i32))
|
|
29
|
+
fd_filestat_get: undefined, // ((param i32 i32) (result i32))
|
|
30
|
+
fd_filestat_set_size: undefined, // ((param i32 i64) (result i32))
|
|
31
|
+
fd_filestat_set_times: undefined, // ((param i32 i64 i64 i32) (result i32))
|
|
32
|
+
fd_pread: undefined, // ((param i32 i32 i32 i64 i32) (result i32))
|
|
33
|
+
fd_prestat_dir_name: undefined, // ((param i32 i32 i32) (result i32))
|
|
34
|
+
fd_prestat_get: undefined, // ((param i32 i32) (result i32))
|
|
35
|
+
fd_pwrite: undefined, // ((param i32 i32 i32 i64 i32) (result i32))
|
|
36
|
+
fd_read: undefined, // ((param i32 i32 i32 i32) (result i32))
|
|
37
|
+
fd_readdir: undefined, // ((param i32 i32 i32 i64 i32) (result i32))
|
|
38
|
+
fd_renumber: undefined, // ((param i32 i32) (result i32))
|
|
39
|
+
fd_seek: undefined, // ((param i32 i64 i32 i32) (result i32))
|
|
40
|
+
fd_sync: undefined, // ((param i32) (result i32))
|
|
41
|
+
fd_tell: undefined, // ((param i32 i32) (result i32))
|
|
42
|
+
fd_write: this.fd_write, // ((param i32 i32 i32 i32) (result i32))
|
|
43
|
+
path_create_directory: undefined, // ((param i32 i32 i32) (result i32))
|
|
44
|
+
path_filestat_get: undefined, // ((param i32 i32 i32 i32 i32) (result i32))
|
|
45
|
+
path_filestat_set_times: undefined, // ((param i32 i32 i32 i32 i64 i64 i32) (result i32))
|
|
46
|
+
path_link: undefined, // ((param i32 i32 i32 i32 i32 i32 i32) (result i32))
|
|
47
|
+
path_open: undefined, // ((param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))
|
|
48
|
+
path_readlink: undefined, // ((param i32 i32 i32 i32 i32 i32) (result i32))
|
|
49
|
+
path_remove_directory: undefined, // ((param i32 i32 i32) (result i32))
|
|
50
|
+
path_rename: undefined, // ((param i32 i32 i32 i32 i32 i32) (result i32))
|
|
51
|
+
path_symlink: undefined, // ((param i32 i32 i32 i32 i32) (result i32))
|
|
52
|
+
path_unlink_file: undefined, // ((param i32 i32 i32) (result i32))
|
|
53
|
+
poll_oneoff: undefined, // ((param i32 i32 i32 i32) (result i32))
|
|
54
|
+
proc_exit: undefined, // ((param i32))
|
|
55
|
+
proc_raise: undefined, // ((param i32) (result i32))
|
|
56
|
+
random_get: this.random_get, // ((param i32 i32) (result i32))
|
|
57
|
+
sched_yield: undefined, // ((result i32))
|
|
58
|
+
sock_recv: undefined, // ((param i32 i32 i32 i32 i32 i32) (result i32))
|
|
59
|
+
sock_send: undefined, // ((param i32 i32 i32 i32 i32) (result i32))
|
|
60
|
+
sock_shutdown: undefined, // ((param i32 i32) (result i32))
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
constructor(trace) {
|
|
64
|
+
for (const ns of Object.keys(this.nameSpaces)) {
|
|
65
|
+
const nameSpace = this.nameSpaces[ns];
|
|
66
|
+
for (const fn of Object.keys(nameSpace)) {
|
|
67
|
+
let func = nameSpace[fn] || this.nosys(fn);
|
|
68
|
+
func = func.bind(this);
|
|
69
|
+
if (trace)
|
|
70
|
+
func = this.trace(fn, func).bind(this);
|
|
71
|
+
nameSpace[fn] = func;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
initialize(instance) {
|
|
76
|
+
this.instance = instance;
|
|
77
|
+
}
|
|
78
|
+
get imports() {
|
|
79
|
+
return this.nameSpaces;
|
|
80
|
+
}
|
|
81
|
+
getMemory() {
|
|
82
|
+
if (this.instance)
|
|
83
|
+
return this.instance.exports.memory;
|
|
84
|
+
else
|
|
85
|
+
throw new Error("Attempt to access instance before initialisation!");
|
|
86
|
+
}
|
|
87
|
+
getDataView() {
|
|
88
|
+
if (this.instance)
|
|
89
|
+
return new DataView(this.instance.exports.memory.buffer);
|
|
90
|
+
else
|
|
91
|
+
throw new Error("Attempt to access instance before initialisation!");
|
|
92
|
+
}
|
|
93
|
+
trace(name, origFunc) {
|
|
94
|
+
return (...args) => {
|
|
95
|
+
const result = origFunc(...args);
|
|
96
|
+
console.log(`Trace: ${name}(${args.toString()}) -> ${result}`);
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
nosys(name) {
|
|
101
|
+
return (...args) => {
|
|
102
|
+
console.error(`Unimplemented call to ${name}(${args.toString()})`);
|
|
103
|
+
return this.WASI_ERRNO_NOSYS;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
clock_res_get(id, resOut) {
|
|
107
|
+
if (id !== 0)
|
|
108
|
+
return this.WASI_ERRNO_INVAL;
|
|
109
|
+
const view = this.getDataView();
|
|
110
|
+
view.setUint32(resOut, 1000000.0 % 0x100000000, true);
|
|
111
|
+
view.setUint32(resOut + 4, 1000000.0 / 0x100000000, true);
|
|
112
|
+
return this.WASI_ERRNO_SUCCESS;
|
|
113
|
+
}
|
|
114
|
+
clock_time_get(id, precision, timeOut) {
|
|
115
|
+
if (id !== 0)
|
|
116
|
+
return this.WASI_ERRNO_INVAL;
|
|
117
|
+
const view = this.getDataView();
|
|
118
|
+
const now = new Date().getTime();
|
|
119
|
+
view.setUint32(timeOut, (now * 1000000.0) % 0x100000000, true);
|
|
120
|
+
view.setUint32(timeOut + 4, (now * 1000000.0) / 0x100000000, true);
|
|
121
|
+
return this.WASI_ERRNO_SUCCESS;
|
|
122
|
+
}
|
|
123
|
+
fd_fdstat_get(fd, fdstat) {
|
|
124
|
+
if (fd > 2)
|
|
125
|
+
return this.WASI_ERRNO_BADF;
|
|
126
|
+
const view = this.getDataView();
|
|
127
|
+
view.setUint8(fdstat, this.WASI_FILETYPE_CHARACTER_DEVICE);
|
|
128
|
+
view.setUint16(fdstat + 2, this.WASI_FDFLAGS_APPEND, true);
|
|
129
|
+
view.setUint16(fdstat + 8, this.WASI_RIGHTS_FD_SYNC |
|
|
130
|
+
this.WASI_RIGHTS_FD_WRITE |
|
|
131
|
+
this.WASI_RIGHTS_FD_FILESTAT_GET, true);
|
|
132
|
+
view.setUint16(fdstat + 16, 0, true);
|
|
133
|
+
return this.WASI_ERRNO_SUCCESS;
|
|
134
|
+
}
|
|
135
|
+
fd_write(fd, iovs, iovsLen, nwritten) {
|
|
136
|
+
if (fd > 2)
|
|
137
|
+
return this.WASI_ERRNO_BADF;
|
|
138
|
+
const view = this.getDataView();
|
|
139
|
+
const memory = this.getMemory();
|
|
140
|
+
const buffers = [];
|
|
141
|
+
for (let i = 0; i < iovsLen; i++) {
|
|
142
|
+
const iov = iovs + i * 8;
|
|
143
|
+
const offset = view.getUint32(iov, true);
|
|
144
|
+
const len = view.getUint32(iov + 4, true);
|
|
145
|
+
buffers.push(new Uint8Array(memory.buffer, offset, len));
|
|
146
|
+
}
|
|
147
|
+
const length = buffers.reduce((s, b) => s + b.length, 0);
|
|
148
|
+
const buffer = new Uint8Array(length);
|
|
149
|
+
let offset = 0;
|
|
150
|
+
buffers.forEach((b) => {
|
|
151
|
+
buffer.set(b, offset);
|
|
152
|
+
offset += b.length;
|
|
153
|
+
});
|
|
154
|
+
const string = new TextDecoder("utf-8").decode(buffer).replace(/\n$/, "");
|
|
155
|
+
if (fd === 1)
|
|
156
|
+
console.log(string);
|
|
157
|
+
else
|
|
158
|
+
console.error(string);
|
|
159
|
+
view.setUint32(nwritten, buffer.length, true);
|
|
160
|
+
return this.WASI_ERRNO_SUCCESS;
|
|
161
|
+
}
|
|
162
|
+
random_get(pointer, size) {
|
|
163
|
+
const memory = this.getMemory();
|
|
164
|
+
const buffer = new Uint8Array(memory.buffer, pointer, size);
|
|
165
|
+
crypto.randomFillSync(buffer);
|
|
166
|
+
return this.WASI_ERRNO_SUCCESS;
|
|
167
|
+
}
|
|
168
|
+
environ_sizes_get(environCount, environBufSize) {
|
|
169
|
+
var view = this.getDataView();
|
|
170
|
+
view.setUint32(environCount, 0, !0);
|
|
171
|
+
view.setUint32(environBufSize, 0, !0);
|
|
172
|
+
return this.WASI_ERRNO_SUCCESS;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class TinyWASI {
|
|
2
|
+
instance?: WebAssembly.Instance;
|
|
3
|
+
private WASI_ERRNO_SUCCESS;
|
|
4
|
+
private WASI_ERRNO_BADF;
|
|
5
|
+
private WASI_ERRNO_NOSYS;
|
|
6
|
+
private WASI_ERRNO_INVAL;
|
|
7
|
+
private WASI_FILETYPE_CHARACTER_DEVICE;
|
|
8
|
+
private WASI_RIGHTS_FD_SYNC;
|
|
9
|
+
private WASI_RIGHTS_FD_WRITE;
|
|
10
|
+
private WASI_RIGHTS_FD_FILESTAT_GET;
|
|
11
|
+
private WASI_FDFLAGS_APPEND;
|
|
12
|
+
private nameSpaces;
|
|
13
|
+
constructor(trace?: boolean);
|
|
14
|
+
initialize(instance: WebAssembly.Instance): void;
|
|
15
|
+
get imports(): WebAssembly.Imports;
|
|
16
|
+
getMemory(): WebAssembly.Memory;
|
|
17
|
+
getDataView(): DataView;
|
|
18
|
+
private trace;
|
|
19
|
+
private nosys;
|
|
20
|
+
private clock_res_get;
|
|
21
|
+
private clock_time_get;
|
|
22
|
+
private fd_fdstat_get;
|
|
23
|
+
private fd_write;
|
|
24
|
+
private random_get;
|
|
25
|
+
private environ_sizes_get;
|
|
26
|
+
}
|