Block brokers for Helia
$ npm i @helia/block-brokersLoading 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>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
},
});Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
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.
