Split Bech32 address into hrp and data.
(bech32-split-address address) → (mv erp ret-hrp data-octets)
Splits the Bech32 or Bech32m address into the human-readable portion
(
Also performs some validity checks.
There are three values returned: an error flag, the
Function:
(defun bech32-split-address (address) (declare (xargs :guard (stringp address))) (let ((__function__ 'bech32-split-address)) (declare (ignorable __function__)) (b* (((unless (<= (length address) 90)) (mv t "" nil)) (separator-1 (bech32-index-of-last-1 address)) ((unless (natp separator-1)) (mv t "" nil)) ((unless (< separator-1 (- (length address) 1))) (mv t "" nil)) (hrp (subseq address 0 separator-1)) ((unless (hrp-valid-p hrp)) (mv t "" nil)) (data-string (subseq address (+ separator-1 1) (length address))) ((unless (<= 6 (length data-string))) (mv t "" nil)) (data-chars (explode data-string)) (data-octets-or-nils (bech32-chars-to-octets data-chars)) ((unless (unsigned-byte-listp 5 data-octets-or-nils)) (mv t "" nil))) (mv nil hrp data-octets-or-nils))))
Theorem:
(defthm booleanp-of-bech32-split-address.erp (b* (((mv ?erp ?ret-hrp ?data-octets) (bech32-split-address address))) (booleanp erp)) :rule-classes :rewrite)
Theorem:
(defthm stringp-of-bech32-split-address.ret-hrp (implies (stringp address) (b* (((mv ?erp ?ret-hrp ?data-octets) (bech32-split-address address))) (stringp ret-hrp))) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-bech32-split-address.data-octets (b* (((mv ?erp ?ret-hrp ?data-octets) (bech32-split-address address))) (unsigned-byte-listp 5 data-octets)) :rule-classes :rewrite)