@vauban-pay/substrate
v0.1.0
Published
TypeScript reference runner for JCS (RFC 8785) preimage discipline in x402 STARK Receipt Format Extension (draft-vauban-x402-stark-receipts).
Downloads
175
Maintainers
Readme
@vauban-pay/substrate
TypeScript reference runner for JCS (RFC 8785) preimage discipline in the x402 STARK Receipt Format Extension (draft-vauban-x402-stark-receipts).
Sister implementations:
- Rust:
vauban-x402-jcs-conformancev0.1.0 (live on crates.io) - Python:
vauban-x402-stark-receipt
Install
pnpm add @vauban-pay/substrateAPI
import { jcsCanonicalBytes, jcsSha256, jcsHash, validatePairInvariant } from "@vauban-pay/substrate";
// Canonical UTF-8 bytes (RFC 8785 key sort, no whitespace)
const bytes: Uint8Array = jcsCanonicalBytes({ amount: 100, currency: "STRK" });
// SHA-256 over canonical bytes, prefixed "sha256:<hex64>"
const digest: string = jcsSha256({ amount: 100, currency: "STRK" });
// => "sha256:a3f9..."
// Both in one call (camelCase TS; Rust struct uses snake_case)
const { base64Canonical, sha256 } = jcsHash({ amount: 100, currency: "STRK" });
// Pair invariant: key order is irrelevant, array order is significant
const ok: boolean = validatePairInvariant({ a: 1, b: 2 }, { b: 2, a: 1 }); // trueRust/TS name mapping (snake_case Rust; camelCase TS):
jcs_canonical_bytes ; jcsCanonicalBytes |
jcs_sha256 ; jcsSha256 |
jcs_hash ; jcsHash |
validate_pair_invariant ; validatePairInvariant
Errors surface as CanonicalisationError (subclass of Error).
Spec reference
IETF I-D: draft-vauban-x402-stark-receipts-00 RFC 8785 (JCS): https://www.rfc-editor.org/rfc/rfc8785
License
Apache-2.0 - Vauban Research [email protected] - https://pay.vauban.tech
