@bsv/overlay 0.4.8 → 0.5.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.
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/src/AdmittanceInstructions.js +3 -0
- package/dist/cjs/src/AdmittanceInstructions.js.map +1 -0
- package/dist/cjs/src/Engine.js +87 -71
- package/dist/cjs/src/Engine.js.map +1 -1
- package/dist/cjs/src/LookupAnswer.js +3 -0
- package/dist/cjs/src/LookupAnswer.js.map +1 -0
- package/dist/cjs/src/LookupQuestion.js +3 -0
- package/dist/cjs/src/LookupQuestion.js.map +1 -0
- package/dist/cjs/src/SHIPAdvertisement.js +3 -0
- package/dist/cjs/src/SHIPAdvertisement.js.map +1 -0
- package/dist/cjs/src/SLAPAdvertisement.js +3 -0
- package/dist/cjs/src/SLAPAdvertisement.js.map +1 -0
- package/dist/cjs/src/STEAK.js +3 -0
- package/dist/cjs/src/STEAK.js.map +1 -0
- package/dist/cjs/src/TaggedBEEF.js +3 -0
- package/dist/cjs/src/TaggedBEEF.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/AdmittanceInstructions.js +2 -0
- package/dist/esm/src/AdmittanceInstructions.js.map +1 -0
- package/dist/esm/src/Engine.js +86 -70
- package/dist/esm/src/Engine.js.map +1 -1
- package/dist/esm/src/LookupAnswer.js +2 -0
- package/dist/esm/src/LookupAnswer.js.map +1 -0
- package/dist/esm/src/LookupQuestion.js +2 -0
- package/dist/esm/src/LookupQuestion.js.map +1 -0
- package/dist/esm/src/SHIPAdvertisement.js +2 -0
- package/dist/esm/src/SHIPAdvertisement.js.map +1 -0
- package/dist/esm/src/SLAPAdvertisement.js +2 -0
- package/dist/esm/src/SLAPAdvertisement.js.map +1 -0
- package/dist/esm/src/STEAK.js +2 -0
- package/dist/esm/src/STEAK.js.map +1 -0
- package/dist/esm/src/TaggedBEEF.js +2 -0
- package/dist/esm/src/TaggedBEEF.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/AdmittanceInstructions.d.ts +14 -0
- package/dist/types/src/AdmittanceInstructions.d.ts.map +1 -0
- package/dist/types/src/Engine.d.ts +9 -2
- package/dist/types/src/Engine.d.ts.map +1 -1
- package/dist/types/src/LookupAnswer.d.ts +15 -0
- package/dist/types/src/LookupAnswer.d.ts.map +1 -0
- package/dist/types/src/LookupQuestion.d.ts +15 -0
- package/dist/types/src/LookupQuestion.d.ts.map +1 -0
- package/dist/types/src/SHIPAdvertisement.d.ts +9 -0
- package/dist/types/src/SHIPAdvertisement.d.ts.map +1 -0
- package/dist/types/src/SLAPAdvertisement.d.ts +9 -0
- package/dist/types/src/SLAPAdvertisement.d.ts.map +1 -0
- package/dist/types/src/STEAK.d.ts +10 -0
- package/dist/types/src/STEAK.d.ts.map +1 -0
- package/dist/types/src/TaggedBEEF.d.ts +11 -0
- package/dist/types/src/TaggedBEEF.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Engine.ts +125 -79
- package/src/__tests/Engine.test.ts +2 -1
- package/dist/cjs/src/GASP/GASP.js +0 -283
- package/dist/cjs/src/GASP/GASP.js.map +0 -1
- package/dist/esm/src/GASP/GASP.js +0 -288
- package/dist/esm/src/GASP/GASP.js.map +0 -1
- package/dist/types/src/GASP/GASP.d.ts +0 -218
- package/dist/types/src/GASP/GASP.d.ts.map +0 -1
|
@@ -1,288 +0,0 @@
|
|
|
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
|
-
unidirectional;
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param storage The GASP Storage interface to use
|
|
27
|
-
* @param remote The GASP Remote interface to use
|
|
28
|
-
* @param lastInteraction The timestamp when we last interacted with this remote party
|
|
29
|
-
* @param logPrefix Optional prefix for log messages
|
|
30
|
-
* @param log Whether to log messages
|
|
31
|
-
* @param unidirectional Whether to disable the "reply" side and do pull-only
|
|
32
|
-
*/
|
|
33
|
-
constructor(storage, remote, lastInteraction = 0, logPrefix = '[GASP] ', log = false, unidirectional = false) {
|
|
34
|
-
this.storage = storage;
|
|
35
|
-
this.remote = remote;
|
|
36
|
-
this.lastInteraction = lastInteraction;
|
|
37
|
-
this.version = 1;
|
|
38
|
-
this.logPrefix = logPrefix;
|
|
39
|
-
this.log = log;
|
|
40
|
-
this.unidirectional = unidirectional;
|
|
41
|
-
this.validateTimestamp(this.lastInteraction);
|
|
42
|
-
this.logData(`GASP initialized with version: ${this.version}, lastInteraction: ${this.lastInteraction}, unidirectional: ${this.unidirectional}`);
|
|
43
|
-
}
|
|
44
|
-
logData(...data) {
|
|
45
|
-
if (this.log) {
|
|
46
|
-
console.log(this.logPrefix, ...data);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
validateTimestamp(timestamp) {
|
|
50
|
-
if (typeof timestamp !== 'number' || isNaN(timestamp) || timestamp < 0 || !Number.isInteger(timestamp)) {
|
|
51
|
-
throw new Error('Invalid timestamp format');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Computes a 36-byte structure from a transaction ID and output index.
|
|
56
|
-
* @param txid The transaction ID.
|
|
57
|
-
* @param index The output index.
|
|
58
|
-
* @returns A string representing the 36-byte structure.
|
|
59
|
-
*/
|
|
60
|
-
compute36ByteStructure(txid, index) {
|
|
61
|
-
const result = `${txid}.${index.toString()}`;
|
|
62
|
-
this.logData(`Computed 36-byte structure: ${result} from txid: ${txid}, index: ${index}`);
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Deconstructs a 36-byte structure into a transaction ID and output index.
|
|
67
|
-
* @param outpoint The 36-byte structure.
|
|
68
|
-
* @returns An object containing the transaction ID and output index.
|
|
69
|
-
*/
|
|
70
|
-
deconstruct36ByteStructure(outpoint) {
|
|
71
|
-
const [txid, index] = outpoint.split('.');
|
|
72
|
-
const result = {
|
|
73
|
-
txid,
|
|
74
|
-
outputIndex: parseInt(index, 10)
|
|
75
|
-
};
|
|
76
|
-
this.logData(`Deconstructed 36-byte structure: ${outpoint} into txid: ${txid}, outputIndex: ${result.outputIndex}`);
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Computes the transaction ID for a given transaction.
|
|
81
|
-
* @param tx The transaction string.
|
|
82
|
-
* @returns The computed transaction ID.
|
|
83
|
-
*/
|
|
84
|
-
computeTXID(tx) {
|
|
85
|
-
const txid = Transaction.fromHex(tx).id('hex');
|
|
86
|
-
this.logData(`Computed TXID: ${txid} from transaction: ${tx}`);
|
|
87
|
-
return txid;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Synchronizes the transaction data between the local and remote participants.
|
|
91
|
-
*/
|
|
92
|
-
async sync() {
|
|
93
|
-
this.logData(`Starting sync process. Last interaction timestamp: ${this.lastInteraction}`);
|
|
94
|
-
const initialRequest = await this.buildInitialRequest(this.lastInteraction);
|
|
95
|
-
const initialResponse = await this.remote.getInitialResponse(initialRequest);
|
|
96
|
-
// 1. Pull the remote UTXOs that we don't already have
|
|
97
|
-
if (initialResponse.UTXOList.length > 0) {
|
|
98
|
-
const foreignUTXOs = await this.storage.findKnownUTXOs(0);
|
|
99
|
-
// -- REPLACE Promise.all WITH A FOR LOOP --
|
|
100
|
-
const missingUTXOs = initialResponse.UTXOList.filter(x => !foreignUTXOs.some(y => x.txid === y.txid && x.outputIndex === y.outputIndex));
|
|
101
|
-
for (const UTXO of missingUTXOs) {
|
|
102
|
-
try {
|
|
103
|
-
this.logData(`Requesting node for UTXO: ${JSON.stringify(UTXO)}`);
|
|
104
|
-
const resolvedNode = await this.remote.requestNode(this.compute36ByteStructure(UTXO.txid, UTXO.outputIndex), UTXO.txid, UTXO.outputIndex, true);
|
|
105
|
-
this.logData(`Received unspent graph node from remote: ${JSON.stringify(resolvedNode)}`);
|
|
106
|
-
await this.processIncomingNode(resolvedNode);
|
|
107
|
-
await this.completeGraph(resolvedNode.graphID);
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
this.logData(`Error with incoming UTXO ${UTXO.txid}.${UTXO.outputIndex}: ${e.message}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// 2. Only do the “reply” half if unidirectional is disabled
|
|
115
|
-
if (!this.unidirectional) {
|
|
116
|
-
const initialReply = await this.getInitialReply(initialResponse);
|
|
117
|
-
this.logData(`Received initial reply: ${JSON.stringify(initialReply)}`);
|
|
118
|
-
if (initialReply.UTXOList.length > 0) {
|
|
119
|
-
// -- REPLACE Promise.all WITH A FOR LOOP --
|
|
120
|
-
for (const UTXO of initialReply.UTXOList) {
|
|
121
|
-
try {
|
|
122
|
-
this.logData(`Hydrating GASP node for UTXO: ${JSON.stringify(UTXO)}`);
|
|
123
|
-
const outgoingNode = await this.storage.hydrateGASPNode(this.compute36ByteStructure(UTXO.txid, UTXO.outputIndex), UTXO.txid, UTXO.outputIndex, true);
|
|
124
|
-
this.logData(`Sending unspent graph node for remote: ${JSON.stringify(outgoingNode)}`);
|
|
125
|
-
await this.processOutgoingNode(outgoingNode);
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
this.logData(`Error with outgoing UTXO ${UTXO.txid}.${UTXO.outputIndex}: ${e.message}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
this.logData('Sync completed!');
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Builds the initial request for the sync process.
|
|
137
|
-
* @returns A promise for the initial request object.
|
|
138
|
-
*/
|
|
139
|
-
async buildInitialRequest(since) {
|
|
140
|
-
const request = {
|
|
141
|
-
version: this.version,
|
|
142
|
-
since
|
|
143
|
-
};
|
|
144
|
-
this.logData(`Built initial request: ${JSON.stringify(request)}`);
|
|
145
|
-
return request;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Builds the initial response based on the received request.
|
|
149
|
-
* @param request The initial request object.
|
|
150
|
-
* @returns A promise for an initial response
|
|
151
|
-
*/
|
|
152
|
-
async getInitialResponse(request) {
|
|
153
|
-
this.logData(`Received initial request: ${JSON.stringify(request)}`);
|
|
154
|
-
if (request.version !== this.version) {
|
|
155
|
-
const error = new GASPVersionMismatchError(`GASP version mismatch. Current version: ${this.version}, foreign version: ${request.version}`, this.version, request.version);
|
|
156
|
-
console.error(`GASP version mismatch error: ${error.message}`);
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
this.validateTimestamp(request.since);
|
|
160
|
-
const response = {
|
|
161
|
-
since: this.lastInteraction,
|
|
162
|
-
UTXOList: await this.storage.findKnownUTXOs(request.since)
|
|
163
|
-
};
|
|
164
|
-
this.logData(`Built initial response: ${JSON.stringify(response)}`);
|
|
165
|
-
return response;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Builds the initial reply based on the received response.
|
|
169
|
-
* @param response The initial response object.
|
|
170
|
-
* @returns A promise for an initial reply
|
|
171
|
-
*/
|
|
172
|
-
async getInitialReply(response) {
|
|
173
|
-
this.logData(`Received initial response: ${JSON.stringify(response)}`);
|
|
174
|
-
const knownUTXOs = await this.storage.findKnownUTXOs(response.since);
|
|
175
|
-
const filteredUTXOs = knownUTXOs.filter(x => !response.UTXOList.some(y => y.txid === x.txid && y.outputIndex === x.outputIndex));
|
|
176
|
-
const reply = {
|
|
177
|
-
UTXOList: filteredUTXOs
|
|
178
|
-
};
|
|
179
|
-
this.logData(`Built initial reply: ${JSON.stringify(reply)}`);
|
|
180
|
-
return reply;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Provides a requested node to a foreign instance who requested it.
|
|
184
|
-
*/
|
|
185
|
-
async requestNode(graphID, txid, outputIndex, metadata) {
|
|
186
|
-
this.logData(`Remote is requesting node with graphID: ${graphID}, txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
|
|
187
|
-
const node = await this.storage.hydrateGASPNode(graphID, txid, outputIndex, metadata);
|
|
188
|
-
this.logData(`Returning node: ${JSON.stringify(node)}`);
|
|
189
|
-
return node;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Provides a set of inputs we care about after processing a new incoming node.
|
|
193
|
-
* Also finalizes or discards a graph if no additional data is requested from the foreign instance.
|
|
194
|
-
*/
|
|
195
|
-
async submitNode(node) {
|
|
196
|
-
this.logData(`Remote party is submitting node: ${JSON.stringify(node)}`);
|
|
197
|
-
await this.storage.appendToGraph(node);
|
|
198
|
-
const requestedInputs = await this.storage.findNeededInputs(node);
|
|
199
|
-
this.logData(`Requested inputs: ${JSON.stringify(requestedInputs)}`);
|
|
200
|
-
if (!requestedInputs) {
|
|
201
|
-
await this.completeGraph(node.graphID);
|
|
202
|
-
}
|
|
203
|
-
return requestedInputs;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Handles the completion of a newly-synced graph
|
|
207
|
-
* @param {string} graphID The ID of the newly-synced graph
|
|
208
|
-
*/
|
|
209
|
-
async completeGraph(graphID) {
|
|
210
|
-
this.logData(`Completing newly-synced graph: ${graphID}`);
|
|
211
|
-
try {
|
|
212
|
-
await this.storage.validateGraphAnchor(graphID);
|
|
213
|
-
this.logData(`Graph validated for node: ${graphID}`);
|
|
214
|
-
await this.storage.finalizeGraph(graphID);
|
|
215
|
-
this.logData(`Graph finalized for node: ${graphID}`);
|
|
216
|
-
}
|
|
217
|
-
catch (e) {
|
|
218
|
-
this.logData(`Error validating graph: ${e.message}. Discarding graph for node: ${graphID}`);
|
|
219
|
-
await this.storage.discardGraph(graphID);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Processes an incoming node from the remote participant.
|
|
224
|
-
* @param node The incoming GASP node.
|
|
225
|
-
* @param spentBy The 36-byte structure of the node that spent this one, if applicable.
|
|
226
|
-
*/
|
|
227
|
-
async processIncomingNode(node, spentBy, seenNodes = new Set()) {
|
|
228
|
-
const nodeId = `${this.computeTXID(node.rawTx)}.${node.outputIndex}`;
|
|
229
|
-
this.logData(`Processing incoming node: ${JSON.stringify(node)}, spentBy: ${spentBy}`);
|
|
230
|
-
if (seenNodes.has(nodeId)) {
|
|
231
|
-
this.logData(`Node ${nodeId} already processed, skipping.`);
|
|
232
|
-
return; // Prevent infinite recursion
|
|
233
|
-
}
|
|
234
|
-
seenNodes.add(nodeId);
|
|
235
|
-
await this.storage.appendToGraph(node, spentBy);
|
|
236
|
-
const neededInputs = await this.storage.findNeededInputs(node);
|
|
237
|
-
this.logData(`Needed inputs for node ${nodeId}: ${JSON.stringify(neededInputs)}`);
|
|
238
|
-
if (neededInputs) {
|
|
239
|
-
// -- REPLACE Promise.all WITH A FOR LOOP --
|
|
240
|
-
for (const [outpoint, { metadata }] of Object.entries(neededInputs.requestedInputs)) {
|
|
241
|
-
const { txid, outputIndex } = this.deconstruct36ByteStructure(outpoint);
|
|
242
|
-
this.logData(`Requesting new node for txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
|
|
243
|
-
const newNode = await this.remote.requestNode(node.graphID, txid, outputIndex, metadata);
|
|
244
|
-
this.logData(`Received new node: ${JSON.stringify(newNode)}`);
|
|
245
|
-
await this.processIncomingNode(newNode, this.compute36ByteStructure(this.computeTXID(node.rawTx), node.outputIndex), seenNodes);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Processes an outgoing node to the remote participant.
|
|
251
|
-
* @param node The outgoing GASP node.
|
|
252
|
-
*/
|
|
253
|
-
async processOutgoingNode(node, seenNodes = new Set()) {
|
|
254
|
-
if (this.unidirectional) {
|
|
255
|
-
this.logData(`Skipping outgoing node processing in unidirectional mode.`);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const nodeId = `${this.computeTXID(node.rawTx)}.${node.outputIndex}`;
|
|
259
|
-
this.logData(`Processing outgoing node: ${JSON.stringify(node)}`);
|
|
260
|
-
if (seenNodes.has(nodeId)) {
|
|
261
|
-
this.logData(`Node ${nodeId} already processed, skipping.`);
|
|
262
|
-
return; // Prevent infinite recursion
|
|
263
|
-
}
|
|
264
|
-
seenNodes.add(nodeId);
|
|
265
|
-
// Attempt to submit the node to the remote
|
|
266
|
-
const response = await this.remote.submitNode(node);
|
|
267
|
-
this.logData(`Received response for submitted node: ${JSON.stringify(response)}`);
|
|
268
|
-
if (response) {
|
|
269
|
-
// Process each requested input sequentially
|
|
270
|
-
for (const [outpoint, { metadata }] of Object.entries(response.requestedInputs)) {
|
|
271
|
-
const { txid, outputIndex } = this.deconstruct36ByteStructure(outpoint);
|
|
272
|
-
try {
|
|
273
|
-
this.logData(`Hydrating node for txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
|
|
274
|
-
const hydratedNode = await this.storage.hydrateGASPNode(node.graphID, txid, outputIndex, metadata);
|
|
275
|
-
this.logData(`Hydrated node: ${JSON.stringify(hydratedNode)}`);
|
|
276
|
-
await this.processOutgoingNode(hydratedNode, seenNodes);
|
|
277
|
-
}
|
|
278
|
-
catch (e) {
|
|
279
|
-
this.logData(`Error hydrating node: ${e.message}`);
|
|
280
|
-
// If we can't send the outgoing node, we just stop.
|
|
281
|
-
// The remote won't validate the anchor, and their temporary graph will be discarded.
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
//# sourceMappingURL=GASP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GASP.js","sourceRoot":"","sources":["../../../../src/GASP/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;IACZ,cAAc,CAAS;IAEvB;;;;;;;;OAQG;IACH,YACE,OAAoB,EACpB,MAAkB,EAClB,eAAe,GAAG,CAAC,EACnB,SAAS,GAAG,SAAS,EACrB,GAAG,GAAG,KAAK,EACX,cAAc,GAAG,KAAK;QAEtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,GAAG,GAAG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,IAAI,CAAC,CAAA;QACnD,IAAI,CAAC,OAAO,CAAC,yCAAyC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACjF,IAAI,QAAQ,EAAE,CAAC;YACb,4CAA4C;YAC5C,KAAK,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;gBAChF,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC;gBAExE,IAAI,CAAC;oBACH,IAAI,CAAC,OAAO,CAAC,4BAA4B,IAAI,kBAAkB,WAAW,eAAe,QAAQ,EAAE,CAAC,CAAC;oBACrG,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;oBACnG,IAAI,CAAC,OAAO,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;oBAE/D,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;gBAC1D,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,IAAI,CAAC,OAAO,CAAC,yBAA0B,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;oBAC9D,oDAAoD;oBACpD,qFAAqF;oBACrF,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the initial request made under the Graph Aware Sync Protocol.
|
|
3
|
-
*/
|
|
4
|
-
export type GASPInitialRequest = {
|
|
5
|
-
/** GASP version. Currently 1. */
|
|
6
|
-
version: number;
|
|
7
|
-
/** An optional timestamp (UNIX-1970-seconds) of the last time these two parties synced */
|
|
8
|
-
since: number;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Represents the initial response made under the Graph Aware Sync Protocol.
|
|
12
|
-
*/
|
|
13
|
-
export type GASPInitialResponse = {
|
|
14
|
-
/** A list of outputs witnessed by the recipient since the initial request's timestamp. If not provided, a complete list of outputs since the beginning of time is returned. Unconfirmed (non-timestamped) UTXOs are always returned. */
|
|
15
|
-
UTXOList: Array<{
|
|
16
|
-
txid: string;
|
|
17
|
-
outputIndex: number;
|
|
18
|
-
}>;
|
|
19
|
-
/** A timestamp from when the responder wants to receive UTXOs in the other direction, back from the requester. */
|
|
20
|
-
since: number;
|
|
21
|
-
};
|
|
22
|
-
/** Represents the subsequent message sent in reply to the initial response. */
|
|
23
|
-
export type GASPInitialReply = {
|
|
24
|
-
/** A list of outputs (excluding outputs received from the Initial Response), and ONLY after the timestamp from the initial response. We don't need to send back things from the initial response, since those were already seen by the counterparty. */
|
|
25
|
-
UTXOList: Array<{
|
|
26
|
-
txid: string;
|
|
27
|
-
outputIndex: number;
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Represents an output, its encompassing transaction, and the associated metadata, together with references to inputs and their metadata.
|
|
32
|
-
*/
|
|
33
|
-
export type GASPNode = {
|
|
34
|
-
/** The graph ID to which this node belongs. */
|
|
35
|
-
graphID: string;
|
|
36
|
-
/** The Bitcoin transaction in rawTX format. */
|
|
37
|
-
rawTx: string;
|
|
38
|
-
/** The index of the output in the transaction. */
|
|
39
|
-
outputIndex: number;
|
|
40
|
-
/** A BUMP proof for the transaction, if it is in a block. */
|
|
41
|
-
proof?: string;
|
|
42
|
-
/** Metadata associated with the transaction, if it was requested. */
|
|
43
|
-
txMetadata?: string;
|
|
44
|
-
/** Metadata associated with the output, if it was requested. */
|
|
45
|
-
outputMetadata?: string;
|
|
46
|
-
/** A mapping of transaction inputs to metadata hashes, if metadata was requested. */
|
|
47
|
-
inputs?: Record<string, {
|
|
48
|
-
hash: string;
|
|
49
|
-
}>;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Denotes which input transactions are requested, and whether metadata needs to be sent.
|
|
53
|
-
*/
|
|
54
|
-
export type GASPNodeResponse = {
|
|
55
|
-
requestedInputs: Record<string, {
|
|
56
|
-
metadata: boolean;
|
|
57
|
-
}>;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Facilitates the finding of UTXOs, determination of needed inputs, temporary graph management, and eventual graph finalization.
|
|
61
|
-
*/
|
|
62
|
-
export interface GASPStorage {
|
|
63
|
-
/**
|
|
64
|
-
* Returns an array of transaction outpoints that are currently known to be unspent (given an optional timestamp).
|
|
65
|
-
* Non-confirmed (non-timestamped) outputs should always be returned, regardless of the timestamp.
|
|
66
|
-
* @returns A promise for an array of objects, each containing txid and outputIndex properties.
|
|
67
|
-
*/
|
|
68
|
-
findKnownUTXOs: (since: number) => Promise<Array<{
|
|
69
|
-
txid: string;
|
|
70
|
-
outputIndex: number;
|
|
71
|
-
}>>;
|
|
72
|
-
/**
|
|
73
|
-
* For a given txid and output index, returns the associated transaction, a merkle proof if the transaction is in a block, and metadata if if requested. If no metadata is requested, metadata hashes on inputs are not returned.
|
|
74
|
-
* @param txid The transaction ID for the node to hydrate.
|
|
75
|
-
* @param outputIndex The output index for the node to hydrate.
|
|
76
|
-
* @param metadata Whether transaction and output metadata should be returned.
|
|
77
|
-
* @returns The hydrated GASP node, with or without metadata.
|
|
78
|
-
*/
|
|
79
|
-
hydrateGASPNode: (graphID: string, txid: string, outputIndex: number, metadata: boolean) => Promise<GASPNode>;
|
|
80
|
-
/**
|
|
81
|
-
* For a given node, returns the inputs needed to complete the graph, including whether updated metadata is requested for those inputs.
|
|
82
|
-
* @param tx The node for which needed inputs should be found.
|
|
83
|
-
* @returns A promise for a mapping of requested input transactions and whether metadata should be provided for each.
|
|
84
|
-
*/
|
|
85
|
-
findNeededInputs: (tx: GASPNode) => Promise<GASPNodeResponse | void>;
|
|
86
|
-
/**
|
|
87
|
-
* Appends a new node to a temporary graph.
|
|
88
|
-
* @param tx The node to append to this graph.
|
|
89
|
-
* @param spentBy Unless this is the same node identified by the graph ID, denotes the TXID and input index for the node which spent this one, in 36-byte format.
|
|
90
|
-
* @throws If the node cannot be appended to the graph, either because the graph ID is for a graph the recipient does not want or because the graph has grown to be too large before being finalized.
|
|
91
|
-
*/
|
|
92
|
-
appendToGraph: (tx: GASPNode, spentBy?: string) => Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Checks whether the given graph, in its current state, makes reference only to transactions that are proven in the blockchain, or already known by the recipient to be valid.
|
|
95
|
-
* @param graphID The TXID and output index (in 36-byte format) for the UTXO at the tip of this graph.
|
|
96
|
-
* @throws If the graph is not well-anchored.
|
|
97
|
-
*/
|
|
98
|
-
validateGraphAnchor: (graphID: string) => Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Deletes all data associated with a temporary graph that has failed to sync, if the graph exists.
|
|
101
|
-
* @param graphID The TXID and output index (in 36-byte format) for the UTXO at the tip of this graph.
|
|
102
|
-
*/
|
|
103
|
-
discardGraph: (graphID: string) => Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Finalizes a graph, solidifying the new UTXO and its ancestors so that it will appear in the list of known UTXOs.
|
|
106
|
-
* @param graphID The TXID and output index (in 36-byte format) for the UTXO at the tip of this graph.
|
|
107
|
-
*/
|
|
108
|
-
finalizeGraph: (graphID: string) => Promise<void>;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The communications mechanism between a local GASP instance and a foreign GASP instance.
|
|
112
|
-
*/
|
|
113
|
-
export interface GASPRemote {
|
|
114
|
-
/** Given an outgoing initial request, send the request to the foreign instance and obtain their initial response. */
|
|
115
|
-
getInitialResponse: (request: GASPInitialRequest) => Promise<GASPInitialResponse>;
|
|
116
|
-
/** Given an outgoing initial response, obtain the reply from the foreign instance. */
|
|
117
|
-
getInitialReply: (response: GASPInitialResponse) => Promise<GASPInitialReply>;
|
|
118
|
-
/** Given an outgoing txid, outputIndex and optional metadata, request the associated GASP node from the foreign instane. */
|
|
119
|
-
requestNode: (graphID: string, txid: string, outputIndex: number, metadata: boolean) => Promise<GASPNode>;
|
|
120
|
-
/** Given an outgoing node, send the node to the foreign instance and determine which additional inputs (if any) they request in response. */
|
|
121
|
-
submitNode: (node: GASPNode) => Promise<GASPNodeResponse | void>;
|
|
122
|
-
}
|
|
123
|
-
export declare class GASPVersionMismatchError extends Error {
|
|
124
|
-
code: 'ERR_GASP_VERSION_MISMATCH';
|
|
125
|
-
currentVersion: number;
|
|
126
|
-
foreignVersion: number;
|
|
127
|
-
constructor(message: string, currentVersion: number, foreignVersion: number);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Main class implementing the Graph Aware Sync Protocol.
|
|
131
|
-
*/
|
|
132
|
-
export declare class GASP implements GASPRemote {
|
|
133
|
-
version: number;
|
|
134
|
-
storage: GASPStorage;
|
|
135
|
-
remote: GASPRemote;
|
|
136
|
-
lastInteraction: number;
|
|
137
|
-
logPrefix: string;
|
|
138
|
-
log: boolean;
|
|
139
|
-
unidirectional: boolean;
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
* @param storage The GASP Storage interface to use
|
|
143
|
-
* @param remote The GASP Remote interface to use
|
|
144
|
-
* @param lastInteraction The timestamp when we last interacted with this remote party
|
|
145
|
-
* @param logPrefix Optional prefix for log messages
|
|
146
|
-
* @param log Whether to log messages
|
|
147
|
-
* @param unidirectional Whether to disable the "reply" side and do pull-only
|
|
148
|
-
*/
|
|
149
|
-
constructor(storage: GASPStorage, remote: GASPRemote, lastInteraction?: number, logPrefix?: string, log?: boolean, unidirectional?: boolean);
|
|
150
|
-
private logData;
|
|
151
|
-
private validateTimestamp;
|
|
152
|
-
/**
|
|
153
|
-
* Computes a 36-byte structure from a transaction ID and output index.
|
|
154
|
-
* @param txid The transaction ID.
|
|
155
|
-
* @param index The output index.
|
|
156
|
-
* @returns A string representing the 36-byte structure.
|
|
157
|
-
*/
|
|
158
|
-
private compute36ByteStructure;
|
|
159
|
-
/**
|
|
160
|
-
* Deconstructs a 36-byte structure into a transaction ID and output index.
|
|
161
|
-
* @param outpoint The 36-byte structure.
|
|
162
|
-
* @returns An object containing the transaction ID and output index.
|
|
163
|
-
*/
|
|
164
|
-
private deconstruct36ByteStructure;
|
|
165
|
-
/**
|
|
166
|
-
* Computes the transaction ID for a given transaction.
|
|
167
|
-
* @param tx The transaction string.
|
|
168
|
-
* @returns The computed transaction ID.
|
|
169
|
-
*/
|
|
170
|
-
private computeTXID;
|
|
171
|
-
/**
|
|
172
|
-
* Synchronizes the transaction data between the local and remote participants.
|
|
173
|
-
*/
|
|
174
|
-
sync(): Promise<void>;
|
|
175
|
-
/**
|
|
176
|
-
* Builds the initial request for the sync process.
|
|
177
|
-
* @returns A promise for the initial request object.
|
|
178
|
-
*/
|
|
179
|
-
buildInitialRequest(since: number): Promise<GASPInitialRequest>;
|
|
180
|
-
/**
|
|
181
|
-
* Builds the initial response based on the received request.
|
|
182
|
-
* @param request The initial request object.
|
|
183
|
-
* @returns A promise for an initial response
|
|
184
|
-
*/
|
|
185
|
-
getInitialResponse(request: GASPInitialRequest): Promise<GASPInitialResponse>;
|
|
186
|
-
/**
|
|
187
|
-
* Builds the initial reply based on the received response.
|
|
188
|
-
* @param response The initial response object.
|
|
189
|
-
* @returns A promise for an initial reply
|
|
190
|
-
*/
|
|
191
|
-
getInitialReply(response: GASPInitialResponse): Promise<GASPInitialReply>;
|
|
192
|
-
/**
|
|
193
|
-
* Provides a requested node to a foreign instance who requested it.
|
|
194
|
-
*/
|
|
195
|
-
requestNode(graphID: string, txid: string, outputIndex: number, metadata: boolean): Promise<GASPNode>;
|
|
196
|
-
/**
|
|
197
|
-
* Provides a set of inputs we care about after processing a new incoming node.
|
|
198
|
-
* Also finalizes or discards a graph if no additional data is requested from the foreign instance.
|
|
199
|
-
*/
|
|
200
|
-
submitNode(node: GASPNode): Promise<GASPNodeResponse | void>;
|
|
201
|
-
/**
|
|
202
|
-
* Handles the completion of a newly-synced graph
|
|
203
|
-
* @param {string} graphID The ID of the newly-synced graph
|
|
204
|
-
*/
|
|
205
|
-
completeGraph(graphID: string): Promise<void>;
|
|
206
|
-
/**
|
|
207
|
-
* Processes an incoming node from the remote participant.
|
|
208
|
-
* @param node The incoming GASP node.
|
|
209
|
-
* @param spentBy The 36-byte structure of the node that spent this one, if applicable.
|
|
210
|
-
*/
|
|
211
|
-
private processIncomingNode;
|
|
212
|
-
/**
|
|
213
|
-
* Processes an outgoing node to the remote participant.
|
|
214
|
-
* @param node The outgoing GASP node.
|
|
215
|
-
*/
|
|
216
|
-
private processOutgoingNode;
|
|
217
|
-
}
|
|
218
|
-
//# sourceMappingURL=GASP.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GASP.d.ts","sourceRoot":"","sources":["../../../../src/GASP/GASP.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,0FAA0F;IAC1F,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,wOAAwO;IACxO,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvD,kHAAkH;IAClH,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,wPAAwP;IACxP,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxD,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,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