-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: update to new multiformats #200
Changes from 2 commits
23be726
530e70b
7906944
fba5201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
const ip = require('./ip') | ||
const protocols = require('./protocols-table') | ||
const CID = require('cids') | ||
const multibase = require('multibase') | ||
const { CID } = require('multiformats/cid') | ||
const { base32 } = require('multiformats/bases/base32') | ||
const varint = require('varint') | ||
const uint8ArrayToString = require('uint8arrays/to-string') | ||
const uint8ArrayFromString = require('uint8arrays/from-string') | ||
|
@@ -163,8 +163,22 @@ function bytes2str (buf) { | |
* @param {string | Uint8Array | CID} hash | ||
*/ | ||
function mh2bytes (hash) { | ||
let cid | ||
|
||
if (typeof hash === 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have this same logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably add it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we export an util static function for this in multiformats then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created multiformats/js-multiformats#92 |
||
cid = CID.parse(hash) | ||
} else if (hash instanceof Uint8Array) { | ||
cid = CID.decode(hash) | ||
} else { | ||
cid = CID.asCID(cid) | ||
} | ||
|
||
if (!cid) { | ||
throw new Error('Invalid CID') | ||
} | ||
|
||
// the address is a varint prefixed multihash string representation | ||
const mh = new CID(hash).multihash | ||
const mh = cid.multihash.bytes | ||
const size = Uint8Array.from(varint.encode(mh.length)) | ||
return uint8ArrayConcat([size, mh], size.length + mh.length) | ||
} | ||
|
@@ -199,7 +213,7 @@ function onion2bytes (str) { | |
} | ||
|
||
// onion addresses do not include the multibase prefix, add it before decoding | ||
const buf = multibase.decode('b' + addr[0]) | ||
const buf = base32.decode('b' + addr[0]) | ||
|
||
// onion port number | ||
const port = parseInt(addr[1], 10) | ||
|
@@ -222,7 +236,7 @@ function onion32bytes (str) { | |
throw new Error('failed to parse onion addr: ' + addr[0] + ' not a Tor onion3 address.') | ||
} | ||
// onion addresses do not include the multibase prefix, add it before decoding | ||
const buf = multibase.decode('b' + addr[0]) | ||
const buf = base32.decode('b' + addr[0]) | ||
|
||
// onion port number | ||
const port = parseInt(addr[1], 10) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this you can't depend on a branch of this repo as otherwise it has no types after install.
prepare
is run during release so it shouldn't break anything?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep it, but I would not remove the build script. Perhaps just add a new one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do, but then it'll build twice during release since npm runs
prepare
and aegir runsbuild