By The Deed SDK · v1.0.0
Current release · v1.2.0
Proof-of-Play infrastructure, built for TypeScript.
Capture typed gameplay actions, evaluate deterministic achievement rules, and issue portable credentials—offline first, with optional OpenAI interpretation and Solana publication.
Typed by default
Generic event maps catch invalid gameplay payloads before release.
Deterministic core
Game-defined rules remain in the critical verification path.
Adapters, not lock-in
Storage, transport, AI, and chain integrations are replaceable.
Installation
Install the Community SDK with npm. Node.js 20 or newer is supported. Browser builds must never include API keys, OpenAI credentials, wallet material, or signing secrets.
npm i @btdworks/sdkServer-only secrets
OpenAI interpretation, protected transport credentials, and signing keys belong on a trusted server—not in game clients.
Five-minute quick start
This complete path starts a session, defines a typed achievement, captures evidence, verifies it, and issues a credential.
import {
BtdClient,
MemoryStorage,
MockTransport,
achievement,
event,
} from "@btdworks/sdk";
type GameEvents = {
enemy_defeated: {
enemyId: string;
critical: boolean;
};
};
const btd = new BtdClient<GameEvents>({
gameId: "arena-legends",
environment: "development",
storage: new MemoryStorage(),
transport: new MockTransport(),
});
const session = await btd.sessions.start({ playerId: "player_123" });
btd.achievements.register(
achievement("boss-breaker")
.named("Boss Breaker")
.when(
event("enemy_defeated")
.where("enemyId", "equals", "boss_01")
.and("critical", "equals", true),
)
.build(),
);
await btd.capture("enemy_defeated", {
enemyId: "boss_01",
critical: true,
});
const result = await btd.verify("boss-breaker", {
playerId: "player_123",
sessionId: session.sessionId,
});
if (result.verified) {
const credential = await btd.credentials.issue(result);
console.log(credential);
}Core concepts
Game
The stable game identity and runtime environment.
Player
An opaque player reference; personal information is not required.
Session
An ordered evidence boundary for one player and play period.
Gameplay event
A typed, validated action with timestamp and sequence.
Achievement
A versioned, JSON-serializable deterministic rule tree.
Credential
A portable claim containing the evidence digest and proof.
Complete flow
Typed gameplay events
The event map is the integration contract between your game and the SDK. Event names become literal types, while each name receives its own payload schema at compile time.
type ArenaEvents = {
match_started: { mode: "ranked" | "casual"; mapId: string };
enemy_defeated: {
enemyId: string;
weapon: string;
damage: number;
critical: boolean;
};
match_completed: {
score: number;
placement: number;
durationMs: number;
};
};
const btd = new BtdClient<ArenaEvents>({
gameId: "arena-legends",
environment: "development",
});Runtime validation protects the event envelope, while application-level Zod schemas should validate payloads that originate outside trusted game code. Duplicate IDs, sequence regressions, unsafe property paths, oversized payloads, and closed sessions are rejected.
Achievement rules
Rules are plain JSON data. They can be reviewed in source control, stored in a trusted configuration service, and versioned independently from SDK releases.
const flawlessRun = achievement("flawless-run")
.named("Flawless Run")
.versioned(1)
.when(
and(
event("enemy_defeated")
.where("critical", "equals", true)
.build(),
count("enemy_defeated", "gte", 10),
sequence(
["match_started", "enemy_defeated", "match_completed"],
15 * 60_000,
),
),
)
.within(30 * 60_000)
.build();Verification
Verification evaluates deterministic rules against normalized evidence. A failed result remains useful: it includes stable reason codes, matched event IDs, individual branch results, confidence, and a canonical SHA-256 evidence digest.
Load evidence
Evaluate rules
Return explainable result
Portable credentials
Credential issuing rejects unverified results. The resulting JSON is inspired by verifiable credential data models without claiming full W3C VC conformance. It includes issuer, subject, game, achievement, evidence digest, timestamps, and a digest or injected signature proof.
Optional OpenAI interpretation
Context, never unchecked authority.
The server-only adapter uses structured output and minimized event context. AI is supplementary by default and cannot independently approve a credential unless the achievement explicitly allows it and the confidence threshold passes.
Optional Solana publishing
Import Solana support from @btdworks/sdk/solana. The proof builder canonicalizes and hashes a credential, while the injected adapter owns transaction construction, signing, submission, and confirmation.
Privacy by boundary
Publish the digest—not raw gameplay evidence—unless players clearly consent otherwise.
Storage and transport adapters
Use MemoryStorage for tests and offline Node environments, LocalStorageAdapter for guarded browser persistence, HttpTransport for remote services, and MockTransport for deterministic examples. Custom adapters keep the SDK independent from databases and frameworks.
Configuration reference
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
| gameId | string | Yes | — | Stable identity for your game. |
| environment | development | staging | production | Yes | — | Runtime environment. |
| storage | StorageAdapter | No | Memory | Session and evidence persistence. |
| transport | TransportAdapter | No | None | Optional remote service boundary. |
| interpreter | Interpreter | No | None | Optional contextual interpretation. |
| maxPayloadBytes | number | No | 65,536 | Maximum event payload size. |
| eventBufferLimit | number | No | 1,000 | Maximum buffered events. |
Errors and observability
Catch BtdError and branch on stable codes such as INVALID_EVENT, DUPLICATE_EVENT, SESSION_CLOSED, VERIFICATION_FAILED, INTERPRETATION_FAILED, and SOLANA_PUBLISH_FAILED. Lifecycle subscriptions expose capture, verification, credential, and publication progress without allowing listener failures to interrupt SDK operations.
Security and trust boundaries
Deterministic validation
Rules prove which supplied evidence matched; they do not establish that a compromised client was honest.
Protected secrets
API keys, OpenAI credentials, signing keys, and wallet material stay server-side.
Authoritative telemetry
Use server events for competitive or economically valuable achievements.
Explicit boundaries
Interpretation, signing, and onchain publication provide different guarantees.
Roadmap
Planned capabilities are directional and do not have promised dates.
- Unity package and editor tooling
- Unreal Engine plugin
- Godot addon
- Hosted rule dashboard
- Managed verification
- Batch and streaming ingestion
- Anti-cheat and anomaly signals
- Cross-game reputation
- Credential revocation
- Solana compressed credentials
- Webhooks and realtime subscriptions
- Analytics and gameplay funnels
Changelog
Current SDK release
- Advanced the stable By The Deed SDK release line to v1.2.0.
- Maintains typed capture, deterministic verification, portable credentials, optional interpretation, and adapter-first architecture.
Batch capture observability and security hardening
- Updated the package version to 1.1.0 while preserving existing v1 public APIs.
- Added the event.batch.captured lifecycle event for batch observability.
- Batch capture now performs complete payload-schema, size, and intra-batch duplicate checks before buffering any event.
- Credential verification now fails closed when a signed credential is checked without a compatible signature verifier.
Initial production release
- Initial production release with typed capture, deterministic achievements, verification, portable credentials, optional OpenAI interpretation, and Solana adapter boundary.