Glossary: treetracker-wallet-api
Generated by .github/scripts/build-glossary.mjs from domain-graph.json (source commit e95c15a). Do not edit by hand.
This glossary lists the business terms of treetracker-wallet-api. Each term links to its domain, which says what the domain does, its rules, and its flows. The estate glossary shows which other repos use the same terms.
Terms
- ApiKey: Authentication
- bundle: Token Transfer
- Event (wallet_event): Event/Audit Logging
- JWT: Authentication
- sub-wallet / managed wallet: Wallet Management
- Token: Token Transfer, Token Query
- Transaction: Token Transfer, Token Query
- Transfer: Token Transfer
- Trust relationship (wallet_trust): Trust Relationship Management
- trust state: Trust Relationship Management
- trust type (send/manage/yield): Trust Relationship Management
- Wallet: Wallet Management
- Wallet credentials: Authentication
Domains
Authentication
Verifies caller identity for every request. Wallets sign in with a password to receive an RS256 JWT, and every protected route is gated by an API-key check and a JWT check before it reaches business logic.
Terms: Wallet credentials, ApiKey, JWT
Rules:
- Password is verified as an HMAC SHA-512 hash against the stored wallet hash, not plaintext.
- Every protected request needs a valid treetracker-api-key header before JWT verification runs.
- A JWT carries wallet_id and is required to resolve 'the logged-in wallet' for all downstream authorization checks.
Flows:
- Wallet Sign-In (
POST /auth): Authenticates a wallet by wallet identifier and password, returning a signed JWT for use on subsequent requests. - Request Authentication Middleware (
Express middleware chain on protected routes): Every protected request passes through API-key validation and JWT verification before reaching a route handler, resolving the acting wallet_id.
Wallet Management
Owns wallet accounts: creation, lookup, hierarchical parent/sub-wallet control, and batch provisioning. A wallet can be a standalone account or a sub-wallet managed by another wallet, and 'control-over' checks here underpin authorization everywhere else in the system.
Terms: Wallet, sub-wallet / managed wallet
Rules:
- Creating a wallet automatically grants the creator a trusted 'manage' relationship over it.
- A wallet controls another wallet if they are the same wallet or a trusted manage/yield sub-wallet relationship exists.
- Wallet listing unions self, child, and managed wallets so a manager can see everything it controls.
- Batch wallet creation and batch transfer are driven by uploaded CSV files.
Flows:
- Create Wallet (
POST /wallets): Creates a new sub-wallet under the requesting wallet, checking name uniqueness and granting the creator a manage trust relationship over the new wallet. - List and Look Up Wallets (
GET /wallets, GET /wallets/:id): Lists wallets visible to the requester (self, children, managed) or resolves a single wallet by id/name, enforcing control-over authorization. - Update Wallet (
PATCH /wallets/:id): Updates an existing wallet's mutable fields after verifying the requester controls it. - Batch Create Wallets (
POST /wallets/batch (multipart CSV upload)): Parses an uploaded CSV of wallet rows, validates each row, and creates the wallets in bulk. - Batch Transfer Tokens (
POST /wallets/batch-transfer (multipart CSV upload)): Parses an uploaded CSV of transfer rows, validates each row, and performs bulk token transfers between wallets.
Trust Relationship Management
Manages consent between wallets before tokens can move automatically. A wallet requests to 'send' to or 'manage'/'yield' another wallet; the target must accept before transfers between them can complete without manual approval.
Terms: Trust relationship (wallet_trust), trust type (send/manage/yield), trust state
Rules:
- Duplicate trust requests of the same type/direction between the same two wallets are rejected.
- Accepting a manage or yield relationship is rejected if it would create a management circle between wallets that already trust each other in the opposite direction.
- Only the wallet that controls the actor, target, or originator side may view, accept, decline, or cancel a given relationship.
- Declining sets state to cancelled-by-target; cancelling sets state to cancelled-by-originator.
Flows:
- Request Trust Relationship (
POST /trust_relationships): One wallet requests a send, manage, or yield trust relationship with another wallet, after duplicate and circular-management checks. - Accept or Decline Trust Request (
POST /trust_relationships/:id/accept, POST /trust_relationships/:id/decline): The target wallet of a pending trust request accepts it (transitioning to trusted, after a management-circle check) or declines it (transitioning to cancelled-by-target). - Cancel Trust Request (
DELETE /trust_relationships/:id): The originating wallet cancels a trust request it created, transitioning it to cancelled-by-originator. - List Trust Relationships (
GET /trust_relationships, GET /wallets/:id/trust_relationships): Lists trust relationships visible to the requesting wallet and its sub-wallets, with optional state/type/search filters.
Token Transfer
Moves tree-planting tokens between wallets, either as explicit named tokens or as unclaimed bundles selected by count. Transfers route to completed, pending, or requested state depending on trust and wallet-control relationships, and support accept, decline, cancel, and fulfill actions.
Terms: Transfer, Token, Transaction, bundle
Rules:
- A transfer completes immediately only if the sender's wallet already trusts the receiver (or the sender controls the receiver).
- Without trust, an explicit send becomes 'pending' (receiver must accept); a pull becomes 'requested' (sender must fulfill).
- Bundle transfers require the sender to have enough unclaimed tokens of the requested count before proceeding.
- Every state transition (initiate, accept, decline, cancel, fulfill) runs inside a database transaction and is logged as an audit event.
- Only the wallet controlling the appropriate side (sender/receiver) may accept, decline, cancel, or fulfill a transfer.
Flows:
- Initiate Transfer (
POST /transfers): Starts a token or bundle transfer between two wallets. Validates token ownership/availability, checks trust and control relationships, then completes, pends, or requests the transfer accordingly. - Accept Transfer (
POST /transfers/:id/accept): The receiving wallet accepts a pending transfer, completing the token/bundle movement and logging the state change. - Decline Transfer (
POST /transfers/:id/decline): The receiving wallet declines a pending or requested transfer, cancelling it and releasing the held tokens back to the sender. - Cancel Transfer (
DELETE /transfers/:id): The originating wallet cancels a pending or requested transfer it created, mirroring decline from the opposite side. - Fulfill Transfer Request (
POST /transfers/:id/fulfill): The sending wallet fulfills a requested (pull) transfer, either from its bundle or by supplying an explicit token list, completing the movement. - List and Look Up Transfers (
GET /transfers, GET /transfers/:id, GET /transfers/:id/tokens): Lists transfers visible to the requesting wallet and its sub-wallets with filters, or fetches a single transfer or its associated tokens by id.
Token Query
Read-only access to a wallet's tokens and their transaction history, with ownership checks ensuring a wallet can only see tokens it owns or controls.
Terms: Token, Transaction
Rules:
- A wallet may only fetch a token or its transactions if it owns or controls the owning wallet.
Flows:
- Query Tokens and Transactions (
GET /tokens, GET /tokens/:id, GET /tokens/:id/transactions): Lists a wallet's tokens, fetches a single token by id, and returns a token's transaction history, all with ownership authorization.
Event/Audit Logging
Records and exposes an audit trail of wallet activity (authentication, trust, transfer, wallet events) and lets a wallet query its own event history.
Terms: Event (wallet_event)
Rules:
- A wallet may only query events for a wallet it controls.
Flows:
- Log Audit Event (
Called internally by AuthService, TrustService, TransferService, WalletService): Internal flow invoked by other domains to persist a structured event record (auth, trust, transfer, or wallet type) whenever a meaningful state change occurs. - Query Wallet Events (
GET /events): Retrieves the audit event history for a wallet, subject to limit/since filters and control-over authorization.