Пример #1
0
        private bool RestoreWallet(string path, string password, out EcdsaKeyPair keyPair, out byte[] hubKey)
        {
            var encryptedContent = File.ReadAllBytes(path);
            var key = Encoding.UTF8.GetBytes(password).KeccakBytes();
            var decryptedContent =
                Encoding.UTF8.GetString(Crypto.AesGcmDecrypt(key, encryptedContent));

            var wallet = JsonConvert.DeserializeObject <JsonWallet>(decryptedContent);

            if (wallet.EcdsaPrivateKey is null)
            {
                throw new Exception("Decrypted wallet does not contain ECDSA key");
            }
            var needsSave = false;

            if (wallet.HubPrivateKey is null)
            {
                wallet.HubPrivateKey = GenerateHubKey().PrivateKey;
                needsSave            = true;
            }

            wallet.ThresholdSignatureKeys ??= new Dictionary <ulong, string>();
            wallet.TpkePrivateKeys ??= new Dictionary <ulong, string>();

            keyPair = new EcdsaKeyPair(wallet.EcdsaPrivateKey.HexToBytes().ToPrivateKey());
            hubKey  = wallet.HubPrivateKey.HexToBytes();
            _tpkeKeys.AddAll(wallet.TpkePrivateKeys
                             .Select(p =>
                                     new C5.KeyValuePair <ulong, PrivateKey>(p.Key, PrivateKey.FromBytes(p.Value.HexToBytes()))));
            _tsKeys.AddAll(wallet.ThresholdSignatureKeys
                           .Select(p =>
                                   new C5.KeyValuePair <ulong, PrivateKeyShare>(p.Key,
                                                                                PrivateKeyShare.FromBytes(p.Value.HexToBytes()))));
            return(needsSave);
        }
Пример #2
0
 public PrivateConsensusKeySet(
     EcdsaKeyPair ecdsaKeyPair, PrivateKey tpkePrivateKey,
     PrivateKeyShare thresholdSignaturePrivateKeyShare)
 {
     EcdsaKeyPair   = ecdsaKeyPair;
     TpkePrivateKey = tpkePrivateKey;
     ThresholdSignaturePrivateKeyShare = thresholdSignaturePrivateKeyShare;
 }
Пример #3
0
 public CommonCoin(
     CoinId coinId, IPublicConsensusKeySet wallet, PrivateKeyShare privateKeyShare,
     IConsensusBroadcaster broadcaster
     ) : base(wallet, coinId, broadcaster)
 {
     _coinId          = coinId ?? throw new ArgumentNullException(nameof(coinId));
     _thresholdSigner = new ThresholdSigner(
         _coinId.ToBytes(), privateKeyShare, wallet.ThresholdSignaturePublicKeySet
         );
     _result = null;
 }
Пример #4
0
        public void AddThresholdSignatureKeyAfterBlock(ulong block, PrivateKeyShare key)
        {
            if (_tsKeys.Contains(block))
            {
                _tsKeys.Update(block, key);
                Logger.LogWarning($"ThresholdSignatureKey for block {block} is overwritten");
            }
            else
            {
                _tsKeys.Add(block, key);
            }

            SaveWallet(_walletPath, _walletPassword);
        }