@bsv/overlay 0.1.0-alpha.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/LICENSE.txt +28 -0
- package/README.md +220 -0
- package/dist/cjs/mod.js +43 -0
- package/dist/cjs/mod.js.map +1 -0
- package/dist/cjs/package.json +53 -0
- package/dist/cjs/src/AdmittanceInstructions.js +3 -0
- package/dist/cjs/src/AdmittanceInstructions.js.map +1 -0
- package/dist/cjs/src/Engine.js +361 -0
- package/dist/cjs/src/Engine.js.map +1 -0
- package/dist/cjs/src/LookupAnswer.js +3 -0
- package/dist/cjs/src/LookupAnswer.js.map +1 -0
- package/dist/cjs/src/LookupFormula.js +3 -0
- package/dist/cjs/src/LookupFormula.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/LookupService.js +3 -0
- package/dist/cjs/src/LookupService.js.map +1 -0
- package/dist/cjs/src/Output.js +3 -0
- package/dist/cjs/src/Output.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/src/TopicManager.js +3 -0
- package/dist/cjs/src/TopicManager.js.map +1 -0
- package/dist/cjs/src/storage/Storage.js +3 -0
- package/dist/cjs/src/storage/Storage.js.map +1 -0
- package/dist/cjs/src/storage/knex/KnexStorage.js +76 -0
- package/dist/cjs/src/storage/knex/KnexStorage.js.map +1 -0
- package/dist/cjs/src/storage/knex/all-migrations.js +11 -0
- package/dist/cjs/src/storage/knex/all-migrations.js.map +1 -0
- package/dist/cjs/src/storage/knex/migrations/2024-05-18-001-initial.js +33 -0
- package/dist/cjs/src/storage/knex/migrations/2024-05-18-001-initial.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/mod.js +17 -0
- package/dist/esm/mod.js.map +1 -0
- package/dist/esm/src/AdmittanceInstructions.js +2 -0
- package/dist/esm/src/AdmittanceInstructions.js.map +1 -0
- package/dist/esm/src/Engine.js +357 -0
- package/dist/esm/src/Engine.js.map +1 -0
- package/dist/esm/src/LookupAnswer.js +2 -0
- package/dist/esm/src/LookupAnswer.js.map +1 -0
- package/dist/esm/src/LookupFormula.js +2 -0
- package/dist/esm/src/LookupFormula.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/LookupService.js +2 -0
- package/dist/esm/src/LookupService.js.map +1 -0
- package/dist/esm/src/Output.js +2 -0
- package/dist/esm/src/Output.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/src/TopicManager.js +2 -0
- package/dist/esm/src/TopicManager.js.map +1 -0
- package/dist/esm/src/storage/Storage.js +2 -0
- package/dist/esm/src/storage/Storage.js.map +1 -0
- package/dist/esm/src/storage/knex/KnexStorage.js +74 -0
- package/dist/esm/src/storage/knex/KnexStorage.js.map +1 -0
- package/dist/esm/src/storage/knex/all-migrations.js +9 -0
- package/dist/esm/src/storage/knex/all-migrations.js.map +1 -0
- package/dist/esm/src/storage/knex/migrations/2024-05-18-001-initial.js +28 -0
- package/dist/esm/src/storage/knex/migrations/2024-05-18-001-initial.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +14 -0
- package/dist/types/mod.d.ts.map +1 -0
- 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 +92 -0
- package/dist/types/src/Engine.d.ts.map +1 -0
- package/dist/types/src/LookupAnswer.d.ts +15 -0
- package/dist/types/src/LookupAnswer.d.ts.map +1 -0
- package/dist/types/src/LookupFormula.d.ts +25 -0
- package/dist/types/src/LookupFormula.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/LookupService.d.ts +52 -0
- package/dist/types/src/LookupService.d.ts.map +1 -0
- package/dist/types/src/Output.d.ts +30 -0
- package/dist/types/src/Output.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/src/TopicManager.d.ts +27 -0
- package/dist/types/src/TopicManager.d.ts.map +1 -0
- package/dist/types/src/storage/Storage.d.ts +66 -0
- package/dist/types/src/storage/Storage.d.ts.map +1 -0
- package/dist/types/src/storage/knex/KnexStorage.d.ts +24 -0
- package/dist/types/src/storage/knex/KnexStorage.d.ts.map +1 -0
- package/dist/types/src/storage/knex/all-migrations.d.ts +10 -0
- package/dist/types/src/storage/knex/all-migrations.d.ts.map +1 -0
- package/dist/types/src/storage/knex/migrations/2024-05-18-001-initial.d.ts +4 -0
- package/dist/types/src/storage/knex/migrations/2024-05-18-001-initial.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/docs/API.md +621 -0
- package/docs/README.md +8 -0
- package/docs/concepts/README.md +4 -0
- package/docs/examples/README.md +5 -0
- package/docs/examples/gs-wip.md +105 -0
- package/docs/internal/README.md +4 -0
- package/mod.ts +18 -0
- package/package.json +78 -0
- package/src/AdmittanceInstructions.ts +14 -0
- package/src/Engine.ts +419 -0
- package/src/LookupAnswer.ts +14 -0
- package/src/LookupFormula.ts +26 -0
- package/src/LookupQuestion.ts +15 -0
- package/src/LookupService.ts +52 -0
- package/src/Output.ts +29 -0
- package/src/STEAK.ts +10 -0
- package/src/TaggedBEEF.ts +10 -0
- package/src/TopicManager.ts +23 -0
- package/src/__tests/Engine.test.ts +792 -0
- package/src/storage/Storage.ts +72 -0
- package/src/storage/knex/KnexStorage.ts +90 -0
- package/src/storage/knex/all-migrations.ts +14 -0
- package/src/storage/knex/migrations/2024-05-18-001-initial.ts +30 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The question asked to the Overlay Services Engine when a consumer of state wishes to look up information.
|
|
3
|
+
*/
|
|
4
|
+
export type LookupQuestion = {
|
|
5
|
+
/**
|
|
6
|
+
* The identifier for a Lookup Service which the person asking the question wishes to use.
|
|
7
|
+
*/
|
|
8
|
+
service: string
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The query which will be forwarded to the Lookup Service.
|
|
12
|
+
* Its type depends on that prescribed by the Lookup Service employed.
|
|
13
|
+
*/
|
|
14
|
+
query: unknown
|
|
15
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LookupQuestion } from './LookupQuestion.js'
|
|
2
|
+
import { LookupFormula } from './LookupFormula.js'
|
|
3
|
+
import { LookupAnswer } from './LookupAnswer.js'
|
|
4
|
+
import { Script } from '@bsv/sdk'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines a Lookup Service interface to be implemented for specific use-cases
|
|
8
|
+
*/
|
|
9
|
+
export default interface LookupService {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Process the event when a new UTXO is let into a topic
|
|
13
|
+
* @param txid
|
|
14
|
+
* @param outputIndex
|
|
15
|
+
* @param outputScript
|
|
16
|
+
* @param topic
|
|
17
|
+
*/
|
|
18
|
+
outputAdded?(txid: string, outputIndex: number, outputScript: Script, topic: string): Promise<void>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Process the spend event for a UTXO
|
|
22
|
+
* @param txid
|
|
23
|
+
* @param outputIndex
|
|
24
|
+
* @param topic
|
|
25
|
+
*/
|
|
26
|
+
outputSpent?(txid: string, outputIndex: number, topic: string): Promise<void>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Process the deletion event for a UTXO
|
|
30
|
+
* @param txid
|
|
31
|
+
* @param outputIndex
|
|
32
|
+
* @param topic
|
|
33
|
+
*/
|
|
34
|
+
outputDeleted?(txid: string, outputIndex: number, topic: string): Promise<void>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Queries the lookup service for information
|
|
38
|
+
* @param question — The question to be answered by the lookup service
|
|
39
|
+
* @returns — The Lookup Answer or Lookup Formula used to answer the question
|
|
40
|
+
*/
|
|
41
|
+
lookup(question: LookupQuestion): Promise<LookupAnswer | LookupFormula>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a Markdown-formatted documentation string for the lookup service.
|
|
45
|
+
*/
|
|
46
|
+
getDocumentation(): Promise<string>
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns a metadata object that can be used to identify the lookup service.
|
|
50
|
+
*/
|
|
51
|
+
getMetaData(): Promise<{ name: string, shortDescription: string, iconURL?: string, version?: string, informationURL?: string }>
|
|
52
|
+
}
|
package/src/Output.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an output to be tracked by the Overlay Services Engine
|
|
3
|
+
*/
|
|
4
|
+
export type Output = {
|
|
5
|
+
/** TXID of the output */
|
|
6
|
+
txid: string
|
|
7
|
+
/** index of the output */
|
|
8
|
+
outputIndex: number
|
|
9
|
+
/** script of the output */
|
|
10
|
+
outputScript: number[]
|
|
11
|
+
/** number of satoshis in the output */
|
|
12
|
+
satoshis: number
|
|
13
|
+
/** topic to which the output belongs */
|
|
14
|
+
topic: string
|
|
15
|
+
/** Whether the output is spent */
|
|
16
|
+
spent: boolean
|
|
17
|
+
/** The transaction data for the output */
|
|
18
|
+
beef: number[]
|
|
19
|
+
/** Outputs consumed by the transaction associated with the output */
|
|
20
|
+
outputsConsumed: {
|
|
21
|
+
txid: string
|
|
22
|
+
outputIndex: number
|
|
23
|
+
}[]
|
|
24
|
+
/** Outputs consuming this output */
|
|
25
|
+
consumedBy: {
|
|
26
|
+
txid: string
|
|
27
|
+
outputIndex: number
|
|
28
|
+
}[]
|
|
29
|
+
}
|
package/src/STEAK.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AdmittanceInstructions } from "./AdmittanceInstructions.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Submitted Transaction Execution AcKnowledgment
|
|
5
|
+
*
|
|
6
|
+
* @description
|
|
7
|
+
* Comprises the topics where a transaction was submitted, and for each one, the output indices for the UTXOs newly admitted into the topics, and the coins retained.
|
|
8
|
+
* An object whose keys are topic names and whose values are topical admittance instructions denoting the state of the submitted transaction with respect to the associated topic.
|
|
9
|
+
*/
|
|
10
|
+
export type STEAK = Record<string, AdmittanceInstructions>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tagged BEEF
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* Tagged BEEF ([Background Evaluation Extended Format](https://brc.dev/62)) structure. Comprises a transaction, its SPV information, and the overlay topics where its inclusion is requested.
|
|
6
|
+
*/
|
|
7
|
+
export type TaggedBEEF = {
|
|
8
|
+
beef: number[]
|
|
9
|
+
topics: string[]
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AdmittanceInstructions } from './AdmittanceInstructions.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines a Topic Manager interface that can be implemented for specific use-cases
|
|
5
|
+
*/
|
|
6
|
+
export default interface TopicManager {
|
|
7
|
+
/**
|
|
8
|
+
* Returns instructions that denote which outputs from the provided transaction to admit into the topic, and which previous coins should be retained.
|
|
9
|
+
* Accepts the transaction in BEEF format and an array of those input indicies which spend previously-admitted outputs from the same topic.
|
|
10
|
+
* The transaction's BEEF structure will always contain the transactions associated with previous coins for reference (if any), regardless of whether the current transaction was directly proven.
|
|
11
|
+
*/
|
|
12
|
+
identifyAdmissibleOutputs(beef: number[], previousCoins: number[]): Promise<AdmittanceInstructions>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns a Markdown-formatted documentation string for the topic manager.
|
|
16
|
+
*/
|
|
17
|
+
getDocumentation(): Promise<string>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns a metadata object that can be used to identify the topic manager.
|
|
21
|
+
*/
|
|
22
|
+
getMetaData(): Promise<{ name: string, shortDescription: string, iconURL?: string, version?: string, informationURL?: string }>
|
|
23
|
+
}
|