summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src')
-rw-r--r--packages/browser/src/helpers/toUint8Array.ts7
-rw-r--r--packages/browser/src/methods/startAttestation.test.ts5
-rw-r--r--packages/browser/src/methods/startAttestation.ts3
3 files changed, 12 insertions, 3 deletions
diff --git a/packages/browser/src/helpers/toUint8Array.ts b/packages/browser/src/helpers/toUint8Array.ts
new file mode 100644
index 0000000..1e2243f
--- /dev/null
+++ b/packages/browser/src/helpers/toUint8Array.ts
@@ -0,0 +1,7 @@
+/**
+ * A helper method to convert an arbitrary string sent from the server to a Uint8Array the
+ * authenticator will expect.
+ */
+export default function toUint8Array(value: string): Uint8Array {
+ return new TextEncoder().encode(value);
+}
diff --git a/packages/browser/src/methods/startAttestation.test.ts b/packages/browser/src/methods/startAttestation.test.ts
index ad71488..d178609 100644
--- a/packages/browser/src/methods/startAttestation.test.ts
+++ b/packages/browser/src/methods/startAttestation.test.ts
@@ -3,6 +3,7 @@ import {
PublicKeyCredentialCreationOptionsJSON,
} from '@simplewebauthn/typescript-types';
+import toUint8Array from '../helpers/toUint8Array';
import supportsWebauthn from '../helpers/supportsWebauthn';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
@@ -17,7 +18,7 @@ const mockAttestationObject = 'mockAtte';
const mockClientDataJSON = 'mockClie';
const goodOpts1: PublicKeyCredentialCreationOptionsJSON = {
- challenge: bufferToBase64URLString(Buffer.from('fizz', 'ascii')),
+ challenge: bufferToBase64URLString(toUint8Array('fizz')),
attestation: 'direct',
pubKeyCredParams: [
{
@@ -87,7 +88,7 @@ test('should return base64url-encoded response values', async done => {
return new Promise(resolve => {
resolve({
id: 'foobar',
- rawId: Buffer.from('foobar', 'ascii'),
+ rawId: toUint8Array('foobar'),
response: {
attestationObject: Buffer.from(mockAttestationObject, 'ascii'),
clientDataJSON: Buffer.from(mockClientDataJSON, 'ascii'),
diff --git a/packages/browser/src/methods/startAttestation.ts b/packages/browser/src/methods/startAttestation.ts
index 9594bb9..0b2235d 100644
--- a/packages/browser/src/methods/startAttestation.ts
+++ b/packages/browser/src/methods/startAttestation.ts
@@ -4,6 +4,7 @@ import {
AttestationCredentialJSON,
} from '@simplewebauthn/typescript-types';
+import toUint8Array from '../helpers/toUint8Array';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
import base64URLStringToBuffer from '../helpers/base64URLStringToBuffer';
import supportsWebauthn from '../helpers/supportsWebauthn';
@@ -27,7 +28,7 @@ export default async function startAttestation(
challenge: base64URLStringToBuffer(creationOptionsJSON.challenge),
user: {
...creationOptionsJSON.user,
- id: base64URLStringToBuffer(creationOptionsJSON.user.id),
+ id: toUint8Array(creationOptionsJSON.user.id),
},
excludeCredentials: creationOptionsJSON.excludeCredentials.map(toPublicKeyCredentialDescriptor),
};