Skip to content

Swift library plus bindings for ECDSA signatures and secret/public key operations using libsecp256k1.

License

Notifications You must be signed in to change notification settings

Fenetik-NFT/secp256k1.swift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

🔐 secp256k1.swift

Swift library plus bindings for ECDSA signatures and secret/public key operations using libsecp256k1.

Objectives

Long-term goals are:

  • Lightweight ECDSA functionality
  • APIs modeled after Swift Crypto
  • Up-to-date with future versions of Swift and libsecp256k1
  • Consistent across multiple platforms

Usage

import secp256k1

let privateKeyBytes = try! "14E4A74438858920D8A35FB2D88677580B6A2EE9BE4E711AE34EC6B396D87B5C".byteArray()
let privatekey = try! secp256k1.Signing.PrivateKey(rawRepresentation: privateKeyBytes)

print(String(byteArray: privatekey.publicKey.rawRepresentation)) //  02734b3511150a60fc8cac329cd5ff804555728740f2f2e98bc4242135ef5d5e4e

let messageData = "Hello World!".data(using: .utf8)!
let signature = try! privateKey.signature(for: messageData)

print(try! signature.derRepresentation().base64EncodedString()) //  MEUCID8JELjY/ua6MSRKh/VtO7q2YAgpPOfqlwi05Lj/gC1jAiEAiJ1r82jIVc9G/2kooLnzIbg04ky/leocdLn9XE1LvwI=

Getting Started

In your Package.swift:

dependencies: [
    .package(
        name: "secp256k1",
        url: "https://github.com/GigaBitcoin/secp256k1.swift.git",
        from: "0.3.0"
    ),
]

Danger

These APIs should not be considered stable and may change at any time. libsecp256k1 is still experimental and has not been formally released.

About

Swift library plus bindings for ECDSA signatures and secret/public key operations using libsecp256k1.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.4%
  • C 4.0%
  • Dockerfile 0.6%