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

Commit

Permalink
fix: add buffer dependency (#71)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
hugomrdias and vmx authored Mar 16, 2020
1 parent 79b9901 commit 1e91e64
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 114 deletions.
2 changes: 0 additions & 2 deletions .coveralls.yml

This file was deleted.

35 changes: 0 additions & 35 deletions .npmignore

This file was deleted.

61 changes: 35 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
# 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.
sudo: false
language: node_js
cache: npm
stages:
- check
- test
- cov

matrix:
include:
- node_js: 6
env: CXX=g++-4.8
- node_js: 8
env: CXX=g++-4.8
# - node_js: stable
# env: CXX=g++-4.8
node_js:
- '10'
- '12'

os:
- linux
- osx
- windows

script:
- npm run lint
- npm run test
- npm run coverage
script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

jobs:
include:
- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- stage: test
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser -t webworker

after_success:
- npm run coverage-publish
- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
notifications:
email: false
29 changes: 0 additions & 29 deletions appveyor.yml

This file was deleted.

15 changes: 0 additions & 15 deletions circle.yml

This file was deleted.

1 change: 1 addition & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
'use strict'

const multihash = require('multihashes')
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
},
"files": [
"src",
"dist"
],
"repository": {
"type": "git",
"url": "git://github.com/multiformats/js-multihash.git"
Expand All @@ -30,10 +34,12 @@
},
"dependencies": {
"bs58": "^4.0.1",
"buffer": "^5.5.0",
"multibase": "^0.6.0",
"varint": "^5.0.0"
},
"devDependencies": {
"aegir": "^15.1.0",
"aegir": "^21.3.0",
"buffer-equal": "1.0.0",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
Expand Down
11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
*/
'use strict'

const bs58 = require('bs58')

const { Buffer } = require('buffer')
const multibase = require('multibase')
const varint = require('varint')
const cs = require('./constants')

exports.names = cs.names
exports.codes = cs.codes
exports.defaultLengths = cs.defaultLengths

const varint = require('varint')

/**
* Convert the given multihash to a hex encoded string.
*
Expand Down Expand Up @@ -50,7 +49,7 @@ exports.toB58String = function toB58String (hash) {
throw new Error('must be passed a buffer')
}

return bs58.encode(hash)
return multibase.encode('base58btc', hash).toString().slice(1)
}

/**
Expand All @@ -65,7 +64,7 @@ exports.fromB58String = function fromB58String (hash) {
encoded = hash.toString()
}

return Buffer.from(bs58.decode(encoded))
return multibase.decode('z' + encoded)
}

/**
Expand Down

0 comments on commit 1e91e64

Please sign in to comment.