[![](https://jitpack.io/v/consenlabs/token-core-android.svg)](https://jitpack.io/#consenlabs/token-core-android)
## Token Core
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
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```
dependencies {
implementation 'com.github.consenlabs:token-core-android:v0.1'
}
```
## Try the API
### Init the storage to store the keystore file
```
public class MainActivity extends AppCompatActivity implements KeystoreStorage {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WalletManager.storage = this;
WalletManager.scanWallets();
}
public File getKeystoreDir() {
return this.getFilesDir();
}
}
```
### Create new Identity and derive the eth, btc wallets
```java
// You should create or recover Identity first before you create other wallets
// The last param, Metadata.P2WPKH means that the derived btc wallet is a SegWit wallet
Identity identity = Identity.createIdentity("MyFirstIdentity", SampleKey.PASSWORD, SampleKey.PASSWORD_HINT, Network.MAINNET, Metadata.P2WPKH);
Wallet ethereumWallet = identity.getWallets().get(0);
Wallet bitcoinWallet = identity.getWallets().get(1);
```
### Export Wallet
```java
String prvKey = WalletManager.exportPrivateKey(ethereumWallet.getId(), SampleKey.PASSWORD);
System.out.println(String.format("PrivateKey: %s", prvKey));
String mnemonic = WalletManager.exportMnemonic(ethereumWallet.getId(), SampleKey.PASSWORD).getMnemonic();
System.out.println(String.format("Mnemonic: %s", mnemonic));
String json = WalletManager.exportKeystore(ethereumWallet.getId(), SampleKey.PASSWORD);
System.out.println(String.format("Keystore: %s", json));
// 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
```java
EthereumTransaction tran = WalletManager.ethSign(BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, String to, BigInteger value, String data)
TxSignResult result = tran.signTransaction(chainId, SampleKey.PASSWORD, ethereumWallet);
String signedTx = result.getSignedTx(); // This is the signature result which you need to broadcast.
String txHash = result.getTxHash(); // This is txHash which you can use for locating your transaction record
```
## 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.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
IMToken核心源码-Android (147个子文件)
gradlew.bat 2KB
.gitignore 193B
.gitignore 7B
build.gradle 2KB
build.gradle 678B
settings.gradle 15B
gradlew 5KB
gradle-wrapper.jar 52KB
BitcoinTransactionTest.java 20KB
EOSWalletTest.java 18KB
StorageTest.java 18KB
BitcoinTransaction.java 17KB
WalletManager.java 17KB
IdentityTest.java 15KB
Identity.java 13KB
Keccak.java 12KB
EOSKeystore.java 12KB
WalletManagerTest.java 10KB
KeystoreTest.java 9KB
NumericUtilTest.java 8KB
Crypto.java 8KB
ValidatorTest.java 8KB
EthereumSignTest.java 8KB
SegWitWalletTest.java 7KB
CryptoTest.java 7KB
HDMnemonicKeystore.java 6KB
NumericUtil.java 6KB
EthereumSign.java 5KB
IdentityKeystore.java 5KB
TokenCoreTour.java 5KB
EOSECDSASigner.java 5KB
Wallet.java 5KB
EthereumTransaction.java 4KB
HashTest.java 4KB
Messages.java 4KB
Metadata.java 3KB
Multihash.java 3KB
EOSSign.java 3KB
AESTest.java 3KB
Hash.java 3KB
MyHMacDSAKCalculator.java 3KB
SampleKey.java 3KB
AddressCreatorTest.java 3KB
V3MnemonicKeystore.java 3KB
RlpEncoder.java 3KB
EthereumTransactionTest.java 3KB
EOSTransaction.java 3KB
V3Keystore.java 3KB
MnemonicUtilTest.java 3KB
ETHAddressValidator.java 2KB
RlpEncoderTest.java 2KB
AES.java 2KB
SCryptParams.java 2KB
PBKDF2Params.java 2KB
SegWitBitcoinAddressCreator.java 2KB
LegacyEOSKeystore.java 2KB
RlpString.java 2KB
ByteUtilTest.java 2KB
EthereumAddressCreator.java 2KB
BIP44Util.java 2KB
EOSKey.java 2KB
MetadataValidator.java 2KB
PrivateKeyValidator.java 2KB
PBKDF2Crypto.java 1KB
WIFValidator.java 1KB
SCryptCrypto.java 1KB
MnemonicUtil.java 1KB
PBKDFTest.java 1KB
SignatureData.java 1KB
WalletSupport.java 1KB
AddressCreatorManager.java 1KB
ResourcesManager.java 1KB
ScryptTest.java 1KB
BitcoinAddressCreator.java 1KB
MultihashTest.java 1KB
CipherParams.java 1017B
KeyPair.java 979B
Keystore.java 945B
TxSignResult.java 857B
ExampleInstrumentedTest.java 731B
EncMnemonicKeystore.java 723B
CachedDerivedKey.java 696B
ByteUtil.java 671B
V3Ignore.java 667B
ChainId.java 646B
TxMultiSignResult.java 540B
IMTKeystore.java 530B
Network.java 491B
RlpList.java 450B
ChainType.java 418B
ExampleUnitTest.java 392B
WalletKeystore.java 382B
EncPair.java 374B
RLPTestCase.java 372B
MnemonicAndPath.java 365B
TokenException.java 325B
LocalFileStorage.java 311B
DateUtil.java 282B
KDFParams.java 264B
TransactionSigner.java 221B
共 147 条
- 1
- 2
资源评论
- agony482020-05-24加载比较慢!
涛餮xt
- 粉丝: 10
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功