Skip to content

Latest commit

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

HPWalletCore

HPWalletCore is committed to build a straightforward and easy-to-use cross platform wallet library. It proposed an unified API suite, which allows users to generate or import BTC, ETH, ETC, LTC, DASH, DOGE, QTUM and USDT tokens' private keys, public key and addresses. It also provided corresponding methods in generating raw transactions of the coins and signing of the transactions.

In addition, it is different to other third-party wallet schemes: when generating mnemonics or private keys, the HPWalletCore allowed optional parameters of the mobile phone's UDID and password to encrypt the secret. When user choose to use this added extra layer in mnemonics or private keys generation, it will provide an additional layer of security to the digital assets. Even if the mnemonics is leaked, adversaries cannot access to your digital assets without first knowing the phone's UDID and the password you set. This way, it hopefully can provide a good enough security for your digital assets.

For a Chinese version of the README file, please see the link below: 中文版🇨🇳

HPWalletCore Supports

Currently, HPWalletCore supports generating and importing of mnemonics private keys and raw transactions related operations. The specific operations that are supported by HPWalletCore are listed in the table below:

CoinMnemonics SupportPrivateKey SupportTransaction SupportExploreRemark
BTC✔️✔️✔️DecodeTxBroadcast
BCH✔️✔️✔️PushTx
DASH✔️✔️✔️BroadcastDecodeTx
DOGE✔️✔️✔️Broadcast
ETH✔️✔️✔️PushTxBroadcastSupport ERC20
ETC✔️✔️✔️PushTx
LTC✔️✔️✔️PushTx
QTUM✔️✔️✔️PushTxSupport QRC20
USDT✔️✔️✔️DecodeTxBroadcast

Environment Setup

  • Go Installation
  • Gomobile Environment Setup
  • In the hpywallet directory, compile the Android Reference Library:gomobile bind -target=android .
  • In the hpywallet directory, compile the iOS Reference Library:gomobile bind -target=ios .
  • About the missing librarys, use go get xxx .. to install them

Mnemonic Generation

Generate mnemonics using the following method:

funcGenerateMnemonic() 

Data structure returned, mnemonics

GenerateMnemonic Example

mnemonic:=hpywallet.GenerateMnemonic()
fmt.Println("Mnemonic: ", mnemonic)

Seed Generation

Seed can be generated by importing the mnemonic & password. Import mnemonics using the following method:

funcGenerateSeed(mnemonicstring, passwordstring)

Data structure returned, hex seed

GenerateSeed Example

mnemonic:="xxx xxx"seed:=hpywallet.GenerateSeed(mnemonic, "")
fmt.Println("Seed = ", seed)

Use Mnemonics to generate wallet

Private key, public key and address can be generated by importing the mnemonic. Import mnemonics using the following methods:

funcGenerateWallet(mnemonicstring, coinstring)

Data structure returned as follow:

typeWalletAccountstruct {
ResCodeint// 0 fail 1 SuccessAddressstringPublicKeystringPrivateKeystringSeedstring// root seedCoinstringErrMsgstring// fail messagesErrCodeint// err codeParams []byte// reserved fields
}

GenerateWallet Example

mnemonic:="xxx xxx"dogeWallet:=hpywallet.GenerateWallet(mnemonic, "doge")
fmt.Println("dogeWallet: ", dogeWallet)

use mnemonics & password to generate wallet

Private key, public key and address can be generated by importing mnemonics & password. Import mnemonics & password using the following methods:

funcGenerateMnemonicWallet(mnemonic, password, coinstring)

Data structure returned as WalletAccount

GenerateMnemonicWallet Example

mnemonic:="xxx xxx"btcWallet:=hpywallet.GenerateMnemonicWallet(mnemonic, "123456", "btc")
fmt.Println("btcWallet: ", btcWallet)

Use the coin's Root Seed to generate wallet

Private key, public key and address can be generated by importing the root seed & coin. Import seed & coin using the following methods:

funcGenerateSeedWallet(seedstring, coinstring)

Data structure returned as WalletAccount

GenerateSeedWallet Example

mnemonic:="xxx xxx"btcWallet:=hpywallet.GenerateSeedWallet(seed, "btc")
fmt.Println("btcWallet: ", btcWallet)

Import private key (WIF) to generate wallet

Private key, public key and address can be generated by importing the WIF (Wallet Import Format) of the private key.

The following methods are used to create a wallet with a private key:

funcImportPrivateWIF(wifstring, coinstring)

Data structure returned as WalletAccount

ImportPrivateWIF Example

mnemonic:="xxx xxx"dogeWallet:=hpywallet.GenerateWallet(mnemonic, "doge")
importWallet:=hpywallet.ImportPrivateWIF(dogeWallet.PrivateKey, "doge")
fmt.Println("importWallet: ", importWallet)

Mnemonics Or PrivateKey Generate KeyStore

The keystore file is generated by using the mnemonics or private key, UDID of the device and the password of the user's choosing.

To generate keystore file, use the following method:

funcEnKeystore(Key, password, udidstring)

Description: Key here can be either the mnemonic or the privatekey (WIF)

Data structure returned as :

typeKeystoreResultstruct {
ResultstringResCodeint// 0 fail 1 successErrMsgstring// fail reason
}

EnKeystore Example

Key:="L1oh9KNH4XpJgqDodxhjPgaEVS1qwXToWvPf2Zyn6bcm7xxxxxxx"pwd:="11111"udid:="AOIJF-QWEQR-VDFBET-YTAWWE"// EncodeenResult:=hpywallet.EnKeystore(Key, pwd, udid)
fmt.Println("Keystore : \n", enResult.Result)

KeyStore File Decrypt

The keystore file is decrypted using the KeyStore json, udid and the password.

To decrypt keystore file, use the following methods:

funcDeKeystore(json, password, udidstring)

Description: JSON is the KeyStore JSON file

Data structure returned as KeystoreResult

DeKeystore Example

enResult:="xxxxxxx"pwd:="11111"udid:="AOIJF-QWEQR-VDFBET-YTAWWE"// DecodedeResult:=hpywallet.DeKeystore(enResult, pwd, udid)
fmt.Println("PrivateKey : ", deResult.Result)

Sign a raw transaction

SignInput Some parameters are optional, the data structure is illustrated as below:

typeSignInputstruct {
PrivateKeystringCoinstringSymbolstringAmountint64// transfer amountChangeint64// transfer change amountFeeint64//transfer feeGasLimitint64GasPriceint64Typestring// contract typeSrcAddrstring// send addressDestAddrstring// destination addressContractAddrstring// contract addressMemostring// memo markSequenceint64Inputs []byte// vinsParams []byte// reserved fields
}

method:

funcSignRawTransaction(signIn*SignInput)

data structure returned as SignResult as below:

typeSignResultstruct {
ResCodeint// 0 fail 1 successCoinstring// name of the crypto tokenSymbolstring// symbolRawTXstring// rawtxTxHashstring// tx hashErrMsgstring// fail reasonErrCodeint// err codeParams []byte// reserved field
}

SignRawTransaction Example

mnemonic:="xxx xxx"btcWallet:=hpywallet.GenerateWallet(mnemonic, "btc")
item1:= hpywallet.OutPutItem{
TxHash: "921784b1e11fcbfe267a04b9e54a45e597710d0f9413e658813737c06f44a987",
Value: 1200000,
Vout: 1,
Pkscript: "76a914bc68c7efc2f672c3ea028e10ec321a9c68d5da7788ac",
}
outputs:= []hpywallet.OutPutItem{item1}
jsonInputs, _:=json.Marshal(outputs)
signInput:=&hpywallet.SignInput{
Coin: "btc",
Symbol: "btc",
PrivateKey: btcWallet.PrivateKey,
SrcAddr: btcWallet.Address,
DestAddr: btcWallet.Address,
Fee: 200000,
Amount: 100000,
Change: 900000,
Inputs: jsonInputs,
}
tranferResult:=hpywallet.SignRawTransaction(signInput)
iftranferResult.ResCode==0 {
fmt.Println("Transfer btc Msg: ", tranferResult.ErrMsg)
} else {
fmt.Println("Transfer btc RawTX: ", tranferResult.RawTX)
}

For the following main-chain currency, Inputs must be included in the call as part of the SignInput data:

  • BTC
  • USDT
  • LTC
  • QTUM
  • BCH
  • DASH

For any UTXO token, the Inputs attribute is JsonArrayToByte[OutPutItem...].Bytes

The data structure about OutPutItemis as follows:

typeOutPutItemstruct {
TxHashstringVoutuint32Valueint64Pkscriptstring// lock script
}

!Please Note!:

  • Qtum QRC20 Transaction: the ContractAddr attribute is a required parameter;

TODO LIST

Features to be completed

  • Verify the token address
  • Multi sign transaction
  • Support more chains

Thanks and more info.

Thanks btcsuitego-ethereumblocktree and others library.

[TOC]

About

HPWalletCore is committed to build a straightforward and easy-to-use cross platform wallet library.

Resources

Stars

9 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages