Skip to content

Trustchain Developer Notes

lukehare edited this page Feb 22, 2023 · 24 revisions

Using ION

Subscription details

  • Subscription: MOSIP Development
  • Subscription ID: a8604fcd-7cc8-4801-a975-a4b777a179a4
  • Resource group: ION_group
  • VM: ION

Restarting the ION node

NOTE: Before following these instructions you will need to first start up the ION VM on the Azure portal (details above).

Basic set-up

  • Terminal/tmux
  • VS code for editing documents

Quick version

Below is a quick-start version of the ION start-up instructions:

# Open new terminal
ssh ion
ipfs daemon
# Open new tab
ssh ion
sudo systemctl start mongod
bitcoind -daemon
tail -f /data/.bitcoin/testnet3/debug.log
# Open new tab, wait until progress is 1.0000
ssh ion
cd ion
npm run bitcoin
# Open new tab, wait until previous command has initialized
ssh ion
cd ion
npm run core

Steps

  1. Login: ssh [email protected]
  2. Start IPFS: ipfs daemon
    • Note: this hogs the shell
    • Stop: ipfs shutdown
  3. Start Mongo DB: sudo systemctl start mongod
    • Check status: sudo systemctl status mongod
    • Stop: sudo systemctl stop mongod
    • Restart: sudo systemctl restart mongod
  4. Start Bitcoin core v0.20.1 (on testnet): bitcoind -daemon
    • Note: bitcoind is an alias for ~/bitcoin/bitcoin-0.20.1/bin/bitcoind -conf=/data/bitcoin.conf -daemon
    • Or to reindex (may take >1 hour): bitcoind -conf=/data/bitcoin.conf -reindex-chainstate
    • Check log: tail -f /data/.bitcoin/testnet3/debug.log
    • To check block height: bitcoin-cli -getinfo
    • NOTE: this also shows wallet balances
    • Compare with the network: Testnet Explorer
    • Stop: bitcoin-cli stop
    • Note: bitcoin-cli is an alias for ~/bitcoin/bitcoin-0.20.1/bin/bitcoin-cli -conf=/data/bitcoin.conf
    • Check which port bitcoind is listening on: netstat -tulpn | grep 'bitcoind'. Should be 18333 for testnet (8333 for mainnet).
  5. Temporary workaround for this upstream issue
    • Nothing to do here (just a note). With a slightly modified BitcoinClient.js (see #379), and an updated bitcoin.conf to load the sidetreeDefaultWallet wallet on startup to workaround the loadwallet issue.
    • Can check with bitcoin-cli listwallets
  6. Start the ION bitcoin service (hogs the shell)
    cd ~/ion
    npm run bitcoin >> .out_<DDMMYY> &
    
    • If you get an ECONNREFUSED error, make sure bitcoind has started and is listening on the expected port.
    • If the loadwallet jRPC call fails, see the comments in #379 (but the Temporary workaround above should avoid it).
    • Once this is successful, you can retrieve the transaction hash for later check. Once you have a hash for a transaction later, you can find it e.g. here.
  7. Start ION core service (hogs the shell)
    cd ~/ion
    npm run core >> .out_core_<DDMMYY> &
    

The npm run core and npm run bitcoin must be started in this order.

  1. Test by navigating here, or:
    curl http://localhost:3000/identifiers/did:ion:test:EiClWZ1MnE8PHjH6y4e4nCKgtKnI1DK1foZiP61I86b6pw | json_pp
    

Note: This does not work from Turing wifi because the link is not https

Working on local machine

You can use your local machine to work with the ION server on the VM by port forwarding:

ssh -N -L 3000:localhost:3000 [email protected]

And test by running a resolution on your local machine:

curl http://localhost:3000/identifiers/did:ion:test:EiClWZ1MnE8PHjH6y4e4nCKgtKnI1DK1foZiP61I86b6pw | json_pp

In order to run the full suite of Trustchain integration tests, you will need to port forward not only the ION server but also the MongoDB server (port 27017) and Bitcoin Core JSON-RPC server (port 18332 for testnet or 8332 for mainnet):

ssh -N -L 27017:localhost:27017 [email protected]

and

ssh -N -L 18332:localhost:18332 [email protected]

SSH config file

To make it easier to log in to the VM, you can set-up your ssh config (~/.ssh/config) like this:

Host ion
    HostName 51.104.16.53
    User ionuser
    IdentityFile ~/.ssh/<NAME_OF_VM_KEY>
    LocalForward 3000 localhost:3000
    LocalForward 18332 localhost:18332
    LocalForward 27017 localhost:27017
    LocalForward 5001 localhost:5001

Create a DID

Inside ~/ion

ion operation create

This yields something that looks like:

```text
DID: did:ion:EiDqmkY_CG6h9rudRXt94wuQJj8G69q32Kh1G9PbWJCnFw

Recovery private key saved as: EiDqmkY_CG6h9rudRXt94wuQJj8G69q32Kh1G9PbWJCnFw-RecoveryPrivateKey.json
Update private key saved as: EiDqmkY_CG6h9rudRXt94wuQJj8G69q32Kh1G9PbWJCnFw-UpdatePrivateKey.json
Signing private key saved as: EiDqmkY_CG6h9rudRXt94wuQJj8G69q32Kh1G9PbWJCnFw-SigningPrivateKey.json

Create request body:
{
 "type": "create",
     "suffixData": {
   "deltaHash": "EiAABMUcyfJ7RszfEVS8h1BPnkBEL-4LsHTXr2-nmqf9Zg",
   "recoveryCommitment": "EiCGw_hcyNgiInK8A6vnJYJizMDKTBUXqOUVHYXr1qO-FA"
 },
 "delta": {
   "updateCommitment": "EiDi3RbRDGOvE0sqjc9vBVOEt2d9DNG-0dhbLfeilYm8Iw",
   "patches": [
     {
       "action": "replace",
       "document": {
         "publicKeys": [
           {
             "id": "signing-key",
             "type": "EcdsaSecp256k1VerificationKey2019",
             "publicKeyJwk": {
               "kty": "EC",
               "crv": "secp256k1",
               "x": "Fb0vramqPql8Rc3G2U0iVtOTwiD5NipNYxCIpWBfMDk",
               "y": "M2krAHJnTdcXYQjBn9ydTM7YcMDJzv2NkAYt7ZCQito"
             }
           }
         ]
       }
     }
   ]
 }
}

Long-form DID:
did:ion:EiDqmkY_CG6h9rudRXt94wuQJj8G69q32Kh1G9PbWJCnFw:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJzaWduaW5nLWtleSIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiJGYjB2cmFtcVBxbDhSYzNHMlUwaVZ0T1R3aUQ1TmlwTll4Q0lwV0JmTURrIiwieSI6Ik0ya3JBSEpuVGRjWFlRakJuOXlkVE03WWNNREp6djJOa0FZdDdaQ1FpdG8ifSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRGkzUmJSREdPdkUwc3FqYzl2QlZPRXQyZDlETkctMGRoYkxmZWlsWW04SXcifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUFBQk1VY3lmSjdSc3pmRVZTOGgxQlBua0JFTC00THNIVFhyMi1ubXFmOVpnIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlDR3dfaGN5TmdpSW5LOEE2dm5KWUppek1ES1RCVVhxT1VWSFlYcjFxTy1GQSJ9fQ

DID suffix data:
{
 "deltaHash": "EiAABMUcyfJ7RszfEVS8h1BPnkBEL-4LsHTXr2-nmqf9Zg",
 "recoveryCommitment": "EiCGw_hcyNgiInK8A6vnJYJizMDKTBUXqOUVHYXr1qO-FA"
}

Document delta:
{
 "updateCommitment": "EiDi3RbRDGOvE0sqjc9vBVOEt2d9DNG-0dhbLfeilYm8Iw",
 "patches": [
   {
     "action": "replace",
     "document": {
       "publicKeys": [
         {
           "id": "signing-key",
           "type": "EcdsaSecp256k1VerificationKey2019",
           "publicKeyJwk": {
             "kty": "EC",
             "crv": "secp256k1",
             "x": "Fb0vramqPql8Rc3G2U0iVtOTwiD5NipNYxCIpWBfMDk",
             "y": "M2krAHJnTdcXYQjBn9ydTM7YcMDJzv2NkAYt7ZCQito"
           }
         }
       ]
     }
   }
 ]
}

This file can be redirected instead:

ion operation create > ~/ion/test_publish/create-request-body
  • To publish the DID, you take the request body:
{
  "type": "create",
  "suffixData": {
    "deltaHash": "EiAzt3kr6iE8iOSyrrnHEEvqTwA9L0G5TyHyKWXU_MY67w",
    "recoveryCommitment": "EiDqu1V9O2cjj2ibwXtdHvQqztMOorLgLPL-3pPSIpuz-A"
  },
  "delta": {
    "updateCommitment": "EiAswFCC0u_7dPm9vNPMtx-ASXFwbt6GK3lz5Y_zPKFt8g",
    "patches": [
      {
        "action": "replace",
        "document": {
          "publicKeys": [
            {
              "id": "signing-key",
              "type": "EcdsaSecp256k1VerificationKey2019",
              "publicKeyJwk": {
                "kty": "EC",
                "crv": "secp256k1",
                "x": "_NseShHvFIyA43uKX9F5_ybr5bDLo0bqZd-x1lhYk7g",
                "y": "rvgBvMmzGh350_YTr5UxHpCaTskymdtLfXkb53EM3Dk"
              }
            }
          ]
        }
      }
    ]
  }
}

and write it to a file:

~/ion/test_publish/request-body-EiAzt3kr6iE8iOSyrrnHEEvqTwA9L0G5TyHyKWXU_MY67w.json
curl --tr-encoding -X POST -v -# -o output -T ~/ion/test_publish/request-body-EiAzt3kr6iE8iOSyrrnHEEvqTwA9L0G5TyHyKWXU_MY67w.json -H "Content-Type: application/json; charset=utf-8" http://localhost:3000/operations
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /operations HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.58.0
> Accept: */*
> Connection: TE
> TE: gzip
> Content-Type: application/json; charset=utf-8
> Content-Length: 788
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
} [788 bytes data]
* We are completely uploaded and fine
########################################################################### 100.0%< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Content-Length: 824
< Date: Mon, 18 Jul 2022 14:15:32 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
{ [824 bytes data]
########################################################################### 100.0%* Connection #0 to host localhost left intact