Skip to content

Instantly share code, notes, and snippets.

@puria
Created May 19, 2023 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puria/31955761920fb7357c91a8783e39a449 to your computer and use it in GitHub Desktop.
Save puria/31955761920fb7357c91a8783e39a449 to your computer and use it in GitHub Desktop.
e2e encryption message wasm
<script type="module">
import { zencode_exec } from "https://jspm.dev/zenroom";
const keys = JSON.stringify({
"Alice": {
"keyring": {
"ecdh": "IStvfSREogWWYLB+DtpaSFqGJYMZMKvLIdGNN/H5DH4="
}
}
})
const data = JSON.stringify({
"Bob": {
"public_key": "BBA0kD35T9lUHR/WhDwBmgg/vMzlu1Vb0qtBjBZ8rbhdtW3AcX6z64a59RqF6FCV5q3lpiFNTmOgA264x1cZHE0="
},
"Carl": {
"public_key": "BLdpLbIcpV5oQ3WWKFDmOQ/zZqTo93cT1SId8HNITgDzFeI6Y3FCBTxsKHeyY1GAbHzABsOf1Zo61FRQFLRAsc8="
},
"message": "Dear Bob and Carl, if you are reading this, then we're not friend anymore. Goodbye.",
"header": "Secret message for Bob and Carl"
})
const contract = `Rule check version 2.0.0
Scenario 'ecdh': Alice encrypts a message for Bob
Given that I am known as 'Alice'
Given that I have my valid 'keyring'
Given that I have a valid 'public key' from 'Bob'
Given that I have a valid 'public key' from 'Carl'
Given that I have a 'string' named 'message'
Given that I have a 'string' named 'header'
When I encrypt the secret message of 'message' for 'Bob'
When I rename the 'secret message' to 'secretForBob'
When I encrypt the secret message of 'message' for 'Carl'
When I rename the 'secret message' to 'secretForCarl'
Then print the 'secretForBob'
Then print the 'secretForCarl'
`
zencode_exec(contract, {data, keys}).then(r => {
console.log(JSON.parse(r.result))
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment