Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
An implementation of address discovery for the random address scheme as used by the legacy Cardano wallets.
Synopsis
-
data
RndState
(network ::
NetworkDiscriminant
) =
RndState
{
- hdPassphrase :: Passphrase "addr-derivation-payload"
- accountIndex :: Index ' Hardened ' AccountK
- discoveredAddresses :: Map DerivationPath ( Address , AddressState )
- pendingAddresses :: Map DerivationPath Address
- gen :: StdGen
- class RndStateLike s
- mkRndState :: ByronKey ' RootK XPrv -> Int -> RndState n
- type DerivationPath = ( Index ' WholeDomain ' AccountK , Index ' WholeDomain ' AddressK )
- toDerivationIndexes :: DerivationPath -> NonEmpty DerivationIndex
- importAddress :: RndStateLike s => Address -> s -> Either ErrImportAddress s
- newtype ErrImportAddress = ErrAddrDoesNotBelong Address
- addPendingAddress :: RndStateLike s => Address -> DerivationPath -> s -> s
- deriveRndStateAddress :: forall n. PaymentAddress n ByronKey => ByronKey ' RootK XPrv -> Passphrase "encryption" -> DerivationPath -> Address
- findUnusedPath :: StdGen -> Index ' Hardened ' AccountK -> Set DerivationPath -> ( DerivationPath , StdGen )
- unavailablePaths :: RndStateLike s => s -> Set DerivationPath
- defaultAccountIndex :: RndStateLike s => s -> Index ' Hardened ' AccountK
- withRNG :: RndStateLike s => s -> ( StdGen -> (a, StdGen )) -> (a, s)
-
newtype
RndAnyState
(network ::
NetworkDiscriminant
) (p ::
Nat
) =
RndAnyState
{
- innerState :: RndState network
- mkRndAnyState :: forall (p :: Nat ) n. ByronKey ' RootK XPrv -> Int -> RndAnyState n p
State
data RndState (network :: NetworkDiscriminant ) Source #
HD random address discovery state and key material for AD.
RndState | |
|
Instances
class RndStateLike s Source #
Instances
mkRndState :: ByronKey ' RootK XPrv -> Int -> RndState n Source #
Initialize the HD random address discovery state from a root key and RNG seed.
type DerivationPath = ( Index ' WholeDomain ' AccountK , Index ' WholeDomain ' AddressK ) Source #
Shortcut type alias for HD random address derivation path.
Low-level API
importAddress :: RndStateLike s => Address -> s -> Either ErrImportAddress s Source #
newtype ErrImportAddress Source #
Instances
Eq ErrImportAddress Source # | |
Defined in Cardano.Wallet.Primitive.AddressDiscovery.Random (==) :: ErrImportAddress -> ErrImportAddress -> Bool Source # (/=) :: ErrImportAddress -> ErrImportAddress -> Bool Source # |
|
Show ErrImportAddress Source # | |
|
|
Generic ErrImportAddress Source # | |
Defined in Cardano.Wallet.Primitive.AddressDiscovery.Random from :: ErrImportAddress -> Rep ErrImportAddress x Source # to :: Rep ErrImportAddress x -> ErrImportAddress Source # |
|
type Rep ErrImportAddress Source # | |
Defined in Cardano.Wallet.Primitive.AddressDiscovery.Random
type
Rep
ErrImportAddress
=
D1
('
MetaData
"ErrImportAddress" "Cardano.Wallet.Primitive.AddressDiscovery.Random" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" '
True
) (
C1
('
MetaCons
"ErrAddrDoesNotBelong" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
Address
)))
|
addPendingAddress :: RndStateLike s => Address -> DerivationPath -> s -> s Source #
deriveRndStateAddress :: forall n. PaymentAddress n ByronKey => ByronKey ' RootK XPrv -> Passphrase "encryption" -> DerivationPath -> Address Source #
Use the key material in
RndState
to derive a change address.
findUnusedPath :: StdGen -> Index ' Hardened ' AccountK -> Set DerivationPath -> ( DerivationPath , StdGen ) Source #
Randomly generates an address derivation path for a given account. If the path is already in the "blacklist", it will try generating another.
Note that performance of this function will degrade poorly as more of the account's address space is used up. We may have to improve it later.
unavailablePaths :: RndStateLike s => s -> Set DerivationPath Source #
Returns the set of derivation paths that should not be used for new address generation because they are already in use.
defaultAccountIndex :: RndStateLike s => s -> Index ' Hardened ' AccountK Source #
Default account used for generating new derivation paths.
withRNG :: RndStateLike s => s -> ( StdGen -> (a, StdGen )) -> (a, s) Source #
Default random number generator.
Benchmarking
newtype RndAnyState (network :: NetworkDiscriminant ) (p :: Nat ) Source #
An "unsound" alternative that can be used for benchmarking and stress
testing. It re-uses the same underlying structure as the
RndState
but
it discover addresses based on an arbitrary ratio instead of decrypting the
derivation path.
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.
RndAnyState | |
|
Instances
mkRndAnyState :: forall (p :: Nat ) n. ByronKey ' RootK XPrv -> Int -> RndAnyState n 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%.