Get started
You need Go 1.26 or newer.
go get gitlab.techeve.de/techeve/pq-seal@latestServer
Section titled “Server”sealer, err := pqseal.New(pqseal.Options{})if err != nil { return err}defer sealer.Close()
// Serves the key and the browser files under a path of your choice.pqfiber.Mount(app, "/pq-seal", sealer)Put Mount before the login check if a login page uses it. Without Fiber, see Integration.
Browser
Section titled “Browser”const address = '/pq-seal/client.js';const { SealClient } = await import(/* @vite-ignore */ address);const seal = await SealClient.connect();
const response = await seal.withFreshKey(async () => fetch('/my/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user, password: await seal.encrypt('login', password) }),}));The result of encrypt is a string, the route belongs to your application. withFreshKey covers a server restart while the page is open.
The address is in a variable on purpose: the Vite dev server tries to resolve a literal, even with @vite-ignore.
Back on the server
Section titled “Back on the server”password, err := sealer.Open(request.Password, "login")if err != nil { return pqfiber.Error(c, err)}The context login is free to choose and must be the same on both sides.
Check it
Section titled “Check it”The selftest shows whether a browser can do everything:
go run gitlab.techeve.de/techeve/pq-seal/cmd/selftest@latestThen open http://localhost:8080/.