@intentrail/core
v1.0.0
Published
Core schemas, types, validators, and error taxonomy for IntentRail
Maintainers
Readme
@intentrail/core
Core schemas, types, validators, and error taxonomy for IntentRail.
Installation
npm install @intentrail/core
# or
pnpm add @intentrail/coreUsage
Validation
import { validateManifest, safeValidateManifest } from "@intentrail/core";
// Throws on invalid input
const manifest = validateManifest(untrustedData);
// Returns result object instead of throwing
const result = safeValidateManifest(untrustedData);
if (result.success) {
console.log(result.data);
} else {
console.error(result.errors);
}Hashing
import { hashManifest, hashManifestSync } from "@intentrail/core";
// Async (works everywhere)
const hash = await hashManifest(manifest);
// Sync (Node.js only)
const hash = hashManifestSync(manifest);Canonicalization
import { canonicalizeManifest, getCanonicalBytes } from "@intentrail/core";
// Get canonical JSON string
const canonical = canonicalizeManifest(manifest);
// Get UTF-8 bytes for hashing
const bytes = getCanonicalBytes(manifest);Errors
import {
IntentExpiredError,
InvalidSignatureError,
ConstraintViolationError,
} from "@intentrail/core";
try {
// ... validation logic
} catch (error) {
if (error instanceof IntentExpiredError) {
console.log("Intent expired at:", error.field);
}
}Types
All TypeScript types are exported:
import type {
IntentManifest,
CreateIntentInput,
VerificationResult,
IntentSummary,
} from "@intentrail/core";License
MIT
