Beispiel #1
0
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWrite(ref _IndexesSalt);
     stream.ReadWrite(ref _FakeIndexes);
     stream.ReadWriteC(ref _Salts);
     stream.ReadWriteC(ref _FeeVariations);
 }
Beispiel #2
0
 public static void ReadWriteC(this BitcoinStream bs, ref Money[][] arr)
 {
     if (bs.Serializing)
     {
         if (arr == null)
         {
             uint o = 0;
             bs.ReadWriteAsVarInt(ref o);
             return;
         }
         var len = (uint)arr.Length;
         bs.ReadWriteAsVarInt(ref len);
         for (int i = 0; i < len; i++)
         {
             var subLen = (uint)arr[i].Length;
             bs.ReadWriteAsVarInt(ref subLen);
             for (int j = 0; j < subLen; j++)
             {
                 var n = arr[i][j];
                 bs.ReadWriteC(ref n);
             }
         }
     }
     else
     {
         uint len = 0;
         bs.ReadWriteAsVarInt(ref len);
         if (len == 0)
         {
             arr = null;
             return;
         }
         if (len > bs.MaxArraySize)
         {
             throw new ArgumentOutOfRangeException("Array is too big");
         }
         arr = new Money[len][];
         for (int i = 0; i < len; i++)
         {
             uint subLen = 0;
             bs.ReadWriteAsVarInt(ref subLen);
             if (subLen == 0)
             {
                 arr[i] = null;
                 return;
             }
             arr[i] = new Money[subLen];
             for (int j = 0; j < subLen; j++)
             {
                 bs.ReadWriteC(ref arr[i][j]);
             }
         }
     }
 }
Beispiel #3
0
 public static void ReadWriteC(this BitcoinStream bs, ref Network network)
 {
     if (bs.Serializing)
     {
         var str = network.ToString();
         bs.ReadWriteC(ref str);
     }
     else
     {
         var str = string.Empty;
         bs.ReadWriteC(ref str);
     }
 }
Beispiel #4
0
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _Network);
     stream.ReadWrite(ref _CycleGenerator);
     stream.ReadWriteC(ref _ServerKey);
     stream.ReadWriteC(ref _VoucherKey);
     stream.ReadWriteC(ref _Denomination);
     stream.ReadWriteC(ref _Fee);
     stream.ReadWrite(ref _FakePuzzleCount);
     stream.ReadWrite(ref _RealPuzzleCount);
     stream.ReadWrite(ref _FakeTransactionCount);
     stream.ReadWrite(ref _RealTransactionCount);
 }
Beispiel #5
0
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _EscrowKey);
     stream.ReadWriteAsVarString(ref _Signature);
     stream.ReadWrite(ref _Nonce);
     stream.ReadWrite(ref _CycleStart);
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteAsVarInt(ref _OutputIndex);
     stream.ReadWrite(ref _Transaction);
     stream.ReadWrite(ref _MerkleProof);
     stream.ReadWriteC(ref _EscrowInitiatorKey);
 }
Beispiel #7
0
 public static void ReadWriteC(this BitcoinStream bs, ref PoupardSternProof proof)
 {
     if (bs.Serializing)
     {
         if (proof == null)
         {
             uint o = 0;
             bs.ReadWriteAsVarInt(ref o);
             return;
         }
         var len = (uint)proof.XValues.Length;
         bs.ReadWriteAsVarInt(ref len);
         for (int i = 0; i < len; i++)
         {
             var n = proof.XValues[i];
             bs.ReadWriteC(ref n);
         }
         var yvalue = proof.YValue;
         bs.ReadWriteC(ref yvalue);
     }
     else
     {
         uint len = 0;
         bs.ReadWriteAsVarInt(ref len);
         if (len == 0)
         {
             proof = null;
             return;
         }
         if (len > bs.MaxArraySize)
         {
             throw new ArgumentOutOfRangeException("Array is too big");
         }
         var xValues = new NTumbleBit.BouncyCastle.Math.BigInteger[len];
         for (int i = 0; i < len; i++)
         {
             NTumbleBit.BouncyCastle.Math.BigInteger b = null;
             bs.ReadWriteC(ref b);
             xValues[i] = b;
         }
         NTumbleBit.BouncyCastle.Math.BigInteger yValue = null;
         bs.ReadWriteC(ref yValue);
         proof = new PoupardSternProof(Tuple.Create(xValues, yValue));
     }
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWrite(ref _Cycle);
     stream.ReadWrite(ref _KeyReference);
     stream.ReadWrite(ref _UnsignedVoucher);
     stream.ReadWrite(ref _MerkleProof);
     stream.ReadWriteC(ref _ClientEscrowKey);
     stream.ReadWrite(ref _Transaction);
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWrite(ref _Version);
     if (_Version != LAST_VERSION)
     {
         throw new FormatException($"Tumbler is running an invalid version ({_Version} while expected is {LAST_VERSION})");
     }
     stream.ReadWriteC(ref _Network);
     stream.ReadWrite(ref _CycleGenerator);
     stream.ReadWrite(ref _ServerKey);
     stream.ReadWrite(ref _VoucherKey);
     stream.ReadWriteC(ref _Denomination);
     stream.ReadWriteC(ref _Fee);
     stream.ReadWrite(ref _FakePuzzleCount);
     stream.ReadWrite(ref _RealPuzzleCount);
     stream.ReadWrite(ref _FakeTransactionCount);
     stream.ReadWrite(ref _RealTransactionCount);
     stream.ReadWriteC(ref _ExpectedAddress);
 }
Beispiel #10
0
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _Fee);
     stream.ReadWrite(ref _LockTime);
     stream.ReadWriteC(ref _FulfillKey);
 }
        private static Tuple <RsaKey, RSAKeyData> LoadRSAKeyData(string dataDir, string keyName, bool noRSAProof)
        {
            RSAKeyData data = new RSAKeyData();
            RsaKey     key  = null;

            {
                var rsaFile = Path.Combine(dataDir, keyName);
                if (!File.Exists(rsaFile))
                {
                    Logs.Configuration.LogWarning("RSA private key not found, please backup it. Creating...");
                    key = new RsaKey();
                    File.WriteAllBytes(rsaFile, key.ToBytes());
                    Logs.Configuration.LogInformation("RSA key saved (" + rsaFile + ")");
                }
                else
                {
                    Logs.Configuration.LogInformation("RSA private key found (" + rsaFile + ")");
                    key = new RsaKey(File.ReadAllBytes(rsaFile));
                }
            }

            data.PublicKey = key.PubKey;


            if (!noRSAProof)
            {
                {
                    var poupard = Path.Combine(dataDir, "ProofPoupard-" + keyName);
                    PoupardSternProof poupardProof = null;
                    if (!File.Exists(poupard))
                    {
                        Logs.Configuration.LogInformation("Creating Poupard Stern proof...");
                        poupardProof = PoupardStern.ProvePoupardStern(key._Key, RSAKeyData.PoupardSetup);
                        MemoryStream  ms = new MemoryStream();
                        BitcoinStream bs = new BitcoinStream(ms, true);
                        bs.ReadWriteC(ref poupardProof);
                        File.WriteAllBytes(poupard, ms.ToArray());
                        Logs.Configuration.LogInformation("Poupard Stern proof created (" + poupard + ")");
                    }
                    else
                    {
                        Logs.Configuration.LogInformation("Poupard Stern Proof found (" + poupard + ")");
                        var           bytes = File.ReadAllBytes(poupard);
                        MemoryStream  ms    = new MemoryStream(bytes);
                        BitcoinStream bs    = new BitcoinStream(ms, false);
                        bs.ReadWriteC(ref poupardProof);
                    }
                    data.PoupardSternProof = poupardProof;
                }

                {
                    var permutation = Path.Combine(dataDir, "ProofPermutation-" + keyName);
                    PermutationTestProof permutationProof = null;
                    if (!File.Exists(permutation))
                    {
                        Logs.Configuration.LogInformation("Creating Permutation Test proof...");
                        permutationProof = PermutationTest.ProvePermutationTest(key._Key, RSAKeyData.PermutationSetup);
                        MemoryStream  ms = new MemoryStream();
                        BitcoinStream bs = new BitcoinStream(ms, true);
                        bs.ReadWriteC(ref permutationProof);
                        File.WriteAllBytes(permutation, ms.ToArray());
                        Logs.Configuration.LogInformation("Permutation Test proof created (" + permutation + ")");
                    }
                    else
                    {
                        Logs.Configuration.LogInformation("Permutation Test Proof found (" + permutation + ")");
                        var           bytes = File.ReadAllBytes(permutation);
                        MemoryStream  ms    = new MemoryStream(bytes);
                        BitcoinStream bs    = new BitcoinStream(ms, false);
                        bs.ReadWriteC(ref permutationProof);
                    }
                    data.PermutationTestProof = permutationProof;
                }
            }
            return(Tuple.Create(key, data));
        }
Beispiel #12
0
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _Value);
 }
Beispiel #13
0
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _Arrays);
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _Hashes);
     stream.ReadWrite(ref _FakeIndexesHash);
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWrite(ref _KeyIndex);
     stream.ReadWriteC(ref _PubKey);
     stream.ReadWrite(ref _ChannelId);
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _FakeSolutions);
     stream.ReadWriteC(ref _Quotients);
 }
 public void ReadWrite(BitcoinStream stream)
 {
     stream.ReadWriteC(ref _PublicKey);
     stream.ReadWriteC(ref _PermutationTestProof);
     stream.ReadWriteC(ref _PoupardSternProof);
 }