EllipticCurveKit

https://github.com/Sajjon/EllipticCurveKit
Elliptic Curve Cryptography in Pure Swift using EquatoinKit. Support for multiple curves, signature type and forms.

let privateKey = PrivateKey<Secp256k1>(hex: "B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF")!

let keyPair = AnyKeyGenerator<Secp256k1>.restoreKeyPairFrom(privateKey: privateKey)

let message = Message(hex: "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89")

let signature = AnyKeySigner<Schnorr<Secp256k1>>.sign(message, using: keyPair)

let expectedSignature = Signature<Secp256k1>(hex: "2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD")!

if signature == expectedSignature {
    print("Correct signature!")
}

if AnyKeySigner<Schnorr<Secp256k1>>.verify(message, wasSignedBy: signature, publicKey: keyPair.publicKey) {
     print("'It's working, it's working!' - Anakin Skywalker ( https://youtu.be/AXwGVXD7qEQ )")
}
1 Like

I like this