public EncryptedKeyResult(CoinEncryptedSecretEC key, CoinAddress address, byte[] seed, Func <CoinConfirmationCode> calculateConfirmation) { _EncryptedKey = key; _GeneratedAddress = address; _CalculateConfirmation = calculateConfirmation; _Seed = seed; }
public override bool Equals(object obj) { CoinAddress item = obj as CoinAddress; if (item == null) { return(false); } return(_Str.Equals(item._Str)); }
public bool Check(string passphrase, CoinAddress expectedAddress) { //Derive passfactor using scrypt with ownerentropy and the user's passphrase and use it to recompute passpoint byte[] passfactor = CoinEncryptedSecretEC.CalculatePassFactor(passphrase, LotSequence, OwnerEntropy); //Derive decryption key for pointb using scrypt with passpoint, addresshash, and ownerentropy byte[] passpoint = CoinEncryptedSecretEC.CalculatePassPoint(passfactor); byte[] derived = CoinEncryptedSecretEC.CalculateDecryptionKey(passpoint, AddressHash, OwnerEntropy); //Decrypt encryptedpointb to yield pointb var pointbprefix = EncryptedPointB[0]; pointbprefix = (byte)(pointbprefix ^ (byte)(derived[63] & (byte)0x01)); //Optional since ArithmeticException will catch it, but it saves some times if (pointbprefix != 0x02 && pointbprefix != 0x03) { return(false); } var pointb = CoinEncryptedSecret.DecryptKey(EncryptedPointB.Skip(1).ToArray(), derived); pointb = new byte[] { pointbprefix }.Concat(pointb).ToArray(); //4.ECMultiply pointb by passfactor. Use the resulting EC point as a public key var curve = ECKey.Secp256k1; ECPoint pointbec; try { pointbec = curve.Curve.DecodePoint(pointb); } catch (ArgumentException) { return(false); } catch (ArithmeticException) { return(false); } PubKey pubkey = new PubKey(pointbec.Multiply(new BigInteger(1, passfactor)).GetEncoded()); //and hash it into address using either compressed or uncompressed public key methodology as specifid in flagbyte. pubkey = IsCompressed ? pubkey.Compress() : pubkey.Decompress(); var actualhash = CoinEncryptedSecretEC.HashAddress(pubkey.GetAddress(Network)); var expectedhash = CoinEncryptedSecretEC.HashAddress(expectedAddress); return(Utils.ArrayEqual(actualhash, expectedhash)); }
/// <summary> /// Take the first four bytes of SHA256(SHA256(generatedaddress)) and call it addresshash. /// </summary> /// <param name="address"></param> /// <returns></returns> public static byte[] HashAddress(CoinAddress address) { return(Hashes.Hash256(Encoders.ASCII.DecodeData(address.ToString())).ToBytes().Take(4).ToArray()); }