diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | packages/browser/tsconfig.json | 4 | ||||
-rw-r--r-- | packages/server/package.json | 6 | ||||
-rw-r--r-- | packages/server/src/assertion/generateAssertionOptions.ts | 2 | ||||
-rw-r--r-- | packages/server/src/assertion/verifyAssertionResponse.ts | 6 | ||||
-rw-r--r-- | packages/server/src/attestation/generateAttestationOptions.ts | 5 | ||||
-rw-r--r-- | packages/server/src/attestation/verifyAttestationResponse.ts | 5 | ||||
-rw-r--r-- | packages/server/src/helpers/convertCOSEtoPKCS.ts | 2 | ||||
-rw-r--r-- | packages/typescript-types/extract-dom-types.ts | 82 | ||||
-rw-r--r-- | packages/typescript-types/package.json | 3 | ||||
-rw-r--r-- | packages/typescript-types/src/index.ts | 15 | ||||
-rw-r--r-- | packages/typescript-types/tsconfig.json | 6 | ||||
-rw-r--r-- | tsconfig.json | 4 | ||||
-rw-r--r-- | tsconfigdoc.json | 6 |
15 files changed, 137 insertions, 11 deletions
@@ -9,3 +9,4 @@ example/*.crt example/fido-conformance-mds/* !example/fido-conformance-mds/.gitkeep package-lock.json +packages/typescript-types/src/dom.ts diff --git a/package.json b/package.json index 0d38e01..5a6e1c9 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "rimraf": "^3.0.2", "semver": "^7.3.2", "ts-jest": "^25.5.1", + "ts-morph": "^9.0.0", "ts-node": "^8.10.2", "ttypescript": "^1.5.12", "typedoc": "^0.20.0-beta.8", diff --git a/packages/browser/tsconfig.json b/packages/browser/tsconfig.json index 349e40c..8b6f0a5 100644 --- a/packages/browser/tsconfig.json +++ b/packages/browser/tsconfig.json @@ -1,6 +1,10 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "lib": [ + "ES2018", + "DOM" + ], "baseUrl": "./src", "outDir": "./dist" } diff --git a/packages/server/package.json b/packages/server/package.json index d196617..d83e9ca 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -32,9 +32,9 @@ "node" ], "dependencies": { - "@peculiar/asn1-android": "^2.0.25", - "@peculiar/asn1-schema": "^2.0.25", - "@peculiar/asn1-x509": "^2.0.25", + "@peculiar/asn1-android": "^2.0.26", + "@peculiar/asn1-schema": "^2.0.26", + "@peculiar/asn1-x509": "^2.0.26", "@simplewebauthn/typescript-types": "file:../typescript-types", "base64url": "^3.0.1", "cbor": "^5.1.0", diff --git a/packages/server/src/assertion/generateAssertionOptions.ts b/packages/server/src/assertion/generateAssertionOptions.ts index 76e951a..d05dc00 100644 --- a/packages/server/src/assertion/generateAssertionOptions.ts +++ b/packages/server/src/assertion/generateAssertionOptions.ts @@ -1,6 +1,8 @@ import type { + AuthenticationExtensionsClientInputs, PublicKeyCredentialRequestOptionsJSON, PublicKeyCredentialDescriptorJSON, + UserVerificationRequirement, } from '@simplewebauthn/typescript-types'; import base64url from 'base64url'; diff --git a/packages/server/src/assertion/verifyAssertionResponse.ts b/packages/server/src/assertion/verifyAssertionResponse.ts index b2923ee..993b7e9 100644 --- a/packages/server/src/assertion/verifyAssertionResponse.ts +++ b/packages/server/src/assertion/verifyAssertionResponse.ts @@ -1,5 +1,9 @@ import base64url from 'base64url'; -import { AssertionCredentialJSON, AuthenticatorDevice } from '@simplewebauthn/typescript-types'; +import { + AssertionCredentialJSON, + AuthenticatorDevice, + UserVerificationRequirement, +} from '@simplewebauthn/typescript-types'; import decodeClientDataJSON from '../helpers/decodeClientDataJSON'; import toHash from '../helpers/toHash'; diff --git a/packages/server/src/attestation/generateAttestationOptions.ts b/packages/server/src/attestation/generateAttestationOptions.ts index 61b1eb5..e1fc70e 100644 --- a/packages/server/src/attestation/generateAttestationOptions.ts +++ b/packages/server/src/attestation/generateAttestationOptions.ts @@ -1,6 +1,11 @@ import type { + AttestationConveyancePreference, + AuthenticationExtensionsClientInputs, + AuthenticatorSelectionCriteria, + COSEAlgorithmIdentifier, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialDescriptorJSON, + PublicKeyCredentialParameters, } from '@simplewebauthn/typescript-types'; import base64url from 'base64url'; diff --git a/packages/server/src/attestation/verifyAttestationResponse.ts b/packages/server/src/attestation/verifyAttestationResponse.ts index 8acd028..8a213f0 100644 --- a/packages/server/src/attestation/verifyAttestationResponse.ts +++ b/packages/server/src/attestation/verifyAttestationResponse.ts @@ -1,5 +1,8 @@ import base64url from 'base64url'; -import { AttestationCredentialJSON } from '@simplewebauthn/typescript-types'; +import { + AttestationCredentialJSON, + COSEAlgorithmIdentifier, +} from '@simplewebauthn/typescript-types'; import decodeAttestationObject, { ATTESTATION_FORMATS } from '../helpers/decodeAttestationObject'; import decodeClientDataJSON from '../helpers/decodeClientDataJSON'; diff --git a/packages/server/src/helpers/convertCOSEtoPKCS.ts b/packages/server/src/helpers/convertCOSEtoPKCS.ts index 2b51d1d..fe88ca6 100644 --- a/packages/server/src/helpers/convertCOSEtoPKCS.ts +++ b/packages/server/src/helpers/convertCOSEtoPKCS.ts @@ -1,5 +1,5 @@ -import cbor from 'cbor'; import type { SigningSchemeHash } from 'node-rsa'; +import { COSEAlgorithmIdentifier } from '@simplewebauthn/typescript-types'; import { decodeCborFirst } from './decodeCbor'; /** diff --git a/packages/typescript-types/extract-dom-types.ts b/packages/typescript-types/extract-dom-types.ts new file mode 100644 index 0000000..bc16554 --- /dev/null +++ b/packages/typescript-types/extract-dom-types.ts @@ -0,0 +1,82 @@ +// n.b. ts-morph is a sibling devDependency of typescript, so that the module +// loader will resolve our project's typescript package, not the transient +// dependency of ts-morph. We only want to reference our typescript dependency +// for its version and its lib.dom.d.ts file. If any typescript functionality +// is needed, use import { ts } from "ts-morph"; +import { + InterfaceDeclaration, + Node, + Project, + Structure, + SyntaxKind, + TypeAliasDeclaration, +} from 'ts-morph'; +import { version } from 'typescript'; + +// List of types we directly reference from the dom lib. Only interface and type +// alias identifiers are valid, since other syntax types (class, function, var) +// are implementations, which will not be available outside of the browser. +const types = [ + 'AuthenticatorAssertionResponse', + 'AttestationConveyancePreference', + 'AuthenticatorAttestationResponse', + 'AuthenticatorTransport', + 'AuthenticationExtensionsClientInputs', + 'AuthenticatorSelectionCriteria', + 'COSEAlgorithmIdentifier', + 'PublicKeyCredential', + 'PublicKeyCredentialCreationOptions', + 'PublicKeyCredentialDescriptor', + 'PublicKeyCredentialParameters', + 'PublicKeyCredentialRequestOptions', + 'PublicKeyCredentialUserEntity', + 'UserVerificationRequirement', +]; + +const project = new Project({ skipAddingFilesFromTsConfig: true }); +const domSourcePath = 'typescript/lib/lib.dom.d.ts'; +const domSourceFile = project.addSourceFileAtPath(require.resolve(domSourcePath)); +const resolvedNodes = new Set<InterfaceDeclaration | TypeAliasDeclaration>(); +const unresolvedNodes = new Set<InterfaceDeclaration | TypeAliasDeclaration>( + types.map(type => { + const node = domSourceFile.getInterface(type) ?? domSourceFile.getTypeAlias(type); + if (!node) { + throw new Error(`${type} does not refer to an interface or type alias`); + } + return node; + }), +); + +while (unresolvedNodes.size > 0) { + for (const node of unresolvedNodes.values()) { + unresolvedNodes.delete(node); + resolvedNodes.add(node); + + // Declarations in lib files are never exported because they are globally + // available. Since we are extracting the types to a module, we export them. + node.setIsExported(true); + + // Find all descendant identifiers which reference an interface or type + // alias, and add them to the unresolved list. + for (const id of node.getDescendantsOfKind(SyntaxKind.Identifier)) { + for (const dn of id.getDefinitionNodes()) { + if (Node.isInterfaceDeclaration(dn) || Node.isTypeAliasDeclaration(dn)) { + if (!resolvedNodes.has(dn)) { + unresolvedNodes.add(dn); + } + } + } + } + } +} + +const outputSourceFile = project.createSourceFile(`src/dom.ts`, undefined, { overwrite: true }); +outputSourceFile.addStatements([ + `// Generated from typescript@${version} ${domSourcePath}`, + `// To regenerate, run the following command from the project root:`, + `// npx lerna --scope=@simplewebauthn/typescript-types exec -- npm run extract-dom-types`, +]); +const resolvedStructures = Array.from(resolvedNodes).map(node => node.getStructure()); +outputSourceFile.addInterfaces(resolvedStructures.filter(Structure.isInterface)); +outputSourceFile.addTypeAliases(resolvedStructures.filter(Structure.isTypeAlias)); +outputSourceFile.saveSync(); diff --git a/packages/typescript-types/package.json b/packages/typescript-types/package.json index 4a42c95..a05db68 100644 --- a/packages/typescript-types/package.json +++ b/packages/typescript-types/package.json @@ -16,7 +16,8 @@ "access": "public" }, "scripts": { - "build": "rimraf dist && tsc", + "build": "rimraf dist && npm run extract-dom-types && tsc", + "extract-dom-types": "ts-node extract-dom-types.ts", "prepublish": "npm run build" }, "keywords": [ diff --git a/packages/typescript-types/src/index.ts b/packages/typescript-types/src/index.ts index 4f238d7..954615b 100644 --- a/packages/typescript-types/src/index.ts +++ b/packages/typescript-types/src/index.ts @@ -2,6 +2,21 @@ * @packageDocumentation * @module @simplewebauthn/typescript-types */ + +import type { + AuthenticatorAssertionResponse, + AuthenticatorAttestationResponse, + AuthenticatorTransport, + COSEAlgorithmIdentifier, + PublicKeyCredential, + PublicKeyCredentialCreationOptions, + PublicKeyCredentialDescriptor, + PublicKeyCredentialRequestOptions, + PublicKeyCredentialUserEntity, +} from './dom'; + +export * from './dom'; + /** * A variant of PublicKeyCredentialCreationOptions suitable for JSON transmission to the browser to * (eventually) get passed into navigator.credentials.create(...) in the browser. diff --git a/packages/typescript-types/tsconfig.json b/packages/typescript-types/tsconfig.json index 349e40c..6dfff5f 100644 --- a/packages/typescript-types/tsconfig.json +++ b/packages/typescript-types/tsconfig.json @@ -2,6 +2,8 @@ "extends": "../../tsconfig.json", "compilerOptions": { "baseUrl": "./src", - "outDir": "./dist" - } + "outDir": "./dist", + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] } diff --git a/tsconfig.json b/tsconfig.json index a8c0eb3..1db0ac9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,9 @@ { "compilerOptions": { "target": "ES2018", - "lib": ["ES2018", "DOM"], + "lib": [ + "ES2018" + ], "module": "commonjs", "esModuleInterop": true, "declaration": true, diff --git a/tsconfigdoc.json b/tsconfigdoc.json index faa4ab7..17338e2 100644 --- a/tsconfigdoc.json +++ b/tsconfigdoc.json @@ -1,6 +1,10 @@ { - "extends": "./tsconfig", + "extends": "./tsconfig.json", "compilerOptions": { + "lib": [ + "ES2018", + "DOM" + ], "baseUrl": ".", "paths": { "@simplewebauthn/*": ["packages/*/src"] |