gocrypto
Version:
Cryption library based on Go-WebAssembly
57 lines (50 loc) • 2.17 kB
HTML
<html>
<head>
<meta charset="utf-8"/>
<script src="wasm_exec.js"></script>
<script src="./test/test.js"></script>
<script>
if (WebAssembly) {
// WebAssembly.instantiateStreaming is not currently available in Safari
if (WebAssembly && !WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const g = global || window || self;
if (!g.__gobridge__) {
g.__gobridge__ = {};
}
const go = new Go();
WebAssembly.instantiateStreaming(fetch("DMSGoCrypto.wasm"), go.importObject).then((result) => {
go.run(result.instance);
var testPrivKey, testPubKey, testSigData;
var testMessage = "test message";
generateKey().then(privKey => {
testPrivKey = privKey;
return sign(testMessage, privKey)
}).then(sigData => {
testSigData = sigData
console.log("Get the signature data!");
console.log(sigData);
return getPublicKey(testPrivKey);
}).then(pubKeyData => {
testPubKey = pubKeyData
return verify(testMessage, pubKeyData, testSigData);
}).then(verifyResult => {
console.log("verify result: ")
console.log(verifyResult)
}).catch(error => {
console.log(error);
});
});
} else {
console.log("WebAssembly is not supported in your browser")
}
</script>
</head>
<body>
<h1>DMSGoPGP WASM Playground...</h1>
</body>
</html>