Skip to content

Commit

Permalink
fix: missing blob-index deps (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed May 15, 2024
1 parent f2192f8 commit deb8cc9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
6 changes: 1 addition & 5 deletions packages/blob-index/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@
"@ucanto/core": "^10.0.1",
"@ucanto/interface": "^10.0.1",
"@web3-storage/capabilities": "workspace:^",
"carstream": "^2.1.0",
"multiformats": "^13.0.1",
"uint8arrays": "^5.0.3"
},
"devDependencies": {
"@ipld/car": "^5.1.1",
"@types/assert": "^1.5.6",
"@types/mocha": "^10.0.1",
"@ucanto/transport": "^9.1.1",
"@web-std/blob": "^3.0.5",
"@web3-storage/eslint-config-w3up": "workspace:^",
"c8": "^7.14.0",
"carstream": "^2.1.0",
"entail": "^2.1.2",
"one-webcrypto": "git://github.com/web3-storage/one-webcrypto",
"typescript": "5.2.2"
Expand Down
22 changes: 6 additions & 16 deletions packages/blob-index/test/helpers/random.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* global crypto */
import { CID } from 'multiformats'
import { webcrypto } from 'one-webcrypto'
import { sha256 } from 'multiformats/hashes/sha2'
import * as CAR from '@ucanto/transport/car'
import * as raw from 'multiformats/codecs/raw'
import { CarWriter } from '@ipld/car'
import { Blob } from '@web-std/blob'
import { webcrypto } from 'one-webcrypto'

/** @param {number} size */
export async function randomBytes(size) {
Expand All @@ -13,7 +12,7 @@ export async function randomBytes(size) {
const chunk = new Uint8Array(Math.min(size, 65_536))
webcrypto.getRandomValues(chunk)

size -= bytes.length
size -= chunk.length
bytes.set(chunk, size)
}
return bytes
Expand All @@ -24,18 +23,9 @@ export async function randomCAR(size) {
const bytes = await randomBytes(size)
const hash = await sha256.digest(bytes)
const root = CID.create(1, raw.code, hash)

const { writer, out } = CarWriter.create(root)
writer.put({ cid: root, bytes })
writer.close()

const chunks = []
for await (const chunk of out) {
chunks.push(chunk)
}
const blob = new Blob(chunks)
const cid = await CAR.codec.link(new Uint8Array(await blob.arrayBuffer()))

const carBytes = CAR.codec.encode({ roots: [{ cid: root, bytes }] })
const blob = new Blob([carBytes])
const cid = await CAR.codec.link(carBytes)
return Object.assign(blob, { cid, roots: [root] })
}

Expand Down
3 changes: 1 addition & 2 deletions packages/blob-index/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"types": ["mocha"]
"outDir": "dist"
},
"include": ["src", "test"],
"exclude": ["**/node_modules/**", "dist"],
Expand Down
21 changes: 5 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit deb8cc9

Please sign in to comment.