Example #1
0
 public byte[] GetAesKey(Secp256r1Point pubkey)
 {
     byte[] prikey = new byte[32];
     ProtectedMemory.Unprotect(key_exported, MemoryProtectionScope.SameProcess);
     Buffer.BlockCopy(key_exported, 8 + 64, prikey, 0, 32);
     ProtectedMemory.Protect(key_exported, MemoryProtectionScope.SameProcess);
     byte[] aeskey = (pubkey * prikey).EncodePoint(false).Skip(1).Sha256();
     Array.Clear(prikey, 0, prikey.Length);
     return aeskey;
 }
Example #2
0
 public bool Add(byte[] redeemScript, Secp256r1Point pubkey, byte[] signature)
 {
     UInt160 scriptHash = redeemScript.ToScriptHash();
     for (int i = 0; i < ScriptHashes.Length; i++)
     {
         if (ScriptHashes[i] == scriptHash)
         {
             if (signatures[i] == null)
                 signatures[i] = new MultiSigContext(redeemScript);
             return signatures[i].Add(pubkey, signature);
         }
     }
     return false;
 }
 void ISignable.DeserializeUnsigned(BinaryReader reader)
 {
     this.PrevHash = reader.ReadSerializable<UInt256>();
     this.Miner = Secp256r1Point.DeserializeFrom(reader);
     this.NoncePieces.Clear();
     int count = (int)reader.ReadVarInt();
     for (int i = 0; i < count; i++)
     {
         Secp256r1Point key = Secp256r1Point.DeserializeFrom(reader);
         byte[] value = reader.ReadBytes((int)reader.ReadVarInt());
         NoncePieces.Add(key, value);
     }
     this.MerkleRoot = reader.ReadSerializable<UInt256>();
 }
Example #4
0
 public bool Add(Secp256r1Point pubkey, byte[] signature)
 {
     if (signature.Length != 64)
         throw new ArgumentException();
     for (int i = 0; i < pubkeys.Length; i++)
     {
         if (pubkeys[i] == pubkey)
         {
             if (signatures[i] != null)
                 return false;
             signatures[i] = signature;
             return true;
         }
     }
     return false;
 }
 public override void Deserialize(BinaryReader reader)
 {
     this.PrevHash = reader.ReadSerializable<UInt256>();
     this.Miner = Secp256r1Point.DeserializeFrom(reader);
     this.NoncePieces.Clear();
     int count = (int)reader.ReadVarInt();
     for (int i = 0; i < count; i++)
     {
         Secp256r1Point key = Secp256r1Point.DeserializeFrom(reader);
         if (key == Miner) throw new FormatException();
         byte[] value = reader.ReadBytes((int)reader.ReadVarInt());
         NoncePieces.Add(key, value);
     }
     this.NonceHash = reader.ReadSerializable<UInt256>();
     this.TransactionHashes = reader.ReadSerializableArray<UInt256>();
     this.Script = reader.ReadBytes((int)reader.ReadVarInt());
 }
 void ISignable.FromUnsignedArray(byte[] value)
 {
     using (MemoryStream ms = new MemoryStream(value, false))
     using (BinaryReader reader = new BinaryReader(ms))
     {
         this.PrevHash = reader.ReadSerializable<UInt256>();
         this.Miner = Secp256r1Point.DeserializeFrom(reader);
         this.NoncePieces.Clear();
         int count = (int)reader.ReadVarInt();
         for (int i = 0; i < count; i++)
         {
             Secp256r1Point key = Secp256r1Point.DeserializeFrom(reader);
             if (key == Miner) throw new FormatException();
             value = reader.ReadBytes((int)reader.ReadVarInt());
             NoncePieces.Add(key, value);
         }
         this.NonceHash = reader.ReadSerializable<UInt256>();
         this.TransactionHashes = reader.ReadSerializableArray<UInt256>();
     }
 }
 public BlockConsensusContext(Secp256r1Point my_pubkey)
 {
     this.my_pubkey = my_pubkey;
     Reset();
 }
Example #8
0
 private MinerWallet(byte[] key_exported)
 {
     this.key_exported = key_exported;
     this.PublicKey = Secp256r1Point.FromBytes(key_exported);
     ProtectedMemory.Protect(key_exported, MemoryProtectionScope.SameProcess);
 }
 public BlockConsensusContext(Secp256r1Point my_pubkey)
 {
     this.my_pubkey = my_pubkey;
     Reset();
     this.action_request = new TimeoutAction(CreateResponse, TimeSpan.FromSeconds(Blockchain.SecondsPerBlock), () => NoncePieces.Count > Miners.Length * (2.0 / 3.0), () => NoncePieces.Count == Miners.Length - 1);
 }
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     this.PublicKey = Secp256r1Point.DeserializeFrom(reader);
 }