• Stars
    star
    648
  • Rank 67,776 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a blockchain private key management library on 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:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

dependencies {
	implementation 'com.github.consenlabs:token-core-android:v0.1'
}

Step 3. Add the JAVA8 support to your build.gradle

android {
    ……
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
   ……
}

Step 4. (Optional) When you wants to debug your app in Android Oreo you shoud add the blow code to your build.gradle. Pls ref to https://issuetracker.google.com/issues/65941637 for more info.

android {
    ……
    packagingOptions {
        exclude 'lib/x86_64/darwin/libscrypt.dylib'
    }
   ……
}

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

// 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 = new EthereumTransaction(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.

More Repositories

1

token-core-ios

a blockchain private key management library on iOS
Swift
879
star
2

token-profile

Blockchain coin and token profile collection
TypeScript
816
star
3

token-core

Next generation core inside imToken Wallet.
Rust
286
star
4

tokenlon-contracts

Tokenlon is a decentralized exchange and payment settlement protocol based on blockchain technology. Visit https://tokenlon.im/
Solidity
77
star
5

eos-stake-vote-dapp

EOS stake vote dapp developed by imToken Dev Team
JavaScript
55
star
6

tokenlon-sdk

The Gateway to Decentralized Exchange
TypeScript
54
star
7

tokenlon-mmsk

Tokenlon Market Maker Service Kit
TypeScript
41
star
8

eos-bp-profile

EOS block producer profile collection
JavaScript
34
star
9

carbonvote

CSS
29
star
10

ethtaipei2023-aa-workshop

Account abstraction workshop @ ETHTaipei 2023
Solidity
14
star
11

imkey-core

Next generation core inside imKey Wallet.
C
14
star
12

imkey-manager

Using the imKey on your PC or Mac
JavaScript
13
star
13

tokenlon-jssdk

Please move to new repo https://github.com/consenlabs/tokenlon-v5-sdk
TypeScript
9
star
14

webview

WebView utils for imToken application v2.
TypeScript
9
star
15

tokenlon-v5-subgraph

define how to index tokenlon exchange data on thegraph protocol
TypeScript
8
star
16

evm-box

use EVM Compatible Network with ease.
TypeScript
7
star
17

imkey-web3-provider

TypeScript
6
star
18

cosmos-staking-dapp

Dapp for staking and vote on Cosmos Network
TypeScript
5
star
19

polkadot-staking-dapp

Polkadot & Kusama Dapp for staking & voting
TypeScript
5
star
20

token-getting-started

Getting started for imToken Applicatoin.
TypeScript
4
star
21

tokenlon-utils

helper functions for tokenlon
TypeScript
4
star
22

tokenlon-contracts-lib-js

Common utility functions (e.g., signing order, encoding data) to interact with Tokenlon contracts.
TypeScript
3
star
23

dapp-url-generator

DApp Url generator in imToken App
TypeScript
2
star
24

tokenlon-dapp-template

A tokenlon dapp template
JavaScript
2
star
25

lotus

Go
2
star
26

imkey-connectjs

The JS SDK of imKey
TypeScript
2
star
27

memory-cache

key-value pair cache in memory.
TypeScript
2
star
28

tezos_index

Go
1
star
29

tokenlon-security

1
star
30

pingpp-react-native

Java
1
star
31

catch-error

a decorator that replace try catch
TypeScript
1
star
32

token-core-monorepo

Monorepo which contains token-core and imkey-core
C
1
star