Example #1
0
 private void AddAccount(NEP6Account account)
 {
     lock (accounts)
     {
         if (accounts.TryGetValue(account.ScriptHash, out NEP6Account 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
             {
                 NEP6Contract contract_old = (NEP6Contract)account_old.Contract;
                 if (contract_old != null)
                 {
                     NEP6Contract contract = (NEP6Contract)account.Contract;
                     contract.ParameterNames = contract_old.ParameterNames;
                     contract.Deployed       = contract_old.Deployed;
                 }
             }
             account.Extra = account_old.Extra;
         }
         accounts[account.ScriptHash] = account;
     }
 }
Example #2
0
 public override bool VerifyPassword(string password)
 {
     lock (accounts)
     {
         NEP6Account 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);
             }
         }
     }
 }
Example #3
0
        public override WalletAccount CreateAccount(Contract contract, KeyPair key = null)
        {
            if (contract is not NEP6Contract nep6contract)
            {
                nep6contract = new NEP6Contract
                {
                    Script         = contract.Script,
                    ParameterList  = contract.ParameterList,
                    ParameterNames = contract.ParameterList.Select((p, i) => $"parameter{i}").ToArray(),
                    Deployed       = false
                };
            }
            NEP6Account account;

            if (key == null)
            {
                account = new NEP6Account(this, nep6contract.ScriptHash);
            }
            else
            {
                account = new NEP6Account(this, nep6contract.ScriptHash, key, password);
            }
            account.Contract = nep6contract;
            AddAccount(account);
            return(account);
        }
Example #4
0
 private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary <UInt160, NEP6Account> accounts, out JObject extra)
 {
     this.version = Version.Parse(wallet["version"].AsString());
     this.name    = wallet["name"]?.AsString();
     scrypt       = ScryptParameters.FromJson(wallet["scrypt"]);
     accounts     = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash);
     extra        = wallet["extra"];
 }
Example #5
0
        public WalletAccount GetDefaultAccount()
        {
            NEP6Account first = null;

            lock (accounts)
            {
                foreach (NEP6Account account in accounts.Values)
                {
                    if (account.IsDefault)
                    {
                        return(account);
                    }
                    if (first == null)
                    {
                        first = account;
                    }
                }
            }
            return(first);
        }
Example #6
0
        public override WalletAccount Import(string nep2, string passphrase, int N = 16384, int r = 8, int p = 8)
        {
            KeyPair      key      = new(GetPrivateKeyFromNEP2(nep2, passphrase, ProtocolSettings.AddressVersion, N, r, p));
            NEP6Contract contract = new()
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            NEP6Account account;

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