btc fixes

This commit is contained in:
timlucmiptev 2020-12-09 11:10:11 +02:00 committed by ixv
parent 30b185a59f
commit 8df6ac81f2

View File

@ -1,5 +1,4 @@
/- sur=btc /- sur=btc
/+ base64
^? ^?
=< [sur .] =< [sur .]
=, sur =, sur
@ -26,7 +25,7 @@
:: if there are leading 0s, lshift by their amount after flip to little endian to preserve :: if there are leading 0s, lshift by their amount after flip to little endian to preserve
=/ pad=@ (sub wid.byts (met 3 dat.byts)) =/ pad=@ (sub wid.byts (met 3 dat.byts))
=/ little-endian=@ =/ little-endian=@
(lsh 3 pad (swp 3 dat.byts)) (lsh [3 pad] (swp 3 dat.byts))
%- hash256 %- hash256
:- 32 :- 32
%+ swp 3 %+ swp 3
@ -175,7 +174,7 @@
|= psbt-base64=cord |= psbt-base64=cord
^- ^buffer ^- ^buffer
~| "Invalid PSBT" ~| "Invalid PSBT"
=+ p=(de:base64 psbt-base64) =+ p=(de:base64:mimes:html psbt-base64)
?~ p !! ?~ p !!
=/ bigend=@ux (swp 3 q.u.p) =/ bigend=@ux (swp 3 q.u.p)
(from-byts:buffer [(met 3 bigend) bigend]) (from-byts:buffer [(met 3 bigend) bigend])
@ -224,7 +223,7 @@
=/ bits=(list @) (flop (rip 0 a)) =/ bits=(list @) (flop (rip 0 a))
=/ pad=@ (sub num-bits (lent bits)) =/ pad=@ (sub num-bits (lent bits))
(weld (reap pad 0) bits) (weld (reap pad 0) bits)
:: converts from bit list to a list of atoms each with bitwidth d(est) :: +convert: list of bits to a list of atoms each with bitwidth d(est)
:: ::
++ convert ++ convert
|= [d=@ bits=(list @)] |= [d=@ bits=(list @)]
@ -234,10 +233,8 @@
=/ dest-bits (scag d ((list @) bits)) =/ dest-bits (scag d ((list @) bits))
:: left-shift the "missing" number of bits :: left-shift the "missing" number of bits
=/ num=@ =/ num=@
%: lsh 0 %+ lsh [0 (sub d (lent dest-bits))]
(sub d (lent dest-bits)) (rep 0 (flop dest-bits))
(rep 0 (flop dest-bits))
==
$(ret (snoc ret num), bits (slag d ((list @) bits))) $(ret (snoc ret num), bits (slag d ((list @) bits)))
:: Converts e.g. ~[0 0 31 31 31 31 0 0] in base32 (5 bitwidth) :: Converts e.g. ~[0 0 31 31 31 31 0 0] in base32 (5 bitwidth)
:: to ~[0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0] :: to ~[0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0]
@ -274,16 +271,16 @@
~[0x3b6a.57b2 0x2650.8e6d 0x1ea1.19fa 0x3d42.33dd 0x2a14.62b3] ~[0x3b6a.57b2 0x2650.8e6d 0x1ea1.19fa 0x3d42.33dd 0x2a14.62b3]
=/ chk=@ 1 =/ chk=@ 1
|- ?~ values chk |- ?~ values chk
=/ top (rsh 0 25 chk) =/ top (rsh [0 25] chk)
=. chk =. chk
(mix i.values (lsh 0 5 (dis chk 0x1ff.ffff))) (mix i.values (lsh [0 5] (dis chk 0x1ff.ffff)))
$(values t.values, chk (update-chk chk top gen)) $(values t.values, chk (update-chk chk top gen))
:: ::
++ update-chk ++ update-chk
|= [chk=@ top=@ gen=(list @ux)] |= [chk=@ top=@ gen=(list @ux)]
=/ is (gulf 0 4) =/ is (gulf 0 4)
|- ?~ is chk |- ?~ is chk
?: =(1 (dis 1 (rsh 0 i.is top))) ?: =(1 (dis 1 (rsh [0 i.is] top)))
$(is t.is, chk (mix chk (snag i.is gen))) $(is t.is, chk (mix chk (snag i.is gen)))
$(is t.is) $(is t.is)
-- --
@ -291,7 +288,7 @@
++ expand-hrp ++ expand-hrp
|= hrp=tape |= hrp=tape
^- (list @) ^- (list @)
=/ front (turn hrp |=(p=@tD (rsh 0 5 p))) =/ front (turn hrp |=(p=@tD (rsh [0 5] p)))
=/ back (turn hrp |=(p=@tD (dis 31 p))) =/ back (turn hrp |=(p=@tD (dis 31 p)))
(zing ~[front ~[0] back]) (zing ~[front ~[0] back])
:: ::
@ -312,7 +309,7 @@
%- polymod %- polymod
(zing ~[(expand-hrp hrp) data (reap 6 0)]) (zing ~[(expand-hrp hrp) data (reap 6 0)])
%+ turn (gulf 0 5) %+ turn (gulf 0 5)
|=(i=@ (dis 31 (rsh 0 (mul 5 (sub 5 i)) pmod))) |=(i=@ (dis 31 (rsh [0 (mul 5 (sub 5 i))] pmod)))
:: ::
++ charset-to-value ++ charset-to-value
|= c=@tD |= c=@tD