Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add IPNI EntryChunk encoding #18

Merged
merged 4 commits into from
Dec 15, 2023
Merged

feat: add IPNI EntryChunk encoding #18

merged 4 commits into from
Dec 15, 2023

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Dec 14, 2023

Provides an EntryChunk class to help encode batches of multihashes as IPNI EntryChunk IPLD blocks.

import { EntryChunk } from '@web3-storage/ipni'
import { sha256 } from 'multiformats/hashes/sha2'

const hash = await sha256.encode(new Uint8Array())
const chunk = EntryChunk.fromMultihashes([hash])
const block = await chunk.export()

// the EntryChunk CID should be passed to an Advertisement as the `entries` Link.
console.log(`entries cid ${block.cid}`)

Encourages using dag-cbor as it's almost half the size as dag-json, and every entrychunk and advert has to be stored and replicated to 1 or more IPNI servers.

Borrows the idea of an export() that provides an encoded IPLD block from @Gozala in ucanto https://github.com/web3-storage/ucanto/blob/2200d43595b85a5e7b60c234987ff3ce91404401/packages/core/src/delegation.js#L248

Provides a cheap and accurate calculateEncodedSize() function to allow callers to determine when to split entries across multiple blocks.

Thanks to @rvagg for the very useful https://github.com/rvagg/cborg module that makes that possible and the inspriation in the calculateHeaderLength fn from js-car

see: https://github.com/ipld/js-car/blob/562c39266edda8422e471b7f83eadc8b7362ea0c/src/buffer-writer.js#L215

Fixes #2

WIP on storacha/specs#85

License: MIT

Provides an EntryChunk class to help encode batches of multihashes as IPNI EntryChunk IPLD blocks.

```js
import { EntryChunk } from '@web3-storage/ipni'
import { sha256 } from 'multiformats/hashes/sha2'

const hash = await sha256.encode(new Uint8Array())
const chunk = EntryChunk.fromMultihashes([hash])
const block = await chunk.export()

// the EntryChunk CID should be passed to an Advertisement as the `entries` Link.
console.log(`entries cid ${block.cid}`)
```

Encourages using dag-cbor as it's almost half the size as dag-json, and every entrychunk and advert has to be stored and replicated to 1 or more IPNI servers.

Borrows the idea of an `export()` that provides an encoded IPLD block from @Gozala in ucanto https://github.com/web3-storage/ucanto/blob/2200d43595b85a5e7b60c234987ff3ce91404401/packages/core/src/delegation.js#L248

Provides a cheap and accurate `calculateEncodedSize()` function to allow callers to determine when to split entries across multiple blocks.

Thanks to @rvagg for the very useful https://github.com/rvagg/cborg module that makes that possible and the inspriation in the calculateHeaderLength fn from js-car

see: https://github.com/ipld/js-car/blob/562c39266edda8422e471b7f83eadc8b7362ea0c/src/buffer-writer.js#L215

License: MIT
Signed-off-by: Oli Evans <[email protected]>
entry-chunk.js Show resolved Hide resolved
@olizilla olizilla requested a review from alanshaw December 14, 2023 18:04
License: MIT
Signed-off-by: Oli Evans <[email protected]>
@olizilla olizilla merged commit d4e44c3 into main Dec 15, 2023
1 check passed
@olizilla olizilla deleted the entry-chunk branch December 15, 2023 11:52
olizilla pushed a commit that referenced this pull request Dec 15, 2023
🤖 I have created a release *beep* *boop*
---


## [3.1.0](v3.0.0...v3.1.0)
(2023-12-15)


### Features

* add IPNI EntryChunk encoding
([#18](#18))
([d4e44c3](d4e44c3))


### Bug Fixes

* test that CID parameters are compatible CID types
([#17](#17))
([b0ca303](b0ca303))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide object for creating entries
2 participants