Swiftpack.co -  tesseract-one/CSecp256k1.swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
tesseract-one/CSecp256k1.swift
Swift C module for bitcoin secp256k1 library
.package(url: "https://github.com/tesseract-one/CSecp256k1.swift.git", from: "0.1.0")

CSecp256k1.swift

🐧 linux: ready GitHub license Build Status GitHub release SPM compatible CocoaPods version Platform macOS | iOS | tvOS | watchOS | Linux

Swift C module for bitcoin secp256k1 library.

Installation

CSecp256k1.swift deploys to macOS, iOS, tvOS, watchOS and Linux. It has been tested on the latest OS releases only however, as the module uses very few platform-provided APIs, there should be very few issues with earlier versions.

Setup instructions:

  • Swift Package Manager: Add this to the dependency section of your Package.swift manifest:

    .package(url: "https://github.com/tesseract-one/CSecp256k1.swift.git", from: "0.1.0")
    
  • CocoaPods: Put this in your Podfile:

    pod 'CSecp256k1', '~> 0.1'
    

Usage Examples

Sign and Verify

import CSecp256k1

let privKey: [UInt8] = [
    0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba,
    0x84, 0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4, 0x44, 0x49,
    0xc5, 0x69, 0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac,
    0x03, 0x1c, 0xae, 0x7f, 0x60
]

let data = [UInt8](https://raw.github.com/tesseract-one/CSecp256k1.swift/main/repeating: 0, count: 32)

let context: OpaquePointer! = secp256k1_context_create(
    UInt32(SECP256K1_CONTEXT_SIGN|SECP256K1_CONTEXT_VERIFY)
)

var signature = secp256k1_ecdsa_recoverable_signature()
let res = secp256k1_ecdsa_sign_recoverable(context, &signature, data, privKey, nil, nil)
assert(res > 0)

var pubKey = secp256k1_pubkey()
let res2 = secp256k1_ec_pubkey_create(context, &pubKey, privKey)
assert(res2 > 0)

var ssig = secp256k1_ecdsa_signature()
let res3 = secp256k1_ecdsa_recoverable_signature_convert(context, &ssig, &signature)
assert(res3 > 0)

let isValid = secp256k1_ecdsa_verify(context, &ssig, hash, &pubKey)
assert(isValid == 1)

License

CSecp256k1.swift can be used, distributed and modified under the Apache 2.0 license.

Bitcoin secp256k1 can be used, distributed and modified under the MIT license.

GitHub

link
Stars: 0
Last commit: 5 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

First working version
5 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API