@helia/utils 2.5.2-6f8165b5 → 2.5.2-9114743f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +22 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/abstract-session.d.ts +3 -3
- package/dist/src/abstract-session.d.ts.map +1 -1
- package/dist/src/abstract-session.js.map +1 -1
- package/dist/src/errors.d.ts +4 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +4 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/graph-walker.d.ts +3 -21
- package/dist/src/graph-walker.d.ts.map +1 -1
- package/dist/src/graph-walker.js +20 -17
- package/dist/src/graph-walker.js.map +1 -1
- package/dist/src/index.d.ts +39 -36
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +62 -30
- package/dist/src/index.js.map +1 -1
- package/dist/src/pins.d.ts.map +1 -1
- package/dist/src/pins.js +11 -39
- package/dist/src/pins.js.map +1 -1
- package/dist/src/routing.d.ts +7 -5
- package/dist/src/routing.d.ts.map +1 -1
- package/dist/src/routing.js +10 -4
- package/dist/src/routing.js.map +1 -1
- package/dist/src/utils/constants.d.ts +4 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +4 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/get-codec.d.ts +2 -1
- package/dist/src/utils/get-codec.d.ts.map +1 -1
- package/dist/src/utils/get-codec.js +0 -1
- package/dist/src/utils/get-codec.js.map +1 -1
- package/dist/src/utils/get-crypto.d.ts +4 -0
- package/dist/src/utils/get-crypto.d.ts.map +1 -0
- package/dist/src/utils/get-crypto.js +35 -0
- package/dist/src/utils/get-crypto.js.map +1 -0
- package/dist/src/utils/get-hasher.d.ts +2 -1
- package/dist/src/utils/get-hasher.d.ts.map +1 -1
- package/dist/src/utils/get-hasher.js.map +1 -1
- package/dist/src/utils/is-cid.d.ts +3 -0
- package/dist/src/utils/is-cid.d.ts.map +1 -0
- package/dist/src/utils/is-cid.js +8 -0
- package/dist/src/utils/is-cid.js.map +1 -0
- package/dist/src/utils/networked-storage.d.ts +2 -1
- package/dist/src/utils/networked-storage.d.ts.map +1 -1
- package/dist/src/utils/networked-storage.js.map +1 -1
- package/dist/src/utils/session-storage.d.ts +2 -2
- package/dist/src/utils/session-storage.d.ts.map +1 -1
- package/dist/src/utils/session-storage.js.map +1 -1
- package/package.json +21 -22
- package/src/abstract-session.ts +4 -4
- package/src/errors.ts +5 -0
- package/src/graph-walker.ts +30 -43
- package/src/index.ts +108 -73
- package/src/pins.ts +12 -50
- package/src/routing.ts +23 -10
- package/src/utils/constants.ts +3 -0
- package/src/utils/get-codec.ts +2 -3
- package/src/utils/get-crypto.ts +44 -0
- package/src/utils/get-hasher.ts +2 -1
- package/src/utils/is-cid.ts +9 -0
- package/src/utils/networked-storage.ts +2 -1
- package/src/utils/session-storage.ts +2 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { UnknownCryptoError } from '@helia/interface'
|
|
2
|
+
import { ecdsaCrypto, ed25519Crypto, rsaCrypto } from '@ipshipyard/crypto'
|
|
3
|
+
import { isPromise } from './is-promise.ts'
|
|
4
|
+
import type { CryptoLoader } from '@helia/interface'
|
|
5
|
+
import type { Crypto } from '@ipshipyard/crypto'
|
|
6
|
+
|
|
7
|
+
export function getCrypto (initialCryptos: Array<Crypto> = [], loadCrypto?: CryptoLoader): CryptoLoader {
|
|
8
|
+
const cryptos: Record<string | number, Crypto> = {}
|
|
9
|
+
|
|
10
|
+
initialCryptos = [
|
|
11
|
+
ecdsaCrypto(),
|
|
12
|
+
ed25519Crypto(),
|
|
13
|
+
rsaCrypto(),
|
|
14
|
+
...initialCryptos
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
initialCryptos.forEach(crypto => {
|
|
18
|
+
cryptos[crypto.type] = crypto
|
|
19
|
+
cryptos[crypto.code] = crypto
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return async (nameOrCode) => {
|
|
23
|
+
let crypto = cryptos[nameOrCode]
|
|
24
|
+
|
|
25
|
+
if (crypto == null && loadCrypto != null) {
|
|
26
|
+
const res = loadCrypto(nameOrCode)
|
|
27
|
+
|
|
28
|
+
if (isPromise(res)) {
|
|
29
|
+
crypto = await res
|
|
30
|
+
} else {
|
|
31
|
+
crypto = res
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
cryptos[crypto.type] = crypto
|
|
35
|
+
cryptos[crypto.code] = crypto
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (crypto != null) {
|
|
39
|
+
return crypto
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new UnknownCryptoError(`Could not load crypto for ${crypto}`)
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/utils/get-hasher.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { UnknownHashAlgorithmError } from '@helia/interface'
|
|
|
2
2
|
import { identity } from 'multiformats/hashes/identity'
|
|
3
3
|
import { sha256, sha512 } from 'multiformats/hashes/sha2'
|
|
4
4
|
import { isPromise } from './is-promise.ts'
|
|
5
|
+
import type { HasherLoader } from '@helia/interface'
|
|
5
6
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
6
7
|
|
|
7
|
-
export function getHasher (initialHashers: MultihashHasher[] = [], loadHasher?:
|
|
8
|
+
export function getHasher (initialHashers: MultihashHasher[] = [], loadHasher?: HasherLoader): HasherLoader {
|
|
8
9
|
const hashers: Record<number, MultihashHasher> = {
|
|
9
10
|
[sha256.code]: sha256,
|
|
10
11
|
[sha512.code]: sha512,
|
|
@@ -4,7 +4,8 @@ import { SessionStorage } from './session-storage.ts'
|
|
|
4
4
|
import { Storage } from './storage.ts'
|
|
5
5
|
import type { StorageComponents, StorageInit } from './storage.ts'
|
|
6
6
|
import type { BlockBroker, Blocks, CreateSessionOptions, SessionBlockstore } from '@helia/interface/blocks'
|
|
7
|
-
import type {
|
|
7
|
+
import type { Startable } from '@libp2p/interface'
|
|
8
|
+
import type { AbortOptions } from 'abort-error'
|
|
8
9
|
import type { Blockstore } from 'interface-blockstore'
|
|
9
10
|
import type { CID } from 'multiformats/cid'
|
|
10
11
|
|
|
@@ -3,7 +3,7 @@ import { anySignal } from 'any-signal'
|
|
|
3
3
|
import { Storage } from './storage.ts'
|
|
4
4
|
import type { StorageComponents } from './storage.ts'
|
|
5
5
|
import type { Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, SessionBlockstore, SessionBlockBroker } from '@helia/interface/blocks'
|
|
6
|
-
import type { AbortOptions
|
|
6
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
7
7
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
8
8
|
import type { InputPair } from 'interface-blockstore'
|
|
9
9
|
import type { CID } from 'multiformats/cid'
|
|
@@ -35,7 +35,7 @@ export class SessionStorage extends Storage<SessionBlockBroker> implements Sessi
|
|
|
35
35
|
this.closeController.abort()
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async addPeer (peer:
|
|
38
|
+
async addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void> {
|
|
39
39
|
await Promise.all(
|
|
40
40
|
this.blockBrokers
|
|
41
41
|
.map(broker => broker.addPeer(peer, options))
|