CodeChain and Regular Key

Park Juhyung
CodeChain
Published in
3 min readApr 29, 2019

Let’s find out what regular keys are, and how to use them.

Photo by James Sutton on Unsplash

Secret Key and Blockchain

In a blockchain, the hash value of the public key, or the public key itself, which is a pair with the secret key, is used as an address to give and receive money. In other words, a secret key represents one’s identity on a blockchain.

Problems that Arise Without Regular Keys

While secret keys are being used, there may be situations where a user has to change that secret key due to reasons such as secret key theft. In this situation, the user will be unable to use the address used with the stolen secret key. In the perspective of a service provider, this can be a critical issue. For instance, users may send tokens to an address that has been changed or no longer accessible. Tokens sent to such addresses will be lost forever.

A Solution Via Regular Keys

The problem mentioned above arises due to the secret key having multiple functions. One function is for proving one’s identity and the other is one’s public address. Is it absolutely necessary to create an address out of the secret key, which is used for signatures?

A solution is to use regular keys. The address is created by using the master key. Then the master key will be stored in a cold storage where there is no network connectivity. When users need to sign something, they would use the regular key. Under this type of model, even if something were to happen to the regular key, a new regular key can be created, making the old regular key invalid, while keeping the same address.

Using a Regular Key

Let’s learn how to use the SDK to take full advantage of the regular key. If this is your first time using CodeChain’s SDK, then read this article by JinGyeong.

We will be taking a look at the following examples:

  1. Randomly create a regular key pair (secret/public).
  2. Register the newly created regular key to an existing master key.
  3. Send a transaction that has been signed by a regular key.
  4. Check whether the regular key has been stored properly by verifying the processing fee that has been charged in the master account.

To facilitate your understanding, here is the relationship between the master and regular key:

Here is an example of code that creates a regular by using the SDK:

Let’s register the newly created regular key in an existing master account.

From this point, you can use the regular key instead of the master key to sign transactions.

The code below is an example of sending CCC to another person by using the regular key instead of the master secret key:

If you look at code closely, the difference in using a regular key instead of the master key occurs when signing a transaction. By applying such small changes, it was possible to differentiate keys for different purposes.

Points of Caution

It is only possible to sign with a regular key after the block that contains the SetRegularKey transaction has been mined. Thus, if you send the SetRegularKey transaction and a transaction that has been signed with that regular key at the same time, it is possible that the transaction that has been signed with the regular key may not be processed. This is because CodeChain prevents transactions that cannot be processed at that point in time from being sent to the P2P network at all. Thus, it is crucial to check whether the regular key has been properly registered before using that regular key to sign off transactions.

Conclusion

CodeChain supports regular keys for service providers, such as game companies, that cannot randomly stop their services to cope with emergency situations where their address must change. I hope this article helps you understand what regular keys are and how to register and use regular keys using the CodeChain SDK.

--

--