Zesame
Zesame 是为 Zilliqa 设计的 非官方 Swift SDK。它使用 Swift 5.0 编写,包含许可您创建和恢复钱包、签名和广播交易的加密方法。这些加密方法在 EllipticCurveKit 中实现。此 SDK 使用 Zilliqa 的 JSON-RPC API
入门指南
carthage bootstrap --platform iOS,macOS --cache-builds --no-use-binaries
Protobuf
Zesame 使用 JSON-RPC API 而不是 protobuf API,但是,我们需要使用 protobuf 来打包交易。请注意,protocolbuffers 仅用于 交易打包,它根本不用于任何与 API 的通信。所有数据都以 JSON 的形式发送到 JSON-RPC API。
我们使用 apple/swift-protobuf 项目用于 protocol buffers,并且需要注意与 Swift Protobuf 相关的两个不同的程序
安装 protobuf
protoc-gen-swift
这个程序仅用于将我们的.proto文件生成.swift文件,我们使用brew(它也可以手动下载和构建)安装此程序。
在此处按照brew的安装说明进行安装。
brew install swift-protobuf
完成这些操作后,我们可以使用
$ protoc --swift_out=. my.proto
SwiftProtobuf
库
为了使用生成的.pb.swift
文件,我们需要包含`SwiftProtobuf`库,我们可以使用cocoapods或carhage来做到这一点。
使用protobuf
站在项目的根目录中,运行
protoc --swift_opt=Visibility=Public --swift_out=. Source/Models/Protobuf/messages.proto
将生成的文件messages.pb.swift
添加到相应的Xcode组。
依赖项
您可以在Cartfile中找到所有依赖项,但值得一提的是
EllipticCurveKit
Zesame依赖于EllipticCurveKit中的椭圆曲线密码学,用于生成新的钱包、恢复现有的钱包、将您的私钥加密到keystores以及使用Schnorr签名对您的交易进行签名。
其他
-
RxSwift:该库使用RxSwift进行异步编程。
-
JSONRPCKit:用于消费Zilliqa JSON-RPC API。
API
闭包或Rx
此SDK为每种方法提供两种实现,一个使用闭包(又称“回调”),另一个使用RxSwift Observables实现的闭包。
Rx
DefaultZilliqaService.shared.rx.getBalance(for: address).subscribe(
onNext: { print("Balance: \($0.balance)") },
onError: { print("Failed to get balance, error: \($0)") }
).disposed(by: bag)
闭包
DefaultZilliqaService.shared.getBalalance(for: address) {
switch $0 {
case .success(let balanceResponse): print("Balance: \(balanceResponse.balance)")
case .failure(let error): print("Failed to get balance, error: \(error)")
}
}
函数
请查看ZilliqaService.swift了解函数概览,以下是反应式API当前函数的快照(每个函数都有一个闭包对应项)
public protocol ZilliqaServiceReactive {
func createNewWallet() -> Observable<Wallet>
func exportKeystore(from wallet: Wallet, encryptWalletBy passphrase: String) -> Observable<Keystore>
func importWalletFrom(keyStore: Keystore, encryptedBy passphrase: String) -> Observable<Wallet>
func getBalance(for address: Address) -> Observable<BalanceResponse>
func sendTransaction(for payment: Payment, signWith keyPair: KeyPair) -> Observable<TransactionIdentifier>
}
浏览器
在开发过程中,您可能需要使用 Zilliqa 探索器。
捐赠
此 SDK 以及其构建的基础 EllipticCurveKit 由独立作者 Alexander Cyon 在其业余时间开发,自 2018 年 5 月以来(查看初始提交),大约消耗了 1000 个小时的工作时间。
任何捐赠都将非常感激。:
- BTC: 3GarsdAzLpEYbhkryYz1WiZxhtTLLaNJwo
- ETH: 0xAB8F0137295BFE37f50b581F76418518a91ab8DB
- NEO: AbbnnCLP26ccSnLooDDcwPLDnfXbVL5skH
许可证
币璞遵循 MIT 许可协议 发布。