Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions typescript-sdk/scripts/unit-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ await assertRejects(
// ---- Receipt verification (end-to-end) ----

const receipt = {
verb: "summarize",
status: "success",
result: { summary: "test" },
metadata: {
Expand Down
15 changes: 11 additions & 4 deletions typescript-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export type RuntimeMetadata = {
};

export type CommandResponse<TResult = unknown, TError = unknown> = {
receipt: CanonicalReceipt<TResult, TError>;
receipt: CanonicalReceipt<TResult>;
runtime_metadata?: RuntimeMetadata;
};

export type LegacyBlendedReceipt<TResult = unknown, TError = unknown> = CanonicalReceipt<TResult, TError> & {
export type LegacyBlendedReceipt<TResult = unknown, TError = unknown> = CanonicalReceipt<TResult> & {
trace?: RuntimeMetadata;
};

Expand Down Expand Up @@ -128,6 +128,12 @@ export type ClientOptions = {
verify?: VerifyOptions;
};

export type ReceiptProtocolMetadata = {
verb: string;
version: string;
[k: string]: unknown;
};

export type CommonsRequestEnvelope<TBody extends Record<string, unknown> = Record<string, unknown>> = {
x402: ReceiptProtocolMetadata;
actor: string;
Expand Down Expand Up @@ -295,7 +301,7 @@ function extractReceipt(subject: CanonicalReceipt | CommandResponse | LegacyBlen

export function extractReceiptVerb(subject: CanonicalReceipt | CommandResponse | LegacyBlendedReceipt): string | null {
const receipt = extractReceipt(subject);
return isRecord(receipt.x402) && typeof receipt.x402.verb === "string" ? receipt.x402.verb : null;
return getReceiptVerb(receipt);
}

export function normalizeCommandResponse<T = unknown>(payload: unknown): CommandResponse<T> {
Expand Down Expand Up @@ -350,6 +356,7 @@ export async function verifyReceipt(receiptLike: CanonicalReceipt | CommandRespo
const hashMatches = claimedHash === recomputedHash;
const receiptId = typeof receipt.metadata?.receipt_id === "string" ? receipt.metadata.receipt_id : null;
const receiptIdMatches = !receiptId || !claimedHash ? true : receiptId === claimedHash;
const receiptIdPresent = typeof receiptId === "string";

let pubkey: Uint8Array | null = null;
let pubkey_source: "explicit" | "ens" | null = null;
Expand Down Expand Up @@ -396,7 +403,7 @@ export async function verifyReceipt(receiptLike: CanonicalReceipt | CommandRespo
},
values: {
verb: getReceiptVerb(receipt),
signer_id,
signer_id: signerId,
alg,
canonical,
claimed_hash: claimedHash,
Expand Down
Loading