feat: add passkey creation functionality

This commit is contained in:
Prad Nukala
2024-12-08 22:53:04 -05:00
parent 5c3966a9d6
commit e0ebe92361
15 changed files with 189 additions and 118 deletions
+47
View File
@@ -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,
},
}
}
+59
View File
@@ -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,
},
}
}
+15
View File
@@ -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