美文网首页宛十八区块链研发
TokenCore -- iOS上的区块链私钥管理库

TokenCore -- iOS上的区块链私钥管理库

作者: Travelcolor | 来源:发表于2019-01-11 15:01 被阅读142次

    TokenCore是一个区块链库。TokenCore提供了相对一致的API,允许您同时管理钱包并在BTC,ETH和EOS链中签署交易。此外,TokenCore引入了“身份”的概念,您可以使用相同的助记符来管理三个链上的钱包。

    TokenCore相关链接

    安装

    要安装TokenCore,请使用CocoaPods并将其添加到您的Podfile:

    pod "TokenCore", git: "https://github.com/consenlabs/token-core-ios.git", branch: "master"
    

    Try the API

    创建新身份并派生eth,btc钱包

    // 在创建其他钱包之前,您应首先创建或恢复身份
    do {
      var metadata = WalletMeta(source: .newIdentity)
      metadata.network = Network.mainnet
      metadata.segWit = .p2wpkh //// .p2wpkh意味着派生的btc钱包是SegWit钱包
      metadata.name = "MyFirstIdentity"
      let (mnemonic, identity) = try Identity.createIdentity(password: TestData.password, metadata: metadata)
      let ethereumWallet = identity.wallets[0]
      let bitcoinWalelt = identity.wallets[1]
    } catch {
      print("createIdentity failed, error:\(error)")
    }
    

    输出钱包(Export Wallet)

    
    let prvKey = try WalletManager.exportPrivateKey(walletID: ethereumWallet.walletID, password: TestData.password)
    print("PrivateKey: \(prvKey)")
    let mnemonics = try WalletManager.exportMnemonic(walletID: ethereumWallet.walletID, password: TestData.password)
    print("Mnemonic: \(mnemonics)")
    let keystore = try WalletManager.exportKeystore(walletID: ethereumWallet.walletID, password: TestData.password)
    print("Keystore: \(keystore)")
    
    // output:
    // PrivateKey: f653be3f639f45ea1ed3eb152829b6d881ce62257aa873891e06fa9569a8d9aa
    // Mnemonic: tide inmate cloud around wise bargain celery cement jungle melody galaxy grocery
    // Keystore: {"id":"c7575eba-3ae3-4cc3-86ba-2eb9c6839cad","version":3,"crypto":{"ciphertext":"7083ba3dd5470ba4be4237604625e05fa6b668954d270beb848365cbf6933ec5","mac":"f4f9ea8d42ff348b11fc146c396da446cc975309b3538e08a58c0b218bddd15d","cipher":"aes-128-ctr","cipherparams":{"iv":"db3f523faf4da4f1c6edcd7bc1386879"},"kdf":"pbkdf2","kdfparams":{"dklen":32,"c":10240,"prf":"hmac-sha256","salt":"0ce830e9f888dfe33c31e6cfc444d6f588161c9d4128d4066ee5dfdcbc5d0079"}},"address":"4a1c2072ac67b616e5c578fd9e2a4d30e0158471"}
    

    签署交易(SignTransaction)

    let signResult = WalletManager.ethSignTransaction(
            walletID: String,
            nonce: String,
            gasPrice: String,
            gasLimit: String,
            to: String,
            value: String,
            data: String,
            password: String,
            chainID: Int
          )
    let signedTx = signResult.signedTx //这是您需要广播的签名结果。
    let txHahs = signResult.txHash //这是txHash,您可以使用它来查找您的交易记录
    

    故障排除 (Troubleshooting)

    For macOS 10.14 Mojave and Xcode 10, install /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg since Xcode command line tools don't install to /usr/include anymore.

    相关文章

      网友评论

        本文标题:TokenCore -- iOS上的区块链私钥管理库

        本文链接:https://www.haomeiwen.com/subject/jrdxdqtx.html