本文整理汇总了Java中com.google.bitcoin.core.Base58类的典型用法代码示例。如果您正苦于以下问题:Java Base58类的具体用法?Java Base58怎么用?Java Base58使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Base58类属于com.google.bitcoin.core包,在下文中一共展示了Base58类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signInput
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
private static byte[] signInput(NetworkParameters params, Transaction tx, int tx_input_index, String base58PrivKey, BitcoinScript script, SigHash sigHash) {
Log.d("SharedCoin", "SharedCoin signInput tx.getInputs().size " + tx.getInputs().size());
Log.d("SharedCoin", "SharedCoin signInput tx_input_index " + tx_input_index);
Log.d("SharedCoin", "SharedCoin signInput base58PrivKey " + base58PrivKey);
try {
ECKey key = new ECKey(Base58.decode(base58PrivKey), null);
Log.d("SharedCoin", "SharedCoin signInput key.toAddress " + key.toAddress(params).toString());
TransactionSignature transactionSignature = tx.calculateSignature(tx_input_index, key, null, script.getProgram(), SigHash.ALL, false);
byte[] signedScript = Script.createInputScript(transactionSignature.encodeToBitcoin(), key.getPubKey());
//ArrayUtils.reverse(signedScript);
String signedScriptHex = new String(Hex.encode(signedScript));
Log.d("SharedCoin", "SharedCoin signInput signedScriptHex " + signedScriptHex);
Log.d("SharedCoin", "SharedCoin signInput script.program hex " + new String(Hex.encode(script.getProgram())));
return signedScript;
} catch (Exception e) {
Log.d("SharedCoin", "SharedCoin signInput e " + e.getLocalizedMessage());
e.printStackTrace();
}
return null;
}
示例2: toString
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
@Override
public String toString() {
if (_toStringCache == null) {
int length = hash160.getBytes().length;
byte[] addressBytes = new byte[1 + length + 4];
addressBytes[0] = (byte) version;
System.arraycopy(hash160.getBytes(), 0, addressBytes, 1, length);
byte[] check = Utils.doubleDigest(addressBytes, 0, length + 1);
System.arraycopy(check, 0, addressBytes, length + 1, 4);
_toStringCache = Base58.encode(addressBytes);
}
return _toStringCache;
}
示例3: createMasterPubKeyFromPubB58
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public static DeterministicKey createMasterPubKeyFromPubB58(String xpubstr)
throws AddressFormatException
{
byte[] data = Base58.decodeChecked(xpubstr);
ByteBuffer ser = ByteBuffer.wrap(data);
if (ser.getInt() != 0x0488B21E)
throw new AddressFormatException("bad xpub version");
ser.get(); // depth
ser.getInt(); // parent fingerprint
ser.getInt(); // child number
byte[] chainCode = new byte[32];
ser.get(chainCode);
byte[] pubBytes = new byte[33];
ser.get(pubBytes);
return HDKeyDerivation.createMasterPubKeyFromBytes(pubBytes, chainCode);
}
示例4: dumps
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public JSONObject dumps() {
try {
JSONObject obj = new JSONObject();
obj.put("addrNum", mAddrNum);
obj.put("path", mPath);
obj.put("pubBytes", Base58.encode(mPubBytes));
obj.put("numTrans", mNumTrans);
obj.put("balance", mBalance);
obj.put("available", mAvailable);
return obj;
}
catch (JSONException ex) {
throw new RuntimeException(ex); // Shouldn't happen.
}
}
示例5: addKey
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
protected boolean addKey(ECKey key, String address, String label, String device_name, String device_version) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String base58Priv = new String(Base58.encode(key.getPrivKeyBytes()));
map.put("addr", address);
if (label != null) {
if (label.length() == 0 || label.length() > 255)
throw new Exception("Label must be between 0 & 255 characters");
map.put("label", label);
}
if (this.isDoubleEncrypted()) {
if (temporySecondPassword == null)
throw new Exception("You must provide a second password");
map.put("priv", encryptPK(base58Priv, getSharedKey(), temporySecondPassword, this.getDoubleEncryptionPbkdf2Iterations()));
} else {
map.put("priv", base58Priv);
}
map.put("created_time", System.currentTimeMillis());
if (device_name != null)
map.put("created_device_name", device_name);
if (device_version != null)
map.put("created_device_version", device_version);
if (getKeysMap().add(map)) {
return true;
} else {
throw new Exception("Error inserting address into keymap");
}
}
示例6: dumps
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public JSONObject dumps() {
try {
JSONObject obj = new JSONObject();
obj.put("xpub", mAccount.xpubstr());
obj.put("account", mAccount.dumps());
obj.put("workaroundPrivKey",
Base58.encode(mWorkaroundKey.getPrivKeyBytes()));
return obj;
}
catch (JSONException ex) {
throw new RuntimeException(ex); // Shouldn't happen.
}
}
示例7: HDAddress
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public HDAddress(NetworkParameters params,
DeterministicKey chainKey,
JSONObject addrNode)
throws RuntimeException, JSONException {
mParams = params;
mAddrNum = addrNode.getInt("addrNum");
mPath = addrNode.getString("path");
// Derive ECKey.
byte[] prvBytes = null;
try {
mPubBytes = Base58.decode(addrNode.getString("pubBytes"));
} catch (AddressFormatException ex) {
throw new RuntimeException("failed to decode pubBytes");
}
mECKey = new ECKey(prvBytes, mPubBytes);
// Set creation time to BTCReceive epoch.
mECKey.setCreationTimeSeconds(EPOCH);
// Derive public key, public hash and address.
mPubKey = mECKey.getPubKey();
mPubKeyHash = mECKey.getPubKeyHash();
mAddress = mECKey.toAddress(mParams);
// Initialize transaction count and balance. If we don't have
// a persisted available amount, presume it is all available.
mNumTrans = addrNode.getInt("numTrans");
mBalance = addrNode.getLong("balance");
mAvailable = addrNode.has("available") ?
addrNode.getLong("available") : mBalance;
mLogger.info("read address " + mPath + ": " + mAddress.toString());
}
示例8: toBase58
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
static String toBase58(byte[] ser) {
return Base58.encode(addChecksum(ser));
}
示例9: testEncode
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
private String testEncode(String what) throws AddressFormatException {
return new String(Hex.encode(Base58.decodeChecked(what)));
}
示例10: parseBIP38
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public static ECKey parseBIP38 (String input, String password) throws Exception
{
byte[] store = Base58.decode(input);
if ( store.length != 43 )
{
throw new Exception ("invalid key length for BIP38");
}
boolean ec = false;
boolean compressed = false;
boolean hasLot = false;
if ( (store[1] & 0xff) == 0x42 )
{
if ( (store[2] & 0xff) == 0xc0 )
{
// non-EC-multiplied keys without compression (prefix 6PR)
}
else if ( (store[2] & 0xff) == 0xe0 )
{
// non-EC-multiplied keys with compression (prefix 6PY)
compressed = true;
}
else
{
throw new Exception ("invalid key");
}
}
else if ( (store[1] & 0xff) == 0x43 )
{
// EC-multiplied keys without compression (prefix 6Pf)
// EC-multiplied keys with compression (prefix 6Pn)
ec = true;
compressed = (store[2] & 0x20) != 0;
hasLot = (store[2] & 0x04) != 0;
if ( (store[2] & 0x24) != store[2] )
{
throw new Exception ("invalid key");
}
}
else
{
throw new Exception ("invalid key");
}
byte[] checksum = new byte[4];
System.arraycopy (store, store.length - 4, checksum, 0, 4);
byte[] ekey = new byte[store.length - 4];
System.arraycopy (store, 0, ekey, 0, store.length - 4);
byte[] hash = hash (ekey);
for ( int i = 0; i < 4; ++i )
{
if ( hash[i] != checksum[i] )
{
throw new Exception ("checksum mismatch");
}
}
if ( ec == false )
{
return parseBIP38NoEC (store, password, compressed);
}
else
{
return parseBIP38EC (store, password, compressed, hasLot);
}
}
示例11: BitcoinAddress
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public BitcoinAddress(String humanReadable) throws AddressFormatException {
byte[] tmp = Base58.decodeChecked(humanReadable);
version = (short) (tmp[0] & 0xFF);
byte[] bytes = new byte[tmp.length - 1];
System.arraycopy(tmp, 1, bytes, 0, tmp.length - 1);
this.hash160 = new Hash(bytes);
}
示例12: decodeBase58PK
import com.google.bitcoin.core.Base58; //导入依赖的package包/类
public static ECKey decodeBase58PK(String base58Priv) throws Exception {
byte[] privBytes = Base58.decode(base58Priv);
// Prppend a zero byte to make the biginteger unsigned
byte[] appendZeroByte = ArrayUtils.addAll(new byte[1], privBytes);
ECKey ecKey = new ECKey(new BigInteger(appendZeroByte));
return ecKey;
}