@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.
@@ -294,11 +294,12 @@ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any,
294
294
 
295
295
  /**
296
296
  * Raises a dispute against an IP NFT.
297
- * Requires the caller to have the dispute bond amount in dispute tokens.
297
+ * Automatically handles token approval for ERC20 bonds or native token value.
298
+ * Includes the protocol dispute fee in the transaction.
298
299
  *
299
300
  * @param targetIpId The token ID of the IP NFT to dispute.
300
301
  * @param evidenceHash The hash of evidence supporting the dispute.
301
- * @param disputeTag A tag identifying the type of dispute.
302
+ * @param disputeTag A tag identifying the type of dispute (bytes32).
302
303
  * @returns A promise that resolves with the transaction result including the dispute ID.
303
304
  *
304
305
  * @example
@@ -306,7 +307,7 @@ declare function getDataWithIntent(this: Origin, tokenId: bigint, signer?: any,
306
307
  * const result = await origin.raiseDispute(
307
308
  * 1n,
308
309
  * "0x1234...", // evidence hash
309
- * "0x5678..." // dispute tag (e.g., "infringement", "fraud")
310
+ * "0x0100000000000000000000000000000000000000000000000000000000000000" // dispute tag (bytes32)
310
311
  * );
311
312
  * ```
312
313
  */
@@ -319,9 +320,13 @@ interface RaiseDisputeSmartResult {
319
320
  }
320
321
  /**
321
322
  * Raises a dispute with automatic evidence upload to IPFS.
322
- * Uploads evidence JSON to IPFS, hashes the CID to bytes32 for on-chain storage,
323
+ * Uploads evidence JSON to IPFS, encodes the CID to bytes32 for on-chain storage,
323
324
  * and calls raiseDispute.
324
325
  *
326
+ * The CID is encoded by stripping the 0x1220 multihash prefix from CIDv0,
327
+ * leaving only the 32-byte SHA-256 digest. This encoding is reversible,
328
+ * allowing the original CID to be reconstructed from the on-chain data.
329
+ *
325
330
  * @param targetIpId The token ID of the IP NFT to dispute.
326
331
  * @param evidence The evidence JSON object to upload to IPFS.
327
332
  * @param disputeTag A tag identifying the type of dispute.
@@ -335,13 +340,11 @@ interface RaiseDisputeSmartResult {
335
340
  * "0x696e6672696e67656d656e74..." // dispute tag
336
341
  * );
337
342
  *
338
- * // Store the CID for evidence retrieval
343
+ * // The CID can be recovered from evidenceHash using decodeCidFromBytes32
339
344
  * console.log("Evidence CID:", result.evidenceCid);
340
345
  *
341
- * // Fetch evidence later via IPFS gateway
346
+ * // Fetch evidence via IPFS gateway
342
347
  * // https://ipfs.io/ipfs/{result.evidenceCid}
343
- *
344
- * // Verify evidence hash matches on-chain: keccak256(toHex(evidenceCid)) === evidenceHash
345
348
  * ```
346
349
  */
347
350
  declare function raiseDisputeSmart(this: Origin, targetIpId: bigint, evidence: Record<string, any>, disputeTag: Hex): Promise<RaiseDisputeSmartResult>;
@@ -361,6 +364,42 @@ declare function raiseDisputeSmart(this: Origin, targetIpId: bigint, evidence: R
361
364
  */
362
365
  declare function disputeAssertion(this: Origin, disputeId: bigint, counterEvidenceHash: Hex): Promise<any>;
363
366
 
367
+ interface DisputeAssertionSmartResult {
368
+ transactionResult: any;
369
+ counterEvidenceCid: string;
370
+ counterEvidenceHash: Hex;
371
+ }
372
+ /**
373
+ * Asserts a dispute with automatic counter-evidence upload to IPFS.
374
+ * Uploads counter-evidence JSON to IPFS, encodes the CID to bytes32 for on-chain storage,
375
+ * and calls disputeAssertion.
376
+ *
377
+ * The CID is encoded by stripping the 0x1220 multihash prefix from CIDv0,
378
+ * leaving only the 32-byte SHA-256 digest. This encoding is reversible,
379
+ * allowing the original CID to be reconstructed from the on-chain data.
380
+ *
381
+ * Must be called by the owner of the disputed IP within the cooldown period.
382
+ *
383
+ * @param disputeId The ID of the dispute to assert.
384
+ * @param counterEvidence The counter-evidence JSON object to upload to IPFS.
385
+ * @returns A promise that resolves with the transaction result, IPFS CID, and counter-evidence hash.
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * const result = await origin.disputeAssertionSmart(
390
+ * 1n,
391
+ * { description: "This is my original work", proofUrl: "https://..." }
392
+ * );
393
+ *
394
+ * // The CID can be recovered from counterEvidenceHash using decodeCidFromBytes32
395
+ * console.log("Counter-evidence CID:", result.counterEvidenceCid);
396
+ *
397
+ * // Fetch counter-evidence via IPFS gateway
398
+ * // https://ipfs.io/ipfs/{result.counterEvidenceCid}
399
+ * ```
400
+ */
401
+ declare function disputeAssertionSmart(this: Origin, disputeId: bigint, counterEvidence: Record<string, any>): Promise<DisputeAssertionSmartResult>;
402
+
364
403
  /**
365
404
  * Votes on a dispute as a CAMP token staker.
366
405
  * Only users who staked before the dispute was raised can vote.
@@ -540,6 +579,31 @@ interface DisputeProgress {
540
579
  */
541
580
  declare function getDisputeProgress(this: Origin, disputeId: bigint): Promise<DisputeProgress>;
542
581
 
582
+ interface DisputeRequirements {
583
+ bondAmount: bigint;
584
+ protocolFee: bigint;
585
+ totalRequired: bigint;
586
+ tokenAddress: Address;
587
+ isNativeToken: boolean;
588
+ userBalance: bigint;
589
+ hasSufficientBalance: boolean;
590
+ }
591
+ /**
592
+ * Gets the requirements for raising a dispute, including balance check.
593
+ *
594
+ * @param userAddress The address to check balance for.
595
+ * @returns A promise that resolves with the dispute requirements.
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const requirements = await origin.getDisputeRequirements(walletAddress);
600
+ * if (!requirements.hasSufficientBalance) {
601
+ * console.log(`Need ${requirements.totalRequired} but only have ${requirements.userBalance}`);
602
+ * }
603
+ * ```
604
+ */
605
+ declare function getDisputeRequirements(this: Origin, userAddress: Address): Promise<DisputeRequirements>;
606
+
543
607
  /**
544
608
  * Fractionalizes an IP NFT into fungible ERC20 tokens.
545
609
  * The NFT is transferred to the fractionalizer contract and a new ERC20 token is created.
@@ -901,6 +965,7 @@ declare class Origin {
901
965
  raiseDispute: typeof raiseDispute;
902
966
  raiseDisputeSmart: typeof raiseDisputeSmart;
903
967
  disputeAssertion: typeof disputeAssertion;
968
+ disputeAssertionSmart: typeof disputeAssertionSmart;
904
969
  voteOnDispute: typeof voteOnDispute;
905
970
  resolveDispute: typeof resolveDispute;
906
971
  cancelDispute: typeof cancelDispute;
@@ -908,6 +973,7 @@ declare class Origin {
908
973
  getDispute: typeof getDispute;
909
974
  canVoteOnDispute: typeof canVoteOnDispute;
910
975
  getDisputeProgress: typeof getDisputeProgress;
976
+ getDisputeRequirements: typeof getDisputeRequirements;
911
977
  fractionalize: typeof fractionalize;
912
978
  redeem: typeof redeem;
913
979
  getTokenForNFT: typeof getTokenForNFT;
@@ -924,6 +990,14 @@ declare class Origin {
924
990
  constructor(environment?: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint, appId?: string);
925
991
  getJwt(): string | undefined;
926
992
  setViemClient(client: WalletClient): void;
993
+ /**
994
+ * Approves an ERC20 token for spending by a spender address if the current allowance is insufficient.
995
+ * Waits for the approval transaction to be confirmed before returning.
996
+ * @param tokenAddress The address of the ERC20 token.
997
+ * @param spender The address that will be approved to spend the tokens.
998
+ * @param amount The amount of tokens to approve.
999
+ */
1000
+ approveERC20IfNeeded(tokenAddress: Address, spender: Address, amount: bigint): Promise<void>;
927
1001
  /**
928
1002
  * Uploads a JSON object to IPFS and returns the resulting CID.
929
1003
  * @param data The JSON object to upload.