mainnet-cash / project

Docs related to the mainnet.cash project
9 stars 3 forks source link

REST API #5

Open readcash opened 4 years ago

readcash commented 4 years ago

This is a work-in-progress draft specification of the REST API

Let's discuss.

To simplify interactions, all exchange will be done via POST (probably except for wait.. responses, for which I guess WebSockets or Server-Sent Events are the way to go)

To avoid writing all the details, I write a concise version here, so

POST wallet
< type: wif, network:regtest
> wallet: wif:regtest:wif12345, wif:abcdef, cashaddr:...

actually means

POST /api/v1/wallet
JSON Request (body): {"type": "wif", "network": "regtest"}
JSON Response: {"wallet": "wif:regtest:wif12345", "wif": "abcdef", "cashaddr": "..."}
readcash commented 4 years ago
POST wallet
< type: wif, network:regtest
> wallet: wif:regtest:wif12345, wif:abcdef, cashaddr:...

< type: hd, network:regtest
> wallet: hd:regtest:BHDIKHD, entropy_base64:BHDIKHD

POST wallet/send
< wallet: regtest:wif12345, to: [[bitcoincash:123, 15, bch]]
> txid: ...

or for HD-wallet
< wallet: hd:regtest:BHDIKHD, to: [[bitcoincash:123, 15, bch]]
...
or to spend specific UTXOs
< wallet: hd:regtest:BHDIKHD, utxos: [...], to: [[bitcoincash:123, 15, bch]], change_address?:
...

POST wallet/utxos (low-level)
< wallet: hd:regtest:BHDIKHD, amount?: [0.1, 'bch'], strategy: least_utxos_count
> [["utxo": "123abc:0", "amount_sat": 12345, "amount_usd": 12.54, "amount_bch": 1.31, "txid": "123abc", "vout": 1], ["utxo": "123abc:1", ....]]
so you can now spend these utxos by providing a list like ["123abc:0", "123abc:1"] to "wallet/send"

POST wallet/calculate_max
< wallet: regtest:wif12345 # to is always 1 here
> txid: ...

POST wallet/send_max
< wallet: regtest:wif12345, to: bitcoincash:123 (or count of "to" addresses?)
> txid: ...

POST wallet/calculate_max_to_send
< wallet: regtest:wif12345, to: [[bitcoincash:123, 15, bch]]  (or count of "to" addresses?)

POST wallet/deposit_address
< wallet: regtest:wif12345
> cashaddr: bitcoincash:qalice123

< wallet: regtest:wif12345, rev_derivation_path: [0]
> cashaddr: bitcoincash:qalice123
We'll use reverse derivation path for convenience, so
[0] = m/44'/0'/0'/0/0/0
[1,2,3] = m/44'/0'/0'/3/2/1
m/44'/0'/0'/0/0/0 is the wallet used in Bitcoin.com wallet (which is super-popular) and it's very good to have this
compatibility, because you can always recommend to users to install this wallet

POST wallet/webhook/set
< wallet: regtest:wif12345 or cashaddr:..., url: https://, expires_in_days: ...
> id: ...

POST wallet/webhook/cancel
> id: ...

POST wallet/balance
< wallet: regtest:wif12345 or cashaddr:...
> incomplete, try again (for HD wallets)

POST wallet/balance/watch
< wallet: regtest:wif12345 or cashaddr:...

POST contract/escrow/create
< wallet: regtest:wif12345, arbiter: bitcoincash:...., buyer: bitcoincash:...., seller: bitcoincash:...
> contract: ...

POST contract/escrow/coins (low-level)
< contract: ...
> coins:

POST contract/escrow/finalize
< wallet: regtest:wif1234 or wif: ..., action: refund, complete (requires arbiter, buyer or seller key)

POST slp/mint
< ...
> ...

POST slp/send
< ...
(SLP postage?)
> ...

POST slp/balance
< ...
> ...

 POST sideshift/exchange
 < wallet: ...., from: BCH, to: USDH, to_address: ...

TODO: Non-Fungible tokens

TODO: SWaP protocol

TODO: AnyHedge ...

TODO: multisig (new, send?)

TODO: Encrypted messaging TODO: registerCashAccount TODO: Send to CashAccounts, phone numbers, emails

TODO: CashShuffle TODO: CashChannels #6 TODO: CashScript TODO: Spedn TODO: CashID (note) TODO: Reusable Payment Codes (note] TODO: CashFusion

Notes: