Seamlessly integrate, test, and utilize the elliptic curve cryptography for development of Bitcoin applications.
Get Startedimport P256K
// Create ECDSA keypair
let priv = try! P256K.Signing.PrivateKey()
let pub = priv.publicKey
// Sign message with private key
let msg = "Hello Bitcoin".data(using: .utf8)!
let sig = try! priv.signature(for: msg)
// Verify signature with public key
let valid = pub.isValidSignature(sig, for: msg)
import P256K
// Create Schnorr keypair
let priv = try! P256K.Schnorr.PrivateKey()
let pub = priv.publicKey
// Sign message with private key
let msg = "Bitcoin Script".data(using: .utf8)!
let sig = try! priv.signature(for: msg)
// Verify signature with public key
let valid = pub.isValidSignature(sig, for: msg)
Integration
Streamline your development: utilize the efficiency of libsecp256k1 for Swift
We've wrapped libsecp256k1 into a package and made it super simple to include into your Xcode project. And it works with Swift Packages too!
Easy Integration
Unlock simplicity and efficiency with just a few lines using the P256K APIs. Leave the heavy lifting of project mutations to libsecp256k1 while you focus on what truly matters.
Swift Packages Support
Most of the time you don't need to compile sources of your Swift Package dependencies. Therefore we wrapped libsecp256k1 for others to integrate.
Advanced Control
Schnorr and ECDSA Signatures functionality with ease. Optional low-level C bindings are available for advanced use cases.
Installation
Get Started
Add P256K using your preferred package manager.
https://github.com/21-DOT-DEV/swift-secp256k1
In Xcode, go to File → Add Package Dependencies, paste the URL above, select version 0.21.1, and add to your target.
.package(url: "https://github.com/21-DOT-DEV/swift-secp256k1", exact: "0.21.1")
Add this line to your Package.swift dependencies array, then run `swift build` to integrate P256K into your project.
pod 'swift-secp256k1', '0.21.1'
Add this line to your Podfile, then run `pod install` to integrate P256K into your Xcode workspace.
Documentation
Explore the APIs
Comprehensive API documentation for P256K cryptography.
ECDSA Signatures
Elliptic Curve Digital Signature Algorithm (ECDSA) offers a variant of the Digital Signature Algorithm (DSA) which uses elliptic-curve cryptography.
Learn more
Schnorr Signatures
Schnorr signatures provide enhanced privacy and efficiency with mathematical properties that enable advanced Bitcoin scripting capabilities.
Learn more
Key Management
Secure key generation, derivation, and management utilities for Bitcoin development with industry-standard practices.
Learn more
FAQ
Frequently Asked Questions
Common questions about using P256K for Swift integration.
What is P256K?
P256K is a Swift library for working with the secp256k1 elliptic curve, commonly used in Bitcoin and related ecosystems. It provides idiomatic, type-safe Swift APIs built on top of the widely used libsecp256k1 library.
How do I install P256K with Swift Package Manager?
What makes P256K different from other secp256k1 libraries?
P256K is designed specifically for Swift developers. It focuses on modern Swift language features, type safety, comprehensive test coverage, and seamless integration with Swift Package Manager. The API follows Swift conventions rather than exposing low-level C interfaces directly.
Is P256K safe for production use?
P256K is built on libsecp256k1, a widely used cryptographic library in the Bitcoin ecosystem. The Swift wrapper is actively maintained and extensively tested. As with all cryptographic software, review the code for your threat model and pin versions for production deployments.
Has P256K been security audited?
The underlying libsecp256k1 has been heavily reviewed and tested in the Bitcoin ecosystem over many years. P256K (the Swift wrapper) has not yet undergone a dedicated third-party security audit.
What Swift versions and platforms are supported?
P256K supports Swift 5.9 and newer and is tested on iOS, macOS, watchOS, tvOS, and Linux. It works with UIKit, SwiftUI, and server-side Swift environments.
What cryptographic operations does P256K support?
P256K supports common secp256k1 operations including ECDSA signing and verification, Schnorr signatures, public key recovery, key agreement, key tweaking, and MuSig-related primitives commonly used in Bitcoin-adjacent protocols.
Is P256K suitable for Bitcoin, Lightning, Nostr, Ecash, or Liquid applications?
Yes. P256K is suitable anywhere you need secp256k1 cryptography in Swift, including Bitcoin apps and related ecosystems like Lightning, Nostr, Ecash, and Liquid.
Is the API stable?
P256K is pre-1.0.0, so APIs may change between releases. For production use, pin an exact version in Swift Package Manager to avoid unexpected breaking changes.
Where can I find documentation and examples?
Equipping developers with the tools they need today to build the Bitcoin apps of tomorrow.