Class BSV::Overlay::AdminTokenTemplate ¶
Inherits: Object
Script template for creating, unlocking, and decoding SHIP and SLAP advertisements.
SHIP (Service Host Interconnect) and SLAP (Service Lookup Availability) tokens are PushDrop scripts containing four data fields:
Field 0: protocol string — 'SHIP' or 'SLAP'
Field 1: identity key — 33-byte compressed public key (binary)
Field 2: domain — UTF-8 string
Field 3: topic or service name — UTF-8 string
The locking script includes a fifth field containing a wallet signature over the concatenation of fields 0–3, which authenticates the token at creation time. The lock is secured with a P2PK condition derived from the wallet using BRC-42/43 key derivation at security level 2.
Script layout (lock-after PushDrop format):
<protocol> <identity_key> <domain> <topic> <wallet_sig>
OP_2DROP OP_2DROP OP_DROP
<derived_pubkey> OP_CHECKSIG
@example Lock a SHIP advertisement
wallet = BSV::Wallet::Client.new(private_key, storage: BSV::Wallet::Store::Memory.new)
template = BSV::Overlay::AdminTokenTemplate.new(wallet)
locking_script = template.lock('SHIP', 'myhost.example.com', 'tm_payments')
decoded = BSV::Overlay::AdminTokenTemplate.decode(locking_script)
decoded.identity_key # => hex public key of the wallet
Constants¶
VALID_PROTOCOLS ¶
Not documented.
Public Class Methods¶
decode(script) ¶
Decode a SHIP or SLAP advertisement from a PushDrop locking script. - @param script [BSV::Script::Script, nil] the locking script to decode - @raise [BSV::Overlay::OverlayError] if the script is PushDrop but has fewer than 4 fields, or if the protocol field is not 'SHIP' or 'SLAP' - @return [Advertisement, nil] the decoded advertisement, or +nil+ if the script is nil, empty, or not a PushDrop script
Public Instance Methods¶
initialize(wallet, originator: = nil) ¶
Construct a new AdminTokenTemplate instance. - @param wallet [#get_public_key, #create_signature] any object implementing the BRC-100 wallet interface (e.g. {BSV::Wallet::Client}) - @param originator [String, nil] optional FQDN of the originating application - @return [AdminTokenTemplate] a new instance of AdminTokenTemplate
lock(protocol, domain, topic_or_service) ¶
Create a SHIP or SLAP advertisement locking script.
Derives the wallet's identity key, builds the four advertisement fields, signs them with the protocol-derived key, and constructs a PushDrop locking script with a P2PK spending condition. - @param protocol [String] 'SHIP' or 'SLAP' - @param domain [String] domain where the service or topic is available - @param topic_or_service [String] topic or service name to advertise - @raise [BSV::Overlay::OverlayError] if protocol is not 'SHIP' or 'SLAP' - @return [BSV::Script::Script] the locking script
unlock(protocol) ¶
Return an unlocker for spending an advertisement token.
The returned object follows the {BSV::Transaction::UnlockingScriptTemplate} interface and can be assigned to an input's unlocking_script_template. - @param protocol [String] 'SHIP' or 'SLAP' — must match the locked token - @raise [BSV::Overlay::OverlayError] if protocol is not 'SHIP' or 'SLAP' - @return [Unlocker] an object with +#sign+ and +#estimated_length+