shogun-core 1.2.7 → 1.2.8

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 (67) hide show
  1. package/README.md +0 -1
  2. package/dist/browser/shogun-core.js +1 -1
  3. package/dist/browser/shogun-core.js.LICENSE.txt +2 -0
  4. package/dist/browser/shogun-core.light.js +1 -1
  5. package/dist/browser/shogun-core.vendors.light.js +1 -1
  6. package/dist/core.js +31 -71
  7. package/dist/gundb/{instance.js → gunInstance.js} +135 -115
  8. package/dist/gundb/index.js +3 -20
  9. package/dist/plugins/index.js +23 -1
  10. package/dist/plugins/nostr/index.js +1 -0
  11. package/dist/plugins/nostr/nostrChain.js +128 -0
  12. package/dist/plugins/nostr/nostrConnector.js +42 -7
  13. package/dist/plugins/nostr/nostrConnectorPlugin.js +157 -1
  14. package/dist/plugins/nostr/nostrSigner.js +343 -0
  15. package/dist/plugins/oauth/index.js +13 -0
  16. package/dist/plugins/oauth/oauthChain.js +161 -0
  17. package/dist/plugins/oauth/oauthConnector.js +542 -0
  18. package/dist/plugins/oauth/oauthPlugin.js +302 -0
  19. package/dist/plugins/oauth/types.js +2 -0
  20. package/dist/plugins/web3/index.js +1 -0
  21. package/dist/plugins/web3/web3Chain.js +77 -2
  22. package/dist/plugins/web3/web3Connector.js +159 -37
  23. package/dist/plugins/web3/web3ConnectorPlugin.js +157 -1
  24. package/dist/plugins/web3/web3Signer.js +268 -0
  25. package/dist/plugins/webauthn/webauthnChain.js +78 -0
  26. package/dist/plugins/webauthn/webauthnPlugin.js +154 -1
  27. package/dist/plugins/webauthn/webauthnSigner.js +318 -0
  28. package/dist/storage/storage.js +0 -8
  29. package/dist/types/core.d.ts +10 -34
  30. package/dist/types/gundb/gun-es/gun-es.d.ts +1 -0
  31. package/dist/types/gundb/{instance.d.ts → gunInstance.d.ts} +2 -2
  32. package/dist/types/gundb/index.d.ts +1 -4
  33. package/dist/types/plugins/index.d.ts +4 -0
  34. package/dist/types/plugins/nostr/index.d.ts +1 -0
  35. package/dist/types/plugins/nostr/nostrConnector.d.ts +3 -2
  36. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +82 -0
  37. package/dist/types/plugins/nostr/nostrSigner.d.ts +104 -0
  38. package/dist/types/plugins/oauth/index.d.ts +4 -0
  39. package/dist/types/plugins/oauth/oauthChain.d.ts +2 -0
  40. package/dist/types/plugins/oauth/oauthConnector.d.ts +100 -0
  41. package/dist/types/plugins/oauth/oauthPlugin.d.ts +89 -0
  42. package/dist/types/plugins/oauth/types.d.ts +106 -0
  43. package/dist/types/plugins/web3/index.d.ts +1 -0
  44. package/dist/types/plugins/web3/types.d.ts +1 -0
  45. package/dist/types/plugins/web3/web3Connector.d.ts +8 -2
  46. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +82 -0
  47. package/dist/types/plugins/web3/web3Signer.d.ts +93 -0
  48. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +81 -0
  49. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +90 -0
  50. package/dist/types/shogun.js +1 -28
  51. package/dist/types/types/events.d.ts +2 -2
  52. package/dist/types/types/shogun.d.ts +13 -49
  53. package/package.json +2 -1
  54. package/dist/browser.js +0 -107
  55. package/dist/contracts/base.js +0 -152
  56. package/dist/contracts/entryPoint.js +0 -407
  57. package/dist/contracts/index.js +0 -47
  58. package/dist/contracts/registry.js +0 -259
  59. package/dist/contracts/relay.js +0 -494
  60. package/dist/contracts/utils.js +0 -582
  61. package/dist/types/browser.d.ts +0 -27
  62. package/dist/types/contracts/base.d.ts +0 -82
  63. package/dist/types/contracts/entryPoint.d.ts +0 -138
  64. package/dist/types/contracts/index.d.ts +0 -17
  65. package/dist/types/contracts/registry.d.ts +0 -97
  66. package/dist/types/contracts/relay.d.ts +0 -165
  67. package/dist/types/contracts/utils.d.ts +0 -173
@@ -1,494 +0,0 @@
1
- "use strict";
2
- /**
3
- * SimpleRelay Class - Provides interaction with the Shogun Protocol SimpleRelay contract
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SimpleRelay = void 0;
7
- const ethers_1 = require("ethers");
8
- const errorHandler_1 = require("../utils/errorHandler");
9
- const base_1 = require("./base");
10
- /**
11
- * SimpleRelay - A class to interact with the Shogun Protocol SimpleRelay contract
12
- */
13
- class SimpleRelay extends base_1.BaseContract {
14
- /**
15
- * Create a new SimpleRelay instance
16
- * @param config - Configuration for the SimpleRelay
17
- */
18
- constructor(config) {
19
- super(config.relayAddress, base_1.SIMPLE_RELAY_ABI, config);
20
- }
21
- /**
22
- * Check if a user's subscription is active
23
- * @param userAddress - The address of the user
24
- * @returns True if the subscription is active, false otherwise
25
- */
26
- async isSubscriptionActive(userAddress) {
27
- try {
28
- if (!this.contract) {
29
- throw new Error("SimpleRelay contract not initialized");
30
- }
31
- return await this.contract.isSubscriptionActive(userAddress);
32
- }
33
- catch (error) {
34
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_IS_SUBSCRIPTION_ACTIVE_FAILED", `Failed to check if subscription is active for user ${userAddress}`, error);
35
- return false;
36
- }
37
- }
38
- /**
39
- * Get detailed subscription information for a user
40
- * @param userAddress - The address of the user
41
- * @returns The subscription information or null if not found
42
- */
43
- async getUserSubscriptionInfo(userAddress) {
44
- try {
45
- if (!this.contract) {
46
- throw new Error("SimpleRelay contract not initialized");
47
- }
48
- const [expires, pubKey] = await this.contract.getUserSubscriptionInfo(userAddress);
49
- const isActive = await this.contract.isSubscriptionActive(userAddress);
50
- return {
51
- expires,
52
- pubKey: ethers_1.ethers.hexlify(pubKey),
53
- isActive,
54
- };
55
- }
56
- catch (error) {
57
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_SUBSCRIPTION_INFO_FAILED", `Failed to get subscription info for user ${userAddress}`, error);
58
- return null;
59
- }
60
- }
61
- /**
62
- * Check if a public key is authorized
63
- * @param pubKey - The public key to check (hex string or Uint8Array)
64
- * @returns True if the public key is authorized, false otherwise
65
- */
66
- async isAuthorizedByPubKey(pubKey) {
67
- try {
68
- if (!this.contract) {
69
- throw new Error("SimpleRelay contract not initialized");
70
- }
71
- // Convert Uint8Array to hex string if needed
72
- const pubKeyHex = pubKey instanceof Uint8Array ? ethers_1.ethers.hexlify(pubKey) : pubKey;
73
- return await this.contract.isAuthorizedByPubKey(pubKeyHex);
74
- }
75
- catch (error) {
76
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_IS_AUTHORIZED_FAILED", "Failed to check if public key is authorized", error);
77
- return false;
78
- }
79
- }
80
- /**
81
- * Check if a public key is subscribed (alias for isAuthorizedByPubKey)
82
- * @param pubKey - The public key to check (hex string or Uint8Array)
83
- * @returns True if the public key is subscribed, false otherwise
84
- */
85
- async isSubscribed(pubKey) {
86
- try {
87
- if (!this.contract) {
88
- throw new Error("SimpleRelay contract not initialized");
89
- }
90
- // Convert Uint8Array to hex string if needed
91
- const pubKeyHex = pubKey instanceof Uint8Array ? ethers_1.ethers.hexlify(pubKey) : pubKey;
92
- return await this.contract.isSubscribed(pubKeyHex);
93
- }
94
- catch (error) {
95
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_IS_SUBSCRIBED_FAILED", "Failed to check if public key is subscribed", error);
96
- return false;
97
- }
98
- }
99
- /**
100
- * Get the monthly subscription price
101
- * @returns The price in wei or null if the call fails
102
- */
103
- async getPricePerMonth() {
104
- try {
105
- if (!this.contract) {
106
- throw new Error("SimpleRelay contract not initialized");
107
- }
108
- return await this.contract.pricePerMonth();
109
- }
110
- catch (error) {
111
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_PRICE_FAILED", "Failed to get price per month", error);
112
- return null;
113
- }
114
- }
115
- /**
116
- * Get the number of days per month used for subscription calculations
117
- * @returns The days per month or null if the call fails
118
- */
119
- async getDaysPerMonth() {
120
- try {
121
- if (!this.contract) {
122
- throw new Error("SimpleRelay contract not initialized");
123
- }
124
- const days = await this.contract.daysPerMonth();
125
- return Number(days);
126
- }
127
- catch (error) {
128
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_DAYS_PER_MONTH_FAILED", "Failed to get days per month", error);
129
- return null;
130
- }
131
- }
132
- /**
133
- * Get the relay URL
134
- * @returns The relay URL or null if the call fails
135
- */
136
- async getRelayUrl() {
137
- try {
138
- if (!this.contract) {
139
- throw new Error("SimpleRelay contract not initialized");
140
- }
141
- return await this.contract.relayUrl();
142
- }
143
- catch (error) {
144
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_URL_FAILED", "Failed to get relay URL", error);
145
- return null;
146
- }
147
- }
148
- /**
149
- * Get complete relay operational configuration
150
- * @returns The relay configuration or null if the call fails
151
- */
152
- async getRelayOperationalConfig() {
153
- try {
154
- if (!this.contract) {
155
- throw new Error("SimpleRelay contract not initialized");
156
- }
157
- const [url, price, daysInMonth] = await this.contract.getRelayOperationalConfig();
158
- return {
159
- url,
160
- price,
161
- daysInMonth,
162
- };
163
- }
164
- catch (error) {
165
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_CONFIG_FAILED", "Failed to get relay operational config", error);
166
- return null;
167
- }
168
- }
169
- /**
170
- * Subscribe to the relay
171
- * @param months - Number of months to subscribe for
172
- * @param pubKey - The public key to register (hex string or Uint8Array)
173
- * @returns The transaction response or null if the call fails
174
- */
175
- async subscribe(months, pubKey) {
176
- try {
177
- if (!this.contract) {
178
- throw new Error("SimpleRelay contract not initialized");
179
- }
180
- if (!this.signer) {
181
- throw new Error("Signer required for this operation");
182
- }
183
- // Convert Uint8Array to hex string if needed
184
- const pubKeyHex = pubKey instanceof Uint8Array ? ethers_1.ethers.hexlify(pubKey) : pubKey;
185
- // Get price
186
- const pricePerMonth = await this.contract.pricePerMonth();
187
- const totalAmount = pricePerMonth * BigInt(months);
188
- // Send transaction
189
- return await this.contract.subscribe(months, pubKeyHex, {
190
- value: totalAmount,
191
- });
192
- }
193
- catch (error) {
194
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_SUBSCRIBE_FAILED", `Failed to subscribe for ${months} months`, error);
195
- return null;
196
- }
197
- }
198
- /**
199
- * Set new price per month (owner only)
200
- * @param newPrice - The new price in wei
201
- * @returns The transaction response or null if the call fails
202
- */
203
- async setPrice(newPrice) {
204
- try {
205
- if (!this.contract) {
206
- throw new Error("SimpleRelay contract not initialized");
207
- }
208
- if (!this.signer) {
209
- throw new Error("Signer required for this operation");
210
- }
211
- return await this.contract.setPrice(newPrice);
212
- }
213
- catch (error) {
214
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_SET_PRICE_FAILED", "Failed to set new price", error);
215
- return null;
216
- }
217
- }
218
- /**
219
- * Set new days per month for subscription calculations (owner only)
220
- * @param days - The new number of days (1-31)
221
- * @returns The transaction response or null if the call fails
222
- */
223
- async setDaysPerMonth(days) {
224
- try {
225
- if (!this.contract) {
226
- throw new Error("SimpleRelay contract not initialized");
227
- }
228
- if (!this.signer) {
229
- throw new Error("Signer required for this operation");
230
- }
231
- if (days < 1 || days > 31) {
232
- throw new Error("Days must be between 1 and 31");
233
- }
234
- return await this.contract.setDaysPerMonth(days);
235
- }
236
- catch (error) {
237
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_SET_DAYS_PER_MONTH_FAILED", `Failed to set days per month to ${days}`, error);
238
- return null;
239
- }
240
- }
241
- /**
242
- * Update the relay URL (owner only)
243
- * @param newUrl - The new URL
244
- * @returns The transaction response or null if the call fails
245
- */
246
- async updateRelayUrl(newUrl) {
247
- try {
248
- if (!this.contract) {
249
- throw new Error("SimpleRelay contract not initialized");
250
- }
251
- if (!this.signer) {
252
- throw new Error("Signer required for this operation");
253
- }
254
- return await this.contract.updateRelayUrl(newUrl);
255
- }
256
- catch (error) {
257
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_UPDATE_URL_FAILED", `Failed to update URL to ${newUrl}`, error);
258
- return null;
259
- }
260
- }
261
- /**
262
- * Withdraw accumulated funds (owner only)
263
- * @returns The transaction response or null if the call fails
264
- */
265
- async withdrawFunds() {
266
- try {
267
- if (!this.contract) {
268
- throw new Error("SimpleRelay contract not initialized");
269
- }
270
- if (!this.signer) {
271
- throw new Error("Signer required for this operation");
272
- }
273
- return await this.contract.withdrawFunds();
274
- }
275
- catch (error) {
276
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_WITHDRAW_FUNDS_FAILED", "Failed to withdraw funds", error);
277
- return null;
278
- }
279
- }
280
- /**
281
- * Decommission the relay and withdraw all funds (owner only)
282
- * @returns The transaction response or null if the call fails
283
- */
284
- async decommissionAndWithdrawAllFunds() {
285
- try {
286
- if (!this.contract) {
287
- throw new Error("SimpleRelay contract not initialized");
288
- }
289
- if (!this.signer) {
290
- throw new Error("Signer required for this operation");
291
- }
292
- return await this.contract.decommissionAndWithdrawAllFunds();
293
- }
294
- catch (error) {
295
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_DECOMMISSION_FAILED", "Failed to decommission relay", error);
296
- return null;
297
- }
298
- }
299
- /**
300
- * Execute a generic transaction (owner only)
301
- * @param to - The destination address
302
- * @param value - The amount of ETH to send
303
- * @param data - The calldata to send
304
- * @returns The transaction response and result or null if the call fails
305
- */
306
- async execute(to, value, data) {
307
- try {
308
- if (!this.contract) {
309
- throw new Error("SimpleRelay contract not initialized");
310
- }
311
- if (!this.signer) {
312
- throw new Error("Signer required for this operation");
313
- }
314
- const [success, result] = await this.contract.execute(to, value, data);
315
- return { success, result: ethers_1.ethers.hexlify(result) };
316
- }
317
- catch (error) {
318
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_EXECUTE_FAILED", `Failed to execute transaction to ${to}`, error);
319
- return null;
320
- }
321
- }
322
- // --- Protocol Integration Functions ---
323
- /**
324
- * Get the current operating mode of the relay
325
- * @returns The operating mode (SINGLE or PROTOCOL) or null if the call fails
326
- */
327
- async getOperatingMode() {
328
- try {
329
- if (!this.contract) {
330
- throw new Error("SimpleRelay contract not initialized");
331
- }
332
- const mode = await this.contract.mode();
333
- return mode;
334
- }
335
- catch (error) {
336
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_MODE_FAILED", "Failed to get relay operating mode", error);
337
- return null;
338
- }
339
- }
340
- /**
341
- * Get the registry address set in the relay
342
- * @returns The registry address or null if the call fails
343
- */
344
- async getRegistryAddress() {
345
- try {
346
- if (!this.contract) {
347
- throw new Error("SimpleRelay contract not initialized");
348
- }
349
- return await this.contract.registryAddress();
350
- }
351
- catch (error) {
352
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_REGISTRY_ADDRESS_FAILED", "Failed to get registry address", error);
353
- return null;
354
- }
355
- }
356
- /**
357
- * Get the entry point address set in the relay
358
- * @returns The entry point address or null if the call fails
359
- */
360
- async getEntryPointAddress() {
361
- try {
362
- if (!this.contract) {
363
- throw new Error("SimpleRelay contract not initialized");
364
- }
365
- return await this.contract.entryPointAddress();
366
- }
367
- catch (error) {
368
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_ENTRY_POINT_ADDRESS_FAILED", "Failed to get entry point address", error);
369
- return null;
370
- }
371
- }
372
- /**
373
- * Check if the relay is registered in the registry
374
- * @returns True if the relay is registered, false otherwise
375
- */
376
- async isRegisteredInRegistry() {
377
- try {
378
- if (!this.contract) {
379
- throw new Error("SimpleRelay contract not initialized");
380
- }
381
- return await this.contract.isRegisteredInRegistry();
382
- }
383
- catch (error) {
384
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_IS_REGISTERED_FAILED", "Failed to check if relay is registered in registry", error);
385
- return false;
386
- }
387
- }
388
- /**
389
- * Get complete relay mode information
390
- * @returns The relay mode information or null if the call fails
391
- */
392
- async getRelayMode() {
393
- try {
394
- if (!this.contract) {
395
- throw new Error("SimpleRelay contract not initialized");
396
- }
397
- const [mode, registry, entryPoint, isRegistered] = await this.contract.getRelayMode();
398
- return {
399
- mode: mode,
400
- registryAddress: registry,
401
- entryPointAddress: entryPoint,
402
- isRegistered,
403
- };
404
- }
405
- catch (error) {
406
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_GET_MODE_INFO_FAILED", "Failed to get relay mode information", error);
407
- return null;
408
- }
409
- }
410
- /**
411
- * Set the registry address for the relay
412
- * @param registryAddress - The registry contract address
413
- * @param autoRegister - Whether to automatically register the relay in the registry
414
- * @param metadata - Metadata for registry registration (only used if autoRegister is true)
415
- * @returns The transaction response or null if the call fails
416
- */
417
- async setRegistry(registryAddress, autoRegister = false, metadata = "") {
418
- try {
419
- if (!this.contract) {
420
- throw new Error("SimpleRelay contract not initialized");
421
- }
422
- if (!this.signer) {
423
- throw new Error("Signer required for this operation");
424
- }
425
- return await this.contract.setRegistry(registryAddress, autoRegister, metadata);
426
- }
427
- catch (error) {
428
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_SET_REGISTRY_FAILED", `Failed to set registry to ${registryAddress}`, error);
429
- return null;
430
- }
431
- }
432
- /**
433
- * Set the entry point address for the relay
434
- * @param entryPointAddress - The entry point contract address
435
- * @param enableProtocolMode - Whether to enable PROTOCOL mode automatically
436
- * @returns The transaction response or null if the call fails
437
- */
438
- async setEntryPoint(entryPointAddress, enableProtocolMode = false) {
439
- try {
440
- if (!this.contract) {
441
- throw new Error("SimpleRelay contract not initialized");
442
- }
443
- if (!this.signer) {
444
- throw new Error("Signer required for this operation");
445
- }
446
- return await this.contract.setEntryPoint(entryPointAddress, enableProtocolMode);
447
- }
448
- catch (error) {
449
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_SET_ENTRY_POINT_FAILED", `Failed to set entry point to ${entryPointAddress}`, error);
450
- return null;
451
- }
452
- }
453
- /**
454
- * Set the operating mode for the relay
455
- * @param mode - The new operating mode (SINGLE or PROTOCOL)
456
- * @returns The transaction response or null if the call fails
457
- */
458
- async setOperatingMode(mode) {
459
- try {
460
- if (!this.contract) {
461
- throw new Error("SimpleRelay contract not initialized");
462
- }
463
- if (!this.signer) {
464
- throw new Error("Signer required for this operation");
465
- }
466
- return await this.contract.setOperatingMode(mode);
467
- }
468
- catch (error) {
469
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_SET_MODE_FAILED", `Failed to set operating mode to ${mode}`, error);
470
- return null;
471
- }
472
- }
473
- /**
474
- * Register the relay in the registry
475
- * @param metadata - Metadata for registry registration
476
- * @returns The transaction response or null if the call fails
477
- */
478
- async registerInRegistry(metadata = "") {
479
- try {
480
- if (!this.contract) {
481
- throw new Error("SimpleRelay contract not initialized");
482
- }
483
- if (!this.signer) {
484
- throw new Error("Signer required for this operation");
485
- }
486
- return await this.contract.registerInRegistry(metadata);
487
- }
488
- catch (error) {
489
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "RELAY_REGISTER_IN_REGISTRY_FAILED", "Failed to register relay in registry", error);
490
- return null;
491
- }
492
- }
493
- }
494
- exports.SimpleRelay = SimpleRelay;