@spirobel/monero-wallet-api 0.1.0 → 0.1.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/package.json +3 -3
- package/dist/cli.js +0 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -23
- package/dist/wasi.d.ts +0 -26
- package/dist/wasi.js +0 -174
- package/dist/wasmFile.d.ts +0 -1
- package/dist/wasmFile.js +0 -8
package/package.json
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"publish": "bun run build && npm publish",
|
|
13
|
-
"inline": "bun build scripts/wasmFile.ts --target=browser --outdir dist",
|
|
14
|
-
"sum": "cat dist/wasmFile.js | sha256sum > checksum.txt",
|
|
13
|
+
"inline": "bun build scripts/wasmFile.ts --target=browser --outdir dist/wasm-processing",
|
|
14
|
+
"sum": "cat dist/wasm-processing/wasmFile.js | sha256sum > checksum.txt",
|
|
15
15
|
"inlinesum": "bun run inline && bun run sum",
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"clean": "rm -rf ./dist"
|
|
18
18
|
},
|
|
19
19
|
"files": ["dist"],
|
|
20
|
-
"version": "0.1.
|
|
20
|
+
"version": "0.1.1",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "latest"
|
|
23
23
|
},
|
package/dist/cli.js
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function init(): Promise<void>;
|
package/dist/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import { TinyWASI } from "./wasi";
|
|
3
|
-
const source = fs.readFileSync("../rust/target/wasm32-wasip1/release/monero_wallet_api.wasm");
|
|
4
|
-
const typedArray = new Uint8Array(source);
|
|
5
|
-
let ffiRegister = (ptr, len) => { };
|
|
6
|
-
export async function init() {
|
|
7
|
-
const tinywasi = new TinyWASI();
|
|
8
|
-
const imports = {
|
|
9
|
-
env: {
|
|
10
|
-
input: (ptr, len) => {
|
|
11
|
-
console.log("input", ptr, len);
|
|
12
|
-
ffiRegister(ptr, len);
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
...tinywasi.imports,
|
|
16
|
-
};
|
|
17
|
-
const { module, instance } = await WebAssembly.instantiate(typedArray, imports);
|
|
18
|
-
tinywasi.initialize(instance);
|
|
19
|
-
console.log(instance.exports);
|
|
20
|
-
//@ts-ignore
|
|
21
|
-
instance.exports.init_viewpair(1, 3);
|
|
22
|
-
}
|
|
23
|
-
init();
|
package/dist/wasi.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/wasmFile.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const monero_wallet_api_wasm: Uint8Array;
|