rings-rpc 0.3.0

Rings is a structured peer-to-peer network implementation using WebRTC, Chord algorithm, and full WebAssembly (WASM) support.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://static.ringsnetwork.io/ringsnetwork_logo.png">
  <img alt="Rings Network" src="https://raw.githubusercontent.com/RingsNetwork/asserts/main/logo/rings_network_red.png">
</picture>


Rings RPC
===============

[![rings-node](https://github.com/RingsNetwork/rings-node/actions/workflows/auto-release.yml/badge.svg)](https://github.com/RingsNetwork/rings-node/actions/workflows/auto-release.yml)


# JSON-RPC API endpoints

### Make requests

#### curl

Url `curl` to make the requests.

```
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "nodeInfo", "params": []}' \
"http://127.0.0.1:50000"
```

#### javascript

TODO

## JSON-RPC methods

This section lists the rings JSON-RPC API endpoints. You can call these [APIs using a variety of tools](#Make_request).

### Error codes

The follow list contains all possible error codes and associated messages:

|code|meaning|category|
|--- |---    |---     |
|-32000|Internal service error|standard|
|-32001|Connect remote server with error occurred|standard|
|-32002|Push or find pending transport failed|standard|
|-32003|Transport not found|standard|
|-32004|Create new `transport` failed|standard|
|-32005|Close `transport` failed|standard|
|-32006|Encode data error|standard|
|-32007|Decode data error|standard|
|-32008|Register ice failed|standard|
|-32009|Create new `offer` failed|standard|
|-32010|Create new `answder` failed|standard|
|-32011|Invalid transport id|standard|
|-32012|Invalid did|standard|
|-32013|Invalid method|standard|
|-32014|Send message with error occurred|standard|
|-32015|Permission requires to do something|standard|
|-32016|VNode action error|standard|
|-32017|Register service with error occurred|standard|
|-32018|Invalid data|standard|
|-32019|Invalid message|standard|
|-32020|Invalid service|standard|
|-32021|Invalid address|standard|
|-32022|Invalid auth data|standard|


Example error response:

```json
{
    "id": 1,
    "jsonrpc": "2.0",
    "error": {
        "code": -32000,
        "message": "internal service error",
    }
}
```

### nodeInfo

return rings node basic information.

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`

#### EXAMPLE

```
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "nodeInfo", "params": []}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `version` - current running node version

#### BODY

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "version": "0.0.1"
    }
}
```


### connectPeerViaHttp

Connect a peer with peer's jsonrpc endpoint

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`

#### EXAMPLE

```
## Replace REMOTE-JSONRPC-ENDPOINT with the url what you want to connect
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "connectPeerViaHttp", "params": ["REMOTE-JSONRPC-ENDPOINT"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `transport_did` - the id of transport

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        "abcd-1234"
    ]
}
```


### connectWithDid

Connect a peer with peer's did

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace REMOTE-PEER-DID with the did what you want to connect
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "connectPeerWithDid", "params": ["REMOTE-PEER-DID"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE


#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": null
}
```


### connectWithSeed

Connect a peer with peer's seed

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace REMOTE-PEER-SEED with the did what you want to connect
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "connectPeerWithSeed", "params": ["REMOTE-PEER-SEED"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE


#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": null
}
```


### createOffer

Create an offer for connection

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace REMOTE-PEER-SEED with the did what you want to connect
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "createOffer", "params": [REMOTE-PEER-DID]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `transport_id`: id of the transport
* `ice`:  ice message

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "transport_id": "1234",
        "ice": "abcd1234",
    }
}
```


### answerOffer

Answer an offer for connection

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace REMOTE-PEER-SEED with the did what you want to connect
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "createOffer", "params": ["REMOTE-PEER-SEED"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `transport_id`: id of the transport
* `ice`:  ice message

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "transport_id": "1234",
        "ice": "abcd1234",
    }
}
```


### listPeers

List all node connected peers

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "listPeers", "params": []}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `peers` - list of connected peers
  - `transport_id` - id of the transport
  - `did` - did of remote peer
  - `state` - transport state

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        {
            "did": "abcd1234"
            "transport_id": "1234",
            "state": "connected",
        }
    ]
}
```


### closeConnection

Close a connected connection with the did of peer

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace REMOTE-PEER-DID with ice what you got from others
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "closeConnection", "params": ["REMOTE-PEER-DID"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {}
}
```


### listPendings

List all pending connections

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "closeConnection", "params": []}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `transport_infos` - list of all pending transports
    - `transport_id` - id of the transport
    - `state` - state of the transport

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        {
            "transport_id": "abcd1234",
            "state": "new"
        }
    ]
}
```


### closePendingTransport

Close a specific pending transport

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace TRANSPORT-ID with the transport_id which in listPendings
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "closePendingTransport", "params": ["TRANSPORT-ID"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {}
}
```


### sendHttpRequestMessage

Send a http request message to remote peer, the remote peer should provide the service you want to use

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace REMOTE-PEER-DID with did of remote peer
## Replace HTTP-REQUEST-ARG with your request arguments
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "sendSimpleTextMessage", "params": ["REMOTE-PEER-DID", {HTTP-REQUEST-ARG}]}' \
"http://127.0.0.1:50000"
```

* HTTP-REQUEST-ARG
  - `name` - service name
  - `method` - http method
  - `path` - resource path
  - `timeout` - timeout of remote request, optional
  - `headers` - remote request with headers, optional
  - `body` - request body what you want to send to remote service, optional

#### RESPONSE

* `tx_id` - transaction id

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
         "tx_id": "abcd1234"
    }
}
```


### sendSimpleTextMessage

Send simple text message to a peer

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace REMOTE-PEER-DID with did of remote peer
## Replace TEXT with what you want to send
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "sendSimpleTextMessage", "params": ["REMOTE-PEER-DID", "TEXT"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `tx_id` - transaction id

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
         "tx_id": "abcd1234"
    }
}
```


### sendCustomMessage

Send custom message to a peer

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace REMOTE-PEER-DID with did of remote peer
## Replace MESSAGE-TYPE with type of your message
## Replace DATA with message payload after base64
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "sendCustomMessage", "params": ["REMOTE-PEER-DID", "MESSAGE-TYPE", "DATA"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* `tx_id` - transaction id

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
         "tx_id": "abcd1234"
    }
}
```


### publishMessageToTopic

Publish data message to specific topic

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace TOPIC with message topic
## Replace DATA with message payload after base64
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "publishMessageToTOpic", "params": ["TOPIC", "DATA"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE


#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {}
}
```


### fetchMessageToTopic

Fetch message from specific topic

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace TOPIC with message topic
## Replace DATA with message payload after base64
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "fetchMessageToTopic", "params": ["TOPIC", "INDEX"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* MESSAGES - message vec of specific topic

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        "topic_message",
    ]
}
```


### registerService

Register custom service to rings network

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace NAME with the service name what you want to publish to rings network
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "registerService", "params": ["NAME"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {}
}
```


### lookupService

Lookup custom service from rings network, you can find all dids of node which provide service you want.

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace NAME with the service name what you want to lookup in rings network
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "lookupService", "params": ["NAME"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* DIDS - did list of nodes which provide service with specific name

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        "did1",
        "did2",
    ]
}
```


### pollMessage

Use this method, you can pull messages received by this node, to provide your custom service,
But we suggest use `websocket` endpoint realtime get messages.

#### REQUEST

`POST http://127.0.0.1:50000`

#### HEADERS

`Content-Type: application/json`
`X-SIGNATURE: YOUR-SIGNATURE`

#### EXAMPLE

```
## Replace YOUR-SIGNATURE with your signature
## Replace WAIT with a bool value, true will block the request, until new message receive.
curl -X POST \
-H "Content-Type: application/json" \
-H "X-SIGNATURE: YOUR-SIGNATURE" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "pollMessage", "params": ["WAIT"]}' \
"http://127.0.0.1:50000"
```

#### RESPONSE

* message - custom message received

#### EXAMPLE

```json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
      "message": {
          message_type: 1,
          data: "base64 text"
      }
    }
}
```