Skip to content

BaerChain OfflineWalletUse

weidong edited this page Jun 23, 2020 · 7 revisions

Guide to using an offline wallet


1. Method for generating address and private key Back Dir

1.1 Generate address and private key process

  • Execute in the compilation directory, get cmdWallet execution file
cd cpp-lsac/build : Enter the directory
cmake ..          : Execute instruction
make              : Execute instruction
cd cpp-lsac/build/wallet/cmdWallet : 此目录下可找到刚才编译好的cmdWallet执行文件

  • run
 ./wallet/cmdWallet/cmdWallet -g 1
  • The program will randomly generate a private key and address
private-key: wDnHJb3kRV7YnUojQ6sjYnfbe93vK1YVCHHPV71GAcA
address    : a49c22485d140e7c725a9d40ce801d19dbb88784
public-key : cd4846e7f5ab2d29e85e033f89cb7000a49bd223ca9fd5df5ef7c162740a7cb1336006807d5e2b8d1c6760922e7399e8ffd3261a16f4c33dd81a41a31822600f
  • 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.

  • The method of generating the address and private key in the above process is for reference only, and can be generated by yourself.

1.2 base58 convert private key formatOne Back Dir

  • run
./cmdWallet --pri-tf wDnHJb3kRV7YnUojQ6sjYnfbe93vK1YVCHHPV71GAcA
  • Return result
address : a49c22485d140e7c725a9d40ce801d19dbb88784
pri-base58 : wDnHJb3kRV7YnUojQ6sjYnfbe93vK1YVCHHPV71GAcA
pri-big int : 0de3d09c2ee9e4c34e47a68edea0ebec6386e9477e6b5c389ff5bfbe8dd34a53
public address : cd4846e7f5ab2d29e85e033f89cb7000a49bd223ca9fd5df5ef7c162740a7cb1336006807d5e2b8d1c6760922e7399e8ffd3261a16f4c33dd81a41a31822600f

From the returned results, we can see: pri-big int: 0de3d09c2ee9e4c34e47a68edea0ebec6386e9477e6b5c389ff5bfbe8dd34a53 is the private key conversion format we need to get

1.3 base58 convert private key formatTwo Back Dir

  • Command
    • Note: At this time, you need to add 0x, such as: 0x0de3d09c2ee9e4c34e47a68edea0ebec6386e9477e6b5c389ff5bfbe8dd34a53
./cmdWallet --pri-tf 0x0de3d09c2ee9e4c34e47a68edea0ebec6386e9477e6b5c389ff5bfbe8dd34a53
  • Return result
address : a49c22485d140e7c725a9d40ce801d19dbb88784
pri-base58 : wDnHJb3kRV7YnUojQ6sjYnfbe93vK1YVCHHPV71GAcA
pri-big int : 0de3d09c2ee9e4c34e47a68edea0ebec6386e9477e6b5c389ff5bfbe8dd34a53
public address : cd4846e7f5ab2d29e85e033f89cb7000a49bd223ca9fd5df5ef7c162740a7cb1336006807d5e2b8d1c6760922e7399e8ffd3261a16f4c33dd81a41a31822600f

It can be seen from the returned result: pri-base58: wDnHJb3kRV7YnUojQ6sjYnfbe93vK1YVCHHPV71GAcA is the format after conversion of the private key we need

2. Use of offline wallet Back Dir

3. Principle of new address Back Dir

3.1 Principle of BearChain new address generation

  • 3.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)
  • 3.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

3.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"

3.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