TokenPass

API Reference

Complete REST API documentation for TokenPass Server

TokenPass Server exposes a REST API on http://localhost:21000. All endpoints are prefixed with /api/ and accept/return JSON.

TokenPass uses a two-step authentication: first unlock the wallet with /api/login, then get access tokens with /api/auth.

Quick Start

Register a Wallet (First Time Only)

curl -X POST http://localhost:21000/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "password": "my-secure-password",
    "displayName": "Alice"
  }'

Login (Unlock Wallet)

curl -X POST http://localhost:21000/api/login \
  -H "Content-Type: application/json" \
  -d '{"password": "my-secure-password"}'

Get an Access Token

curl -X POST http://localhost:21000/api/auth \
  -H "Content-Type: application/json" \
  -d '{
    "password": "my-secure-password",
    "host": "example.com",
    "expire": "1h",
    "scopes": "sign,encrypt"
  }'

Use the Token

curl -X POST http://localhost:21000/api/sign \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -d '{"message": "Hello World"}'

Endpoints


Wallet Management

POST /api/register

Create a new wallet with an encrypted master seed. Only call this once during initial setup.

{
  "password": "string (required)",
  "displayName": "string (optional)",
  "paymail": "string (optional)",
  "logo": "string (optional, URL or data URI)"
}
FieldTypeDescription
passwordstringPassword to encrypt the master seed
displayNamestringYour display name
paymailstringYour paymail address
logostringProfile image URL or data URI
{
  "success": true
}

POST /api/login

Unlock the wallet by decrypting the master seed.

{
  "password": "string (required)"
}
{
  "success": true
}

Must be called after server restart or /api/logout before using protected endpoints.


POST /api/logout

Lock the wallet by clearing the in-memory decrypted seed.

{
  "success": true
}

GET /api/status

Check the current wallet status.

{
  "seed": true,
  "unlocked": true,
  "keys": [...],
  "states": [...]
}
FieldTypeDescription
seedbooleantrue if wallet exists
unlockedbooleantrue if wallet is unlocked
keysarrayDerived keys (empty if locked)
statesarrayAccess token states (empty if locked)

POST /api/export

Export the master seed and mnemonic phrase.

Never share your seed or mnemonic. Anyone with access has full control of your identity.

{
  "password": "string (required)"
}
{
  "seed": "hex-encoded-seed",
  "mnemonic": "twelve or twenty-four word phrase"
}

Access Tokens

POST /api/auth

Generate an OAuth-style access token for a specific web host.

{
  "password": "string (required)",
  "host": "string (required)",
  "expire": "string (optional, default: 'once')",
  "scopes": "string (optional, comma-separated)",
  "icon": "string (optional)"
}

Expire Options:

ValueDuration
once10 seconds (default)
1h1 hour
1d1 day
1w1 week
1m1 month
foreverNo expiration

Scope Options:

ScopeDescription
signSign messages
encryptEncrypt messages
decryptDecrypt messages
read_profileRead BAP identity
write_profileModify BAP identity
read_stateRead per-host state
write_stateWrite per-host state
fundRequest funding/payment
transferTransfer tokens/assets
{
  "success": true,
  "accessToken": "uuid-v4-token",
  "expireTime": 1234567890123,
  "host": "example.com"
}

Cryptographic Operations

POST /api/sign

Sign a message with the derived Bitcoin private key for the authenticated host.

Requires Authorization: ACCESS_TOKEN header (no "Bearer" prefix)

{
  "message": "string (required)",
  "encoding": "string (optional, default: 'utf8')"
}
FieldTypeDescription
messagestringThe message to sign
encodingstringutf8, hex, or base64
{
  "address": "1BitcoinAddress...",
  "sig": "signature-string",
  "message": "original-message",
  "ts": 1234567890123
}

POST /api/encrypt

Encrypt a message using ECIES.

Requires Authorization: ACCESS_TOKEN header with encrypt scope

{
  "message": "string (required)"
}
{
  "encrypted": "encrypted-message-data"
}

Identity Management

GET /api/profile

Retrieve the global BAP identity profile. No authentication required.

{
  "host": "global",
  "displayName": "Alice",
  "paymail": "alice@example.com",
  "logo": "https://...",
  "bapID": "identity-key-string"
}

POST /api/profile

Update the global BAP identity profile.

{
  "displayName": "string (optional)",
  "paymail": "string (optional)",
  "logo": "string (optional)",
  "customField": "any value"
}
{
  "success": true
}

Error Handling

All errors return a consistent format:

{
  "error": "Error message description",
  "code": 1,
  "success": false
}
CodeDescription
1Wallet is locked
2Missing authorization header
3Invalid access token
5Access token has expired
HTTP StatusDescription
200Success
400Bad Request - missing required fields
401Unauthorized - invalid password or token
417Expectation Failed - wallet not created
500Internal Server Error

Configuration

CORS

Configure allowed origins:

TOKENPASS_ORIGIN_WHITELIST=https://app1.com,https://app2.com bun dev

Storage

All data is stored in ~/.tokenpass/:

FileDescription
seed.dbEncrypted master seed (AES-256-CBC)
keys.dbDerived Bitcoin keys per host
state.dbAccess tokens and per-host state

On this page