Bitski 0.5.0

Bitski 0.5.0

Josh Pyles 维护。



 
依赖
Web3~> 0.3.1
Web3/ContractABI~> 0.3.1
Web3/PromiseKit~> 0.3.1
AppAuth~> 0.93
BigInt.swift~> 1.0
secp256k1.swift~> 0.1
PromiseKit/CorePromise~> 6.0
 

Bitski 0.5.0

  • Josh Pyles

Bitski iOS SDK

CocoaPods CocoaPods CocoaPods Documentation Codecov

官方的 Bitski SDK for iOS。使用 OAuth 基于的平台钱包构建以太坊去中心化 iOS 应用。

  • 请阅读我们的 文档API 参考 以开始学习。
  • 想要看到 SDK 的示例?请查看我们的 iOS 示例 Dapp
  • 了解更多关于 iOS 上使用 Ethereum 的信息,请访问 Web3.swift

示例

要运行示例项目,请首先克隆仓库,然后从 Example 目录运行 pod install。您需要将客户端 ID 和重定向 URL 添加到 AppDelegate 中。

要求

  • 目前仅支持 iOS 11 及以上版本

安装

Bitski 通过 CocoaPods 提供。要安装它,请在 Podfile 中添加以下行即可

pod 'Bitski'

使用

初始化

首先,在此处创建应用以获取客户端ID。务必在选择应用类型时选择“原生应用”。

您还需要在开发人员门户中的重定向URL下添加在应用程序中使用的 redirectURL。这确保只有您信任的URL可以与您的客户端ID一起使用。

在您的应用程序中,初始化Bitski实例

// Replace redirect URL with an url scheme that will hit your native app
Bitski.shared = Bitski(clientID: "<YOUR CLIENT ID>", redirectURL: URL(string: "exampleapp://application/callback")!)

我们在 Bitski.shared 中提供了一个方便的静态位置来初始化您的实例,但如果您想避免使用单例,则可以以最适合您的方式存储您的实例。

认证

配置好 Bitski 实例后,您可以检查登录状态。用户在执行任何Web3调用之前需要先登录。

if Bitski.shared?.isLoggedIn == true {
    self.web3 = Bitski.shared?.getWeb3()
    // show logged in state
} else {
    // show logged out state
}

要登录,只需调用 signIn()(这将打开浏览器窗口)

Bitski.shared?.signIn() { error in
    // Once signed in, get an instance of Web3
    self.web3 = Bitski.shared?.getWeb3()
    // or, specify a network with getWeb3(network:)
}

用户将无限期地保持登录状态,除非访问令牌被撤销。要明确登出

Bitski.shared?.signOut()

本地开发

如果您在进行本地开发(例如使用 truffle develop 或 ganache),则可以使用开发网络。

let network: Bitski.Network = .development(url: "https://:9545", chainId: 0) //or use your local IP if building for a device.
let web3 = Bitski.getWeb3(network: network)

处理隐式登出

当用户登录和登出时(分别对应于 Bitski.LoggedInNotificationBitski.LoggedOutNotification)将发布通知。用户可以通过明确定期或隐性地(如果访问令牌被撤销)登录。因此,响应这些通知是一个好习惯。

NotificationCenter.default.addObserver(self, selector: #selector(userDidLogout), name: Bitski.LoggedOutNotification, object: nil)

使用 Web3

初始化 Web3 实例后,您可以使用它来进行以太坊调用和交易。我们通过我们的 API 提供对以太坊网络的全面访问。

// Example: Make a simple transfer transaction
firstly {
    web3.eth.accounts().firstValue
}.then { account in
    let to = try? EthereumAddress(hex: "SOME ADDRESS", eip55: false)
    let transaction = EthereumTransaction(nonce: nil, gasPrice: EthereumQuantity(quantity: 1.gwei), gas: EthereumQuantity(quantity: 21.gwei), from: account, to: to, value: EthereumQuantity(quantity: 1.eth))
    return web3.eth.sendTransaction(transaction: transaction)
}.then { transactionHash in
    web3.eth.getTransactionReceipt(transactionHash)
}.done { receipt in
    let watcher = TransactionWatcher(hash: transactionHash, web3: web3)
    watcher.expectedConfirmations = 3
    watcher.delegate = self
    self.transactionWatcher = watcher
}

有关 Web3 可以做什么的更多信息,请参阅 Web3.swift

授权

我们的 Web3 提供商允许您发送需要签名的交易,但用户必须明确批准它们。出于安全考虑,这种授权在您的网页界面中进行,并将显示为位于应用程序上方的浏览器模态。一旦交易被批准或拒绝,模态将关闭。为了获得最佳体验,我们建议限制您发送的交易数量。

报告漏洞

Bitski 为与社区中的安全研究人员合作提供“漏洞赏金”。如果您在我们的产品或服务中发现了漏洞,请向 Bitski 安全团队 提交漏洞报告

许可协议

Bitski 在 MIT 许可协议下提供。更多信息请参阅 LICENSE 文件。