Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: refresh and update all deps (#410)
- Loading branch information
Showing
13 changed files
with
1,004 additions
and
6,977 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import multicodecs from 'multicodec' | ||
|
||
/** | ||
* Converts supported codec codes from https://github.com/multiformats/multicodec/blob/master/table.csv to their names. | ||
*/ | ||
export default function getCodecNameFromCode (code: number): string { | ||
switch (code) { | ||
case multicodecs.DAG_CBOR: | ||
case 113: | ||
return 'dag-cbor' | ||
case multicodecs.DAG_PB: | ||
case 112: | ||
return 'dag-pb' | ||
case multicodecs.GIT_RAW: | ||
case 120: | ||
return 'git-raw' | ||
case multicodecs.RAW: | ||
case 85: | ||
return 'raw' | ||
case multicodecs.JSON: | ||
case 512: | ||
return 'json' | ||
case multicodecs.DAG_JSON: | ||
case 297: | ||
return 'dag-json' | ||
case multicodecs.DAG_JOSE: | ||
case 133: | ||
return 'dag-jose' | ||
default: | ||
// TODO: Remove dependency on multicodecs | ||
return multicodecs.codeToName[code as multicodecs.CodecCode] | ||
return `codec code ${code}=unknown` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { type Helia } from '@helia/interface' | ||
import { CID, type MultihashDigest } from 'multiformats' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
import { CID } from 'multiformats' | ||
|
||
import codecImporter from './codec-importer.js' | ||
import { getHasherForCode } from './hash-importer.js' | ||
|
||
export function ensureLeadingSlash (str: string): string { | ||
if (str.startsWith('/')) return str | ||
return `/${str}` | ||
} | ||
|
||
export interface DigestFn { | ||
(data: Uint8Array): Promise<MultihashDigest<number>> | ||
} | ||
|
||
export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode(n: T): Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> { | ||
export async function addDagNodeToHelia <T> (helia: Helia, codecName: string, node: T, hasherCode = 18): Promise<CID> { | ||
const codec = await codecImporter(codecName) | ||
const hasher = await getHasherForCode(hasherCode) | ||
const encodedNode = codec.encode(node) | ||
const hash = digestFn != null ? await digestFn(encodedNode) : await sha256.digest(encodedNode) | ||
const cid = CID.createV1(codec.code, hash) | ||
const mhDigest = await hasher.digest(encodedNode) | ||
const cid = CID.createV1(codec.code, mhDigest) | ||
|
||
return helia.blockstore.put(cid, encodedNode) | ||
} |
Oops, something went wrong.