...
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
linenumbers | true |
---|
|
rule mischief_hat_lifted {
select when mischief hat_lifted
foreach Subscriptionssubscriptions:getSubscriptionsestablished() setting (subscription)
pre {
thing_subs = subscription.klog("subs")
subs_attrs = thing_subs{"attributes"}
map = {"test": 1}
message = map.encode() // signChannelMessage requires a string so objects should be encoded
signed_message = engine:signChannelMessage(subscription.eci{"Rx"}, message)
}
if true then
event:send({
"eci": subs_attrs{"outbound_eci"},
"eid": "hat-lifted",
"domain": "mischief",
"type": "hat_lifted",
"attrs": {"signed_message": signed_message, "sub_nameid" : subscription.name{"Id"}}
})
} |
The following rule shows how to verify a signed message. The key used to verify a signed message is stored on the subscription map and can be accessed with the key "other_verify_key".
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
linenumbers | true |
---|
|
rule mischief_hat_lifted {
select when mischief hat_lifted
pre {
subscriptions subID = Subscriptionsevent:getSubscriptionsattr("sub_id")
subscription = subscriptions{event:attrestablished("sub_name")}Id", subID).head()
verified_message = engine:verifySignedMessage(subscription{"otherTx_verify_key"}, event:attr("signed_message"))
}
if verified_message != false then // If verifying the signed message fails then it will return false
noop()
fired {
ent:message := verified_message.decode() // Objects will need to be decoded before being treated as an object
} else {
raise wrangler event "signature_verification_failed"
}
} |
...
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
linenumbers | true |
---|
|
rule mischief_encrypted {
select when mischief encrypted
foreach Subscriptionssubscriptions:getSubscriptionsestablished() setting (subscription)
pre {
thing_subs = subscription.klog("subs")
subs_attrs = thing_subs{"attributes"}
map = {"encryption": 1}
message = map.encode() // The encryptChannelMessage requires a string so objects should be encoded
eci = subscription{"Rx"}
subID = subscription.eci{"Id"}
encrypted_object = engine:encryptChannelMessage(subscription.eci, message, subscription.other_encryption{"Tx_public_key"})
}
if true then
event:send({
"eci": subs_attrs{"outbound_eci"},
"eid": "hat-lifted",
"domain": "mischief",
"type": "encrypted",
"attrs": { "encryptedMessage": encrypted_object{"encryptedMessage"},
"sub_nameid" : subscription.namesubID,
"nonce": encrypted_object{"nonce"}}
})
} |
...
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
linenumbers | true |
---|
|
rule mischief_hat_lifted_encrypted {
select when mischief encrypted
pre {
subscriptions subID = Subscriptionsevent:getSubscriptionsattr("sub_id")
subscription = subscriptions{event:attrestablished("sub_name")}Id", subID).head()
nonce = event:attr("nonce")
encrypted_message = event:attr("encryptedMessage")
decrypted_message = engine:decryptChannelMessage(subscription.eci{"Rx"},
encrypted_message,
nonce,
subscription{"other_encryptionTx_public_key"})
}
if decrypted_message != false then
noop()
fired {
ent:decrypted_message := decrypted_message.decode() // Objects will need to be decoded before being treated as an object
} else {
raise wrangler event "decryption_failure"
}
} |
...