Skip to main content

@exodus/headless

The platform-agnostic Exodus wallet SDK, including core features such as seed phrase management, transaction signing, blockchain metadata, balances and others.

Table of Contents

Quick Start

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()

Lifecycle

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.

Port

Event bus between headless wallet and client

MethodTypeDescription
subscribe({ type: string, payload: any }) => voidSubscribe to receive events.
unsubscribe({ type: string, payload: any }) => voidUnsubscribe handler from receiving events.
emit(type: string, payload: any) => voidEmit an event.

Adapters

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

AssetsModule implementation. Currently being injected as each of our clients have different implementations.

createLogger

A function that returns an instance of the Logger class with the given namespace.

ParameterTypeDescription
namespacestringThe namespace for the logger.

The returned Logger instance has the following methods:

MethodTypeDescription
trace(...args: any[]) => voidLog a message with the trace level.
debug(...args: any[]) => voidLog a message with the debug level.
log(...args: any[]) => voidLog a message with the log level.
info(...args: any[]) => voidLog a message with the info level.
warn(...args: any[]) => voidLog a message with the warn level.
error(...args: any[]) => voidLog 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.

legacyPrivToPub

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.

unsafeStorage

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

seedStorage

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

passphraseCache

An instance of the PassphraseCache class.

MethodTypeDescription
set(passphrase: string) => voidSet the passphrase with the given value.
get() => stringGet the current passphrase value.
changeTtl(ttl: number) => voidChange the time-to-live (TTL) value of the passphrase cache.
clear() => voidClear the passphrase cache.
scheduleClear() => void

Config

An object with additional configuration options for the Exodus instance.

Currently not used.

Debugging

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:

import createExodus from '@exodus/headless'

const exodusContainer = createExodus({ port, adapters, config, debug: true })

exodusContainer.debug.geolocation.merge({ countryCode: 'US' })

Headless API

wallet

Type: object

MethodTypeDescription
existsasync () => booleanChecks if a wallet exists on the device.
createasync ({ passphrase?: string }) => voidCreates new wallet
importasync ({ mnemonic: string, passphrase?: string, forceRestart?: boolean }) => voidImports existing wallet
deleteasync ({ passphrase?: string }) => voidDeletes wallet. Passphrase is mandatory if wallet was created with one
lockasync () => voidLocks wallet
unlockasync ({ passphrase?: string }) => voidUnlocks wallet. Passphrase is mandatory if wallet was created with one
isLockedasync () => booleanChecks if wallet is locked
getMnemonicasync () => voidSets wallet as backed up
changePassphraseasync ({ currentPassphrase?: string. newPassphrase: string }) => voidChange passphrase. Current passphrase is mandatory if wallet was created with one
restoreFromCurrentPhraseasync ({ passphrase?: string }) => voidRestore current wallet. Passphrase is mandatory if wallet was created with one
loadasync () => voidLoads UI by rehydratating data through port (BE Only)
unloadasync () => voidUnloads UI by rehydratating data through port (BE Only)
changeLockTimerasync ({ ttl: number }) => voidChange auto unlock ttl (BE Only)

walletAccounts

Type: object

MethodTypeDescription
createasync (walletAccountFields) => voidCreates a new WalletAccount with the provided fields.
updateasync (name, walletAccountFields) => voidUpdates an existing WalletAccount with the provided fields.
enableasync (name) => voidEnables an existing WalletAccount.
disableasync (name) => voidDisables an existing WalletAccount.
getEnabledasync () => objectReturns enabled walletAccounts as { [name]: WalletAccount }.

blockchainMetadata

Type: object

MethodTypeDescription
getTxLogasync ({ assetName, walletAccount }) => TxSetGet the TxSet for the provided assetName/walletAccount combination (AssetSource)
getLoadedTxLogsasync () => objectGet the all loaded TxSets as a { [walletAccount]: { [assetName]: TxSet } } object
updateTxsasync ({ assetName: string, walletAccount: string, txs: object[] }) => voidAdd or update txs with updates provided in txs
overwriteTxsasync ({ assetName: string, walletAccount: string, txs: object[], notifyReceivedTxs: ?boolean }) => voidOverwrite specified txs.
clearTxsasync ({ assetName: string, walletAccount: string }) => voidRemove txs for AssetSource.
removeTxsasync ({ assetName: string, walletAccount: string, txs: object[] }) => voidRemove provided txs.
getAccountStateasync ({ assetName, walletAccount }) => AccountStateGet the AccountState for the provided AssetSource
getLoadedAccountStatesasync () => objectGet the all loaded AccountStates as a { [walletAccount]: { [assetName]: AccountState } } object
updateAccountStateasync ({ assetName: string, walletAccount: string, newData: object }) => voidUpdate accountState for AssetSource.
removeAccountStateasync ({ assetName: string, walletAccount: string }) => voidRemove accountState for AssetSource.
batch() => BatchCreate a batch of updates. See blockchainMetadata README for batching details.

assets

Type: object

MethodTypeDescription
enableasync (assetNames: string[]) => voidEnables assets.
disableasync (assetNames: string[]) => voidDisables assets.
addAndEnableTokenasync (assetId: string, baseAssetName: string) => stringAdds and enables a custom token. Returns the created asset's .name

locale

Type: object

MethodTypeDescription
setCurrencyasync (currency: string) => voidChanges current currency.
setLanguageasync (language: string) => voidChanges current language.

subscribe

Type: function

ArgumentTypeDescription
subscribe({ type: string, payload: any }) => voidSubscribe to receive events.
unsubscribe({ type: string, payload: any }) => voidUnsubscribe handler from receiving events.

featureFlags

Type: object

MethodTypeDescription
enableasync (featureName: string) => voidEnables a feature-flag gated feature.
disableasync (featureName: string) => voidDisables a feature-flag gated feature.

See more details.