@bsv/overlay-discovery-services 1.4.2 → 1.5.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 (141) hide show
  1. package/package.json +5 -5
  2. package/src/SHIP/SHIPLookupService.ts +8 -0
  3. package/src/SHIP/SHIPStorage.ts +16 -0
  4. package/src/SLAP/SLAPLookupService.ts +8 -0
  5. package/src/SLAP/SLAPStorage.ts +16 -0
  6. package/dist/cjs/mod.js +0 -28
  7. package/dist/cjs/mod.js.map +0 -1
  8. package/dist/cjs/package.json +0 -55
  9. package/dist/cjs/src/LegacyNinjaAdvertiser.js +0 -235
  10. package/dist/cjs/src/LegacyNinjaAdvertiser.js.map +0 -1
  11. package/dist/cjs/src/SHIP/SHIPLookup.docs.js +0 -103
  12. package/dist/cjs/src/SHIP/SHIPLookup.docs.js.map +0 -1
  13. package/dist/cjs/src/SHIP/SHIPLookupService.js +0 -113
  14. package/dist/cjs/src/SHIP/SHIPLookupService.js.map +0 -1
  15. package/dist/cjs/src/SHIP/SHIPStorage.js +0 -114
  16. package/dist/cjs/src/SHIP/SHIPStorage.js.map +0 -1
  17. package/dist/cjs/src/SHIP/SHIPTopic.docs.js +0 -60
  18. package/dist/cjs/src/SHIP/SHIPTopic.docs.js.map +0 -1
  19. package/dist/cjs/src/SHIP/SHIPTopicManager.js +0 -95
  20. package/dist/cjs/src/SHIP/SHIPTopicManager.js.map +0 -1
  21. package/dist/cjs/src/SLAP/SLAPLookup.docs.js +0 -97
  22. package/dist/cjs/src/SLAP/SLAPLookup.docs.js.map +0 -1
  23. package/dist/cjs/src/SLAP/SLAPLookupService.js +0 -128
  24. package/dist/cjs/src/SLAP/SLAPLookupService.js.map +0 -1
  25. package/dist/cjs/src/SLAP/SLAPStorage.js +0 -114
  26. package/dist/cjs/src/SLAP/SLAPStorage.js.map +0 -1
  27. package/dist/cjs/src/SLAP/SLAPTopic.docs.js +0 -69
  28. package/dist/cjs/src/SLAP/SLAPTopic.docs.js.map +0 -1
  29. package/dist/cjs/src/SLAP/SLAPTopicManager.js +0 -96
  30. package/dist/cjs/src/SLAP/SLAPTopicManager.js.map +0 -1
  31. package/dist/cjs/src/WalletAdvertiser.js +0 -229
  32. package/dist/cjs/src/WalletAdvertiser.js.map +0 -1
  33. package/dist/cjs/src/types.js +0 -3
  34. package/dist/cjs/src/types.js.map +0 -1
  35. package/dist/cjs/src/utils/generateDocs.js +0 -81
  36. package/dist/cjs/src/utils/generateDocs.js.map +0 -1
  37. package/dist/cjs/src/utils/getDocumentation.js +0 -22
  38. package/dist/cjs/src/utils/getDocumentation.js.map +0 -1
  39. package/dist/cjs/src/utils/isAdvertisableURI.js +0 -123
  40. package/dist/cjs/src/utils/isAdvertisableURI.js.map +0 -1
  41. package/dist/cjs/src/utils/isTokenSignatureCorrectlyLinked.js +0 -45
  42. package/dist/cjs/src/utils/isTokenSignatureCorrectlyLinked.js.map +0 -1
  43. package/dist/cjs/src/utils/isValidDomain.js +0 -15
  44. package/dist/cjs/src/utils/isValidDomain.js.map +0 -1
  45. package/dist/cjs/src/utils/isValidServiceName.js +0 -14
  46. package/dist/cjs/src/utils/isValidServiceName.js.map +0 -1
  47. package/dist/cjs/src/utils/isValidTopicOrServiceName.js +0 -14
  48. package/dist/cjs/src/utils/isValidTopicOrServiceName.js.map +0 -1
  49. package/dist/cjs/src/utils/verifyToken.js +0 -22
  50. package/dist/cjs/src/utils/verifyToken.js.map +0 -1
  51. package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  52. package/dist/esm/mod.js +0 -12
  53. package/dist/esm/mod.js.map +0 -1
  54. package/dist/esm/src/LegacyNinjaAdvertiser.js +0 -233
  55. package/dist/esm/src/LegacyNinjaAdvertiser.js.map +0 -1
  56. package/dist/esm/src/SHIP/SHIPLookup.docs.js +0 -101
  57. package/dist/esm/src/SHIP/SHIPLookup.docs.js.map +0 -1
  58. package/dist/esm/src/SHIP/SHIPLookupService.js +0 -107
  59. package/dist/esm/src/SHIP/SHIPLookupService.js.map +0 -1
  60. package/dist/esm/src/SHIP/SHIPStorage.js +0 -111
  61. package/dist/esm/src/SHIP/SHIPStorage.js.map +0 -1
  62. package/dist/esm/src/SHIP/SHIPTopic.docs.js +0 -58
  63. package/dist/esm/src/SHIP/SHIPTopic.docs.js.map +0 -1
  64. package/dist/esm/src/SHIP/SHIPTopicManager.js +0 -88
  65. package/dist/esm/src/SHIP/SHIPTopicManager.js.map +0 -1
  66. package/dist/esm/src/SLAP/SLAPLookup.docs.js +0 -95
  67. package/dist/esm/src/SLAP/SLAPLookup.docs.js.map +0 -1
  68. package/dist/esm/src/SLAP/SLAPLookupService.js +0 -122
  69. package/dist/esm/src/SLAP/SLAPLookupService.js.map +0 -1
  70. package/dist/esm/src/SLAP/SLAPStorage.js +0 -111
  71. package/dist/esm/src/SLAP/SLAPStorage.js.map +0 -1
  72. package/dist/esm/src/SLAP/SLAPTopic.docs.js +0 -67
  73. package/dist/esm/src/SLAP/SLAPTopic.docs.js.map +0 -1
  74. package/dist/esm/src/SLAP/SLAPTopicManager.js +0 -89
  75. package/dist/esm/src/SLAP/SLAPTopicManager.js.map +0 -1
  76. package/dist/esm/src/WalletAdvertiser.js +0 -234
  77. package/dist/esm/src/WalletAdvertiser.js.map +0 -1
  78. package/dist/esm/src/types.js +0 -2
  79. package/dist/esm/src/types.js.map +0 -1
  80. package/dist/esm/src/utils/generateDocs.js +0 -46
  81. package/dist/esm/src/utils/generateDocs.js.map +0 -1
  82. package/dist/esm/src/utils/getDocumentation.js +0 -20
  83. package/dist/esm/src/utils/getDocumentation.js.map +0 -1
  84. package/dist/esm/src/utils/isAdvertisableURI.js +0 -119
  85. package/dist/esm/src/utils/isAdvertisableURI.js.map +0 -1
  86. package/dist/esm/src/utils/isTokenSignatureCorrectlyLinked.js +0 -41
  87. package/dist/esm/src/utils/isTokenSignatureCorrectlyLinked.js.map +0 -1
  88. package/dist/esm/src/utils/isValidDomain.js +0 -11
  89. package/dist/esm/src/utils/isValidDomain.js.map +0 -1
  90. package/dist/esm/src/utils/isValidServiceName.js +0 -10
  91. package/dist/esm/src/utils/isValidServiceName.js.map +0 -1
  92. package/dist/esm/src/utils/isValidTopicOrServiceName.js +0 -10
  93. package/dist/esm/src/utils/isValidTopicOrServiceName.js.map +0 -1
  94. package/dist/esm/src/utils/verifyToken.js +0 -18
  95. package/dist/esm/src/utils/verifyToken.js.map +0 -1
  96. package/dist/esm/tsconfig.esm.tsbuildinfo +0 -1
  97. package/dist/types/mod.d.ts +0 -12
  98. package/dist/types/mod.d.ts.map +0 -1
  99. package/dist/types/src/LegacyNinjaAdvertiser.d.ts +0 -60
  100. package/dist/types/src/LegacyNinjaAdvertiser.d.ts.map +0 -1
  101. package/dist/types/src/SHIP/SHIPLookup.docs.d.ts +0 -3
  102. package/dist/types/src/SHIP/SHIPLookup.docs.d.ts.map +0 -1
  103. package/dist/types/src/SHIP/SHIPLookupService.d.ts +0 -27
  104. package/dist/types/src/SHIP/SHIPLookupService.d.ts.map +0 -1
  105. package/dist/types/src/SHIP/SHIPStorage.d.ts +0 -48
  106. package/dist/types/src/SHIP/SHIPStorage.d.ts.map +0 -1
  107. package/dist/types/src/SHIP/SHIPTopic.docs.d.ts +0 -3
  108. package/dist/types/src/SHIP/SHIPTopic.docs.d.ts.map +0 -1
  109. package/dist/types/src/SHIP/SHIPTopicManager.d.ts +0 -34
  110. package/dist/types/src/SHIP/SHIPTopicManager.d.ts.map +0 -1
  111. package/dist/types/src/SLAP/SLAPLookup.docs.d.ts +0 -3
  112. package/dist/types/src/SLAP/SLAPLookup.docs.d.ts.map +0 -1
  113. package/dist/types/src/SLAP/SLAPLookupService.d.ts +0 -28
  114. package/dist/types/src/SLAP/SLAPLookupService.d.ts.map +0 -1
  115. package/dist/types/src/SLAP/SLAPStorage.d.ts +0 -48
  116. package/dist/types/src/SLAP/SLAPStorage.d.ts.map +0 -1
  117. package/dist/types/src/SLAP/SLAPTopic.docs.d.ts +0 -3
  118. package/dist/types/src/SLAP/SLAPTopic.docs.d.ts.map +0 -1
  119. package/dist/types/src/SLAP/SLAPTopicManager.d.ts +0 -34
  120. package/dist/types/src/SLAP/SLAPTopicManager.d.ts.map +0 -1
  121. package/dist/types/src/WalletAdvertiser.d.ts +0 -55
  122. package/dist/types/src/WalletAdvertiser.d.ts.map +0 -1
  123. package/dist/types/src/types.d.ts +0 -39
  124. package/dist/types/src/types.d.ts.map +0 -1
  125. package/dist/types/src/utils/generateDocs.d.ts +0 -2
  126. package/dist/types/src/utils/generateDocs.d.ts.map +0 -1
  127. package/dist/types/src/utils/getDocumentation.d.ts +0 -8
  128. package/dist/types/src/utils/getDocumentation.d.ts.map +0 -1
  129. package/dist/types/src/utils/isAdvertisableURI.d.ts +0 -19
  130. package/dist/types/src/utils/isAdvertisableURI.d.ts.map +0 -1
  131. package/dist/types/src/utils/isTokenSignatureCorrectlyLinked.d.ts +0 -9
  132. package/dist/types/src/utils/isTokenSignatureCorrectlyLinked.d.ts.map +0 -1
  133. package/dist/types/src/utils/isValidDomain.d.ts +0 -7
  134. package/dist/types/src/utils/isValidDomain.d.ts.map +0 -1
  135. package/dist/types/src/utils/isValidServiceName.d.ts +0 -7
  136. package/dist/types/src/utils/isValidServiceName.d.ts.map +0 -1
  137. package/dist/types/src/utils/isValidTopicOrServiceName.d.ts +0 -7
  138. package/dist/types/src/utils/isValidTopicOrServiceName.d.ts.map +0 -1
  139. package/dist/types/src/utils/verifyToken.d.ts +0 -12
  140. package/dist/types/src/utils/verifyToken.d.ts.map +0 -1
  141. package/dist/types/tsconfig.types.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/overlay-discovery-services",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Overlay Services Engine",
6
6
  "main": "dist/cjs/mod.js",
@@ -62,9 +62,9 @@
62
62
  "typescript": "^5.2.2"
63
63
  },
64
64
  "dependencies": {
65
- "@bsv/overlay": "^0.4.4",
66
- "@bsv/sdk": "^1.6.19",
67
- "@bsv/wallet-toolbox-client": "^1.5.18",
68
- "mongodb": "^6.11.0"
65
+ "@bsv/overlay": "^0.4.8",
66
+ "@bsv/sdk": "^1.8.2",
67
+ "@bsv/wallet-toolbox-client": "^1.6.26",
68
+ "mongodb": "^6.20.0"
69
69
  }
70
70
  }
@@ -25,6 +25,14 @@ export class SHIPLookupService implements LookupService {
25
25
  const domain = Utils.toUTF8(result.fields[2])
26
26
  const topicSupported = Utils.toUTF8(result.fields[3])
27
27
  if (shipIdentifier !== 'SHIP') return
28
+
29
+ // Check for duplicates before storing
30
+ const isDuplicate = await this.storage.hasDuplicateRecord(identityKey, domain, topicSupported)
31
+ if (isDuplicate) {
32
+ console.log(`🚢 Skipping duplicate SHIP record: ${domain} / ${topicSupported}`)
33
+ return
34
+ }
35
+
28
36
  await this.storage.storeSHIPRecord(txid, outputIndex, identityKey, domain, topicSupported)
29
37
  }
30
38
 
@@ -22,6 +22,22 @@ export class SHIPStorage {
22
22
  await this.shipRecords.createIndex({ domain: 1, topic: 1 })
23
23
  }
24
24
 
25
+ /**
26
+ * Checks if a duplicate SHIP record exists with the same field values
27
+ * @param {string} identityKey identity key
28
+ * @param {string} domain domain name
29
+ * @param {string} topic topic name
30
+ * @returns {Promise<boolean>} true if a duplicate exists
31
+ */
32
+ async hasDuplicateRecord(identityKey: string, domain: string, topic: string): Promise<boolean> {
33
+ const existingRecord = await this.shipRecords.findOne({
34
+ identityKey,
35
+ domain,
36
+ topic
37
+ })
38
+ return existingRecord !== null
39
+ }
40
+
25
41
  /**
26
42
  * Stores a SHIP record
27
43
  * @param {string} txid transaction id
@@ -26,6 +26,14 @@ export class SLAPLookupService implements LookupService {
26
26
  const domain = Utils.toUTF8(result.fields[2])
27
27
  const service = Utils.toUTF8(result.fields[3])
28
28
  if (protocol !== 'SLAP') return
29
+
30
+ // Check for duplicates before storing
31
+ const isDuplicate = await this.storage.hasDuplicateRecord(identityKey, domain, service)
32
+ if (isDuplicate) {
33
+ console.log(`👏 Skipping duplicate SLAP record: ${domain} / ${service}`)
34
+ return
35
+ }
36
+
29
37
  await this.storage.storeSLAPRecord(txid, outputIndex, identityKey, domain, service)
30
38
  }
31
39
 
@@ -22,6 +22,22 @@ export class SLAPStorage {
22
22
  await this.slapRecords.createIndex({ domain: 1, service: 1 })
23
23
  }
24
24
 
25
+ /**
26
+ * Checks if a duplicate SLAP record exists with the same field values
27
+ * @param {string} identityKey identity key
28
+ * @param {string} domain domain name
29
+ * @param {string} service service name
30
+ * @returns {Promise<boolean>} true if a duplicate exists
31
+ */
32
+ async hasDuplicateRecord(identityKey: string, domain: string, service: string): Promise<boolean> {
33
+ const existingRecord = await this.slapRecords.findOne({
34
+ identityKey,
35
+ domain,
36
+ service
37
+ })
38
+ return existingRecord !== null
39
+ }
40
+
25
41
  /**
26
42
  * Stores a SLAP record
27
43
  * @param {string} txid transaction id
package/dist/cjs/mod.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src/SHIP/SHIPLookupService.js"), exports);
18
- __exportStar(require("./src/SHIP/SHIPStorage.js"), exports);
19
- __exportStar(require("./src/SHIP/SHIPTopicManager.js"), exports);
20
- __exportStar(require("./src/SLAP/SLAPLookupService.js"), exports);
21
- __exportStar(require("./src/SLAP/SLAPStorage.js"), exports);
22
- __exportStar(require("./src/SLAP/SLAPTopicManager.js"), exports);
23
- __exportStar(require("./src/WalletAdvertiser.js"), exports);
24
- __exportStar(require("./src/utils/isAdvertisableURI.js"), exports);
25
- __exportStar(require("./src/utils/isValidTopicOrServiceName.js"), exports);
26
- __exportStar(require("./src/utils/isTokenSignatureCorrectlyLinked.js"), exports);
27
- __exportStar(require("./src/types.js"), exports);
28
- //# sourceMappingURL=mod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAA+C;AAC/C,4DAAyC;AACzC,iEAA8C;AAE9C,kEAA+C;AAC/C,4DAAyC;AACzC,iEAA8C;AAE9C,4DAAyC;AAEzC,mEAAgD;AAChD,2EAAwD;AACxD,iFAA8D;AAE9D,iDAA8B"}
@@ -1,55 +0,0 @@
1
- {
2
- "name": "@bsv/overlay-discovery-services",
3
- "version": "1.4.2",
4
- "type": "commonjs",
5
- "description": "BSV Blockchain Overlay Services Engine",
6
- "files": [
7
- "dist",
8
- "src",
9
- "docs",
10
- "mod.ts",
11
- "LICENSE.txt"
12
- ],
13
- "scripts": {
14
- "test": "npm run build && jest",
15
- "test:watch": "npm run build && jest --watch",
16
- "test:coverage": "npm run build && jest --coverage",
17
- "lint": "ts-standard --fix src/**/*.ts",
18
- "build": "tsc -b && tsconfig-to-dual-package tsconfig.cjs.json",
19
- "dev": "tsc -b -w",
20
- "prepublish": "npm run build",
21
- "doc": "ts2md --inputFilename=mod.ts --outputFilename=API.md --filenameSubstring=API --firstHeadingLevel=1"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/bitcoin-sv/overlay-discovery-services.git"
26
- },
27
- "keywords": [
28
- "BSV",
29
- "Blockchain",
30
- "Overlay",
31
- "Bitcoin",
32
- "SV"
33
- ],
34
- "author": "BSV Association",
35
- "license": "SEE LICENSE IN LICENSE.txt",
36
- "bugs": {
37
- "url": "https://github.com/bitcoin-sv/overlay-discovery-services/issues"
38
- },
39
- "homepage": "https://github.com/bitcoin-sv/overlay-discovery-services#readme",
40
- "devDependencies": {
41
- "@types/jest": "^29.5.12",
42
- "jest": "^29.7.0",
43
- "ts-jest": "^29.1.1",
44
- "ts-standard": "^12.0.2",
45
- "ts2md": "^0.2.0",
46
- "tsconfig-to-dual-package": "^1.2.0",
47
- "typescript": "^5.2.2"
48
- },
49
- "dependencies": {
50
- "@bsv/overlay": "^0.4.4",
51
- "@bsv/sdk": "^1.6.19",
52
- "@bsv/wallet-toolbox-client": "^1.5.18",
53
- "mongodb": "^6.11.0"
54
- }
55
- }
@@ -1,235 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LegacyNinjaAdvertiser = void 0;
7
- const pushdrop_1 = __importDefault(require("pushdrop"));
8
- const ninja_base_1 = require("ninja-base");
9
- const sdk_ts_1 = require("@babbage/sdk-ts");
10
- const sdk_1 = require("@bsv/sdk");
11
- const sendover_1 = require("sendover");
12
- const toBEEF_js_1 = require("@babbage/sdk-ts/out/src/utils/toBEEF.js");
13
- const AD_TOKEN_VALUE = 1;
14
- // TODO: Add 'implements Advertiser' back, once Advertiser can be properly imported from Overlay Services.
15
- /**
16
- * Implements the Advertiser interface for managing SHIP and SLAP advertisements using a Ninja.
17
- */
18
- class LegacyNinjaAdvertiser {
19
- /**
20
- * Constructs a new NinjaAdvertiser instance.
21
- * @param privateKey - The private key used for signing transactions.
22
- * @param dojoURL - The URL of the dojo server for the Ninja.
23
- * @param hostingDomain - The base server URL for the NinjaAdvertiser.
24
- */
25
- constructor(privateKey, dojoURL, hostingDomain) {
26
- this.privateKey = privateKey;
27
- this.dojoURL = dojoURL;
28
- this.hostingDomain = hostingDomain;
29
- this.ninja = new ninja_base_1.Ninja({
30
- privateKey,
31
- config: {
32
- dojoURL
33
- }
34
- });
35
- }
36
- /**
37
- * Sets the Engine instance to be used by this NinjaAdvertiser. This method allows for late
38
- * binding of the Engine, thus avoiding circular dependencies during instantiation. The Engine
39
- * provides necessary context with the relevant topic managers and lookup services,
40
- * as well as the lookup function used for querying advertisements.
41
- *
42
- * @param engine The Engine instance to be associated with this NinjaAdvertiser. The Engine should
43
- * be fully initialized before being passed to this method to ensure all functionalities are available.
44
- */
45
- setLookupEngine(engine) {
46
- this.engine = engine;
47
- }
48
- /**
49
- * Utility function to create multiple advertisements in a single transaction.
50
- * @param privateKey The private key used to sign the transaction.
51
- * @param adsData Array of advertisement details.
52
- * @param ninja Ninja instance for transaction processing.
53
- * @param note A note attached to the transaction.
54
- * @returns A promise that resolves to an array of TaggedBEEF objects.
55
- * @throws Will throw an error if the locking key is invalid.
56
- */
57
- async createAdvertisements(adsData) {
58
- const identityKey = sdk_1.PublicKey.fromPrivateKey(new sdk_1.PrivateKey(this.privateKey, 'hex')).toString();
59
- const outputs = await Promise.all(adsData.map(async (ad) => {
60
- // Derive a locking private key using BRC-42 derivation scheme
61
- const derivedPrivateKey = (0, sendover_1.getPaymentPrivateKey)({
62
- recipientPrivateKey: this.privateKey,
63
- senderPublicKey: identityKey,
64
- invoiceNumber: `2-${ad.protocol}-1`,
65
- returnType: 'hex'
66
- });
67
- const lockingScript = await pushdrop_1.default.create({
68
- fields: [
69
- Buffer.from(ad.protocol),
70
- Buffer.from(identityKey, 'hex'),
71
- Buffer.from(this.hostingDomain),
72
- Buffer.from(ad.topicOrServiceName)
73
- ],
74
- key: derivedPrivateKey
75
- });
76
- return {
77
- satoshis: AD_TOKEN_VALUE,
78
- script: lockingScript
79
- };
80
- }));
81
- const tx = await this.ninja.getTransactionWithOutputs({
82
- outputs,
83
- note: 'SHIP/SLAP Advertisement Issuance',
84
- autoProcess: true
85
- });
86
- const beef = (0, sdk_ts_1.toBEEFfromEnvelope)({
87
- rawTx: tx.rawTx,
88
- inputs: tx.inputs,
89
- txid: tx.txid
90
- }).beef;
91
- return {
92
- beef,
93
- topics: [...new Set(adsData.map(ad => ad.protocol === 'SHIP' ? 'tm_ship' : 'tm_slap'))]
94
- };
95
- }
96
- /**
97
- * Finds all SHIP advertisements for a given topic.
98
- * @param topic - The topic name to search for.
99
- * @returns A promise that resolves to an array of SHIP advertisements.
100
- */
101
- async findAllAdvertisements(protocol) {
102
- if (this.engine === undefined) {
103
- throw new Error('Advertiser must be configured with an overlay services engine for advertisement lookup.');
104
- }
105
- const advertisements = [];
106
- const lookupAnswer = await this.engine.lookup({
107
- service: protocol === 'SHIP' ? 'ls_ship' : 'ls_slap',
108
- query: 'findAll'
109
- });
110
- // Lookup will currently always return type output-list
111
- if (lookupAnswer.type === 'output-list') {
112
- lookupAnswer.outputs.forEach(output => {
113
- try {
114
- // Parse out the advertisements using the provided parser
115
- const tx = sdk_1.Transaction.fromBEEF(output.beef);
116
- const advertisement = this.parseAdvertisement(tx.outputs[output.outputIndex].lockingScript);
117
- if (advertisement !== undefined && advertisement !== null && advertisement.protocol === protocol) {
118
- advertisements.push({
119
- ...advertisement,
120
- beef: output.beef,
121
- outputIndex: output.outputIndex
122
- });
123
- }
124
- }
125
- catch (error) {
126
- console.error('Failed to parse advertisement output:', error);
127
- }
128
- });
129
- }
130
- return advertisements;
131
- }
132
- /**
133
- * Revokes an existing advertisement.
134
- * @param advertisements - The advertisements to revoke, either SHIP or SLAP.
135
- * @returns A promise that resolves to the revoked advertisement as TaggedBEEF.
136
- */
137
- async revokeAdvertisements(advertisements) {
138
- if (advertisements.length === 0) {
139
- throw new Error('Must provide advertisements to revoke!');
140
- }
141
- const inputsByTxid = {};
142
- for (const advertisement of advertisements) {
143
- if (advertisement.beef === undefined || advertisement.outputIndex === undefined) {
144
- throw new Error('Advertisement to revoke must contain tagged beef!');
145
- }
146
- // Parse the transaction and UTXO to spend
147
- const advertisementTx = sdk_1.Transaction.fromBEEF(advertisement.beef);
148
- const adTxid = advertisementTx.id('hex');
149
- const outputToRedeem = advertisementTx.outputs[advertisement.outputIndex];
150
- const identityKey = sdk_1.PublicKey.fromPrivateKey(new sdk_1.PrivateKey(this.privateKey, 'hex')).toString();
151
- // Derive a unlocking private key using BRC-42 derivation scheme
152
- const derivedPrivateKey = (0, sendover_1.getPaymentPrivateKey)({
153
- recipientPrivateKey: this.privateKey,
154
- senderPublicKey: identityKey,
155
- invoiceNumber: `2-${advertisement.protocol}-1`,
156
- returnType: 'hex'
157
- });
158
- const unlockingScript = await pushdrop_1.default.redeem({
159
- key: derivedPrivateKey,
160
- prevTxId: adTxid,
161
- outputIndex: advertisement.outputIndex,
162
- lockingScript: outputToRedeem.lockingScript.toHex(),
163
- outputAmount: outputToRedeem.satoshis
164
- });
165
- const constructedRedeem = {
166
- index: advertisement.outputIndex,
167
- unlockingScript
168
- };
169
- // Group outputs by their transaction ID
170
- if (inputsByTxid[adTxid] === undefined) {
171
- inputsByTxid[adTxid] = {
172
- ...(0, toBEEF_js_1.toEnvelopeFromBEEF)(advertisementTx),
173
- rawTx: advertisementTx.toHex(),
174
- outputsToRedeem: [constructedRedeem]
175
- };
176
- }
177
- else {
178
- inputsByTxid[adTxid].outputsToRedeem.push(constructedRedeem);
179
- }
180
- }
181
- // Create a new transaction that spends the SHIP or SLAP advertisement issuance token
182
- const revokeTx = await this.ninja.getTransactionWithOutputs({
183
- inputs: inputsByTxid,
184
- outputs: [],
185
- labels: [],
186
- note: 'Revoked SHIP/SLAP advertisements',
187
- autoProcess: true
188
- });
189
- const beef = (0, sdk_ts_1.toBEEFfromEnvelope)({
190
- rawTx: revokeTx.rawTx,
191
- inputs: revokeTx.inputs,
192
- txid: revokeTx.txid
193
- }).beef;
194
- return {
195
- beef,
196
- topics: [...new Set(advertisements.map(ad => ad.protocol === 'SHIP' ? 'tm_ship' : 'tm_slap'))]
197
- };
198
- }
199
- /**
200
- * Parses an advertisement from the provided output script.
201
- * @param outputScript - The output script to parse.
202
- * @returns An Advertisement object if the script matches the expected format, otherwise throws an error.
203
- */
204
- parseAdvertisement(outputScript) {
205
- try {
206
- const result = pushdrop_1.default.decode({
207
- script: outputScript.toHex(),
208
- fieldFormat: 'buffer'
209
- });
210
- if (result.fields.length < 4) {
211
- throw new Error('Invalid SHIP/SLAP advertisement!');
212
- }
213
- const protocol = result.fields[0].toString();
214
- if (protocol !== 'SHIP' && protocol !== 'SLAP') {
215
- throw new Error('Invalid protocol type!');
216
- }
217
- const identityKey = result.fields[1].toString('hex');
218
- const domain = result.fields[2].toString();
219
- const topicOrService = result.fields[3].toString();
220
- // Construct a unified Advertisement object
221
- return {
222
- protocol: protocol,
223
- identityKey,
224
- domain,
225
- topicOrService
226
- };
227
- }
228
- catch (error) {
229
- console.error('Error parsing advertisement:', error);
230
- throw new Error('Error parsing advertisement!');
231
- }
232
- }
233
- }
234
- exports.LegacyNinjaAdvertiser = LegacyNinjaAdvertiser;
235
- //# sourceMappingURL=LegacyNinjaAdvertiser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LegacyNinjaAdvertiser.js","sourceRoot":"","sources":["../../../src/LegacyNinjaAdvertiser.ts"],"names":[],"mappings":";;;;;;AACA,wDAA+B;AAC/B,2CAAoD;AACpD,4CAAyE;AACzE,kCAAqE;AAErE,uCAA+C;AAE/C,uEAA4E;AAE5E,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB,0GAA0G;AAE1G;;GAEG;AACH,MAAa,qBAAqB;IAIhC;;;;;OAKG;IACH,YACS,UAAkB,EAClB,OAAe,EACf,aAAqB;QAFrB,eAAU,GAAV,UAAU,CAAQ;QAClB,YAAO,GAAP,OAAO,CAAQ;QACf,kBAAa,GAAb,aAAa,CAAQ;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,kBAAK,CAAC;YACrB,UAAU;YACV,MAAM,EAAE;gBACN,OAAO;aACR;SACF,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;OAQG;IACH,eAAe,CA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,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAA;YACpD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;CACF;AAlPD,sDAkPC"}
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = `# SHIP Lookup Service
4
-
5
- **Protocol Name**: SHIP (Service Host Interconnect Protocol)
6
- **Lookup Service Name**: \`SHIPLookupService\`
7
-
8
- ---
9
-
10
- ## Overview
11
-
12
- The SHIP Lookup Service is used to **query** the known SHIP tokens in your overlay database. It allows you to discover nodes that have published SHIP outputs, indicating they host or participate in certain topics (prefixed \`tm_\`).
13
-
14
- This lookup service is typically invoked by sending a [LookupQuestion](https://www.npmjs.com/package/@bsv/overlay#lookupservice) with:
15
- - \`question.service = 'ls_ship'\`
16
- - \`question.query\` containing parameters for searching.
17
-
18
- ---
19
-
20
- ## Purpose
21
-
22
- - **Discovery**: Find all hosts that declared themselves via SHIP tokens.
23
- - **Filtering**: Narrow results by domain, by topic, or both.
24
-
25
- ---
26
-
27
- ## Querying the SHIP Lookup Service
28
-
29
- When you call \`lookup(question)\` on the SHIP Lookup Service, you must include:
30
-
31
- 1. **\`question.service\`** set to \`"ls_ship"\`.
32
- 2. **\`question.query\`**: Can be one of the following:
33
- - \`"findAll"\` (string literal): Returns **all** known SHIP records.
34
- - An object of type:
35
- \`\`\`ts
36
- interface SHIPQuery {
37
- domain?: string
38
- topics?: string[]
39
- }
40
- \`\`\`
41
- where:
42
- - \`domain\` is an optional string. If provided, results will match that domain/advertisedURI.
43
- - \`topics\` is an optional string array. If provided, results will match any of those \`tm_\` topics.
44
-
45
- ### Examples
46
-
47
- 1. **Find all SHIP records**:
48
- \`\`\`js
49
- const question = {
50
- service: 'ls_ship',
51
- query: 'findAll'
52
- }
53
- const results = await overlayClient.lookup(question)
54
- \`\`\`
55
-
56
- 2. **Find by domain**:
57
- \`\`\`js
58
- const question = {
59
- service: 'ls_ship',
60
- query: { domain: 'https://myexample.com' }
61
- }
62
- const results = await overlayClient.lookup(question)
63
- \`\`\`
64
-
65
- 3. **Find by topics**:
66
- \`\`\`js
67
- const question = {
68
- service: 'ls_ship',
69
- query: { topics: ['tm_bridge', 'tm_sync'] }
70
- }
71
- const results = await overlayClient.lookup(question)
72
- \`\`\`
73
-
74
- 4. **Find by domain AND topics**:
75
- \`\`\`js
76
- const question = {
77
- service: 'ls_ship',
78
- query: {
79
- domain: 'https://myexample.com',
80
- topics: ['tm_bridge']
81
- }
82
- }
83
- const results = await overlayClient.lookup(question)
84
- \`\`\`
85
-
86
- ---
87
-
88
- ## Gotchas and Tips
89
-
90
- - **Topic Prefix**: The SHIP manager expects topics to start with \`tm_\`. If you see no results, ensure you used the correct prefix.
91
- - **Strict Matching**: Domain matching requires an exact string match. If you have a different protocol (https vs https+bsvauth vs https+bsvauth+smf), be sure to store/lookup accordingly.
92
- - **Partial Queries**: If you only provide \`topics\`, domain-based filtering is not applied, and vice versa.
93
- - **Multiple Topics**: Since \`topics\` is an array, the storage will return all records matching **any** listed topic.
94
-
95
- ---
96
-
97
- ## Further Reading
98
-
99
- - **SHIPTopicManager**: For how the outputs are admitted.
100
- - **BRC-101 Overlays**: The general pattern for these sorts of services.
101
- - **SLAP**: The complementary protocol for service lookup availability ads.
102
- `;
103
- //# sourceMappingURL=SHIPLookup.docs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SHIPLookup.docs.js","sourceRoot":"","sources":["../../../../src/SHIP/SHIPLookup.docs.ts"],"names":[],"mappings":";;AAAA,kBAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmGd,CAAA"}
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SHIPLookupService = void 0;
7
- const sdk_1 = require("@bsv/sdk");
8
- const SHIPLookup_docs_js_1 = __importDefault(require("./SHIPLookup.docs.js"));
9
- /**
10
- * Implements the SHIP lookup service
11
- *
12
- * The SHIP lookup service allows querying for overlay services hosting specific topics
13
- * within the overlay network.
14
- */
15
- class SHIPLookupService {
16
- constructor(storage) {
17
- this.storage = storage;
18
- this.admissionMode = 'locking-script';
19
- this.spendNotificationMode = 'none';
20
- }
21
- async outputAdmittedByTopic(payload) {
22
- if (payload.mode !== 'locking-script')
23
- throw new Error('Invalid payload');
24
- const { topic, lockingScript, txid, outputIndex } = payload;
25
- if (topic !== 'tm_ship')
26
- return;
27
- const result = sdk_1.PushDrop.decode(lockingScript);
28
- const shipIdentifier = sdk_1.Utils.toUTF8(result.fields[0]);
29
- const identityKey = sdk_1.Utils.toHex(result.fields[1]);
30
- const domain = sdk_1.Utils.toUTF8(result.fields[2]);
31
- const topicSupported = sdk_1.Utils.toUTF8(result.fields[3]);
32
- if (shipIdentifier !== 'SHIP')
33
- return;
34
- await this.storage.storeSHIPRecord(txid, outputIndex, identityKey, domain, topicSupported);
35
- }
36
- async outputSpent(payload) {
37
- if (payload.mode !== 'none')
38
- throw new Error('Invalid payload');
39
- const { topic, txid, outputIndex } = payload;
40
- if (topic !== 'tm_ship')
41
- return;
42
- await this.storage.deleteSHIPRecord(txid, outputIndex);
43
- }
44
- async outputEvicted(txid, outputIndex) {
45
- await this.storage.deleteSHIPRecord(txid, outputIndex);
46
- }
47
- async lookup(question) {
48
- if (question.query === undefined || question.query === null) {
49
- throw new Error('A valid query must be provided!');
50
- }
51
- if (question.service !== 'ls_ship') {
52
- throw new Error('Lookup service not supported!');
53
- }
54
- // Handle legacy "findAll" string query
55
- if (question.query === 'findAll') {
56
- return await this.storage.findAll();
57
- }
58
- // Handle object-based query
59
- if (typeof question.query === 'object') {
60
- const query = question.query;
61
- // Handle new findAll mode with pagination
62
- if (query.findAll) {
63
- const { limit, skip, sortOrder } = query;
64
- // Validate pagination parameters
65
- if (typeof limit !== 'undefined' && (typeof limit !== 'number' || limit < 0)) {
66
- throw new Error('query.limit must be a positive number if provided');
67
- }
68
- if (typeof skip !== 'undefined' && (typeof skip !== 'number' || skip < 0)) {
69
- throw new Error('query.skip must be a non-negative number if provided');
70
- }
71
- if (typeof sortOrder !== 'undefined' && sortOrder !== 'asc' && sortOrder !== 'desc') {
72
- throw new Error('query.sortOrder must be "asc" or "desc" if provided');
73
- }
74
- return await this.storage.findAll(limit, skip, sortOrder);
75
- }
76
- // Handle specific query with domain, topics, identityKey
77
- const { domain, topics, identityKey, limit, skip, sortOrder } = query;
78
- // Validate query parameters
79
- if (typeof domain !== 'string' && typeof domain !== 'undefined') {
80
- throw new Error('query.domain must be a string if provided');
81
- }
82
- if (!Array.isArray(topics) && typeof topics !== 'undefined') {
83
- throw new Error('query.topics must be an array of strings if provided');
84
- }
85
- if (typeof identityKey !== 'string' && typeof identityKey !== 'undefined') {
86
- throw new Error('query.identityKey must be a string if provided');
87
- }
88
- // Validate pagination parameters
89
- if (typeof limit !== 'undefined' && (typeof limit !== 'number' || limit < 0)) {
90
- throw new Error('query.limit must be a positive number if provided');
91
- }
92
- if (typeof skip !== 'undefined' && (typeof skip !== 'number' || skip < 0)) {
93
- throw new Error('query.skip must be a non-negative number if provided');
94
- }
95
- if (typeof sortOrder !== 'undefined' && sortOrder !== 'asc' && sortOrder !== 'desc') {
96
- throw new Error('query.sortOrder must be "asc" or "desc" if provided');
97
- }
98
- return await this.storage.findRecord({ domain, topics, identityKey, limit, skip, sortOrder });
99
- }
100
- throw new Error('Invalid query format. Query must be "findAll" string or an object with valid parameters.');
101
- }
102
- async getDocumentation() {
103
- return SHIPLookup_docs_js_1.default;
104
- }
105
- async getMetaData() {
106
- return {
107
- name: 'SHIP Lookup Service',
108
- shortDescription: 'Provides lookup capabilities for SHIP tokens.'
109
- };
110
- }
111
- }
112
- exports.SHIPLookupService = SHIPLookupService;
113
- //# sourceMappingURL=SHIPLookupService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SHIPLookupService.js","sourceRoot":"","sources":["../../../../src/SHIP/SHIPLookupService.ts"],"names":[],"mappings":";;;;;;AAEA,kCAA0C;AAE1C,8EAAiD;AAEjD;;;;;GAKG;AACH,MAAa,iBAAiB;IAG5B,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;QAFxC,kBAAa,GAAkB,gBAAgB,CAAA;QAC/C,0BAAqB,GAA0B,MAAM,CAAA;IACT,CAAC;IAE7C,KAAK,CAAC,qBAAqB,CAAE,OAA8B;QACzD,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB;YAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;QACzE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;QAC3D,IAAI,KAAK,KAAK,SAAS;YAAE,OAAM;QAC/B,MAAM,MAAM,GAAG,cAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;QAC7C,MAAM,cAAc,GAAG,WAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACrD,MAAM,WAAW,GAAG,WAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACjD,MAAM,MAAM,GAAG,WAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7C,MAAM,cAAc,GAAG,WAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACrD,IAAI,cAAc,KAAK,MAAM;YAAE,OAAM;QACrC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAA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