Ejemplo n.º 1
0
def testFullSigning():
    # stored securely/privately
    seed = randombytes(32)

    # generates key pair based on seed
    sk = SigningKey(seed=seed)

    # helper for signing
    signer = Signer(sk)

    # this is the public key used to verify signatures (securely shared before-hand with recipient)
    verkey = signer.verhex

    # the message to be signed
    msg = b'1234'

    # the signature
    sig = signer.signature(msg)

    # helper for verification
    vr = Verifier(verkey)

    # verification
    isVerified = vr.verify(sig, msg)

    assert isVerified
Ejemplo n.º 2
0
def verifySig(identifier, signature, msg) -> bool:
    key = cryptonymToHex(identifier) if not isHex(identifier) else identifier
    ser = serializeMsg(msg)
    b64sig = signature.encode('utf-8')
    sig = b58decode(b64sig)
    vr = Verifier(key)
    return vr.verify(sig, ser)
Ejemplo n.º 3
0
def testFullSigning():
    # stored securely/privately
    seed = randombytes(32)

    # generates key pair based on seed
    sk = SigningKey(seed=seed)

    # helper for signing
    signer = Signer(sk)

    # this is the public key used to verify signatures (securely shared
    # before-hand with recipient)
    verkey = signer.verhex

    # the message to be signed
    msg = b'1234'

    # the signature
    sig = signer.signature(msg)

    # helper for verification
    vr = Verifier(verkey)

    # verification
    isVerified = vr.verify(sig, msg)

    assert isVerified
Ejemplo n.º 4
0
class AddressSigVerifier(Verifier):
    def __init__(self, verkey, **kwargs):
        self.verkey = verkey
        self._vr = NaclVerifier(b58decode(verkey))

    def verify(self, sig, msg) -> bool:
        return self._vr.verify(sig, msg)
Ejemplo n.º 5
0
class DidVerifier(Verifier):
    def __init__(self, verkey, identifier=None):
        _verkey = verkey
        self._verkey = None
        self._vr = None
        if identifier:
            rawIdr = b58decode(identifier)
            if len(rawIdr) == 32 and not verkey:  # assume cryptonym
                verkey = identifier

            assert verkey, 'verkey must be provided'
            if verkey[0] == '~':  # abbreviated
                verkey = b58encode(
                    b58decode(identifier) +
                    b58decode(verkey[1:])).decode("utf-8")
        try:
            self.verkey = verkey
        except Exception as ex:
            raise InvalidKey("verkey {}".format(_verkey)) from ex

    @property
    def verkey(self):
        return self._verkey

    @verkey.setter
    def verkey(self, value):
        self._verkey = value
        self._vr = NaclVerifier(b58decode(value))

    def verify(self, sig, msg) -> bool:
        return self._vr.verify(sig, msg)
Ejemplo n.º 6
0
class DidVerifier(Verifier):
    def __init__(self, verkey, identifier=None):
        self._verkey = None
        self._vr = None
        if identifier:
            rawIdr = b58decode(identifier)
            if len(rawIdr) == 32 and not verkey:  # assume cryptonym
                verkey = identifier
            if verkey[0] == '~':  # abbreviated
                verkey = b58encode(
                    b58decode(identifier) + b58decode(verkey[1:]))
        self.verkey = verkey

    @property
    def verkey(self):
        return self._verkey

    @verkey.setter
    def verkey(self, value):
        self._verkey = value
        self._vr = NaclVerifier(b58decode(value))

    def verify(self, sig, msg) -> bool:
        return self._vr.verify(sig, msg)
Ejemplo n.º 7
0
 def addVerifier(self, verkey):
     self.verifiers[verkey] = Verifier(z85.decode(verkey))
Ejemplo n.º 8
0
 def __init__(self, verkey, **kwargs):
     self.verkey = verkey
     self._vr = NaclVerifier(b58decode(verkey))
Ejemplo n.º 9
0
 def verkey(self, value):
     self._verkey = value
     self._vr = NaclVerifier(b58decode(value))