helia 6.1.4 → 7.0.0
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 +65 -55
- package/dist/index.min.js.map +4 -4
- package/dist/src/block-storage.d.ts +62 -0
- package/dist/src/block-storage.d.ts.map +1 -0
- package/dist/src/block-storage.js +159 -0
- package/dist/src/block-storage.js.map +1 -0
- package/dist/src/datastore-version.d.ts +3 -0
- package/dist/src/datastore-version.d.ts.map +1 -0
- package/dist/src/datastore-version.js +20 -0
- package/dist/src/datastore-version.js.map +1 -0
- package/dist/src/get-codec.d.ts +4 -0
- package/dist/src/get-codec.d.ts.map +1 -0
- package/dist/src/get-codec.js +31 -0
- package/dist/src/get-codec.js.map +1 -0
- package/dist/src/get-crypto.d.ts +4 -0
- package/dist/src/get-crypto.d.ts.map +1 -0
- package/dist/src/get-crypto.js +35 -0
- package/dist/src/get-crypto.js.map +1 -0
- package/dist/src/get-hasher.d.ts +4 -0
- package/dist/src/get-hasher.d.ts.map +1 -0
- package/dist/src/get-hasher.js +31 -0
- package/dist/src/get-hasher.js.map +1 -0
- package/dist/src/helia.d.ts +165 -0
- package/dist/src/helia.d.ts.map +1 -0
- package/dist/src/helia.js +165 -0
- package/dist/src/helia.js.map +1 -0
- package/dist/src/index.d.ts +30 -19
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +78 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/networked-storage.d.ts +28 -0
- package/dist/src/networked-storage.d.ts.map +1 -0
- package/dist/src/networked-storage.js +52 -0
- package/dist/src/networked-storage.js.map +1 -0
- package/dist/src/pins.d.ts +21 -0
- package/dist/src/pins.d.ts.map +1 -0
- package/dist/src/pins.js +140 -0
- package/dist/src/pins.js.map +1 -0
- package/dist/src/routing.d.ts +51 -0
- package/dist/src/routing.d.ts.map +1 -0
- package/dist/src/routing.js +311 -0
- package/dist/src/routing.js.map +1 -0
- package/dist/src/session-storage.d.ts +47 -0
- package/dist/src/session-storage.d.ts.map +1 -0
- package/dist/src/session-storage.js +148 -0
- package/dist/src/session-storage.js.map +1 -0
- package/dist/src/storage.d.ts +55 -0
- package/dist/src/storage.d.ts.map +1 -0
- package/dist/src/storage.js +225 -0
- package/dist/src/storage.js.map +1 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/typedoc-urls.json +3 -6
- package/package.json +38 -41
- package/src/block-storage.ts +194 -0
- package/src/datastore-version.ts +25 -0
- package/src/get-codec.ts +39 -0
- package/src/get-crypto.ts +44 -0
- package/src/get-hasher.ts +39 -0
- package/src/helia.ts +364 -0
- package/src/index.ts +58 -30
- package/src/networked-storage.ts +74 -0
- package/src/pins.ts +208 -0
- package/src/routing.ts +389 -0
- package/src/session-storage.ts +174 -0
- package/src/storage.ts +294 -0
- package/src/version.ts +1 -1
- package/dist/src/utils/bootstrappers.d.ts +0 -4
- package/dist/src/utils/bootstrappers.d.ts.map +0 -1
- package/dist/src/utils/bootstrappers.js +0 -13
- package/dist/src/utils/bootstrappers.js.map +0 -1
- package/dist/src/utils/helia-defaults.d.ts +0 -48
- package/dist/src/utils/helia-defaults.d.ts.map +0 -1
- package/dist/src/utils/helia-defaults.js +0 -85
- package/dist/src/utils/helia-defaults.js.map +0 -1
- package/dist/src/utils/libp2p-defaults.browser.d.ts +0 -19
- package/dist/src/utils/libp2p-defaults.browser.d.ts.map +0 -1
- package/dist/src/utils/libp2p-defaults.browser.js +0 -73
- package/dist/src/utils/libp2p-defaults.browser.js.map +0 -1
- package/dist/src/utils/libp2p-defaults.d.ts +0 -49
- package/dist/src/utils/libp2p-defaults.d.ts.map +0 -1
- package/dist/src/utils/libp2p-defaults.js +0 -113
- package/dist/src/utils/libp2p-defaults.js.map +0 -1
- package/dist/src/utils/libp2p.d.ts +0 -19
- package/dist/src/utils/libp2p.d.ts.map +0 -1
- package/dist/src/utils/libp2p.js +0 -19
- package/dist/src/utils/libp2p.js.map +0 -1
- package/src/utils/bootstrappers.ts +0 -12
- package/src/utils/helia-defaults.ts +0 -92
- package/src/utils/libp2p-defaults.browser.ts +0 -92
- package/src/utils/libp2p-defaults.ts +0 -137
- package/src/utils/libp2p.ts +0 -42
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Routing } from '@helia/interface';
|
|
2
|
+
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, SessionBlockstore } from '@helia/interface';
|
|
3
|
+
import type { Pins } from '@helia/interface';
|
|
4
|
+
import type { AbortOptions, Startable } from '@libp2p/interface';
|
|
5
|
+
import type { Blockstore, InputPair } from 'interface-blockstore';
|
|
6
|
+
import type { Mortice } from 'mortice';
|
|
7
|
+
import type { CID } from 'multiformats/cid';
|
|
8
|
+
import type { ProgressOptions } from 'progress-events';
|
|
9
|
+
export interface BlockStorageInit {
|
|
10
|
+
holdGcLock?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface GetOptions extends AbortOptions {
|
|
13
|
+
progress?(evt: Event): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* BlockStorage is a hybrid blockstore that puts/gets blocks from a configured
|
|
17
|
+
* blockstore (that may be on disk, s3, or something else). If the blocks are
|
|
18
|
+
* not present Bitswap will be used to fetch them from network peers.
|
|
19
|
+
*/
|
|
20
|
+
export declare class BlockStorage implements Blocks, Startable {
|
|
21
|
+
lock: Mortice;
|
|
22
|
+
private readonly child;
|
|
23
|
+
private readonly pins;
|
|
24
|
+
private readonly routing;
|
|
25
|
+
private started;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new BlockStorage
|
|
28
|
+
*/
|
|
29
|
+
constructor(blockstore: Blocks, pins: Pins, routing: Routing, options?: BlockStorageInit);
|
|
30
|
+
isStarted(): boolean;
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
unwrap(): Blockstore;
|
|
34
|
+
/**
|
|
35
|
+
* Put a block to the underlying datastore
|
|
36
|
+
*/
|
|
37
|
+
put(cid: CID, block: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>): Promise<CID>;
|
|
38
|
+
/**
|
|
39
|
+
* Put a multiple blocks to the underlying datastore
|
|
40
|
+
*/
|
|
41
|
+
putMany(blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): AsyncGenerator<CID>;
|
|
42
|
+
/**
|
|
43
|
+
* Get a block by cid
|
|
44
|
+
*/
|
|
45
|
+
get(cid: CID, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents>): AsyncGenerator<Uint8Array>;
|
|
46
|
+
/**
|
|
47
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
48
|
+
*/
|
|
49
|
+
getMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>): AsyncGenerator<Pair>;
|
|
50
|
+
/**
|
|
51
|
+
* Delete a block from the blockstore
|
|
52
|
+
*/
|
|
53
|
+
delete(cid: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Delete multiple blocks from the blockstore
|
|
56
|
+
*/
|
|
57
|
+
deleteMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>): AsyncGenerator<CID>;
|
|
58
|
+
has(cid: CID, options?: AbortOptions): Promise<boolean>;
|
|
59
|
+
getAll(options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>): AsyncGenerator<Pair>;
|
|
60
|
+
createSession(root: CID, options?: AbortOptions): SessionBlockstore;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=block-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|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G,OAAO,CAAC,OAAO,CAAC;IAW1D,MAAM,CAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,0BAA0B,CAAM,GAAG,cAAc,CAAC,IAAI,CAAC;IAW/G,aAAa,CAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,iBAAiB;CAIrE"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { BlockPinnedError } from '@helia/utils';
|
|
2
|
+
import { start, stop } from '@libp2p/interface';
|
|
3
|
+
import createMortice from 'mortice';
|
|
4
|
+
/**
|
|
5
|
+
* BlockStorage is a hybrid blockstore that puts/gets blocks from a configured
|
|
6
|
+
* blockstore (that may be on disk, s3, or something else). If the blocks are
|
|
7
|
+
* not present Bitswap will be used to fetch them from network peers.
|
|
8
|
+
*/
|
|
9
|
+
export class BlockStorage {
|
|
10
|
+
lock;
|
|
11
|
+
child;
|
|
12
|
+
pins;
|
|
13
|
+
routing;
|
|
14
|
+
started;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new BlockStorage
|
|
17
|
+
*/
|
|
18
|
+
constructor(blockstore, pins, routing, options = {}) {
|
|
19
|
+
this.child = blockstore;
|
|
20
|
+
this.pins = pins;
|
|
21
|
+
this.routing = routing;
|
|
22
|
+
this.lock = createMortice({
|
|
23
|
+
singleProcess: options.holdGcLock
|
|
24
|
+
});
|
|
25
|
+
this.started = false;
|
|
26
|
+
}
|
|
27
|
+
isStarted() {
|
|
28
|
+
return this.started;
|
|
29
|
+
}
|
|
30
|
+
async start() {
|
|
31
|
+
await start(this.child);
|
|
32
|
+
this.started = true;
|
|
33
|
+
}
|
|
34
|
+
async stop() {
|
|
35
|
+
await stop(this.child);
|
|
36
|
+
this.started = false;
|
|
37
|
+
}
|
|
38
|
+
unwrap() {
|
|
39
|
+
return this.child;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Put a block to the underlying datastore
|
|
43
|
+
*/
|
|
44
|
+
async put(cid, block, options = {}) {
|
|
45
|
+
options?.signal?.throwIfAborted();
|
|
46
|
+
const releaseLock = await this.lock.readLock();
|
|
47
|
+
try {
|
|
48
|
+
return await this.child.put(cid, block, options);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
releaseLock();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Put a multiple blocks to the underlying datastore
|
|
56
|
+
*/
|
|
57
|
+
async *putMany(blocks, options = {}) {
|
|
58
|
+
options?.signal?.throwIfAborted();
|
|
59
|
+
const releaseLock = await this.lock.readLock();
|
|
60
|
+
try {
|
|
61
|
+
yield* this.child.putMany(blocks, options);
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
releaseLock();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get a block by cid
|
|
69
|
+
*/
|
|
70
|
+
async *get(cid, options = {}) {
|
|
71
|
+
options?.signal?.throwIfAborted();
|
|
72
|
+
const releaseLock = await this.lock.readLock();
|
|
73
|
+
try {
|
|
74
|
+
yield* this.child.get(cid, options);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
releaseLock();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
82
|
+
*/
|
|
83
|
+
async *getMany(cids, options = {}) {
|
|
84
|
+
options?.signal?.throwIfAborted();
|
|
85
|
+
const releaseLock = await this.lock.readLock();
|
|
86
|
+
try {
|
|
87
|
+
yield* this.child.getMany(cids, options);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
releaseLock();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Delete a block from the blockstore
|
|
95
|
+
*/
|
|
96
|
+
async delete(cid, options = {}) {
|
|
97
|
+
options?.signal?.throwIfAborted();
|
|
98
|
+
const releaseLock = await this.lock.writeLock();
|
|
99
|
+
try {
|
|
100
|
+
if (await this.pins.isPinned(cid)) {
|
|
101
|
+
throw new BlockPinnedError('Block was pinned - please unpin and try again');
|
|
102
|
+
}
|
|
103
|
+
// stop re-providing this CID if necessary
|
|
104
|
+
await this.routing.cancelReprovide(cid, options);
|
|
105
|
+
await this.child.delete(cid, options);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
releaseLock();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Delete multiple blocks from the blockstore
|
|
113
|
+
*/
|
|
114
|
+
async *deleteMany(cids, options = {}) {
|
|
115
|
+
options?.signal?.throwIfAborted();
|
|
116
|
+
const releaseLock = await this.lock.writeLock();
|
|
117
|
+
try {
|
|
118
|
+
const storage = this;
|
|
119
|
+
yield* this.child.deleteMany((async function* () {
|
|
120
|
+
for await (const cid of cids) {
|
|
121
|
+
if (await storage.pins.isPinned(cid)) {
|
|
122
|
+
throw new BlockPinnedError('Block was pinned - please unpin and try again');
|
|
123
|
+
}
|
|
124
|
+
// stop re-providing this CID if necessary
|
|
125
|
+
await storage.routing.cancelReprovide(cid, options);
|
|
126
|
+
yield cid;
|
|
127
|
+
}
|
|
128
|
+
}()), options);
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
releaseLock();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async has(cid, options = {}) {
|
|
135
|
+
options?.signal?.throwIfAborted();
|
|
136
|
+
const releaseLock = await this.lock.readLock();
|
|
137
|
+
try {
|
|
138
|
+
return await this.child.has(cid, options);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
releaseLock();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async *getAll(options = {}) {
|
|
145
|
+
options?.signal?.throwIfAborted();
|
|
146
|
+
const releaseLock = await this.lock.readLock();
|
|
147
|
+
try {
|
|
148
|
+
yield* this.child.getAll(options);
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
releaseLock();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
createSession(root, options) {
|
|
155
|
+
options?.signal?.throwIfAborted();
|
|
156
|
+
return this.child.createSession(root, options);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=block-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-storage.js","sourceRoot":"","sources":["../../src/block-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,aAAa,MAAM,SAAS,CAAA;AAkBnC;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAChB,IAAI,CAAS;IACH,KAAK,CAAQ;IACb,IAAI,CAAM;IACV,OAAO,CAAS;IACzB,OAAO,CAAS;IAExB;;OAEG;IACH,YAAa,UAAkB,EAAE,IAAU,EAAE,OAAgB,EAAE,UAA4B,EAAE;QAC3F,IAAI,CAAC,KAAK,GAAG,UAAU,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;YACxB,aAAa,EAAE,OAAO,CAAC,UAAU;SAClC,CAAC,CAAA;QACF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;IACtB,CAAC;IAED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EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datastore-version.d.ts","sourceRoot":"","sources":["../../src/datastore-version.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAKpD,wBAAsB,+BAA+B,CAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAe1F"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InvalidDatastoreVersionError } from '@helia/utils';
|
|
2
|
+
import { Key } from 'interface-datastore';
|
|
3
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
4
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
5
|
+
const DS_VERSION_KEY = new Key('/version');
|
|
6
|
+
const CURRENT_VERSION = 1;
|
|
7
|
+
export async function assertDatastoreVersionIsCurrent(datastore) {
|
|
8
|
+
if (!(await datastore.has(DS_VERSION_KEY))) {
|
|
9
|
+
await datastore.put(DS_VERSION_KEY, uint8ArrayFromString(`${CURRENT_VERSION}`));
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const buf = await datastore.get(DS_VERSION_KEY);
|
|
13
|
+
const str = uint8ArrayToString(buf);
|
|
14
|
+
const version = parseInt(str, 10);
|
|
15
|
+
if (version !== CURRENT_VERSION) {
|
|
16
|
+
// TODO: write migrations when we break compatibility - for an example, see https://github.com/ipfs/js-ipfs-repo/tree/master/packages/ipfs-repo-migrations
|
|
17
|
+
throw new InvalidDatastoreVersionError('Invalid datastore version, a datastore migration may be required');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=datastore-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datastore-version.js","sourceRoot":"","sources":["../../src/datastore-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGtE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAA;AAC1C,MAAM,eAAe,GAAG,CAAC,CAAA;AAEzB,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAE,SAAoB;IACzE,IAAI,CAAC,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC;QAC3C,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,oBAAoB,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CAAA;QAE/E,OAAM;IACR,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAC/C,MAAM,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IAEjC,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;QAChC,0JAA0J;QAC1J,MAAM,IAAI,4BAA4B,CAAC,kEAAkE,CAAC,CAAA;IAC5G,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CodecLoader } from '@helia/interface';
|
|
2
|
+
import type { BlockCodec } from 'multiformats/codecs/interface';
|
|
3
|
+
export declare function getCodec(initialCodecs?: Array<BlockCodec<any, any>>, loadCodec?: CodecLoader): CodecLoader;
|
|
4
|
+
//# sourceMappingURL=get-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-codec.d.ts","sourceRoot":"","sources":["../../src/get-codec.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/D,wBAAgB,QAAQ,CAAE,aAAa,GAAE,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAM,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,WAAW,CA+B/G"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UnknownCodecError } from '@helia/interface';
|
|
2
|
+
import { isPromise } from '@helia/utils';
|
|
3
|
+
import * as dagPb from '@ipld/dag-pb';
|
|
4
|
+
import * as raw from 'multiformats/codecs/raw';
|
|
5
|
+
export function getCodec(initialCodecs = [], loadCodec) {
|
|
6
|
+
const codecs = {
|
|
7
|
+
[dagPb.code]: dagPb,
|
|
8
|
+
[raw.code]: raw
|
|
9
|
+
};
|
|
10
|
+
initialCodecs.forEach(codec => {
|
|
11
|
+
codecs[codec.code] = codec;
|
|
12
|
+
});
|
|
13
|
+
return async (code) => {
|
|
14
|
+
let codec = codecs[code];
|
|
15
|
+
if (codec == null && loadCodec != null) {
|
|
16
|
+
const res = loadCodec(code);
|
|
17
|
+
if (isPromise(res)) {
|
|
18
|
+
codec = await res;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
codec = res;
|
|
22
|
+
}
|
|
23
|
+
codecs[codec.code] = codec;
|
|
24
|
+
}
|
|
25
|
+
if (codec != null) {
|
|
26
|
+
return codec;
|
|
27
|
+
}
|
|
28
|
+
throw new UnknownCodecError(`Could not load codec for ${code}`);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=get-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-codec.js","sourceRoot":"","sources":["../../src/get-codec.ts"],"names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"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,wBAAgB,SAAS,CAAE,cAAc,GAAE,KAAK,CAAC,MAAM,CAAM,EAAE,UAAU,CAAC,EAAE,YAAY,GAAG,YAAY,CAqCtG"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UnknownCryptoError } from '@helia/interface';
|
|
2
|
+
import { isPromise } from '@helia/utils';
|
|
3
|
+
import { ecdsaCrypto, ed25519Crypto, rsaCrypto } from '@ipshipyard/crypto';
|
|
4
|
+
export function getCrypto(initialCryptos = [], loadCrypto) {
|
|
5
|
+
const cryptos = {};
|
|
6
|
+
initialCryptos = [
|
|
7
|
+
ecdsaCrypto(),
|
|
8
|
+
ed25519Crypto(),
|
|
9
|
+
rsaCrypto(),
|
|
10
|
+
...initialCryptos
|
|
11
|
+
];
|
|
12
|
+
initialCryptos.forEach(crypto => {
|
|
13
|
+
cryptos[crypto.type] = crypto;
|
|
14
|
+
cryptos[crypto.code] = crypto;
|
|
15
|
+
});
|
|
16
|
+
return async (nameOrCode) => {
|
|
17
|
+
let crypto = cryptos[nameOrCode];
|
|
18
|
+
if (crypto == null && loadCrypto != null) {
|
|
19
|
+
const res = loadCrypto(nameOrCode);
|
|
20
|
+
if (isPromise(res)) {
|
|
21
|
+
crypto = await res;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
crypto = res;
|
|
25
|
+
}
|
|
26
|
+
cryptos[crypto.type] = crypto;
|
|
27
|
+
cryptos[crypto.code] = crypto;
|
|
28
|
+
}
|
|
29
|
+
if (crypto != null) {
|
|
30
|
+
return crypto;
|
|
31
|
+
}
|
|
32
|
+
throw new UnknownCryptoError(`Could not load crypto for ${crypto}`);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=get-crypto.js.map
|
|
@@ -0,0 +1 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AED,MAAM,IAAI,kBAAkB,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAA;IACrE,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HasherLoader } from '@helia/interface';
|
|
2
|
+
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
3
|
+
export declare function getHasher(initialHashers?: MultihashHasher[], loadHasher?: HasherLoader): HasherLoader;
|
|
4
|
+
//# sourceMappingURL=get-hasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hasher.d.ts","sourceRoot":"","sources":["../../src/get-hasher.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE,wBAAgB,SAAS,CAAE,cAAc,GAAE,eAAe,EAAO,EAAE,UAAU,CAAC,EAAE,YAAY,GAAG,YAAY,CA+B1G"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UnknownHashAlgorithmError } from '@helia/interface';
|
|
2
|
+
import { isPromise } from '@helia/utils';
|
|
3
|
+
import { identity } from 'multiformats/hashes/identity';
|
|
4
|
+
import { sha256 } from 'multiformats/hashes/sha2';
|
|
5
|
+
export function getHasher(initialHashers = [], loadHasher) {
|
|
6
|
+
const hashers = {
|
|
7
|
+
[sha256.code]: sha256,
|
|
8
|
+
[identity.code]: identity
|
|
9
|
+
};
|
|
10
|
+
initialHashers.forEach(hasher => {
|
|
11
|
+
hashers[hasher.code] = hasher;
|
|
12
|
+
});
|
|
13
|
+
return async (code) => {
|
|
14
|
+
let hasher = hashers[code];
|
|
15
|
+
if (hasher == null && loadHasher != null) {
|
|
16
|
+
const res = loadHasher(code);
|
|
17
|
+
if (isPromise(res)) {
|
|
18
|
+
hasher = await res;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
hasher = res;
|
|
22
|
+
}
|
|
23
|
+
hashers[hasher.code] = hasher;
|
|
24
|
+
}
|
|
25
|
+
if (hasher != null) {
|
|
26
|
+
return hasher;
|
|
27
|
+
}
|
|
28
|
+
throw new UnknownHashAlgorithmError(`No hasher configured for multihash code 0x${code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=get-hasher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hasher.js","sourceRoot":"","sources":["../../src/get-hasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAIjD,MAAM,UAAU,SAAS,CAAE,iBAAoC,EAAE,EAAE,UAAyB;IAC1F,MAAM,OAAO,GAAoC;QAC/C,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM;QACrB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ;KAC1B,CAAA;IAED,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC9B,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,IAAI,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QAE1B,IAAI,MAAM,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACzC,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;YAE5B,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;gBACnB,MAAM,GAAG,MAAM,GAAG,CAAA;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,GAAG,CAAA;YACd,CAAC;YAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAA;QAC/B,CAAC;QAED,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,OAAO,MAAM,CAAA;QACf,CAAC;QAED,MAAM,IAAI,yBAAyB,CAAC,6CAA6C,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,gIAAgI,CAAC,CAAA;IACrO,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* This module contains utility code that is shared between various Helia
|
|
5
|
+
* modules such as `helia`, `@helia/http`, etc.
|
|
6
|
+
*/
|
|
7
|
+
import { TypedEventEmitter } from 'main-event';
|
|
8
|
+
import { BlockStorage } from './block-storage.ts';
|
|
9
|
+
import { Routing as RoutingClass } from './routing.ts';
|
|
10
|
+
import type { BlockStorageInit } from './block-storage.ts';
|
|
11
|
+
import type { CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, HeliaEvents, CryptoLoader, Crypto, NodeInfo, Router, HeliaMixin } from '@helia/interface';
|
|
12
|
+
import type { BlockBroker } from '@helia/interface';
|
|
13
|
+
import type { Pins } from '@helia/interface';
|
|
14
|
+
import type { Keychain, KeychainInit } from '@ipshipyard/keychain';
|
|
15
|
+
import type { ComponentLogger, Metrics } from '@libp2p/interface';
|
|
16
|
+
import type { DNS } from '@multiformats/dns';
|
|
17
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
18
|
+
import type { Datastore } from 'interface-datastore';
|
|
19
|
+
import type { BlockCodec } from 'multiformats';
|
|
20
|
+
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
21
|
+
export type { BlockStorage, BlockStorageInit };
|
|
22
|
+
/**
|
|
23
|
+
* Options used to create a Helia node.
|
|
24
|
+
*/
|
|
25
|
+
export interface HeliaInit {
|
|
26
|
+
/**
|
|
27
|
+
* By default Helia stores the node's PeerId in an encrypted form in a
|
|
28
|
+
* libp2p keystore. These options control how that keystore is configured.
|
|
29
|
+
*/
|
|
30
|
+
keychain?: KeychainInit;
|
|
31
|
+
/**
|
|
32
|
+
* The blockstore is where blocks are stored
|
|
33
|
+
*/
|
|
34
|
+
blockstore?: Blockstore;
|
|
35
|
+
/**
|
|
36
|
+
* The datastore is where data is stored
|
|
37
|
+
*/
|
|
38
|
+
datastore?: Datastore;
|
|
39
|
+
/**
|
|
40
|
+
* By default sha256, sha512 and identity hashes are supported for
|
|
41
|
+
* bitswap operations. To bitswap blocks with CIDs using other hashes
|
|
42
|
+
* pass appropriate MultihashHashers here.
|
|
43
|
+
*/
|
|
44
|
+
hashers?: MultihashHasher[];
|
|
45
|
+
/**
|
|
46
|
+
* An optional function that can load a MultihashHasher on demand. May return
|
|
47
|
+
* a promise.
|
|
48
|
+
*/
|
|
49
|
+
loadHasher?(code: number): MultihashHasher | Promise<MultihashHasher>;
|
|
50
|
+
/**
|
|
51
|
+
* A BlockCodec allows converting a block to an object representation
|
|
52
|
+
*/
|
|
53
|
+
codecs?: Array<BlockCodec<any, any>>;
|
|
54
|
+
/**
|
|
55
|
+
* An optional function that can load a BlockCodec on demand. May return a
|
|
56
|
+
* promise.
|
|
57
|
+
*/
|
|
58
|
+
loadCodec?(code: number): BlockCodec<any, any> | Promise<BlockCodec<any, any>>;
|
|
59
|
+
/**
|
|
60
|
+
* A list of pre-supported public/private key implementations
|
|
61
|
+
*/
|
|
62
|
+
cryptos?: Array<Crypto>;
|
|
63
|
+
/**
|
|
64
|
+
* Dynamically load a cryptography implementation
|
|
65
|
+
*/
|
|
66
|
+
loadCrypto?: CryptoLoader;
|
|
67
|
+
/**
|
|
68
|
+
* Garbage collection requires preventing blockstore writes during searches
|
|
69
|
+
* for unpinned blocks as DAGs are typically pinned after they've been
|
|
70
|
+
* imported - without locking this could lead to the deletion of blocks while
|
|
71
|
+
* they are being added to the blockstore.
|
|
72
|
+
*
|
|
73
|
+
* By default this lock is held on the current process and other processes
|
|
74
|
+
* will contact this process for access.
|
|
75
|
+
*
|
|
76
|
+
* If Helia is being run in multiple processes, one process must hold the GC
|
|
77
|
+
* lock so use this option to control which process that is.
|
|
78
|
+
*
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
holdGcLock?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* An optional logging component to pass to libp2p. If not specified the
|
|
84
|
+
* default implementation from libp2p will be used.
|
|
85
|
+
*/
|
|
86
|
+
logger?: ComponentLogger;
|
|
87
|
+
/**
|
|
88
|
+
* A list of strategies used to fetch blocks when they are not present in
|
|
89
|
+
* the local blockstore
|
|
90
|
+
*/
|
|
91
|
+
blockBrokers?: Array<BlockBroker | ((components: any) => BlockBroker)>;
|
|
92
|
+
/**
|
|
93
|
+
* Routers perform operations such as looking up content providers,
|
|
94
|
+
* information about network peers or getting/putting records.
|
|
95
|
+
*/
|
|
96
|
+
routers?: Array<Router | ((components: any) => Router)>;
|
|
97
|
+
/**
|
|
98
|
+
* During provider lookups, peers can be returned from routing implementations
|
|
99
|
+
* with no multiaddrs.
|
|
100
|
+
*
|
|
101
|
+
* This can happen when they've been retrieved from network peers that only
|
|
102
|
+
* store multiaddrs for a limited amount of time.
|
|
103
|
+
*
|
|
104
|
+
* When this happens the peer's info has to be looked up with a further query.
|
|
105
|
+
*
|
|
106
|
+
* To not have this query block the yielding of other providers returned with
|
|
107
|
+
* multiaddrs, a separate queue is used to perform this lookup.
|
|
108
|
+
*
|
|
109
|
+
* This config value controls the concurrency of that queue.
|
|
110
|
+
*
|
|
111
|
+
* @default 5
|
|
112
|
+
*/
|
|
113
|
+
providerLookupConcurrency?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Components used by subclasses
|
|
116
|
+
*/
|
|
117
|
+
components?: Record<string, any>;
|
|
118
|
+
/**
|
|
119
|
+
* An optional DNS implementation used to perform queries for DNS records.
|
|
120
|
+
*/
|
|
121
|
+
dns?: DNS;
|
|
122
|
+
/**
|
|
123
|
+
* A metrics object that can be used to collected arbitrary stats about node
|
|
124
|
+
* usage.
|
|
125
|
+
*/
|
|
126
|
+
metrics?: Metrics;
|
|
127
|
+
/**
|
|
128
|
+
* Limit the maximum supported size of identity hash digests to this value
|
|
129
|
+
*
|
|
130
|
+
* @default 128
|
|
131
|
+
*/
|
|
132
|
+
maxIdentityHashDigestLength?: number;
|
|
133
|
+
}
|
|
134
|
+
export declare class Helia implements HeliaInterface {
|
|
135
|
+
info: NodeInfo;
|
|
136
|
+
blockstore: BlockStorage;
|
|
137
|
+
datastore: Datastore;
|
|
138
|
+
events: TypedEventEmitter<HeliaEvents<this>>;
|
|
139
|
+
pins: Pins;
|
|
140
|
+
logger: ComponentLogger;
|
|
141
|
+
routing: RoutingClass;
|
|
142
|
+
getCodec: CodecLoader;
|
|
143
|
+
getHasher: HasherLoader;
|
|
144
|
+
getCrypto: CryptoLoader;
|
|
145
|
+
dns: DNS;
|
|
146
|
+
keychain: Keychain;
|
|
147
|
+
metrics?: Metrics;
|
|
148
|
+
status: 'stopped' | 'stopping' | 'starting' | 'started';
|
|
149
|
+
private readonly log;
|
|
150
|
+
private readonly blockBrokers;
|
|
151
|
+
private readonly mixins;
|
|
152
|
+
constructor(init: HeliaInit & {
|
|
153
|
+
name: string;
|
|
154
|
+
version: string;
|
|
155
|
+
});
|
|
156
|
+
hasRouter(name: string): boolean;
|
|
157
|
+
addRouter(router: Router): void;
|
|
158
|
+
hasBlockBroker(name: string): boolean;
|
|
159
|
+
addBlockBroker(blockBroker: BlockBroker): void;
|
|
160
|
+
addMixin(mixin: HeliaMixin): void;
|
|
161
|
+
start(): Promise<this>;
|
|
162
|
+
stop(): Promise<this>;
|
|
163
|
+
gc(options?: GCOptions): Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=helia.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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