@bsv/overlay-discovery-services 2.0.1 → 2.0.2

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 (41) hide show
  1. package/dist/cjs/package.json +4 -4
  2. package/dist/cjs/src/LegacyNinjaAdvertiser.js +235 -0
  3. package/dist/cjs/src/LegacyNinjaAdvertiser.js.map +1 -0
  4. package/dist/cjs/src/utils/generateDocs.js +81 -0
  5. package/dist/cjs/src/utils/generateDocs.js.map +1 -0
  6. package/dist/cjs/src/utils/getDocumentation.js +22 -0
  7. package/dist/cjs/src/utils/getDocumentation.js.map +1 -0
  8. package/dist/cjs/src/utils/isValidDomain.js +15 -0
  9. package/dist/cjs/src/utils/isValidDomain.js.map +1 -0
  10. package/dist/cjs/src/utils/isValidServiceName.js +14 -0
  11. package/dist/cjs/src/utils/isValidServiceName.js.map +1 -0
  12. package/dist/cjs/src/utils/verifyToken.js +22 -0
  13. package/dist/cjs/src/utils/verifyToken.js.map +1 -0
  14. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  15. package/dist/esm/src/LegacyNinjaAdvertiser.js +233 -0
  16. package/dist/esm/src/LegacyNinjaAdvertiser.js.map +1 -0
  17. package/dist/esm/src/utils/generateDocs.js +46 -0
  18. package/dist/esm/src/utils/generateDocs.js.map +1 -0
  19. package/dist/esm/src/utils/getDocumentation.js +20 -0
  20. package/dist/esm/src/utils/getDocumentation.js.map +1 -0
  21. package/dist/esm/src/utils/isValidDomain.js +11 -0
  22. package/dist/esm/src/utils/isValidDomain.js.map +1 -0
  23. package/dist/esm/src/utils/isValidServiceName.js +10 -0
  24. package/dist/esm/src/utils/isValidServiceName.js.map +1 -0
  25. package/dist/esm/src/utils/verifyToken.js +18 -0
  26. package/dist/esm/src/utils/verifyToken.js.map +1 -0
  27. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  28. package/dist/types/src/LegacyNinjaAdvertiser.d.ts +60 -0
  29. package/dist/types/src/LegacyNinjaAdvertiser.d.ts.map +1 -0
  30. package/dist/types/src/utils/generateDocs.d.ts +2 -0
  31. package/dist/types/src/utils/generateDocs.d.ts.map +1 -0
  32. package/dist/types/src/utils/getDocumentation.d.ts +8 -0
  33. package/dist/types/src/utils/getDocumentation.d.ts.map +1 -0
  34. package/dist/types/src/utils/isValidDomain.d.ts +7 -0
  35. package/dist/types/src/utils/isValidDomain.d.ts.map +1 -0
  36. package/dist/types/src/utils/isValidServiceName.d.ts +7 -0
  37. package/dist/types/src/utils/isValidServiceName.d.ts.map +1 -0
  38. package/dist/types/src/utils/verifyToken.d.ts +12 -0
  39. package/dist/types/src/utils/verifyToken.d.ts.map +1 -0
  40. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  41. package/package.json +4 -4
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/overlay-discovery-services",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "commonjs",
5
5
  "description": "BSV Blockchain Overlay Services Engine",
6
6
  "files": [
@@ -47,9 +47,9 @@
47
47
  "typescript": "^5.2.2"
48
48
  },
49
49
  "dependencies": {
50
- "@bsv/overlay": "^2.0.0",
51
- "@bsv/sdk": "^2.0.1",
52
- "@bsv/wallet-toolbox-client": "^2.0.5",
50
+ "@bsv/overlay": "^2.0.1",
51
+ "@bsv/sdk": "^2.0.4",
52
+ "@bsv/wallet-toolbox-client": "^2.0.20",
53
53
  "mongodb": "^7.1.0"
54
54
  }
55
55
  }
@@ -0,0 +1,235 @@
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
@@ -0,0 +1 @@
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,CAAC,MAAc;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,oBAAoB,CACxB,OAA4B;QAE5B,MAAM,WAAW,GAAG,eAAS,CAAC,cAAc,CAAC,IAAI,gBAAU,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;QAE/F,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YACzD,8DAA8D;YAC9D,MAAM,iBAAiB,GAAG,IAAA,+BAAoB,EAAC;gBAC7C,mBAAmB,EAAE,IAAI,CAAC,UAAU;gBACpC,eAAe,E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AAE,QAAQ;aACtB,CAAC,CAAA;YAEF,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;YACrD,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;YAC5C,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;gBAC/C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;YAC3C,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YACpD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;YAC1C,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;YAElD,2CAA2C;YAC3C,OAAO;gBACL,QAAQ,EAAE,QAA2B;gBACrC,WAAW;gBACX,MAAM;gBACN,cAAc;aACf,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"}
@@ -0,0 +1,81 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const child_process_1 = require("child_process");
37
+ const util_1 = require("util");
38
+ const path = __importStar(require("path"));
39
+ const execPromise = (0, util_1.promisify)(child_process_1.exec);
40
+ const docs = [
41
+ {
42
+ input: './src/SHIP/SHIPTopicManager.ts',
43
+ output: './docs/SHIP/ship-topic-manager.md'
44
+ },
45
+ {
46
+ input: './src/SHIP/SHIPLookupService.ts',
47
+ output: './docs/SHIP/ship-lookup-service.md'
48
+ },
49
+ {
50
+ input: './src/SHIP/SHIPStorage.ts',
51
+ output: './docs/SHIP/ship-storage.md'
52
+ },
53
+ {
54
+ input: './src/SLAP/SLAPTopicManager.ts',
55
+ output: './docs/SLAP/slap-topic-manager.md'
56
+ },
57
+ {
58
+ input: './src/SLAP/SLAPLookupService.ts',
59
+ output: './docs/SLAP/slap-lookup-service.md'
60
+ },
61
+ {
62
+ input: './src/SLAP/SLAPStorage.ts',
63
+ output: './docs/SLAP/slap-storage.md'
64
+ }
65
+ ];
66
+ // Helper function for generating updated documentation
67
+ const generateDocs = async () => {
68
+ for (const doc of docs) {
69
+ const command = `npx ts2md --inputFilename ${path.resolve(doc.input)} --outputFilename ${path.resolve(doc.output)} --firstHeadingLevel 2 --noTitle true --readmeMerge true`;
70
+ try {
71
+ const { stdout, stderr } = await execPromise(command);
72
+ console.log(`stdout: ${stdout}`);
73
+ console.error(`stderr: ${stderr}`);
74
+ }
75
+ catch (error) {
76
+ console.error(`Error generating documentation for ${doc.input}:`, error);
77
+ }
78
+ }
79
+ };
80
+ generateDocs().then(() => console.log('Documentation generation complete')).catch(error => console.error('Error:', error));
81
+ //# sourceMappingURL=generateDocs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateDocs.js","sourceRoot":"","sources":["../../../../src/utils/generateDocs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAoC;AACpC,+BAAgC;AAChC,2CAA4B;AAE5B,MAAM,WAAW,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAA;AAOnC,MAAM,IAAI,GAAgB;IACxB;QACE,KAAK,EAAE,gCAAgC;QACvC,MAAM,EAAE,mCAAmC;KAC5C;IACD;QACE,KAAK,EAAE,iCAAiC;QACxC,MAAM,EAAE,oCAAoC;KAC7C;IACD;QACE,KAAK,EAAE,2BAA2B;QAClC,MAAM,EAAE,6BAA6B;KACtC;IACD;QACE,KAAK,EAAE,gCAAgC;QACvC,MAAM,EAAE,mCAAmC;KAC5C;IACD;QACE,KAAK,EAAE,iCAAiC;QACxC,MAAM,EAAE,oCAAoC;KAC7C;IACD;QACE,KAAK,EAAE,2BAA2B;QAClC,MAAM,EAAE,6BAA6B;KACtC;CACF,CAAA;AAED,uDAAuD;AACvD,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,6BAA6B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,qBAAqB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,0DAA0D,CAAA;QAC3K,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAA;YACrD,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,EAAE,CAAC,CAAA;YAChC,OAAO,CAAC,KAAK,CAAC,WAAW,MAAM,EAAE,CAAC,CAAA;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,GAAG,CAAC,KAAK,GAAG,EAAE,KAAK,CAAC,CAAA;QAC1E,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED,YAAY,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDocumentation = getDocumentation;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Returns documentation specific to the provided filename
8
+ * @param {string} filePath - The path of the markdown file
9
+ * @returns A promise that resolves to the documentation string
10
+ */
11
+ async function getDocumentation(filePath) {
12
+ try {
13
+ const resolvedPath = (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@bsv/overlay-discovery-services')), '../../', filePath);
14
+ const data = await fs_1.promises.readFile(resolvedPath, 'utf-8');
15
+ return data;
16
+ }
17
+ catch (error) {
18
+ console.error('Error reading documentation file:', error);
19
+ throw new Error('Failed to read documentation file');
20
+ }
21
+ }
22
+ //# sourceMappingURL=getDocumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDocumentation.js","sourceRoot":"","sources":["../../../../src/utils/getDocumentation.ts"],"names":[],"mappings":";;AAkBS,4CAAgB;AAlBzB,2BAAmC;AACnC,+BAAuC;AACvC;;;;GAIG;AACH,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IAC9C,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,IAAA,cAAO,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAC7G,MAAM,IAAI,GAAG,MAAM,aAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QACrD,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAA;QACzD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IACtD,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidDomain = void 0;
4
+ /**
5
+ * Validates if the provided domain name is valid.
6
+ * @param domain - The domain name to validate.
7
+ * @returns True if the domain name is valid, false otherwise.
8
+ */
9
+ const isValidDomain = (domain) => {
10
+ // Simple regex to validate domain name
11
+ const domainRegex = /^(https?:\/\/)?((([a-zA-Z0-9-]+)\.)+([a-zA-Z]{2,})|localhost(:[0-9]+))(\/.*)?$/;
12
+ return domainRegex.test(domain);
13
+ };
14
+ exports.isValidDomain = isValidDomain;
15
+ //# sourceMappingURL=isValidDomain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidDomain.js","sourceRoot":"","sources":["../../../../src/utils/isValidDomain.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,aAAa,GAAG,CAAC,MAAc,EAAW,EAAE;IACvD,uCAAuC;IACvC,MAAM,WAAW,GAAG,gFAAgF,CAAA;IACpG,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AACjC,CAAC,CAAA;AAJY,QAAA,aAAa,iBAIzB"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidServiceName = void 0;
4
+ /**
5
+ * Validates if the provided service name is valid based on BRC-87 guidelines.
6
+ * @param service - The service name to validate.
7
+ * @returns True if the service name is valid, false otherwise.
8
+ */
9
+ const isValidServiceName = (service) => {
10
+ const serviceRegex = /^(?!_)(?!.*__)[a-z_]{1,50}(?<!_)$/;
11
+ return serviceRegex.test(service);
12
+ };
13
+ exports.isValidServiceName = isValidServiceName;
14
+ //# sourceMappingURL=isValidServiceName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidServiceName.js","sourceRoot":"","sources":["../../../../src/utils/isValidServiceName.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAW,EAAE;IAC7D,MAAM,YAAY,GAAG,mCAAmC,CAAA;IACxD,OAAO,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACnC,CAAC,CAAA;AAHY,QAAA,kBAAkB,sBAG9B"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyToken = void 0;
4
+ const sdk_1 = require("@bsv/sdk");
5
+ /**
6
+ * Verifies the BRC-48 locking key and the signature.
7
+ * @private
8
+ * @param identityKey - The BRC-31 identity key of the advertiser.
9
+ * @param lockingPublicKey - The public key used in the output's locking script.
10
+ * @param fields - The fields of the token.
11
+ * @param signature - The signature over the token fields.
12
+ * @param protocolId - The protocol ID (e.g., 'SHIP' or 'SLAP').
13
+ * @throws Will throw an error if the locking key or signature is invalid.
14
+ */
15
+ const verifyToken = (identityKey, lockingPublicKey, fields, signature) => {
16
+ const pubKey = sdk_1.PublicKey.fromString(lockingPublicKey);
17
+ const hasValidSignature = pubKey.verify(Array.from(Buffer.concat(fields)), sdk_1.Signature.fromDER(signature, 'hex'));
18
+ if (!hasValidSignature)
19
+ throw new Error('Invalid signature!');
20
+ };
21
+ exports.verifyToken = verifyToken;
22
+ //# sourceMappingURL=verifyToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyToken.js","sourceRoot":"","sources":["../../../../src/utils/verifyToken.ts"],"names":[],"mappings":";;;AAAA,kCAA+C;AAE/C;;;;;;;;;GASG;AACI,MAAM,WAAW,GAAG,CACzB,WAAmB,EACnB,gBAAwB,EACxB,MAAgB,EAChB,SAAiB,EACX,EAAE;IACR,MAAM,MAAM,GAAG,eAAS,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAA;IACrD,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CACrC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EACjC,eAAS,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CACpC,CAAA;IAED,IAAI,CAAC,iBAAiB;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;AAC/D,CAAC,CAAA;AAbY,QAAA,WAAW,eAavB"}