Skip to content

Spike: run @mysten/seal encrypt+decrypt inside a Cloudflare Worker #5

Description

@harrymove-ctrl

Context

The Harbor HTTP API is plain fetch + multipart and is Worker-friendly, but @mysten/seal leans on WebCrypto + @noble curves + CPU-intensive BLS12-381. The Worker runs with compatibility_flags: ["nodejs_compat"] and compatibility_date: 2026-05-21 (apps/api/cloudflare/wrangler.jsonc:17), and @mysten/sui ^2.9.1 is already a dependency of apps/api (apps/api/package.json). Whether SEAL fits the Worker's compressed-bundle cap and CPU limit is the single highest-risk unknown gating the entire private-memory workstream (roadmap "The key runtime unknown (must spike early)" + §1 spike row).

Goal / user story

As an engineer, I want a throwaway Worker that imports @mysten/seal, encrypts one blob and decrypts it back, so we can decide WHERE encryption runs (Worker vs queue consumer vs Node CLI/MCP) before investing in HarborClient/seal.ts.

Acceptance criteria

  • A minimal Worker (or apps/api test entry) imports @mysten/seal + @mysten/sui/keypairs/ed25519, and encrypts a small (<10KB) Uint8Array against a Seal policy id on Sui testnet, returning ciphertext.
  • The same Worker builds a SessionKey + seal_approve PTB and decrypts the ciphertext back to the original bytes (round-trip asserted byte-equal).
  • wrangler deploy --dry-run (or a real deploy) reports the compressed bundle size, recorded against the Workers size cap; CPU ms for one encrypt+decrypt is noted.
  • A written finding recommends where encryption runs (Worker / queue consumer / Node-only) backed by the bundle + CPU numbers.
  • If the Worker busts limits, the fallback (encrypt in the queue consumer or Node CLI/MCP) is documented so the Harbor client/encrypted-path issues target the right runtime.

Implementation notes

  • Add @mysten/seal to a scratch package or apps/api (do NOT keep it in the prod bundle if the spike fails). @mysten/sui is already present.
  • You need a real seal_policy_id on Sui testnet — create one via Harbor (a bucket create yields a Seal policy) or reuse the seal-docs.wal.app example policy; the demo sample target already points there (CONTEXTMEM_DEMO_SAMPLE_TARGET in wrangler.jsonc).
  • SessionKey requires an Ed25519 signer: decodeSuiPrivateKey(suiprivkey1...)Ed25519Keypair. Use SuiGrpcClient (already used in packages/walrus/src/proof.ts/history.ts/resolve.ts) for the seal_approve devInspect.
  • Gotchas: nodejs_compat polyfills crypto, but BLS in @noble/curves is CPU-heavy (Worker CPU limit ~30s paid, lower on free) and the compressed-bundle cap is small. This is throwaway — do not ship to prod. Keep tar-based packProofBundle (packages/walrus/src/storage.ts:231) out; it's Node-only regardless.

Sui Overflow angle

This de-risks the whole Sui-native private-memory demo. The answer (edge-encrypt vs offload) determines the live-demo architecture: whether the hackathon judges see encryption happen in the same Worker that serves recall, or in a queue/Node tier.

Dependencies

None — do this first. Blocks the HarborClient issue and the private SEAL encrypted remember/recall issue.

Part of the ContextMEM roadmap (#4) • Sui Overflow build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Demo-blocking: required for a working Sui Overflow demoharborHarbor encrypted Walrus storage on Sui (Space/Bucket/File)seal@mysten/seal client-side encryption + on-chain access controlspikeTime-boxed throwaway investigation to de-risk a decision

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions