@campnetwork/origin 1.2.1 → 1.2.3

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.
@@ -168,6 +168,52 @@ declare function hasAccess(this: Origin, user: Address, tokenId: bigint): Promis
168
168
 
169
169
  declare function subscriptionExpiry(this: Origin, tokenId: bigint, user: Address): Promise<bigint>;
170
170
 
171
+ /**
172
+ * Response from getDataWithX402 when payment is required
173
+ */
174
+ interface X402Response {
175
+ error: string;
176
+ marketplaceAction?: {
177
+ kind: string;
178
+ contract: Address;
179
+ network: string;
180
+ chainId: number;
181
+ method: string;
182
+ payer: Address;
183
+ payTo: Address;
184
+ tokenId: string;
185
+ duration: number;
186
+ asset: Address;
187
+ amount: string;
188
+ amountFormatted: string;
189
+ };
190
+ }
191
+ interface TransactionResult {
192
+ txHash: string;
193
+ receipt?: any;
194
+ }
195
+ /**
196
+ * Settles an X402 payment response by purchasing access if needed.
197
+ * This method checks if the user already has access to the item, and if not,
198
+ * it calls buyAccess with the parameters from the X402 response.
199
+ * Supports viem WalletClient, ethers Signer, and custom signer implementations.
200
+ *
201
+ * @param x402Response - The response from getDataWithX402 containing payment details.
202
+ * @param signer - Optional signer object used to interact with the blockchain. If not provided, uses the connected wallet client.
203
+ * @returns A promise that resolves with the transaction hash and receipt, or null if access already exists.
204
+ * @throws {Error} If the response doesn't contain marketplace action or if the method is not buyAccess.
205
+ */
206
+ declare function settleX402(this: Origin, x402Response: X402Response, signer?: any): Promise<TransactionResult | null>;
207
+
208
+ /**
209
+ * Fetch data with X402 payment handling.
210
+ * @param {bigint} tokenId The token ID to fetch data for.
211
+ * @param {any} [signer] Optional signer object for signing the X402 intent.
212
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
213
+ * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
214
+ */
215
+ declare function getDataWithX402(this: Origin, tokenId: bigint, signer?: any): Promise<any>;
216
+
171
217
  interface RoyaltyInfo {
172
218
  tokenBoundAccount: Address;
173
219
  balance: bigint;
@@ -203,12 +249,14 @@ declare class Origin {
203
249
  buyAccess: typeof buyAccess;
204
250
  hasAccess: typeof hasAccess;
205
251
  subscriptionExpiry: typeof subscriptionExpiry;
206
- private jwt;
252
+ settleX402: typeof settleX402;
253
+ getDataWithX402: typeof getDataWithX402;
254
+ private jwt?;
207
255
  environment: Environment;
208
256
  private viemClient?;
209
257
  baseParentId?: bigint;
210
- constructor(jwt: string, environment: Environment, viemClient?: WalletClient, baseParentId?: bigint);
211
- getJwt(): string;
258
+ constructor(environment: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint);
259
+ getJwt(): string | undefined;
212
260
  setViemClient(client: WalletClient): void;
213
261
  mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
214
262
  progressCallback?: (percent: number) => void;
@@ -231,6 +279,12 @@ declare class Origin {
231
279
  * @returns {Promise<any>} The result of the buyAccess call.
232
280
  */
233
281
  buyAccessSmart(tokenId: bigint): Promise<any>;
282
+ /**
283
+ * Fetch the underlying data associated with a specific token ID.
284
+ * @param {bigint} tokenId - The token ID to fetch data for.
285
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
286
+ * @throws {Error} Throws an error if the data cannot be fetched.
287
+ */
234
288
  getData(tokenId: bigint): Promise<any>;
235
289
  /**
236
290
  * Get the Token Bound Account (TBA) address for a specific token ID.