forked from cryptol0g1c/bitsign-federation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiary.apib
560 lines (478 loc) · 18.9 KB
/
apiary.apib
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
FORMAT: 1A
HOST: https://api.bitsign.io/
# Bitsign BaaS API documentation
![Bitsign](https://bitsign.io/img/logos/logo.png "Bitsign Logo")
Version: 0.1.0
##### What is Bitsign Baas?
Bitsign's BaaS **(Blockchain as a Service)** is a service which acts as an
abstraction layer and lets you interact with different types of blockchains and
run descentralized apps (DApps) like Smart Contracts.
Bitsign resources can be found here:
https://github.com/cryptol0g1c/bitsign
Anytime you alter the blockchain state thus creating a transaction that information can
be searched using transaction hash, account or smart contract address at:
https://explorer.bitsign.io
In depth information about the service and it's endpoints can be found here:
[http://bitsign.readthedocs.io/en/latest/](http://bitsign.readthedocs.io/en/latest/)
##### Blockchain types
* BSG blockchain
Bitsign chain is an Ethereum opcode compatible chain that runs on several
Parity nodes using **PoA** (Proof of Authority) consensus algorithm.
Chain parameters and initial conditions can be found here:
https://github.com/cryptol0g1c/bitsign/blob/master/genesis.json
New nodes can be addeed using a validator contract, its code can be found here:
https://github.com/cryptol0g1c/bitsign/blob/master/contracts/validator.sol
* Ropsten Blockchain (WIP)
* Ethereum Main Net (WIP)
* RSK (WIP)
* MultiChain (WIP)
### Get Bitsign Status [GET /status]
This endpoint returns Bitsign blockchain status, latestblock, bootnodes, etc.
+ Response 200 (application/json)
{
"success": true,
"data": {
"status": "Running, healthy",
"lastblock": 20201,
"hash": "0x2c1b018d0cb86087f7e226459e998e6b7515bc6bf529833c90f8e3883d290c49",
"timestamp": 1515282880,
"explorer": "https://explorer.bitsign.io/block/20201",
"bootnodes": [
"enode://a891225909f70a4ee3f40c1dac05da763fe0354d5f259922abf841db51706283d2957c09fc7266e5f4633583a34dbef3f38a769eb35551788740a06e387dfa2a@159.203.176.160:30303",
"enode://b21d8b85165319a86c822dadcd51fbaf1aca3fe7854df8644c03ac304e34205d31d44d0eac7dd6366a8f8a621eeb2198d9644090d59771148fb3ac92630d2dd6@198.211.100.127:30303"
]
},
"error": null
}
## User Endpoints [/api/v2/user]
### User Info [GET /api/v2/user?email={email}&password={password}]
This endpoint retrieves token and Ethereum keys needed to interact with the rest of the endpoints.
**Email** and **password** parameters must be provided.
+ Parameters
+ email: [email protected] (string) - Unique email address.
+ password: some_crafty_password (string) - User password
+ Response 200 (application/json)
{
"success": true,
"data": {
"username": "alice",
"email": "[email protected]",
"ethereumAddress": "0xA2..99",
"token": "ey..yk"
},
"error": null
}
### New User [POST]
Create new user trough our API to get token access and pre-configured Ethereum keys.
With the token you can query all other endpoints and interact with all blockchains and the Smart Contracts.
+ Attributes
+ email: [email protected] (string) - Unique email address.
+ password: some_crafty_password (string) - User password.
+ username: alice (string) - Unique user name.
+ Request (application/json)
{
"email": "",
"password": "",
"username": ""
}
+ Response 200 (application/json)
{
"success": true,
"data": {
"_id": "",
"username": "",
"email": "",
"etherAddress": "",
"etherPrivKey": "",
"token": ""
},
"error": null
}
### Change Password [PUT]
This endpoint allow the user to changes their password. You must send the old password and the new one that must respect our security policies.
+ Attributes
+ email: [email protected] (string) - Unique email address.
+ password: some_crafty_password (string) - User password.
+ newPassword: new_crafty_password (string) - User new password.
+ Request (application/json)
{
"email": "[email protected]",
"password": "crafty_password!",
"newPassword": "new_crafty_password"
}
+ Response 200 (application/json)
{
"success": true,
"data": {
"_id": "5a..1a",
"username": "alice",
"email": "[email protected]",
"token": "ey..gk"
},
"error": null
}
## Transaction Endpoints [/eth/notarizetx]
### Notarization TX [POST]
This endpoints uses data field input to create a **notary transaction** and include it in a new block.
Transactions from this endpoints will be executed **from Bitsign's main node** to facilitate its creation.
If you want to create your own transaction and send it from your account please use **sendRawTX endpoint instead**.
+ Attributes
+ token: ey..yk (string) - User token.
+ data: 0x..3F (string) - Data to notarize.
+ address: 0x..m3 (string) - User ethereum address.
+ password: new_crafty_password (string) - User password.
+ Request (application/json)
{
"token": "<your_token>",
"data": "<some_hexadecimal_data>",
"address": "<your_ethereum_address>",
"password": "<your_password>"
}
+ Response 200 (application/json)
{
"success": true,
"data": {
"blockHash": "0x96..3b",
"blockNumber": 1958,
"gasUsed": 21136,
"transactionHash": "0x2d..b7",
"explorerUrl": "https://explorer.bitsign.io/tx/0x2d49344a2d59d713a2195acd934060d945bb4fc4c0e792d46d1d5e33b67aaeb7"
},
"error": null
}
## Raw Transactions Endpoints [/eth/signedRawTx]
### SendRawTransaction [POST]
If you don't trust or don't want to use the **keypair provided by Bitsign**, you can always call this endpoint that will publish your **offline
signed** raw [transaction](https://web3js.readthedocs.io/en/1.0/web3-eth.html#sendsignedtransaction). Bitsign node will only handle gas cost and transaction publication,
but you have to **craft the entire transaction** on your end.
We will be releasing Bitsign tx library to facilitate this process soon.
+ Attributes
+ token: ey..yk (string) - User token.
+ env: production (string) - Environment to deploy the smart contract.
+ tx: 0x..m3 (string) - Signed data.
+ Request (application/json)
{
"token": "",
"env": "",
"tx": ""
}
+ Response 200 (application/json)
{
"success": true,
"data": {},
"error": null
}
## Smart Contract Endpoints [/eth/contract]
### Deploy new Smart Contract [PUT]
This endpoint allow the user to deploy a new smart contract. The available smart contracts are:
##### Notarize
This smart contract allow the user to notarize documents.
###### Constructor
In order to initialize Notarize contract the user must send an address, that will be set as the owner of the contract. The owner will be the only one that is able to notarize.
###### Methods
* notarize: This method receive as a parameter a bytes32 that will be the evidence to be notarized. The owner of the contract will be the only one that is capable of execute this method. If the sender is not the owner, the tx will be reverted. After the evidence is notarized the Notary event will be raised with two parameters: the evidence and the address.
##### Escrow
This smart contract allows the user to deposit funds in the smart contract and define a buyer and a seller. Each actor can release the funds to the other part based on pre established conditions. Also there is BSG arbiter which act as an impartial third party that can release the payment to one party in case the other part breaks the initial conditions.
###### Constructor
In order to initialize Escrow contract the user must send _seller (address), _buyer (address) and _endTime (uint). The sender of the transaction will be the arbiter of the contract. The arbiter act as an impartial third party. Also the value should be passed in order to set funds on the contract.
###### Methods
* pay: This method can be executed by the buyer or the arbiter. This method will transfer the balance of the contract to the seller address. After that, it will raise the Payout event with two parameters: balance and seller address.
* refund: This method can be executed by the seller or the arbiter. This method will transfer the balance of the contract to the buyer address. After that, it will raise the Refund event with two parameters: balance and buyer address.
* getBalance: This method will return the balance of the contract. It can be executed by any member of the contract.
* kill: This method can be executed by the arbiter only. It will destruct the contract and send the balance of the contract to its address.
##### NotarizeTX
###### Constructor
In order to initialize NotarizeTx contract the user must send the following values:
buyer (address),
seller (address),
id (bytes32),
date (string),
value (uint),
hash (bytes32),
status (string),
shipping (string)
###### Methods
* updateStatus: This method can be executed by the buyer or the BSG node. Also it checks that the id passed is the same as one that user sent when deployed. The parameters of this method are status (string), hash (bytes32) and id (bytes32). The main purpose of this method is to update the tx status. After the method notarize the new tx, it raise the NotaryEvt event with the parameters: hash (bytes32) and id (bytes32).
* updateShipping: This method can be executed by the buyer or the BSG node. Also it checks that the id passed is the same as one that user sent when deployed. The parameters of this method are status (string), hash (bytes32) and id (bytes32). The main purpose of this method is to update the tx shipping. After the method notarize the new tx, it raise the NotaryEvt event with the parameters: hash (bytes32) and id (bytes32).
+ Attributes
+ token: ey..yk (string) - User token.
+ env: production (string) - Environment to deploy the smart contract.
+ args
+ _buyer: 0x..yk (string) - Buyer address.
+ _seller: 0x..6f (string) - Seller address.
+ _endTime: 314159 (number) - Escrow automatic endtime.
+ type: Escrow (string) - Contract type to deploy.
+ value: 0 (string) - Value in ethers to send to the smart contract.
+ password: some_crafty_password (string) - User Password.
+ Request (application/json)
{
"token": "",
"env": "production",
"args": {
"_buyer": "",
"_seller": "",
"_endTime": 314159
},
"type": "Escrow",
"value": "0",
"password": "<your_password>"
}
+ Response 200 (application/json)
{
"success": true,
"data": {
"__v": 0,
"encodedAbi": "00..84",
"address": "0x9B..D3",
"bytecode": "0x60..029",
"gas": 166571,
"type": "Notarize",
"_id": "5a..31",
"events": [],
"abi": [
{
"signature": "0xcbef362f",
"type": "function",
"stateMutability": "nonpayable",
"payable": false,
"outputs": [],
"name": "notarize",
"inputs": [
{
"type": "bytes32",
"name": "_sghash"
}
],
"constant": false
},
{
"signature": "constructor",
"type": "constructor",
"stateMutability": "nonpayable",
"payable": false,
"inputs": [
{
"type": "address",
"name": "_user"
}
]
},
{
"signature": "0x8d..f6",
"type": "event",
"name": "Notary",
"inputs": [
{
"type": "bytes32",
"name": "_sghash",
"indexed": false
},
{
"type": "address",
"name": "_address",
"indexed": false
}
],
"anonymous": false
}
],
"owner": {
"address": "0x06..E4",
"email": "[email protected]"
},
"date": {
"created": "2017-12-09T01:07:30.634Z"
}
},
"error": null
}
### Contract Usage [GET /eth/contract/doc?token={token}&type={type}]
This endpoint returns smart contract's ABI and functions to use its functionality.
+ Parameters
+ token: <user_token> (string) - User token.
+ type: <contract_name> (string) - Smart Contract type.
+ Response 200 (application/json)
{
"success": true,
"data": [
{
"name": "seller",
"parameters": [],
"return": [
{
"name": "",
"type": "address"
}
],
"type": "function"
},
{
"name": "getBalance",
"parameters": [],
"return": [
{
"name": "",
"type": "uint256"
}
],
"type": "function"
},
{
"name": "pay",
"parameters": [],
"return": [],
"type": "function"
},
{
"name": "endTime",
"parameters": [],
"return": [
{
"name": "",
"type": "uint256"
}
],
"type": "function"
},
{
"name": "value",
"parameters": [],
"return": [
{
"name": "",
"type": "uint256"
}
],
"type": "function"
},
{
"name": "kill",
"parameters": [],
"return": [],
"type": "function"
},
{
"name": "refund",
"parameters": [],
"return": [],
"type": "function"
},
{
"name": "buyer",
"parameters": [],
"return": [
{
"name": "",
"type": "address"
}
],
"type": "function"
},
{
"name": "arbiter",
"parameters": [],
"return": [
{
"name": "",
"type": "address"
}
],
"type": "function"
},
{
"parameters": [
{
"name": "_seller",
"type": "address"
},
{
"name": "_buyer",
"type": "address"
},
{
"name": "_endtime",
"type": "uint256"
}
],
"type": "constructor"
},
{
"name": "Payout",
"parameters": [
{
"indexed": false,
"name": "_value",
"type": "uint256"
},
{
"indexed": false,
"name": "_to",
"type": "address"
}
],
"type": "event"
},
{
"name": "Refund",
"parameters": [
{
"indexed": false,
"name": "_value",
"type": "uint256"
},
{
"indexed": false,
"name": "_to",
"type": "address"
}
],
"type": "event"
}
],
"error": null
}
### Call Contract Method [POST]
This endpoint allow the user to read the state from the blockchain using contract methods.
This endpoint will not alter blockchain state and therefore wont cost gas.
+ Request (application/json)
{
"token": "",
"address": "",
"env": "",
"method": "",
"args": {}
}
+ Response 200 (application/json)
{
"success": true,
"data": {},
"error": null
}
### Execute Contract Method[PATCH]
This endpoint allow the user to send a transaction to the node and therefore modify the blockchain state.
Altough this method will generally cost gas, there is no limitation about it when using BSG Chain and gast cost will be handled internally.
+ Attributes
+ token: ey..yk (string) - User token.
+ address: production (string) - Contract's address.
+ env: production (string) - Environment.
+ args
+ arg_1
+ arg_2
+ method: pay (string) - Contract's method to execute.
+ password: some_crafty_password (string) - User Password.
+ Request (application/json)
{
"token": "",
"address": "<contract_address>",
"env": "production",
"method": "pay",
"args": {
},
"password": "<your_password>"
}
+ Response 200 (application/json)
{
"success": true,
"data": {},
"error": null
}