-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1745 lines (1682 loc) · 48.4 KB
/
openapi.yaml
File metadata and controls
1745 lines (1682 loc) · 48.4 KB
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.3
info:
title: RETE API
description: |
REST API for the RETE (Renewable Energy Token Economy) platform.
Manages authentication, community operations, token distribution, marketplace,
wallet management, and blockchain interactions for Renewable Energy Communities.
version: 1.0.0
license:
name: MIT
url: https://opensource.org/licenses/MIT
contact:
name: Apio S.r.l.
url: https://www.apio.cc
servers:
- url: http://localhost:5000
description: Development server
tags:
- name: Auth
description: Authentication and session management
- name: Community
description: Community management and statistics
- name: Tokens
description: Token distribution, burn, and transfer operations
- name: Products
description: Marketplace product management
- name: Purchase
description: Marketplace purchases
- name: Transactions
description: Transaction history
- name: Wallets
description: Wallet management and export
- name: Blockchain
description: Low-level blockchain operations and configuration
- name: Chain Profiles
description: Multi-chain profile management
paths:
# ── Auth ────────────────────────────────────────────────────────────
/api/auth/register:
post:
tags: [Auth]
summary: Register a new user
description: |
Creates a new account. Coordinators automatically create a community.
Users must have a pending invite from a coordinator.
Providers are created without a community association.
A custodial wallet is generated server-side for every new user.
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [email, password, name, role]
properties:
email:
type: string
format: email
password:
type: string
minLength: 6
name:
type: string
role:
$ref: '#/components/schemas/UserRole'
communityName:
type: string
description: Required when role is coordinator
communityId:
type: string
description: Optional community ID
responses:
'200':
description: Registration successful
content:
application/json:
schema:
type: object
properties:
user:
$ref: '#/components/schemas/UserPublic'
'400':
$ref: '#/components/responses/BadRequest'
'403':
description: User role requires an invite
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
$ref: '#/components/responses/InternalError'
/api/auth/login:
post:
tags: [Auth]
summary: Log in
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [email, password]
properties:
email:
type: string
format: email
password:
type: string
minLength: 6
responses:
'200':
description: Login successful
content:
application/json:
schema:
type: object
properties:
user:
$ref: '#/components/schemas/UserPublic'
'400':
$ref: '#/components/responses/BadRequest'
'401':
description: Invalid credentials
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/auth/logout:
post:
tags: [Auth]
summary: Log out
responses:
'200':
description: Logout successful
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
'500':
$ref: '#/components/responses/InternalError'
/api/auth/me:
get:
tags: [Auth]
summary: Get current authenticated user
security:
- sessionAuth: []
responses:
'200':
description: Current user
content:
application/json:
schema:
type: object
properties:
user:
$ref: '#/components/schemas/UserPublic'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
description: User not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/invites/check:
get:
tags: [Auth]
summary: Check if an email has a pending invite
parameters:
- name: email
in: query
required: true
schema:
type: string
format: email
responses:
'200':
description: Invite check result
content:
application/json:
schema:
type: object
properties:
hasInvite:
type: boolean
communityId:
type: string
communityName:
type: string
'400':
$ref: '#/components/responses/BadRequest'
# ── Community ───────────────────────────────────────────────────────
/api/communities:
get:
tags: [Community]
summary: List all communities
security:
- sessionAuth: []
responses:
'200':
description: List of communities
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Community'
/api/communities/{id}:
get:
tags: [Community]
summary: Get a community by ID
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
responses:
'200':
description: Community details
content:
application/json:
schema:
$ref: '#/components/schemas/Community'
'404':
description: Community not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/communities/{id}/users:
get:
tags: [Community]
summary: Get users of a specific community
description: The authenticated user must belong to the requested community.
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
responses:
'200':
description: List of community members
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserPublic'
'403':
$ref: '#/components/responses/Forbidden'
/api/community/stats:
get:
tags: [Community]
summary: Get community statistics
description: Returns stats for the authenticated user's community.
security:
- sessionAuth: []
responses:
'200':
description: Community statistics
content:
application/json:
schema:
type: object
description: Community statistics (members, transactions, etc.)
'400':
description: No associated community
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/community/users:
get:
tags: [Community]
summary: Get users in the coordinator's community
description: Coordinator-only endpoint.
security:
- sessionAuth: []
responses:
'200':
description: List of community members
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserPublic'
'403':
$ref: '#/components/responses/Forbidden'
/api/community/balances:
get:
tags: [Community]
summary: Get token balances for all community members
description: Coordinator-only endpoint.
security:
- sessionAuth: []
responses:
'200':
description: List of user balances
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
type: string
name:
type: string
email:
type: string
role:
$ref: '#/components/schemas/UserRole'
ethAddress:
type: string
tokenBalance:
type: integer
'403':
$ref: '#/components/responses/Forbidden'
# ── Token Operations ────────────────────────────────────────────────
/api/tokens/distribute:
post:
tags: [Tokens]
summary: Distribute tokens to community members
description: |
Coordinator-only. Mints tokens on-chain via EIP-712 signed authorization
and credits each recipient's balance. Supports batch distribution.
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [distributions]
properties:
distributions:
type: array
items:
type: object
required: [email, amount]
properties:
email:
type: string
format: email
amount:
type: number
minimum: 0
exclusiveMinimum: true
responses:
'200':
description: Distribution results
content:
application/json:
schema:
type: object
properties:
distributed:
type: array
items:
type: object
properties:
email:
type: string
amount:
type: number
userName:
type: string
txHash:
type: string
errors:
type: array
items:
type: object
properties:
email:
type: string
error:
type: string
'403':
$ref: '#/components/responses/Forbidden'
/api/tokens/burn:
post:
tags: [Tokens]
summary: Burn tokens from a user's balance
description: |
Coordinator-only. Burns tokens on-chain via EIP-712 signed authorization.
Can burn from the coordinator's own balance or from a target user.
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [amount]
properties:
amount:
type: number
minimum: 0
exclusiveMinimum: true
description:
type: string
targetUserId:
type: string
description: If omitted, burns from the coordinator's own balance
responses:
'200':
description: Burn result
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
burned:
type: number
txHash:
type: string
'403':
$ref: '#/components/responses/Forbidden'
/api/tokens/burn-all:
post:
tags: [Tokens]
summary: Burn all tokens in the community
description: |
Coordinator-only. Iterates over every member with a positive balance
and burns their tokens on-chain. Used for periodic reset cycles.
security:
- sessionAuth: []
responses:
'200':
description: Burn-all results
content:
application/json:
schema:
type: object
properties:
totalBurned:
type: number
usersAffected:
type: integer
results:
type: array
items:
type: object
properties:
name:
type: string
amount:
type: number
txHash:
type: string
errors:
type: array
items:
type: object
properties:
name:
type: string
error:
type: string
'403':
$ref: '#/components/responses/Forbidden'
/api/tokens/transfer:
post:
tags: [Tokens]
summary: Transfer tokens to another user
description: |
Uses ERC-2612 permit + transferFrom to move tokens on-chain
without requiring the sender to hold native gas tokens.
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [recipientId, amount]
properties:
recipientId:
type: string
amount:
type: number
minimum: 0
exclusiveMinimum: true
note:
type: string
responses:
'200':
description: Transfer result
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
transferred:
type: number
txHash:
type: string
to:
type: string
'400':
$ref: '#/components/responses/BadRequest'
# ── Invites ─────────────────────────────────────────────────────────
/api/users/invite:
post:
tags: [Community]
summary: Invite a user to the community
description: Coordinator-only. Creates an invite for the given email.
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [email]
properties:
email:
type: string
format: email
responses:
'200':
description: Invite sent
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
message:
type: string
'403':
$ref: '#/components/responses/Forbidden'
# ── Provider ────────────────────────────────────────────────────────
/api/provider/balances:
get:
tags: [Tokens]
summary: Get provider token balances by community
description: Provider-only. Returns the provider's balances across communities.
security:
- sessionAuth: []
responses:
'200':
description: Provider balances
content:
application/json:
schema:
type: array
items:
type: object
'403':
$ref: '#/components/responses/Forbidden'
# ── Products ────────────────────────────────────────────────────────
/api/products:
get:
tags: [Products]
summary: List products available in the user's community
security:
- sessionAuth: []
responses:
'200':
description: List of products
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Product'
post:
tags: [Products]
summary: Create a new product
description: Provider-only. Creates a product available in one or more communities.
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [name, price, category, communityIds]
properties:
name:
type: string
description:
type: string
price:
type: integer
minimum: 1
category:
type: string
imageUrl:
type: string
nullable: true
available:
type: boolean
default: true
communityIds:
type: array
items:
type: string
minItems: 1
responses:
'200':
description: Created product
content:
application/json:
schema:
$ref: '#/components/schemas/ProductWithCommunities'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/Forbidden'
/api/products/mine:
get:
tags: [Products]
summary: List the authenticated provider's products
description: Provider-only.
security:
- sessionAuth: []
responses:
'200':
description: List of provider's products
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ProductWithCommunities'
'403':
$ref: '#/components/responses/Forbidden'
/api/products/{id}:
put:
tags: [Products]
summary: Update a product
description: Provider-only. Only the product owner can update.
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
description:
type: string
price:
type: integer
category:
type: string
imageUrl:
type: string
nullable: true
available:
type: boolean
communityIds:
type: array
items:
type: string
minItems: 1
responses:
'200':
description: Updated product
content:
application/json:
schema:
$ref: '#/components/schemas/ProductWithCommunities'
'403':
$ref: '#/components/responses/Forbidden'
'404':
description: Product not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
tags: [Products]
summary: Delete a product
description: Provider-only. Only the product owner can delete.
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
responses:
'200':
description: Deletion successful
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
'403':
$ref: '#/components/responses/Forbidden'
'404':
description: Product not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
# ── Purchase ────────────────────────────────────────────────────────
/api/purchase:
post:
tags: [Purchase]
summary: Purchase a product from the marketplace
description: |
Executes an on-chain permit + transferFrom to pay the provider,
then updates local balances and records the transaction.
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [productId]
properties:
productId:
type: string
responses:
'200':
description: Purchase successful
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
newBalance:
type: integer
product:
type: string
txHash:
type: string
'400':
$ref: '#/components/responses/BadRequest'
'404':
description: Product not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
# ── Transactions ────────────────────────────────────────────────────
/api/transactions:
get:
tags: [Transactions]
summary: Get the authenticated user's transactions
security:
- sessionAuth: []
responses:
'200':
description: List of transactions
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
/api/transactions/community:
get:
tags: [Transactions]
summary: Get all transactions in the coordinator's community
description: Coordinator-only.
security:
- sessionAuth: []
responses:
'200':
description: List of community transactions
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
'403':
$ref: '#/components/responses/Forbidden'
# ── Wallets ─────────────────────────────────────────────────────────
/api/wallets:
get:
tags: [Wallets]
summary: Get the authenticated user's wallets
security:
- sessionAuth: []
responses:
'200':
description: List of wallets
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/WalletPublic'
/api/wallets/generate:
post:
tags: [Wallets]
summary: Generate a new custodial wallet
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [label]
properties:
label:
type: string
walletType:
$ref: '#/components/schemas/WalletType'
responses:
'200':
description: Generated wallet
content:
application/json:
schema:
$ref: '#/components/schemas/WalletPublic'
/api/wallets/import:
post:
tags: [Wallets]
summary: Import an existing wallet by private key
security:
- sessionAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [label, privateKey]
properties:
label:
type: string
privateKey:
type: string
walletType:
$ref: '#/components/schemas/WalletType'
responses:
'200':
description: Imported wallet
content:
application/json:
schema:
$ref: '#/components/schemas/WalletPublic'
/api/wallets/{id}/set-default:
post:
tags: [Wallets]
summary: Set a wallet as default
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
responses:
'200':
description: Default wallet updated
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
'404':
description: Wallet not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/wallets/{id}/export-keystore:
post:
tags: [Wallets]
summary: Export wallet as encrypted keystore (JSON)
description: Requires account password verification and a separate keystore password.
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [password, keystorePassword]
properties:
password:
type: string
description: Account password for verification
keystorePassword:
type: string
minLength: 8
description: Password to encrypt the keystore file
responses:
'200':
description: Keystore JSON
content:
application/json:
schema:
type: object
properties:
keystore:
type: object
description: Encrypted keystore JSON (Web3 Secret Storage format)
address:
type: string
label:
type: string
'401':
description: Invalid account password
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/wallets/{id}:
delete:
tags: [Wallets]
summary: Delete a wallet
security:
- sessionAuth: []
parameters:
- $ref: '#/components/parameters/ResourceId'
responses:
'200':
description: Wallet deleted
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
'404':
description: Wallet not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
# ── Blockchain ──────────────────────────────────────────────────────
/api/blockchain/config:
get:
tags: [Blockchain]
summary: Get token configuration
security:
- sessionAuth: []
parameters:
- name: token