示例#1
0
        private void btn_new_wallet_yes_Click(object sender, EventArgs e)
        {
            if (!CheckParameter())
            {
                return;
            }

            UserWallet wallet;

            if (chk_anonymous.Checked == true)
            {
                wallet = UserWallet.Create(txb_wallet_path.Text, txb_password.Text, KeyType.Anonymous);
            }
            else
            {
                wallet = UserWallet.Create(txb_wallet_path.Text, txb_password.Text, KeyType.Transparent);
            }


            Settings.Default.LastWalletPath = txb_wallet_path.Text;
            Settings.Default.Save();

            using (MainWalletForm dialog = new MainWalletForm(wallet))
            {
                this.Hide();
                FormManager.GetInstance().Push(dialog);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            //Get hSig
            byte[] random_byte256 = new byte[32];
            using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(random_byte256);
            }
            UInt256        hSig    = new UInt256(random_byte256);
            NoteEncryption noteEnc = new NoteEncryption(hSig);

            SpendingKey sk = SpendingKey.random();

            Console.Write("SpendingKey is " + sk.ToArray().ToHexString());
            Console.WriteLine();

            PaymentAddress addr  = sk.address();
            PaymentAddress addr1 = sk.address();


            byte[] plain_text  = { 0x74, 0x64, 0x64, 0x66, 0x23, 0x46, 0x54, 0x23, 0x32, 0x33, 0x33, 0x33, 0x33 };
            byte[] cipher_text = noteEnc.Encrypt(addr.pk_enc, plain_text);

            NoteDecryption noteDec = new NoteDecryption(sk.receiving_key());

            byte[] plain_text_m = noteDec.Decrypt(cipher_text, noteEnc.get_epk(), hSig, (char)0);
        }
示例#2
0
        public byte[] encrypt(NoteEncryption encryptor,
                              UInt256 pk_enc)
        {
            NotePlaintext pt = new NotePlaintext();

            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    ((ISerializable)this).Serialize(writer);
                    writer.Flush();
                    return(encryptor.Encrypt(pk_enc, ms.ToArray()));
                }
        }
示例#3
0
        public virtual QrsProof prove(
            List <JSInput> inputs,
            List <JSOutput> outputs,
            List <Note> out_notes,
            List <byte[]> out_ciphertexts,
            UInt256 out_ephemeralKey,
            UInt256 pubKeyHash,
            UInt256 out_randomSeed,
            List <UInt256> out_macs,
            List <UInt256> out_nullifiers,
            List <UInt256> out_commitments,
            Fixed8 vpub_old,
            Fixed8 vpub_new,
            UInt256 rt,
            bool computeProof = true,
            // For paymentdisclosure, we need to retrieve the esk.
            // Reference as non-const parameter with default value leads to compile error.
            // So use pointer for simplicity.
            UInt256 out_esk = null
            )
        {
            Fixed8 lhs_value = vpub_old;
            Fixed8 rhs_value = vpub_new;

            for (int i = 0; i < inputs.Count; i++)
            {
                lhs_value += inputs[i].note.value;
                out_nullifiers.Add(inputs[i].Nullifier());
            }

            out_randomSeed = UInt256.Random();

            UInt256 h_sig = QrsJoinSplit.h_sig(out_randomSeed, out_nullifiers, pubKeyHash);

            UInt252 phi = new UInt252(UInt256.Random());

            for (int i = 0; i < outputs.Count; i++)
            {
                rhs_value += outputs[i].value;

                UInt256 r = UInt256.Random();

                out_notes.Add(outputs[i].note(phi, r, new Fixed8(i), h_sig));
            }

            if (lhs_value != rhs_value)
            {
                throw new ArgumentException();
            }

            for (int i = 0; i < outputs.Count; i++)
            {
                out_commitments.Add(out_notes[i].CM());
            }

            {
                NoteEncryption encryptor = new NoteEncryption(h_sig);

                for (int i = 0; i < outputs.Count; i++)
                {
                    NotePlaintext pt = new NotePlaintext(out_notes[i], outputs[i].memo);
                    out_ciphertexts.Add(pt.encrypt(encryptor, outputs[i].addr.pk_enc));
                }

                out_ephemeralKey = encryptor.get_epk();

                out_esk = encryptor.get_esk();
            }

            for (int i = 0; i < inputs.Count; i++)
            {
                out_macs.Add(PRFClass.PRF_pk(inputs[i].key, new Fixed8(i), h_sig));
            }



            return(null);
        }