webauthn-open-source / fido2-lib

A node.js library for performing FIDO 2.0 / WebAuthn server functionality
https://webauthn.io
MIT License
394 stars 118 forks source link

User id should be type "BufferSource", not string #146

Closed segevmalool closed 7 months ago

segevmalool commented 8 months ago
image

https://www.w3.org/TR/webauthn/#dictionary-user-credential-params https://webidl.spec.whatwg.org/#BufferSource

Consider a code like this


// based on https://developer.chrome.com/blog/how-to-convert-arraybuffer-to-and-from-string/
function utf8StringToArrayBuffer (s: string) {
  const abuf = new ArrayBuffer(s.length);
  const abufView = new Uint8Array(abuf);
  for (let i = 0; i < s.length; i += 1) {
    abufView[i] = s.charCodeAt(i);
  }
  return abuf;
}
JamesCullum commented 8 months ago

Thanks for the suggestion - can you propose a PR that solves it and passes the tests?

segevmalool commented 8 months ago

Hi @JamesCullum, hope all is well! Do you think anything needs to change code wise or just a typing issue?

This PR seems to make the type error go away:

https://github.com/webauthn-open-source/fido2-lib/pull/148

JamesCullum commented 7 months ago

Thanks a lot, that was quick! 💯