mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 09:51:39 +00:00
feat: add passkey creation functionality
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package passkeys
|
||||
|
||||
import (
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/go-webauthn/webauthn/protocol/webauthncose"
|
||||
)
|
||||
|
||||
func defaultPrimaryAttestationFormats() []protocol.AttestationFormat {
|
||||
return []protocol.AttestationFormat{
|
||||
protocol.AttestationFormatApple,
|
||||
protocol.AttestationFormatAndroidKey,
|
||||
protocol.AttestationFormatAndroidSafetyNet,
|
||||
protocol.AttestationFormatFIDOUniversalSecondFactor,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultSecondaryAttestationFormats() []protocol.AttestationFormat {
|
||||
return []protocol.AttestationFormat{
|
||||
protocol.AttestationFormatPacked,
|
||||
protocol.AttestationFormatTPM,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultAuthenticatorSelection() protocol.AuthenticatorSelection {
|
||||
return protocol.AuthenticatorSelection{
|
||||
AuthenticatorAttachment: protocol.Platform,
|
||||
ResidentKey: protocol.ResidentKeyRequirementRequired,
|
||||
UserVerification: protocol.VerificationRequired,
|
||||
}
|
||||
}
|
||||
|
||||
func buildCredentialParameters() []protocol.CredentialParameter {
|
||||
return []protocol.CredentialParameter{
|
||||
{
|
||||
Type: "public-key",
|
||||
Algorithm: webauthncose.AlgES256,
|
||||
},
|
||||
{
|
||||
Type: "public-key",
|
||||
Algorithm: webauthncose.AlgES256K,
|
||||
},
|
||||
{
|
||||
Type: "public-key",
|
||||
Algorithm: webauthncose.AlgEdDSA,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package passkeys
|
||||
|
||||
import (
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/crypto/mpc"
|
||||
"github.com/onsonr/sonr/pkg/common"
|
||||
)
|
||||
|
||||
func Create(c echo.Context, handle string, ks mpc.Keyset) protocol.PublicKeyCredentialCreationOptions {
|
||||
origin := c.Request().Host
|
||||
svcName := c.Request().Host
|
||||
addr := ks.Address()
|
||||
return buildRegisterOptions(addr, handle, ks, origin, svcName)
|
||||
}
|
||||
|
||||
func buildRegisterOptions(addr string, handle string, ks mpc.Keyset, origin string, svcName string) protocol.PublicKeyCredentialCreationOptions {
|
||||
return protocol.PublicKeyCredentialCreationOptions{
|
||||
Attestation: protocol.PreferDirectAttestation,
|
||||
AttestationFormats: defaultPrimaryAttestationFormats(),
|
||||
AuthenticatorSelection: defaultAuthenticatorSelection(),
|
||||
RelyingParty: buildServiceEntity(origin, svcName),
|
||||
Extensions: buildExtensions(ks),
|
||||
Parameters: buildCredentialParameters(),
|
||||
Timeout: 10000,
|
||||
User: buildUserEntity(addr, handle),
|
||||
}
|
||||
}
|
||||
|
||||
func buildExtensions(ks mpc.Keyset) protocol.AuthenticationExtensions {
|
||||
return protocol.AuthenticationExtensions{
|
||||
"largeBlob": common.LargeBlob{
|
||||
Support: "required",
|
||||
Write: ks.UserJSON(),
|
||||
},
|
||||
"payment": common.Payment{
|
||||
IsPayment: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func buildServiceEntity(name string, host string) protocol.RelyingPartyEntity {
|
||||
return protocol.RelyingPartyEntity{
|
||||
CredentialEntity: protocol.CredentialEntity{
|
||||
Name: name,
|
||||
},
|
||||
ID: host,
|
||||
}
|
||||
}
|
||||
|
||||
func buildUserEntity(userAddress string, userHandle string) protocol.UserEntity {
|
||||
return protocol.UserEntity{
|
||||
ID: userAddress,
|
||||
DisplayName: userHandle,
|
||||
CredentialEntity: protocol.CredentialEntity{
|
||||
Name: userAddress,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package passkeys
|
||||
|
||||
//
|
||||
// import (
|
||||
// "github.com/go-webauthn/webauthn/protocol"
|
||||
// "github.com/labstack/echo/v4"
|
||||
// "github.com/onsonr/sonr/crypto/mpc"
|
||||
// )
|
||||
//
|
||||
// func Link(c echo.Context, handle string, ks mpc.Keyset) protocol.PublicKeyCredentialCreationOptions {
|
||||
// origin := c.Request().Host
|
||||
// svcName := c.Request().Host
|
||||
// addr := ks.Address()
|
||||
// return c.String(200, origin+" "+svcName+" "+addr+" "+handle)
|
||||
// }
|
||||
@@ -0,0 +1 @@
|
||||
package passkeys
|
||||
Reference in New Issue
Block a user