Пример #1
0
        public SwitcheoAuthenticationProvider(ApiCredentials credentials, BlockchainType keyType)
            : base(new ApiCredentials(new PrivateKey(EnsureHexFormat(credentials.PrivateKey.Key,
                                                                     credentials.PrivateKey?.Passphrase))))
        {
            if (this.CanSign)
            {
                if (keyType == BlockchainType.Qtum || keyType == BlockchainType.Ethereum)
                {
                    throw new NotImplementedException();
                }

                try
                {
                    this.KeyType = keyType;

                    SecureString readablePrivateKey = credentials.PrivateKey.Key;

                    // Decrypting private key if Nep2 format was provided
                    if (WalletsHelper.IsNep2(credentials.PrivateKey.Key))
                    {
                        readablePrivateKey = Nep2.Decrypt(credentials.PrivateKey.Key.GetString(),
                                                          credentials.PrivateKey.Passphrase.GetString()).Result.ToHexString().ToSecureString();
                    }

                    // Extracting wallet informations (public key, script hash, address and fixed address)
                    this.WalletInformations = WalletsHelper.GetWalletInformations(readablePrivateKey, keyType);
                }
                catch (Exception)
                {
                    throw privateKeyException;
                }
            }
        }
Пример #2
0
        public static WalletInformations GetWalletInformations(SecureString privateKey, BlockchainType keyType)
        {
            WalletInformations walletInformations = new WalletInformations();

            switch (keyType)
            {
            case BlockchainType.Neo:
                var keyPair = new KeyPair(privateKey.GetString().HexToBytes());

                string  publicKey  = keyPair.PublicKey.ToString();
                UInt160 scriptHash = Helper.CreateSignatureRedeemScript(keyPair.PublicKey).ToScriptHash();

                // This is a basic NEO address
                string address = scriptHash.ToAddress();
                // This is a derivative of script hash (required by Switcheo)
                string fixedAddress = scriptHash.ToString().RemoveZeroX();

                walletInformations = new WalletInformations()
                {
                    Wif          = keyPair.Export().ToSecureString(),
                    PublicKey    = publicKey,
                    ScriptHash   = scriptHash.ToString(),
                    Address      = address,
                    FixedAddress = fixedAddress
                };
                break;

            case BlockchainType.Qtum:
                throw new NotImplementedException();

            case BlockchainType.Ethereum:
                throw new NotImplementedException();
            }

            return(walletInformations);
        }