@finchip.ai/foga 0.0.0-stage → 0.6.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +216 -2
  4. package/artifacts/bundle.json +74250 -0
  5. package/artifacts/bundle.sha256 +1 -0
  6. package/bin/foga.js +14 -0
  7. package/build/known-interface-ids.json +18 -0
  8. package/build/profiles.json +120 -0
  9. package/dist/build/bundle.js +417 -0
  10. package/dist/build/vendor.js +74 -0
  11. package/dist/bundle/load.js +24 -0
  12. package/dist/bundle/types.js +1 -0
  13. package/dist/cli-cell.js +395 -0
  14. package/dist/cli.js +505 -0
  15. package/dist/core/acdf.js +162 -0
  16. package/dist/core/adrf.js +273 -0
  17. package/dist/core/aid.js +83 -0
  18. package/dist/core/ard.js +146 -0
  19. package/dist/core/asf.js +157 -0
  20. package/dist/core/canonical.js +79 -0
  21. package/dist/core/erc8004.js +52 -0
  22. package/dist/core/kya.js +225 -0
  23. package/dist/core/measure.js +96 -0
  24. package/dist/core/pack/cbor.js +130 -0
  25. package/dist/core/pack/skillpack.js +142 -0
  26. package/dist/core/skills.js +40 -0
  27. package/dist/core/swarm.js +206 -0
  28. package/dist/core/tenders.js +121 -0
  29. package/dist/core/units.js +122 -0
  30. package/dist/core/world.js +104 -0
  31. package/dist/demo/demander.js +76 -0
  32. package/dist/demo/evidence.js +1 -0
  33. package/dist/demo/loop-d.js +449 -0
  34. package/dist/doctor/checks.js +51 -0
  35. package/dist/doctor/doctor.js +385 -0
  36. package/dist/doctor/loop-d.js +103 -0
  37. package/dist/doctor/probe.js +97 -0
  38. package/dist/doctor/semantic.js +83 -0
  39. package/dist/genesis/extract.js +64 -0
  40. package/dist/genesis/funding.js +126 -0
  41. package/dist/genesis/operator-scope.js +90 -0
  42. package/dist/genesis/preflight.js +54 -0
  43. package/dist/genesis/probe.js +164 -0
  44. package/dist/genesis/roles.js +96 -0
  45. package/dist/genesis/run.js +71 -0
  46. package/dist/genesis/scenario.js +765 -0
  47. package/dist/genesis/skill-runner.js +103 -0
  48. package/dist/genesis/skill-worker.js +41 -0
  49. package/dist/genesis/t1-zk.js +62 -0
  50. package/dist/genesis/t3-zk.js +105 -0
  51. package/dist/genesis/t4.js +259 -0
  52. package/dist/genesis/t5.js +168 -0
  53. package/dist/genesis/t6.js +222 -0
  54. package/dist/genesis/t7.js +198 -0
  55. package/dist/genesis/t8.js +189 -0
  56. package/dist/genesis/t9.js +188 -0
  57. package/dist/genesis/zk.js +128 -0
  58. package/dist/http/server.js +276 -0
  59. package/dist/kernel/cell.js +104 -0
  60. package/dist/kernel/errors.js +78 -0
  61. package/dist/kernel/kernel.js +251 -0
  62. package/dist/kernel/provider.js +125 -0
  63. package/dist/kernel/store.js +470 -0
  64. package/dist/kernel/tx.js +385 -0
  65. package/dist/mcp/server.js +170 -0
  66. package/dist/node/config.js +195 -0
  67. package/dist/node/init.js +200 -0
  68. package/dist/node/keys.js +95 -0
  69. package/dist/node/migrate.js +173 -0
  70. package/dist/node/model/anthropic.js +97 -0
  71. package/dist/node/model/stub.js +129 -0
  72. package/dist/node/model/types.js +9 -0
  73. package/dist/node/node.js +198 -0
  74. package/dist/node/policy.js +95 -0
  75. package/dist/node/runner.js +256 -0
  76. package/dist/node/watchers.js +88 -0
  77. package/dist/tools/admin.js +184 -0
  78. package/dist/tools/catalog.js +261 -0
  79. package/dist/tools/common.js +143 -0
  80. package/dist/tools/identity.js +107 -0
  81. package/dist/tools/index.js +14 -0
  82. package/dist/tools/read.js +471 -0
  83. package/dist/tools/tenders.js +400 -0
  84. package/dist/tools/types.js +4 -0
  85. package/dist/util/bytecode.js +123 -0
  86. package/dist/util/fs.js +58 -0
  87. package/dist/util/hash.js +4 -0
  88. package/dist/util/log.js +11 -0
  89. package/dist/util/version.js +12 -0
  90. package/dist/world/deploy.js +277 -0
  91. package/dist/world/plan.js +93 -0
  92. package/dist/world/types.js +1 -0
  93. package/docs/build.md +45 -0
  94. package/docs/cell-account.md +58 -0
  95. package/docs/compatibility-matrix.md +38 -0
  96. package/docs/design-memo.md +113 -0
  97. package/docs/doctor.md +53 -0
  98. package/docs/examples/README.md +11 -0
  99. package/docs/examples/claude-code-mcp.json +13 -0
  100. package/docs/examples/claude_desktop_config.json +12 -0
  101. package/docs/examples/cursor-mcp.json +11 -0
  102. package/docs/genesis.md +312 -0
  103. package/docs/kernel.md +101 -0
  104. package/docs/loop-d.md +90 -0
  105. package/docs/mcp.md +105 -0
  106. package/docs/node.md +66 -0
  107. package/docs/version-lock.md +67 -0
  108. package/docs/world.md +50 -0
  109. package/docs/zk.md +48 -0
  110. package/package.json +82 -4
  111. package/prover/README.md +26 -0
  112. package/prover/build-predicate.mjs +77 -0
  113. package/prover/package-lock.json +1837 -0
  114. package/prover/package.json +15 -0
  115. package/prover/run.cjs +199 -0
  116. package/scenarios/fixtures/sample-filing.txt +16 -0
  117. package/scenarios/skills/finch-extract-verify/LICENSE +2 -0
  118. package/scenarios/skills/finch-extract-verify/SKILL.md +34 -0
  119. package/scenarios/skills/finch-extract-verify/fields.json +56 -0
  120. package/scenarios/skills/finch-extract-verify/manifest.json +16 -0
  121. package/scenarios/skills/foga-probe/LICENSE +2 -0
  122. package/scenarios/skills/foga-probe/SKILL.md +35 -0
  123. package/scenarios/skills/foga-probe/manifest.json +16 -0
  124. package/scenarios/skills/foga-probe/probe.schema.json +40 -0
  125. package/server.json +79 -0
  126. package/vendor/LOCK.json +107 -0
  127. package/vendor/README.md +13 -0
  128. package/worlds/local.json +34 -0
  129. package/worlds/sepolia.json +314 -0
  130. package/zk/build/verification_key.json +174 -0
  131. package/zk/circuits/kya_predicate_count_v1.circom +231 -0
@@ -0,0 +1,26 @@
1
+ # foga-prover
2
+
3
+ The proving side of the two ERC-8419 ZK paths, kept as a sub-package so that the kernel's dependency tree stays
4
+ free of the proving libraries. `npm run zk:install` installs them here (`npm --prefix prover ci`).
5
+
6
+ `run.cjs` is a stdin/stdout bridge with one JSON job per process:
7
+
8
+ - the credential pattern (`kya-public-v1`) over the upstream prover (`vendor/kya-standard/companions/zk-kya-groth16/prover.js`,
9
+ materialized by `foga vendor sync`, which also holds that circuit's wasm, proving key and verification key; nothing of
10
+ it is copied here): `root`, `commit`, `attest`, `prove`;
11
+ - the predicate pattern (`kya-predicate-count-v1`, FOGA's own circuit in `../zk/circuits`) over the material built by
12
+ `build-predicate.mjs` into `../zk/build` (`npm run zk:predicate`; `FOGA_ZK_PREDICATE_DIR` overrides): `record.sign`,
13
+ `predicate.prove` (and `root` again, for the source set).
14
+
15
+ The bridge separates the roles the protocol separates. Credential: the prover (a cell) computes `Poseidon(secret)` and
16
+ hands the commitment to the attestor; the attestor signs the scheme-bound credential without seeing the secret; the
17
+ prover alone turns the credential into a proof for the admitting registry's domain and the current epoch. Predicate: a
18
+ source signs task-completion records about a subject; the prover shows that at least K of them are Accepted inside a
19
+ window, with the records, their signatures and its own secret as private input and the rule's parameters as public
20
+ input; the result is verified locally against the committed verification key before it leaves the bridge.
21
+
22
+ `build-predicate.mjs` compiles the predicate circuit with the WASM build of circom and runs a deterministic
23
+ **development** ceremony (public beacon, 2^17 powers of tau, Groth16 setup, phase-2 beacon); it exports the
24
+ verification key (`../zk/build/verification_key.json`, committed) and the Solidity verifier
25
+ (`../contracts/src/zk/Groth16PredicateVerifier.sol`, committed). Public randomness means a forgeable proving key: fit
26
+ for the genesis and tests, to be replaced by a real multi-party ceremony before any other use. See `../docs/zk.md`.
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ // Builds FOGA's predicate-pattern circuit (zk/circuits/kya_predicate_count_v1.circom) and runs its DEVELOPMENT
3
+ // trusted setup: compile with circom (the WASM build of the compiler shipped in this sub-package), a powers-of-tau
4
+ // of 2^17 created here with a public, fixed beacon, phase 2 with the same beacon, the verification key and the
5
+ // Solidity verifier. Everything is deterministic, so anyone can rebuild the same keys bit for bit — which is
6
+ // exactly why this is a development ceremony and not a trusted one: the randomness is public, the proving key
7
+ // is forgeable in principle, and it must be replaced by a real multi-party ceremony before any non-test use.
8
+ //
9
+ // node prover/build-predicate.mjs # full build into zk/build (10-20 minutes; the phase-2 preparation dominates)
10
+ // node prover/build-predicate.mjs --verifier # only re-export the verification key and the Solidity verifier from the final zkey
11
+ //
12
+ // Outputs (zk/build, gitignored except the small files):
13
+ // kya_predicate_count_v1.r1cs / .sym / _js/kya_predicate_count_v1.wasm
14
+ // pot17_final.ptau, kya_predicate_count_v1_0000.zkey, kya_predicate_count_v1_final.zkey
15
+ // verification_key.json (committed)
16
+ // ../../contracts/src/zk/Groth16PredicateVerifier.sol (committed; the generated verifier, contract renamed)
17
+ import { execFileSync } from "node:child_process";
18
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
19
+ import { createRequire } from "node:module";
20
+ import { dirname, join } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+
23
+ const here = dirname(fileURLToPath(import.meta.url));
24
+ const root = join(here, "..");
25
+ const require = createRequire(import.meta.url);
26
+ const circuit = join(root, "zk", "circuits", "kya_predicate_count_v1.circom");
27
+ const build = join(root, "zk", "build");
28
+ const name = "kya_predicate_count_v1";
29
+ const POWER = 17;
30
+ // keccak256("foga.kya-predicate-count-v1.development-ceremony"), fixed and public on purpose
31
+ const BEACON = "7c1f6c2e0f4a4f0a9d6a2b8e1c5d3f7a9b0c2d4e6f8a1b3c5d7e9f0a2b4c6d8e";
32
+ const ITERATIONS = 10;
33
+
34
+ function sh(cmd, args, opts = {}) {
35
+ console.log(`+ ${cmd} ${args.join(" ")}`);
36
+ execFileSync(cmd, args, { stdio: "inherit", ...opts });
37
+ }
38
+
39
+ const snarkjs = join(here, "node_modules", ".bin", "snarkjs");
40
+ const circom = join(here, "node_modules", ".bin", "circom2");
41
+ const onlyVerifier = process.argv.includes("--verifier");
42
+ mkdirSync(build, { recursive: true });
43
+
44
+ if (!onlyVerifier) {
45
+ // 1. compile
46
+ sh(circom, [circuit, "-l", join(here, "node_modules"), "--r1cs", "--wasm", "--sym", "-o", build]);
47
+ sh(snarkjs, ["r1cs", "info", join(build, `${name}.r1cs`)]);
48
+ // 2. powers of tau: new -> beacon -> prepare phase 2 (deterministic)
49
+ const pot0 = join(build, `pot${POWER}_0000.ptau`);
50
+ const potB = join(build, `pot${POWER}_beacon.ptau`);
51
+ const potF = join(build, `pot${POWER}_final.ptau`);
52
+ if (!existsSync(potF)) {
53
+ sh(snarkjs, ["powersoftau", "new", "bn128", String(POWER), pot0]);
54
+ sh(snarkjs, ["powersoftau", "beacon", pot0, potB, BEACON, String(ITERATIONS), "-n=FOGA development beacon (phase 1)"]);
55
+ sh(snarkjs, ["powersoftau", "prepare", "phase2", potB, potF]);
56
+ }
57
+ // 3. phase 2 (deterministic beacon)
58
+ const z0 = join(build, `${name}_0000.zkey`);
59
+ const zF = join(build, `${name}_final.zkey`);
60
+ sh(snarkjs, ["groth16", "setup", join(build, `${name}.r1cs`), potF, z0]);
61
+ sh(snarkjs, ["zkey", "beacon", z0, zF, BEACON, String(ITERATIONS), "-n=FOGA development beacon (phase 2)"]);
62
+ }
63
+
64
+ // 4. verification key and the Solidity verifier
65
+ const zF = join(build, `${name}_final.zkey`);
66
+ sh(snarkjs, ["zkey", "export", "verificationkey", zF, join(build, "verification_key.json")]);
67
+ const solTmp = join(build, "Groth16PredicateVerifier.sol");
68
+ sh(snarkjs, ["zkey", "export", "solidityverifier", zF, solTmp]);
69
+ let sol = readFileSync(solTmp, "utf8");
70
+ sol = sol.replace(/contract Groth16Verifier\b/, "contract Groth16PredicateVerifier");
71
+ sol = sol.replace(/^\/\/ SPDX-License-Identifier: GPL-3.0$/m, "// SPDX-License-Identifier: GPL-3.0\n// Generated by snarkjs from zk/circuits/kya_predicate_count_v1.circom with the development ceremony of\n// prover/build-predicate.mjs. Do not edit; rebuild.");
72
+ const outDir = join(root, "contracts", "src", "zk");
73
+ mkdirSync(outDir, { recursive: true });
74
+ writeFileSync(join(outDir, "Groth16PredicateVerifier.sol"), sol);
75
+ const vk = JSON.parse(readFileSync(join(build, "verification_key.json"), "utf8"));
76
+ console.log(`verification key: ${vk.nPublic} public signals, protocol ${vk.protocol}, curve ${vk.curve}`);
77
+ console.log(`wrote ${join(outDir, "Groth16PredicateVerifier.sol")}`);