Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.43 KB

File metadata and controls

91 lines (68 loc) · 3.43 KB

Helia logo

@helia/block-brokers

ipfs.tech Discuss codecov CI

Block brokers for Helia

Install

$ npm i @helia/block-brokers

Browser <script> tag

Loading this module through a script tag will make its exports available as HeliaBlockBrokers in the global namespace.

<script src="https://unpkg.com/@helia/block-brokers/dist/index.min.js"></script>

Example - Customizing trustless gateway requests

import { TrustlessGatewayBlockBroker } from "@helia/block-brokers/trustless-gateway/broker.js";
import { defaultLogger } from "@libp2p/logger";
import { CID } from "multiformats/cid";

// Create a trustless gateway block broker with custom request options
const gatewayBlockBroker = new TrustlessGatewayBlockBroker(
  {
    routing, // Your routing implementation
    logger: defaultLogger(),
  },
  {
    allowInsecure: true,
    allowLocal: true,
    // Add a transformRequestInit function to customize the fetch request
    transformRequestInit: (requestInit) => {
      // Add authentication headers for your gateway
      requestInit.headers = {
        ...requestInit.headers,
        Authorization: "Bearer your-jwt-token-here",
      };
      return requestInit;
    },
  }
);

// Use the block broker to retrieve blocks
const cid = CID.parse(
  "bafybeic3q4y65yxu3yckr76q63bcvanhklwf6cwxuacnrot6v3gykrgsvq"
);
const block = await gatewayBlockBroker.retrieve?.(cid, {
  validateFn: async (block) => {
    // Optional validation function
    // You can validate the retrieved block here
  },
});

API Docs

License

Licensed under either of

Contribute

Contributions welcome! Please check out the issues.

Also see our contributing document for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.