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

@aragon/sdk-ipfs

v1.1.0

Published

@aragon/sdk-ifps provides a wrapper to send requests to an IPFS Cluster using the IPFS API. It supports standard requests as well as streamed requests.

Downloads

1,080

Readme

Aragon JS SDK IPFS

@aragon/sdk-ifps provides a wrapper to send requests to an IPFS Cluster using the IPFS API. It supports standard requests as well as streamed requests.

Installation

Use npm or yarn to install @aragon/sdk-ipfs.

npm install @aragon/sdk-ipfs
yarn add @aragon/sdk-ipfs

Usage

IPFS Client

The Aragon infrastructure uses an IPFS cluster which requires authentication based on an API key. The provided Client works as well on any canonical deployment by just not providing any API key in the headers.

import { Client as IpfsClient } from "@aragon/sdk-ipfs";

const headers = {
  "X-API-KEY": "1234...",
};
const client = new IpfsClient(clusterUrl, headers);

Node info

Retrieves the details of the node behind the endpoint.

const client = new IpfsClient(clusterUrl, headers);

const versionInfo = await client.nodeInfo();
console.log(versionInfo);
// {
//   id: string;
//   addresses: string[];
//   agentVersion: string;
//   protocolVersion: string;
//   protocols: string[];
//   publicKey: string;
// }

IPFS add

Uploads data to the IPFS cluster and returns the hash of the newly pinned file. The following data types are supported:

As a string (preferred)

const client = new IpfsClient(clusterUrl, headers);

const content = "I am a test";
const { hash } = await client.add(content);
console.log(hash);
// QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK

Uint8Array (preferred)

const client = new IpfsClient(clusterUrl, headers);

const content = Uint8Array([73, 32, 97, 109, 32, 97, 32, 116, 101, 115, 116]);
const { hash } = await client.add(content);
console.log(hash);
// QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK

File (browser-only)

const client = new IpfsClient(clusterUrl, headers);

const content = new File(["I am a test"], "test.txt", { type: "text/plain" });
const { hash } = await client.add(content);
console.log(hash);
// QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK

Blob (browser-only)

const client = new IpfsClient(clusterUrl, headers);

const content = new File(["I am a test"], { type: "text/plain" });
const { hash } = await client.add(content);
console.log(hash);
// QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK

IPFS cat

Fetches the content behind the given CiD and returns it as a Uint8Array.

const client = new IpfsClient(clusterUrl, headers);

const cid = "QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK";
const recoveredBytes = await client.cat(cid);
console.log(recoveredBytes);
// Uint8Array(11) [
//    73, 32,  97, 109,  32,
//    97, 32, 116, 101, 115,
//   116
// ]

Decoding as text

const recoveredString = new TextDecoder().decode(recoveredBytes);
console.log(recoveredString);
// I am a test

IPFS pin

Requests the node to keep a local copy of the data behind the given CiD.

const client = new IpfsClient(clusterUrl, headers);

const cid = "QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK";
const { pins } = await client.pin(cid);
console.log(pins);
// ["QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK"]

Note: Using IPFS pin on the Aragon IPFS cluster may be restricted. Use IPFS add instead.

IPFS unpin

Requests the node to keep a local copy of the data behind the given CiD.

const client = new IpfsClient(clusterUrl, headers);

const cid = "QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK";
const { pins } = await client.unpin(cid);
console.log(pins);
// ["QmeJ4kRW21RRgjywi9ydvY44kfx71x2WbRq7ik5xh5zBZK"]

Note: Using IPFS unpin on the Aragon IPFS cluster may be restricted.

Testing

To execute library tests just run:

yarn build
yarn test