olm prototype from tutorial

This commit is contained in:
Bruno Windels 2020-03-26 21:14:31 +01:00
parent 24bf074aa3
commit d49115c69b
5 changed files with 67 additions and 0 deletions

1
lib/olm.js Symbolic link
View File

@ -0,0 +1 @@
../node_modules/olm/olm.js

1
lib/olm.wasm Symbolic link
View File

@ -0,0 +1 @@
../node_modules/olm/olm.wasm

View File

@ -29,5 +29,8 @@
"postcss-import": "^12.0.1", "postcss-import": "^12.0.1",
"rollup": "^1.15.6", "rollup": "^1.15.6",
"serve-static": "^1.13.2" "serve-static": "^1.13.2"
},
"dependencies": {
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz"
} }
} }

58
prototypes/olmtest.html Normal file
View File

@ -0,0 +1,58 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
pre {
font-family: monospace;
display: block;
white-space: pre;
font-size: 2em;
}
</style>
</head>
<body>
<script type="text/javascript" src="../lib/olm.js"></script>
<script type="module">
async function main() {
const Olm = window.Olm;
await Olm.init({
locateFile: () => "../lib/olm.wasm",
});
const alice = new Olm.Account();
alice.create();
console.log("alice", alice.identity_keys());
const bob = new Olm.Account();
bob.unpickle("secret", "EWfA87or4GgQ+wqVkyuFiW9gUk3FI6QSXgp8E2dS5RFLvXgy4oFvxwQ1gVnbMkdJz2Hy9ex9UmJ/ZyuRU0aRt0IwXpw/SUNq4IQeVJ7J/miXW7rV4Ep+4RSEf945KbDrokDCS2CoL5PIfv/NYyey32gA0hMi8wWIfIlOxFBV4SBJYSC+Qd54VjprwCg0Sn9vjQouKVrM/+5jzsv9+JK5OpWW0Vrb3qrXwyAOEAQ4WlOQcqZHAyPQIw");
console.log("bob", bob.identity_keys());
// generate OTK on receiver side
bob.generate_one_time_keys(1);
const bobOneTimeKeys = JSON.parse(bob.one_time_keys());
const bobOneTimeKey = Object.values(bobOneTimeKeys.curve25519)[0];
// encrypt
const aliceSession = new Olm.Session();
aliceSession.create_outbound(
alice,
JSON.parse(bob.identity_keys()).curve25519,
bobOneTimeKey,
);
const message = aliceSession.encrypt("hello secret world");
console.log("message", message);
// decrypt
const bobSession = new Olm.Session();
bobSession.create_inbound(bob, message.body);
const plaintext = bobSession.decrypt(message.type, message.body);
console.log("plaintext", plaintext);
// remove Bob's OTK as it was used to start an olm session
console.log("bob OTK before removing", bob.one_time_keys());
bob.remove_one_time_keys(bobSession);
console.log("bob OTK after removing", bob.one_time_keys());
}
main();
</script>
</body>
</html>

View File

@ -274,6 +274,10 @@ nth-check@~1.0.1:
dependencies: dependencies:
boolbase "~1.0.0" boolbase "~1.0.0"
"olm@https://packages.matrix.org/npm/olm/olm-3.1.4.tgz":
version "3.1.4"
resolved "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz#0f03128b7d3b2f614d2216409a1dfccca765fdb3"
on-finished@~2.3.0: on-finished@~2.3.0:
version "2.3.0" version "2.3.0"
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"