Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ path = '..'
package = "cesride"

[dependencies]
wasm-bindgen = "0.2.84"
wasm-bindgen = "0.2.88"
js-sys = '0.3'
serde_json = "1.0"

[dev-dependencies]
wasm-bindgen-test = "0.3.38"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be used for headless browser testing


[profile.release]
opt_level = "s"
80 changes: 57 additions & 23 deletions wasm/demo/web/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,61 @@
// Note that a dynamic `import` statement here is required due to
// webpack/webpack#6615, but in theory `import { greet } from './pkg';`
// will work here one day as well!
const wasm = import('cesride-wasm');
import * as cesride from 'cesride-wasm';

wasm
.then(cesride => {
date = cesride.Dater.new_with_dts(dts = "2020-08-22T17:50:09.988921+00:00");
document.write("<p>Date:</p>");
document.write("dts: " + date.dts() + "<br/>");
document.write("dtsb: " + date.dtsb() + "<br/>");
document.write("code: " + date.code() + "<br/>");
document.write("size: " + date.size() + "<br/>");
document.write("raw: " + date.raw() + "<br/>");
document.write("qb64: " + date.qb64() + "<br/>");
document.write("qb64b: " + date.qb64b() + "<br/>");
document.write("qb2: " + date.qb2() + "<br/>");
try {
date = cesride.Dater.new_with_dts(dts = "asdf");
document.write("Wrong date: " + date.dts() + "<br/>");
} catch (error) {
document.write("Error: " + error + "<br/>");
document.write("Error name: " + error.name + "<br/>");
document.write("Error message: " + error.message + "<br/>");
}
})
.catch(console.error);
document.write(`
<style>
body {
background-color: black;
color: #cccccc;
}
</style>
`)

let dts = "2020-08-22T17:50:09.988921+00:00";
let dater = cesride.Dater.new_with_dts(dts);

const icp = {
"v": "KERI10JSON00015a_",
"t": "icp",
"d": "EBAjyPZ8Ed4XXl5cVZhqAy7SuaGivQp0WqQKVXvg7oqd",
"i": "BEy_EvE8OUMqj0AgCJ3wOCOrIVHVtwubYAysPyaAv9VI",
"s": "0",
"kt": "1",
"k": [
"BEy_EvE8OUMqj0AgCJ3wOCOrIVHVtwubYAysPyaAv9VI"
],
"nt": "0",
"n": [],
"bt": "2",
"b": [
"BC9Df6ssUZQFQZJYVUyfudw4WTQsugGcvVD_Z4ChFGE4",
"BEejlxZytU7gjUwtgkmNKmBWiFPKSsXjk_uxzoun8dtK"
],
"c": [],
"a": []
}

const raw = new TextEncoder().encode(JSON.stringify(icp))
const serder = cesride.Serder.new_with_raw(raw)
console.log(serder.saider().qb64())

document.write("<p>Date:</p>");
document.write("<code>")
document.write("dts: " + dater.dts() + "<br/>");
document.write("dtsb: " + dater.dtsb() + "<br/>");
document.write("code: " + dater.code() + "<br/>");
document.write("size: " + dater.size() + "<br/>");
document.write("raw: " + dater.raw() + "<br/>");
document.write("qb64: " + dater.qb64() + "<br/>");
document.write("qb64b: " + dater.qb64b() + "<br/>");
document.write("qb2: " + dater.qb2() + "<br/>");
try {
dater = cesride.Dater.new_with_dts(dts = "asdf");
document.write("Wrong dater: " + dater.dts() + "<br/>");
} catch (error) {
document.write("Error: " + error + "<br/>");
document.write("Error name: " + error.name + "<br/>");
document.write("Error message: " + error.message + "<br/>");
}
document.write("</code>")
Loading