npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@web3-storage/pieces

v2.1.0

Published

CLI to verify w3filecoin aggregate offers

Downloads

5

Readme

pieces 🍑

CLI to verify w3filecoin aggregate offers

# Create an aria2 download plan for all CARs with checksums
$ pieces plan -i offer.json --output piece-urls.aria

# Fetch and verify all the cars with aria2
$ aria2c -i piece-urls.aria

# Verify the piece cids and aggregate cid
$ pieces verify -i offer.json

Getting Started

With nodejs >= v20, You can install the pieces cli via npm

# install it globally with -g
$ npm install -g @web3-storage/pieces

$ pieces --help

  Usage
    $ piece <command> [options]

  Available Commands
    plan      create aria2 download plan for aggregate offer json
    verify    check the car piece cid is correct
    find      resolve url for piece cid
    v2        convert PieceCIDv1 to PieceCIDv2

or you can run it directly with npx

# run pieces from npm
$ npx @web3-storage/pieces --help

or run it from source; clone this repo, install the deps, and run cli.js

$ npm i
$ ./cli.js --help

Usage

The following commands are available

plan

Create an aria2 input file to download all the CARs for the pieces in an aggregate offer json

$ pieces plan --input aggregate-offer.json --output piece.urls

Pass the output to aria2 to fetch all the things, with checksum validation and resumable goodness.

$ aria2c -i piece.urls

input

{
  "aggregate": "bafkzcibbd3lmdpootmhl7xhn6dnz7ynhe5a7kaurlnppj7rqd4lembwgdfrdy",
  "collection": "did:key:z6MkqdncRZ1wj8zxCTDUQ8CRT8NQWd63T7mZRvZUX8B7XDFi",
  "orderID": 1695590709485,
  "pieces": [
    "bafkzcibbatsmklu6hhjkdz4hbatu4uk5bd4uk4zj43xocspxn7yiyo54jy7bg",
    "bafkzcibbas7jhdreszithbxqzcxvln2usxtbyeo75pqqsnzz26hybgvlpggcw",

output

  • Sets --checksum flag from car cid from roundabout, to ensure car bytes are correct
  • Sets --out to the piece cid, so we can map from input json to file name.
https://roundabout.web3.storage/bafkzcibbatsmklu6hhjkdz4hbatu4uk5bd4uk4zj43xocspxn7yiyo54jy7bg
  checksum=sha-256=47757f47518259fd3b6575d6cd48e161bcf23ea7cbf16b0638c8c981a0522f63
  out=bafkzcibbatsmklu6hhjkdz4hbatu4uk5bd4uk4zj43xocspxn7yiyo54jy7bg.car
https://roundabout.web3.storage/bafkzcibbas7jhdreszithbxqzcxvln2usxtbyeo75pqqsnzz26hybgvlpggcw
  checksum=sha-256=95673f0ef43a769840aba99e10b41b55601d42eb08e1d7b68b53750f5c6c826d
  out=bafkzcibbas7jhdreszithbxqzcxvln2usxtbyeo75pqqsnzz26hybgvlpggcw.car

verify

Check the piece CID for each car. Pass the path to the offer json as --input.

Run it from the dir with all the cars that you downloaded with aria from the aria download plan created with piece plan

$ pieces verify --input aggregate-offer.json
aggregate cid bafkzcibbd3lmdpootmhl7xhn6dnz7ynhe5a7kaurlnppj7rqd4lembwgdfrdy ok
verifying 1284 pieces
████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 30% | 5276557/17571857 MiB

takes ~120s to verify 1284 pieces at 18.4GiB

find

Find the car URL for a piece CID, if the car is stored in w3up and we have a content-claim for it.

$ pieces find bafkzcibbatsmklu6hhjkdz4hbatu4uk5bd4uk4zj43xocspxn7yiyo54jy7bg

output

{
  "piece":"bafkzcibbatsmklu6hhjkdz4hbatu4uk5bd4uk4zj43xocspxn7yiyo54jy7bg",
  "car":"bagbaierai52x6r2rqjm72o3foxlm2shbmg6pepvhzpywwbryzdeydicsf5rq",
  "url":"https://carpark-prod-0...",
  "roundabout":"https://roundabout.web3.storage/bafkzcibbatsmklu6hhjkdz4hbatu4uk5bd4uk4zj43xocspxn7yiyo54jy7bg"
}

v2

Converts PieceCIDv1 to PieceCIDv2 with its height embedded.

$ pieces v2 baga6ea4seaqhmw7z7q3jypdr54xaluhzdn6syn7ovovvjpaqul2qqenhmg43wii --height 30
bafkzcibcaaphmw7z7q3jypdr54xaluhzdn6syn7ovovvjpaqul2qqenhmg43wii
$ pieces v2 baga6ea4seaqhmw7z7q3jypdr54xaluhzdn6syn7ovovvjpaqul2qqenhmg43wii --log-size 35
bafkzcibcaaphmw7z7q3jypdr54xaluhzdn6syn7ovovvjpaqul2qqenhmg43wii