@ar.io/sdk 3.13.0-beta.1 → 3.14.0-alpha.1
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 +1 -1
- package/bundles/web.bundle.min.js +133 -136
- package/lib/cjs/cli/cli.js +8 -0
- package/lib/cjs/common/ant.js +102 -1
- package/lib/cjs/common/index.js +0 -2
- package/lib/cjs/utils/ant.js +32 -1
- package/lib/cjs/utils/hash.js +31 -83
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +8 -0
- package/lib/esm/common/ant.js +103 -2
- package/lib/esm/common/index.js +0 -2
- package/lib/esm/utils/ant.js +30 -0
- package/lib/esm/utils/hash.js +27 -74
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +9 -1
- package/lib/types/common/index.d.ts +0 -1
- package/lib/types/types/ant.d.ts +17 -0
- package/lib/types/types/io.d.ts +0 -3
- package/lib/types/utils/ant.d.ts +7 -1
- package/lib/types/utils/hash.d.ts +4 -8
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -2
- package/lib/cjs/common/wayfinder/gateways/network.js +0 -48
- package/lib/cjs/common/wayfinder/gateways/simple-cache.js +0 -35
- package/lib/cjs/common/wayfinder/gateways/static.js +0 -13
- package/lib/cjs/common/wayfinder/index.js +0 -48
- package/lib/cjs/common/wayfinder/routing/strategies/ping.js +0 -72
- package/lib/cjs/common/wayfinder/routing/strategies/preferred-with-fallback.js +0 -50
- package/lib/cjs/common/wayfinder/routing/strategies/random.js +0 -13
- package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +0 -42
- package/lib/cjs/common/wayfinder/routing/strategies/static.js +0 -29
- package/lib/cjs/common/wayfinder/verification/strategies/data-root-verifier.js +0 -110
- package/lib/cjs/common/wayfinder/verification/strategies/hash-verifier.js +0 -27
- package/lib/cjs/common/wayfinder/verification/trusted.js +0 -125
- package/lib/cjs/common/wayfinder/wayfinder.js +0 -508
- package/lib/cjs/types/wayfinder.js +0 -3
- package/lib/esm/common/wayfinder/gateways/network.js +0 -44
- package/lib/esm/common/wayfinder/gateways/simple-cache.js +0 -31
- package/lib/esm/common/wayfinder/gateways/static.js +0 -9
- package/lib/esm/common/wayfinder/index.js +0 -32
- package/lib/esm/common/wayfinder/routing/strategies/ping.js +0 -68
- package/lib/esm/common/wayfinder/routing/strategies/preferred-with-fallback.js +0 -46
- package/lib/esm/common/wayfinder/routing/strategies/random.js +0 -9
- package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +0 -38
- package/lib/esm/common/wayfinder/routing/strategies/static.js +0 -25
- package/lib/esm/common/wayfinder/verification/strategies/data-root-verifier.js +0 -102
- package/lib/esm/common/wayfinder/verification/strategies/hash-verifier.js +0 -23
- package/lib/esm/common/wayfinder/verification/trusted.js +0 -121
- package/lib/esm/common/wayfinder/wayfinder.js +0 -499
- package/lib/esm/types/wayfinder.js +0 -2
- package/lib/types/common/wayfinder/gateways/network.d.ts +0 -33
- package/lib/types/common/wayfinder/gateways/simple-cache.d.ts +0 -31
- package/lib/types/common/wayfinder/gateways/static.d.ts +0 -23
- package/lib/types/common/wayfinder/index.d.ts +0 -27
- package/lib/types/common/wayfinder/routing/strategies/ping.d.ts +0 -27
- package/lib/types/common/wayfinder/routing/strategies/preferred-with-fallback.d.ts +0 -31
- package/lib/types/common/wayfinder/routing/strategies/random.d.ts +0 -21
- package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +0 -29
- package/lib/types/common/wayfinder/routing/strategies/static.d.ts +0 -29
- package/lib/types/common/wayfinder/verification/strategies/data-root-verifier.d.ts +0 -27
- package/lib/types/common/wayfinder/verification/strategies/hash-verifier.d.ts +0 -26
- package/lib/types/common/wayfinder/verification/trusted.d.ts +0 -51
- package/lib/types/common/wayfinder/wayfinder.d.ts +0 -257
- package/lib/types/types/wayfinder.d.ts +0 -66
|
@@ -1,21 +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 { RoutingStrategy } from '../../../../types/wayfinder.js';
|
|
17
|
-
export declare class RandomRoutingStrategy implements RoutingStrategy {
|
|
18
|
-
selectGateway({ gateways }: {
|
|
19
|
-
gateways: URL[];
|
|
20
|
-
}): Promise<URL>;
|
|
21
|
-
}
|
|
@@ -1,29 +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 { Logger } from '../../../../common/logger.js';
|
|
17
|
-
import { RoutingStrategy } from '../../../../types/wayfinder.js';
|
|
18
|
-
export declare class RoundRobinRoutingStrategy implements RoutingStrategy {
|
|
19
|
-
private gateways;
|
|
20
|
-
private currentIndex;
|
|
21
|
-
private logger;
|
|
22
|
-
constructor({ gateways, logger, }: {
|
|
23
|
-
gateways: URL[];
|
|
24
|
-
logger?: Logger;
|
|
25
|
-
});
|
|
26
|
-
selectGateway({ gateways, }?: {
|
|
27
|
-
gateways?: URL[];
|
|
28
|
-
}): Promise<URL>;
|
|
29
|
-
}
|
|
@@ -1,29 +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 { RoutingStrategy } from '../../../../types/wayfinder.js';
|
|
17
|
-
import { Logger } from '../../../logger.js';
|
|
18
|
-
export declare class StaticRoutingStrategy implements RoutingStrategy {
|
|
19
|
-
readonly name = "static";
|
|
20
|
-
private gateway;
|
|
21
|
-
private logger;
|
|
22
|
-
constructor({ gateway, logger, }: {
|
|
23
|
-
gateway: string;
|
|
24
|
-
logger?: Logger;
|
|
25
|
-
});
|
|
26
|
-
selectGateway({ gateways, }?: {
|
|
27
|
-
gateways?: URL[];
|
|
28
|
-
}): Promise<URL>;
|
|
29
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { DataRootProvider, DataStream, DataVerificationStrategy } from '../../../../types/wayfinder.js';
|
|
2
|
-
export declare const convertDataStreamToDataRoot: ({ dataStream, }: {
|
|
3
|
-
dataStream: DataStream;
|
|
4
|
-
}) => Promise<string>;
|
|
5
|
-
export declare class DataRootVerificationStrategy implements DataVerificationStrategy {
|
|
6
|
-
private readonly trustedDataRootProvider;
|
|
7
|
-
constructor({ trustedDataRootProvider, }: {
|
|
8
|
-
trustedDataRootProvider: DataRootProvider;
|
|
9
|
-
});
|
|
10
|
-
verifyData({ data, txId, }: {
|
|
11
|
-
data: DataStream;
|
|
12
|
-
txId: string;
|
|
13
|
-
}): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* - when you get a signature of a data item, you can only verify the owner
|
|
17
|
-
* - you still need to verify it's going back to the bundle, unpack it, and verify the data item exists at the offset
|
|
18
|
-
* - 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
|
|
19
|
-
* - 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
|
|
20
|
-
*
|
|
21
|
-
* Composite verifier - you'll want to be very efficient with streams
|
|
22
|
-
* - hash verifier
|
|
23
|
-
* - parent chunks verifier --> for any range of data within a single transaction, tell me that it's correct
|
|
24
|
-
* - signature verifier
|
|
25
|
-
* - offset verifier
|
|
26
|
-
* - data item verifier
|
|
27
|
-
*/
|
|
@@ -1,26 +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 { DataHashProvider, DataStream, DataVerificationStrategy } from '../../../../types/wayfinder.js';
|
|
17
|
-
export declare class HashVerificationStrategy implements DataVerificationStrategy {
|
|
18
|
-
private readonly trustedHashProvider;
|
|
19
|
-
constructor({ trustedHashProvider, }: {
|
|
20
|
-
trustedHashProvider: DataHashProvider;
|
|
21
|
-
});
|
|
22
|
-
verifyData({ data, txId, }: {
|
|
23
|
-
data: DataStream;
|
|
24
|
-
txId: string;
|
|
25
|
-
}): Promise<void>;
|
|
26
|
-
}
|
|
@@ -1,51 +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 { DataHashProvider, DataRootProvider } from '../../../types/wayfinder.js';
|
|
17
|
-
import { GatewaysProvider } from '../../../types/wayfinder.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
|
-
*/
|
|
@@ -1,257 +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 'eventemitter3';
|
|
17
|
-
import { DataVerificationStrategy, GatewaysProvider, RoutingStrategy } from '../../types/wayfinder.js';
|
|
18
|
-
import { Logger } from '../logger.js';
|
|
19
|
-
type WayfinderHttpClient = typeof fetch;
|
|
20
|
-
export declare const arnsRegex: RegExp;
|
|
21
|
-
export declare const txIdRegex: RegExp;
|
|
22
|
-
/**
|
|
23
|
-
* Core function that converts a wayfinder url to the proper ar-io gateway URL
|
|
24
|
-
* @param originalUrl - the wayfinder url to resolve
|
|
25
|
-
* @param selectedGateway - the target gateway to resolve the url against
|
|
26
|
-
* @returns the resolved url that can be used to make a request
|
|
27
|
-
*/
|
|
28
|
-
export declare const resolveWayfinderUrl: ({ originalUrl, selectedGateway, logger, }: {
|
|
29
|
-
originalUrl: string | URL;
|
|
30
|
-
selectedGateway: URL;
|
|
31
|
-
logger?: Logger;
|
|
32
|
-
}) => URL;
|
|
33
|
-
/**
|
|
34
|
-
* Wayfinder event emitter with verification events
|
|
35
|
-
*/
|
|
36
|
-
export type WayfinderEvent = {
|
|
37
|
-
'verification-succeeded': {
|
|
38
|
-
txId: string;
|
|
39
|
-
};
|
|
40
|
-
'verification-failed': Error;
|
|
41
|
-
'verification-skipped': {
|
|
42
|
-
originalUrl: string;
|
|
43
|
-
};
|
|
44
|
-
'verification-progress': {
|
|
45
|
-
txId: string;
|
|
46
|
-
processedBytes: number;
|
|
47
|
-
totalBytes: number;
|
|
48
|
-
};
|
|
49
|
-
'routing-started': {
|
|
50
|
-
originalUrl: string;
|
|
51
|
-
};
|
|
52
|
-
'routing-skipped': {
|
|
53
|
-
originalUrl: string;
|
|
54
|
-
};
|
|
55
|
-
'routing-succeeded': {
|
|
56
|
-
originalUrl: string;
|
|
57
|
-
selectedGateway: string;
|
|
58
|
-
redirectUrl: string;
|
|
59
|
-
};
|
|
60
|
-
'routing-failed': Error;
|
|
61
|
-
'identified-transaction-id': {
|
|
62
|
-
originalUrl: string;
|
|
63
|
-
selectedGateway: string;
|
|
64
|
-
txId: string;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
export interface WayfinderEventArgs {
|
|
68
|
-
onVerificationSucceeded?: (payload: WayfinderEvent['verification-succeeded']) => void;
|
|
69
|
-
onVerificationFailed?: (payload: WayfinderEvent['verification-failed']) => void;
|
|
70
|
-
onVerificationProgress?: (payload: WayfinderEvent['verification-progress']) => void;
|
|
71
|
-
}
|
|
72
|
-
export declare class WayfinderEmitter extends EventEmitter<WayfinderEvent> {
|
|
73
|
-
constructor({ onVerificationSucceeded, onVerificationFailed, onVerificationProgress, }?: WayfinderEventArgs);
|
|
74
|
-
}
|
|
75
|
-
export declare function tapAndVerifyReadableStream({ originalStream, contentLength, verifyData, txId, emitter, strict, }: {
|
|
76
|
-
originalStream: ReadableStream;
|
|
77
|
-
contentLength: number;
|
|
78
|
-
verifyData: DataVerificationStrategy['verifyData'];
|
|
79
|
-
txId: string;
|
|
80
|
-
emitter?: WayfinderEmitter;
|
|
81
|
-
strict?: boolean;
|
|
82
|
-
}): ReadableStream;
|
|
83
|
-
/**
|
|
84
|
-
* Gets the sandbox hash for a given transaction id
|
|
85
|
-
*/
|
|
86
|
-
export declare function sandboxFromId(id: string): string;
|
|
87
|
-
/**
|
|
88
|
-
* Creates a wrapped fetch function that supports ar:// protocol
|
|
89
|
-
*
|
|
90
|
-
* This function leverages a Proxy to intercept calls to fetch
|
|
91
|
-
* and redirects them to the target gateway using the resolveUrl function.
|
|
92
|
-
*
|
|
93
|
-
* Any URLs provided that are not wayfinder urls will be passed directly to fetch.
|
|
94
|
-
*
|
|
95
|
-
* @param resolveUrl - the function to construct the redirect url for ar:// requests
|
|
96
|
-
* @returns a wrapped fetch function that supports ar:// protocol and always returns Response
|
|
97
|
-
*/
|
|
98
|
-
export declare const createWayfinderClient: ({ resolveUrl, verifyData, selectGateway, emitter, logger, strict, }: {
|
|
99
|
-
selectGateway: () => Promise<URL>;
|
|
100
|
-
resolveUrl: (params: {
|
|
101
|
-
originalUrl: string | URL;
|
|
102
|
-
selectedGateway: URL;
|
|
103
|
-
logger?: Logger;
|
|
104
|
-
}) => URL;
|
|
105
|
-
verifyData?: DataVerificationStrategy["verifyData"];
|
|
106
|
-
logger?: Logger;
|
|
107
|
-
emitter?: WayfinderEmitter;
|
|
108
|
-
strict?: boolean;
|
|
109
|
-
}) => (url: string, init?: RequestInit) => Promise<Response>;
|
|
110
|
-
/**
|
|
111
|
-
* The main class for the wayfinder
|
|
112
|
-
*/
|
|
113
|
-
export declare class Wayfinder {
|
|
114
|
-
/**
|
|
115
|
-
* The gateways provider is responsible for providing the list of gateways to use for routing requests.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* const wayfinder = new Wayfinder({
|
|
119
|
-
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
120
|
-
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
121
|
-
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
122
|
-
* }),
|
|
123
|
-
* });
|
|
124
|
-
*/
|
|
125
|
-
readonly gatewaysProvider: GatewaysProvider;
|
|
126
|
-
/**
|
|
127
|
-
* The routing strategy to use when routing requests.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* const wayfinder = new Wayfinder({
|
|
131
|
-
* strategy: new FastestPingStrategy({
|
|
132
|
-
* timeoutMs: 1000,
|
|
133
|
-
* }),
|
|
134
|
-
* });
|
|
135
|
-
*/
|
|
136
|
-
readonly routingStrategy: RoutingStrategy;
|
|
137
|
-
/**
|
|
138
|
-
* A helper function that resolves the redirect url for ar:// requests to a target gateway.
|
|
139
|
-
*
|
|
140
|
-
* Note: no verification is done when resolving an ar://<path> url to a wayfinder route.
|
|
141
|
-
* In order to verify the data, you must use the `request` function or request the data and
|
|
142
|
-
* verify it yourself via the `verifyData` function.
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* const { resolveUrl } = new Wayfinder();
|
|
146
|
-
*
|
|
147
|
-
* // returns the redirected URL based on the routing strategy and the original url
|
|
148
|
-
* const redirectUrl = await resolveUrl({ originalUrl: 'ar://example' });
|
|
149
|
-
*
|
|
150
|
-
* window.open(redirectUrl.toString(), '_blank');
|
|
151
|
-
*/
|
|
152
|
-
readonly resolveUrl: (params: {
|
|
153
|
-
originalUrl: string;
|
|
154
|
-
logger?: Logger;
|
|
155
|
-
}) => Promise<URL>;
|
|
156
|
-
/**
|
|
157
|
-
* A wrapped fetch function that supports ar:// protocol. If a verification strategy is provided,
|
|
158
|
-
* the request will be verified and events will be emitted as the request is processed.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* const wayfinder = new Wayfinder({
|
|
162
|
-
* verificationStrategy: new HashVerificationStrategy({
|
|
163
|
-
* trustedHashProvider: new TrustedGatewaysHashProvider({
|
|
164
|
-
* gatewaysProvider: new StaticGatewaysProvider({
|
|
165
|
-
* gateways: ['https://permagate.io'],
|
|
166
|
-
* }),
|
|
167
|
-
* }),
|
|
168
|
-
* }),
|
|
169
|
-
* })
|
|
170
|
-
*
|
|
171
|
-
* // request an arns name
|
|
172
|
-
* const response = await wayfinder.request('ar://ardrive')
|
|
173
|
-
*
|
|
174
|
-
* // request a transaction id
|
|
175
|
-
* const response = await wayfinder.request('ar://1234567890')
|
|
176
|
-
*
|
|
177
|
-
* // Set strict mode to true to make verification blocking
|
|
178
|
-
* const wayfinder = new Wayfinder({
|
|
179
|
-
* strict: true,
|
|
180
|
-
* });
|
|
181
|
-
*
|
|
182
|
-
* // This will throw an error if verification fails
|
|
183
|
-
* try {
|
|
184
|
-
* const response = await wayfinder.request('ar://1234567890');
|
|
185
|
-
* } catch (error) {
|
|
186
|
-
* console.error('Verification failed', error);
|
|
187
|
-
* }
|
|
188
|
-
*/
|
|
189
|
-
readonly request: WayfinderHttpClient;
|
|
190
|
-
/**
|
|
191
|
-
* The function that verifies the data hash for a given transaction id.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* const wayfinder = new Wayfinder({
|
|
195
|
-
* verifyData: (data, txId) => {
|
|
196
|
-
* // some custom verification logic
|
|
197
|
-
* return true;
|
|
198
|
-
* },
|
|
199
|
-
* });
|
|
200
|
-
*/
|
|
201
|
-
readonly verifyData: DataVerificationStrategy['verifyData'];
|
|
202
|
-
/**
|
|
203
|
-
* Whether verification should be strict (blocking) or not.
|
|
204
|
-
* If true, verification failures will cause requests to fail.
|
|
205
|
-
* If false, verification will be performed asynchronously and failures will only emit events.
|
|
206
|
-
*/
|
|
207
|
-
readonly strict: boolean;
|
|
208
|
-
/**
|
|
209
|
-
* The event emitter for wayfinder that emits verification events.
|
|
210
|
-
*
|
|
211
|
-
* const wayfinder = new Wayfinder()
|
|
212
|
-
*
|
|
213
|
-
* wayfinder.emitter.on('verification-succeeded', (event) => {
|
|
214
|
-
* console.log('Verification passed!', event);
|
|
215
|
-
* })
|
|
216
|
-
*
|
|
217
|
-
* wayfinder.emitter.on('verification-failed', (event) => {
|
|
218
|
-
* console.log('Verification failed!', event);
|
|
219
|
-
* })
|
|
220
|
-
*
|
|
221
|
-
* or implement the events interface and pass it in, using callback functions
|
|
222
|
-
*
|
|
223
|
-
* const wayfinder = new Wayfinder({
|
|
224
|
-
* events: {
|
|
225
|
-
* onVerificationPassed: (event) => {
|
|
226
|
-
* console.log('Verification passed!', event);
|
|
227
|
-
* },
|
|
228
|
-
* onVerificationFailed: (event) => {
|
|
229
|
-
* console.log('Verification failed!', event);
|
|
230
|
-
* },
|
|
231
|
-
* onVerificationProgress: (event) => {
|
|
232
|
-
* console.log('Verification progress!', event);
|
|
233
|
-
* },
|
|
234
|
-
* }
|
|
235
|
-
* })
|
|
236
|
-
*
|
|
237
|
-
* const response = await wayfind('ar://example');
|
|
238
|
-
*/
|
|
239
|
-
readonly emitter: WayfinderEmitter;
|
|
240
|
-
/**
|
|
241
|
-
* The constructor for the wayfinder
|
|
242
|
-
* @param routingStrategy - the routing strategy to use for requests
|
|
243
|
-
* @param verificationStrategy - the verification strategy to use for requests
|
|
244
|
-
* @param gatewaysProvider - the gateways provider to use for routing requests
|
|
245
|
-
* @param logger - the logger to use for logging
|
|
246
|
-
* @param strict - if true, verification will be blocking and will fail requests if verification fails; if false, verification will be non-blocking
|
|
247
|
-
*/
|
|
248
|
-
constructor({ logger, gatewaysProvider, routingStrategy, verificationStrategy, events, strict, }?: {
|
|
249
|
-
routingStrategy?: RoutingStrategy;
|
|
250
|
-
gatewaysProvider?: GatewaysProvider;
|
|
251
|
-
verificationStrategy?: DataVerificationStrategy;
|
|
252
|
-
logger?: Logger;
|
|
253
|
-
events?: WayfinderEventArgs;
|
|
254
|
-
strict?: boolean;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
export {};
|
|
@@ -1,66 +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
|
-
export interface RoutingStrategy {
|
|
17
|
-
selectGateway: ({ gateways }: {
|
|
18
|
-
gateways: URL[];
|
|
19
|
-
}) => Promise<URL>;
|
|
20
|
-
}
|
|
21
|
-
export interface GatewaysProvider {
|
|
22
|
-
getGateways: () => Promise<URL[]>;
|
|
23
|
-
}
|
|
24
|
-
export type DataStream = AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>;
|
|
25
|
-
export interface DataVerificationStrategy {
|
|
26
|
-
/**
|
|
27
|
-
* Verifies the provided data for a given txId
|
|
28
|
-
*
|
|
29
|
-
* 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.
|
|
30
|
-
*
|
|
31
|
-
* The interface is intended to be vague in order to support various degrees of verification.
|
|
32
|
-
*
|
|
33
|
-
* @param data - The data to verify
|
|
34
|
-
* @param txId - The txId of the data
|
|
35
|
-
* @returns the hash of the data
|
|
36
|
-
*/
|
|
37
|
-
verifyData: ({ data, txId, }: {
|
|
38
|
-
data: DataStream;
|
|
39
|
-
txId: string;
|
|
40
|
-
}) => Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
export interface DataHashProvider {
|
|
43
|
-
/**
|
|
44
|
-
* Returns a hash for the provided txId using the specified algorithm.
|
|
45
|
-
*
|
|
46
|
-
* @param txId - The txId of the data
|
|
47
|
-
* @returns the hash of the data
|
|
48
|
-
*/
|
|
49
|
-
getHash: ({ txId, }: {
|
|
50
|
-
txId: string;
|
|
51
|
-
}) => Promise<{
|
|
52
|
-
hash: string;
|
|
53
|
-
algorithm: 'sha256';
|
|
54
|
-
}>;
|
|
55
|
-
}
|
|
56
|
-
export interface DataRootProvider {
|
|
57
|
-
/**
|
|
58
|
-
* Returns the data root for the provided txId
|
|
59
|
-
*
|
|
60
|
-
* @param txId - The txId of the data
|
|
61
|
-
* @returns the data root of the data
|
|
62
|
-
*/
|
|
63
|
-
getDataRoot: ({ txId }: {
|
|
64
|
-
txId: string;
|
|
65
|
-
}) => Promise<string>;
|
|
66
|
-
}
|