@bsv/dpp-overlay-topics 0.4.0-beta.1

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 (87) hide show
  1. package/LICENSE +58 -0
  2. package/README.md +169 -0
  3. package/dist/anchorStorage.d.ts +58 -0
  4. package/dist/anchorStorage.d.ts.map +1 -0
  5. package/dist/anchorStorage.js +72 -0
  6. package/dist/anchorStorage.js.map +1 -0
  7. package/dist/attestationAnchor.d.ts +10 -0
  8. package/dist/attestationAnchor.d.ts.map +1 -0
  9. package/dist/attestationAnchor.js +10 -0
  10. package/dist/attestationAnchor.js.map +1 -0
  11. package/dist/attestationStorage.d.ts +49 -0
  12. package/dist/attestationStorage.d.ts.map +1 -0
  13. package/dist/attestationStorage.js +78 -0
  14. package/dist/attestationStorage.js.map +1 -0
  15. package/dist/capabilities.d.ts +127 -0
  16. package/dist/capabilities.d.ts.map +1 -0
  17. package/dist/capabilities.js +210 -0
  18. package/dist/capabilities.js.map +1 -0
  19. package/dist/engineStorage.d.ts +106 -0
  20. package/dist/engineStorage.d.ts.map +1 -0
  21. package/dist/engineStorage.js +253 -0
  22. package/dist/engineStorage.js.map +1 -0
  23. package/dist/evidenceExport.d.ts +189 -0
  24. package/dist/evidenceExport.d.ts.map +1 -0
  25. package/dist/evidenceExport.js +517 -0
  26. package/dist/evidenceExport.js.map +1 -0
  27. package/dist/history.d.ts +114 -0
  28. package/dist/history.d.ts.map +1 -0
  29. package/dist/history.js +215 -0
  30. package/dist/history.js.map +1 -0
  31. package/dist/index.d.ts +269 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +1223 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/lib.d.ts +31 -0
  36. package/dist/lib.d.ts.map +1 -0
  37. package/dist/lib.js +31 -0
  38. package/dist/lib.js.map +1 -0
  39. package/dist/limits.d.ts +44 -0
  40. package/dist/limits.d.ts.map +1 -0
  41. package/dist/limits.js +44 -0
  42. package/dist/limits.js.map +1 -0
  43. package/dist/lsAttestation.d.ts +21 -0
  44. package/dist/lsAttestation.d.ts.map +1 -0
  45. package/dist/lsAttestation.js +45 -0
  46. package/dist/lsAttestation.js.map +1 -0
  47. package/dist/lsDpp.d.ts +53 -0
  48. package/dist/lsDpp.d.ts.map +1 -0
  49. package/dist/lsDpp.js +148 -0
  50. package/dist/lsDpp.js.map +1 -0
  51. package/dist/lsUoraDpp.d.ts +55 -0
  52. package/dist/lsUoraDpp.d.ts.map +1 -0
  53. package/dist/lsUoraDpp.js +152 -0
  54. package/dist/lsUoraDpp.js.map +1 -0
  55. package/dist/policyConfig.d.ts +31 -0
  56. package/dist/policyConfig.d.ts.map +1 -0
  57. package/dist/policyConfig.js +112 -0
  58. package/dist/policyConfig.js.map +1 -0
  59. package/dist/retraction.d.ts +41 -0
  60. package/dist/retraction.d.ts.map +1 -0
  61. package/dist/retraction.js +147 -0
  62. package/dist/retraction.js.map +1 -0
  63. package/dist/storage.d.ts +117 -0
  64. package/dist/storage.d.ts.map +1 -0
  65. package/dist/storage.js +158 -0
  66. package/dist/storage.js.map +1 -0
  67. package/dist/sync.d.ts +75 -0
  68. package/dist/sync.d.ts.map +1 -0
  69. package/dist/sync.js +118 -0
  70. package/dist/sync.js.map +1 -0
  71. package/dist/tmAttestation.d.ts +36 -0
  72. package/dist/tmAttestation.d.ts.map +1 -0
  73. package/dist/tmAttestation.js +50 -0
  74. package/dist/tmAttestation.js.map +1 -0
  75. package/dist/tmDpp.d.ts +154 -0
  76. package/dist/tmDpp.d.ts.map +1 -0
  77. package/dist/tmDpp.js +397 -0
  78. package/dist/tmDpp.js.map +1 -0
  79. package/dist/tmUoraDpp.d.ts +73 -0
  80. package/dist/tmUoraDpp.d.ts.map +1 -0
  81. package/dist/tmUoraDpp.js +150 -0
  82. package/dist/tmUoraDpp.js.map +1 -0
  83. package/dist/uoraAnchor.d.ts +209 -0
  84. package/dist/uoraAnchor.d.ts.map +1 -0
  85. package/dist/uoraAnchor.js +433 -0
  86. package/dist/uoraAnchor.js.map +1 -0
  87. package/package.json +51 -0
@@ -0,0 +1,253 @@
1
+ import { Utils } from '@bsv/sdk';
2
+ function toOutput(stored, beef) {
3
+ const output = {
4
+ txid: stored.txid,
5
+ outputIndex: stored.outputIndex,
6
+ outputScript: Utils.toArray(stored.outputScript, 'base64'),
7
+ satoshis: stored.satoshis,
8
+ topic: stored.topic,
9
+ spent: stored.spent,
10
+ outputsConsumed: stored.outputsConsumed,
11
+ consumedBy: stored.consumedBy,
12
+ };
13
+ if (stored.blockHeight != null)
14
+ output.blockHeight = stored.blockHeight;
15
+ if (stored.score != null)
16
+ output.score = stored.score;
17
+ if (beef != null)
18
+ output.beef = Utils.toArray(beef, 'base64');
19
+ return output;
20
+ }
21
+ function fromOutput(output) {
22
+ const stored = {
23
+ txid: output.txid,
24
+ outputIndex: Number(output.outputIndex),
25
+ outputScript: Utils.toBase64(output.outputScript),
26
+ satoshis: Number(output.satoshis),
27
+ topic: output.topic,
28
+ spent: output.spent,
29
+ outputsConsumed: output.outputsConsumed ?? [],
30
+ consumedBy: output.consumedBy ?? [],
31
+ };
32
+ if (output.blockHeight != null)
33
+ stored.blockHeight = output.blockHeight;
34
+ if (output.score != null)
35
+ stored.score = output.score;
36
+ return stored;
37
+ }
38
+ const outpointKey = (txid, outputIndex, topic) => `${txid}.${outputIndex}.${topic}`;
39
+ /** Engine storage in memory: for tests, local runs and the offline rehearsal. */
40
+ export class InMemoryOverlayStorage {
41
+ outputs = new Map();
42
+ transactions = new Map();
43
+ applied = new Set();
44
+ interactions = new Map();
45
+ async insertOutput(utxo) {
46
+ const key = outpointKey(utxo.txid, Number(utxo.outputIndex), utxo.topic);
47
+ if (!this.outputs.has(key))
48
+ this.outputs.set(key, fromOutput(utxo));
49
+ if (utxo.beef != null && !this.transactions.has(utxo.txid)) {
50
+ this.transactions.set(utxo.txid, Utils.toBase64(utxo.beef));
51
+ }
52
+ }
53
+ async findOutput(txid, outputIndex, topic, spent, includeBEEF = false) {
54
+ for (const stored of this.outputs.values()) {
55
+ if (stored.txid !== txid || stored.outputIndex !== outputIndex)
56
+ continue;
57
+ if (topic != null && stored.topic !== topic)
58
+ continue;
59
+ if (spent != null && stored.spent !== spent)
60
+ continue;
61
+ return toOutput(stored, includeBEEF ? this.transactions.get(txid) : undefined);
62
+ }
63
+ return null;
64
+ }
65
+ async findOutputsByOutpoints(outpoints, includeBEEF = false) {
66
+ const wanted = new Set(outpoints.map((o) => `${o.txid}.${o.outputIndex}`));
67
+ const found = [];
68
+ for (const stored of this.outputs.values()) {
69
+ if (!wanted.has(`${stored.txid}.${stored.outputIndex}`))
70
+ continue;
71
+ found.push(toOutput(stored, includeBEEF ? this.transactions.get(stored.txid) : undefined));
72
+ }
73
+ return found;
74
+ }
75
+ async findOutputsForTransaction(txid, includeBEEF = false) {
76
+ const beef = includeBEEF ? this.transactions.get(txid) : undefined;
77
+ return [...this.outputs.values()]
78
+ .filter((stored) => stored.txid === txid)
79
+ .map((stored) => toOutput(stored, beef));
80
+ }
81
+ async findUTXOsForTopic(topic, since, limit, includeBEEF = false) {
82
+ let rows = [...this.outputs.values()].filter((stored) => stored.topic === topic && !stored.spent);
83
+ if (since != null && since > 0)
84
+ rows = rows.filter((stored) => (stored.score ?? 0) >= since);
85
+ rows.sort((a, b) => (a.score ?? 0) - (b.score ?? 0));
86
+ if (limit != null && limit > 0)
87
+ rows = rows.slice(0, limit);
88
+ return rows.map((stored) => toOutput(stored, includeBEEF ? this.transactions.get(stored.txid) : undefined));
89
+ }
90
+ async deleteOutput(txid, outputIndex, _topic) {
91
+ for (const [key, stored] of this.outputs) {
92
+ if (stored.txid === txid && stored.outputIndex === outputIndex)
93
+ this.outputs.delete(key);
94
+ }
95
+ const remaining = [...this.outputs.values()].some((stored) => stored.txid === txid);
96
+ if (!remaining)
97
+ this.transactions.delete(txid);
98
+ }
99
+ async markUTXOAsSpent(txid, outputIndex, topic) {
100
+ const stored = this.outputs.get(outpointKey(txid, outputIndex, topic));
101
+ if (stored != null)
102
+ stored.spent = true;
103
+ }
104
+ async markUTXOAsUnspent(txid, outputIndex, topic) {
105
+ const stored = this.outputs.get(outpointKey(txid, outputIndex, topic));
106
+ if (stored != null)
107
+ stored.spent = false;
108
+ }
109
+ async updateConsumedBy(txid, outputIndex, topic, consumedBy) {
110
+ const stored = this.outputs.get(outpointKey(txid, outputIndex, topic));
111
+ if (stored != null)
112
+ stored.consumedBy = consumedBy;
113
+ }
114
+ async updateTransactionBEEF(txid, beef) {
115
+ this.transactions.set(txid, Utils.toBase64(beef));
116
+ }
117
+ async updateOutputBlockHeight(txid, outputIndex, topic, blockHeight) {
118
+ const stored = this.outputs.get(outpointKey(txid, outputIndex, topic));
119
+ if (stored != null)
120
+ stored.blockHeight = blockHeight;
121
+ }
122
+ async insertAppliedTransaction(tx) {
123
+ this.applied.add(`${tx.txid}.${tx.topic}`);
124
+ }
125
+ async doesAppliedTransactionExist(tx) {
126
+ return this.applied.has(`${tx.txid}.${tx.topic}`);
127
+ }
128
+ async deleteAppliedTransaction(txid, topic) {
129
+ this.applied.delete(`${txid}.${topic}`);
130
+ }
131
+ async updateLastInteraction(host, topic, since) {
132
+ this.interactions.set(`${host}.${topic}`, since);
133
+ }
134
+ async getLastInteraction(host, topic) {
135
+ return this.interactions.get(`${host}.${topic}`) ?? 0;
136
+ }
137
+ }
138
+ /** Engine storage on MongoDB: the hosted deployment's persistence. */
139
+ export class MongoOverlayStorage {
140
+ outputs;
141
+ transactions;
142
+ applied;
143
+ interactions;
144
+ constructor(db, prefix = 'overlay') {
145
+ this.outputs = db.collection(`${prefix}Outputs`);
146
+ this.transactions = db.collection(`${prefix}Transactions`);
147
+ this.applied = db.collection(`${prefix}AppliedTransactions`);
148
+ this.interactions = db.collection(`${prefix}Interactions`);
149
+ }
150
+ /** Call once at boot; index creation is not on any request path. */
151
+ async ensureIndexes() {
152
+ await this.outputs.createIndex({ txid: 1, outputIndex: 1, topic: 1 }, { unique: true, name: 'outpoint_topic' });
153
+ await this.outputs.createIndex({ txid: 1, outputIndex: 1 }, { name: 'outpoint' });
154
+ await this.outputs.createIndex({ topic: 1, spent: 1, score: 1 }, { name: 'topic_spent_score' });
155
+ await this.transactions.createIndex({ txid: 1 }, { unique: true, name: 'txid' });
156
+ await this.applied.createIndex({ txid: 1, topic: 1 }, { unique: true, name: 'applied' });
157
+ await this.interactions.createIndex({ host: 1, topic: 1 }, { unique: true, name: 'host_topic' });
158
+ }
159
+ async beefFor(txids) {
160
+ if (txids.length === 0)
161
+ return new Map();
162
+ const rows = await this.transactions.find({ txid: { $in: txids } }).toArray();
163
+ return new Map(rows.map((row) => [row.txid, row.beef]));
164
+ }
165
+ async insertOutput(utxo) {
166
+ const stored = fromOutput(utxo);
167
+ // $setOnInsert only: an output already admitted is never rewritten, which
168
+ // is what KnexStorage does with its existence check.
169
+ await this.outputs.updateOne({ txid: stored.txid, outputIndex: stored.outputIndex, topic: stored.topic }, { $setOnInsert: stored }, { upsert: true });
170
+ if (utxo.beef != null) {
171
+ await this.transactions.updateOne({ txid: stored.txid }, { $setOnInsert: { txid: stored.txid, beef: Utils.toBase64(utxo.beef) } }, { upsert: true });
172
+ }
173
+ }
174
+ async findOutput(txid, outputIndex, topic, spent, includeBEEF = false) {
175
+ const filter = { txid, outputIndex };
176
+ if (topic != null)
177
+ filter.topic = topic;
178
+ if (spent != null)
179
+ filter.spent = spent;
180
+ const stored = await this.outputs.findOne(filter);
181
+ if (stored == null)
182
+ return null;
183
+ const beef = includeBEEF ? (await this.beefFor([txid])).get(txid) : undefined;
184
+ return toOutput(stored, beef);
185
+ }
186
+ async findOutputsByOutpoints(outpoints, includeBEEF = false) {
187
+ if (outpoints.length === 0)
188
+ return [];
189
+ const stored = await this.outputs
190
+ .find({ $or: outpoints.map((o) => ({ txid: o.txid, outputIndex: o.outputIndex })) })
191
+ .toArray();
192
+ if (!includeBEEF)
193
+ return stored.map((row) => toOutput(row));
194
+ const beef = await this.beefFor([...new Set(stored.map((row) => row.txid))]);
195
+ return stored.map((row) => toOutput(row, beef.get(row.txid)));
196
+ }
197
+ async findOutputsForTransaction(txid, includeBEEF = false) {
198
+ const stored = await this.outputs.find({ txid }).toArray();
199
+ const beef = includeBEEF ? (await this.beefFor([txid])).get(txid) : undefined;
200
+ return stored.map((row) => toOutput(row, beef));
201
+ }
202
+ async findUTXOsForTopic(topic, since, limit, includeBEEF = false) {
203
+ const filter = { topic, spent: false };
204
+ if (since != null && since > 0)
205
+ filter.score = { $gte: since };
206
+ let cursor = this.outputs.find(filter).sort({ score: 1 });
207
+ if (limit != null && limit > 0)
208
+ cursor = cursor.limit(limit);
209
+ const stored = await cursor.toArray();
210
+ if (!includeBEEF)
211
+ return stored.map((row) => toOutput(row));
212
+ const beef = await this.beefFor([...new Set(stored.map((row) => row.txid))]);
213
+ return stored.map((row) => toOutput(row, beef.get(row.txid)));
214
+ }
215
+ async deleteOutput(txid, outputIndex, _topic) {
216
+ await this.outputs.deleteMany({ txid, outputIndex });
217
+ const remaining = await this.outputs.countDocuments({ txid }, { limit: 1 });
218
+ if (remaining === 0)
219
+ await this.transactions.deleteOne({ txid });
220
+ }
221
+ async markUTXOAsSpent(txid, outputIndex, topic) {
222
+ await this.outputs.updateOne({ txid, outputIndex, topic }, { $set: { spent: true } });
223
+ }
224
+ async markUTXOAsUnspent(txid, outputIndex, topic) {
225
+ await this.outputs.updateOne({ txid, outputIndex, topic }, { $set: { spent: false } });
226
+ }
227
+ async updateConsumedBy(txid, outputIndex, topic, consumedBy) {
228
+ await this.outputs.updateOne({ txid, outputIndex, topic }, { $set: { consumedBy } });
229
+ }
230
+ async updateTransactionBEEF(txid, beef) {
231
+ await this.transactions.updateOne({ txid }, { $set: { beef: Utils.toBase64(beef) } }, { upsert: true });
232
+ }
233
+ async updateOutputBlockHeight(txid, outputIndex, topic, blockHeight) {
234
+ await this.outputs.updateOne({ txid, outputIndex, topic }, { $set: { blockHeight } });
235
+ }
236
+ async insertAppliedTransaction(tx) {
237
+ await this.applied.updateOne({ txid: tx.txid, topic: tx.topic }, { $setOnInsert: { txid: tx.txid, topic: tx.topic } }, { upsert: true });
238
+ }
239
+ async doesAppliedTransactionExist(tx) {
240
+ return (await this.applied.countDocuments({ txid: tx.txid, topic: tx.topic }, { limit: 1 })) > 0;
241
+ }
242
+ async deleteAppliedTransaction(txid, topic) {
243
+ await this.applied.deleteOne({ txid, topic });
244
+ }
245
+ async updateLastInteraction(host, topic, since) {
246
+ await this.interactions.updateOne({ host, topic }, { $set: { since } }, { upsert: true });
247
+ }
248
+ async getLastInteraction(host, topic) {
249
+ const row = await this.interactions.findOne({ host, topic });
250
+ return row?.since ?? 0;
251
+ }
252
+ }
253
+ //# sourceMappingURL=engineStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineStorage.js","sourceRoot":"","sources":["../src/engineStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AA+EhC,SAAS,QAAQ,CAAC,MAAoB,EAAE,IAAa;IACnD,MAAM,MAAM,GAAW;QACrB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC;QAC1D,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAA;IACD,IAAI,MAAM,CAAC,WAAW,IAAI,IAAI;QAAE,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;IACvE,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI;QAAE,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;IACrD,IAAI,IAAI,IAAI,IAAI;QAAE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EAAE,EAAE,CAAC,KAAK,EAAE,EAClC,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,EACpD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,2BAA2B,CAAC,EAAsB;QACtD,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CACvC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EAClC,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC,GAAG,CAAC,CAAA;IACR,CAAC;IAED,KAAK,CAAC,wBAAwB,CAAC,IAAY,EAAE,KAAa;QACxD,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,IAAY,EAAE,KAAa,EAAE,KAAa;QACpE,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3F,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAY,EAAE,KAAa;QAClD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAC5D,OAAO,GAAG,EAAE,KAAK,IAAI,CAAC,CAAA;IACxB,CAAC;CACF"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * The evidence package export (`spec/portable-evidence.md` section 2,
3
+ * `contracts/evidence-package.schema.json`): everything this node holds about
4
+ * one passport, as content-addressed files under a manifest the node signs.
5
+ *
6
+ * What goes in, from this node's own stores and nothing fetched: every
7
+ * retained state's raw transaction under `transactions/`, the BEEF it is held
8
+ * in under `proofs/` (the merkle path and ancestors a verifier needs, once
9
+ * `/arc-ingest` has delivered the proof), the publisher policy chain under
10
+ * `authority/` when one is configured, the spend observations under `status/`
11
+ * and a verification report under `reports/`. The signature says this node
12
+ * assembled these bytes; it says nothing about their truth, which a reader
13
+ * establishes from the bytes and its own header source, and nothing about
14
+ * completeness beyond the snapshot the manifest names.
15
+ *
16
+ * Two routes build from the same pieces. `GET /evidence-package` is the
17
+ * bounded package: the newest states within the cap, the rest declared
18
+ * absent, complete for its snapshot only when the cap was not reached. `GET
19
+ * /evidence-export` is the complete export: parts over one snapshot, oldest
20
+ * first, each a package of its own over a contiguous sequence range bounded
21
+ * by states and by bytes, resumed by a cursor, tiling the snapshot so a
22
+ * reader joins them with `joinEvidenceExport` and knows whether it holds
23
+ * everything the snapshot held (`contracts/evidence-export.schema.json`).
24
+ *
25
+ * The archive form is this build's own, as the standard leaves it: a JSON
26
+ * envelope `{ manifest, files: { "<path>": "<base64>" } }`, so a browser or a
27
+ * script reads it without an archive library and the file map is exactly the
28
+ * one `inspectEvidencePackage` takes.
29
+ */
30
+ import { type ChainTracker, type PrivateKey } from '@bsv/sdk';
31
+ import type { Storage } from '@bsv/overlay';
32
+ import { type EvidencePackageManifest, type PackageInspection } from '@bsv/dpp-core';
33
+ import type { HistoryPaginator } from './history.js';
34
+ import { type PublisherPolicyConfig } from './policyConfig.js';
35
+ /** The archive form: the manifest beside every inventoried file, base64 by path. */
36
+ export interface EvidencePackageEnvelope {
37
+ manifest: EvidencePackageManifest;
38
+ files: Record<string, string>;
39
+ }
40
+ export interface EvidenceExportRequest {
41
+ passportId: string;
42
+ paginator: HistoryPaginator;
43
+ engineStorage: Storage;
44
+ /** EXPORT_SIGNING_KEY; the manifest's signer is its public key. */
45
+ signingKey: PrivateKey;
46
+ publisherPolicy?: PublisherPolicyConfig;
47
+ serviceIdentityKey?: string;
48
+ ownerConsent?: boolean | {
49
+ authorities: string[];
50
+ };
51
+ /** The version 2 options the node admits under (CONTROL_AUTHORITIES, ACCEPTANCE_COMMITMENT). */
52
+ controlAuthorities?: string[];
53
+ managedAcceptance?: boolean;
54
+ chainTracker?: ChainTracker | 'scripts only';
55
+ /** The export instant, injected so a test can pin it. */
56
+ now: Date;
57
+ /** What the manifest names as the exporter's software. */
58
+ software: string;
59
+ }
60
+ /** The version of the complete export's wrapper, `contracts/evidence-export.schema.json`. */
61
+ export declare const EVIDENCE_EXPORT_VERSION = "1";
62
+ /**
63
+ * The coverage record of a part: every fact a reader uses to establish that
64
+ * the parts of an export tile a snapshot, signed by the exporter beside the
65
+ * package and bound to the exact signed manifest by its digest. A wrapper
66
+ * field outside this record (the cursor, the package bytes) establishes
67
+ * nothing about coverage; a reader that trusted an unsigned `final` or range
68
+ * could be handed a genuine first part dressed as a whole export.
69
+ */
70
+ export interface ExportCoverage {
71
+ exportVersion: typeof EVIDENCE_EXPORT_VERSION;
72
+ passportId: string;
73
+ snapshot: {
74
+ source: string;
75
+ id: string;
76
+ sequence: number;
77
+ };
78
+ part: {
79
+ index: number;
80
+ sequenceRange: {
81
+ from: number;
82
+ to: number;
83
+ };
84
+ states: number;
85
+ };
86
+ final: boolean;
87
+ /** SHA-256 of the canonical JSON of the part's signed package manifest, signature value included. */
88
+ manifestSha256: string;
89
+ signature: {
90
+ suite: 'bsv-ecdsa-der';
91
+ signer: string;
92
+ };
93
+ }
94
+ /** One part of the complete export, as the wire carries it: the signed coverage record, the cursor and the package. */
95
+ export interface EvidenceExportPart extends Omit<ExportCoverage, 'signature'> {
96
+ nextCursor: string | null;
97
+ signature: {
98
+ suite: 'bsv-ecdsa-der';
99
+ signer: string;
100
+ value: string;
101
+ };
102
+ package: EvidencePackageEnvelope;
103
+ }
104
+ /** The digest the coverage record binds the package by: the manifest exactly as signed, canonical JSON, signature value included. */
105
+ export declare function exportManifestDigest(manifest: EvidencePackageManifest): string;
106
+ /** The coverage record a part carries: the wrapper without its cursor, its package and the signature value. */
107
+ export declare function exportCoverageOf(part: Omit<EvidenceExportPart, 'nextCursor' | 'package'> | EvidenceExportPart): ExportCoverage;
108
+ /** The bytes the exporter signs for a part: the coverage record in canonical JSON, UTF-8, exactly as the manifest's own preimage rule; ECDSA then runs over their SHA-256. */
109
+ export declare function exportCoveragePreimage(part: Omit<EvidenceExportPart, 'nextCursor' | 'package'> | EvidenceExportPart): number[];
110
+ /** The scope sentence a part's manifest carries, rendered from the coverage record so the signed manifest and the signed coverage say one thing. */
111
+ export declare function exportScopeText(passportId: string, snapshotId: string, index: number, from: number, to: number, final: boolean): string;
112
+ export interface ExportPartInspection {
113
+ /** The coverage signature verifies under the record's signer, or null when the record has no canonical form. */
114
+ coverageAuthentic: boolean | null;
115
+ /** The package manifest hashes to the digest the coverage record names, and its own signed declarations agree with the record. */
116
+ manifestBound: boolean;
117
+ /** The package on its three questions, as `inspectEvidencePackage` answers them. */
118
+ package: PackageInspection;
119
+ failures: string[];
120
+ }
121
+ /**
122
+ * Inspect one part: the coverage signature, the binding of the package to
123
+ * the record, the agreement of the signed manifest with the record, and the
124
+ * package itself. Only a part whose coverage is authentic and bound may say
125
+ * anything about what an export covers.
126
+ */
127
+ export declare function inspectEvidenceExportPart(part: EvidenceExportPart, options?: {
128
+ expectedPassportId?: string;
129
+ expectedSigner?: string;
130
+ }): ExportPartInspection;
131
+ export interface EvidencePartRequest extends Omit<EvidenceExportRequest, 'chainTracker' | 'ownerConsent' | 'controlAuthorities' | 'managedAcceptance'> {
132
+ /** The nextCursor of the previous part; absent or empty for the first. */
133
+ cursor?: string | null;
134
+ /** The bounds of one part; the limits module's numbers unless a test narrows them. */
135
+ maxStates?: number;
136
+ maxBytes?: number;
137
+ }
138
+ /** The tiers this node never holds, named as the disclosure scopes name them (`spec/record-model.md` section 7). */
139
+ export declare const WITHHELD_TIERS: string[];
140
+ /**
141
+ * Build the bounded package, or return undefined when this node holds
142
+ * nothing for the passport, which the route answers as 404 rather than as an
143
+ * empty package claiming completeness over nothing.
144
+ */
145
+ export declare function buildEvidencePackage(request: EvidenceExportRequest): Promise<EvidencePackageEnvelope | undefined>;
146
+ /**
147
+ * Build one part of the complete export: the first when no cursor is given,
148
+ * which pins the snapshot, or the part the cursor names over the snapshot it
149
+ * carries. Returns undefined when this node holds nothing for the passport
150
+ * in the snapshot. A cursor of the wrong kind, for another passport, from
151
+ * another process or older than the TTL throws the paginator's named
152
+ * refusal, which the route answers as it answers a history cursor.
153
+ */
154
+ export declare function buildEvidenceExportPart(request: EvidencePartRequest): Promise<EvidenceExportPart | undefined>;
155
+ /** The envelope's file map as `inspectEvidencePackage` takes it. */
156
+ export declare function envelopeFiles(envelope: EvidencePackageEnvelope): Map<string, number[]>;
157
+ export interface JoinedEvidenceExport {
158
+ passportId?: string;
159
+ snapshotId?: string;
160
+ /** True only when every part of the snapshot is present, in order, tiling its range, each package inspecting clean, and the final part is last. */
161
+ complete: boolean;
162
+ problems: string[];
163
+ manifests: EvidencePackageManifest[];
164
+ /** Every inventoried file across the parts, by path; a path repeated across parts is admitted only with identical bytes. */
165
+ files: Map<string, number[]>;
166
+ /** The absences every part declared, by reference. */
167
+ absent: string[];
168
+ }
169
+ /**
170
+ * Join the parts of one complete export as a reader does. First each part on
171
+ * its own: the coverage signature under the exporter's key, the binding of
172
+ * the package to the record by digest, the agreement of the signed manifest
173
+ * with the record, and the package on its three questions. Only a part that
174
+ * passes all of that says anything about coverage; then, across the parts
175
+ * that do: the same passport, the same snapshot, the same exporter, indexes
176
+ * 1 to n with no repeat, ranges that tile the snapshot from 1 to its
177
+ * sequence with no gap and no overlap, and the signed final flag on the last
178
+ * part alone, ending at the snapshot's sequence. Anything else is a problem
179
+ * by sentence and `complete` is false. The join establishes what the
180
+ * exporter asserted it held at that snapshot and that every part of that
181
+ * assertion arrived; a reader still verifies every transaction, proof and
182
+ * signature inside, and no signature proves the exporter held everything
183
+ * that exists elsewhere.
184
+ */
185
+ export declare function joinEvidenceExport(parts: EvidenceExportPart[], options?: {
186
+ expectedPassportId?: string;
187
+ expectedSigner?: string;
188
+ }): JoinedEvidenceExport;
189
+ //# sourceMappingURL=evidenceExport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidenceExport.d.ts","sourceRoot":"","sources":["../src/evidenceExport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAkD,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAA;AAC7G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAaL,KAAK,uBAAuB,EAG5B,KAAK,iBAAiB,EAGvB,MAAM,eAAe,CAAA;AAItB,OAAO,KAAK,EAAE,gBAAgB,EAAY,MAAM,cAAc,CAAA;AAE9D,OAAO,EAAgB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAG5E,oFAAoF;AACpF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,aAAa,EAAE,OAAO,CAAA;IACtB,mEAAmE;IACnE,UAAU,EAAE,UAAU,CAAA;IACtB,eAAe,CAAC,EAAE,qBAAqB,CAAA;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,YAAY,CAAC,EAAE,OAAO,GAAG;QAAE,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;IAClD,gGAAgG;IAChG,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,YAAY,CAAC,EAAE,YAAY,GAAG,cAAc,CAAA;IAC5C,yDAAyD;IACzD,GAAG,EAAE,IAAI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