private static string GenerateWif(string passphrase, Network network, LotSequence lotsequence, byte[] ownersalt)
        {
            bool hasLotSequence = lotsequence != null;

            //ownersalt is 8 random bytes
            ownersalt = ownersalt ?? RandomUtils.GetBytes(8);
            var ownerEntropy = ownersalt;

            if (hasLotSequence)
            {
                ownersalt    = ownersalt.Take(4).ToArray();
                ownerEntropy = ownersalt.Concat(lotsequence.ToBytes()).ToArray();
            }


            var prefactor  = SCrypt.BitcoinComputeDerivedKey(Encoding.UTF8.GetBytes(passphrase), ownersalt, 32);
            var passfactor = prefactor;

            if (hasLotSequence)
            {
                passfactor = Hashes.Hash256(prefactor.Concat(ownerEntropy).ToArray()).ToBytes();
            }

            var passpoint = new Key(passfactor, fCompressedIn: true).PubKey.ToBytes();

            var bytes =
                network.GetVersionBytes(Base58Type.PASSPHRASE_CODE)
                .Concat(new[] { hasLotSequence ? (byte)0x51 : (byte)0x53 })
                .Concat(ownerEntropy)
                .Concat(passpoint)
                .ToArray();

            return(Encoders.Base58Check.EncodeData(bytes));
        }
示例#2
0
 internal static byte[] CalculatePassFactor(string password, LotSequence lotSequence, byte[] ownerEntropy)
 {
     byte[] passfactor;
     if (lotSequence == null)
     {
         passfactor = SCrypt.BitcoinComputeDerivedKey(Encoding.UTF8.GetBytes(password), ownerEntropy, 32);
     }
     else
     {
         var ownersalt = ownerEntropy.SafeSubarray(0, 4);
         var prefactor = SCrypt.BitcoinComputeDerivedKey(Encoding.UTF8.GetBytes(password), ownersalt, 32);
         passfactor = Hashes.Hash256(prefactor.Concat(ownerEntropy).ToArray()).ToBytes();
     }
     return(passfactor);
 }
 public BitcoinPassphraseCode(string passphrase, Network network, LotSequence lotsequence, byte[] ownersalt = null)
     : base(GenerateWif(passphrase, network, lotsequence, ownersalt), network)
 {
 }
        public override bool Equals(object obj)
        {
            LotSequence item = obj as LotSequence;

            return(item != null && Id.Equals(item.Id));
        }