@helia/routers 1.1.1 → 2.0.0-1b2934b
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 +12 -13
- package/dist/src/delegated-http-routing.d.ts.map +1 -1
- package/dist/src/delegated-http-routing.js +16 -13
- package/dist/src/delegated-http-routing.js.map +1 -1
- package/dist/src/http-gateway-routing.d.ts.map +1 -1
- package/dist/src/http-gateway-routing.js +3 -38
- package/dist/src/http-gateway-routing.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +8 -7
- package/src/delegated-http-routing.ts +17 -14
- package/src/http-gateway-routing.ts +5 -50
- package/src/index.ts +1 -0
- package/dist/typedoc-urls.json +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegated-http-routing.d.ts","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delegated-http-routing.d.ts","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AAoFzE;;GAEG;AACH,wBAAgB,oBAAoB,CAAE,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAEhE"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { NotFoundError } from '@libp2p/interface';
|
|
3
|
+
import { marshalIPNSRecord, multihashFromIPNSRoutingKey, unmarshalIPNSRecord } from 'ipns';
|
|
4
4
|
import first from 'it-first';
|
|
5
5
|
import map from 'it-map';
|
|
6
|
+
import { CID } from 'multiformats/cid';
|
|
6
7
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
7
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
8
9
|
const IPNS_PREFIX = uint8ArrayFromString('/ipns/');
|
|
@@ -30,24 +31,26 @@ class DelegatedHTTPRouter {
|
|
|
30
31
|
if (!isIPNSKey(key)) {
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const digest = multihashFromIPNSRoutingKey(key);
|
|
35
|
+
const cid = CID.createV1(0x72, digest);
|
|
36
|
+
const record = unmarshalIPNSRecord(value);
|
|
37
|
+
await this.client.putIPNS(cid, record, options);
|
|
36
38
|
}
|
|
37
39
|
async get(key, options) {
|
|
38
40
|
if (!isIPNSKey(key)) {
|
|
39
|
-
throw new
|
|
41
|
+
throw new NotFoundError('Not found');
|
|
40
42
|
}
|
|
41
|
-
const
|
|
43
|
+
const digest = multihashFromIPNSRoutingKey(key);
|
|
44
|
+
const cid = CID.createV1(0x72, digest);
|
|
42
45
|
try {
|
|
43
|
-
const record = await this.client.getIPNS(
|
|
44
|
-
return
|
|
46
|
+
const record = await this.client.getIPNS(cid, options);
|
|
47
|
+
return marshalIPNSRecord(record);
|
|
45
48
|
}
|
|
46
49
|
catch (err) {
|
|
47
|
-
//
|
|
50
|
+
// BadResponseError is thrown when the response had no body, which means
|
|
48
51
|
// the record couldn't be found
|
|
49
|
-
if (err.
|
|
50
|
-
throw new
|
|
52
|
+
if (err.name === 'BadResponseError') {
|
|
53
|
+
throw new NotFoundError('Not found');
|
|
51
54
|
}
|
|
52
55
|
throw err;
|
|
53
56
|
}
|
|
@@ -60,7 +63,7 @@ class DelegatedHTTPRouter {
|
|
|
60
63
|
multiaddrs: peer.Addrs ?? []
|
|
61
64
|
};
|
|
62
65
|
}
|
|
63
|
-
throw new
|
|
66
|
+
throw new NotFoundError('Not found');
|
|
64
67
|
}
|
|
65
68
|
async *getClosestPeers(key, options) {
|
|
66
69
|
// noop
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegated-http-routing.js","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAA;AACnG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"delegated-http-routing.js","sourceRoot":"","sources":["../../src/delegated-http-routing.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-gateway-routing.d.ts","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-gateway-routing.d.ts","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AAIzE,eAAO,MAAM,0BAA0B,UAMtC,CAAA;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,CAAA;CAC/B;AA+BD;;GAEG;AACH,wBAAgB,kBAAkB,CAAE,IAAI,GAAE,oBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC,CAErF"}
|
|
@@ -1,55 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
2
2
|
import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr';
|
|
3
3
|
import { CID } from 'multiformats/cid';
|
|
4
4
|
import { identity } from 'multiformats/hashes/identity';
|
|
5
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
6
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
7
6
|
export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
8
7
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
9
8
|
'https://trustless-gateway.link',
|
|
10
9
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
11
10
|
'https://4everland.io'
|
|
12
11
|
];
|
|
13
|
-
//
|
|
12
|
+
// this value is from https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
14
13
|
const TRANSPORT_IPFS_GATEWAY_HTTP_CODE = 0x0920;
|
|
15
|
-
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
16
|
-
class URLPeerId {
|
|
17
|
-
type = 'url';
|
|
18
|
-
multihash;
|
|
19
|
-
privateKey;
|
|
20
|
-
publicKey;
|
|
21
|
-
url;
|
|
22
|
-
constructor(url) {
|
|
23
|
-
this.url = url.toString();
|
|
24
|
-
this.multihash = identity.digest(uint8ArrayFromString(this.url));
|
|
25
|
-
}
|
|
26
|
-
[inspect]() {
|
|
27
|
-
return `PeerId(${this.url})`;
|
|
28
|
-
}
|
|
29
|
-
[peerIdSymbol] = true;
|
|
30
|
-
toString() {
|
|
31
|
-
return this.toCID().toString();
|
|
32
|
-
}
|
|
33
|
-
toCID() {
|
|
34
|
-
return CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, this.multihash);
|
|
35
|
-
}
|
|
36
|
-
toBytes() {
|
|
37
|
-
return this.toCID().bytes;
|
|
38
|
-
}
|
|
39
|
-
equals(other) {
|
|
40
|
-
if (other == null) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (other instanceof Uint8Array) {
|
|
44
|
-
other = uint8ArrayToString(other);
|
|
45
|
-
}
|
|
46
|
-
return other.toString() === this.toString();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
14
|
function toPeerInfo(url) {
|
|
50
15
|
url = url.toString();
|
|
51
16
|
return {
|
|
52
|
-
id:
|
|
17
|
+
id: peerIdFromCID(CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, identity.digest(uint8ArrayFromString(url)))),
|
|
53
18
|
multiaddrs: [
|
|
54
19
|
uriToMultiaddr(url)
|
|
55
20
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-gateway-routing.js","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"http-gateway-routing.js","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAK5E,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,wGAAwG;IACxG,gCAAgC;IAEhC,wGAAwG;IACxG,sBAAsB;CACvB,CAAA;AAMD,sFAAsF;AACtF,MAAM,gCAAgC,GAAG,MAAM,CAAA;AAE/C,SAAS,UAAU,CAAE,GAAiB;IACpC,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA;IAEpB,OAAO;QACL,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,gCAAgC,EAAE,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7G,UAAU,EAAE;YACV,cAAc,CAAC,GAAG,CAAC;SACpB;KACF,CAAA;AACH,CAAC;AAED,MAAM,gBAAgB;IACH,QAAQ,CAAY;IAErC,YAAa,OAA6B,EAAE;QAC1C,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,0BAA0B,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;IAC3F,CAAC;IAED,KAAK,CAAC,CAAE,aAAa,CAAE,GAA0C,EAAE,OAAoC;QACrG,KAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9E,GAAG,IAAI;YACP,SAAS,EAAE,CAAC,6BAA6B,CAAC;SAC3C,CAAC,CAAC,CAAA;IACL,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAE,OAA6B,EAAE;IACjE,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { delegatedHTTPRouting } from './delegated-http-routing.js';
|
|
7
7
|
export { httpGatewayRouting } from './http-gateway-routing.js';
|
|
8
|
+
export type { HTTPGatwayRouterInit } from './http-gateway-routing.js';
|
|
8
9
|
export { libp2pRouting } from './libp2p-routing.js';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/routers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-1b2934b",
|
|
4
4
|
"description": "Routers for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/routers#readme",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"clean": "aegir clean",
|
|
44
44
|
"lint": "aegir lint",
|
|
45
45
|
"dep-check": "aegir dep-check",
|
|
46
|
+
"doc-check": "aegir doc-check",
|
|
46
47
|
"build": "aegir build",
|
|
47
48
|
"test": "aegir test",
|
|
48
49
|
"test:chrome": "aegir test -t browser --cov",
|
|
@@ -53,19 +54,19 @@
|
|
|
53
54
|
"test:electron-main": "aegir test -t electron-main"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@helia/delegated-routing-v1-http-api-client": "^
|
|
57
|
-
"@helia/interface": "
|
|
58
|
-
"@libp2p/
|
|
57
|
+
"@helia/delegated-routing-v1-http-api-client": "^4.0.0",
|
|
58
|
+
"@helia/interface": "5.0.0-1b2934b",
|
|
59
|
+
"@libp2p/peer-id": "^5.0.0",
|
|
60
|
+
"@libp2p/interface": "^2.0.0",
|
|
59
61
|
"@multiformats/uri-to-multiaddr": "^8.0.0",
|
|
60
|
-
"ipns": "^
|
|
62
|
+
"ipns": "^10.0.0",
|
|
61
63
|
"it-first": "^3.0.4",
|
|
62
64
|
"it-map": "^3.0.5",
|
|
63
65
|
"multiformats": "^13.1.0",
|
|
64
66
|
"uint8arrays": "^5.0.2"
|
|
65
67
|
},
|
|
66
68
|
"devDependencies": {
|
|
67
|
-
"@libp2p/
|
|
68
|
-
"@libp2p/peer-id-factory": "^4.0.7",
|
|
69
|
+
"@libp2p/crypto": "^5.0.0",
|
|
69
70
|
"aegir": "^44.0.1",
|
|
70
71
|
"it-all": "^3.0.4",
|
|
71
72
|
"it-drain": "^3.0.5",
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { NotFoundError } from '@libp2p/interface'
|
|
3
|
+
import { marshalIPNSRecord, multihashFromIPNSRoutingKey, unmarshalIPNSRecord } from 'ipns'
|
|
4
4
|
import first from 'it-first'
|
|
5
5
|
import map from 'it-map'
|
|
6
|
+
import { CID } from 'multiformats/cid'
|
|
6
7
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
7
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
8
9
|
import type { DelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
|
|
9
10
|
import type { Provider, Routing, RoutingOptions } from '@helia/interface'
|
|
10
11
|
import type { PeerId, PeerInfo } from '@libp2p/interface'
|
|
11
|
-
import type {
|
|
12
|
+
import type { Version } from 'multiformats'
|
|
12
13
|
|
|
13
14
|
const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
|
|
14
15
|
|
|
@@ -42,28 +43,30 @@ class DelegatedHTTPRouter implements Routing {
|
|
|
42
43
|
return
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
-
const
|
|
46
|
+
const digest = multihashFromIPNSRoutingKey(key)
|
|
47
|
+
const cid = CID.createV1(0x72, digest)
|
|
48
|
+
const record = unmarshalIPNSRecord(value)
|
|
47
49
|
|
|
48
|
-
await this.client.putIPNS(
|
|
50
|
+
await this.client.putIPNS(cid, record, options)
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
async get (key: Uint8Array, options?: RoutingOptions | undefined): Promise<Uint8Array> {
|
|
52
54
|
if (!isIPNSKey(key)) {
|
|
53
|
-
throw new
|
|
55
|
+
throw new NotFoundError('Not found')
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
const
|
|
58
|
+
const digest = multihashFromIPNSRoutingKey(key)
|
|
59
|
+
const cid = CID.createV1(0x72, digest)
|
|
57
60
|
|
|
58
61
|
try {
|
|
59
|
-
const record = await this.client.getIPNS(
|
|
62
|
+
const record = await this.client.getIPNS(cid, options)
|
|
60
63
|
|
|
61
|
-
return
|
|
64
|
+
return marshalIPNSRecord(record)
|
|
62
65
|
} catch (err: any) {
|
|
63
|
-
//
|
|
66
|
+
// BadResponseError is thrown when the response had no body, which means
|
|
64
67
|
// the record couldn't be found
|
|
65
|
-
if (err.
|
|
66
|
-
throw new
|
|
68
|
+
if (err.name === 'BadResponseError') {
|
|
69
|
+
throw new NotFoundError('Not found')
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
throw err
|
|
@@ -80,7 +83,7 @@ class DelegatedHTTPRouter implements Routing {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
throw new
|
|
86
|
+
throw new NotFoundError('Not found')
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
async * getClosestPeers (key: Uint8Array, options?: RoutingOptions | undefined): AsyncIterable<PeerInfo> {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
2
2
|
import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr'
|
|
3
3
|
import { CID } from 'multiformats/cid'
|
|
4
4
|
import { identity } from 'multiformats/hashes/identity'
|
|
5
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
7
6
|
import type { Provider, Routing, RoutingOptions } from '@helia/interface'
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interface'
|
|
8
|
+
import type { Version } from 'multiformats'
|
|
10
9
|
|
|
11
10
|
export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
12
11
|
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/
|
|
@@ -20,58 +19,14 @@ export interface HTTPGatwayRouterInit {
|
|
|
20
19
|
gateways?: Array<URL | string>
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
//
|
|
22
|
+
// this value is from https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
24
23
|
const TRANSPORT_IPFS_GATEWAY_HTTP_CODE = 0x0920
|
|
25
|
-
const inspect = Symbol.for('nodejs.util.inspect.custom')
|
|
26
|
-
|
|
27
|
-
class URLPeerId implements PeerId {
|
|
28
|
-
readonly type = 'url'
|
|
29
|
-
readonly multihash: MultihashDigest
|
|
30
|
-
readonly privateKey?: Uint8Array
|
|
31
|
-
readonly publicKey?: Uint8Array
|
|
32
|
-
readonly url: string
|
|
33
|
-
|
|
34
|
-
constructor (url: URL) {
|
|
35
|
-
this.url = url.toString()
|
|
36
|
-
this.multihash = identity.digest(uint8ArrayFromString(this.url))
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
[inspect] (): string {
|
|
40
|
-
return `PeerId(${this.url})`
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
readonly [peerIdSymbol] = true
|
|
44
|
-
|
|
45
|
-
toString (): string {
|
|
46
|
-
return this.toCID().toString()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
toCID (): CID {
|
|
50
|
-
return CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, this.multihash)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
toBytes (): Uint8Array {
|
|
54
|
-
return this.toCID().bytes
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
equals (other?: PeerId | Uint8Array | string): boolean {
|
|
58
|
-
if (other == null) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (other instanceof Uint8Array) {
|
|
63
|
-
other = uint8ArrayToString(other)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return other.toString() === this.toString()
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
24
|
|
|
70
25
|
function toPeerInfo (url: string | URL): PeerInfo {
|
|
71
26
|
url = url.toString()
|
|
72
27
|
|
|
73
28
|
return {
|
|
74
|
-
id:
|
|
29
|
+
id: peerIdFromCID(CID.createV1(TRANSPORT_IPFS_GATEWAY_HTTP_CODE, identity.digest(uint8ArrayFromString(url)))),
|
|
75
30
|
multiaddrs: [
|
|
76
31
|
uriToMultiaddr(url)
|
|
77
32
|
]
|
package/src/index.ts
CHANGED
package/dist/typedoc-urls.json
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"delegatedHTTPRouting": "https://ipfs.github.io/helia/functions/_helia_routers.delegatedHTTPRouting.html",
|
|
3
|
-
"httpGatewayRouting": "https://ipfs.github.io/helia/functions/_helia_routers.httpGatewayRouting.html",
|
|
4
|
-
"libp2pRouting": "https://ipfs.github.io/helia/functions/_helia_routers.libp2pRouting.html"
|
|
5
|
-
}
|