How to use bs58 - 10 common examples

To help you get started, we’ve selected a few bs58 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 maxogden / emojilock / minilock.js View on Github external
function publicKeyFromId (id) {
  // The last byte is the checksum, slice it off
  return new Uint8Array(Base58.decode(id).slice(0, 32))
}
github kingswisdom / SteemMessenger / view / js / crypto / steem-js / auth / ecc / src / key_private.js View on Github external
static fromWif(_private_wif) {
        var private_wif = new Buffer(base58.decode(_private_wif));
        var version = private_wif.readUInt8(0);
        assert.equal(0x80, version, `Expected version ${0x80}, instead got ${version}`);
        // checksum includes the version
        var private_key = private_wif.slice(0, -4);
        var checksum = private_wif.slice(-4);
        var new_checksum = hash.sha256(private_key);
        new_checksum = hash.sha256(new_checksum);
        new_checksum = new_checksum.slice(0, 4);
        if (checksum.toString() !== new_checksum.toString())
            throw new Error('Invalid WIF key (checksum miss-match)')

        private_key = private_key.slice(1);
        return PrivateKey.fromBuffer(private_key);
    }
github orbs-network / orbs-network-typescript / projects / common-library-typescript / src / CryptoUtils.ts View on Github external
public verifySignature(signer: string, data: Buffer | string, signature: string): boolean {
    // TODO remove dummy keys
    const publicKey: PublicKey = this.nodePublicKeys.get(signer) || this.nodePublicKeys.get("dummy");
    logger.debug(`Got public key ${base58.encode(publicKey)} for ${signer}`);
    if (!publicKey) {
      return false;
    }
    const dataBuf: Buffer = (typeof(data) === "string") ? new Buffer(data, "utf8") : data;
    const digest: Buffer = crypto.createHash("SHA256").update(dataBuf).digest();
    return ec.verify(digest, base58.decode(signature), publicKey);
  }
github OriginProtocol / origin / experimental / origin-ipfs / src / index.js View on Github external
function getIpfsHashFromBytes32(bytes32Hex) {
  // Add our default ipfs values for first 2 bytes:
  // function:0x12=sha2, size:0x20=256 bits
  // and cut off leading "0x"
  const hashHex = '1220' + bytes32Hex.slice(2)
  const hashBytes = Buffer.from(hashHex, 'hex')
  const hashStr = bs58.encode(hashBytes)
  return hashStr
}
github maxogden / emojilock / minilock.js View on Github external
function validateId (id) {
  var idRegex = /^[1-9ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{40,55}$/
  if (!idRegex.test(id)) return false

  var bytes = Base58.decode(id)
  if (bytes.length !== 33) return false

  var hash = new BLAKE2s(1)
  hash.update(bytes.slice(0, 32))

  return hash.digest()[0] === bytes[32]
}
github realitio / realitio-dapp / assets / js / scripts / main.js View on Github external
function bytes32ToIPFSHash(hash_hex) {
    //console.log('bytes32ToIPFSHash starts with hash_buffer', hash_hex.replace(/^0x/, ''));
    var buf = new Buffer(hash_hex.replace(/^0x/, '1220'), 'hex')
    return bs58.encode(buf)
}
github kingswisdom / SteemMessenger / view / js / crypto / steem-js / auth / ecc / src / key_public.js View on Github external
toPublicKeyString(address_prefix = 'STM') {
        if(this.pubdata) return address_prefix + this.pubdata
        const pub_buf = this.toBuffer();
        const checksum = hash.ripemd160(pub_buf);
        const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
        this.pubdata = base58.encode(addy)
        return address_prefix + this.pubdata;
    }
github steemit / steem-js / src / auth / ecc / src / key_public.js View on Github external
toPublicKeyString(address_prefix = config.get('address_prefix')) {
        if(this.pubdata) return address_prefix + this.pubdata
        const pub_buf = this.toBuffer();
        const checksum = hash.ripemd160(pub_buf);
        const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
        this.pubdata = base58.encode(addy)
        return address_prefix + this.pubdata;
    }
github freedomexio / rocketx-condenser / shared / ecc / src / key_public.js View on Github external
toPublicKeyString(address_prefix = config.address_prefix) {
        if(this.pubdata) return address_prefix + this.pubdata
        const pub_buf = this.toBuffer();
        const checksum = hash.ripemd160(pub_buf);
        const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
        this.pubdata = base58.encode(addy)
        return address_prefix + this.pubdata;
    }
github peerplays-network / peerplays-core-gui / lib / ecc / src / PublicKey.js View on Github external
toAddressString(address_prefix = ChainConfig.address_prefix) {
    let pub_buf = this.toBuffer();
    let pub_sha = sha512(pub_buf);
    let addy = ripemd160(pub_sha);
    let checksum = ripemd160(addy);
    addy = Buffer.concat([addy, checksum.slice(0, 4)]);
    return address_prefix + encode(addy);
  }

bs58

Base 58 encoding / decoding

MIT
Latest version published 5 months ago

Package Health Score

74 / 100
Full package analysis

Popular bs58 functions