The Nomad Virtual Machine reference implementation and NIP proposals.
Clone the repository as usual:
git clone https://github.com/lacrypta/nomad.gitnow simply install all dependencies:
pnpm iAfter you make the changes you intended to, simply run:
pnpm formatto reformat the whole project, or:
pnpm lintto check if the formatting is correct.
You can run:
pnpm buildto generate the transpiled files in ./dist/cjs, ./dist/esm, and ./dist/umd, and types in ./dist/types.
To run the test suite run:
pnpm testfor the "standard" test suite, or:
pnpm test:metato test the test helpers themselves, or:
pnpm test:regressionto run the regression tests.
Finally, run:
pnpm docto generate the documentation in ./dist/docs:
- in
./dist/docs/apiyou'll find the "end-user" documentation: only the interfaces available to consumers is documented therein. - in
./dist/docs/internalyou'll find the "maintainer" documentation: every part of the project is documented therein.
If you're feeling lazy, you may run:
pnpm alland this will reset the project and update all dependencies, and run the formatting, building, testing, and documentation steps described above.
The demo has a minimal example, but this simply consists of (a variation on):
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>...</title>
<script referrerpolicy="no-referrer" src="https://unpkg.com/@lacrypta/nomad"></script>
<!-- or, alternatively:
<script referrerpolicy="no-referrer" src="https://cdn.jsdelivr.net/npm/@lacrypta/nomad"></script>
-->
<script type="module" referrerpolicy="no-referrer">
'use strict';
// take a hold of the relevant entry points
const { vmCreate, dependencyFrom } = nomad;
// build a new VM
const vm = vmCreate();
// listen on every event cast on it
vm.on('**', (...args) => console.log(args));
// define some functions
// (note how the first closure establishes the dependencies and the returned function uses those same dependencies)
const duplicate = () =>
(x) => 2 * x;
const quadruple = (dupA = duplicate, dupB = duplicate) =>
(x) => dupA(dupB(x));
const root = await vm.start();
console.log('BOOTED');
await root.install(dependencyFrom(duplicate));
await root.install(dependencyFrom(quadruple));
const result = await root.execute(dependencyFrom(
function x(quad = quadruple) {
return quad(42);
}),
);
console.log(`RESULT = ${result}`);
await vm.shutdown();
</script>
</head>
<body></body>
</html>