Comments (5)
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.
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.
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.
Fixed in #43
@olizilla May you help to get it merged?
from js-multibase.
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)
- ReferenceError: TextDecoder is not defined
- Move from Coveralls to CodeCov.io HOT 2
- base32 is broken HOT 3
- base64pad/base64urlpad not yet implemented HOT 3
- Ambigous encoding due to underlying design HOT 1
- typescript support HOT 2
- suggest to add suuport base58 HOT 1
- Test against spec
- Standardize README HOT 1
- More description error text
- Export the names and codes as object (instead of array)
- Implement base36 HOT 1
- `web-encoding` package causes problems with jest in env=node and env=jsdom HOT 19
- QUESTION: how to get the string from the encode function HOT 12
- Upgrade to aegir@9 HOT 1
- Incompatibility with "zii" HOT 13
- Recent release broke our build HOT 2
- ReferenceError: TextDecoder is not defined HOT 1
- React Native support is dropped HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-multibase.