@campnetwork/origin 0.0.2 → 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.
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Abi } from 'viem';
1
+ import { Address, Hex, Abi } from 'viem';
2
2
 
3
3
  /**
4
4
  * The TwitterAPI class.
@@ -196,6 +196,99 @@ declare class SpotifyAPI {
196
196
  _fetchDataWithAuth(url: string): Promise<object>;
197
197
  }
198
198
 
199
+ /**
200
+ * Represents the terms of a license for a digital asset.
201
+ * @property price - The price of the asset in wei.
202
+ * @property duration - The duration of the license in seconds.
203
+ * @property royaltyBps - The royalty percentage in basis points (0-10000).
204
+ * @property paymentToken - The address of the payment token (ERC20 / address(0) for native currency).
205
+ */
206
+ type LicenseTerms = {
207
+ price: bigint;
208
+ duration: number;
209
+ royaltyBps: number;
210
+ paymentToken: Address;
211
+ };
212
+ /**
213
+ * Enum representing the status of data in the system.
214
+ * * - ACTIVE: The data is currently active and available.
215
+ * * - PENDING_DELETE: The data is scheduled for deletion but not yet removed.
216
+ * * - DELETED: The data has been deleted and is no longer available.
217
+ */
218
+ declare enum DataStatus {
219
+ ACTIVE = 0,
220
+ PENDING_DELETE = 1,
221
+ DELETED = 2
222
+ }
223
+ /**
224
+ * Represents the source of a Data NFT.
225
+ * This can be one of the supported social media platforms or a file upload.
226
+ */
227
+ type DataNFTSource = "spotify" | "twitter" | "tiktok" | "file";
228
+
229
+ /**
230
+ * Mints a Data NFT with a signature.
231
+ * @param to The address to mint the NFT to.
232
+ * @param tokenId The ID of the token to mint.
233
+ * @param hash The hash of the data associated with the NFT.
234
+ * @param uri The URI of the NFT metadata.
235
+ * @param licenseTerms The terms of the license for the NFT.
236
+ * @param deadline The deadline for the minting operation.
237
+ * @param signature The signature for the minting operation.
238
+ * @returns A promise that resolves when the minting is complete.
239
+ */
240
+ declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, hash: Hex, uri: string, licenseTerms: LicenseTerms, deadline: bigint, signature: {
241
+ v: number;
242
+ r: Hex;
243
+ s: Hex;
244
+ }): Promise<any>;
245
+ /**
246
+ * Registers a Data NFT with the Origin service in order to obtain a signature for minting.
247
+ * @param source The source of the Data NFT (e.g., "spotify", "twitter", "tiktok", or "file").
248
+ * @param deadline The deadline for the registration operation.
249
+ * @param fileKey Optional file key for file uploads.
250
+ * @return A promise that resolves with the registration data.
251
+ */
252
+ declare function registerDataNFT(this: Origin, source: DataNFTSource, deadline: bigint, fileKey?: string | string[]): Promise<any>;
253
+
254
+ declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTerms): Promise<any>;
255
+
256
+ declare function requestDelete(this: Origin, tokenId: bigint): Promise<any>;
257
+
258
+ declare function getTerms(this: Origin, tokenId: bigint): Promise<any>;
259
+
260
+ declare function ownerOf(this: Origin, tokenId: bigint): Promise<any>;
261
+
262
+ declare function balanceOf(this: Origin, owner: Address): Promise<any>;
263
+
264
+ declare function contentHash(this: Origin, tokenId: bigint): Promise<any>;
265
+
266
+ declare function tokenURI(this: Origin, tokenId: bigint): Promise<any>;
267
+
268
+ declare function dataStatus(this: Origin, tokenId: bigint): Promise<DataStatus>;
269
+
270
+ declare function royaltyInfo(this: Origin, tokenId: bigint, salePrice: bigint): Promise<[Address, bigint]>;
271
+
272
+ declare function getApproved(this: Origin, tokenId: bigint): Promise<Address>;
273
+
274
+ declare function isApprovedForAll(this: Origin, owner: Address, operator: Address): Promise<boolean>;
275
+
276
+ declare function transferFrom(this: Origin, from: Address, to: Address, tokenId: bigint): Promise<any>;
277
+
278
+ declare function safeTransferFrom(this: Origin, from: Address, to: Address, tokenId: bigint, data?: Hex): Promise<any>;
279
+
280
+ declare function approve(this: Origin, to: Address, tokenId: bigint): Promise<any>;
281
+
282
+ declare function setApprovalForAll(this: Origin, operator: Address, approved: boolean): Promise<any>;
283
+
284
+ declare function buyAccess(this: Origin, tokenId: bigint, periods: number, value?: bigint): Promise<any>;
285
+
286
+ declare function renewAccess(this: Origin, tokenId: bigint, buyer: Address, periods: number, value?: bigint): Promise<any>;
287
+
288
+ declare function hasAccess(this: Origin, user: Address, tokenId: bigint): Promise<boolean>;
289
+
290
+ declare function subscriptionExpiry(this: Origin, tokenId: bigint, user: Address): Promise<bigint>;
291
+
199
292
  interface OriginUsageReturnType {
200
293
  user: {
201
294
  multiplier: number;
@@ -205,17 +298,50 @@ interface OriginUsageReturnType {
205
298
  teams: Array<any>;
206
299
  dataSources: Array<any>;
207
300
  }
301
+ type CallOptions = {
302
+ value?: bigint;
303
+ gas?: bigint;
304
+ waitForReceipt?: boolean;
305
+ };
208
306
  /**
209
307
  * The Origin class
210
308
  * Handles the upload of files to Origin, as well as querying the user's stats
211
309
  */
212
310
  declare class Origin {
213
311
  #private;
312
+ mintWithSignature: typeof mintWithSignature;
313
+ registerDataNFT: typeof registerDataNFT;
314
+ updateTerms: typeof updateTerms;
315
+ requestDelete: typeof requestDelete;
316
+ getTerms: typeof getTerms;
317
+ ownerOf: typeof ownerOf;
318
+ balanceOf: typeof balanceOf;
319
+ contentHash: typeof contentHash;
320
+ tokenURI: typeof tokenURI;
321
+ dataStatus: typeof dataStatus;
322
+ royaltyInfo: typeof royaltyInfo;
323
+ getApproved: typeof getApproved;
324
+ isApprovedForAll: typeof isApprovedForAll;
325
+ transferFrom: typeof transferFrom;
326
+ safeTransferFrom: typeof safeTransferFrom;
327
+ approve: typeof approve;
328
+ setApprovalForAll: typeof setApprovalForAll;
329
+ buyAccess: typeof buyAccess;
330
+ renewAccess: typeof renewAccess;
331
+ hasAccess: typeof hasAccess;
332
+ subscriptionExpiry: typeof subscriptionExpiry;
214
333
  private jwt;
215
- constructor(jwt: string);
334
+ private viemClient?;
335
+ constructor(jwt: string, viemClient?: any);
336
+ getJwt(): string;
337
+ setViemClient(client: any): void;
216
338
  uploadFile: (file: File, options?: {
217
339
  progressCallback?: (percent: number) => void;
218
- }) => Promise<void>;
340
+ }) => Promise<any>;
341
+ mintFile: (file: File, license: LicenseTerms, options?: {
342
+ progressCallback?: (percent: number) => void;
343
+ }) => Promise<string | null>;
344
+ mintSocial: (source: "spotify" | "twitter" | "tiktok") => Promise<string | null>;
219
345
  getOriginUploads: () => Promise<any>;
220
346
  /**
221
347
  * Get the user's Origin stats (multiplier, consent, usage, etc.).
@@ -236,6 +362,25 @@ declare class Origin {
236
362
  * @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the multiplier is not provided.
237
363
  */
238
364
  setOriginMultiplier(multiplier: number): Promise<void>;
365
+ /**
366
+ * Call a contract method.
367
+ * @param {string} contractAddress The contract address.
368
+ * @param {Abi} abi The contract ABI.
369
+ * @param {string} methodName The method name.
370
+ * @param {any[]} params The method parameters.
371
+ * @param {CallOptions} [options] The call options.
372
+ * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
373
+ * @throws {Error} - Throws an error if the wallet client is not connected and the method is not a view function.
374
+ */
375
+ callContractMethod(contractAddress: string, abi: Abi, methodName: string, params: any[], options?: CallOptions): Promise<any>;
376
+ /**
377
+ * Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
378
+ * @param {bigint} tokenId The token ID of the asset.
379
+ * @param {number} periods The number of periods to buy access for.
380
+ * @returns {Promise<any>} The result of the buyAccess call.
381
+ */
382
+ buyAccessSmart(tokenId: bigint, periods: number): Promise<any>;
383
+ getData(tokenId: bigint): Promise<any>;
239
384
  }
240
385
 
241
386
  declare global {
@@ -243,11 +388,6 @@ declare global {
243
388
  ethereum?: any;
244
389
  }
245
390
  }
246
- type CallOptions = {
247
- value?: bigint;
248
- gas?: bigint;
249
- waitForReceipt?: boolean;
250
- };
251
391
  /**
252
392
  * The Auth class.
253
393
  * @class
@@ -413,17 +553,6 @@ declare class Auth {
413
553
  * @throws {APIError} - Throws an error if the request fails.
414
554
  */
415
555
  unlinkTelegram(): Promise<any>;
416
- /**
417
- * Call a contract method.
418
- * @param {string} contractAddress The contract address.
419
- * @param {Abi} abi The contract ABI.
420
- * @param {string} methodName The method name.
421
- * @param {any[]} params The method parameters.
422
- * @param {CallOptions} [options] The call options.
423
- * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
424
- * @throws {Error} - Throws an error if the wallet client is not connected or if the method is not a view function.
425
- */
426
- callContractMethod(contractAddress: string, abi: Abi, methodName: string, params: any[], options?: CallOptions): Promise<any>;
427
556
  }
428
557
 
429
558
  export { Auth, SpotifyAPI, TwitterAPI };
@@ -1,4 +1,4 @@
1
- import { Abi } from 'viem';
1
+ import { Address, Hex, Abi } from 'viem';
2
2
 
3
3
  /**
4
4
  * The TwitterAPI class.
@@ -196,6 +196,99 @@ declare class SpotifyAPI {
196
196
  _fetchDataWithAuth(url: string): Promise<object>;
197
197
  }
198
198
 
199
+ /**
200
+ * Represents the terms of a license for a digital asset.
201
+ * @property price - The price of the asset in wei.
202
+ * @property duration - The duration of the license in seconds.
203
+ * @property royaltyBps - The royalty percentage in basis points (0-10000).
204
+ * @property paymentToken - The address of the payment token (ERC20 / address(0) for native currency).
205
+ */
206
+ type LicenseTerms = {
207
+ price: bigint;
208
+ duration: number;
209
+ royaltyBps: number;
210
+ paymentToken: Address;
211
+ };
212
+ /**
213
+ * Enum representing the status of data in the system.
214
+ * * - ACTIVE: The data is currently active and available.
215
+ * * - PENDING_DELETE: The data is scheduled for deletion but not yet removed.
216
+ * * - DELETED: The data has been deleted and is no longer available.
217
+ */
218
+ declare enum DataStatus {
219
+ ACTIVE = 0,
220
+ PENDING_DELETE = 1,
221
+ DELETED = 2
222
+ }
223
+ /**
224
+ * Represents the source of a Data NFT.
225
+ * This can be one of the supported social media platforms or a file upload.
226
+ */
227
+ type DataNFTSource = "spotify" | "twitter" | "tiktok" | "file";
228
+
229
+ /**
230
+ * Mints a Data NFT with a signature.
231
+ * @param to The address to mint the NFT to.
232
+ * @param tokenId The ID of the token to mint.
233
+ * @param hash The hash of the data associated with the NFT.
234
+ * @param uri The URI of the NFT metadata.
235
+ * @param licenseTerms The terms of the license for the NFT.
236
+ * @param deadline The deadline for the minting operation.
237
+ * @param signature The signature for the minting operation.
238
+ * @returns A promise that resolves when the minting is complete.
239
+ */
240
+ declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, hash: Hex, uri: string, licenseTerms: LicenseTerms, deadline: bigint, signature: {
241
+ v: number;
242
+ r: Hex;
243
+ s: Hex;
244
+ }): Promise<any>;
245
+ /**
246
+ * Registers a Data NFT with the Origin service in order to obtain a signature for minting.
247
+ * @param source The source of the Data NFT (e.g., "spotify", "twitter", "tiktok", or "file").
248
+ * @param deadline The deadline for the registration operation.
249
+ * @param fileKey Optional file key for file uploads.
250
+ * @return A promise that resolves with the registration data.
251
+ */
252
+ declare function registerDataNFT(this: Origin, source: DataNFTSource, deadline: bigint, fileKey?: string | string[]): Promise<any>;
253
+
254
+ declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTerms): Promise<any>;
255
+
256
+ declare function requestDelete(this: Origin, tokenId: bigint): Promise<any>;
257
+
258
+ declare function getTerms(this: Origin, tokenId: bigint): Promise<any>;
259
+
260
+ declare function ownerOf(this: Origin, tokenId: bigint): Promise<any>;
261
+
262
+ declare function balanceOf(this: Origin, owner: Address): Promise<any>;
263
+
264
+ declare function contentHash(this: Origin, tokenId: bigint): Promise<any>;
265
+
266
+ declare function tokenURI(this: Origin, tokenId: bigint): Promise<any>;
267
+
268
+ declare function dataStatus(this: Origin, tokenId: bigint): Promise<DataStatus>;
269
+
270
+ declare function royaltyInfo(this: Origin, tokenId: bigint, salePrice: bigint): Promise<[Address, bigint]>;
271
+
272
+ declare function getApproved(this: Origin, tokenId: bigint): Promise<Address>;
273
+
274
+ declare function isApprovedForAll(this: Origin, owner: Address, operator: Address): Promise<boolean>;
275
+
276
+ declare function transferFrom(this: Origin, from: Address, to: Address, tokenId: bigint): Promise<any>;
277
+
278
+ declare function safeTransferFrom(this: Origin, from: Address, to: Address, tokenId: bigint, data?: Hex): Promise<any>;
279
+
280
+ declare function approve(this: Origin, to: Address, tokenId: bigint): Promise<any>;
281
+
282
+ declare function setApprovalForAll(this: Origin, operator: Address, approved: boolean): Promise<any>;
283
+
284
+ declare function buyAccess(this: Origin, tokenId: bigint, periods: number, value?: bigint): Promise<any>;
285
+
286
+ declare function renewAccess(this: Origin, tokenId: bigint, buyer: Address, periods: number, value?: bigint): Promise<any>;
287
+
288
+ declare function hasAccess(this: Origin, user: Address, tokenId: bigint): Promise<boolean>;
289
+
290
+ declare function subscriptionExpiry(this: Origin, tokenId: bigint, user: Address): Promise<bigint>;
291
+
199
292
  interface OriginUsageReturnType {
200
293
  user: {
201
294
  multiplier: number;
@@ -205,17 +298,50 @@ interface OriginUsageReturnType {
205
298
  teams: Array<any>;
206
299
  dataSources: Array<any>;
207
300
  }
301
+ type CallOptions = {
302
+ value?: bigint;
303
+ gas?: bigint;
304
+ waitForReceipt?: boolean;
305
+ };
208
306
  /**
209
307
  * The Origin class
210
308
  * Handles the upload of files to Origin, as well as querying the user's stats
211
309
  */
212
310
  declare class Origin {
213
311
  #private;
312
+ mintWithSignature: typeof mintWithSignature;
313
+ registerDataNFT: typeof registerDataNFT;
314
+ updateTerms: typeof updateTerms;
315
+ requestDelete: typeof requestDelete;
316
+ getTerms: typeof getTerms;
317
+ ownerOf: typeof ownerOf;
318
+ balanceOf: typeof balanceOf;
319
+ contentHash: typeof contentHash;
320
+ tokenURI: typeof tokenURI;
321
+ dataStatus: typeof dataStatus;
322
+ royaltyInfo: typeof royaltyInfo;
323
+ getApproved: typeof getApproved;
324
+ isApprovedForAll: typeof isApprovedForAll;
325
+ transferFrom: typeof transferFrom;
326
+ safeTransferFrom: typeof safeTransferFrom;
327
+ approve: typeof approve;
328
+ setApprovalForAll: typeof setApprovalForAll;
329
+ buyAccess: typeof buyAccess;
330
+ renewAccess: typeof renewAccess;
331
+ hasAccess: typeof hasAccess;
332
+ subscriptionExpiry: typeof subscriptionExpiry;
214
333
  private jwt;
215
- constructor(jwt: string);
334
+ private viemClient?;
335
+ constructor(jwt: string, viemClient?: any);
336
+ getJwt(): string;
337
+ setViemClient(client: any): void;
216
338
  uploadFile: (file: File, options?: {
217
339
  progressCallback?: (percent: number) => void;
218
- }) => Promise<void>;
340
+ }) => Promise<any>;
341
+ mintFile: (file: File, license: LicenseTerms, options?: {
342
+ progressCallback?: (percent: number) => void;
343
+ }) => Promise<string | null>;
344
+ mintSocial: (source: "spotify" | "twitter" | "tiktok") => Promise<string | null>;
219
345
  getOriginUploads: () => Promise<any>;
220
346
  /**
221
347
  * Get the user's Origin stats (multiplier, consent, usage, etc.).
@@ -236,6 +362,25 @@ declare class Origin {
236
362
  * @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the multiplier is not provided.
237
363
  */
238
364
  setOriginMultiplier(multiplier: number): Promise<void>;
365
+ /**
366
+ * Call a contract method.
367
+ * @param {string} contractAddress The contract address.
368
+ * @param {Abi} abi The contract ABI.
369
+ * @param {string} methodName The method name.
370
+ * @param {any[]} params The method parameters.
371
+ * @param {CallOptions} [options] The call options.
372
+ * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
373
+ * @throws {Error} - Throws an error if the wallet client is not connected and the method is not a view function.
374
+ */
375
+ callContractMethod(contractAddress: string, abi: Abi, methodName: string, params: any[], options?: CallOptions): Promise<any>;
376
+ /**
377
+ * Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
378
+ * @param {bigint} tokenId The token ID of the asset.
379
+ * @param {number} periods The number of periods to buy access for.
380
+ * @returns {Promise<any>} The result of the buyAccess call.
381
+ */
382
+ buyAccessSmart(tokenId: bigint, periods: number): Promise<any>;
383
+ getData(tokenId: bigint): Promise<any>;
239
384
  }
240
385
 
241
386
  declare global {
@@ -243,11 +388,6 @@ declare global {
243
388
  ethereum?: any;
244
389
  }
245
390
  }
246
- type CallOptions = {
247
- value?: bigint;
248
- gas?: bigint;
249
- waitForReceipt?: boolean;
250
- };
251
391
  /**
252
392
  * The Auth class.
253
393
  * @class
@@ -413,17 +553,6 @@ declare class Auth {
413
553
  * @throws {APIError} - Throws an error if the request fails.
414
554
  */
415
555
  unlinkTelegram(): Promise<any>;
416
- /**
417
- * Call a contract method.
418
- * @param {string} contractAddress The contract address.
419
- * @param {Abi} abi The contract ABI.
420
- * @param {string} methodName The method name.
421
- * @param {any[]} params The method parameters.
422
- * @param {CallOptions} [options] The call options.
423
- * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
424
- * @throws {Error} - Throws an error if the wallet client is not connected or if the method is not a view function.
425
- */
426
- callContractMethod(contractAddress: string, abi: Abi, methodName: string, params: any[], options?: CallOptions): Promise<any>;
427
556
  }
428
557
 
429
558
  export { Auth, SpotifyAPI, TwitterAPI };