WebAssembly
Getting Started
Basic Setup
-
Include
wasm_exec.js
to your web app<Script src="wasm_exec.js"/> -
Add following code to check the WebAssembly compatibility:
if WebAssembly// WebAssembly.instantiateStreaming is not currently available in Safariif WebAssembly && !WebAssemblyinstantiateStreaming // polyfillWebAssemblyinstantiateStreaming = async {const source = await await resp;return await WebAssembly;}; -
Instantiate and attach a
__gobridge__
object to the global object, DMSCrypto will hook and exports all available function to the__gobridge__
objectconst g = global || window || self;if !g__gobridge__g__gobridge__ = {}; -
Use
WebAssembly.instantiateStreaming
to load and instantiate theDMSGoCrypto.wasm
library:const go = ; // Go provided by the wasm_exec.js to run the GoWasm libraryWebAssembly;
API Reference
Overall API Design
Due to restriction of Go-WebAssembly, all DMSCrypto WebAssembly API is designed to provide a Parameters + Callback
function signature pattern.
Take generateSecp256k1Key
as the example:
__gobridge__;