How to use the decode function from bs58

Find comprehensive JavaScript bs58.decode code examples handpicked from public code repositorys.

bs58.decode is a function that decodes a Base58Check encoded string into its original byte array representation.

242
243
244
245
246
247
248
249
250
251
252
253


/*
For POW coins - used to format wallet address for use in generation transaction's output
 */
exports.addressToScript = function (addr) {
  var decoded = bs58.decode(addr);


  if (decoded.length != 25) {
    console.error("invalid address length for " + addr);
    throw new Error();
fork icon3
star icon2
watch icon2

+ 3 other calls in file

130
131
132
133
134
135
136
137
138
139
const signature = req.body.signature;
const signMessage = "sign";

const verified = nacl.sign.detached.verify(
  new TextEncoder().encode(signMessage),
  bs58.decode(signature),
  bs58.decode(publicKey)
);

if (verified) {
fork icon0
star icon0
watch icon1

+ 19 other calls in file

How does bs58.decode work?

bs58.decode is a function that takes a base58-encoded string and returns its corresponding bytes in the original data. In detail, the function first converts the input string to a buffer using Buffer.from(), then decodes the buffer using the Base58 algorithm to obtain a buffer containing the original bytes. Finally, the function returns this buffer.

392
393
394
395
396
397
398
399
400
401

static validateSolanaAddressLocal (sig, address) {
  try {
    const encodeFunction = new TextEncoder()
    const addressWallet = new PublicKey(address)
    const signatureDecode = base58.decode(sig)
    const messageEncoded = encodeFunction.encode(dagoraHashMessage)
    const verifySign = nacl.sign.detached.verify(
      messageEncoded,
      signatureDecode,
fork icon0
star icon0
watch icon1

63
64
65
66
67
68
69
70
71
72
73
74
    fromBase(string){


        if (consts.ADDRESSES.ADDRESS.USE_BASE64)
            return WebDollarCrypto.decodeBase64(string); //if it is string, it must be a Base string
        else
            return bs58.decode(string);
    }


}

fork icon0
star icon0
watch icon1

Ai Example

1
2
3
4
5
6
const bs58 = require("bs58");

const encodedString = "3mJr7AoURxVbeBFLpfrqLAPGqMk79p6f4t";
const decodedBuffer = bs58.decode(encodedString);

console.log(decodedBuffer);

This will output the decoded buffer for the given Base58 encoded string.