@ar.io/sdk 3.11.0-alpha.1 → 3.11.0-alpha.11
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 +52 -0
- package/bundles/web.bundle.min.js +119 -116
- package/lib/cjs/cli/cli.js +137 -122
- package/lib/cjs/cli/commands/readCommands.js +6 -0
- package/lib/cjs/cli/utils.js +4 -1
- package/lib/cjs/common/ant.js +5 -5
- package/lib/cjs/common/io.js +49 -3
- package/lib/cjs/common/wayfinder/gateways/trusted-gateways.js +106 -0
- package/lib/cjs/common/wayfinder/gateways.js +19 -8
- package/lib/cjs/common/wayfinder/index.js +9 -1
- package/lib/cjs/common/wayfinder/routers/priority.js +11 -20
- package/lib/cjs/common/wayfinder/routers/priority.test.js +5 -5
- package/lib/cjs/common/wayfinder/routers/random.js +2 -2
- package/lib/cjs/common/wayfinder/routers/random.test.js +5 -84
- package/lib/cjs/common/wayfinder/routers/{fixed.js → static.js} +5 -5
- package/lib/cjs/common/wayfinder/routers/{fixed.test.js → static.test.js} +4 -4
- package/lib/cjs/common/wayfinder/verification/data-root-verifier.js +139 -0
- package/lib/cjs/common/wayfinder/verification/hash-verifier.js +50 -0
- package/lib/cjs/common/wayfinder/wayfinder.js +459 -30
- package/lib/cjs/common/wayfinder/wayfinder.test.js +296 -49
- package/lib/cjs/types/wayfinder.js +1 -0
- package/lib/cjs/utils/ao.js +37 -0
- package/lib/cjs/utils/arweave.js +1 -1
- package/lib/cjs/utils/hash.js +56 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +138 -123
- package/lib/esm/cli/commands/readCommands.js +5 -0
- package/lib/esm/cli/utils.js +4 -1
- package/lib/esm/common/ant.js +5 -5
- package/lib/esm/common/io.js +49 -3
- package/lib/esm/common/wayfinder/gateways/trusted-gateways.js +102 -0
- package/lib/esm/common/wayfinder/gateways.js +17 -6
- package/lib/esm/common/wayfinder/index.js +9 -1
- package/lib/esm/common/wayfinder/routers/priority.js +11 -20
- package/lib/esm/common/wayfinder/routers/priority.test.js +5 -5
- package/lib/esm/common/wayfinder/routers/random.js +2 -2
- package/lib/esm/common/wayfinder/routers/random.test.js +5 -84
- package/lib/esm/common/wayfinder/routers/{fixed.js → static.js} +3 -3
- package/lib/esm/common/wayfinder/routers/{fixed.test.js → static.test.js} +4 -4
- package/lib/esm/common/wayfinder/verification/data-root-verifier.js +130 -0
- package/lib/esm/common/wayfinder/verification/hash-verifier.js +46 -0
- package/lib/esm/common/wayfinder/wayfinder.js +453 -30
- package/lib/esm/common/wayfinder/wayfinder.test.js +297 -50
- package/lib/esm/types/wayfinder.js +1 -0
- package/lib/esm/utils/ao.js +37 -0
- package/lib/esm/utils/arweave.js +1 -1
- package/lib/esm/utils/hash.js +50 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/readCommands.d.ts +1 -0
- package/lib/types/common/io.d.ts +7 -8
- package/lib/types/common/wayfinder/gateways/trusted-gateways.d.ts +51 -0
- package/lib/types/common/wayfinder/gateways.d.ts +16 -7
- package/lib/types/common/wayfinder/index.d.ts +5 -1
- package/lib/types/common/wayfinder/routers/priority.d.ts +8 -12
- package/lib/types/common/wayfinder/routers/{fixed.d.ts → static.d.ts} +3 -3
- package/lib/types/common/wayfinder/verification/data-root-verifier.d.ts +31 -0
- package/lib/types/common/wayfinder/verification/hash-verifier.d.ts +27 -0
- package/lib/types/common/wayfinder/wayfinder.d.ts +169 -17
- package/lib/types/types/io.d.ts +16 -1
- package/lib/types/types/wayfinder.d.ts +43 -0
- package/lib/types/utils/hash.d.ts +4 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- /package/lib/types/common/wayfinder/routers/{fixed.test.d.ts → static.test.d.ts} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
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 { DataHashProvider, DataRootProvider } from '../../../types/wayfinder.js';
|
|
17
|
+
import { GatewaysProvider } from '../gateways.js';
|
|
18
|
+
export declare class TrustedGatewaysHashProvider implements DataHashProvider, DataRootProvider {
|
|
19
|
+
private gatewaysProvider;
|
|
20
|
+
constructor({ gatewaysProvider, }: {
|
|
21
|
+
gatewaysProvider: GatewaysProvider;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Gets the digest for a given txId from all trusted gateways and ensures they all match.
|
|
25
|
+
* @param txId - The txId to get the digest for.
|
|
26
|
+
* @returns The digest for the given txId.
|
|
27
|
+
*/
|
|
28
|
+
getHash({ txId, }: {
|
|
29
|
+
txId: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
hash: string;
|
|
32
|
+
algorithm: 'sha256';
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the data root for a given txId from all trusted gateways and ensure they all match.
|
|
36
|
+
* @param txId - The txId to get the data root for.
|
|
37
|
+
* @returns The data root for the given txId.
|
|
38
|
+
*/
|
|
39
|
+
getDataRoot({ txId }: {
|
|
40
|
+
txId: string;
|
|
41
|
+
}): Promise<string>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Note from @djwhitt
|
|
45
|
+
*
|
|
46
|
+
* Calculating data roots this way is fine, but it may not reproduce the original data root.
|
|
47
|
+
* We could also implement a data root verifier that pulls all the chunks, checks that they
|
|
48
|
+
* reproduce the expected data root, and then compares the concatenated chunk data to the
|
|
49
|
+
* original data retrieved. That would take a while, but it should be able to verify any L1
|
|
50
|
+
* data where we can find the chunks.
|
|
51
|
+
*/
|
|
@@ -15,21 +15,30 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { AoARIORead, AoGatewayWithAddress } from '../../types/io.js';
|
|
17
17
|
export interface GatewaysProvider {
|
|
18
|
-
getGateways(): Promise<
|
|
18
|
+
getGateways(): Promise<URL[]>;
|
|
19
19
|
}
|
|
20
|
-
export declare class
|
|
20
|
+
export declare class NetworkGatewaysProvider implements GatewaysProvider {
|
|
21
21
|
private ario;
|
|
22
|
-
|
|
22
|
+
private sortBy;
|
|
23
|
+
private sortOrder;
|
|
24
|
+
private limit;
|
|
25
|
+
private filter;
|
|
26
|
+
constructor({ ario, sortBy, sortOrder, limit, filter, }: {
|
|
23
27
|
ario: AoARIORead;
|
|
28
|
+
sortBy?: 'totalDelegatedStake' | 'operatorStake' | 'startTimestamp';
|
|
29
|
+
sortOrder?: 'asc' | 'desc';
|
|
30
|
+
limit?: number;
|
|
31
|
+
blocklist?: string[];
|
|
32
|
+
filter?: (gateway: AoGatewayWithAddress) => boolean;
|
|
24
33
|
});
|
|
25
|
-
getGateways(): Promise<
|
|
34
|
+
getGateways(): Promise<URL[]>;
|
|
26
35
|
}
|
|
27
36
|
export declare class StaticGatewaysProvider implements GatewaysProvider {
|
|
28
37
|
private gateways;
|
|
29
38
|
constructor({ gateways }: {
|
|
30
|
-
gateways:
|
|
39
|
+
gateways: string[];
|
|
31
40
|
});
|
|
32
|
-
getGateways(): Promise<
|
|
41
|
+
getGateways(): Promise<URL[]>;
|
|
33
42
|
}
|
|
34
43
|
export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
|
|
35
44
|
private gatewaysProvider;
|
|
@@ -40,5 +49,5 @@ export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
|
|
|
40
49
|
gatewaysProvider: GatewaysProvider;
|
|
41
50
|
ttlSeconds?: number;
|
|
42
51
|
});
|
|
43
|
-
getGateways(): Promise<
|
|
52
|
+
getGateways(): Promise<URL[]>;
|
|
44
53
|
}
|
|
@@ -16,4 +16,8 @@
|
|
|
16
16
|
export * from './wayfinder.js';
|
|
17
17
|
export * from './routers/random.js';
|
|
18
18
|
export * from './routers/priority.js';
|
|
19
|
-
export * from './routers/
|
|
19
|
+
export * from './routers/static.js';
|
|
20
|
+
export * from './gateways.js';
|
|
21
|
+
export * from './gateways/trusted-gateways.js';
|
|
22
|
+
export * from './verification/data-root-verifier.js';
|
|
23
|
+
export * from './verification/hash-verifier.js';
|
|
@@ -14,20 +14,16 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { WayfinderRouter } from '../../../types/wayfinder.js';
|
|
17
|
-
import {
|
|
17
|
+
import { AoARIORead } from '../../../web/index.js';
|
|
18
|
+
import { NetworkGatewaysProvider } from '../gateways.js';
|
|
18
19
|
export declare class PriorityGatewayRouter implements WayfinderRouter {
|
|
19
20
|
readonly name = "priority";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
gatewaysProvider: GatewaysProvider;
|
|
27
|
-
limit?: number;
|
|
28
|
-
sortBy?: 'totalDelegatedStake' | 'operatorStake' | 'startTimestamp';
|
|
29
|
-
sortOrder?: 'asc' | 'desc';
|
|
30
|
-
blocklist?: string[];
|
|
21
|
+
readonly gatewaysProvider: NetworkGatewaysProvider;
|
|
22
|
+
constructor({ ario, sortBy, sortOrder, limit, }: {
|
|
23
|
+
ario: AoARIORead;
|
|
24
|
+
sortBy: 'operatorStake' | 'totalDelegatedStake' | 'startTimestamp';
|
|
25
|
+
sortOrder: 'asc' | 'desc';
|
|
26
|
+
limit: number;
|
|
31
27
|
});
|
|
32
28
|
getTargetGateway(): Promise<URL>;
|
|
33
29
|
}
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { WayfinderRouter } from '../../../types/wayfinder.js';
|
|
17
|
-
export declare class
|
|
18
|
-
readonly name = "
|
|
17
|
+
export declare class StaticGatewayRouter implements WayfinderRouter {
|
|
18
|
+
readonly name = "static";
|
|
19
19
|
private gateway;
|
|
20
20
|
constructor({ gateway }: {
|
|
21
|
-
gateway:
|
|
21
|
+
gateway: string;
|
|
22
22
|
});
|
|
23
23
|
getTargetGateway(): Promise<URL>;
|
|
24
24
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
19
23
|
export declare const arnsRegex: RegExp;
|
|
20
24
|
export declare const txIdRegex: RegExp;
|
|
21
25
|
/**
|
|
@@ -24,10 +28,74 @@ export declare const txIdRegex: RegExp;
|
|
|
24
28
|
* @param targetGateway - the target gateway to resolve the url against
|
|
25
29
|
* @returns the resolved url that can be used to make a request
|
|
26
30
|
*/
|
|
27
|
-
export declare const resolveWayfinderUrl: ({ originalUrl, targetGateway, }: {
|
|
31
|
+
export declare const resolveWayfinderUrl: ({ originalUrl, targetGateway, logger, }: {
|
|
28
32
|
originalUrl: string | URL;
|
|
29
|
-
targetGateway: string | URL
|
|
30
|
-
|
|
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;
|
|
31
99
|
/**
|
|
32
100
|
* Creates a wrapped http client that supports ar:// protocol
|
|
33
101
|
*
|
|
@@ -41,11 +109,18 @@ export declare const resolveWayfinderUrl: ({ originalUrl, targetGateway, }: {
|
|
|
41
109
|
* @param resolveUrl - the function to construct the redirect url for ar:// requests
|
|
42
110
|
* @returns a wrapped http client that supports ar:// protocol
|
|
43
111
|
*/
|
|
44
|
-
export declare const createWayfinderClient: <T extends
|
|
112
|
+
export declare const createWayfinderClient: <T extends HttpClientFunction>({ httpClient, resolveUrl, verifyData, emitter, logger, }: {
|
|
45
113
|
httpClient: T;
|
|
46
114
|
resolveUrl: (params: {
|
|
47
115
|
originalUrl: string | URL;
|
|
116
|
+
logger?: Logger;
|
|
48
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;
|
|
49
124
|
}) => WayfinderHttpClient<T>;
|
|
50
125
|
/**
|
|
51
126
|
* The main class for the wayfinder
|
|
@@ -53,24 +128,38 @@ export declare const createWayfinderClient: <T extends AnyFunction>({ httpClient
|
|
|
53
128
|
* @param httpClient - the http client to use for requests
|
|
54
129
|
* @param blocklist - the blocklist of gateways to avoid
|
|
55
130
|
*/
|
|
56
|
-
export declare class Wayfinder<T extends
|
|
131
|
+
export declare class Wayfinder<T extends HttpClientFunction> {
|
|
57
132
|
/**
|
|
58
133
|
* The router to use for requests
|
|
59
134
|
*
|
|
60
135
|
* @example
|
|
61
136
|
* const wayfinder = new Wayfinder({
|
|
62
|
-
* router: new RandomGatewayRouter({
|
|
137
|
+
* router: new RandomGatewayRouter({
|
|
138
|
+
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
139
|
+
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
140
|
+
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
141
|
+
* }),
|
|
142
|
+
* }),
|
|
63
143
|
* });
|
|
144
|
+
*
|
|
145
|
+
* // Returns a target gateway based on the routing strategy
|
|
146
|
+
* const targetGateway = await wayfinder.router.getTargetGateway();
|
|
64
147
|
*/
|
|
65
148
|
readonly router: WayfinderRouter;
|
|
66
149
|
/**
|
|
67
|
-
* The http client
|
|
150
|
+
* The native http client used by wayfinder
|
|
68
151
|
*
|
|
69
152
|
* @example
|
|
70
153
|
* const wayfinder = new Wayfinder({
|
|
71
|
-
* router: new RandomGatewayRouter({
|
|
154
|
+
* router: new RandomGatewayRouter({
|
|
155
|
+
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
156
|
+
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
157
|
+
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
158
|
+
* }),
|
|
159
|
+
* }),
|
|
72
160
|
* httpClient: axios,
|
|
73
161
|
* });
|
|
162
|
+
*
|
|
74
163
|
*/
|
|
75
164
|
readonly httpClient: T;
|
|
76
165
|
/**
|
|
@@ -78,26 +167,37 @@ export declare class Wayfinder<T extends AnyFunction> {
|
|
|
78
167
|
*
|
|
79
168
|
* @example
|
|
80
169
|
* const wayfinder = new Wayfinder({
|
|
81
|
-
* router: new RandomGatewayRouter({
|
|
170
|
+
* router: new RandomGatewayRouter({
|
|
171
|
+
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
172
|
+
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
173
|
+
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
174
|
+
* }),
|
|
175
|
+
* }),
|
|
82
176
|
* httpClient: axios,
|
|
83
177
|
* });
|
|
84
178
|
*
|
|
179
|
+
* // returns the redirected URL based on the routing strategy and the original url
|
|
85
180
|
* const redirectUrl = await wayfinder.resolveUrl({ originalUrl: 'ar://example' });
|
|
86
181
|
*/
|
|
87
182
|
readonly resolveUrl: (params: {
|
|
88
183
|
originalUrl: string;
|
|
184
|
+
logger?: Logger;
|
|
89
185
|
}) => Promise<URL>;
|
|
90
186
|
/**
|
|
91
187
|
* A wrapped http client that supports ar:// protocol
|
|
92
188
|
*
|
|
93
189
|
* @example
|
|
94
190
|
* const { request: wayfind } = new Wayfinder({
|
|
95
|
-
* router: new RandomGatewayRouter({
|
|
191
|
+
* router: new RandomGatewayRouter({
|
|
192
|
+
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
193
|
+
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
194
|
+
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
195
|
+
* }),
|
|
196
|
+
* }),
|
|
96
197
|
* httpClient: axios,
|
|
97
198
|
* });;
|
|
98
199
|
*
|
|
99
|
-
*
|
|
100
|
-
* const response = await wayfind('ar://', {
|
|
200
|
+
* const response = await wayfind('ar://example', {
|
|
101
201
|
* method: 'POST',
|
|
102
202
|
* data: {
|
|
103
203
|
* name: 'John Doe',
|
|
@@ -105,9 +205,61 @@ export declare class Wayfinder<T extends AnyFunction> {
|
|
|
105
205
|
* })
|
|
106
206
|
*/
|
|
107
207
|
readonly request: WayfinderHttpClient<T>;
|
|
108
|
-
|
|
109
|
-
|
|
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, }: {
|
|
110
242
|
httpClient: T;
|
|
243
|
+
router?: WayfinderRouter;
|
|
244
|
+
logger?: Logger;
|
|
245
|
+
verifier?: DataVerifier;
|
|
246
|
+
hashProvider?: DataHashProvider;
|
|
247
|
+
events?: WayfinderEventArgs;
|
|
111
248
|
});
|
|
112
249
|
}
|
|
113
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
|
+
*/
|
package/lib/types/types/io.d.ts
CHANGED
|
@@ -420,7 +420,22 @@ export type DemandFactorSettings = {
|
|
|
420
420
|
maxPeriodsAtMinDemandFactor: number;
|
|
421
421
|
criteria: string;
|
|
422
422
|
};
|
|
423
|
-
export
|
|
423
|
+
export type ArNSNameResolutionData = {
|
|
424
|
+
name: string;
|
|
425
|
+
owner?: string;
|
|
426
|
+
txId: string;
|
|
427
|
+
type: 'lease' | 'permabuy';
|
|
428
|
+
processId: string;
|
|
429
|
+
ttlSeconds: number;
|
|
430
|
+
priority?: number;
|
|
431
|
+
undernameLimit: number;
|
|
432
|
+
};
|
|
433
|
+
export interface ArNSNameResolver {
|
|
434
|
+
resolveArNSName({ name }: {
|
|
435
|
+
name: string;
|
|
436
|
+
}): Promise<ArNSNameResolutionData>;
|
|
437
|
+
}
|
|
438
|
+
export interface AoARIORead extends ArNSNameResolver {
|
|
424
439
|
process: AOProcess;
|
|
425
440
|
getInfo(): Promise<{
|
|
426
441
|
Ticker: string;
|
|
@@ -13,7 +13,50 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { Readable } from 'stream';
|
|
16
17
|
export interface WayfinderRouter {
|
|
17
18
|
readonly name: string;
|
|
18
19
|
getTargetGateway: () => Promise<URL>;
|
|
19
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
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
export declare const hashReadableToB64Url: (stream: Readable, algorithm?: string) => Promise<string>;
|
|
3
|
+
export declare const hashReadableStreamToB64Url: (stream: ReadableStream, algorithm?: string) => Promise<string>;
|
|
4
|
+
export declare const hashBufferToB64Url: (buffer: Buffer, algorithm?: string) => string;
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
File without changes
|