Learn Lua · Time, IDs and checks · Lesson 2 of 4
IDs and fingerprints
A UUID is an identifier that won't clash with anyone else's. uuid.v4() makes a new
one, and uuid.is_valid checks text that claims to be one:
uuid.is_valid("0190a5c8-8c3e-7b4a-9f21-3d6c2a1b0e9f") --> true
uuid.is_valid("not-an-id") --> falseA hash is a fingerprint of some text: the same text always gives the same hash, and
any change gives a different one. hash.sha256 is the usual choice:
hash.sha256("hello") --> "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { id = "0190a5c8-8c3e-7b4a-9f21-3d6c2a1b0e9f", text = "hello" }Steps
- Return
valid: whetherinput.idis a valid UUID. - Add
fingerprint: the SHA-256 hash ofinput.text. - Add
newId: a new random UUID.
Show a hint
Each field is one call. A new UUID is different every time, so the checks only test that it's valid.