Skip to content

BaerChain OnlineWalletUse

weidong edited this page Jun 23, 2020 · 5 revisions

Guide to using online wallet

1. Online wallet compile and start Back Dir

  • 1.1 Compile the project

    • Execute the following command in the cpp-lsac / build directory: cmake .. && make to compile, if you have already executed the cmake .. command, you only need to execute: make command

    • In the directory cpp-lsac/build/wallet/http_wallet, find and find: httpWallet executable program, start operation

    • Remarks: The address generation method will call std::random_device to obtain a random number. This method is only allowed to be used in Linux; under specific platforms and specific versions, the entropy value of the random number obtained by std::random_device is insufficient, and the private key is in danger of being predicted.

  • View help:

./httpWallet -h
  • Parameter Description
command line :
  -h [ --help ]         show help message.
  -p [ --port ] arg     http listen port.
  -s [ --send ] arg     get the http ip and port, use this option will auto to send rawTransation to http host...

--port Online wallet http monitoring port. The default value is 8088.

--send [Optional] After signing the transaction, the wallet sends the transaction to the chain where the address is changed. If there is no such parameter, the parameter signature transaction will not be issued


1.2 Launch online wallet Back to Contents

./httpWallet -p 8081 -s http://127.0.0.1:8111

After starting, the program waits for http request


2 Use online wallet sign_transaction Back Dir

  • This instruction is only signed and not chained
2.1 Request sign_transaction data
  • request
    • Transaction signature returns transaction hash and transaction signature data, if there is an error this returns a response error prompt
{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "sign_transaction",
	"params": {
	    "param": {
		"source": [{
		  "from": "cccc7a30bf688c060524dfd759fe2627ed3387bc",
		  "to": "0x00000000000000000000000000000000766f7465",
		  "value": "0x0",
		  "data": [{
			"type": 2,
			"m_from": "cccc7a30bf688c060524dfd759fe2627ed3387bc",
			"m_to": "d0e89b32875f5a1d68ecbfb3995263adc3439bea",
			"m_transcation_type": 1,
			"m_transcation_numbers": "0x5f5e100"
		  }],
		  "chainId": "0x1",
		  "nonce": "0x18",
		  "gas": "0x138080",
		  "gasPrice": "0x5"
	  }],
	  "keys": ["AupMRj8bvnTwL5No6aE2LKR8hEa2KUZqGwrYMJAXSYuc"]
	  }
    }
}
2.2 Instruction example Back Dir
curl -d '{"jsonrpc":"2.0","id":1,"method":"sign_transaction","params":{ "param":{"source":[{"from":"cccc7a30bf688c060524dfd759fe2627ed3387bc","to":"0x00000000000000000000000000000000766f7465","value":"0x0","data":[{"type":2,"m_from":"cccc7a30bf688c060524dfd759fe2627ed3387bc","m_to":"d0e89b32875f5a1d68ecbfb3995263adc3439bea","m_transcation_type":1,"m_transcation_numbers":"0x5f5e100"}],"chainId":"0x1","nonce":"0x18","gas":"0x138080","gasPrice":"0x5"}],"keys":["AupMRj8bvnTwL5No6aE2LKR8hEa2KUZqGwrYMJAXSYuc"]}}}' http://127.0.0.1:8111

Remarks: Note that you need to add '' to the outermost {} curly bracket, please check the specific use of the instruction

2.3 Request parameter description Back Dir

The request is in jsonrpc standard format, in which:

2.4 Interface response Back Dir
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "hash": "0x581d17a13b5662846947e2bfcaa080cd1cb3a595df287f5db4b44920c76b04bf",
	"isSend": false,
	"rlp": "0xf8941805831380809400000000000000000000000000000000766f746580b4f3b2f10294cccc7a30bf688c060524dfd759fe2627ed3387bc94d0e89b32875f5a1d68ecbfb3995263adc3439bea01843b9aca0026a043725f6ba923e56e3651e4ed1ee53b7f2b7a32a653b3b6a749567a48a7df0f5da03c9041274bb23f636b9f8502825e9ea277f037afec3948ce269c4b1316263417"
  }
}
2.5 Response description Back Dir

The response result is in standard jsonrpc format. The interface call result is in the field "result"

  • (1). Interface call succeeded

    • hash : Transaction hash
    • rlp : Transaction rlp data
    • isSend : Whether to send to the chain, return false by default, this interface implements data signature, but does not go to the chain
  • (2). Interface call failed

    • Interface method name error
{
    "error": {
        "code": -32601,
        "message": "METHOD_NOT_FOUND: The method being requested is not available on this server"
    },
    "id": 1,
    "jsonrpc": "2.0"
}
  • (3). Interface parameter error
{
    "error": {
        "code": -32602,
        "message": "INVALID_PARAMS: Invalid method parameters (invalid name and/or type) recognised"
    },
    "id": 1,
    "jsonrpc": "2.0"
}
  • (4) Transaction json data error
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "error": "the data_json is error"
    }
}

3. Sign transaction and send (sign_transaction_send) Back Dir

  • This instruction is signed and chained
  • 3.1 Request sign_transaction_send data
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "sign_transaction_send",
  "params": {
   "param": {
	 "source": [{
	   "from": "cccc7a30bf688c060524dfd759fe2627ed3387bc",
	   "to": "0x00000000000000000000000000000000766f7465",
	   "value": "0",
	   "data": [{
		 "type": 2,
		 "m_from": "cccc7a30bf688c060524dfd759fe2627ed3387bc",
		 "m_to": "d0e89b32875f5a1d68ecbfb3995263adc3439bea",
		 "m_transcation_type": 1,
		 "m_transcation_numbers": "0x5f5e100"
		}],
	  "chainId": "0x1",
	  "nonce": "0x0",
	  "gas": "0x138080",
	  "gasPrice": "0x5"
	}],
	"keys": ["AupMRj8bvnTwL5No6aE2LKR8hEa2KUZqGwrYMJAXSYuc"]
   }
  }
}
curl -d '{"jsonrpc":"2.0","id":1,"method":"sign_transaction_send","params":{ "param":{"source":[{"from":"cccc7a30bf688c060524dfd759fe2627ed3387bc","to":"0x00000000000000000000000000000000766f7465","value":"0","data":[{"type":2,"m_from":"cccc7a30bf688c060524dfd759fe2627ed3387bc","m_to":"d0e89b32875f5a1d68ecbfb3995263adc3439bea","m_transcation_type":1,"m_transcation_numbers":"0x5f5e100"}],"chainId":"0x1","nonce":"0x0","gas":"0x138080","gasPrice":"0x5"}],"keys":["AupMRj8bvnTwL5No6aE2LKR8hEa2KUZqGwrYMJAXSYuc"]}}}' http://127.0.0.1:8111

Remarks: Note that you need to add '' to the outermost {} curly bracket, please check the specific use of the instruction

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
	"hash": "0x1bf48beac1498752d0b90466e6c237887c7f4caa20a91714b935ae174806f8d1",
	"rlp": "0xf8968005831380809400000000000000000000000000000000766f7465820100b4f3b2f10294cccc7a30bf688c060524dfd759fe2627ed3387bc94d0e89b32875f5a1d68ecbfb3995263adc3439bea01843b9aca0025a077abdfc6f0b4730fc1b5833dae5ed145732c9b45b96116960629463145c33feea01415dcff697067ca59bbd0ce65b29266d8da027bcb1829d627d17e816da66cbe",
	"sendRet": {
	"id": 1,
	"jsonrpc": "2.0",
	"result": "0x1bf48beac1498752d0b90466e6c237887c7f4caa20a91714b935ae174806f8d1"
	}
  }
}
  • 3.5 Return parameter description Back Dir

  • (1). Interface call succeeded

    • hash : transaction hsah
    • rlp : Transaction rlp data
    • sendRet : Return value of successful transaction(transaction hash)
  • (2). Interface call failed

    • Interface method name error : Same as sign_transaction interface failure

    • Interface parameter error : Same as sign_transaction interface failure

    • Transaction json data error : Same as sign_transaction interface failure

    • The signature is successful and the transmission is successful but the transaction fails (transaction nonce error), The specific error reason is as follows: "error" field returned

      {
          "id": 1,
          "jsonrpc": "2.0",
          "result": {
              "hash": "0xc65590930708d5d74678cce71a658dabe8b4253512b17ed977797e76299e22a8",
              "rlp": "0xf8960405831380809400000000000000000000000000000000766f7465820100b4f3b2f10294000000000000000000000000000000000000000094d0e89b32875f5a1d68ecbfb3995263adc3439bea01843b9aca0025a01d2c3bd9f4e6b51fa1d48427905e84d18740d9b85a0ccc9245c0ac3d14a53723a010c59dbed79a648781dc09c5dc020d1525abed5682bb880e841291f506952de5",
              "sendRet": {
                  "error": {
                      "code": 0,
                      "data": null,
                      "message": "Invalid transaction nonce.the sender Nonce error"
                  },
                  "id": 1,
                  "jsonrpc": "2.0"
              }
          }
      }
      
  • (3) httpWallet Start parameters --send (Parameter error, unable to send transaction to chain)

    {
        "id": 1,
        "jsonrpc": "2.0",
        "result": {
            "error": "send field check the send_url",
            "hash": "0xc65590930708d5d74678cce71a658dabe8b4253512b17ed977797e76299e22a8",
            "rlp": "0xf8960405831380809400000000000000000000000000000000766f7465820100b4f3b2f10294000000000000000000000000000000000000000094d0e89b32875f5a1d68ecbfb3995263adc3439bea01843b9aca0025a01d2c3bd9f4e6b51fa1d48427905e84d18740d9b85a0ccc9245c0ac3d14a53723a010c59dbed79a648781dc09c5dc020d1525abed5682bb880e841291f506952de5"
        }
    }
    

4. Apply to generate address and private key(new_address) Back Dir

  • request
{"jsonrpc":"2.0","method":"new_address","params":["2"],"id":1}
curl -d '{"jsonrpc":"2.0","method":"new_address","params":["2"],"id":1}' http://127.0.0.1:8111
  • Parameter Description
method : Method name
params : string, Represents the number of generated addresses, in this case 2
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
	"result": [{
	    "address": "6d9b912d847d146ab00eed2d8e23b1846d2567d4",
	    "pri-key-base58": "4nQVPAddSi67pNGWJwEo4gbuegn7m8ySXEfBVix8exEk",
	    "pri-key-bigInt": "3834c1b5a0f75c83ac5a4350af437df828da7d4c3e8a36bd3b69b6292fdcbeb1",
	    "pub-key": "206a7c04c5d5b06481e758fc559556e990944a6bc09690b95cf740c75f8797b684819aa084d09dd5758f0a75628abb773f2b95355a4ab557725289d49375c43f"
	},
	{
	    "address": "8a9f0ccae769f1b83858cd04d4ae8b0a988a32c0",
	    "pri-key-base58": "5idSd8sCeP2nqF4TkTiLSpkSSbQAc95zJeo6V8iopPCF",
	    "pri-key-bigInt": "4618c40693bd1fb8bedfa66f63bc094cc70aff0db0880174cd8e8690d6726f3c",
	    "pub-key": "c59504eacb630cad69bda4eac556d4625368205f9886416a023b5145fb4e583fbe49b46fb136ad331111e10062f637613ea935f96c8dbb42181ee267b4ddfba8"
         }
     ]}
}
  • Parameter Description
address        : Generated address
pri-key-base58 : base58 encoded private key
pri-key-bigInt : bigInt encoded private key
pub-key        : Public key

5. Principle of new address Back Dir

5.1 Principle of BearChain new address generation

  • 5.1.1 The new address is generated by hash base58 encoding according to the old address of BearChain
formula: newAddress =brc+base58(sha3(sha3(oldAddress))[0,4) + oldAddress)
  • 5.1.2 Description:
(1). First hash oldAddress twice, get the first 4 bits of the hash value to get: ret_hash: sha3(sha3(oldAddress))[0,4)
(2). Then splice ret_hash and oldAddress, and then get the base58: ret_base58 = base58( ret_hash+ oldAddress)
(3). Finally, splice with brc to get a new address newAddress = brc + ret_base58

5.2 New address generation example

  • Old address: oldAddress = 0xefee5b4be9ba66b2f371d305cd4e0788fa2c7661
(1). Old address hash 2 times:ret_hash2 = sha3(sha3(oldAddress))
	ret_hash2 = 0x8ea9e0ad5c06c04aedf99ba8a964b02ab4692acf5acce21ccd76b4fcbba48e4c
(2). Old address 2 times hash first 4:  hash_2_4  = ret_hash2[0,4)
	 hash_2_4 = 0x8ea9e0ad
(3). The old address is hashed twice with the old address: hash_oldAddress = hash_2_4 + oldAddress
	hash_oldAddress = 0x8ea9e0adefee5b4be9ba66b2f371d305cd4e0788fa2c7661
(4). New address: newAddress, the string “brc” is concatenated with the bese58 encoded string (hash_oldAddress_base58) of the concatenated address (hash_oldAddress) to obtain a new address
	newAddress = “brc”+base58(hash_oldAddress)
	newAddress = "brcE1LTYgazkmryZPpiDErSQBnBgcTpdJL2t"

5.3 New address to old address + verification example

  • new address: newAddress = "brcE1LTYgazkmryZPpiDErSQBnBgcTpdJL2t"
(1). Split "brc" and base58 encoding to get: old address and old address hash_2 after string base58 encoding
	hash_oldAddress_base58 = "E1LTYgazkmryZPpiDErSQBnBgcTpdJL2t"
(2).Base58 anti-coding results: the first 4 bits of the old address hash value and the old address string concatenation: hash_oldAddress = from_base58(hash_oldAddress_base58)
	hash_oldAddress = 0x8ea9e0adefee5b4be9ba66b2f371d305cd4e0788fa2c7661
(3). Split hash_oldAddress to get: the first 4 bits of the old address hash twice and the old address
	hash_2_4 = 0x8ea9e0ad
	oldAddress = 0xefee5b4be9ba66b2f371d305cd4e0788fa2c7661
(4). Verify the correctness of the address: hash the oldAddress twice: check_hash = sha3(sha3(Will get the oldAddress))
	check_hash = 0x8ea9e0ad5c06c04aedf99ba8a964b02ab4692acf5acce21ccd76b4fcbba48e4c
	Take the top 4 of check_hash and compare with hash_2_4
	check_hash == hash_2_4
	The new address is legal, get old address oldAddress=0xefee5b4be9ba66b2f371d305cd4e0788fa2c7661

Clone this wiki locally