VERDOCK

Node API

The exports of the npm package verdock, version 0.3.0. Node 18 or newer, zero runtime dependencies, the same receipts as the Python package.

On this page
Terminal
npm install verdock
npx verdock --help

The package is an ES module. A receipt written by Node verifies in Python and the other way round, with the same failure reasons.

Guard and decide#

Node
import verdock, { loadPolicy, decide } from 'verdock';

const decision = decide(loadPolicy('verdock.yaml'), 'payout', 1500, 'USD');

const payout = verdock.guard('payout', async ({ amountMinor, currency, counterparty, requestId }) => {
  return sendPayout(amountMinor, currency, counterparty, requestId);
}, {
  policyPath: 'verdock.yaml',
  stateDir: '.verdock',
  reconcile: async (requestId) => readPayoutRecord(requestId),
});

await payout({ amountMinor: 1500, currency: 'USD', counterparty: 'c1', requestKey: 'order-1017' });

reconcile returns { amountMinor, currency } or null. The decision has allowed, needsApproval, reason, limitMinor and approversRequired.

Exports#

AreaNames
PolicyLEVELS, RETRY_VALUES, parseYamlSubset, validatePolicy, loadsPolicy, loadPolicy, policyHash, decide
StoresApprovalStore, Invariants, OutcomeLog, LocalState
OutcomesVERIFIED, MISMATCH, UNKNOWN, PENDING, STATES, compare, mayRetry
ReceiptscanonicalBytes, buildLine, lineHash, createSeed, loadSeed, ReceiptLog, verifyBytes, verifyLog, canonical
DisclosureSENSITIVE, fieldSalt, commitment, protect, verifyDisclosure, disclose
ApprovalssignVote, checkEvidence
ManifestsManifestError, normalizeActions, widening, issueManifest, verifyChain, checkAction, checkDelegation, ManifestRegistry
Exchangerfc6238Totp, timeStep, boundCode, exchangeHash, signRole, attestCode, SendPolicy, draftExchange, verifyExchangeReceipt
Otherguard, exceptions, runDemo, runScenes, publicKey, VERSION, Refused, PolicyError, ReceiptError
AdaptersStripeAdapter, RazorpayAdapter, ProviderError, Result, loadEnv, also from verdock/adapters

Differences from Python#

  • State is kept in JSON files in the state folder (adapters.json, invariants.json, outcomes.json, receipts.ndjson) rather than SQLite, and is shared with guard. Receipt bytes are the same as the Python package.
  • Arguments are camelCase: amountMinor, requestKey, fundAccountId.
  • Producing exchanges over a store (request, approve, accept) and exceptions over SQLite files are Python commands. The Node package verifies exchange receipts and exposes the producers that the built in run uses.
  • Node 18 prints a runtime warning to stderr the first time an adapter uses fetch.

Commands are in the CLI reference.