internal static SimpleWallet CreateNewSimpleWallet(string name, Password password, PrivateAccount account, NetworkType.Types network) { var encKey = new EncryptedPrivateKey(CryptoUtils.EncodePrivateKey(account.PrivateKey, password.Value)); var wlt = new WalletObject() { Accounts = new WalletAccounts() { Account = new List <WalletAccount> { new WalletAccount { Address = account.Address.Plain, Algo = "pass:bip32", Brain = false, Child = "", Encrypted = encKey.EncryptedKey, Iv = encKey.Iv, Label = "Primary", Network = network.GetNetwork() } } }, Name = name, PrivateKey = "" }; return(new SimpleWallet(name, network, wlt, encKey)); }
/// <summary> /// Create an Address from a given public key and network type. /// </summary> /// <param name="publicKey">The public key.</param> /// <param name="networkType">The network type</param> /// <returns>Address.</returns> public Address(string publicKey, NetworkType.Types networkType) { // step 1) sha-3(256) public key var digestSha3 = new KeccakDigest(256); var stepOne = new byte[Constants.Key]; digestSha3.BlockUpdate(publicKey.FromHex(), 0, Constants.Key); digestSha3.DoFinal(stepOne, 0); // step 2) perform ripemd160 on previous step var digestRipeMd160 = new RipeMD160Digest(); var stepTwo = new byte[Constants.Ripemd160]; digestRipeMd160.BlockUpdate(stepOne, 0, Constants.Key); digestRipeMd160.DoFinal(stepTwo, 0); // step3) prepend network byte var stepThree = new[] { networkType.GetNetwork() }.Concat(stepTwo).ToArray(); // step 4) perform sha3 on previous step var stepFour = new byte[Constants.Key]; digestSha3.BlockUpdate(stepThree, 0, Constants.Ripemd160 + 1); digestSha3.DoFinal(stepFour, 0); // step 5) retrieve checksum var stepFive = new byte[Constants.Checksum]; Array.Copy(stepFour, 0, stepFive, 0, Constants.Checksum); // step 6) append stepFive to resulst of stepThree var stepSix = new byte[Constants.AddressDecoded]; Array.Copy(stepThree, 0, stepSix, 0, Constants.Ripemd160 + 1); Array.Copy(stepFive, 0, stepSix, Constants.Ripemd160 + 1, Constants.Checksum); // step 7) return base 32 encode address byte array Initialize(stepSix.ToBase32String()); }