Skip to content

The core components of the blockchain wallet backend, support a variety of blockchain address generation and offline signatures

License

Notifications You must be signed in to change notification settings

RookieExaminer/tokencore

 
 

Repository files navigation

Tokencore

Build Status Issues Pull Requests Contributors License

Contact

Use Cases

This serves as the exchange wallet backend. For more details, check out java-wallet.

Introduction

Tokencore is a central component for blockchain wallet backends. It currently supports the following:

  • BTC, OMNI, ETH, ERC20
  • TRX, TRC20, BCH, BSV
  • DOGE, DASH, LTC, FILECOIN

Integration

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.galaxyscitech:tokencore:1.2.7'
}

Maven

<repositories>
    <repository>
        <id>tronj</id>
        <url>https://dl.bintray.com/tronj/tronj</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.galaxyzxcv</groupId>
    <artifactId>tokencore</artifactId>
    <version>1.2.7</version>
</dependency>

Sample Test

View a sample test at Tokencore Test Sample.

Usage Guide

Initialize Identity

try {
    Files.createDirectories(Paths.get("${keyStoreProperties.dir}/wallets"));
} catch(Throwable ignored) {}

WalletManager.storage = new KeystoreStorage();
WalletManager.scanWallets();
String password = "123456";
Identity identity = Identity.getCurrentIdentity();

if(identity == null) {
    Identity.createIdentity("token", password, "", Network.MAINNET, Metadata.P2WPKH);
}

Generate Wallet

Identity identity = Identity.getCurrentIdentity();
String password = "123456";
Wallet wallet = identity.deriveWalletByMnemonics(ChainType.BITCOIN, password, MnemonicUtil.randomMnemonicCodes());
System.out.println(wallet.getAddress());

Offline Signature

Offline signing refers to the process of creating a digital signature for a transaction without connecting to the internet. This method enhances security by ensuring private keys never come in contact with an online environment. Here's how you can create an offline signature with Tokencore for Bitcoin and TRON:

Bitcoin

  1. Set Up Transaction Details

    Define the details of your Bitcoin transaction, including recipient's address, change index, amount to be transferred, and the fee.

    String password = "123456";
    String toAddress = "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9";
    int changeIdx = 0;
    long amount = 1000L;
    long fee = 555L;
  2. Fetch UTXOs

    You'll need UTXOs (Unspent Transaction Outputs) for the transaction. Usually, these are fetched from a node or an external API.

    ArrayList<BitcoinTransaction.UTXO> utxos = new ArrayList<>();
  3. Initialize Transaction & Sign

    With all the details in place, initialize the Bitcoin transaction and sign it offline.

    BitcoinTransaction bitcoinTransaction = new BitcoinTransaction(toAddress, changeIdx, amount, fee, utxos);
    Wallet wallet = WalletManager.findWalletByAddress(ChainType.BITCOIN, "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9");
    TxSignResult txSignResult = bitcoinTransaction.signTransaction(String.valueOf(ChainId.BITCOIN_MAINNET), password, wallet);
    System.out.println(txSignResult);

TRON

  1. Set Up Transaction Details

    Define your TRON transaction details, including the sender's address, recipient's address, and amount.

    String from = "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8";
    String to = "TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3";
    long amount = 1;
    String password = "123456";
  2. Initialize Transaction & Sign

    Once you have the transaction details, initialize the TRON transaction and sign it offline.

    TronTransaction transaction = new TronTransaction(from, to, amount);
    Wallet wallet = WalletManager.findWalletByAddress(ChainType.BITCOIN, "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8");
    TxSignResult txSignResult = transaction.signTransaction(String.valueOf(ChainId.BITCOIN_MAINNET), password, wallet);
    System.out.println(txSignResult);

Remember, offline signing enhances security but requires a thorough understanding of transaction construction to avoid errors.

Note: Tokencore is a functional component for digital currency. It's primarily for learning purposes and doesn't offer a complete blockchain business suite.

About

The core components of the blockchain wallet backend, support a variety of blockchain address generation and offline signatures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%