Asentum

Build on Asentum

Secrets and Workers

Store API keys on chain, schedule outbound HTTP calls, all gated by smart contract. Estimated read time: 10 minutes

TL;DR

Your contract needs to call Stripe, Resend, OpenAI, Slack, or any other API on a schedule. You don't want to paste a credential into contract source. You don't want to trust an off-chain bot to fire the call without anyone being able to audit it. Vault lets you encrypt a secret to a hybrid post-quantum keypair and store the ciphertext on chain. Workers are off-chain processes that watch the chain for authorized requests, decrypt the secret in their own memory, perform the HTTP call, and post a signed receipt back. The whole flow is gated by smart contract code that anyone can read.

Asentum hosts a free default Worker at workerId asentum-hosted. You install one npm package and write 5 lines of JavaScript.

Why this exists

Every blockchain has the same gap. A smart contract that wants to do anything useful with the real world needs to call an API. Calling an API needs a credential. There's nowhere on chain to put the credential, because everything on chain is public.

Most chains punt this. You write an off-chain bot that watches your contract's events, holds the credential in its env vars, makes the call, hopes nobody asks too many questions. The bot becomes the system of record for who can fire what and when. The chain stops being a chain.

Vault + Workers is the answer. The credential is on chain, encrypted. The rules about who can trigger decryption live in smart contract code. The actual decryption and call happen in a Worker process, but the Worker is constrained by what the contract authorizes. Every fire shows up as an event. Every fulfillment shows up as a signed tx. Audit is built in.

How it works

┌─────────────────────────────────────────────────────────────┐
│                     Asentum Chain                            │
│                                                              │
│  ┌──────────────┐   ┌──────────────┐   ┌──────────────┐    │
│  │ Vault        │   │ Your         │   │ Worker       │    │
│  │ contract     │◄──┤ contract     │   │ Registry     │    │
│  │              │   │ (e.g. HR)    │   │ contract     │    │
│  │ - secrets    │   │              │   │              │    │
│  │ - authz      │   │ - cron sched │   │ - worker IDs │    │
│  │ - audit log  │   │ - on-tick    │   │ - pubkeys    │    │
│  └──────┬───────┘   └──────┬───────┘   └──────┬───────┘    │
│         │            cron fires               │             │
│         │                  │                  │             │
│         │                  ▼                  │             │
│         │     ┌────────────────────────┐      │             │
│         │     │ Event: WorkRequested   │      │             │
│         │     │ { workerId, jobId,     │      │             │
│         │     │   secretRef, payload } │      │             │
│         │     └───────────┬────────────┘      │             │
│         │                 │                   │             │
└─────────┼─────────────────┼───────────────────┼─────────────┘
          │                 │                   │
          ▼                 ▼                   ▼
┌──────────────────────────────────────────────────────────────┐
│                  Off-chain Worker                             │
│  1. Tail chain for own jobs                                   │
│  2. Decrypt secret (hybrid X25519 + ML-KEM-768)               │
│  3. Validate URL against integrations allowlist               │
│  4. Make HTTP call                                            │
│  5. Sign + post fulfillment tx back to chain                  │
└──────────────────────────────────────────────────────────────┘

The chain enforces the rules. The Worker just executes. Every step shows up on chain so anyone can audit who fired what, when, against which URL, and what the response hash was.

Which APIs you can call

A Worker can only reach hosts on the integrations allowlist. This is a large, curated set of well-known SaaS and API providers (AI models, messaging, automation, payments, developer tooling, CRM, commerce, and more) baked into the Worker itself, so the popular services you already use work out of the box. Browse the full list on the Integrations page.

If a host you need is not listed, it can be added through on-chain governance: an AsentumWorkerAllowlist contract records approved additions, and Workers pick them up automatically at the next refresh. The baked list plus any governance additions form the effective allowlist.

Underneath the allowlist sits a safety floor that cannot be relaxed: private, loopback, link-local, and cloud-metadata addresses are always refused, and DNS results are pinned to the address that was checked so a host cannot rebind to an internal target mid-request. Even an allowlisted host resolving to a private IP is rejected.

Install the SDK

npm install @asentum/vault-sdk

That's it. The SDK handles the hybrid X25519 + ML-KEM-768 + ChaCha20-Poly1305 encryption, derives the deterministic sid and jobId identifiers, builds and signs the Vault transactions, and submits them to a chain RPC of your choice.

Put a secret

The minimum viable example. Encrypt a Slack webhook URL to the hosted Worker, authorize one of your contracts to trigger decryption, store the ciphertext on chain.

import { VaultClient } from '@asentum/vault-sdk';

// Your Dilithium3 keypair, loaded however you load it
import { keypair } from './my-wallet.js';

const vault = new VaultClient({
  rpc: 'https://explorer.asentum.com',
  vaultAddress: 'ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg2dyvhm',
  registryAddress: 'ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfhmse2f',
  keypair,
});

const { sid, txHash } = await vault.put('slack-webhook', {
  plaintext: process.env.SLACK_WEBHOOK_URL,
  workerId: 'asentum-hosted',
  authorizedContracts: ['ase1…yourHRContract'],
});

console.log('sid:', sid);
console.log('tx:', txHash);

The SDK fetches the Worker's hybrid public keypair from the on-chain registry, encrypts your plaintext locally (the secret never leaves your machine in cleartext), and submits the put transaction. The returned sid is the on-chain identifier you reference from your contract.

Authorize a contract

You can authorize additional contracts at any time:

await vault.authorize(sid, 'ase1…anotherContract');

Only the owner of the secret (whoever signed the original put) can add or remove authorized contracts. Each addition and removal emits an event so the authorization history is fully auditable on chain.

Trigger decryption from a contract

This is where the magic happens. Your contract calls the Vault's requestDecryption method with a payload that tells the Worker what to do once the secret is in memory.

// In your HR contract. Schedule notifyBirthday through the cron
// registry (see Scheduled Contract Calls) or call it from a transaction.

// A unique 64-hex jobId: this contract's address plus a counter.
function makeJobId(count) {
  const addr = String(msg.contractAddress).toLowerCase().replace(/^0x/, '');
  return (addr + count.toString(16).padStart(24, '0')).slice(0, 64);
}

({
  // Pass the Vault's ase1 address (ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg2dyvhm)
  // and your secret id when you call init. The SDK converts ase1
  // arguments to the hex form E() needs.
  init(vault, slackSid) {
    assert(!storage.has('vault'), 'already initialized');
    storage.set('vault', String(vault).toLowerCase());
    storage.set('slack-sid', String(slackSid).toLowerCase());
    storage.set('jobs', '0');
  },

  notifyBirthday(employeeName) {
    const sid = storage.get('slack-sid');
    const count = BigInt(storage.get('jobs')) + 1n;
    storage.set('jobs', count.toString());
    const jobId = makeJobId(count);

    E(storage.get('vault')).requestDecryption(
      sid,
      jobId,
      JSON.stringify({
        url: 'https://hooks.slack.com/services/...',
        method: 'POST',
        secretAs: { kind: 'body-key', key: 'webhook_token' },
        body: { text: 'Happy birthday ' + employeeName + '!' },
        resultMode: 'hash',
      }),
    );
    return jobId;
  },
})

The payload is opaque to the Vault, but the contract is the policy. The Worker reads the payload, validates the URL against the integrations allowlist, injects the decrypted secret where you asked (header, query param, or body key), and makes the call.

The resultMode field controls whether the response body is hashed (default, privacy-preserving) or returned in full (for oracle-style use where the contract needs the data, capped at 1 KB).

Inspect job state

Every job has a public record on chain. Pending, ok, error, with hashes, HTTP status codes, and the fulfilling Worker's identity. From the SDK:

const job = await vault.getJob(jobId);

// {
//   jobId: '0x...',
//   sid: '0x...',
//   requester: '<requesting contract>',
//   workerId: 'asentum-hosted',
//   status: 'ok',                     // 'pending' | 'ok' | 'error'
//   statusCode: '200',
//   hash: '0x...',                    // sha256 of response body
//   fulfilledAt: '20047',
//   fulfiller: '<worker account>',
// }

From a contract: E(storage.get('vault')).getJob(jobId) returns the same record, synchronously. Use it to decide whether to retry, alert, or move on.

Verify results before acting

Advisory, until the next Vault upgrade. The current Vault records any account that writes a result as the job's fulfiller, without checking it against the WorkerRegistry. A result is only trustworthy once you have confirmed that the fulfiller is the registered owner of the job's Worker. The upgrade moves this check into the Vault itself. Until then, do it in your contract.

The safe pattern has two steps. When a result arrives, record it as unverified and do nothing else. Then, in a separate call (a method you or anyone can call, or a scheduled call), read the job from the Vault, check who fulfilled it, and only then act on it. The check cannot run inside onFulfilled itself: the Vault is still on the call stack at that point, so your contract cannot call back into it, and the callback does not carry the fulfiller.

({
  // Pass the Vault (ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg2dyvhm), the
  // WorkerRegistry (ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfhmse2f) and your sid.
  init(vault, registry, sid) {
    assert(!storage.has('vault'), 'already initialized');
    storage.set('vault', String(vault).toLowerCase());
    storage.set('registry', String(registry).toLowerCase());
    storage.set('sid', String(sid).toLowerCase());
  },

  // Step 1: the Vault pushes the result. Note it, act on nothing yet.
  onFulfilled(jobId, status, statusCode, hash, body, error) {
    assert(String(msg.sender).toLowerCase() === storage.get('vault'), 'only the Vault');
    storage.set('unverified:' + jobId, '1');
    return true;
  },

  // Step 2: anyone may call this. Read the stored job and check it.
  settle(jobId) {
    assert(storage.get('unverified:' + jobId) === '1', 'nothing to settle');
    const job = E(storage.get('vault')).getJob(jobId);
    assert(job && job.status !== 'pending', 'no result yet');
    assert(job.requester === String(msg.contractAddress).toLowerCase(), 'not our job');
    assert(job.sid === storage.get('sid'), 'not our secret');
    assert(E(storage.get('registry')).isOwner(job.workerId, job.fulfiller) === true,
      'result not written by the registered Worker');
    storage.delete('unverified:' + jobId);
    // Verified: use job.status, job.statusCode, job.hash, job.body here.
    return true;
  },
})

If settle fails the Worker check, discard that result and request a new job with a new jobId.

A few more rules for the same period:

  • Never release funds, refund, or make any change you cannot undo on a result you have not verified. That includes treating an error status as proof that a call failed.
  • Build each jobId from your own contract's address plus a counter, as in the example above, so no other account can use it first.
  • Create secrets with the latest @asentum/vault-sdk. Its sids start with your own address, which the upgraded Vault requires for new secrets.
  • Leave expiresAt at 0 for now. The current Vault reads a non-zero expiry as already passed. To stop a secret from being used, revoke the contract instead.
  • Prefer revoke over delete for now. The current Vault cannot undo a delete; the upgrade adds restore.

Once the upgrade is live, the Vault only accepts a result from the registered owner of the job's Worker, so a result that reaches onFulfilled can be acted on directly. Keeping the check above does no harm. The upgrade height will be announced before it activates.

Rotate, revoke, delete

// Rotate the underlying plaintext (e.g. API key got cycled)
await vault.rotate('slack-webhook', {
  plaintext: 'new-slack-webhook',
  workerId: 'asentum-hosted',
});

// Revoke a contract's authorization
await vault.revoke(sid, 'ase1…contractWeNoLongerTrust');

// Soft-delete the secret (record stays, decryption refused)
await vault.delete(sid);

Deletion is soft on purpose. The record stays in storage so the audit trail is preserved. Future calls to requestDecryption refuse the deleted sid. On the current Vault a delete cannot be undone, so use revoke if you only need to pause a secret; the next Vault upgrade adds restore(sid).

Self-host a Worker

The hosted Worker is fine for testnet and most production cases. If you want to run your own (you don't want to trust someone else with your decryption keys, or you need to whitelist a custom internal API), the daemon is one npm install:

npm install @asentum/workers
npx asentum-worker init        # generates keypair + scaffolds allow-extra.json
npx asentum-worker status      # shows pubkeys + policy hash
# register the worker on chain with the printed pubkeys
ASENTUM_RPC=https://explorer.asentum.com \
ASENTUM_VAULT_ADDRESS=ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg2dyvhm \
ASENTUM_REGISTRY_ADDRESS=ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfhmse2f \
  npx asentum-worker start

Production deployments typically run as a systemd unit. The daemon tails the chain, decrypts secrets in its own memory, validates each call against the integrations allowlist plus any hosts you add in allow-extra.json, makes the HTTP call, and posts a signed fulfillment tx. Reachability from the public internet is not required: the daemon polls, it doesn't listen.

Trust model

Be honest about what this gives you.

The Worker operator holds the decryption key for any secret encrypted to their Worker. You trust them the same way you would trust a SaaS vendor with your API keys today. There is no way around this on a transparent chain: if a contract can decrypt a secret autonomously, then whoever runs the decryption process can read the secret.

What you GAIN over "trust Vercel" alone:

  • Who can trigger decryption: enforced by authorized-contract list on chain.
  • When it fires: enforced by cron schedule on chain.
  • What the payload looks like: defined by your smart contract code on chain.
  • That it fired: emitted as a public event.
  • Which Worker fulfilled: signed tx with registered pubkey on chain.
  • Policy the Worker is operating under: hash committed at registration.

The Worker cannot fire a call your contract did not authorize. The contract owner can rotate to a different Worker at any time. A future V2 of the protocol will distribute decryption across multiple Workers via threshold cryptography, eliminating the single point of trust entirely.

Cheatsheet

// Testnet contract addresses
WorkerRegistry  ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfhmse2f
Vault           ase1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg2dyvhm

// Hosted Worker (free during testnet)
workerId        asentum-hosted
integrations    180+ hosts (see /docs/reference/integrations),
                e.g. api.openai.com, api.resend.com, hooks.slack.com

// SDK exports
VaultClient                     // connected client
encrypt / decrypt               // standalone crypto helpers
deriveSid / deriveJobId         // deterministic identifiers
generateHybridKeypair           // standalone keygen

// Vault contract methods (callable from any contract)
put(sid, workerId, ciphertext, authorized, expiresAt)
rotate(sid, workerId, ciphertext, expiresAt)
authorize(sid, contractAddr)
revoke(sid, contractAddr)
delete(sid)
requestDecryption(sid, jobId, payload)
fulfillWork(jobId, status, statusCode, hash, body, error)   // Workers only
getSecret(sid)
getJob(jobId)
canUse(sid, contractAddr)

// WorkerRegistry
isOwner(workerId, address)      // check a job's fulfiller (see Verify results)

Full design doc lives in the AsentumChain repo at notes/asentum-workers-vault-design.md. Concept overview is at Concepts: Secrets and Workers.