@ar.io/sdk 3.10.2 → 3.11.0-alpha.10

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 (114) hide show
  1. package/README.md +52 -0
  2. package/bundles/web.bundle.min.js +140 -132
  3. package/lib/cjs/cli/cli.js +137 -122
  4. package/lib/cjs/cli/commands/readCommands.js +6 -0
  5. package/lib/cjs/cli/options.js +12 -0
  6. package/lib/cjs/cli/utils.js +40 -11
  7. package/lib/cjs/common/ant-versions.js +5 -5
  8. package/lib/cjs/common/ant.js +5 -5
  9. package/lib/cjs/common/index.js +2 -0
  10. package/lib/cjs/common/io.js +106 -1
  11. package/lib/cjs/common/turbo.js +208 -0
  12. package/lib/cjs/common/wayfinder/gateways/trusted-gateways.js +106 -0
  13. package/lib/cjs/common/wayfinder/gateways.js +86 -0
  14. package/lib/cjs/common/wayfinder/index.js +44 -0
  15. package/lib/cjs/common/wayfinder/routers/priority.js +29 -0
  16. package/lib/cjs/common/wayfinder/routers/priority.test.js +155 -0
  17. package/lib/cjs/common/wayfinder/routers/random.js +23 -0
  18. package/lib/cjs/common/wayfinder/routers/random.test.js +25 -0
  19. package/lib/cjs/common/wayfinder/routers/simple-cache.js +25 -0
  20. package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +41 -0
  21. package/lib/cjs/common/wayfinder/routers/static.js +14 -0
  22. package/lib/cjs/common/wayfinder/routers/static.test.js +14 -0
  23. package/lib/cjs/common/wayfinder/verification/data-root-verifier.js +139 -0
  24. package/lib/cjs/common/wayfinder/verification/hash-verifier.js +50 -0
  25. package/lib/cjs/common/wayfinder/wayfinder.js +596 -0
  26. package/lib/cjs/common/wayfinder/wayfinder.test.js +500 -0
  27. package/lib/cjs/types/ant.js +12 -1
  28. package/lib/cjs/types/index.js +1 -0
  29. package/lib/cjs/types/io.js +1 -1
  30. package/lib/cjs/types/wayfinder.js +3 -0
  31. package/lib/cjs/utils/ao.js +42 -0
  32. package/lib/cjs/utils/hash.js +56 -0
  33. package/lib/cjs/utils/random.js +30 -0
  34. package/lib/cjs/utils/url.js +28 -0
  35. package/lib/cjs/utils/url.test.js +24 -0
  36. package/lib/cjs/utils/utils.test.js +8 -8
  37. package/lib/cjs/version.js +1 -1
  38. package/lib/cjs/web/index.js +3 -1
  39. package/lib/esm/cli/cli.js +138 -123
  40. package/lib/esm/cli/commands/readCommands.js +5 -0
  41. package/lib/esm/cli/options.js +12 -0
  42. package/lib/esm/cli/utils.js +39 -11
  43. package/lib/esm/common/ant-versions.js +5 -5
  44. package/lib/esm/common/ant.js +5 -5
  45. package/lib/esm/common/index.js +2 -0
  46. package/lib/esm/common/io.js +106 -1
  47. package/lib/esm/common/turbo.js +200 -0
  48. package/lib/esm/common/wayfinder/gateways/trusted-gateways.js +102 -0
  49. package/lib/esm/common/wayfinder/gateways.js +80 -0
  50. package/lib/esm/common/wayfinder/index.js +28 -0
  51. package/lib/esm/common/wayfinder/routers/priority.js +25 -0
  52. package/lib/esm/common/wayfinder/routers/priority.test.js +153 -0
  53. package/lib/esm/common/wayfinder/routers/random.js +19 -0
  54. package/lib/esm/common/wayfinder/routers/random.test.js +23 -0
  55. package/lib/esm/common/wayfinder/routers/simple-cache.js +21 -0
  56. package/lib/esm/common/wayfinder/routers/simple-cache.test.js +39 -0
  57. package/lib/esm/common/wayfinder/routers/static.js +10 -0
  58. package/lib/esm/common/wayfinder/routers/static.test.js +12 -0
  59. package/lib/esm/common/wayfinder/verification/data-root-verifier.js +130 -0
  60. package/lib/esm/common/wayfinder/verification/hash-verifier.js +46 -0
  61. package/lib/esm/common/wayfinder/wayfinder.js +584 -0
  62. package/lib/esm/common/wayfinder/wayfinder.test.js +495 -0
  63. package/lib/esm/types/ant.js +11 -0
  64. package/lib/esm/types/index.js +1 -0
  65. package/lib/esm/types/io.js +1 -1
  66. package/lib/esm/types/wayfinder.js +2 -0
  67. package/lib/esm/utils/ao.js +42 -0
  68. package/lib/esm/utils/hash.js +50 -0
  69. package/lib/esm/utils/random.js +26 -0
  70. package/lib/esm/utils/url.js +24 -0
  71. package/lib/esm/utils/url.test.js +19 -0
  72. package/lib/esm/utils/utils.test.js +1 -1
  73. package/lib/esm/version.js +1 -1
  74. package/lib/esm/web/index.js +1 -1
  75. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  76. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  77. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  78. package/lib/types/cli/commands/readCommands.d.ts +2 -0
  79. package/lib/types/cli/commands/transfer.d.ts +3 -3
  80. package/lib/types/cli/options.d.ts +9 -0
  81. package/lib/types/cli/types.d.ts +3 -0
  82. package/lib/types/cli/utils.d.ts +4 -0
  83. package/lib/types/common/ant-versions.d.ts +3 -6
  84. package/lib/types/common/index.d.ts +1 -0
  85. package/lib/types/common/io.d.ts +13 -8
  86. package/lib/types/common/turbo.d.ts +62 -0
  87. package/lib/types/common/wayfinder/gateways/trusted-gateways.d.ts +51 -0
  88. package/lib/types/common/wayfinder/gateways.d.ts +53 -0
  89. package/lib/types/common/wayfinder/index.d.ts +23 -0
  90. package/lib/types/common/wayfinder/routers/priority.d.ts +29 -0
  91. package/lib/types/common/wayfinder/routers/priority.test.d.ts +1 -0
  92. package/lib/types/common/wayfinder/routers/random.d.ts +27 -0
  93. package/lib/types/common/wayfinder/routers/random.test.d.ts +1 -0
  94. package/lib/types/common/wayfinder/routers/simple-cache.d.ts +28 -0
  95. package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +1 -0
  96. package/lib/types/common/wayfinder/routers/static.d.ts +24 -0
  97. package/lib/types/common/wayfinder/routers/static.test.d.ts +1 -0
  98. package/lib/types/common/wayfinder/verification/data-root-verifier.d.ts +31 -0
  99. package/lib/types/common/wayfinder/verification/hash-verifier.d.ts +27 -0
  100. package/lib/types/common/wayfinder/wayfinder.d.ts +265 -0
  101. package/lib/types/common/wayfinder/wayfinder.test.d.ts +1 -0
  102. package/lib/types/types/ant.d.ts +53 -1
  103. package/lib/types/types/common.d.ts +7 -2
  104. package/lib/types/types/index.d.ts +1 -0
  105. package/lib/types/types/io.d.ts +23 -6
  106. package/lib/types/types/wayfinder.d.ts +62 -0
  107. package/lib/types/utils/ao.d.ts +1 -12
  108. package/lib/types/utils/hash.d.ts +4 -0
  109. package/lib/types/utils/random.d.ts +7 -0
  110. package/lib/types/utils/url.d.ts +19 -0
  111. package/lib/types/utils/url.test.d.ts +1 -0
  112. package/lib/types/version.d.ts +1 -1
  113. package/lib/types/web/index.d.ts +1 -1
  114. package/package.json +5 -3
@@ -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
+ }
@@ -0,0 +1,265 @@
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
+ */
@@ -0,0 +1 @@
1
+ export {};
@@ -127,11 +127,63 @@ export declare const AntStateSchema: z.ZodObject<{
127
127
  Initialized: boolean;
128
128
  }>;
129
129
  export type AoANTState = z.infer<typeof AntStateSchema>;
130
+ export declare const SpawnANTStateSchema: z.ZodObject<{
131
+ name: z.ZodString;
132
+ ticker: z.ZodString;
133
+ description: z.ZodString;
134
+ keywords: z.ZodArray<z.ZodString, "many">;
135
+ owner: z.ZodString;
136
+ controllers: z.ZodArray<z.ZodString, "many">;
137
+ records: z.ZodRecord<z.ZodString, z.ZodObject<{
138
+ transactionId: z.ZodEffects<z.ZodString, string, string>;
139
+ ttlSeconds: z.ZodNumber;
140
+ priority: z.ZodOptional<z.ZodNumber>;
141
+ }, "strip", z.ZodTypeAny, {
142
+ transactionId: string;
143
+ ttlSeconds: number;
144
+ priority?: number | undefined;
145
+ }, {
146
+ transactionId: string;
147
+ ttlSeconds: number;
148
+ priority?: number | undefined;
149
+ }>>;
150
+ balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
151
+ logo: z.ZodEffects<z.ZodString, string, string>;
152
+ }, "strip", z.ZodTypeAny, {
153
+ description: string;
154
+ name: string;
155
+ ticker: string;
156
+ keywords: string[];
157
+ owner: string;
158
+ controllers: string[];
159
+ records: Record<string, {
160
+ transactionId: string;
161
+ ttlSeconds: number;
162
+ priority?: number | undefined;
163
+ }>;
164
+ balances: Record<string, number>;
165
+ logo: string;
166
+ }, {
167
+ description: string;
168
+ name: string;
169
+ ticker: string;
170
+ keywords: string[];
171
+ owner: string;
172
+ controllers: string[];
173
+ records: Record<string, {
174
+ transactionId: string;
175
+ ttlSeconds: number;
176
+ priority?: number | undefined;
177
+ }>;
178
+ balances: Record<string, number>;
179
+ logo: string;
180
+ }>;
181
+ export type SpawnANTState = z.infer<typeof SpawnANTStateSchema>;
130
182
  export declare const AntReadHandlers: readonly ["balance", "balances", "totalSupply", "info", "controllers", "record", "records", "state"];
131
183
  export type AoANTReadHandler = (typeof AntReadHandlers)[number];
132
184
  export declare const AntWriteHandlers: readonly ["_eval", "_default", "transfer", "addController", "removeController", "setRecord", "removeRecord", "setName", "setTicker", "setDescription", "setKeywords", "setLogo", "initializeState", "releaseName", "reassignName", "approvePrimaryName", "removePrimaryNames"];
133
185
  export type AoANTWriteHandler = (typeof AntWriteHandlers)[number];
134
- export declare const AntHandlerNames: ("balance" | "balances" | "totalSupply" | "info" | "controllers" | "record" | "records" | "state" | "_eval" | "_default" | "transfer" | "addController" | "removeController" | "setRecord" | "removeRecord" | "setName" | "setTicker" | "setDescription" | "setKeywords" | "setLogo" | "initializeState" | "releaseName" | "reassignName" | "approvePrimaryName" | "removePrimaryNames")[];
186
+ export declare const AntHandlerNames: ("controllers" | "records" | "balances" | "balance" | "totalSupply" | "info" | "record" | "state" | "_eval" | "_default" | "transfer" | "addController" | "removeController" | "setRecord" | "removeRecord" | "setName" | "setTicker" | "setDescription" | "setKeywords" | "setLogo" | "initializeState" | "releaseName" | "reassignName" | "approvePrimaryName" | "removePrimaryNames")[];
135
187
  export type AoANTHandler = AoANTWriteHandler | AoANTReadHandler;
136
188
  export declare const AntHandlersSchema: z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>;
137
189
  export declare const AntInfoSchema: z.ZodObject<{
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Signer } from '@dha-team/arbundles';
16
+ import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, Signer } from '@dha-team/arbundles';
17
17
  import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
18
18
  import Arweave from 'arweave';
19
19
  import { AoSigner } from './token.js';
@@ -26,6 +26,10 @@ export type ProcessId = string;
26
26
  export type OptionalArweave<T = NonNullable<unknown>> = {
27
27
  arweave?: Arweave;
28
28
  } & T;
29
+ export type OptionalPaymentUrl<T = NonNullable<unknown>> = {
30
+ paymentUrl?: string;
31
+ } & T;
32
+ export type TurboArNSSigner = EthereumSigner | InjectedEthereumSigner | ArweaveSigner | ArconnectSigner | Window['arweaveWallet'];
29
33
  export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
30
34
  export type WithSigner<T = NonNullable<unknown>> = {
31
35
  signer: ContractSigner;
@@ -44,8 +48,9 @@ export type WriteOptions = {
44
48
  }[];
45
49
  };
46
50
  export type WriteParameters<Input> = WithSigner<Required<ReadParameters<Input>>>;
47
- export type AoMessageResult = {
51
+ export type AoMessageResult<T = Record<string, string | number | boolean | null>> = {
48
52
  id: string;
53
+ result?: T;
49
54
  };
50
55
  export type AoPrimaryNameRequest = {
51
56
  name: string;
@@ -19,3 +19,4 @@ export * from './common.js';
19
19
  export * from './faucet.js';
20
20
  export * from './io.js';
21
21
  export * from './token.js';
22
+ export * from './wayfinder.js';
@@ -310,7 +310,7 @@ export type AoTokenCostParams = {
310
310
  quantity?: number;
311
311
  fromAddress?: WalletAddress;
312
312
  };
313
- export declare const fundFromOptions: readonly ["balance", "stakes", "any"];
313
+ export declare const fundFromOptions: readonly ["balance", "stakes", "any", "turbo"];
314
314
  export type FundFrom = (typeof fundFromOptions)[number];
315
315
  export declare const isValidFundFrom: (fundFrom: string) => fundFrom is FundFrom;
316
316
  export type AoGetCostDetailsParams = AoTokenCostParams & {
@@ -338,6 +338,7 @@ export type CostDetailsResult = {
338
338
  basePrice: number;
339
339
  };
340
340
  fundingPlan?: AoFundingPlan;
341
+ wincQty?: string;
341
342
  };
342
343
  export type AoGetVaultParams = {
343
344
  address: WalletAddress;
@@ -419,7 +420,23 @@ export type DemandFactorSettings = {
419
420
  maxPeriodsAtMinDemandFactor: number;
420
421
  criteria: string;
421
422
  };
422
- export interface AoARIORead {
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 {
439
+ process: AOProcess;
423
440
  getInfo(): Promise<{
424
441
  Ticker: string;
425
442
  Name: string;
@@ -523,10 +540,10 @@ export interface AoARIOWrite extends AoARIORead {
523
540
  reportTxId: TransactionId;
524
541
  failedGateways: WalletAddress[];
525
542
  }>;
526
- buyRecord: AoWriteAction<AoBuyRecordParams>;
527
- upgradeRecord: AoWriteAction<AoArNSPurchaseParams>;
528
- extendLease: AoWriteAction<AoExtendLeaseParams>;
529
- increaseUndernameLimit: AoWriteAction<AoIncreaseUndernameLimitParams>;
543
+ buyRecord: AoWriteAction<AoBuyRecordParams, AoMessageResult>;
544
+ upgradeRecord: AoWriteAction<AoArNSPurchaseParams, AoMessageResult>;
545
+ extendLease: AoWriteAction<AoExtendLeaseParams, AoMessageResult>;
546
+ increaseUndernameLimit: AoWriteAction<AoIncreaseUndernameLimitParams, AoMessageResult>;
530
547
  cancelWithdrawal: AoWriteAction<{
531
548
  gatewayAddress?: WalletAddress;
532
549
  vaultId: string;
@@ -0,0 +1,62 @@
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
+ }
@@ -1,18 +1,7 @@
1
1
  import Arweave from 'arweave';
2
2
  import { Logger } from '../common/index.js';
3
- import { AoANTRecord } from '../types/ant.js';
3
+ import { SpawnANTState } from '../types/ant.js';
4
4
  import { AoClient, AoEpochData, AoEpochDistributed, AoSigner, ContractSigner, WalletAddress } from '../types/index.js';
5
- export type SpawnANTState = {
6
- owner: WalletAddress;
7
- controllers: WalletAddress[];
8
- name: string;
9
- description: string;
10
- keywords: string[];
11
- ticker: string;
12
- records: Record<string, AoANTRecord>;
13
- balances: Record<WalletAddress, number>;
14
- logo: string;
15
- };
16
5
  export type SpawnANTParams = {
17
6
  signer: AoSigner;
18
7
  module?: string;
@@ -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;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Cryptographically secure helper for randomness, does not support seeding
3
+ * @param min - the minimum value
4
+ * @param max - the maximum value
5
+ * @returns a random integer between min and max
6
+ */
7
+ export declare const randomInt: (min: number, max: number) => number;
@@ -0,0 +1,19 @@
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 declare const urlWithSearchParams: ({ baseUrl, params, }: {
17
+ baseUrl: string;
18
+ params: Record<string, string | number | boolean | null | undefined>;
19
+ }) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.10.1";
16
+ export declare const version = "3.11.0-alpha.9";
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { ArweaveSigner, ArconnectSigner } from '@dha-team/arbundles';
16
+ export { ArweaveSigner, ArconnectSigner, InjectedEthereumSigner, EthereumSigner, } from '@dha-team/arbundles';
17
17
  export * from '../types/index.js';
18
18
  export * from '../common/index.js';
19
19
  export * from '../constants.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.10.2",
3
+ "version": "3.11.0-alpha.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -72,7 +72,7 @@
72
72
  "test:cjs": "yarn build:cjs && yarn link && cd ./tests/e2e/cjs && yarn && yarn test",
73
73
  "test:esm": "yarn build:esm && yarn link && cd ./tests/e2e/esm && yarn && yarn test",
74
74
  "test:web": "yarn build:esm && yarn link && cd ./tests/e2e/web && yarn && yarn test",
75
- "test:unit": "node --import=./register.mjs --test --test-reporter=spec src/**/**.test.ts",
75
+ "test:unit": "node --import=./register.mjs --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
76
76
  "test:link": "yarn build && yarn link",
77
77
  "test:e2e": "yarn test:cjs && yarn test:esm && yarn test:web",
78
78
  "test:integration": "yarn build:esm && yarn link && cd ./tests/integration && yarn && yarn test",
@@ -91,8 +91,9 @@
91
91
  "@semantic-release/exec": "^6.0.3",
92
92
  "@semantic-release/git": "^10.0.1",
93
93
  "@semantic-release/npm": "^11.0.3",
94
+ "@swc/core": "^1.11.22",
94
95
  "@trivago/prettier-plugin-sort-imports": "^4.2.0",
95
- "@types/node": "^20.12.12",
96
+ "@types/node": "^22.14.1",
96
97
  "@types/prompts": "^2.4.9",
97
98
  "@types/sinon": "^10.0.15",
98
99
  "@typescript-eslint/eslint-plugin": "^5.62.0",
@@ -110,6 +111,7 @@
110
111
  "eslint-plugin-n": "^16.0.1",
111
112
  "eslint-plugin-prettier": "^5.0.0",
112
113
  "eslint-plugin-promise": "^6.1.1",
114
+ "got": "^12.4.7",
113
115
  "http-server": "^14.1.1",
114
116
  "husky": "^8.0.3",
115
117
  "lint-staged": "^15.2.2",