@campnetwork/origin 1.2.0-1 → 1.2.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 { Address, Hex, WalletClient, Abi } from 'viem';
1
+ import { Address, Hex, WalletClient, Abi, Account, Chain } from 'viem';
2
2
 
3
3
  /**
4
4
  * The TwitterAPI class.
@@ -234,6 +234,15 @@ declare enum DataStatus {
234
234
  PENDING_DELETE = 1,
235
235
  DELETED = 2
236
236
  }
237
+ /**
238
+ * Creates license terms for a digital asset.
239
+ * @param price The price of the asset in wei.
240
+ * @param duration The duration of the license in seconds.
241
+ * @param royaltyBps The royalty percentage in basis points (0-10000).
242
+ * @param paymentToken The address of the payment token (ERC20 / address(0) for native currency).
243
+ * @returns The created license terms.
244
+ */
245
+ declare const createLicenseTerms: (price: bigint, duration: number, royaltyBps: number, paymentToken: Address) => LicenseTerms;
237
246
  /**
238
247
  * Represents the source of an IpNFT.
239
248
  * This can be one of the supported social media platforms or a file upload.
@@ -493,6 +502,30 @@ declare class Origin {
493
502
  claimRoyalties(tokenId: bigint, recipient?: Address, token?: Address): Promise<any>;
494
503
  }
495
504
 
505
+ interface StorageAdapter {
506
+ getItem(key: string): Promise<string | null>;
507
+ setItem(key: string, value: string): Promise<void>;
508
+ removeItem(key: string): Promise<void>;
509
+ }
510
+ /**
511
+ * Browser localStorage adapter
512
+ */
513
+ declare class BrowserStorage implements StorageAdapter {
514
+ getItem(key: string): Promise<string | null>;
515
+ setItem(key: string, value: string): Promise<void>;
516
+ removeItem(key: string): Promise<void>;
517
+ }
518
+ /**
519
+ * In-memory storage adapter for Node.js
520
+ */
521
+ declare class MemoryStorage implements StorageAdapter {
522
+ private storage;
523
+ getItem(key: string): Promise<string | null>;
524
+ setItem(key: string, value: string): Promise<void>;
525
+ removeItem(key: string): Promise<void>;
526
+ clear(): void;
527
+ }
528
+
496
529
  declare global {
497
530
  interface Window {
498
531
  ethereum?: any;
@@ -520,12 +553,14 @@ declare class Auth {
520
553
  * @param {string} options.clientId The client ID.
521
554
  * @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.
522
555
  * @param {("DEVELOPMENT"|"PRODUCTION")} [options.environment="DEVELOPMENT"] The environment to use.
556
+ * @param {StorageAdapter} [options.storage] Custom storage adapter. Defaults to localStorage in browser, memory storage in Node.js.
523
557
  * @throws {APIError} - Throws an error if the clientId is not provided.
524
558
  */
525
- constructor({ clientId, redirectUri, environment, }: {
559
+ constructor({ clientId, redirectUri, environment, storage, }: {
526
560
  clientId: string;
527
561
  redirectUri: string | Record<string, string>;
528
562
  environment?: "DEVELOPMENT" | "PRODUCTION";
563
+ storage?: StorageAdapter;
529
564
  });
530
565
  /**
531
566
  * Subscribe to an event. Possible events are "state", "provider", "providers", and "viem".
@@ -588,6 +623,33 @@ declare class Auth {
588
623
  message: string;
589
624
  walletAddress: string;
590
625
  }>;
626
+ /**
627
+ * Connect with a custom signer (for Node.js or custom wallet implementations).
628
+ * This method bypasses browser wallet interactions and uses the provided signer directly.
629
+ * @param {any} signer The signer instance (viem WalletClient, ethers Signer, or custom signer).
630
+ * @param {object} [options] Optional configuration.
631
+ * @param {string} [options.domain] The domain to use in SIWE message (defaults to 'localhost').
632
+ * @param {string} [options.uri] The URI to use in SIWE message (defaults to 'http://localhost').
633
+ * @returns {Promise<{ success: boolean; message: string; walletAddress: string }>} A promise that resolves with the authentication result.
634
+ * @throws {APIError} - Throws an error if authentication fails.
635
+ * @example
636
+ * // Using with ethers
637
+ * const signer = new ethers.Wallet(privateKey, provider);
638
+ * await auth.connectWithSigner(signer, { domain: 'myapp.com', uri: 'https://myapp.com' });
639
+ *
640
+ * // Using with viem
641
+ * const account = privateKeyToAccount('0x...');
642
+ * const client = createWalletClient({ account, chain: mainnet, transport: http() });
643
+ * await auth.connectWithSigner(client);
644
+ */
645
+ connectWithSigner(signer: any, options?: {
646
+ domain?: string;
647
+ uri?: string;
648
+ }): Promise<{
649
+ success: boolean;
650
+ message: string;
651
+ walletAddress: string;
652
+ }>;
591
653
  /**
592
654
  * Get the user's linked social accounts.
593
655
  * @returns {Promise<Record<string, boolean>>} A promise that resolves with the user's linked social accounts.
@@ -601,19 +663,19 @@ declare class Auth {
601
663
  /**
602
664
  * Link the user's Twitter account.
603
665
  * @returns {Promise<void>}
604
- * @throws {Error} - Throws an error if the user is not authenticated.
666
+ * @throws {Error} - Throws an error if the user is not authenticated or in Node.js environment.
605
667
  */
606
668
  linkTwitter(): Promise<void>;
607
669
  /**
608
670
  * Link the user's Discord account.
609
671
  * @returns {Promise<void>}
610
- * @throws {Error} - Throws an error if the user is not authenticated.
672
+ * @throws {Error} - Throws an error if the user is not authenticated or in Node.js environment.
611
673
  */
612
674
  linkDiscord(): Promise<void>;
613
675
  /**
614
676
  * Link the user's Spotify account.
615
677
  * @returns {Promise<void>}
616
- * @throws {Error} - Throws an error if the user is not authenticated.
678
+ * @throws {Error} - Throws an error if the user is not authenticated or in Node.js environment.
617
679
  */
618
680
  linkSpotify(): Promise<void>;
619
681
  /**
@@ -676,4 +738,106 @@ declare class Auth {
676
738
  unlinkTelegram(): Promise<any>;
677
739
  }
678
740
 
679
- export { Auth, SpotifyAPI, TwitterAPI };
741
+ interface BaseSigner {
742
+ getAddress(): Promise<string>;
743
+ signMessage(message: string): Promise<string>;
744
+ getChainId(): Promise<number>;
745
+ }
746
+ type SignerType = "viem" | "ethers" | "custom";
747
+ interface SignerAdapter {
748
+ type: SignerType;
749
+ signer: any;
750
+ getAddress(): Promise<string>;
751
+ signMessage(message: string): Promise<string>;
752
+ getChainId(): Promise<number>;
753
+ }
754
+
755
+ /**
756
+ * Adapter for viem WalletClient
757
+ */
758
+ declare class ViemSignerAdapter implements SignerAdapter {
759
+ type: SignerType;
760
+ signer: WalletClient;
761
+ constructor(signer: WalletClient);
762
+ getAddress(): Promise<string>;
763
+ signMessage(message: string): Promise<string>;
764
+ getChainId(): Promise<number>;
765
+ }
766
+ /**
767
+ * Adapter for ethers Signer (v5 and v6)
768
+ */
769
+ declare class EthersSignerAdapter implements SignerAdapter {
770
+ type: SignerType;
771
+ signer: any;
772
+ constructor(signer: any);
773
+ getAddress(): Promise<string>;
774
+ signMessage(message: string): Promise<string>;
775
+ getChainId(): Promise<number>;
776
+ }
777
+ /**
778
+ * Adapter for custom signer implementations
779
+ */
780
+ declare class CustomSignerAdapter implements SignerAdapter {
781
+ type: SignerType;
782
+ signer: any;
783
+ constructor(signer: any);
784
+ getAddress(): Promise<string>;
785
+ signMessage(message: string): Promise<string>;
786
+ getChainId(): Promise<number>;
787
+ }
788
+ /**
789
+ * Factory function to create appropriate adapter based on signer type
790
+ */
791
+ declare function createSignerAdapter(signer: any): SignerAdapter;
792
+
793
+ /**
794
+ * Create a wallet client for Node.js environment
795
+ * @param account The viem account
796
+ * @param chain The chain to use
797
+ * @param rpcUrl Optional RPC URL (defaults to chain's default RPC)
798
+ * @returns WalletClient
799
+ */
800
+ declare function createNodeWalletClient(account: Account, chain: Chain, rpcUrl?: string): WalletClient;
801
+
802
+ declare const testnet: {
803
+ id: number;
804
+ name: string;
805
+ nativeCurrency: {
806
+ decimals: number;
807
+ name: string;
808
+ symbol: string;
809
+ };
810
+ rpcUrls: {
811
+ default: {
812
+ http: string[];
813
+ };
814
+ };
815
+ blockExplorers: {
816
+ default: {
817
+ name: string;
818
+ url: string;
819
+ };
820
+ };
821
+ };
822
+ declare const mainnet: {
823
+ id: number;
824
+ name: string;
825
+ nativeCurrency: {
826
+ decimals: number;
827
+ name: string;
828
+ symbol: string;
829
+ };
830
+ rpcUrls: {
831
+ default: {
832
+ http: string[];
833
+ };
834
+ };
835
+ blockExplorers: {
836
+ default: {
837
+ name: string;
838
+ url: string;
839
+ };
840
+ };
841
+ };
842
+
843
+ export { Auth, type BaseSigner, BrowserStorage, CustomSignerAdapter, DataStatus, EthersSignerAdapter, type LicenseTerms, MemoryStorage, type SignerAdapter, type SignerType, SpotifyAPI, type StorageAdapter, TwitterAPI, ViemSignerAdapter, mainnet as campMainnet, testnet as campTestnet, createLicenseTerms, createNodeWalletClient, createSignerAdapter };
@@ -1,4 +1,4 @@
1
- import { Address, Hex, WalletClient, Abi } from 'viem';
1
+ import { Address, Hex, WalletClient, Abi, Account, Chain } from 'viem';
2
2
 
3
3
  /**
4
4
  * The TwitterAPI class.
@@ -234,6 +234,15 @@ declare enum DataStatus {
234
234
  PENDING_DELETE = 1,
235
235
  DELETED = 2
236
236
  }
237
+ /**
238
+ * Creates license terms for a digital asset.
239
+ * @param price The price of the asset in wei.
240
+ * @param duration The duration of the license in seconds.
241
+ * @param royaltyBps The royalty percentage in basis points (0-10000).
242
+ * @param paymentToken The address of the payment token (ERC20 / address(0) for native currency).
243
+ * @returns The created license terms.
244
+ */
245
+ declare const createLicenseTerms: (price: bigint, duration: number, royaltyBps: number, paymentToken: Address) => LicenseTerms;
237
246
  /**
238
247
  * Represents the source of an IpNFT.
239
248
  * This can be one of the supported social media platforms or a file upload.
@@ -493,6 +502,30 @@ declare class Origin {
493
502
  claimRoyalties(tokenId: bigint, recipient?: Address, token?: Address): Promise<any>;
494
503
  }
495
504
 
505
+ interface StorageAdapter {
506
+ getItem(key: string): Promise<string | null>;
507
+ setItem(key: string, value: string): Promise<void>;
508
+ removeItem(key: string): Promise<void>;
509
+ }
510
+ /**
511
+ * Browser localStorage adapter
512
+ */
513
+ declare class BrowserStorage implements StorageAdapter {
514
+ getItem(key: string): Promise<string | null>;
515
+ setItem(key: string, value: string): Promise<void>;
516
+ removeItem(key: string): Promise<void>;
517
+ }
518
+ /**
519
+ * In-memory storage adapter for Node.js
520
+ */
521
+ declare class MemoryStorage implements StorageAdapter {
522
+ private storage;
523
+ getItem(key: string): Promise<string | null>;
524
+ setItem(key: string, value: string): Promise<void>;
525
+ removeItem(key: string): Promise<void>;
526
+ clear(): void;
527
+ }
528
+
496
529
  declare global {
497
530
  interface Window {
498
531
  ethereum?: any;
@@ -520,12 +553,14 @@ declare class Auth {
520
553
  * @param {string} options.clientId The client ID.
521
554
  * @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.
522
555
  * @param {("DEVELOPMENT"|"PRODUCTION")} [options.environment="DEVELOPMENT"] The environment to use.
556
+ * @param {StorageAdapter} [options.storage] Custom storage adapter. Defaults to localStorage in browser, memory storage in Node.js.
523
557
  * @throws {APIError} - Throws an error if the clientId is not provided.
524
558
  */
525
- constructor({ clientId, redirectUri, environment, }: {
559
+ constructor({ clientId, redirectUri, environment, storage, }: {
526
560
  clientId: string;
527
561
  redirectUri: string | Record<string, string>;
528
562
  environment?: "DEVELOPMENT" | "PRODUCTION";
563
+ storage?: StorageAdapter;
529
564
  });
530
565
  /**
531
566
  * Subscribe to an event. Possible events are "state", "provider", "providers", and "viem".
@@ -588,6 +623,33 @@ declare class Auth {
588
623
  message: string;
589
624
  walletAddress: string;
590
625
  }>;
626
+ /**
627
+ * Connect with a custom signer (for Node.js or custom wallet implementations).
628
+ * This method bypasses browser wallet interactions and uses the provided signer directly.
629
+ * @param {any} signer The signer instance (viem WalletClient, ethers Signer, or custom signer).
630
+ * @param {object} [options] Optional configuration.
631
+ * @param {string} [options.domain] The domain to use in SIWE message (defaults to 'localhost').
632
+ * @param {string} [options.uri] The URI to use in SIWE message (defaults to 'http://localhost').
633
+ * @returns {Promise<{ success: boolean; message: string; walletAddress: string }>} A promise that resolves with the authentication result.
634
+ * @throws {APIError} - Throws an error if authentication fails.
635
+ * @example
636
+ * // Using with ethers
637
+ * const signer = new ethers.Wallet(privateKey, provider);
638
+ * await auth.connectWithSigner(signer, { domain: 'myapp.com', uri: 'https://myapp.com' });
639
+ *
640
+ * // Using with viem
641
+ * const account = privateKeyToAccount('0x...');
642
+ * const client = createWalletClient({ account, chain: mainnet, transport: http() });
643
+ * await auth.connectWithSigner(client);
644
+ */
645
+ connectWithSigner(signer: any, options?: {
646
+ domain?: string;
647
+ uri?: string;
648
+ }): Promise<{
649
+ success: boolean;
650
+ message: string;
651
+ walletAddress: string;
652
+ }>;
591
653
  /**
592
654
  * Get the user's linked social accounts.
593
655
  * @returns {Promise<Record<string, boolean>>} A promise that resolves with the user's linked social accounts.
@@ -601,19 +663,19 @@ declare class Auth {
601
663
  /**
602
664
  * Link the user's Twitter account.
603
665
  * @returns {Promise<void>}
604
- * @throws {Error} - Throws an error if the user is not authenticated.
666
+ * @throws {Error} - Throws an error if the user is not authenticated or in Node.js environment.
605
667
  */
606
668
  linkTwitter(): Promise<void>;
607
669
  /**
608
670
  * Link the user's Discord account.
609
671
  * @returns {Promise<void>}
610
- * @throws {Error} - Throws an error if the user is not authenticated.
672
+ * @throws {Error} - Throws an error if the user is not authenticated or in Node.js environment.
611
673
  */
612
674
  linkDiscord(): Promise<void>;
613
675
  /**
614
676
  * Link the user's Spotify account.
615
677
  * @returns {Promise<void>}
616
- * @throws {Error} - Throws an error if the user is not authenticated.
678
+ * @throws {Error} - Throws an error if the user is not authenticated or in Node.js environment.
617
679
  */
618
680
  linkSpotify(): Promise<void>;
619
681
  /**
@@ -676,4 +738,106 @@ declare class Auth {
676
738
  unlinkTelegram(): Promise<any>;
677
739
  }
678
740
 
679
- export { Auth, SpotifyAPI, TwitterAPI };
741
+ interface BaseSigner {
742
+ getAddress(): Promise<string>;
743
+ signMessage(message: string): Promise<string>;
744
+ getChainId(): Promise<number>;
745
+ }
746
+ type SignerType = "viem" | "ethers" | "custom";
747
+ interface SignerAdapter {
748
+ type: SignerType;
749
+ signer: any;
750
+ getAddress(): Promise<string>;
751
+ signMessage(message: string): Promise<string>;
752
+ getChainId(): Promise<number>;
753
+ }
754
+
755
+ /**
756
+ * Adapter for viem WalletClient
757
+ */
758
+ declare class ViemSignerAdapter implements SignerAdapter {
759
+ type: SignerType;
760
+ signer: WalletClient;
761
+ constructor(signer: WalletClient);
762
+ getAddress(): Promise<string>;
763
+ signMessage(message: string): Promise<string>;
764
+ getChainId(): Promise<number>;
765
+ }
766
+ /**
767
+ * Adapter for ethers Signer (v5 and v6)
768
+ */
769
+ declare class EthersSignerAdapter implements SignerAdapter {
770
+ type: SignerType;
771
+ signer: any;
772
+ constructor(signer: any);
773
+ getAddress(): Promise<string>;
774
+ signMessage(message: string): Promise<string>;
775
+ getChainId(): Promise<number>;
776
+ }
777
+ /**
778
+ * Adapter for custom signer implementations
779
+ */
780
+ declare class CustomSignerAdapter implements SignerAdapter {
781
+ type: SignerType;
782
+ signer: any;
783
+ constructor(signer: any);
784
+ getAddress(): Promise<string>;
785
+ signMessage(message: string): Promise<string>;
786
+ getChainId(): Promise<number>;
787
+ }
788
+ /**
789
+ * Factory function to create appropriate adapter based on signer type
790
+ */
791
+ declare function createSignerAdapter(signer: any): SignerAdapter;
792
+
793
+ /**
794
+ * Create a wallet client for Node.js environment
795
+ * @param account The viem account
796
+ * @param chain The chain to use
797
+ * @param rpcUrl Optional RPC URL (defaults to chain's default RPC)
798
+ * @returns WalletClient
799
+ */
800
+ declare function createNodeWalletClient(account: Account, chain: Chain, rpcUrl?: string): WalletClient;
801
+
802
+ declare const testnet: {
803
+ id: number;
804
+ name: string;
805
+ nativeCurrency: {
806
+ decimals: number;
807
+ name: string;
808
+ symbol: string;
809
+ };
810
+ rpcUrls: {
811
+ default: {
812
+ http: string[];
813
+ };
814
+ };
815
+ blockExplorers: {
816
+ default: {
817
+ name: string;
818
+ url: string;
819
+ };
820
+ };
821
+ };
822
+ declare const mainnet: {
823
+ id: number;
824
+ name: string;
825
+ nativeCurrency: {
826
+ decimals: number;
827
+ name: string;
828
+ symbol: string;
829
+ };
830
+ rpcUrls: {
831
+ default: {
832
+ http: string[];
833
+ };
834
+ };
835
+ blockExplorers: {
836
+ default: {
837
+ name: string;
838
+ url: string;
839
+ };
840
+ };
841
+ };
842
+
843
+ export { Auth, type BaseSigner, BrowserStorage, CustomSignerAdapter, DataStatus, EthersSignerAdapter, type LicenseTerms, MemoryStorage, type SignerAdapter, type SignerType, SpotifyAPI, type StorageAdapter, TwitterAPI, ViemSignerAdapter, mainnet as campMainnet, testnet as campTestnet, createLicenseTerms, createNodeWalletClient, createSignerAdapter };