@helia/verified-fetch 7.2.16 → 8.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/README.md +8 -12
- package/dist/index.min.js +70 -59
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +18 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -34
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js +20 -6
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/plugins/plugin-handle-unixfs.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-unixfs.js +7 -4
- package/dist/src/plugins/plugin-handle-unixfs.js.map +1 -1
- package/dist/src/url-resolver.d.ts.map +1 -1
- package/dist/src/url-resolver.js +27 -9
- package/dist/src/url-resolver.js.map +1 -1
- package/dist/src/utils/convert-output.d.ts +2 -2
- package/dist/src/utils/convert-output.d.ts.map +1 -1
- package/dist/src/utils/convert-output.js +11 -5
- package/dist/src/utils/convert-output.js.map +1 -1
- package/dist/src/utils/ipfs-path-to-cid.d.ts +6 -0
- package/dist/src/utils/ipfs-path-to-cid.d.ts.map +1 -0
- package/dist/src/utils/ipfs-path-to-cid.js +9 -0
- package/dist/src/utils/ipfs-path-to-cid.js.map +1 -0
- package/dist/src/utils/libp2p-defaults.browser.js +1 -1
- package/dist/src/utils/libp2p-defaults.browser.js.map +1 -1
- package/dist/src/utils/libp2p-defaults.d.ts.map +1 -1
- package/dist/src/utils/libp2p-defaults.js +2 -10
- package/dist/src/utils/libp2p-defaults.js.map +1 -1
- package/package.json +28 -31
- package/src/index.ts +53 -40
- package/src/plugins/plugin-handle-ipns-record.ts +25 -6
- package/src/plugins/plugin-handle-unixfs.ts +7 -4
- package/src/url-resolver.ts +35 -9
- package/src/utils/convert-output.ts +13 -7
- package/src/utils/ipfs-path-to-cid.ts +9 -0
- package/src/utils/libp2p-defaults.browser.ts +2 -2
- package/src/utils/libp2p-defaults.ts +3 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-output.js","sourceRoot":"","sources":["../../../src/utils/convert-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAA;AAChD,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,eAAe,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAI/K,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"convert-output.js","sourceRoot":"","sources":["../../../src/utils/convert-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAA;AAChD,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,eAAe,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,oBAAoB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EAAE,KAAK;SACd,CAAA;IACH,CAAC;IAED,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;QAEvE,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,OAAO;gBACL,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC;aACzB,CAAA;QACH,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,cAAc,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC9G,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfs-path-to-cid.d.ts","sourceRoot":"","sources":["../../../src/utils/ipfs-path-to-cid.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAE,IAAI,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAQvF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfs-path-to-cid.js","sourceRoot":"","sources":["../../../src/utils/ipfs-path-to-cid.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAE,IAAY;IACzC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAEpD,OAAO;QACL,EAAE;QACF,IAAI;QACJ,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;KACjD,CAAA;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { libp2pDefaults } from '@helia/libp2p';
|
|
1
2
|
import { webRTCDirect } from '@libp2p/webrtc';
|
|
2
3
|
import { webSockets } from '@libp2p/websockets';
|
|
3
|
-
import { libp2pDefaults } from 'helia';
|
|
4
4
|
export function getLibp2pConfig() {
|
|
5
5
|
const libp2pDefaultOptions = libp2pDefaults();
|
|
6
6
|
libp2pDefaultOptions.start = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.browser.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.browser.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAO/C,MAAM,UAAU,eAAe;IAC7B,MAAM,oBAAoB,GAAG,cAAc,EAAE,CAAA;IAE7C,oBAAoB,CAAC,KAAK,GAAG,KAAK,CAAA;IAClC,oBAAoB,CAAC,SAAS,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;IAC/C,oBAAoB,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IAChE,oBAAoB,CAAC,aAAa,GAAG,EAAE,CAAA,CAAC,sCAAsC;IAE9E,MAAM,QAAQ,GAAkC;QAC9C,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,KAAK;QAC1C,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,IAAI,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI;KACzC,CAAA;IAED,OAAO;QACL,GAAG,oBAAoB;QACvB,KAAK,EAAE,KAAK;QACZ,QAAQ;KACT,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAI3C,wBAAgB,eAAe,IAAK,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAsB5F"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { libp2pDefaults } from '@helia/libp2p';
|
|
1
2
|
import { kadDHT } from '@libp2p/kad-dht';
|
|
2
|
-
import { libp2pDefaults } from 'helia';
|
|
3
|
-
import { ipnsSelector } from 'ipns/selector';
|
|
4
|
-
import { ipnsValidator } from 'ipns/validator';
|
|
5
3
|
export function getLibp2pConfig() {
|
|
6
4
|
const libp2pDefaultOptions = libp2pDefaults();
|
|
7
5
|
libp2pDefaultOptions.start = false;
|
|
@@ -9,13 +7,7 @@ export function getLibp2pConfig() {
|
|
|
9
7
|
autoNAT: libp2pDefaultOptions.services.autoNAT,
|
|
10
8
|
dcutr: libp2pDefaultOptions.services.dcutr,
|
|
11
9
|
dht: kadDHT({
|
|
12
|
-
clientMode: true
|
|
13
|
-
validators: {
|
|
14
|
-
ipns: ipnsValidator
|
|
15
|
-
},
|
|
16
|
-
selectors: {
|
|
17
|
-
ipns: ipnsSelector
|
|
18
|
-
}
|
|
10
|
+
clientMode: true
|
|
19
11
|
}),
|
|
20
12
|
identify: libp2pDefaultOptions.services.identify,
|
|
21
13
|
keychain: libp2pDefaultOptions.services.keychain,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAOxC,MAAM,UAAU,eAAe;IAC7B,MAAM,oBAAoB,GAAG,cAAc,EAAE,CAAA;IAE7C,oBAAoB,CAAC,KAAK,GAAG,KAAK,CAAA;IAElC,MAAM,QAAQ,GAAkC;QAC9C,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,OAAO;QAC9C,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,KAAK;QAC1C,GAAG,EAAE,MAAM,CAAC;YACV,UAAU,EAAE,IAAI;SACjB,CAAC;QACF,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,IAAI,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI;QACxC,IAAI,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI;KACzC,CAAA;IAED,OAAO;QACL,GAAG,oBAAoB;QACvB,KAAK,EAAE,KAAK;QACZ,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/verified-fetch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "A fetch-like API for obtaining verified & trustless IPFS content on the web",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia-verified-fetch/tree/main/packages/verified-fetch#readme",
|
|
@@ -166,16 +166,17 @@
|
|
|
166
166
|
"release": "aegir release"
|
|
167
167
|
},
|
|
168
168
|
"dependencies": {
|
|
169
|
-
"@helia/
|
|
170
|
-
"@helia/car": "^
|
|
171
|
-
"@helia/delegated-routing-v1-http-api-client": "^
|
|
172
|
-
"@helia/dnslink": "^
|
|
173
|
-
"@helia/
|
|
174
|
-
"@helia/
|
|
175
|
-
"@helia/
|
|
176
|
-
"@helia/
|
|
177
|
-
"@
|
|
178
|
-
"@ipld/dag-
|
|
169
|
+
"@helia/bitswap": "^4.0.0",
|
|
170
|
+
"@helia/car": "^6.0.0",
|
|
171
|
+
"@helia/delegated-routing-v1-http-api-client": "^9.0.0",
|
|
172
|
+
"@helia/dnslink": "^2.0.0",
|
|
173
|
+
"@helia/http": "^4.0.2",
|
|
174
|
+
"@helia/interface": "^7.0.0",
|
|
175
|
+
"@helia/ipns": "^10.0.0",
|
|
176
|
+
"@helia/libp2p": "^1.0.3",
|
|
177
|
+
"@helia/unixfs": "^8.0.0",
|
|
178
|
+
"@ipld/dag-cbor": "^10.0.1",
|
|
179
|
+
"@ipld/dag-json": "^11.0.0",
|
|
179
180
|
"@ipld/dag-pb": "^4.1.5",
|
|
180
181
|
"@libp2p/interface": "^3.2.0",
|
|
181
182
|
"@libp2p/kad-dht": "^16.2.0",
|
|
@@ -186,51 +187,47 @@
|
|
|
186
187
|
"@multiformats/dns": "^1.0.13",
|
|
187
188
|
"@multiformats/multiaddr": "^13.0.1",
|
|
188
189
|
"@multiformats/multiaddr-matcher": "^3.0.2",
|
|
190
|
+
"cborg": "^5.1.6",
|
|
189
191
|
"file-type": "^22.0.1",
|
|
190
|
-
"helia": "^
|
|
191
|
-
"interface-blockstore": "^
|
|
192
|
-
"ipfs-unixfs-exporter": "^
|
|
193
|
-
"ipns": "^10.1.6",
|
|
192
|
+
"helia": "^7.0.0",
|
|
193
|
+
"interface-blockstore": "^7.0.1",
|
|
194
|
+
"ipfs-unixfs-exporter": "^16.0.2",
|
|
194
195
|
"it-first": "^3.0.11",
|
|
195
196
|
"it-last": "^3.0.11",
|
|
196
197
|
"it-map": "^3.1.6",
|
|
197
198
|
"it-pipe": "^3.0.1",
|
|
198
199
|
"it-tar": "^6.0.5",
|
|
199
200
|
"it-to-browser-readablestream": "^2.0.14",
|
|
200
|
-
"it-to-buffer": "^
|
|
201
|
+
"it-to-buffer": "^5.0.0",
|
|
201
202
|
"libp2p": "^3.2.0",
|
|
202
|
-
"multiformats": "^
|
|
203
|
+
"multiformats": "^14.0.2",
|
|
203
204
|
"progress-events": "^1.1.0",
|
|
204
205
|
"quick-lru": "^7.3.0",
|
|
205
206
|
"regexp.escape": "^2.0.1",
|
|
206
|
-
"uint8arrays": "^
|
|
207
|
+
"uint8arrays": "^6.1.1"
|
|
207
208
|
},
|
|
208
209
|
"devDependencies": {
|
|
209
|
-
"@helia/dag-cbor": "^
|
|
210
|
-
"@helia/dag-json": "^
|
|
211
|
-
"@helia/
|
|
212
|
-
"@helia/json": "^5.1.1",
|
|
210
|
+
"@helia/dag-cbor": "^6.0.0",
|
|
211
|
+
"@helia/dag-json": "^6.0.0",
|
|
212
|
+
"@helia/json": "^6.0.0",
|
|
213
213
|
"@ipld/car": "^5.4.3",
|
|
214
|
+
"@ipshipyard/crypto": "^1.1.0",
|
|
214
215
|
"@libp2p/crypto": "^5.1.15",
|
|
215
216
|
"@libp2p/logger": "^6.2.4",
|
|
216
217
|
"@types/regexp.escape": "^2.0.0",
|
|
217
|
-
"@types/sinon": "^
|
|
218
|
+
"@types/sinon": "^22.0.0",
|
|
218
219
|
"aegir": "^48.0.4",
|
|
219
|
-
"blockstore-core": "^
|
|
220
|
+
"blockstore-core": "^7.0.1",
|
|
220
221
|
"browser-readablestream-to-it": "^2.0.12",
|
|
221
|
-
"
|
|
222
|
-
"ipfs-unixfs-importer": "^16.1.4",
|
|
222
|
+
"ipfs-unixfs-importer": "^17.0.1",
|
|
223
223
|
"it-all": "^3.0.11",
|
|
224
224
|
"magic-bytes.js": "^1.13.0",
|
|
225
225
|
"race-signal": "^2.0.0",
|
|
226
|
-
"sinon": "^
|
|
226
|
+
"sinon": "^22.0.0",
|
|
227
227
|
"sinon-ts": "^2.0.0"
|
|
228
228
|
},
|
|
229
229
|
"browser": {
|
|
230
230
|
"./dist/src/utils/libp2p-defaults.js": "./dist/src/utils/libp2p-defaults.browser.js"
|
|
231
231
|
},
|
|
232
|
-
"sideEffects": false
|
|
233
|
-
"overrides": {
|
|
234
|
-
"multiformats": "^13.4.2"
|
|
235
|
-
}
|
|
232
|
+
"sideEffects": false
|
|
236
233
|
}
|
package/src/index.ts
CHANGED
|
@@ -100,23 +100,19 @@
|
|
|
100
100
|
* You can see variations of Helia and js-libp2p configuration options at <https://ipfs.github.io/helia/interfaces/helia.HeliaInit.html>.
|
|
101
101
|
*
|
|
102
102
|
* ```typescript
|
|
103
|
-
* import {
|
|
104
|
-
* import {
|
|
103
|
+
* import { createHeliaLight } from 'helia'
|
|
104
|
+
* import { withHTTP } from '@helia/http'
|
|
105
105
|
* import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
|
|
106
106
|
* import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
107
107
|
*
|
|
108
108
|
* const fetch = await createVerifiedFetch(
|
|
109
|
-
* await
|
|
110
|
-
*
|
|
111
|
-
*
|
|
109
|
+
* await withHTTP(createHeliaLight(), {
|
|
110
|
+
* delegatedRouters: [
|
|
111
|
+
* 'http://delegated-ipfs.dev'
|
|
112
112
|
* ],
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* }),
|
|
117
|
-
* httpGatewayRouting({
|
|
118
|
-
* gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
|
|
119
|
-
* })
|
|
113
|
+
* recursiveGateways: [
|
|
114
|
+
* 'https://mygateway.example.net',
|
|
115
|
+
* 'https://trustless-gateway.link'
|
|
120
116
|
* ]
|
|
121
117
|
* })
|
|
122
118
|
* )
|
|
@@ -856,19 +852,23 @@
|
|
|
856
852
|
* fetch if not.
|
|
857
853
|
*/
|
|
858
854
|
|
|
859
|
-
import {
|
|
860
|
-
import {
|
|
861
|
-
import {
|
|
855
|
+
import { withBitswap } from '@helia/bitswap'
|
|
856
|
+
import { delegatedRoutingV1HttpApiClientContentRouting, delegatedRoutingV1HttpApiClientPeerRouting } from '@helia/delegated-routing-v1-http-api-client'
|
|
857
|
+
import { withHTTP } from '@helia/http'
|
|
858
|
+
import { withLibp2p } from '@helia/libp2p'
|
|
859
|
+
import * as dagCbor from '@ipld/dag-cbor'
|
|
860
|
+
import * as dagJson from '@ipld/dag-json'
|
|
862
861
|
import { dns } from '@multiformats/dns'
|
|
863
|
-
import {
|
|
862
|
+
import { createHeliaLight } from 'helia'
|
|
864
863
|
import { createLibp2p } from 'libp2p'
|
|
864
|
+
import * as json from 'multiformats/codecs/json'
|
|
865
865
|
import { getLibp2pConfig } from './utils/libp2p-defaults.ts'
|
|
866
866
|
import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.ts'
|
|
867
867
|
import type { RangeHeader } from './utils/get-range-header.ts'
|
|
868
868
|
import type { ServerTiming } from './utils/server-timing.ts'
|
|
869
869
|
import type { RequestedMimeType } from './verified-fetch.ts'
|
|
870
870
|
import type { DNSLink, ResolveProgressEvents as ResolveDNSLinkProgressEvents } from '@helia/dnslink'
|
|
871
|
-
import type { GetBlockProgressEvents, Helia, ProviderOptions
|
|
871
|
+
import type { GetBlockProgressEvents, Helia, ProviderOptions } from '@helia/interface'
|
|
872
872
|
import type { ResolveProgressEvents as ResolveIPNSNameProgressEvents, IPNSRoutingProgressEvents, IPNSResolver } from '@helia/ipns'
|
|
873
873
|
import type { AbortOptions, Libp2p, ServiceMap, Logger, PeerId, PublicKey } from '@libp2p/interface'
|
|
874
874
|
import type { DNSResolvers, DNS } from '@multiformats/dns'
|
|
@@ -1098,7 +1098,7 @@ export interface CreateVerifiedFetchInit {
|
|
|
1098
1098
|
|
|
1099
1099
|
/**
|
|
1100
1100
|
* In order to parse DNSLink records, we need to resolve DNS queries. You can
|
|
1101
|
-
* pass a list of DNS resolvers that we will provide to the
|
|
1101
|
+
* pass a list of DNS resolvers that we will provide to the `@helia/ipns`
|
|
1102
1102
|
* instance for you. You must construct them using the `dnsJsonOverHttps` or
|
|
1103
1103
|
* `dnsOverHttps` functions exported from `@helia/ipns/dns-resolvers`.
|
|
1104
1104
|
*
|
|
@@ -1109,12 +1109,19 @@ export interface CreateVerifiedFetchInit {
|
|
|
1109
1109
|
dnsResolvers?: DNSResolver[] | DNSResolvers
|
|
1110
1110
|
|
|
1111
1111
|
/**
|
|
1112
|
-
* By default sha256
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1112
|
+
* By default sha256 and identity hashes are supported for retrieval
|
|
1113
|
+
* operations. To retrieve blocks by CIDs using other hashes pass
|
|
1114
|
+
* appropriate MultihashHashers here.
|
|
1115
1115
|
*/
|
|
1116
1116
|
hashers?: HeliaInit['hashers']
|
|
1117
1117
|
|
|
1118
|
+
/**
|
|
1119
|
+
* By default raw, dag-pb, dag-json, dag-cbor, json and cbor codecs are
|
|
1120
|
+
* supported for retrieval operations. To retrieve blocks with CIDs that use
|
|
1121
|
+
* other codecs pass appropriate BlockCodecs here.
|
|
1122
|
+
*/
|
|
1123
|
+
codecs?: HeliaInit['codecs']
|
|
1124
|
+
|
|
1118
1125
|
/**
|
|
1119
1126
|
* By default we will not connect to any HTTP Gateways providers over local or
|
|
1120
1127
|
* loopback addresses, this is because they are typically running on remote
|
|
@@ -1385,6 +1392,7 @@ export interface URLResolver {
|
|
|
1385
1392
|
*/
|
|
1386
1393
|
export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchInit, options?: CreateVerifiedFetchOptions): Promise<VerifiedFetch> {
|
|
1387
1394
|
let libp2p: Libp2p<any> | undefined
|
|
1395
|
+
|
|
1388
1396
|
if (!isHelia(init)) {
|
|
1389
1397
|
const dns = createDns(init?.dnsResolvers)
|
|
1390
1398
|
|
|
@@ -1393,35 +1401,40 @@ export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchIni
|
|
|
1393
1401
|
|
|
1394
1402
|
const delegatedRouters = init?.routers ?? ['https://delegated-ipfs.dev']
|
|
1395
1403
|
for (let index = 0; index < delegatedRouters.length; index++) {
|
|
1396
|
-
libp2pConfig.services[`
|
|
1404
|
+
libp2pConfig.services[`delegatedContentRouting${index}`] = delegatedRoutingV1HttpApiClientContentRouting({
|
|
1405
|
+
url: delegatedRouters[index]
|
|
1406
|
+
})
|
|
1407
|
+
libp2pConfig.services[`delegatedPeerRouting${index}`] = delegatedRoutingV1HttpApiClientPeerRouting({
|
|
1397
1408
|
url: delegatedRouters[index]
|
|
1398
1409
|
})
|
|
1399
1410
|
}
|
|
1411
|
+
|
|
1400
1412
|
// merge any passed options from init.libp2pConfig into libp2pConfig if it exists
|
|
1401
1413
|
if (init?.libp2pConfig != null) {
|
|
1402
1414
|
Object.assign(libp2pConfig, init.libp2pConfig)
|
|
1403
1415
|
}
|
|
1404
|
-
libp2p = await createLibp2p(libp2pConfig)
|
|
1405
1416
|
|
|
1406
|
-
|
|
1407
|
-
bitswap()
|
|
1408
|
-
]
|
|
1409
|
-
const routers: Array<Partial<Routing>> = [
|
|
1410
|
-
libp2pRouting(libp2p)
|
|
1411
|
-
]
|
|
1412
|
-
if (init?.gateways == null || init.gateways.length > 0) {
|
|
1413
|
-
// if gateways is null, or set to a non-empty array, use trustless gateways.
|
|
1414
|
-
blockBrokers.push(trustlessGateway({ allowInsecure: init?.allowInsecure, allowLocal: init?.allowLocal }))
|
|
1415
|
-
routers.push(httpGatewayRouting({ gateways: init?.gateways ?? ['https://trustless-gateway.link'] }))
|
|
1416
|
-
}
|
|
1417
|
+
libp2p = await createLibp2p(libp2pConfig)
|
|
1417
1418
|
|
|
1418
|
-
init = await
|
|
1419
|
-
libp2p,
|
|
1420
|
-
blockBrokers,
|
|
1419
|
+
init = await withBitswap(withLibp2p(withHTTP(createHeliaLight({
|
|
1421
1420
|
dns,
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1421
|
+
hashers: init?.hashers,
|
|
1422
|
+
codecs: [
|
|
1423
|
+
dagCbor,
|
|
1424
|
+
dagJson,
|
|
1425
|
+
json,
|
|
1426
|
+
...(init?.codecs ?? [])
|
|
1427
|
+
]
|
|
1428
|
+
}), {
|
|
1429
|
+
delegatedRouters,
|
|
1430
|
+
recursiveGateways: init?.gateways ?? [
|
|
1431
|
+
'https://trustless-gateway.link'
|
|
1432
|
+
],
|
|
1433
|
+
trustlessGatewayBlockBrokerInit: {
|
|
1434
|
+
allowInsecure: init?.allowInsecure,
|
|
1435
|
+
allowLocal: init?.allowLocal
|
|
1436
|
+
}
|
|
1437
|
+
}), libp2p)).start()
|
|
1425
1438
|
init.logger.forComponent('helia:verified-fetch').trace('created verified-fetch with libp2p config: %j', libp2pConfig)
|
|
1426
1439
|
}
|
|
1427
1440
|
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { IPNSEntry } from '@helia/ipns'
|
|
2
|
+
import * as dagCbor from '@ipld/dag-cbor'
|
|
1
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
2
|
-
import {
|
|
4
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
3
5
|
import { CONTENT_TYPE_IPNS, MEDIA_TYPE_IPNS_RECORD } from '../utils/content-types.ts'
|
|
4
6
|
import { getContentDispositionFilename } from '../utils/get-content-disposition-filename.ts'
|
|
7
|
+
import { splitIPNSName } from '../utils/ipfs-path-to-cid.ts'
|
|
5
8
|
import { badRequestResponse, okResponse } from '../utils/responses.ts'
|
|
6
9
|
import { BasePlugin } from './plugin-base.ts'
|
|
7
10
|
import type { PluginContext } from '../index.ts'
|
|
11
|
+
import type { IPNSRecordData, IPNSResolveResult } from '@helia/ipns'
|
|
8
12
|
import type { PeerId } from '@libp2p/interface'
|
|
9
13
|
|
|
10
14
|
/**
|
|
@@ -43,11 +47,26 @@ export class IpnsRecordPlugin extends BasePlugin {
|
|
|
43
47
|
return badRequestResponse(resource, err)
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
const block = marshalIPNSRecord(result.record)
|
|
50
|
+
let result: IPNSResolveResult | undefined
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
for await (const res of ipnsResolver.resolve(peerId.toCID().multihash, context)) {
|
|
53
|
+
result = res
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (result == null) {
|
|
57
|
+
const err = new Error(`Could not resolve IPNS record for ${peerId}`)
|
|
58
|
+
this.log.error('could not parse peer id from IPNS url %s', resource, err)
|
|
59
|
+
|
|
60
|
+
return badRequestResponse(resource, err)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const block = IPNSEntry.encode(result.record)
|
|
64
|
+
const data = dagCbor.decode<IPNSRecordData>(result.record.data ?? new Uint8Array(0))
|
|
65
|
+
|
|
66
|
+
// 0 is EOL
|
|
67
|
+
// @ts-expect-error TODO: remove TypeScript enums
|
|
68
|
+
if (data.ValidityType === 0 && data.Validity instanceof Uint8Array) {
|
|
69
|
+
const eol = new Date(uint8ArrayToString(data.Validity))
|
|
51
70
|
|
|
52
71
|
context.expires = eol
|
|
53
72
|
context.ttl = Math.round(Number((result.record.ttl ?? 0n) / BigInt(1e9)))
|
|
@@ -61,7 +80,7 @@ export class IpnsRecordPlugin extends BasePlugin {
|
|
|
61
80
|
'content-disposition': `attachment; ${
|
|
62
81
|
getContentDispositionFilename(url.searchParams.get('filename') ?? `${peerId}${CONTENT_TYPE_IPNS.extension}`)
|
|
63
82
|
}`,
|
|
64
|
-
'x-ipfs-roots': result.
|
|
83
|
+
'x-ipfs-roots': splitIPNSName(result.value).name,
|
|
65
84
|
'accept-ranges': 'none'
|
|
66
85
|
}
|
|
67
86
|
})
|
|
@@ -6,6 +6,7 @@ import last from 'it-last'
|
|
|
6
6
|
import itToBrowserReadableStream from 'it-to-browser-readablestream'
|
|
7
7
|
import toBuffer from 'it-to-buffer'
|
|
8
8
|
import * as raw from 'multiformats/codecs/raw'
|
|
9
|
+
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
|
|
9
10
|
import { MEDIA_TYPE_OCTET_STREAM, MEDIA_TYPE_DAG_PB } from '../utils/content-types.ts'
|
|
10
11
|
import { getContentDispositionFilename } from '../utils/get-content-disposition-filename.ts'
|
|
11
12
|
import { badGatewayResponse, movedPermanentlyResponse, partialContentResponse, okResponse } from '../utils/responses.ts'
|
|
@@ -147,15 +148,17 @@ export class UnixFSPlugin extends BasePlugin {
|
|
|
147
148
|
Name: dirEntry.name,
|
|
148
149
|
Hash: dirEntry.cid,
|
|
149
150
|
|
|
150
|
-
// @
|
|
151
|
-
|
|
151
|
+
// TODO: downcast bigint to number until @ipld/dag-pb supports the
|
|
152
|
+
// correct field type
|
|
153
|
+
Tsize: Number(dirEntry.size)
|
|
152
154
|
})
|
|
153
155
|
}
|
|
154
156
|
|
|
155
|
-
|
|
157
|
+
// TODO: remove withArrayBuffer when dag-pb is explicit about it's return type
|
|
158
|
+
block = withArrayBuffer(dagPb.encode({
|
|
156
159
|
Data: data.Data,
|
|
157
160
|
Links: links.sort((a, b) => a.Name?.localeCompare(b.Name ?? '') ?? 0)
|
|
158
|
-
})
|
|
161
|
+
}))
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
return okResponse(resource, block, {
|
package/src/url-resolver.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { DoesNotExistError } from '@helia/unixfs/errors'
|
|
2
|
-
import
|
|
2
|
+
import * as cborg from 'cborg'
|
|
3
3
|
import { exporter, InvalidParametersError, walkPath } from 'ipfs-unixfs-exporter'
|
|
4
|
+
import last from 'it-last'
|
|
4
5
|
import toBuffer from 'it-to-buffer'
|
|
6
|
+
import { base58btc } from 'multiformats/bases/base58'
|
|
5
7
|
import { CID } from 'multiformats/cid'
|
|
8
|
+
import * as Digest from 'multiformats/hashes/digest'
|
|
6
9
|
import QuickLRU from 'quick-lru'
|
|
7
10
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
8
11
|
import { CODEC_LIBP2P_KEY, SESSION_CACHE_MAX_SIZE, SESSION_CACHE_TTL_MS } from './constants.ts'
|
|
9
12
|
import { abbreviate } from './utils/abbreviate.ts'
|
|
10
13
|
import { applyRedirects } from './utils/apply-redirect.ts'
|
|
14
|
+
import { splitIPNSName } from './utils/ipfs-path-to-cid.ts'
|
|
11
15
|
import { ServerTiming } from './utils/server-timing.ts'
|
|
12
16
|
import type { ResolveURLOptions, ResolveURLResult, URLResolver as URLResolverInterface } from './index.ts'
|
|
13
17
|
import type { DNSLink } from '@helia/dnslink'
|
|
@@ -16,6 +20,7 @@ import type { AbortOptions, Logger } from '@libp2p/interface'
|
|
|
16
20
|
import type { Helia, ProviderOptions, SessionBlockstore } from 'helia'
|
|
17
21
|
import type { Blockstore } from 'interface-blockstore'
|
|
18
22
|
import type { PathEntry, UnixFSEntry } from 'ipfs-unixfs-exporter'
|
|
23
|
+
import type { MultihashDigest } from 'multiformats/cid'
|
|
19
24
|
import type { ProgressOptions } from 'progress-events'
|
|
20
25
|
|
|
21
26
|
// 1 year in seconds for ipfs content
|
|
@@ -137,7 +142,7 @@ export class URLResolver implements URLResolverInterface {
|
|
|
137
142
|
|
|
138
143
|
if (result.namespace === 'ipns') {
|
|
139
144
|
// dnslink resolved to IPNS name
|
|
140
|
-
const ipnsUrl = new URL(`ipns://${result.
|
|
145
|
+
const ipnsUrl = new URL(`ipns://${base58btc.baseEncode(result.value.bytes)}${path}`)
|
|
141
146
|
resolveResult = await this.resolveIPNSName(ipnsUrl, serverTiming, options)
|
|
142
147
|
} else if (result.namespace === 'ipfs') {
|
|
143
148
|
// dnslink resolved to CID
|
|
@@ -161,11 +166,22 @@ export class URLResolver implements URLResolverInterface {
|
|
|
161
166
|
}
|
|
162
167
|
|
|
163
168
|
private async resolveIPNSName (url: URL, serverTiming: ServerTiming, options?: ResolveURLOptions): Promise<ResolveURLResult | Response> {
|
|
164
|
-
const
|
|
165
|
-
const result = await serverTiming.time(abbreviate('ipns.resolve'), '', this.components.ipnsResolver.resolve(
|
|
166
|
-
const path = normalizePath(`${result.path ?? ''}/${url.pathname}`)
|
|
169
|
+
const multihash = parseMultihash(url.hostname)
|
|
170
|
+
const result = await serverTiming.time(abbreviate('ipns.resolve'), '', last(this.components.ipnsResolver.resolve(multihash, options)))
|
|
167
171
|
|
|
168
|
-
|
|
172
|
+
if (result == null) {
|
|
173
|
+
throw new InvalidParametersError('Could not resolve IPNS name')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const {
|
|
177
|
+
ns, name, path
|
|
178
|
+
} = splitIPNSName(result.value)
|
|
179
|
+
|
|
180
|
+
if (ns !== 'ipfs') {
|
|
181
|
+
throw new InvalidParametersError('IPNS name resolved to non-IPFS path')
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const ipfsUrl = new URL(`ipfs://${name}${normalizePath(`${path ?? ''}/${url.pathname}`)}`)
|
|
169
185
|
const ipfsResult = await this.resolveIPFSPath(ipfsUrl, serverTiming, options)
|
|
170
186
|
|
|
171
187
|
if (ipfsResult instanceof Response) {
|
|
@@ -173,9 +189,11 @@ export class URLResolver implements URLResolverInterface {
|
|
|
173
189
|
}
|
|
174
190
|
|
|
175
191
|
let expires: Date | undefined
|
|
192
|
+
const data = cborg.decode(result.record.data ?? new Uint8Array(0))
|
|
176
193
|
|
|
177
|
-
|
|
178
|
-
|
|
194
|
+
// 0 is EOL
|
|
195
|
+
if (data.ValidityType === 0 && data.Validity instanceof Uint8Array) {
|
|
196
|
+
expires = new Date(uint8ArrayToString(data.Validity))
|
|
179
197
|
}
|
|
180
198
|
|
|
181
199
|
return {
|
|
@@ -197,7 +215,7 @@ export class URLResolver implements URLResolverInterface {
|
|
|
197
215
|
|
|
198
216
|
if (walkPathResult.terminalElement.cid.code === CODEC_LIBP2P_KEY) {
|
|
199
217
|
// special case, peer id encoded as libp2p key CID - interpret as IPNS
|
|
200
|
-
const ipnsUrl = new URL(`ipns://${
|
|
218
|
+
const ipnsUrl = new URL(`ipns://${base58btc.baseEncode(walkPathResult.terminalElement.cid.multihash.bytes)}`)
|
|
201
219
|
const ipnsResult = await this.resolveIPNSName(ipnsUrl, serverTiming, options)
|
|
202
220
|
|
|
203
221
|
if (ipnsResult instanceof Response) {
|
|
@@ -339,3 +357,11 @@ function normalizePath (path: string): string {
|
|
|
339
357
|
|
|
340
358
|
return ''
|
|
341
359
|
}
|
|
360
|
+
|
|
361
|
+
function parseMultihash (str: string): MultihashDigest {
|
|
362
|
+
if (str.startsWith('1') || str.startsWith('Q')) {
|
|
363
|
+
return Digest.decode(base58btc.baseDecode(str))
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return CID.parse(str).multihash
|
|
367
|
+
}
|
|
@@ -4,12 +4,13 @@ import * as dagPb from '@ipld/dag-pb'
|
|
|
4
4
|
import * as json from 'multiformats/codecs/json'
|
|
5
5
|
import * as raw from 'multiformats/codecs/raw'
|
|
6
6
|
import { identity } from 'multiformats/hashes/identity'
|
|
7
|
+
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
|
|
7
8
|
import { CODEC_CBOR } from '../constants.ts'
|
|
8
9
|
import { getContentTypesForCid, MEDIA_TYPE_CBOR, MEDIA_TYPE_DAG_CBOR, MEDIA_TYPE_DAG_JSON, MEDIA_TYPE_JSON, MEDIA_TYPE_OCTET_STREAM, MEDIA_TYPE_RAW } from './content-types.ts'
|
|
9
10
|
import type { AcceptHeader, ContentType } from '../index.ts'
|
|
10
11
|
import type { CID } from 'multiformats/cid'
|
|
11
12
|
|
|
12
|
-
const CONVERSIONS: Record<number, Record<string, (buf: Uint8Array) => Uint8Array
|
|
13
|
+
const CONVERSIONS: Record<number, Record<string, (buf: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>>> = {
|
|
13
14
|
[dagCbor.code]: {
|
|
14
15
|
[MEDIA_TYPE_CBOR]: (buf) => {
|
|
15
16
|
return buf
|
|
@@ -18,7 +19,8 @@ const CONVERSIONS: Record<number, Record<string, (buf: Uint8Array) => Uint8Array
|
|
|
18
19
|
return buf
|
|
19
20
|
},
|
|
20
21
|
[MEDIA_TYPE_JSON]: (buf) => {
|
|
21
|
-
return
|
|
22
|
+
// TODO: remove withArrayBuffer when dag-json is explicit about it's return type
|
|
23
|
+
return withArrayBuffer(dagJson.encode(dagCbor.decode(buf)))
|
|
22
24
|
},
|
|
23
25
|
[MEDIA_TYPE_DAG_JSON]: () => {
|
|
24
26
|
throw new Error('Cannot perform conversion since IPIP-0524')
|
|
@@ -41,7 +43,8 @@ const CONVERSIONS: Record<number, Record<string, (buf: Uint8Array) => Uint8Array
|
|
|
41
43
|
return buf
|
|
42
44
|
},
|
|
43
45
|
[MEDIA_TYPE_DAG_JSON]: (buf) => {
|
|
44
|
-
return
|
|
46
|
+
// TODO: remove withArrayBuffer when dag-json is explicit about it's return type
|
|
47
|
+
return withArrayBuffer(dagJson.encode(dagCbor.decode(buf)))
|
|
45
48
|
},
|
|
46
49
|
[MEDIA_TYPE_RAW]: (buf) => {
|
|
47
50
|
return buf
|
|
@@ -75,7 +78,8 @@ const CONVERSIONS: Record<number, Record<string, (buf: Uint8Array) => Uint8Array
|
|
|
75
78
|
return buf
|
|
76
79
|
},
|
|
77
80
|
[MEDIA_TYPE_DAG_CBOR]: (buf) => {
|
|
78
|
-
return
|
|
81
|
+
// TODO: remove withArrayBuffer when dag-cbor is explicit about it's return type
|
|
82
|
+
return withArrayBuffer(dagCbor.encode(json.decode(buf)))
|
|
79
83
|
},
|
|
80
84
|
[MEDIA_TYPE_JSON]: (buf) => {
|
|
81
85
|
return buf
|
|
@@ -135,13 +139,15 @@ const CONVERSIONS: Record<number, Record<string, (buf: Uint8Array) => Uint8Array
|
|
|
135
139
|
return buf
|
|
136
140
|
},
|
|
137
141
|
[MEDIA_TYPE_DAG_CBOR]: (buf) => {
|
|
138
|
-
return
|
|
142
|
+
// TODO: remove withArrayBuffer when dag-cbor is explicit about it's return type
|
|
143
|
+
return withArrayBuffer(dagCbor.encode(buf))
|
|
139
144
|
},
|
|
140
145
|
[MEDIA_TYPE_JSON]: (buf) => {
|
|
141
146
|
return buf
|
|
142
147
|
},
|
|
143
148
|
[MEDIA_TYPE_DAG_JSON]: (buf) => {
|
|
144
|
-
return
|
|
149
|
+
// TODO: remove withArrayBuffer when dag-json is explicit about it's return type
|
|
150
|
+
return withArrayBuffer(dagJson.encode(buf))
|
|
145
151
|
},
|
|
146
152
|
[MEDIA_TYPE_RAW]: (buf) => {
|
|
147
153
|
return buf
|
|
@@ -163,7 +169,7 @@ export interface ConvertedOutput {
|
|
|
163
169
|
* the deserialized value to that format and serialize it back to a block -
|
|
164
170
|
* return the first successful result.
|
|
165
171
|
*/
|
|
166
|
-
export function convertOutput (cid: CID, block: Uint8Array
|
|
172
|
+
export function convertOutput (cid: CID, block: Uint8Array<ArrayBuffer>, accept: AcceptHeader[]): { contentType: ContentType, output: Uint8Array<ArrayBuffer> } {
|
|
167
173
|
if (accept.length === 0) {
|
|
168
174
|
// return current format
|
|
169
175
|
return {
|