@aztec/foundation 0.16.3 → 0.16.5
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/dest/abi/function_selector.js +2 -2
- package/dest/aztec-address/index.js +2 -2
- package/dest/json-rpc/server/index.d.ts +1 -1
- package/dest/json-rpc/server/index.d.ts.map +1 -1
- package/dest/json-rpc/server/index.js +2 -2
- package/dest/json-rpc/server/json_rpc_server.d.ts +7 -0
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/json_rpc_server.js +13 -1
- package/package.json +2 -2
- package/src/abi/abi.ts +0 -310
- package/src/abi/abi_coder.ts +0 -25
- package/src/abi/decoder.ts +0 -161
- package/src/abi/encoder.ts +0 -120
- package/src/abi/function_selector.ts +0 -135
- package/src/abi/index.ts +0 -6
- package/src/abi/utils.ts +0 -28
- package/src/async-map/index.ts +0 -18
- package/src/aztec-address/index.ts +0 -30
- package/src/bigint-buffer/index.ts +0 -74
- package/src/collection/array.ts +0 -54
- package/src/collection/index.ts +0 -1
- package/src/committable/committable.ts +0 -46
- package/src/committable/index.ts +0 -1
- package/src/crypto/index.ts +0 -16
- package/src/crypto/keccak/index.ts +0 -33
- package/src/crypto/pedersen/index.ts +0 -1
- package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
- package/src/crypto/pedersen/pedersen.noble.ts +0 -573
- package/src/crypto/pedersen/pedersen.wasm.ts +0 -42
- package/src/crypto/random/index.ts +0 -42
- package/src/crypto/sha256/index.ts +0 -3
- package/src/errors/index.ts +0 -6
- package/src/eth-address/index.ts +0 -244
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/fields.ts +0 -261
- package/src/fields/index.ts +0 -3
- package/src/fields/point.ts +0 -140
- package/src/fifo/bounded_serial_queue.ts +0 -100
- package/src/fifo/index.ts +0 -4
- package/src/fifo/memory_fifo.ts +0 -114
- package/src/fifo/semaphore.ts +0 -33
- package/src/fifo/serial_queue.ts +0 -78
- package/src/index.ts +0 -29
- package/src/json-rpc/README.md +0 -55
- package/src/json-rpc/class_converter.ts +0 -209
- package/src/json-rpc/client/index.ts +0 -1
- package/src/json-rpc/client/json_rpc_client.ts +0 -136
- package/src/json-rpc/convert.ts +0 -163
- package/src/json-rpc/fixtures/class_a.ts +0 -15
- package/src/json-rpc/fixtures/class_b.ts +0 -15
- package/src/json-rpc/fixtures/test_state.ts +0 -59
- package/src/json-rpc/index.ts +0 -8
- package/src/json-rpc/js_utils.ts +0 -20
- package/src/json-rpc/server/index.ts +0 -2
- package/src/json-rpc/server/json_proxy.ts +0 -43
- package/src/json-rpc/server/json_rpc_server.ts +0 -190
- package/src/log/console.ts +0 -39
- package/src/log/debug.ts +0 -83
- package/src/log/index.ts +0 -5
- package/src/log/log_fn.ts +0 -5
- package/src/log/log_history.ts +0 -44
- package/src/log/logger.ts +0 -137
- package/src/mutex/index.ts +0 -83
- package/src/mutex/mutex_database.ts +0 -12
- package/src/noir/index.ts +0 -1
- package/src/noir/noir_package_config.ts +0 -54
- package/src/retry/index.ts +0 -99
- package/src/running-promise/index.ts +0 -60
- package/src/serialize/buffer_reader.ts +0 -250
- package/src/serialize/free_funcs.ts +0 -279
- package/src/serialize/index.ts +0 -3
- package/src/serialize/types.ts +0 -40
- package/src/sleep/index.ts +0 -71
- package/src/testing/index.ts +0 -1
- package/src/testing/test_data.ts +0 -36
- package/src/timer/elapsed.ts +0 -23
- package/src/timer/index.ts +0 -3
- package/src/timer/timeout.ts +0 -64
- package/src/timer/timer.ts +0 -48
- package/src/transport/browser/index.ts +0 -4
- package/src/transport/browser/message_port_socket.ts +0 -48
- package/src/transport/browser/shared_worker_connector.ts +0 -21
- package/src/transport/browser/shared_worker_listener.ts +0 -53
- package/src/transport/browser/worker_connector.ts +0 -30
- package/src/transport/browser/worker_listener.ts +0 -54
- package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
- package/src/transport/dispatch/create_dispatch_proxy.ts +0 -141
- package/src/transport/dispatch/messages.ts +0 -58
- package/src/transport/index.ts +0 -11
- package/src/transport/interface/connector.ts +0 -9
- package/src/transport/interface/listener.ts +0 -16
- package/src/transport/interface/socket.ts +0 -15
- package/src/transport/interface/transferable.ts +0 -125
- package/src/transport/node/index.ts +0 -2
- package/src/transport/node/node_connector.ts +0 -30
- package/src/transport/node/node_connector_socket.ts +0 -52
- package/src/transport/node/node_listener.ts +0 -34
- package/src/transport/node/node_listener_socket.ts +0 -48
- package/src/transport/transport_client.ts +0 -131
- package/src/transport/transport_server.ts +0 -108
- package/src/trees/index.ts +0 -48
- package/src/types/index.ts +0 -7
- package/src/url/index.ts +0 -73
- package/src/wasm/README.md +0 -6
- package/src/wasm/empty_wasi_sdk.ts +0 -166
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +0 -27
- package/src/wasm/index.ts +0 -1
- package/src/wasm/wasm_module.ts +0 -260
- package/src/worker/browser/index.ts +0 -2
- package/src/worker/browser/start_web_module.ts +0 -23
- package/src/worker/browser/web_data_store.ts +0 -38
- package/src/worker/browser/web_worker.ts +0 -24
- package/src/worker/data_store.ts +0 -19
- package/src/worker/index.ts +0 -2
- package/src/worker/node/index.ts +0 -2
- package/src/worker/node/node_data_store.ts +0 -27
- package/src/worker/node/node_worker.ts +0 -22
- package/src/worker/node/start_node_module.ts +0 -29
- package/src/worker/wasm_worker.ts +0 -7
- package/src/worker/worker_pool.ts +0 -73
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
2
|
-
import { format } from 'util';
|
|
3
|
-
|
|
4
|
-
import { createDebugLogger } from '../log/index.js';
|
|
5
|
-
import { EventMessage, ResponseMessage, isEventMessage } from './dispatch/messages.js';
|
|
6
|
-
import { Connector } from './interface/connector.js';
|
|
7
|
-
import { Socket } from './interface/socket.js';
|
|
8
|
-
|
|
9
|
-
const debug = createDebugLogger('aztec:transport_client');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Represents a pending request in the TransportClient.
|
|
13
|
-
* Contains information about the message ID, and resolve/reject functions for handling responses.
|
|
14
|
-
* Used to track and manage asynchronous request/response communication with the TransportServer.
|
|
15
|
-
*/
|
|
16
|
-
interface PendingRequest {
|
|
17
|
-
/**
|
|
18
|
-
* The unique message identifier used for tracking and matching request/response pairs.
|
|
19
|
-
*/
|
|
20
|
-
msgId: number;
|
|
21
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
22
|
-
resolve(data: any): void;
|
|
23
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
24
|
-
reject(error: Error): void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Represents a transport client for communication between TransportServer and clients.
|
|
29
|
-
* Provides request/response functionality, event handling, and multiplexing support
|
|
30
|
-
* for efficient and concurrent communication with a corresponding TransportServer.
|
|
31
|
-
*/
|
|
32
|
-
export interface ITransportClient<Payload> extends EventEmitter {
|
|
33
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
34
|
-
on(name: 'event_msg', handler: (payload: Payload) => void): this;
|
|
35
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
36
|
-
emit(name: 'event_msg', payload: Payload): boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A TransportClient provides a request/response and event api to a corresponding TransportServer.
|
|
41
|
-
* If `broadcast` is called on TransportServer, TransportClients will emit an `event_msg`.
|
|
42
|
-
* The `request` method will block until a response is returned from the TransportServer's dispatch function.
|
|
43
|
-
* Request multiplexing is supported.
|
|
44
|
-
*/
|
|
45
|
-
export class TransportClient<Payload> extends EventEmitter {
|
|
46
|
-
private msgId = 0;
|
|
47
|
-
private pendingRequests: PendingRequest[] = [];
|
|
48
|
-
private socket?: Socket;
|
|
49
|
-
|
|
50
|
-
constructor(private transportConnect: Connector) {
|
|
51
|
-
super();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Initializes and opens the socket connection for the TransportClient.
|
|
56
|
-
* This method creates a new Socket instance using the provided Connector,
|
|
57
|
-
* registers a handler for incoming messages, and establishes the connection.
|
|
58
|
-
* It should be called before making any requests or handling events.
|
|
59
|
-
*
|
|
60
|
-
* @throws An error if the socket is already open or there's an issue opening the connection.
|
|
61
|
-
* @returns A Promise that resolves when the socket connection is successfully opened.
|
|
62
|
-
*/
|
|
63
|
-
async open() {
|
|
64
|
-
this.socket = await this.transportConnect.createSocket();
|
|
65
|
-
this.socket.registerHandler(msg => this.handleSocketMessage(msg));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Close the transport client's socket connection and remove all event listeners.
|
|
70
|
-
* This method should be called when the client is no longer needed to ensure proper cleanup
|
|
71
|
-
* and prevent potential memory leaks. Once closed, the client cannot be reused and a new
|
|
72
|
-
* instance must be created if another connection is needed.
|
|
73
|
-
*/
|
|
74
|
-
close() {
|
|
75
|
-
this.socket?.close();
|
|
76
|
-
this.socket = undefined;
|
|
77
|
-
this.removeAllListeners();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Sends a request to the TransportServer with the given payload and transferable objects.
|
|
82
|
-
* The method will block until a response from the TransportServer's dispatch function is returned.
|
|
83
|
-
* Request multiplexing is supported, allowing multiple requests to be sent concurrently.
|
|
84
|
-
*
|
|
85
|
-
* @param payload - The message payload to send to the server.
|
|
86
|
-
* @param transfer - An optional array of ArrayBuffer, MessagePort, or ImageBitmap objects to transfer ownership.
|
|
87
|
-
* @returns A Promise that resolves with the server's response data or rejects with an error message.
|
|
88
|
-
*/
|
|
89
|
-
request(payload: Payload, transfer?: Transferable[]) {
|
|
90
|
-
if (!this.socket) {
|
|
91
|
-
throw new Error('Socket not open.');
|
|
92
|
-
}
|
|
93
|
-
const msgId = this.msgId++;
|
|
94
|
-
const msg = { msgId, payload };
|
|
95
|
-
debug(format(`->`, msg));
|
|
96
|
-
return new Promise<any>((resolve, reject) => {
|
|
97
|
-
this.pendingRequests.push({ resolve, reject, msgId });
|
|
98
|
-
this.socket!.send(msg, transfer).catch(reject);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Handles incoming socket messages from the TransportServer, such as ResponseMessage and EventMessage.
|
|
104
|
-
* If it's an EventMessage, emits an 'event_msg' event with the payload.
|
|
105
|
-
* If it's a ResponseMessage, resolves or rejects the corresponding pending request based on the message content.
|
|
106
|
-
*
|
|
107
|
-
* @param msg - The ResponseMessage or EventMessage received from the TransportServer, or undefined if the remote socket closed.
|
|
108
|
-
*/
|
|
109
|
-
private handleSocketMessage(msg: ResponseMessage<Payload> | EventMessage<Payload> | undefined) {
|
|
110
|
-
if (msg === undefined) {
|
|
111
|
-
// The remote socket closed.
|
|
112
|
-
this.close();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
debug(format(`<-`, msg));
|
|
116
|
-
if (isEventMessage(msg)) {
|
|
117
|
-
this.emit('event_msg', msg.payload);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const reqIndex = this.pendingRequests.findIndex(r => r.msgId === msg.msgId);
|
|
121
|
-
if (reqIndex === -1) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const [pending] = this.pendingRequests.splice(reqIndex, 1);
|
|
125
|
-
if (msg.error) {
|
|
126
|
-
pending.reject(new Error(msg.error));
|
|
127
|
-
} else {
|
|
128
|
-
pending.resolve(msg.payload);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { RequestMessage, ResponseMessage } from './dispatch/messages.js';
|
|
2
|
-
import { Listener } from './interface/listener.js';
|
|
3
|
-
import { Socket } from './interface/socket.js';
|
|
4
|
-
import { isTransferDescriptor } from './interface/transferable.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Keeps track of clients, providing a broadcast, and request/response api with multiplexing.
|
|
8
|
-
*/
|
|
9
|
-
export class TransportServer<Payload> {
|
|
10
|
-
private sockets: Socket[] = [];
|
|
11
|
-
|
|
12
|
-
constructor(private listener: Listener, private msgHandlerFn: (msg: Payload) => Promise<any>) {}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Starts the TransportServer, allowing it to accept new connections and handle incoming messages.
|
|
16
|
-
* The server will listen for 'new_socket' events from the underlying listener and invoke the provided message handler function
|
|
17
|
-
* for each received message. The server remains active until the 'stop' method is called.
|
|
18
|
-
*/
|
|
19
|
-
start() {
|
|
20
|
-
this.listener.on('new_socket', client => this.handleNewSocket(client));
|
|
21
|
-
this.listener.open();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Stops accepting new connections. It doesn't close existing sockets.
|
|
26
|
-
* It's expected the clients will gracefully complete by closing their end, sending an `undefined` message.
|
|
27
|
-
*/
|
|
28
|
-
stop() {
|
|
29
|
-
this.listener.close();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Sends a broadcast message to all connected clients.
|
|
34
|
-
* The given payload will be sent to all the clients currently connected to the TransportServer.
|
|
35
|
-
* It waits for all the messages to be sent and resolves when they are all sent successfully.
|
|
36
|
-
*
|
|
37
|
-
* @param msg - The payload to broadcast to all connected clients.
|
|
38
|
-
* @returns A Promise that resolves when all messages have been sent successfully.
|
|
39
|
-
*/
|
|
40
|
-
async broadcast(msg: Payload) {
|
|
41
|
-
await Promise.all(this.sockets.map(s => s.send({ payload: msg })));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Handles the addition of a new socket to the server by registering a message handler for the client
|
|
46
|
-
* and adding the socket to the list of active sockets. The message handler processes incoming messages
|
|
47
|
-
* from the client, including detecting client disconnection and removing the closed socket.
|
|
48
|
-
*
|
|
49
|
-
* @param socket - The new Socket instance that has connected to the server.
|
|
50
|
-
*/
|
|
51
|
-
private handleNewSocket(socket: Socket) {
|
|
52
|
-
socket.registerHandler(async msg => {
|
|
53
|
-
if (msg === undefined) {
|
|
54
|
-
// Client socket has closed. Remove it from the list of sockets. Call close on it for any cleanup.
|
|
55
|
-
const socketIndex = this.sockets.findIndex(s => s === socket);
|
|
56
|
-
const [closingSocket] = this.sockets.splice(socketIndex, 1);
|
|
57
|
-
closingSocket.close();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
return await this.handleSocketMessage(socket, msg);
|
|
61
|
-
});
|
|
62
|
-
this.sockets.push(socket);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Detect the 'transferables' argument to our socket from our message
|
|
67
|
-
* handler return type.
|
|
68
|
-
* @param data - The compound payload data.
|
|
69
|
-
* @returns The split data and transferables.
|
|
70
|
-
*/
|
|
71
|
-
private getPayloadAndTransfers(data: any): [any, Transferable[]] {
|
|
72
|
-
if (isTransferDescriptor(data)) {
|
|
73
|
-
// We treat PayloadWithTransfers specially so that we're able to
|
|
74
|
-
// attach transferables while keeping a simple return-type based usage
|
|
75
|
-
return [data.send, data.transferables];
|
|
76
|
-
}
|
|
77
|
-
if (data instanceof Uint8Array) {
|
|
78
|
-
// We may want to devise a better solution to this. We maybe given a view over a non cloneable/transferrable
|
|
79
|
-
// ArrayBuffer (such as a view over wasm memory). In this case we want to take a copy, and then transfer it.
|
|
80
|
-
const respPayload = data instanceof Uint8Array && ArrayBuffer.isView(data) ? new Uint8Array(data) : data;
|
|
81
|
-
const transferables = data instanceof Uint8Array ? [respPayload.buffer] : [];
|
|
82
|
-
return [respPayload, transferables];
|
|
83
|
-
}
|
|
84
|
-
return [data, []];
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Handles incoming socket messages, processing the request and sending back a response.
|
|
88
|
-
* This function is responsible for invoking the registered message handler function with the received
|
|
89
|
-
* payload, extracting the result and transferables, and sending a response message back to the client.
|
|
90
|
-
* In case of an error during message handling, it sends an error response with the stack trace.
|
|
91
|
-
*
|
|
92
|
-
* @param socket - The Socket instance from which the message was received.
|
|
93
|
-
* @param msg - The RequestMessage object containing the message ID and payload.
|
|
94
|
-
*/
|
|
95
|
-
private async handleSocketMessage(socket: Socket, { msgId, payload }: RequestMessage<Payload>) {
|
|
96
|
-
try {
|
|
97
|
-
const data = await this.msgHandlerFn(payload);
|
|
98
|
-
|
|
99
|
-
const [respPayload, transferables] = this.getPayloadAndTransfers(data);
|
|
100
|
-
const rep: ResponseMessage<Payload> = { msgId, payload: respPayload };
|
|
101
|
-
|
|
102
|
-
await socket.send(rep, transferables);
|
|
103
|
-
} catch (err: any) {
|
|
104
|
-
const rep: ResponseMessage<Payload> = { msgId, error: err.stack };
|
|
105
|
-
await socket.send(rep);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
package/src/trees/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A leaf of an indexed merkle tree.
|
|
3
|
-
*/
|
|
4
|
-
export interface IndexedTreeLeaf {
|
|
5
|
-
/**
|
|
6
|
-
* Returns key of the leaf. It's used for indexing.
|
|
7
|
-
*/
|
|
8
|
-
getKey(): bigint;
|
|
9
|
-
/**
|
|
10
|
-
* Serializes the leaf into a buffer.
|
|
11
|
-
*/
|
|
12
|
-
toBuffer(): Buffer;
|
|
13
|
-
/**
|
|
14
|
-
* Returns true if the leaf is empty.
|
|
15
|
-
*/
|
|
16
|
-
isEmpty(): boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Preimage of an indexed merkle tree leaf.
|
|
21
|
-
*/
|
|
22
|
-
export interface IndexedTreeLeafPreimage {
|
|
23
|
-
/**
|
|
24
|
-
* Returns key of the leaf corresponding to this preimage.
|
|
25
|
-
*/
|
|
26
|
-
getKey(): bigint;
|
|
27
|
-
/**
|
|
28
|
-
* Returns the key of the next leaf.
|
|
29
|
-
*/
|
|
30
|
-
getNextKey(): bigint;
|
|
31
|
-
/**
|
|
32
|
-
* Returns the index of the next leaf.
|
|
33
|
-
*/
|
|
34
|
-
getNextIndex(): bigint;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Returns the preimage as a leaf.
|
|
38
|
-
*/
|
|
39
|
-
asLeaf(): IndexedTreeLeaf;
|
|
40
|
-
/**
|
|
41
|
-
* Serializes the preimage into a buffer.
|
|
42
|
-
*/
|
|
43
|
-
toBuffer(): Buffer;
|
|
44
|
-
/**
|
|
45
|
-
* Serializes the preimage to an array of buffers for hashing.
|
|
46
|
-
*/
|
|
47
|
-
toHashInputs(): Buffer[];
|
|
48
|
-
}
|
package/src/types/index.ts
DELETED
package/src/url/index.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
// a copy of this software and associated documentation files (the
|
|
5
|
-
// 'Software'), to deal in the Software without restriction, including
|
|
6
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
// permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
// the following conditions:
|
|
10
|
-
// The above copyright notice and this permission notice shall be
|
|
11
|
-
// included in all copies or substantial portions of the Software.
|
|
12
|
-
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
13
|
-
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
14
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
15
|
-
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
16
|
-
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
17
|
-
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
18
|
-
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
|
-
import { sep } from 'path';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* File URI to Path function.
|
|
23
|
-
*
|
|
24
|
-
* @param {String} uri
|
|
25
|
-
* @return {String} path
|
|
26
|
-
* @api public
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
export function fileURLToPath(uri: string): string {
|
|
30
|
-
if (typeof uri !== 'string' || uri.length <= 7 || uri.substring(0, 7) !== 'file://') {
|
|
31
|
-
throw new TypeError('must pass in a file:// URI to convert to a file path');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const rest = decodeURI(uri.substring(7));
|
|
35
|
-
const firstSlash = rest.indexOf('/');
|
|
36
|
-
let host = rest.substring(0, firstSlash);
|
|
37
|
-
let path = rest.substring(firstSlash + 1);
|
|
38
|
-
|
|
39
|
-
// 2. Scheme Definition
|
|
40
|
-
// As a special case, <host> can be the string "localhost" or the empty
|
|
41
|
-
// string; this is interpreted as "the machine from which the URL is
|
|
42
|
-
// being interpreted".
|
|
43
|
-
if (host === 'localhost') {
|
|
44
|
-
host = '';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (host) {
|
|
48
|
-
host = sep + sep + host;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 3.2 Drives, drive letters, mount points, file system root
|
|
52
|
-
// Drive letters are mapped into the top of a file URI in various ways,
|
|
53
|
-
// depending on the implementation; some applications substitute
|
|
54
|
-
// vertical bar ("|") for the colon after the drive letter, yielding
|
|
55
|
-
// "file:///c|/tmp/test.txt". In some cases, the colon is left
|
|
56
|
-
// unchanged, as in "file:///c:/tmp/test.txt". In other cases, the
|
|
57
|
-
// colon is simply omitted, as in "file:///c/tmp/test.txt".
|
|
58
|
-
path = path.replace(/^(.+)\|/, '$1:');
|
|
59
|
-
|
|
60
|
-
// for Windows, we need to invert the path separators from what a URI uses
|
|
61
|
-
if (sep === '\\') {
|
|
62
|
-
path = path.replace(/\//g, '\\');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (/^.+:/.test(path)) {
|
|
66
|
-
// has Windows drive at beginning of path
|
|
67
|
-
} else {
|
|
68
|
-
// unix path…
|
|
69
|
-
path = sep + path;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return host + path;
|
|
73
|
-
}
|
package/src/wasm/README.md
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createDebugOnlyLogger } from '../log/index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Dummy implementation of a necessary part of the wasi api:
|
|
5
|
-
* https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
6
|
-
* We don't use these functions, but the environment expects them.
|
|
7
|
-
* TODO find a way to update off of wasi 12.
|
|
8
|
-
*/
|
|
9
|
-
/* eslint-disable camelcase */
|
|
10
|
-
export const getEmptyWasiSdk = (debug = createDebugOnlyLogger('wasm:empty_wasi_sdk')) => ({
|
|
11
|
-
/**
|
|
12
|
-
* Retrieves the current time from the system clock.
|
|
13
|
-
* This function is a dummy implementation of the WASI API's `clock_time_get` method,
|
|
14
|
-
* which is expected by the environment but not used in this context.
|
|
15
|
-
*
|
|
16
|
-
* No input parameters or return values are required, as the purpose of this function
|
|
17
|
-
* is solely to satisfy the environment expectations and provide debugging information.
|
|
18
|
-
*/
|
|
19
|
-
clock_time_get() {
|
|
20
|
-
debug('clock_time_get');
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* Dummy implementation of WASI's environ_get function.
|
|
24
|
-
* This function is used to obtain a snapshot of the current environment variables.
|
|
25
|
-
* In this dummy implementation, no actual actions are performed, but the debug logger logs 'environ_get' when called.
|
|
26
|
-
* Environment variables are not used in this context, so the real implementation is not required.
|
|
27
|
-
*
|
|
28
|
-
* @see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#environ_get
|
|
29
|
-
*/
|
|
30
|
-
environ_get() {
|
|
31
|
-
debug('environ_get');
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* Retrieves the environment variable sizes from the WebAssembly environment.
|
|
35
|
-
* This function is part of the WASI API and provides a dummy implementation to fulfill the expected APIs.
|
|
36
|
-
* It does not have any actual functionality, but serves as a placeholder in the environment.
|
|
37
|
-
*/
|
|
38
|
-
environ_sizes_get() {
|
|
39
|
-
debug('environ_sizes_get');
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Closes a file descriptor, releasing any resources associated with it.
|
|
43
|
-
* This function does not perform any actual closing operation, but exists to
|
|
44
|
-
* satisfy the requirements of the WebAssembly System Interface (WASI) API,
|
|
45
|
-
* which expects certain functions to be present for compatibility purposes.
|
|
46
|
-
*
|
|
47
|
-
* @see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
48
|
-
*/
|
|
49
|
-
fd_close() {
|
|
50
|
-
debug('fd_close');
|
|
51
|
-
},
|
|
52
|
-
/**
|
|
53
|
-
* A dummy implementation of the 'fd_read' function from the WASI API.
|
|
54
|
-
* This function is required by the environment, but not used in this context.
|
|
55
|
-
* It would normally read data from a file descriptor into an array buffer,
|
|
56
|
-
* but here it simply logs the invocation for debugging purposes.
|
|
57
|
-
*/
|
|
58
|
-
fd_read() {
|
|
59
|
-
debug('fd_read');
|
|
60
|
-
},
|
|
61
|
-
/**
|
|
62
|
-
* Handles the file descriptor write operation.
|
|
63
|
-
* This dummy implementation of the WASI 'fd_write' function is part of the wasi API:
|
|
64
|
-
* https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
65
|
-
* The environment expects this function, but it is not used in the current implementation.
|
|
66
|
-
* It is used to write data from WebAssembly memory to a file descriptor.
|
|
67
|
-
*/
|
|
68
|
-
fd_write() {
|
|
69
|
-
debug('fd_write');
|
|
70
|
-
},
|
|
71
|
-
/**
|
|
72
|
-
* Perform a file seek operation on the given file descriptor to change its current position.
|
|
73
|
-
* The new position is calculated using the provided offset and whence values.
|
|
74
|
-
* Throws an error if the file descriptor is invalid or the operation cannot be performed.
|
|
75
|
-
*
|
|
76
|
-
* @param fd - The file descriptor of the file to perform the seek operation on.
|
|
77
|
-
* @param offset - The relative offset to apply, based on the whence value.
|
|
78
|
-
* @param whence - The reference point from which the offset should be calculated. One of SEEK_SET (start), SEEK_CUR (current), or SEEK_END (end).
|
|
79
|
-
* @returns The new position in the file after the seek operation has been performed.
|
|
80
|
-
*/
|
|
81
|
-
fd_seek() {
|
|
82
|
-
debug('fd_seek');
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* This function is a dummy implementation of the 'fd_fdstat_get' function in the WebAssembly System Interface (WASI) API.
|
|
86
|
-
* Although not actually used in this context, it is present due to the environment's expectation of its existence.
|
|
87
|
-
* The 'fd_fdstat_get' function is typically responsible for obtaining file descriptor status information.
|
|
88
|
-
*/
|
|
89
|
-
fd_fdstat_get() {
|
|
90
|
-
debug('fd_fdstat_get');
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* Sets the file descriptor flags for a given file descriptor.
|
|
94
|
-
* This function is a dummy implementation of the WASI API function 'fd_fdstat_set_flags'.
|
|
95
|
-
* It currently does not perform any operation but logs the function call with a debug instance.
|
|
96
|
-
* This is provided since the environment expects this function to be present.
|
|
97
|
-
*/
|
|
98
|
-
fd_fdstat_set_flags() {
|
|
99
|
-
debug('fd_fdstat_set_flags');
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
* Handles the `fd_prestat_get` function call for the dummy WebAssembly System Interface (WASI) implementation.
|
|
103
|
-
* This function is expected by the WASI environment, although it is not used in this implementation.
|
|
104
|
-
* The `fd_prestat_get` function retrieves pre-opened file descriptor properties.
|
|
105
|
-
*
|
|
106
|
-
* @returns A constant integer value indicating successful completion of the function call.
|
|
107
|
-
*/
|
|
108
|
-
fd_prestat_get() {
|
|
109
|
-
debug('fd_prestat_get');
|
|
110
|
-
return 8;
|
|
111
|
-
},
|
|
112
|
-
/**
|
|
113
|
-
* Provides a dummy implementation for the `fd_prestat_dir_name` function, which is expected to be called by the WASI environment.
|
|
114
|
-
* This function is intended to retrieve the pre-opened directory's path associated with the given file descriptor. However, since it's a dummy implementation,
|
|
115
|
-
* it doesn't perform any actual operation and only logs the function call with the provided debug logger.
|
|
116
|
-
*
|
|
117
|
-
* @returns A constant number representing a dummy return value for the function call.
|
|
118
|
-
*/
|
|
119
|
-
fd_prestat_dir_name() {
|
|
120
|
-
debug('fd_prestat_dir_name');
|
|
121
|
-
return 28;
|
|
122
|
-
},
|
|
123
|
-
/**
|
|
124
|
-
* Handles the opening of a file path within the WASI environment.
|
|
125
|
-
* This function is a dummy implementation required for compatibility with
|
|
126
|
-
* the WebAssembly System Interface (WASI) API, but it does not perform any
|
|
127
|
-
* actual file opening operation. It is mainly used for debugging purposes.
|
|
128
|
-
*/
|
|
129
|
-
path_open() {
|
|
130
|
-
debug('path_open');
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* Retrieve file system information of the specified path.
|
|
134
|
-
* This function retrieves statistics, such as size and permissions, associated with the file or directory
|
|
135
|
-
* identified by the given path. In case of an error or non-existing path, appropriate debug logs will be generated.
|
|
136
|
-
*
|
|
137
|
-
* @returns An object containing file statistics like size, permissions, etc.
|
|
138
|
-
*/
|
|
139
|
-
path_filestat_get() {
|
|
140
|
-
debug('path_filestat_get');
|
|
141
|
-
},
|
|
142
|
-
/**
|
|
143
|
-
* Terminate the process normally, performing the regular cleanup for terminating programs.
|
|
144
|
-
* The input 'status' represents the exit code and is used to indicate success or failure
|
|
145
|
-
* of the program execution. A zero value typically indicates successful execution,
|
|
146
|
-
* while non-zero values are treated as errors by the operating system.
|
|
147
|
-
*
|
|
148
|
-
* @param status - The exit code representing the success or failure of the program execution.
|
|
149
|
-
* @returns The exit status code.
|
|
150
|
-
*/
|
|
151
|
-
proc_exit() {
|
|
152
|
-
debug('proc_exit');
|
|
153
|
-
return 52;
|
|
154
|
-
},
|
|
155
|
-
/**
|
|
156
|
-
* Generates a random number and returns it.
|
|
157
|
-
* This dummy implementation of 'random_get' method in the wasi API is expected by the environment.
|
|
158
|
-
* In this case, the function always returns 1 to maintain consistency with the environment's expectations.
|
|
159
|
-
*
|
|
160
|
-
* @returns A random number. In this implementation, always returns 1.
|
|
161
|
-
*/
|
|
162
|
-
random_get() {
|
|
163
|
-
debug('random_get');
|
|
164
|
-
return 1;
|
|
165
|
-
},
|
|
166
|
-
});
|
|
Binary file
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
(module
|
|
2
|
-
(func $gcd (param i32 i32) (result i32)
|
|
3
|
-
(local i32)
|
|
4
|
-
block ;; label = @1
|
|
5
|
-
block ;; label = @2
|
|
6
|
-
local.get 0
|
|
7
|
-
br_if 0 (;@2;)
|
|
8
|
-
local.get 1
|
|
9
|
-
local.set 2
|
|
10
|
-
br 1 (;@1;)
|
|
11
|
-
end
|
|
12
|
-
loop ;; label = @2
|
|
13
|
-
local.get 1
|
|
14
|
-
local.get 0
|
|
15
|
-
local.tee 2
|
|
16
|
-
i32.rem_u
|
|
17
|
-
local.set 0
|
|
18
|
-
local.get 2
|
|
19
|
-
local.set 1
|
|
20
|
-
local.get 0
|
|
21
|
-
br_if 0 (;@2;)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
local.get 2
|
|
25
|
-
)
|
|
26
|
-
(export "gcd" (func $gcd))
|
|
27
|
-
)
|
package/src/wasm/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { WasmModule, IWasmModule } from './wasm_module.js';
|