sub3 example

Loading…

A small app that takes payments with sub3

Use it as a customer would, and see the code behind each step.

Everything at once.

Sign in with a wallet

Your user sees

Your code does

The user signs a message with their wallet. sub3 returns a JWT that your server verifies: no passwords.

Opens

GET /login?merchant=…
Show the code
In the browser, public/app.js
async function signIn() {
	const handle = config.product.split('/')[0];
	await receive(await openSub3(`/login?merchant=${handle}`, options()));
}
On the server, sub3.mjs: the token's subject is the user's address
const { payload } = await jwtVerify(token, keys.get(config.api), {
	algorithms: ['EdDSA'],
	issuer: config.site,
	audience: config.origin
});
if (!/^0x[0-9a-fA-F]{40}$/.test(payload.sub ?? '')) throw problem(401, 'Invalid session');
return payload.sub.toLowerCase();

See what the app knows about you

Buy something on sub3's checkout

Come back and see what changed

Use what you bought

What just happened