TokenCoreisablockchainlibrary.TokenCoreprovidestherelativelyconsistentAPIthatallowsyoutomanageyourwalletsandsigntransactionsinBTC,ETHandEOSchainssimultaneously.Inaddition,TokenCoreintroducestheconceptof'identity',youcanusethesamemnemonictomanagewalletsonthethreechains.
InstallationToinstallTokenCore,useCocoaPodsandaddthistoyourPodfile:
pod"TokenCore",git:"https://github.com/consenlabs/token-core-ios.git",branch:"master"RuntheExampleTheexampleshowhowtomanagerthewalletandsigntransaction,theeossignwillcomingsoon.
$cdExample$podinstallTrytheAPICreatenewIdentityandderivetheeth,btcwallets//YoushouldcreateorrecoverIdentityfirstbeforeyoucreateotherwalletsdo{varmetadata=WalletMeta(source:.newIdentity)metadata.network=Network.mainnetmetadata.segWit=.p2wpkh//.p2wpkhmeansthatthederivedbtcwalletisaSegWitwalletmetadata.name="MyFirstIdentity"let(mnemonic,identity)=tryIdentity.createIdentity(password:TestData.password,metadata:metadata)letethereumWallet=identity.wallets[0]letbitcoinWalelt=identity.wallets[1]}catch{print("createIdentityfailed,error:\(error)")}ExportWalletletprvKey=tryWalletManager.exportPrivateKey(walletID:ethereumWallet.walletID,password:TestData.password)print("PrivateKey:\(prvKey)")letmnemonics=tryWalletManager.exportMnemonic(walletID:ethereumWallet.walletID,password:TestData.password)print("Mnemonic:\(mnemonics)")letkeystore=tryWalletManager.exportKeystore(walletID:ethereumWallet.walletID,password:TestData.password)print("Keystore:\(keystore)")//output://PrivateKey:f653be3f639f45ea1ed3eb152829b6d881ce62257aa873891e06fa9569a8d9aa//Mnemonic:tideinmatecloudaroundwisebargaincelerycementjunglemelodygalaxygrocery//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"}SignTransactionletsignResult=WalletManager.ethSignTransaction(walletID:String,nonce:String,gasPrice:String,gasLimit:String,to:String,value:String,data:String,password:String,chainID:Int)letsignedTx=signResult.signedTx//Thisisthesignatureresultwhichyouneedtobroadcast.lettxHahs=signResult.txHash//ThisistxHashwhichyoucanuseforlocatingyourtransactionrecordTroubleshootingFormacOS10.14MojaveandXcode10,install/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkgsinceXcodecommandlinetoolsdon'tinstallto/usr/includeanymore.
TODOTestonObjective-CupgradetheBigIntfrom3.0to3.1CopyrightandLicenseCopyright2018imTokenPTE.LTD.LicensedundertheApacheLicense,Version2.0(the"License");youmaynotusethisfileexceptincompliancewiththeLicense.YoumayobtainacopyoftheLicenseathttps://www.apache.org/licenses/LICENSE-2.0Unlessrequiredbyapplicablelaworagreedtoinwriting,softwaredistributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicenseforthespecificlanguagegoverningpermissionsandlimitationsundertheLicense.ThanksandmoreinfoThanksbitcoinj,CoreBitcoinandotherslibrary.
评论