mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
develop
This commit is contained in:
@@ -95,13 +95,6 @@ endif
|
|||||||
install: go.sum
|
install: go.sum
|
||||||
go install -mod=readonly $(BUILD_FLAGS) ./cmd/sonrd
|
go install -mod=readonly $(BUILD_FLAGS) ./cmd/sonrd
|
||||||
|
|
||||||
deps:
|
|
||||||
@echo "(go) Installing go dependencies"
|
|
||||||
@which air > /dev/null || go install github.com/air-verse/air@latest
|
|
||||||
@which templ > /dev/null || go install github.com/a-h/templ/cmd/templ@latest
|
|
||||||
@which xcaddy > /dev/null || go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
|
|
||||||
@mkdir -p ./bin
|
|
||||||
@[ ! -f ./bin/caddy ] && xcaddy build --with github.com/caddy-dns/cloudflare && mv ./caddy ./bin/caddy || echo "Caddy already exists"
|
|
||||||
########################################
|
########################################
|
||||||
### Tools & dependencies
|
### Tools & dependencies
|
||||||
|
|
||||||
@@ -316,6 +309,7 @@ motr:
|
|||||||
|
|
||||||
templ:
|
templ:
|
||||||
@echo "(templ) Generating templ files"
|
@echo "(templ) Generating templ files"
|
||||||
|
go install github.com/a-h/templ/cmd/templ@latest
|
||||||
templ generate
|
templ generate
|
||||||
|
|
||||||
pkl:
|
pkl:
|
||||||
@@ -325,6 +319,11 @@ pkl:
|
|||||||
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/web.pkl
|
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/web.pkl
|
||||||
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/txns.pkl
|
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/txns.pkl
|
||||||
|
|
||||||
|
air:
|
||||||
|
@echo "(air) Building air"
|
||||||
|
go install github.com/air-verse/air@latest
|
||||||
|
air -c ./deploy/air.toml
|
||||||
|
|
||||||
ipfs-cluster-start:
|
ipfs-cluster-start:
|
||||||
@echo "(ipfs) Starting ipfs-cluster"
|
@echo "(ipfs) Starting ipfs-cluster"
|
||||||
ipfs-cluster-service init --consensus crdt
|
ipfs-cluster-service init --consensus crdt
|
||||||
@@ -332,6 +331,10 @@ ipfs-cluster-start:
|
|||||||
|
|
||||||
xcaddy:
|
xcaddy:
|
||||||
@echo "(proxy) Starting caddy"
|
@echo "(proxy) Starting caddy"
|
||||||
|
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
|
||||||
|
mkdir -p ./bin
|
||||||
|
xcaddy build --with github.com/caddy-dns/cloudflare
|
||||||
|
mv ./caddy ./bin/caddy
|
||||||
# ./bin/caddy adapt ./config/caddy/Caddyfile > ./config/caddy/caddy.json
|
# ./bin/caddy adapt ./config/caddy/Caddyfile > ./config/caddy/caddy.json
|
||||||
./bin/caddy run --config ./config/caddy/caddy.json
|
./bin/caddy run --config ./config/caddy/caddy.json
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ version: "0.6"
|
|||||||
processes:
|
processes:
|
||||||
sonr:
|
sonr:
|
||||||
namespace: testnet
|
namespace: testnet
|
||||||
command: "devbox run sonr"
|
command: "devbox run serve:sonr"
|
||||||
restart: on_failure
|
restart: on_failure
|
||||||
max_restarts: 3
|
max_restarts: 3
|
||||||
depends:
|
depends:
|
||||||
|
|
||||||
caddy:
|
caddy:
|
||||||
namespace: testnet
|
namespace: testnet
|
||||||
command: "devbox run xcaddy"
|
command: "devbox run serve:xcaddy"
|
||||||
restart: on_failure
|
restart: on_failure
|
||||||
max_restarts: 3
|
max_restarts: 3
|
||||||
depends:
|
depends:
|
||||||
@@ -18,7 +18,7 @@ processes:
|
|||||||
|
|
||||||
air:
|
air:
|
||||||
namespace: testnet
|
namespace: testnet
|
||||||
command: "devbox run air"
|
command: "devbox run serve:air"
|
||||||
restart: on_failure
|
restart: on_failure
|
||||||
max_restarts: 3
|
max_restarts: 3
|
||||||
depends:
|
depends:
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ version: "0.6"
|
|||||||
processes:
|
processes:
|
||||||
sonr:
|
sonr:
|
||||||
namespace: testnet
|
namespace: testnet
|
||||||
command: "make sh-testnet"
|
command: "devbox run serve:sonr"
|
||||||
restart: on_failure
|
restart: on_failure
|
||||||
max_restarts: 3
|
max_restarts: 3
|
||||||
depends:
|
depends:
|
||||||
|
|
||||||
caddy:
|
caddy:
|
||||||
namespace: testnet
|
namespace: testnet
|
||||||
command: "make xcaddy"
|
command: "devbox run serve:xcaddy"
|
||||||
restart: on_failure
|
restart: on_failure
|
||||||
max_restarts: 3
|
max_restarts: 3
|
||||||
depends:
|
depends:
|
||||||
|
|||||||
+12
-15
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
|
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
|
||||||
"packages": [
|
"packages": [
|
||||||
"go@1.22",
|
|
||||||
"bun@latest",
|
"bun@latest",
|
||||||
"ipfs-cluster@latest",
|
"go@1.22",
|
||||||
|
"gum@latest",
|
||||||
"process-compose@latest"
|
"process-compose@latest"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
@@ -24,9 +24,6 @@
|
|||||||
"install": [
|
"install": [
|
||||||
"make install"
|
"make install"
|
||||||
],
|
],
|
||||||
"install:deps": [
|
|
||||||
"make deps"
|
|
||||||
],
|
|
||||||
"build": [
|
"build": [
|
||||||
"make build"
|
"make build"
|
||||||
],
|
],
|
||||||
@@ -48,20 +45,20 @@
|
|||||||
"gen:templ": [
|
"gen:templ": [
|
||||||
"make templ"
|
"make templ"
|
||||||
],
|
],
|
||||||
"serve:local": [
|
"serve:air": [
|
||||||
"process-compose -f ./deploy/process-compose.dev.yaml"
|
"make air"
|
||||||
],
|
],
|
||||||
"serve:testnet": [
|
"serve:xcaddy": [
|
||||||
"process-compose -f ./deploy/process-compose.yaml"
|
|
||||||
],
|
|
||||||
"air": [
|
|
||||||
"air -c ./deploy/air.toml"
|
|
||||||
],
|
|
||||||
"xcaddy": [
|
|
||||||
"make xcaddy"
|
"make xcaddy"
|
||||||
],
|
],
|
||||||
"sonr": [
|
"serve:sonr": [
|
||||||
"make sh-testnet"
|
"make sh-testnet"
|
||||||
|
],
|
||||||
|
"local": [
|
||||||
|
"process-compose -f ./deploy/process-compose.dev.yaml"
|
||||||
|
],
|
||||||
|
"testnet": [
|
||||||
|
"process-compose -f ./deploy/process-compose.yaml"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package builder
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/cosmos/cosmos-sdk/types/bech32"
|
|
||||||
"github.com/ipfs/boxo/files"
|
|
||||||
"github.com/onsonr/crypto/mpc"
|
|
||||||
"github.com/onsonr/sonr/pkg/vault"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Vault struct {
|
|
||||||
FS files.Node
|
|
||||||
ValKs mpc.Share
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewVault(subject string, origin string, chainID string) (*Vault, error) {
|
|
||||||
shares, err := mpc.GenerateKeyshares()
|
|
||||||
var (
|
|
||||||
valKs = shares[0]
|
|
||||||
usrKs = shares[1]
|
|
||||||
)
|
|
||||||
usrKsJSON, err := usrKs.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sonrAddr, err := bech32.ConvertAndEncode("idx", valKs.GetPublicKey())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cnfg := vault.NewConfig(usrKsJSON, sonrAddr, chainID, DefaultSchema())
|
|
||||||
cnfgFile, err := vault.MarshalConfigFile(cnfg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
idxFile, err := vault.IndexHTMLFile(cnfg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fileMap := map[string]files.Node{
|
|
||||||
"config.json": cnfgFile,
|
|
||||||
"motr.mjs": vault.MotrMJSFile(),
|
|
||||||
"sw.js": vault.SWJSFile(),
|
|
||||||
"app.wasm": vault.DWNWasmFile(),
|
|
||||||
"index.html": idxFile,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Vault{
|
|
||||||
FS: files.NewMapDirectory(fileMap),
|
|
||||||
ValKs: valKs,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
+32
-15
@@ -20,6 +20,12 @@ var motrMJSData []byte
|
|||||||
//go:embed sw.js
|
//go:embed sw.js
|
||||||
var swJSData []byte
|
var swJSData []byte
|
||||||
|
|
||||||
|
var (
|
||||||
|
dwnWasmFile = files.NewBytesFile(dwnWasmData)
|
||||||
|
motrMJSFile = files.NewBytesFile(motrMJSData)
|
||||||
|
swJSFile = files.NewBytesFile(swJSData)
|
||||||
|
)
|
||||||
|
|
||||||
// NewConfig uses the config template to generate the dwn config file
|
// NewConfig uses the config template to generate the dwn config file
|
||||||
func NewConfig(keyshareJSON string, adddress string, chainID string, schema *dwn.Schema) *dwn.Config {
|
func NewConfig(keyshareJSON string, adddress string, chainID string, schema *dwn.Schema) *dwn.Config {
|
||||||
dwnCfg := &dwn.Config{
|
dwnCfg := &dwn.Config{
|
||||||
@@ -31,6 +37,32 @@ func NewConfig(keyshareJSON string, adddress string, chainID string, schema *dwn
|
|||||||
return dwnCfg
|
return dwnCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewVaultDirectory creates a new directory with the default files
|
||||||
|
func NewVaultDirectory(cnfg *dwn.Config) (files.Node, error) {
|
||||||
|
dwnJSON, err := json.Marshal(cnfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dwnStr, err := templ.JSONString(cnfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
w := bytes.NewBuffer(nil)
|
||||||
|
err = indexFile(dwnStr).Render(context.Background(), w)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fileMap := map[string]files.Node{
|
||||||
|
"config.json": files.NewBytesFile(dwnJSON),
|
||||||
|
"motr.mjs": motrMJSFile,
|
||||||
|
"sw.js": swJSFile,
|
||||||
|
"app.wasm": dwnWasmFile,
|
||||||
|
"index.html": files.NewBytesFile(w.Bytes()),
|
||||||
|
}
|
||||||
|
return files.NewMapDirectory(fileMap), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Use IndexHTML template to generate the index file
|
// Use IndexHTML template to generate the index file
|
||||||
func IndexHTMLFile(c *dwn.Config) (files.Node, error) {
|
func IndexHTMLFile(c *dwn.Config) (files.Node, error) {
|
||||||
str, err := templ.JSONString(c)
|
str, err := templ.JSONString(c)
|
||||||
@@ -55,21 +87,6 @@ func MarshalConfigFile(c *dwn.Config) (files.Node, error) {
|
|||||||
return files.NewBytesFile(dwnConfigData), nil
|
return files.NewBytesFile(dwnConfigData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use DWNWasm template to generate the dwn wasm file
|
|
||||||
func DWNWasmFile() files.Node {
|
|
||||||
return files.NewBytesFile(dwnWasmData)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use MotrMJS template to generate the dwn wasm file
|
|
||||||
func MotrMJSFile() files.Node {
|
|
||||||
return files.NewBytesFile(motrMJSData)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use ServiceWorkerJS template to generate the service worker file
|
|
||||||
func SWJSFile() files.Node {
|
|
||||||
return files.NewBytesFile(swJSData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func createMotrConfig(keyshareJSON string, adddress string, origin string) *dwn.Motr {
|
func createMotrConfig(keyshareJSON string, adddress string, origin string) *dwn.Motr {
|
||||||
return &dwn.Motr{
|
return &dwn.Motr{
|
||||||
Keyshare: keyshareJSON,
|
Keyshare: keyshareJSON,
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ templ indexFile(cfg string) {
|
|||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templ serviceWorker() {
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
script initializeMotr(config string) {
|
script initializeMotr(config string) {
|
||||||
const motr = new Motr(JSON.parse(config));
|
const motr = new Motr(JSON.parse(config));
|
||||||
|
|
||||||
@@ -100,7 +105,6 @@ script initializeMotr(config string) {
|
|||||||
document.getElementById('output').innerHTML = `<p>Error: ${error.message}</p>`;
|
document.getElementById('output').innerHTML = `<p>Error: ${error.message}</p>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the demo when the page loads
|
// Run the demo when the page loads
|
||||||
window.onload = demo;
|
window.onload = demo;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ importScripts(
|
|||||||
"https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js",
|
"https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js",
|
||||||
);
|
);
|
||||||
|
|
||||||
registerWasmHTTPListener("app.wasm");
|
registerWasmHTTPListener("/app.wasm");
|
||||||
|
|
||||||
// Skip installed stage and jump to activating stage
|
// Skip installed stage and jump to activating stage
|
||||||
self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
|
|||||||
@@ -1,11 +1,50 @@
|
|||||||
package builder
|
package vault
|
||||||
|
|
||||||
import "github.com/onsonr/sonr/config/dwn"
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/types/bech32"
|
||||||
|
"github.com/ipfs/boxo/files"
|
||||||
|
"github.com/onsonr/crypto/mpc"
|
||||||
|
"github.com/onsonr/sonr/config/dwn"
|
||||||
|
)
|
||||||
|
|
||||||
type SchemaVersion = int
|
type SchemaVersion = int
|
||||||
|
|
||||||
var CurrentSchemaVersion SchemaVersion = 1
|
var CurrentSchemaVersion SchemaVersion = 1
|
||||||
|
|
||||||
|
type Vault struct {
|
||||||
|
FS files.Node
|
||||||
|
ValKs mpc.Share
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(subject string, origin string, chainID string) (*Vault, error) {
|
||||||
|
shares, err := mpc.GenerateKeyshares()
|
||||||
|
var (
|
||||||
|
valKs = shares[0]
|
||||||
|
usrKs = shares[1]
|
||||||
|
)
|
||||||
|
usrKsJSON, err := usrKs.Marshal()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sonrAddr, err := bech32.ConvertAndEncode("idx", valKs.GetPublicKey())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cnfg := NewConfig(usrKsJSON, sonrAddr, chainID, DefaultSchema())
|
||||||
|
|
||||||
|
fileMap, err := NewVaultDirectory(cnfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Vault{
|
||||||
|
FS: fileMap,
|
||||||
|
ValKs: valKs,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func DefaultSchema() *dwn.Schema {
|
func DefaultSchema() *dwn.Schema {
|
||||||
return &dwn.Schema{
|
return &dwn.Schema{
|
||||||
Version: CurrentSchemaVersion,
|
Version: CurrentSchemaVersion,
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/ipfs/boxo/path"
|
"github.com/ipfs/boxo/path"
|
||||||
"github.com/ipfs/kubo/client/rpc"
|
"github.com/ipfs/kubo/client/rpc"
|
||||||
"github.com/ipfs/kubo/core/coreiface/options"
|
"github.com/ipfs/kubo/core/coreiface/options"
|
||||||
"github.com/onsonr/sonr/pkg/builder"
|
"github.com/onsonr/sonr/pkg/vault"
|
||||||
"github.com/onsonr/sonr/x/did/types"
|
"github.com/onsonr/sonr/x/did/types"
|
||||||
"google.golang.org/grpc/peer"
|
"google.golang.org/grpc/peer"
|
||||||
"gopkg.in/macaroon.v2"
|
"gopkg.in/macaroon.v2"
|
||||||
@@ -32,7 +32,7 @@ type Context struct {
|
|||||||
|
|
||||||
// AssembleVault assembles the initial vault
|
// AssembleVault assembles the initial vault
|
||||||
func (k Keeper) AssembleVault(ctx Context, subject string, origin string) (string, int64, error) {
|
func (k Keeper) AssembleVault(ctx Context, subject string, origin string) (string, int64, error) {
|
||||||
v, err := builder.NewVault(subject, origin, "sonr-testnet")
|
v, err := vault.New(subject, origin, "sonr-testnet")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user