mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
- **refactor: move session-related code to middleware package** - **refactor: update PKL build process and adjust related configurations** - **feat: integrate base.cosmos.v1 Genesis module** - **refactor: pass session context to modal rendering functions** - **refactor: move nebula package to app directory and update templ version** - **refactor: Move home section video view to dedicated directory** - **refactor: remove unused views file** - **refactor: move styles and UI components to global scope** - **refactor: Rename images.go to cdn.go** - **feat: Add Empty State Illustrations** - **refactor: Consolidate Vault Index Logic** - **fix: References to App.wasm and remove Vault Directory embedded CDN files** - **refactor: Move CDN types to Models** - **fix: Correct line numbers in templ error messages for arch_templ.go** - **refactor: use common types for peer roles** - **refactor: move common types and ORM to a shared package** - **fix: Config import dwn** - **refactor: move nebula directory to app** - **feat: Rebuild nebula** - **fix: correct file paths in panels templates** - **feat: Remove duplicate types** - **refactor: Move dwn to pkg/core** - **refactor: Binary Structure** - **feat: Introduce Crypto Pkg** - **fix: Broken Process Start** - **feat: Update pkg/* structure** - **feat: Refactor PKL Structure** - **build: update pkl build process** - **chore: Remove Empty Files** - **refactor: remove unused macaroon package** - **feat: Add WebAwesome Components** - **refactor: consolidate build and generation tasks into a single taskfile, remove redundant makefile targets** - **refactor: refactor server and move components to pkg/core/dwn** - **build: update go modules** - **refactor: move gateway logic into dedicated hway command** - **feat: Add KSS (Krawczyk-Song-Song) MPC cryptography module** - **feat: Implement MPC-based JWT signing and UCAN token generation** - **feat: add support for MPC-based JWT signing** - **feat: Implement MPC-based UCAN capabilities for smart accounts** - **feat: add address field to keyshareSource** - **feat: Add comprehensive MPC test suite for keyshares, UCAN tokens, and token attenuations** - **refactor: improve MPC keyshare management and signing process** - **feat: enhance MPC capability hierarchy documentation** - **refactor: rename GenerateKeyshares function to NewKeyshareSource for clarity** - **refactor: remove unused Ethereum address computation** - **feat: Add HasHandle and IsAuthenticated methods to HTTPContext** - **refactor: Add context.Context support to session HTTPContext** - **refactor: Resolve context interface conflicts in HTTPContext** - **feat: Add session ID context key and helper functions** - **feat: Update WebApp Page Rendering** - **refactor: Simplify context management by using single HTTPContext key** - **refactor: Simplify HTTPContext creation and context management in session middleware** - **refactor: refactor session middleware to use a single data structure** - **refactor: Simplify HTTPContext implementation and session data handling** - **refactor: Improve session context handling and prevent nil pointer errors** - **refactor: Improve session context handling with nil safety and type support** - **refactor: improve session data injection** - **feat: add full-screen modal component and update registration flow** - **chore: add .air.toml to .gitignore** - **feat: add Air to devbox and update dependencies**
113 lines
2.7 KiB
Go
113 lines
2.7 KiB
Go
package mpc
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/ucan-wg/go-ucan"
|
|
)
|
|
|
|
type KeyshareSource interface {
|
|
ucan.Source
|
|
|
|
Address() string
|
|
Issuer() string
|
|
DefaultOriginToken() (*Token, error)
|
|
PublicKey() []byte
|
|
TokenParser() *ucan.TokenParser
|
|
SignData(data []byte) ([]byte, error)
|
|
VerifyData(data []byte, sig []byte) (bool, error)
|
|
}
|
|
|
|
func createKeyshareSource(val *ValKeyshare, user *UserKeyshare) (KeyshareSource, error) {
|
|
iss, addr, err := ComputeIssuerDID(val.GetPublicKey())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return keyshareSource{
|
|
userShare: user,
|
|
valShare: val,
|
|
addr: addr,
|
|
issuerDID: iss,
|
|
}, nil
|
|
}
|
|
|
|
// Address returns the address of the keyshare
|
|
func (k keyshareSource) Address() string {
|
|
return k.addr
|
|
}
|
|
|
|
// Issuer returns the DID of the issuer of the keyshare
|
|
func (k keyshareSource) Issuer() string {
|
|
return k.issuerDID
|
|
}
|
|
|
|
// PublicKey returns the public key of the keyshare
|
|
func (k keyshareSource) PublicKey() []byte {
|
|
return k.valShare.PublicKey
|
|
}
|
|
|
|
// DefaultOriginToken returns a default token with the keyshare's issuer as the audience
|
|
func (k keyshareSource) DefaultOriginToken() (*Token, error) {
|
|
caps := NewSmartAccountCapabilities()
|
|
att := CreateSmartAccountAttenuations(caps, k.addr)
|
|
zero := time.Time{}
|
|
return k.NewOriginToken(k.issuerDID, att, nil, zero, zero)
|
|
}
|
|
|
|
// TokenParser returns a token parser that can be used to parse tokens
|
|
func (k keyshareSource) TokenParser() *ucan.TokenParser {
|
|
caps := NewSmartAccountCapabilities()
|
|
ac := func(m map[string]interface{}) (ucan.Attenuation, error) {
|
|
var (
|
|
cap string
|
|
rsc ucan.Resource
|
|
)
|
|
for key, vali := range m {
|
|
val, ok := vali.(string)
|
|
if !ok {
|
|
return ucan.Attenuation{}, fmt.Errorf(`expected attenuation value to be a string`)
|
|
}
|
|
|
|
if key == ucan.CapKey {
|
|
cap = val
|
|
} else {
|
|
rsc = ucan.NewStringLengthResource(key, val)
|
|
}
|
|
}
|
|
|
|
return ucan.Attenuation{
|
|
Rsc: rsc,
|
|
Cap: caps.Cap(cap),
|
|
}, nil
|
|
}
|
|
|
|
store := ucan.NewMemTokenStore()
|
|
return ucan.NewTokenParser(ac, ucan.StringDIDPubKeyResolver{}, store.(ucan.CIDBytesResolver))
|
|
}
|
|
|
|
func (k keyshareSource) SignData(data []byte) ([]byte, error) {
|
|
|
|
// Create signing functions
|
|
signFunc, err := k.userShare.SignFunc(data)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create sign function: %w", err)
|
|
}
|
|
|
|
valSignFunc, err := k.valShare.SignFunc(data)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create validator sign function: %w", err)
|
|
}
|
|
|
|
// Run the signing protocol
|
|
sig, err := RunSignProtocol(valSignFunc, signFunc)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to run sign protocol: %w", err)
|
|
}
|
|
return SerializeSignature(sig)
|
|
}
|
|
|
|
func (k keyshareSource) VerifyData(data []byte, sig []byte) (bool, error) {
|
|
return VerifySignature(k.userShare.PublicKey, data, sig)
|
|
}
|