Skip to content

Commit

Permalink
fix: use the bytes field of a multihash
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosa committed May 9, 2024
1 parent e4ab876 commit 3825838
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 3 additions & 4 deletions packages/upload-client/src/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export async function add(
const bytes =
data instanceof Uint8Array ? data : new Uint8Array(await data.arrayBuffer())
const multihash = await sha256.digest(bytes)
const { digest } = multihash
const size = bytes.length
/* c8 ignore next */
const conn = options.connection ?? connection
Expand All @@ -188,7 +187,7 @@ export async function add(
with: SpaceDID.from(resource),
nb: {
blob: {
digest,
digest: multihash.bytes,
size,
},
},
Expand Down Expand Up @@ -371,7 +370,7 @@ export async function list(
*/
export async function remove(
{ issuer, with: resource, proofs, audience },
{ digest },
multihashDigest,
options = {}
) {
/* c8 ignore next */
Expand All @@ -383,7 +382,7 @@ export async function remove(
audience: audience ?? servicePrincipal,
with: SpaceDID.from(resource),
nb: {
digest,
digest: multihashDigest.bytes,
},
proofs,
})
Expand Down
9 changes: 3 additions & 6 deletions packages/upload-client/test/blob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Blob.add', () => {
)

assert(multihash)
assert.deepEqual(multihash.digest, car.cid.multihash.digest)
assert.deepEqual(multihash.bytes, car.cid.multihash.bytes)

// make sure it can also work without fetchWithUploadProgress
/** @type {import('../src/types.js').ProgressStatus[]} */
Expand All @@ -106,10 +106,7 @@ describe('Blob.add', () => {
},
}
)
assert.deepEqual(
addedWithoutUploadProgress.digest,
car.cid.multihash.digest
)
assert.deepEqual(addedWithoutUploadProgress.bytes, car.cid.multihash.bytes)
assert.equal(
progressWithoutUploadProgress.reduce(
(max, { loaded }) => Math.max(max, loaded),
Expand Down Expand Up @@ -628,7 +625,7 @@ describe('Blob.remove', () => {
const invCap = invocation.capabilities[0]
assert.equal(invCap.can, BlobCapabilities.remove.can)
assert.equal(invCap.with, space.did())
assert.equal(String(invCap.nb?.digest), car.cid.multihash.digest)
assert.equal(String(invCap.nb?.digest), car.cid.multihash.bytes)
return { ok: { size: car.size } }
}),
},
Expand Down

0 comments on commit 3825838

Please sign in to comment.