Skip to content
/ nomad Public

The Nomad Virtual Machine reference implementation

License

Notifications You must be signed in to change notification settings

lacrypta/nomad

Repository files navigation

Nomad logo

Nomad

The Nomad Virtual Machine reference implementation and NIP proposals.

Install

Simply install via pnpm:

pnpm i --save-dev @lacrypta/nomad

Development

Clone the repository as usual:

git clone https://github.com/lacrypta/nomad.git

now simply install all dependencies:

pnpm i

After you make the changes you intended to, simply run:

pnpm format

to reformat the whole project, or:

pnpm lint

to check if the formatting is correct.

You can run:

pnpm build

to generate the transpiled files in ./dist/cjs, ./dist/esm, and ./dist/umd, and types in ./dist/types.

To run the test suite run:

pnpm test

for the "standard" test suite, or:

pnpm test:meta

to test the test helpers themselves, or:

pnpm test:regression

to run the regression tests.

Finally, run:

pnpm doc

to generate the documentation in ./dist/docs:

  • in ./dist/docs/api you'll find the "end-user" documentation: only the interfaces available to consumers is documented therein.
  • in ./dist/docs/internal you'll find the "maintainer" documentation: every part of the project is documented therein.

If you're feeling lazy, you may run:

pnpm all

and this will reset the project and update all dependencies, and run the formatting, building, testing, and documentation steps described above.

Usage

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>

About

The Nomad Virtual Machine reference implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published