Framework
P256K
P256K is a Swift library for elliptic curve cryptography on the secp256k1 curve, providing ECDSA signing, Schnorr signatures, MuSig2 multi-signatures, ECDH key agreement, and key recovery.
Overview
The P256K module wraps the libsecp256k1 C library with a type-safe Swift API designed to match the style of Apple’s swift-crypto framework. It provides cryptographic primitives for the secp256k1 elliptic curve, which is widely used in Bitcoin, Lightning Network, Nostr, and other open protocols.
All operations require a secp256k1 context. The library provides a shared P256K.Context that is created and randomized once at process startup, protecting ECDSA signing, Schnorr signing, and public key generation against timing and power analysis attacks via base point blinding.
Where to start
New to P256K? Begin with Getting Started with secp256k1 in Swift for a task-oriented walkthrough of ECDSA signing, BIP-340 Schnorr signatures, and ECDH key agreement. Aggregating signatures across multiple signers? Read MuSig2 Multi-Signatures for the BIP-327 protocol. The Elliptic Curve Diffie-Hellman guide covers ECDH end-to-end — the building block behind Nostr NIP-04, Lightning’s Noise XK handshake, and BIP-352 Silent Payments. Sending Bitcoin to a reusable receiver address without on-chain linkability lives in Silent Payments. Working with tweaks (BIP-32 derivation, Taproot key paths) is covered in Tweaking Keys. Persisting keys? See Serializing Keys and the conceptual Key Formats. Recovering public keys from signatures (BIP-137 / BIP-322) lives in Recovering Public Keys. Production-readiness caveats — context randomization, nonce hygiene, comparison timing, secret zeroization, signature malleability — are in Security Considerations.
Topics
Guides
Concepts
Essentials
ECDSA Signatures
Schnorr Signatures
MuSig2 Multi-Signatures
Key Agreement (ECDH)
Key Recovery
Hashing
Supporting Types
Protocols
Structures
Type Aliases
Enumerations
Extended Modules