Giter Club home page Giter Club logo

server's Introduction

Cosmic Bridge

Dependency Status devDependencies Status

Server node for the Cosmic Bridge application. Manages tracking payments/balance on the Cosmos chain and bundled scheduled payouts on the Bitcoin mainnet.

For architectural overview, see here: https://docs.google.com/presentation/d/1-8MP2yRhTy7D1YDUiauJoJ1g_ppXQbRpk0YTQ0ZFEzw/edit#slide=id.g3772f84a12_0_18

Concept

The Cosmic Bridge server node serves as a validator/facilitator of transactions.

The funds are stored in a multi-sig wallet ; any payment needs to be properly signed by a subset of the validators.

In order to participate in the Cosmic Bridge network, a user should send bitcoin to a particular payment zone address - a specific wallet on the Bitcoin blockchain. Once bitcoin has been received, users can micro-transact bitcoin on a Cosmos chain (this chain is the "payment zone"). The balances can be paid out on-demand on the Bitcoin chain, vastly reducing the number of required transactions (and hence the transaction fees paid) as the number of transactions on the off-chain network increases.

The end result is that users save transaction fees by bundling up transactions on the bitcoin network while still enjoying transparency and safety. In return, the complete trustlessness of the Bitcoin chain is exchanged with a degree of trust in the validator set of the payment zone. This compromise can be acceptable for many potential uses, such as large volumes of micropayments.

Potential Uses

Cosmic Bridge can be used for any application that requires cheap, fast and auditable settlement of Bitcoin transactions, assuming on-demand Bitcoin-chain settlement is acceptable. Payment Zones can be free for anyone to join, or limited to certain parties. In theory, the longer users maintain and use the balances on the cosmos bridge network, the more optimizations can be done in terms of payment merging. Some potential applications:

  • Bitcoin micropayments
  • Dark pools of BTC liquidity between exchanges or large traders
  • A merchant network supporting free bitcoin payments for participating merchants

Staking

Right now the system does not involve stake mechanics, since the idea is to rely on a trusted, well-known set of validators. In the future, staking mechanics, based on BTC staking or a native token, could be implemented easily as Cosmos supports them.

How it works

Connecting to the payment zone is done via the Tendermint API. Transactions have a 'command' field that indicates the type of transaction. Following are examples for possible transactions:

  • Deposit - process a deposit made on the Bitcoin chain to the Payment Zone master address, so the bitcoin can be used for payments in the Cosmic Bridge Payment Zone:

    curl http://localhost:PORT/txs -d '{"command": "deposit", "txHash": "<Transaction ID of the Bitcoin transaction>"}'

  • Pay - perform a payment within the payment zone.

    For instance, to perform a microtransaction of 1 satoshi from ADDRESS1 to ADDRESS2:

    curl http://localhost:PORT/txs -d '{"command": "pay", "amount": 1, "from": "ADDRESS1", "to": "ADDRESS2", "signature": "<XXX - see below>"}'

    The signature is a proof of ownership. It should be the transaction ID of one of the deposit transactions to the 'from' address, signed with that address' private key. Note that the depositing Bitcoin addresses are used for transaction addressing within the Payment Zone (e.g. on the Cosmos chain) as well - there's no need for "new" or Cosmic-Bridge-specific addresses.

Checking the app state (Balances).

To check the balance of ADDRESS1, just do:

curl http://localhost:PORT/state

Which returns a JSON dictionary, and then use the key 'balances' and then key 'ADDRESS1' to get the balance for ADDRESS1

Setup

Examine the config files first.

If you're creating a new payment zone (or app), you should create a new multisig wallet for the master address. This can be done from the src/multisig folder by running the create_multisig.js script.

Configuration files are loaded from the /config sub-directory. The file default.json contains development configuration values, while production.json contains production (mainnet) configuration values.

Running the Cosmic Bridge app (creating a payment zone).

WARNING: This is a work-in-progress towards a MVP. Do NOT, under any circumstanes, use this in production. The current implementation has MULTIPLE, VERY OBVIOUS security flaws. You have been warned!!!

To start a Cosmic Bridge node, run the following command:

npm install && npm start

bcoin is required on every validator node in order to test transactions for correctness and submit transactions to the bitcoin network. Indexing of transactions and addresses is required in order to support the queries done by the validator nodes. Set your /.bcoin/bcoin.conf file with new values like the following (for testnet):

`bcoin.conf`
  network: testnet
  prefix: ~/.bcoin
  api-key: hunter2
  prune: false
  index-tx: true
  index-address: true

or use the following command:

bcoin --http-host=0.0.0.0 --api-key hunter2 --network=testnet --daemon --index-tx --index-address

removing the network flag for mainnet deployments. Note that the index-tx and index-address flags are required by the node in order to perform historic queries on the master address.

Running tests (jest):

  npm test

Notes for production use

For a mainnet app, you'll want to define a set of validators as well as a genesis block so the app doesn't create a new GCI each time the app is run. This is documented further in the initial state of lotion_app.js.

Useful Links

Powered by the Lotion dapp framework:

server's People

Contributors

cbonoz avatar itamarro avatar lidarwin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

server's Issues

Implement the master wallet multi-sig management logic

Its general design is detailed in the deck: https://docs.google.com/presentation/d/1-8MP2yRhTy7D1YDUiauJoJ1g_ppXQbRpk0YTQ0ZFEzw/edit#slide=id.g365dfefbd4_0_5

In short, the funds in the payment zone's master bitcoin wallet are locked by the keys of all of the payment zone's validators. Managing this includes generating the master address for receiving user funds, sending funds out and signing those transactions, key management as the validator set changes, etc.

Close details of addressing on the Cosmos Payment Zone

Ideally, a user will have the same address - his Bitcoin address - in any Cosmos Payment Zone he's a member of. (e.g. in any PZ he sent funds to.)

However, I don't really know how addressing works in Cosmos. If the above simple way won't work, we'll need to think of the next simplest way for addressing. Perhaps by mapping transparently on the server side from bitcoin address to the Cosmos PZ address. The client (wallet) will always use the BTC address, but the server will translate it to CPZ address before doing operations on the CPZ chain.

Create periodical settlement logic

Code needs to run every K seconds (configurable K), settle the balances on the Bitcoin chain from the balances on the Cosmos PZ chain, and update the Cosmos PZ balances accordingly.

Create core module

Create main lotion.js server with shell endpoints / mocked interactions with bcoin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.