By The DeedSDK Docsv1.0.0

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.

bash
npm i @btdworks/sdk

Server-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.

ts
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

Play
Capture
Interpret
Verify
Prove
Own

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.

ts
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.

ts
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();
AND / OR / NOT
Count & aggregate
Sequence & time window

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.

01

Load evidence

02

Evaluate rules

03

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

OptionTypeRequiredDefaultDescription
gameIdstringYesStable identity for your game.
environmentdevelopment | staging | productionYesRuntime environment.
storageStorageAdapterNoMemorySession and evidence persistence.
transportTransportAdapterNoNoneOptional remote service boundary.
interpreterInterpreterNoNoneOptional contextual interpretation.
maxPayloadBytesnumberNo65,536Maximum event payload size.
eventBufferLimitnumberNo1,000Maximum 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

v1.2.0

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.
v1.1.0

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.
v1.0.0

Initial production release

  • Initial production release with typed capture, deterministic achievements, verification, portable credentials, optional OpenAI interpretation, and Solana adapter boundary.
MIT licensed. Built by Btd Works.