From 6fc68b415d4abe12d1af01baad3b50de76d484d6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:17:27 +0100 Subject: [PATCH 1/8] fix: use MultihashDigest type in stores --- packages/upload-api/src/blob/accept.js | 8 ++--- packages/upload-api/src/blob/allocate.js | 8 +++-- packages/upload-api/src/blob/remove.js | 4 ++- packages/upload-api/src/index/add.js | 2 +- packages/upload-api/src/types/blob.ts | 13 +++---- .../upload-api/test/handlers/web3.storage.js | 2 +- .../test/storage/blobs-storage-tests.js | 8 ++--- .../upload-api/test/storage/blobs-storage.js | 35 ++++++++----------- 8 files changed, 38 insertions(+), 42 deletions(-) diff --git a/packages/upload-api/src/blob/accept.js b/packages/upload-api/src/blob/accept.js index 6e2d31b7a..94bdd3f5f 100644 --- a/packages/upload-api/src/blob/accept.js +++ b/packages/upload-api/src/blob/accept.js @@ -27,8 +27,9 @@ export function blobAcceptProvider(context) { } const { blob, space } = capability.nb + const digest = Digest.decode(blob.digest) // If blob is not stored, we must fail - const hasBlob = await context.blobsStorage.has(blob.digest) + const hasBlob = await context.blobsStorage.has(digest) if (hasBlob.error) { return hasBlob } else if (!hasBlob.ok) { @@ -37,10 +38,7 @@ export function blobAcceptProvider(context) { } } - const digest = Digest.decode(blob.digest) - const createUrl = await context.blobsStorage.createDownloadUrl( - digest.bytes - ) + const createUrl = await context.blobsStorage.createDownloadUrl(digest) if (createUrl.error) { return createUrl } diff --git a/packages/upload-api/src/blob/allocate.js b/packages/upload-api/src/blob/allocate.js index b11f363a2..5898aadb0 100644 --- a/packages/upload-api/src/blob/allocate.js +++ b/packages/upload-api/src/blob/allocate.js @@ -1,5 +1,6 @@ import * as Server from '@ucanto/server' import * as W3sBlob from '@web3-storage/capabilities/web3.storage/blob' +import * as Digest from 'multiformats/hashes/digest' import * as API from '../types.js' import { BlobSizeOutsideOfSupportedRange, @@ -26,6 +27,7 @@ export const allocate = async (context, { capability }) => { } const { blob, cause, space } = capability.nb + const digest = Digest.decode(blob.digest) let { size } = blob // We check if space has storage provider associated. If it does not @@ -51,7 +53,7 @@ export const allocate = async (context, { capability }) => { // While blob may exceed current maxUploadSize limit it could be that limit // was higher in the past and user had this blob uploaded already in which // case we should not error. - const exists = await context.allocationsStorage.exists(space, blob.digest) + const exists = await context.allocationsStorage.exists(space, digest) if (exists.ok) { return { ok: { size: 0 } } } else { @@ -88,7 +90,7 @@ export const allocate = async (context, { capability }) => { // Check if we already have blob stored // TODO: this may depend on the region we want to allocate and will need // changes in the future. - const hasBlobStore = await context.blobsStorage.has(blob.digest) + const hasBlobStore = await context.blobsStorage.has(digest) if (hasBlobStore.error) { return hasBlobStore } @@ -106,7 +108,7 @@ export const allocate = async (context, { capability }) => { const expiresIn = 60 * 60 * 24 // 1 day const expiresAt = new Date(Date.now() + expiresIn).toISOString() const createUploadUrl = await context.blobsStorage.createUploadUrl( - blob.digest, + digest, blob.size, expiresIn ) diff --git a/packages/upload-api/src/blob/remove.js b/packages/upload-api/src/blob/remove.js index e4e4d9400..cd157326f 100644 --- a/packages/upload-api/src/blob/remove.js +++ b/packages/upload-api/src/blob/remove.js @@ -1,5 +1,6 @@ import * as Server from '@ucanto/server' import * as Blob from '@web3-storage/capabilities/blob' +import * as Digest from 'multiformats/hashes/digest' import * as API from '../types.js' import { RecordNotFoundErrorName } from '../errors.js' @@ -11,7 +12,8 @@ import { RecordNotFoundErrorName } from '../errors.js' export function blobRemoveProvider(context) { return Server.provide(Blob.remove, async ({ capability }) => { const space = capability.with - const { digest } = capability.nb + const digest = Digest.decode(capability.nb.digest) + const res = await context.allocationsStorage.remove(space, digest) if (res.error && res.error.name === RecordNotFoundErrorName) { return { diff --git a/packages/upload-api/src/index/add.js b/packages/upload-api/src/index/add.js index 9c0945fbd..395018962 100644 --- a/packages/upload-api/src/index/add.js +++ b/packages/upload-api/src/index/add.js @@ -78,7 +78,7 @@ const add = async ({ capability }, context) => { * @returns {Promise>} */ const assertAllocated = async (context, space, digest, errorName) => { - const result = await context.allocationsStorage.exists(space, digest.bytes) + const result = await context.allocationsStorage.exists(space, digest) if (result.error) return result if (!result.ok) return error( diff --git a/packages/upload-api/src/types/blob.ts b/packages/upload-api/src/types/blob.ts index 937eb6c66..a12464424 100644 --- a/packages/upload-api/src/types/blob.ts +++ b/packages/upload-api/src/types/blob.ts @@ -12,6 +12,7 @@ import { BlobRemoveSuccess, BlobGetSuccess, } from '@web3-storage/capabilities/types' +import { MultihashDigest } from 'multiformats' import { RecordKeyConflict, ListResponse } from '../types.js' import { Storage } from './storage.js' @@ -21,11 +22,11 @@ export type TasksStorage = Storage export interface AllocationsStorage { get: ( space: DID, - blobMultihash: Multihash + digest: MultihashDigest ) => Promise> exists: ( space: DID, - blobMultihash: Multihash + digest: MultihashDigest ) => Promise> /** Inserts an item in the table if it does not already exist. */ insert: ( @@ -38,7 +39,7 @@ export interface AllocationsStorage { /** Removes an item from the table, returning zero on size if non existent. */ remove: ( space: DID, - digest: Multihash + digest: MultihashDigest ) => Promise> } @@ -61,9 +62,9 @@ export interface BlobAddInput { export interface BlobAddOutput extends Omit {} export interface BlobsStorage { - has: (content: Multihash) => Promise> + has: (content: MultihashDigest) => Promise> createUploadUrl: ( - content: Multihash, + content: MultihashDigest, size: number, /** * The number of seconds before the presigned URL expires @@ -81,5 +82,5 @@ export interface BlobsStorage { Failure > > - createDownloadUrl: (content: Multihash) => Promise> + createDownloadUrl: (content: MultihashDigest) => Promise> } diff --git a/packages/upload-api/test/handlers/web3.storage.js b/packages/upload-api/test/handlers/web3.storage.js index 0e2ebfba3..092039d91 100644 --- a/packages/upload-api/test/handlers/web3.storage.js +++ b/packages/upload-api/test/handlers/web3.storage.js @@ -683,7 +683,7 @@ export const test = { assert.equal(locations.length, 1) const loc = Result.unwrap( - await context.blobsStorage.createDownloadUrl(digest) + await context.blobsStorage.createDownloadUrl(multihash) ) assert.ok(locations.includes(loc)) }, diff --git a/packages/upload-api/test/storage/blobs-storage-tests.js b/packages/upload-api/test/storage/blobs-storage-tests.js index 9ca49d2ef..9596533ef 100644 --- a/packages/upload-api/test/storage/blobs-storage-tests.js +++ b/packages/upload-api/test/storage/blobs-storage-tests.js @@ -20,7 +20,7 @@ export const test = { size: size, } const createUploadUrl = await blobsStorage.createUploadUrl( - blob.digest, + multihash0, blob.size, expiresIn ) @@ -41,7 +41,7 @@ export const test = { assert.equal(goodPut.status, 200, await goodPut.text()) // check it exists - const hasBlob = await blobsStorage.has(blob.digest) + const hasBlob = await blobsStorage.has(multihash0) assert.ok(hasBlob.ok) }, @@ -54,7 +54,7 @@ export const test = { const expires = 60 * 60 * 24 // 1 day const upload = Result.unwrap( - await blobsStorage.createUploadUrl(digest.bytes, data.length, expires) + await blobsStorage.createUploadUrl(digest, data.length, expires) ) await fetch(upload.url, { @@ -65,7 +65,7 @@ export const test = { }) const downloadUrl = Result.unwrap( - await blobsStorage.createDownloadUrl(digest.bytes) + await blobsStorage.createDownloadUrl(digest) ) const res = await fetch(downloadUrl) diff --git a/packages/upload-api/test/storage/blobs-storage.js b/packages/upload-api/test/storage/blobs-storage.js index 745b1d521..903389f4e 100644 --- a/packages/upload-api/test/storage/blobs-storage.js +++ b/packages/upload-api/test/storage/blobs-storage.js @@ -1,14 +1,12 @@ import * as Types from '../../src/types.js' - import { base64pad } from 'multiformats/bases/base64' -import { decode as digestDecode } from 'multiformats/hashes/digest' import { SigV4 } from '@web3-storage/sigv4' import { base58btc } from 'multiformats/bases/base58' import { sha256 } from 'multiformats/hashes/sha2' import { ok, error } from '@ucanto/core' import { BlobNotFound } from '../../src/blob/lib.js' -/** @param {import('multiformats').MultihashDigest} digest */ +/** @param {Types.MultihashDigest} digest */ const contentKey = (digest) => { const encodedMultihash = base58btc.encode(digest.bytes) return `${encodedMultihash}/${encodedMultihash}.blob` @@ -126,21 +124,17 @@ export class BlobsStorage { this.content = content } - /** @param {import('multiformats').MultihashDigest} digest */ + /** @param {Types.MultihashDigest} digest */ #bucketPath(digest) { return `/${this.bucket}/${contentKey(digest)}` } - /** - * @param {Uint8Array} multihash - */ - async has(multihash) { - return ok(this.content.has(this.#bucketPath(digestDecode(multihash)))) + /** @param {Types.MultihashDigest} digest */ + async has(digest) { + return ok(this.content.has(this.#bucketPath(digest))) } - /** - * @param {import('multiformats').MultihashDigest} digest - */ + /** @param {Types.MultihashDigest} digest */ async stream(digest) { const key = this.#bucketPath(digest) if (!this.server) { @@ -169,13 +163,13 @@ export class BlobsStorage { } /** - * @param {Uint8Array} multihash + * @param {Types.MultihashDigest} digest * @param {number} size * @param {number} expiresIn */ - async createUploadUrl(multihash, size, expiresIn) { + async createUploadUrl(digest, size, expiresIn) { const { bucket, accessKeyId, secretAccessKey, region, baseURL } = this - const multihashDigest = digestDecode(multihash) + // sigv4 const sig = new SigV4({ accessKeyId, @@ -183,9 +177,9 @@ export class BlobsStorage { region, }) - const checksum = base64pad.baseEncode(multihashDigest.digest) + const checksum = base64pad.baseEncode(digest.bytes) const { search, hash } = sig.sign({ - key: contentKey(multihashDigest), + key: contentKey(digest), checksum, bucket, expires: expiresIn, @@ -193,7 +187,7 @@ export class BlobsStorage { const url = new URL(baseURL) url.search = search - url.pathname = this.#bucketPath(multihashDigest) + url.pathname = this.#bucketPath(digest) url.hash = hash url.searchParams.set( 'X-Amz-SignedHeaders', @@ -211,9 +205,8 @@ export class BlobsStorage { } } - /** @param {Uint8Array} multihash */ - async createDownloadUrl(multihash) { - const digest = digestDecode(multihash) + /** @param {Types.MultihashDigest} digest */ + async createDownloadUrl (digest) { const url = new URL(this.#bucketPath(digest), this.baseURL) return ok(/** @type {Types.URI} */ (url.toString())) } From 5ad6b9401c7434aab99973fa3ffab6f2ed4904fb Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:21:43 +0100 Subject: [PATCH 2/8] fix: allocations storage in tests --- .../test/storage/allocations-storage-tests.js | 12 ++++++------ .../test/storage/allocations-storage.js | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/upload-api/test/storage/allocations-storage-tests.js b/packages/upload-api/test/storage/allocations-storage-tests.js index 6ba345adb..a9adc1b24 100644 --- a/packages/upload-api/test/storage/allocations-storage-tests.js +++ b/packages/upload-api/test/storage/allocations-storage-tests.js @@ -102,7 +102,7 @@ export const test = { const digest = multihash.bytes const size = data.byteLength - const allocationGet0 = await allocationsStorage.get(spaceDid, digest) + const allocationGet0 = await allocationsStorage.get(spaceDid, multihash) assert.ok(allocationGet0.error) assert.equal(allocationGet0.error?.name, RecordNotFoundErrorName) @@ -132,7 +132,7 @@ export const test = { assert.ok(allocationInsert.ok) assert.ok(allocationInsert.ok?.blob) - const allocationGet1 = await allocationsStorage.get(spaceDid, digest) + const allocationGet1 = await allocationsStorage.get(spaceDid, multihash) assert.ok(allocationGet1.ok) assert.ok(allocationGet1.ok?.blob) assert.equal(allocationGet1.ok?.blob.size, size) @@ -150,7 +150,7 @@ export const test = { const digest = multihash.bytes const size = data.byteLength - const allocationExist0 = await allocationsStorage.exists(spaceDid, digest) + const allocationExist0 = await allocationsStorage.exists(spaceDid, multihash) assert.ok(!allocationExist0.error) assert.ok(!allocationExist0.ok) @@ -180,7 +180,7 @@ export const test = { assert.ok(allocationInsert.ok) assert.ok(allocationInsert.ok?.blob) - const allocationExist1 = await allocationsStorage.exists(spaceDid, digest) + const allocationExist1 = await allocationsStorage.exists(spaceDid, multihash) assert.ok(allocationExist1.ok) assert.ok(!allocationExist1.error) }, @@ -317,7 +317,7 @@ export const test = { const multihash = await sha256.digest(data) const digest = multihash.bytes - const removeResult = await allocationsStorage.remove(spaceDid, digest) + const removeResult = await allocationsStorage.remove(spaceDid, multihash) assert.ok(removeResult.error) assert.equal(removeResult.error?.name, RecordNotFoundErrorName) @@ -355,7 +355,7 @@ export const test = { }) assert.ok(allocationInsert0.ok) - const removeResult = await allocationsStorage.remove(spaceDid, digest) + const removeResult = await allocationsStorage.remove(spaceDid, multihash) assert.ok(removeResult.ok) assert.equal(removeResult.ok?.size, size) }, diff --git a/packages/upload-api/test/storage/allocations-storage.js b/packages/upload-api/test/storage/allocations-storage.js index bf548ddf6..27634c118 100644 --- a/packages/upload-api/test/storage/allocations-storage.js +++ b/packages/upload-api/test/storage/allocations-storage.js @@ -36,12 +36,12 @@ export class AllocationsStorage { /** * @param {Types.DID} space - * @param {Uint8Array} blobMultihash + * @param {Types.MultihashDigest} digest * @returns {ReturnType} */ - async get(space, blobMultihash) { + async get(space, digest) { const item = this.items.find( - (i) => i.space === space && equals(i.blob.digest, blobMultihash) + (i) => i.space === space && equals(i.blob.digest, digest.bytes) ) if (!item) { return { error: new RecordNotFound() } @@ -51,24 +51,24 @@ export class AllocationsStorage { /** * @param {Types.DID} space - * @param {Uint8Array} blobMultihash + * @param {Types.MultihashDigest} digest * @returns {ReturnType} */ - async exists(space, blobMultihash) { + async exists(space, digest) { const item = this.items.find( - (i) => i.space === space && equals(i.blob.digest, blobMultihash) + (i) => i.space === space && equals(i.blob.digest, digest.bytes) ) return { ok: !!item } } /** * @param {Types.DID} space - * @param {Uint8Array} blobMultihash + * @param {Types.MultihashDigest} digest * @returns {ReturnType} */ - async remove(space, blobMultihash) { + async remove(space, digest) { const item = this.items.find( - (i) => i.space === space && equals(i.blob.digest, blobMultihash) + (i) => i.space === space && equals(i.blob.digest, digest.bytes) ) if (!item) { return { error: new RecordNotFound() } From 4e8010ccb672dbbf63ce6d491c3eb7cd542e5e1b Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:23:18 +0100 Subject: [PATCH 3/8] fix: allocations storage in tests --- packages/upload-api/test/storage/allocations-storage-tests.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/upload-api/test/storage/allocations-storage-tests.js b/packages/upload-api/test/storage/allocations-storage-tests.js index a9adc1b24..213830fe2 100644 --- a/packages/upload-api/test/storage/allocations-storage-tests.js +++ b/packages/upload-api/test/storage/allocations-storage-tests.js @@ -315,7 +315,6 @@ export const test = { const data = new Uint8Array([11, 22, 34, 44, 55]) const multihash = await sha256.digest(data) - const digest = multihash.bytes const removeResult = await allocationsStorage.remove(spaceDid, multihash) From 86133ad33d72c52f53bac59d5f111afe7be3ff09 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:26:46 +0100 Subject: [PATCH 4/8] fix: more test fixes --- packages/w3up-client/test/capability/blob.test.js | 2 +- packages/w3up-client/test/client.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/w3up-client/test/capability/blob.test.js b/packages/w3up-client/test/capability/blob.test.js index 5f47d7f95..becae986d 100644 --- a/packages/w3up-client/test/capability/blob.test.js +++ b/packages/w3up-client/test/capability/blob.test.js @@ -39,7 +39,7 @@ export const BlobClient = Test.withContext({ // TODO we should check blobsStorage as well assert.deepEqual( - await allocationsStorage.exists(space.did(), multihash.bytes), + await allocationsStorage.exists(space.did(), multihash), { ok: true, } diff --git a/packages/w3up-client/test/client.test.js b/packages/w3up-client/test/client.test.js index b5ba8f8fe..53e8ea3bc 100644 --- a/packages/w3up-client/test/client.test.js +++ b/packages/w3up-client/test/client.test.js @@ -56,7 +56,7 @@ export const testClient = { assert.deepEqual( await allocationsStorage.exists( space.did(), - expectedCar.cid.multihash.bytes + expectedCar.cid.multihash ), { ok: true, @@ -181,7 +181,7 @@ export const testClient = { } assert.deepEqual( - await allocationsStorage.exists(space.did(), carCID.multihash.bytes), + await allocationsStorage.exists(space.did(), carCID.multihash), { ok: true, } From ea284d8216b4ec5dc2c9ac73514809b93bdd75d6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:30:27 +0100 Subject: [PATCH 5/8] fix: more test fixes --- packages/upload-api/test/handlers/blob.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/upload-api/test/handlers/blob.js b/packages/upload-api/test/handlers/blob.js index 33da67d0a..52f194b6e 100644 --- a/packages/upload-api/test/handlers/blob.js +++ b/packages/upload-api/test/handlers/blob.js @@ -243,6 +243,7 @@ export const test = { assert.ok(!secondNext.accept.receipt, 'accept receipt was not received') // Store the blob to the address + console.log(address.url) const goodPut = await fetch(address.url, { method: 'PUT', mode: 'cors', From 91b65cf07654061490a53735e4c8d1f84bfe71a2 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:34:48 +0100 Subject: [PATCH 6/8] fix: checksum --- packages/upload-api/test/handlers/blob.js | 1 - packages/upload-api/test/storage/blobs-storage.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/upload-api/test/handlers/blob.js b/packages/upload-api/test/handlers/blob.js index 52f194b6e..33da67d0a 100644 --- a/packages/upload-api/test/handlers/blob.js +++ b/packages/upload-api/test/handlers/blob.js @@ -243,7 +243,6 @@ export const test = { assert.ok(!secondNext.accept.receipt, 'accept receipt was not received') // Store the blob to the address - console.log(address.url) const goodPut = await fetch(address.url, { method: 'PUT', mode: 'cors', diff --git a/packages/upload-api/test/storage/blobs-storage.js b/packages/upload-api/test/storage/blobs-storage.js index 903389f4e..c4622e85c 100644 --- a/packages/upload-api/test/storage/blobs-storage.js +++ b/packages/upload-api/test/storage/blobs-storage.js @@ -177,7 +177,7 @@ export class BlobsStorage { region, }) - const checksum = base64pad.baseEncode(digest.bytes) + const checksum = base64pad.baseEncode(digest.digest) const { search, hash } = sig.sign({ key: contentKey(digest), checksum, From d9bd509184331a3e4344e39aebd50f114b55a59b Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 14:36:52 +0100 Subject: [PATCH 7/8] chore: appease linter --- .../test/storage/allocations-storage-tests.js | 10 ++++++++-- packages/upload-api/test/storage/blobs-storage.js | 2 +- packages/w3up-client/test/capability/blob.test.js | 9 +++------ packages/w3up-client/test/client.test.js | 5 +---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/upload-api/test/storage/allocations-storage-tests.js b/packages/upload-api/test/storage/allocations-storage-tests.js index 213830fe2..910093c6b 100644 --- a/packages/upload-api/test/storage/allocations-storage-tests.js +++ b/packages/upload-api/test/storage/allocations-storage-tests.js @@ -150,7 +150,10 @@ export const test = { const digest = multihash.bytes const size = data.byteLength - const allocationExist0 = await allocationsStorage.exists(spaceDid, multihash) + const allocationExist0 = await allocationsStorage.exists( + spaceDid, + multihash + ) assert.ok(!allocationExist0.error) assert.ok(!allocationExist0.ok) @@ -180,7 +183,10 @@ export const test = { assert.ok(allocationInsert.ok) assert.ok(allocationInsert.ok?.blob) - const allocationExist1 = await allocationsStorage.exists(spaceDid, multihash) + const allocationExist1 = await allocationsStorage.exists( + spaceDid, + multihash + ) assert.ok(allocationExist1.ok) assert.ok(!allocationExist1.error) }, diff --git a/packages/upload-api/test/storage/blobs-storage.js b/packages/upload-api/test/storage/blobs-storage.js index c4622e85c..f1f7489dd 100644 --- a/packages/upload-api/test/storage/blobs-storage.js +++ b/packages/upload-api/test/storage/blobs-storage.js @@ -206,7 +206,7 @@ export class BlobsStorage { } /** @param {Types.MultihashDigest} digest */ - async createDownloadUrl (digest) { + async createDownloadUrl(digest) { const url = new URL(this.#bucketPath(digest), this.baseURL) return ok(/** @type {Types.URI} */ (url.toString())) } diff --git a/packages/w3up-client/test/capability/blob.test.js b/packages/w3up-client/test/capability/blob.test.js index becae986d..a713f4756 100644 --- a/packages/w3up-client/test/capability/blob.test.js +++ b/packages/w3up-client/test/capability/blob.test.js @@ -38,12 +38,9 @@ export const BlobClient = Test.withContext({ }) // TODO we should check blobsStorage as well - assert.deepEqual( - await allocationsStorage.exists(space.did(), multihash), - { - ok: true, - } - ) + assert.deepEqual(await allocationsStorage.exists(space.did(), multihash), { + ok: true, + }) assert.deepEqual(multihash.bytes, bytesHash.bytes) }, diff --git a/packages/w3up-client/test/client.test.js b/packages/w3up-client/test/client.test.js index 53e8ea3bc..831fb1578 100644 --- a/packages/w3up-client/test/client.test.js +++ b/packages/w3up-client/test/client.test.js @@ -54,10 +54,7 @@ export const testClient = { }) assert.deepEqual( - await allocationsStorage.exists( - space.did(), - expectedCar.cid.multihash - ), + await allocationsStorage.exists(space.did(), expectedCar.cid.multihash), { ok: true, } From 08c169511619ad76533a53aca594d1b3022666f3 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 6 Jun 2024 13:35:38 +0100 Subject: [PATCH 8/8] fix: blob get --- packages/upload-api/src/blob/get.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/upload-api/src/blob/get.js b/packages/upload-api/src/blob/get.js index 7d0a2678f..2176a4b7f 100644 --- a/packages/upload-api/src/blob/get.js +++ b/packages/upload-api/src/blob/get.js @@ -1,8 +1,8 @@ import * as Server from '@ucanto/server' import * as Blob from '@web3-storage/capabilities/blob' +import * as Digest from 'multiformats/hashes/digest' import * as API from '../types.js' import { BlobNotFound } from './lib.js' -import { decode } from 'multiformats/hashes/digest' /** * @param {API.BlobServiceContext} context @@ -10,11 +10,11 @@ import { decode } from 'multiformats/hashes/digest' */ export function blobGetProvider(context) { return Server.provide(Blob.get, async ({ capability }) => { - const { digest } = capability.nb + const digest = Digest.decode(capability.nb.digest) const space = Server.DID.parse(capability.with).did() const res = await context.allocationsStorage.get(space, digest) if (res.error && res.error.name === 'RecordNotFound') { - return Server.error(new BlobNotFound(decode(digest))) + return Server.error(new BlobNotFound(digest)) } return res })