Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
e28f0989
Commit
e28f0989
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Add a demo for the javascript bindings
parent
f2168004
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
javascript/demo.html
+136
-0
136 additions, 0 deletions
javascript/demo.html
with
136 additions
and
0 deletions
javascript/demo.html
0 → 100644
+
136
−
0
View file @
e28f0989
<html>
<head>
<script
src=
"../build/axolotl.js"
></script>
<script>
document
.
addEventListener
(
"
DOMContentLoaded
"
,
function
(
event
)
{
function
progress
(
who
,
message
)
{
var
message_element
=
document
.
createElement
(
"
pre
"
);
var
progress
=
document
.
getElementById
(
who
+
"
_progress
"
);
var
start_content
=
document
.
createTextNode
(
message
+
"
...
"
);
var
done_content
=
document
.
createTextNode
(
message
+
"
... Done
"
);
function
start
()
{
message_element
.
appendChild
(
start_content
);
progress
.
appendChild
(
message_element
);
}
function
done
()
{
message_element
.
replaceChild
(
done_content
,
start_content
);
}
return
{
start
:
start
,
done
:
done
};
}
var
alice
=
new
Axolotl
.
Account
();
var
bob
=
new
Axolotl
.
Account
();
var
a_session
=
new
Axolotl
.
Session
();
var
b_session
=
new
Axolotl
.
Session
();
var
message_1
;
var
tasks
=
[];
tasks
.
push
([
"
alice
"
,
"
Creating account
"
,
function
()
{
alice
.
create
()
}]);
tasks
.
push
([
"
bob
"
,
"
Creating account
"
,
function
()
{
bob
.
create
()
}]);
tasks
.
push
([
"
alice
"
,
"
Create outbound session
"
,
function
()
{
var
bobs_keys_1
=
JSON
.
parse
(
bob
.
identity_keys
())[
0
];
var
bobs_keys_2
=
JSON
.
parse
(
bob
.
one_time_keys
())[
1
];
a_session
.
create_outbound
(
alice
,
bobs_keys_1
[
1
],
bobs_keys_2
[
0
],
bobs_keys_2
[
1
]
);
}]);
tasks
.
push
([
"
alice
"
,
"
Encrypt first message
"
,
function
()
{
message_1
=
a_session
.
encrypt
(
""
);
}]);
tasks
.
push
([
"
bob
"
,
"
Create inbound session
"
,
function
()
{
b_session
.
create_inbound
(
bob
,
message_1
.
body
);
}]);
tasks
.
push
([
"
bob
"
,
"
Decrypt first message
"
,
function
()
{
b_session
.
decrypt
(
message_1
.
type
,
message_1
.
body
);
}]);
function
glue_encrypt
(
from
,
to
,
from_session
)
{
var
plain_input
=
document
.
getElementById
(
from
+
"
_plain_input
"
);
var
cipher_output
=
document
.
getElementById
(
from
+
"
_cipher_output
"
);
var
cipher_input
=
document
.
getElementById
(
to
+
"
_cipher_input
"
);
var
encrypt
=
document
.
getElementById
(
from
+
"
_encrypt
"
);
encrypt
.
addEventListener
(
"
click
"
,
function
()
{
var
message
=
from_session
.
encrypt
(
plain_input
.
value
);
var
message_element
=
document
.
createElement
(
"
pre
"
);
var
content
=
document
.
createTextNode
(
JSON
.
stringify
(
message
));
message_element
.
appendChild
(
content
);
cipher_output
.
appendChild
(
message_element
);
message_element
.
addEventListener
(
"
click
"
,
function
()
{
cipher_input
.
value
=
JSON
.
stringify
(
message
);
},
false
);
},
false
);
}
function
glue_decrypt
(
to
,
to_session
)
{
var
cipher_input
=
document
.
getElementById
(
to
+
"
_cipher_input
"
);
var
plain_output
=
document
.
getElementById
(
to
+
"
_plain_output
"
);
var
decrypt
=
document
.
getElementById
(
to
+
"
_decrypt
"
);
decrypt
.
addEventListener
(
"
click
"
,
function
()
{
var
message
=
JSON
.
parse
(
cipher_input
.
value
);
try
{
var
plaintext
=
to_session
.
decrypt
(
message
.
type
,
message
.
body
);
}
catch
(
e
)
{
var
plaintext
=
"
ERROR:
"
+
e
.
message
;
}
var
message_element
=
document
.
createElement
(
"
pre
"
);
var
message_content
=
document
.
createTextNode
(
plaintext
);
message_element
.
appendChild
(
message_content
);
plain_output
.
appendChild
(
message_element
);
},
false
);
}
function
do_tasks
(
next
)
{
if
(
tasks
.
length
>
0
)
{
var
task
=
tasks
.
shift
();
var
p
=
progress
(
task
[
0
],
task
[
1
])
p
.
start
();
window
.
setTimeout
(
function
()
{
task
[
2
]();
p
.
done
();
window
.
setTimeout
(
do_tasks
,
0
,
next
);
},
0
)
}
else
{
next
();
}
}
do_tasks
(
function
()
{
glue_encrypt
(
"
alice
"
,
"
bob
"
,
a_session
);
glue_decrypt
(
"
bob
"
,
b_session
);
glue_encrypt
(
"
bob
"
,
"
alice
"
,
b_session
);
glue_decrypt
(
"
alice
"
,
a_session
);
});
},
false
);
</script>
<body>
<div
id=
"alice"
>
<h1>
Alice
</h1>
<div
id=
"alice_progress"
></div>
<h2>
Encryption
</h2>
<textarea
id=
"alice_plain_input"
></textarea>
<button
id=
"alice_encrypt"
>
Encrypt
</button>
<div
id=
"alice_cipher_output"
></div>
<h2>
Decryption
</h2>
<textarea
id=
"alice_cipher_input"
></textarea>
<button
id=
"alice_decrypt"
>
Decrypt
</button>
<div
id=
"alice_plain_output"
></div>
</div>
<div
id=
"bob"
>
<h1>
Bob
</h1>
<div
id=
"bob_progress"
></div>
<h2>
Encryption
</h2>
<textarea
id=
"bob_plain_input"
></textarea>
<button
id=
"bob_encrypt"
>
Encrypt
</button>
<div
id=
"bob_cipher_output"
></div>
<h2>
Decryption
</h2>
<textarea
id=
"bob_cipher_input"
></textarea>
<button
id=
"bob_decrypt"
>
Decrypt
</button>
<div
id=
"bob_plain_output"
></div>
</div>
</body>
</html>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment