2024-11-23 01:28:58 -05:00
|
|
|
//go:build js && wasm
|
|
|
|
|
// +build js,wasm
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-12-02 14:27:18 -05:00
|
|
|
"encoding/json"
|
|
|
|
|
"syscall/js"
|
|
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
2024-12-10 12:52:19 -05:00
|
|
|
"github.com/onsonr/sonr/internal/vault"
|
2024-12-11 12:26:48 -05:00
|
|
|
"github.com/onsonr/sonr/pkg/common/wasm"
|
|
|
|
|
"github.com/onsonr/sonr/pkg/config/motr"
|
2024-12-09 18:39:57 -05:00
|
|
|
"github.com/onsonr/sonr/pkg/didauth/controller"
|
2024-11-23 01:28:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2024-12-11 12:26:48 -05:00
|
|
|
env *motr.Environment
|
|
|
|
|
config *motr.Config
|
2024-11-23 01:28:58 -05:00
|
|
|
err error
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-02 14:27:18 -05:00
|
|
|
func broadcastTx(this js.Value, args []js.Value) interface{} {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func simulateTx(this js.Value, args []js.Value) interface{} {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func processConfig(this js.Value, args []js.Value) interface{} {
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configString := args[0].String()
|
|
|
|
|
if err := json.Unmarshal([]byte(configString), &config); err != nil {
|
|
|
|
|
println("Error parsing config:", err.Error())
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 01:28:58 -05:00
|
|
|
func main() {
|
|
|
|
|
// Load dwn config
|
2024-12-02 14:27:18 -05:00
|
|
|
js.Global().Set("broadcastTx", js.FuncOf(broadcastTx))
|
|
|
|
|
js.Global().Set("simulateTx", js.FuncOf(simulateTx))
|
|
|
|
|
js.Global().Set("processConfig", js.FuncOf(processConfig))
|
|
|
|
|
|
|
|
|
|
e := echo.New()
|
2024-12-11 12:26:48 -05:00
|
|
|
e.Use(wasm.ContextMiddleware)
|
2024-12-09 18:24:27 -05:00
|
|
|
e.Use(controller.Middleware(nil))
|
2024-12-05 20:36:58 -05:00
|
|
|
vault.RegisterRoutes(e, config)
|
2024-12-11 12:26:48 -05:00
|
|
|
wasm.ServeFetch(e)
|
2024-11-23 01:28:58 -05:00
|
|
|
}
|