Skip to content

Class BSV::Wallet::ProtoWallet::KeyDeriver

Inherits: Object Includes: BSV::Wallet::ProtoWallet::Validators

BRC-42/43 key derivation.

Derives child keys from a root private key using BKDS (BSV Key Derivation Scheme). Supports protocol IDs, key IDs, counterparties, and security levels as defined in BRC-43.

Constants

ANYONE_BN

Not documented.

Attributes

root_key [R]

Returns the value of attribute root_key.

Public Instance Methods

derive_private_key(protocol_id, key_id, counterparty)

Derives a private key using BRC-42 key derivation. - @param protocol_id [Array] [security_level, protocol_name] - @param key_id [String] key identifier - @param counterparty [String] public key hex, 'self', or 'anyone' - @return [BSV::Primitives::PrivateKey]

derive_public_key(protocol_id, key_id, counterparty, for_self: = false)

Derives a public key using BRC-42 key derivation. - @param protocol_id [Array] [security_level, protocol_name] - @param key_id [String] key identifier - @param counterparty [String] public key hex, 'self', or 'anyone' - @param for_self [Boolean] derive from own identity rather than counterparty's - @return [BSV::Primitives::PublicKey]

derive_symmetric_key(protocol_id, key_id, counterparty)

Derives a symmetric key for encryption/HMAC operations.

Uses ECDH between the derived private and public child keys to produce a shared secret, then uses the X-coordinate as the key. - @param protocol_id [Array] [security_level, protocol_name] - @param key_id [String] key identifier - @param counterparty [String] public key hex, 'self', or 'anyone' - @return [BSV::Primitives::SymmetricKey]

identity_key()

Returns the identity public key as a hex string. - @return [String] 66-character compressed public key hex

identity_key_bytes()

Returns the identity public key as a 33-byte compressed binary string.

Pubkeys are hex-canonical in this SDK (see ADR-001 — the documented exception to binary-internal), so {#identity_key} (hex) is the default. This binary accessor exists for the rare sites that need raw bytes (e.g. feeding +BSV::Primitives::Hash#hash160+) without round-tripping hex → binary at each call. - @return [String] 33-byte compressed public key binary

initialize(root_key)

  • @param root_key [BSV::Primitives::PrivateKey, String] a private key or 'anyone'
  • @return [KeyDeriver] a new instance of KeyDeriver

reveal_counterparty_secret(counterparty)

Reveals the ECDH shared secret between this wallet and a counterparty. Used for BRC-69 Method 1 (counterparty key linkage). - @param counterparty [String] public key hex (not 'self') - @raise [InvalidParameterError] - @return [String] compressed shared secret bytes

reveal_specific_secret(counterparty, protocol_id, key_id)

Reveals the specific key offset for a particular derived key. Used for BRC-69 Method 2 (specific key linkage). - @param counterparty [String] public key hex - @param protocol_id [Array] [security_level, protocol_name] - @param key_id [String] key identifier - @return [String] HMAC-SHA256 bytes (the key offset)