Cryptopunk.Crypto.Tron (cryptopunk v0.7.7)

Tron address generation logic.

Summary

Functions

Link to this function

address(key, network \\ :mainnet)

@spec address(Cryptopunk.Key.t(), atom()) :: String.t()

Generate a tron address.

It accepts two parameters:

  • public or private key. if a private key is provided, it will be converted to public key.
  • network (:mainnet or :testnet)

Examples:

iex> private_key = %Cryptopunk.Key{key: <<16, 42, 130, 92, 247, 244, 62, 96, 24, 129, 187, 141, 124, 42, 176, 116, 234, 171, 184, 107, 3, 229, 255, 72, 30, 116, 79, 243, 36, 142, 184, 24>>, type: :private}
iex> Cryptopunk.Crypto.Tron.address(private_key, :mainnet)
"TLaEVB6foF9nPn4sqscXc5jeH1PVyLwwFK"

iex> public_key = %Cryptopunk.Key{key: <<4, 57, 163, 96, 19, 48, 21, 151, 218, 239, 65, 251, 229, 147, 160, 44, 197, 19, 208, 181, 85, 39, 236, 45, 241, 5, 14, 46, 143, 244, 156, 133, 194, 60, 190, 125, 237, 14, 124, 230, 165, 148, 137, 107, 143, 98, 136, 143, 219, 197, 200, 130, 19, 5, 226, 234, 66, 191, 1, 227, 115, 0, 17, 98, 129>>, type: :public}
iex> Cryptopunk.Crypto.Tron.address(public_key, :testnet)
"27PaDLFYbGN9ztPPT3YiTatLQEdEJ2xsfWM"
Link to this function

valid?(address)

@spec valid?(binary()) :: boolean()

Validate a tron address

Examples:

iex> Cryptopunk.Crypto.Tron.valid?("TLHv3v5EuMQgdkghMaj5AAWy6bE4tu2qi2")
true

iex> Cryptopunk.Crypto.Tron.valid?("0xea0a6e3c511bbd10f4519ece37dc24887e11b55D")
false
Link to this function

validate_address(address)

@spec validate_address(binary()) :: :ok | {:error, atom()}