import base64
import re

FRAGMENT_DELIM_RE = re.compile(r"((?:[^;]|;;)+);?")


def parse_setup_url(url: str) -> dict:
    params = {}
    for frag in FRAGMENT_DELIM_RE.findall(url.rpartition("#")[-1]):
        k, _, v = frag.partition("!")
        params[k] = base64.b64decode(v.replace(";;", ";"))
    assert set(params.keys()) == {"sk", "p1"}
    return params
