mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
(no commit message provided)
This commit is contained in:
committed by
Prad Nukala (aider)
parent
5fd43dfd6b
commit
2f976209db
@@ -1,44 +0,0 @@
|
||||
package orm
|
||||
|
||||
import "github.com/go-webauthn/webauthn/protocol"
|
||||
|
||||
// Authenticator contains all needed information about an authenticator for storage.
|
||||
type Authenticator struct {
|
||||
Attachment protocol.AuthenticatorAttachment `json:"attachment"`
|
||||
AAGUID []byte `json:"AAGUID"`
|
||||
SignCount uint32 `json:"signCount"`
|
||||
CloneWarning bool `json:"cloneWarning"`
|
||||
}
|
||||
|
||||
// SelectAuthenticator allow for easy marshaling of authenticator options that are provided to the user.
|
||||
func SelectAuthenticator(att string, rrk *bool, uv string) protocol.AuthenticatorSelection {
|
||||
return protocol.AuthenticatorSelection{
|
||||
AuthenticatorAttachment: protocol.AuthenticatorAttachment(att),
|
||||
RequireResidentKey: rrk,
|
||||
UserVerification: protocol.UserVerificationRequirement(uv),
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateCounter updates the authenticator and either sets the clone warning value or the sign count.
|
||||
//
|
||||
// Step 17 of §7.2. about verifying attestation. If the signature counter value authData.signCount
|
||||
// is nonzero or the value stored in conjunction with credential’s id attribute is nonzero, then
|
||||
// run the following sub-step:
|
||||
//
|
||||
// If the signature counter value authData.signCount is
|
||||
//
|
||||
// → Greater than the signature counter value stored in conjunction with credential’s id attribute.
|
||||
// Update the stored signature counter value, associated with credential’s id attribute, to be the value of
|
||||
// authData.signCount.
|
||||
//
|
||||
// → Less than or equal to the signature counter value stored in conjunction with credential’s id attribute.
|
||||
// This is a signal that the authenticator may be cloned, see CloneWarning above for more information.
|
||||
func (a *Authenticator) UpdateCounter(authDataCount uint32) {
|
||||
if authDataCount <= a.SignCount && (authDataCount != 0 || a.SignCount != 0) {
|
||||
a.CloneWarning = true
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
a.SignCount = authDataCount
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CredentialFlags struct {
|
||||
// Flag UP indicates the users presence.
|
||||
UserPresent bool `json:"userPresent"`
|
||||
|
||||
// Flag UV indicates the user performed verification.
|
||||
UserVerified bool `json:"userVerified"`
|
||||
|
||||
// Flag BE indicates the credential is able to be backed up and/or sync'd between devices. This should NEVER change.
|
||||
BackupEligible bool `json:"backupEligible"`
|
||||
|
||||
// Flag BS indicates the credential has been backed up and/or sync'd. This value can change but it's recommended
|
||||
// that RP's keep track of this value.
|
||||
BackupState bool `json:"backupState"`
|
||||
}
|
||||
|
||||
// Credential contains all needed information about a WebAuthn credential for storage.
|
||||
type Credential struct {
|
||||
gorm.Model
|
||||
DisplayName string
|
||||
Origin string
|
||||
Controller string
|
||||
AttestationType string `json:"attestationType"`
|
||||
DID string
|
||||
ID []byte `json:"id"`
|
||||
PublicKey []byte `json:"publicKey"`
|
||||
Transport []protocol.AuthenticatorTransport `json:"transport"`
|
||||
Authenticator Authenticator `json:"authenticator"`
|
||||
Flags CredentialFlags `json:"flags"`
|
||||
}
|
||||
|
||||
// MakeNewCredential will return a credential pointer on successful validation of a registration response.
|
||||
func MakeNewCredential(c *protocol.ParsedCredentialCreationData) *Credential {
|
||||
return &Credential{
|
||||
ID: c.Response.AttestationObject.AuthData.AttData.CredentialID,
|
||||
PublicKey: c.Response.AttestationObject.AuthData.AttData.CredentialPublicKey,
|
||||
AttestationType: c.Response.AttestationObject.Format,
|
||||
Transport: c.Response.Transports,
|
||||
Flags: CredentialFlags{
|
||||
UserPresent: c.Response.AttestationObject.AuthData.Flags.HasUserPresent(),
|
||||
UserVerified: c.Response.AttestationObject.AuthData.Flags.HasUserVerified(),
|
||||
BackupEligible: c.Response.AttestationObject.AuthData.Flags.HasBackupEligible(),
|
||||
BackupState: c.Response.AttestationObject.AuthData.Flags.HasBackupState(),
|
||||
},
|
||||
Authenticator: Authenticator{
|
||||
AAGUID: c.Response.AttestationObject.AuthData.AttData.AAGUID,
|
||||
SignCount: c.Response.AttestationObject.AuthData.Counter,
|
||||
Attachment: c.AuthenticatorAttachment,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Descriptor converts a Credential into a protocol.CredentialDescriptor.
|
||||
func (c *Credential) Descriptor() protocol.CredentialDescriptor {
|
||||
return protocol.CredentialDescriptor{
|
||||
Type: protocol.PublicKeyCredentialType,
|
||||
CredentialID: c.ID,
|
||||
Transport: c.Transport,
|
||||
AttestationType: c.AttestationType,
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/onsonr/hway/crypto"
|
||||
fs "github.com/onsonr/hway/internal/vfs"
|
||||
"github.com/ipfs/boxo/path"
|
||||
)
|
||||
|
||||
// Metadata represents metadata of a resource
|
||||
type Metadata struct {
|
||||
PublicKey crypto.PublicKey `json:"publicKey"`
|
||||
Path path.Path `json:"path"`
|
||||
Address string `json:"address"`
|
||||
ChainID string `json:"chainId"`
|
||||
ValAddress string `json:"valAddress"`
|
||||
RPCEndpoint string `json:"rpcEndpoint"`
|
||||
APIEndpoint string `json:"apiEndpoint"`
|
||||
IPFSEndpoint string `json:"ipfsEndpoint"`
|
||||
PeerID string `json:"peerId"`
|
||||
SupportedDenominations []string `json:"supportedDenominations"`
|
||||
Number int `json:"number"`
|
||||
}
|
||||
|
||||
// CreateMetadata returns a new Metadata
|
||||
func CreateMetadata(ctx context.Context) *Metadata {
|
||||
return &Metadata{}
|
||||
}
|
||||
|
||||
// Marshal returns the JSON encoding of the Metadata
|
||||
func (i *Metadata) Marshal() ([]byte, error) {
|
||||
return json.Marshal(i)
|
||||
}
|
||||
|
||||
// Unmarshal parses the JSON-encoded data and stores the result in the Metadata
|
||||
func (i *Metadata) Unmarshal(data []byte) error {
|
||||
return json.Unmarshal(data, i)
|
||||
}
|
||||
|
||||
// Save writes the JSON encoding of the Metadata to the provided file
|
||||
func (i *Metadata) Save(file fs.File) error {
|
||||
bz, err := i.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return file.Write(bz)
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package orm
|
||||
|
||||
type UserInfo struct {
|
||||
DID string
|
||||
Sub string `json:"sub"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
// Add other claims as needed
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package orm
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Profile struct {
|
||||
gorm.Model
|
||||
DID string
|
||||
DisplayName string
|
||||
Name string
|
||||
Origin string
|
||||
Controller string
|
||||
Credentials []Credential
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"github.com/onsonr/hway/crypto"
|
||||
"github.com/onsonr/hway/crypto/bip32"
|
||||
"github.com/onsonr/hway/pkg/coins"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Wallet is a struct that contains the information of a wallet account
|
||||
type Wallet struct {
|
||||
gorm.Model
|
||||
Address string `json:"address"`
|
||||
Controller string `json:"controller"`
|
||||
Name string `json:"name"`
|
||||
ChainID string `json:"chainId"`
|
||||
Network string `json:"network"`
|
||||
Label string `json:"label"`
|
||||
DID string `json:"did"`
|
||||
PublicKey []byte `json:"publicKey"`
|
||||
Index int `json:"index"`
|
||||
CoinType int64 `json:"coinType"`
|
||||
}
|
||||
|
||||
// NewWallet creates a new account from a public key, coin, and index
|
||||
func NewWallet(pubkey crypto.PublicKey, coin coins.Coin, index int) (*Wallet, error) {
|
||||
expbz := pubkey.Bytes()
|
||||
pubBz, err := bip32.ComputePublicKey(expbz, coin.GetPath(), index)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addr, err := coin.FormatAddress(pubBz)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Wallet{
|
||||
PublicKey: pubBz,
|
||||
Index: index,
|
||||
Address: addr,
|
||||
CoinType: coin.GetIndex(),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user