Skip to content

Commit 022ab87

Browse files
authored
fix: replace node buffers with uint8arrays (#59)
BREAKING CHANGES: - Now uses a version of `multiaddr` than has a `.bytes` property instead of `.buffer`
1 parent af85d97 commit 022ab87

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
"@types/chai": "^4.2.8",
3232
"@types/mocha": "^8.0.0",
3333
"aegir": "^25.0.0",
34-
"buffer": "^5.6.0",
35-
"chai": "^4.2.0"
34+
"uint8arrays": "^1.1.0"
3635
},
3736
"dependencies": {
38-
"multiaddr": "^7.3.0"
37+
"multiaddr": "^8.0.0"
3938
},
4039
"contributors": [
4140
"Alan Shaw <alan@tableflip.io>",

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Multiaddr = require('multiaddr');
33
export declare interface Mafmt {
44
toString(): string;
55
input?: (Mafmt | (() => Mafmt))[];
6-
matches: (a: string | Buffer | Multiaddr) => boolean;
6+
matches: (a: string | Uint8Array | Multiaddr) => boolean;
77
partialMatch: (protos: string[]) => boolean;
88
}
99

test/index.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
'use strict'
44

5-
const { Buffer } = require('buffer')
6-
const expect = require('chai').expect
5+
const { expect } = require('aegir/utils/chai')
76
const multiaddr = require('multiaddr')
7+
const uint8ArrayFromString = require('uint8arrays/from-string')
88

99
const mafmt = require('./../src')
1010

@@ -182,7 +182,7 @@ describe('multiaddr validation', function () {
182182
expect(p.matches(testcase), `assertMatches: ${testcase} (string)`).to.be.eql(true)
183183
const ma = multiaddr(testcase)
184184
expect(p.matches(ma), `assertMatches: ${testcase} (multiaddr object)`).to.be.eql(true)
185-
expect(p.matches(ma.buffer), `assertMatches: ${testcase} (multiaddr.buffer)`).to.be.eql(true)
185+
expect(p.matches(ma.bytes), `assertMatches: ${testcase} (multiaddr.bytes)`).to.be.eql(true)
186186
} catch (err) {
187187
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=true] ' + err.stack
188188
throw err
@@ -200,15 +200,15 @@ describe('multiaddr validation', function () {
200200
let validMultiaddrObj
201201
try {
202202
// if testcase string happens to be a valid multiaddr,
203-
// we expect 'p' test to also return false for Multiaddr object and Buffer versions
203+
// we expect 'p' test to also return false for Multiaddr object and Uint8Array versions
204204
validMultiaddrObj = multiaddr(testcase)
205205
} catch (e) {
206206
// Ignoring testcase as the string is not a multiaddr
207-
// (There is a separate 'Buffer is invalid' test later below)
207+
// (There is a separate 'Uint8Array is invalid' test later below)
208208
}
209209
if (validMultiaddrObj) {
210210
expect(p.matches(validMultiaddrObj), `assertMismatches: ${testcase} (multiaddr object)`).to.be.eql(false)
211-
expect(p.matches(validMultiaddrObj.buffer), `assertMismatches: ${testcase} (multiaddr.buffer)`).to.be.eql(false)
211+
expect(p.matches(validMultiaddrObj.bytes), `assertMismatches: ${testcase} (multiaddr.bytes)`).to.be.eql(false)
212212
}
213213
} catch (err) {
214214
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=false] ' + err.stack
@@ -222,8 +222,8 @@ describe('multiaddr validation', function () {
222222
expect(mafmt.HTTP.matches('/http-google-com')).to.be.eql(false)
223223
})
224224

225-
it('do not throw if multiaddr Buffer is invalid', function () {
226-
expect(mafmt.HTTP.matches(Buffer.from('no spoon'))).to.be.eql(false)
225+
it('do not throw if multiaddr Uint8Array is invalid', function () {
226+
expect(mafmt.HTTP.matches(uint8ArrayFromString('no spoon'))).to.be.eql(false)
227227
})
228228

229229
it('DNS validation', function () {

0 commit comments

Comments
 (0)