Docs / Build

secant.js

secant.js is the whole client in one file with no dependencies. It runs in the browser and in Node 20 or newer. The blocks on this page load it from this site and run it in your tab.

$SECANTsoonChartBuy $SECANT

Install

import * as secant from "{{ORIGIN}}/lib/secant.js";
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 n nodes on a disc and links each to its links nearest 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 by GET /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.

Live · secant.js
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)
true if 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.

Live · offline
press Sign.

Boxes

lease({ seconds, rate })
The bill for a box open for seconds.
meter({ rate, every, onTick })
Ticks every every ms with the running bill. stop() returns the final one.
BOX_RATE
11,600 lamports a second.
Live · meter
press Open a box.

Constants and errors

NameValue
VERSION0.3.1
LAMPORTS1,000,000,000 per SOL
BOX_RATE11,600 lamports/s
TIP_SPLIT{ gateway: 0.4, carriers: 0.6 }
ErrorWhen
secant.js needs WebCryptoVery old browser, or Node older than 19.
call boot(m) before seal()Nodes have no keys yet.
a route needs at least 3 hopshops below 3.
node X cannot open this layerThe cell was sealed for someone else, or changed on the way.
voucher needs { to, lamports }Missing recipient or a zero amount.