Skip to content

Commit

Permalink
fix(typescript): fix compiling by adding .d.ts files for runtime modules
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Nov 15, 2020
1 parent 076eea1 commit d9cb573
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# crypto runtime copies
src/runtime/*.ts
+src/runtime/interfaces.d.ts
+src/runtime/*.d.ts

# cjs clone of the test suite
test/cjs
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,9 @@
"dist/**/*.js",
"src/**/*.d.ts",
"src/**/*.ts",
"!src/runtime/*/*.ts",
"!src/runtime/*.ts",
"src/runtime/interfaces.d.ts"
"src/runtime/*.d.ts"
],
"scripts": {
"build": "tsc",
Expand All @@ -447,7 +448,7 @@
"runtime-node-webcrypto": "run-s runtime:clear runtime:browser:* && cp ./src/runtime/node/webcrypto.ts ./src/runtime/ && cp ./src/runtime/node/fetch.ts ./src/runtime/ && cp ./src/runtime/node/base64url.ts ./src/runtime/ && cp ./src/runtime/node/zlib.ts ./src/runtime/ && run-s runtime:refs",
"runtime:browser:copy": "cp ./src/runtime/browser/*.ts ./src/runtime",
"runtime:clear": "run-s -s runtime:find | xargs -0 rm -f",
"runtime:find": "find src/runtime -not -name 'interfaces.d.ts' -maxdepth 1 -type f -print0",
"runtime:find": "find src/runtime -not -name '*.d.ts' -maxdepth 1 -type f -print0",
"runtime:node:copy": "cp ./src/runtime/node/*.ts ./src/runtime",
"runtime:refs": "run-s -s runtime:find | xargs -0 sed -i '' -e \"s/'\\.\\.\\//'\\.\\//g\" -e \"s/'\\.\\/\\.\\./'../g\"",
"test": "npm run-script test-rollup && ava",
Expand Down
2 changes: 1 addition & 1 deletion src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"globals": {
"window": "readonly"
},
"ignorePatterns": ["src/runtime/*/*.ts", "src/runtime/webcrypto.ts", "dist"]
"ignorePatterns": ["src/runtime/*/*.ts", "src/runtime/webcrypto.ts", "dist", "src/runtime/*.d.ts"]
}
3 changes: 3 additions & 0 deletions src/runtime/aesgcmkw.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { AesGcmKwUnwrapFunction, AesGcmKwWrapFunction } from './interfaces.d';
export declare const wrap: AesGcmKwWrapFunction;
export declare const unwrap: AesGcmKwUnwrapFunction;
3 changes: 3 additions & 0 deletions src/runtime/aeskw.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { AesKwUnwrapFunction, AesKwWrapFunction } from './interfaces.d';
export declare const wrap: AesKwWrapFunction;
export declare const unwrap: AesKwUnwrapFunction;
3 changes: 3 additions & 0 deletions src/runtime/base64url.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { Base64UrlDecode, Base64UrlEncode } from './interfaces.d';
export declare const encode: Base64UrlEncode;
export declare const decode: Base64UrlDecode;
3 changes: 3 additions & 0 deletions src/runtime/decrypt.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { DecryptFunction } from './interfaces.d';
declare const decrypt: DecryptFunction;
export default decrypt;
3 changes: 3 additions & 0 deletions src/runtime/digest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { AsyncOrSync } from '../types.i.d'
declare const _default: (digest: string, data: Uint8Array) => AsyncOrSync<Uint8Array>;
export default _default;
6 changes: 6 additions & 0 deletions src/runtime/ecdhes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { EcdhAllowedFunction, EcdhESDeriveKeyFunction, EphemeralKeyToPublicJwkFunction, GenerateEpkFunction, PublicJwkToEphemeralKeyFunction } from './interfaces.d';
export declare const deriveKey: EcdhESDeriveKeyFunction;
export declare const ephemeralKeyToPublicJWK: EphemeralKeyToPublicJwkFunction;
export declare const generateEpk: GenerateEpkFunction;
export declare const publicJwkToEphemeralKey: PublicJwkToEphemeralKeyFunction;
export declare const ecdhAllowed: EcdhAllowedFunction;
3 changes: 3 additions & 0 deletions src/runtime/encrypt.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { EncryptFunction } from './interfaces.d';
declare const encrypt: EncryptFunction;
export default encrypt;
2 changes: 2 additions & 0 deletions src/runtime/fetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _default: (url: URL, timeout: number) => Promise<any>;
export default _default;
11 changes: 11 additions & 0 deletions src/runtime/generate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { KeyObject } from 'crypto';
import type { KeyLike } from '../types.d';
export declare function generateSecret(alg: string): Promise<KeyLike>;
interface Options {
crv?: string;
}
export declare function generateKeyPair(alg: string, options?: Options): Promise<{
privateKey: CryptoKey | KeyObject,
publicKey: CryptoKey | KeyObject
}>;
export {};
8 changes: 8 additions & 0 deletions src/runtime/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ export interface DecryptFunction {
additionalData: Uint8Array,
): Promise<Uint8Array>
}
// TODO:
export interface FetchFunction {
(url: URL, timeout: number): Promise<any>
}
// TODO:
export interface DigestFunction {
(digest: string, data: Uint8Array): AsyncOrSync<Uint8Array>
}
3 changes: 3 additions & 0 deletions src/runtime/jwk_to_key.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { KeyLike, JWK } from '../types.d';
declare const _default: (jwk: JWK) => Promise<KeyLike>;
export default _default;
3 changes: 3 additions & 0 deletions src/runtime/pbes2kw.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { Pbes2KWDecryptFunction, Pbes2KWEncryptFunction } from './interfaces.d';
export declare const encrypt: Pbes2KWEncryptFunction;
export declare const decrypt: Pbes2KWDecryptFunction;
3 changes: 3 additions & 0 deletions src/runtime/random.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { GetRandomValuesFunction } from './interfaces.d';
declare const random: GetRandomValuesFunction;
export default random;
3 changes: 3 additions & 0 deletions src/runtime/rsaes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { RsaEsDecryptFunction, RsaEsEncryptFunction } from './interfaces.d';
export declare const encrypt: RsaEsEncryptFunction;
export declare const decrypt: RsaEsDecryptFunction;
3 changes: 3 additions & 0 deletions src/runtime/sign.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { SignFunction } from './interfaces.d';
declare const sign: SignFunction;
export default sign;
3 changes: 3 additions & 0 deletions src/runtime/verify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { VerifyFunction } from './interfaces.d';
declare const verify: VerifyFunction;
export default verify;
3 changes: 3 additions & 0 deletions src/runtime/zlib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { InflateFunction, DeflateFunction } from '../types.d';
export declare const inflate: InflateFunction;
export declare const deflate: DeflateFunction;

0 comments on commit d9cb573

Please sign in to comment.