注意:此框架不提供推导 Eth2 私钥的方法 (eip-2333)。请使用您自己的实现
bls-eth-swift 提供了一种便捷的方式来集成 https://github.com/herumi/bls-eth-go-binary
好心情
您可以使用 Swift 包管理器,并在 Package.swift
中通过添加以下内容来指定依赖项
.package(url: "https://github.com/MyEtherWallet/bls-eth-swift.git", .upToNextMajor(from: "1.0.0"))
XCFrameworks
需要 Xcode 11 或更高版本,它们的集成方式类似于我们过去集成 .framework
格式的方式。请使用脚本 bls_framework/build.sh
生成二进制文件 bls_framework.xcframework
归档,您可以在 Xcode 中将其用作依赖项,或者您可以使用预编译的版本。
bls_framework.xcframework
是一个 Release (优化) 二进制文件,可以提供最佳的 Swift 代码性能。
import bls_framework
try BLSInterface.blsInit()
let serializedSecretKey = Data(hex: "455c0dc9fccb3395825d92a60d2672d69416be1c2578a87a7a3d3ced11ebb88d").bytes // [UInt8]
var secretKey = blsSecretKey.init()
blsSecretKeyDeserialize(&secretKey, &serializedSecretKey, numericCast(serializedSecretKey.count))
var publicKey = blsPublicKey.init()
blsGetPublicKey(&publicKey, &secretKey)
let PUBLIC_KEY_SIZE = 48
var publicKeyBytes = Data(count: PUBLIC_KEY_SIZE).bytes // [UInt8]
blsPublicKeySerialize(&publicKeyBytes, PUBLIC_KEY_SIZE, &publicKey)
return Data(publicKeyBytes)
MIT