Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"dep-check": "aegir dep-check"
},
"dependencies": {
"cborg": "^4.0.0",
"cborg": "^4.4.0",
"multiformats": "^13.1.0"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,26 @@ class DagJsonTokenizer extends cborgJson.Tokenizer {
next () {
const token = this._next()

if (token.type === Type.map) {
if (Type.equals(token.type, Type.map)) {
const keyToken = this._next()
if (keyToken.type === Type.string && keyToken.value === '/') {
if (Type.equals(keyToken.type, Type.string) && keyToken.value === '/') {
const valueToken = this._next()
if (valueToken.type === Type.string) { // *must* be a CID
if (Type.equals(valueToken.type, Type.string)) { // *must* be a CID
const breakToken = this._next() // swallow the end-of-map token
if (breakToken.type !== Type.break) {
if (!Type.equals(breakToken.type, Type.break)) {
throw new Error('Invalid encoded CID form')
}
this.tokenBuffer.push(valueToken) // CID.parse will pick this up after our tag token
return new Token(Type.tag, 42, 0)
}
if (valueToken.type === Type.map) {
if (Type.equals(valueToken.type, Type.map)) {
const innerKeyToken = this._next()
if (innerKeyToken.type === Type.string && innerKeyToken.value === 'bytes') {
if (Type.equals(innerKeyToken.type, Type.string) && innerKeyToken.value === 'bytes') {
const innerValueToken = this._next()
if (innerValueToken.type === Type.string) { // *must* be Bytes
if (Type.equals(innerValueToken.type, Type.string)) { // *must* be Bytes
for (let i = 0; i < 2; i++) {
const breakToken = this._next() // swallow two end-of-map tokens
if (breakToken.type !== Type.break) {
if (!Type.equals(breakToken.type, Type.break)) {
throw new Error('Invalid encoded Bytes form')
}
}
Expand Down