token-core-iosa blockchain private key management library on iOS
TokenCore
TokenCore is a blockchain library. TokenCore provides the relatively consistent API that allows you to manage your wallets and sign transactions in BTC, ETH and EOS chains simultaneously. In addition, TokenCore introduces the concept of 'identity', you can use the same mnemonic to manage wallets on the three chains.
Installation
To install TokenCore, use CocoaPods and add this to your Podfile:
pod "TokenCore", git: "https://github.com/consenlabs/token-core-ios.git", branch: "master"
Run the Example
The example show how to manager the wallet and sign transaction, the eos sign will coming soon.
$ cd Example
$ pod install
Try the API
Create new Identity and derive the eth, btc wallets
// You should create or recover Identity first before you create other wallets
do {
var metadata = WalletMeta(source: .newIdentity)
metadata.network = Network.mainnet
metadata.segWit = .p2wpkh // .p2wpkh means that the derived btc wallet is a SegWit wallet
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 // This is the signature result which you need to broadcast.
let txHahs = signResult.txHash // This is txHash which you can use for locating your transaction record
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.
TODO
- Test on Objective-C
- upgrade the
BigInt
from 3.0 to 3.1
Copyright and License
Copyright 2018 imToken PTE. LTD.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Thanks and more info
Thanks bitcoinj, CoreBitcoin and others library.
评论
iOS 17.5Beta2 发布,小细节
苹果今天更新了iOS17.5 beta2测试版,iOS17.5 beta2版本号:21F5058e。本次更新大小为562.6MB,机型不同大小有所差异。 更新变化 iOS 17.5 beta2针对欧盟市场,推出了对基于网络的应用程序分发的全新支持功能。开发人员现在有了将应用程序直
宅哥技术
0
iOS 模拟器终于上架,手慢无,附300+游戏
AltStore开发者放大招!首款Delta游戏模拟器正式问世,就在今天凌晨,AltStore自签工具开发者,推出了Delta游戏模拟器,更是为我们带来了一个充满怀旧与乐趣的游戏世界! Delta 游戏模拟器支持的游戏主机如下方图片,我都进行了翻译方便大家查看,只需下载相应的游戏
宅哥技术
0
SpringBoot接口安全快试试用 API Key 来保护吧
星标▲Java学习之道▲一起成长,一起学习~目录1、概述2、REST API Security3、用API Keys保护REST API4、测试文章来源: https://www.baeldung.com/spring-boot-api-key-secret1、概述安全性在REST API开发中扮演着重要...
Java学习之道
0
iOS程序员失业,老婆威胁要堕胎,怎么办?
近几年互联网增长放缓,不少大厂裁员,生活中的困境迫使人们不得不做出艰难的选择。深圳一位iOS 程序员面临失业,家庭经济陷入困境的情况下,他的妻子威胁要堕胎,这一事件引发了广泛的社会关注。一些网友认为,在面...
Python涨薪研究所
0
史上最全的 iOS 各种测试工具集锦!
引言: 随着移动互联网的兴起,APP 测试的越来越被重视!Android 系统因为自己的开源性,测试工具和测试方法比较广为流传,但是 iOS 系统的私密性,导致很多测试的执行都有点麻烦。 为了帮助大家更好的执行 iOS APP...
测试开发技术
0
iOS 上的 PWA:我们现在的处境
苹果试图消灭其 App Store 唯一可行替代品的令人困惑的细节。 苹果公司在 iOS 17.4 中彻底破坏了渐进式 Web 应用程序(PWA),给它们造成了巨大的破坏,这让全球的开发者感到沮丧和困惑。这不仅是因为苹果最近改进了...
前端全栈开发者
0
狐讯 | 苹果 iOS 再面临侧载压力;广汽三菱正式更名易主
苹果 iOS 再面临侧载压力 据俄新社报道,俄罗斯联邦数字发展部正在推动一项与欧盟 DMA 法案类似的立法,要求苹果公司向 iPhone 等用户开放安装第三方应用商店的权限。 俄罗斯 ROCIT 董事会主席称:目前俄罗斯相关部...
胡乐枫
0
快试试用 API Key 来保护你的 SpringBoot 接口安全吧
目录 1、概述 2、REST API Security 3、用API Keys保护REST API 4. 测试 文章来源:https://www.baeldung.com/spring-boot-api-key-secret 1、概述 安全性在REST API开发中扮演着重要的角色。一个不安全的REST API可...
Java专栏
0