Install
import * as secant from "{{ORIGIN}}/lib/secant.js";curl -o secant.mjs {{ORIGIN}}/lib/secant.js
node -e "import('./secant.mjs').then(s => console.log(s.VERSION))"<script type="module">
import { VERSION } from "{{ORIGIN}}/lib/secant.js";
console.log(VERSION);
</script>NOTEIn Node, save the file with the
.mjs ending. Node only reads .js as a module inside a package that says so.Network
mesh(n = 48, { seed, links })- Places
nnodes on a disc and links each to itslinksnearest neighbours (default 2), then joins any islands. Same seed, same network. boot(m)- Gives every node a P-256 key pair. Needed before
seal. route(m, { hops = 4, seed })- Returns node ids: entry, relays, exit. At least 3 hops.
Layers
seal(m, path, payload)- One encrypted layer per hop. Returns the cell as
Uint8Array. sealTo(hops, payload)- The same for real nodes:
hops = [{ pub, addr }], as returned byGET /id. peel(node, cell)- Opens one layer. Returns
{ next, body }or throws. cross(m, path, payload)- Seals, then peels hop by hop. Returns
{ trace, delivered }. identity() / exportIdentity() / importIdentity()- Key pairs for real nodes, and saving them as JSON.
Try a route
Boots 48 nodes in this tab, picks a straight line across them and sends your address through it. The table is what each hop knew.
press Cut a line.Payments
wallet()- A P-256 signing key and an address derived from it.
voucher(w, { to, lamports, tip })- A signed transfer that can travel offline.
verify(v)trueif the signature and the address match the body.carry(v, devices, { online })- Walks a voucher along devices until
online. Returns{ landed, trace, tips }.
Try a payment
Sign a voucher, then carry it through three phones with no signal to a laptop that has some. Tick the box to change the amount on the way and watch the first phone refuse it.
press Sign.Boxes
lease({ seconds, rate })- The bill for a box open for
seconds. meter({ rate, every, onTick })- Ticks every
everyms with the running bill.stop()returns the final one. BOX_RATE- 11,600 lamports a second.
press Open a box.Constants and errors
| Name | Value |
|---|---|
VERSION | 0.3.1 |
LAMPORTS | 1,000,000,000 per SOL |
BOX_RATE | 11,600 lamports/s |
TIP_SPLIT | { gateway: 0.4, carriers: 0.6 } |
| Error | When |
|---|---|
secant.js needs WebCrypto | Very old browser, or Node older than 19. |
call boot(m) before seal() | Nodes have no keys yet. |
a route needs at least 3 hops | hops below 3. |
node X cannot open this layer | The cell was sealed for someone else, or changed on the way. |
voucher needs { to, lamports } | Missing recipient or a zero amount. |