Esempio n. 1
0
        public async Task <bool> SignDelegationOperationAsync(
            IKeyStorage keyStorage,
            WalletAddress address,
            CancellationToken cancellationToken = default)
        {
            var xtz = (Atomex.Tezos)Currency;

            if (address.KeyIndex == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var securePrivateKey = keyStorage
                                         .GetPrivateKey(Currency, address.KeyIndex);

            if (securePrivateKey == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var privateKey = securePrivateKey.ToUnsecuredBytes();

            var rpc = new Rpc(xtz.RpcNodeUri);

            Head = await rpc
                   .GetHeader()
                   .ConfigureAwait(false);

            var forgedOpGroup = await rpc
                                .ForgeOperations(Head, Operations)
                                .ConfigureAwait(false);

            var forgedOpGroupLocal = Forge.ForgeOperationsLocal(Head, Operations);

            if (true)  //if (config.CheckForge == true) add option for higher security tezos mode to config
            {
                if (forgedOpGroupLocal.ToString() != forgedOpGroup.ToString())
                {
                    Log.Error("Local and remote forge results differ");
                    return(false);
                }
            }

            SignedMessage = TezosSigner.SignHash(
                data: Hex.FromString(forgedOpGroup.ToString()),
                privateKey: privateKey,
                watermark: Watermark.Generic,
                isExtendedKey: privateKey.Length == 64);

            return(true);
        }
        public async Task <bool> SignAsync(
            IKeyStorage keyStorage,
            WalletAddress address,
            CurrencyConfig currencyConfig,
            CancellationToken cancellationToken = default)
        {
            if (address.KeyIndex == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var securePrivateKey = keyStorage.GetPrivateKey(
                      currency: currencyConfig,
                      keyIndex: address.KeyIndex,
                      keyType: address.KeyType);

            if (securePrivateKey == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var privateKey = securePrivateKey.ToUnsecuredBytes();

            var xtz = currencyConfig as TezosConfig;

            var rpc = new Rpc(xtz.RpcNodeUri);

            var forgedOpGroup = await rpc
                                .ForgeOperations(Head, Operations)
                                .ConfigureAwait(false);

            //var forgedOpGroup = Forge.ForgeOperationsLocal(Head["hash"].ToString(), Operations);

            SignedMessage = TezosSigner.SignHash(
                data: Hex.FromString(forgedOpGroup.ToString()),
                privateKey: privateKey,
                watermark: Watermark.Generic,
                isExtendedKey: privateKey.Length == 64);

            return(SignedMessage != null);
        }
Esempio n. 3
0
        public async Task <bool> SignAsync(
            IKeyStorage keyStorage,
            WalletAddress address,
            CancellationToken cancellationToken = default)
        {
            var xtz = (Atomex.Tezos)Currency;

            if (address.KeyIndex == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var securePrivateKey = keyStorage
                                         .GetPrivateKey(Currency, address.KeyIndex);

            if (securePrivateKey == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var privateKey = securePrivateKey.ToUnsecuredBytes();

            using var securePublicKey = keyStorage
                                        .GetPublicKey(Currency, address.KeyIndex);

            var rpc = new Rpc(xtz.RpcNodeUri);

            Head = await rpc
                   .GetHeader()
                   .ConfigureAwait(false);

            await FillOperationsAsync(Head, securePublicKey)
            .ConfigureAwait(false);

            if (Type != BlockchainTransactionType.Output)
            {
                UseDefaultFee = true;
            }

            var fill = await rpc
                       .AutoFillOperations(xtz, Head, Operations, UseDefaultFee)
                       .ConfigureAwait(false);

            if (!fill)
            {
                Log.Error("Transaction autofilling error");
                return(false);
            }

            // todo: update Fee, GasLimit, StorageLimit

            var forgedOpGroup = await rpc
                                .ForgeOperations(Head, Operations)
                                .ConfigureAwait(false);

            var forgedOpGroupLocal = Forge.ForgeOperationsLocal(Head, Operations);

            //if (true)  //if (config.CheckForge == true) add option for higher security tezos mode to config
            //{
            //    if (forgedOpGroupLocal.ToString() != forgedOpGroup.ToString())
            //    {
            //        Log.Error("Local and remote forge results differ");
            //        return false;
            //    }
            //}

            SignedMessage = TezosSigner.SignHash(
                data: Hex.FromString(forgedOpGroup.ToString()),
                privateKey: privateKey,
                watermark: Watermark.Generic,
                isExtendedKey: privateKey.Length == 64);

            return(true);
        }