@julclang/julc-vm-wasm 0.0.0-stage → 0.1.0-pre22
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/LICENSE +21 -0
- package/README.md +115 -2
- package/engine/engine.json +1 -0
- package/engine/julc-vm-47a30d49de00.js +3306 -0
- package/engine/julc-vm-47a30d49de00.js.wasm +0 -0
- package/engine/package.json +1 -0
- package/engine.d.ts +13 -0
- package/engine.js +20 -0
- package/index.d.ts +12 -0
- package/index.js +21 -0
- package/node.js +4 -0
- package/package.json +44 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BloxBean Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @julclang/julc-vm-wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
JuLC's Plutus virtual machine, compiled to WebAssembly, for browsers and Node.js. It decodes, hashes, evaluates and
|
|
4
|
+
debugs Plutus V1, V2 and V3 scripts (UPLC 1.0.0 and 1.1.0), and applies parameters to them: `vm.applyParams` returns the
|
|
5
|
+
applied script and its hash under the language the request states (V1, V2 or V3). It runs in a worker, through
|
|
6
|
+
[`@julclang/wasm-client`](https://www.npmjs.com/package/@julclang/wasm-client), which this package depends on at its own
|
|
7
|
+
exact version. For the Java compiler, the decompiler and source debugging as well, install
|
|
8
|
+
[`@julclang/julc-wasm`](https://www.npmjs.com/package/@julclang/julc-wasm) instead.
|
|
9
|
+
|
|
10
|
+
**Experimental.** The JavaScript API is version 0 and may change in any release before 1.0; the release notes list
|
|
11
|
+
every change. JuLC is a research project: do not treat a result as proof that a contract is safe to deploy.
|
|
12
|
+
|
|
13
|
+
## Versions
|
|
14
|
+
|
|
15
|
+
The npm version is the JuLC release version. Dist-tags:
|
|
16
|
+
|
|
17
|
+
| Install | Gets |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `npm install @julclang/julc-vm-wasm` | `latest`: the newest `-preN` until JuLC's first final release; then the newest final release, unless that final is older than the `-preN` on `latest` (see below) |
|
|
20
|
+
| `npm install @julclang/julc-vm-wasm@preview` | the newest `-preN` prerelease after a final release |
|
|
21
|
+
| `npm install @julclang/julc-vm-wasm@beta` | the newest `-betaN` |
|
|
22
|
+
| `npm install @julclang/julc-vm-wasm@next` | the newest release candidate of a final release (`X.Y.Z-rcN`) |
|
|
23
|
+
|
|
24
|
+
- A channel (`preview`, `beta`, `next`) exists only after its first version; until then installing it fails.
|
|
25
|
+
- A final release does not reset the channels, so after one a channel can name a version older than `latest`.
|
|
26
|
+
- No dist-tag ever moves to an older version: a version older than the one a tag names (a backfilled first final
|
|
27
|
+
after a `-preN` on `latest`, or a `-betaN` after a `-preN` of the same `X.Y.Z`, which semver orders below it) is on a
|
|
28
|
+
`release-<major>.<minor>` or `release-<version>` tag instead. Such a backfilled final leaves `latest` on that older
|
|
29
|
+
prerelease, and later `-preN`s go to `preview`, until a final higher than it is published.
|
|
30
|
+
- Pin a prerelease exactly (`"@julclang/julc-vm-wasm": "0.1.0-pre22"`): a caret range such as `^0.1.0-pre21` also
|
|
31
|
+
matches a later `0.1.0-rcN`.
|
|
32
|
+
|
|
33
|
+
## Use
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import {createJulcVm} from '@julclang/julc-vm-wasm';
|
|
37
|
+
|
|
38
|
+
const julc = await createJulcVm();
|
|
39
|
+
try {
|
|
40
|
+
const {info} = await julc.vm.decode({script: {script: '46450101002499'}});
|
|
41
|
+
console.log(info.scriptHash);
|
|
42
|
+
const evaluation = await julc.vm.evaluate({script: {script: '46450101002499'}});
|
|
43
|
+
console.log(evaluation.status, evaluation.cpu, evaluation.mem);
|
|
44
|
+
// Apply the integer 42 to a parameterised script (the language is always stated).
|
|
45
|
+
const applied = await julc.vm.applyParams({language: 'V3', script: {script: '46450101002499'}, params: [{int: 42n}]});
|
|
46
|
+
console.log(applied.cborHex, applied.scriptHash);
|
|
47
|
+
} finally {
|
|
48
|
+
julc.dispose();
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Each client runs the engine in its own worker (`worker_threads` in Node.js); `dispose()` ends it. The package's version
|
|
53
|
+
is the JuLC release, and the client refuses to run an engine, a manifest or a runtime file of another release.
|
|
54
|
+
`createJulcVm(options)` takes `timeoutMs`, `loadTimeoutMs` and `workerFactory`; the engine's files are always this
|
|
55
|
+
package's. The types of every request and response are exported from the package root. The subpath `./engine` describes
|
|
56
|
+
the engine: its frozen `manifest`, `launcherUrl`, `moduleUrl` and `version`, and `engineFiles()`, which returns new
|
|
57
|
+
copies of them, for example for `@julclang/wasm-client`'s own `createJulc`.
|
|
58
|
+
|
|
59
|
+
## Size and requirements
|
|
60
|
+
|
|
61
|
+
- The WebAssembly module is 14.5 MB (uncompressed). Serve it compressed: it compresses well.
|
|
62
|
+
- **First load:** a client was ready in about 0.2 s in Node.js 22 and 24 and in Chromium on an Apple-silicon
|
|
63
|
+
laptop, with the module already on disk or in the HTTP cache. Network transfer comes on top.
|
|
64
|
+
- **Browsers:** WebAssembly GC and exception references (`exnref`). Tested in Chromium 156.0.8078.4; Firefox and
|
|
65
|
+
Safari are not tested yet. BLS12-381 builtins are not available in WebAssembly.
|
|
66
|
+
- **TypeScript 5.0 or later** for the declarations, which re-export `@julclang/wasm-client`'s types with
|
|
67
|
+
`export type *`.
|
|
68
|
+
- **Node.js 22.3.0 or later.** Node 22 enables WebAssembly exception references only with
|
|
69
|
+
`--experimental-wasm-exnref`: the client checks for them before it starts its first worker and, when they are
|
|
70
|
+
missing, sets that flag with `v8.setFlagsFromString`. The flag is process-wide. Node 24 needs nothing. The engine
|
|
71
|
+
also loads inside your own `worker_threads` worker.
|
|
72
|
+
- **Node.js security releases:** `engines` (`>=22.3.0`) is the lowest version that works, not a recommendation. Run a
|
|
73
|
+
supported Node.js release line, updated to its latest security release.
|
|
74
|
+
- **Content Security Policy:** `script-src 'self' 'wasm-unsafe-eval'`, on the page and on the responses of the worker
|
|
75
|
+
scripts, the runtime and the launcher (a worker script has its own policy). No `'unsafe-eval'` is needed.
|
|
76
|
+
- **Origins:** in a browser the worker loads the engine's files only from its own origin, which must not be opaque.
|
|
77
|
+
Other hosts, such as Electron with a custom scheme registered as standard, are untested; an Electron page loaded
|
|
78
|
+
from `file:` is refused.
|
|
79
|
+
- **Chrome extensions** (tested with an unpacked Manifest V3 extension page): Manifest V3's default policy does not
|
|
80
|
+
allow WebAssembly, so the manifest must:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
"content_security_policy": {"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Bundlers
|
|
87
|
+
|
|
88
|
+
The engine's files are named by `new URL('./engine/…', import.meta.url)` in `engine.js`, and the worker by
|
|
89
|
+
`new Worker(new URL('./julc-worker.js', import.meta.url))` in `@julclang/wasm-client`, so bundlers copy them.
|
|
90
|
+
|
|
91
|
+
- **Vite 8** needs no configuration. The **development servers of Vite 5 to 7** need both packages excluded from
|
|
92
|
+
dependency pre-bundling; their production builds need nothing:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
// vite.config.js
|
|
96
|
+
export default {optimizeDeps: {exclude: ['@julclang/wasm-client', '@julclang/julc-vm-wasm']}};
|
|
97
|
+
```
|
|
98
|
+
- **webpack 5** works with no configuration, but its Terser minifies the engine's launcher. To ship the launcher
|
|
99
|
+
unchanged, emit the engine files as assets and keep them out of minification:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
// webpack.config.cjs
|
|
103
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
104
|
+
module.exports = {
|
|
105
|
+
module: {rules: [{test: /[\\/]@julclang[\\/][^\\/]+[\\/]engine[\\/]/, type: 'asset/resource',
|
|
106
|
+
generator: {filename: 'engine/[name]-[contenthash:8][ext]'}}]},
|
|
107
|
+
optimization: {minimizer: [new TerserPlugin({exclude: /^engine\//})]},
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
- **Plain `<script type="module">`** with an import map naming both packages' `index.js` works without a bundler.
|
|
111
|
+
- **Server bundles:** webpack with `target: 'node'` (its Terser minifies the launcher here too, which still works), and
|
|
112
|
+
Next.js with Turbopack (`next build`, `next dev` and `output: 'standalone'`), work as they are. **esbuild** does not
|
|
113
|
+
copy files named by `new URL`: keep the packages external (`--packages=external`, or `external: ['@julclang/*']`).
|
|
114
|
+
**Next.js with `--webpack`** rewrites the URLs: list both packages in `serverExternalPackages`.
|
|
115
|
+
|
|
116
|
+
Version 0.1.0-pre22. Source, issues and the design (ADR-077): https://github.com/bloxbean/julc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"47a30d49de00","launcher":"julc-vm-47a30d49de00.js","variant":"vm","api":0,"groups":["vm","debug"],"julcVersion":"0.1.0-pre22"}
|