Exemplo n.º 1
0
 public void PublicKey_Can_Be_Created_With_Valid_Input()
 {
     const string publicKeyHex = "fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025";
     var publicKeyBytes = publicKeyHex.HexToByteArray();
     var publicKey = _wrapper.GetPublicKeyFromBytes(publicKeyBytes);
     publicKey.Should().NotBe(null);
 }
Exemplo n.º 2
0
        private void UpdateLedgerAccountFromEntry(PublicEntry entry)
        {
            var pubKey = _cryptoContext.GetPublicKeyFromBytes(entry.Base.ReceiverPublicKey.ToByteArray());

            //todo: get an address from the key using the Account class from Common lib
            var account = Accounts.Get(pubKey.Bytes.ToBase32());

            //todo: a different logic for to and from entries
            account.Balance += entry.Amount.ToUInt256();
        }
Exemplo n.º 3
0
        private Address GetAccountAddress(ByteString publicKeyByteString)
        {
            if (publicKeyByteString == null || publicKeyByteString.IsEmpty)
            {
                return(null);
            }

            var publicKey = _cryptoContext.GetPublicKeyFromBytes(publicKeyByteString.ToByteArray());

            return(publicKey.ToKvmAddress());
        }
Exemplo n.º 4
0
        public void TestVerifyWithImportedPublicKey()
        {
            var privateKey     = _context.GeneratePrivateKey();
            var publicKey      = _context.GetPublicKeyFromPrivateKey(privateKey);
            var data           = Encoding.UTF8.GetBytes("Testing testing 1 2 3");
            var signingContext = Encoding.UTF8.GetBytes("Testing testing 1 2 3 context");
            var signature      = _context.Sign(privateKey, data, signingContext);

            var blob = _context.ExportPublicKey(publicKey);

            var importedKey = _context.GetPublicKeyFromBytes(blob);
            var signatureWithImportedKey = _context.GetSignatureFromBytes(signature.SignatureBytes, importedKey.Bytes);

            _context.Verify(signatureWithImportedKey, data, signingContext).Should()
            .BeTrue("signature should verify with imported public key");
        }