How to use bs58check - 10 common examples

To help you get started, we’ve selected a few bs58check examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ArkEcosystem / ark-js / lib / v2 / transactions / crypto.js View on Github external
bb.writeInt(transaction.timestamp);
	bb.append(transaction.senderPublicKey, "hex");
	bb.writeLong(transaction.fee);
	if(transaction.vendorFieldHex){
		bb.writeByte(transaction.vendorFieldHex.length/2);
		bb.append(transaction.vendorFieldHex, "hex");
	}
	else {
		bb.writeByte(0x00);
	}

	switch (transaction.type) {
		case 0: // Transfer
			bb.writeLong(transaction.amount);
			bb.writeInt(transaction.expiration);
			bb.append(bs58check.decode(transaction.recipientId));
			break;

		case 1: // Signature
			bb.append(transaction.asset.signature.publicKey,"hex");
			break;

		case 2: // Delegate
			var delegateBytes = new Buffer(transaction.asset.delegate.username, "utf8");
			bb.writeByte(delegateBytes.length/2);
			bb.append(delegateBytes,"hex");
			break;

		case 3: // Vote
			var voteBytes = transaction.asset.votes.map(function(vote){
				return (vote[0] == "+" ? "01" : "00") + vote.slice(1);
			}).join("");
github bitcoinjs / bip38 / index.js View on Github external
function getAddress (d, compressed) {
  var Q = curve.G.multiply(d).getEncoded(compressed)
  var hash = hash160(Q)
  var payload = Buffer.allocUnsafe(21)
  payload.writeUInt8(0x00, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38
  hash.copy(payload, 1)

  return bs58check.encode(payload)
}
github bitcoinjs / bitcoinjs-lib / src / address.js View on Github external
function fromBase58Check(address) {
    const payload = bs58check.decode(address);
    // TODO: 4.0.0, move to "toOutputScript"
    if (payload.length < 21)
        throw new TypeError(address + ' is too short');
    if (payload.length > 21)
        throw new TypeError(address + ' is too long');
    const version = payload.readUInt8(0);
    const hash = payload.slice(1);
    return { version, hash };
}
exports.fromBase58Check = fromBase58Check;
github coreyphillips / rn-bitcoinjs-lib / src / address.js View on Github external
function fromBase58Check(address) {
  const payload = bs58check.decode(address);
  // TODO: 4.0.0, move to "toOutputScript"
  if (payload.length < 21) throw new TypeError(address + ' is too short');
  if (payload.length > 21) throw new TypeError(address + ' is too long');
  const version = payload.readUInt8(0);
  const hash = payload.slice(1);
  return { version, hash };
}
exports.fromBase58Check = fromBase58Check;
github ArkEcosystem / ark-js / lib / v2 / transactions / crypto.js View on Github external
function getAddress(publicKey, version){
	var pubKeyRegex = /^[0-9A-Fa-f]{66}$/;
	if(!version){
		version = networkVersion;
	}
	if (!pubKeyRegex.test(publicKey))
		throw "publicKey is invalid";
	var buffer = crypto_utils.ripemd160(new Buffer(publicKey, "hex"));
	var payload = new Buffer(21);
	payload.writeUInt8(version, 0);
	buffer.copy(payload, 1);

	return bs58check.encode(payload);
}
github ArkEcosystem / core / packages / crypto / lib / models / transaction.js View on Github external
if (transaction.vendorField) {
      const vf = Buffer.from(transaction.vendorField, 'utf8')
      bb.writeByte(vf.length)
      bb.append(vf)
    } else if (transaction.vendorFieldHex) {
      bb.writeByte(transaction.vendorFieldHex.length / 2)
      bb.append(transaction.vendorFieldHex, 'hex')
    } else {
      bb.writeByte(0x00)
    }

    if (transaction.type === TRANSACTION_TYPES.TRANSFER) {
      bb.writeUInt64(+new Bignum(transaction.amount).toFixed())
      bb.writeUInt32(transaction.expiration || 0)
      bb.append(bs58check.decode(transaction.recipientId))
    } else if (transaction.type === TRANSACTION_TYPES.VOTE) {
      const voteBytes = transaction.asset.votes
        .map(vote => (vote[0] === '+' ? '01' : '00') + vote.slice(1))
        .join('')
      bb.writeByte(transaction.asset.votes.length)
      bb.append(voteBytes, 'hex')
    } else if (transaction.type === TRANSACTION_TYPES.SECOND_SIGNATURE) {
      bb.append(transaction.asset.signature.publicKey, 'hex')
    } else if (transaction.type === TRANSACTION_TYPES.DELEGATE_REGISTRATION) {
      const delegateBytes = Buffer.from(
        transaction.asset.delegate.username,
        'utf8',
      )
      bb.writeByte(delegateBytes.length)
      bb.append(delegateBytes, 'hex')
    } else if (transaction.type === TRANSACTION_TYPES.MULTI_SIGNATURE) {
github cryptocoinjs / hdkey / lib / hdkey.js View on Github external
get: function () {
    return bs58check.encode(serialize(this, this.versions.public, this.publicKey))
  }
})
github bitcoinjs / bitcoinjs-lib / src / address.js View on Github external
function toBase58Check(hash, version) {
    typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments);
    const payload = Buffer.allocUnsafe(21);
    payload.writeUInt8(version, 0);
    hash.copy(payload, 1);
    return bs58check.encode(payload);
}
exports.toBase58Check = toBase58Check;
github bitcoinjs / bitcoinjs-lib / ts_src / payments / p2sh.ts View on Github external
lazy.prop(o, 'address', () => {
    if (!o.hash) return;

    const payload = Buffer.allocUnsafe(21);
    payload.writeUInt8(o.network!.scriptHash, 0);
    o.hash.copy(payload, 1);
    return bs58check.encode(payload);
  });
  lazy.prop(o, 'hash', () => {
github bitcoinjs / bitcoinjs-lib / ts_src / payments / p2pkh.ts View on Github external
lazy.prop(o, 'address', () => {
    if (!o.hash) return;

    const payload = Buffer.allocUnsafe(21);
    payload.writeUInt8(network.pubKeyHash, 0);
    o.hash.copy(payload, 1);
    return bs58check.encode(payload);
  });
  lazy.prop(o, 'hash', () => {

bs58check

A straightforward implementation of base58-check encoding

MIT
Latest version published 5 months ago

Package Health Score

74 / 100
Full package analysis

Popular bs58check functions