cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Description

An implementation of address discovery for the sequential address derivation scheme specified in BIP-0044.

The management of _accounts_ is left-out for this implementation focuses on a single account. In practice, one wants to manage a set of pools, one per account.

Synopsis

Sequential Derivation

Address Pool Gap

data AddressPoolGap Source #

Maximum number of consecutive undiscovered addresses allowed

Instances

Instances details
Bounded AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Enum AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Eq AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Ord AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Show AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Generic AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

NFData AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

PersistFieldSql AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

PersistField AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

ToText AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

FromText AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

SymbolToField "seqStateExternalGap" SeqState AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "seqStateInternalGap" SeqState AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "sharedStateScriptGap" SharedState AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

ToJSON ( ApiT AddressPoolGap ) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

FromJSON ( ApiT AddressPoolGap ) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

type Rep AddressPoolGap Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

type Rep AddressPoolGap = D1 (' MetaData "AddressPoolGap" "Cardano.Wallet.Primitive.AddressDiscovery.Sequential" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "AddressPoolGap" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getAddressPoolGap") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Word32 )))

mkUnboundedAddressPoolGap :: Word32 -> AddressPoolGap Source #

Constructor which allows by-passing the address pool gap boundary limitations. A practical use-case for this are sequential wallets for which we don't have access to the whole history which therefore require using arbitrary big gaps in order to discover addresses with indexes separated by possible huge gaps.

This defies a bit the purpose of this type though.

Address Pool

newtype SeqAddressPool (c :: Role ) (key :: Depth -> Type -> Type ) Source #

An address pool which keeps track of sequential addresses. To create a new pool, see newSeqAddressPool .

Instances

Instances details
Show ( SeqAddressPool c key) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Generic ( SeqAddressPool c key) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Associated Types

type Rep ( SeqAddressPool c key) :: Type -> Type Source #

NFData ( SeqAddressPool c k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Buildable ( SeqAddressPool c k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

type Rep ( SeqAddressPool c key) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

type Rep ( SeqAddressPool c key) = D1 (' MetaData "SeqAddressPool" "Cardano.Wallet.Primitive.AddressDiscovery.Sequential" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "SeqAddressPool" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getPool") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Pool ( KeyFingerprint "payment" key) ( Index ' Soft ' AddressK )))))

newSeqAddressPool :: forall (n :: NetworkDiscriminant ) c key. (SupportsDiscovery n key, Typeable c) => key ' AccountK XPub -> AddressPoolGap -> SeqAddressPool c key Source #

Create a new Address pool from a list of addresses. Note that, the list is expected to be ordered in sequence (first indexes, first in the list).

State

data SeqState (n :: NetworkDiscriminant ) k Source #

A state to keep track of sequential addresses as described in BIP-44

Internally, the state keeps track of a few things for us and is it is parameterized by a type n which captures a particular network discrimination. This enables the state to be agnostic to the underlying address format.

Constructors

SeqState

Fields

Instances

Instances details
Eq ( SeqState n k) => Eq ( Prologue ( SeqState n k)) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

Eq ( SeqState n k) => Eq ( Discoveries ( SeqState n k)) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

Buildable ( Prologue ( SeqState n k)) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

KnownDiscovery ( SeqState network key :: Type ) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

( Eq (k ' AccountK XPub ), Eq (k ' AddressK XPub ), Eq (k ' PolicyK XPub ), Eq ( KeyFingerprint "payment" k)) => Eq ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

( Show (k ' AccountK XPub ), Show (k ' AddressK XPub ), Show (k ' PolicyK XPub ), Show ( KeyFingerprint "payment" k)) => Show ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Generic ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Associated Types

type Rep ( SeqState n k) :: Type -> Type Source #

( NFData (k ' AccountK XPub ), NFData (k ' AddressK XPub ), NFData (k ' PolicyK XPub ), NFData ( KeyFingerprint "payment" k)) => NFData ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Methods

rnf :: SeqState n k -> () Source #

Buildable ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

DelegationAddress n ShelleyKey => MaybeLight ( SeqState n ShelleyKey ) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation.Shelley

PaymentAddress n IcarusKey => MaybeLight ( SeqState n IcarusKey ) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation.Icarus

PaymentAddress n k => KnownAddresses ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

SupportsDiscovery n k => CompareDiscovery ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

SoftDerivation k => GenChange ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Associated Types

type ArgGenChange ( SeqState n k) Source #

((key == SharedKey ) ~ ' False , Eq ( SeqState n key)) => AddressBookIso ( SeqState n key) Source #

Isomorphism for sequential address book.

Instance details

Defined in Cardano.Wallet.Address.Book

( PersistPublicKey (key ' AccountK ), PersistPublicKey (key ' AddressK ), PersistPublicKey (key ' PolicyK ), MkKeyFingerprint key ( Proxy n, key ' AddressK XPub ), PaymentAddress n key, SoftDerivation key, Typeable n, (key == SharedKey ) ~ ' False , Eq ( SeqState n key)) => PersistAddressBook ( SeqState n key) Source #
Instance details

Defined in Cardano.Wallet.DB.Store.Checkpoints

GetAccount ( SeqState n k) k Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

( IsOurs ( SeqState n k) Address , SupportsDiscovery n k, AddressIndexDerivationType k ~ ' Soft ) => IsOwned ( SeqState n k) k Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

SupportsDiscovery n k => IsOurs ( SeqState n k) Address Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

IsOurs ( SeqState n ShelleyKey ) RewardAccount Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation.Shelley

IsOurs ( SeqState n IcarusKey ) RewardAccount Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation.Icarus

type Rep ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

type ArgGenChange ( SeqState n k) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

data Prologue ( SeqState n key) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

data Discoveries ( SeqState n key) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

newtype DerivationPrefix Source #

Each SeqState is like a bucket of addresses associated with an account . An account corresponds to a subset of an HD tree as defined in BIP-0039.

cardano-wallet implements two similar HD schemes on top of BIP-0039 that are:

  • BIP-0044 (for so-called Icarus wallets)
  • CIP-1815 (for so-called Shelley and Jormungandr wallets)

Both scheme works by considering 5 levels of derivation from an initial root key (see also Depth from Cardano.Wallet.Primitive.AddressDerivation). A SeqState keeps track of indexes from the two last levels of a derivation branch. The DerivationPrefix defines the first three indexes chosen for this particular SeqState .

Instances

Instances details
Eq DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

Ord DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

Show DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

Generic DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

NFData DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

PersistFieldSql DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

PersistField DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

ToText DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

FromText DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

SymbolToField "seqStateDerivationPrefix" SeqState DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "sharedStateDerivationPrefix" SharedState DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

type Rep DerivationPrefix Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDerivation

type Rep DerivationPrefix = D1 (' MetaData "DerivationPrefix" "Cardano.Wallet.Primitive.AddressDerivation" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "DerivationPrefix" ' PrefixI ' False ) ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Index ' Hardened ' PurposeK , Index ' Hardened ' CoinTypeK , Index ' Hardened ' AccountK ))))

purposeBIP44 :: Index ' Hardened ' PurposeK Source #

Purpose is a constant set to 44' (or 0x8000002C) following the original BIP-44 specification.

It indicates that the subtree of this node is used according to this specification.

Hardened derivation is used at this level.

purposeCIP1852 :: Index ' Hardened ' PurposeK Source #

Purpose is a constant set to 1852' (or 0x8000073c) following the BIP-44 extension for Cardano:

https://github.com/input-output-hk/implementation-decisions/blob/e2d1bed5e617f0907bc5e12cf1c3f3302a4a7c42/text/1852-hd-chimeric.md

It indicates that the subtree of this node is used according to this specification.

Hardened derivation is used at this level.

coinTypeAda :: Index ' Hardened ' CoinTypeK Source #

One master node (seed) can be used for unlimited number of independent cryptocoins such as Bitcoin, Litecoin or Namecoin. However, sharing the same space for various cryptocoins has some disadvantages.

This level creates a separate subtree for every cryptocoin, avoiding reusing addresses across cryptocoins and improving privacy issues.

Coin type is a constant, set for each cryptocoin. For Cardano this constant is set to 1815' (or 0x80000717). 1815 is the birthyear of our beloved Ada Lovelace.

Hardened derivation is used at this level.

mkSeqStateFromRootXPrv :: forall n k. ( WalletKey k, SupportsDiscovery n k, (k == SharedKey ) ~ ' False ) => (k ' RootK XPrv , Passphrase "encryption") -> Index ' Hardened ' PurposeK -> AddressPoolGap -> SeqState n k Source #

Construct a Sequential state for a wallet from root private key and password.

mkSeqStateFromAccountXPub :: forall (n :: NetworkDiscriminant ) k. (SupportsDiscovery n k, (k == SharedKey ) ~ ' False ) => k ' AccountK XPub -> Maybe (k ' PolicyK XPub ) -> Index ' Hardened ' PurposeK -> AddressPoolGap -> SeqState n k Source #

Construct a Sequential state for a wallet from public account key.

discoverSeq :: forall n k m. ( PaymentAddress n k, Monad m) => ( Either Address RewardAccount -> m ChainEvents ) -> SeqState n k -> m ( ChainEvents , SeqState n k) Source #

Discover addresses and transactions using an efficient query addr -> m txs . Does not take RewardAccount into account.

discoverSeqWithRewards :: forall n k m. ( DelegationAddress n k, ToRewardAccount k, Monad m) => ( Either Address RewardAccount -> m ChainEvents ) -> SeqState n k -> m ( ChainEvents , SeqState n k) Source #

Discover addresses and transactions using an efficient query addr -> m txs . Does take RewardAccount into account.

Benchmarking

newtype SeqAnyState (network :: NetworkDiscriminant ) key (p :: Nat ) Source #

An "unsound" alternative that can be used for benchmarking and stress testing. It re-uses the same underlying structure as the SeqState but it discovers addresses based on an arbitrary ratio instead of respecting BIP-44 discovery.

The proportion is stored as a type-level parameter so that we don't have to alter the database schema to store it. It simply exists and depends on the caller creating the wallet to define it.

Constructors

SeqAnyState

Fields

Instances

Instances details
Eq ( SeqState n k) => Eq ( Prologue ( SeqAnyState n k p)) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

Eq ( SeqState n k) => Eq ( Discoveries ( SeqAnyState n k p)) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

( Show (k ' AccountK XPub ), Show (k ' AddressK XPub ), Show (k ' PolicyK XPub ), Show ( KeyFingerprint "payment" k)) => Show ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Generic ( SeqAnyState network key p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Associated Types

type Rep ( SeqAnyState network key p) :: Type -> Type Source #

Methods

from :: SeqAnyState network key p -> Rep ( SeqAnyState network key p) x Source #

to :: Rep ( SeqAnyState network key p) x -> SeqAnyState network key p Source #

( NFData (k ' AccountK XPub ), NFData (k ' AddressK XPub ), NFData (k ' PolicyK XPub ), NFData ( KeyFingerprint "payment" k)) => NFData ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Methods

rnf :: SeqAnyState n k p -> () Source #

MaybeLight ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Methods

maybeDiscover :: Maybe (LightDiscoverTxs ( SeqAnyState n k p)) Source #

PaymentAddress n k => KnownAddresses ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

SupportsDiscovery n k => CompareDiscovery ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

SoftDerivation k => GenChange ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

Associated Types

type ArgGenChange ( SeqAnyState n k p) Source #

((key == SharedKey ) ~ ' False , Eq ( SeqState n key)) => AddressBookIso ( SeqAnyState n key p) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

( Eq ( SeqState n k), (k == SharedKey ) ~ ' False , PersistAddressBook ( SeqState n k)) => PersistAddressBook ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.DB.Store.Checkpoints

( AddressIndexDerivationType k ~ ' Soft , KnownNat p) => IsOwned ( SeqAnyState n k p) k Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

IsOurs ( SeqAnyState n k p) RewardAccount Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

KnownNat p => IsOurs ( SeqAnyState n k p) Address Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

type Rep ( SeqAnyState network key p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

type Rep ( SeqAnyState network key p) = D1 (' MetaData "SeqAnyState" "Cardano.Wallet.Primitive.AddressDiscovery.Sequential" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "SeqAnyState" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "innerState") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( SeqState network key))))
type ArgGenChange ( SeqAnyState n k p) Source #
Instance details

Defined in Cardano.Wallet.Primitive.AddressDiscovery.Sequential

data Prologue ( SeqAnyState n key p) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

data Discoveries ( SeqAnyState n key p) Source #
Instance details

Defined in Cardano.Wallet.Address.Book

mkSeqAnyState :: forall (p :: Nat ) n k. (SupportsDiscovery n k, WalletKey k, (k == SharedKey ) ~ ' False ) => (k ' RootK XPrv , Passphrase "encryption") -> Index ' Hardened ' PurposeK -> AddressPoolGap -> SeqAnyState n k p Source #

Initialize the HD random address discovery state from a root key and RNG seed.

The type parameter is expected to be a ratio of addresses we ought to simply recognize as ours. It is expressed in per-myriad, so "1" means 0.01%, "100" means 1% and 10000 means 100%.

Orphan instances