1package webauthn 2 3import ( 4 "github.com/duo-labs/webauthn/protocol" 5) 6 7// Credential contains all needed information about a WebAuthn credential for storage 8type Credential struct { 9 // A probabilistically-unique byte sequence identifying a public key credential source and its authentication assertions. 10 ID []byte 11 // The public key portion of a Relying Party-specific credential key pair, generated by an authenticator and returned to 12 // a Relying Party at registration time (see also public key credential). The private key portion of the credential key 13 // pair is known as the credential private key. Note that in the case of self attestation, the credential key pair is also 14 // used as the attestation key pair, see self attestation for details. 15 PublicKey []byte 16 // The attestation format used (if any) by the authenticator when creating the credential. 17 AttestationType string 18 // The Authenticator information for a given certificate 19 Authenticator Authenticator 20} 21 22// MakeNewCredential will return a credential pointer on successful validation of a registration response 23func MakeNewCredential(c *protocol.ParsedCredentialCreationData) (*Credential, error) { 24 newCredential := &Credential{ 25 ID: c.Response.AttestationObject.AuthData.AttData.CredentialID, 26 PublicKey: c.Response.AttestationObject.AuthData.AttData.CredentialPublicKey, 27 AttestationType: c.Response.AttestationObject.Format, 28 Authenticator: Authenticator{ 29 AAGUID: c.Response.AttestationObject.AuthData.AttData.AAGUID, 30 SignCount: c.Response.AttestationObject.AuthData.Counter, 31 }, 32 } 33 34 return newCredential, nil 35} 36