@neuraiproject/neurai-rpc 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5,6 +5,8 @@ function $parcel$export(e, n, v, s) {
5
5
 
6
6
  $parcel$export(module.exports, "getRPC", () => $80bd448eb6ea085b$export$eb94c228b080d168);
7
7
  $parcel$export(module.exports, "methods", () => $ca417a034047e18f$export$e13b82b2b0368a6a);
8
+ $parcel$export(module.exports, "getDePinRPC", () => $9df46f7047db01a3$export$e3c4528d9eee3c6);
9
+ $parcel$export(module.exports, "requestDePinChallenge", () => $9df46f7047db01a3$export$9d7d174baf084291);
8
10
  const $ca417a034047e18f$export$e13b82b2b0368a6a = {
9
11
  /** abandontransaction "txid"
10
12
 
@@ -169,6 +171,26 @@ Examples:
169
171
  > neurai-cli checkaddresstag "address" "tag_name"
170
172
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "checkaddresstag", "params": ["address" "tag_name"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
171
173
  **/ checkaddresstag: 'checkaddresstag',
174
+ /** checkdepinvalidity "asset_name" "address"
175
+
176
+ Check if a DEPIN asset is valid/active for a specific address
177
+
178
+ Arguments:
179
+ 1. "asset_name" (string, required) The DEPIN asset name (must start with &)
180
+ 2. "address" (string, required) The address to check
181
+
182
+ Result:
183
+ {
184
+ "has_asset": true|false, (boolean) Whether the address holds the asset
185
+ "amount": n, (numeric) The amount (if has_asset is true)
186
+ "valid": 1|0, (numeric) 1 = active/valid, 0 = blocked/revoked (if has_asset is true)
187
+ "blocked": true|false (boolean) Whether the asset is blocked (if has_asset is true)
188
+ }
189
+
190
+ Examples:
191
+ > neurai-cli checkdepinvalidity "&FRANCE" "address"
192
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "checkdepinvalidity", "params": ["&FRANCE", "address"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
193
+ **/ checkdepinvalidity: 'checkdepinvalidity',
172
194
  /** checkglobalrestriction restricted_name
173
195
 
174
196
  Checks to see if a restricted asset is globally frozen
@@ -622,6 +644,213 @@ Examples:
622
644
  > neurai-cli decodescript "hexstring"
623
645
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "decodescript", "params": ["hexstring"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
624
646
  **/ decodescript: 'decodescript',
647
+ /** depinclearmsg ( "all" | hours )
648
+
649
+ Remove messages from DePIN messaging pool
650
+
651
+ Arguments:
652
+ 1. mode (string or numeric, optional) Cleanup mode:
653
+ - omitted: Remove only expired messages (default)
654
+ - "all": Remove ALL messages from pool
655
+ - <hours>: Remove messages older than specified hours (numeric)
656
+
657
+ Result:
658
+ {
659
+ "removed": n, (numeric) Number of messages removed
660
+ "remaining": n (numeric) Number of messages remaining
661
+ }
662
+
663
+ Examples:
664
+ > neurai-cli depinclearmsg
665
+ > neurai-cli depinclearmsg "all"
666
+ > neurai-cli depinclearmsg 7
667
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depinclearmsg", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
668
+ **/ depinclearmsg: 'depinclearmsg',
669
+ /** depingetmsg "token" ("ip[:port]"|"fromaddress") ("fromaddress")
670
+
671
+ Retrieve and decrypt DePIN messages for your addresses
672
+
673
+ Arguments:
674
+ 1. "token" (string, required) Token name
675
+ 2. "ip[:port]" OR "fromaddress" (string, optional)
676
+ - IP address with optional port (e.g., "192.168.1.31" or "192.168.1.31:19002")
677
+ - OR Neurai address for local query with specific address
678
+ - Omit for local query with all addresses
679
+ 3. "fromaddress" (string, optional) Specific address to decrypt with (only if arg 2 is an IP)
680
+
681
+ Result:
682
+ [
683
+ {
684
+ "recipient": "address", (string) Recipient address (your address)
685
+ "sender": "address", (string) Sender address
686
+ "message": "text", (string) Decrypted message
687
+ "timestamp": n, (numeric) Unix timestamp
688
+ "date": "YYYY-MM-DD HH:MM:SS", (string) Formatted date
689
+ "expires": "YYYY-MM-DD HH:MM:SS" (string) Expiration date
690
+ },
691
+ ...
692
+ ]
693
+
694
+ Examples:
695
+ > neurai-cli depingetmsg "MYTOKEN"
696
+ > neurai-cli depingetmsg "MYTOKEN" "NXyouraddress..."
697
+ > neurai-cli depingetmsg "MYTOKEN" "192.168.1.78"
698
+ > neurai-cli depingetmsg "MYTOKEN" "192.168.1.78:19002" "NXyouraddress..."
699
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depingetmsg", "params": ["MYTOKEN"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
700
+ **/ depingetmsg: 'depingetmsg',
701
+ /** depingetmsginfo
702
+
703
+ Returns information about the DePIN messaging system
704
+
705
+ Result:
706
+ {
707
+ "enabled": true|false, (boolean) Whether DePIN messaging is enabled
708
+ "token": "name", (string) Active token name
709
+ "port": n, (numeric) Listening port
710
+ "maxrecipients": n, (numeric) Maximum recipients per message
711
+ "maxmessagesize": n, (numeric) Maximum message size in bytes
712
+ "messageexpiryhours": n, (numeric) Message expiry time in hours
713
+ "maxpoolsizemb": n, (numeric) Maximum pool size in MB
714
+ "messages": n, (numeric) Number of messages in mempool
715
+ "memoryusage": n, (numeric) Memory usage in bytes
716
+ "memoryusagemb": n, (numeric) Memory usage in MB
717
+ "oldestmessage": "time", (string) Timestamp of oldest message
718
+ "newestmessage": "time" (string) Timestamp of newest message
719
+ }
720
+
721
+ Examples:
722
+ > neurai-cli depingetmsginfo
723
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depingetmsginfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
724
+ **/ depingetmsginfo: 'depingetmsginfo',
725
+ /** depingetpoolcontent ( verbose sender_address recipient_address start_time end_time limit offset )
726
+
727
+ Inspect the contents of the DePIN message pool.
728
+
729
+ Arguments:
730
+ 1. verbose (boolean, "all", or "raw", optional, default=false) Show detailed message structure. Use "all" for all messages, "raw" to show encrypted hex data
731
+ 2. sender_address (string, optional) Filter by sender address
732
+ 3. recipient_address (string, optional) Filter by recipient address
733
+ 4. start_time (numeric, optional) Filter messages after timestamp
734
+ 5. end_time (numeric, optional) Filter messages before timestamp
735
+ 6. limit (numeric, optional, default=100) Maximum messages to return
736
+ 7. offset (numeric, optional, default=0) Skip first N messages
737
+
738
+ Result (verbose=false):
739
+ [
740
+ {
741
+ "hash": "hex",
742
+ "sender": "address",
743
+ "timestamp": n,
744
+ "date": "YYYY-MM-DD HH:MM:SS",
745
+ "expires": "YYYY-MM-DD HH:MM:SS",
746
+ "encryption_type": "ECIES_shared",
747
+ "size": n
748
+ },
749
+ ...
750
+ ]
751
+
752
+ Examples:
753
+ > neurai-cli depingetpoolcontent
754
+ > neurai-cli depingetpoolcontent true
755
+ > neurai-cli depingetpoolcontent "all"
756
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depingetpoolcontent", "params": [true] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
757
+ **/ depingetpoolcontent: 'depingetpoolcontent',
758
+ /** depinmcpstatus
759
+
760
+ Get status information about the DePIN MCP (AI) worker
761
+
762
+ Result:
763
+ {
764
+ "enabled": true|false, (boolean) Whether MCP worker is enabled
765
+ "running": true|false, (boolean) Whether MCP worker is running
766
+ "mcp_url": "url", (string) MCP server URL
767
+ "model_name": "name", (string) Name of the loaded AI model
768
+ "command_key": "key", (string) Command prefix (e.g. /ai)
769
+ "depin_token": "token", (string) DePIN token being monitored
770
+ "poll_interval": n, (numeric) Polling interval in seconds
771
+ "commands_processed": n, (numeric) Total commands processed
772
+ "total_errors": n, (numeric) Total errors encountered
773
+ "last_poll_time": n (numeric) Unix timestamp of last poll
774
+ }
775
+
776
+ Examples:
777
+ > neurai-cli depinmcpstatus
778
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depinmcpstatus", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
779
+ **/ depinmcpstatus: 'depinmcpstatus',
780
+ /** depinpoolstats
781
+
782
+ Get statistical analysis of the DePIN message pool.
783
+
784
+ Result:
785
+ {
786
+ "enabled": true|false,
787
+ "token": "string",
788
+ "total_messages": n,
789
+ "total_size_bytes": n,
790
+ "memory_usage_bytes": n,
791
+ "oldest_message": "YYYY-MM-DD HH:MM:SS",
792
+ "newest_message": "YYYY-MM-DD HH:MM:SS",
793
+ "messages_by_age": {
794
+ "last_hour": n,
795
+ "last_day": n,
796
+ "last_week": n
797
+ },
798
+ "unique_senders": n,
799
+ "avg_message_size": n,
800
+ "expiring_in_24h": n
801
+ }
802
+
803
+ Examples:
804
+ > neurai-cli depinpoolstats
805
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depinpoolstats", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
806
+ **/ depinpoolstats: 'depinpoolstats',
807
+ /** depinsendmsg "token" "ip[:port]" "message" "fromaddress" (port)
808
+
809
+ Send an encrypted message through a remote DePIN gateway (challenge/response)
810
+
811
+ Arguments:
812
+ 1. "token" (string, required) Token name
813
+ 2. "ip[:port]" (string, required) Target node address (optional :port to contact remote gateway)
814
+ 3. "message" (string, required) Message to send (max 1KB)
815
+ 4. "fromaddress" (string, required) Wallet address used for signing/encryption
816
+ 5. port (numeric, optional) Destination message port (defaults to 19002). Only used when specified after fromaddress
817
+
818
+ Result:
819
+ {
820
+ "result": "success", (string) Status
821
+ "hash": "hash", (string) Message hash
822
+ "recipients": n, (numeric) Number of recipients
823
+ "timestamp": n (numeric) Message timestamp
824
+ }
825
+
826
+ Examples:
827
+ > neurai-cli depinsendmsg "MYTOKEN" "192.168.1.100" "Hello team!" "NXsender..."
828
+ > neurai-cli depinsendmsg "MYTOKEN" "192.168.1.100:19005" "Hello team!" "NXsender..." 19005
829
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depinsendmsg", "params": ["MYTOKEN", "192.168.1.100", "Hello team!", "NXsender..."] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
830
+ **/ depinsendmsg: 'depinsendmsg',
831
+ /** depinsubmitmsg "hexmessage"
832
+
833
+ Submit a pre-encrypted and signed DePIN message to the pool
834
+
835
+ This is the secure protocol where the client prepares the complete message
836
+ (encryption + signature) and the server only validates and stores it.
837
+
838
+ Arguments:
839
+ 1. "hexmessage" (string, required) Hex-encoded serialized CDepinMessage
840
+
841
+ Result:
842
+ {
843
+ "result": "success", (string) Status
844
+ "hash": "hash", (string) Message hash
845
+ "timestamp": n (numeric) Unix timestamp
846
+ }
847
+
848
+ Note: This endpoint is typically called by remote nodes after challenge/response authentication.
849
+
850
+ Examples:
851
+ > neurai-cli depinsubmitmsg "0a3f2e..."
852
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "depinsubmitmsg", "params": ["0a3f2e..."] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
853
+ **/ depinsubmitmsg: 'depinsubmitmsg',
625
854
  /** disconnectnode "[address]" [nodeid]
626
855
 
627
856
  Immediately disconnects from the specified peer node.
@@ -811,6 +1040,26 @@ Examples:
811
1040
  > neurai-cli freezeaddress "$RESTRICTED_ASSET" "address" "change_address"
812
1041
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "freezeaddress", "params": ["$RESTRICTED_ASSET" "address" "change_address"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
813
1042
  **/ freezeaddress: 'freezeaddress',
1043
+ /** freezedepin "asset_name" "address" ("change_address")
1044
+
1045
+ Freeze a DEPIN asset for a specific address (owner only)
1046
+
1047
+ The address will still hold the asset but it will be marked as invalid
1048
+
1049
+ Requires the owner token (&ASSET!) in the wallet
1050
+
1051
+ Arguments:
1052
+ 1. "asset_name" (string, required) The DEPIN asset name (must start with &)
1053
+ 2. "address" (string, required) The address to freeze
1054
+ 3. "change_address" (string, optional) The change address for the owner token
1055
+
1056
+ Result:
1057
+ "txid" (string) The transaction id
1058
+
1059
+ Examples:
1060
+ > neurai-cli freezedepin "&FRANCE" "address"
1061
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "freezedepin", "params": ["&FRANCE", "address"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
1062
+ **/ freezedepin: 'freezedepin',
814
1063
  /** freezerestrictedasset asset_name (change_address) (asset_data)
815
1064
 
816
1065
  Freeze all trading for a specific restricted asset
@@ -2909,6 +3158,29 @@ Examples:
2909
3158
  > neurai-cli listbanned
2910
3159
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listbanned", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
2911
3160
  **/ listbanned: 'listbanned',
3161
+ /** listdepinholders "asset_name"
3162
+
3163
+ Returns all addresses holding a DEPIN asset with validity status
3164
+
3165
+ DEPIN assets are soulbound (non-transferable except by owner) and can be frozen/revoked
3166
+
3167
+ Arguments:
3168
+ 1. "asset_name" (string, required) The DEPIN asset name (must start with &)
3169
+
3170
+ Result:
3171
+ [
3172
+ {
3173
+ "address": "address", (string) The address
3174
+ "amount": n, (numeric) The amount (always 1 for DEPIN)
3175
+ "valid": 1|0 (numeric) 1 = active/valid, 0 = blocked/revoked
3176
+ },
3177
+ ...
3178
+ ]
3179
+
3180
+ Examples:
3181
+ > neurai-cli listdepinholders "&FRANCE"
3182
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listdepinholders", "params": ["&FRANCE"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
3183
+ **/ listdepinholders: 'listdepinholders',
2912
3184
  /** listglobalrestrictions
2913
3185
 
2914
3186
  List all global restricted assets
@@ -3544,6 +3816,24 @@ Examples:
3544
3816
  > neurai-cli savemempool
3545
3817
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "savemempool", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
3546
3818
  **/ savemempool: 'savemempool',
3819
+ /** selfrevokedepin "asset_name"
3820
+
3821
+ Self-revoke a DEPIN asset held in this wallet
3822
+
3823
+ The asset will be marked as invalid but will remain in the address
3824
+
3825
+ This action can only be undone by the asset owner
3826
+
3827
+ Arguments:
3828
+ 1. "asset_name" (string, required) The DEPIN asset name (must start with &)
3829
+
3830
+ Result:
3831
+ "txid" (string) The transaction id
3832
+
3833
+ Examples:
3834
+ > neurai-cli selfrevokedepin "&FRANCE"
3835
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "selfrevokedepin", "params": ["&FRANCE"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
3836
+ **/ selfrevokedepin: 'selfrevokedepin',
3547
3837
  /** sendfrom "fromaccount" "toaddress" amount ( minconf "comment" "comment_to" )
3548
3838
 
3549
3839
  DEPRECATED (use sendtoaddress). Sent an amount from an account to a neurai address.
@@ -4069,6 +4359,26 @@ Examples:
4069
4359
  > neurai-cli unfreezeaddress "$RESTRICTED_ASSET" "address" "change_address"
4070
4360
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "unfreezeaddress", "params": ["$RESTRICTED_ASSET" "address" "change_address"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
4071
4361
  **/ unfreezeaddress: 'unfreezeaddress',
4362
+ /** unfreezedepin "asset_name" "address" ("change_address")
4363
+
4364
+ Unfreeze a DEPIN asset for a specific address (owner only)
4365
+
4366
+ The asset will be marked as valid again
4367
+
4368
+ Requires the owner token (&ASSET!) in the wallet
4369
+
4370
+ Arguments:
4371
+ 1. "asset_name" (string, required) The DEPIN asset name (must start with &)
4372
+ 2. "address" (string, required) The address to unfreeze
4373
+ 3. "change_address" (string, optional) The change address for the owner token
4374
+
4375
+ Result:
4376
+ "txid" (string) The transaction id
4377
+
4378
+ Examples:
4379
+ > neurai-cli unfreezedepin "&FRANCE" "address"
4380
+ > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "unfreezedepin", "params": ["&FRANCE", "address"] }' -H 'content-type: text/plain;' http://127.0.0.1:8766/
4381
+ **/ unfreezedepin: 'unfreezedepin',
4072
4382
  /** unfreezerestrictedasset asset_name (change_address) (asset_data)
4073
4383
 
4074
4384
  Unfreeze all trading for a specific restricted asset
@@ -4265,6 +4575,154 @@ Examples:
4265
4575
  };
4266
4576
 
4267
4577
 
4578
+ /**
4579
+ * DePIN RPC Client for Neurai
4580
+ *
4581
+ * This module provides support for communicating with Neurai DePIN messaging
4582
+ * on port 19002 using the challenge/response authentication protocol.
4583
+ */ /**
4584
+ * Request a challenge from DePIN server
4585
+ * Uses the simple protocol: AUTH|token|address|mode
4586
+ */ async function $9df46f7047db01a3$var$requestChallenge(url, authOptions) {
4587
+ const mode = authOptions.mode || 'RECEIVE';
4588
+ const authCommand = `AUTH|${authOptions.token}|${authOptions.address}|${mode}`;
4589
+ try {
4590
+ const response = await fetch(url, {
4591
+ method: 'POST',
4592
+ headers: {
4593
+ 'Content-Type': 'text/plain'
4594
+ },
4595
+ body: authCommand
4596
+ });
4597
+ if (!response.ok) throw new Error(`Failed to request challenge: ${response.statusText}`);
4598
+ const responseText = await response.text();
4599
+ // Parse response: CHALLENGE|<challenge>|<timeout>
4600
+ if (!responseText.startsWith('CHALLENGE|')) throw new Error(`Invalid challenge response: ${responseText}`);
4601
+ const parts = responseText.split('|');
4602
+ if (parts.length < 3) throw new Error(`Malformed challenge response: ${responseText}`);
4603
+ const challenge = parts[1];
4604
+ const timeout = parseInt(parts[2], 10);
4605
+ if (!challenge || isNaN(timeout)) throw new Error(`Invalid challenge data: ${responseText}`);
4606
+ // Construct the message that needs to be signed
4607
+ const messageToSign = `DEPIN-${mode}|${authOptions.token}|${authOptions.address}|${challenge}`;
4608
+ return {
4609
+ challenge: challenge,
4610
+ timeout: timeout,
4611
+ messageToSign: messageToSign
4612
+ };
4613
+ } catch (error) {
4614
+ throw new Error(`Failed to request DePIN challenge: ${error.message}`);
4615
+ }
4616
+ }
4617
+ /**
4618
+ * Make authenticated JSON-RPC request to DePIN server
4619
+ */ async function $9df46f7047db01a3$var$postDePinData(url, data, challenge, signature) {
4620
+ const response = await fetch(url, {
4621
+ method: 'POST',
4622
+ mode: 'cors',
4623
+ headers: {
4624
+ 'Content-Type': 'application/json'
4625
+ },
4626
+ body: JSON.stringify(data)
4627
+ });
4628
+ return response;
4629
+ }
4630
+ /**
4631
+ * Get or refresh challenge if needed
4632
+ */ async function $9df46f7047db01a3$var$ensureValidChallenge(context, requiredMode) {
4633
+ const now = Date.now();
4634
+ // Check if we have a valid cached challenge
4635
+ if (context.currentChallenge && context.currentChallenge.mode === requiredMode && context.currentChallenge.expiresAt > now) return context.currentChallenge.challenge;
4636
+ // Request new challenge
4637
+ const authOptions = {
4638
+ ...context.authOptions,
4639
+ mode: requiredMode
4640
+ };
4641
+ const challengeData = await $9df46f7047db01a3$var$requestChallenge(context.url, authOptions);
4642
+ // Cache challenge (expires 5 seconds before actual timeout for safety)
4643
+ context.currentChallenge = {
4644
+ challenge: challengeData.challenge,
4645
+ expiresAt: now + (challengeData.timeout - 5) * 1000,
4646
+ mode: requiredMode
4647
+ };
4648
+ return challengeData.challenge;
4649
+ }
4650
+ function $9df46f7047db01a3$export$e3c4528d9eee3c6(url, authOptions) {
4651
+ if (!url) throw new Error('URL is required for DePIN RPC');
4652
+ if (!authOptions.token) throw new Error('Token is required for DePIN authentication');
4653
+ if (!authOptions.address) throw new Error('Address is required for DePIN authentication');
4654
+ if (!authOptions.signMessage || typeof authOptions.signMessage !== 'function') throw new Error('signMessage function is required for DePIN authentication');
4655
+ const context = {
4656
+ url: url,
4657
+ authOptions: authOptions
4658
+ };
4659
+ return async function depinRpc(method, params) {
4660
+ return new Promise(async (resolve, reject)=>{
4661
+ try {
4662
+ // Determine operation mode from method
4663
+ const requiredMode = method === 'depinsendmsg' || method === 'depinsubmitmsg' ? 'SEND' : 'RECEIVE';
4664
+ // Get valid challenge
4665
+ const challenge = await $9df46f7047db01a3$var$ensureValidChallenge(context, requiredMode);
4666
+ // Build message to sign
4667
+ const messageToSign = `DEPIN-${requiredMode}|${authOptions.token}|${authOptions.address}|${challenge}`;
4668
+ // Sign the message
4669
+ const signature = await authOptions.signMessage(messageToSign);
4670
+ if (!signature) throw new Error('Signature function returned empty result');
4671
+ // Add challenge and signature to params
4672
+ const enhancedParams = [
4673
+ ...params,
4674
+ challenge,
4675
+ signature
4676
+ ];
4677
+ // Build JSON-RPC request
4678
+ const requestData = {
4679
+ jsonrpc: '2.0',
4680
+ id: Math.random(),
4681
+ method: method,
4682
+ params: enhancedParams
4683
+ };
4684
+ // Make request
4685
+ const response = await $9df46f7047db01a3$var$postDePinData(url, requestData, challenge, signature);
4686
+ if (response.ok) {
4687
+ const responseData = await response.json();
4688
+ if (responseData.error) {
4689
+ // Check if it's an expired challenge error
4690
+ if (responseData.error.message && responseData.error.message.includes('expired')) {
4691
+ // Clear cached challenge and retry once
4692
+ context.currentChallenge = undefined;
4693
+ // Retry the request with a new challenge
4694
+ return depinRpc(method, params).then(resolve).catch(reject);
4695
+ }
4696
+ reject({
4697
+ error: responseData.error,
4698
+ description: responseData.error.message || 'Unknown error'
4699
+ });
4700
+ } else resolve(responseData.result);
4701
+ } else {
4702
+ const errorData = await response.json().catch(()=>({}));
4703
+ reject({
4704
+ statusText: response.statusText,
4705
+ status: response.status,
4706
+ error: errorData.error,
4707
+ description: errorData.error?.message || 'Request failed'
4708
+ });
4709
+ }
4710
+ } catch (error) {
4711
+ reject({
4712
+ originalError: error,
4713
+ type: 'DePinRequestError',
4714
+ error: error.message || 'Failed to communicate with DePIN server',
4715
+ description: 'Check that the DePIN server URL is correct and that the server is running'
4716
+ });
4717
+ }
4718
+ });
4719
+ };
4720
+ }
4721
+ async function $9df46f7047db01a3$export$9d7d174baf084291(url, authOptions) {
4722
+ return $9df46f7047db01a3$var$requestChallenge(url, authOptions);
4723
+ }
4724
+
4725
+
4268
4726
  function $80bd448eb6ea085b$var$throwSyntaxError() {
4269
4727
  throw new Error("Syntax error, call getRPC with (username, password, URL)");
4270
4728
  }