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,152 +0,0 @@
1
- "use strict";
2
- /**
3
- * Shogun Protocol Contracts SDK
4
- * This file provides interfaces and ABIs for interacting with the Shogun Protocol smart contracts
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BaseContract = exports.ENTRY_POINT_ABI = exports.SIMPLE_RELAY_ABI = exports.REGISTRY_ABI = exports.RelayOperatingMode = void 0;
8
- const ethers_1 = require("ethers");
9
- const errorHandler_1 = require("../utils/errorHandler");
10
- const logger_1 = require("../utils/logger");
11
- // ABI for the Registry contract
12
- const REGISTRY_ABI = [
13
- // Read functions
14
- "function isRegisteredRelay(address _relayAddress) external view returns (bool)",
15
- "function isRelayActive(address _relayAddress) external view returns (bool)",
16
- "function findRelayByUrl(string calldata _url) external view returns (address)",
17
- "function getRelayInfo(address _relayAddress) external view returns (address owner, string memory url, string memory metadata, uint256 registrationTime, bool active)",
18
- "function getRelayCountByOwner(address _owner) external view returns (uint256)",
19
- "function getRelaysByOwner(address _owner, uint256 _offset, uint256 _limit) external view returns (tuple(address[] relays, uint256 total, uint256 offset, uint256 limit))",
20
- "function getAllRelays(bool _onlyActive, uint256 _offset, uint256 _limit) external view returns (tuple(address[] relays, uint256 total, uint256 offset, uint256 limit))",
21
- // Write functions
22
- "function registerRelay(address _relayAddress, string calldata _url, string calldata _metadata) external",
23
- "function updateRelay(address _relayAddress, string calldata _newUrl, string calldata _newMetadata) external",
24
- "function deactivateRelay(address _relayAddress) external",
25
- "function reactivateRelay(address _relayAddress) external",
26
- "function setRegistrationOpen(bool _isOpen) external",
27
- ];
28
- exports.REGISTRY_ABI = REGISTRY_ABI;
29
- // ABI for the SimpleRelay contract
30
- const SIMPLE_RELAY_ABI = [
31
- // Read functions
32
- "function isSubscriptionActive(address _user) external view returns (bool)",
33
- "function getUserSubscriptionInfo(address _user) external view returns (uint256 expires, bytes memory pubKey)",
34
- "function isAuthorizedByPubKey(bytes calldata _pubKey) external view returns (bool)",
35
- "function isSubscribed(bytes calldata _pubKey) external view returns (bool)",
36
- "function pricePerMonth() external view returns (uint256)",
37
- "function daysPerMonth() external view returns (uint256)",
38
- "function relayUrl() external view returns (string)",
39
- "function getRelayOperationalConfig() external view returns (string memory _url, uint256 _price, uint256 _daysInMonth)",
40
- // Protocol Integration functions
41
- "function mode() external view returns (uint8)",
42
- "function registryAddress() external view returns (address)",
43
- "function entryPointAddress() external view returns (address)",
44
- "function isRegisteredInRegistry() external view returns (bool)",
45
- "function getRelayMode() external view returns (uint8 _mode, address _registry, address _entryPoint, bool _isRegistered)",
46
- // Protocol Integration write functions
47
- "function setRegistry(address _registryAddress, bool _autoRegister, string calldata _metadata) external",
48
- "function setEntryPoint(address _entryPointAddress, bool _enableProtocolMode) external",
49
- "function setOperatingMode(uint8 _newMode) external",
50
- "function registerInRegistry(string calldata _metadata) external",
51
- // Write functions
52
- "function subscribe(uint256 _months, bytes calldata _pubKey) external payable",
53
- "function setPrice(uint256 _newPrice) external",
54
- "function setDaysPerMonth(uint256 _days) external",
55
- "function updateRelayUrl(string calldata _newUrl) external",
56
- "function withdrawFunds() external",
57
- "function decommissionAndWithdrawAllFunds() external",
58
- "function execute(address _to, uint256 _value, bytes calldata _data) external returns (bool success, bytes memory result)",
59
- ];
60
- exports.SIMPLE_RELAY_ABI = SIMPLE_RELAY_ABI;
61
- // ABI for the EntryPoint contract
62
- const ENTRY_POINT_ABI = [
63
- // Read functions
64
- "function registry() external view returns (address)",
65
- "function serviceFeePercentage() external view returns (uint256)",
66
- "function calculateFee(uint256 _amount) external view returns (uint256)",
67
- "function checkSubscription(address _user, address _relayAddress) external view returns (bool)",
68
- "function hasRegisteredPubKey(address _user, address _relayAddress) external view returns (bool)",
69
- "function isPubKeySubscribed(address _relayAddress, bytes calldata _pubKey) external view returns (bool)",
70
- "function batchCheckPubKeySubscription(address[] calldata _relayAddresses, bytes[] calldata _pubKeys) external view returns (bool[] memory)",
71
- "function getSubscriptionDetails(address _user, address _relayAddress) external view returns (uint256 expires, bytes memory pubKey)",
72
- "function batchCheckSubscriptions(address _user, address[] calldata _relayAddresses) external view returns (bool[] memory)",
73
- "function batchCheckPubKeys(address _user, address[] calldata _relayAddresses) external view returns (bool[] memory)",
74
- "function getStatistics() external view returns (uint256 _userCount, uint256 _totalSubscriptions, uint256 _totalViaUrl, uint256 _totalViaDirect, uint256 _totalAmountProcessed, uint256 _totalFeesCollected, uint256 _currentBalance)",
75
- // Write functions
76
- "function subscribeViaUrl(string calldata _relayUrl, uint256 _months, bytes calldata _pubKey) external payable",
77
- "function subscribeDirect(address _relayAddress, uint256 _months, bytes calldata _pubKey) external payable",
78
- "function batchSubscribe(address[] calldata _relayAddresses, uint256 _months, bytes[] calldata _pubKeys) external payable",
79
- "function updateRegistry(address _newRegistry) external",
80
- "function updateServiceFee(uint256 _newFeePercentage) external",
81
- "function withdrawFees() external",
82
- ];
83
- exports.ENTRY_POINT_ABI = ENTRY_POINT_ABI;
84
- // Enum for Relay operating mode
85
- var RelayOperatingMode;
86
- (function (RelayOperatingMode) {
87
- RelayOperatingMode[RelayOperatingMode["SINGLE"] = 0] = "SINGLE";
88
- RelayOperatingMode[RelayOperatingMode["PROTOCOL"] = 1] = "PROTOCOL";
89
- })(RelayOperatingMode || (exports.RelayOperatingMode = RelayOperatingMode = {}));
90
- // Base class for contract interactions
91
- class BaseContract {
92
- provider = null;
93
- signer = null;
94
- contract = null;
95
- contractAddress;
96
- constructor(address, abi, config) {
97
- this.contractAddress = address;
98
- // Setup provider
99
- if (config.provider) {
100
- this.provider = config.provider;
101
- }
102
- else if (config.providerUrl) {
103
- this.provider = new ethers_1.ethers.JsonRpcProvider(config.providerUrl);
104
- }
105
- // Setup signer
106
- this.signer = config.signer || null;
107
- // Initialize contract
108
- if (!this.provider) {
109
- (0, logger_1.logError)("No provider available for contract initialization");
110
- return;
111
- }
112
- try {
113
- if (this.signer) {
114
- this.contract = new ethers_1.ethers.Contract(address, abi, this.signer);
115
- }
116
- else {
117
- this.contract = new ethers_1.ethers.Contract(address, abi, this.provider);
118
- }
119
- }
120
- catch (error) {
121
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "CONTRACT_INIT_FAILED", `Failed to initialize contract at ${address}`, error);
122
- }
123
- }
124
- /**
125
- * Set a new provider
126
- * @param provider - The new provider
127
- */
128
- setProvider(provider) {
129
- this.provider = provider;
130
- if (this.contract) {
131
- this.contract = this.contract.connect(provider);
132
- }
133
- }
134
- /**
135
- * Set a new signer
136
- * @param signer - The new signer
137
- */
138
- setSigner(signer) {
139
- this.signer = signer;
140
- if (this.contract && this.signer) {
141
- this.contract = this.contract.connect(signer);
142
- }
143
- }
144
- /**
145
- * Get the contract address
146
- * @returns The contract address
147
- */
148
- getAddress() {
149
- return this.contractAddress;
150
- }
151
- }
152
- exports.BaseContract = BaseContract;
@@ -1,407 +0,0 @@
1
- "use strict";
2
- /**
3
- * EntryPoint Class - Provides interaction with the Shogun Protocol EntryPoint contract
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EntryPoint = void 0;
7
- const ethers_1 = require("ethers");
8
- const errorHandler_1 = require("../utils/errorHandler");
9
- const base_1 = require("./base");
10
- /**
11
- * EntryPoint - A class to interact with the Shogun Protocol EntryPoint contract
12
- */
13
- class EntryPoint extends base_1.BaseContract {
14
- /**
15
- * Create a new EntryPoint instance
16
- * @param config - Configuration for the EntryPoint
17
- */
18
- constructor(config) {
19
- super(config.entryPointAddress, base_1.ENTRY_POINT_ABI, config);
20
- }
21
- /**
22
- * Get the registry address
23
- * @returns The registry address or null if the call fails
24
- */
25
- async getRegistryAddress() {
26
- try {
27
- if (!this.contract) {
28
- throw new Error("EntryPoint contract not initialized");
29
- }
30
- return await this.contract.registry();
31
- }
32
- catch (error) {
33
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_GET_REGISTRY_FAILED", "Failed to get registry address", error);
34
- return null;
35
- }
36
- }
37
- /**
38
- * Get the service fee percentage
39
- * @returns The fee percentage or null if the call fails
40
- */
41
- async getServiceFeePercentage() {
42
- try {
43
- if (!this.contract) {
44
- throw new Error("EntryPoint contract not initialized");
45
- }
46
- const feePercentage = await this.contract.serviceFeePercentage();
47
- return Number(feePercentage);
48
- }
49
- catch (error) {
50
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_GET_FEE_PERCENTAGE_FAILED", "Failed to get service fee percentage", error);
51
- return null;
52
- }
53
- }
54
- /**
55
- * Calculate fee amount
56
- * @param amount - The amount to calculate fee on
57
- * @returns The fee amount or null if the call fails
58
- */
59
- async calculateFee(amount) {
60
- try {
61
- if (!this.contract) {
62
- throw new Error("EntryPoint contract not initialized");
63
- }
64
- return await this.contract.calculateFee(amount);
65
- }
66
- catch (error) {
67
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_CALCULATE_FEE_FAILED", "Failed to calculate fee", error);
68
- return null;
69
- }
70
- }
71
- /**
72
- * Check if a user has an active subscription on a relay
73
- * @param userAddress - The address of the user
74
- * @param relayAddress - The address of the relay
75
- * @returns True if the user has an active subscription, false otherwise
76
- */
77
- async checkSubscription(userAddress, relayAddress) {
78
- try {
79
- if (!this.contract) {
80
- throw new Error("EntryPoint contract not initialized");
81
- }
82
- return await this.contract.checkSubscription(userAddress, relayAddress);
83
- }
84
- catch (error) {
85
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_CHECK_SUBSCRIPTION_FAILED", `Failed to check subscription for user ${userAddress} on relay ${relayAddress}`, error);
86
- return false;
87
- }
88
- }
89
- /**
90
- * Check if a user has a registered public key on a relay
91
- * @param userAddress - The address of the user
92
- * @param relayAddress - The address of the relay
93
- * @returns True if the user has a registered public key, false otherwise
94
- */
95
- async hasRegisteredPubKey(userAddress, relayAddress) {
96
- try {
97
- if (!this.contract) {
98
- throw new Error("EntryPoint contract not initialized");
99
- }
100
- return await this.contract.hasRegisteredPubKey(userAddress, relayAddress);
101
- }
102
- catch (error) {
103
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_HAS_REGISTERED_PUBKEY_FAILED", `Failed to check if user ${userAddress} has registered pubkey on relay ${relayAddress}`, error);
104
- return false;
105
- }
106
- }
107
- /**
108
- * Check if a specific public key is subscribed on a relay
109
- * @param relayAddress - The address of the relay
110
- * @param pubKey - The public key to check (hex string or Uint8Array)
111
- * @returns True if the public key is subscribed, false otherwise
112
- */
113
- async isPubKeySubscribed(relayAddress, pubKey) {
114
- try {
115
- if (!this.contract) {
116
- throw new Error("EntryPoint contract not initialized");
117
- }
118
- // Convert Uint8Array to hex string if needed
119
- const pubKeyHex = pubKey instanceof Uint8Array ? ethers_1.ethers.hexlify(pubKey) : pubKey;
120
- return await this.contract.isPubKeySubscribed(relayAddress, pubKeyHex);
121
- }
122
- catch (error) {
123
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_IS_PUBKEY_SUBSCRIBED_FAILED", `Failed to check if pubkey is subscribed on relay ${relayAddress}`, error);
124
- return false;
125
- }
126
- }
127
- /**
128
- * Check if public keys are subscribed on multiple relays
129
- * @param relayAddresses - Array of relay addresses
130
- * @param pubKeys - Array of public keys (hex strings or Uint8Arrays)
131
- * @returns Array of booleans indicating subscription status for each relay/pubkey pair
132
- */
133
- async batchCheckPubKeySubscription(relayAddresses, pubKeys) {
134
- try {
135
- if (!this.contract) {
136
- throw new Error("EntryPoint contract not initialized");
137
- }
138
- if (relayAddresses.length !== pubKeys.length) {
139
- throw new Error("Array lengths must match");
140
- }
141
- // Convert Uint8Arrays to hex strings
142
- const pubKeyHexes = pubKeys.map((pk) => pk instanceof Uint8Array ? ethers_1.ethers.hexlify(pk) : pk);
143
- return await this.contract.batchCheckPubKeySubscription(relayAddresses, pubKeyHexes);
144
- }
145
- catch (error) {
146
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_BATCH_CHECK_PUBKEYS_FAILED", "Failed to batch check public key subscriptions", error);
147
- return Array(relayAddresses.length).fill(false);
148
- }
149
- }
150
- /**
151
- * Get detailed subscription information
152
- * @param userAddress - The address of the user
153
- * @param relayAddress - The address of the relay
154
- * @returns The subscription details or null if not found
155
- */
156
- async getSubscriptionDetails(userAddress, relayAddress) {
157
- try {
158
- if (!this.contract) {
159
- throw new Error("EntryPoint contract not initialized");
160
- }
161
- const [expires, pubKey] = await this.contract.getSubscriptionDetails(userAddress, relayAddress);
162
- return {
163
- expires,
164
- pubKey: ethers_1.ethers.hexlify(pubKey),
165
- };
166
- }
167
- catch (error) {
168
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_GET_SUBSCRIPTION_DETAILS_FAILED", `Failed to get subscription details for user ${userAddress} on relay ${relayAddress}`, error);
169
- return null;
170
- }
171
- }
172
- /**
173
- * Check if a user has active subscriptions on multiple relays
174
- * @param userAddress - The address of the user
175
- * @param relayAddresses - Array of relay addresses
176
- * @returns Array of booleans indicating subscription status for each relay
177
- */
178
- async batchCheckSubscriptions(userAddress, relayAddresses) {
179
- try {
180
- if (!this.contract) {
181
- throw new Error("EntryPoint contract not initialized");
182
- }
183
- return await this.contract.batchCheckSubscriptions(userAddress, relayAddresses);
184
- }
185
- catch (error) {
186
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_BATCH_CHECK_SUBSCRIPTIONS_FAILED", `Failed to batch check subscriptions for user ${userAddress}`, error);
187
- return Array(relayAddresses.length).fill(false);
188
- }
189
- }
190
- /**
191
- * Check if a user has registered public keys on multiple relays
192
- * @param userAddress - The address of the user
193
- * @param relayAddresses - Array of relay addresses
194
- * @returns Array of booleans indicating if public keys are registered for each relay
195
- */
196
- async batchCheckPubKeys(userAddress, relayAddresses) {
197
- try {
198
- if (!this.contract) {
199
- throw new Error("EntryPoint contract not initialized");
200
- }
201
- return await this.contract.batchCheckPubKeys(userAddress, relayAddresses);
202
- }
203
- catch (error) {
204
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_BATCH_CHECK_PUBKEYS_FAILED", `Failed to batch check pubkeys for user ${userAddress}`, error);
205
- return Array(relayAddresses.length).fill(false);
206
- }
207
- }
208
- /**
209
- * Get EntryPoint statistics
210
- * @returns The EntryPoint statistics or null if the call fails
211
- */
212
- async getStatistics() {
213
- try {
214
- if (!this.contract) {
215
- throw new Error("EntryPoint contract not initialized");
216
- }
217
- const [userCount, totalSubscriptions, totalViaUrl, totalViaDirect, totalAmountProcessed, totalFeesCollected, currentBalance,] = await this.contract.getStatistics();
218
- return {
219
- userCount,
220
- totalSubscriptions,
221
- totalViaUrl,
222
- totalViaDirect,
223
- totalAmountProcessed,
224
- totalFeesCollected,
225
- currentBalance,
226
- };
227
- }
228
- catch (error) {
229
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_GET_STATISTICS_FAILED", "Failed to get EntryPoint statistics", error);
230
- return null;
231
- }
232
- }
233
- /**
234
- * Subscribe to a relay via URL
235
- * @param relayUrl - The URL of the relay
236
- * @param months - Number of months to subscribe for
237
- * @param pubKey - The public key to register (hex string or Uint8Array)
238
- * @param value - The payment amount (will be calculated if not provided)
239
- * @returns The transaction response or null if the call fails
240
- */
241
- async subscribeViaUrl(relayUrl, months, pubKey, value) {
242
- try {
243
- if (!this.contract) {
244
- throw new Error("EntryPoint contract not initialized");
245
- }
246
- if (!this.signer) {
247
- throw new Error("Signer required for this operation");
248
- }
249
- // Convert Uint8Array to hex string if needed
250
- const pubKeyHex = pubKey instanceof Uint8Array ? ethers_1.ethers.hexlify(pubKey) : pubKey;
251
- // If value is not provided, we need to query the correct amount
252
- // This is a simplified estimation and may not be accurate
253
- // In production, you would need to get the price from the relay and add the service fee
254
- const txOptions = {
255
- value: value || ethers_1.ethers.parseEther("0.01"), // Default value as a placeholder
256
- };
257
- return await this.contract.subscribeViaUrl(relayUrl, months, pubKeyHex, txOptions);
258
- }
259
- catch (error) {
260
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_SUBSCRIBE_VIA_URL_FAILED", `Failed to subscribe via URL ${relayUrl} for ${months} months`, error);
261
- return null;
262
- }
263
- }
264
- /**
265
- * Subscribe directly to a relay
266
- * @param relayAddress - The address of the relay
267
- * @param months - Number of months to subscribe for
268
- * @param pubKey - The public key to register (hex string or Uint8Array)
269
- * @param value - The payment amount (will be calculated if not provided)
270
- * @returns The transaction response or null if the call fails
271
- */
272
- async subscribeDirect(relayAddress, months, pubKey, value) {
273
- try {
274
- if (!this.contract) {
275
- throw new Error("EntryPoint contract not initialized");
276
- }
277
- if (!this.signer) {
278
- throw new Error("Signer required for this operation");
279
- }
280
- // Convert Uint8Array to hex string if needed
281
- const pubKeyHex = pubKey instanceof Uint8Array ? ethers_1.ethers.hexlify(pubKey) : pubKey;
282
- // If value is not provided, we need to query the correct amount
283
- // This is a simplified estimation and may not be accurate
284
- // In production, you would need to get the price from the relay and add the service fee
285
- const txOptions = {
286
- value: value || ethers_1.ethers.parseEther("0.01"), // Default value as a placeholder
287
- };
288
- return await this.contract.subscribeDirect(relayAddress, months, pubKeyHex, txOptions);
289
- }
290
- catch (error) {
291
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_SUBSCRIBE_DIRECT_FAILED", `Failed to subscribe directly to relay ${relayAddress} for ${months} months`, error);
292
- return null;
293
- }
294
- }
295
- /**
296
- * Subscribe to multiple relays in a single transaction
297
- * @param relayAddresses - Array of relay addresses
298
- * @param months - Number of months to subscribe for
299
- * @param pubKeys - Array of public keys (hex strings or Uint8Arrays)
300
- * @param value - The payment amount (will be calculated if not provided)
301
- * @returns The transaction response or null if the call fails
302
- */
303
- async batchSubscribe(relayAddresses, months, pubKeys, value) {
304
- try {
305
- if (!this.contract) {
306
- throw new Error("EntryPoint contract not initialized");
307
- }
308
- if (!this.signer) {
309
- throw new Error("Signer required for this operation");
310
- }
311
- if (relayAddresses.length !== pubKeys.length) {
312
- throw new Error("Array lengths must match");
313
- }
314
- // Convert Uint8Arrays to hex strings
315
- const pubKeyHexes = pubKeys.map((pk) => pk instanceof Uint8Array ? ethers_1.ethers.hexlify(pk) : pk);
316
- // If value is not provided, we need to query the correct amount
317
- // This is a simplified estimation and may not be accurate
318
- // In production, you would need to calculate based on all relay prices and service fees
319
- const txOptions = {
320
- value: value || ethers_1.ethers.parseEther("0.01") * BigInt(relayAddresses.length),
321
- };
322
- return await this.contract.batchSubscribe(relayAddresses, months, pubKeyHexes, txOptions);
323
- }
324
- catch (error) {
325
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_BATCH_SUBSCRIBE_FAILED", `Failed to batch subscribe to ${relayAddresses.length} relays for ${months} months`, error);
326
- return null;
327
- }
328
- }
329
- /**
330
- * Update the registry address (owner only)
331
- * @param newRegistryAddress - The new registry address
332
- * @returns The transaction response or null if the call fails
333
- */
334
- async updateRegistry(newRegistryAddress) {
335
- try {
336
- if (!this.contract) {
337
- throw new Error("EntryPoint contract not initialized");
338
- }
339
- if (!this.signer) {
340
- throw new Error("Signer required for this operation");
341
- }
342
- return await this.contract.updateRegistry(newRegistryAddress);
343
- }
344
- catch (error) {
345
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_UPDATE_REGISTRY_FAILED", `Failed to update registry to ${newRegistryAddress}`, error);
346
- return null;
347
- }
348
- }
349
- /**
350
- * Update the service fee percentage (owner only)
351
- * @param newFeePercentage - The new fee percentage
352
- * @returns The transaction response or null if the call fails
353
- */
354
- async updateServiceFee(newFeePercentage) {
355
- try {
356
- if (!this.contract) {
357
- throw new Error("EntryPoint contract not initialized");
358
- }
359
- if (!this.signer) {
360
- throw new Error("Signer required for this operation");
361
- }
362
- return await this.contract.updateServiceFee(newFeePercentage);
363
- }
364
- catch (error) {
365
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_UPDATE_SERVICE_FEE_FAILED", `Failed to update service fee to ${newFeePercentage}`, error);
366
- return null;
367
- }
368
- }
369
- /**
370
- * Withdraw accumulated fees (owner only)
371
- * @returns The transaction response or null if the call fails
372
- */
373
- async withdrawFees() {
374
- try {
375
- if (!this.contract) {
376
- throw new Error("EntryPoint contract not initialized");
377
- }
378
- if (!this.signer) {
379
- throw new Error("Signer required for this operation");
380
- }
381
- return await this.contract.withdrawFees();
382
- }
383
- catch (error) {
384
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_WITHDRAW_FEES_FAILED", "Failed to withdraw fees", error);
385
- return null;
386
- }
387
- }
388
- /**
389
- * Check if a relay is in protocol mode
390
- * @param relayAddress - The address of the relay
391
- * @returns True if the relay is in protocol mode, false otherwise
392
- */
393
- async isRelayInProtocolMode(relayAddress) {
394
- try {
395
- if (!this.contract) {
396
- throw new Error("EntryPoint contract not initialized");
397
- }
398
- const mode = await this.contract.isRelayInProtocolMode(relayAddress);
399
- return mode === 1; // 1 is PROTOCOL
400
- }
401
- catch (error) {
402
- errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.CONTRACT, "ENTRY_POINT_IS_RELAY_IN_PROTOCOL_MODE_FAILED", `Failed to check if relay ${relayAddress} is in protocol mode`, error);
403
- return false;
404
- }
405
- }
406
- }
407
- exports.EntryPoint = EntryPoint;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- /**
3
- * Relay module - Provides interaction with the Shogun Protocol Relay system
4
- */
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.RelayVerifier = exports.RelayEventType = exports.getUsageDataForChart = exports.subscribeToRelayEvents = exports.getNetworkSummary = exports.getRelayPerformance = exports.getSubscriptionHistory = exports.getRegisteredPubKeys = exports.getRelayUrls = exports.SimpleRelay = exports.Registry = exports.EntryPoint = void 0;
21
- // Export all relay SDK components
22
- // Contract interfaces and ABIs
23
- __exportStar(require("./base"), exports);
24
- // Registry functionality
25
- __exportStar(require("./registry"), exports);
26
- // SimpleRelay functionality
27
- __exportStar(require("./relay"), exports);
28
- // EntryPoint functionality
29
- __exportStar(require("./entryPoint"), exports);
30
- var entryPoint_1 = require("./entryPoint");
31
- Object.defineProperty(exports, "EntryPoint", { enumerable: true, get: function () { return entryPoint_1.EntryPoint; } });
32
- var registry_1 = require("./registry");
33
- Object.defineProperty(exports, "Registry", { enumerable: true, get: function () { return registry_1.Registry; } });
34
- var relay_1 = require("./relay");
35
- Object.defineProperty(exports, "SimpleRelay", { enumerable: true, get: function () { return relay_1.SimpleRelay; } });
36
- var utils_1 = require("./utils");
37
- Object.defineProperty(exports, "getRelayUrls", { enumerable: true, get: function () { return utils_1.getRelayUrls; } });
38
- Object.defineProperty(exports, "getRegisteredPubKeys", { enumerable: true, get: function () { return utils_1.getRegisteredPubKeys; } });
39
- Object.defineProperty(exports, "getSubscriptionHistory", { enumerable: true, get: function () { return utils_1.getSubscriptionHistory; } });
40
- Object.defineProperty(exports, "getRelayPerformance", { enumerable: true, get: function () { return utils_1.getRelayPerformance; } });
41
- Object.defineProperty(exports, "getNetworkSummary", { enumerable: true, get: function () { return utils_1.getNetworkSummary; } });
42
- Object.defineProperty(exports, "subscribeToRelayEvents", { enumerable: true, get: function () { return utils_1.subscribeToRelayEvents; } });
43
- Object.defineProperty(exports, "getUsageDataForChart", { enumerable: true, get: function () { return utils_1.getUsageDataForChart; } });
44
- Object.defineProperty(exports, "RelayEventType", { enumerable: true, get: function () { return utils_1.RelayEventType; } });
45
- // Export contract relationships to handle the protocol integration
46
- var utils_2 = require("./utils");
47
- Object.defineProperty(exports, "RelayVerifier", { enumerable: true, get: function () { return utils_2.RelayVerifier; } });