smoldot 1.0.2 → 1.0.4
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/cjs/client.d.ts +1 -1
- package/dist/cjs/client.js +15 -18
- package/dist/cjs/index-browser.js +17 -5
- package/dist/cjs/index-deno.js +38 -28
- package/dist/cjs/index-nodejs.js +7 -4
- package/dist/cjs/instance/autogen/wasm0.js +1 -1
- package/dist/cjs/instance/autogen/wasm1.js +1 -1
- package/dist/cjs/instance/autogen/wasm2.js +1 -1
- package/dist/cjs/instance/bindings-smoldot-light.d.ts +7 -6
- package/dist/cjs/instance/bindings-smoldot-light.js +6 -7
- package/dist/cjs/instance/bindings-wasi.d.ts +4 -0
- package/dist/cjs/instance/bindings-wasi.js +30 -0
- package/dist/cjs/instance/bindings.d.ts +3 -3
- package/dist/cjs/instance/buffer.d.ts +1 -0
- package/dist/cjs/instance/buffer.js +13 -1
- package/dist/cjs/instance/instance.d.ts +1 -1
- package/dist/cjs/instance/instance.js +41 -59
- package/dist/cjs/instance/raw-instance.d.ts +2 -11
- package/dist/cjs/instance/raw-instance.js +65 -9
- package/dist/mjs/client.d.ts +1 -1
- package/dist/mjs/client.js +15 -18
- package/dist/mjs/index-browser.js +17 -5
- package/dist/mjs/index-deno.js +38 -28
- package/dist/mjs/index-nodejs.js +7 -4
- package/dist/mjs/instance/autogen/wasm0.js +1 -1
- package/dist/mjs/instance/autogen/wasm1.js +1 -1
- package/dist/mjs/instance/autogen/wasm2.js +1 -1
- package/dist/mjs/instance/bindings-smoldot-light.d.ts +7 -6
- package/dist/mjs/instance/bindings-smoldot-light.js +6 -7
- package/dist/mjs/instance/bindings-wasi.d.ts +4 -0
- package/dist/mjs/instance/bindings-wasi.js +30 -0
- package/dist/mjs/instance/bindings.d.ts +3 -3
- package/dist/mjs/instance/buffer.d.ts +1 -0
- package/dist/mjs/instance/buffer.js +11 -0
- package/dist/mjs/instance/instance.d.ts +1 -1
- package/dist/mjs/instance/instance.js +41 -59
- package/dist/mjs/instance/raw-instance.d.ts +2 -11
- package/dist/mjs/instance/raw-instance.js +65 -9
- package/package.json +2 -2
package/dist/mjs/index-deno.js
CHANGED
|
@@ -22,6 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
23
|
import { start as innerStart } from './client.js';
|
|
24
24
|
import { ConnectionError } from './instance/instance.js';
|
|
25
|
+
import { default as wasmBase64 } from './instance/autogen/wasm.js';
|
|
25
26
|
export { AddChainError, AlreadyDestroyedError, CrashError, MalformedJsonRpcError, QueueFullError, JsonRpcDisabledError } from './client.js';
|
|
26
27
|
/**
|
|
27
28
|
* Initializes a new client. This is a pre-requisite to connecting to a blockchain.
|
|
@@ -32,33 +33,12 @@ export { AddChainError, AlreadyDestroyedError, CrashError, MalformedJsonRpcError
|
|
|
32
33
|
*/
|
|
33
34
|
export function start(options) {
|
|
34
35
|
options = options || {};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const writer = ds.writable.getWriter();
|
|
42
|
-
writer.write(buffer);
|
|
43
|
-
writer.close();
|
|
44
|
-
const output = [];
|
|
45
|
-
const reader = ds.readable.getReader();
|
|
46
|
-
let totalSize = 0;
|
|
47
|
-
while (true) {
|
|
48
|
-
const { value, done } = yield reader.read();
|
|
49
|
-
if (done)
|
|
50
|
-
break;
|
|
51
|
-
output.push(value);
|
|
52
|
-
totalSize += value.byteLength;
|
|
53
|
-
}
|
|
54
|
-
const concatenated = new Uint8Array(totalSize);
|
|
55
|
-
let offset = 0;
|
|
56
|
-
for (const array of output) {
|
|
57
|
-
concatenated.set(array, offset);
|
|
58
|
-
offset += array.byteLength;
|
|
59
|
-
}
|
|
60
|
-
return concatenated;
|
|
61
|
-
}),
|
|
36
|
+
// The actual Wasm bytecode is base64-decoded then deflate-decoded from a constant found in a
|
|
37
|
+
// different file.
|
|
38
|
+
// This is suboptimal compared to using `instantiateStreaming`, but it is the most
|
|
39
|
+
// cross-platform cross-bundler approach.
|
|
40
|
+
const wasmModule = zlibInflate(trustedBase64Decode(wasmBase64)).then(((bytecode) => WebAssembly.compile(bytecode)));
|
|
41
|
+
return innerStart(options || {}, wasmModule, {
|
|
62
42
|
registerShouldPeriodicallyYield: (_callback) => {
|
|
63
43
|
return [true, () => { }];
|
|
64
44
|
},
|
|
@@ -76,6 +56,36 @@ export function start(options) {
|
|
|
76
56
|
}
|
|
77
57
|
});
|
|
78
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Applies the zlib inflate algorithm on the buffer.
|
|
61
|
+
*/
|
|
62
|
+
function zlibInflate(buffer) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
// This code has been copy-pasted from the official streams draft specification.
|
|
65
|
+
// At the moment, it is found here: https://wicg.github.io/compression/#example-deflate-compress
|
|
66
|
+
const ds = new DecompressionStream('deflate');
|
|
67
|
+
const writer = ds.writable.getWriter();
|
|
68
|
+
writer.write(buffer);
|
|
69
|
+
writer.close();
|
|
70
|
+
const output = [];
|
|
71
|
+
const reader = ds.readable.getReader();
|
|
72
|
+
let totalSize = 0;
|
|
73
|
+
while (true) {
|
|
74
|
+
const { value, done } = yield reader.read();
|
|
75
|
+
if (done)
|
|
76
|
+
break;
|
|
77
|
+
output.push(value);
|
|
78
|
+
totalSize += value.byteLength;
|
|
79
|
+
}
|
|
80
|
+
const concatenated = new Uint8Array(totalSize);
|
|
81
|
+
let offset = 0;
|
|
82
|
+
for (const array of output) {
|
|
83
|
+
concatenated.set(array, offset);
|
|
84
|
+
offset += array.byteLength;
|
|
85
|
+
}
|
|
86
|
+
return concatenated;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
79
89
|
/**
|
|
80
90
|
* Decodes a base64 string.
|
|
81
91
|
*
|
|
@@ -227,7 +237,7 @@ function connect(config, forbidTcp, forbidWs, forbidNonLocalWs, forbidWss) {
|
|
|
227
237
|
config.onMessage(readBuffer.slice(0, outcome));
|
|
228
238
|
return read(readBuffer);
|
|
229
239
|
});
|
|
230
|
-
read(new Uint8Array(
|
|
240
|
+
read(new Uint8Array(32768));
|
|
231
241
|
return established;
|
|
232
242
|
});
|
|
233
243
|
return {
|
package/dist/mjs/index-nodejs.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// with both at the same time.
|
|
17
17
|
import { start as innerStart } from './client.js';
|
|
18
18
|
import { ConnectionError } from './instance/instance.js';
|
|
19
|
+
import { default as wasmBase64 } from './instance/autogen/wasm.js';
|
|
19
20
|
import { WebSocket } from 'ws';
|
|
20
21
|
import { inflate } from 'pako';
|
|
21
22
|
import { performance } from 'node:perf_hooks';
|
|
@@ -31,10 +32,12 @@ export { AddChainError, AlreadyDestroyedError, CrashError, MalformedJsonRpcError
|
|
|
31
32
|
*/
|
|
32
33
|
export function start(options) {
|
|
33
34
|
options = options || {};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// The actual Wasm bytecode is base64-decoded then deflate-decoded from a constant found in a
|
|
36
|
+
// different file.
|
|
37
|
+
// This is suboptimal compared to using `instantiateStreaming`, but it is the most
|
|
38
|
+
// cross-platform cross-bundler approach.
|
|
39
|
+
const wasmModule = WebAssembly.compile(inflate(Buffer.from(wasmBase64, 'base64')));
|
|
40
|
+
return innerStart(options || {}, wasmModule, {
|
|
38
41
|
registerShouldPeriodicallyYield: (_callback) => {
|
|
39
42
|
return [true, () => { }];
|
|
40
43
|
},
|