Skip to content

Commit

Permalink
fix: cid for filecoin offer must be raw
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed May 14, 2024
1 parent 5618644 commit 28d1acf
Show file tree
Hide file tree
Showing 5 changed files with 7,682 additions and 9,292 deletions.
1 change: 0 additions & 1 deletion packages/upload-api/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export async function randomCAR(size) {
const hash = await sha256.digest(bytes)
const root = CID.create(1, raw.code, hash)

// @ts-expect-error old multiformats in @ipld/car
const { writer, out } = CarWriter.create(root)
writer.put({ cid: root, bytes })
writer.close()
Expand Down
5 changes: 4 additions & 1 deletion packages/upload-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ async function uploadBlockStream(
const bytes = new Uint8Array(await car.arrayBuffer())
// Invoke blob/add and write bytes to write target
const multihash = await Blob.add(conf, bytes, options)
// Should this be raw instead?
const cid = Link.create(carCodec.code, multihash)
let piece
if (pieceHasher) {
const multihashDigest = await pieceHasher.digest(bytes)
/** @type {import('@web3-storage/capabilities/types').PieceLink} */
piece = Link.create(raw.code, multihashDigest)
const content = Link.create(raw.code, multihash)

// Invoke filecoin/offer for data
const result = await Storefront.filecoinOffer(
{
Expand All @@ -149,7 +152,7 @@ async function uploadBlockStream(
with: conf.issuer.did(),
proofs: conf.proofs,
},
cid,
content,
piece,
options
)
Expand Down
1 change: 0 additions & 1 deletion packages/upload-client/test/helpers/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { toBlock } from './block.js'
*/
export async function toCAR(bytes) {
const block = await toBlock(bytes)
// @ts-expect-error old multiformats in @ipld/car
const { writer, out } = CarWriter.create(block.cid)
writer.put(block)
writer.close()
Expand Down
1 change: 0 additions & 1 deletion packages/w3up-client/test/helpers/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export async function toCAR(bytes) {
const hash = await sha256.digest(bytes)
const root = CID.create(1, raw.code, hash)

// @ts-expect-error old multiformats in @ipld/car
const { writer, out } = CarWriter.create(root)
writer.put({ cid: root, bytes })
writer.close()
Expand Down
Loading

0 comments on commit 28d1acf

Please sign in to comment.