Skip to content

Repository files navigation

Kaspa Pact

中文 | English

Kaspa Pact 是一个部署在 Cloudflare Workers 上的 Kaspa testnet-10(TN10)SilverScript 契约应用,目前专注于两个确定性功能:

  • 双方买卖托管:买方和卖方分别用自己的 KasWare 钱包提供 UTXO 并签名。
  • 心跳继承保险库:支持 1–5 位固定继承人以及创建时锁定的分配比例。

本项目完全不需要 AI、模型 API 或 AI 密钥。契约源码由固定规则确定性生成,私钥始终保留在 KasWare 中,交易在浏览器广播到 TN10 前会先经过预检。

可使用 Cloudflare 免费创建

任何拥有 Cloudflare 账号的用户都可以从 Workers Free 方案开始,自行创建 Worker 和 D1 数据库并部署本项目,不必购买服务器,也不需要配置 AI 服务。

Cloudflare 当前默认向用户提供 Workers Free 方案;官方文档列出的免费额度包括每天 100,000 次 Worker 请求。D1 也长期为 Workers Free 方案提供免费的原型开发与实验额度。免费方案不是无限资源,超过每日请求、数据库读写或存储限制后,相关操作可能暂时失败,具体额度应以 Cloudflare 最新官方说明为准:

安全边界

  • SilverScript 固定在已审查的实验性基线提交 26e3b9f94821b6fe47a2492755252ec4f995abb1
  • 主网操作目前关闭;界面与交易构建器只允许 testnet-10
  • 编译成功不代表资金已经锁定。只有钱包签名、广播以及节点精确确认 covenant UTXO 后,界面才显示链上生效。
  • Worker 不接收私钥或助记词。
  • D1 只保存共享的房间/保险库状态,以及浏览器持有令牌的哈希值。
  • 开放主网前必须进行独立的契约与交易构建器审计。

买卖托管流程

  1. 买方创建房间,并设定双方锁定金额和超时时间。
  2. 卖方使用独立的 TN10 钱包加入。
  3. 双方分别选择自己的 UTXO,只签署属于自己的锁仓输入。
  4. 两个签名齐全后,浏览器预检并广播同一笔锁仓交易。
  5. 买方可以向卖方放款;超时前退款需要双方签名,超时后由退款分支退回买方。
  6. 尚未产生锁仓签名前可以退出,未使用的空房间可以删除。

继承保险库流程

  1. 所有者选择 1–5 个 TN10 继承人地址、合计 100% 的固定份额、锁定金额和续期周期。
  2. 服务端按这些参数确定性生成并编译 SilverScript。
  3. 所有者通过 KasWare 签名和广播;节点确认后保险库才正式生效。
  4. 续期会创建相同 covenant 输出并重置相对 DAA 年龄;所有者可以随时签名撤回。
  5. 到期后任何人都能触发继承分支,但契约会强制执行每个继承人的钱包、金额和输出顺序。
  6. Kaspa 不会自动发起交易,因此到期后仍需继承人、可信亲友或 keeper 主动触发继承。

本地运行

要求 Node.js 22.13 或更高版本:

npm install
npm run dev

只有在替换 Kascov 兼容的编译/预检服务地址时,才需要把 .env.example 复制为 .env.local

部署到自己的 Cloudflare

  1. 注册或登录 Cloudflare,并启用 Workers Free 方案。
  2. 创建一个 D1 数据库。
  3. 复制 wrangler.direct.jsonc,替换 Worker 名称、域名路由、D1 数据库名称与 database_id
  4. 登录 Wrangler:npx wrangler login
  5. 应用数据库迁移并部署:
npm install
npx wrangler d1 migrations apply YOUR_D1_NAME --remote --config wrangler.direct.jsonc
npm run deploy

当前仓库的生产配置使用 cov.w00c00.cyou。Fork 后应替换为自己的域名;也可以只使用 Cloudflare 自动提供的 workers.dev 地址,无需购买自定义域名。

有效 API

  • GET|POST /api/rooms:托管房间发现、签名状态、链上确认和结算元数据。
  • GET|POST /api/inheritance:继承保险库创建、确认、续期、撤回和到期领取元数据。
  • GET /api/network:TN10 当前 DAA 信息,用于显示可读时间估算。
  • POST /api/preflight:浏览器广播前使用的受限 TN10 Kascov 预检代理。

运行 npm test 可执行生产构建和确定性测试。只有在明确需要访问公共 TN10 编译/预检服务时,才运行:

RUN_TN10_INTEGRATION=1 node --test tests/inheritance-preflight.integration.test.mjs

English

Kaspa Pact is a Cloudflare Workers application for deterministic SilverScript covenants on Kaspa testnet-10 (TN10). It currently focuses on two workflows:

  • Two-party trade escrow with separate buyer and seller UTXO signatures.
  • Heartbeat inheritance vaults with one to five immutable heirs and fixed allocation percentages.

The project uses no AI, model API, or AI key. Contract source is generated deterministically from fixed rules, private keys stay inside KasWare, and every transaction is preflighted before the browser broadcasts it to TN10.

Free Cloudflare deployment

Anyone with a Cloudflare account can start on the Workers Free plan, create a Worker and D1 database, and deploy this project without purchasing a server or configuring an AI service.

Cloudflare currently gives users access to the Workers Free plan. Its official documentation lists 100,000 Worker requests per day on the free tier, while D1 includes free capacity for prototyping and experimentation. The free plan is not unlimited: requests or database operations may fail after daily read, write, request, or storage limits are reached. Always check Cloudflare's current documentation:

Safety boundary

  • SilverScript is pinned to the reviewed experimental baseline commit 26e3b9f94821b6fe47a2492755252ec4f995abb1.
  • Mainnet actions are disabled. The UI and transaction builders currently target testnet-10 only.
  • Compilation does not lock funds. The UI reports an active lock only after wallet signatures, broadcast, and exact covenant UTXO confirmation.
  • The Worker never receives private keys or seed phrases.
  • D1 stores shared room/vault state and hashes of browser-held bearer tokens.
  • Obtain an independent contract and transaction-builder audit before enabling mainnet.

Trade escrow flow

  1. The buyer creates a room and defines both deposits and a timeout.
  2. The seller joins with a separate TN10 wallet.
  3. Each participant selects a funded UTXO and signs only their own funding input.
  4. After both signatures, the browser preflights and broadcasts the shared funding transaction.
  5. The buyer can release funds to the seller. A pre-timeout refund requires both signatures; the timeout branch refunds the buyer after expiry.
  6. Participants can leave before any funding signature exists, and an unused empty room can be deleted.

Inheritance vault flow

  1. The owner selects one to five TN10 heir addresses, immutable shares totaling 100%, an amount, and a heartbeat interval.
  2. The server deterministically builds and compiles the matching SilverScript source.
  3. The owner signs and broadcasts funding from KasWare; the vault becomes active only after node confirmation.
  4. A heartbeat recreates the same covenant output and resets its relative DAA age. The owner can withdraw at any time.
  5. After expiry, anyone can trigger the inherit branch, but the covenant fixes every heir address, payout amount, and output order.
  6. Kaspa does not initiate transactions automatically, so an heir, trusted person, or keeper must trigger inheritance after expiry.

Local development

Node.js 22.13 or newer is required:

npm install
npm run dev

Copy .env.example to .env.local only when overriding the Kascov-compatible compiler/preflight endpoint.

Deploy to your own Cloudflare account

  1. Sign up for or log in to Cloudflare and enable the Workers Free plan.
  2. Create a D1 database.
  3. Copy wrangler.direct.jsonc and replace the Worker name, route, D1 database name, and database_id.
  4. Authenticate Wrangler with npx wrangler login.
  5. Apply migrations and deploy:
npm install
npx wrangler d1 migrations apply YOUR_D1_NAME --remote --config wrangler.direct.jsonc
npm run deploy

The production config in this repository uses cov.w00c00.cyou. Forks should replace it with their own domain, or use the automatically provided workers.dev address without purchasing a custom domain.

Active API routes

  • GET|POST /api/rooms — escrow room discovery, signing state, confirmation, and settlement metadata.
  • GET|POST /api/inheritance — inheritance vault creation, confirmation, heartbeat, withdrawal, and post-expiry claim metadata.
  • GET /api/network — current TN10 DAA information for human-readable time estimates.
  • POST /api/preflight — bounded TN10 Kascov preflight proxy used before browser broadcast.

Run npm test for the production build and deterministic test suite. Only when intentionally calling the public TN10 compiler/preflight service, run:

RUN_TN10_INTEGRATION=1 node --test tests/inheritance-preflight.integration.test.mjs

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages