Ejemplo n.º 1
0
        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.CoinComputeDerivedKey(Encoding.UTF8.GetBytes(passphrase), ownersalt, 32);
            var passfactor = prefactor;

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

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

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

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

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