Coder Social home page Coder Social logo

Comments (5)

beenotung avatar beenotung commented on July 30, 2024

also some character(s) are not identified, see examples below:

> require('multibase').encode('base58btc','/').toString()
'zundefined'
> require('multibase').encode('base58btc','1/').toString()
'zundefined'
> require('multibase').encode('base58btc','/1').toString()
'zB'

from js-multibase.

beenotung avatar beenotung commented on July 30, 2024

It seems the base58btc do not handle string properly

console.log(multibase.encode("base64", 'hello').toString());
// maGVsbG8
console.log(multibase.encode("base64", new Buffer('hello')).toString());
// maGVsbG8

console.log(multibase.encode("base58btc", 'hello').toString());
// zundefined
console.log(multibase.encode("base58btc", new Buffer('hello')).toString());
// zCn8eVZg

from js-multibase.

beenotung avatar beenotung commented on July 30, 2024

The bug is coming from base-x.

When source is string, e.g. 'y0': carry (source[i]) + digits[j] becomes a string.
So it seems baseX created in constants.js do not support string encoding natively, so I suggest to warp that to support string encoding.

Work in progress thread: #43

Below is the code of encode base-x for understanding:

function encode(source) {
    if (source.length === 0) return ''

    var digits = [0]
    for (var i = 0; i < source.length; ++i) {
      // when source is string, e.g. 'y0': carry (source[i]) + digits[j] becomes a string
      for (var j = 0, carry = source[i]; j < digits.length; ++j) {
        carry += digits[j] << 8
        digits[j] = carry % BASE
        carry = (carry / BASE) | 0
      }

      while (carry > 0) {
        digits.push(carry % BASE)
        carry = (carry / BASE) | 0
      }
    }

    var string = ''

    // deal with leading zeros
    for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += LEADER
    // convert digits to a string
    for (var q = digits.length - 1; q >= 0; --q) {
      string += ALPHABET[digits[q]]
    }
    if (string === 'undefined') {
      process.exit(1)
    }

    return string
  }

from js-multibase.

beenotung avatar beenotung commented on July 30, 2024

Fixed in #43
@olizilla May you help to get it merged?

from js-multibase.

hugomrdias avatar hugomrdias commented on July 30, 2024

encode only supports Buffer https://github.com/multiformats/js-multibase#multibaseencode---encodes-a-buffer-into-one-of-the-supported-encodings-prefixing-it-with-the-multibase-code

from js-multibase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.