@campnetwork/origin 1.2.2 → 1.2.4

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/core.d.ts CHANGED
@@ -306,6 +306,52 @@ declare function hasAccess(this: Origin, user: Address, tokenId: bigint): Promis
306
306
 
307
307
  declare function subscriptionExpiry(this: Origin, tokenId: bigint, user: Address): Promise<bigint>;
308
308
 
309
+ /**
310
+ * Response from getDataWithX402 when payment is required
311
+ */
312
+ interface X402Response {
313
+ error: string;
314
+ marketplaceAction?: {
315
+ kind: string;
316
+ contract: Address;
317
+ network: string;
318
+ chainId: number;
319
+ method: string;
320
+ payer: Address;
321
+ payTo: Address;
322
+ tokenId: string;
323
+ duration: number;
324
+ asset: Address;
325
+ amount: string;
326
+ amountFormatted: string;
327
+ };
328
+ }
329
+ interface TransactionResult {
330
+ txHash: string;
331
+ receipt?: any;
332
+ }
333
+ /**
334
+ * Settles a payment intent response by purchasing access if needed.
335
+ * This method checks if the user already has access to the item, and if not,
336
+ * it calls buyAccess with the parameters from the payment intent response.
337
+ * Supports viem WalletClient, ethers Signer, and custom signer implementations.
338
+ *
339
+ * @param paymentIntentResponse - The response from getDataWithIntent containing payment details.
340
+ * @param signer - Optional signer object used to interact with the blockchain. If not provided, uses the connected wallet client.
341
+ * @returns A promise that resolves with the transaction hash and receipt, or null if access already exists.
342
+ * @throws {Error} If the response doesn't contain marketplace action or if the method is not buyAccess.
343
+ */
344
+ declare function settlePaymentIntent(this: Origin, paymentIntentResponse: X402Response, signer?: any): Promise<TransactionResult | null>;
345
+
346
+ /**
347
+ * Fetch data with X402 payment handling.
348
+ * @param {bigint} tokenId The token ID to fetch data for.
349
+ * @param {any} [signer] Optional signer object for signing the X402 intent.
350
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
351
+ * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
352
+ */
353
+ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any, decide?: (terms: any) => Promise<boolean>): Promise<any>;
354
+
309
355
  interface RoyaltyInfo {
310
356
  tokenBoundAccount: Address;
311
357
  balance: bigint;
@@ -341,11 +387,13 @@ declare class Origin {
341
387
  buyAccess: typeof buyAccess;
342
388
  hasAccess: typeof hasAccess;
343
389
  subscriptionExpiry: typeof subscriptionExpiry;
390
+ settlePaymentIntent: typeof settlePaymentIntent;
391
+ getDataWithIntent: typeof getDataWithIntent;
344
392
  private jwt?;
345
393
  environment: Environment;
346
394
  private viemClient?;
347
395
  baseParentId?: bigint;
348
- constructor(environment: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint);
396
+ constructor(environment?: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint);
349
397
  getJwt(): string | undefined;
350
398
  setViemClient(client: WalletClient): void;
351
399
  mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
@@ -376,14 +424,6 @@ declare class Origin {
376
424
  * @throws {Error} Throws an error if the data cannot be fetched.
377
425
  */
378
426
  getData(tokenId: bigint): Promise<any>;
379
- /**
380
- * Fetch data with X402 payment handling.
381
- * @param {bigint} tokenId The token ID to fetch data for.
382
- * @param {any} [signer] Optional signer object for signing the X402 intent.
383
- * @returns {Promise<any>} A promise that resolves with the fetched data.
384
- * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
385
- */
386
- getDataWithX402(tokenId: bigint, signer?: any): Promise<any>;
387
427
  /**
388
428
  * Get the Token Bound Account (TBA) address for a specific token ID.
389
429
  * @param {bigint} tokenId - The token ID to get the TBA address for.
@@ -306,6 +306,52 @@ declare function hasAccess(this: Origin, user: Address, tokenId: bigint): Promis
306
306
 
307
307
  declare function subscriptionExpiry(this: Origin, tokenId: bigint, user: Address): Promise<bigint>;
308
308
 
309
+ /**
310
+ * Response from getDataWithX402 when payment is required
311
+ */
312
+ interface X402Response {
313
+ error: string;
314
+ marketplaceAction?: {
315
+ kind: string;
316
+ contract: Address;
317
+ network: string;
318
+ chainId: number;
319
+ method: string;
320
+ payer: Address;
321
+ payTo: Address;
322
+ tokenId: string;
323
+ duration: number;
324
+ asset: Address;
325
+ amount: string;
326
+ amountFormatted: string;
327
+ };
328
+ }
329
+ interface TransactionResult {
330
+ txHash: string;
331
+ receipt?: any;
332
+ }
333
+ /**
334
+ * Settles a payment intent response by purchasing access if needed.
335
+ * This method checks if the user already has access to the item, and if not,
336
+ * it calls buyAccess with the parameters from the payment intent response.
337
+ * Supports viem WalletClient, ethers Signer, and custom signer implementations.
338
+ *
339
+ * @param paymentIntentResponse - The response from getDataWithIntent containing payment details.
340
+ * @param signer - Optional signer object used to interact with the blockchain. If not provided, uses the connected wallet client.
341
+ * @returns A promise that resolves with the transaction hash and receipt, or null if access already exists.
342
+ * @throws {Error} If the response doesn't contain marketplace action or if the method is not buyAccess.
343
+ */
344
+ declare function settlePaymentIntent(this: Origin, paymentIntentResponse: X402Response, signer?: any): Promise<TransactionResult | null>;
345
+
346
+ /**
347
+ * Fetch data with X402 payment handling.
348
+ * @param {bigint} tokenId The token ID to fetch data for.
349
+ * @param {any} [signer] Optional signer object for signing the X402 intent.
350
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
351
+ * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
352
+ */
353
+ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any, decide?: (terms: any) => Promise<boolean>): Promise<any>;
354
+
309
355
  interface RoyaltyInfo {
310
356
  tokenBoundAccount: Address;
311
357
  balance: bigint;
@@ -341,11 +387,13 @@ declare class Origin {
341
387
  buyAccess: typeof buyAccess;
342
388
  hasAccess: typeof hasAccess;
343
389
  subscriptionExpiry: typeof subscriptionExpiry;
390
+ settlePaymentIntent: typeof settlePaymentIntent;
391
+ getDataWithIntent: typeof getDataWithIntent;
344
392
  private jwt?;
345
393
  environment: Environment;
346
394
  private viemClient?;
347
395
  baseParentId?: bigint;
348
- constructor(environment: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint);
396
+ constructor(environment?: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint);
349
397
  getJwt(): string | undefined;
350
398
  setViemClient(client: WalletClient): void;
351
399
  mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
@@ -376,14 +424,6 @@ declare class Origin {
376
424
  * @throws {Error} Throws an error if the data cannot be fetched.
377
425
  */
378
426
  getData(tokenId: bigint): Promise<any>;
379
- /**
380
- * Fetch data with X402 payment handling.
381
- * @param {bigint} tokenId The token ID to fetch data for.
382
- * @param {any} [signer] Optional signer object for signing the X402 intent.
383
- * @returns {Promise<any>} A promise that resolves with the fetched data.
384
- * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
385
- */
386
- getDataWithX402(tokenId: bigint, signer?: any): Promise<any>;
387
427
  /**
388
428
  * Get the Token Bound Account (TBA) address for a specific token ID.
389
429
  * @param {bigint} tokenId - The token ID to get the TBA address for.