fn(signed_event_bytes$0, then$1) =>
match @std.base64-to-bytes(text: $0) {
#none(_) =>
$1(result: #invalid<@definy.signed-event-verification>("signedEventBytes must be Base64")),
#some(bytes$2) =>
match @definy.decode-signed-event(bytes: $2) {
#invalid(message$3) =>
$1(result: #invalid<@definy.signed-event-verification>($3)),
#decoded(decoded$4) =>
#verify_ed25519<@definy.service-io>({
public_key: $4.account_id_bytes,
signature: $4.signature,
message: $4.message,
then: fn(valid$5) =>
match $5 {
false =>
$1(result: #invalid<@definy.signed-event-verification>("Ed25519 signature verification failed")),
true =>
#read_time<@definy.service-io>({
then: fn(now_ms$6) =>
match @core.less-than(left: @core.plus(left: $6, right: 600000), right: $4.time_ms) {
true =>
$1(result: #invalid<@definy.signed-event-verification>("event time is too far in the future")),
false =>
#hash_contents<@definy.service-io>({
contents_bytes: [$0],
then: fn(hashes$7) =>
$1(
result: #valid<@definy.signed-event-verification>({
event_hash: match @core.list-get(list: $7, index: 0) {
#some(hash$8) =>
match $8 {
#some(text$9) =>
$9,
#none(_) =>
""
},
#none(_) =>
""
},
account_id: @core.bytes-to-base64url(bytes: $4.account_id_bytes),
time_ms: $4.time_ms,
content: $4.content,
referenced_content_hashes: match $4.content {
#project_commit(commit$10) =>
@definy.snapshot-content-hashes(modules: $10.modules, index: 0),
_ =>
[]
}
})
)
})
}
})
}
})
}
}