Exemplo n.º 1
0
        public override WalletAccount CreateAccount(UInt160 scriptHash)
        {
            TLP6Account account = new TLP6Account(this, scriptHash);

            AddAccount(account, true);
            return(account);
        }
Exemplo n.º 2
0
 private void AddAccount(TLP6Account account, bool is_import)
 {
     lock (accounts)
     {
         if (accounts.TryGetValue(account.ScriptHash, out TLP6Account account_old))
         {
             account.Label     = account_old.Label;
             account.IsDefault = account_old.IsDefault;
             account.Lock      = account_old.Lock;
             if (account.Contract == null)
             {
                 account.Contract = account_old.Contract;
             }
             else
             {
                 TLP6Contract contract_old = (TLP6Contract)account_old.Contract;
                 if (contract_old != null)
                 {
                     TLP6Contract contract = (TLP6Contract)account.Contract;
                     contract.ParameterNames = contract_old.ParameterNames;
                     contract.Deployed       = contract_old.Deployed;
                 }
             }
             account.Extra = account_old.Extra;
         }
         accounts[account.ScriptHash] = account;
     }
 }
Exemplo n.º 3
0
 public override bool VerifyPassword(string password)
 {
     lock (accounts)
     {
         TLP6Account account = accounts.Values.FirstOrDefault(p => !p.Decrypted);
         if (account == null)
         {
             account = accounts.Values.FirstOrDefault(p => p.HasKey);
         }
         if (account == null)
         {
             return(true);
         }
         if (account.Decrypted)
         {
             return(account.VerifyPassword(password));
         }
         else
         {
             try
             {
                 account.GetKey(password);
                 return(true);
             }
             catch (FormatException)
             {
                 return(false);
             }
         }
     }
 }
Exemplo n.º 4
0
        public override WalletAccount CreateAccount(Contract contract, KeyPair key = null)
        {
            TLP6Contract tlp6contract = contract as TLP6Contract;

            if (tlp6contract == null)
            {
                tlp6contract = new TLP6Contract
                {
                    Script         = contract.Script,
                    ParameterList  = contract.ParameterList,
                    ParameterNames = contract.ParameterList.Select((p, i) => $"parameter{i}").ToArray(),
                    Deployed       = false
                };
            }
            TLP6Account account;

            if (key == null)
            {
                account = new TLP6Account(this, tlp6contract.ScriptHash);
            }
            else
            {
                account = new TLP6Account(this, tlp6contract.ScriptHash, key, password);
            }
            account.Contract = tlp6contract;
            AddAccount(account, false);
            return(account);
        }
Exemplo n.º 5
0
 private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary <UInt160, TLP6Account> accounts, out JObject extra)
 {
     this.name    = wallet["name"]?.AsString();
     this.version = Version.Parse(wallet["version"].AsString());
     scrypt       = ScryptParameters.FromJson(wallet["scrypt"]);
     accounts     = ((JArray)wallet["accounts"]).Select(p => TLP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash);
     extra        = wallet["extra"];
 }
Exemplo n.º 6
0
        public override WalletAccount Import(string wif)
        {
            KeyPair      key      = new KeyPair(GetPrivateKeyFromWIF(wif));
            TLP6Contract contract = new TLP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            TLP6Account account = new TLP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

            AddAccount(account, true);
            return(account);
        }
Exemplo n.º 7
0
        public override WalletAccount CreateAccount(byte[] privateKey)
        {
            KeyPair      key      = new KeyPair(privateKey);
            TLP6Contract contract = new TLP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            TLP6Account account = new TLP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

            AddAccount(account, false);
            return(account);
        }
Exemplo n.º 8
0
        public override WalletAccount Import(X509Certificate2 cert)
        {
            KeyPair key;

            using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
            {
                key = new KeyPair(ecdsa.ExportParameters(true).D);
            }
            TLP6Contract contract = new TLP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            TLP6Account account = new TLP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

            AddAccount(account, true);
            return(account);
        }
Exemplo n.º 9
0
        public override WalletAccount Import(string tlp2, string passphrase, int N = 16384, int r = 8, int p = 8)
        {
            KeyPair      key      = new KeyPair(GetPrivateKeyFromTLP2(tlp2, passphrase, N, r, p));
            TLP6Contract contract = new TLP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            TLP6Account account;

            if (Scrypt.N == 16384 && Scrypt.R == 8 && Scrypt.P == 8)
            {
                account = new TLP6Account(this, contract.ScriptHash, tlp2);
            }
            else
            {
                account = new TLP6Account(this, contract.ScriptHash, key, passphrase);
            }
            account.Contract = contract;
            AddAccount(account, true);
            return(account);
        }