Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Commit 1e91e64

Browse files
hugomrdiasvmx
andauthored
fix: add buffer dependency (#71)
* fix: add buffer Adds buffer related to ipfs/js-ipfs#2924 Uses multibase to encode. * fix: cleanup * fix: allow console calls in example Co-authored-by: Volker Mische <[email protected]>
1 parent 79b9901 commit 1e91e64

File tree

8 files changed

+48
-114
lines changed

8 files changed

+48
-114
lines changed

.coveralls.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.npmignore

Lines changed: 0 additions & 35 deletions
This file was deleted.

.travis.yml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
2-
sudo: false
31
language: node_js
2+
cache: npm
3+
stages:
4+
- check
5+
- test
6+
- cov
47

5-
matrix:
6-
include:
7-
- node_js: 6
8-
env: CXX=g++-4.8
9-
- node_js: 8
10-
env: CXX=g++-4.8
11-
# - node_js: stable
12-
# env: CXX=g++-4.8
8+
node_js:
9+
- '10'
10+
- '12'
11+
12+
os:
13+
- linux
14+
- osx
15+
- windows
1316

14-
script:
15-
- npm run lint
16-
- npm run test
17-
- npm run coverage
17+
script: npx nyc -s npm run test:node -- --bail
18+
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
19+
20+
jobs:
21+
include:
22+
- stage: check
23+
script:
24+
- npx aegir commitlint --travis
25+
- npx aegir dep-check
26+
- npm run lint
1827

19-
before_script:
20-
- export DISPLAY=:99.0
21-
- sh -e /etc/init.d/xvfb start
28+
- stage: test
29+
name: chrome
30+
addons:
31+
chrome: stable
32+
script: npx aegir test -t browser -t webworker
2233

23-
after_success:
24-
- npm run coverage-publish
34+
- stage: test
35+
name: firefox
36+
addons:
37+
firefox: latest
38+
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
2539

26-
addons:
27-
firefox: 'latest'
28-
apt:
29-
sources:
30-
- ubuntu-toolchain-r-test
31-
packages:
32-
- g++-4.8
40+
notifications:
41+
email: false

appveyor.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

circle.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
'use strict'
23

34
const multihash = require('multihashes')

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"coverage": "aegir coverage",
1818
"coverage-publish": "aegir coverage --provider coveralls"
1919
},
20+
"files": [
21+
"src",
22+
"dist"
23+
],
2024
"repository": {
2125
"type": "git",
2226
"url": "git://github.com/multiformats/js-multihash.git"
@@ -30,10 +34,12 @@
3034
},
3135
"dependencies": {
3236
"bs58": "^4.0.1",
37+
"buffer": "^5.5.0",
38+
"multibase": "^0.6.0",
3339
"varint": "^5.0.0"
3440
},
3541
"devDependencies": {
36-
"aegir": "^15.1.0",
42+
"aegir": "^21.3.0",
3743
"buffer-equal": "1.0.0",
3844
"chai": "^4.1.2",
3945
"dirty-chai": "^2.0.1",

src/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
*/
66
'use strict'
77

8-
const bs58 = require('bs58')
9-
8+
const { Buffer } = require('buffer')
9+
const multibase = require('multibase')
10+
const varint = require('varint')
1011
const cs = require('./constants')
1112

1213
exports.names = cs.names
1314
exports.codes = cs.codes
1415
exports.defaultLengths = cs.defaultLengths
1516

16-
const varint = require('varint')
17-
1817
/**
1918
* Convert the given multihash to a hex encoded string.
2019
*
@@ -50,7 +49,7 @@ exports.toB58String = function toB58String (hash) {
5049
throw new Error('must be passed a buffer')
5150
}
5251

53-
return bs58.encode(hash)
52+
return multibase.encode('base58btc', hash).toString().slice(1)
5453
}
5554

5655
/**
@@ -65,7 +64,7 @@ exports.fromB58String = function fromB58String (hash) {
6564
encoded = hash.toString()
6665
}
6766

68-
return Buffer.from(bs58.decode(encoded))
67+
return multibase.decode('z' + encoded)
6968
}
7069

7170
/**

0 commit comments

Comments
 (0)