mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
* 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
177 lines
4.6 KiB
Go
177 lines
4.6 KiB
Go
package builder
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
|
|
"github.com/go-webauthn/webauthn/protocol/webauthncose"
|
|
didv1 "github.com/onsonr/sonr/api/did/v1"
|
|
"github.com/onsonr/sonr/x/did/types"
|
|
)
|
|
|
|
func FormatEC2PublicKey(key *webauthncose.EC2PublicKeyData) (*types.JWK, error) {
|
|
curve, err := GetCOSECurveName(key.Curve)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
jwkMap := map[string]interface{}{
|
|
"kty": "EC",
|
|
"crv": curve,
|
|
"x": base64.RawURLEncoding.EncodeToString(key.XCoord),
|
|
"y": base64.RawURLEncoding.EncodeToString(key.YCoord),
|
|
}
|
|
|
|
return MapToJWK(jwkMap)
|
|
}
|
|
|
|
func FormatRSAPublicKey(key *webauthncose.RSAPublicKeyData) (*types.JWK, error) {
|
|
jwkMap := map[string]interface{}{
|
|
"kty": "RSA",
|
|
"n": base64.RawURLEncoding.EncodeToString(key.Modulus),
|
|
"e": base64.RawURLEncoding.EncodeToString(key.Exponent),
|
|
}
|
|
|
|
return MapToJWK(jwkMap)
|
|
}
|
|
|
|
func FormatOKPPublicKey(key *webauthncose.OKPPublicKeyData) (*types.JWK, error) {
|
|
curve, err := getOKPCurveName(key.Curve)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
jwkMap := map[string]interface{}{
|
|
"kty": "OKP",
|
|
"crv": curve,
|
|
"x": base64.RawURLEncoding.EncodeToString(key.XCoord),
|
|
}
|
|
|
|
return MapToJWK(jwkMap)
|
|
}
|
|
|
|
func MapToJWK(m map[string]interface{}) (*types.JWK, error) {
|
|
jwk := &types.JWK{}
|
|
for k, v := range m {
|
|
switch k {
|
|
case "kty":
|
|
jwk.Kty = v.(string)
|
|
case "crv":
|
|
jwk.Crv = v.(string)
|
|
case "x":
|
|
jwk.X = v.(string)
|
|
case "y":
|
|
jwk.Y = v.(string)
|
|
case "n":
|
|
jwk.N = v.(string)
|
|
case "e":
|
|
jwk.E = v.(string)
|
|
}
|
|
}
|
|
return jwk, nil
|
|
}
|
|
|
|
func GetCOSECurveName(curveID int64) (string, error) {
|
|
switch curveID {
|
|
case int64(webauthncose.P256):
|
|
return "P-256", nil
|
|
case int64(webauthncose.P384):
|
|
return "P-384", nil
|
|
case int64(webauthncose.P521):
|
|
return "P-521", nil
|
|
default:
|
|
return "", fmt.Errorf("unknown curve ID: %d", curveID)
|
|
}
|
|
}
|
|
|
|
func getOKPCurveName(curveID int64) (string, error) {
|
|
switch curveID {
|
|
case int64(webauthncose.Ed25519):
|
|
return "Ed25519", nil
|
|
default:
|
|
return "", fmt.Errorf("unknown OKP curve ID: %d", curveID)
|
|
}
|
|
}
|
|
|
|
func ModulePubKeyToAPI(pk *types.PubKey) *didv1.PubKey {
|
|
return &didv1.PubKey{
|
|
Role: ModuleKeyRoleToAPI(pk.GetRole()),
|
|
Algorithm: ModuleKeyAlgorithmToAPI(pk.GetAlgorithm()),
|
|
Encoding: ModuleKeyEncodingToAPI(pk.GetEncoding()),
|
|
Curve: ModuleKeyCurveToAPI(pk.GetCurve()),
|
|
KeyType: ModuleKeyTypeToAPI(pk.GetKeyType()),
|
|
Raw: pk.GetRaw(),
|
|
}
|
|
}
|
|
|
|
func ModuleKeyRoleToAPI(role types.KeyRole) didv1.KeyRole {
|
|
switch role {
|
|
case types.KeyRole_KEY_ROLE_INVOCATION:
|
|
return didv1.KeyRole_KEY_ROLE_INVOCATION
|
|
case types.KeyRole_KEY_ROLE_ASSERTION:
|
|
return didv1.KeyRole_KEY_ROLE_ASSERTION
|
|
case types.KeyRole_KEY_ROLE_DELEGATION:
|
|
return didv1.KeyRole_KEY_ROLE_DELEGATION
|
|
default:
|
|
return didv1.KeyRole_KEY_ROLE_INVOCATION
|
|
}
|
|
}
|
|
|
|
func ModuleKeyAlgorithmToAPI(algorithm types.KeyAlgorithm) didv1.KeyAlgorithm {
|
|
switch algorithm {
|
|
case types.KeyAlgorithm_KEY_ALGORITHM_ES256K:
|
|
return didv1.KeyAlgorithm_KEY_ALGORITHM_ES256K
|
|
case types.KeyAlgorithm_KEY_ALGORITHM_ES256:
|
|
return didv1.KeyAlgorithm_KEY_ALGORITHM_ES256
|
|
case types.KeyAlgorithm_KEY_ALGORITHM_ES384:
|
|
return didv1.KeyAlgorithm_KEY_ALGORITHM_ES384
|
|
case types.KeyAlgorithm_KEY_ALGORITHM_ES512:
|
|
return didv1.KeyAlgorithm_KEY_ALGORITHM_ES512
|
|
case types.KeyAlgorithm_KEY_ALGORITHM_EDDSA:
|
|
return didv1.KeyAlgorithm_KEY_ALGORITHM_EDDSA
|
|
default:
|
|
return didv1.KeyAlgorithm_KEY_ALGORITHM_ES256K
|
|
}
|
|
}
|
|
|
|
func ModuleKeyCurveToAPI(curve types.KeyCurve) didv1.KeyCurve {
|
|
switch curve {
|
|
case types.KeyCurve_KEY_CURVE_P256:
|
|
return didv1.KeyCurve_KEY_CURVE_P256
|
|
case types.KeyCurve_KEY_CURVE_SECP256K1:
|
|
return didv1.KeyCurve_KEY_CURVE_SECP256K1
|
|
case types.KeyCurve_KEY_CURVE_BLS12381:
|
|
return didv1.KeyCurve_KEY_CURVE_BLS12381
|
|
case types.KeyCurve_KEY_CURVE_KECCAK256:
|
|
return didv1.KeyCurve_KEY_CURVE_KECCAK256
|
|
default:
|
|
return didv1.KeyCurve_KEY_CURVE_P256
|
|
}
|
|
}
|
|
|
|
func ModuleKeyEncodingToAPI(encoding types.KeyEncoding) didv1.KeyEncoding {
|
|
switch encoding {
|
|
case types.KeyEncoding_KEY_ENCODING_RAW:
|
|
return didv1.KeyEncoding_KEY_ENCODING_RAW
|
|
case types.KeyEncoding_KEY_ENCODING_HEX:
|
|
return didv1.KeyEncoding_KEY_ENCODING_HEX
|
|
case types.KeyEncoding_KEY_ENCODING_MULTIBASE:
|
|
return didv1.KeyEncoding_KEY_ENCODING_MULTIBASE
|
|
default:
|
|
return didv1.KeyEncoding_KEY_ENCODING_RAW
|
|
}
|
|
}
|
|
|
|
func ModuleKeyTypeToAPI(keyType types.KeyType) didv1.KeyType {
|
|
switch keyType {
|
|
case types.KeyType_KEY_TYPE_BIP32:
|
|
return didv1.KeyType_KEY_TYPE_BIP32
|
|
case types.KeyType_KEY_TYPE_ZK:
|
|
return didv1.KeyType_KEY_TYPE_ZK
|
|
case types.KeyType_KEY_TYPE_WEBAUTHN:
|
|
return didv1.KeyType_KEY_TYPE_WEBAUTHN
|
|
default:
|
|
return didv1.KeyType_KEY_TYPE_BIP32
|
|
}
|
|
}
|