@provablehq/sdk 0.10.0-rc → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dynamic/browser.d.ts +8 -0
- package/dist/dynamic/browser.js +8 -0
- package/dist/dynamic/node.d.ts +8 -0
- package/dist/dynamic/node.js +8 -0
- package/dist/mainnet/account.d.ts +61 -6
- package/dist/mainnet/browser.d.ts +41 -8
- package/dist/mainnet/browser.js +3699 -564
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/constants.d.ts +6 -0
- package/dist/mainnet/external-signing.d.ts +76 -0
- package/dist/mainnet/integrations/sealance/merkle-tree.d.ts +192 -0
- package/dist/mainnet/keys/keystore/error.d.ts +24 -0
- package/dist/mainnet/keys/keystore/file.d.ts +177 -0
- package/dist/mainnet/keys/keystore/interface.d.ts +161 -0
- package/dist/mainnet/keys/provider/interface.d.ts +170 -0
- package/dist/mainnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +27 -167
- package/dist/mainnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +21 -4
- package/dist/mainnet/keys/verifier/interface.d.ts +70 -0
- package/dist/mainnet/keys/verifier/memory.d.ts +37 -0
- package/dist/mainnet/models/cryptoBoxPubkey.d.ts +4 -0
- package/dist/mainnet/models/encryptedProvingRequest.d.ts +4 -0
- package/dist/mainnet/models/external-signing.d.ts +123 -0
- package/dist/mainnet/models/functionInput.d.ts +7 -0
- package/dist/mainnet/models/input/inputJSON.d.ts +1 -0
- package/dist/mainnet/models/input/inputObject.d.ts +1 -0
- package/dist/mainnet/models/keyPair.d.ts +4 -0
- package/dist/mainnet/models/output/outputJSON.d.ts +1 -0
- package/dist/mainnet/models/output/outputObject.d.ts +1 -0
- package/dist/mainnet/models/provingResponse.d.ts +48 -2
- package/dist/mainnet/models/record-provider/encryptedRecord.d.ts +58 -0
- package/dist/mainnet/models/record-provider/ownedRecord.d.ts +60 -0
- package/dist/mainnet/models/record-provider/recordSearchParams.d.ts +19 -0
- package/dist/mainnet/models/record-scanner/encryptedRecordsResult.d.ts +7 -0
- package/dist/mainnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
- package/dist/mainnet/models/record-scanner/error.d.ts +47 -0
- package/dist/mainnet/models/record-scanner/ownedFilter.d.ts +22 -0
- package/dist/mainnet/models/record-scanner/ownedRecordsResponseFilter.d.ts +42 -0
- package/dist/mainnet/models/record-scanner/ownedRecordsResult.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/recordsFilter.d.ts +35 -0
- package/dist/mainnet/models/record-scanner/recordsResponseFilter.d.ts +42 -0
- package/dist/mainnet/models/record-scanner/registrationRequest.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResponse.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResult.d.ts +9 -0
- package/dist/mainnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/mainnet/models/record-scanner/serialNumbersResult.d.ts +15 -0
- package/dist/mainnet/models/record-scanner/statusResponse.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/statusResult.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/tagsResult.d.ts +12 -0
- package/dist/mainnet/network-client.d.ts +129 -46
- package/dist/mainnet/node-polyfill.js +2 -49
- package/dist/mainnet/node-polyfill.js.map +1 -1
- package/dist/mainnet/node.d.ts +1 -0
- package/dist/mainnet/node.js +376 -4
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +538 -58
- package/dist/mainnet/record-provider.d.ts +113 -75
- package/dist/mainnet/record-scanner.d.ts +368 -0
- package/dist/mainnet/security.d.ts +62 -0
- package/dist/mainnet/utils.d.ts +1 -0
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/account.d.ts +61 -6
- package/dist/testnet/browser.d.ts +41 -8
- package/dist/testnet/browser.js +3699 -564
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/constants.d.ts +6 -0
- package/dist/testnet/external-signing.d.ts +76 -0
- package/dist/testnet/integrations/sealance/merkle-tree.d.ts +192 -0
- package/dist/testnet/keys/keystore/error.d.ts +24 -0
- package/dist/testnet/keys/keystore/file.d.ts +177 -0
- package/dist/testnet/keys/keystore/interface.d.ts +161 -0
- package/dist/testnet/keys/provider/interface.d.ts +170 -0
- package/dist/testnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +27 -167
- package/dist/testnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +21 -4
- package/dist/testnet/keys/verifier/interface.d.ts +70 -0
- package/dist/testnet/keys/verifier/memory.d.ts +37 -0
- package/dist/testnet/models/cryptoBoxPubkey.d.ts +4 -0
- package/dist/testnet/models/encryptedProvingRequest.d.ts +4 -0
- package/dist/testnet/models/external-signing.d.ts +123 -0
- package/dist/testnet/models/functionInput.d.ts +7 -0
- package/dist/testnet/models/input/inputJSON.d.ts +1 -0
- package/dist/testnet/models/input/inputObject.d.ts +1 -0
- package/dist/testnet/models/keyPair.d.ts +4 -0
- package/dist/testnet/models/output/outputJSON.d.ts +1 -0
- package/dist/testnet/models/output/outputObject.d.ts +1 -0
- package/dist/testnet/models/provingResponse.d.ts +48 -2
- package/dist/testnet/models/record-provider/encryptedRecord.d.ts +58 -0
- package/dist/testnet/models/record-provider/ownedRecord.d.ts +60 -0
- package/dist/testnet/models/record-provider/recordSearchParams.d.ts +19 -0
- package/dist/testnet/models/record-scanner/encryptedRecordsResult.d.ts +7 -0
- package/dist/testnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
- package/dist/testnet/models/record-scanner/error.d.ts +47 -0
- package/dist/testnet/models/record-scanner/ownedFilter.d.ts +22 -0
- package/dist/testnet/models/record-scanner/ownedRecordsResponseFilter.d.ts +42 -0
- package/dist/testnet/models/record-scanner/ownedRecordsResult.d.ts +13 -0
- package/dist/testnet/models/record-scanner/recordsFilter.d.ts +35 -0
- package/dist/testnet/models/record-scanner/recordsResponseFilter.d.ts +42 -0
- package/dist/testnet/models/record-scanner/registrationRequest.d.ts +13 -0
- package/dist/testnet/models/record-scanner/registrationResponse.d.ts +13 -0
- package/dist/testnet/models/record-scanner/registrationResult.d.ts +9 -0
- package/dist/testnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/testnet/models/record-scanner/serialNumbersResult.d.ts +15 -0
- package/dist/testnet/models/record-scanner/statusResponse.d.ts +13 -0
- package/dist/testnet/models/record-scanner/statusResult.d.ts +13 -0
- package/dist/testnet/models/record-scanner/tagsResult.d.ts +12 -0
- package/dist/testnet/network-client.d.ts +129 -46
- package/dist/testnet/node-polyfill.js +2 -49
- package/dist/testnet/node-polyfill.js.map +1 -1
- package/dist/testnet/node.d.ts +1 -0
- package/dist/testnet/node.js +376 -4
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +538 -58
- package/dist/testnet/record-provider.d.ts +113 -75
- package/dist/testnet/record-scanner.d.ts +368 -0
- package/dist/testnet/security.d.ts +62 -0
- package/dist/testnet/utils.d.ts +1 -0
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StatusResponse is a type that represents a response from a record scanning service's status endpoint.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const statusResponse: StatusResponse = {
|
|
6
|
+
* synced: true,
|
|
7
|
+
* percentage: 100,
|
|
8
|
+
* }
|
|
9
|
+
*/
|
|
10
|
+
export interface StatusResponse {
|
|
11
|
+
synced: boolean;
|
|
12
|
+
percentage: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
import type { StatusResponse } from "./statusResponse.js";
|
|
3
|
+
/**
|
|
4
|
+
* Success variant of status() result.
|
|
5
|
+
*
|
|
6
|
+
* @property ok - Whether the request was successful, always true for this interface variant.
|
|
7
|
+
* @property data - StatusResponse returned by the server.
|
|
8
|
+
*/
|
|
9
|
+
export interface StatusSuccess {
|
|
10
|
+
ok: true;
|
|
11
|
+
data: StatusResponse;
|
|
12
|
+
}
|
|
13
|
+
export type StatusResult = StatusSuccess | RecordScannerFailure;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Success variant of tags() result.
|
|
4
|
+
*
|
|
5
|
+
* @property ok - Whether the request was successful, always true for this interface variant.
|
|
6
|
+
* @property data - A map of tags to whether they are owned by the account.
|
|
7
|
+
*/
|
|
8
|
+
export interface TagsSuccess {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: Record<string, boolean>;
|
|
11
|
+
}
|
|
12
|
+
export type TagsResult = TagsSuccess | RecordScannerFailure;
|
|
@@ -3,7 +3,7 @@ import { BlockJSON } from "./models/blockJSON.js";
|
|
|
3
3
|
import { TransactionJSON } from "./models/transaction/transactionJSON.js";
|
|
4
4
|
import { Address, Plaintext, Program, ProvingRequest, RecordPlaintext, PrivateKey, Transaction } from "./wasm.js";
|
|
5
5
|
import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js";
|
|
6
|
-
import { ProvingResponse } from "./models/provingResponse.js";
|
|
6
|
+
import { ProvingResponse, ProvingResult } from "./models/provingResponse.js";
|
|
7
7
|
type ProgramImports = {
|
|
8
8
|
[key: string]: string | Program;
|
|
9
9
|
};
|
|
@@ -11,6 +11,35 @@ interface AleoNetworkClientOptions {
|
|
|
11
11
|
headers?: {
|
|
12
12
|
[key: string]: string;
|
|
13
13
|
};
|
|
14
|
+
proverUri?: string;
|
|
15
|
+
recordScannerUri?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Interface for the JWT data.
|
|
19
|
+
*
|
|
20
|
+
* @property jwt {string} The JWT token string.
|
|
21
|
+
* @property expiration {number} The expiration time of the JWT token in UNIX timestamp format.
|
|
22
|
+
*/
|
|
23
|
+
interface JWTData {
|
|
24
|
+
jwt: string;
|
|
25
|
+
expiration: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for submitting a proving request.
|
|
29
|
+
*
|
|
30
|
+
* @property provingRequest {ProvingRequest | string} The proving request being submitted to the network.
|
|
31
|
+
* @property url {string} The URL of the delegated proving service.
|
|
32
|
+
* @property apiKey {string} The API key used for generating a JWT.
|
|
33
|
+
* @property consumerId {string} The consumer ID associated with the API key.
|
|
34
|
+
* @property jwt {string} An optional JWT token used for authenticating with the proving service.
|
|
35
|
+
*/
|
|
36
|
+
interface DelegatedProvingParams {
|
|
37
|
+
provingRequest: ProvingRequest | string;
|
|
38
|
+
url?: string;
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
consumerId?: string;
|
|
41
|
+
jwtData?: JWTData;
|
|
42
|
+
dpsPrivacy?: boolean;
|
|
14
43
|
}
|
|
15
44
|
/**
|
|
16
45
|
* Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
|
|
@@ -23,10 +52,13 @@ interface AleoNetworkClientOptions {
|
|
|
23
52
|
*
|
|
24
53
|
* // Connection to a public beacon node
|
|
25
54
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
26
|
-
* const
|
|
55
|
+
* const apiKey = process.env.apiKey;
|
|
56
|
+
* const consumerId = process.env.consumerId;
|
|
57
|
+
* const publicNetworkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined, account);
|
|
27
58
|
*/
|
|
28
59
|
declare class AleoNetworkClient {
|
|
29
60
|
host: string;
|
|
61
|
+
private readonly baseUrl;
|
|
30
62
|
headers: {
|
|
31
63
|
[key: string]: string;
|
|
32
64
|
};
|
|
@@ -34,8 +66,13 @@ declare class AleoNetworkClient {
|
|
|
34
66
|
ctx: {
|
|
35
67
|
[key: string]: string;
|
|
36
68
|
};
|
|
37
|
-
|
|
69
|
+
verboseErrors: boolean;
|
|
38
70
|
readonly network: string;
|
|
71
|
+
apiKey?: string;
|
|
72
|
+
consumerId?: string;
|
|
73
|
+
jwtData?: JWTData;
|
|
74
|
+
proverUri?: string;
|
|
75
|
+
recordScannerUri?: string;
|
|
39
76
|
constructor(host: string, options?: AleoNetworkClientOptions);
|
|
40
77
|
/**
|
|
41
78
|
* Set an account to use in networkClient calls
|
|
@@ -44,7 +81,7 @@ declare class AleoNetworkClient {
|
|
|
44
81
|
* @example
|
|
45
82
|
* import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
46
83
|
*
|
|
47
|
-
* const networkClient = new AleoNetworkClient("
|
|
84
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
48
85
|
* const account = new Account();
|
|
49
86
|
* networkClient.setAccount(account);
|
|
50
87
|
*/
|
|
@@ -60,7 +97,6 @@ declare class AleoNetworkClient {
|
|
|
60
97
|
* Set a new host for the networkClient
|
|
61
98
|
*
|
|
62
99
|
* @param {string} host The address of a node hosting the Aleo API
|
|
63
|
-
* @param host
|
|
64
100
|
*
|
|
65
101
|
* @example
|
|
66
102
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
@@ -69,14 +105,43 @@ declare class AleoNetworkClient {
|
|
|
69
105
|
* const networkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined);
|
|
70
106
|
*
|
|
71
107
|
* // Set the host to a public node.
|
|
72
|
-
* networkClient.setHost("
|
|
108
|
+
* networkClient.setHost("https://api.provable.com/v2");
|
|
73
109
|
*/
|
|
74
110
|
setHost(host: string): void;
|
|
75
111
|
/**
|
|
76
|
-
* Set
|
|
77
|
-
*
|
|
112
|
+
* Set a new uri for a remote prover.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} proverUri The uri of the remote prover.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
118
|
+
*
|
|
119
|
+
* // Create a networkClient that connects to the provable explorer api.
|
|
120
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
121
|
+
*
|
|
122
|
+
* // Set the prover uri.
|
|
123
|
+
* networkClient.setProverUri("https://prover.provable.prove");
|
|
124
|
+
*/
|
|
125
|
+
setProverUri(proverUri: string): void;
|
|
126
|
+
/**
|
|
127
|
+
* Set a new uri for a remote record scanner.
|
|
78
128
|
*
|
|
79
|
-
* @param {
|
|
129
|
+
* @param {string} recordScannerUri The uri of the remote record scanner.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
133
|
+
*
|
|
134
|
+
* // Create a networkClient that connects to the provable explorer api.
|
|
135
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
136
|
+
*
|
|
137
|
+
* // Set the record scanner uri.
|
|
138
|
+
* networkClient.setRecordScannerUri("https://scanner.provable.scan");
|
|
139
|
+
*/
|
|
140
|
+
setRecordScannerUri(recordScannerUri: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Set verbose errors to true or false for the `AleoNetworkClient`. When set to true, if `submitTransaction` fails, the failure responses will report descriptive information as to why the transaction failed.
|
|
143
|
+
*
|
|
144
|
+
* @param {boolean} verboseErrors Set verbose error mode to true or false for the AleoNetworkClient.
|
|
80
145
|
* @example
|
|
81
146
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
82
147
|
*
|
|
@@ -84,9 +149,9 @@ declare class AleoNetworkClient {
|
|
|
84
149
|
* const networkClient = new AleoNetworkClient();
|
|
85
150
|
*
|
|
86
151
|
* // Set debug mode to true
|
|
87
|
-
* networkClient.
|
|
152
|
+
* networkClient.setVerboseTransactionErrors(true);
|
|
88
153
|
**/
|
|
89
|
-
|
|
154
|
+
setVerboseErrors(verboseErrors: boolean): void;
|
|
90
155
|
/**
|
|
91
156
|
* Set a header in the `AleoNetworkClient`s header map
|
|
92
157
|
*
|
|
@@ -147,7 +212,7 @@ declare class AleoNetworkClient {
|
|
|
147
212
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
148
213
|
*
|
|
149
214
|
* // Create a network client.
|
|
150
|
-
* const networkClient = new AleoNetworkClient("
|
|
215
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
151
216
|
* networkClient.setAccount(account);
|
|
152
217
|
*
|
|
153
218
|
* // Find specific amounts
|
|
@@ -178,7 +243,7 @@ declare class AleoNetworkClient {
|
|
|
178
243
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
179
244
|
*
|
|
180
245
|
* // Create a network client and set an account to search for records with.
|
|
181
|
-
* const networkClient = new AleoNetworkClient("
|
|
246
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
182
247
|
* networkClient.setAccount(account);
|
|
183
248
|
*
|
|
184
249
|
* // Find specific amounts
|
|
@@ -211,7 +276,7 @@ declare class AleoNetworkClient {
|
|
|
211
276
|
* @example
|
|
212
277
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
213
278
|
*
|
|
214
|
-
* const networkClient = new AleoNetworkClient("
|
|
279
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
215
280
|
* const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
216
281
|
*/
|
|
217
282
|
getBlockByHash(blockHash: string): Promise<BlockJSON>;
|
|
@@ -246,7 +311,7 @@ declare class AleoNetworkClient {
|
|
|
246
311
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
247
312
|
*
|
|
248
313
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
249
|
-
* const networkClient = new AleoNetworkClient("
|
|
314
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
250
315
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
251
316
|
*
|
|
252
317
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -266,7 +331,7 @@ declare class AleoNetworkClient {
|
|
|
266
331
|
* import { AleoNetworkClient, DeploymentJSON } from "@provablehq/sdk/testnet.js";
|
|
267
332
|
*
|
|
268
333
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
269
|
-
* const networkClient = new AleoNetworkClient("
|
|
334
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
270
335
|
* const transaction = networkClient.getDeploymentTransactionForProgram("hello_hello.aleo");
|
|
271
336
|
*
|
|
272
337
|
* // Get the verifying keys for each function in the deployment.
|
|
@@ -284,7 +349,7 @@ declare class AleoNetworkClient {
|
|
|
284
349
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
285
350
|
*
|
|
286
351
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
287
|
-
* const networkClient = new AleoNetworkClient("
|
|
352
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
288
353
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
289
354
|
*
|
|
290
355
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -303,7 +368,7 @@ declare class AleoNetworkClient {
|
|
|
303
368
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
304
369
|
*
|
|
305
370
|
* // Create a network client.
|
|
306
|
-
* const networkClient = new AleoNetworkClient("
|
|
371
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
307
372
|
*
|
|
308
373
|
* const latestHeight = networkClient.getLatestBlock();
|
|
309
374
|
*/
|
|
@@ -317,10 +382,10 @@ declare class AleoNetworkClient {
|
|
|
317
382
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
318
383
|
*
|
|
319
384
|
* // Create a network client.
|
|
320
|
-
* const networkClient = new AleoNetworkClient("
|
|
385
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
321
386
|
*
|
|
322
387
|
* // Create a network client and get the latest committee.
|
|
323
|
-
* const networkClient = new AleoNetworkClient("
|
|
388
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
324
389
|
* const latestCommittee = await networkClient.getLatestCommittee();
|
|
325
390
|
*/
|
|
326
391
|
getLatestCommittee(): Promise<object>;
|
|
@@ -334,10 +399,10 @@ declare class AleoNetworkClient {
|
|
|
334
399
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
335
400
|
*
|
|
336
401
|
* // Create a network client.
|
|
337
|
-
* const networkClient = new AleoNetworkClient("
|
|
402
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
338
403
|
*
|
|
339
404
|
* // Create a network client and get the committee for a specific block.
|
|
340
|
-
* const networkClient = new AleoNetworkClient("
|
|
405
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
341
406
|
* const committee = await networkClient.getCommitteeByBlockHeight(1234);
|
|
342
407
|
*/
|
|
343
408
|
getCommitteeByBlockHeight(blockHeight: number): Promise<object>;
|
|
@@ -350,7 +415,7 @@ declare class AleoNetworkClient {
|
|
|
350
415
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
351
416
|
*
|
|
352
417
|
* // Create a network client.
|
|
353
|
-
* const networkClient = new AleoNetworkClient("
|
|
418
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
354
419
|
*
|
|
355
420
|
* const latestHeight = networkClient.getLatestHeight();
|
|
356
421
|
*/
|
|
@@ -364,7 +429,7 @@ declare class AleoNetworkClient {
|
|
|
364
429
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
365
430
|
*
|
|
366
431
|
* // Create a network client.
|
|
367
|
-
* const networkClient = new AleoNetworkClient("
|
|
432
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
368
433
|
*
|
|
369
434
|
* // Get the latest block hash.
|
|
370
435
|
* const latestHash = networkClient.getLatestBlockHash();
|
|
@@ -381,7 +446,7 @@ declare class AleoNetworkClient {
|
|
|
381
446
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
382
447
|
*
|
|
383
448
|
* // Create a network client.
|
|
384
|
-
* const networkClient = new AleoNetworkClient("
|
|
449
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
385
450
|
*
|
|
386
451
|
* // Get the source code of a program.)
|
|
387
452
|
* @returns {Promise<string>} Source code of the program
|
|
@@ -390,7 +455,7 @@ declare class AleoNetworkClient {
|
|
|
390
455
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
391
456
|
*
|
|
392
457
|
* // Create a network client.
|
|
393
|
-
* const networkClient = new AleoNetworkClient("
|
|
458
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
394
459
|
*
|
|
395
460
|
* const program = networkClient.getProgram("hello_hello.aleo");
|
|
396
461
|
* const expectedSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
|
|
@@ -407,7 +472,7 @@ declare class AleoNetworkClient {
|
|
|
407
472
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
408
473
|
*
|
|
409
474
|
* // Create a network client.
|
|
410
|
-
* const networkClient = new AleoNetworkClient("
|
|
475
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
411
476
|
*
|
|
412
477
|
* const programVersion = networkClient.getLatestProgramEdition("hello_hello.aleo");
|
|
413
478
|
* assert.equal(programVersion, 1);
|
|
@@ -424,7 +489,7 @@ declare class AleoNetworkClient {
|
|
|
424
489
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
425
490
|
*
|
|
426
491
|
* // Create a network client.
|
|
427
|
-
* const networkClient = new AleoNetworkClient("
|
|
492
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
428
493
|
*
|
|
429
494
|
* const programID = "hello_hello.aleo";
|
|
430
495
|
* const programSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
|
|
@@ -453,7 +518,7 @@ declare class AleoNetworkClient {
|
|
|
453
518
|
* }
|
|
454
519
|
*
|
|
455
520
|
* // Create a network client.
|
|
456
|
-
* const networkClient = new AleoNetworkClient("
|
|
521
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
457
522
|
*
|
|
458
523
|
* // Imports can be fetched using the program ID, source code, or program object
|
|
459
524
|
* let programImports = await networkClient.getProgramImports("double_test.aleo");
|
|
@@ -467,7 +532,7 @@ declare class AleoNetworkClient {
|
|
|
467
532
|
* programImports = await networkClient.getProgramImports(double_test);
|
|
468
533
|
* assert.deepStrictEqual(programImports, expectedImports);
|
|
469
534
|
*/
|
|
470
|
-
getProgramImports(inputProgram: Program | string): Promise<ProgramImports>;
|
|
535
|
+
getProgramImports(inputProgram: Program | string, imports?: ProgramImports): Promise<ProgramImports>;
|
|
471
536
|
/**
|
|
472
537
|
* Get a list of the program names that a program imports.
|
|
473
538
|
*
|
|
@@ -478,7 +543,7 @@ declare class AleoNetworkClient {
|
|
|
478
543
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
479
544
|
*
|
|
480
545
|
* // Create a network client.
|
|
481
|
-
* const networkClient = new AleoNetworkClient("
|
|
546
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
482
547
|
*
|
|
483
548
|
* const programImportsNames = networkClient.getProgramImports("wrapped_credits.aleo");
|
|
484
549
|
* const expectedImportsNames = ["credits.aleo"];
|
|
@@ -495,7 +560,7 @@ declare class AleoNetworkClient {
|
|
|
495
560
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
496
561
|
*
|
|
497
562
|
* // Create a network client.
|
|
498
|
-
* const networkClient = new AleoNetworkClient("
|
|
563
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
499
564
|
*
|
|
500
565
|
* const mappings = networkClient.getProgramMappingNames("credits.aleo");
|
|
501
566
|
* const expectedMappings = [
|
|
@@ -522,7 +587,7 @@ declare class AleoNetworkClient {
|
|
|
522
587
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
523
588
|
*
|
|
524
589
|
* // Create a network client.
|
|
525
|
-
* const networkClient = new AleoNetworkClient("
|
|
590
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
526
591
|
*
|
|
527
592
|
* // Get public balance of an account
|
|
528
593
|
* const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -542,7 +607,7 @@ declare class AleoNetworkClient {
|
|
|
542
607
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
543
608
|
*
|
|
544
609
|
* // Create a network client.
|
|
545
|
-
* const networkClient = new AleoNetworkClient("
|
|
610
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
546
611
|
*
|
|
547
612
|
* // Get the bond state as an account.
|
|
548
613
|
* const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -575,7 +640,7 @@ declare class AleoNetworkClient {
|
|
|
575
640
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
576
641
|
*
|
|
577
642
|
* // Create a network client.
|
|
578
|
-
* const networkClient = new AleoNetworkClient("
|
|
643
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
579
644
|
*
|
|
580
645
|
* // Get the balance of an account from either an address object or address string.
|
|
581
646
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
@@ -593,7 +658,7 @@ declare class AleoNetworkClient {
|
|
|
593
658
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
594
659
|
*
|
|
595
660
|
* // Create a network client.
|
|
596
|
-
* const networkClient = new AleoNetworkClient("
|
|
661
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
597
662
|
*
|
|
598
663
|
* // Get the latest state root.
|
|
599
664
|
* const stateRoot = networkClient.getStateRoot();
|
|
@@ -609,7 +674,7 @@ declare class AleoNetworkClient {
|
|
|
609
674
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
610
675
|
*
|
|
611
676
|
* // Create a network client.
|
|
612
|
-
* const networkClient = new AleoNetworkClient("
|
|
677
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
613
678
|
*
|
|
614
679
|
* const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
615
680
|
*/
|
|
@@ -624,7 +689,7 @@ declare class AleoNetworkClient {
|
|
|
624
689
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
625
690
|
*
|
|
626
691
|
* // Create a network client.
|
|
627
|
-
* const networkClient = new AleoNetworkClient("
|
|
692
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
628
693
|
*
|
|
629
694
|
* const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
630
695
|
* assert.equal(transaction.status, "confirmed");
|
|
@@ -666,7 +731,7 @@ declare class AleoNetworkClient {
|
|
|
666
731
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
667
732
|
*
|
|
668
733
|
* // Create a network client.
|
|
669
|
-
* const networkClient = new AleoNetworkClient("
|
|
734
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
670
735
|
*
|
|
671
736
|
* const transactions = networkClient.getTransactions(654);
|
|
672
737
|
*/
|
|
@@ -681,7 +746,7 @@ declare class AleoNetworkClient {
|
|
|
681
746
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
682
747
|
*
|
|
683
748
|
* // Create a network client.
|
|
684
|
-
* const networkClient = new AleoNetworkClient("
|
|
749
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
685
750
|
*
|
|
686
751
|
* const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
687
752
|
*/
|
|
@@ -695,7 +760,7 @@ declare class AleoNetworkClient {
|
|
|
695
760
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
696
761
|
*
|
|
697
762
|
* // Create a network client.
|
|
698
|
-
* const networkClient = new AleoNetworkClient("
|
|
763
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
699
764
|
*
|
|
700
765
|
* // Get the current transactions in the mempool.
|
|
701
766
|
* const transactions = networkClient.getTransactionsInMempool();
|
|
@@ -725,13 +790,31 @@ declare class AleoNetworkClient {
|
|
|
725
790
|
*/
|
|
726
791
|
submitSolution(solution: string): Promise<string>;
|
|
727
792
|
/**
|
|
728
|
-
*
|
|
793
|
+
* Refreshes the JWT by making a POST request to /jwts/{consumer_id}
|
|
729
794
|
*
|
|
730
|
-
* @param {
|
|
731
|
-
* @param {string}
|
|
795
|
+
* @param {string} apiKey - The API key for authentication.
|
|
796
|
+
* @param {string} consumerId - The consumer ID associated with the API key.
|
|
797
|
+
* @returns {Promise<JwtData>} The JWT token and expiration time
|
|
798
|
+
*/
|
|
799
|
+
private refreshJwt;
|
|
800
|
+
/**
|
|
801
|
+
* Parses a /prove or /prove/encrypted response. Returns a result object (never throws for 200/400/500/503).
|
|
802
|
+
*/
|
|
803
|
+
private handleProvingResponse;
|
|
804
|
+
/**
|
|
805
|
+
* Submit a `ProvingRequest` to a remote proving service for delegated proving. If the broadcast flag of the `ProvingRequest` is set to `true` the remote service will attempt to broadcast the result `Transaction` on behalf of the requestor. Throws on HTTP 400, 500, 503 (and retries on 500/503). Callers should {@link submitProvingRequestSafe} to handle proving request failures without throwing.
|
|
806
|
+
*
|
|
807
|
+
* @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request.
|
|
732
808
|
* @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`.
|
|
733
809
|
*/
|
|
734
|
-
submitProvingRequest(
|
|
810
|
+
submitProvingRequest(options: DelegatedProvingParams): Promise<ProvingResponse>;
|
|
811
|
+
/**
|
|
812
|
+
* Submit a proving request and return a result object instead of throwing. This method is usable when callers want to handle HTTP status (400, 500, 503) yourself. Retries on 500/503 and returns on 200 or 400.
|
|
813
|
+
*
|
|
814
|
+
* @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request.
|
|
815
|
+
* @returns {Promise<ProvingResult>} `{ ok: true, data }` on success (200), or `{ ok: false, status, error }` on 400/500/503. Check `result.ok` and then either `result.data` or `result.status` / `result.error.message`.
|
|
816
|
+
*/
|
|
817
|
+
submitProvingRequestSafe(options: DelegatedProvingParams): Promise<ProvingResult>;
|
|
735
818
|
/**
|
|
736
819
|
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
|
|
737
820
|
*
|
|
@@ -744,7 +827,7 @@ declare class AleoNetworkClient {
|
|
|
744
827
|
* import { AleoNetworkClient, Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
745
828
|
*
|
|
746
829
|
* // Create a network client and program manager.
|
|
747
|
-
* const networkClient = new AleoNetworkClient("
|
|
830
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
748
831
|
* const programManager = new ProgramManager(networkClient);
|
|
749
832
|
*
|
|
750
833
|
* // Set the account for the program manager.
|
|
@@ -3,7 +3,6 @@ import { webcrypto } from 'node:crypto';
|
|
|
3
3
|
import * as $fs from 'node:fs';
|
|
4
4
|
import $mime from 'mime/lite';
|
|
5
5
|
import $xmlhttprequest from 'xmlhttprequest-ssl';
|
|
6
|
-
import $request from 'sync-request';
|
|
7
6
|
import * as $worker from 'node:worker_threads';
|
|
8
7
|
import * as $os from 'node:os';
|
|
9
8
|
|
|
@@ -53,54 +52,8 @@ globalThis.fetch = async function (resource, options) {
|
|
|
53
52
|
// @ts-ignore
|
|
54
53
|
if (globalThis.XMLHttpRequest == null) {
|
|
55
54
|
globalThis.XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// instead it defines all of the methods inside of the constructor.
|
|
59
|
-
constructor(...args) {
|
|
60
|
-
super(...args);
|
|
61
|
-
const open = this.open;
|
|
62
|
-
const send = this.send;
|
|
63
|
-
let _async = true;
|
|
64
|
-
let _url = null;
|
|
65
|
-
let _mime = "text/xml";
|
|
66
|
-
function reset() {
|
|
67
|
-
_async = true;
|
|
68
|
-
_url = null;
|
|
69
|
-
_mime = "text/xml";
|
|
70
|
-
}
|
|
71
|
-
this.open = function (method, url, async, user, password) {
|
|
72
|
-
// Special behavior for synchronous requests
|
|
73
|
-
if (method === "GET" && !async && !user && !password) {
|
|
74
|
-
_async = false;
|
|
75
|
-
_url = url;
|
|
76
|
-
// Default to the normal polyfill for async requests
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
reset();
|
|
80
|
-
return open.call(this, method, url, async, user, password);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
this.send = function (data) {
|
|
84
|
-
if (_async) {
|
|
85
|
-
return send.call(this, data);
|
|
86
|
-
// Use `sync-request` for synchronous requests.
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const response = $request("GET", _url, {
|
|
90
|
-
headers: {
|
|
91
|
-
"Content-Type": _mime,
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
const buffer = response.body.buffer;
|
|
95
|
-
const responseText = new TextDecoder("iso-8859-5", { fatal: true }).decode(buffer);
|
|
96
|
-
this.status = 200;
|
|
97
|
-
this.response = this.responseText = responseText;
|
|
98
|
-
reset();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.overrideMimeType = function (mime) {
|
|
102
|
-
_mime = mime;
|
|
103
|
-
};
|
|
55
|
+
constructor(opts) {
|
|
56
|
+
super({ syncPolicy: "enabled", ...opts });
|
|
104
57
|
}
|
|
105
58
|
};
|
|
106
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-polyfill.js","sources":["../../src/polyfill/crypto.ts","../../src/polyfill/fetch.ts","../../src/polyfill/xmlhttprequest.ts","../../src/polyfill/worker.ts","../../src/node-polyfill.ts"],"sourcesContent":["import { webcrypto } from \"node:crypto\";\n\nif ((globalThis as any).crypto == null) {\n (globalThis as any).crypto = webcrypto;\n}\n","import * as $fs from \"node:fs\";\nimport $mime from \"mime/lite\";\n\n\nconst oldFetch = globalThis.fetch;\n\n\nlet supports: Promise<boolean> | null = null;\n\nasync function checkFetch() {\n try {\n await oldFetch(new URL(\"file:\"));\n return true;\n\n } catch (e) {\n return false;\n }\n}\n\nasync function supportsFetch(): Promise<boolean> {\n if (supports === null) {\n supports = checkFetch();\n }\n\n return await supports;\n}\n\n\n// We always polyfill fetch because Node's fetch doesn't support file URLs.\n(globalThis.fetch as any) = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise<Response> {\n const request = new Request(resource, options);\n\n const url = new URL(request.url);\n\n if (!(await supportsFetch()) && url.protocol === \"file:\") {\n const readStream = $fs.createReadStream(url);\n\n const headers: HeadersInit = {};\n\n const type = $mime.getType(url.pathname);\n\n if (type) {\n headers[\"Content-Type\"] = type;\n }\n\n return new Response(readStream as any, {\n status: 200,\n statusText: \"OK\",\n headers,\n });\n\n } else {\n return await oldFetch(request);\n }\n};\n","// @ts-ignore\nimport $xmlhttprequest from \"xmlhttprequest-ssl\";\nimport $request from \"sync-request\";\n\nif (globalThis.XMLHttpRequest == null) {\n globalThis.XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {\n // We have to override the methods inside of the `constructor`\n // because `xmlhttprequest-ssl` doesn't use a regular class,\n // instead it defines all of the methods inside of the constructor.\n constructor(...args: Array<any>) {\n super(...args);\n\n const open = (this as any).open;\n const send = (this as any).send;\n\n let _async: boolean = true;\n let _url: null | string = null;\n let _mime: string = \"text/xml\";\n\n function reset() {\n _async = true;\n _url = null;\n _mime = \"text/xml\";\n }\n\n (this as any).open = function (method: string, url: string, async: boolean, user?: string, password?: string) {\n // Special behavior for synchronous requests\n if (method === \"GET\" && !async && !user && !password) {\n _async = false;\n _url = url;\n\n // Default to the normal polyfill for async requests\n } else {\n reset();\n return open.call(this, method, url, async, user, password);\n }\n };\n\n (this as any).send = function (data: any) {\n if (_async) {\n return send.call(this, data);\n\n // Use `sync-request` for synchronous requests.\n } else {\n const response = $request(\"GET\", _url!, {\n headers: {\n \"Content-Type\": _mime,\n }\n });\n\n const buffer = (response.body as Buffer).buffer as any;\n\n const responseText = new TextDecoder(\"iso-8859-5\", { fatal: true }).decode(buffer);\n\n (this as any).status = 200;\n (this as any).response = (this as any).responseText = responseText;\n\n reset();\n }\n };\n\n (this as any).overrideMimeType = function (mime: string) {\n _mime = mime;\n };\n }\n } as any;\n}\n","import * as $worker from \"node:worker_threads\";\nimport * as $os from \"node:os\";\n\n// This is technically not a part of the Worker polyfill,\n// but Workers are used for multi-threading, so this is often\n// needed when writing Worker code.\nif (globalThis.navigator == null) {\n globalThis.navigator = {\n hardwareConcurrency: $os.cpus().length,\n } as Navigator;\n}\n\nif (globalThis.Worker == null) {\n globalThis.Worker = class Worker extends EventTarget {\n private _worker: import(\"node:worker_threads\").Worker;\n\n constructor(url: string | URL, options?: WorkerOptions | undefined) {\n super();\n\n if (url instanceof URL) {\n if (url.protocol !== \"file:\") {\n throw new Error(\"Worker only supports file: URLs\");\n }\n\n url = url.href;\n\n } else {\n throw new Error(\"Filepaths are unreliable, use `new URL(\\\"...\\\", import.meta.url)` instead.\");\n }\n\n if (!options || options.type !== \"module\") {\n throw new Error(\"Workers must use \\`type: \\\"module\\\"\\`\");\n }\n\n const code = `\n import(\"node:worker_threads\")\n .then(({ workerData }) => {\n return import(workerData.polyfill)\n .then(() => import(workerData.url))\n })\n .catch((e) => {\n // TODO maybe it should send a message to the parent?\n console.error(e.stack);\n });\n `;\n\n this._worker = new $worker.Worker(code, {\n eval: true,\n workerData: {\n url,\n polyfill: new URL(\"node-polyfill.js\", import.meta.url).href,\n },\n });\n\n this._worker.on(\"message\", (data) => {\n this.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n\n this._worker.on(\"messageerror\", (error) => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n this._worker.on(\"error\", (error) => {\n // TODO attach the error to the event somehow\n const event = new Event(\"error\");\n this.dispatchEvent(event);\n });\n }\n\n set onmessage(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onmessageerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n postMessage(message: any, transfer: Array<Transferable>): void;\n postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n postMessage(value: any, transfer: any) {\n this._worker.postMessage(value, transfer);\n }\n\n terminate() {\n this._worker.terminate();\n }\n\n // This is Node-specific, it allows the process to exit\n // even if the Worker is still running.\n unref() {\n this._worker.unref();\n }\n };\n}\n\n\nif (!$worker.isMainThread) {\n const globals = globalThis as unknown as DedicatedWorkerGlobalScope;\n\n // This is used to create the onmessage, onmessageerror, and onerror setters\n const makeSetter = (prop: string, event: string) => {\n let oldvalue: () => void;\n\n Object.defineProperty(globals, prop, {\n get() {\n return oldvalue;\n },\n set(value) {\n if (oldvalue) {\n globals.removeEventListener(event, oldvalue);\n }\n\n oldvalue = value;\n\n if (oldvalue) {\n globals.addEventListener(event, oldvalue);\n }\n },\n });\n };\n\n // This makes sure that `f` is only run once\n const memoize = (f: () => void) => {\n let run = false;\n\n return () => {\n if (!run) {\n run = true;\n f();\n }\n };\n };\n\n\n // We only start listening for messages / errors when the worker calls addEventListener\n const startOnMessage = memoize(() => {\n $worker.parentPort!.on(\"message\", (data) => {\n workerEvents.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n });\n\n const startOnMessageError = memoize(() => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n const startOnError = memoize(() => {\n $worker.parentPort!.on(\"error\", (data) => {\n workerEvents.dispatchEvent(new Event(\"error\"));\n });\n });\n\n\n // Node workers don't have top-level events, so we have to make our own\n const workerEvents = new EventTarget();\n\n globals.close = () => {\n process.exit();\n };\n\n globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.addEventListener(type, callback, options);\n\n if (type === \"message\") {\n startOnMessage();\n } else if (type === \"messageerror\") {\n startOnMessageError();\n } else if (type === \"error\") {\n startOnError();\n }\n };\n\n globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.removeEventListener(type, callback, options);\n };\n\n function postMessage(message: any, transfer: Transferable[]): void;\n function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n function postMessage(value: any, transfer: any) {\n $worker.parentPort!.postMessage(value, transfer);\n }\n\n globals.postMessage = postMessage;\n\n makeSetter(\"onmessage\", \"message\");\n makeSetter(\"onmessageerror\", \"messageerror\");\n makeSetter(\"onerror\", \"error\");\n}\n","import \"./polyfill/shared.js\";\nimport \"./polyfill/crypto.js\";\nimport \"./polyfill/fetch.js\";\nimport \"./polyfill/xmlhttprequest.js\";\nimport \"./polyfill/worker.js\";\n\nif (!globalThis.self) {\n (globalThis as any).self = globalThis;\n}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AO,CAAC;AAClC;;ACxLA,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AACjB,IAAA,UAAkB,CAAC,IAAI,GAAG,UAAU;AACzC"}
|
|
1
|
+
{"version":3,"file":"node-polyfill.js","sources":["../../src/polyfill/crypto.ts","../../src/polyfill/fetch.ts","../../src/polyfill/xmlhttprequest.ts","../../src/polyfill/worker.ts","../../src/node-polyfill.ts"],"sourcesContent":["import { webcrypto } from \"node:crypto\";\n\nif ((globalThis as any).crypto == null) {\n (globalThis as any).crypto = webcrypto;\n}\n","import * as $fs from \"node:fs\";\nimport $mime from \"mime/lite\";\n\n\nconst oldFetch = globalThis.fetch;\n\n\nlet supports: Promise<boolean> | null = null;\n\nasync function checkFetch() {\n try {\n await oldFetch(new URL(\"file:\"));\n return true;\n\n } catch (e) {\n return false;\n }\n}\n\nasync function supportsFetch(): Promise<boolean> {\n if (supports === null) {\n supports = checkFetch();\n }\n\n return await supports;\n}\n\n\n// We always polyfill fetch because Node's fetch doesn't support file URLs.\n(globalThis.fetch as any) = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise<Response> {\n const request = new Request(resource, options);\n\n const url = new URL(request.url);\n\n if (!(await supportsFetch()) && url.protocol === \"file:\") {\n const readStream = $fs.createReadStream(url);\n\n const headers: HeadersInit = {};\n\n const type = $mime.getType(url.pathname);\n\n if (type) {\n headers[\"Content-Type\"] = type;\n }\n\n return new Response(readStream as any, {\n status: 200,\n statusText: \"OK\",\n headers,\n });\n\n } else {\n return await oldFetch(request);\n }\n};\n","// @ts-ignore\nimport $xmlhttprequest from \"xmlhttprequest-ssl\";\n\nif (globalThis.XMLHttpRequest == null) {\n (globalThis as any).XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {\n constructor(opts?: any) {\n super({ syncPolicy: \"enabled\", ...opts });\n }\n };\n}","import * as $worker from \"node:worker_threads\";\nimport * as $os from \"node:os\";\n\n// This is technically not a part of the Worker polyfill,\n// but Workers are used for multi-threading, so this is often\n// needed when writing Worker code.\nif (globalThis.navigator == null) {\n globalThis.navigator = {\n hardwareConcurrency: $os.cpus().length,\n } as Navigator;\n}\n\nif (globalThis.Worker == null) {\n globalThis.Worker = class Worker extends EventTarget {\n private _worker: import(\"node:worker_threads\").Worker;\n\n constructor(url: string | URL, options?: WorkerOptions | undefined) {\n super();\n\n if (url instanceof URL) {\n if (url.protocol !== \"file:\") {\n throw new Error(\"Worker only supports file: URLs\");\n }\n\n url = url.href;\n\n } else {\n throw new Error(\"Filepaths are unreliable, use `new URL(\\\"...\\\", import.meta.url)` instead.\");\n }\n\n if (!options || options.type !== \"module\") {\n throw new Error(\"Workers must use \\`type: \\\"module\\\"\\`\");\n }\n\n const code = `\n import(\"node:worker_threads\")\n .then(({ workerData }) => {\n return import(workerData.polyfill)\n .then(() => import(workerData.url))\n })\n .catch((e) => {\n // TODO maybe it should send a message to the parent?\n console.error(e.stack);\n });\n `;\n\n this._worker = new $worker.Worker(code, {\n eval: true,\n workerData: {\n url,\n polyfill: new URL(\"node-polyfill.js\", import.meta.url).href,\n },\n });\n\n this._worker.on(\"message\", (data) => {\n this.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n\n this._worker.on(\"messageerror\", (error) => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n this._worker.on(\"error\", (error) => {\n // TODO attach the error to the event somehow\n const event = new Event(\"error\");\n this.dispatchEvent(event);\n });\n }\n\n set onmessage(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onmessageerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n postMessage(message: any, transfer: Array<Transferable>): void;\n postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n postMessage(value: any, transfer: any) {\n this._worker.postMessage(value, transfer);\n }\n\n terminate() {\n this._worker.terminate();\n }\n\n // This is Node-specific, it allows the process to exit\n // even if the Worker is still running.\n unref() {\n this._worker.unref();\n }\n };\n}\n\n\nif (!$worker.isMainThread) {\n const globals = globalThis as unknown as DedicatedWorkerGlobalScope;\n\n // This is used to create the onmessage, onmessageerror, and onerror setters\n const makeSetter = (prop: string, event: string) => {\n let oldvalue: () => void;\n\n Object.defineProperty(globals, prop, {\n get() {\n return oldvalue;\n },\n set(value) {\n if (oldvalue) {\n globals.removeEventListener(event, oldvalue);\n }\n\n oldvalue = value;\n\n if (oldvalue) {\n globals.addEventListener(event, oldvalue);\n }\n },\n });\n };\n\n // This makes sure that `f` is only run once\n const memoize = (f: () => void) => {\n let run = false;\n\n return () => {\n if (!run) {\n run = true;\n f();\n }\n };\n };\n\n\n // We only start listening for messages / errors when the worker calls addEventListener\n const startOnMessage = memoize(() => {\n $worker.parentPort!.on(\"message\", (data) => {\n workerEvents.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n });\n\n const startOnMessageError = memoize(() => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n const startOnError = memoize(() => {\n $worker.parentPort!.on(\"error\", (data) => {\n workerEvents.dispatchEvent(new Event(\"error\"));\n });\n });\n\n\n // Node workers don't have top-level events, so we have to make our own\n const workerEvents = new EventTarget();\n\n globals.close = () => {\n process.exit();\n };\n\n globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.addEventListener(type, callback, options);\n\n if (type === \"message\") {\n startOnMessage();\n } else if (type === \"messageerror\") {\n startOnMessageError();\n } else if (type === \"error\") {\n startOnError();\n }\n };\n\n globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.removeEventListener(type, callback, options);\n };\n\n function postMessage(message: any, transfer: Transferable[]): void;\n function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n function postMessage(value: any, transfer: any) {\n $worker.parentPort!.postMessage(value, transfer);\n }\n\n globals.postMessage = postMessage;\n\n makeSetter(\"onmessage\", \"message\");\n makeSetter(\"onmessageerror\", \"messageerror\");\n makeSetter(\"onerror\", \"error\");\n}\n","import \"./polyfill/shared.js\";\nimport \"./polyfill/crypto.js\";\nimport \"./polyfill/fetch.js\";\nimport \"./polyfill/xmlhttprequest.js\";\nimport \"./polyfill/worker.js\";\n\nif (!globalThis.self) {\n (globalThis as any).self = globalThis;\n}\n"],"names":[],"mappings":";;;;;;;;AAEA,IAAK,UAAkB,CAAC,MAAM,IAAI,IAAI,EAAE;AACnC,IAAA,UAAkB,CAAC,MAAM,GAAG,SAAS;AAC1C;;ACAA,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK;AAGjC,IAAI,QAAQ,GAA4B,IAAI;AAE5C,eAAe,UAAU,GAAA;AACrB,IAAA,IAAI;QACA,MAAM,QAAQ,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;AAChC,QAAA,OAAO,IAAI;IAEf;IAAE,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,KAAK;IAChB;AACJ;AAEA,eAAe,aAAa,GAAA;AACxB,IAAA,IAAI,QAAQ,KAAK,IAAI,EAAE;QACnB,QAAQ,GAAG,UAAU,EAAE;IAC3B;IAEA,OAAO,MAAM,QAAQ;AACzB;AAGA;AACC,UAAU,CAAC,KAAa,GAAG,gBAAgB,QAA2B,EAAE,OAAgC,EAAA;IACrG,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE9C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;AAEhC,IAAA,IAAI,EAAE,MAAM,aAAa,EAAE,CAAC,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE;QACtD,MAAM,UAAU,GAAG,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC;QAE5C,MAAM,OAAO,GAAgB,EAAE;QAE/B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QAExC,IAAI,IAAI,EAAE;AACN,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