santoku
santoku

santoku

A Lua framework for building applications end to end

Lua 5.1 from the build system to the server to the browser. Every example on this site runs in your browser. Edit one and run it.


santoku targets Lua 5.1, because 5.1 is the version its platforms actually share. LuaJIT implements 5.1 and OpenResty embeds LuaJIT, so server code, client code and the build harness all run the same language. Compiled to WebAssembly, the 5.1 core is smaller to embed, and its single number type sidesteps the integer and float split introduced in 5.3, which keeps numeric values crossing the JavaScript boundary simple. Support for newer versions is meant to come from compatibility shims layered over the 5.1 core rather than version branches in the tree; contributions and design ideas for that layer are welcome.

santoku-monocypher

View on LuaRocks

Monocypher crypto bindings: diceware passphrases, Argon2id identities, EdDSA request signing, XChaCha20-Poly1305 AEAD keys, HMAC helpers

santoku-monocypher binds the Monocypher cryptography library into one Lua module, santoku.monocypher, with a bundled SHA-256, SHA-1 and the EFF diceware wordlist. A passphrase runs through Argon2id once to make a master secret. Everything else derives from that master with HMAC-SHA256 under fixed labels.

Details
  • The module ships an opinionated identity and key model in place of the full Monocypher API.
  • The master derives a public account id, an EdDSA signing pair through Monocypher's crypto_eddsa, an XChaCha20-Poly1305 data key, and domain-separated subkeys.
  • On top sit HMAC utilities, constant-time comparison, key wrapping, and passphrase quality checks.
  • The same C compiles to native Lua and to WebAssembly, so every example on this page runs live in your browser.
  • Base64 output uses the standard alphabet with padding: 44 characters for 32-byte values, 88 for 64-byte signatures.
  • hash_password is the exception. Its PHC string carries unpadded salt and hash.
  • The defaults are 65536 Argon2id blocks (64 MiB) and 3 passes, which is slow on purpose. The examples pass 1024 and 1 so they finish quickly.
  • Never use the reduced parameters in production.

Generate and validate a passphrase

generate rolls six words from the EFF large wordlist with rejection-sampled system randomness. validate tokenizes on whitespace, lowercases, and needs at least six words that all appear on the list.

local crypto = require("santoku.monocypher")
local secret = crypto.generate()
print("passphrase:", secret)
print("valid:", crypto.validate(secret))
print("case-insensitive:", crypto.validate(secret:upper()))
print("five words:", crypto.validate("abacus abdomen abdominal abide abiding"))
print("not on the list:", crypto.validate("hunter2 hunter2 hunter2 hunter2 hunter2 hunter2"))
return crypto.validate(secret)
Details

So validate rejects ordinary passwords and short diceware phrases.

The EFF wordlist

eff_words() returns the EFF large wordlist that generate and validate use: 7776 words in ascending order. eff_word(dice) maps five dice digits, each 1 to 6, to the word at that roll.

local crypto = require("santoku.monocypher")
local arr = require("santoku.array")
local err = require("santoku.error")
local words = crypto.eff_words()
print("words:", #words, words[1], words[#words])
print("11111:", crypto.eff_word("11111"))
print("16666:", crypto.eff_word("16666"))
print("21111:", crypto.eff_word("21111"))
print("66666:", crypto.eff_word("66666"))
local rolls = { "43246", "15511", "62124", "35541", "21526", "54611" }
local picked = {}
for i = 1, #rolls do
  picked[i] = crypto.eff_word(rolls[i])
end
local phrase = arr.concat(picked, " ")
print("phrase:", phrase)
print("valid:", crypto.validate(phrase))
words[1] = "changed"
print("fresh copy:", crypto.eff_words()[1])
print("four digits:", (err.pcall(crypto.eff_word, "1234")))
print("a 7:", (err.pcall(crypto.eff_word, "12347")))
return phrase
Details
  • eff_words returns a fresh table on every call, so a change to that table changes nothing else.
  • "11111" is abacus and "66666" is zoom.
  • A string of any other length or with any other digit raises.
  • Roll real dice and look the words up to build a passphrase with no computer randomness at all.

Weak-pattern checks

phrase_audit flags human-picked phrases that a dice roll would almost never produce. It returns the first string below that applies, checked in this priority order, or nil when none apply.

local crypto = require("santoku.monocypher")
print("repeated:", crypto.phrase_audit("dog dog canyon ethics sushi hazelnut"))
print("same letter:", crypto.phrase_audit("sand sushi salad sixth sizzle serving"))
print("sequential:", crypto.phrase_audit("apple bat crab dove echo flag"))
print("sorted:", crypto.phrase_audit("apple canyon ethics hazelnut opera trend"))
print("reverse sorted:", crypto.phrase_audit("trend opera hazelnut ethics canyon apple"))
print("random:", crypto.phrase_audit("canyon ethics sushi hazelnut opera trend"))
return crypto.phrase_audit("canyon ethics sushi hazelnut opera trend") == nil
Details
  • repeated_word
  • same_letter: all words share a first letter.
  • sequential: the first letters step through the alphabet.
  • alphabetical: the words are fully sorted in either direction.

Derive an identity

derive_identity(secret[, memory, passes]) runs Argon2id once over the passphrase to make a master secret. From it come a public sub, the account id, and an EdDSA keypair, each under its own HMAC label.

local crypto = require("santoku.monocypher")
local err = require("santoku.error")
local id = crypto.derive_identity("canyon ethics sushi hazelnut opera trend", 1024, 1)
print("sub:", id:sub())
print("public key:", id:public_key())
local again = crypto.derive_identity("canyon ethics sushi hazelnut opera trend", 1024, 1)
print("deterministic:", id:sub() == again:sub())
local exported = id:export()
print("argon2:", exported.argon2_memory, exported.argon2_passes)
print("bad params:", err.pcall(crypto.derive_identity, "x", 4, 1))
return id:public_key()
Details
  • The Argon2id run uses a fixed salt and is memory-hard.
  • The same passphrase always produces the same identity on any machine.
  • memory is in KiB blocks and defaults to 65536, so 64 MiB. passes defaults to 3.
  • Parameters below 8 blocks or 1 pass are rejected. err.pcall unwraps the structured error cleanly.
  • The fixed salt suits an identity. Store user passwords with hash_password instead.

Salted password hashes

hash_password(password[, memory, passes]) runs Argon2id with a fresh salt and returns one PHC string. verify_password(password, encoded) reads the parameters back from that string, recomputes, and compares in constant time.

local crypto = require("santoku.monocypher")
local err = require("santoku.error")
local stored = crypto.hash_password("correct horse battery staple", 1024, 1)
print(stored)
print("right:", crypto.verify_password("correct horse battery staple", stored))
print("wrong:", crypto.verify_password("correct horse battery stable", stored))
print("salted:", stored ~= crypto.hash_password("correct horse battery staple", 1024, 1))
print("malformed:", err.pcall(crypto.verify_password, "x", "plaintext"))
return crypto.verify_password("correct horse battery staple", stored)
Details
  • The salt is 16 bytes from the system's random source.
  • The defaults are 64 MiB and 3 passes.
  • The PHC string is $argon2id$v=19$m=...,t=...,p=1$salt$hash. It carries everything needed to check it later, so store it as is.
  • Because verify_password reads the parameters from the string, a higher cost for new hashes never breaks old ones.
  • A string that verify_password can't parse raises malformed password hash.

Detached EdDSA signatures

sign produces a detached 64-byte signature, base64 encoded to 88 characters. EdDSA is deterministic, so the same identity and message always give the same bytes.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local sig = id:sign("release-v1.2.0")
print("signature:", sig)
print("length:", #sig)
print("deterministic:", id:sign("release-v1.2.0") == sig)
print("message-bound:", id:sign("release-v1.2.1") ~= sig)
return #sig
Details
  • Any change to the message changes the signature.
  • The module exposes no bare verify for these signatures. verify_request checks them over the sub:body framing in the next card.

Signed requests

sign_request signs sub .. ":" .. body, which binds a request to the account that sent it. verify_request checks the signature with only public values.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local body = "PUT:/items:42"
local sig = id:sign_request(body)
print("ok:", crypto.verify_request(id:public_key(), sig, id:sub(), body))
print("tampered body:", crypto.verify_request(id:public_key(), sig, id:sub(), "PUT:/items:43"))
local other = crypto.derive_identity("secret two", 1024, 1)
print("wrong signer:", crypto.verify_request(id:public_key(), other:sign_request(body), id:sub(), body))
print("garbage sig:", crypto.verify_request(id:public_key(), "AAAA", id:sub(), body))
return crypto.verify_request(id:public_key(), sig, id:sub(), body)
Details
  • So a server can hold no passwords, just public keys, with every mutation arriving signed.
  • Failures, undecodable signatures included, come back as nil plus invalid_signature.

Data keys and AEAD

derive_key turns the same passphrase into an XChaCha20-Poly1305 data key. encrypt returns a self-contained base64 blob. decrypt authenticates before it returns a single byte.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local ct = key:encrypt("attack at dawn")
print("ciphertext:", ct)
print("plaintext:", key:decrypt(ct))
local id2 = crypto.derive_identity("secret two", 1024, 1)
local other = crypto.derive_key("secret two", id2)
print("wrong key:", other:decrypt(ct))
return key:decrypt(ct)
Details
  • derive_key reuses the identity's cached master, so Argon2id doesn't run again.
  • A wrong key yields nil and an error string. decrypt never returns garbage plaintext.

Fresh nonces

Each encrypt call draws a random 24-byte XChaCha20 nonce. So two encryptions of the same plaintext under the same key give unrelated ciphertexts that both decrypt.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local a = key:encrypt("same message")
local b = key:encrypt("same message")
print("distinct ciphertexts:", a ~= b)
print("a decrypts:", key:decrypt(a))
print("b decrypts:", key:decrypt(b))
return a ~= b

Ciphertext layout

The blob is the base64 of a version byte, the nonce, the ciphertext and the Poly1305 tag. santoku.string's codec functions take it apart.

local crypto = require("santoku.monocypher")
local str = require("santoku.string")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local pt = "attack at dawn"
local raw = str.from_base64(key:encrypt(pt))
print("version:", raw:byte(1))
print("total bytes:", #raw, "= 1 + 24 + " .. #pt .. " + 16")
print("nonce:", str.to_hex(raw:sub(2, 25)))
print("tag:", str.to_hex(raw:sub(#raw - 15)))
print("aad version:", str.from_base64(key:encrypt(pt, "ctx")):byte(1))
return #raw == 1 + 24 + #pt + 16
Details

| Field | Size | |---|---| | version | 1 byte: 1 plain, 2 AAD-bound | | nonce | 24 bytes | | ciphertext | the length of the plaintext | | Poly1305 tag | 16 bytes |

AAD-bound ciphertext

Associated data passed to encrypt binds the blob to a context string. encrypt authenticates that string but doesn't store it in the blob. Pin each encrypted record to its id and clock this way.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local ct = key:encrypt("hello", "sub:id-1")
print("right aad:", key:decrypt(ct, "sub:id-1"))
print("wrong aad:", key:decrypt(ct, "sub:id-2"))
print("no aad:", key:decrypt(ct))
return key:decrypt(ct, "sub:id-1")
Details

A valid blob replayed under a different context then refuses to open.

Decrypt failure modes

decrypt never raises. It returns nil plus one of the strings below.

local crypto = require("santoku.monocypher")
local str = require("santoku.string")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
print("truncated:", key:decrypt("AA"))
print("unknown version:", key:decrypt(str.to_base64(str.char(3) .. str.rep("x", 40))))
local ct = key:encrypt("hello", "sub:1")
print("missing aad:", key:decrypt(ct))
print("wrong aad:", key:decrypt(ct, "sub:2"))
local raw = str.from_base64(key:encrypt("hello"))
local flipped = raw:sub(1, 29) .. str.char((raw:byte(30) + 1) % 256) .. raw:sub(31)
print("bit flipped:", key:decrypt(str.to_base64(flipped)))
return select(2, key:decrypt(ct, "sub:2"))
Details
  • unsupported version: a truncated blob or an unknown version byte.
  • aad mismatch: the caller's AAD presence disagrees with the blob's version byte.
  • decryption failed: the Poly1305 tag rejected the key, the AAD value, or a flipped ciphertext bit.

Domain-separated subkeys

derive spawns a deterministic subkey per label, an HMAC of the parent key over the label. bytes exposes the raw 32-byte material to hand to other systems.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local dbkey = key:derive("db")
local searchkey = key:derive("search")
print("deterministic:", dbkey:bytes() == key:derive("db"):bytes())
print("separated:", dbkey:bytes() ~= searchkey:bytes())
print("distinct from parent:", dbkey:bytes() ~= key:bytes())
print("raw length:", #dbkey:bytes())
local ct = dbkey:encrypt("row data")
print("cross-domain decrypt:", searchkey:decrypt(ct))
return dbkey:decrypt(ct)
Details
  • For example, feed a subkey's bytes to an encrypting SQLite VFS.
  • Subkeys never decrypt each other's output.

A keyed fingerprint

key:hmac(msg) is exactly hmac_sha256 keyed by the key's raw bytes, returned as 64 hex characters. It's a deterministic, key-private fingerprint to name files or rows without revealing what they are.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local h = key:hmac("doc:42")
print("keyed hex:", h)
print("equals module fn:", h == crypto.hmac_sha256(key:bytes(), "doc:42"))
print("stable:", key:hmac("doc:42") == h)
print("input-bound:", key:hmac("doc:43") ~= h)
return #h

HMACs and const_eq

hmac_sha256, hmac_sha1 and hmac_md5 take any key string and return lowercase hex. const_eq compares strings in constant time. Always compare secrets with const_eq, never with ==.

local crypto = require("santoku.monocypher")
local mac = crypto.hmac_sha256("server-pepper", "user@example.com")
print("hmac_sha256:", mac)
print("hex length:", #mac)
print("rfc 2202:", crypto.hmac_sha1("Jefe", "what do ya want for nothing?"))
print("hmac_md5:", crypto.hmac_md5("Jefe", "what do ya want for nothing?"))
print("equal:", crypto.const_eq(mac, crypto.hmac_sha256("server-pepper", "user@example.com")))
print("different key:", crypto.const_eq(mac, crypto.hmac_sha256("other-pepper", "user@example.com")))
print("length mismatch:", crypto.const_eq(mac, mac:sub(1, 32)))
return crypto.const_eq(mac, crypto.hmac_sha256("server-pepper", "user@example.com"))
Details
  • The SHA-1 and MD5 variants exist for legacy protocols, such as TOTP below and old session cookies.
  • The SHA-1 and MD5 variants match the RFC 2202 test vectors.
  • const_eq returns false immediately only on a length mismatch.

Legacy PBKDF2 hashes

pbkdf2_sha512(password, salt, iterations, keylen) returns keylen raw bytes of PBKDF2 over HMAC-SHA-512. pbkdf2_verify(hash, password) checks a Crypt::PBKDF2 LDAP hash in constant time and returns true or false.

local crypto = require("santoku.monocypher")
local str = require("santoku.string")
local err = require("santoku.error")
local key = crypto.pbkdf2_sha512("password", "salt", 1, 64)
print("rfc vector:", str.sub(str.to_hex(key), 1, 16))
local salt = "pepper-salt"
local hash = "{X-PBKDF2}HMACSHA2+512:" .. str.to_base64(str.char(0, 0, 39, 16)) .. ":" ..
  str.to_base64(salt) .. ":" .. str.to_base64(crypto.pbkdf2_sha512("correct-horse-battery", salt, 10000, 64))
print("right:", crypto.pbkdf2_verify(hash, "correct-horse-battery"))
print("wrong:", crypto.pbkdf2_verify(hash, "correct-horse-batterz"))
print(err.pcall(crypto.pbkdf2_verify, "{X-PBKDF2}HMACSHA2+256:AAAnEA:AAEC:AAECAwQFBgcICQ==", "x"))
print("zero iterations raises:", (err.pcall(crypto.pbkdf2_sha512, "pw", "salt", 0, 64)))
return #key
Details
  • iterations runs 1 to 2^32-1 and keylen 1 to 4096. Anything outside raises.
  • The LDAP hash is {X-PBKDF2}HMACSHA2+512:<iterations>:<salt>:<hash>. Each field is base64, and the iteration count is a 4-byte big-endian integer.
  • A string under 31 bytes returns false. A malformed string, or a hash from another hasher, raises.
  • Use these functions to accept passwords from an older system. hash_password is the scheme for new passwords.

A webhook signature check

The Stripe-style webhook check takes three lines. Recompute the HMAC over timestamp.payload with the endpoint secret, and compare with const_eq.

local crypto = require("santoku.monocypher")
local str = require("santoku.string")
local whsec = "whsec_demo_secret"
local payload = '1724000000.{"id":"evt_1","type":"invoice.paid"}'
local signature = crypto.hmac_sha256(whsec, payload)
local function verify (sig, body)
  return crypto.const_eq(sig, crypto.hmac_sha256(whsec, body))
end
print("genuine:", verify(signature, payload))
print("tampered:", verify(signature, payload .. "x"))
print("forged:", verify(str.rep("0", 64), payload))
return verify(signature, payload)
Details

The same check works for any HMAC-signed callback.

A complete TOTP generator

hmac_sha1 is enough to implement RFC 6238 time-based one-time codes in a dozen lines. For the RFC test key at t=59 the code prints the published vector 94287082.

local crypto = require("santoku.monocypher")
local arr = require("santoku.array")
local str = require("santoku.string")
local num = require("santoku.num")
local function totp (key, now, period, digits)
  local counter = num.floor(now / period)
  local msg = {}
  for i = 8, 1, -1 do
    msg[i] = str.char(counter % 256)
    counter = num.floor(counter / 256)
  end
  local hex = crypto.hmac_sha1(key, arr.concat(msg))
  local offset = tonumber(str.sub(hex, 40, 40), 16)
  local v = tonumber(str.sub(hex, offset * 2 + 1, offset * 2 + 8), 16) % 0x80000000
  local code = tostring(num.floor(v % 10 ^ digits))
  while #code < digits do code = "0" .. code end
  return code
end
print("rfc 6238 t=59:", totp("12345678901234567890", 59, 30, 8))
print("rfc 6238 t=1111111109:", totp("12345678901234567890", 1111111109, 30, 8))
print("6-digit now-style:", totp("12345678901234567890", 1724000000, 30, 6))
return totp("12345678901234567890", 59, 30, 8)
Details

The steps are a big-endian counter, dynamic truncation from the last hex nibble, and modulo 10^digits.

Bulk keyed hashing

hash_ivec HMACs every int64 in a santoku.ivec in place and returns the same vector. Each element becomes the leading 8 bytes of its keyed hash.

local crypto = require("santoku.monocypher")
local ivec = require("santoku.ivec")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local tokens = ivec.create({ 101, 202, 303 })
local hashed = key:hash_ivec(tokens)
print("same object:", hashed == tokens)
local again = ivec.create({ 101, 202, 303 })
key:hash_ivec(again)
print("deterministic:", tokens:get(0) == again:get(0))
local other = key:derive("other"):hash_ivec(ivec.create({ 101, 202, 303 }))
print("key-dependent:", tokens:get(0) ~= other:get(0))
return tokens:size()
Details
  • hash_ivec exists to blind whole token-id vectors, such as search indexes, in one C-side pass.
  • The result is deterministic per key and unlinkable across keys.

Export and import

export serializes an identity to a plain table and a key to one base64 string, ready for JSON or sessionStorage. Imported identities sign identically.

local crypto = require("santoku.monocypher")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local blob = id:export()
print("fields:", blob.sub == id:sub(), blob.public_key == id:public_key())
print("params travel:", blob.argon2_memory, blob.argon2_passes)
local id2 = crypto.import_identity(blob)
print("signs identically:", id2:sign("x") == id:sign("x"))
local key2 = crypto.import_key(key:export())
print("key roundtrip:", key2:bytes() == key:bytes())
local rekeyed = crypto.derive_key("secret one", id2)
print("re-derived from import:", rekeyed:bytes() == key:bytes())
return key2:export()
Details
  • The identity table holds sub, signing_key, public_key and the Argon2 parameters.
  • Because the Argon2 parameters travel along, derive_key on an imported identity reruns Argon2id with the original settings. It lands on the same key.

Wipe and wiped

key:wipe() and identity:wipe() zero the secret bytes in place. The garbage collector runs the same wipe on anything left unwiped.

local crypto = require("santoku.monocypher")
local err = require("santoku.error")
local key = crypto.derive_key("secret one", crypto.derive_identity("secret one", 1024, 1))
key:wipe()
key:wipe()
print("wiped:", key:wiped())
local ok, e = err.pcall(key.bytes, key)
print("use after wipe:", ok, e)
return key:wiped()
Details
  • wipe is idempotent, and wiped() reports whether the object is wiped.
  • Any later use of the object raises "key has been wiped" or "identity has been wiped".

P-256 ECDSA

p256_keypair() returns a raw 32-byte private key and a 64-byte public key. p256_sign(priv, digest) returns a raw 64-byte r and s. p256_verify(pub, sig, digest) returns true or false.

local crypto = require("santoku.monocypher")
local str = require("santoku.string")
local priv, pub = crypto.p256_keypair()
print("sizes:", #priv, #pub)
local digest = str.sha256("message to sign")
local sig = crypto.p256_sign(priv, digest)
print("signature bytes:", #sig)
print("verifies:", crypto.p256_verify(pub, sig, digest))
print("other message:", crypto.p256_verify(pub, sig, str.sha256("other")))
return crypto.p256_verify(pub, sig, digest)
Details
  • The public key is x then y, with no 0x04 prefix.
  • p256_sign signs a digest you compute, usually SHA-256.
  • Signatures are randomized, so two signs of one digest differ and both verify.
  • p256_verify returns false for a key or signature of the wrong length.
  • Use P-256 only for a protocol that names it, such as WebAuthn or ES256 JWTs. Prefer the EdDSA identity above otherwise.

Wrap and unwrap keys

wrap_key seals a key's 32 bytes under an external 32-byte secret with the same AEAD envelope. It's the primitive to hand custody to something outside the passphrase.

local crypto = require("santoku.monocypher")
local str = require("santoku.string")
local id = crypto.derive_identity("secret one", 1024, 1)
local key = crypto.derive_key("secret one", id)
local wrap = str.rep(str.char(0x42), 32)
local wrapped = crypto.wrap_key(key, wrap)
print("wrapped:", wrapped)
local unwrapped = crypto.unwrap_key(wrapped, wrap)
print("roundtrip:", unwrapped:bytes() == key:bytes())
print("wrong wrap:", crypto.unwrap_key(wrapped, str.rep(str.char(0x43), 32)))
print("bad size:", crypto.wrap_key(key, "tooshort"))
print("fresh nonce:", crypto.wrap_key(key, wrap) ~= wrapped)
return unwrapped:bytes() == key:bytes()
Details
  • An example is a hardware-held secret that restores the data key on biometric unlock.
  • Wrong wrap bytes fail authentication, and wrong sizes are rejected outright.
  • Each wrap uses a fresh nonce.

A tiny vault

One passphrase and one Argon2id run give a db subkey. Each record is AEAD-sealed with its own id as AAD, so blobs can't be shuffled. The server verifies a signed manifest without ever seeing a key.

local crypto = require("santoku.monocypher")
local arr = require("santoku.array")
local secret = "canyon ethics sushi hazelnut opera trend"
local id = crypto.derive_identity(secret, 1024, 1)
local key = crypto.derive_key(secret, id)
local dbkey = key:derive("db")
local rows = { ["note:1"] = "buy milk", ["note:2"] = "renew passport" }
local sealed, ids = {}, {}
for rid, text in pairs(rows) do
  sealed[rid] = dbkey:encrypt(text, rid)
  ids[#ids + 1] = rid
end
arr.sort(ids)
local manifest = arr.concat(ids, ";")
local sig = id:sign_request(manifest)
print("manifest ok:", crypto.verify_request(id:public_key(), sig, id:sub(), manifest))
print("note:1:", dbkey:decrypt(sealed["note:1"], "note:1"))
print("shuffled blob:", dbkey:decrypt(sealed["note:1"], "note:2"))
return dbkey:decrypt(sealed["note:2"], "note:2")
Details