sonr/x/did/builder/service.go
Prad Nukala 4f2d342649
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
2024-09-07 18:12:58 -04:00

103 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package builder
import (
"crypto/rand"
"github.com/onsonr/sonr/x/did/types"
)
// ChallengeLength - Length of bytes to generate for a challenge.
const ChallengeLength = 32
// CreateChallenge creates a new challenge that should be signed and returned by the authenticator. The spec recommends
// using at least 16 bytes with 100 bits of entropy. We use 32 bytes.
func CreateChallenge() (challenge URLEncodedBase64, err error) {
challenge = make([]byte, ChallengeLength)
if _, err = rand.Read(challenge); err != nil {
return nil, err
}
return challenge, nil
}
type CredentialEntity struct {
// A human-palatable name for the entity. Its function depends on what the PublicKeyCredentialEntity represents:
//
// When inherited by PublicKeyCredentialRpEntity it is a human-palatable identifier for the Relying Party,
// intended only for display. For example, "ACME Corporation", "Wonderful Widgets, Inc." or "ОАО Примертех".
//
// When inherited by PublicKeyCredentialUserEntity, it is a human-palatable identifier for a user account. It is
// intended only for display, i.e., aiding the user in determining the difference between user accounts with similar
// displayNames. For example, "alexm", "alex.p.mueller@example.com" or "+14255551234".
Name string `json:"name"`
}
func NewCredentialEntity(name string) CredentialEntity {
return CredentialEntity{
Name: name,
}
}
type CredentialParameter struct {
Type CredentialType `json:"type"`
Algorithm types.COSEAlgorithmIdentifier `json:"alg"`
}
func NewCredentialParameter(ki *types.KeyInfo) CredentialParameter {
return CredentialParameter{
Type: CredentialTypePublicKeyCredential,
Algorithm: ki.Algorithm.CoseIdentifier(),
}
}
func ExtractCredentialParameters(p *types.Params) []CredentialParameter {
var keys []*types.KeyInfo
for _, v := range p.AllowedPublicKeys {
if v.Role == types.KeyRole_KEY_ROLE_AUTHENTICATION {
keys = append(keys, v)
}
}
var cparams []CredentialParameter
for _, ki := range keys {
cparams = append(cparams, NewCredentialParameter(ki))
}
return cparams
}
type RelyingPartyEntity struct {
CredentialEntity
// A unique identifier for the Relying Party entity, which sets the RP ID.
ID string `json:"id"`
}
func NewRelayingParty(name string, origin string) RelyingPartyEntity {
return RelyingPartyEntity{
CredentialEntity: NewCredentialEntity(origin),
ID: origin,
}
}
type UserEntity struct {
CredentialEntity
// A human-palatable name for the user account, intended only for display.
// For example, "Alex P. Müller" or "田中 倫". The Relying Party SHOULD let
// the user choose this, and SHOULD NOT restrict the choice more than necessary.
DisplayName string `json:"displayName"`
// ID is the user handle of the user account entity. To ensure secure operation,
// authentication and authorization decisions MUST be made on the basis of this id
// member, not the displayName nor name members. See Section 6.1 of
// [RFC8266](https://www.w3.org/TR/webauthn/#biblio-rfc8266).
ID any `json:"id"`
}
func NewUserEntity(name string, subject string, cid string) UserEntity {
return UserEntity{
CredentialEntity: NewCredentialEntity(name),
DisplayName: subject,
ID: cid,
}
}