アカウントとアドレス#

はじめに#

TRONはアカウントモデルを使用しています。アドレスはアカウントの一意の識別子であり、アカウントを操作するには秘密鍵の署名が必要です。アカウントには、TRXとトークンの残高、帯域幅、エネルギーなど、TRXとトークンの転送コスト帯域幅、スマートコントラクト関連の運用コストエネルギーなど、多くの属性があります。
アカウントは、スーパー代表候補になるために申請し、他のアカウントからの投票を受け入れることができます。アカウントは、TRONに関わる操作をする際の基礎となります。

アカウントの作成#

ウォレットまたはエクスプローラーを使用して、アドレスと秘密鍵を生成します。アカウントをアクティブ化するには、次の2つの方法を使用します。TRX/ TRC-10トークンをこのアドレスに転送します。もう1つの方法は、契約でTRX / TRC-10を転送することです。この操作には、さらに25,000のエネルギーがかかります。 既存のアカウントからCreateAccountコントラクトを呼び出します。
アカウントの作成には帯域幅のみがかかります。帯域幅が不十分な場合、TRXが焼却されます。
TRC20を転送しても、アカウントはアクティブ化されません。ただし、残高はTronscanから住所で問い合わせることができます。

Key-pair Generation#

Tronの署名アルゴリズムはECDSAであり、使用される曲線はSECP256K1です。
秘密鍵は乱数であり、対応する公開鍵は楕円曲線上の点です。
生成プロセス:
秘密鍵として乱数dを作成します。
P = d * Gを公開鍵として計算します。(Gは楕円曲線の基点です)

Address Format#

Use the public key P as the input, and use SHA3 get the result H. The length of the public key is 64 bytes (SHA3 uses Keccak256). Use the last 20 bytes of H, and add a byte of 0x41 as a prefix. Do a basecheck (see next paragraph), and the result will be the final address. All addresses start with 'T'.

Basecheck process: first run SHA256 on the address to get h1, then run SHA256 on h1 to get h2. Use the first 4 bytes as a checksum, add it to the end of the address (address||check). Finally, base58 encode address||check to get the final result.

Character map ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"

Signature#

Steps Transfer the rawdata of the transaction to byte[]. Run SHA256 on the rawdata. Use the private key to sign the result of step 2. Add the signature to the transaction.

Algorithm#

ECDSA, SECP256K

Example#

Java

priKey:::8e812436a0e3323166e1f0e8ba79e19e217b2c4a53c970d4cca0cfb1078979df?       
pubKey::04a5bb3b28466f578e6e93fbfd5f75cee1ae86033aa4bbea690e3312c087181eb366f9a1d1d6a437a9bf9fc65ec853b9fd60fa322be3997c47144eb20da658b3d1?        
hash:::159817a085f113d099d3d93c051410e9bfe043cc5c20e43aa9a083bf73660145?        
r:::38b7dac5ee932ac1bf2bc62c05b792cd93c3b4af61dc02dbb4b93dacb758123f?        
s:::08bf123eabe77480787d664ca280dc1f20d9205725320658c39c6c143fd5642d?        
v:::0

Note: The size of the signature result is 65 bytes:

r = 32 bytes
s = 32 bytes
v = 1 byte
Full node verifies the signature once receiving a transaction; it generates an address with the value of hash, r, s, and v, then it compares with the address in the transaction.

Demo#

Java

public static Transaction sign(Transaction transaction, ECKey myKey) {
    Transaction.Builder transactionBuilderSigned = transaction.toBuilder();
    byte[] hash = sha256(transaction.getRawData().toByteArray());
    List<Contract> listContract = transaction.getRawData().getContractList();

    for (int i = 0; i < listContract.size(); i++) {
      ECDSASignature signature = myKey.sign(hash);
      ByteString bsSign = ByteString.copyFrom(signature.toByteArray());

      //Each contract may be signed with a different private key in the future.
      transactionBuilderSigned.addSignature(bsSign);
    }
  }