forked from AnnabelJoe/solarproof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
380 lines (364 loc) · 10.9 KB
/
openapi.yaml
File metadata and controls
380 lines (364 loc) · 10.9 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
openapi: 3.1.0
info:
title: SolarProof API
version: 1.0.0
description: |
End-to-end cryptographic proof of renewable energy — from physical meter to on-chain certificate.
All responses are JSON. Timestamps are ISO 8601 strings unless noted.
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0
servers:
- url: https://solarproof.vercel.app
description: Production
security: []
paths:
/api/readings:
post:
operationId: submitReading
summary: Submit a signed meter reading
description: |
Verifies the Ed25519 signature, anchors the reading hash on Stellar,
and mints energy certificates (1 token = 1 kWh).
security: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ReadingRequest'
example:
meter_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
kwh: 12.5
timestamp: 1745366400
signature_hex: "4b3e9f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f09a"
responses:
'201':
description: Reading accepted, anchored, and certificates minted
content:
application/json:
schema:
$ref: '#/components/schemas/ReadingResponse'
'400':
description: Validation failed
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
'401':
description: Ed25519 signature invalid
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: Invalid meter signature
'404':
description: Meter not registered or inactive
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: Meter not found or inactive
'409':
description: Reading already anchored
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: Anchor or mint failed
content:
application/json:
schema:
$ref: '#/components/schemas/ReadingError'
/api/verify:
get:
operationId: verifyCertificate
summary: Retrieve chain of custody for a certificate
description: |
Public endpoint — no authentication required.
Accepts a certificate UUID, reading hash (64-char hex), or mint transaction hash.
Results are cached for 60 seconds.
security: []
parameters:
- name: id
in: query
required: true
description: Certificate UUID, reading hash (64-char hex), or mint transaction hash
schema:
type: string
example: a1b2c3d4-e5f6-7890-abcd-ef1234567890
responses:
'200':
description: Certificate found — full chain of custody returned
headers:
Cache-Control:
schema:
type: string
example: public, max-age=60, stale-while-revalidate=30
X-Cache:
schema:
type: string
enum: [HIT, MISS]
content:
application/json:
schema:
$ref: '#/components/schemas/ChainOfCustody'
'400':
description: Missing or invalid id parameter
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
'404':
description: No certificate matches the given id
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: Certificate not found
/api/certificates/{id}/retire:
post:
operationId: retireCertificate
summary: Retire a certificate
description: |
Permanently retires a certificate by calling the energy_token contract retire function.
A retired certificate cannot be used again.
security: []
parameters:
- name: id
in: path
required: true
description: Certificate UUID
schema:
type: string
format: uuid
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/RetireRequest'
responses:
'200':
description: Certificate retired successfully
content:
application/json:
schema:
$ref: '#/components/schemas/RetireResponse'
'400':
description: Validation failed
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
'404':
description: Certificate not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'409':
description: Certificate already retired
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: Certificate already retired
'500':
description: Retire transaction failed
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/health:
get:
operationId: healthCheck
summary: Liveness check
description: Returns 200 when the service is running. Used by uptime monitoring.
security: []
responses:
'200':
description: Service is healthy
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
example:
status: ok
ts: 1745366400000
'503':
description: Service unavailable
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
ReadingRequest:
type: object
required: [meter_id, kwh, timestamp, signature_hex]
properties:
meter_id:
type: string
format: uuid
description: Registered meter identifier
kwh:
type: number
exclusiveMinimum: 0
description: Energy generated in kilowatt-hours
timestamp:
type: integer
description: Unix timestamp in seconds (integer)
signature_hex:
type: string
minLength: 128
maxLength: 128
description: Ed25519 signature of the canonical reading hash, hex-encoded (64 bytes)
ReadingResponse:
type: object
required: [reading_id, anchor_tx_hash, mint_tx_hash]
properties:
reading_id:
type: string
format: uuid
anchor_tx_hash:
type: string
description: Stellar transaction hash for the on-chain anchor
mint_tx_hash:
type: string
description: Stellar transaction hash for the certificate mint
ReadingError:
type: object
required: [error, reading_id]
properties:
error:
type: string
reading_id:
type: string
format: uuid
anchor_tx_hash:
type: string
description: Present if anchoring succeeded but minting failed
ChainOfCustody:
type: object
required: [certificate, on_chain]
properties:
certificate:
type: object
required: [id, kwh, issued_at, retired]
properties:
id:
type: string
format: uuid
kwh:
type: number
issued_at:
type: string
format: date-time
retired:
type: boolean
retired_at:
type: ['string', 'null']
format: date-time
retired_by:
type: ['string', 'null']
description: Stellar wallet address that retired the certificate
on_chain:
type: object
required: [anchor_tx, anchor_explorer, mint_tx, mint_explorer]
properties:
anchor_tx:
type: string
anchor_explorer:
type: string
format: uri
mint_tx:
type: string
mint_explorer:
type: string
format: uri
meter_proof:
oneOf:
- type: 'null'
- type: object
required: [meter_id, reading_hash, signature_hex, kwh, timestamp, verified]
properties:
meter_id:
type: string
format: uuid
reading_hash:
type: string
description: Hex-encoded SHA-256 hash of the canonical reading
signature_hex:
type: string
description: Ed25519 signature hex (128 chars)
kwh:
type: number
timestamp:
type: string
format: date-time
verified:
type: boolean
RetireRequest:
type: object
required: [wallet_address]
properties:
wallet_address:
type: string
description: Stellar wallet address of the certificate holder
RetireResponse:
type: object
required: [id, retired, retired_at, retired_by, retire_tx_hash]
properties:
id:
type: string
format: uuid
retired:
type: boolean
retired_at:
type: string
format: date-time
retired_by:
type: string
retire_tx_hash:
type: string
HealthResponse:
type: object
required: [status, ts]
properties:
status:
type: string
enum: [ok]
ts:
type: integer
description: Current Unix timestamp in milliseconds
Error:
type: object
required: [error]
properties:
error:
type: string
ValidationError:
type: object
required: [error]
properties:
error:
oneOf:
- type: string
- type: object
properties:
fieldErrors:
type: object
additionalProperties:
type: array
items:
type: string
formErrors:
type: array
items:
type: string