示例#1
0
文件: UserWallet.cs 项目: txhsl/neo
        public override WalletAccount CreateAccount(SmartContract.Contract contract, KeyPair key = null)
        {
            VerificationContract verification_contract = contract as VerificationContract;

            if (verification_contract == null)
            {
                verification_contract = new VerificationContract
                {
                    Script        = contract.Script,
                    ParameterList = contract.ParameterList
                };
            }
            byte[] decryptedPrivateKey = new byte[96];
            Buffer.BlockCopy(key.PublicKey.EncodePoint(false), 1, decryptedPrivateKey, 0, 64);
            Buffer.BlockCopy(key.PrivateKey, 0, decryptedPrivateKey, 64, 32);
            UserWalletAccount account = new UserWalletAccount(this, verification_contract.ScriptHash)
            {
                Key = key,
                EncryptedPrivateKey = EncryptPrivateKey(decryptedPrivateKey),
                Contract            = verification_contract
            };

            AddAccount(account, false);
            return(account);
        }
示例#2
0
 private Dictionary <UInt160, UserWalletAccount> LoadAccounts()
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         Dictionary <UInt160, UserWalletAccount> accounts = ctx.Addresses.Select(p => p.ScriptHash).AsEnumerable().Select(p => new UserWalletAccount(new UInt160(p))).ToDictionary(p => p.ScriptHash);
         foreach (Contract db_contract in ctx.Contracts.Include(p => p.Account))
         {
             VerificationContract contract = db_contract.RawData.AsSerializable <VerificationContract>();
             UserWalletAccount    account  = accounts[contract.ScriptHash];
             account.Contract = contract;
             account.Key      = new KeyPair(DecryptPrivateKey(db_contract.Account.PrivateKeyEncrypted));
         }
         return(accounts);
     }
 }
示例#3
0
 private Dictionary <UInt160, UserWalletAccount> LoadAccounts()
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         string passphrase = Encoding.UTF8.GetString(masterKey);
         Dictionary <UInt160, UserWalletAccount> accounts = ctx.Addresses.Select(p => p.ScriptHash).AsEnumerable().Select(p => new UserWalletAccount(new UInt160(p))).ToDictionary(p => p.ScriptHash);
         foreach (Contract db_contract in ctx.Contracts.Include(p => p.Account))
         {
             VerificationContract contract = db_contract.RawData.AsSerializable <VerificationContract>();
             UserWalletAccount    account  = accounts[contract.ScriptHash];
             account.Contract = contract;
             account.Key      = new KeyPair(GetPrivateKeyFromNEP2(db_contract.Account.Nep2key, passphrase, scrypt.N, scrypt.R, scrypt.P));
         }
         return(accounts);
     }
 }
示例#4
0
        public override WalletAccount CreateAccount(byte[] privateKey)
        {
            KeyPair key = new KeyPair(privateKey);
            VerificationContract contract = new VerificationContract
            {
                Script        = SmartContract.Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList = new[] { ContractParameterType.Signature }
            };
            UserWalletAccount account = new UserWalletAccount(contract.ScriptHash)
            {
                Key      = key,
                Contract = contract
            };

            AddAccount(account);
            return(account);
        }
示例#5
0
        public override WalletAccount CreateAccount(SmartContract.Contract contract, KeyPair key = null)
        {
            VerificationContract verification_contract = contract as VerificationContract;

            if (verification_contract == null)
            {
                verification_contract = new VerificationContract
                {
                    Script        = contract.Script,
                    ParameterList = contract.ParameterList
                };
            }
            UserWalletAccount account = new UserWalletAccount(verification_contract.ScriptHash)
            {
                Key      = key,
                Contract = verification_contract
            };

            AddAccount(account);
            return(account);
        }
示例#6
0
文件: UserWallet.cs 项目: txhsl/neo
        public override WalletAccount CreateAccount(byte[] privateKey)
        {
            KeyPair key = new KeyPair(privateKey);
            VerificationContract contract = new VerificationContract
            {
                Script        = SmartContract.Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList = new[] { ContractParameterType.Signature }
            };

            byte[] decryptedPrivateKey = new byte[96];
            Buffer.BlockCopy(key.PublicKey.EncodePoint(false), 1, decryptedPrivateKey, 0, 64);
            Buffer.BlockCopy(key.PrivateKey, 0, decryptedPrivateKey, 64, 32);
            UserWalletAccount account = new UserWalletAccount(this, contract.ScriptHash)
            {
                Key = key,
                EncryptedPrivateKey = EncryptPrivateKey(decryptedPrivateKey),
                Contract            = contract
            };

            AddAccount(account, false);
            return(account);
        }