@oceanprotocol/lib 4.1.4 → 4.2.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.
@@ -0,0 +1,5 @@
1
+ export interface JwtPayload {
2
+ address: string;
3
+ nonce: string;
4
+ createdAt: number;
5
+ }
@@ -21,7 +21,7 @@ export declare class Aquarius {
21
21
  * @param {AbortSignal} signal abort signal
22
22
  * @return {Promise<Asset>} Asset
23
23
  */
24
- resolve(did: string, signal?: AbortSignal): Promise<Asset>;
24
+ resolve(did: string, signal?: AbortSignal, authorization?: string): Promise<Asset>;
25
25
  /**
26
26
  * Blocks until Indexer will cache the did (or the update for that did) or timeouts
27
27
  * @param {string} did DID of the asset.
@@ -29,7 +29,7 @@ export declare class Aquarius {
29
29
  * @param {AbortSignal} signal abort signal
30
30
  * @return {Promise<Asset>} DDO of the asset.
31
31
  */
32
- waitForIndexer(did: string, txid?: string, signal?: AbortSignal, interval?: number, maxRetries?: number): Promise<Asset>;
32
+ waitForIndexer(did: string, txid?: string, signal?: AbortSignal, interval?: number, maxRetries?: number, authorization?: string): Promise<Asset>;
33
33
  /**
34
34
  * Validate DDO content
35
35
  * @param {DDO} ddo DID Descriptor Object content.
@@ -38,19 +38,19 @@ export declare class Aquarius {
38
38
  * @param {AbortSignal} signal abort signal
39
39
  * @return {Promise<ValidateMetadata>}.
40
40
  */
41
- validate(ddo: DDO, signer: Signer, providerUrl: string, signal?: AbortSignal): Promise<ValidateMetadata>;
41
+ validate(ddo: DDO, signer: Signer, providerUrl: string, signal?: AbortSignal, authorization?: string): Promise<ValidateMetadata>;
42
42
  /**
43
43
  * Search over the DDOs using a query.
44
44
  * @param {string} did DID of the asset
45
45
  * @param {AbortSignal} signal abort signal
46
46
  * @return {Promise<QueryResult>}
47
47
  */
48
- getAssetMetadata(did: string, signal?: AbortSignal): Promise<any>;
48
+ getAssetMetadata(did: string, signal?: AbortSignal, authorization?: string): Promise<any>;
49
49
  /**
50
50
  * Search over the DDOs using a query.
51
51
  * @param {SearchQuery} query Query to filter the DDOs.
52
52
  * @param {AbortSignal} signal abort signal
53
53
  * @return {Promise<QueryResult>}
54
54
  */
55
- querySearch(query: SearchQuery, signal?: AbortSignal): Promise<any>;
55
+ querySearch(query: SearchQuery, signal?: AbortSignal, authorization?: string): Promise<any>;
56
56
  }
@@ -1,12 +1,15 @@
1
1
  import { Signer } from 'ethers';
2
2
  import { Arweave, FileInfo, ComputeJob, ComputeOutput, ComputeAlgorithm, ComputeAsset, ComputeEnvironment, ProviderInitialize, ProviderComputeInitializeResults, ServiceEndpoint, UrlFile, UserCustomParameters, Ipfs, ComputeResourceRequest } from '../@types';
3
3
  export declare class Provider {
4
+ private getConsumerAddress;
5
+ private getSignature;
6
+ private getAuthorization;
4
7
  /**
5
8
  * Returns the provider endpoints
6
9
  * @param {string} providerUri - the provider url
7
10
  * @return {Promise<any>}
8
11
  */
9
- getEndpoints(providerUri: string): Promise<any>;
12
+ getEndpoints(providerUri: string, authorization?: string): Promise<any>;
10
13
  /**
11
14
  * This function returns the endpoint URL for a given service name.
12
15
  * @param {ServiceEndpoint[]} servicesEndpoints - The array of service endpoints
@@ -105,11 +108,13 @@ export declare class Provider {
105
108
  * @param {string} token The payment token address.
106
109
  * @param {number} validUntil The job expiration date.
107
110
  * @param {string} providerUri The provider URI.
108
- * @param {Signer} signer caller address
111
+ * @param {SignerOrAuthToken} signerOrAuthToken Signer or auth token
112
+ * @param {ComputeResourceRequest[]} resources The resources to start compute job with.
113
+ * @param {number} chainId The chain used to do payments
109
114
  * @param {AbortSignal} signal abort signal
110
115
  * @return {Promise<ProviderComputeInitialize>} ProviderComputeInitialize data
111
116
  */
112
- initializeCompute(assets: ComputeAsset[], algorithm: ComputeAlgorithm, computeEnv: string, token: string, validUntil: number, providerUri: string, signer: Signer, resources: ComputeResourceRequest[], signal?: AbortSignal): Promise<ProviderComputeInitializeResults>;
117
+ initializeCompute(assets: ComputeAsset[], algorithm: ComputeAlgorithm, computeEnv: string, token: string, validUntil: number, providerUri: string, signerOrAuthToken: Signer | string, resources: ComputeResourceRequest[], chainId: number, signal?: AbortSignal): Promise<ProviderComputeInitializeResults>;
113
118
  /**
114
119
  * Gets the download URL.
115
120
  * @param {string} did - The DID.
@@ -117,12 +122,12 @@ export declare class Provider {
117
122
  * @param {number} fileIndex - The file index.
118
123
  * @param {string} transferTxId - The transfer transaction ID.
119
124
  * @param {string} providerUri - The provider URI.
120
- * @param {Signer} signer - The signer.
125
+ * @param {SignerOrAuthToken} signerOrAuthToken - The signer or auth token.
121
126
  * @param {any} policyServer - The policy server (if any is to be used).
122
127
  * @param {UserCustomParameters} userCustomParameters - The user custom parameters.
123
128
  * @returns {Promise<any>} The download URL.
124
129
  */
125
- getDownloadUrl(did: string, serviceId: string, fileIndex: number, transferTxId: string, providerUri: string, signer: Signer, policyServer?: any, userCustomParameters?: UserCustomParameters): Promise<any>;
130
+ getDownloadUrl(did: string, serviceId: string, fileIndex: number, transferTxId: string, providerUri: string, signerOrAuthToken: Signer | string, policyServer?: any, userCustomParameters?: UserCustomParameters): Promise<any>;
126
131
  /** Instruct the provider to start a compute job (Old C2D V1) Kept for now, for backwards compatibility
127
132
  * @param {string} providerUri The provider URI.
128
133
  * @param {Signer} signer The consumer signer object.
@@ -138,7 +143,7 @@ export declare class Provider {
138
143
  computeStartV1(providerUri: string, consumer: Signer, computeEnv: string, dataset: ComputeAsset, algorithm: ComputeAlgorithm, signal?: AbortSignal, additionalDatasets?: ComputeAsset[], output?: ComputeOutput): Promise<ComputeJob | ComputeJob[]>;
139
144
  /** Instruct the provider to start a PAYED compute job (new C2D V2)
140
145
  * @param {string} providerUri The provider URI.
141
- * @param {Signer} signer The consumer signer object.
146
+ * @param {SignerOrAuthToken} signerOrAuthToken The consumer signer object or auth token.
142
147
  * @param {string} computeEnv The compute environment.
143
148
  * @param {ComputeAsset} datasets The dataset to start compute on + additionalDatasets (the additional datasets if that is the case)
144
149
  * @param {ComputeAlgorithm} algorithm The algorithm to start compute with.
@@ -150,11 +155,11 @@ export declare class Provider {
150
155
  * @param {AbortSignal} signal abort signal
151
156
  * @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
152
157
  */
153
- computeStart(providerUri: string, consumer: Signer, computeEnv: string, datasets: ComputeAsset[], algorithm: ComputeAlgorithm, maxJobDuration: number, token: string, resources: ComputeResourceRequest[], chainId?: number, // network used by payment (only for payed compute jobs)
158
+ computeStart(providerUri: string, signerOrAuthToken: Signer | string, computeEnv: string, datasets: ComputeAsset[], algorithm: ComputeAlgorithm, maxJobDuration: number, token: string, resources: ComputeResourceRequest[], chainId: number, // network used by payment (only for payed compute jobs)
154
159
  output?: ComputeOutput, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
155
160
  /** Instruct the provider to start a FREE compute job (new C2D V2)
156
161
  * @param {string} providerUri The provider URI.
157
- * @param {Signer} signer The consumer signer object.
162
+ * @param {SignerOrAuthToken} signerOrAuthToken The consumer signer object or auth token.
158
163
  * @param {string} computeEnv The compute environment.
159
164
  * @param {ComputeAsset} datasets The dataset to start compute on + additionalDatasets (the additional datasets if that is the case)
160
165
  * @param {ComputeAlgorithm} algorithm The algorithm to start compute with.
@@ -163,27 +168,27 @@ export declare class Provider {
163
168
  * @param {AbortSignal} signal abort signal
164
169
  * @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
165
170
  */
166
- freeComputeStart(providerUri: string, consumer: Signer, computeEnv: string, datasets: ComputeAsset[], algorithm: ComputeAlgorithm, resources?: ComputeResourceRequest[], output?: ComputeOutput, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
171
+ freeComputeStart(providerUri: string, signerOrAuthToken: Signer | string, computeEnv: string, datasets: ComputeAsset[], algorithm: ComputeAlgorithm, resources?: ComputeResourceRequest[], output?: ComputeOutput, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
167
172
  /**
168
173
  *
169
174
  * @param providerUri provider URL
170
- * @param consumer consumer
175
+ * @param signerOrAuthToken signer or auth token
171
176
  * @param jobId jobId
172
177
  * @param signal abort signal
173
178
  * @returns logs response
174
179
  */
175
- computeStreamableLogs(providerUri: string, signer: Signer, jobId: string, signal?: AbortSignal): Promise<any>;
180
+ computeStreamableLogs(providerUri: string, signerOrAuthToken: Signer | string, jobId: string, signal?: AbortSignal): Promise<any>;
176
181
  getComputeStartRoutes(providerUri: string, isFreeCompute?: boolean): Promise<string | null>;
177
182
  /** Instruct the provider to Stop the execution of a to stop a compute job.
178
183
  * @param {string} did the asset did
179
184
  * @param {string} consumerAddress The consumer address.
180
185
  * @param {string} jobId the compute job id
181
186
  * @param {string} providerUri The provider URI.
182
- * @param {Signer} signer The consumer signer object.
187
+ * @param {SignerOrAuthToken} signerOrAuthToken The consumer signer or auth token.
183
188
  * @param {AbortSignal} signal abort signal
184
189
  * @return {Promise<ComputeJob | ComputeJob[]>}
185
190
  */
186
- computeStop(did: string, consumerAddress: string, jobId: string, providerUri: string, signer: Signer, agreementId?: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
191
+ computeStop(did: string, consumerAddress: string, jobId: string, providerUri: string, signerOrAuthToken: Signer | string, agreementId?: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
187
192
  /** Get compute status for a specific jobId/documentId/owner.
188
193
  * @param {string} providerUri The URI of the provider we want to query
189
194
  * @param {string} consumerAddress The consumer ethereum address
@@ -192,24 +197,41 @@ export declare class Provider {
192
197
  * @param {AbortSignal} signal abort signal
193
198
  * @return {Promise<ComputeJob | ComputeJob[]>}
194
199
  */
195
- computeStatus(providerUri: string, consumerAddress: string, jobId?: string, agreementId?: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
200
+ computeStatus(providerUri: string, consumerAddress: string, jobId?: string, agreementId?: string, signal?: AbortSignal, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
196
201
  /** Get compute result url
197
202
  * @param {string} providerUri The URI of the provider we want to query
198
- * @param {Signer} consumer consumer Signer wallet object
203
+ * @param {SignerOrAuthToken} signerOrAuthToken signer or auth token
199
204
  * @param {string} jobId The ID of a compute job.
200
205
  * @param {number} index Result index
201
206
  * @return {Promise<string>}
202
207
  */
203
- getComputeResultUrl(providerUri: string, consumer: Signer, jobId: string, index: number): Promise<string>;
208
+ getComputeResultUrl(providerUri: string, signerOrAuthToken: Signer | string, jobId: string, index: number): Promise<string>;
204
209
  /** Deletes a compute job.
205
210
  * @param {string} did asset did
206
- * @param {Signer} consumer consumer Signer wallet object
211
+ * @param {SignerOrAuthToken} signerOrAuthToken signer or auth token
207
212
  * @param {string} jobId the compute job ID
208
213
  * @param {string} providerUri The URI of the provider we want to query
209
214
  * @param {AbortSignal} signal abort signal
210
215
  * @return {Promise<ComputeJob | ComputeJob[]>}
211
216
  */
212
- computeDelete(did: string, consumer: Signer, jobId: string, providerUri: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
217
+ computeDelete(did: string, signerOrAuthToken: Signer | string, jobId: string, providerUri: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
218
+ /** Generates an auth token
219
+ * @param {Signer} consumer consumer Signer wallet object
220
+ * @param {string} providerUri The URI of the provider we want to query
221
+ * @param {AbortSignal} signal abort signal
222
+ * @return {Promise<ComputeJob | ComputeJob[]>}
223
+ */
224
+ generateAuthToken(consumer: Signer, providerUri: string, signal?: AbortSignal): Promise<string>;
225
+ /** Generates an auth token
226
+ * @param {Signer} consumer consumer Signer wallet object
227
+ * @param {string} token The auth token to invalidate
228
+ * @param {string} providerUri The URI of the provider we want to query
229
+ * @param {AbortSignal} signal abort signal
230
+ * @return {Promise<ComputeJob | ComputeJob[]>}
231
+ */
232
+ invalidateAuthToken(consumer: Signer, token: string, providerUri: string, signal?: AbortSignal): Promise<{
233
+ success: boolean;
234
+ }>;
213
235
  /** Check for a valid provider at URL
214
236
  * @param {String} url provider uri address
215
237
  * @param {AbortSignal} signal abort signal
@@ -20,4 +20,4 @@ export declare function getOceanArtifactsAddressesByChainId(chain: number): any;
20
20
  * @returns index of the template on the list
21
21
  */
22
22
  export declare function calculateActiveTemplateIndex(owner: Signer, nftContractAddress: string, // addresses.ERC721Factory,
23
- template: string | number, chainID: number): Promise<number>;
23
+ template: string | number, chainID?: number): Promise<number>;
@@ -0,0 +1,2 @@
1
+ import { JwtPayload } from '../@types/Jwt';
2
+ export declare function decodeJwt(token: string): JwtPayload;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oceanprotocol/lib",
3
3
  "source": "./src/index.ts",
4
- "version": "4.1.4",
4
+ "version": "4.2.1",
5
5
  "description": "JavaScript client library for Ocean Protocol",
6
6
  "main": "./dist/lib.cjs",
7
7
  "umd:main": "dist/lib.umd.js",
@@ -66,7 +66,8 @@
66
66
  "crypto-js": "^4.1.1",
67
67
  "decimal.js": "^10.4.1",
68
68
  "ethers": "^5.7.2",
69
- "form-data": "^2.3.3"
69
+ "form-data": "^2.3.3",
70
+ "jsonwebtoken": "^9.0.2"
70
71
  },
71
72
  "devDependencies": {
72
73
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
@@ -74,6 +75,7 @@
74
75
  "@types/chai": "^4.3.1",
75
76
  "@types/chai-spies": "^1.0.3",
76
77
  "@types/crypto-js": "^4.1.1",
78
+ "@types/jsonwebtoken": "^9.0.10",
77
79
  "@types/mocha": "^10.0.10",
78
80
  "@types/node": "^18.0.1",
79
81
  "@types/node-fetch": "^3.0.3",
@@ -86,7 +88,7 @@
86
88
  "cross-env": "^7.0.3",
87
89
  "eslint": "^8.23.1",
88
90
  "eslint-config-oceanprotocol": "^2.0.3",
89
- "eslint-config-prettier": "^9.0.0",
91
+ "eslint-config-prettier": "^10.1.5",
90
92
  "eslint-plugin-prettier": "^4.2.1",
91
93
  "fs": "0.0.1-security",
92
94
  "microbundle": "0.14.2",