@campnetwork/origin 0.0.1 → 0.0.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.
@@ -1,7 +1,366 @@
1
1
  import React, { JSX } from 'react';
2
- import { Auth } from '@campnetwork/sdk';
2
+ import { Address, Hex, Abi } from 'viem';
3
3
  import { UseQueryResult } from '@tanstack/react-query';
4
4
 
5
+ /**
6
+ * Represents the terms of a license for a digital asset.
7
+ * @property price - The price of the asset in wei.
8
+ * @property duration - The duration of the license in seconds.
9
+ * @property royaltyBps - The royalty percentage in basis points (0-10000).
10
+ * @property paymentToken - The address of the payment token (ERC20 / address(0) for native currency).
11
+ */
12
+ type LicenseTerms = {
13
+ price: bigint;
14
+ duration: number;
15
+ royaltyBps: number;
16
+ paymentToken: Address;
17
+ };
18
+ /**
19
+ * Enum representing the status of data in the system.
20
+ * * - ACTIVE: The data is currently active and available.
21
+ * * - PENDING_DELETE: The data is scheduled for deletion but not yet removed.
22
+ * * - DELETED: The data has been deleted and is no longer available.
23
+ */
24
+ declare enum DataStatus {
25
+ ACTIVE = 0,
26
+ PENDING_DELETE = 1,
27
+ DELETED = 2
28
+ }
29
+ /**
30
+ * Represents the source of a Data NFT.
31
+ * This can be one of the supported social media platforms or a file upload.
32
+ */
33
+ type DataNFTSource = "spotify" | "twitter" | "tiktok" | "file";
34
+
35
+ /**
36
+ * Mints a Data NFT with a signature.
37
+ * @param to The address to mint the NFT to.
38
+ * @param tokenId The ID of the token to mint.
39
+ * @param hash The hash of the data associated with the NFT.
40
+ * @param uri The URI of the NFT metadata.
41
+ * @param licenseTerms The terms of the license for the NFT.
42
+ * @param deadline The deadline for the minting operation.
43
+ * @param signature The signature for the minting operation.
44
+ * @returns A promise that resolves when the minting is complete.
45
+ */
46
+ declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, hash: Hex, uri: string, licenseTerms: LicenseTerms, deadline: bigint, signature: {
47
+ v: number;
48
+ r: Hex;
49
+ s: Hex;
50
+ }): Promise<any>;
51
+ /**
52
+ * Registers a Data NFT with the Origin service in order to obtain a signature for minting.
53
+ * @param source The source of the Data NFT (e.g., "spotify", "twitter", "tiktok", or "file").
54
+ * @param deadline The deadline for the registration operation.
55
+ * @param fileKey Optional file key for file uploads.
56
+ * @return A promise that resolves with the registration data.
57
+ */
58
+ declare function registerDataNFT(this: Origin, source: DataNFTSource, deadline: bigint, fileKey?: string | string[]): Promise<any>;
59
+
60
+ declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTerms): Promise<any>;
61
+
62
+ declare function requestDelete(this: Origin, tokenId: bigint): Promise<any>;
63
+
64
+ declare function getTerms(this: Origin, tokenId: bigint): Promise<any>;
65
+
66
+ declare function ownerOf(this: Origin, tokenId: bigint): Promise<any>;
67
+
68
+ declare function balanceOf(this: Origin, owner: Address): Promise<any>;
69
+
70
+ declare function contentHash(this: Origin, tokenId: bigint): Promise<any>;
71
+
72
+ declare function tokenURI(this: Origin, tokenId: bigint): Promise<any>;
73
+
74
+ declare function dataStatus(this: Origin, tokenId: bigint): Promise<DataStatus>;
75
+
76
+ declare function royaltyInfo(this: Origin, tokenId: bigint, salePrice: bigint): Promise<[Address, bigint]>;
77
+
78
+ declare function getApproved(this: Origin, tokenId: bigint): Promise<Address>;
79
+
80
+ declare function isApprovedForAll(this: Origin, owner: Address, operator: Address): Promise<boolean>;
81
+
82
+ declare function transferFrom(this: Origin, from: Address, to: Address, tokenId: bigint): Promise<any>;
83
+
84
+ declare function safeTransferFrom(this: Origin, from: Address, to: Address, tokenId: bigint, data?: Hex): Promise<any>;
85
+
86
+ declare function approve(this: Origin, to: Address, tokenId: bigint): Promise<any>;
87
+
88
+ declare function setApprovalForAll(this: Origin, operator: Address, approved: boolean): Promise<any>;
89
+
90
+ declare function buyAccess(this: Origin, tokenId: bigint, periods: number, value?: bigint): Promise<any>;
91
+
92
+ declare function renewAccess(this: Origin, tokenId: bigint, buyer: Address, periods: number, value?: bigint): Promise<any>;
93
+
94
+ declare function hasAccess(this: Origin, user: Address, tokenId: bigint): Promise<boolean>;
95
+
96
+ declare function subscriptionExpiry(this: Origin, tokenId: bigint, user: Address): Promise<bigint>;
97
+
98
+ interface OriginUsageReturnType {
99
+ user: {
100
+ multiplier: number;
101
+ points: number;
102
+ active: boolean;
103
+ };
104
+ teams: Array<any>;
105
+ dataSources: Array<any>;
106
+ }
107
+ type CallOptions = {
108
+ value?: bigint;
109
+ gas?: bigint;
110
+ waitForReceipt?: boolean;
111
+ };
112
+ /**
113
+ * The Origin class
114
+ * Handles the upload of files to Origin, as well as querying the user's stats
115
+ */
116
+ declare class Origin {
117
+ #private;
118
+ mintWithSignature: typeof mintWithSignature;
119
+ registerDataNFT: typeof registerDataNFT;
120
+ updateTerms: typeof updateTerms;
121
+ requestDelete: typeof requestDelete;
122
+ getTerms: typeof getTerms;
123
+ ownerOf: typeof ownerOf;
124
+ balanceOf: typeof balanceOf;
125
+ contentHash: typeof contentHash;
126
+ tokenURI: typeof tokenURI;
127
+ dataStatus: typeof dataStatus;
128
+ royaltyInfo: typeof royaltyInfo;
129
+ getApproved: typeof getApproved;
130
+ isApprovedForAll: typeof isApprovedForAll;
131
+ transferFrom: typeof transferFrom;
132
+ safeTransferFrom: typeof safeTransferFrom;
133
+ approve: typeof approve;
134
+ setApprovalForAll: typeof setApprovalForAll;
135
+ buyAccess: typeof buyAccess;
136
+ renewAccess: typeof renewAccess;
137
+ hasAccess: typeof hasAccess;
138
+ subscriptionExpiry: typeof subscriptionExpiry;
139
+ private jwt;
140
+ private viemClient?;
141
+ constructor(jwt: string, viemClient?: any);
142
+ getJwt(): string;
143
+ setViemClient(client: any): void;
144
+ uploadFile: (file: File, options?: {
145
+ progressCallback?: (percent: number) => void;
146
+ }) => Promise<any>;
147
+ mintFile: (file: File, license: LicenseTerms, options?: {
148
+ progressCallback?: (percent: number) => void;
149
+ }) => Promise<string | null>;
150
+ mintSocial: (source: "spotify" | "twitter" | "tiktok") => Promise<string | null>;
151
+ getOriginUploads: () => Promise<any>;
152
+ /**
153
+ * Get the user's Origin stats (multiplier, consent, usage, etc.).
154
+ * @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
155
+ */
156
+ getOriginUsage(): Promise<OriginUsageReturnType>;
157
+ /**
158
+ * Set the user's consent for Origin usage.
159
+ * @param {boolean} consent The user's consent.
160
+ * @returns {Promise<void>}
161
+ * @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the consent is not provided.
162
+ */
163
+ setOriginConsent(consent: boolean): Promise<void>;
164
+ /**
165
+ * Set the user's Origin multiplier.
166
+ * @param {number} multiplier The user's Origin multiplier.
167
+ * @returns {Promise<void>}
168
+ * @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the multiplier is not provided.
169
+ */
170
+ setOriginMultiplier(multiplier: number): Promise<void>;
171
+ /**
172
+ * Call a contract method.
173
+ * @param {string} contractAddress The contract address.
174
+ * @param {Abi} abi The contract ABI.
175
+ * @param {string} methodName The method name.
176
+ * @param {any[]} params The method parameters.
177
+ * @param {CallOptions} [options] The call options.
178
+ * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
179
+ * @throws {Error} - Throws an error if the wallet client is not connected and the method is not a view function.
180
+ */
181
+ callContractMethod(contractAddress: string, abi: Abi, methodName: string, params: any[], options?: CallOptions): Promise<any>;
182
+ /**
183
+ * Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
184
+ * @param {bigint} tokenId The token ID of the asset.
185
+ * @param {number} periods The number of periods to buy access for.
186
+ * @returns {Promise<any>} The result of the buyAccess call.
187
+ */
188
+ buyAccessSmart(tokenId: bigint, periods: number): Promise<any>;
189
+ getData(tokenId: bigint): Promise<any>;
190
+ }
191
+
192
+ declare global {
193
+ interface Window {
194
+ ethereum?: any;
195
+ }
196
+ }
197
+ /**
198
+ * The Auth class.
199
+ * @class
200
+ * @classdesc The Auth class is used to authenticate the user.
201
+ */
202
+ declare class Auth {
203
+ #private;
204
+ redirectUri: Record<string, string>;
205
+ clientId: string;
206
+ isAuthenticated: boolean;
207
+ jwt: string | null;
208
+ walletAddress: string | null;
209
+ userId: string | null;
210
+ viem: any;
211
+ origin: Origin | null;
212
+ /**
213
+ * Constructor for the Auth class.
214
+ * @param {object} options The options object.
215
+ * @param {string} options.clientId The client ID.
216
+ * @param {string|object} options.redirectUri The redirect URI used for oauth. Leave empty if you want to use the current URL. If you want different redirect URIs for different socials, pass an object with the socials as keys and the redirect URIs as values.
217
+ * @param {boolean} [options.allowAnalytics=true] Whether to allow analytics to be sent.
218
+ * @param {object} [options.ackeeInstance] The Ackee instance.
219
+ * @throws {APIError} - Throws an error if the clientId is not provided.
220
+ */
221
+ constructor({ clientId, redirectUri, allowAnalytics, ackeeInstance, }: {
222
+ clientId: string;
223
+ redirectUri: string | Record<string, string>;
224
+ allowAnalytics?: boolean;
225
+ ackeeInstance?: any;
226
+ });
227
+ /**
228
+ * Subscribe to an event. Possible events are "state", "provider", "providers", and "viem".
229
+ * @param {("state"|"provider"|"providers"|"viem")} event The event.
230
+ * @param {function} callback The callback function.
231
+ * @returns {void}
232
+ * @example
233
+ * auth.on("state", (state) => {
234
+ * console.log(state);
235
+ * });
236
+ */
237
+ on(event: "state" | "provider" | "providers" | "viem", callback: Function): void;
238
+ /**
239
+ * Set the loading state.
240
+ * @param {boolean} loading The loading state.
241
+ * @returns {void}
242
+ */
243
+ setLoading(loading: boolean): void;
244
+ /**
245
+ * Set the provider. This is useful for setting the provider when the user selects a provider from the UI or when dApp wishes to use a specific provider.
246
+ * @param {object} options The options object. Includes the provider and the provider info.
247
+ * @returns {void}
248
+ * @throws {APIError} - Throws an error if the provider is not provided.
249
+ */
250
+ setProvider({ provider, info, address, }: {
251
+ provider: any;
252
+ info: any;
253
+ address?: string;
254
+ }): void;
255
+ /**
256
+ * Set the wallet address. This is useful for edge cases where the provider can't return the wallet address. Don't use this unless you know what you're doing.
257
+ * @param {string} walletAddress The wallet address.
258
+ * @returns {void}
259
+ */
260
+ setWalletAddress(walletAddress: string): void;
261
+ /**
262
+ * Disconnect the user.
263
+ * @returns {Promise<void>}
264
+ */
265
+ disconnect(): Promise<void>;
266
+ /**
267
+ * Connect the user's wallet and sign the message.
268
+ * @returns {Promise<{ success: boolean; message: string; walletAddress: string }>} A promise that resolves with the authentication result.
269
+ * @throws {APIError} - Throws an error if the user cannot be authenticated.
270
+ */
271
+ connect(): Promise<{
272
+ success: boolean;
273
+ message: string;
274
+ walletAddress: string;
275
+ }>;
276
+ /**
277
+ * Get the user's linked social accounts.
278
+ * @returns {Promise<Record<string, boolean>>} A promise that resolves with the user's linked social accounts.
279
+ * @throws {Error|APIError} - Throws an error if the user is not authenticated or if the request fails.
280
+ * @example
281
+ * const auth = new Auth({ clientId: "your-client-id" });
282
+ * const socials = await auth.getLinkedSocials();
283
+ * console.log(socials);
284
+ */
285
+ getLinkedSocials(): Promise<Record<string, boolean>>;
286
+ /**
287
+ * Link the user's Twitter account.
288
+ * @returns {Promise<void>}
289
+ * @throws {Error} - Throws an error if the user is not authenticated.
290
+ */
291
+ linkTwitter(): Promise<void>;
292
+ /**
293
+ * Link the user's Discord account.
294
+ * @returns {Promise<void>}
295
+ * @throws {Error} - Throws an error if the user is not authenticated.
296
+ */
297
+ linkDiscord(): Promise<void>;
298
+ /**
299
+ * Link the user's Spotify account.
300
+ * @returns {Promise<void>}
301
+ * @throws {Error} - Throws an error if the user is not authenticated.
302
+ */
303
+ linkSpotify(): Promise<void>;
304
+ /**
305
+ * Link the user's TikTok account.
306
+ * @param {string} handle The user's TikTok handle.
307
+ * @returns {Promise<any>} A promise that resolves with the TikTok account data.
308
+ * @throws {Error|APIError} - Throws an error if the user is not authenticated.
309
+ */
310
+ linkTikTok(handle: string): Promise<any>;
311
+ /**
312
+ * Send an OTP to the user's Telegram account.
313
+ * @param {string} phoneNumber The user's phone number.
314
+ * @returns {Promise<any>} A promise that resolves with the OTP data.
315
+ * @throws {Error|APIError} - Throws an error if the user is not authenticated.
316
+ */
317
+ sendTelegramOTP(phoneNumber: string): Promise<any>;
318
+ /**
319
+ * Link the user's Telegram account.
320
+ * @param {string} phoneNumber The user's phone number.
321
+ * @param {string} otp The OTP.
322
+ * @param {string} phoneCodeHash The phone code hash.
323
+ * @returns {Promise<object>} A promise that resolves with the Telegram account data.
324
+ * @throws {APIError|Error} - Throws an error if the user is not authenticated. Also throws an error if the phone number, OTP, and phone code hash are not provided.
325
+ */
326
+ linkTelegram(phoneNumber: string, otp: string, phoneCodeHash: string): Promise<any>;
327
+ /**
328
+ * Unlink the user's Twitter account.
329
+ * @returns {Promise<any>} A promise that resolves with the unlink result.
330
+ * @throws {Error} - Throws an error if the user is not authenticated.
331
+ * @throws {APIError} - Throws an error if the request fails.
332
+ */
333
+ unlinkTwitter(): Promise<any>;
334
+ /**
335
+ * Unlink the user's Discord account.
336
+ * @returns {Promise<any>} A promise that resolves with the unlink result.
337
+ * @throws {Error} - Throws an error if the user is not authenticated.
338
+ * @throws {APIError} - Throws an error if the request fails.
339
+ */
340
+ unlinkDiscord(): Promise<any>;
341
+ /**
342
+ * Unlink the user's Spotify account.
343
+ * @returns {Promise<any>} A promise that resolves with the unlink result.
344
+ * @throws {Error} - Throws an error if the user is not authenticated.
345
+ * @throws {APIError} - Throws an error if the request fails.
346
+ */
347
+ unlinkSpotify(): Promise<any>;
348
+ /**
349
+ * Unlink the user's TikTok account.
350
+ * @returns {Promise<any>} A promise that resolves with the unlink result.
351
+ * @throws {Error} - Throws an error if the user is not authenticated.
352
+ * @throws {APIError} - Throws an error if the request fails.
353
+ */
354
+ unlinkTikTok(): Promise<any>;
355
+ /**
356
+ * Unlink the user's Telegram account.
357
+ * @returns {Promise<any>} A promise that resolves with the unlink result.
358
+ * @throws {Error} - Throws an error if the user is not authenticated.
359
+ * @throws {APIError} - Throws an error if the request fails.
360
+ */
361
+ unlinkTelegram(): Promise<any>;
362
+ }
363
+
5
364
  /**
6
365
  * CampContext
7
366
  * @type {React.Context}
@@ -13,7 +372,7 @@ import { UseQueryResult } from '@tanstack/react-query';
13
372
  interface CampContextType {
14
373
  clientId: string | null;
15
374
  auth: Auth | null;
16
- setAuth: React.Dispatch<React.SetStateAction<Auth>>;
375
+ setAuth: React.Dispatch<React.SetStateAction<Auth | null>>;
17
376
  wagmiAvailable: boolean;
18
377
  ackee: any;
19
378
  setAckee: any;