Ejemplo n.º 1
0
    def parse_fixed(byte_string):
        if len(byte_string) != ONION_BYTE_LENGTH:
            return None, "onion is the wrong length"
        version, remainder, err = Namespace.pop_u8(byte_string)
        if err:
            return None, "could not pop version byte"
        if version != 0:
            return None, "unsupported onion packet version"
        public_key, remainder, err = Namespace.pop_point(remainder)
        if err:
            return None, "could not pop public key: %s" % err

        hop_payloads, remainder, err = Namespace.pop_bytes(HOP_PAYLOADS_LENGTH,
                                                           remainder)
        if err:
            return None, "could not pop hops_payloads: %s" % err
        hmac, remainder, err =  Namespace.pop_bytes(HMAC_LENGTH, remainder)
        if err:
            return None, "could not pop hmac: %s" % err
        if len(remainder) != 0:
            return None, "unexpected remaining bytes"
        # TODO Check hmac for validity, need assocdata
        return {'version':      version,
                'public_key':   public_key,
                'hop_payloads': hop_payloads,
                'hmac':         hmac}, None
Ejemplo n.º 2
0
 def parse(byte_string):
     scid, remainder, err = Namespace.pop_short_channel_id(byte_string)
     if err:
         return None, err
     #print("scid: %s, remainder: %s\n" % (scid, remainder.hex()))
     amt_to_forward, remainder, err = Namespace.pop_u64(remainder)
     if err:
         return None, err
     #print("amt: %s, remainder: %s\n" % (amt_to_forward, remainder.hex()))
     outgoing_cltv_value, remainder, err = Namespace.pop_u32(remainder)
     if err:
         return None, err
     #print("outgoing: %s,  remainder: %s\n" % (outgoing_cltv_value,
     #                                          remainder.hex()))
     padding, remainder, err = Namespace.pop_bytes(12, remainder)
     if err:
         return None, err
     #print("padding %s, remainder: %s\n" % (padding, remainder.hex()))
     if len(remainder) != 0:
         return None, "unexpected remaining bytes"
     return {
         'format': 'legacy',
         'short_channel_id': scid,
         'amt_to_forward': amt_to_forward,
         'outgoing_cltv_value': outgoing_cltv_value,
         'padding': padding
     }, None
Ejemplo n.º 3
0
 def parse_pixels(tlv):
     pixels = []
     if tlv.l % 5 != 0:
         return None, "unexpected length"
     remainder = tlv.v
     while len(remainder) > 0:
         pixel_hex, remainder, err = Namespace.pop_bytes(5, remainder)
         if err:
             return None, err
         pixels.append(Pixel.from_bin(h2b(pixel_hex)))
     return {'tlv_type_name': "bannerpunk_pixels", 'pixels': pixels}, None
Ejemplo n.º 4
0
 def parse_payment_data(tlv):
     payment_secret, remainder, err = Namespace.pop_bytes(32, tlv.v)
     if err:
         return None, err
     total_msat, remainder, err = Namespace.pop_tu64(
         len(remainder), remainder)
     if err:
         return None, err
     if len(remainder) != 0:
         return None, "unexpected remaining bytes"
     return {
         'tlv_type_name': 'payment_data',
         'payment_secret': payment_secret,
         'total_msat': total_msat
     }, None