@campnetwork/origin 1.0.0-alpha.2 → 1.0.0-alpha.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.
@@ -12,6 +12,7 @@ interface Environment {
12
12
  CHAIN: any;
13
13
  IPNFT_ABI?: any;
14
14
  MARKETPLACE_ABI?: any;
15
+ ROYALTY_VAULT_ABI?: any;
15
16
  }
16
17
 
17
18
  /**
@@ -81,6 +82,13 @@ declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTer
81
82
  */
82
83
  declare function finalizeDelete(this: Origin, tokenId: bigint): Promise<any>;
83
84
 
85
+ /**
86
+ * Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
87
+ * @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
88
+ * @returns The address of the royalty vault associated with the specified token owner.
89
+ */
90
+ declare function getOrCreateRoyaltyVault(this: Origin, tokenOwner: Address): Promise<Address>;
91
+
84
92
  /**
85
93
  * Returns the license terms associated with a specific token ID.
86
94
  * @param tokenId The token ID to query.
@@ -163,6 +171,11 @@ interface OriginUsageReturnType {
163
171
  teams: Array<any>;
164
172
  dataSources: Array<any>;
165
173
  }
174
+ interface RoyaltyInfo {
175
+ royaltyVault: Address;
176
+ balance: bigint;
177
+ balanceFormatted: string;
178
+ }
166
179
  type CallOptions = {
167
180
  value?: bigint;
168
181
  gas?: bigint;
@@ -178,6 +191,7 @@ declare class Origin {
178
191
  registerIpNFT: typeof registerIpNFT;
179
192
  updateTerms: typeof updateTerms;
180
193
  finalizeDelete: typeof finalizeDelete;
194
+ getOrCreateRoyaltyVault: typeof getOrCreateRoyaltyVault;
181
195
  getTerms: typeof getTerms;
182
196
  ownerOf: typeof ownerOf;
183
197
  balanceOf: typeof balanceOf;
@@ -197,14 +211,14 @@ declare class Origin {
197
211
  constructor(jwt: string, environment: Environment, viemClient?: any);
198
212
  getJwt(): string;
199
213
  setViemClient(client: any): void;
200
- uploadFile: (file: File, options?: {
214
+ uploadFile(file: File, options?: {
201
215
  progressCallback?: (percent: number) => void;
202
- }) => Promise<any>;
203
- mintFile: (file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
216
+ }): Promise<any>;
217
+ mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
204
218
  progressCallback?: (percent: number) => void;
205
- }) => Promise<string | null>;
206
- mintSocial: (source: "spotify" | "twitter" | "tiktok", metadata: Record<string, unknown>, license: LicenseTerms) => Promise<string | null>;
207
- getOriginUploads: () => Promise<any>;
219
+ }): Promise<string | null>;
220
+ mintSocial(source: "spotify" | "twitter" | "tiktok", metadata: Record<string, unknown>, license: LicenseTerms): Promise<string | null>;
221
+ getOriginUploads(): Promise<any[] | null>;
208
222
  /**
209
223
  * Get the user's Origin stats (multiplier, consent, usage, etc.).
210
224
  * @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
@@ -235,6 +249,29 @@ declare class Origin {
235
249
  */
236
250
  buyAccessSmart(tokenId: bigint): Promise<any>;
237
251
  getData(tokenId: bigint): Promise<any>;
252
+ /**
253
+ * Get royalty information for a wallet address, including the royalty vault address and its balance.
254
+ * @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
255
+ * @returns {Promise<RoyaltyInfo>} A promise that resolves with the royalty vault address and balance information.
256
+ * @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
257
+ * @example
258
+ * ```typescript
259
+ * // Get royalties for connected wallet
260
+ * const royalties = await origin.getRoyalties();
261
+ *
262
+ * // Get royalties for specific address
263
+ * const royalties = await origin.getRoyalties("0x1234...");
264
+ * ```
265
+ */
266
+ getRoyalties(token?: Address, owner?: Address): Promise<RoyaltyInfo>;
267
+ /**
268
+ * Claim royalties from the royalty vault.
269
+ * @param {Address} [token] - Optional token address to claim royalties in. If not provided, claims in native token.
270
+ * @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
271
+ * @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
272
+ * @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
273
+ */
274
+ claimRoyalties(token?: Address, owner?: Address): Promise<any>;
238
275
  }
239
276
 
240
277
  declare global {
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import React, { createContext, useState, useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
3
- import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress, checksumAddress } from 'viem';
3
+ import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress, formatEther, formatUnits, checksumAddress } from 'viem';
4
4
  import { toAccount } from 'viem/accounts';
5
5
  import { createSiweMessage } from 'viem/siwe';
6
6
  import axios from 'axios';
@@ -2394,6 +2394,116 @@ var marketplaceMainnetAbi = [
2394
2394
  }
2395
2395
  ];
2396
2396
 
2397
+ var royaltyVaultAbi = [
2398
+ {
2399
+ type: "constructor",
2400
+ inputs: [
2401
+ {
2402
+ name: "_owner",
2403
+ type: "address",
2404
+ internalType: "address"
2405
+ }
2406
+ ],
2407
+ stateMutability: "nonpayable"
2408
+ },
2409
+ {
2410
+ type: "receive",
2411
+ stateMutability: "payable"
2412
+ },
2413
+ {
2414
+ type: "function",
2415
+ name: "claimRoyalty",
2416
+ inputs: [
2417
+ {
2418
+ name: "token",
2419
+ type: "address",
2420
+ internalType: "address"
2421
+ }
2422
+ ],
2423
+ outputs: [
2424
+ ],
2425
+ stateMutability: "nonpayable"
2426
+ },
2427
+ {
2428
+ type: "function",
2429
+ name: "owner",
2430
+ inputs: [
2431
+ ],
2432
+ outputs: [
2433
+ {
2434
+ name: "",
2435
+ type: "address",
2436
+ internalType: "address"
2437
+ }
2438
+ ],
2439
+ stateMutability: "view"
2440
+ },
2441
+ {
2442
+ type: "function",
2443
+ name: "renounceOwnership",
2444
+ inputs: [
2445
+ ],
2446
+ outputs: [
2447
+ ],
2448
+ stateMutability: "nonpayable"
2449
+ },
2450
+ {
2451
+ type: "function",
2452
+ name: "transferOwnership",
2453
+ inputs: [
2454
+ {
2455
+ name: "newOwner",
2456
+ type: "address",
2457
+ internalType: "address"
2458
+ }
2459
+ ],
2460
+ outputs: [
2461
+ ],
2462
+ stateMutability: "nonpayable"
2463
+ },
2464
+ {
2465
+ type: "event",
2466
+ name: "OwnershipTransferred",
2467
+ inputs: [
2468
+ {
2469
+ name: "previousOwner",
2470
+ type: "address",
2471
+ indexed: true,
2472
+ internalType: "address"
2473
+ },
2474
+ {
2475
+ name: "newOwner",
2476
+ type: "address",
2477
+ indexed: true,
2478
+ internalType: "address"
2479
+ }
2480
+ ],
2481
+ anonymous: false
2482
+ },
2483
+ {
2484
+ type: "error",
2485
+ name: "OwnableInvalidOwner",
2486
+ inputs: [
2487
+ {
2488
+ name: "owner",
2489
+ type: "address",
2490
+ internalType: "address"
2491
+ }
2492
+ ]
2493
+ },
2494
+ {
2495
+ type: "error",
2496
+ name: "OwnableUnauthorizedAccount",
2497
+ inputs: [
2498
+ {
2499
+ name: "account",
2500
+ type: "address",
2501
+ internalType: "address"
2502
+ }
2503
+ ]
2504
+ }
2505
+ ];
2506
+
2397
2507
  var constants = {
2398
2508
  SIWE_MESSAGE_STATEMENT: "Connect with Camp Network",
2399
2509
  AUTH_HUB_BASE_API: "https://wv2h4to5qa.execute-api.us-east-2.amazonaws.com/dev",
@@ -2435,6 +2545,7 @@ const ENVIRONMENTS = {
2435
2545
  CHAIN: testnet,
2436
2546
  IPNFT_ABI: ipnftMainnetAbi,
2437
2547
  MARKETPLACE_ABI: marketplaceMainnetAbi,
2548
+ ROYALTY_VAULT_ABI: royaltyVaultAbi,
2438
2549
  },
2439
2550
  PRODUCTION: {
2440
2551
  NAME: "PRODUCTION",
@@ -2446,6 +2557,7 @@ const ENVIRONMENTS = {
2446
2557
  CHAIN: mainnet,
2447
2558
  IPNFT_ABI: ipnftMainnetAbi,
2448
2559
  MARKETPLACE_ABI: marketplaceMainnetAbi,
2560
+ ROYALTY_VAULT_ABI: royaltyVaultAbi,
2449
2561
  },
2450
2562
  };
2451
2563
 
@@ -2611,6 +2723,15 @@ function finalizeDelete(tokenId) {
2611
2723
  return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "finalizeDelete", [tokenId]);
2612
2724
  }
2613
2725
 
2726
+ /**
2727
+ * Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
2728
+ * @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
2729
+ * @returns The address of the royalty vault associated with the specified token owner.
2730
+ */
2731
+ function getOrCreateRoyaltyVault(tokenOwner) {
2732
+ return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "getOrCreateRoyaltyVault", [tokenOwner], { waitForReceipt: true });
2733
+ }
2734
+
2614
2735
  /**
2615
2736
  * Returns the license terms associated with a specific token ID.
2616
2737
  * @param tokenId The token ID to query.
@@ -2747,7 +2868,7 @@ function approveIfNeeded(_a) {
2747
2868
  });
2748
2869
  }
2749
2870
 
2750
- var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_waitForTxReceipt, _Origin_ensureChainId;
2871
+ var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_waitForTxReceipt, _Origin_ensureChainId, _Origin_resolveWalletAddress;
2751
2872
  /**
2752
2873
  * The Origin class
2753
2874
  * Handles the upload of files to Origin, as well as querying the user's stats
@@ -2755,61 +2876,41 @@ var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_wai
2755
2876
  class Origin {
2756
2877
  constructor(jwt, environment, viemClient) {
2757
2878
  _Origin_instances.add(this);
2758
- _Origin_generateURL.set(this, (file) => __awaiter(this, void 0, void 0, function* () {
2759
- try {
2760
- const uploadRes = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`, {
2761
- method: "POST",
2762
- body: JSON.stringify({
2763
- name: file.name,
2764
- type: file.type,
2765
- }),
2766
- headers: {
2767
- Authorization: `Bearer ${this.jwt}`,
2768
- "Content-Type": "application/json",
2769
- },
2770
- });
2771
- if (!uploadRes.ok) {
2772
- throw new Error(`HTTP ${uploadRes.status}: ${uploadRes.statusText}`);
2773
- }
2774
- const data = yield uploadRes.json();
2775
- if (data.isError) {
2776
- throw new Error(data.message || "Failed to generate upload URL");
2777
- }
2778
- return data.data;
2779
- }
2780
- catch (error) {
2781
- console.error("Failed to generate upload URL:", error);
2782
- throw error;
2783
- }
2784
- }));
2785
- _Origin_setOriginStatus.set(this, (key, status) => __awaiter(this, void 0, void 0, function* () {
2786
- try {
2787
- const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`, {
2788
- method: "PATCH",
2789
- body: JSON.stringify({
2790
- status,
2791
- fileKey: key,
2792
- }),
2793
- headers: {
2794
- Authorization: `Bearer ${this.jwt}`,
2795
- "Content-Type": "application/json",
2796
- },
2797
- });
2798
- if (!res.ok) {
2799
- const errorText = yield res.text().catch(() => "Unknown error");
2800
- throw new Error(`HTTP ${res.status}: ${errorText}`);
2801
- }
2802
- return true;
2803
- }
2804
- catch (error) {
2805
- console.error("Failed to update origin status:", error);
2806
- throw error;
2807
- }
2808
- }));
2809
- this.uploadFile = (file, options) => __awaiter(this, void 0, void 0, function* () {
2879
+ this.jwt = jwt;
2880
+ this.viemClient = viemClient;
2881
+ this.environment = environment;
2882
+ // DataNFT methods
2883
+ this.mintWithSignature = mintWithSignature.bind(this);
2884
+ this.registerIpNFT = registerIpNFT.bind(this);
2885
+ this.updateTerms = updateTerms.bind(this);
2886
+ this.finalizeDelete = finalizeDelete.bind(this);
2887
+ this.getOrCreateRoyaltyVault = getOrCreateRoyaltyVault.bind(this);
2888
+ this.getTerms = getTerms.bind(this);
2889
+ this.ownerOf = ownerOf.bind(this);
2890
+ this.balanceOf = balanceOf.bind(this);
2891
+ this.tokenURI = tokenURI.bind(this);
2892
+ this.dataStatus = dataStatus.bind(this);
2893
+ this.isApprovedForAll = isApprovedForAll.bind(this);
2894
+ this.transferFrom = transferFrom.bind(this);
2895
+ this.safeTransferFrom = safeTransferFrom.bind(this);
2896
+ this.approve = approve.bind(this);
2897
+ this.setApprovalForAll = setApprovalForAll.bind(this);
2898
+ // Marketplace methods
2899
+ this.buyAccess = buyAccess.bind(this);
2900
+ this.hasAccess = hasAccess.bind(this);
2901
+ this.subscriptionExpiry = subscriptionExpiry.bind(this);
2902
+ }
2903
+ getJwt() {
2904
+ return this.jwt;
2905
+ }
2906
+ setViemClient(client) {
2907
+ this.viemClient = client;
2908
+ }
2909
+ uploadFile(file, options) {
2910
+ return __awaiter(this, void 0, void 0, function* () {
2810
2911
  let uploadInfo;
2811
2912
  try {
2812
- uploadInfo = yield __classPrivateFieldGet(this, _Origin_generateURL, "f").call(this, file);
2913
+ uploadInfo = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_generateURL).call(this, file);
2813
2914
  }
2814
2915
  catch (error) {
2815
2916
  console.error("Failed to generate upload URL:", error);
@@ -2823,7 +2924,7 @@ class Origin {
2823
2924
  }
2824
2925
  catch (error) {
2825
2926
  try {
2826
- yield __classPrivateFieldGet(this, _Origin_setOriginStatus, "f").call(this, uploadInfo.key, "failed");
2927
+ yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, uploadInfo.key, "failed");
2827
2928
  }
2828
2929
  catch (statusError) {
2829
2930
  console.error("Failed to update status to failed:", statusError);
@@ -2832,14 +2933,16 @@ class Origin {
2832
2933
  throw new Error(`Failed to upload file: ${errorMessage}`);
2833
2934
  }
2834
2935
  try {
2835
- yield __classPrivateFieldGet(this, _Origin_setOriginStatus, "f").call(this, uploadInfo.key, "success");
2936
+ yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, uploadInfo.key, "success");
2836
2937
  }
2837
2938
  catch (statusError) {
2838
2939
  console.error("Failed to update status to success:", statusError);
2839
2940
  }
2840
2941
  return uploadInfo;
2841
2942
  });
2842
- this.mintFile = (file, metadata, license, parents, options) => __awaiter(this, void 0, void 0, function* () {
2943
+ }
2944
+ mintFile(file, metadata, license, parents, options) {
2945
+ return __awaiter(this, void 0, void 0, function* () {
2843
2946
  if (!this.viemClient) {
2844
2947
  throw new Error("WalletClient not connected.");
2845
2948
  }
@@ -2868,7 +2971,9 @@ class Origin {
2868
2971
  }
2869
2972
  return tokenId.toString();
2870
2973
  });
2871
- this.mintSocial = (source, metadata, license) => __awaiter(this, void 0, void 0, function* () {
2974
+ }
2975
+ mintSocial(source, metadata, license) {
2976
+ return __awaiter(this, void 0, void 0, function* () {
2872
2977
  if (!this.viemClient) {
2873
2978
  throw new Error("WalletClient not connected.");
2874
2979
  }
@@ -2892,7 +2997,9 @@ class Origin {
2892
2997
  }
2893
2998
  return tokenId.toString();
2894
2999
  });
2895
- this.getOriginUploads = () => __awaiter(this, void 0, void 0, function* () {
3000
+ }
3001
+ getOriginUploads() {
3002
+ return __awaiter(this, void 0, void 0, function* () {
2896
3003
  const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`, {
2897
3004
  method: "GET",
2898
3005
  headers: {
@@ -2906,34 +3013,6 @@ class Origin {
2906
3013
  const data = yield res.json();
2907
3014
  return data.data;
2908
3015
  });
2909
- this.jwt = jwt;
2910
- this.viemClient = viemClient;
2911
- this.environment = environment;
2912
- // DataNFT methods
2913
- this.mintWithSignature = mintWithSignature.bind(this);
2914
- this.registerIpNFT = registerIpNFT.bind(this);
2915
- this.updateTerms = updateTerms.bind(this);
2916
- this.finalizeDelete = finalizeDelete.bind(this);
2917
- this.getTerms = getTerms.bind(this);
2918
- this.ownerOf = ownerOf.bind(this);
2919
- this.balanceOf = balanceOf.bind(this);
2920
- this.tokenURI = tokenURI.bind(this);
2921
- this.dataStatus = dataStatus.bind(this);
2922
- this.isApprovedForAll = isApprovedForAll.bind(this);
2923
- this.transferFrom = transferFrom.bind(this);
2924
- this.safeTransferFrom = safeTransferFrom.bind(this);
2925
- this.approve = approve.bind(this);
2926
- this.setApprovalForAll = setApprovalForAll.bind(this);
2927
- // Marketplace methods
2928
- this.buyAccess = buyAccess.bind(this);
2929
- this.hasAccess = hasAccess.bind(this);
2930
- this.subscriptionExpiry = subscriptionExpiry.bind(this);
2931
- }
2932
- getJwt() {
2933
- return this.jwt;
2934
- }
2935
- setViemClient(client) {
2936
- this.viemClient = client;
2937
3016
  }
2938
3017
  /**
2939
3018
  * Get the user's Origin stats (multiplier, consent, usage, etc.).
@@ -3105,8 +3184,139 @@ class Origin {
3105
3184
  return response.json();
3106
3185
  });
3107
3186
  }
3187
+ /**
3188
+ * Get royalty information for a wallet address, including the royalty vault address and its balance.
3189
+ * @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
3190
+ * @returns {Promise<RoyaltyInfo>} A promise that resolves with the royalty vault address and balance information.
3191
+ * @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
3192
+ * @example
3193
+ * ```typescript
3194
+ * // Get royalties for connected wallet
3195
+ * const royalties = await origin.getRoyalties();
3196
+ *
3197
+ * // Get royalties for specific address
3198
+ * const royalties = await origin.getRoyalties("0x1234...");
3199
+ * ```
3200
+ */
3201
+ getRoyalties(token, owner) {
3202
+ return __awaiter(this, void 0, void 0, function* () {
3203
+ const walletAddress = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_resolveWalletAddress).call(this, owner);
3204
+ try {
3205
+ const royaltyVaultAddress = yield this.getOrCreateRoyaltyVault(walletAddress);
3206
+ console.log("Royalty Vault Address:", royaltyVaultAddress);
3207
+ const publicClient = getPublicClient();
3208
+ let balance;
3209
+ let balanceFormatted;
3210
+ if (!token || token === zeroAddress) {
3211
+ balance = yield publicClient.getBalance({
3212
+ address: royaltyVaultAddress,
3213
+ });
3214
+ balanceFormatted = formatEther(balance);
3215
+ }
3216
+ else {
3217
+ // erc20 (wrapped camp)
3218
+ const erc20Abi = [
3219
+ {
3220
+ inputs: [{ name: "owner", type: "address" }],
3221
+ name: "balanceOf",
3222
+ outputs: [{ name: "", type: "uint256" }],
3223
+ stateMutability: "view",
3224
+ type: "function",
3225
+ },
3226
+ {
3227
+ inputs: [],
3228
+ name: "decimals",
3229
+ outputs: [{ name: "", type: "uint8" }],
3230
+ stateMutability: "view",
3231
+ type: "function",
3232
+ },
3233
+ ];
3234
+ balance = yield this.callContractMethod(token, erc20Abi, "balanceOf", [
3235
+ royaltyVaultAddress,
3236
+ ]);
3237
+ const decimals = yield this.callContractMethod(token, erc20Abi, "decimals", []);
3238
+ balanceFormatted = formatUnits(balance, decimals);
3239
+ }
3240
+ return {
3241
+ royaltyVault: royaltyVaultAddress,
3242
+ balance,
3243
+ balanceFormatted,
3244
+ };
3245
+ }
3246
+ catch (error) {
3247
+ throw new Error(`Failed to retrieve royalties for address ${walletAddress}: ${error instanceof Error ? error.message : String(error)}`);
3248
+ }
3249
+ });
3250
+ }
3251
+ /**
3252
+ * Claim royalties from the royalty vault.
3253
+ * @param {Address} [token] - Optional token address to claim royalties in. If not provided, claims in native token.
3254
+ * @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
3255
+ * @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
3256
+ * @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
3257
+ */
3258
+ claimRoyalties(token, owner) {
3259
+ return __awaiter(this, void 0, void 0, function* () {
3260
+ const walletAddress = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_resolveWalletAddress).call(this, owner);
3261
+ const royaltyVaultAddress = yield this.getOrCreateRoyaltyVault(walletAddress);
3262
+ return this.callContractMethod(royaltyVaultAddress, this.environment.ROYALTY_VAULT_ABI, "claimRoyalties", [token !== null && token !== void 0 ? token : zeroAddress], { waitForReceipt: true });
3263
+ });
3264
+ }
3108
3265
  }
3109
- _Origin_generateURL = new WeakMap(), _Origin_setOriginStatus = new WeakMap(), _Origin_instances = new WeakSet(), _Origin_waitForTxReceipt = function _Origin_waitForTxReceipt(txHash) {
3266
+ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_generateURL(file) {
3267
+ return __awaiter(this, void 0, void 0, function* () {
3268
+ try {
3269
+ const uploadRes = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`, {
3270
+ method: "POST",
3271
+ body: JSON.stringify({
3272
+ name: file.name,
3273
+ type: file.type,
3274
+ }),
3275
+ headers: {
3276
+ Authorization: `Bearer ${this.jwt}`,
3277
+ "Content-Type": "application/json",
3278
+ },
3279
+ });
3280
+ if (!uploadRes.ok) {
3281
+ throw new Error(`HTTP ${uploadRes.status}: ${uploadRes.statusText}`);
3282
+ }
3283
+ const data = yield uploadRes.json();
3284
+ if (data.isError) {
3285
+ throw new Error(data.message || "Failed to generate upload URL");
3286
+ }
3287
+ return data.data;
3288
+ }
3289
+ catch (error) {
3290
+ console.error("Failed to generate upload URL:", error);
3291
+ throw error;
3292
+ }
3293
+ });
3294
+ }, _Origin_setOriginStatus = function _Origin_setOriginStatus(key, status) {
3295
+ return __awaiter(this, void 0, void 0, function* () {
3296
+ try {
3297
+ const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`, {
3298
+ method: "PATCH",
3299
+ body: JSON.stringify({
3300
+ status,
3301
+ fileKey: key,
3302
+ }),
3303
+ headers: {
3304
+ Authorization: `Bearer ${this.jwt}`,
3305
+ "Content-Type": "application/json",
3306
+ },
3307
+ });
3308
+ if (!res.ok) {
3309
+ const errorText = yield res.text().catch(() => "Unknown error");
3310
+ throw new Error(`HTTP ${res.status}: ${errorText}`);
3311
+ }
3312
+ return true;
3313
+ }
3314
+ catch (error) {
3315
+ console.error("Failed to update origin status:", error);
3316
+ throw error;
3317
+ }
3318
+ });
3319
+ }, _Origin_waitForTxReceipt = function _Origin_waitForTxReceipt(txHash) {
3110
3320
  return __awaiter(this, void 0, void 0, function* () {
3111
3321
  if (!this.viemClient)
3112
3322
  throw new Error("WalletClient not connected.");
@@ -3165,6 +3375,28 @@ _Origin_generateURL = new WeakMap(), _Origin_setOriginStatus = new WeakMap(), _O
3165
3375
  }
3166
3376
  }
3167
3377
  });
3378
+ }, _Origin_resolveWalletAddress = function _Origin_resolveWalletAddress(owner) {
3379
+ return __awaiter(this, void 0, void 0, function* () {
3380
+ if (owner) {
3381
+ return owner;
3382
+ }
3383
+ if (!this.viemClient) {
3384
+ throw new Error("No wallet address provided and no wallet client connected. Please provide an owner address or connect a wallet.");
3385
+ }
3386
+ try {
3387
+ const accounts = yield this.viemClient.request({
3388
+ method: "eth_requestAccounts",
3389
+ params: [],
3390
+ });
3391
+ if (!accounts || accounts.length === 0) {
3392
+ throw new Error("No accounts found in connected wallet.");
3393
+ }
3394
+ return accounts[0];
3395
+ }
3396
+ catch (error) {
3397
+ throw new Error(`Failed to get wallet address: ${error instanceof Error ? error.message : String(error)}`);
3398
+ }
3399
+ });
3168
3400
  };
3169
3401
 
3170
3402
  var _Auth_instances, _Auth_triggers, _Auth_ackeeInstance, _Auth_trigger, _Auth_loadAuthStatusFromStorage, _Auth_requestAccount, _Auth_fetchNonce, _Auth_verifySignature, _Auth_createMessage, _Auth_sendAnalyticsEvent;
@@ -4856,6 +5088,7 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
4856
5088
  wagmiConnectorClient = useConnectorClient();
4857
5089
  wagmiAccount = useAccount();
4858
5090
  }
5091
+ const { addToast: toast } = useToast();
4859
5092
  if (!auth) {
4860
5093
  throw new Error("Auth instance is not available. Make sure to wrap your component with CampProvider.");
4861
5094
  }
@@ -4928,7 +5161,7 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
4928
5161
  }
4929
5162
  };
4930
5163
  }, [wcProvider]);
4931
- const handleConnect = (provider) => {
5164
+ const handleConnect = (provider) => __awaiter(void 0, void 0, void 0, function* () {
4932
5165
  var _a, _b;
4933
5166
  if (provider) {
4934
5167
  let addr = null;
@@ -4946,8 +5179,14 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
4946
5179
  ((_b = provider === null || provider === void 0 ? void 0 : provider.provider) === null || _b === void 0 ? void 0 : _b.uid) === (customProvider === null || customProvider === void 0 ? void 0 : customProvider.uid)) {
4947
5180
  auth.setWalletAddress(customAccount === null || customAccount === void 0 ? void 0 : customAccount.address);
4948
5181
  }
4949
- connect();
4950
- };
5182
+ try {
5183
+ yield connect();
5184
+ }
5185
+ catch (error) {
5186
+ console.error("Error during connect:", error);
5187
+ toast("Error connecting wallet. Please try again.", "error", 5000);
5188
+ }
5189
+ });
4951
5190
  return (React.createElement("div", { className: styles["outer-container"] },
4952
5191
  React.createElement("div", { className: `${styles.container} ${styles["linking-container"]}` },
4953
5192
  React.createElement(ArrowCorners, { padding: 8, color: "#AAA" }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campnetwork/origin",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
4
4
  "main": "dist/core.cjs",
5
5
  "exports": {
6
6
  ".": {