mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/ipfs vault allocation (#8)
* refactor: move constants to genesis.proto * feat: add ipfs_active flag to genesis state * feat: add IPFS connection initialization to keeper * feat: add testnet process-compose * refactor: rename sonr-testnet docker image to sonr-runner * refactor: update docker-vm-release workflow to use 'latest' tag * feat: add permission to workflows * feat: add new service chain execution * feat: add abstract vault class to pkl * feat: use jetpackio/devbox image for runner * feat: introduce dwn for local service worker * refactor: remove unnecessary dockerfile layers * refactor(deploy): Update Dockerfile to copy go.mod and go.sum from the parent directory * build: move Dockerfile to root directory * build: Add Dockerfile for deployment * feat: Update Dockerfile to work with Go project in parent directory * build: Update docker-compose.yaml to use relative paths * feat: Update docker-compose to work with new image and parent git directory * refactor: remove unnecessary test script * <no value> * feat: add test_node script for running node tests * feat: add IPFS cluster to testnet * feat: add docker image for sonr-runner * fix: typo in export path * feat(did): Add Localhost Registration Enabled Genesis Option * feat: add support for Sqlite DB in vault * feat: improve vault model JSON serialization * feat: support querying HTMX endpoint for DID * feat: Add primary key, unique, default, not null, auto increment, and foreign key field types * feat: Add PublicKey model in pkl/vault.pkl * feat: add frontend server * refactor: move dwn.wasm to vfs directory * feat(frontend): remove frontend server implementation * feat: Add a frontend server and web auth protocol * feat: implement new key types for MPC and ZK proofs * fix: Update enum types and DefaultKeyInfos * fix: correct typo in KeyAlgorithm enum * feat(did): add attestation format validation * feat: Add x/did/builder/extractor.go * feat: Update JWK parsing in x/did/builder/extractor.go * feat: Use github.com/onsonr/sonr/x/did/types package * feat: Extract and format public keys from WebAuthn credentials * feat: Introduce a new `mapToJWK` function to convert a map to a `types.JWK` struct * feat: add support for extracting JWK public keys * feat: remove VerificationMethod struct * refactor: extract public key extraction logic * feat: add helper functions to map COSECurveID to JWK curve names * feat: pin initial vault
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/onsonr/sonr/internal/db"
|
||||
)
|
||||
|
||||
var (
|
||||
kServiceWorkerFileName = "sw.js"
|
||||
kVaultFileName = "vault.wasm"
|
||||
kIndexFileName = "index.html"
|
||||
)
|
||||
|
||||
func Assemble(dir string) error {
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write the vault file
|
||||
if err := writeVaultWASM(filepath.Join(dir, kVaultFileName)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write the service worker file
|
||||
if err := writeServiceWorkerJS(filepath.Join(dir, kServiceWorkerFileName)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write the index file
|
||||
if err := writeIndexHTML(filepath.Join(dir, kIndexFileName)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initialize the database
|
||||
if err := initializeDatabase(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initializeDatabase(dir string) error {
|
||||
db, err := db.Open(db.New(db.WithDir(dir)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open database: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// You can add some initial data here if needed
|
||||
// For example:
|
||||
// err = db.AddChain("Ethereum", "1")
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed to add initial chain: %w", err)
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed vault.wasm
|
||||
var vaultWasmData []byte
|
||||
|
||||
func writeServiceWorkerJS(path string) error {
|
||||
// Create the service worker file
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Write the service worker file to the specified path
|
||||
err = VaultServiceWorker(kVaultFileName).Render(context.Background(), file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeVaultWASM(path string) error {
|
||||
// Create the vault file
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Write the embedded vault file to the specified path
|
||||
err = os.WriteFile(file.Name(), vaultWasmData, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeIndexHTML(path string) error {
|
||||
// create the index file
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// write the index file to the specified path
|
||||
err = IndexHTML().Render(context.Background(), file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package files
|
||||
|
||||
templ VaultServiceWorker(path string) {
|
||||
@serviceWorkerJS(path)
|
||||
}
|
||||
|
||||
script serviceWorkerJS(path string) {
|
||||
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
|
||||
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
|
||||
}
|
||||
|
||||
templ IndexHTML() {
|
||||
<html>
|
||||
<head>
|
||||
<title>Sonr ID</title>
|
||||
<script>
|
||||
navigator.serviceWorker.register('sw.js')
|
||||
registerWasmHTTPListener(path)
|
||||
|
||||
// Skip installed stage and jump to activating stage
|
||||
addEventListener('install', (event) => {
|
||||
event.waitUntil(skipWaiting())
|
||||
})
|
||||
|
||||
// Start controlling clients as soon as the SW is activated
|
||||
addEventListener('activate', event => {
|
||||
event.waitUntil(clients.claim())
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.771
|
||||
package files
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func VaultServiceWorker(path string) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = serviceWorkerJS(path).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func serviceWorkerJS(path string) templ.ComponentScript {
|
||||
return templ.ComponentScript{
|
||||
Name: `__templ_serviceWorkerJS_2501`,
|
||||
Function: `function __templ_serviceWorkerJS_2501(path){importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
|
||||
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
|
||||
}`,
|
||||
Call: templ.SafeScript(`__templ_serviceWorkerJS_2501`, path),
|
||||
CallInline: templ.SafeScriptInline(`__templ_serviceWorkerJS_2501`, path),
|
||||
}
|
||||
}
|
||||
|
||||
func IndexHTML() templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var2 == nil {
|
||||
templ_7745c5c3_Var2 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<html><head><title>Sonr ID</title><script>\n navigator.serviceWorker.register('sw.js')\n registerWasmHTTPListener(path)\n\n // Skip installed stage and jump to activating stage\n addEventListener('install', (event) => {\n event.waitUntil(skipWaiting())\n })\n\n // Start controlling clients as soon as the SW is activated\n addEventListener('activate', event => {\n event.waitUntil(clients.claim())\n })\n </script></head></html>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
package front
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewServeFrontendCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "serve-web",
|
||||
Short: "TUI for managing the local Sonr validator node",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
e := echo.New()
|
||||
if err := e.Start(":42069"); err != http.ErrServerClosed {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1 @@
|
||||
package handlers
|
||||
@@ -0,0 +1 @@
|
||||
package routes
|
||||
@@ -0,0 +1 @@
|
||||
package routes
|
||||
@@ -322,7 +322,7 @@ func RunTUIForm() (*tx.TxBody, error) {
|
||||
return finalM.message, nil
|
||||
}
|
||||
|
||||
func NewBuildProtoMsgCmd() *cobra.Command {
|
||||
func NewTUIDashboardCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "dash",
|
||||
Short: "TUI for managing the local Sonr validator node",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package vfs
|
||||
|
||||
import (
|
||||
"github.com/ipfs/boxo/files"
|
||||
)
|
||||
|
||||
var (
|
||||
kServiceWorkerFileName = "sw.js"
|
||||
kVaultFileName = "vault.wasm"
|
||||
kIndexFileName = "index.html"
|
||||
)
|
||||
|
||||
func AssembleDirectory() files.Directory {
|
||||
fileMap := map[string]files.Node{
|
||||
kVaultFileName: DWNWasmFile(),
|
||||
kServiceWorkerFileName: SWJSFile(),
|
||||
kIndexFileName: IndexHTMLFile(),
|
||||
}
|
||||
|
||||
return files.NewMapDirectory(fileMap)
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
package vfs
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"github.com/ipfs/boxo/files"
|
||||
)
|
||||
|
||||
//go:embed dwn.wasm
|
||||
var dwnWasmData []byte
|
||||
|
||||
func DWNWasmFile() files.Node {
|
||||
return files.NewBytesFile(dwnWasmData)
|
||||
}
|
||||
|
||||
//go:embed sw.js
|
||||
var swJSData []byte
|
||||
|
||||
func SWJSFile() files.Node {
|
||||
return files.NewBytesFile(swJSData)
|
||||
}
|
||||
|
||||
//go:embed index.html
|
||||
var indexHTMLData []byte
|
||||
|
||||
func IndexHTMLFile() files.Node {
|
||||
return files.NewBytesFile(indexHTMLData)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Sonr Vault</title>
|
||||
<script>
|
||||
navigator.serviceWorker.register({ swPath });
|
||||
|
||||
// Skip installed stage and jump to activating stage
|
||||
addEventListener("install", (event) => {
|
||||
event.waitUntil(skipWaiting());
|
||||
});
|
||||
|
||||
// Start controlling clients as soon as the SW is activated
|
||||
addEventListener("activate", (event) => {
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
importScripts(
|
||||
"https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js",
|
||||
);
|
||||
|
||||
importScripts(
|
||||
"https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js",
|
||||
);
|
||||
|
||||
registerWasmHTTPListener("dwn.wasm");
|
||||
Reference in New Issue
Block a user