Exemplo n.º 1
0
def revoke(
    vcdig,
    dig,
    version=Version,
    kind=Serials.json,
):
    """

    Returns serder of rev message event
    Utility function to create a VC revocation vent

    Parameters:
        vcdig is hash digest of vc content qb64
        regk is regsitry identifier prefix qb64
        dig is digest of previous event qb64

    """

    vs = Versify(version=version, kind=kind, size=0)
    isn = 1
    ilk = Ilks.rev

    ked = dict(
        v=vs,
        i=vcdig,
        s="{:x}".format(isn),  # hex string no leading zeros lowercase
        t=ilk,
        p=dig)

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 2
0
def backer_revoke(
    vcdig,
    regk,
    regsn,
    regd,
    version=Version,
    kind=Serials.json,
):
    """

    Returns serder of brv message event
    Utility function to create a VC revocation event

    Parameters:
        vcdig is hash digest of vc content qb64
        regk is regsitry identifier prefix qb64
        regsn is int sequence number of anchoring registry TEL event
        regd is digest qb64 of anchoring registry TEL event
    """

    vs = Versify(version=version, kind=kind, size=0)
    isn = 1
    ilk = Ilks.rev

    seal = SealEvent(regk, regsn, regd)

    ked = dict(
        v=vs,
        i=vcdig,
        s="{:x}".format(isn),  # hex string no leading zeros lowercase
        t=ilk,
        ra=seal._asdict())

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 3
0
def issue(
    vcdig,
    regk,
    version=Version,
    kind=Serials.json,
):
    """

    Returns serder of iss message event
    Utility function to create a VC issuance event

    Parameters:
        vcdig is hash digest of vc content qb64
        regk is regsitry identifier prefix qb64

    """

    vs = Versify(version=version, kind=kind, size=0)
    ked = dict(
        v=vs,  # version string
        i=vcdig,  # qb64 prefix
        s="{:x}".format(0),  # hex string no leading zeros lowercase
        t=Ilks.iss,
        ri=regk)

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 4
0
def gen_nontransferable_serialized_aid():
    with openDB() as bsr:
        # Inception: Non-transferable (ephemeral) case
        signer0 = Signer(
            transferable=False)  #  original signing keypair non transferable
        assert signer0.code == CryOneDex.Ed25519_Seed
        assert signer0.verfer.code == CryOneDex.Ed25519N
        keys0 = [signer0.verfer.qb64]
        serder = incept(keys=keys0)  #  default nxt is empty so abandoned

        # Derive AID from ked
        aid0 = Prefixer(ked=serder.ked, code=CryOneDex.Ed25519N)

        # update ked with pre
        serder.ked["pre"] = aid0.qb64

        # Serialize ked0
        tser0 = Serder(ked=serder.ked)

        # sign serialization
        skp0 = Signer()  # original signing keypair transferable default
        tsig0 = skp0.sign(tser0.raw, index=0)

        # verify signature
        assert skp0.verfer.verify(tsig0.raw, tser0.raw)

        # not sure why this errors out when enabled; I guess kevers can't be used with nontransferable ids
        # kever = Kever(serder=tser0, sigers=[tsig0], baser=bsr)  # no error

        # return base 64 serialization of signed aid
        return tsig0.qb64
Exemplo n.º 5
0
    def _derive_blake3_256(self, ked):
        """
        Returns tuple (raw, code) of basic Ed25519 pre (qb64)
            as derived from inception key event dict ked
        """
        ked = dict(ked)  # make copy so don't clobber original ked
        ilk = ked["t"]
        if ilk == Ilks.vcp:
            labels = [key for key in ked if key not in self.VcpExcludes]
        else:
            raise DerivationError(
                "Invalid ilk = {} to derive pre.".format(ilk))

        # put in dummy pre to get size correct
        ked["i"] = "{}".format(self.Dummy * Matter.Codes[MtrDex.Blake3_256].fs)
        serder = Serder(ked=ked)
        ked = serder.ked  # use updated ked with valid vs element

        for l in labels:
            if l not in ked:
                raise DerivationError(
                    "Missing element = {} from ked.".format(l))

        dig = blake3.blake3(serder.raw).digest()
        return dig, MtrDex.Blake3_256
Exemplo n.º 6
0
def kever():
    # Setup inception key event dict
    salt = b'\x05\xaa\x8f-S\x9a\xe9\xfaU\x9c\x02\x9c\x9b\x08Hu'
    salter = Salter(raw=salt)
    # create current key
    sith = 1  #  one signer
    #  original signing keypair transferable default
    skp0 = salter.signer(path="A", temp=True)
    keys = [skp0.verfer.qb64]

    # create next key
    #  next signing keypair transferable is default
    skp1 = salter.signer(path="N", temp=True)
    nxtkeys = [skp1.verfer.qb64]
    # compute nxt digest
    nexter = Nexter(keys=nxtkeys)
    nxt = nexter.qb64
    assert nxt == "E_d8cX6vuQwmD5P62_b663OeaVCLbiBFsirRHJsHn9co"  # transferable so nxt is not empty

    sn = 0  #  inception event so 0
    toad = 0  # no witnesses
    nsigs = 1  #  one attached signature unspecified index

    ked0 = dict(
        v=Versify(kind=Serials.json, size=0),
        i="",  # qual base 64 prefix
        s="{:x}".format(sn),  # hex string no leading zeros lowercase
        t=Ilks.icp,
        kt="{:x}".format(sith),  # hex string no leading zeros lowercase
        k=keys,  # list of signing keys each qual Base64
        n=nxt,  # hash qual Base64
        wt="{:x}".format(toad),  # hex string no leading zeros lowercase
        w=[],  # list of qual Base64 may be empty
        c=[],  # list of config ordered mappings may be empty
    )

    # Derive AID from ked
    aid0 = Prefixer(ked=ked0, code=MtrDex.Ed25519)
    assert aid0.code == MtrDex.Ed25519
    assert aid0.qb64 == skp0.verfer.qb64 == 'DBQOqSaf6GqVAoPxb4UARrklS8kLYj3JqsR6b4AASDd4'

    # update ked with pre
    ked0["i"] = aid0.qb64

    # Serialize ked0
    tser0 = Serder(ked=ked0)

    # sign serialization
    tsig0 = skp0.sign(tser0.raw, index=0)

    # verify signature
    assert skp0.verfer.verify(tsig0.raw, tser0.raw)

    return Kever(serder=tser0, sigers=[tsig0])
Exemplo n.º 7
0
def incept(
    pre,
    baks=None,
    cnfg=None,
    version=Version,
    kind=Serials.json,
):
    """

    Returns serder of vcp message event
    Utility function to create a Registry inception event

    Parameters:
         pre is issuer identifier prefix qb64
         cnfg is list of strings TraitDex of configuration traits
         baks is the initial list of backers prefixes for VCs in the Registry

         version is the API version
         kind is the event type

    """

    vs = Versify(version=version, kind=kind, size=0)
    isn = 0
    ilk = Ilks.vcp

    cnfg = cnfg if cnfg is not None else []

    if TraitDex.NoBackers in cnfg and len(baks) > 0:
        raise ValueError("{} backers specified for NB vcp, 0 allowed".format(
            len(baks)))

    ked = dict(
        v=vs,  # version string
        i="",  # qb64 prefix
        ii=pre,
        s="{:x}".format(isn),  # hex string no leading zeros lowercase
        t=ilk,
        c=cnfg,
        b=baks  # list of qb64 may be empty
    )

    prefixer = Prefixer(ked=ked)  # Derive AID from ked and code
    ked["i"] = prefixer.qb64  # update pre element in ked with pre qb64

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 8
0
def rotate(
    pre,
    regk,
    sn=1,
    baks=None,
    version=Version,
    kind=Serials.json,
):
    """

    Returns serder of vrt message event
    Utility function to create a Registry rotation event

    Parameters:
        pre is identifier prefix qb64
        regk is regsitry identifier prefix qb64
        sn is int sequence number
        baks is new list of backers prefixes for VCs in the Registry


    """

    if sn < 1:
        raise ValueError("Invalid sn = {} for vrt.".format(sn))

    vs = Versify(version=version, kind=kind, size=0)
    ilk = Ilks.vrt

    ked = dict(
        v=vs,  # version string
        i=regk,  # qb64 prefix
        ii=pre,
        s="{:x}".format(sn),  # hex string no leading zeros lowercase
        t=ilk,
        b=baks,  # list of qb64 may be empty
    )

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 9
0
def incept(
    pre,
    toad=None,
    baks=None,
    cnfg=None,
    version=Version,
    kind=Serials.json,
    code=None,
):
    """

    Returns serder of vcp message event
    Utility function to create a Registry inception event

    Parameters:
         pre is issuer identifier prefix qb64
         cnfg is list of strings TraitDex of configuration traits
         toad is int, or str hex of backer threshold
         baks is the initial list of backers prefixes for VCs in the Registry

         version is the API version
         kind is the event type
         code is default code for Prefixer

    """

    vs = Versify(version=version, kind=kind, size=0)
    isn = 0
    ilk = Ilks.vcp

    cnfg = cnfg if cnfg is not None else []

    baks = baks if baks is not None else []
    if TraitDex.NoBackers in cnfg and len(baks) > 0:
        raise ValueError("{} backers specified for NB vcp, 0 allowed".format(
            len(baks)))

    if len(oset(baks)) != len(baks):
        raise ValueError("Invalid baks = {}, has duplicates.".format(baks))

    if isinstance(toad, str):
        toad = "{:x}".format(toad)
    elif toad is None:
        if not baks:
            toad = 0
        else:  #  compute default f and m for len(baks)
            toad = ample(len(baks))

    if baks:
        if toad < 1 or toad > len(baks):  # out of bounds toad
            raise ValueError("Invalid toad = {} for baks = {}".format(
                toad, baks))
    else:
        if toad != 0:  # invalid toad
            raise ValueError("Invalid toad = {} for baks = {}".format(
                toad, baks))

    ked = dict(
        v=vs,  # version string
        i="",  # qb64 prefix
        ii=pre,
        s="{:x}".format(isn),  # hex string no leading zeros lowercase
        t=ilk,
        c=cnfg,
        bt="{:x}".format(toad),  # hex string no leading zeros lowercase
        b=baks  # list of qb64 may be empty
    )

    prefixer = Prefixer(ked=ked, code=code,
                        allows=[MtrDex.Blake3_256
                                ])  # Derive AID from ked and code
    ked["i"] = prefixer.qb64  # update pre element in ked with pre qb64

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 10
0
def gen_serialized_aid(witnesses):
    # taken from https://github.com/decentralized-identity/keripy/blob/6b85417ce1188543493efff48f95ebabd12fb0c6/tests/core/test_eventing.py
    with openDB() as bsr:
        # Transferable case
        # Setup inception key event dict
        # create current key
        sith = 1  #  one signer
        skp0 = Signer()  #  original signing keypair transferable default
        assert skp0.code == CryOneDex.Ed25519_Seed
        assert skp0.verfer.code == CryOneDex.Ed25519
        keys = [skp0.verfer.qb64]

        # create next key
        nxtsith = 1  #  one signer
        skp1 = Signer()  #  next signing keypair transferable is default
        assert skp1.code == CryOneDex.Ed25519_Seed
        assert skp1.verfer.code == CryOneDex.Ed25519
        nxtkeys = [skp1.verfer.qb64]
        # compute nxt digest
        nexter = Nexter(sith=nxtsith, keys=nxtkeys)
        nxt = nexter.qb64  # transferable so nxt is not empty

        sn = 0  #  inception event so 0
        toad = len(witnesses)
        nsigs = 1  #  one attached signature unspecified index

        ked0 = dict(
            vs=Versify(kind=Serials.json, size=0),
            pre="",  # qual base 64 prefix
            sn="{:x}".format(sn),  # hex string no leading zeros lowercase
            ilk=Ilks.icp,
            sith="{:x}".format(sith),  # hex string no leading zeros lowercase
            keys=keys,  # list of signing keys each qual Base64
            nxt=nxt,  # hash qual Base64
            toad="{:x}".format(toad),  # hex string no leading zeros lowercase
            # I think these are always necessary for direct mode
            wits=witnesses or [],  # list of qual Base64 may be empty
            cnfg=[],  # list of config ordered mappings may be empty
        )

        # Derive AID from ked
        aid0 = Prefixer(ked=ked0, code=CryOneDex.Ed25519)
        assert aid0.code == CryOneDex.Ed25519
        assert aid0.qb64 == skp0.verfer.qb64

        # update ked with pre
        ked0["pre"] = aid0.qb64

        # Serialize ked0
        tser0 = Serder(ked=ked0)

        # sign serialization
        tsig0 = skp0.sign(tser0.raw, index=0)

        # verify signature
        assert skp0.verfer.verify(tsig0.raw, tser0.raw)

        kever = Kever(serder=tser0, sigers=[tsig0], baser=bsr)  # no error

        # return base 64 serialization of signed aid
        # return tsig0.qb64
        return tsig0, tser0, tsig0.qb64
Exemplo n.º 11
0
def test_tever_no_backers(mockHelpingNowUTC):
    # registry with no backers
    # registry with backer and receipt
    with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg(
    ) as reg:
        hab = buildHab(db, kpr)

        vcp = eventing.incept(hab.pre,
                              baks=[],
                              toad=0,
                              cnfg=["NB"],
                              code=MtrDex.Blake3_256)
        regk = vcp.pre

        # successfully anchor to a rotation event
        rseal = SealEvent(i=regk, s=vcp.ked["s"], d=vcp.diger.qb64)

        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)

        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tev = Tever(serder=vcp, seqner=seqner, diger=diger, db=db, reger=reg)

        assert tev.prefixer.qb64 == vcp.pre
        assert tev.sn == 0

        dgkey = dgKey(pre=regk, dig=vcp.dig)
        assert reg.getTvt(dgkey) == (
            b'{"v":"KERI10JSON0000ad_","i":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw",'
            b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":["NB"],"bt":"0","b":[]}'
        )

        assert reg.getAnc(dgkey) == (
            b'0AAAAAAAAAAAAAAAAAAAAAAQE-yQ6BjCaJg-u2mNuE-ycVWVTq7IZ8TuN-Ew8soLijSA'
        )
        assert reg.getTel(snKey(
            pre=regk, sn=0)) == b'ElYstqTocyQixLLz4zYCAs2unaFco_p6LqH0W01loIg4'
        assert reg.getTibs(dgkey) == []
        assert reg.getTwe(snKey(pre=regk, sn=0)) is None

        # try to rotate a backerless registry
        vrt = eventing.rotate(regk, dig=vcp.dig)
        rseal = SealEvent(regk, vrt.ked["s"], vrt.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        # should raise validation err because rotation is not supported
        with pytest.raises(ValidationError):
            tev.update(serder=vrt, seqner=seqner, diger=diger)

        vcdig = b'EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU'

        iss = eventing.issue(vcdig=vcdig.decode("utf-8"), regk=regk)

        # successfully anchor to a rotation event
        rseal = SealEvent(iss.ked["i"], iss.ked["s"], iss.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tev.update(iss, seqner=seqner, diger=diger)

        vci = nsKey([regk, vcdig])
        dgkey = dgKey(pre=vci, dig=iss.dig)
        assert bytes(reg.getTvt(dgkey)) == (
            b'{"v":"KERI10JSON0000ba_","i":"EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU",'
            b'"s":"0","t":"iss","ri":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw","dt":"'
            b'2021-01-01T00:00:00.000000+00:00"}')
        assert bytes(
            reg.getAnc(dgkey)
        ) == b'0AAAAAAAAAAAAAAAAAAAAAAwEJLLpuUKPSDIcoOAOArQBzceWc8MoShm-cDL-w81liIw'

        # revoke vc with no backers
        rev = eventing.revoke(vcdig=vcdig.decode("utf-8"),
                              regk=regk,
                              dig=iss.dig)

        # successfully anchor to a rotation event
        rseal = SealEvent(rev.ked["i"], rev.ked["s"], rev.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tev.update(rev, seqner=seqner, diger=diger)
        dgkey = dgKey(pre=vci, dig=rev.dig)
        assert bytes(reg.getTvt(dgkey)) == (
            b'{"v":"KERI10JSON0000ed_","i":"EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU",'
            b'"s":"1","t":"rev","ri":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw","p":"E'
            b'C9PffPrvyaKzsn72SWTvgyvWCJ1FbDThvJhsQ9LWo9M","dt":"2021-01-01T00:00:00.00000'
            b'0+00:00"}')
Exemplo n.º 12
0
def test_issuer(mockHelpingNowUTC):
    # help.ogler.resetLevel(level=logging.DEBUG)

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)
        # setup issuer with defaults for allowBackers, backers and estOnly
        issuer = Issuer(hab=hab, name="bob", reger=reg)
        assert issuer.incept == (
            b'{"v":"KERI10JSON0000a9_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":[],"bt":"0",'
            b'"b":[]}-GAB0AAAAAAAAAAAAAAAAAAAAAAQElQxdAkGEMsdDn_GFiYPU1eVgQ3z1MvVPEoAGP3THI3A'
        )
        assert issuer.ianchor == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"1","t":"ixn",'
            b'"p":"Eg3wsIOW3RdCqhcG4xZ4uZhTA_qTE24DoLeyjFBB8rks",'
            b'"a":[{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY","s":"0",'
            b'"d":"EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg'
            b'"}]}-AABAAVDMZ3Zfu5Vhw4vIBBbh4oh7l6XACLfOFpS7VN_Tn0vrBlZuHxktv1D9S0Q_e-YbP-PXBjiAnkupzaQ50saSfAA'
        )

        # ensure the digest in the seal from the key event matches the transacript event digest
        ser = Serder(raw=issuer.incept)
        assert ser.diger.qb64 == 'EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg'

        tevt, kevt = issuer.rotate(
            adds=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])
        assert tevt == (
            b'{"v":"KERI10JSON0000d8_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"p":"EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg","s":"1","t":"vrt","bt":"1","br":[],'
            b'"ba":["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU'
            b'"]}-GAB0AAAAAAAAAAAAAAAAAAAAAAgEf12IRHtb_gVo5ClaHHNV90b43adA0f8vRs3jeU-AstY'
        )
        assert kevt == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"2","t":"ixn",'
            b'"p":"ElQxdAkGEMsdDn_GFiYPU1eVgQ3z1MvVPEoAGP3THI3A",'
            b'"a":[{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY","s":"1",'
            b'"d":"EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqbI0"}]}-AABAAb-kk2ijQRZkVmmvWpRcyDLRZad3YOKOvev0yZq'
            b'-ay5QyW9J574kIUxOwgFbC-DUkRIKdPPHkBWZdPSjw6IT-Cg')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqbI0'

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (
            b'{"v":"KERI10JSON00012d_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
            b'vaU6Z-i0d8","ii":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"s":"0","t":"bis","ra":{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDG'
            b'eLWHb9vSY","s":1,"d":"EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqb'
            b'I0"},"dt":"2021-01-01T00:00:00.000000+00:00"}-GAB0AAAAAAAAAAAAAA'
            b'AAAAAAAAwEke0QhYPogZ-pKBMDhQj6fImswFB3HSZLVdYPvvQeBCE')
        assert kevt == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
            b'k5aMtSrMtY","s":"3","t":"ixn","p":"Ef12IRHtb_gVo5ClaHHNV90b43adA'
            b'0f8vRs3jeU-AstY","a":[{"i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULva'
            b'U6Z-i0d8","s":"0","d":"EyRQ8Yz7vkua8qIqp89_cuYt71gdc9rpE4A6aj_qc'
            b'71Q"}]}-AABAA7i4dJM3hMs9yZpUL01mzNbnai6Q6obbvChybnVNodoRiEZfrz9n'
            b'rmMFtyJcYCUbg8rnfcJfDK9O8sZOeY5yuBg')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'EyRQ8Yz7vkua8qIqp89_cuYt71gdc9rpE4A6aj_qc71Q'

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (
            b'{"v":"KERI10JSON00012c_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
            b'vaU6Z-i0d8","s":"1","t":"brv","p":"ERXlSUThZejd2a3VhOHFJcXA4OV9j'
            b'dVl0NzFnZGM5cnA","ra":{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGe'
            b'LWHb9vSY","s":1,"d":"EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqbI'
            b'0"},"dt":"2021-01-01T00:00:00.000000+00:00"}-GAB0AAAAAAAAAAAAAAA'
            b'AAAAAABAESxOEc18GkapqfM70hpcLouPFYW4WY-h7LwNQKVsNMtE')

        assert kevt == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
            b'k5aMtSrMtY","s":"4","t":"ixn","p":"Eke0QhYPogZ-pKBMDhQj6fImswFB3'
            b'HSZLVdYPvvQeBCE","a":[{"i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULva'
            b'U6Z-i0d8","s":"1","d":"Ew5r1LvoqsDUb16zlCnCgmmdOn3rpYLw1HpHtr6GM'
            b'ZW8"}]}-AABAAfqZErFN0nEdL-FnQv75UMW_8XZH60qaXsIbTY2wzIf1FB5r9OjO'
            b'M5rC0ULuGl4MK1kR3LDaP9maso9GUn-lGDQ')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'Ew5r1LvoqsDUb16zlCnCgmmdOn3rpYLw1HpHtr6GMZW8'

        with basing.openDB(name="bob") as db, keeping.openKS(
                name="bob") as kpr, viring.openReg() as reg:
            hab = buildHab(db, kpr)
            # issuer, not allowed to issue backers
            issuer = Issuer(hab=hab, name="bob", noBackers=True, reger=reg)
            ser = Serder(raw=issuer.incept)
            assert ser.pre == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
            assert ser.ked["t"] == "vcp"
            assert ser.ked["c"] == ["NB"]
            assert ser.ked["b"] == []
            assert ser.ked["bt"] == "0"

            ser = Serder(raw=issuer.ianchor)
            assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
            assert ser.ked["t"] == "ixn"
            seal = ser.ked["a"][0]
            assert seal["i"] == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
            assert seal["s"] == "0"
            assert seal["d"] == "ElYstqTocyQixLLz4zYCAs2unaFco_p6LqH0W01loIg4"

            with pytest.raises(ValueError):
                issuer.rotate(
                    adds=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])

        with basing.openDB(name="bob") as db, keeping.openKS(
                name="bob") as kpr, viring.openReg() as reg:
            hab = buildHab(db, kpr)
            issuer = Issuer(hab=hab, name="bob", noBackers=True, reger=reg)

            tevt, kevt = issuer.issue(
                vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
            ser = Serder(raw=tevt)
            assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert ser.ked[
                "ri"] == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
            assert ser.ked["t"] == "iss"

            ser = Serder(raw=kevt)
            assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
            assert ser.ked["t"] == "ixn"
            seal = ser.ked["a"][0]
            assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert seal["s"] == "0"
            assert seal["d"] == 'Ewia5uvi4RAgr3rG_YlHSNPT3DxCa-2UDZ-TldDJPDWs'

            tevt, kevt = issuer.revoke(
                vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
            ser = Serder(raw=tevt)
            assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert ser.ked["t"] == "rev"
            assert ser.ked[
                "ri"] == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"

            ser = Serder(raw=kevt)
            assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
            assert ser.ked["t"] == "ixn"
            seal = ser.ked["a"][0]
            assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert seal["s"] == "1"
            # assert seal["d"] == 'EESqpWTkUklke73mGjf6TE-ojHEJLultMlQhKddfNx6w'
            assert seal["d"] == 'E8JefMOVzgcRfzBeREhrpialRR5pQnvxThuzj9Q-E47I'

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)

        # issuer, allowed backers, initial set of backers
        issuer = Issuer(hab=hab,
                        reger=reg,
                        baks=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])
        ser = Serder(raw=issuer.incept)
        # print(ser.pre)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vcp"
        assert ser.ked["b"] == ["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"]
        assert ser.ked["bt"] == "1"

        ser = Serder(raw=issuer.ianchor)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "bis"
        seal = ser.ked["ra"]
        assert seal["i"] == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert seal["s"] == "0"

        tevt, kevt = issuer.rotate(adds=[
            "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
            "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
        ])
        vrtser = Serder(raw=tevt)
        ser = Serder(raw=tevt)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vrt"
        assert ser.ked["ba"] == [
            "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
            "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
        ]

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert seal["s"] == "1"

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "brv"
        seal = ser.ked["ra"]
        # ensure the ra seal digest matches the vrt event digest
        assert seal["d"] == vrtser.diger.qb64

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert seal["s"] == "1"

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)

        # issuer, no backers allowed, establishment events only
        issuer = Issuer(hab=hab, reger=reg, noBackers=True, estOnly=True)
        ser = Serder(raw=issuer.incept)
        assert ser.pre == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
        assert ser.ked["t"] == "vcp"
        assert ser.ked["c"] == ["NB"]
        assert ser.ked["bt"] == "0"

        ser = Serder(raw=issuer.ianchor)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        assert ser.ked["k"] == ["DKPE5eeJRzkRTMOoRGVd2m18o8fLqM2j9kaxLhV3x8AQ"]
        assert ser.ked["n"] == "ELqHYQwWR0h2vP1_cxTsutU0wKJ_NrwBVKJCgPgWGgwc"

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "iss"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "rev"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"

        with pytest.raises(ValueError):
            issuer.rotate(
                adds=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)

        # issuer, backers allowed, initial backer, establishment events only
        issuer = Issuer(hab=hab,
                        reger=reg,
                        baks=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"],
                        estOnly=True)
        ser = Serder(raw=issuer.incept)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["b"] == ["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"]
        assert ser.diger.qb64 == 'EevCI-l5dfYW63xg1bQ52ldLQa3li8FBo-znWxNEzv7E'
        ser = Serder(raw=issuer.ianchor)
        assert ser.ked["t"] == "rot"

        tevt, kevt = issuer.rotate(
            toad=3,
            adds=[
                "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
                "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
            ])
        vrtser = Serder(raw=tevt)
        ser = Serder(raw=tevt)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vrt"
        assert issuer.backers == [
            "BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU",
            "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
            "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
        ]

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "bis"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        assert vrtser.diger.qb64 == 'ECQbOOZdBxpw5RTH4VvPXDSH_o2uYdPWSoWolW5tobgA'

        # rotate to no backers
        tevt, kevt = issuer.rotate(
            toad=2, cuts=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])
        ser = Serder(raw=tevt)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vrt"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        vrtser = Serder(raw=tevt)

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "brv"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        assert vrtser.diger.qb64 == 'EnUD_KZu-dGpFSEWZOlFdQSydioYY78qIDPfzA7Fhr-Q'
    """ End Test """
Exemplo n.º 13
0
def test_issuer():
    with dbing.openDB(name="bob") as db, keeping.openKS(name="bob") as kpr:
        hab = buildHab(db, kpr)

        # setup issuer with defaults for allowBackers, backers and estOnly
        issuer = Issuer(hab=hab, name="test")
        assert issuer.incept == (b'{"v":"KERI10JSON0000a9_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkD'
                                b'GeLWHb9vSY","ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY",'
                                b'"s":"0","t":"vcp","c":[],"bt":"0","b":[]}-eABEaKJ0FoLxO1TYmyuprg'
                                b'uKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAAAAAAAAAAAAAQEoDaZfC2yqtPwKJ'
                                b'BrhAGzP20SOslMZ-eQ7hAbl3w4JP0')
        assert issuer.ianchor == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                                b'k5aMtSrMtY","s":"1","t":"ixn","p":"Eg3wsIOW3RdCqhcG4xZ4uZhTA_qTE'
                                b'24DoLeyjFBB8rks","a":["EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9'
                                b'vSY","0","EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg"]}-AABAAw'
                                b'3jupSvehfh-Ow0v_E3Er49HUvwQp0Qa0P9KYNdaf9ihtzZU0bJtrbIW1z6eMoR3B'
                                b'52SDSxw9gfMmqlZRZfaBQ')
        # ensure the digest in the seal from the key event matches the transacript event digest
        ser = Serder(raw=issuer.incept)
        assert ser.diger.qb64 == 'EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg'

        tevt, kevt = issuer.rotate(adds=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])
        assert tevt == (b'{"v":"KERI10JSON0000d8_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkD'
                        b'GeLWHb9vSY","p":"EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg","'
                        b's":"1","t":"vrt","bt":"1","br":[],"ba":["EqoNZAX5Lu8RuHzwwyn5tCZ'
                        b'Te-mDBq5zusCrRo5TDugs"]}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5'
                        b'aMtSrMtY0AAAAAAAAAAAAAAAAAAAAAAgEoDJpf8xcmVXj3chkgVpVXvFgAaHyohm'
                        b'v-Bkgjsf5yf4')
        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"2","t":"ixn","p":"EoDaZfC2yqtPwKJBrhAGzP20SOslM'
                        b'Z-eQ7hAbl3w4JP0","a":["EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9'
                        b'vSY","1","Ex1ZICku_jaiYzNIjfw1Q46T_srpyz7YJwpqS1xA9xuo"]}-AABAAG'
                        b'XF1gyvCxtP3GaL-MenYOYSAqf0_BzzyRknY6mhCohXK5cIA0CrJfkPandYmDvGxo'
                        b'63K0BPxCR3ey6PbjabkBg')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'Ex1ZICku_jaiYzNIjfw1Q46T_srpyz7YJwpqS1xA9xuo'

        tevt, kevt = issuer.issue(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (b'{"v":"KERI10JSON000105_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z-i0d8","ii":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
                        b'"s":"0","t":"bis","ra":{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDG'
                        b'eLWHb9vSY","s":1,"d":"Ex1ZICku_jaiYzNIjfw1Q46T_srpyz7YJwpqS1xA9x'
                        b'uo"}}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAA'
                        b'AAAAAAAAAAAAwEJDkcdO3kE_gFLxSZA53HsEr9DK3gI1j6qEcwsZjzcZo')
        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"3","t":"ixn","p":"EoDJpf8xcmVXj3chkgVpVXvFgAaHy'
                        b'ohmv-Bkgjsf5yf4","a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i'
                        b'0d8","0","E_RmCtCYGKOUj9-r2HbZlTOTzrViYvlthhlhZFElyjzw"]}-AABAAN'
                        b'bk_fVhHJVPZpwLA2Bmj9ZvD6T885Krwd8RJn2AGgQHVux7fsr-ZW4BXtFT7DW9Cj'
                        b'jXkxP8gBSmIQt9gHPljBA')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'E_RmCtCYGKOUj9-r2HbZlTOTzrViYvlthhlhZFElyjzw'

        tevt, kevt = issuer.revoke(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (b'{"v":"KERI10JSON000104_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z-i0d8","s":"1","t":"brv","p":"E_RmCtCYGKOUj9-r2HbZlTOTzrViY'
                        b'vlthhlhZFElyjzw","ra":{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGe'
                        b'LWHb9vSY","s":1,"d":"Ex1ZICku_jaiYzNIjfw1Q46T_srpyz7YJwpqS1xA9xu'
                        b'o"}}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAA'
                        b'AAAAAAAAAABAEUQewfkI5B3VEU1w0BPpikSBdchw52PW4MrMcgizKVpc')

        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"4","t":"ixn","p":"EJDkcdO3kE_gFLxSZA53HsEr9DK3g'
                        b'I1j6qEcwsZjzcZo","a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i'
                        b'0d8","1","Ei1-r5vju2kh44KY09nd1KzeB1mq5_a33CwlYFs0tH3c"]}-AABAA3'
                        b'3POBHT4hao0mAXiOAsji3ft-NLbGRAVJ1kh1VBu9eTddSO6mUYwZpQCDgQc2SwqS'
                        b'C7VuegB_UVHbRtQcNiLCA')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'Ei1-r5vju2kh44KY09nd1KzeB1mq5_a33CwlYFs0tH3c'

        # issuer, not allowed to issue backers
        issuer = Issuer(hab=hab, name="test", allowBackers=False)
        assert issuer.incept == (b'{"v":"KERI10JSON0000ad_","i":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEG'
                                b'I0egFyLehw","ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY",'
                                b'"s":"0","t":"vcp","c":["NB"],"bt":"0","b":[]}-eABEaKJ0FoLxO1TYmy'
                                b'uprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAAAAAAAAAAAABQEAUius1E3mN'
                                b'za_tVygjmKAd5tIz9JVAP8PTLaEHwnx7w')
        assert issuer.ianchor == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                                b'k5aMtSrMtY","s":"5","t":"ixn","p":"EUQewfkI5B3VEU1w0BPpikSBdchw5'
                                b'2PW4MrMcgizKVpc","a":["Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyL'
                                b'ehw","0","ElYstqTocyQixLLz4zYCAs2unaFco_p6LqH0W01loIg4"]}-AABAAN'
                                b'Tokkv5aZ_MPLauMFsgzASyFs5qMb4-fo7HIofmpRa-XMfDS9vccchXXZb47774Be'
                                b'YR6Nljg9m_ehk3b8NnTCg')
        with pytest.raises(ValueError):
            issuer.rotate(adds=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])

        tevt, kevt = issuer.issue(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (b'{"v":"KERI10JSON000092_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z-i0d8","s":"0","t":"iss","ri":"Ezm53Qww2LTJ1yksEL06Wtt-5D23'
                        b'QKdJEGI0egFyLehw"}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrM'
                        b'tY0AAAAAAAAAAAAAAAAAAAAABgErPUCiDOsokTzqSx3ktSFx6P6bhfWLps3PbvbY'
                        b'ZIdjMw')
        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"6","t":"ixn","p":"EAUius1E3mNza_tVygjmKAd5tIz9J'
                        b'VAP8PTLaEHwnx7w","a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i'
                        b'0d8","0","EXTVuADWAm9XOG6XKMyKRs8FO2dYPFo12rinap96BUjU"]}-AABAAf'
                        b'tQ5Ccj6aiZCVArCRlcBPhUKnO0m5q75dRgs316rxbsbEdXC3lB2AC4TWCMB0EVv5'
                        b'rzGRu6Gnw6134VpkkrPCw')


        tevt, kevt = issuer.revoke(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (b'{"v":"KERI10JSON000091_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z-i0d8","s":"1","t":"rev","p":"EXTVuADWAm9XOG6XKMyKRs8FO2dYP'
                        b'Fo12rinap96BUjU"}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMt'
                        b'Y0AAAAAAAAAAAAAAAAAAAAABwEpzwTULkTXErmB12S-vR4Ysi22kFCtqaV9_uoP2'
                        b'zBWNE')
        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"7","t":"ixn","p":"ErPUCiDOsokTzqSx3ktSFx6P6bhfW'
                        b'Lps3PbvbYZIdjMw","a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i'
                        b'0d8","1","EgaGSsEExjY_19HbFsfWjtrj_nmtYmDU23qaod0KSr2o"]}-AABAAM'
                        b'w_8vSj-GBc1dMDTeNZg1sRhqOOBIROUDXAEvY5nICWhgp1RP-XYOYaVlJpLOLN6M'
                        b'nm6JU_z3rvsq475D4WsBQ')
        # issuer, allowed backers, initial set of backers
        issuer = Issuer(hab=hab, name="test", baks=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])
        assert issuer.incept == (b'{"v":"KERI10JSON0000d7_","i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78'
                                b'p90WN3sG3I","ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY",'
                                b'"s":"0","t":"vcp","c":[],"bt":"1","b":["EqoNZAX5Lu8RuHzwwyn5tCZT'
                                b'e-mDBq5zusCrRo5TDugs"]}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5a'
                                b'MtSrMtY0AAAAAAAAAAAAAAAAAAAAACAERI1IUUGtVVKDEqLw59qPJzIIwRFVU1sN'
                                b'n__B8Z6GgXk')
        assert issuer.ianchor == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                                b'k5aMtSrMtY","s":"8","t":"ixn","p":"EpzwTULkTXErmB12S-vR4Ysi22kFC'
                                b'tqaV9_uoP2zBWNE","a":["EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p90WN3s'
                                b'G3I","0","EMMt2bfrg5ACOrCLQRuU21qWMBxDPwzIhOANvHKAGJWc"]}-AABAAZ'
                                b'Zo51JRK2aU0zppx12N584195BP-UjAtCly9_Z1dfuoUQz5yV4m_NJSt-w86t9VsH'
                                b'UMDtI20EbRtenypM3NyDw')

        tevt, kevt = issuer.issue(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (b'{"v":"KERI10JSON000105_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z-i0d8","ii":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p90WN3sG3I",'
                        b'"s":"0","t":"bis","ra":{"i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p'
                        b'90WN3sG3I","s":0,"d":"EMMt2bfrg5ACOrCLQRuU21qWMBxDPwzIhOANvHKAGJ'
                        b'Wc"}}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAA'
                        b'AAAAAAAAAAACQETPkpmuLwJY4SXHPw0kjrKG5CYTTkf-OMxTgDnBFx7_k')
        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"9","t":"ixn","p":"ERI1IUUGtVVKDEqLw59qPJzIIwRFV'
                        b'U1sNn__B8Z6GgXk","a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i'
                        b'0d8","0","Eu9JBjmUh10w5FLNORAdHuICsQ0VJ7WLoxvAA56fQr0w"]}-AABAAY'
                        b'Dm3lQah_ZQhX9wJmgHY6eWTtFozD2HLA004TIm-w2LIdqS-tw6pHSNgYQKBvNt0T'
                        b'4t2Y1pL0rsDBTGAEaw_Cg')

        tevt, kevt = issuer.rotate(adds=["EtEBUSHpJDMfzHdDt3QCtrA-iVlP-0DT03AdqeeDa7vs",
                                         "ERVZTggTUOPmLcWBESrxcI-VsB48FerF6sz2boziikcY"])
        vrtser = Serder(raw=tevt)

        assert tevt == (b'{"v":"KERI10JSON000107_","i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78'
                        b'p90WN3sG3I","p":"EMMt2bfrg5ACOrCLQRuU21qWMBxDPwzIhOANvHKAGJWc","'
                        b's":"1","t":"vrt","bt":"3","br":[],"ba":["EtEBUSHpJDMfzHdDt3QCtrA'
                        b'-iVlP-0DT03AdqeeDa7vs","ERVZTggTUOPmLcWBESrxcI-VsB48FerF6sz2bozi'
                        b'ikcY"]}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAA'
                        b'AAAAAAAAAAAAACgE58EtRRxJROE7qmMnHV6fnP8FeFTBkX8eMlZbMNDFY6w')

        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"a","t":"ixn","p":"ETPkpmuLwJY4SXHPw0kjrKG5CYTTk'
                        b'f-OMxTgDnBFx7_k","a":["EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p90WN3s'
                        b'G3I","1","EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_YhuA"]}-AABAAp'
                        b'fZ6LoLMi4L_nabHRQZgW59NT3xt6IYrZ5D4lc7gUoalP-VraZ-TIThFSJSKsZER7'
                        b'W0Ev1FD6Zn5pb1JTAgKAg')

        tevt, kevt = issuer.revoke(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (b'{"v":"KERI10JSON000104_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z-i0d8","s":"1","t":"brv","p":"Eu9JBjmUh10w5FLNORAdHuICsQ0VJ'
                        b'7WLoxvAA56fQr0w","ra":{"i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p9'
                        b'0WN3sG3I","s":1,"d":"EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_Yhu'
                        b'A"}}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAA'
                        b'AAAAAAAAAACwE71WIaYxok1t0xzC9OYyX1TYjsKG1o9LCnj_o_gsGH4M')

        assert kevt == (b'{"v":"KERI10JSON0000f9_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"b","t":"ixn","p":"E58EtRRxJROE7qmMnHV6fnP8FeFTB'
                        b'kX8eMlZbMNDFY6w","a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i'
                        b'0d8","1","E9lcc71zkJXoc5E7qcCKOjZrhsNqqenXhTJMShSVek04"]}-AABAAq'
                        b'1GKbPLjSoNJLTiAbSP6EM0j2d3IOzw9LTbGGrXw3GVT6P6P-S9y8kPdmIXszP5PB'
                        b'CDJehu8GsgvxLR2f_alCg')

        # ensure the ra seal digest matches the vrt event digest
        assert vrtser.diger.qb64 == 'EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_YhuA'

        # issuer, no backers allowed, establishment events only
        issuer = Issuer(hab=hab, name="test", allowBackers=False, estOnly=True)
        assert issuer.incept == (b'{"v":"KERI10JSON0000ad_","i":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEG'
                                b'I0egFyLehw","ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY",'
                                b'"s":"0","t":"vcp","c":["NB"],"bt":"0","b":[]}-eABEaKJ0FoLxO1TYmy'
                                b'uprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAAAAAAAAAAAADAEE4ISn-pS8v'
                                b'oter-KsYyHlMb8pxiG_Uazvjw-cNRlm8s')

        assert issuer.ianchor == (b'{"v":"KERI10JSON000183_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                                b'k5aMtSrMtY","s":"c","t":"rot","p":"E71WIaYxok1t0xzC9OYyX1TYjsKG1'
                                b'o9LCnj_o_gsGH4M","kt":"1","k":["DKPE5eeJRzkRTMOoRGVd2m18o8fLqM2j'
                                b'9kaxLhV3x8AQ"],"n":"ELqHYQwWR0h2vP1_cxTsutU0wKJ_NrwBVKJCgPgWGgwc'
                                b'","bt":"0","br":[],"ba":[],"a":["Ezm53Qww2LTJ1yksEL06Wtt-5D23QKd'
                                b'JEGI0egFyLehw","0","ElYstqTocyQixLLz4zYCAs2unaFco_p6LqH0W01loIg4'
                                b'"]}-AABAATpTzNLJAV5CLD8znuTh2w73ZwqlsrOJIXa-XK2uY7QhnFHAD16yoDma'
                                b'BhdNFEKhFhqFLWnwUVe8myYkVnh8YCQ')

        tevt, kevt = issuer.issue(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z")
        assert tevt == (b'{"v":"KERI10JSON00008d_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z","s":"0","t":"iss","ri":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJE'
                        b'GI0egFyLehw"}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AA'
                        b'AAAAAAAAAAAAAAAAAAADQEDrLbf5h3GE06g3v-Ox2fFoolQyrvKW_sTrIxtQxuZAU')
        assert kevt == (b'{"v":"KERI10JSON00017e_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"d","t":"rot","p":"EE4ISn-pS8voter-KsYyHlMb8pxiG'
                        b'_Uazvjw-cNRlm8s","kt":"1","k":["DSuhyBcPZEZLK-fcw5tzHn2N46wRCG_Z'
                        b'OoeKtWTOunRA"],"n":"EPYuj8mq_PYYsoBKkzX1kxSPGYBWaIya3slgCOyOtlqU'
                        b'","bt":"0","br":[],"ba":[],"a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH'
                        b'3ULvaU6Z","0","EnZpkCQXGps7J8hO5BbFrVG7KSaEd1J3u-mAL8-E-JoY"]}-A'
                        b'ABAANcQvSou7f1vUanuNPB0QWSsv0_NUupscqNl4sY7HijmH0eUDxiz9ryWa-UdQ'
                        b'nzHLI-gY7ITVB5JgXJMtxKkxBw')

        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'EnZpkCQXGps7J8hO5BbFrVG7KSaEd1J3u-mAL8-E-JoY'

        tevt, kevt = issuer.revoke(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z")
        assert tevt == (b'{"v":"KERI10JSON00008c_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z","s":"1","t":"rev","p":"EnZpkCQXGps7J8hO5BbFrVG7KSaEd1J3u-'
                        b'mAL8-E-JoY"}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAA'
                        b'AAAAAAAAAAAAAAAAAADgE9-23oNfUrdBvXi-x89tgF8cO6mLCW5rGdQZ-C6agszE')

        assert kevt == (b'{"v":"KERI10JSON00017e_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"e","t":"rot","p":"EDrLbf5h3GE06g3v-Ox2fFoolQyrv'
                        b'KW_sTrIxtQxuZAU","kt":"1","k":["DVcuJOOJF1IE8svqEtrSuyQjGTd2HhfA'
                        b'kt9y2QkUtFJI"],"n":"E-dapdcC6XR1KWmWDsNl4J_OxcGxNZw1Xd95JH5a34fI'
                        b'","bt":"0","br":[],"ba":[],"a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH'
                        b'3ULvaU6Z","1","EVFiCQMPCoXtMpK-yoLWIVfwifQkLSH1Dj4RtzyOCVuo"]}-A'
                        b'ABAArUM8moanrzuFmxW48V4XE06zRkvnRHmtQtxt-q8ZqDoZeU0fTvJu_qQC0Qrb'
                        b'KVfVBNQ8ajphcJDdRP82d5aWAQ')

        with pytest.raises(ValueError):
            issuer.rotate(adds=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])

        # issuer, backers allowed, initial backer, establishment events only
        issuer = Issuer(hab=hab, name="test", baks=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"], estOnly=True)
        assert issuer.incept == (b'{"v":"KERI10JSON0000d7_","i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78'
                                b'p90WN3sG3I","ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY",'
                                b'"s":"0","t":"vcp","c":[],"bt":"1","b":["EqoNZAX5Lu8RuHzwwyn5tCZT'
                                b'e-mDBq5zusCrRo5TDugs"]}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5a'
                                b'MtSrMtY0AAAAAAAAAAAAAAAAAAAAADwEvDmjSZQmSLqNzTJDq9rdDd7X-ffGPt6z'
                                b'uD2n51EFRLw')

        assert issuer.ianchor == (b'{"v":"KERI10JSON000183_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                                b'k5aMtSrMtY","s":"f","t":"rot","p":"E9-23oNfUrdBvXi-x89tgF8cO6mLC'
                                b'W5rGdQZ-C6agszE","kt":"1","k":["DT1iAhBWCkvChxNWsby2J0pJyxBIxbAt'
                                b'bLA0Ljx-Grh8"],"n":"EDs-qIrh79lTtoIz4K9q_vu7-avDc79YkNCfK49HpwQg'
                                b'","bt":"0","br":[],"ba":[],"a":["EZRowynuVBviCH0ZfUx24mkMWn-jGRB'
                                b'm78p90WN3sG3I","0","EMMt2bfrg5ACOrCLQRuU21qWMBxDPwzIhOANvHKAGJWc'
                                b'"]}-AABAAmTxyOx_38hK74779sN9vPXxcRHV49li9vt0RvAKlfuCBKG2hwWyy0P-'
                                b'9tFF_2VMvAfrWChEsjWPm9lsPeWIwBw')
        ser = Serder(raw=issuer.incept)
        assert ser.diger.qb64 == 'EMMt2bfrg5ACOrCLQRuU21qWMBxDPwzIhOANvHKAGJWc'

        tevt, kevt = issuer.rotate(adds=["EtEBUSHpJDMfzHdDt3QCtrA-iVlP-0DT03AdqeeDa7vs",
                                         "ERVZTggTUOPmLcWBESrxcI-VsB48FerF6sz2boziikcY"])
        vrtser = Serder(raw=tevt)
        assert tevt == (b'{"v":"KERI10JSON000107_","i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78'
                        b'p90WN3sG3I","p":"EMMt2bfrg5ACOrCLQRuU21qWMBxDPwzIhOANvHKAGJWc","'
                        b's":"1","t":"vrt","bt":"3","br":[],"ba":["EtEBUSHpJDMfzHdDt3QCtrA'
                        b'-iVlP-0DT03AdqeeDa7vs","ERVZTggTUOPmLcWBESrxcI-VsB48FerF6sz2bozi'
                        b'ikcY"]}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAA'
                        b'AAAAAAAAAAAAAEAEKKopp_VUWhCpagBvKuWMfuSwRe5gcmh4LO4kJB1rItE')
        assert kevt == (b'{"v":"KERI10JSON000184_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"10","t":"rot","p":"EvDmjSZQmSLqNzTJDq9rdDd7X-ff'
                        b'GPt6zuD2n51EFRLw","kt":"1","k":["D4JDgo3WNSUpt-NG14Ni31_GCmrU0r3'
                        b'8yo7kgDuyGkQM"],"n":"EvbWtNrsw7dfaWRiDMXcF6P90KM1gdfPhg7FWTIwD39'
                        b'c","bt":"0","br":[],"ba":[],"a":["EZRowynuVBviCH0ZfUx24mkMWn-jGR'
                        b'Bm78p90WN3sG3I","1","EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_Yhu'
                        b'A"]}-AABAAonXgmX0PD7e94oqW9yhkm9ydZjwivpNWEPPLIQkOzzvfqGlI79io4x'
                        b'FF8-8K8UWok5dfb9j9fhrqR-e9p23bBw')

        tevt, kevt = issuer.issue(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z")
        assert tevt == (b'{"v":"KERI10JSON000100_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z","ii":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p90WN3sG3I","s":"'
                        b'0","t":"bis","ra":{"i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p90WN3'
                        b'sG3I","s":1,"d":"EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_YhuA"}}'
                        b'-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAAAAAA'
                        b'AAAAAAEQEoRSZSkIHCJjvW9KDO26tFW4VQkhZXVXuYm8OrfxUfh8')
        assert kevt == (b'{"v":"KERI10JSON00017f_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"11","t":"rot","p":"EKKopp_VUWhCpagBvKuWMfuSwRe5'
                        b'gcmh4LO4kJB1rItE","kt":"1","k":["DVjWcaNX2gCkHOjk6rkmqPBCxkRCqwI'
                        b'J-3OjdYmMwxf4"],"n":"EpusdZwamtwTwqtwOenXWKQ0FpX9yWnq0XHlOEgQmss'
                        b'0","bt":"0","br":[],"ba":[],"a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZ'
                        b'H3ULvaU6Z","0","EXklP9Aj6ZXeC4Ox-TFExo_pk5u-ocMacfq82evq0rVo"]}-'
                        b'AABAAIcH6E9px8Tcz2kbJd8vmOvcvnb4Pe2QYL5Y6hkbIPsymR7awzvThHx8qkXB'
                        b'G51sJIgUExNoyaAOnkp20psoeAQ')
        assert vrtser.diger.qb64 == 'EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_YhuA'

        # rotate to no backers
        tevt, kevt = issuer.rotate(cuts=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])
        assert tevt == (b'{"v":"KERI10JSON0000d8_","i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78'
                        b'p90WN3sG3I","p":"EKwtenOwTRhQCzIiBWTPWPCWB6PQ9sF0pnPrsCS_YhuA","'
                        b's":"2","t":"vrt","bt":"0","br":["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5'
                        b'zusCrRo5TDugs"],"ba":[]}-eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5'
                        b'aMtSrMtY0AAAAAAAAAAAAAAAAAAAAAEgEX0HvF8uLvwvQcbnMq1JaMqoPSiJ0RqZ'
                        b'dhyM7gWfYS4g')
        assert kevt == (b'{"v":"KERI10JSON000184_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"12","t":"rot","p":"EoRSZSkIHCJjvW9KDO26tFW4VQkh'
                        b'ZXVXuYm8OrfxUfh8","kt":"1","k":["DT1nEDepd6CSAMCE7NY_jlLdG6_mKUl'
                        b'KS_mW-2HJY1hg"],"n":"ER0SqaQnpyIxxtL_UFvE8wpooAjKNiq36zhpwwbfuZo'
                        b'w","bt":"0","br":[],"ba":[],"a":["EZRowynuVBviCH0ZfUx24mkMWn-jGR'
                        b'Bm78p90WN3sG3I","2","ETtfhi2rdeM4yqMuBb1fLXMjZlG_n_I3N00JMfaIBUn'
                        b's"]}-AABAARKOiQnD9BSRUqFg63Q3lUjyMAJ-cZiVVCHO4POe0iEAXdIRp4Ylzdt'
                        b'PJzVTRpuJC2YecICPXkEehBbnQhXwHBg')
        vrtser = Serder(raw=tevt)

        tevt, kevt = issuer.revoke(vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z")
        assert tevt == (b'{"v":"KERI10JSON0000ff_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
                        b'vaU6Z","s":"1","t":"brv","p":"EXklP9Aj6ZXeC4Ox-TFExo_pk5u-ocMacf'
                        b'q82evq0rVo","ra":{"i":"EZRowynuVBviCH0ZfUx24mkMWn-jGRBm78p90WN3s'
                        b'G3I","s":2,"d":"ETtfhi2rdeM4yqMuBb1fLXMjZlG_n_I3N00JMfaIBUns"}}-'
                        b'eABEaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY0AAAAAAAAAAAAAAAA'
                        b'AAAAAEwE97hmLY8BYtFhPxzmN0ZweLfeU_hU7RVgD8e6BvZA92U')
        assert kevt == (b'{"v":"KERI10JSON00017f_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
                        b'k5aMtSrMtY","s":"13","t":"rot","p":"EX0HvF8uLvwvQcbnMq1JaMqoPSiJ'
                        b'0RqZdhyM7gWfYS4g","kt":"1","k":["DiDeeYNZLsQncGJZ6DR54gAy-HySmzz'
                        b'gl61KFMZ4iR0U"],"n":"E9IUWbvzBjn0ubo_lpKsjCb6ajDS1V23iLHrJFHZ2rV'
                        b'k","bt":"0","br":[],"ba":[],"a":["EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZ'
                        b'H3ULvaU6Z","1","EI_uyS9EE7t3s_TD5PpqqpLXb3PfPt8K0J7VnNLF50-o"]}-'
                        b'AABAAdKHkxbgf1PgVw8dfg4taD8igLLzGlZkifbMcVL3cLOciDn6Ovi39Xsk36Y8'
                        b'a3xHh8WJkIfOaONYscc_bz-jJBw')
        assert vrtser.diger.qb64 == 'ETtfhi2rdeM4yqMuBb1fLXMjZlG_n_I3N00JMfaIBUns'

    """ End Test """
Exemplo n.º 14
0
def test_tevery():
    with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg(
    ) as reg:
        hab = buildHab(db, kpr)

        vcp = eventing.incept(hab.pre,
                              baks=[],
                              toad=0,
                              cnfg=["NB"],
                              code=MtrDex.Blake3_256)
        regk = vcp.pre

        # successfully anchor to a rotation event
        rseal = SealEvent(i=regk, s=vcp.ked["s"], d=vcp.diger.qb64)

        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)

        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tvy = Tevery(reger=reg, db=db)

        tvy.processEvent(serder=vcp, seqner=seqner, diger=diger)

        assert regk in tvy.tevers
        tev = tvy.tevers[regk]
        assert tev.prefixer.qb64 == vcp.pre
        assert tev.sn == 0

        # send vcp again, get error
        with pytest.raises(LikelyDuplicitousError):
            tvy.processEvent(serder=vcp, seqner=seqner, diger=diger)

        # process issue vc event
        vcdig = b'EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU'

        iss = eventing.issue(vcdig=vcdig.decode("utf-8"), regk=regk)

        # successfully anchor to a rotation event
        rseal = SealEvent(iss.ked["i"], iss.ked["s"], iss.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tvy.processEvent(serder=iss, seqner=seqner, diger=diger)
        assert tev.vcState(vcdig) == VcStates.issued
        assert tev.vcSn(vcdig) == 0

        # revoke the vc
        rev = eventing.revoke(vcdig=vcdig.decode("utf-8"),
                              regk=regk,
                              dig=iss.dig)

        # successfully anchor to a rotation event
        rseal = SealEvent(rev.ked["i"], rev.ked["s"], rev.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tvy.processEvent(serder=rev, seqner=seqner, diger=diger)
        assert tev.vcState(vcdig) == VcStates.revoked
        assert tev.vcSn(vcdig) == 1
Exemplo n.º 15
0
def test_tever_backers(mockHelpingNowUTC):
    # registry with backer and receipt
    with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg(
    ) as reg:
        valSecret = 'AgjD4nRlycmM5cPcAkfOATAp8wVldRsnc9f1tiwctXlw'

        # create receipt signer prefixer default code is non-transferable
        valSigner = Signer(qb64=valSecret, transferable=False)
        valPrefixer = Prefixer(qb64=valSigner.verfer.qb64)
        valpre = valPrefixer.qb64
        assert valpre == 'B8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc'

        hab = buildHab(db, kpr)

        vcp = eventing.incept(hab.pre,
                              baks=[valpre],
                              toad=1,
                              cnfg=[],
                              code=MtrDex.Blake3_256)
        regk = vcp.pre
        valCigar = valSigner.sign(ser=vcp.raw, index=0)

        # successfully anchor to a rotation event
        rseal = SealEvent(i=regk, s=vcp.ked["s"], d=vcp.diger.qb64)

        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)

        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tev = Tever(serder=vcp,
                    seqner=seqner,
                    diger=diger,
                    bigers=[valCigar],
                    db=db,
                    reger=reg)

        dgkey = dgKey(pre=regk, dig=vcp.dig)
        assert reg.getTvt(dgkey) == (
            b'{"v":"KERI10JSON0000d7_","i":"EBZR8LxEozgFa6UXwtSAmiXsmdChrT7Hr-jcxc9NFfrU",'
            b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":[],'
            b'"bt":"1",'
            b'"b":["B8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc"]}')
        assert reg.getAnc(
            dgkey
        ) == b'0AAAAAAAAAAAAAAAAAAAAAAQEpWPsFsCcsu5SpVH0416qHx3gvG0CWlrP_i7BVdbmRBg'
        assert reg.getTel(snKey(
            pre=regk, sn=0)) == b'EJTWiS0ebp8VSyLr38x73dAHdUqivisUtAaGpEHt5HDc'
        assert [bytes(tib) for tib in reg.getTibs(dgkey)] == [
            b'AAGhpPxAoltsRAnqxf7NsBzWSxWYLZ_ALImVVBiTlzJSdlATxRp_hBK4AbOzu-a900hwRxa0RX-yVWbVJA6oxoBw'
        ]
        assert reg.getTwe(snKey(pre=regk, sn=0)) is None

        debSecret = 'AKUotEE0eAheKdDJh9QvNmSEmO_bjIav8V_GmctGpuCQ'

        # create receipt signer prefixer default code is non-transferable
        debSigner = Signer(qb64=debSecret, transferable=False)
        debPrefixer = Prefixer(qb64=debSigner.verfer.qb64)
        debpre = debPrefixer.qb64
        assert debpre == 'BbWeWTNGXPMQrVuJmScNQn81YF7T2fhh2kXwT8E_NbeI'

        vrt = eventing.rotate(regk, dig=vcp.dig, baks=[valpre], adds=[debpre])
        valCigar = valSigner.sign(ser=vrt.raw, index=0)
        debCigar = debSigner.sign(ser=vrt.raw, index=1)

        # successfully anchor to a rotation event
        rseal = SealEvent(regk, vrt.ked["s"], vrt.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tev.update(serder=vrt,
                   seqner=seqner,
                   diger=diger,
                   bigers=[valCigar, debCigar])

        assert tev.baks == [
            'B8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc',
            'BbWeWTNGXPMQrVuJmScNQn81YF7T2fhh2kXwT8E_NbeI'
        ]

        vcdig = b'EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU'

        bis = eventing.backerIssue(vcdig=vcdig.decode("utf-8"),
                                   regk=regk,
                                   regsn=tev.sn,
                                   regd=tev.serder.dig)
        valCigar = valSigner.sign(ser=bis.raw, index=0)
        debCigar = debSigner.sign(ser=bis.raw, index=1)

        # successfully anchor to a rotation event
        rseal = SealEvent(bis.ked["i"], bis.ked["s"], bis.diger.qb64)
        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)
        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        tev.update(bis,
                   seqner=seqner,
                   diger=diger,
                   bigers=[valCigar, debCigar])

        vci = nsKey([regk, vcdig])
        dgkey = dgKey(pre=vci, dig=bis.dig)
        assert bytes(reg.getTvt(dgkey)) == (
            b'{"v":"KERI10JSON00012d_","i":"EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU",'
            b'"ii":"EBZR8LxEozgFa6UXwtSAmiXsmdChrT7Hr-jcxc9NFfrU","s":"0","t":"bis","ra":{'
            b'"i":"EBZR8LxEozgFa6UXwtSAmiXsmdChrT7Hr-jcxc9NFfrU","s":1,"d":"EZH2Cfw3nvcMRg'
            b'Y31Jyc2zHVh4a0LO_bVZ4EmL4V8Ol8"},"dt":"2021-01-01T00:00:00.000000+00:00"}'
        )
Exemplo n.º 16
0
def rotate(
    regk,
    dig,
    sn=1,
    toad=None,
    baks=None,
    cuts=None,
    adds=None,
    version=Version,
    kind=Serials.json,
):
    """

    Returns serder of vrt message event
    Utility function to create a Registry rotation event

    Parameters:
        pre is identifier prefix qb64
        regk is regsitry identifier prefix qb64
        sn is int sequence number
        toad is int or str hex of witness threshold
        baks is list of prior backers prefixes qb64
        cuts is list of witness prefixes to cut qb64
        adds is list of witness prefixes to add qb64

    """

    if sn < 1:
        raise ValueError("Invalid sn = {} for vrt.".format(sn))

    vs = Versify(version=version, kind=kind, size=0)
    ilk = Ilks.vrt

    baks = baks if baks is not None else []
    bakset = oset(baks)
    if len(bakset) != len(baks):
        raise ValueError("Invalid baks = {}, has duplicates.".format(baks))

    cuts = cuts if cuts is not None else []
    cutset = oset(cuts)
    if len(cutset) != len(cuts):
        raise ValueError("Invalid cuts = {}, has duplicates.".format(cuts))

    if (bakset & cutset) != cutset:  #  some cuts not in wits
        raise ValueError(
            "Invalid cuts = {}, not all members in baks.".format(cuts))

    adds = adds if adds is not None else []
    addset = oset(adds)
    if len(addset) != len(adds):
        raise ValueError("Invalid adds = {}, has duplicates.".format(adds))

    if cutset & addset:  # non empty intersection
        raise ValueError("Intersecting cuts = {} and  adds = {}.".format(
            cuts, adds))

    if bakset & addset:  # non empty intersection
        raise ValueError("Intersecting baks = {} and  adds = {}.".format(
            baks, adds))

    newbakset = (bakset - cutset) | addset

    if len(newbakset) != (len(baks) - len(cuts) + len(adds)):  # redundant?
        raise ValueError(
            "Invalid member combination among baks = {}, cuts ={}, "
            "and adds = {}.".format(baks, cuts, adds))

    if isinstance(toad, str):
        toad = "{:x}".format(toad)
    elif toad is None:
        if not newbakset:
            toad = 0
        else:  # compute default f and m for len(newbakset)
            toad = ample(len(newbakset))

    if newbakset:
        if toad < 1 or toad > len(newbakset):  # out of bounds toad
            raise ValueError("Invalid toad = {} for resultant wits = {}"
                             "".format(toad, list(newbakset)))
    else:
        if toad != 0:  # invalid toad
            raise ValueError("Invalid toad = {} for resultant wits = {}"
                             "".format(toad, list(newbakset)))

    ked = dict(
        v=vs,  # version string
        i=regk,  # qb64 prefix
        p=dig,
        s="{:x}".format(sn),  # hex string no leading zeros lowercase
        t=ilk,
        bt="{:x}".format(toad),  # hex string no leading zeros lowercase
        br=cuts,  # list of qb64 may be empty
        ba=adds,  # list of qb64 may be empty
    )

    return Serder(ked=ked)  # return serialized ked
Exemplo n.º 17
0
def test_issuer(mockHelpingNowUTC):
    # help.ogler.resetLevel(level=logging.DEBUG)

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)
        # setup issuer with defaults for allowBackers, backers and estOnly
        issuer = Issuer(hab=hab, name="bob", reger=reg)
        assert issuer.incept == (
            b'{"v":"KERI10JSON0000a9_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":[],"bt":"0",'
            b'"b":[]}-GAB0AAAAAAAAAAAAAAAAAAAAAAQElQxdAkGEMsdDn_GFiYPU1eVgQ3z1MvVPEoAGP3THI3A'
        )
        assert issuer.ianchor == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"1","t":"ixn",'
            b'"p":"Eg3wsIOW3RdCqhcG4xZ4uZhTA_qTE24DoLeyjFBB8rks",'
            b'"a":[{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY","s":"0",'
            b'"d":"EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg'
            b'"}]}-AABAAVDMZ3Zfu5Vhw4vIBBbh4oh7l6XACLfOFpS7VN_Tn0vrBlZuHxktv1D9S0Q_e-YbP-PXBjiAnkupzaQ50saSfAA'
        )

        # ensure the digest in the seal from the key event matches the transacript event digest
        ser = Serder(raw=issuer.incept)
        assert ser.diger.qb64 == 'EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg'

        tevt, kevt = issuer.rotate(
            adds=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])
        assert tevt == (
            b'{"v":"KERI10JSON0000d8_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"p":"EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg","s":"1","t":"vrt","bt":"1","br":[],'
            b'"ba":["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU'
            b'"]}-GAB0AAAAAAAAAAAAAAAAAAAAAAgEf12IRHtb_gVo5ClaHHNV90b43adA0f8vRs3jeU-AstY'
        )
        assert kevt == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"2","t":"ixn",'
            b'"p":"ElQxdAkGEMsdDn_GFiYPU1eVgQ3z1MvVPEoAGP3THI3A",'
            b'"a":[{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY","s":"1",'
            b'"d":"EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqbI0"}]}-AABAAb-kk2ijQRZkVmmvWpRcyDLRZad3YOKOvev0yZq'
            b'-ay5QyW9J574kIUxOwgFbC-DUkRIKdPPHkBWZdPSjw6IT-Cg')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqbI0'

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (
            b'{"v":"KERI10JSON00012d_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3UL'
            b'vaU6Z-i0d8","ii":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"s":"0","t":"bis","ra":{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDG'
            b'eLWHb9vSY","s":1,"d":"EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqb'
            b'I0"},"dt":"2021-01-01T00:00:00.000000+00:00"}-GAB0AAAAAAAAAAAAAA'
            b'AAAAAAAAwEke0QhYPogZ-pKBMDhQj6fImswFB3HSZLVdYPvvQeBCE')
        assert kevt == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wu'
            b'k5aMtSrMtY","s":"3","t":"ixn","p":"Ef12IRHtb_gVo5ClaHHNV90b43adA'
            b'0f8vRs3jeU-AstY","a":[{"i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULva'
            b'U6Z-i0d8","s":"0","d":"EyRQ8Yz7vkua8qIqp89_cuYt71gdc9rpE4A6aj_qc'
            b'71Q"}]}-AABAA7i4dJM3hMs9yZpUL01mzNbnai6Q6obbvChybnVNodoRiEZfrz9n'
            b'rmMFtyJcYCUbg8rnfcJfDK9O8sZOeY5yuBg')
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'EyRQ8Yz7vkua8qIqp89_cuYt71gdc9rpE4A6aj_qc71Q'

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        assert tevt == (
            b'{"v":"KERI10JSON00012c_","i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8","s":"1","t":"brv",'
            b'"p":"EyRQ8Yz7vkua8qIqp89_cuYt71gdc9rpE4A6aj_qc71Q",'
            b'"ra":{"i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY","s":1,'
            b'"d":"EpltHxeKueSR1a7e0_oSAhgO6U7VDnX7x4KqNCwBqbI0"},'
            b'"dt":"2021-01-01T00:00:00.000000+00:00"}-GAB0AAAAAAAAAAAAAAAAAAAAABAE3b-DChDs_elyF8J'
            b'-2NF5E9LugwzV_zJ_QqlUg46aWS0')
        assert kevt == (
            b'{"v":"KERI10JSON000107_","i":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"4","t":"ixn",'
            b'"p":"Eke0QhYPogZ-pKBMDhQj6fImswFB3HSZLVdYPvvQeBCE",'
            b'"a":[{"i":"EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8","s":"1",'
            b'"d":"EoZbbgb3JrlQFAyTwXwt_yJj-pE2M7kGTCgZ1nMA1j30'
            b'"}]}-AABAA2uvL7t5qPsWmwyGtcOktw6nXLKXMLBIsgd_XikYulv0UNfNZ-Ef-4af1WkAOlv226p9pZIjBFGy427TaOi5bAg'
        )
        ser = Serder(raw=tevt)
        assert ser.diger.qb64 == 'EoZbbgb3JrlQFAyTwXwt_yJj-pE2M7kGTCgZ1nMA1j30'

        with basing.openDB(name="bob") as db, keeping.openKS(
                name="bob") as kpr, viring.openReg() as reg:
            hab = buildHab(db, kpr)
            # issuer, not allowed to issue backers
            issuer = Issuer(hab=hab, name="bob", noBackers=True, reger=reg)
            ser = Serder(raw=issuer.incept)
            assert ser.pre == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
            assert ser.ked["t"] == "vcp"
            assert ser.ked["c"] == ["NB"]
            assert ser.ked["b"] == []
            assert ser.ked["bt"] == "0"

            ser = Serder(raw=issuer.ianchor)
            assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
            assert ser.ked["t"] == "ixn"
            seal = ser.ked["a"][0]
            assert seal["i"] == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
            assert seal["s"] == "0"
            assert seal["d"] == "ElYstqTocyQixLLz4zYCAs2unaFco_p6LqH0W01loIg4"

            with pytest.raises(ValueError):
                issuer.rotate(
                    adds=["EqoNZAX5Lu8RuHzwwyn5tCZTe-mDBq5zusCrRo5TDugs"])

        with basing.openDB(name="bob") as db, keeping.openKS(
                name="bob") as kpr, viring.openReg() as reg:
            hab = buildHab(db, kpr)
            issuer = Issuer(hab=hab, name="bob", noBackers=True, reger=reg)

            tevt, kevt = issuer.issue(
                vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
            ser = Serder(raw=tevt)
            assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert ser.ked[
                "ri"] == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
            assert ser.ked["t"] == "iss"

            ser = Serder(raw=kevt)
            assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
            assert ser.ked["t"] == "ixn"
            seal = ser.ked["a"][0]
            assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert seal["s"] == "0"
            assert seal["d"] == 'Ewia5uvi4RAgr3rG_YlHSNPT3DxCa-2UDZ-TldDJPDWs'

            tevt, kevt = issuer.revoke(
                vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
            ser = Serder(raw=tevt)
            assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert ser.ked["t"] == "rev"
            assert ser.ked[
                "ri"] == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"

            ser = Serder(raw=kevt)
            assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
            assert ser.ked["t"] == "ixn"
            seal = ser.ked["a"][0]
            assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
            assert seal["s"] == "1"
            assert seal["d"] == 'EZGxxhShIC6KT_iKRHMtONyKpckqGa-waTbpPo7gn21A'

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)

        # issuer, allowed backers, initial set of backers
        issuer = Issuer(hab=hab,
                        reger=reg,
                        baks=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])
        ser = Serder(raw=issuer.incept)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vcp"
        assert ser.ked["b"] == ["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"]
        assert ser.ked["bt"] == "1"

        ser = Serder(raw=issuer.ianchor)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "bis"
        seal = ser.ked["ra"]
        assert seal["i"] == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert seal["s"] == "0"

        tevt, kevt = issuer.rotate(adds=[
            "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
            "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
        ])
        vrtser = Serder(raw=tevt)
        ser = Serder(raw=tevt)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vrt"
        assert ser.ked["ba"] == [
            "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
            "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
        ]

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert seal["s"] == "1"

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "brv"
        seal = ser.ked["ra"]
        # ensure the ra seal digest matches the vrt event digest
        assert seal["d"] == vrtser.diger.qb64

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "ixn"
        seal = ser.ked["a"][0]
        assert seal["i"] == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert seal["s"] == "1"

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)

        # issuer, no backers allowed, establishment events only
        issuer = Issuer(hab=hab, reger=reg, noBackers=True, estOnly=True)
        ser = Serder(raw=issuer.incept)
        assert ser.pre == "Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw"
        assert ser.ked["t"] == "vcp"
        assert ser.ked["c"] == ["NB"]
        assert ser.ked["bt"] == "0"

        ser = Serder(raw=issuer.ianchor)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        assert ser.ked["k"] == ["DKPE5eeJRzkRTMOoRGVd2m18o8fLqM2j9kaxLhV3x8AQ"]
        assert ser.ked["n"] == "ELqHYQwWR0h2vP1_cxTsutU0wKJ_NrwBVKJCgPgWGgwc"

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "iss"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "rev"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"

        with pytest.raises(ValueError):
            issuer.rotate(
                adds=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])

    with basing.openDB(name="bob") as db, keeping.openKS(
            name="bob") as kpr, viring.openReg() as reg:
        hab = buildHab(db, kpr)

        # issuer, backers allowed, initial backer, establishment events only
        issuer = Issuer(hab=hab,
                        reger=reg,
                        baks=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"],
                        estOnly=True)
        ser = Serder(raw=issuer.incept)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["b"] == ["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"]
        assert ser.diger.qb64 == 'EevCI-l5dfYW63xg1bQ52ldLQa3li8FBo-znWxNEzv7E'
        ser = Serder(raw=issuer.ianchor)
        assert ser.ked["t"] == "rot"

        tevt, kevt = issuer.rotate(
            toad=3,
            adds=[
                "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
                "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
            ])
        vrtser = Serder(raw=tevt)
        ser = Serder(raw=tevt)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vrt"
        assert issuer.backers == [
            "BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU",
            "B9DfgIp33muOuCI0L8db_TldMJXv892UmW8yfpUuKzkw",
            "BBC_BBLMeVwKFbfYSWU7aATS9itLSrGtIFQzCkfoKnjk"
        ]

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"

        tevt, kevt = issuer.issue(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "bis"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        assert vrtser.diger.qb64 == 'ECQbOOZdBxpw5RTH4VvPXDSH_o2uYdPWSoWolW5tobgA'

        # rotate to no backers
        tevt, kevt = issuer.rotate(
            toad=2, cuts=["BwFbQvUaS4EirvZVPUav7R_KDHB8AKmSfXNpWnZU_YEU"])
        ser = Serder(raw=tevt)
        assert ser.pre == "EaU321874i434f59ab7cMH6YlN52PJ395nrLS_6tLq6c"
        assert ser.ked["t"] == "vrt"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        vrtser = Serder(raw=tevt)

        tevt, kevt = issuer.revoke(
            vcdig="EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8")
        ser = Serder(raw=tevt)
        assert ser.pre == "EJJR2nmwyYAfSVPzhzS6b5CMZAoTNZH3ULvaU6Z-i0d8"
        assert ser.ked["t"] == "brv"

        ser = Serder(raw=kevt)
        assert ser.pre == "EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY"
        assert ser.ked["t"] == "rot"
        assert vrtser.diger.qb64 == 'EnUD_KZu-dGpFSEWZOlFdQSydioYY78qIDPfzA7Fhr-Q'
    """ End Test """
Exemplo n.º 18
0
def test_tever_escrow():
    with pytest.raises(TypeError):
        Tever()

    # registry with no backers, invalid anchor
    with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg(
    ) as reg:
        hab = buildHab(db, kpr)
        vcp = eventing.incept(hab.pre,
                              baks=[],
                              toad=0,
                              cnfg=[],
                              code=MtrDex.Blake3_256)
        regk = vcp.pre
        assert regk == "EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY"
        assert vcp.dig == "EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg"
        assert vcp.ked["ii"] == hab.pre

        # anchor to nothing, exception expected
        seqner = Seqner(sn=4)

        # invalid seal sn
        with pytest.raises(ValidationError):
            Tever(serder=vcp, seqner=seqner, diger=None, db=db, reger=reg)

    # registry with no backers
    with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg(
    ) as reg:
        hab = buildHab(db, kpr)
        vcp = eventing.incept(hab.pre,
                              baks=[],
                              toad=0,
                              cnfg=[],
                              code=MtrDex.Blake3_256)
        regk = vcp.pre

        # anchoring event not in db, exception and escrow
        seqner = Seqner(sn=1)

        with pytest.raises(MissingAnchorError):
            Tever(serder=vcp, seqner=seqner, db=db, reger=reg)

        dgkey = dgKey(pre=regk, dig=vcp.dig)
        assert reg.getTvt(dgkey) == (
            b'{"v":"KERI10JSON0000a9_","i":"EoN_Ln_JpgqsIys-jDOH8oWdxgWqs7hzkDGeLWHb9vSY",'
            b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":[],"bt":"0","b":[]}'
        )
        assert reg.getTae(snKey(
            pre=regk, sn=0)) == b'EvpB-_BWD7tOhLI0cDyEQbziBt6IMyQnkrh0booR4vhg'

    # registry with backers, no signatures.  should escrow
    with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg(
    ) as reg:
        hab = buildHab(db, kpr)
        vcp = eventing.incept(
            hab.pre,
            baks=["BoOcciw30IVQsaenKXpiyMVrjtPDW3KeD_6KFnSfoaqI"],
            toad=1,
            cnfg=[],
            code=MtrDex.Blake3_256)
        regk = vcp.pre

        # successfully anchor to a rotation event
        rseal = SealEvent(regk, vcp.ked["s"], vcp.diger.qb64)

        rot = hab.rotate(data=[rseal._asdict()])
        rotser = Serder(raw=rot)

        seqner = Seqner(sn=int(rotser.ked["s"], 16))
        diger = rotser.diger

        with pytest.raises(MissingWitnessSignatureError):
            Tever(serder=vcp, seqner=seqner, diger=diger, db=db, reger=reg)

        dgkey = dgKey(pre=regk, dig=vcp.dig)
        assert reg.getTvt(dgkey) == (
            b'{"v":"KERI10JSON0000d7_","i":"E1cv04kvHvWPrfncYsq-lQ-QvyKmKz6-hlGj02B2QWbk",'
            b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":[],"bt":"1",'
            b'"b":["BoOcciw30IVQsaenKXpiyMVrjtPDW3KeD_6KFnSfoaqI"]}')

        assert reg.getAnc(dgkey) == (
            b'0AAAAAAAAAAAAAAAAAAAAAAQE1NdOqtN0HlhBPc7-MHvsA4vajMwFYp2eIturQQo0stM'
        )
        assert reg.getTel(snKey(pre=regk, sn=0)) is None
        assert reg.getTwe(snKey(
            pre=regk, sn=0)) == b'EjhsbizNCwN_EFuOxbUt8CN0xOctGRIVOW8X-XqA3fSk'