registrationCredential method

Map<String, dynamic> registrationCredential({
  1. required String challenge,
})

Builds a browser-shaped registration credential for challenge.

Implementation

Map<String, dynamic> registrationCredential({required String challenge}) {
  final coseKey = cbor.cbor.encode(<Object?, Object?>{
    1: 2,
    3: -7,
    -1: 1,
    -2: _keyPair.x.toList(growable: false),
    -3: _keyPair.y.toList(growable: false),
  });
  final authenticatorData = <int>[
    ...crypto.sha256.convert(utf8.encode(relyingPartyId)).bytes,
    0x45,
    0,
    0,
    0,
    0,
    ...List<int>.filled(16, 0),
    _credentialBytes.length >> 8,
    _credentialBytes.length & 0xff,
    ..._credentialBytes,
    ...coseKey,
  ];
  final attestationObject = cbor.cbor.encode(<String, Object?>{
    'fmt': 'none',
    'authData': authenticatorData,
    'attStmt': <String, Object?>{},
  });
  return <String, dynamic>{
    'id': credentialId,
    'rawId': credentialId,
    'type': 'public-key',
    'authenticatorAttachment': 'platform',
    'clientExtensionResults': <String, Object?>{},
    'response': <String, dynamic>{
      'clientDataJSON': _base64Url(
        _clientData(type: 'webauthn.create', challenge: challenge),
      ),
      'attestationObject': _base64Url(attestationObject),
      'transports': <String>['internal'],
    },
    'name': credentialName,
  };
}