dero-mcp-server 0.1.2 → 0.4.0

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 (77) hide show
  1. package/POSITIONING.md +94 -0
  2. package/README.md +132 -31
  3. package/SKILL.md +264 -0
  4. package/data/docs-index.json +276 -264
  5. package/dist/bn254.d.ts +74 -0
  6. package/dist/bn254.d.ts.map +1 -0
  7. package/dist/bn254.js +205 -0
  8. package/dist/bn254.js.map +1 -0
  9. package/dist/citations.d.ts +140 -0
  10. package/dist/citations.d.ts.map +1 -0
  11. package/dist/citations.js +322 -0
  12. package/dist/citations.js.map +1 -0
  13. package/dist/composites/_shared.d.ts +119 -0
  14. package/dist/composites/_shared.d.ts.map +1 -0
  15. package/dist/composites/_shared.js +152 -0
  16. package/dist/composites/_shared.js.map +1 -0
  17. package/dist/composites/audit-chain-artifact-claim.d.ts +128 -0
  18. package/dist/composites/audit-chain-artifact-claim.d.ts.map +1 -0
  19. package/dist/composites/audit-chain-artifact-claim.js +305 -0
  20. package/dist/composites/audit-chain-artifact-claim.js.map +1 -0
  21. package/dist/composites/diagnose-chain-health.d.ts +64 -0
  22. package/dist/composites/diagnose-chain-health.d.ts.map +1 -0
  23. package/dist/composites/diagnose-chain-health.js +144 -0
  24. package/dist/composites/diagnose-chain-health.js.map +1 -0
  25. package/dist/composites/estimate-deploy-cost.d.ts +83 -0
  26. package/dist/composites/estimate-deploy-cost.d.ts.map +1 -0
  27. package/dist/composites/estimate-deploy-cost.js +116 -0
  28. package/dist/composites/estimate-deploy-cost.js.map +1 -0
  29. package/dist/composites/explain-smart-contract.d.ts +64 -0
  30. package/dist/composites/explain-smart-contract.d.ts.map +1 -0
  31. package/dist/composites/explain-smart-contract.js +149 -0
  32. package/dist/composites/explain-smart-contract.js.map +1 -0
  33. package/dist/composites/forge-demo-proof.d.ts +81 -0
  34. package/dist/composites/forge-demo-proof.d.ts.map +1 -0
  35. package/dist/composites/forge-demo-proof.js +204 -0
  36. package/dist/composites/forge-demo-proof.js.map +1 -0
  37. package/dist/composites/recommend-docs-path.d.ts +97 -0
  38. package/dist/composites/recommend-docs-path.d.ts.map +1 -0
  39. package/dist/composites/recommend-docs-path.js +149 -0
  40. package/dist/composites/recommend-docs-path.js.map +1 -0
  41. package/dist/composites/trace-transaction-with-context.d.ts +107 -0
  42. package/dist/composites/trace-transaction-with-context.d.ts.map +1 -0
  43. package/dist/composites/trace-transaction-with-context.js +217 -0
  44. package/dist/composites/trace-transaction-with-context.js.map +1 -0
  45. package/dist/daemon-base.d.ts +28 -0
  46. package/dist/daemon-base.d.ts.map +1 -0
  47. package/dist/daemon-base.js +62 -0
  48. package/dist/daemon-base.js.map +1 -0
  49. package/dist/dero-curve.d.ts +79 -0
  50. package/dist/dero-curve.d.ts.map +1 -0
  51. package/dist/dero-curve.js +79 -0
  52. package/dist/dero-curve.js.map +1 -0
  53. package/dist/docs-parse.d.ts.map +1 -1
  54. package/dist/docs-parse.js +18 -2
  55. package/dist/docs-parse.js.map +1 -1
  56. package/dist/http-server.d.ts +37 -0
  57. package/dist/http-server.d.ts.map +1 -0
  58. package/dist/http-server.js +132 -0
  59. package/dist/http-server.js.map +1 -0
  60. package/dist/index.js +18 -11
  61. package/dist/index.js.map +1 -1
  62. package/dist/proof-decode.d.ts +125 -0
  63. package/dist/proof-decode.d.ts.map +1 -0
  64. package/dist/proof-decode.js +619 -0
  65. package/dist/proof-decode.js.map +1 -0
  66. package/dist/server.d.ts.map +1 -1
  67. package/dist/server.js +414 -114
  68. package/dist/server.js.map +1 -1
  69. package/dist/tool-descriptions.d.ts +53 -0
  70. package/dist/tool-descriptions.d.ts.map +1 -0
  71. package/dist/tool-descriptions.js +285 -0
  72. package/dist/tool-descriptions.js.map +1 -0
  73. package/dist/tx-parse.d.ts +63 -0
  74. package/dist/tx-parse.d.ts.map +1 -0
  75. package/dist/tx-parse.js +183 -0
  76. package/dist/tx-parse.js.map +1 -0
  77. package/package.json +27 -2
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Thin wrapper around `@noble/curves` bn254 G1 for the FORGE feature.
3
+ *
4
+ * Two responsibilities:
5
+ * 1. Expose DERO's custom Pedersen base point `G` (not the standard bn254
6
+ * generator). See [src/dero-curve.ts](./dero-curve.ts) for the source.
7
+ * 2. Compress/decompress points in **DERO format** (big-endian X + 1 sign
8
+ * byte), not the SEC1 format noble uses natively.
9
+ *
10
+ * Compression format mirrors `derohe/cryptography/bn256/changes.go:19-35`:
11
+ * bytes[0..32] = X big-endian
12
+ * bytes[32] = 0x01 if Y is the larger of the two square roots of x^3 + 3
13
+ * mod P (i.e. Y > P - Y), else 0x00.
14
+ *
15
+ * Scalar handling mirrors `proof.go:89` — DERO casts `uint64 → int64` before
16
+ * passing to `big.Int.SetInt64`, so the uint64 wraparound `18446744073709451616`
17
+ * becomes scalar `-100000`. `scalarMult` accepts arbitrary signed bigints and
18
+ * reduces mod the curve order before multiplication.
19
+ */
20
+ declare const Point: import("@noble/curves/abstract/weierstrass.js").WeierstrassPointCons<bigint>;
21
+ export type DeroPoint = InstanceType<typeof Point>;
22
+ /**
23
+ * Decompress a 33-byte DERO point. Throws on malformed input or x not on curve.
24
+ *
25
+ * Logic mirrors `Decompress` in `cryptography/bn256/changes.go:215-241`:
26
+ * compute both square roots of x^3 + 3 mod P, then pick smaller/larger based
27
+ * on the sign byte.
28
+ */
29
+ export declare function deroDecompress(bytes: Uint8Array): DeroPoint;
30
+ /**
31
+ * Compress a point to DERO 33-byte format.
32
+ *
33
+ * Mirrors `Compress` in `cryptography/bn256/changes.go:19-35`:
34
+ * sign = 0 if Y < P - Y, else 1.
35
+ */
36
+ export declare function deroCompress(point: DeroPoint): Uint8Array;
37
+ /** Convenience: hex string round-trip. */
38
+ export declare function deroDecompressHex(hex: string): DeroPoint;
39
+ /** Convenience: returns lowercase hex of the 33-byte compressed form. */
40
+ export declare function deroCompressHex(point: DeroPoint): string;
41
+ /** DERO's Pedersen base point G (custom — not the standard bn254 generator). */
42
+ export declare const G: DeroPoint;
43
+ /**
44
+ * Scalar multiplication mirroring `proof.go:89`.
45
+ *
46
+ * DERO casts `uint64 → int64 → big.Int` before multiplying, so the uint64
47
+ * wraparound `2^64 - n` for small `n` becomes the negative scalar `-n`. We
48
+ * accept arbitrary signed bigints here and reduce mod the curve order before
49
+ * delegating to noble.
50
+ */
51
+ export declare function scalarMult(point: DeroPoint, scalar: bigint): DeroPoint;
52
+ /**
53
+ * Treat `value` as a Go `uint64`, mimic `big.Int.SetInt64(int64(value))`, and
54
+ * return the resulting signed scalar reduced mod the curve order.
55
+ *
56
+ * For the cited 2022 proof's V = 18446743853709551435, this returns the
57
+ * curve-order reduction of -220000000181 — the same scalar `proof.Prove()` uses.
58
+ */
59
+ export declare function uint64ToSignedScalar(uintValue: bigint): bigint;
60
+ export declare function add(a: DeroPoint, b: DeroPoint): DeroPoint;
61
+ export declare function subtract(a: DeroPoint, b: DeroPoint): DeroPoint;
62
+ export declare function negate(point: DeroPoint): DeroPoint;
63
+ export declare function pointsEqual(a: DeroPoint, b: DeroPoint): boolean;
64
+ /**
65
+ * Re-derive each fixture from scalar operations and compare against the
66
+ * compressed bytes printed by the Go scratch program. Throws on any mismatch.
67
+ *
68
+ * This is the cross-implementation correctness gate — if the wiring is wrong
69
+ * (custom G missing, SEC1 vs DERO compression confused, sqrt root inversion),
70
+ * one of the six fixtures will fail and forging anything else is unsafe.
71
+ */
72
+ export declare function verifyDeroBn254(): void;
73
+ export {};
74
+ //# sourceMappingURL=bn254.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bn254.d.ts","sourceRoot":"","sources":["../src/bn254.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAYH,QAAA,MAAM,KAAK,8EAAiB,CAAA;AAG5B,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,KAAK,CAAC,CAAA;AA8ClD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CA4B3D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAOzD;AAED,0CAA0C;AAC1C,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAExD;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAExD;AAMD,gFAAgF;AAChF,eAAO,MAAM,CAAC,EAAE,SAAoD,CAAA;AAEpE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAMtE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK9D;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS,CAEzD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS,CAE9D;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAElD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAE/D;AAMD;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,IAAI,CA0BtC"}
package/dist/bn254.js ADDED
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Thin wrapper around `@noble/curves` bn254 G1 for the FORGE feature.
3
+ *
4
+ * Two responsibilities:
5
+ * 1. Expose DERO's custom Pedersen base point `G` (not the standard bn254
6
+ * generator). See [src/dero-curve.ts](./dero-curve.ts) for the source.
7
+ * 2. Compress/decompress points in **DERO format** (big-endian X + 1 sign
8
+ * byte), not the SEC1 format noble uses natively.
9
+ *
10
+ * Compression format mirrors `derohe/cryptography/bn256/changes.go:19-35`:
11
+ * bytes[0..32] = X big-endian
12
+ * bytes[32] = 0x01 if Y is the larger of the two square roots of x^3 + 3
13
+ * mod P (i.e. Y > P - Y), else 0x00.
14
+ *
15
+ * Scalar handling mirrors `proof.go:89` — DERO casts `uint64 → int64` before
16
+ * passing to `big.Int.SetInt64`, so the uint64 wraparound `18446744073709451616`
17
+ * becomes scalar `-100000`. `scalarMult` accepts arbitrary signed bigints and
18
+ * reduces mod the curve order before multiplication.
19
+ */
20
+ import { bn254 } from '@noble/curves/bn254.js';
21
+ import { BN254_B, BN254_P, BN254_R, CURVE_FIXTURES, DERO_G_COMPRESSED_HEX, } from './dero-curve.js';
22
+ const Point = bn254.G1.Point;
23
+ const Fp = bn254.G1.Point.Fp;
24
+ // ─────────────────────────────────────────────────────────────────────────────
25
+ // Hex / bytes helpers (private — proof-decode.ts has its own copies).
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+ function hexToBytes(hex) {
28
+ if (hex.length % 2 !== 0)
29
+ throw new Error(`hex: odd length ${hex.length}`);
30
+ const out = new Uint8Array(hex.length / 2);
31
+ for (let i = 0; i < out.length; i++) {
32
+ const b = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
33
+ if (Number.isNaN(b))
34
+ throw new Error(`hex: invalid byte "${hex.slice(i * 2, i * 2 + 2)}"`);
35
+ out[i] = b;
36
+ }
37
+ return out;
38
+ }
39
+ function bytesToHex(bytes) {
40
+ let hex = '';
41
+ for (const b of bytes)
42
+ hex += b.toString(16).padStart(2, '0');
43
+ return hex;
44
+ }
45
+ function bigIntToBE32(value) {
46
+ if (value < 0n || value >= 1n << 256n) {
47
+ throw new Error(`bigIntToBE32: out of range ${value}`);
48
+ }
49
+ const out = new Uint8Array(32);
50
+ let v = value;
51
+ for (let i = 31; i >= 0; i--) {
52
+ out[i] = Number(v & 0xffn);
53
+ v >>= 8n;
54
+ }
55
+ return out;
56
+ }
57
+ function be32ToBigInt(bytes, offset = 0) {
58
+ let v = 0n;
59
+ for (let i = 0; i < 32; i++)
60
+ v = (v << 8n) | BigInt(bytes[offset + i]);
61
+ return v;
62
+ }
63
+ // ─────────────────────────────────────────────────────────────────────────────
64
+ // DERO-format compress / decompress
65
+ // ─────────────────────────────────────────────────────────────────────────────
66
+ /**
67
+ * Decompress a 33-byte DERO point. Throws on malformed input or x not on curve.
68
+ *
69
+ * Logic mirrors `Decompress` in `cryptography/bn256/changes.go:215-241`:
70
+ * compute both square roots of x^3 + 3 mod P, then pick smaller/larger based
71
+ * on the sign byte.
72
+ */
73
+ export function deroDecompress(bytes) {
74
+ if (bytes.length !== 33) {
75
+ throw new Error(`deroDecompress: expected 33 bytes, got ${bytes.length}`);
76
+ }
77
+ const sign = bytes[32];
78
+ if (sign !== 0 && sign !== 1) {
79
+ throw new Error(`deroDecompress: invalid sign byte 0x${sign.toString(16).padStart(2, '0')}`);
80
+ }
81
+ const x = be32ToBigInt(bytes, 0);
82
+ if (x >= BN254_P)
83
+ throw new Error(`deroDecompress: x >= P`);
84
+ // rhs = x^3 + B mod P, computed in the field.
85
+ const xF = Fp.create(x);
86
+ const x3 = Fp.mul(Fp.mul(xF, xF), xF);
87
+ const rhs = Fp.add(x3, Fp.create(BN254_B));
88
+ const y1 = Fp.sqrt(rhs);
89
+ if (y1 === undefined)
90
+ throw new Error('deroDecompress: x not on curve (no sqrt)');
91
+ const y2 = Fp.neg(y1);
92
+ // Confirm we actually got a square root (defensive — Fp.sqrt may return any root).
93
+ if (Fp.mul(y1, y1) !== rhs)
94
+ throw new Error('deroDecompress: sqrt verification failed');
95
+ const smaller = y1 < y2 ? y1 : y2;
96
+ const larger = y1 < y2 ? y2 : y1;
97
+ const y = sign === 0 ? smaller : larger;
98
+ return Point.fromAffine({ x: xF, y });
99
+ }
100
+ /**
101
+ * Compress a point to DERO 33-byte format.
102
+ *
103
+ * Mirrors `Compress` in `cryptography/bn256/changes.go:19-35`:
104
+ * sign = 0 if Y < P - Y, else 1.
105
+ */
106
+ export function deroCompress(point) {
107
+ const { x, y } = point.toAffine();
108
+ const out = new Uint8Array(33);
109
+ out.set(bigIntToBE32(x), 0);
110
+ const negY = (BN254_P - y) % BN254_P;
111
+ out[32] = y < negY ? 0 : 1;
112
+ return out;
113
+ }
114
+ /** Convenience: hex string round-trip. */
115
+ export function deroDecompressHex(hex) {
116
+ return deroDecompress(hexToBytes(hex));
117
+ }
118
+ /** Convenience: returns lowercase hex of the 33-byte compressed form. */
119
+ export function deroCompressHex(point) {
120
+ return bytesToHex(deroCompress(point));
121
+ }
122
+ // ─────────────────────────────────────────────────────────────────────────────
123
+ // Point operations
124
+ // ─────────────────────────────────────────────────────────────────────────────
125
+ /** DERO's Pedersen base point G (custom — not the standard bn254 generator). */
126
+ export const G = deroDecompressHex(DERO_G_COMPRESSED_HEX);
127
+ /**
128
+ * Scalar multiplication mirroring `proof.go:89`.
129
+ *
130
+ * DERO casts `uint64 → int64 → big.Int` before multiplying, so the uint64
131
+ * wraparound `2^64 - n` for small `n` becomes the negative scalar `-n`. We
132
+ * accept arbitrary signed bigints here and reduce mod the curve order before
133
+ * delegating to noble.
134
+ */
135
+ export function scalarMult(point, scalar) {
136
+ const r = BN254_R;
137
+ let s = scalar % r;
138
+ if (s < 0n)
139
+ s += r;
140
+ if (s === 0n)
141
+ return Point.ZERO;
142
+ return point.multiply(s);
143
+ }
144
+ /**
145
+ * Treat `value` as a Go `uint64`, mimic `big.Int.SetInt64(int64(value))`, and
146
+ * return the resulting signed scalar reduced mod the curve order.
147
+ *
148
+ * For the cited 2022 proof's V = 18446743853709551435, this returns the
149
+ * curve-order reduction of -220000000181 — the same scalar `proof.Prove()` uses.
150
+ */
151
+ export function uint64ToSignedScalar(uintValue) {
152
+ if (uintValue < 0n || uintValue >= 1n << 64n) {
153
+ throw new Error(`uint64ToSignedScalar: out of uint64 range ${uintValue}`);
154
+ }
155
+ return uintValue >= 1n << 63n ? uintValue - (1n << 64n) : uintValue;
156
+ }
157
+ export function add(a, b) {
158
+ return a.add(b);
159
+ }
160
+ export function subtract(a, b) {
161
+ return a.subtract(b);
162
+ }
163
+ export function negate(point) {
164
+ return point.negate();
165
+ }
166
+ export function pointsEqual(a, b) {
167
+ return a.equals(b);
168
+ }
169
+ // ─────────────────────────────────────────────────────────────────────────────
170
+ // Self-test against the Go-extracted fixtures.
171
+ // ─────────────────────────────────────────────────────────────────────────────
172
+ /**
173
+ * Re-derive each fixture from scalar operations and compare against the
174
+ * compressed bytes printed by the Go scratch program. Throws on any mismatch.
175
+ *
176
+ * This is the cross-implementation correctness gate — if the wiring is wrong
177
+ * (custom G missing, SEC1 vs DERO compression confused, sqrt root inversion),
178
+ * one of the six fixtures will fail and forging anything else is unsafe.
179
+ */
180
+ export function verifyDeroBn254() {
181
+ const checks = [
182
+ ['G', CURVE_FIXTURES.G, G],
183
+ ['2G', CURVE_FIXTURES.twoG, G.double()],
184
+ ['3G', CURVE_FIXTURES.threeG, G.double().add(G)],
185
+ ['-G', CURVE_FIXTURES.negG, G.negate()],
186
+ ['G*100000', CURVE_FIXTURES.gMul1Dero, scalarMult(G, 100000n)],
187
+ [
188
+ 'G*int64(uint_wrap)',
189
+ CURVE_FIXTURES.gMulNeg1DeroAtoms,
190
+ scalarMult(G, uint64ToSignedScalar(18446744073709451616n)),
191
+ ],
192
+ [
193
+ 'G*int64(cited2022V)',
194
+ CURVE_FIXTURES.gMulCited2022V,
195
+ scalarMult(G, uint64ToSignedScalar(18446743853709551435n)),
196
+ ],
197
+ ];
198
+ for (const [label, expectedHex, point] of checks) {
199
+ const actualHex = deroCompressHex(point);
200
+ if (actualHex !== expectedHex) {
201
+ throw new Error(`verifyDeroBn254: ${label} mismatch\n expected: ${expectedHex}\n actual: ${actualHex}`);
202
+ }
203
+ }
204
+ }
205
+ //# sourceMappingURL=bn254.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bn254.js","sourceRoot":"","sources":["../src/bn254.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CA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E,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;QACvC,CAAC,UAAU,EAAE,cAAc,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,EAAE,OAAQ,CAAC,CAAC;QAC/D;YACE,oBAAoB;YACpB,cAAc,CAAC,iBAAiB;YAChC,UAAU,CAAC,CAAC,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;SAC3D;QACD;YACE,qBAAqB;YACrB,cAAc,CAAC,cAAc;YAC7B,UAAU,CAAC,CAAC,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;SAC3D;KACF,CAAA;IACD,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC;QACjD,MAAM,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;QACxC,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACb,oBAAoB,KAAK,0BAA0B,WAAW,iBAAiB,SAAS,EAAE,CAC3F,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Citation helper for DERO MCP tool responses.
3
+ *
4
+ * The wedge for this server is the combination of live chain reads and the
5
+ * in-process bundled docs index (145+ pages across derod, tela, hologram,
6
+ * deropay). Citations let agents link their responses back to authoritative
7
+ * docs without a second tool call, and they give downstream composite tools
8
+ * a uniform shape to compose.
9
+ *
10
+ * Design contract:
11
+ * - One shape, used by primitives and composites alike.
12
+ * - URLs are produced by the same builder used by `dero_docs_*` so the
13
+ * citation always points at the same canonical page the agent would
14
+ * reach via dero_docs_get_page.
15
+ * - The slug is duplicated as `page_id` to give composites a stable join
16
+ * key across tools (mirrors the FoodNearMe COMPOSITES.md citation pattern).
17
+ * - The map of related docs per tool is hand-maintained and validated by
18
+ * `scripts/check-citations.ts` (added alongside this helper) so a docs
19
+ * reorganization cannot silently produce 404 citations in production.
20
+ */
21
+ import { type DeroDocProduct } from './docs-parse.js';
22
+ export type DeroCitation = {
23
+ /** Always `'dero_docs'` for now; future sources (e.g. `'dero_chain'`) can extend this. */
24
+ source: 'dero_docs';
25
+ product: DeroDocProduct;
26
+ slug: string;
27
+ title: string;
28
+ canonical_url: string;
29
+ /** Alias of `slug` so composites can use a single join key across tools. */
30
+ page_id: string;
31
+ };
32
+ /**
33
+ * Build a DeroCitation pointing at one bundled docs page.
34
+ *
35
+ * The title is required (not derived from the bundled index) so this helper
36
+ * stays synchronous and zero-IO. It must match the docs page title; the
37
+ * citation guard validates this against the bundled index in CI.
38
+ */
39
+ export declare function buildDeroCitation(product: DeroDocProduct, slug: string, title: string): DeroCitation;
40
+ /**
41
+ * Map of MCP tool name → hand-curated related docs pages.
42
+ *
43
+ * Keep this list tight — only add entries when a tool's response is
44
+ * meaningfully improved by linking the agent at a specific page. The CI
45
+ * guard verifies every slug resolves against the bundled docs index, so any
46
+ * docs reorganization will fail the build before it ships.
47
+ *
48
+ * Adding a tool here:
49
+ * 1. Use `dero_docs_search` to find the right slug(s).
50
+ * 2. Add an entry with product + slug + exact page title.
51
+ * 3. Run `npm run check:citations` to confirm slugs resolve.
52
+ */
53
+ type RelatedDocsEntry = {
54
+ product: DeroDocProduct;
55
+ slug: string;
56
+ title: string;
57
+ };
58
+ export declare const RELATED_DOCS_BY_TOOL: Record<string, readonly RelatedDocsEntry[]>;
59
+ /**
60
+ * Resolve the hand-curated related docs list for a tool name and return it
61
+ * as fully-built `DeroCitation` objects. Returns `undefined` when the tool
62
+ * has no related docs configured.
63
+ *
64
+ * Use in tool handlers like:
65
+ * const related_docs = relatedDocsFor('dero_get_sc')
66
+ * return { ...rpcResult, ...(related_docs ? { related_docs } : {}) }
67
+ */
68
+ export declare function relatedDocsFor(toolName: string): DeroCitation[] | undefined;
69
+ export type FlaggedArtifactMatcher = {
70
+ kind: 'topoheight';
71
+ value: number;
72
+ } | {
73
+ kind: 'block_hash';
74
+ value: string;
75
+ } | {
76
+ kind: 'tx_hash';
77
+ value: string;
78
+ } | {
79
+ kind: 'proof_string';
80
+ value: string;
81
+ };
82
+ export type FlaggedArtifact = {
83
+ /** Stable human-readable id for logs and downstream tooling. */
84
+ id: string;
85
+ matchers: readonly FlaggedArtifactMatcher[];
86
+ /** Short factual statement appended to responses that match this artifact. */
87
+ context_note: string;
88
+ related_docs: readonly RelatedDocsEntry[];
89
+ /**
90
+ * The most rebuttal-relevant signed-DERO amount for `dero_forge_demo_proof`
91
+ * to use when `audit_chain_artifact_claim` is called with
92
+ * `include_forge_demo: true` and this artifact matches. For the 2022 claim
93
+ * this is the report's headline amount — forging the same display number
94
+ * for a non-receiver ring slot is the most direct demonstration that the
95
+ * pasted string is a display object, not a consensus statement.
96
+ */
97
+ demo_amount_dero?: string;
98
+ };
99
+ export declare const FLAGGED_CHAIN_ARTIFACTS: readonly FlaggedArtifact[];
100
+ /**
101
+ * Input shape passed by tool handlers. Optional fields let each tool pass
102
+ * only the inputs it actually has (e.g. dero_get_block_header_by_topo_height
103
+ * only knows about topoheight; dero_get_transaction only knows about
104
+ * tx_hashes). String comparisons are case-insensitive on hex values.
105
+ */
106
+ export type FlaggedArtifactQuery = {
107
+ topoheight?: number;
108
+ block_hash?: string;
109
+ tx_hash?: string;
110
+ tx_hashes?: readonly string[];
111
+ proof_string?: string;
112
+ };
113
+ /**
114
+ * Return all flagged artifacts whose matchers fire against the given inputs.
115
+ *
116
+ * Multiple matches return multiple artifacts (rare today; would happen if the
117
+ * same TX got cited in multiple false claims). Tool handlers should merge all
118
+ * matches into a single response.
119
+ */
120
+ export declare function flaggedArtifactsForInput(query: FlaggedArtifactQuery): FlaggedArtifact[];
121
+ /**
122
+ * Build the response-side enrichment for matched artifacts: a context note
123
+ * (joined if multiple match) plus prepended citations for each match.
124
+ *
125
+ * `baseRelatedDocs` is the tool's existing relatedDocsFor() output (or undefined).
126
+ * Returns `undefined` when no artifacts match — caller should noop in that case.
127
+ *
128
+ * Usage in a tool handler:
129
+ * const enrichment = enrichWithFlaggedArtifacts(
130
+ * { topoheight: args.topoheight },
131
+ * relatedDocsFor('dero_get_block_header_by_topo_height'),
132
+ * )
133
+ * return { ...result, ...(enrichment ?? {}) }
134
+ */
135
+ export declare function enrichWithFlaggedArtifacts(query: FlaggedArtifactQuery, baseRelatedDocs: DeroCitation[] | undefined): {
136
+ context_note: string;
137
+ related_docs: DeroCitation[];
138
+ } | undefined;
139
+ export {};
140
+ //# sourceMappingURL=citations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"citations.d.ts","sourceRoot":"","sources":["../src/citations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEpE,MAAM,MAAM,YAAY,GAAG;IACzB,0FAA0F;IAC1F,MAAM,EAAE,WAAW,CAAA;IACnB,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAWD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,YAAY,CASd;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,gBAAgB,GAAG;IAAE,OAAO,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEhF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CA8InE,CAAA;AAEV;;;;;;;;GAQG;AACH,wBAAgB,cAAc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