The platform-agnostic Exodus wallet SDK
npm install @exodus/headlessThe platform-agnostic Exodus wallet SDK, including core features such as seed phrase management, transaction signing, blockchain metadata, balances and others.
- Quick Start
- Lifecycle
- Port
- Adapters
- Config
- Headless API
``js
import createExodus from '@exodus/headless'
import referrals from '@exodus/headless/src/modules/referrals'
import Emitter from '@exodus/wild-emitter'
// 1. Create port. Acts as an event bus between headless wallet and client
const port = new Emitter()
// 2. Instantiate client-specific adapters and config. More details below
const adapters = {}
const config = {}
// 3. Create Exodus container
const exodusContainer = createExodus({ port, adapters, config })
// 4. Register external modules. Does not support overriding modules at the moment.
exodusContainer.register({
definition: {
id: 'remoteConfig',
factory: createRemoteConfig,
dependencies: ['config', 'fetch', 'logger'],
},
})
// see an example feature definition:
// ../../features/geolocation/index.js
exodusContainer.use(referrals())
exodusContainer.use(myCustomFeature({ id: 'myCustomFeature', ... }))
// 5. Resolve exodus instance
const exodus = exodusContainer.resolve()
// 6. Start exodus instance
await exodus.wallet.start()
// 7. Use it!
await exodus.wallet.create({ passphrase: 'my-super-secure-passphrase' })
// 8. Use your custom feature API, if any
exodus.myCustomFeature.doThatThingYouDo()
`
The headless wallet instance transitions through different states during his life. When moving from one another, there are two things that are triggered:
- Fires hook call: Allows modules to subscribe and halt transition until listener resolves.
- Fires event call: Emitted after all hooks had been executed and resolved.
For more information about lifecycle hooks, please refer to the application feature documentation.
Event bus between headless wallet and client
| Method | Type | Description |
| ----------- | ------------------------------------------ | ------------------------------------------ |
| subscribe | ({ type: string, payload: any }) => void | Subscribe to receive events. |({ type: string, payload: any }) => void
| unsubscribe | | Unsubscribe handler from receiving events. |(type: string, payload: any) => void
| emit | | Emit an event. |
Adapters are client-specific implementations of defined APIs needed for the wallet to function.
New adapters will be required by this module as we migrate more modules into it. Below are explained the ones that this module requires at the date.
AssetsModule implementation. Currently being injected as each of our clients have different implementations.
A function that returns an instance of the Logger class with the given namespace.
| Parameter | Type | Description |
| --------- | -------- | ----------------------------- |
| namespace | string | The namespace for the logger. |
The returned Logger instance has the following methods:
| Method | Type | Description |
| ------ | -------------------------- | ----------------------------------- |
| trace | (...args: any[]) => void | Log a message with the trace level. |(...args: any[]) => void
| debug | | Log a message with the debug level. |(...args: any[]) => void
| log | | Log a message with the log level. |(...args: any[]) => void
| info | | Log a message with the info level. |(...args: any[]) => void
| warn | | Log a message with the warn level. |(...args: any[]) => void
| error | | Log a message with the error level. |
Each method takes any number of arguments, which will be logged as a message with the corresponding log level. The message will be prefixed with the logger's namespace.
Legacy private to public key transformation function.
An object where each key is an asset name and the value is a function that takes a Buffer and returns a Buffer.
Unsafe (raw text) storage instance. Used internally by modules to persist data in client underlying storage layer.
In most cases you probably want to use encrypted storage instead (not yet migrated).
Check storage-spec for more details about Storage API
duplicated storage but to be used only for migrations. so that we can unlock storage but other parts of app still can't access it.
Storage instance used unquely by wallet module to store seed and autogenerated passphrase (if present).
Check storage-spec for more details about Storage API
> Note: Because Browser Extension needs the passphrase to encrypt/decrypt seed, it get's passed as a 3rd parameter to get/set
An instance of the PassphraseCache class.
| Method | Type | Description |
| ------------- | ------------------------------ | ------------------------------------------------------------ |
| set | (passphrase: string) => void | Set the passphrase with the given value. |() => string
| get | | Get the current passphrase value. |(ttl: number) => void
| changeTtl | | Change the time-to-live (TTL) value of the passphrase cache. |() => void
| clear | | Clear the passphrase cache. |() => void
| scheduleClear | | |
An object with additional configuration options for the Exodus instance.
Currently not used.
Some features expose APIs for easy debugging, troubleshooting, and PR testing. You can access these APIs under exodus.debug. To enable them, simply pass debug: true to the headless factory function:
`js
import createExodus from '@exodus/headless'
const exodusContainer = createExodus({ port, adapters, config, debug: true })
exodusContainer.debug.geolocation.merge({ countryCode: 'US' })
`
> Type: object
| Method | Type | Description |
| ------------------------ | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| exists | async () => boolean | Checks if a wallet exists on the device. |async ({ passphrase?: string }) => void
| create | | Creates new wallet |async ({ mnemonic: string, passphrase?: string, forceRestart?: boolean }) => void
| import | | Imports existing wallet |async ({ passphrase?: string }) => void
| delete | | Deletes wallet. Passphrase is mandatory if wallet was created with one |async () => void
| lock | | Locks wallet |async ({ passphrase?: string }) => void
| unlock | | Unlocks wallet. Passphrase is mandatory if wallet was created with one |async () => boolean
| isLocked | | Checks if wallet is locked |async () => void
| getMnemonic | | Sets wallet as backed up |async ({ currentPassphrase?: string. newPassphrase: string }) => void
| changePassphrase | | Change passphrase. Current passphrase is mandatory if wallet was created with one |async ({ passphrase?: string }) => void
| restoreFromCurrentPhrase | | Restore current wallet. Passphrase is mandatory if wallet was created with one |async () => void
| load | | Loads UI by rehydratating data through port (BE Only) |async () => void
| unload | | Unloads UI by rehydratating data through port (BE Only) |async ({ ttl: number }) => void
| changeLockTimer | | Change auto unlock ttl (BE Only) |
> Type: object
| Method | Type | Description |
| ---------- | ------------------------------------------- | -------------------------------------------------------------- |
| create | async (walletAccountFields) => void | Creates a new WalletAccount with the provided fields. |async (name, walletAccountFields) => void
| update | | Updates an existing WalletAccount with the provided fields. |async (name) => void
| enable | | Enables an existing WalletAccount. |async (name) => void
| disable | | Disables an existing WalletAccount. |async () => object
| getEnabled | | Returns enabled walletAccounts as { [name]: WalletAccount }. |
> Type: object
| Method | Type | Description |
| ---------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| getTxLog | async ({ assetName, walletAccount }) => TxSet | Get the TxSet for the provided assetName/walletAccount combination (AssetSource) |async () => object
| getLoadedTxLogs | | Get the all loaded TxSets as a { [walletAccount]: { [assetName]: TxSet } } object |async ({ assetName: string, walletAccount: string, txs: object[] }) => void
| updateTxs | | Add or update txs with updates provided in txs |async ({ assetName: string, walletAccount: string, txs: object[], notifyReceivedTxs: ?boolean }) => void
| overwriteTxs | | Overwrite specified txs. |async ({ assetName: string, walletAccount: string }) => void
| clearTxs | | Remove txs for AssetSource. |async ({ assetName: string, walletAccount: string, txs: object[] }) => void
| removeTxs | | Remove provided txs. |async ({ assetName, walletAccount }) => AccountState
| getAccountState | | Get the AccountState for the provided AssetSource |async () => object
| getLoadedAccountStates | | Get the all loaded AccountStates as a { [walletAccount]: { [assetName]: AccountState } } object |async ({ assetName: string, walletAccount: string, newData: object }) => void
| updateAccountState | | Update accountState for AssetSource. |async ({ assetName: string, walletAccount: string }) => void
| removeAccountState | | Remove accountState for AssetSource. |() => Batch
| batch | | Create a batch of updates. See blockchainMetadata README for batching details. |
> Type: object
| Method | Type | Description |
| ----------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------- |
| enable | async (assetNames: string[]) => void | Enables assets. |async (assetNames: string[]) => void
| disable | | Disables assets. |async (assetId: string, baseAssetName: string) => string
| addAndEnableToken | | Adds and enables a custom token. Returns the created asset's .name |
> Type: object
| Method | Type | Description |
| ----------- | ---------------------------------- | ------------------------- |
| setCurrency | async (currency: string) => void | Changes current currency. |async (language: string) => void
| setLanguage | | Changes current language. |
> Type: function
| Argument | Type | Description |
| ----------- | ------------------------------------------ | ------------------------------------------ |
| subscribe | ({ type: string, payload: any }) => void | Subscribe to receive events. |({ type: string, payload: any }) => void
| unsubscribe | | Unsubscribe handler from receiving events. |
> Type: object
| Method | Type | Description |
| ------- | ------------------------------------- | -------------------------------------- |
| enable | async (featureName: string) => void | Enables a feature-flag gated feature. |async (featureName: string) => void` | Disables a feature-flag gated feature. |
| disable |
See more details.