This directory contains practical examples demonstrating PASETO, PASERK, and external implementation integration.
Each example selects only the capability factories or operation creators it needs. LocalProtocol
and PublicProtocol expose exactly the selected operations, allowing a bundler to discard other
versions, purposes, token operations, key lifecycle operations, and PASERK operations.
Local-purpose PASETO using only standard runtime APIs. Demonstrates:
- Generating a symmetric key
- Encrypting a
v3.localtoken - Authenticating and decrypting the token
Public-purpose PASETO using only standard runtime APIs. Demonstrates:
- Generating an asymmetric signing key pair
- Signing a
v4.publictoken - Authenticating the token and verifying its signature
Each example implements the version-bound LocalKey type from paseto/v2/local or
paseto/v4/local. Custom operations define their own key implementation because keys created by the
built-in capabilities are intentionally opaque to external implementations.
v2.local using @noble/ciphers and @noble/hashes through the extension API. Demonstrates:
- Defining an opaque application key type
- Providing key generation, encryption, and decryption capability factories
- Composing only those capabilities into a
v2.localprotocol
v4.local using @noble/ciphers and @noble/hashes through the extension API. Demonstrates:
- Implementing the v4.local BLAKE2b key derivation and authentication steps
- Providing key generation, encryption, and decryption capability factories
- Producing and consuming a token with an implicit assertion
PASERK key serialization without selecting any token operation. Demonstrates:
- Exporting an extractable local key
- Importing its plaintext PASERK serialization
- Calculating its PASERK key identifier
Repository-only @noble/* reference implementations used to test primitives that Web Cryptography
does not expose. This directory is private and is not published or supported as a separate package.
The reference implementations use the same public operation creators exported by paseto, such as
LocalEncrypt, LocalDecrypt, PublicSign, and PublicVerify. Applications can provide their own
key representations and implementations through those creators, then compose them alongside
compatible built-in operations.
Examples run directly with Node.js 22.19.0 or newer.
git clone https://github.com/panva/paseto.git
cd paseto
npm install
node examples/01-local.ts
node examples/04-v2-local-with-noble.ts
node examples/05-v4-local-with-noble.ts