@ar.io/sdk 3.11.0-alpha.9 → 3.11.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.
Files changed (72) hide show
  1. package/bundles/web.bundle.min.js +120 -123
  2. package/lib/cjs/cli/utils.js +4 -1
  3. package/lib/cjs/common/ant-versions.js +3 -2
  4. package/lib/cjs/common/contracts/ao-process.js +2 -1
  5. package/lib/cjs/common/index.js +0 -2
  6. package/lib/cjs/common/io.js +13 -9
  7. package/lib/cjs/common/turbo.js +1 -1
  8. package/lib/cjs/types/index.js +0 -1
  9. package/lib/cjs/utils/ao.js +2 -1
  10. package/lib/cjs/version.js +1 -1
  11. package/lib/esm/cli/utils.js +4 -1
  12. package/lib/esm/common/ant-versions.js +3 -2
  13. package/lib/esm/common/contracts/ao-process.js +2 -1
  14. package/lib/esm/common/index.js +0 -2
  15. package/lib/esm/common/io.js +13 -9
  16. package/lib/esm/common/turbo.js +1 -1
  17. package/lib/esm/types/index.js +0 -1
  18. package/lib/esm/utils/ao.js +2 -1
  19. package/lib/esm/version.js +1 -1
  20. package/lib/types/common/ant-versions.d.ts +3 -5
  21. package/lib/types/common/index.d.ts +0 -1
  22. package/lib/types/types/index.d.ts +0 -1
  23. package/lib/types/version.d.ts +1 -1
  24. package/package.json +1 -1
  25. package/lib/cjs/common/wayfinder/gateways/trusted-gateways.js +0 -106
  26. package/lib/cjs/common/wayfinder/gateways.js +0 -86
  27. package/lib/cjs/common/wayfinder/index.js +0 -44
  28. package/lib/cjs/common/wayfinder/routers/priority.js +0 -29
  29. package/lib/cjs/common/wayfinder/routers/priority.test.js +0 -155
  30. package/lib/cjs/common/wayfinder/routers/random.js +0 -23
  31. package/lib/cjs/common/wayfinder/routers/random.test.js +0 -25
  32. package/lib/cjs/common/wayfinder/routers/simple-cache.js +0 -25
  33. package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +0 -41
  34. package/lib/cjs/common/wayfinder/routers/static.js +0 -14
  35. package/lib/cjs/common/wayfinder/routers/static.test.js +0 -14
  36. package/lib/cjs/common/wayfinder/verification/data-root-verifier.js +0 -139
  37. package/lib/cjs/common/wayfinder/verification/hash-verifier.js +0 -50
  38. package/lib/cjs/common/wayfinder/wayfinder.js +0 -596
  39. package/lib/cjs/common/wayfinder/wayfinder.test.js +0 -500
  40. package/lib/cjs/types/wayfinder.js +0 -3
  41. package/lib/esm/common/wayfinder/gateways/trusted-gateways.js +0 -102
  42. package/lib/esm/common/wayfinder/gateways.js +0 -80
  43. package/lib/esm/common/wayfinder/index.js +0 -28
  44. package/lib/esm/common/wayfinder/routers/priority.js +0 -25
  45. package/lib/esm/common/wayfinder/routers/priority.test.js +0 -153
  46. package/lib/esm/common/wayfinder/routers/random.js +0 -19
  47. package/lib/esm/common/wayfinder/routers/random.test.js +0 -23
  48. package/lib/esm/common/wayfinder/routers/simple-cache.js +0 -21
  49. package/lib/esm/common/wayfinder/routers/simple-cache.test.js +0 -39
  50. package/lib/esm/common/wayfinder/routers/static.js +0 -10
  51. package/lib/esm/common/wayfinder/routers/static.test.js +0 -12
  52. package/lib/esm/common/wayfinder/verification/data-root-verifier.js +0 -130
  53. package/lib/esm/common/wayfinder/verification/hash-verifier.js +0 -46
  54. package/lib/esm/common/wayfinder/wayfinder.js +0 -584
  55. package/lib/esm/common/wayfinder/wayfinder.test.js +0 -495
  56. package/lib/esm/types/wayfinder.js +0 -2
  57. package/lib/types/common/wayfinder/gateways/trusted-gateways.d.ts +0 -51
  58. package/lib/types/common/wayfinder/gateways.d.ts +0 -53
  59. package/lib/types/common/wayfinder/index.d.ts +0 -23
  60. package/lib/types/common/wayfinder/routers/priority.d.ts +0 -29
  61. package/lib/types/common/wayfinder/routers/priority.test.d.ts +0 -1
  62. package/lib/types/common/wayfinder/routers/random.d.ts +0 -27
  63. package/lib/types/common/wayfinder/routers/random.test.d.ts +0 -1
  64. package/lib/types/common/wayfinder/routers/simple-cache.d.ts +0 -28
  65. package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +0 -1
  66. package/lib/types/common/wayfinder/routers/static.d.ts +0 -24
  67. package/lib/types/common/wayfinder/routers/static.test.d.ts +0 -1
  68. package/lib/types/common/wayfinder/verification/data-root-verifier.d.ts +0 -31
  69. package/lib/types/common/wayfinder/verification/hash-verifier.d.ts +0 -27
  70. package/lib/types/common/wayfinder/wayfinder.d.ts +0 -265
  71. package/lib/types/common/wayfinder/wayfinder.test.d.ts +0 -1
  72. package/lib/types/types/wayfinder.d.ts +0 -62
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { WayfinderRouter } from '../../../types/wayfinder.js';
17
- import { GatewaysProvider } from '../gateways.js';
18
- export declare class RandomGatewayRouter implements WayfinderRouter {
19
- readonly name = "random";
20
- private gatewaysProvider;
21
- private blocklist;
22
- constructor({ gatewaysProvider, blocklist, }: {
23
- gatewaysProvider: GatewaysProvider;
24
- blocklist?: string[];
25
- });
26
- getTargetGateway(): Promise<URL>;
27
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { WayfinderRouter } from '../../../types/wayfinder.js';
17
- export declare class SimpleCacheRouter implements WayfinderRouter {
18
- readonly name: 'simple-cache';
19
- private lastUpdatedTimestamp;
20
- private ttlSeconds;
21
- private targetGateway;
22
- private router;
23
- constructor({ router, ttlSeconds, }: {
24
- router: WayfinderRouter;
25
- ttlSeconds?: number;
26
- });
27
- getTargetGateway(): Promise<URL>;
28
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { WayfinderRouter } from '../../../types/wayfinder.js';
17
- export declare class StaticGatewayRouter implements WayfinderRouter {
18
- readonly name = "static";
19
- private gateway;
20
- constructor({ gateway }: {
21
- gateway: string;
22
- });
23
- getTargetGateway(): Promise<URL>;
24
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import { DataRootProvider, DataVerifier } from '../../../types/wayfinder.js';
3
- export declare function convertBufferToDataRoot({ buffer, }: {
4
- buffer: Buffer;
5
- }): Promise<string>;
6
- export declare const convertReadableToDataRoot: <T extends AsyncIterable<Uint8Array>>({ iterable, }: {
7
- iterable: T;
8
- }) => Promise<string>;
9
- export declare class DataRootVerifier implements DataVerifier {
10
- private readonly trustedDataRootProvider;
11
- constructor({ trustedDataRootProvider, }: {
12
- trustedDataRootProvider: DataRootProvider;
13
- });
14
- verifyData({ data, txId, }: {
15
- data: Buffer | Readable | ReadableStream;
16
- txId: string;
17
- }): Promise<void>;
18
- }
19
- /**
20
- * - when you get a signature of a data item, you can only verify the owner
21
- * - you still need to verify it's going back to the bundle, unpack it, and verify the data item exists at the offset
22
- * - you need to the location of the chunks for the data item, and prove it's in the chunk and then prove the data root of the bundle, then you have fully verified the data verifier
23
- * - how to prove the data item is on arweave - verify the merkle hash that the chunks for the data item, fit within the expected tree of the parent bundle
24
- *
25
- * Composite verifier - you'll want to be very efficient with streams
26
- * - hash verifier
27
- * - parent chunks verifier --> for any range of data within a single transaction, tell me that it's correct
28
- * - signature verifier
29
- * - offset verifier
30
- * - data item verifier
31
- */
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { Readable } from 'node:stream';
17
- import { DataHashProvider, DataVerifier } from '../../../types/wayfinder.js';
18
- export declare class HashVerifier implements DataVerifier {
19
- private readonly trustedHashProvider;
20
- constructor({ trustedHashProvider, }: {
21
- trustedHashProvider: DataHashProvider;
22
- });
23
- verifyData({ data, txId, }: {
24
- data: Buffer | Readable | ReadableStream;
25
- txId: string;
26
- }): Promise<void>;
27
- }
@@ -1,265 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import EventEmitter from 'node:events';
17
- import { PassThrough, Readable } from 'node:stream';
18
- import { DataHashProvider, DataVerifier, WayfinderRouter } from '../../types/wayfinder.js';
19
- import { Logger } from '../logger.js';
20
- type HttpClientArgs = unknown[];
21
- type HttpClientFunction = (...args: HttpClientArgs) => unknown;
22
- type WayfinderHttpClient<T extends HttpClientFunction> = T;
23
- export declare const arnsRegex: RegExp;
24
- export declare const txIdRegex: RegExp;
25
- /**
26
- * Core function to resolve a wayfinder url against a target gateway
27
- * @param originalUrl - the wayfinder url to resolve
28
- * @param targetGateway - the target gateway to resolve the url against
29
- * @returns the resolved url that can be used to make a request
30
- */
31
- export declare const resolveWayfinderUrl: ({ originalUrl, targetGateway, logger, }: {
32
- originalUrl: string | URL;
33
- targetGateway: () => Promise<string | URL>;
34
- logger?: Logger;
35
- }) => Promise<URL>;
36
- /**
37
- * Wayfinder event emitter with verification events
38
- */
39
- export type WayfinderEvent = {
40
- type: 'verification-passed';
41
- txId: string;
42
- } | {
43
- type: 'verification-failed';
44
- txId: string;
45
- error: Error;
46
- } | {
47
- type: 'verification-skipped';
48
- originalUrl: string;
49
- } | {
50
- type: 'verification-progress';
51
- txId: string;
52
- processedBytes: number;
53
- totalBytes: number;
54
- } | {
55
- type: 'routing-started';
56
- originalUrl: string;
57
- } | {
58
- type: 'routing-succeeded';
59
- originalUrl: string;
60
- targetGateway: string;
61
- } | {
62
- type: 'routing-failed';
63
- originalUrl: string;
64
- error: Error;
65
- } | {
66
- type: 'identified-transaction-id';
67
- originalUrl: string;
68
- targetGateway: string;
69
- txId: string;
70
- };
71
- export interface WayfinderEventArgs {
72
- onVerificationPassed?: (payload: Omit<Extract<WayfinderEvent, {
73
- type: 'verification-passed';
74
- }>, 'type'>) => void;
75
- onVerificationFailed?: (payload: Omit<Extract<WayfinderEvent, {
76
- type: 'verification-failed';
77
- }>, 'type'>) => void;
78
- onVerificationProgress?: (payload: Omit<Extract<WayfinderEvent, {
79
- type: 'verification-progress';
80
- }>, 'type'>) => void;
81
- }
82
- export declare class WayfinderEmitter extends EventEmitter {
83
- constructor({ onVerificationPassed, onVerificationFailed, onVerificationProgress, }?: WayfinderEventArgs);
84
- emit<E extends WayfinderEvent['type']>(event: E, payload: Omit<Extract<WayfinderEvent, {
85
- type: E;
86
- }>, 'type'>): boolean;
87
- on<E extends WayfinderEvent['type']>(event: E, listener: (payload: Omit<Extract<WayfinderEvent, {
88
- type: E;
89
- }>, 'type'>) => void): this;
90
- }
91
- export declare function tapAndVerifyStream<T extends Readable | ReadableStream>({ originalStream, contentLength, verifyData, txId, emitter, }: {
92
- originalStream: T;
93
- contentLength: number;
94
- verifyData: DataVerifier['verifyData'];
95
- txId: string;
96
- emitter?: WayfinderEmitter;
97
- }): T extends Readable ? PassThrough : T;
98
- export declare function wrapVerifiedResponse(original: Response, newBody: ReadableStream<Uint8Array>, txId: string): Response;
99
- /**
100
- * Creates a wrapped http client that supports ar:// protocol
101
- *
102
- * This function leverages a Proxy to intercept calls to the http client
103
- * and redirects them to the target gateway using the resolveUrl function url.
104
- * It also supports the http client methods like get(), post(), put(), delete(), etc.
105
- *
106
- * Any URLs provided that are not wayfinder urls will be returned as is.
107
- *
108
- * @param httpClient - the http client to wrap (e.g. axios, fetch, got, etc.)
109
- * @param resolveUrl - the function to construct the redirect url for ar:// requests
110
- * @returns a wrapped http client that supports ar:// protocol
111
- */
112
- export declare const createWayfinderClient: <T extends HttpClientFunction>({ httpClient, resolveUrl, verifyData, emitter, logger, }: {
113
- httpClient: T;
114
- resolveUrl: (params: {
115
- originalUrl: string | URL;
116
- logger?: Logger;
117
- }) => Promise<URL>;
118
- verifyData?: <T_1 extends Readable | ReadableStream | Buffer>({ data, txId, }: {
119
- data: T_1;
120
- txId: string;
121
- }) => Promise<void>;
122
- logger?: Logger;
123
- emitter?: WayfinderEmitter;
124
- }) => WayfinderHttpClient<T>;
125
- /**
126
- * The main class for the wayfinder
127
- * @param router - the router to use for requests
128
- * @param httpClient - the http client to use for requests
129
- * @param blocklist - the blocklist of gateways to avoid
130
- */
131
- export declare class Wayfinder<T extends HttpClientFunction> {
132
- /**
133
- * The router to use for requests
134
- *
135
- * @example
136
- * const wayfinder = new Wayfinder({
137
- * router: new RandomGatewayRouter({
138
- * gatewaysProvider: new SimpleCacheGatewaysProvider({
139
- * gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
140
- * ttlSeconds: 60 * 60 * 24, // 1 day
141
- * }),
142
- * }),
143
- * });
144
- *
145
- * // Returns a target gateway based on the routing strategy
146
- * const targetGateway = await wayfinder.router.getTargetGateway();
147
- */
148
- readonly router: WayfinderRouter;
149
- /**
150
- * The native http client used by wayfinder
151
- *
152
- * @example
153
- * const wayfinder = new Wayfinder({
154
- * router: new RandomGatewayRouter({
155
- * gatewaysProvider: new SimpleCacheGatewaysProvider({
156
- * gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
157
- * ttlSeconds: 60 * 60 * 24, // 1 day
158
- * }),
159
- * }),
160
- * httpClient: axios,
161
- * });
162
- *
163
- */
164
- readonly httpClient: T;
165
- /**
166
- * The function that resolves the redirect url for ar:// requests to a target gateway
167
- *
168
- * @example
169
- * const wayfinder = new Wayfinder({
170
- * router: new RandomGatewayRouter({
171
- * gatewaysProvider: new SimpleCacheGatewaysProvider({
172
- * gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
173
- * ttlSeconds: 60 * 60 * 24, // 1 day
174
- * }),
175
- * }),
176
- * httpClient: axios,
177
- * });
178
- *
179
- * // returns the redirected URL based on the routing strategy and the original url
180
- * const redirectUrl = await wayfinder.resolveUrl({ originalUrl: 'ar://example' });
181
- */
182
- readonly resolveUrl: (params: {
183
- originalUrl: string;
184
- logger?: Logger;
185
- }) => Promise<URL>;
186
- /**
187
- * A wrapped http client that supports ar:// protocol
188
- *
189
- * @example
190
- * const { request: wayfind } = new Wayfinder({
191
- * router: new RandomGatewayRouter({
192
- * gatewaysProvider: new SimpleCacheGatewaysProvider({
193
- * gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
194
- * ttlSeconds: 60 * 60 * 24, // 1 day
195
- * }),
196
- * }),
197
- * httpClient: axios,
198
- * });;
199
- *
200
- * const response = await wayfind('ar://example', {
201
- * method: 'POST',
202
- * data: {
203
- * name: 'John Doe',
204
- * },
205
- * })
206
- */
207
- readonly request: WayfinderHttpClient<T>;
208
- readonly verifyData: DataVerifier['verifyData'];
209
- /**
210
- * The event emitter for wayfinder that emits verification events.
211
- *
212
- * const wayfinder = new Wayfinder()
213
- *
214
- * wayfinder.emitter.on('verification-passed', (event) => {
215
- * console.log('Verification passed!', event);
216
- * })
217
- *
218
- * wayfinder.emitter.on('verification-failed', (event) => {
219
- * console.log('Verification failed!', event);
220
- * })
221
- *
222
- * or implement the events interface and pass it in, using callback functions
223
- *
224
- * const wayfinder = new Wayfinder({
225
- * events: {
226
- * onVerificationPassed: (event) => {
227
- * console.log('Verification passed!', event);
228
- * },
229
- * onVerificationFailed: (event) => {
230
- * console.log('Verification failed!', event);
231
- * },
232
- * onVerificationProgress: (event) => {
233
- * console.log('Verification progress!', event);
234
- * },
235
- * }
236
- * })
237
- *
238
- * const response = await wayfind('ar://example');
239
- */
240
- readonly emitter: WayfinderEmitter;
241
- constructor({ httpClient, router, logger, verifier, events, }: {
242
- httpClient: T;
243
- router?: WayfinderRouter;
244
- logger?: Logger;
245
- verifier?: DataVerifier;
246
- hashProvider?: DataHashProvider;
247
- events?: WayfinderEventArgs;
248
- });
249
- }
250
- export {};
251
- /**
252
- *
253
- * type | complexity | performance | security
254
- * ---------|------------|-------------|---------
255
- * hash | low | high | low
256
- * ---------|------------|-------------|---------
257
- * data root | medium | medium | low | only L1
258
- * ---------|------------|-------------|---------
259
- * signature | medium | medium | medium
260
- * ---------|------------|-------------|---------
261
- * composite | high | low | high
262
- * ---------|------------|-------------|---------
263
- *
264
- *
265
- */
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { Readable } from 'stream';
17
- export interface WayfinderRouter {
18
- readonly name: string;
19
- getTargetGateway: () => Promise<URL>;
20
- }
21
- export interface DataVerifier {
22
- /**
23
- * Verifies the provided data for a given txId
24
- *
25
- * Depending on the implementation, the hash can be the computed data root of a transaction, the digest of the data, or some other hash of the data.
26
- *
27
- * The interface is intended to be vague in order to support various degrees of verification.
28
- *
29
- * @param data - The data to verify
30
- * @param txId - The txId of the data
31
- * @returns the hash of the data
32
- */
33
- verifyData: ({ data, txId, }: {
34
- data: Buffer | Readable | ReadableStream;
35
- txId: string;
36
- }) => Promise<void>;
37
- }
38
- export interface DataHashProvider {
39
- /**
40
- * Returns a hash for the provided txId using the specified algorithm.
41
- *
42
- * @param txId - The txId of the data
43
- * @returns the hash of the data
44
- */
45
- getHash: ({ txId, }: {
46
- txId: string;
47
- }) => Promise<{
48
- hash: string;
49
- algorithm: 'sha256';
50
- }>;
51
- }
52
- export interface DataRootProvider {
53
- /**
54
- * Returns the data root for the provided txId
55
- *
56
- * @param txId - The txId of the data
57
- * @returns the data root of the data
58
- */
59
- getDataRoot: ({ txId }: {
60
- txId: string;
61
- }) => Promise<string>;
62
- }