示例#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);
        }
        public JSInput()
        {
            byte[] random_byte256 = new byte[32];
            using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(random_byte256);
            }
            key = new SpendingKey(new UInt256(random_byte256));

            note = new Note(key.address().a_pk, new Fixed8(0), UInt256.Random(), UInt256.Random(), UInt256.Random());

            witness = new byte[0];
            AssetID = new UInt256();
        }
示例#3
0
        public JSOutput()
        {
            byte[] random_byte256 = new byte[32];
            using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(random_byte256);
            }

            SpendingKey a_sk = new SpendingKey(new UInt256(random_byte256));

            addr = a_sk.address();

            AssetID = Blockchain.GoverningToken.Hash;

            memo = new byte[0];
        }
示例#4
0
        public UInt256 Nullifier(SpendingKey a_sk)
        {
            byte[] byNullifier = new byte[32];

            SnarkDllApi.GetNullifier(a_pk.ToArray(),
                                     rho.ToArray(),
                                     r.ToArray(),
                                     value.GetData(),
                                     a_sk.ToArray(),
                                     byNullifier);

            byte[] byConvNullifier = new byte[32];
            for (int nuIn = 0; nuIn < 32; nuIn++)
            {
                byConvNullifier[nuIn] = byNullifier[31 - nuIn];
            }
            UInt256 nullifier = new UInt256(byConvNullifier);

            return(nullifier);
        }
示例#5
0
        public override WalletKeyPair CreateKey(byte[] privateKey, KeyType nVersion = KeyType.Transparent)
        {
            if (nVersion == KeyType.Transparent)
            {
                WalletKeyPair account = base.CreateKey(privateKey, nVersion);
                OnCreateAccount(account);
                AddContract(VerificationContract.CreateSignatureContract(account.PublicKey));
                return(account);
            }
            else if (nVersion == KeyType.Anonymous)
            {
                WalletKeyPair account = base.CreateKey(privateKey, nVersion);
                SpendingKey   sKey;

                sKey = new SpendingKey(new UInt256(privateKey));
                OnCreateAccount(account);
                AddContract(VerificationContract.CreateSignatureAnonymousContract(account.PublicKey, sKey.address()));
                return(account);
            }
            else
            {
                return(null);
            }
        }
示例#6
0
        public UInt256 Nullifier(SpendingKey key)
        {
            Note nt = new Note(Output.addr.a_pk, Output.Value, Output.rho, Output.r, Output.AssetId);

            return(nt.Nullifier(key));
        }