@bsv/overlay 0.1.2 → 0.1.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.
@@ -0,0 +1,274 @@
1
+ import { Transaction } from '@bsv/sdk';
2
+ export class GASPVersionMismatchError extends Error {
3
+ code;
4
+ currentVersion;
5
+ foreignVersion;
6
+ constructor(message, currentVersion, foreignVersion) {
7
+ super(message);
8
+ this.code = 'ERR_GASP_VERSION_MISMATCH';
9
+ this.currentVersion = currentVersion;
10
+ this.foreignVersion = foreignVersion;
11
+ }
12
+ }
13
+ /**
14
+ * Main class implementing the Graph Aware Sync Protocol.
15
+ */
16
+ export class GASP {
17
+ version;
18
+ storage;
19
+ remote;
20
+ lastInteraction;
21
+ logPrefix;
22
+ log;
23
+ /**
24
+ *
25
+ * @param storage The GASP Storage interface to use
26
+ * @param remote The GASP Remote interface to use
27
+ * @param lastInteraction The timestamp when we last interacted with this remote party
28
+ */
29
+ constructor(storage, remote, lastInteraction = 0, logPrefix = '[GASP] ', log = false) {
30
+ this.storage = storage;
31
+ this.remote = remote;
32
+ this.lastInteraction = lastInteraction;
33
+ this.version = 1;
34
+ this.logPrefix = logPrefix;
35
+ this.log = log;
36
+ this.validateTimestamp(this.lastInteraction);
37
+ this.logData(`GASP initialized with version: ${this.version}, lastInteraction: ${this.lastInteraction}`);
38
+ }
39
+ logData(...data) {
40
+ if (this.log) {
41
+ console.log(this.logPrefix, ...data);
42
+ }
43
+ }
44
+ validateTimestamp(timestamp) {
45
+ if (typeof timestamp !== 'number' || isNaN(timestamp) || timestamp < 0 || !Number.isInteger(timestamp)) {
46
+ throw new Error('Invalid timestamp format');
47
+ }
48
+ }
49
+ /**
50
+ * Computes a 36-byte structure from a transaction ID and output index.
51
+ * @param txid The transaction ID.
52
+ * @param index The output index.
53
+ * @returns A string representing the 36-byte structure.
54
+ */
55
+ compute36ByteStructure(txid, index) {
56
+ const result = `${txid}.${index.toString()}`;
57
+ this.logData(`Computed 36-byte structure: ${result} from txid: ${txid}, index: ${index}`);
58
+ return result;
59
+ }
60
+ /**
61
+ * Deconstructs a 36-byte structure into a transaction ID and output index.
62
+ * @param outpoint The 36-byte structure.
63
+ * @returns An object containing the transaction ID and output index.
64
+ */
65
+ deconstruct36ByteStructure(outpoint) {
66
+ const [txid, index] = outpoint.split('.');
67
+ const result = {
68
+ txid,
69
+ outputIndex: parseInt(index, 10)
70
+ };
71
+ this.logData(`Deconstructed 36-byte structure: ${outpoint} into txid: ${txid}, outputIndex: ${result.outputIndex}`);
72
+ return result;
73
+ }
74
+ /**
75
+ * Computes the transaction ID for a given transaction.
76
+ * @param tx The transaction string.
77
+ * @returns The computed transaction ID.
78
+ */
79
+ computeTXID(tx) {
80
+ const txid = Transaction.fromHex(tx).id('hex');
81
+ this.logData(`Computed TXID: ${txid} from transaction: ${tx}`);
82
+ return txid;
83
+ }
84
+ /**
85
+ * Synchronizes the transaction data between the local and remote participants.
86
+ */
87
+ async sync() {
88
+ this.logData(`Starting sync process. Last interaction timestamp: ${this.lastInteraction}`);
89
+ debugger;
90
+ const initialRequest = await this.buildInitialRequest(this.lastInteraction);
91
+ const initialResponse = await this.remote.getInitialResponse(initialRequest);
92
+ if (initialResponse.UTXOList.length > 0) {
93
+ const foreignUTXOs = await this.storage.findKnownUTXOs(0);
94
+ await Promise.all(initialResponse.UTXOList
95
+ .filter(x => !foreignUTXOs.some(y => x.txid === y.txid && x.outputIndex === y.outputIndex))
96
+ .map(async (UTXO) => {
97
+ try {
98
+ this.logData(`Requesting node for UTXO: ${JSON.stringify(UTXO)}`);
99
+ const resolvedNode = await this.remote.requestNode(this.compute36ByteStructure(UTXO.txid, UTXO.outputIndex), UTXO.txid, UTXO.outputIndex, true);
100
+ this.logData(`Received unspent graph node from remote: ${JSON.stringify(resolvedNode)}`);
101
+ await this.processIncomingNode(resolvedNode);
102
+ await this.completeGraph(resolvedNode.graphID);
103
+ }
104
+ catch (e) {
105
+ this.logData(`Error with incoming UTXO ${UTXO.txid}.${UTXO.outputIndex}: ${e.message}`);
106
+ }
107
+ }));
108
+ }
109
+ const initialReply = await this.getInitialReply(initialResponse);
110
+ this.logData(`Received initial reply: ${JSON.stringify(initialReply)}`);
111
+ if (initialReply.UTXOList.length > 0) {
112
+ await Promise.all(initialReply.UTXOList.map(async (UTXO) => {
113
+ try {
114
+ this.logData(`Hydrating GASP node for UTXO: ${JSON.stringify(UTXO)}`);
115
+ const outgoingNode = await this.storage.hydrateGASPNode(this.compute36ByteStructure(UTXO.txid, UTXO.outputIndex), UTXO.txid, UTXO.outputIndex, true);
116
+ this.logData(`Sending unspent graph node for remote: ${JSON.stringify(outgoingNode)}`);
117
+ await this.processOutgoingNode(outgoingNode);
118
+ }
119
+ catch (e) {
120
+ this.logData(`Error with outgoing UTXO ${UTXO.txid}.${UTXO.outputIndex}: ${e.message}`);
121
+ }
122
+ }));
123
+ }
124
+ this.logData('Sync completed!');
125
+ }
126
+ /**
127
+ * Builds the initial request for the sync process.
128
+ * @returns A promise for the initial request object.
129
+ */
130
+ async buildInitialRequest(since) {
131
+ const request = {
132
+ version: this.version,
133
+ since
134
+ };
135
+ this.logData(`Built initial request: ${JSON.stringify(request)}`);
136
+ return request;
137
+ }
138
+ /**
139
+ * Builds the initial response based on the received request.
140
+ * @param request The initial request object.
141
+ * @returns A promise for an initial response
142
+ */
143
+ async getInitialResponse(request) {
144
+ this.logData(`Received initial request: ${JSON.stringify(request)}`);
145
+ if (request.version !== this.version) {
146
+ const error = new GASPVersionMismatchError(`GASP version mismatch. Current version: ${this.version}, foreign version: ${request.version}`, this.version, request.version);
147
+ console.error(`GASP version mismatch error: ${error.message}`);
148
+ throw error;
149
+ }
150
+ this.validateTimestamp(request.since);
151
+ const response = {
152
+ since: this.lastInteraction,
153
+ UTXOList: await this.storage.findKnownUTXOs(request.since)
154
+ };
155
+ this.logData(`Built initial response: ${JSON.stringify(response)}`);
156
+ return response;
157
+ }
158
+ /**
159
+ * Builds the initial reply based on the received response.
160
+ * @param response The initial response object.
161
+ * @returns A promise for an initial reply
162
+ */
163
+ async getInitialReply(response) {
164
+ this.logData(`Received initial response: ${JSON.stringify(response)}`);
165
+ const knownUTXOs = await this.storage.findKnownUTXOs(response.since);
166
+ const filteredUTXOs = knownUTXOs.filter(x => !response.UTXOList.some(y => y.txid === x.txid && y.outputIndex === x.outputIndex));
167
+ const reply = {
168
+ UTXOList: filteredUTXOs
169
+ };
170
+ this.logData(`Built initial reply: ${JSON.stringify(reply)}`);
171
+ return reply;
172
+ }
173
+ /**
174
+ * Provides a requested node to a foreign instance who requested it.
175
+ */
176
+ async requestNode(graphID, txid, outputIndex, metadata) {
177
+ this.logData(`Remote is requesting node with graphID: ${graphID}, txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
178
+ const node = await this.storage.hydrateGASPNode(graphID, txid, outputIndex, metadata);
179
+ this.logData(`Returning node: ${JSON.stringify(node)}`);
180
+ return node;
181
+ }
182
+ /**
183
+ * Provides a set of inputs we care about after processing a new incoming node.
184
+ * Also finalizes or discards a graph if no additional data is requested from the foreign instance.
185
+ */
186
+ async submitNode(node) {
187
+ this.logData(`Remote party is submitting node: ${JSON.stringify(node)}`);
188
+ await this.storage.appendToGraph(node);
189
+ const requestedInputs = await this.storage.findNeededInputs(node);
190
+ this.logData(`Requested inputs: ${JSON.stringify(requestedInputs)}`);
191
+ if (!requestedInputs) {
192
+ await this.completeGraph(node.graphID);
193
+ }
194
+ return requestedInputs;
195
+ }
196
+ /**
197
+ * Handles the completion of a newly-synced graph
198
+ * @param {string} graphID The ID of the newly-synced graph
199
+ */
200
+ async completeGraph(graphID) {
201
+ this.logData(`Completing newly-synced graph: ${graphID}`);
202
+ try {
203
+ await this.storage.validateGraphAnchor(graphID);
204
+ this.logData(`Graph validated for node: ${graphID}`);
205
+ await this.storage.finalizeGraph(graphID);
206
+ this.logData(`Graph finalized for node: ${graphID}`);
207
+ }
208
+ catch (e) {
209
+ this.logData(`Error validating graph: ${e.message}. Discarding graph for node: ${graphID}`);
210
+ await this.storage.discardGraph(graphID);
211
+ }
212
+ }
213
+ /**
214
+ * Processes an incoming node from the remote participant.
215
+ * @param node The incoming GASP node.
216
+ * @param spentBy The 36-byte structure of the node that spent this one, if applicable.
217
+ */
218
+ async processIncomingNode(node, spentBy, seenNodes = new Set()) {
219
+ const nodeId = `${this.computeTXID(node.rawTx)}.${node.outputIndex}`;
220
+ this.logData(`Processing incoming node: ${JSON.stringify(node)}, spentBy: ${spentBy}`);
221
+ if (seenNodes.has(nodeId)) {
222
+ this.logData(`Node ${nodeId} already processed, skipping.`);
223
+ return; // Prevent infinite recursion
224
+ }
225
+ seenNodes.add(nodeId);
226
+ await this.storage.appendToGraph(node, spentBy);
227
+ const neededInputs = await this.storage.findNeededInputs(node);
228
+ this.logData(`Needed inputs for node ${nodeId}: ${JSON.stringify(neededInputs)}`);
229
+ if (neededInputs) {
230
+ await Promise.all(Object.entries(neededInputs.requestedInputs).map(async ([outpoint, { metadata }]) => {
231
+ const { txid, outputIndex } = this.deconstruct36ByteStructure(outpoint);
232
+ this.logData(`Requesting new node for txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
233
+ const newNode = await this.remote.requestNode(node.graphID, txid, outputIndex, metadata);
234
+ this.logData(`Received new node: ${JSON.stringify(newNode)}`);
235
+ await this.processIncomingNode(newNode, this.compute36ByteStructure(this.computeTXID(node.rawTx), node.outputIndex), seenNodes);
236
+ }));
237
+ }
238
+ }
239
+ /**
240
+ * Processes an outgoing node to the remote participant.
241
+ * @param node The outgoing GASP node.
242
+ */
243
+ async processOutgoingNode(node, seenNodes = new Set()) {
244
+ const nodeId = `${this.computeTXID(node.rawTx)}.${node.outputIndex}`;
245
+ this.logData(`Processing outgoing node: ${JSON.stringify(node)}`);
246
+ if (seenNodes.has(nodeId)) {
247
+ this.logData(`Node ${nodeId} already processed, skipping.`);
248
+ return; // Prevent infinite recursion
249
+ }
250
+ seenNodes.add(nodeId);
251
+ if (this.remote.submitNode === undefined) {
252
+ throw new Error('Remote does not support GASP node submission!');
253
+ }
254
+ const response = await this.remote.submitNode(node);
255
+ this.logData(`Received response for submitted node: ${JSON.stringify(response)}`);
256
+ if (response) {
257
+ await Promise.all(Object.entries(response.requestedInputs).map(async ([outpoint, { metadata }]) => {
258
+ const { txid, outputIndex } = this.deconstruct36ByteStructure(outpoint);
259
+ try {
260
+ this.logData(`Hydrating node for txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
261
+ const hydratedNode = await this.storage.hydrateGASPNode(node.graphID, txid, outputIndex, metadata);
262
+ this.logData(`Hydrated node: ${JSON.stringify(hydratedNode)}`);
263
+ await this.processOutgoingNode(hydratedNode, seenNodes);
264
+ }
265
+ catch (e) {
266
+ this.logData(`Error hydrating node: ${e.message}`);
267
+ // If we can't send the outgoing node, we just stop. The remote won't validate the anchor, and their temporary graph will be discarded.
268
+ return;
269
+ }
270
+ }));
271
+ }
272
+ }
273
+ }
274
+ //# sourceMappingURL=GASP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GASP.js","sourceRoot":"","sources":["../../../src/GASP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAsHtC,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,IAAI,CAA6B;IACjC,cAAc,CAAQ;IACtB,cAAc,CAAQ;IAEtB,YAAY,OAAe,EAAE,cAAsB,EAAE,cAAsB;QACzE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;QACvC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACtC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,IAAI;IACf,OAAO,CAAQ;IACf,OAAO,CAAa;IACpB,MAAM,CAAY;IAClB,eAAe,CAAQ;IACvB,SAAS,CAAQ;IACjB,GAAG,CAAS;IAEZ;;;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