Skip to content

MyEtherWallet/bls-eth-swift

Repository files navigation

GitHub Platform Swift support Swift Package Manager compatible

Note: this framework doesn't provide a way to derive Eth2 secret key (eip-2333). Please use your own implementation

bls-eth-swift

bls-eth-swift provides convenient way to integrate https://github.com/herumi/bls-eth-go-binary

Requirements

Good mood

Features

  • Easy to use
  • Precompiled sources
  • Safe to use with app extensions

Installation

Swift Package Manager

You can use Swift Package Manager and specify dependency in Package.swift by adding this:

.package(url: "https://github.com/MyEtherWallet/bls-eth-swift.git", .upToNextMajor(from: "1.0.0"))

XCFramework

XCFrameworks require Xcode 11 or later and they can be integrated similarly to how we’re used to integrating the .framework format. Please use a script bls_framework/build.sh to generate binary bls_framework.xcframework archive that you can use as a dependency in Xcode or you can use precompiled one.

bls_framework.xcframework is a Release (Optimized) binary that offer best available Swift code performance.

How to

import bls_framework
blsSecretKey
try BLSInterface.blsInit()

let serializedSecretKey = Data(hex: "455c0dc9fccb3395825d92a60d2672d69416be1c2578a87a7a3d3ced11ebb88d").bytes // [UInt8]

var secretKey = blsSecretKey.init()
blsSecretKeyDeserialize(&secretKey, &serializedSecretKey, numericCast(serializedSecretKey.count))
blsPublicKey
var publicKey = blsPublicKey.init()
blsGetPublicKey(&publicKey, &secretKey)
Eth2 Public Key
let PUBLIC_KEY_SIZE = 48
var publicKeyBytes = Data(count: PUBLIC_KEY_SIZE).bytes // [UInt8]
blsPublicKeySerialize(&publicKeyBytes, PUBLIC_KEY_SIZE, &publicKey)

return Data(publicKeyBytes)

Swift versions support

  • Swift 5.0 and newer, branch master

License

MIT