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

Function forge_rune

tests/test_runes.py:923–933  ·  view source on GitHub ↗

Mint a rune with no restriction but its unique_id from a master secret. The authcode is the SHA256 state after the secret and each restriction, each padded exactly like the SHA256 end marker, so knowing the secret it is plain SHA256 over the whole padded stream.

(secret, unique_id)

Source from the content-addressed store, hash-verified

921
922
923def forge_rune(secret, unique_id):
924 """Mint a rune with no restriction but its unique_id from a master secret.
925
926 The authcode is the SHA256 state after the secret and each restriction,
927 each padded exactly like the SHA256 end marker, so knowing the secret it
928 is plain SHA256 over the whole padded stream."""
929 padded = (secret + b'\x80' + bytes(64 - len(secret) - 1 - 8)
930 + (len(secret) * 8).to_bytes(8, 'big'))
931 restr = ('=' + unique_id).encode()
932 authcode = hashlib.sha256(padded + restr).digest()
933 return base64.urlsafe_b64encode(authcode + restr).decode()
934
935
936def test_makesecret_rune_master_secret(node_factory):

Callers 1

Calls 4

digestMethod · 0.80
to_bytesMethod · 0.45
encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected