# Module BSV::Wallet::Migration <a id="module-BSV-Wallet-Migration"></a>

Migration-time wallet context.

The per-wallet <code>outputs.spendable_recoverable</code> CHECK (HLR #467)
embeds the WIF-derived root P2PKH script as a binary literal — the constraint
has to know the wallet's identity at +CREATE TABLE+ time. Sequel migrations
don't take parameters, so this module exposes a global accessor that
+Store#migrate!+ populates before the migrator runs and resets in its `ensure`
block.

The literal is built via +BSV::Script::Script.p2pkh_lock(hash).to_binary+
(single source of truth, SDK). Never hand-roll the +x76xa9x14...x88xac+ byte
sequence.

Lifecycle (per wallet boot):

    1. CLI constructs +KeyDeriver+ → has +identity_pubkey_hash+.
    2. CLI constructs +Store.new(identity_pubkey_hash: kd.identity_pubkey_hash, ...)+.
    3. +Store#migrate!+ stashes the hash on +Migration.identity_pubkey_hash+,
       runs +Sequel::Migrator+ (CHECK expressions read +expected_root_script+),
       and nils the accessor in its +ensure+.

See <code>docs/reference/intent-and-outcomes.md</code> and HLR #467 for the
principle (intent stated explicitly; outcomes persisted as rows).

## Attributes
### `identity_pubkey_hash` [RW] <a id="attribute-c-identity_pubkey_hash"></a> <a id="identity_pubkey_hash-class_method"></a>
Returns the value of attribute identity_pubkey_hash.

## Public Class Methods
### `expected_root_script()` <a id="method-c-expected_root_script"></a> <a id="expected_root_script-class_method"></a>
The wallet's root P2PKH locking script bytes, derived from the currently-set
`identity_pubkey_hash`. Raises if no hash is set —the migrator must populate
the global before invoking any migration that reads this helper. Callers like
+Store#migrate!+ for a fresh wallet DB MUST pass
<code>identity_pubkey_hash:</code> at <code>Store.new</code>; daemon-style
callers that boot against an already-migrated DB don't invoke this path (the
migrator is a no-op when there are no pending migrations).
- **@raise** [BSV::Wallet::SchemaIntegrityError] when
+identity_pubkey_hash+ is unset
- **@return** [String] 25-byte binary P2PKH locking script
