Swiftpack.co - Package - GigaBitcoin/secp256k1.swift

🔐 secp256k1.swift Build Status

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

Objective

This library aims to be a lightweight dependency for clients and wrapper libraries to include ECDSA functionality.

This package is set to the default git branch of secp256k1 and aims to stay up-to-date without using a mirrored repository. An extra module is available for convenience functionality.

Getting Started

In your Package.swift:

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

Currently, this Swift package only provides a single product library built using the libsecp256k1 basic config.

Usage

import secp256k1
import secp256k1_utils

// Initialize context
let context = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY))!

// Setup private and public key variables
var pubkeyLen = 33
var cPubkey = secp256k1_pubkey()
var pubkey = [UInt8](https://raw.github.com/GigaBitcoin/secp256k1.swift/blob/main/repeating: 0, count: pubkeyLen)
let privkey = try! "14E4A74438858920D8A35FB2D88677580B6A2EE9BE4E711AE34EC6B396D87B5C".byteArray()

// Verify the context and keys are setup correctly
guard secp256k1_context_randomize(context, privkey) == 1,
    secp256k1_ec_pubkey_create(context, &cPubkey, privkey) == 1,
    secp256k1_ec_pubkey_serialize(context, &pubkey, &pubkeyLen, &cPubkey, UInt32(SECP256K1_EC_COMPRESSED)) == 1 else {
    // Destory context after creation
    secp256k1_context_destroy(context)
    return
}

print(String(byteArray: pubKey)) //  02734b3511150a60fc8cac329cd5ff804555728740f2f2e98bc4242135ef5d5e4e

// Destory context after creation
secp256k1_context_destroy(context)

Contributing

To start developing, clone the package from github, and from the root directory, run the following commands:

git clone --recurse-submodules https://github.com/GigaBitcoin/secp256k1.swift
cd secp256k1.swift
swift build

Tests can be run by calling swift test

Danger

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

Github

link
Stars: 2

Dependencies

Used By

Total: 0

Releases

Schnorr - 2020-09-16 08:10:16

0.0.15 - 2020-09-05 00:42:35

0.0.14 - 2020-09-04 23:22:30

0.0.13 - 2020-09-04 02:25:35

0.0.12 - 2020-09-03 21:32:53

0.0.11 - 2020-09-02 20:24:22

0.0.10 - 2020-09-01 05:21:33

0.0.9 - 2020-08-19 20:46:49

Upstream version bump

0.0.8 - 2020-08-14 17:33:16

Upstream version bump

0.0.7 - 2020-08-13 17:06:16

Upstream version bump

0.0.6 - 2020-08-12 18:41:40

Upstream version bump

0.0.5 - 2020-08-05 17:21:57

Upstream version bump

0.0.4 - 2020-07-28 17:31:52

Upstream version bump

Three engineers walk past a bar... - 2020-07-27 16:14:52

Upstream version bump

Sophomore Bump - 2020-07-22 23:06:27

Upstream version bump

Merkle Root - 2020-07-05 08:28:03