Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add blake3 hasher #421

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@libp2p/websockets": "^9.0.11",
"@libp2p/webtransport": "^5.0.16",
"@multiformats/dns": "^1.0.6",
"@noble/hashes": "^1.5.0",
"@sgtpooki/file-type": "^1.0.1",
"helia": "^5.1.0",
"ipfs-css": "^1.4.0",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/blake3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { blake3 as b3 } from '@noble/hashes/blake3'
import { from } from 'multiformats/hashes/hasher'

export const blake3 = from({
name: 'blake3',
code: 0x1e, // Code for blake3 from https://github.com/multiformats/multicodec/blob/352d05ad430713088e867216152725f581387bc8/table.csv#L21
encode: (input) => b3(input)
})
5 changes: 5 additions & 0 deletions src/lib/get-verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
import { createHelia, type Helia, type Routing } from 'helia'
import { createLibp2p, type Libp2pOptions } from 'libp2p'
import * as libp2pInfo from 'libp2p/version'
import { blake3 } from './blake3.js'
import { contentTypeParser } from './content-type-parser.js'
import type { ConfigDb } from './config-db.js'
import type { ComponentLogger } from '@libp2p/logger'
Expand Down Expand Up @@ -52,6 +53,8 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
blockBrokers.push(trustlessGateway())
}

const hashers = [blake3]

let helia: Helia
if (config.enableWss || config.enableWebTransport) {
// If we are using websocket or webtransport, we need to instantiate libp2p
Expand All @@ -65,6 +68,7 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
libp2p,
routers,
blockBrokers,
hashers,
dns: dnsConfig
})
} else {
Expand All @@ -81,6 +85,7 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
helia = await createHeliaHTTP({
routers,
blockBrokers,
hashers,
dns: dnsConfig
})
}
Expand Down
Loading