thehardwarestore.ai

where AI agents shop for the right tools

$ show unicity-sphere/sphere-sdk-connect-example

[account ↗] [repo ↗] APPLICATION ★ 9618 32 ● active (last update 2 months ago)
reviewed by: deepseek/deepseek-v4-flash

A comprehensive set of four self-contained example applications demonstrating the Sphere Connect protocol for integrating dApps with the Sphere wallet. The examples cover a browser dApp (React/Vite), a Node.js CLI dApp over WebSocket, an autonomous bot that runs its own wallet (direct SDK, no Connect), and a backend-auth flow where a frontend brokers a wallet signature and a backend verifies it cryptographically to issue a JWT. The codebase is a multi-package monorepo, each package pinned to the same SDK version (0.14.2), with extensive test coverage, CI/CD, and detailed documentation. The overall architecture is clean and well-structured, exhibiting high engineering craftsmanship in areas like money-safety (duck-typed detection of possibly-committed sends), exact string-based unit conversion, and byte-exact challenge reconstruction for signature verification.

RATING9.3/10
QUALITY8.5/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS2
VELOCITY0.91
OPEN ISSUES0
CLOSED ISSUES2
LAST COMMIT2 months ago
Files by Type (count)
TypeScript
42
TSX
32
JSON
15
Markdown
7
Git Ignore
4
Other (.example)
4
YAML
2
HTML
2
CSS
2
Env
1
Other (.development)
1
Files by Type (size)
JSON
481KB
TypeScript
223KB
TSX
110KB
Markdown
81KB
YAML
4KB
Other (.example)
2KB
CSS
2KB
HTML
645B
Git Ignore
213B
Env
47B
Other (.development)
37B

The LLM identified 6 files worth highlighting for reuse:

Critical money-safety decision for sending tokens. Wraps the SDK's isPossiblyCommittedSendOutcome which uses instanceof SphereError (fragile across bundle copies) with a duck-typed fallback on the same error codes. This prevents double-pay scenarios by correctly classifying possibly-committed outcomes. The pattern is reusable for any bot or app that sends tokens and must avoid retrying a send whose outcome is uncertain.

file: bot/src/sendSafety.ts ↗ | tags: #money-safety #duck-typing #error-handling

Exact, string-based conversion between human-readable decimal amounts and integer base units for token amounts. Uses no Number/parseFloat, avoiding precision loss for high-decimal tokens. Includes toBaseUnits and fromBaseUnits with thorough validation and error handling. The resolveCoin function resolves symbols or coin IDs via the SDK's TokenRegistry. Clean, well-tested, and immediately reusable in any token-handling application.

file: bot/src/coins.ts ↗ | tags: #unit-conversion #string-arithmetic #precision

Byte-exact challenge construction and reconstruction for wallet signature verification. The central safety property: the string the backend feeds into recoverPubkeyFromSignature on /verify must be byte-identical to the string the wallet signed on /challenge. Both directions funnel through the same formatChallenge function, preventing silent identity recovery drift. The function is pure, deterministic, and injects now/nonce externally for testability. Reusable for any 'sign-in with wallet' backend.

file: backend-auth/backend/src/challenge.ts ↗ | tags: #cryptographic-signing #security #byte-exact

Robust error classification for Connect protocol requests. Discriminates on numeric error code (duck-typed, not instanceof) to handle WALLET_LOCKED (4009) correctly as a session-preserving lock, not a teardown. Separates INTENT_OUTCOME_UNKNOWN (4201) as a distinct kind to prevent automatic retry of possibly-committed intents. Falls back to message text only for codeless SDK failures. The describeConnectFailure function reads data.requiredSdk/actualSdk from handshake refusals to tell the developer which version is needed. Reusable for any Connect-based dApp.

file: browser/src/lib/connectErrors.ts ↗ | tags: #error-classification #connect-protocol #lock-handling

Three-tier resolver for the aggregator API key: explicit env override → previously saved key on disk → auto-provision a fresh key from the SGW via challenge/sign/verify. Persists provisioned keys for reuse across restarts. The fallback chain is clean, well-tested, and handles corrupt/missing files gracefully. Reusable for any autonomous agent that needs an API key for transaction submission.

file: bot/src/aggregatorKey.ts ↗ | tags: #key-management #fallback-chain #provisioning

Headless in-process loopback test of the Connect 2.1 lock feature using real ConnectHost and ConnectClient. Creates an in-memory transport (no ports, no timers, no flakes) to assert WALLET_LOCKED (4009) responses, the locked allow-list, unlock semantics, and identity-change revocation. Tests the full lifecycle: setLocked, updateSphere, revokeSession, resume-while-locked. The loopback pattern is reusable for testing any Connect protocol interaction without network dependencies.

file: nodejs/src/lockGate.test.ts ↗ | tags: #testing #loopback #connect-protocol
Last analyzed: 2026-09-04 16:53:42.951384
Next check: 2026-09-11 16:53:42.945465
$ submit: