Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smoldot

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smoldot - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

26

dist/cjs/client.js

@@ -89,6 +89,6 @@ "use strict";

// Immediately cleared when `remove()` is called on a chain.
let chainIds = new WeakMap();
const chainIds = new WeakMap();
// If `Client.terminate()̀ is called, this error is set to a value.
// All the functions of the public API check if this contains a value.
let alreadyDestroyedError = null;
const alreadyDestroyedError = { value: null };
const instance = (0, instance_js_1.start)({

@@ -107,4 +107,4 @@ // Maximum level of log entries sent by the client.

addChain: (options) => __awaiter(this, void 0, void 0, function* () {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
// Passing a JSON object for the chain spec is an easy mistake, so we provide a more

@@ -134,4 +134,4 @@ // readable error.

sendJsonRpc: (request) => {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
if (wasDestroyed.destroyed)

@@ -148,4 +148,4 @@ throw new AlreadyDestroyedError();

nextJsonRpcResponse: () => {
if (alreadyDestroyedError)
return Promise.reject(alreadyDestroyedError);
if (alreadyDestroyedError.value)
return Promise.reject(alreadyDestroyedError.value);
if (wasDestroyed.destroyed)

@@ -158,4 +158,4 @@ return Promise.reject(new AlreadyDestroyedError());

remove: () => {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
if (wasDestroyed.destroyed)

@@ -173,5 +173,5 @@ throw new AlreadyDestroyedError();

terminate: () => __awaiter(this, void 0, void 0, function* () {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
alreadyDestroyedError = new AlreadyDestroyedError();
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
alreadyDestroyedError.value = new AlreadyDestroyedError();
instance.startShutdown();

@@ -178,0 +178,0 @@ })

@@ -11,6 +11,2 @@ import type { SmoldotWasmInstance } from './bindings.js';

/**
* Returns the number of milliseconds since an arbitrary epoch.
*/
performanceNow: () => number;
/**
* Tries to open a new connection using the given configuration.

@@ -75,3 +71,3 @@ *

*
* The number of bytes most never exceed the number of "writable bytes" of the stream.
* The number of bytes must never exceed the number of "writable bytes" of the stream.
* `onWritableBytes` can be used in order to notify that more writable bytes are available.

@@ -165,3 +161,4 @@ *

/**
* Callback called when more data can be written on the stream.
* Callback called when some data sent using {@link Connection.send} has effectively been
* written on the stream, meaning that some buffer space is now free.
*

@@ -174,2 +171,5 @@ * Can only happen while the connection is in the `Open` state.

* "multi-stream".
*
* Only a number of bytes equal to the size of the data provided to {@link Connection.send}
* must be reported. In other words, the `initialWritableBytes` must never be exceeded.
*/

@@ -176,0 +176,0 @@ onWritableBytes: (numExtra: number, streamId?: number) => void;

@@ -92,6 +92,2 @@ "use strict";

},
// Must return the UNIX time in milliseconds.
unix_time_ms: () => Date.now(),
// Must return the value of a monotonic clock in milliseconds.
monotonic_clock_ms: () => config.performanceNow(),
// Must call `timer_finished` after the given number of milliseconds has elapsed.

@@ -98,0 +94,0 @@ start_timer: (id, ms) => {

@@ -9,2 +9,6 @@ import type { SmoldotWasmInstance } from './bindings.js';

/**
* Returns the number of milliseconds since an arbitrary epoch.
*/
performanceNow: () => number;
/**
* List of environment variables to feed to the Rust program. An array of strings.

@@ -11,0 +15,0 @@ * Example: `["RUST_BACKTRACE=1", "RUST_LOG=foo"];`

@@ -44,2 +44,32 @@ "use strict";

},
clock_time_get: (clockId, _precision, outPtr) => {
// See <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/wasi/time.rs>
// and <docs.rs/wasi/> for help.
const instance = config.instance;
const mem = new Uint8Array(instance.exports.memory.buffer);
outPtr >>>= 0;
// We ignore the precision, as it can't be implemented anyway.
switch (clockId) {
case 0: {
// Realtime clock.
const now = BigInt(Math.floor(Date.now())) * BigInt(1000000);
buffer.writeUInt64LE(mem, outPtr, now);
// Success.
return 0;
}
case 1: {
// Monotonic clock.
const nowMs = config.performanceNow();
const nowMsInt = Math.floor(nowMs);
const now = BigInt(nowMsInt) * BigInt(1000000) +
BigInt(Math.floor(((nowMs - nowMsInt) * 1000000)));
buffer.writeUInt64LE(mem, outPtr, now);
// Success.
return 0;
}
default:
// Return an `EINVAL` error.
return 28;
}
},
// Writing to a file descriptor is used in order to write to stdout/stderr.

@@ -46,0 +76,0 @@ fd_write: (fd, addr, num, outPtr) => {

@@ -11,1 +11,2 @@ export declare function utf8BytesToString(buffer: Uint8Array, offset: number, length: number): string;

export declare function writeUInt32LE(buffer: Uint8Array, offset: number, value: number): void;
export declare function writeUInt64LE(buffer: Uint8Array, offset: number, value: bigint): void;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.writeUInt32LE = exports.writeUInt8 = exports.readUInt32LE = exports.utf8BytesToString = void 0;
exports.writeUInt64LE = exports.writeUInt32LE = exports.writeUInt8 = exports.readUInt32LE = exports.utf8BytesToString = void 0;
// This program is free software: you can redistribute it and/or modify

@@ -49,2 +49,14 @@ // it under the terms of the GNU General Public License as published by

exports.writeUInt32LE = writeUInt32LE;
function writeUInt64LE(buffer, offset, value) {
checkRange(buffer, offset, 8);
buffer[offset + 7] = Number((value >> BigInt(56)) & BigInt(0xff));
buffer[offset + 6] = Number((value >> BigInt(48)) & BigInt(0xff));
buffer[offset + 5] = Number((value >> BigInt(40)) & BigInt(0xff));
buffer[offset + 4] = Number((value >> BigInt(32)) & BigInt(0xff));
buffer[offset + 3] = Number((value >> BigInt(24)) & BigInt(0xff));
buffer[offset + 2] = Number((value >> BigInt(16)) & BigInt(0xff));
buffer[offset + 1] = Number((value >> BigInt(8)) & BigInt(0xff));
buffer[offset] = Number(value & BigInt(0xff));
}
exports.writeUInt64LE = writeUInt64LE;
function checkRange(buffer, offset, length) {

@@ -51,0 +63,0 @@ if (!Number.isInteger(offset) || offset < 0)

@@ -41,3 +41,3 @@ "use strict";

// Used to bind with the smoldot-light bindings. See the `bindings-smoldot-light.js` file.
const smoldotJsConfig = Object.assign({ bufferIndices, performanceNow: platformBindings.performanceNow, connect: platformBindings.connect, onPanic: (message) => {
const smoldotJsConfig = Object.assign({ bufferIndices, connect: platformBindings.connect, onPanic: (message) => {
killAll();

@@ -51,2 +51,3 @@ config.onWasmPanic(message);

getRandomValues: platformBindings.getRandomValues,
performanceNow: platformBindings.performanceNow,
onProcExit: (retCode) => {

@@ -53,0 +54,0 @@ killAll();

@@ -80,6 +80,6 @@ // Smoldot

// Immediately cleared when `remove()` is called on a chain.
let chainIds = new WeakMap();
const chainIds = new WeakMap();
// If `Client.terminate()̀ is called, this error is set to a value.
// All the functions of the public API check if this contains a value.
let alreadyDestroyedError = null;
const alreadyDestroyedError = { value: null };
const instance = startInstance({

@@ -98,4 +98,4 @@ // Maximum level of log entries sent by the client.

addChain: (options) => __awaiter(this, void 0, void 0, function* () {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
// Passing a JSON object for the chain spec is an easy mistake, so we provide a more

@@ -125,4 +125,4 @@ // readable error.

sendJsonRpc: (request) => {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
if (wasDestroyed.destroyed)

@@ -139,4 +139,4 @@ throw new AlreadyDestroyedError();

nextJsonRpcResponse: () => {
if (alreadyDestroyedError)
return Promise.reject(alreadyDestroyedError);
if (alreadyDestroyedError.value)
return Promise.reject(alreadyDestroyedError.value);
if (wasDestroyed.destroyed)

@@ -149,4 +149,4 @@ return Promise.reject(new AlreadyDestroyedError());

remove: () => {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
if (wasDestroyed.destroyed)

@@ -164,5 +164,5 @@ throw new AlreadyDestroyedError();

terminate: () => __awaiter(this, void 0, void 0, function* () {
if (alreadyDestroyedError)
throw alreadyDestroyedError;
alreadyDestroyedError = new AlreadyDestroyedError();
if (alreadyDestroyedError.value)
throw alreadyDestroyedError.value;
alreadyDestroyedError.value = new AlreadyDestroyedError();
instance.startShutdown();

@@ -169,0 +169,0 @@ })

@@ -11,6 +11,2 @@ import type { SmoldotWasmInstance } from './bindings.js';

/**
* Returns the number of milliseconds since an arbitrary epoch.
*/
performanceNow: () => number;
/**
* Tries to open a new connection using the given configuration.

@@ -75,3 +71,3 @@ *

*
* The number of bytes most never exceed the number of "writable bytes" of the stream.
* The number of bytes must never exceed the number of "writable bytes" of the stream.
* `onWritableBytes` can be used in order to notify that more writable bytes are available.

@@ -165,3 +161,4 @@ *

/**
* Callback called when more data can be written on the stream.
* Callback called when some data sent using {@link Connection.send} has effectively been
* written on the stream, meaning that some buffer space is now free.
*

@@ -174,2 +171,5 @@ * Can only happen while the connection is in the `Open` state.

* "multi-stream".
*
* Only a number of bytes equal to the size of the data provided to {@link Connection.send}
* must be reported. In other words, the `initialWritableBytes` must never be exceeded.
*/

@@ -176,0 +176,0 @@ onWritableBytes: (numExtra: number, streamId?: number) => void;

@@ -88,6 +88,2 @@ // Smoldot

},
// Must return the UNIX time in milliseconds.
unix_time_ms: () => Date.now(),
// Must return the value of a monotonic clock in milliseconds.
monotonic_clock_ms: () => config.performanceNow(),
// Must call `timer_finished` after the given number of milliseconds has elapsed.

@@ -94,0 +90,0 @@ start_timer: (id, ms) => {

@@ -9,2 +9,6 @@ import type { SmoldotWasmInstance } from './bindings.js';

/**
* Returns the number of milliseconds since an arbitrary epoch.
*/
performanceNow: () => number;
/**
* List of environment variables to feed to the Rust program. An array of strings.

@@ -11,0 +15,0 @@ * Example: `["RUST_BACKTRACE=1", "RUST_LOG=foo"];`

@@ -42,2 +42,32 @@ // Smoldot

},
clock_time_get: (clockId, _precision, outPtr) => {
// See <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/wasi/time.rs>
// and <docs.rs/wasi/> for help.
const instance = config.instance;
const mem = new Uint8Array(instance.exports.memory.buffer);
outPtr >>>= 0;
// We ignore the precision, as it can't be implemented anyway.
switch (clockId) {
case 0: {
// Realtime clock.
const now = BigInt(Math.floor(Date.now())) * BigInt(1000000);
buffer.writeUInt64LE(mem, outPtr, now);
// Success.
return 0;
}
case 1: {
// Monotonic clock.
const nowMs = config.performanceNow();
const nowMsInt = Math.floor(nowMs);
const now = BigInt(nowMsInt) * BigInt(1000000) +
BigInt(Math.floor(((nowMs - nowMsInt) * 1000000)));
buffer.writeUInt64LE(mem, outPtr, now);
// Success.
return 0;
}
default:
// Return an `EINVAL` error.
return 28;
}
},
// Writing to a file descriptor is used in order to write to stdout/stderr.

@@ -44,0 +74,0 @@ fd_write: (fd, addr, num, outPtr) => {

@@ -11,1 +11,2 @@ export declare function utf8BytesToString(buffer: Uint8Array, offset: number, length: number): string;

export declare function writeUInt32LE(buffer: Uint8Array, offset: number, value: number): void;
export declare function writeUInt64LE(buffer: Uint8Array, offset: number, value: bigint): void;

@@ -41,2 +41,13 @@ // Smoldot

}
export function writeUInt64LE(buffer, offset, value) {
checkRange(buffer, offset, 8);
buffer[offset + 7] = Number((value >> BigInt(56)) & BigInt(0xff));
buffer[offset + 6] = Number((value >> BigInt(48)) & BigInt(0xff));
buffer[offset + 5] = Number((value >> BigInt(40)) & BigInt(0xff));
buffer[offset + 4] = Number((value >> BigInt(32)) & BigInt(0xff));
buffer[offset + 3] = Number((value >> BigInt(24)) & BigInt(0xff));
buffer[offset + 2] = Number((value >> BigInt(16)) & BigInt(0xff));
buffer[offset + 1] = Number((value >> BigInt(8)) & BigInt(0xff));
buffer[offset] = Number(value & BigInt(0xff));
}
function checkRange(buffer, offset, length) {

@@ -43,0 +54,0 @@ if (!Number.isInteger(offset) || offset < 0)

@@ -37,3 +37,3 @@ // Smoldot

// Used to bind with the smoldot-light bindings. See the `bindings-smoldot-light.js` file.
const smoldotJsConfig = Object.assign({ bufferIndices, performanceNow: platformBindings.performanceNow, connect: platformBindings.connect, onPanic: (message) => {
const smoldotJsConfig = Object.assign({ bufferIndices, connect: platformBindings.connect, onPanic: (message) => {
killAll();

@@ -47,2 +47,3 @@ config.onWasmPanic(message);

getRandomValues: platformBindings.getRandomValues,
performanceNow: platformBindings.performanceNow,
onProcExit: (retCode) => {

@@ -49,0 +50,0 @@ killAll();

{
"name": "smoldot",
"version": "1.0.2",
"version": "1.0.3",
"description": "Light client that connects to Polkadot and Substrate-based blockchains",

@@ -49,3 +49,3 @@ "author": "Parity Technologies <admin@parity.io>",

"dtslint": "^4.0.6",
"rimraf": "^4.1.2",
"rimraf": "^5.0.0",
"typedoc": "^0.24.1",

@@ -52,0 +52,0 @@ "typescript": "^5.0.2"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc