4a: Exotic Bases

++po

Phonetic base

Container core for providing phonetic syllables and name generators for the Urbit naming system. The two faces, sis and dex, are available to the contained arms.

Source

~/ %po
=+ :- ^= sis :: prefix syllables
'dozmarbinwansamlitsighidfidlissogdirwacsabwissib\
/rigsoldopmodfoglidhopdardorlorhodfolrintogsilmir\
/holpaslacrovlivdalsatlibtabhanticpidtorbolfosdot\
/losdilforpilramtirwintadbicdifrocwidbisdasmidlop\
/rilnardapmolsanlocnovsitnidtipsicropwitnatpanmin\
/ritpodmottamtolsavposnapnopsomfinfonbanmorworsip\
/ronnorbotwicsocwatdolmagpicdavbidbaltimtasmallig\
/sivtagpadsaldivdactansidfabtarmonranniswolmispal\
/lasdismaprabtobrollatlonnodnavfignomnibpagsopral\
/bilhaddocridmocpacravripfaltodtiltinhapmicfanpat\
/taclabmogsimsonpinlomrictapfirhasbosbatpochactid\
/havsaplindibhosdabbitbarracparloddosbortochilmac\
/tomdigfilfasmithobharmighinradmashalraglagfadtop\
/mophabnilnosmilfopfamdatnoldinhatnacrisfotribhoc\
/nimlarfitwalrapsarnalmoslandondanladdovrivbacpol\
/laptalpitnambonrostonfodponsovnocsorlavmatmipfip'
^= dex :: suffix syllables
'zodnecbudwessevpersutletfulpensytdurwepserwylsun\
/rypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnex\
/lunmeplutseppesdelsulpedtemledtulmetwenbynhexfeb\
/pyldulhetmevruttylwydtepbesdexsefwycburderneppur\
/rysrebdennutsubpetrulsynregtydsupsemwynrecmegnet\
/secmulnymtevwebsummutnyxrextebfushepbenmuswyxsym\
/selrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpel\
/syptermebsetdutdegtexsurfeltudnuxruxrenwytnubmed\
/lytdusnebrumtynseglyxpunresredfunrevrefmectedrus\
/bexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermer\
/tenlusnussyltecmexpubrymtucfyllepdebbermughuttun\
/bylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmyl\
/wedducfurfexnulluclennerlexrupnedlecrydlydfenwel\
/nydhusrelrudneshesfetdesretdunlernyrsebhulryllud\
/remlysfynwerrycsugnysnyllyndyndemluxfedsedbecmun\
/lyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes'
|%

++ind:po

Parse suffix

Produces the byte of the right-hand syllable a.

Accepts

a is a @tas.

Produces

A (unit @).

Source

++ ind ~/ %ind
|= a=@tas
=+ b=0
|- ^- (unit @)
?:(=(256 b) ~ ?:(=(a (tod b)) [~ b] $(b +(b))))

Examples

> (ind:po %zod)
[~ 0]
> (ind:po %foo)
~
> (ind:po %wet)
[~ 101]

++ins:po

Parse prefix

Produces the byte of the left-hand phonetic syllable a.

Accepts

a is a @tas.

Produces

A (unit @).

Source

++ ins ~/ %ins
|= a=@tas
=+ b=0
|- ^- (unit @)
?:(=(256 b) ~ ?:(=(a (tos b)) [~ b] $(b +(b))))

Examples

> (ins:po %doz)
[~ 0]
> (ins:po %foo)
~
> (ins:po %pit)
[~ 242]

++tod:po

Fetch suffix

Produces the phonetic suffix syllable from index a within dex as an atom.

Accepts

a is an atom

Produces

An atom.

Source

++ tod ~/ %tod
|=(a=@ ?>((lth a 256) (cut 3 [(mul 3 a) 3] dex)))

Examples

> `@t`(tod:po 0)
'zod'
> `@t`(tod:po 100)
'syr'
> `@t`(tod:po 255)
'fes'
> `@t`(tod:po 256)
dojo: hoon expression failed

++tos:po

Fetch prefix

Produces the phonetic prefix syllable from index a within sis as an atom.

Accepts

a is an atom.

Produces

An atom.

Source

++ tos ~/ %tos
|=(a=@ ?>((lth a 256) (cut 3 [(mul 3 a) 3] sis)))

Examples

> `@t`(tos:po 0)
'doz'
> `@t`(tos:po 100)
'soc'
> `@t`(tos:po 255)
'fip'
> `@t`(tos:po 256)
dojo: hoon expression failed

++fa

base58check

Container core for base58check (e.g. bitcoin address) functions.

Source

++ fa
=+ key='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
=/ yek=@ux ~+
=- yek:(roll (rip 3 key) -)
=+ [a=*char b=*@ yek=`@ux`(fil 3 256 0xff)]
|.
[+(b) (mix yek (lsh [3 `@u`a] (~(inv fe 3) b)))]
|%

++cha:fa

Decode base58check character

Check whether character a is valid in base58check encoding, producing a unit of its decoded value if it's valid, and a null unit if it's not.

Accepts

a is a char.

Produces

A (unit @uF).

Source

++ cha |=(a=char `(unit @uF)`=+(b=(cut 3 [`@`a 1] yek) ?:(=(b 0xff) ~ `b)))

Examples

> (cha:fa 'Z')
[~ 32]
> (cha:fa 'n')
[~ 45]
> (cha:fa 'l')
~

++tok:fa

Compute base58check checksum

Compute the base58check checksum of a.

Accepts

a is a @ux.

Produces

A @ux.

Source

++ tok
|= a=@ux ^- @ux
=+ b=(pad a)
=- (~(net fe 5) (end [3 4] (shay 32 -)))
(shay (add b (met 3 a)) (lsh [3 b] (swp 3 a)))

Examples

> (tok:fa 0xdead.beef)
0x938b.8b0c

++pad:fa

base58check padding bytes

Compute the number of bytes of 0s needed to pad a to 21 bytes, if it's less than 21 bytes.

Accepts

a is a @ - a value without its base58check checksum.

Produces

A @.

Source

++ pad |=(a=@ =+(b=(met 3 a) ?:((gte b 21) 0 (sub 21 b))))

Examples

> (pad:fa 0xdead.beef)
17

++enc:fa

encode base58check

Compute and append checksum to a.

Accepts

a is a @ux.

Produces

A @ux.

Source

++ enc |=(a=@ux `@ux`(mix (lsh [3 4] a) (tok a)))

Example

> (enc:fa 0xdead.beef)
0xdead.beef.938b.8b0c

++den:fa

decode base58check

Check checksum of a, return a unit of a sans the checksum if successful, or a null unit otherwise.

Accepts

a is a @ux

Produces

A (unit @ux).

Source

++ den
|= a=@ux ^- (unit @ux)
=+ b=(rsh [3 4] a)
?. =((tok b) (end [3 4] a))
~
`b

Examples

> (den:fa 0xdead.beef.938b.8b0c)
[~ 0xdead.beef]
> (den:fa 0xdead.beef.1111.1111)
~

Edit this page on GitHub

Last modified October 8, 2023