MCPcopy Index your code
hub / github.com/consenlabs/token-core-android

github.com/consenlabs/token-core-android @v0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1 ↗ · + Follow
757 symbols 2,866 edges 97 files 59 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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:

    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

Create new Identity and derive the eth, btc wallets

// 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


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

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.

Extension points exported contracts — how you extend this code

Validator (Interface)
Created by xyz on 2018/2/27. [9 implementers]
app/src/main/java/org/consenlabs/tokencore/wallet/validators/Validator.java
AddressCreator (Interface)
(no doc) [6 implementers]
app/src/main/java/org/consenlabs/tokencore/wallet/address/AddressCreator.java
TransactionSigner (Interface)
(no doc) [7 implementers]
app/src/main/java/org/consenlabs/tokencore/wallet/transaction/TransactionSigner.java
KeystoreStorage (Interface)
Created by xyz on 2018/4/8. [2 implementers]
app/src/main/java/org/consenlabs/tokencore/wallet/KeystoreStorage.java
EncMnemonicKeystore (Interface)
(no doc) [4 implementers]
app/src/main/java/org/consenlabs/tokencore/wallet/keystore/EncMnemonicKeystore.java

Core symbols most depended-on inside this repo

hexToBytes
called by 83
app/src/main/java/org/consenlabs/tokencore/foundation/utils/NumericUtil.java
bytesToHex
called by 71
app/src/main/java/org/consenlabs/tokencore/foundation/utils/NumericUtil.java
getMetadata
called by 53
app/src/main/java/org/consenlabs/tokencore/wallet/Wallet.java
getId
called by 41
app/src/main/java/org/consenlabs/tokencore/wallet/Wallet.java
getAddress
called by 38
app/src/main/java/org/consenlabs/tokencore/wallet/Wallet.java
setSource
called by 38
app/src/main/java/org/consenlabs/tokencore/wallet/model/Metadata.java
getBytes
called by 35
app/src/main/java/org/consenlabs/tokencore/foundation/rlp/RlpString.java
fromPrivate
called by 28
app/src/main/java/org/consenlabs/tokencore/wallet/transaction/EOSKey.java

Shape

Method 652
Class 95
Interface 8
Enum 2

Languages

Java100%

Modules by API surface

app/src/main/java/org/consenlabs/tokencore/wallet/keystore/EOSKeystore.java40 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/transaction/BitcoinTransaction.java35 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/WalletManager.java34 symbols
app/src/main/java/org/consenlabs/tokencore/foundation/crypto/Crypto.java32 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/model/Metadata.java24 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/Identity.java22 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/keystore/HDMnemonicKeystore.java20 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/Wallet.java20 symbols
app/src/main/java/org/consenlabs/tokencore/foundation/utils/NumericUtil.java20 symbols
app/src/test/java/org/consenlabs/tokencore/wallet/EOSWalletTest.java18 symbols
app/src/main/java/org/consenlabs/tokencore/wallet/keystore/IdentityKeystore.java18 symbols
app/src/main/java/org/consenlabs/tokencore/foundation/crypto/SCryptParams.java16 symbols

For agents

$ claude mcp add token-core-android \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact