public void SignatureSwap() { var rawTx = Base16.Decode("80000001AA2F638AE527480F6976CBFC268E06048040F77328F78A8F269F9DAB660715C70000029B7CFFDAA674BEAE0F930EBE6085AF9093E5FE56B34A5C220CCDCF6EFC336FC500E1F50500000000D9020CC50B04E75027E19A5D5A9E377A042A0BB59B7CFFDAA674BEAE0F930EBE6085AF9093E5FE56B34A5C220CCDCF6EFC336FC500C2EB0B000000005B1258432BE2AB39C5CD1CAAFBD2B7AAA4B0F034014140A24433C702A47174B9DC1CC6DA90611AA8895B09A5BAD82406CCEF77D594A7343F79084D42BBF8D7C818C4540B38A2E168A7B932D2C0999059A0B3A3B43F6D31232102FC1D6F42B05D00E6AEDA82DF286EB6E2578042F6CAEBE72144342466113BD81EAC"); var tx = Neo.Core.Transaction.Unserialize(rawTx); var wif = "KwVG94yjfVg1YKFyRxAGtug93wdRbmLnqqrFV6Yd2CiA9KZDAp4H"; var neoKeys = Phantasma.Neo.Core.NeoKeys.FromWIF(wif); Assert.IsTrue(tx.witnesses.Any()); var wit = tx.witnesses.First(); var witAddress = wit.ExtractAddress(); var transposedAddress = Address.FromKey(neoKeys); Assert.IsTrue(transposedAddress.IsUser); Assert.IsTrue(transposedAddress == witAddress); var msg = "Hello Phantasma!"; var payload = Encoding.UTF8.GetBytes(msg); var neoSig = ECDsaSignature.Generate(neoKeys, payload, ECDsaCurve.Secp256r1); var validateNeoSig = neoSig.Verify(payload, transposedAddress); Assert.IsTrue(validateNeoSig); }
public void ECDsaSecP256k1() { var address = "0x66571c32d77c4852be4c282eb952ba94efbeac20"; var key = "6f6784731c4e526c97fa6a97b6f22e96f307588c5868bc2c545248bc31207eb1"; Assert.IsTrue(key.Length == 64); var curve = ECCurve.Secp256k1; var privateKey = key.HexToByteArray(); var pKey = ECCurve.Secp256k1.G * privateKey; var publicKey = pKey.EncodePoint(true).ToArray(); var uncompressedPublicKey = pKey.EncodePoint(false).Skip(1).ToArray(); var kak = new Phantasma.Ethereum.Util.Sha3Keccack().CalculateHash(uncompressedPublicKey); var Address = "0x" + Base16.Encode(kak.Skip(12).ToArray()).ToLower(); Console.WriteLine("Address: " + Address); Console.WriteLine("address: " + address); Assert.IsTrue(Address == address); var msgBytes = Encoding.ASCII.GetBytes("Phantasma"); // CryptoExtensions.SignECDsa()/.VerifySignatureECDsa() tests. var signature = CryptoExtensions.SignECDsa(msgBytes, privateKey, publicKey, ECDsaCurve.Secp256k1); Assert.IsNotNull(signature); Console.WriteLine("CryptoExtensions.SignECDsa() signature: " + Base16.Encode(signature)); var signatureUncompressed = CryptoExtensions.SignECDsa(msgBytes, privateKey, uncompressedPublicKey, ECDsaCurve.Secp256k1); Assert.IsNotNull(signatureUncompressed); Assert.IsTrue(CryptoExtensions.VerifySignatureECDsa(msgBytes, signature, publicKey, ECDsaCurve.Secp256k1)); Assert.IsTrue(CryptoExtensions.VerifySignatureECDsa(msgBytes, signature, uncompressedPublicKey, ECDsaCurve.Secp256k1)); // ECDsaSignature.Generate()/ECDsaSignature.Verify() tests. var ethKeys = Ethereum.EthereumKey.FromPrivateKey(key); // Verifying previous signature, received from CryptoExtensions.SignECDsa(). var ecdsaSignature = new ECDsaSignature(signature, ECDsaCurve.Secp256k1); Console.WriteLine("ECDsaSignature() signature: " + Base16.Encode(ecdsaSignature.ToByteArray())); Assert.IsTrue(ecdsaSignature.Verify(msgBytes, Phantasma.Cryptography.Address.FromKey(ethKeys))); // Generating new signature with ECDsaSignature.Generate() and verifying it. var ecdsaSignature2 = ECDsaSignature.Generate(ethKeys, msgBytes, ECDsaCurve.Secp256k1); Console.WriteLine("ECDsaSignature() signature2: " + Base16.Encode(ecdsaSignature2.ToByteArray())); Assert.IsTrue(ecdsaSignature.Verify(msgBytes, Phantasma.Cryptography.Address.FromKey(ethKeys))); }
public Signature Sign(byte[] msg, Func <byte[], byte[], byte[], byte[]> customSignFunction = null) { return(ECDsaSignature.Generate(this, msg, ECDsaCurve.Secp256r1)); }
public Signature Sign(byte[] msg) { return(ECDsaSignature.Generate(this, msg, ECDsaCurve.Secp256r1)); }