diff --git a/CHANGELOG.md b/CHANGELOG.md index 9641eddf..a75d1f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### v0.36.1 + +Fixes an issue with the CID log, which, in certain scenarios, caused Webnative to load the wrong version of an account's file system. + ### v0.36.0 #### Breaking changes diff --git a/package-lock.json b/package-lock.json index d8f3da0f..87189e65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "webnative", - "version": "0.36.0", + "version": "0.36.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "webnative", - "version": "0.36.0", + "version": "0.36.1", "license": "Apache-2.0", "dependencies": { "@ipld/dag-cbor": "^8.0.0", diff --git a/package.json b/package.json index 2c3884a9..304d5f87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webnative", - "version": "0.36.0", + "version": "0.36.1", "description": "Webnative SDK", "keywords": [ "WebCrypto", diff --git a/src/common/version.ts b/src/common/version.ts index dbbec8a9..adbc329e 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1,2 +1,2 @@ -export const VERSION = "0.36.0" +export const VERSION = "0.36.1" export const WASM_WNFS_VERSION = "0.1.7" diff --git a/src/filesystem.ts b/src/filesystem.ts index dca189a8..081189f7 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -44,7 +44,7 @@ export async function loadFileSystem({ config, dependencies, eventEmitter, rootK // Determine the correct CID of the file system to load const dataCid = navigator.onLine ? await getDataRoot(reference, username, { maxRetries: 20 }) : null - const logIdx = dataCid ? cidLog.length() - cidLog.indexOf(dataCid) - 1 : -1 + const logIdx = dataCid ? cidLog.indexOf(dataCid) : -1 if (!navigator.onLine) { // Offline, use local CID @@ -59,15 +59,16 @@ export async function loadFileSystem({ config, dependencies, eventEmitter, rootK if (cid) manners.log("📓 No DNSLink, using local CID:", cid.toString()) else manners.log("📓 Creating a new file system") - } else if (logIdx === 0) { + } else if (logIdx === cidLog.length() - 1) { // DNS is up to date cid = dataCid manners.log("📓 DNSLink is up to date:", cid.toString()) - } else if (logIdx > 0) { + } else if (logIdx !== -1 && logIdx < cidLog.length() - 1) { // DNS is outdated cid = cidLog.newest() - const idxLog = logIdx === 1 ? "1 newer local entry" : (cidLog.length() - logIdx - 1).toString() + " newer local entries" + const diff = cidLog.length() - 1 - logIdx + const idxLog = diff === 1 ? "1 newer local entry" : diff.toString() + " newer local entries" manners.log("📓 DNSLink is outdated (" + idxLog + "), using local CID:", cid.toString()) } else { diff --git a/src/repositories/cid-log.node.test.ts b/src/repositories/cid-log.node.test.ts index 621ee910..ab666906 100644 --- a/src/repositories/cid-log.node.test.ts +++ b/src/repositories/cid-log.node.test.ts @@ -66,7 +66,7 @@ describe("cid-log", () => { const cid = cids[ idx ] // Get the index of test cid after all CIDs have been added - const index = await cidLog.indexOf(cid) + const index = cidLog.indexOf(cid) expect(index).toEqual(idx) }) @@ -85,7 +85,7 @@ describe("cid-log", () => { const cid = cids[ cids.length - 1 ] // Get the newest cid after all CIDs have been added - const newest = await cidLog.newest() + const newest = cidLog.newest() expect(newest.toString()).toEqual(cid.toString()) })