diff --git a/package-lock.json b/package-lock.json index 018a9327b..17b79c548 100644 --- a/package-lock.json +++ b/package-lock.json @@ -913,9 +913,9 @@ "link": true }, "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.0.32", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.0.32.tgz", - "integrity": "sha512-SijEHpmJDa0I9hC7jn/8P7XeYeFAi9byMc+b36yuCPDiF+j/hLLYGMpZpnbylJ6+ldWqWWEunumeWjxU4zrc3g==", + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.0.33.tgz", + "integrity": "sha512-ZdQtRTd0M2VcgGli7kDzkePsuxpwiOg+PRsBJ/UPC5fc6oflzbRqV6Lg9v8bWHozjdnijP58J3RMWmf4cj7bWw==", "dependencies": { "@ipld/dag-cbor": "9.0.0", "@js-temporal/polyfill": "0.4.3", @@ -7742,12 +7742,12 @@ }, "packages/dids": { "name": "@tbd54566975/dids", - "version": "0.1.5", + "version": "0.1.6", "license": "Apache-2.0", "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", "@tbd54566975/crypto": "0.1.4", - "@tbd54566975/dwn-sdk-js": "0.0.32", + "@tbd54566975/dwn-sdk-js": "0.0.33", "cross-fetch": "3.1.5" }, "devDependencies": { @@ -7785,16 +7785,16 @@ }, "packages/web5": { "name": "@tbd54566975/web5", - "version": "0.7.5", + "version": "0.7.6", "license": "Apache-2.0", "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", "@tbd54566975/crypto": "0.1.4", - "@tbd54566975/dids": "0.1.5", - "@tbd54566975/dwn-sdk-js": "0.0.32", - "@tbd54566975/web5-agent": "0.1.4", - "@tbd54566975/web5-proxy-agent": "0.1.4", - "@tbd54566975/web5-user-agent": "0.1.5", + "@tbd54566975/dids": "0.1.6", + "@tbd54566975/dwn-sdk-js": "0.0.33", + "@tbd54566975/web5-agent": "0.1.5", + "@tbd54566975/web5-proxy-agent": "0.1.5", + "@tbd54566975/web5-user-agent": "0.1.6", "level": "8.0.0", "ms": "2.1.3", "readable-web-to-node-stream": "3.0.2" @@ -7835,10 +7835,10 @@ }, "packages/web5-agent": { "name": "@tbd54566975/web5-agent", - "version": "0.1.4", + "version": "0.1.5", "license": "Apache-2.0", "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.0.32", + "@tbd54566975/dwn-sdk-js": "0.0.33", "readable-stream": "4.4.0" }, "devDependencies": { @@ -7876,10 +7876,10 @@ }, "packages/web5-proxy-agent": { "name": "@tbd54566975/web5-proxy-agent", - "version": "0.1.4", + "version": "0.1.5", "license": "Apache-2.0", "dependencies": { - "@tbd54566975/web5-agent": "0.1.4" + "@tbd54566975/web5-agent": "0.1.5" }, "devDependencies": { "@types/chai": "4.3.0", @@ -7917,13 +7917,13 @@ }, "packages/web5-user-agent": { "name": "@tbd54566975/web5-user-agent", - "version": "0.1.5", + "version": "0.1.6", "license": "Apache-2.0", "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/dids": "0.1.5", - "@tbd54566975/dwn-sdk-js": "0.0.32", - "@tbd54566975/web5-agent": "0.1.4", + "@tbd54566975/dids": "0.1.6", + "@tbd54566975/dwn-sdk-js": "0.0.33", + "@tbd54566975/web5-agent": "0.1.5", "abstract-level": "1.0.3", "cross-fetch": "3.1.5", "flat": "5.0.2", diff --git a/packages/dids/package.json b/packages/dids/package.json index 9d6b80f96..ac9b8ab7f 100644 --- a/packages/dids/package.json +++ b/packages/dids/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/dids", - "version": "0.1.5", + "version": "0.1.6", "description": "TBD DIDs library", "type": "module", "main": "./dist/cjs/main.cjs", @@ -80,7 +80,7 @@ "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", "@tbd54566975/crypto": "0.1.4", - "@tbd54566975/dwn-sdk-js": "0.0.32", + "@tbd54566975/dwn-sdk-js": "0.0.33", "cross-fetch": "3.1.5" }, "devDependencies": { diff --git a/packages/web5-agent/package.json b/packages/web5-agent/package.json index 5a59bf763..b70c0743f 100644 --- a/packages/web5-agent/package.json +++ b/packages/web5-agent/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5-agent", - "version": "0.1.4", + "version": "0.1.5", "description": "Web5 Agent", "type": "module", "main": "./dist/cjs/main.cjs", @@ -76,7 +76,7 @@ }, "dependencies": { "readable-stream": "4.4.0", - "@tbd54566975/dwn-sdk-js": "0.0.32" + "@tbd54566975/dwn-sdk-js": "0.0.33" }, "devDependencies": { "@types/chai": "4.3.0", @@ -109,5 +109,5 @@ }, "overrides": { "socket.io-parser@>4.0.4 <4.2.3": "4.2.3" - } + } } \ No newline at end of file diff --git a/packages/web5-proxy-agent/package.json b/packages/web5-proxy-agent/package.json index 32bfb8aaf..8d526e9a6 100644 --- a/packages/web5-proxy-agent/package.json +++ b/packages/web5-proxy-agent/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5-proxy-agent", - "version": "0.1.4", + "version": "0.1.5", "description": "Web5 Proxy Agent", "type": "module", "main": "./dist/cjs/main.cjs", @@ -75,7 +75,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@tbd54566975/web5-agent": "0.1.4" + "@tbd54566975/web5-agent": "0.1.5" }, "devDependencies": { "@types/chai": "4.3.0", diff --git a/packages/web5-user-agent/package.json b/packages/web5-user-agent/package.json index a168abd8b..42dd8dae0 100644 --- a/packages/web5-user-agent/package.json +++ b/packages/web5-user-agent/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5-user-agent", - "version": "0.1.5", + "version": "0.1.6", "description": "Web5 User Agent", "type": "module", "main": "./dist/cjs/main.cjs", @@ -76,9 +76,9 @@ }, "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/dids": "0.1.5", - "@tbd54566975/dwn-sdk-js": "0.0.32", - "@tbd54566975/web5-agent": "0.1.4", + "@tbd54566975/dids": "0.1.6", + "@tbd54566975/dwn-sdk-js": "0.0.33", + "@tbd54566975/web5-agent": "0.1.5", "abstract-level": "1.0.3", "cross-fetch": "3.1.5", "flat": "5.0.2", @@ -119,5 +119,5 @@ }, "overrides": { "socket.io-parser@>4.0.4 <4.2.3": "4.2.3" - } + } } \ No newline at end of file diff --git a/packages/web5-user-agent/src/sync-api.ts b/packages/web5-user-agent/src/sync-api.ts index 257d92fce..fe0c70ed4 100644 --- a/packages/web5-user-agent/src/sync-api.ts +++ b/packages/web5-user-agent/src/sync-api.ts @@ -162,6 +162,13 @@ export class SyncApi implements SyncManager { } const dwnMessage = await this.#getDwnMessage(did, messageCid); + if (!dwnMessage) { + delOps.push({ type: 'del', key: key }); + await this.setWatermark(did, dwnUrl, 'push', watermark); + await this.#addMessage(did, messageCid); + + continue; + } try { const reply = await this.#dwnRpcClient.sendDwnRequest({ @@ -339,13 +346,16 @@ export class SyncApi implements SyncManager { const result: MessagesGetReply = await this.#dwn.processMessage(author, messagesGet.toJSON()); const [ messageEntry ] = result.messages; + // absence of a messageEntry or message within messageEntry can happen because updating a Record actually creates another + // RecordsWrite with the same recordId. only the first and most recent RecordsWrite messages are kept for a given + // recordId. any in between are outright nuked from everywhere. if (!messageEntry) { - throw new Error('TODO: figure out error message'); + return undefined; } let { message } = messageEntry; if (!message) { - throw new Error('TODO: message not found'); + return undefined; } let dwnMessage: DwnMessage = { message }; @@ -367,12 +377,16 @@ export class SyncApi implements SyncManager { const reply = await this.#dwn.processMessage(author, recordsRead.toJSON()) as RecordsReadReply; - if (reply.status.code >= 400) { - const { status: { code, detail } } = reply; - throw new Error(`(${code}) Failed to read data associated with record ${message['recordId']}. ${detail}}`); - } else { + // if the data no longer exists (aka 404), it's likely that a `RecordsDelete` took place. + // `RecordsDelete` keeps a `RecordsWrite` and just deletes the associated data, effectively acting as a "tombstone". + // We still need to _push_ this tombstone so that the `RecordsDelete` can be processed successfully. + // if 200, return the data. if 4xx ignore for the reason explained, if >= 5xx throw error + if (reply.status.code === 200) { const dataBytes = await DataStream.toBytes(reply.record.data); dwnMessage.data = new Blob([dataBytes]); + } else if (reply.status.code >= 500) { + const { status: { code, detail } } = reply; + throw new Error(`(${code}) Failed to read data associated with record ${message['recordId']}. ${detail}}`); } } } diff --git a/packages/web5/package.json b/packages/web5/package.json index 5dba625c8..b364d558b 100644 --- a/packages/web5/package.json +++ b/packages/web5/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5", - "version": "0.7.5", + "version": "0.7.6", "description": "SDK for accessing the features and capabilities of Web5", "type": "module", "main": "./dist/cjs/main.cjs", @@ -81,11 +81,11 @@ "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", "@tbd54566975/crypto": "0.1.4", - "@tbd54566975/dids": "0.1.5", - "@tbd54566975/dwn-sdk-js": "0.0.32", - "@tbd54566975/web5-agent": "0.1.4", - "@tbd54566975/web5-proxy-agent": "0.1.4", - "@tbd54566975/web5-user-agent": "0.1.5", + "@tbd54566975/dids": "0.1.6", + "@tbd54566975/dwn-sdk-js": "0.0.33", + "@tbd54566975/web5-agent": "0.1.5", + "@tbd54566975/web5-proxy-agent": "0.1.5", + "@tbd54566975/web5-user-agent": "0.1.6", "level": "8.0.0", "ms": "2.1.3", "readable-web-to-node-stream": "3.0.2" @@ -122,5 +122,5 @@ }, "overrides": { "socket.io-parser@>4.0.4 <4.2.3": "4.2.3" - } + } } \ No newline at end of file diff --git a/packages/web5/tests/record.spec.ts b/packages/web5/tests/record.spec.ts index 1a970996b..15932c678 100644 --- a/packages/web5/tests/record.spec.ts +++ b/packages/web5/tests/record.spec.ts @@ -99,11 +99,13 @@ describe('Record', () => { keyEncryptionInputs : [ { derivationScheme : KeyDerivationScheme.Protocols, - publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk + publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, + publicKeyId : recordEncryptionKeyId }, { derivationScheme : KeyDerivationScheme.Schemas, - publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk + publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, + publicKeyId : recordEncryptionKeyId }, ] }; @@ -908,11 +910,13 @@ describe('Record', () => { keyEncryptionInputs : [ { derivationScheme : KeyDerivationScheme.Protocols, - publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk + publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, + publicKeyId : recordEncryptionKeyId }, { derivationScheme : KeyDerivationScheme.Schemas, - publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk + publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, + publicKeyId : recordEncryptionKeyId }, ] };