Example #1
0
    def sign_stream_claim(self, claim, claim_address, cert_claim_id):
        validate_claim_id(cert_claim_id)
        if not base_decode(claim_address, 58):
            raise Exception("Invalid claim address")

        to_sign = "%s%s%s" % (base_decode(claim_address, 58),
                              claim.serialized_no_signature,
                              cert_claim_id.decode('hex'))

        digest = self.HASHFUNC(to_sign).digest()

        if not isinstance(self.private_key, ecdsa.SigningKey):
            raise Exception("Not given a signing key")
        sig_dict = {
            "version": V_0_0_1,
            "signatureType": self.CURVE_NAME,
            "signature": self.private_key.sign_digest_deterministic(digest, hashfunc=self.HASHFUNC),
            "certificateId": cert_claim_id.decode('hex')
        }

        msg = {
            "version": V_0_0_1,
            "stream": decode_b64_fields(claim.protobuf_dict)['stream'],
            "publisherSignature": sig_dict
        }

        return Claim.load(msg)
Example #2
0
 def protobuf(self):
     pb = {
         "version": self.version,
         "currency": CURRENCY_MAP[self.currency],
         "address": base_decode(self.address, 58),
         "amount": self.amount
     }
     return FeeHelper.load(pb)
Example #3
0
def migrate(fee):
    if len(fee.keys(
    )) == 3 and 'currency' in fee and 'amount' in fee and 'address' in fee:
        return FeeHelper.load({
            "version": "_0_0_1",
            "currency": fee['currency'],
            "amount": fee['amount'],
            "address": base_decode(fee['address'], 58)
        })
    if len(fee.keys()) > 1:
        raise Exception("Invalid fee")

    currency = fee.keys()[0]
    amount = fee[currency]['amount']
    address = fee[currency]['address']

    return FeeHelper.load({
        "version": "_0_0_1",
        "currency": currency,
        "amount": amount,
        "address": base_decode(address, 58)
    })
Example #4
0
    def validate_claim_signature(self, claim, claim_address):
        decoded_address = base_decode(claim_address, 58)
        if not decoded_address:
            raise Exception("Invalid claim address")

        # extract and serialize the stream from the claim, then check the signature
        signature = claim.signature.decode('hex')

        if signature is None:
            raise Exception("No signature to validate")

        to_sign = "%s%s%s" % (decoded_address, claim.serialized_no_signature,
                              self.certificate_claim_id.decode('hex'))

        return self.validate_signature(
            self.HASHFUNC(to_sign).digest(), signature)
Example #5
0
def decode_fields(claim_dictionary):
    """Decode hex and b58 encoded bytes in dictionaries given to ClaimDict"""
    claim_dictionary = deepcopy(claim_dictionary)
    claim_type = CLAIM_TYPES[claim_dictionary[CLAIM_TYPE]]
    claim_value = claim_dictionary[claim_type]
    if claim_type == CLAIM_TYPES[STREAM_TYPE]:
        claim_value['source']['source'] = claim_value['source'][
            'source'].decode('hex')
        if 'fee' in claim_value['metadata']:
            address = base_decode(claim_value['metadata']['fee']['address'],
                                  58)
            claim_value['metadata']['fee']['address'] = address
    elif claim_type == CLAIM_TYPES[CERTIFICATE_TYPE]:
        public_key = claim_value["publicKey"].decode('hex')
        claim_value["publicKey"] = public_key
    if SIGNATURE in claim_dictionary:
        decoded_sig = claim_dictionary[SIGNATURE]['signature'].decode('hex')
        decoded_cert_id = claim_dictionary[SIGNATURE]['certificateId'].decode(
            'hex')
        claim_dictionary[SIGNATURE]['signature'] = decoded_sig
        claim_dictionary[SIGNATURE]['certificateId'] = decoded_cert_id
    claim_dictionary[claim_type] = claim_value
    return claim_dictionary