ever-sdk-js
ever-sdk-js copied to clipboard
Deno runtime support
Detail experiment can be found here: readme
I think it's pretty easy to add Deno support. Deno can work almost like web runtime with wasm.
We just need to fix some hardcoded assumptions like fetch('/evernode.wasm')
because this is too browser-specific.
- Right now the naive approach doesn't work yet. Consider:
import { TonClient } from "npm:@eversdk/core";
import { libWeb } from "npm:@eversdk/lib-web"; // or lib-node
TonClient.useBinaryLibrary(libWeb);
const client = new TonClient();
const { phrase } = await client.crypto.mnemonic_from_random({});
console.log(phrase);
client.close();
Will give us:
error: Could not resolve 'npm:@eversdk/lib-web'
-
lib-node
approach also doesn't work.
In short:
error: Uncaught TypeError: /root/.tonlabs/binaries/1/eversdk.node: undefined symbol: SSL_CTX_free
Seems like something with dynamic linking made for nodejs runtime. It feels easily fixable since Deno is made on Rust and Eversdk too.
UPD 3. Workaround: https://github.com/awnion/example-ever-sdk-deno/blob/main/deno-custom-wasm-url.ts
import { TonClient } from "npm:@eversdk/core";
// require npm i @eversdk/lib-web
import { libWeb, libWebSetup } from "./node_modules/@eversdk/lib-web/index.js";
// require npm i @eversdk/lib-web
libWebSetup({
disableSeparateWorker: true,
binaryURL: new URL(
"./node_modules/@eversdk/lib-web/eversdk.wasm",
import.meta.url,
),
});
TonClient.useBinaryLibrary(libWeb);
// ------------------------^^^^^^
// here linter will complain but it's OK
const client = new TonClient();
const { phrase } = await client.crypto.mnemonic_from_random({});
console.log(phrase);
client.close();
Whilst it works it's not very convenient because we have to manually import index.js
from node_modules
. The main concern is that we use two different ways of distribution:
- TonClient comes from
npm:
and we can't easily vendor it from node_modules since its internals link to each other node-js (or rather CommonJS) way. - And vice versa
lib-web
can be imported only viaindex.js
directly and doesn't work withnpm:
deno-way.
The ideal solution would be to have libDeno (or rather libWasm / libWasi / etc) for server-side WASM + deno modules deployed on Deno