@oceanprotocol/lib 4.2.0 → 4.3.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.
@@ -56,6 +56,9 @@ export interface ComputeResult {
56
56
  type: ComputeResultType;
57
57
  index?: number;
58
58
  }
59
+ export type ComputeJobMetadata = {
60
+ [key: string]: string | number | boolean;
61
+ };
59
62
  export interface ComputeJob {
60
63
  owner: string;
61
64
  did?: string;
@@ -69,6 +72,7 @@ export interface ComputeJob {
69
72
  algoDID?: string;
70
73
  agreementId?: string;
71
74
  expireTimestamp: number;
75
+ metadata?: ComputeJobMetadata;
72
76
  }
73
77
  export interface ComputeOutput {
74
78
  publishAlgorithmLog?: boolean;
@@ -0,0 +1,5 @@
1
+ export interface JwtPayload {
2
+ address: string;
3
+ nonce: string;
4
+ createdAt: number;
5
+ }
@@ -0,0 +1,7 @@
1
+ export interface PolicyServer {
2
+ sessionId?: string;
3
+ successRedirectUri?: string;
4
+ errorRedirectUri?: string;
5
+ responseRedirectUri?: string;
6
+ presentationDefinitionUri?: string;
7
+ }
@@ -1,6 +1,10 @@
1
1
  import { Signer } from 'ethers';
2
- import { Arweave, FileInfo, ComputeJob, ComputeOutput, ComputeAlgorithm, ComputeAsset, ComputeEnvironment, ProviderInitialize, ProviderComputeInitializeResults, ServiceEndpoint, UrlFile, UserCustomParameters, Ipfs, ComputeResourceRequest } from '../@types';
2
+ import { Arweave, FileInfo, ComputeJob, ComputeOutput, ComputeAlgorithm, ComputeAsset, ComputeEnvironment, ProviderInitialize, ProviderComputeInitializeResults, ServiceEndpoint, UrlFile, UserCustomParameters, Ipfs, ComputeResourceRequest, ComputeJobMetadata } from '../@types';
3
+ import { PolicyServer } from '../@types/PolicyServer.js';
3
4
  export declare class Provider {
5
+ private getConsumerAddress;
6
+ private getSignature;
7
+ private getAuthorization;
4
8
  /**
5
9
  * Returns the provider endpoints
6
10
  * @param {string} providerUri - the provider url
@@ -30,7 +34,7 @@ export declare class Provider {
30
34
  * @param {string} serviceEndpoints document description object (DDO)=
31
35
  * @return {Promise<string>} urlDetails
32
36
  */
33
- getNonce(providerUri: string, consumerAddress: string, signal?: AbortSignal, providerEndpoints?: any, serviceEndpoints?: ServiceEndpoint[], authorization?: string): Promise<number>;
37
+ getNonce(providerUri: string, consumerAddress: string, signal?: AbortSignal, providerEndpoints?: any, serviceEndpoints?: ServiceEndpoint[]): Promise<number>;
34
38
  /**
35
39
  * Sign a provider request with a signer.
36
40
  * @param {Signer} signer - The signer to use.
@@ -46,7 +50,7 @@ export declare class Provider {
46
50
  * @param {AbortSignal} signal abort signal
47
51
  * @return {Promise<string>} urlDetails
48
52
  */
49
- encrypt(data: any, chainId: number, providerUri: string, signal?: AbortSignal, authorization?: string): Promise<string>;
53
+ encrypt(data: any, chainId: number, providerUri: string, signal?: AbortSignal): Promise<string>;
50
54
  /**
51
55
  * Get file details for a given DID and service ID.
52
56
  * @param {string} did - The DID to check.
@@ -56,7 +60,7 @@ export declare class Provider {
56
60
  * @param {AbortSignal} [signal] - An optional abort signal.
57
61
  * @returns {Promise<FileInfo[]>} A promise that resolves with an array of file info objects.
58
62
  */
59
- checkDidFiles(did: string, serviceId: string, providerUri: string, withChecksum?: boolean, signal?: AbortSignal, authorization?: string): Promise<FileInfo[]>;
63
+ checkDidFiles(did: string, serviceId: string, providerUri: string, withChecksum?: boolean, signal?: AbortSignal): Promise<FileInfo[]>;
60
64
  /**
61
65
  * Get File details (if possible)
62
66
  * @param {UrlFile | Arweave | Ipfs | GraphqlQuery | Smartcontract} file one of the supported file structures
@@ -65,14 +69,14 @@ export declare class Provider {
65
69
  * @param {AbortSignal} [signal] - An optional abort signal.
66
70
  * @returns {Promise<FileInfo[]>} A promise that resolves with an array of file info objects.
67
71
  */
68
- getFileInfo(file: UrlFile | Arweave | Ipfs, providerUri: string, withChecksum?: boolean, signal?: AbortSignal, authorization?: string): Promise<FileInfo[]>;
72
+ getFileInfo(file: UrlFile | Arweave | Ipfs, providerUri: string, withChecksum?: boolean, signal?: AbortSignal): Promise<FileInfo[]>;
69
73
  /**
70
74
  * Returns compute environments from a provider.
71
75
  * @param {string} providerUri - The URI of the provider.
72
76
  * @param {AbortSignal} [signal] - An optional abort signal.
73
77
  * @returns {Promise<{[chainId: number]: ComputeEnvironment[]}>} A promise that resolves with an object containing compute environments for each chain ID.
74
78
  */
75
- getComputeEnvironments(providerUri: string, signal?: AbortSignal, authorization?: string): Promise<ComputeEnvironment[]>;
79
+ getComputeEnvironments(providerUri: string, signal?: AbortSignal): Promise<ComputeEnvironment[]>;
76
80
  /**
77
81
  * Initializes the provider for a service request.
78
82
  * @param {string} did - The asset DID .
@@ -86,7 +90,7 @@ export declare class Provider {
86
90
  * @param {number} [validUntil] - The validity time if any.
87
91
  * @returns {Promise<ProviderInitialize>} A promise that resolves with ProviderInitialize response.
88
92
  */
89
- initialize(did: string, serviceId: string, fileIndex: number, consumerAddress: string, providerUri: string, signal?: AbortSignal, userCustomParameters?: UserCustomParameters, computeEnv?: string, validUntil?: number, authorization?: string): Promise<ProviderInitialize>;
93
+ initialize(did: string, serviceId: string, fileIndex: number, consumerAddress: string, providerUri: string, signal?: AbortSignal, userCustomParameters?: UserCustomParameters, computeEnv?: string, validUntil?: number): Promise<ProviderInitialize>;
90
94
  /** Initializes the provider for a compute request.
91
95
  * @param {ComputeAsset[]} assets The datasets array to initialize compute request.
92
96
  * @param {ComputeAlgorithmber} algorithm The algorithm to use.
@@ -97,7 +101,7 @@ export declare class Provider {
97
101
  * @param {AbortSignal} signal abort signal
98
102
  * @return {Promise<ProviderComputeInitialize>} ProviderComputeInitialize data
99
103
  */
100
- initializeComputeV1(assets: ComputeAsset[], algorithm: ComputeAlgorithm, computeEnv: string, providerUri: string, accountId: string, chainId: number, token: string, maxJobDuration: number, signal?: AbortSignal, authorization?: string): Promise<ProviderComputeInitializeResults>;
104
+ initializeComputeV1(assets: ComputeAsset[], algorithm: ComputeAlgorithm, computeEnv: string, providerUri: string, accountId: string, chainId: number, token: string, maxJobDuration: number, signal?: AbortSignal): Promise<ProviderComputeInitializeResults>;
101
105
  /** Initializes the provider for a compute request.
102
106
  * @param {ComputeAsset[]} assets The datasets array to initialize compute request.
103
107
  * @param {ComputeAlgorithmber} algorithm The algorithm to use.
@@ -105,11 +109,14 @@ export declare class Provider {
105
109
  * @param {string} token The payment token address.
106
110
  * @param {number} validUntil The job expiration date.
107
111
  * @param {string} providerUri The provider URI.
108
- * @param {Signer} signer caller address
112
+ * @param {SignerOrAuthToken} signerOrAuthToken Signer or auth token
113
+ * @param {ComputeResourceRequest[]} resources The resources to start compute job with.
114
+ * @param {number} chainId The chain used to do payments
115
+ * @param {PolicyServer} policyServer The policy server object.
109
116
  * @param {AbortSignal} signal abort signal
110
117
  * @return {Promise<ProviderComputeInitialize>} ProviderComputeInitialize data
111
118
  */
112
- initializeCompute(assets: ComputeAsset[], algorithm: ComputeAlgorithm, computeEnv: string, token: string, validUntil: number, providerUri: string, signer: Signer, resources: ComputeResourceRequest[], signal?: AbortSignal, authorization?: string): Promise<ProviderComputeInitializeResults>;
119
+ initializeCompute(assets: ComputeAsset[], algorithm: ComputeAlgorithm, computeEnv: string, token: string, validUntil: number, providerUri: string, signerOrAuthToken: Signer | string, resources: ComputeResourceRequest[], chainId: number, policyServer?: PolicyServer, signal?: AbortSignal): Promise<ProviderComputeInitializeResults>;
113
120
  /**
114
121
  * Gets the download URL.
115
122
  * @param {string} did - The DID.
@@ -117,12 +124,12 @@ export declare class Provider {
117
124
  * @param {number} fileIndex - The file index.
118
125
  * @param {string} transferTxId - The transfer transaction ID.
119
126
  * @param {string} providerUri - The provider URI.
120
- * @param {Signer} signer - The signer.
121
- * @param {any} policyServer - The policy server (if any is to be used).
127
+ * @param {SignerOrAuthToken} signerOrAuthToken - The signer or auth token.
128
+ * @param {PolicyServer} policyServer - The policy server (if any is to be used).
122
129
  * @param {UserCustomParameters} userCustomParameters - The user custom parameters.
123
130
  * @returns {Promise<any>} The download URL.
124
131
  */
125
- getDownloadUrl(did: string, serviceId: string, fileIndex: number, transferTxId: string, providerUri: string, signer: Signer, policyServer?: any, userCustomParameters?: UserCustomParameters, authorization?: string): Promise<any>;
132
+ getDownloadUrl(did: string, serviceId: string, fileIndex: number, transferTxId: string, providerUri: string, signerOrAuthToken: Signer | string, policyServer?: PolicyServer, userCustomParameters?: UserCustomParameters): Promise<any>;
126
133
  /** Instruct the provider to start a compute job (Old C2D V1) Kept for now, for backwards compatibility
127
134
  * @param {string} providerUri The provider URI.
128
135
  * @param {Signer} signer The consumer signer object.
@@ -135,10 +142,10 @@ export declare class Provider {
135
142
  * @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
136
143
  * @deprecated Use {@link computeStart} instead.
137
144
  */
138
- computeStartV1(providerUri: string, consumer: Signer, computeEnv: string, dataset: ComputeAsset, algorithm: ComputeAlgorithm, signal?: AbortSignal, additionalDatasets?: ComputeAsset[], output?: ComputeOutput, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
145
+ computeStartV1(providerUri: string, consumer: Signer, computeEnv: string, dataset: ComputeAsset, algorithm: ComputeAlgorithm, signal?: AbortSignal, additionalDatasets?: ComputeAsset[], output?: ComputeOutput): Promise<ComputeJob | ComputeJob[]>;
139
146
  /** Instruct the provider to start a PAYED compute job (new C2D V2)
140
147
  * @param {string} providerUri The provider URI.
141
- * @param {Signer} signer The consumer signer object.
148
+ * @param {SignerOrAuthToken} signerOrAuthToken The consumer signer object or auth token.
142
149
  * @param {string} computeEnv The compute environment.
143
150
  * @param {ComputeAsset} datasets The dataset to start compute on + additionalDatasets (the additional datasets if that is the case)
144
151
  * @param {ComputeAlgorithm} algorithm The algorithm to start compute with.
@@ -146,44 +153,48 @@ export declare class Provider {
146
153
  * @param {string} token The token address for compute payment.
147
154
  * @param {ComputeResourceRequest} resources The resources to start compute job with.
148
155
  * @param {chainId} chainId The chain used to do payments
156
+ * @param {ComputeJobMetadata} metadata The compute job metadata. Additional metadata to be stored in the database.
149
157
  * @param {ComputeOutput} output The compute job output settings.
158
+ * @param {PolicyServer} policyServer The policy server object.
150
159
  * @param {AbortSignal} signal abort signal
151
160
  * @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
152
161
  */
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)
154
- output?: ComputeOutput, signal?: AbortSignal, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
162
+ 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)
163
+ metadata?: ComputeJobMetadata, output?: ComputeOutput, policyServer?: PolicyServer, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
155
164
  /** Instruct the provider to start a FREE compute job (new C2D V2)
156
165
  * @param {string} providerUri The provider URI.
157
- * @param {Signer} signer The consumer signer object.
166
+ * @param {SignerOrAuthToken} signerOrAuthToken The consumer signer object or auth token.
158
167
  * @param {string} computeEnv The compute environment.
159
168
  * @param {ComputeAsset} datasets The dataset to start compute on + additionalDatasets (the additional datasets if that is the case)
160
169
  * @param {ComputeAlgorithm} algorithm The algorithm to start compute with.
161
170
  * @param {ComputeResourceRequest} resources The resources to start compute job with.
171
+ * @param {ComputeJobMetadata} metadata The compute job metadata. Additional metadata to be stored in the database.
162
172
  * @param {ComputeOutput} output The compute job output settings.
173
+ * @param {PolicyServer} policyServer The policy server object.
163
174
  * @param {AbortSignal} signal abort signal
164
175
  * @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
165
176
  */
166
- freeComputeStart(providerUri: string, consumer: Signer, computeEnv: string, datasets: ComputeAsset[], algorithm: ComputeAlgorithm, resources?: ComputeResourceRequest[], output?: ComputeOutput, signal?: AbortSignal, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
177
+ freeComputeStart(providerUri: string, signerOrAuthToken: Signer | string, computeEnv: string, datasets: ComputeAsset[], algorithm: ComputeAlgorithm, resources?: ComputeResourceRequest[], metadata?: ComputeJobMetadata, output?: ComputeOutput, policyServer?: PolicyServer, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
167
178
  /**
168
179
  *
169
180
  * @param providerUri provider URL
170
- * @param consumer consumer
181
+ * @param signerOrAuthToken signer or auth token
171
182
  * @param jobId jobId
172
183
  * @param signal abort signal
173
184
  * @returns logs response
174
185
  */
175
- computeStreamableLogs(providerUri: string, signer: Signer, jobId: string, signal?: AbortSignal, authorization?: string): Promise<any>;
186
+ computeStreamableLogs(providerUri: string, signerOrAuthToken: Signer | string, jobId: string, signal?: AbortSignal): Promise<any>;
176
187
  getComputeStartRoutes(providerUri: string, isFreeCompute?: boolean): Promise<string | null>;
177
188
  /** Instruct the provider to Stop the execution of a to stop a compute job.
178
189
  * @param {string} did the asset did
179
190
  * @param {string} consumerAddress The consumer address.
180
191
  * @param {string} jobId the compute job id
181
192
  * @param {string} providerUri The provider URI.
182
- * @param {Signer} signer The consumer signer object.
193
+ * @param {SignerOrAuthToken} signerOrAuthToken The consumer signer or auth token.
183
194
  * @param {AbortSignal} signal abort signal
184
195
  * @return {Promise<ComputeJob | ComputeJob[]>}
185
196
  */
186
- computeStop(did: string, consumerAddress: string, jobId: string, providerUri: string, signer: Signer, agreementId?: string, signal?: AbortSignal, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
197
+ computeStop(did: string, consumerAddress: string, jobId: string, providerUri: string, signerOrAuthToken: Signer | string, agreementId?: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
187
198
  /** Get compute status for a specific jobId/documentId/owner.
188
199
  * @param {string} providerUri The URI of the provider we want to query
189
200
  * @param {string} consumerAddress The consumer ethereum address
@@ -195,21 +206,21 @@ export declare class Provider {
195
206
  computeStatus(providerUri: string, consumerAddress: string, jobId?: string, agreementId?: string, signal?: AbortSignal, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
196
207
  /** Get compute result url
197
208
  * @param {string} providerUri The URI of the provider we want to query
198
- * @param {Signer} consumer consumer Signer wallet object
209
+ * @param {SignerOrAuthToken} signerOrAuthToken signer or auth token
199
210
  * @param {string} jobId The ID of a compute job.
200
211
  * @param {number} index Result index
201
212
  * @return {Promise<string>}
202
213
  */
203
- getComputeResultUrl(providerUri: string, consumer: Signer, jobId: string, index: number, authorization?: string): Promise<string>;
214
+ getComputeResultUrl(providerUri: string, signerOrAuthToken: Signer | string, jobId: string, index: number): Promise<string>;
204
215
  /** Deletes a compute job.
205
216
  * @param {string} did asset did
206
- * @param {Signer} consumer consumer Signer wallet object
217
+ * @param {SignerOrAuthToken} signerOrAuthToken signer or auth token
207
218
  * @param {string} jobId the compute job ID
208
219
  * @param {string} providerUri The URI of the provider we want to query
209
220
  * @param {AbortSignal} signal abort signal
210
221
  * @return {Promise<ComputeJob | ComputeJob[]>}
211
222
  */
212
- computeDelete(did: string, consumer: Signer, jobId: string, providerUri: string, signal?: AbortSignal, authorization?: string): Promise<ComputeJob | ComputeJob[]>;
223
+ computeDelete(did: string, signerOrAuthToken: Signer | string, jobId: string, providerUri: string, signal?: AbortSignal): Promise<ComputeJob | ComputeJob[]>;
213
224
  /** Generates an auth token
214
225
  * @param {Signer} consumer consumer Signer wallet object
215
226
  * @param {string} providerUri The URI of the provider we want to query
@@ -232,7 +243,7 @@ export declare class Provider {
232
243
  * @param {AbortSignal} signal abort signal
233
244
  * @return {Promise<boolean>} valid or not
234
245
  */
235
- isValidProvider(url: string, signal?: AbortSignal, authorization?: string): Promise<boolean>;
246
+ isValidProvider(url: string, signal?: AbortSignal): Promise<boolean>;
236
247
  /**
237
248
  * Private method that removes the leading 0x from a string.
238
249
  * @param {string} input - The input string.
@@ -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.2.0",
4
+ "version": "4.3.0",
5
5
  "description": "JavaScript client library for Ocean Protocol",
6
6
  "main": "./dist/lib.cjs",
7
7
  "umd:main": "dist/lib.umd.js",
@@ -58,7 +58,7 @@
58
58
  "dependencies": {
59
59
  "@oasisprotocol/sapphire-paratime": "^1.3.2",
60
60
  "@oceanprotocol/contracts": "^2.3.0",
61
- "@oceanprotocol/ddo-js": "^0.1.0",
61
+ "@oceanprotocol/ddo-js": "^0.1.2",
62
62
  "@rdfjs/dataset": "^2.0.2",
63
63
  "@rdfjs/formats-common": "^3.1.0",
64
64
  "@zazuko/env-node": "^2.1.4",
@@ -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",