Skip to content

Commit

Permalink
feature/data persistence (#1180)
Browse files Browse the repository at this point in the history
- **feat: add documentation and GitHub Actions workflow for publishing
documentation**
- **docs(concepts): add documentation for chain modules**
- **refactor: Simplify session management with SQLite storage and remove
deprecated code**
- **refactor: Simplify database initialization and remove
DatabaseContext**
- **refactor: move connection handling logic to resolver package**
- **feat: implement session management with database persistence**
- **feat: Ensure config directory exists when creating database path**
- **feat: Add SetUserHandle function to set user handle in session**
- **feat: Add public methods to set session fields with database save**
- **refactor: Remove unused session setter functions**
- **feat: Add getter methods for all Session Model properties**
- **feat: enhance Session model with user name details**
- **feat: add Motr support and update UI elements**
- **<no value>**
- **feat: Add unique handle constraint and method to check handle
existence**
- **docs: update site URL to onsonr.dev**
- **fix: correct import statement for database package**
- **test: updated CI to run tests on pull requests and merge groups**
- **docs: remove reference to develop branch in workflow**
- **feat: add WebAuthn support for user registration**
- **fix: correct smart account attenuation preset name**
- **feat: add ComputeIssuerDID and ComputeSonrAddr functions to ucan
package**
- **test: add unit tests for MPC keyset and keyshare**
- **feat: introduce new script to streamline GitHub issue creation**
  • Loading branch information
prnk28 authored Dec 7, 2024
1 parent 94fb4dc commit 38447af
Show file tree
Hide file tree
Showing 47 changed files with 1,964 additions and 697 deletions.
189 changes: 189 additions & 0 deletions .github/scopes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
[
{
"name": "cosmos/sdk",
"path": "app",
"docs": [
"https://docs.cosmos.network/v0.50/build/building-modules/module-manager",
"https://docs.cosmos.network/v0.50/build/building-modules/messages-and-queries",
"https://docs.cosmos.network/v0.50/build/building-modules/msg-services",
"https://docs.cosmos.network/v0.50/build/building-modules/query-services",
"https://docs.cosmos.network/v0.50/build/building-modules/depinject"
]
},
{
"name": "cosmos/ibc",
"path": "app",
"docs": [
"https://ibc.cosmos.network/v8/apps/interchain-accounts/overview/",
"https://ibc.cosmos.network/v8/apps/transfer/overview/",
"https://docs.osmosis.zone/osmosis-core/asset-info/",
"https://docs.osmosis.zone/osmosis-core/modules/tokenfactory",
"https://docs.noble.xyz/cctp/mint",
"https://docs.noble.xyz/cctp/mint_forward",
"https://docs.evmos.org/protocol/modules/erc20",
"https://docs.nomic.io/nbtc"
]
},
{
"name": "crypto/mpc",
"path": "crypto/mpc",
"docs": [
"https://csrc.nist.gov/CSRC/media/Events/NTCW19/papers/paper-DKLS.pdf"
]
},
{
"name": "crypto/ucan",
"path": "crypto/ucan",
"docs": [
"https://raw.githubusercontent.com/ucan-wg/spec/refs/heads/main/README.md"
]
},
{
"name": "crypto/zkp",
"path": "crypto/accumulator",
"docs": [
"https://eprint.iacr.org/2021/1672.pdf"
]
},
{
"name": "gateway/handlers",
"path": "pkg/gateway/handlers",
"docs": [
"https://echo.labstack.com/docs/cookbook/sse",
"https://echo.labstack.com/docs/cookbook/websocket",
"https://echo.labstack.com/docs/cookbook/subdomain"
]
},
{
"name": "gateway/database",
"path": "pkg/gateway/internal/database",
"docs": [
"https://docs.tigerbeetle.com/coding/data-modeling",
"https://docs.tigerbeetle.com/coding/two-phase-transfers",
"https://docs.tigerbeetle.com/coding/reliable-transaction-submission",
"https://docs.tigerbeetle.com/coding/recipes/currency-exchange",
"https://docs.tigerbeetle.com/coding/recipes/balance-conditional-transfers",
"https://docs.tigerbeetle.com/reference/account",
"https://docs.tigerbeetle.com/reference/transfer",
"https://docs.substreams.dev/documentation/consume/packages",
"https://docs.substreams.dev/documentation/consume/sql/deployable-services/local-service",
"https://docs.substreams.dev/tutorials/cosmos/injective/foundational"
]
},
{
"name": "vault/handlers",
"path": "pkg/vault/handlers",
"docs": [
"https://echo.labstack.com/docs/cookbook/jwt",
"https://echo.labstack.com/docs/middleware/secure",
"https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API"
]
},
{
"name": "vault/database",
"path": "pkg/vault/internal/database",
"docs": [
"https://dexie.org/docs/ExportImport/dexie-export-import",
"https://dexie.org/docs/API-Reference#quick-reference",
"https://templ.guide/syntax-and-usage/script-templates"
]
},
{
"name": "pkl/ipfs",
"path": "pkl/ipfs.net",
"docs": [
"https://github.com/ipfs/kubo/blob/master/docs/config.md",
"https://pkl-lang.org/main/current/language-reference/index.html"
]
},
{
"name": "pkl/matrix",
"path": "pkl/matrix.net",
"docs": [
"https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html",
"https://pkl-lang.org/main/current/language-reference/index.html"
]
},
{
"name": "pkl/chain",
"path": "pkl/sonr.chain",
"docs": [
"https://tutorials.cosmos.network/tutorials/9-path-to-prod/5-network.html",
"https://tutorials.cosmos.network/tutorials/9-path-to-prod/4-genesis.html",
"https://pkl-lang.org/main/current/language-reference/index.html",
"https://docs.cosmos.network/v0.50/user/run-node/run-testnet"
]
},
{
"name": "pkl/hway",
"path": "pkl/sonr.hway",
"docs": [
"https://pkl-lang.org/main/current/language-reference/index.html"
]
},
{
"name": "pkl/motr",
"path": "pkl/sonr.motr",
"docs": [
"https://pkl-lang.org/main/current/language-reference/index.html",
"https://web.dev/learn/pwa/service-workers/",
"https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API"
]
},
{
"name": "x/did",
"path": "proto/did",
"docs": [
"https://docs.cosmos.network/v0.50/build/packages/orm",
"https://docs.cosmos.network/v0.50/build/building-modules/protobuf-annotations",
"https://docs.cosmos.network/v0.50/build/modules/auth",
"https://docs.cosmos.network/v0.50/build/packages/collections",
"https://docs.cosmos.network/v0.50/build/modules/bank"
]
},
{
"name": "x/dwn",
"path": "proto/dwn",
"docs": [
"https://docs.cosmos.network/v0.50/build/building-modules/protobuf-annotations",
"https://docs.cosmos.network/v0.50/build/packages/orm",
"https://docs.cosmos.network/v0.50/build/modules/authz",
"https://docs.cosmos.network/v0.50/build/packages/collections",
"https://docs.cosmos.network/v0.50/build/modules/gov",
"https://docs.cosmos.network/v0.50/build/modules/staking"
]
},
{
"name": "x/svc",
"path": "proto/svc",
"docs": [
"https://docs.cosmos.network/v0.50/build/packages/collections",
"https://docs.cosmos.network/v0.50/build/building-modules/protobuf-annotations",
"https://docs.cosmos.network/v0.50/build/packages/orm",
"https://docs.cosmos.network/v0.50/build/modules/group",
"https://docs.cosmos.network/v0.50/build/modules/nft"
]
},
{
"name": "repo/ci-cd",
"path": "deploy",
"docs": [
"https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions",
"https://docs.cosmos.network/v0.50/build/tooling/cosmovisor",
"https://f1bonacc1.github.io/process-compose/configuration/",
"https://docs.nomic.io/network/ibc-relayer",
"https://www.jetify.com/docs/devbox",
"https://taskfile.dev/reference/cli",
"https://taskfile.dev/reference/schema",
"https://taskfile.dev/reference/templating/"
]
},
{
"name": "repo/docs",
"path": "docs",
"docs": [
"https://squidfunk.github.io/mkdocs-material/reference/",
"https://github.com/mkdocs/catalog/blob/main/README.md"
]
}
]
63 changes: 63 additions & 0 deletions .github/scripts/new_issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

set -e

ROOT_DIR=$(git rev-parse --show-toplevel)

# Extract scope name and path using jq, and pass it to fzf for selection
SCOPE=$(cat "$ROOT_DIR/.github/scopes.json" | jq -r '.[] | "\(.name)"' | fzf --prompt "Select scope:")
DOCS=$(cat "$ROOT_DIR/.github/scopes.json" | jq -r ".[] | select(.name == \"$SCOPE\") | .docs[]")

# Write Title
TITLE=$(gum input --placeholder "Issue Title...")

# Write Goal
GOAL=$(mods --role "determine-issue-goal" "$SCOPE $TITLE")

# Input Requirements
REQUIREMENTS=()
while true; do
if [ ${#REQUIREMENTS[@]} -ge 2 ]; then
if ! gum confirm "Do you want to add another requirement?"; then
break
fi
fi
REQUIREMENT=$(gum input --placeholder "Add a requirement...")
if [ -n "$REQUIREMENT" ]; then
REQUIREMENTS+=("$REQUIREMENT")
else
echo "Requirement cannot be empty. Please enter a valid requirement."
fi
done

create_body() {
echo "### Goal(s):"
echo "$GOAL"
echo "### Requirements:"
for i in "${!REQUIREMENTS[@]}"; do
echo "$(($i + 1)). ${REQUIREMENTS[$i]}"
done
echo "### Resources:"
for doc in "${DOCS[@]}"; do
echo "- $doc"
done
}

ISSUE_BODY=$(create_body)

# Function to collect output
preview_output() {
echo "# ($SCOPE) $TITLE"
echo "$ISSUE_BODY"
}

# Display the formatted output
preview_output | gum format

# Confirm to create a GitHub issue
if gum confirm "Do you want to create a new GitHub issue with this information?"; then
# Create a new GitHub issue using the gh CLI
gh issue create --repo onsonr/sonr --title "($SCOPE) $TITLE" --body "$ISSUE_BODY"
else
exit 1
fi
28 changes: 28 additions & 0 deletions .github/workflows/make-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish Docs via GitHub Pages
on:
push:
branches:
- master
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material
- run: cd docs && mkdocs gh-deploy --force
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Run Tests

on:
push:
branches:
- feature/*
pull_request:
merge_group:

jobs:
test-unit:
Expand Down
6 changes: 6 additions & 0 deletions crypto/mpc/keyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type (
)

type Keyset interface {
Address() string
Val() *ValKeyshare
ValJSON() string
User() *UserKeyshare
Expand All @@ -25,6 +26,11 @@ type Keyset interface {
type keyset struct {
val *ValKeyshare
user *UserKeyshare
addr string
}

func (k keyset) Address() string {
return k.addr
}

func (k keyset) Val() *ValKeyshare {
Expand Down
34 changes: 19 additions & 15 deletions crypto/mpc/keyshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,9 @@ import (
"crypto/ecdsa"

"github.com/onsonr/sonr/crypto/core/protocol"
"github.com/onsonr/sonr/crypto/tecdsa/dklsv1/dkg"
)

// Keyshare represents the common interface for both validator and user keyshares
type Keyshare interface {
GetPayloads() map[string][]byte
GetMetadata() map[string]string
GetPublicKey() []byte
GetProtocol() string
GetRole() int32
GetVersion() uint32
ECDSAPublicKey() (*ecdsa.PublicKey, error)
ExtractMessage() *protocol.Message
RefreshFunc() (RefreshFunc, error)
SignFunc(msg []byte) (SignFunc, error)
Marshal() (string, error)
}

// BaseKeyshare contains common fields and methods for both validator and user keyshares
type BaseKeyshare struct {
Message *protocol.Message `json:"message"`
Expand All @@ -29,6 +15,24 @@ type BaseKeyshare struct {
CompressedPubKey []byte `json:"compressed_public_key"`
}

func initFromAlice(aliceOut *dkg.AliceOutput, originalMsg *protocol.Message) BaseKeyshare {
return BaseKeyshare{
Message: originalMsg,
Role: 1,
UncompressedPubKey: aliceOut.PublicKey.ToAffineUncompressed(),
CompressedPubKey: aliceOut.PublicKey.ToAffineCompressed(),
}
}

func initFromBob(bobOut *dkg.BobOutput, originalMsg *protocol.Message) BaseKeyshare {
return BaseKeyshare{
Message: originalMsg,
Role: 2,
UncompressedPubKey: bobOut.PublicKey.ToAffineUncompressed(),
CompressedPubKey: bobOut.PublicKey.ToAffineCompressed(),
}
}

func (b *BaseKeyshare) GetPayloads() map[string][]byte {
return b.Message.Payloads
}
Expand Down
12 changes: 10 additions & 2 deletions crypto/mpc/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func NewKeyset() (Keyset, error) {
if err != nil {
return nil, err
}
return keyset{val: valShare, user: userShare}, nil
addr, err := computeSonrAddr(valShare.CompressedPublicKey())
if err != nil {
return nil, err
}
return keyset{val: valShare, user: userShare, addr: addr}, nil
}

// ExecuteSigning runs the MPC signing protocol
Expand Down Expand Up @@ -73,7 +77,11 @@ func ExecuteRefresh(refreshFuncVal RefreshFunc, refreshFuncUser RefreshFunc) (Ke
if err != nil {
return nil, err
}
return keyset{val: valShare, user: userShare}, nil
addr, err := computeSonrAddr(valShare.CompressedPublicKey())
if err != nil {
return nil, err
}
return keyset{val: valShare, user: userShare, addr: addr}, nil
}

// SerializeSecp256k1Signature serializes an ECDSA signature into a byte slice
Expand Down
Loading

0 comments on commit 38447af

Please sign in to comment.