eNotesSDK
轻松验证和管理您的电子支票。
描述
eNotesSDK 是一个 Swift 实现,通过智能手机和蓝牙 NFC 读取器(需单独购买)来验证和管理您的电子支票。
功能
- 支持 BTC(主网和测试网)
- 支持 ETH(主网、ropsten、rinkeby 和 kovan)
- 支持 ERC20 代币
- 使用 NFC 和蓝牙验证数字资产的实体形式
- 提供最常见的 RPC 请求
要求
- iOS 10.0+
- Xcode 10+
- Swift 4.2+
通信
- 如果您想 提出一般性疑问,请使用 Stack Overflow。
- 如果您 发现了错误,请提交一个问题。
- 如果您 有功能需求,请提交一个问题。
- 如果您 想要贡献,请提交一个拉取请求。
安装
CocoaPods
eNotesSDK 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'eNotesSDKPre'
然后,运行以下命令
pod install
项目设置
在编译代码时,可能会出现一些错误,您可以尝试以下方法来解决
目标
->构建设置
->启用 Bitcode
设置为 No,这是因为我们使用的内核实现是 CoreBitcoin,它不支持 Bitcode目标
->构建设置
->其他链接器标志
添加-ObjC
,这是因为我们使用的 ACS 的蓝牙 NFC 读取库明确指出必须在其他链接器标志
中添加-ObjC
使用方法
CardReaderManager
- 在初始化代码中添加观察者,例如在 UIViewController 中的
viewDidLoad
CardReaderManager.shared.addObserver(observer: self)
- 根据需要实现
CardReaderObserver
方法
extension UIViewController: CardReaderObserver {
func didDiscover(peripherals: [CBPeripheral]) {
// Discoverd peripherals
}
func didBluetoothConnected() {
// Bluetooth connected, when attached to reader
}
func didBluetoothDisconnect() {
// Bluetooth disconnected, error occurred or manually disconnect
}
func didBluetoothUpdateState(state: CBManagerState) {
// Bluetooth state changed, see CBManagerState for more
}
func didCardRead(card: Card?, error: CardReaderError?) {
// Card reader progress done, return card info if success, return error if fail
}
func didCardPresent() {
// Card did present on NFC device
}
func didCardAbsent() {
// Card did absent on NFC device
}
}
- 扫描 NFC 蓝牙设备,查看 CardReaderObserver 获取更多回调详细
CardReaderManager.shared.startBluetoothScan()
- 找到设备后连接设备,查看 CardReaderObserver 获取更多回调详细
CardReaderManager.shared.connectBluetooth(peripheral: peripheral)
-
如果连接成功,如果您的卡片未能出现,则会在
didCardAbsent
中调用,现在您可以在设备上出示卡片,获取证书信息,验证证书,验证设备,验证区块链将自动在设备上完成。如果验证通过,则会调用didCardRead
并可以获取到包括地址、面值、序列号等信息。 -
在发送交易之前获取原始交易,我们提供了
Bitcoin
和Ethereum
/// For Bitcoin
CardReaderManager.shared.getBtcRawTransaction(publicKey: publicKey, toAddress: toAddress, utxos: unspend, network: card.network, fee: fee) { (rawtx) in
// use rawtx as parameter to send a transaction
// sendRawTransaction(rawtx: rawtx), see NetworkManager for more
}
/// For Ethereum
CardReaderManager.shared.getEthRawTransaction(sendAddress: senderAddress, toAddress: toAddress, value: value, gasPrice: gasPrice, estimateGas: estimateGas, nonce: nonce) { (rawtx) in
// use rawtx as parameter to send a transaction
// sendRawTransaction(rawtx: rawtx), see NetworkManager for more
}
NetworkManager
我们提供大多数用于区块链的常用 API,您可以使用 NetworkManager
单例来使用它们,包括以下内容
- 通用
- 获取余额
- 发送原始交易
- 获取交易收据
- Bitcoin
- 获取未花费余额
- 获取估计费用
- Ethereum
- 获取 gas 价格
- 调用
- 获取 gas 数量
- 估计 gas 数量
注意 在您发出请求之前,最好调用 setNetwork
来配置 ApiKey。我们的内部实现使用多个第三方 API 进行请求,有些 API 需要 API 密钥,因此最好配置它,即使我们提供了默认值,您也可以这样配置
let config = ApiKeyConfig(etherscanApiKeys: ["etherscanApiKey1", "etherscanApiKey2"], infuraApiKeys: ["infuraApiKey1", "infuraApiKey2", "infuraApiKey3"], blockcypherApiKeys: ["blockcypherApiKey1"])
NetworkManager.shared.setNetwork(config: config)
- Bitcoin 请求示例
NetworkManager.shared.getBalance(blockchain: .bitcoin, network: .testnet, address: "address") { (balance, error) in
guard error == nil else {
// error handle code will be here
return
}
// update UI for balance for example
self.balanceLabel.text = balance
}
- Ethereum 请求示例
NetworkManager.shared.getNonce(network: .kovan, address: "sendAddress") { (nonce, error) in
guard error == nil else {
// error handle code will be here
return
}
// store the nonce for example
self.nonce = nonce
}
查看 示例
或 eNotesSDK 源代码
以检查所有请求的使用方法
示例
要运行示例项目,首先克隆存储库,然后从示例目录运行 pod install
许可
eNotesSDK 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。