@campnetwork/origin 1.3.0-alpha.1 → 1.3.0-alpha.10

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
@@ -433,11 +433,12 @@ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any,
433
433
 
434
434
  /**
435
435
  * Raises a dispute against an IP NFT.
436
- * Requires the caller to have the dispute bond amount in dispute tokens.
436
+ * Automatically handles token approval for ERC20 bonds or native token value.
437
+ * Includes the protocol dispute fee in the transaction.
437
438
  *
438
439
  * @param targetIpId The token ID of the IP NFT to dispute.
439
440
  * @param evidenceHash The hash of evidence supporting the dispute.
440
- * @param disputeTag A tag identifying the type of dispute.
441
+ * @param disputeTag A tag identifying the type of dispute (bytes32).
441
442
  * @returns A promise that resolves with the transaction result including the dispute ID.
442
443
  *
443
444
  * @example
@@ -445,7 +446,7 @@ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any,
445
446
  * const result = await origin.raiseDispute(
446
447
  * 1n,
447
448
  * "0x1234...", // evidence hash
448
- * "0x5678..." // dispute tag (e.g., "infringement", "fraud")
449
+ * "0x0100000000000000000000000000000000000000000000000000000000000000" // dispute tag (bytes32)
449
450
  * );
450
451
  * ```
451
452
  */
@@ -458,9 +459,13 @@ interface RaiseDisputeSmartResult {
458
459
  }
459
460
  /**
460
461
  * Raises a dispute with automatic evidence upload to IPFS.
461
- * Uploads evidence JSON to IPFS, hashes the CID to bytes32 for on-chain storage,
462
+ * Uploads evidence JSON to IPFS, encodes the CID to bytes32 for on-chain storage,
462
463
  * and calls raiseDispute.
463
464
  *
465
+ * The CID is encoded by stripping the 0x1220 multihash prefix from CIDv0,
466
+ * leaving only the 32-byte SHA-256 digest. This encoding is reversible,
467
+ * allowing the original CID to be reconstructed from the on-chain data.
468
+ *
464
469
  * @param targetIpId The token ID of the IP NFT to dispute.
465
470
  * @param evidence The evidence JSON object to upload to IPFS.
466
471
  * @param disputeTag A tag identifying the type of dispute.
@@ -474,17 +479,26 @@ interface RaiseDisputeSmartResult {
474
479
  * "0x696e6672696e67656d656e74..." // dispute tag
475
480
  * );
476
481
  *
477
- * // Store the CID for evidence retrieval
482
+ * // The CID can be recovered from evidenceHash using decodeCidFromBytes32
478
483
  * console.log("Evidence CID:", result.evidenceCid);
479
484
  *
480
- * // Fetch evidence later via IPFS gateway
485
+ * // Fetch evidence via IPFS gateway
481
486
  * // https://ipfs.io/ipfs/{result.evidenceCid}
482
- *
483
- * // Verify evidence hash matches on-chain: keccak256(toHex(evidenceCid)) === evidenceHash
484
487
  * ```
485
488
  */
486
489
  declare function raiseDisputeSmart(this: Origin, targetIpId: bigint, evidence: Record<string, any>, disputeTag: Hex): Promise<RaiseDisputeSmartResult>;
487
490
 
491
+ /**
492
+ * Encode a CID to bytes32 by extracting the 32-byte SHA-256 digest.
493
+ * Supports both CIDv0 (starts with "Qm") and CIDv1 (starts with "bafy").
494
+ */
495
+ declare function encodeCidToBytes32(cid: string): Hex;
496
+ /**
497
+ * Decode bytes32 back to CIDv1 format (base32, dag-pb codec).
498
+ * Returns a CID starting with "bafybei" that works with Pinata gateways.
499
+ */
500
+ declare function decodeCidFromBytes32(bytes32: Hex): string;
501
+
488
502
  /**
489
503
  * Asserts a dispute as the IP owner with counter-evidence.
490
504
  * Must be called by the owner of the disputed IP within the cooldown period.
@@ -500,6 +514,42 @@ declare function raiseDisputeSmart(this: Origin, targetIpId: bigint, evidence: R
500
514
  */
501
515
  declare function disputeAssertion(this: Origin, disputeId: bigint, counterEvidenceHash: Hex): Promise<any>;
502
516
 
517
+ interface DisputeAssertionSmartResult {
518
+ transactionResult: any;
519
+ counterEvidenceCid: string;
520
+ counterEvidenceHash: Hex;
521
+ }
522
+ /**
523
+ * Asserts a dispute with automatic counter-evidence upload to IPFS.
524
+ * Uploads counter-evidence JSON to IPFS, encodes the CID to bytes32 for on-chain storage,
525
+ * and calls disputeAssertion.
526
+ *
527
+ * The CID is encoded by stripping the 0x1220 multihash prefix from CIDv0,
528
+ * leaving only the 32-byte SHA-256 digest. This encoding is reversible,
529
+ * allowing the original CID to be reconstructed from the on-chain data.
530
+ *
531
+ * Must be called by the owner of the disputed IP within the cooldown period.
532
+ *
533
+ * @param disputeId The ID of the dispute to assert.
534
+ * @param counterEvidence The counter-evidence JSON object to upload to IPFS.
535
+ * @returns A promise that resolves with the transaction result, IPFS CID, and counter-evidence hash.
536
+ *
537
+ * @example
538
+ * ```typescript
539
+ * const result = await origin.disputeAssertionSmart(
540
+ * 1n,
541
+ * { description: "This is my original work", proofUrl: "https://..." }
542
+ * );
543
+ *
544
+ * // The CID can be recovered from counterEvidenceHash using decodeCidFromBytes32
545
+ * console.log("Counter-evidence CID:", result.counterEvidenceCid);
546
+ *
547
+ * // Fetch counter-evidence via IPFS gateway
548
+ * // https://ipfs.io/ipfs/{result.counterEvidenceCid}
549
+ * ```
550
+ */
551
+ declare function disputeAssertionSmart(this: Origin, disputeId: bigint, counterEvidence: Record<string, any>): Promise<DisputeAssertionSmartResult>;
552
+
503
553
  /**
504
554
  * Votes on a dispute as a CAMP token staker.
505
555
  * Only users who staked before the dispute was raised can vote.
@@ -679,6 +729,31 @@ interface DisputeProgress {
679
729
  */
680
730
  declare function getDisputeProgress(this: Origin, disputeId: bigint): Promise<DisputeProgress>;
681
731
 
732
+ interface DisputeRequirements {
733
+ bondAmount: bigint;
734
+ protocolFee: bigint;
735
+ totalRequired: bigint;
736
+ tokenAddress: Address;
737
+ isNativeToken: boolean;
738
+ userBalance: bigint;
739
+ hasSufficientBalance: boolean;
740
+ }
741
+ /**
742
+ * Gets the requirements for raising a dispute, including balance check.
743
+ *
744
+ * @param userAddress The address to check balance for.
745
+ * @returns A promise that resolves with the dispute requirements.
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * const requirements = await origin.getDisputeRequirements(walletAddress);
750
+ * if (!requirements.hasSufficientBalance) {
751
+ * console.log(`Need ${requirements.totalRequired} but only have ${requirements.userBalance}`);
752
+ * }
753
+ * ```
754
+ */
755
+ declare function getDisputeRequirements(this: Origin, userAddress: Address): Promise<DisputeRequirements>;
756
+
682
757
  /**
683
758
  * Fractionalizes an IP NFT into fungible ERC20 tokens.
684
759
  * The NFT is transferred to the fractionalizer contract and a new ERC20 token is created.
@@ -1050,6 +1125,7 @@ declare class Origin {
1050
1125
  raiseDispute: typeof raiseDispute;
1051
1126
  raiseDisputeSmart: typeof raiseDisputeSmart;
1052
1127
  disputeAssertion: typeof disputeAssertion;
1128
+ disputeAssertionSmart: typeof disputeAssertionSmart;
1053
1129
  voteOnDispute: typeof voteOnDispute;
1054
1130
  resolveDispute: typeof resolveDispute;
1055
1131
  cancelDispute: typeof cancelDispute;
@@ -1057,6 +1133,7 @@ declare class Origin {
1057
1133
  getDispute: typeof getDispute;
1058
1134
  canVoteOnDispute: typeof canVoteOnDispute;
1059
1135
  getDisputeProgress: typeof getDisputeProgress;
1136
+ getDisputeRequirements: typeof getDisputeRequirements;
1060
1137
  fractionalize: typeof fractionalize;
1061
1138
  redeem: typeof redeem;
1062
1139
  getTokenForNFT: typeof getTokenForNFT;
@@ -1073,6 +1150,14 @@ declare class Origin {
1073
1150
  constructor(environment?: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint, appId?: string);
1074
1151
  getJwt(): string | undefined;
1075
1152
  setViemClient(client: WalletClient): void;
1153
+ /**
1154
+ * Approves an ERC20 token for spending by a spender address if the current allowance is insufficient.
1155
+ * Waits for the approval transaction to be confirmed before returning.
1156
+ * @param tokenAddress The address of the ERC20 token.
1157
+ * @param spender The address that will be approved to spend the tokens.
1158
+ * @param amount The amount of tokens to approve.
1159
+ */
1160
+ approveERC20IfNeeded(tokenAddress: Address, spender: Address, amount: bigint): Promise<void>;
1076
1161
  /**
1077
1162
  * Uploads a JSON object to IPFS and returns the resulting CID.
1078
1163
  * @param data The JSON object to upload.
@@ -1419,4 +1504,4 @@ declare class Auth {
1419
1504
  unlinkTelegram(): Promise<any>;
1420
1505
  }
1421
1506
 
1422
- export { type AppInfo, Auth, type BaseSigner, BrowserStorage, type BulkCostPreview, type BuyParams, CustomSignerAdapter, DataStatus, type Dispute, type DisputeProgress, DisputeStatus, EthersSignerAdapter, type FractionOwnership, type FractionalizeEligibility, type LicenseTerms, LicenseType, MemoryStorage, Origin, type SignerAdapter, type SignerType, type StorageAdapter, type TokenInfo, type TolerantResult, ViemSignerAdapter, type VoteEligibility, mainnet as campMainnet, testnet as campTestnet, createLicenseTerms, createNodeWalletClient, createSignerAdapter };
1507
+ export { type AppInfo, Auth, type BaseSigner, BrowserStorage, type BulkCostPreview, type BuyParams, CustomSignerAdapter, DataStatus, type Dispute, type DisputeProgress, DisputeStatus, EthersSignerAdapter, type FractionOwnership, type FractionalizeEligibility, type LicenseTerms, LicenseType, MemoryStorage, Origin, type SignerAdapter, type SignerType, type StorageAdapter, type TokenInfo, type TolerantResult, ViemSignerAdapter, type VoteEligibility, mainnet as campMainnet, testnet as campTestnet, createLicenseTerms, createNodeWalletClient, createSignerAdapter, decodeCidFromBytes32, encodeCidToBytes32 };
@@ -433,11 +433,12 @@ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any,
433
433
 
434
434
  /**
435
435
  * Raises a dispute against an IP NFT.
436
- * Requires the caller to have the dispute bond amount in dispute tokens.
436
+ * Automatically handles token approval for ERC20 bonds or native token value.
437
+ * Includes the protocol dispute fee in the transaction.
437
438
  *
438
439
  * @param targetIpId The token ID of the IP NFT to dispute.
439
440
  * @param evidenceHash The hash of evidence supporting the dispute.
440
- * @param disputeTag A tag identifying the type of dispute.
441
+ * @param disputeTag A tag identifying the type of dispute (bytes32).
441
442
  * @returns A promise that resolves with the transaction result including the dispute ID.
442
443
  *
443
444
  * @example
@@ -445,7 +446,7 @@ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any,
445
446
  * const result = await origin.raiseDispute(
446
447
  * 1n,
447
448
  * "0x1234...", // evidence hash
448
- * "0x5678..." // dispute tag (e.g., "infringement", "fraud")
449
+ * "0x0100000000000000000000000000000000000000000000000000000000000000" // dispute tag (bytes32)
449
450
  * );
450
451
  * ```
451
452
  */
@@ -458,9 +459,13 @@ interface RaiseDisputeSmartResult {
458
459
  }
459
460
  /**
460
461
  * Raises a dispute with automatic evidence upload to IPFS.
461
- * Uploads evidence JSON to IPFS, hashes the CID to bytes32 for on-chain storage,
462
+ * Uploads evidence JSON to IPFS, encodes the CID to bytes32 for on-chain storage,
462
463
  * and calls raiseDispute.
463
464
  *
465
+ * The CID is encoded by stripping the 0x1220 multihash prefix from CIDv0,
466
+ * leaving only the 32-byte SHA-256 digest. This encoding is reversible,
467
+ * allowing the original CID to be reconstructed from the on-chain data.
468
+ *
464
469
  * @param targetIpId The token ID of the IP NFT to dispute.
465
470
  * @param evidence The evidence JSON object to upload to IPFS.
466
471
  * @param disputeTag A tag identifying the type of dispute.
@@ -474,17 +479,26 @@ interface RaiseDisputeSmartResult {
474
479
  * "0x696e6672696e67656d656e74..." // dispute tag
475
480
  * );
476
481
  *
477
- * // Store the CID for evidence retrieval
482
+ * // The CID can be recovered from evidenceHash using decodeCidFromBytes32
478
483
  * console.log("Evidence CID:", result.evidenceCid);
479
484
  *
480
- * // Fetch evidence later via IPFS gateway
485
+ * // Fetch evidence via IPFS gateway
481
486
  * // https://ipfs.io/ipfs/{result.evidenceCid}
482
- *
483
- * // Verify evidence hash matches on-chain: keccak256(toHex(evidenceCid)) === evidenceHash
484
487
  * ```
485
488
  */
486
489
  declare function raiseDisputeSmart(this: Origin, targetIpId: bigint, evidence: Record<string, any>, disputeTag: Hex): Promise<RaiseDisputeSmartResult>;
487
490
 
491
+ /**
492
+ * Encode a CID to bytes32 by extracting the 32-byte SHA-256 digest.
493
+ * Supports both CIDv0 (starts with "Qm") and CIDv1 (starts with "bafy").
494
+ */
495
+ declare function encodeCidToBytes32(cid: string): Hex;
496
+ /**
497
+ * Decode bytes32 back to CIDv1 format (base32, dag-pb codec).
498
+ * Returns a CID starting with "bafybei" that works with Pinata gateways.
499
+ */
500
+ declare function decodeCidFromBytes32(bytes32: Hex): string;
501
+
488
502
  /**
489
503
  * Asserts a dispute as the IP owner with counter-evidence.
490
504
  * Must be called by the owner of the disputed IP within the cooldown period.
@@ -500,6 +514,42 @@ declare function raiseDisputeSmart(this: Origin, targetIpId: bigint, evidence: R
500
514
  */
501
515
  declare function disputeAssertion(this: Origin, disputeId: bigint, counterEvidenceHash: Hex): Promise<any>;
502
516
 
517
+ interface DisputeAssertionSmartResult {
518
+ transactionResult: any;
519
+ counterEvidenceCid: string;
520
+ counterEvidenceHash: Hex;
521
+ }
522
+ /**
523
+ * Asserts a dispute with automatic counter-evidence upload to IPFS.
524
+ * Uploads counter-evidence JSON to IPFS, encodes the CID to bytes32 for on-chain storage,
525
+ * and calls disputeAssertion.
526
+ *
527
+ * The CID is encoded by stripping the 0x1220 multihash prefix from CIDv0,
528
+ * leaving only the 32-byte SHA-256 digest. This encoding is reversible,
529
+ * allowing the original CID to be reconstructed from the on-chain data.
530
+ *
531
+ * Must be called by the owner of the disputed IP within the cooldown period.
532
+ *
533
+ * @param disputeId The ID of the dispute to assert.
534
+ * @param counterEvidence The counter-evidence JSON object to upload to IPFS.
535
+ * @returns A promise that resolves with the transaction result, IPFS CID, and counter-evidence hash.
536
+ *
537
+ * @example
538
+ * ```typescript
539
+ * const result = await origin.disputeAssertionSmart(
540
+ * 1n,
541
+ * { description: "This is my original work", proofUrl: "https://..." }
542
+ * );
543
+ *
544
+ * // The CID can be recovered from counterEvidenceHash using decodeCidFromBytes32
545
+ * console.log("Counter-evidence CID:", result.counterEvidenceCid);
546
+ *
547
+ * // Fetch counter-evidence via IPFS gateway
548
+ * // https://ipfs.io/ipfs/{result.counterEvidenceCid}
549
+ * ```
550
+ */
551
+ declare function disputeAssertionSmart(this: Origin, disputeId: bigint, counterEvidence: Record<string, any>): Promise<DisputeAssertionSmartResult>;
552
+
503
553
  /**
504
554
  * Votes on a dispute as a CAMP token staker.
505
555
  * Only users who staked before the dispute was raised can vote.
@@ -679,6 +729,31 @@ interface DisputeProgress {
679
729
  */
680
730
  declare function getDisputeProgress(this: Origin, disputeId: bigint): Promise<DisputeProgress>;
681
731
 
732
+ interface DisputeRequirements {
733
+ bondAmount: bigint;
734
+ protocolFee: bigint;
735
+ totalRequired: bigint;
736
+ tokenAddress: Address;
737
+ isNativeToken: boolean;
738
+ userBalance: bigint;
739
+ hasSufficientBalance: boolean;
740
+ }
741
+ /**
742
+ * Gets the requirements for raising a dispute, including balance check.
743
+ *
744
+ * @param userAddress The address to check balance for.
745
+ * @returns A promise that resolves with the dispute requirements.
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * const requirements = await origin.getDisputeRequirements(walletAddress);
750
+ * if (!requirements.hasSufficientBalance) {
751
+ * console.log(`Need ${requirements.totalRequired} but only have ${requirements.userBalance}`);
752
+ * }
753
+ * ```
754
+ */
755
+ declare function getDisputeRequirements(this: Origin, userAddress: Address): Promise<DisputeRequirements>;
756
+
682
757
  /**
683
758
  * Fractionalizes an IP NFT into fungible ERC20 tokens.
684
759
  * The NFT is transferred to the fractionalizer contract and a new ERC20 token is created.
@@ -1050,6 +1125,7 @@ declare class Origin {
1050
1125
  raiseDispute: typeof raiseDispute;
1051
1126
  raiseDisputeSmart: typeof raiseDisputeSmart;
1052
1127
  disputeAssertion: typeof disputeAssertion;
1128
+ disputeAssertionSmart: typeof disputeAssertionSmart;
1053
1129
  voteOnDispute: typeof voteOnDispute;
1054
1130
  resolveDispute: typeof resolveDispute;
1055
1131
  cancelDispute: typeof cancelDispute;
@@ -1057,6 +1133,7 @@ declare class Origin {
1057
1133
  getDispute: typeof getDispute;
1058
1134
  canVoteOnDispute: typeof canVoteOnDispute;
1059
1135
  getDisputeProgress: typeof getDisputeProgress;
1136
+ getDisputeRequirements: typeof getDisputeRequirements;
1060
1137
  fractionalize: typeof fractionalize;
1061
1138
  redeem: typeof redeem;
1062
1139
  getTokenForNFT: typeof getTokenForNFT;
@@ -1073,6 +1150,14 @@ declare class Origin {
1073
1150
  constructor(environment?: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint, appId?: string);
1074
1151
  getJwt(): string | undefined;
1075
1152
  setViemClient(client: WalletClient): void;
1153
+ /**
1154
+ * Approves an ERC20 token for spending by a spender address if the current allowance is insufficient.
1155
+ * Waits for the approval transaction to be confirmed before returning.
1156
+ * @param tokenAddress The address of the ERC20 token.
1157
+ * @param spender The address that will be approved to spend the tokens.
1158
+ * @param amount The amount of tokens to approve.
1159
+ */
1160
+ approveERC20IfNeeded(tokenAddress: Address, spender: Address, amount: bigint): Promise<void>;
1076
1161
  /**
1077
1162
  * Uploads a JSON object to IPFS and returns the resulting CID.
1078
1163
  * @param data The JSON object to upload.
@@ -1419,4 +1504,4 @@ declare class Auth {
1419
1504
  unlinkTelegram(): Promise<any>;
1420
1505
  }
1421
1506
 
1422
- export { type AppInfo, Auth, type BaseSigner, BrowserStorage, type BulkCostPreview, type BuyParams, CustomSignerAdapter, DataStatus, type Dispute, type DisputeProgress, DisputeStatus, EthersSignerAdapter, type FractionOwnership, type FractionalizeEligibility, type LicenseTerms, LicenseType, MemoryStorage, Origin, type SignerAdapter, type SignerType, type StorageAdapter, type TokenInfo, type TolerantResult, ViemSignerAdapter, type VoteEligibility, mainnet as campMainnet, testnet as campTestnet, createLicenseTerms, createNodeWalletClient, createSignerAdapter };
1507
+ export { type AppInfo, Auth, type BaseSigner, BrowserStorage, type BulkCostPreview, type BuyParams, CustomSignerAdapter, DataStatus, type Dispute, type DisputeProgress, DisputeStatus, EthersSignerAdapter, type FractionOwnership, type FractionalizeEligibility, type LicenseTerms, LicenseType, MemoryStorage, Origin, type SignerAdapter, type SignerType, type StorageAdapter, type TokenInfo, type TolerantResult, ViemSignerAdapter, type VoteEligibility, mainnet as campMainnet, testnet as campTestnet, createLicenseTerms, createNodeWalletClient, createSignerAdapter, decodeCidFromBytes32, encodeCidToBytes32 };