Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@libp2p/fetch
Advanced tools
Implementation of the Fetch Protocol
An implementation of the Fetch protocol as described here: https://github.com/libp2p/specs/tree/master/fetch
The fetch protocol is a simple protocol for requesting a value corresponding to a key from a peer.
import { createLibp2p } from 'libp2p'
import { fetch } from '@libp2p/fetch'
import { peerIdFromString } from '@libp2p/peer-id'
const libp2p = await createLibp2p({
services: {
fetch: fetch()
}
})
// Given a key (as a Uint8Array) returns a value (as a Uint8Array), or
// undefined if the key isn't found.
//
// All keys must be prefixed by the same prefix, which will be used to find
// the appropriate key lookup function.
async function my_subsystem_key_lookup (key: Uint8Array): Promise<Uint8Array | undefined> {
// app specific callback to lookup key-value pairs.
return Uint8Array.from([0, 1, 2, 3, 4])
}
// Enable this peer to respond to fetch requests for keys that begin with
// '/my_subsystem_key_prefix/'
libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
const key = '/my_subsystem_key_prefix/{...}'
const peerDst = peerIdFromString('Qmfoo...')
// Load the value from the remote peer, timing out after 10s
const value = await libp2p.services.fetch.fetch(peerDst, key, {
signal: AbortSignal.timeout(10_000)
})
$ npm i @libp2p/fetch
<script>
tagLoading this module through a script tag will make its exports available as Libp2pFetch
in the global namespace.
<script src="https://unpkg.com/@libp2p/fetch/dist/index.min.js"></script>
Licensed under either of
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.
FAQs
Implementation of the Fetch Protocol
The npm package @libp2p/fetch receives a total of 0 weekly downloads. As such, @libp2p/fetch popularity was classified as not popular.
We found that @libp2p/fetch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.