Skip to content

v3.2.0

Latest

Choose a tag to compare

@dev-adamant-im dev-adamant-im released this 25 Nov 15:08
58ab6e4

adamant-api v3.2.0

SDK release coordinated with ADAMANT Node v0.11.0. This release includes critical security and correctness fixes: local Ed25519 + address-binding verification of recipient and delegate public keys before caching or encryption (#109 / #110), plain filter serialization for getKVS() and chat queries (#97), usable-node onReady readiness with capped startup backoff (#99), resilient HTTP 429 Too Many Requests failover and per-node cooldowns, POST /api/states/get support, OpenAPI DTO generation migrated to Adamant-im/adamant, and a 7-day npm dependency release-age quarantine with zero production audit vulnerabilities.

Important security & correctness upgrade notice: All v3.0.0 and v3.1.0 consumers should upgrade to v3.2.0:

  • Verifies recipient and delegate Ed25519 public keys and local address derivation before caching or encrypting messages (#109, #110).
  • Fixes getKVS(), getChatTransactions(), getChats(), and getChatMessages() sending and:-prefixed filters that pre-v0.11.0 nodes silently ignored while returning success: true with unfiltered network-wide records (#97).

Highlights

Recipient & delegate public-key verification (#109, #110)

  • Enforces canonical 32-byte on-curve Ed25519 validation (rejecting non-canonical, off-curve, and small-order Curve25519 keys of orders 1, 2, 4, and 8) and local ADM address derivation checks before caching or encrypting messages.
  • getPublicKey() returns '' without a network request for invalid ADM addresses and returns '' without poisoning the cache when a node returns a mismatched or malformed key.
  • sendMessage() locally re-verifies resolved recipient keys and rejects invalid/mismatched keys with {success: false, errorMessage}; voteForDelegate() rejects delegate keys failing address binding.
  • Uses a Map-backed publicKeysCache verified on both writes and reads, and isolates network-dependent delegate caches (byAddress, byUsername) per AdamantApi instance.

Security & correctness fix for KVS and chat filters

  • getKVS(), getChatTransactions(), getChats(), and getChatMessages() now emit plain filter names (flattening explicit and: { ... } wrappers), matching the documented node contract across every ADAMANT Node version.
  • Rejects unsupported or wrappers and pre-prefixed and: / or: filter keys on AND-only endpoints client-side with {success: false, errorMessage} instead of sending prefixes that older nodes ignore and v0.11.0+ nodes reject.
  • Verified with a recorded mainnet /api/states/get fixture test.

Usable-node readiness & loader filtering

  • Excludes nodes reporting loader.loaded: false or loader.syncing: true from primary active node selection and WebSocket connection lists, while keeping legacy nodes without a loader object eligible.
  • Holds onReady (and exposes api.isReady) until a usable node is actually selected, retrying startup checks with capped backoff (5s, 10s, 30s, 60s, continuing even if an earlier sweep throws) instead of waiting for the 5-minute periodic sweep.
  • When already initialized and all ready nodes fail or fall below minVersion, falls back with a warning to a minVersion-compatible loaded-but-syncing node only when a recent synced height reference is available (within 10 minutes) and the candidate is within 25 blocks of that height (checkHealthAtStartup: false without a prior synced sweep, lagging nodes, and loaded: false nodes are never selected).
  • Prevents double-firing onReady if the callback throws and safely skips non-object responses (e.g., HTML 200 maintenance pages), null, or incomplete {success: true} status payloads.

ADAMANT Node v0.11.0 API, OpenAPI & KVS POST alignment

  • Migrates deterministic API DTO generation (scripts/sync-api-types.mjs) from the archived Adamant-im/adamant-schema repo to Adamant-im/adamant (openapi/specification/openapi.yaml at released v0.11.0 master commit 50568f37dc2b7da86f44991f96c40c8edde74d67), reading exact installed tool versions via createRequire.
  • Regenerates src/api/generated.ts with RateLimitErrorResponseDto, GetKVSRequestBody, and updated https://docs.adamant.im/ links.
  • Aligns endpoint option types (ChatroomsOptions, new ChatTransactionsOptions, and KVSOptions) with ADAMANT Node v0.11.0 strict filter validation (toHeight enforced on /api/chats/get and /api/states/get; height/range filters excluded from /api/chatrooms/*).
  • Deprecates ChatroomsOptions.userId and strips it at runtime on /api/chatrooms/* with a dedicated one-time deprecation warning so legacy callers do not fail validation on v0.11.0+ nodes.
  • Adds POST /api/states/get support via api.getKVS(options, {method: 'POST'}) for large keyIds / senderIds queries, with full idempotent read failover matching GET.

Resilient HTTP 429 Too Many Requests & failover hardening

  • Captures targetNode before each request so concurrent failures never flip this.node back to a failed node.
  • Switches immediately to another cached synced, non-rate-limited node on multi-node HTTP 429 without extra /api/node/status probes; skips health sweeps on single-node 429 responses and handles 429 in checkNode() distinctly from offline nodes.
  • Deduplicates concurrent updateNodes() sweeps via an in-flight promise (updateNodesPromise) and upgrades an in-flight planned sweep to forced failover when a request reports a failed node.
  • Rotates away from failedNode across both 2-node and 3+-node synced sets and tracks per-node 429 cooldowns (rateLimitedUntil, capped at 60s) so forced and planned health sweeps avoid rate-limited nodes until cooldown expires.
  • Parses Retry-After (seconds or HTTP-date), RateLimit-Reset, and RateLimit-Scope headers; fails over immediately for idempotent reads (GET and POST /api/states/get) when another synced node exists, or honors bounded backoff with jitter (up to 10s) on a single node without tight-looping.
  • Exposes optional status, retryAfterMs, and rateLimitScope metadata on HTTP 429 failure results in AdamantApiResult, while keeping write POST requests strictly non-replayed.

Dependency security refresh & 7-day release-age quarantine

  • Enforces minimumReleaseAge: 10080 (7 days) and explicit allowBuilds ('@parcel/watcher': false, esbuild: true, unrs-resolver: true) in pnpm-workspace.yaml with zero release-age exclusions.
  • Refreshes direct and transitive dependencies past the 7-day cutoff (axios@^1.21.1, bitcoinjs-lib@^7.0.5, tiny-secp256k1@^2.2.5, pbkdf2@^3.1.7, socket.io-client@^4.8.4, bip39@^3.1.2, ecpair@^3.0.2, semver@^7.8.6, @redocly/cli@2.78.0, eslint@10.15.0, jest@^30.5.2, prettier@3.10.1, swagger-typescript-api@13.14.0, and more), reducing production audit findings from 20 to 0.
  • Publishes via GitHub Actions npm Trusted Publishing with build provenance.

Compatibility and migration notes

  • Strict Ed25519 key & address-binding verification (#109, #110):
    • encodeMessage() and decodeMessage() now throw invalid key for non-canonical, off-curve, and small-order (orders 1, 2, 4, 8) Ed25519 keys. Legitimate mainnet keys are unaffected.
    • getPublicKey() returns '' without a network request for invalid ADM addresses and also returns '' when the node's key does not derive the address.
    • sendMessage() rejects such recipients with {success: false, errorMessage}, and voteForDelegate() rejects delegate keys failing address binding.
  • TypeScript query option narrowing: ChatroomsOptions and KVSOptions no longer inherit unsupported TransactionQueryParameters fields that ADAMANT Node v0.11.0 rejects. getChatTransactions() now uses ChatTransactionsOptions (a superset of ChatroomsOptions retaining fromHeight, toHeight, inId, and isIn). TransactionQueryParameters remains exported unchanged.
  • transformTransactionQuery() throw behavior: Calling transformTransactionQuery(query, 'states' | 'chats' | 'chatrooms') directly with an or wrapper or pre-prefixed and: / or: filter keys now throws an Error with the badParameter message (whereas AdamantApi client methods return {success: false, errorMessage}).
  • toHeight on getKVS() / getChatTransactions(): Enforced only by ADAMANT Node v0.11.0+; older nodes silently ignore toHeight and return newer records with success: true, so callers relying on an upper height bound should set minVersion: '0.11.0'.
  • userId on /api/chatrooms/*: Deprecated on ChatroomsOptions and stripped at runtime with a dedicated warning; pass the account address only as the URL path argument of getChats(address) / getChatMessages(address1, address2).
  • onReady behavior: With checkHealthAtStartup: true, onReady now waits (and api.isReady stays false) until a usable, loaded, non-syncing node is selected, retrying startup checks with 5s → 10s → 30s → 60s backoff.
  • HTTP 429 failure metadata: Optional status, retryAfterMs, and rateLimitScope fields are added to the success: false variant of AdamantApiResult when a request fails with HTTP 429.

Transaction byte layout, hashes, IDs, signatures, encryption, wallet derivation, and root exports are unchanged.

Diff overview

  • 20 commits (16 non-merge commits)
  • 32 files changed, 6,490 insertions and 2,476 deletions

Validation

Verified on Node.js v24.19.0 and pnpm 11.13.1:

  • pnpm test — compile, typecheck, 20 suites and 333 tests (100% function coverage), and gts lint passed
  • pnpm run api-types:check — matches Adamant-im/adamant@50568f37dc2b7da86f44991f96c40c8edde74d67
  • pnpm run metadata:check — matches Adamant-im/adamant-wallets@54a820b6dc5e0ec77c3a6fbac91d2f7809a2f5b7
  • pnpm run docs:build — TypeDoc and VitePress build passed (vitepress dev also verified)
  • pnpm run test:package — ESM, CommonJS, live consumers, package subpaths, and TypeScript declarations passed
  • pnpm audit --prod --audit-level=moderate — 0 vulnerabilities
  • pnpm audit signatures — all 893 locked packages verified

Related

Full Changelog: v3.1.0...v3.2.0