Ejemplo n.º 1
0
 /// <summary>
 /// Generate a DAppChain address for the given identity.
 /// Address generation is based on the identity public key and the chain ID,
 /// the algorithm is deterministic.
 /// </summary>
 /// <param name="identity">Identity with a valid public key.</param>
 /// <param name="chainId">Identifier of a DAppChain.</param>
 /// <returns>An address</returns>
 public static Address ToAddress(this Identity identity, string chainId = "default")
 {
     return(new Address
     {
         ChainId = chainId,
         Local = ByteString.CopyFrom(CryptoUtils.LocalAddressFromPublicKey(identity.PublicKey))
     });
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates an Address instance from a 32-byte public key.
 /// </summary>
 /// <param name="publicKey">32-byte public key.</param>
 /// <param name="chainId">Identifier of a DAppChain.</param>
 /// <returns>An address</returns>
 public static Address FromPublicKey(byte[] publicKey, string chainId = "default")
 {
     return(new Address
     {
         ChainId = chainId,
         Local = ByteString.CopyFrom(CryptoUtils.LocalAddressFromPublicKey(publicKey))
     });
 }
Ejemplo n.º 3
0
        private static string AddressStringFromPublicKey(byte[] publicKey)
        {
            if (publicKey == null)
            {
                throw new ArgumentNullException(nameof(publicKey));
            }

            if (publicKey.Length != 32)
            {
                throw new ArgumentException("Expected a 32-byte array", nameof(publicKey));
            }

            return(CryptoUtils.BytesToHexString(CryptoUtils.LocalAddressFromPublicKey(publicKey)));
        }