Skip to content

Commit

Permalink
fix: add buffer and use multibase (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored Apr 24, 2020
1 parent 77a2afe commit 26eec66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,26 @@
},
"homepage": "https://github.com/ipfs/js-ipns#readme",
"dependencies": {
"base32-encode": "^1.1.0",
"buffer": "^5.6.0",
"debug": "^4.1.1",
"err-code": "^2.0.0",
"interface-datastore": "^0.8.0",
"libp2p-crypto": "^0.17.1",
"multibase": "^0.7.0",
"multihashes": "~0.4.14",
"peer-id": "^0.13.6",
"protons": "^1.0.1",
"timestamp-nano": "^1.0.0"
},
"devDependencies": {
"aegir": "^20.3.1",
"aegir": "^21.9.0",
"chai": "^4.2.0",
"chai-bytes": "~0.1.2",
"chai-string": "^1.5.0",
"dirty-chai": "^2.0.1",
"ipfs": "^0.37.1",
"ipfs-http-client": "^33.1.1",
"ipfsd-ctl": "^0.47.2"
"ipfs": "^0.43.0",
"ipfs-http-client": "^44.0.0",
"ipfsd-ctl": "^4.0.1"
},
"contributors": [
"Alan Shaw <[email protected]>",
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict'

const base32Encode = require('base32-encode')
const NanoDate = require('timestamp-nano')
const { Key } = require('interface-datastore')
const crypto = require('libp2p-crypto')
const PeerId = require('peer-id')
const multihash = require('multihashes')
const errCode = require('err-code')
const { Buffer } = require('buffer')
const multibase = require('multibase')

const debug = require('debug')
const log = debug('jsipns')
Expand Down Expand Up @@ -207,7 +208,7 @@ const extractPublicKey = (peerId, entry) => {
}

// rawStdEncoding with RFC4648
const rawStdEncoding = (key) => base32Encode(key, 'RFC4648', { padding: false })
const rawStdEncoding = (key) => multibase.encode('base32', key).toString().slice(1).toUpperCase()

/**
* Get key for storing the record locally.
Expand Down
11 changes: 6 additions & 5 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiBytes = require('chai-bytes')
const chaiString = require('chai-string')
const { Buffer } = require('buffer')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiBytes)
chai.use(chaiString)

const ipfs = require('ipfs')
const ipfsHttpClient = require('ipfs-http-client')
const DaemonFactory = require('ipfsd-ctl')
const { createFactory } = require('ipfsd-ctl')
const crypto = require('libp2p-crypto')
const { fromB58String } = require('multihashes')

const ipns = require('../src')
const ERRORS = require('../src/errors')

const df = DaemonFactory.create({
const ctl = createFactory({
type: 'proc',
exec: ipfs,
IpfsClient: ipfsHttpClient
ipfsHttpModule: ipfsHttpClient,
ipfsModule: ipfs
})

describe('ipns', function () {
Expand All @@ -37,7 +38,7 @@ describe('ipns', function () {

before(async () => {
rsa = await crypto.keys.generateKeyPair('RSA', 2048)
ipfsd = await df.spawn({ initOptions: { bits: 512 } })
ipfsd = await ctl.spawn()
ipfs = ipfsd.api
ipfsId = await ipfs.id()
})
Expand Down

0 comments on commit 26eec66

Please sign in to comment.