@mycelium-sdk/core 0.1.0 → 1.0.0-alpha.0

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/index.d.ts CHANGED
@@ -553,71 +553,54 @@ interface SparkVaultBalance {
553
553
  }
554
554
 
555
555
  /**
556
- * Abstract base class for smart wallet providers
557
- *
558
- * @internal
559
- * @category Wallet Providers
560
- * @remarks
561
- * Defines the interface for factories that create and manage {@link SmartWallet} instances
562
- * Extended by implementations such as {@link DefaultSmartWalletProvider}
556
+ * Options for creating a smart wallet
557
+ * Parameters for creating a new smart wallet with specified owners and signer
563
558
  */
564
- declare abstract class SmartWalletProvider$1 {
565
- /**
566
- * Creates a new smart wallet instance that will be deployed on first transaction
567
- *
568
- * @internal
569
- * @category Creation
570
- * @remarks
571
- * Address is calculated deterministically using owners and nonce
572
- *
573
- * @param params Wallet creation parameters
574
- * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
575
- * @param params.signer Local account used for signing
576
- * @param params.nonce Optional nonce for address derivation, default 0
577
- * @returns Promise resolving to a {@link SmartWallet} instance
578
- */
579
- abstract createWallet(params: {
580
- owners: Array<Address | WebAuthnAccount>;
581
- signer: LocalAccount;
582
- nonce?: bigint;
583
- }): Promise<SmartWallet>;
584
- /**
585
- * Returns a smart wallet instance for an already deployed contract
586
- *
587
- * @internal
588
- * @category Retrieval
589
- * @remarks
590
- * Use when the wallet address is already known
591
- *
592
- * @param params Wallet retrieval parameters
593
- * @param params.walletAddress Deployed smart wallet address
594
- * @param params.signer Local account to operate the wallet
595
- * @param params.ownerIndex Optional index of signer in the owners list, default 0
596
- * @returns A {@link SmartWallet} instance
597
- */
598
- abstract getWallet(params: {
599
- walletAddress: Address;
600
- signer: LocalAccount;
601
- ownerIndex?: number;
602
- }): SmartWallet;
603
- /**
604
- * Predicts the deterministic address of a smart wallet
605
- *
606
- * @internal
607
- * @category Addressing
608
- * @remarks
609
- * Uses CREATE2 with owners and nonce to calculate the wallet address
610
- *
611
- * @param params Prediction parameters
612
- * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
613
- * @param params.nonce Optional nonce, default 0
614
- * @returns Promise resolving to the predicted {@link Address}
615
- */
616
- abstract getWalletAddress(params: {
617
- owners: Array<Address | WebAuthnAccount>;
618
- nonce?: bigint;
619
- }): Promise<Address>;
620
- }
559
+ type CreateSmartWalletOptions = {
560
+ owners: Array<Address | WebAuthnAccount>;
561
+ signer: LocalAccount;
562
+ nonce?: bigint;
563
+ };
564
+ /**
565
+ * Options for creating a wallet with embedded signer
566
+ * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
567
+ */
568
+ type CreateAccountOptions = {
569
+ owners?: Array<Address | WebAuthnAccount>;
570
+ embeddedWalletIndex?: number;
571
+ nonce?: bigint;
572
+ };
573
+ /**
574
+ * Options for retrieving a smart wallet with provided signer
575
+ * Parameters for getting an existing smart wallet using a provided LocalAccount signer
576
+ */
577
+ type GetSmartWalletOptions = {
578
+ signer: LocalAccount;
579
+ deploymentOwners?: Array<Address | WebAuthnAccount>;
580
+ signerOwnerIndex?: number;
581
+ walletAddress?: Address;
582
+ nonce?: bigint;
583
+ };
584
+ /**
585
+ * Options for retrieving an embedded wallet
586
+ * Parameters for getting an existing embedded wallet
587
+ */
588
+ type GetEmbeddedWalletOptions = {
589
+ walletId: string;
590
+ };
591
+ /**
592
+ * Options for retrieving a smart wallet with embedded wallet signer
593
+ * Parameters for getting an existing smart wallet using an embedded wallet as signer.
594
+ * If neither walletAddress nor deploymentOwners is provided, defaults to using the embedded wallet as single owner.
595
+ */
596
+ type GetAccountOptions = Omit<GetSmartWalletOptions, 'signer'> & GetEmbeddedWalletOptions;
597
+ /**
598
+ * Result of creating a unified web3 account in {@link WalletProvider.createAccount} and {@link WalletNamespace.createAccount}
599
+ */
600
+ type CreateAccountResult = {
601
+ embeddedWalletId: string;
602
+ smartWallet: SmartWallet;
603
+ };
621
604
 
622
605
  /**
623
606
  * Abstract base class for embedded wallet implementations
@@ -703,47 +686,71 @@ declare abstract class EmbeddedWalletProvider {
703
686
  }
704
687
 
705
688
  /**
706
- * Options for creating a smart wallet
707
- * Parameters for creating a new smart wallet with specified owners and signer
708
- */
709
- type CreateSmartWalletOptions = {
710
- owners: Array<Address | WebAuthnAccount>;
711
- signer: LocalAccount;
712
- nonce?: bigint;
713
- };
714
- /**
715
- * Options for creating a wallet with embedded signer
716
- * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
717
- */
718
- type CreateWalletWithEmbeddedSignerOptions = {
719
- owners?: Array<Address | WebAuthnAccount>;
720
- embeddedWalletIndex?: number;
721
- nonce?: bigint;
722
- };
723
- /**
724
- * Options for retrieving a smart wallet with provided signer
725
- * Parameters for getting an existing smart wallet using a provided LocalAccount signer
726
- */
727
- type GetSmartWalletOptions = {
728
- signer: LocalAccount;
729
- deploymentOwners?: Array<Address | WebAuthnAccount>;
730
- signerOwnerIndex?: number;
731
- walletAddress?: Address;
732
- nonce?: bigint;
733
- };
734
- /**
735
- * Options for retrieving an embedded wallet
736
- * Parameters for getting an existing embedded wallet
737
- */
738
- type GetEmbeddedWalletOptions = {
739
- walletId: string;
740
- };
741
- /**
742
- * Options for retrieving a smart wallet with embedded wallet signer
743
- * Parameters for getting an existing smart wallet using an embedded wallet as signer.
744
- * If neither walletAddress nor deploymentOwners is provided, defaults to using the embedded wallet as single owner.
689
+ * Abstract base class for smart wallet providers
690
+ *
691
+ * @internal
692
+ * @category Wallet Providers
693
+ * @remarks
694
+ * Defines the interface for factories that create and manage {@link SmartWallet} instances
695
+ * Extended by implementations such as {@link DefaultSmartWalletProvider}
745
696
  */
746
- type GetSmartWalletWithEmbeddedSignerOptions = Omit<GetSmartWalletOptions, 'signer'> & GetEmbeddedWalletOptions;
697
+ declare abstract class SmartWalletProvider$1 {
698
+ /**
699
+ * Creates a new smart wallet instance that will be deployed on first transaction
700
+ *
701
+ * @internal
702
+ * @category Creation
703
+ * @remarks
704
+ * Address is calculated deterministically using owners and nonce
705
+ *
706
+ * @param params Wallet creation parameters
707
+ * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
708
+ * @param params.signer Local account used for signing
709
+ * @param params.nonce Optional nonce for address derivation, default 0
710
+ * @returns Promise resolving to a {@link SmartWallet} instance
711
+ */
712
+ abstract createWallet(params: {
713
+ owners: Array<Address | WebAuthnAccount>;
714
+ signer: LocalAccount;
715
+ nonce?: bigint;
716
+ }): Promise<SmartWallet>;
717
+ /**
718
+ * Returns a smart wallet instance for an already deployed contract
719
+ *
720
+ * @internal
721
+ * @category Retrieval
722
+ * @remarks
723
+ * Use when the wallet address is already known
724
+ *
725
+ * @param params Wallet retrieval parameters
726
+ * @param params.walletAddress Deployed smart wallet address
727
+ * @param params.signer Local account to operate the wallet
728
+ * @param params.ownerIndex Optional index of signer in the owners list, default 0
729
+ * @returns A {@link SmartWallet} instance
730
+ */
731
+ abstract getWallet(params: {
732
+ walletAddress: Address;
733
+ signer: LocalAccount;
734
+ ownerIndex?: number;
735
+ }): SmartWallet;
736
+ /**
737
+ * Predicts the deterministic address of a smart wallet
738
+ *
739
+ * @internal
740
+ * @category Addressing
741
+ * @remarks
742
+ * Uses CREATE2 with owners and nonce to calculate the wallet address
743
+ *
744
+ * @param params Prediction parameters
745
+ * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
746
+ * @param params.nonce Optional nonce, default 0
747
+ * @returns Promise resolving to the predicted {@link Address}
748
+ */
749
+ abstract getWalletAddress(params: {
750
+ owners: Array<Address | WebAuthnAccount>;
751
+ nonce?: bigint;
752
+ }): Promise<Address>;
753
+ }
747
754
 
748
755
  /**
749
756
  * Unified Wallet Provider class
@@ -821,9 +828,9 @@ declare class WalletProvider {
821
828
  * @param params.nonce Optional salt/nonce for deterministic address calculation (defaults to 0)
822
829
  * @returns Promise that resolves to the created {@link SmartWallet}
823
830
  */
824
- createWalletWithEmbeddedSigner(params?: CreateWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
831
+ createAccount(params?: CreateAccountOptions): Promise<CreateAccountResult>;
825
832
  /**
826
- * Gets a smart wallet using an embedded wallet as the signer
833
+ * Gets a unified web3 account: a smart wallet using an embedded wallet as the signer
827
834
  *
828
835
  * @internal
829
836
  * @remarks
@@ -840,7 +847,7 @@ declare class WalletProvider {
840
847
  * @returns Promise that resolves to the {@link SmartWallet}
841
848
  * @throws Error if the embedded wallet cannot be found
842
849
  */
843
- getSmartWalletWithEmbeddedSigner(params: GetSmartWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
850
+ getAccount(params: GetAccountOptions): Promise<SmartWallet>;
844
851
  /**
845
852
  * Gets an existing embedded wallet by ID
846
853
  *
@@ -873,22 +880,27 @@ declare class WalletProvider {
873
880
  }
874
881
 
875
882
  /**
876
- * Public wallet namespace that exposes unified wallet operations
883
+ * Wallet namespace to create and retrieve different wallet formats and overall web3 account
877
884
  *
878
885
  * @public
879
- * @category Wallets creation and retrieval
886
+ * @category 2. Accounts creation and retrieval
880
887
  * @remarks
881
- * This class is returned by {@link MyceliumSDK} and provides a simplified
882
- * interface for wallet creation and retrieval. Advanced functionality can be accessed through
883
- * the underlying providers via the getters {@link embeddedWalletProvider} and
884
- * {@link smartWalletProvider}
888
+ * This class is returned by {@link MyceliumSDK} and provides a methods to create and retrieve different wallet formats
889
+ * The common methods are:
890
+ * - {@link createAccount} which creates a unified account: a smart wallet with an embedded wallet as signer
891
+ * - {@link getAccount} which retrieves a unified account: a smart wallet using an embedded walletId
892
+ * More advanced option are also available
885
893
  *
886
- * Typical flows:
887
- * - Create embedded wallet only: {@link createEmbeddedWallet}
888
- * - Create smart wallet only (you provide signer/owners): {@link createSmartWallet}
889
- * - Create smart wallet with embedded as signer: {@link createWalletWithEmbeddedSigner}
890
- * - Get smart wallet using embedded as signer: {@link getSmartWalletWithEmbeddedSigner}
891
- * - Get smart wallet using a provided signer: {@link getSmartWallet}
894
+ * @example
895
+ * ```ts
896
+ * // Create a smart wallet and related embedded wallet
897
+ * const { embeddedWalletId, smartWallet } = await myceliumSDK.wallet.createAccount();
898
+ *
899
+ * // Get the smart wallet using the embedded walletId
900
+ * const smartWallet = await myceliumSDK.wallet.getAccount({
901
+ * embeddedWalletId,
902
+ * });
903
+ * ```
892
904
  */
893
905
  declare class WalletNamespace {
894
906
  /**
@@ -901,28 +913,6 @@ declare class WalletNamespace {
901
913
  * @param provider Unified provider that composes embedded & smart providers
902
914
  */
903
915
  constructor(provider: WalletProvider);
904
- /**
905
- * Direct access to the underlying embedded wallet provider
906
- *
907
- * @public
908
- * @category Providers
909
- * @remarks
910
- * Useful when you need advanced functionality beyond the unified namespace. By default, you should use the unified namespace
911
- *
912
- * @returns The configured embedded wallet provider instance
913
- */
914
- get embeddedWalletProvider(): EmbeddedWalletProvider;
915
- /**
916
- * Direct access to the underlying smart wallet provider
917
- *
918
- * @public
919
- * @category Providers
920
- * @remarks
921
- * Useful when you need advanced functionality beyond the unified namespace. By default, you should use the unified namespace
922
- *
923
- * @returns The configured smart wallet provider instance
924
- */
925
- get smartWalletProvider(): SmartWalletProvider$1;
926
916
  /**
927
917
  * Creates an embedded wallet
928
918
  *
@@ -951,7 +941,7 @@ declare class WalletNamespace {
951
941
  */
952
942
  createSmartWallet(params: CreateSmartWalletOptions): Promise<SmartWallet>;
953
943
  /**
954
- * Creates a smart wallet with an embedded wallet as signer
944
+ * A unified a web3 account: creates a smart wallet with an embedded wallet as signer
955
945
  *
956
946
  * @public
957
947
  * @category Creation
@@ -965,9 +955,9 @@ declare class WalletNamespace {
965
955
  * @param params.nonce Optional nonce/salt for deterministic address generation (defaults to 0)
966
956
  * @returns Promise that resolves to the created {@link SmartWallet}
967
957
  */
968
- createWalletWithEmbeddedSigner(params?: CreateWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
958
+ createAccount(params?: CreateAccountOptions): Promise<CreateAccountResult>;
969
959
  /**
970
- * Gets a smart wallet using an embedded wallet as the signer
960
+ * Gets a unified web3 account: a smart wallet using an embedded wallet as the signer
971
961
  *
972
962
  * @public
973
963
  * @category Retrieval
@@ -985,7 +975,7 @@ declare class WalletNamespace {
985
975
  * @returns Promise that resolves to the {@link SmartWallet}
986
976
  * @throws Error if the embedded wallet cannot be found
987
977
  */
988
- getSmartWalletWithEmbeddedSigner(params: GetSmartWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
978
+ getAccount(params: GetAccountOptions): Promise<SmartWallet>;
989
979
  /**
990
980
  * Gets an existing embedded wallet by ID
991
981
  *
@@ -1245,7 +1235,7 @@ declare class CoinbaseCDP {
1245
1235
  * Default ERC-4337 smart wallet implementation. Implements main methods that a user can use to interact with DeFi protocols and use all related functionalities
1246
1236
  *
1247
1237
  * @public
1248
- * @category Wallets operations
1238
+ * @category 3. Account operations
1249
1239
  * @remarks
1250
1240
  * Backed by Coinbase Smart Account and compatible with ERC-4337 UserOperations
1251
1241
  * Supports multi-owner wallets (EVM addresses or WebAuthn owners), gas-sponsored flows,
@@ -1379,7 +1369,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1379
1369
  * Funds the smart wallet with the specified amount of the specified token via Coinbase CDP on-ramp service
1380
1370
  *
1381
1371
  * @public
1382
- * @category Ramp
1372
+ * @category Funding
1383
1373
  *
1384
1374
  * @remarks
1385
1375
  * If Coinbase CDP is not initialized, the method will throw an error. For more details, visit @see {@link https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-session}
@@ -1400,7 +1390,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1400
1390
  * Cashout token from smart wallet to fiat currency via Coinbase CDP off-ramp service
1401
1391
  *
1402
1392
  * @public
1403
- * @category Ramp
1393
+ * @category Funding
1404
1394
  *
1405
1395
  * @remarks
1406
1396
  * If Coinbase CDP is not initialized, the method will throw an error. For more details, visit @see {@link https://docs.cdp.coinbase.com/api-reference/rest-api/onramp-offramp/create-sell-quote}
@@ -1431,11 +1421,59 @@ declare class DefaultSmartWallet extends SmartWallet {
1431
1421
  sendTokens(amount: number, asset: AssetIdentifier, recipientAddress: Address): Promise<TransactionData>;
1432
1422
  }
1433
1423
 
1424
+ /**
1425
+ * Namespace to manage funding & payouts of an account
1426
+ * @public
1427
+ * @remarks
1428
+ * Contains 2 methods to get available options to top up an account and cash out funds
1429
+ * - {@link getTopUpConfig} to get available options to top up an account
1430
+ * - {@link getCashOutConfig} to get available options to cash out funds
1431
+ *
1432
+ * @example
1433
+ * ```ts
1434
+ * const topUpConfig = await myceliumSDK.funding.getTopUpConfig();
1435
+ * const cashOutConfig = await myceliumSDK.funding.getCashOutConfig();
1436
+ * ```
1437
+ * @category 4. Funding & payouts
1438
+ */
1439
+ declare class FundingNamespace {
1440
+ private readonly coinbaseCDP;
1441
+ constructor(coinbaseCDP: CoinbaseCDP);
1442
+ /**
1443
+ * Return all supported countries and payment methods for on-ramp by Coinbase CDP
1444
+ * @public
1445
+ * @category Funding
1446
+ *
1447
+ * @returns @see {@link RampConfigResponse} with supported countries and payment methods for top-up
1448
+ * @throws If API returned an error
1449
+ */
1450
+ getTopUpConfig(): Promise<RampConfigResponse>;
1451
+ /**
1452
+ * Return all supported countries and payment methods for off-ramp by Coinbase CDP
1453
+ * @public
1454
+ * @category Funding
1455
+ *
1456
+ *
1457
+ * @returns @see {@link RampConfigResponse} with supported countries and payment methods for cash out
1458
+ * @throws If API returned an error
1459
+ */
1460
+ getCashOutConfig(): Promise<RampConfigResponse>;
1461
+ }
1462
+
1463
+ /**
1464
+ * @packageDocumentation
1465
+ * Entry point for the Mycelium SDK
1466
+ *
1467
+ * Exports stable types and the main SDK facade (`MyceliumSDK`)
1468
+ * Internal base classes and implementations are not part of the public API
1469
+ * and are hidden from public documentation
1470
+ */
1471
+
1434
1472
  /**
1435
1473
  * Main SDK facade for integrating wallets and protocols.
1436
1474
  *
1437
1475
  * @public
1438
- * @category Get started
1476
+ * @category 1. Getting started
1439
1477
  * @remarks
1440
1478
  * This class encapsulates:
1441
1479
  * - protocol selection and initialization (`Smart Router`),
@@ -1459,21 +1497,26 @@ declare class DefaultSmartWallet extends SmartWallet {
1459
1497
  *
1460
1498
  * const sdk = new MyceliumSDK(config);
1461
1499
  *
1462
- * const embeddedWallet = await sdk.wallet.createEmbeddedWallet();
1463
- * const wallet = await sdk.wallet.createSmartWallet({
1464
- * owners: [embeddedWallet.address],
1465
- * signer: await embeddedWallet.account(),
1466
- * })
1467
- * const balance = await wallet.getBalance();
1500
+ * const {embeddedWalletId, smartWallet} = await sdk.wallet.createAccount();
1501
+ * const balance = await smartWallet.getBalance();
1468
1502
  * ```
1469
1503
  */
1470
1504
  declare class MyceliumSDK {
1471
1505
  /**
1472
- * Unified wallet namespace to manage embedded/smart wallets and related operations
1506
+ * Returns a unified wallet namespace to manage embedded/smart wallets and related operations
1473
1507
  * @public
1474
1508
  * @category Wallets
1475
1509
  */
1476
1510
  readonly wallet: WalletNamespace;
1511
+ /**
1512
+ * Ramp namespace to manage ramp operations. Methods are available on {@link RampNamespace}
1513
+ * @internal
1514
+ * @remarks
1515
+ * If the Coinbase CDP configuration is not provided, the ramp functionality will be disabled.
1516
+ * Calling the respective method will throw an error
1517
+ * @category Tools
1518
+ */
1519
+ readonly fundingNamespace: FundingNamespace | null;
1477
1520
  /**
1478
1521
  * Chain manager instance to manage chain related entities
1479
1522
  * @internal
@@ -1507,37 +1550,23 @@ declare class MyceliumSDK {
1507
1550
  /**
1508
1551
  * Returns the chain manager instance for multi-chain operations
1509
1552
  * @public
1553
+ * @remarks
1554
+ * More about methods in {@link ChainManager}
1510
1555
  * @category Tools
1511
1556
  *
1512
1557
  * @returns ChainManager instance of the type {@link ChainManager}
1513
1558
  */
1514
1559
  get chainManager(): ChainManager;
1515
1560
  /**
1516
- * Coinbase CDP configuration methods for ramp operations
1561
+ * Returns a funding namespace to manage top ups & cash outs configurations
1517
1562
  * @public
1563
+ * @remarks
1564
+ * More about methods in {@link FundingNamespace}
1518
1565
  * @category Tools
1566
+ *
1567
+ * @returns Funding namespace of the type {@link FundingNamespace}
1519
1568
  */
1520
- readonly rampConfig: {
1521
- /**
1522
- * Return all supported countries and payment methods for on-ramp by Coinbase CDP
1523
- * @public
1524
- * @category Ramp
1525
- *
1526
- * @returns @see {@link RampConfigResponse} with supported countries and payment methods for top-up
1527
- * @throws If API returned an error
1528
- */
1529
- getTopUpConfig: () => Promise<RampConfigResponse>;
1530
- /**
1531
- * Return all supported countries and payment methods for off-ramp by Coinbase CDP
1532
- * @public
1533
- * @category Ramp
1534
- *
1535
- *
1536
- * @returns @see {@link RampConfigResponse} with supported countries and payment methods for cash out
1537
- * @throws If API returned an error
1538
- */
1539
- getCashOutConfig: () => Promise<RampConfigResponse>;
1540
- };
1569
+ get funding(): FundingNamespace;
1541
1570
  /**
1542
1571
  * Recommends and initializes a protocol based on router settings
1543
1572
  *
@@ -1565,4 +1594,4 @@ declare class MyceliumSDK {
1565
1594
  private createWalletNamespace;
1566
1595
  }
1567
1596
 
1568
- export { type OffRampUrlResponse as CashOutUrlResponse, DefaultSmartWallet, EmbeddedWallet, MyceliumSDK, type MyceliumSDKConfig, type RampConfigResponse, SmartWallet, type SparkVaultBalance, type SparkVaultTxnResult, type TokenBalance, type OnRampUrlResponse as TopUpUrlResponse, type VaultBalance, type VaultTxnResult, WalletNamespace };
1597
+ export { type OffRampUrlResponse as CashOutUrlResponse, DefaultSmartWallet, EmbeddedWallet, FundingNamespace, type RampConfigResponse as FundingOptionsResponse, MyceliumSDK, type MyceliumSDKConfig, SmartWallet, type SparkVaultBalance, type SparkVaultTxnResult, type TokenBalance, type OnRampUrlResponse as TopUpUrlResponse, type VaultBalance, type VaultTxnResult, WalletNamespace };