MCPcopy Create free account
hub / github.com/ElementsProject/lightning / crafted_bolt11

Function crafted_bolt11

tests/test_invoices.py:1181–1198  ·  view source on GitHub ↗

A parseable-but-junk-signed bolt11: createinvoice decodes without verifying the signature, so the 65 trailing bytes are filler; every field the parser needs is real.

(hrp, payment_hash, expiry)

Source from the content-addressed store, hash-verified

1179 from pyln.proto.bech32 import bech32_encode
1180
1181 def crafted_bolt11(hrp, payment_hash, expiry):
1182 """A parseable-but-junk-signed bolt11: createinvoice decodes
1183 without verifying the signature, so the 65 trailing bytes are
1184 filler; every field the parser needs is real."""
1185 data = bitstring.pack('uint:35', 12345678)
1186 data += tagged_bytes('p', payment_hash)
1187 data += tagged('d', bitstring.BitArray(b'crafted'))
1188 xbits = bitstring.pack('uint:64', expiry)[4:]
1189 while xbits.startswith('0b00000'):
1190 xbits = xbits[5:]
1191 while xbits.len % 5 != 0:
1192 xbits.prepend('0b0')
1193 data += tagged('x', xbits)
1194 data += tagged_bytes('s', bytes(32))
1195 data += bitstring.BitArray(bytes(65))
1196 return bech32_encode(
1197 hrp, bytes([data[i:i + 5].uint
1198 for i in range(0, data.len, 5)]))
1199
1200 l1 = node_factory.get_node()
1201 # The bech32 HRP is network-dependent (lnbcrt on regtest, another

Callers 1

Calls 3

tagged_bytesFunction · 0.90
taggedFunction · 0.90
bech32_encodeFunction · 0.90

Tested by

no test coverage detected