summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2020-11-16 10:49:38 -0800
committerMatthew Miller <matthew@millerti.me>2020-11-16 10:49:38 -0800
commit3b4c7a05ce0b43aeff7d5be96f130714fd09002c (patch)
treecf7b6e93ec2f71990ee0269436e068117deff99a
parentbd76bad51c50d2849794e564e9fed4e06612aad6 (diff)
Start porting fido-conformance to TS
-rw-r--r--example/fido-conformance.ts (renamed from example/fido-conformance.js)23
1 files changed, 13 insertions, 10 deletions
diff --git a/example/fido-conformance.js b/example/fido-conformance.ts
index 9317a27..759bd23 100644
--- a/example/fido-conformance.js
+++ b/example/fido-conformance.ts
@@ -1,15 +1,18 @@
/* eslint-disable @typescript-eslint/no-var-requires */
-const fs = require('fs');
-const express = require('express');
-const fetch = require('node-fetch');
+import fs from 'fs';
+import express from 'express';
+import fetch from 'node-fetch';
-const {
+import {
generateAttestationOptions,
verifyAttestationResponse,
generateAssertionOptions,
verifyAssertionResponse,
MetadataService,
-} = require('@simplewebauthn/server');
+} from '@simplewebauthn/server';
+import { MetadataStatement } from '@simplewebauthn/server/dist/metadata/metadataService';
+
+import { LoggedInUser } from './example-server';
/**
* Create paths specifically for testing with the FIDO Conformance Tools
@@ -26,7 +29,7 @@ const fidoRouteSuffix = '/fido';
*
* FIDO2 > TESTS CONFIGURATION > DOWNLOAD SERVER METADATA (button)
*/
-const statements = [];
+const statements: MetadataStatement[] = [];
try {
// Update this to whatever folder you extracted the statements to
@@ -53,7 +56,7 @@ fetch('https://mds.certinfra.fidoalliance.org/getEndpoints', {
.then(resp => resp.json())
.then(json => {
const routes = json.result;
- const mdsServers = routes.map(url => ({
+ const mdsServers = routes.map((url: string) => ({
url,
rootCertURL: 'https://mds.certinfra.fidoalliance.org/pki/MDSROOT.crt',
metadataURLSuffix: '',
@@ -72,7 +75,7 @@ fetch('https://mds.certinfra.fidoalliance.org/getEndpoints', {
console.log('🔐 FIDO Conformance routes ready');
});
-const inMemoryUserDeviceDB = {
+const inMemoryUserDeviceDB: { [username: string]: LoggedInUser } = {
// [username]: string: {
// id: loggedInUserId,
// username: 'user@yourdomain.com',
@@ -90,7 +93,7 @@ const inMemoryUserDeviceDB = {
// },
};
// A cheap way of remembering who's "logged in" between the request for options and the response
-let loggedInUsername = undefined;
+let loggedInUsername: string | undefined = undefined;
/**
* [FIDO2] Server Tests > MakeCredential Request
@@ -196,7 +199,7 @@ fidoConformanceRouter.post('/assertion/options', (req, res) => {
loggedInUsername = username;
- let user = inMemoryUserDeviceDB[username];
+ const user = inMemoryUserDeviceDB[username];
const { devices } = user;