From 285458173a42bd70fbae59bea8714ff05dcaef94 Mon Sep 17 00:00:00 2001 From: Frank Hinek Date: Sun, 9 Jul 2023 13:17:13 -0400 Subject: [PATCH] Minor formatting changes and removed type defs from coverage calculation Signed-off-by: Frank Hinek --- packages/common/.c8rc.json | 1 + packages/common/src/type-utils.ts | 36 ++++++------- packages/crypto/src/utils-new.ts | 58 ++++++++++---------- packages/web5/examples/alice.html | 88 ------------------------------- 4 files changed, 48 insertions(+), 135 deletions(-) delete mode 100644 packages/web5/examples/alice.html diff --git a/packages/common/.c8rc.json b/packages/common/.c8rc.json index 0d483c700..e2e272d2e 100644 --- a/packages/common/.c8rc.json +++ b/packages/common/.c8rc.json @@ -9,6 +9,7 @@ ], "exclude": [ "__tests__/src/main.js", + "__tests__/src/types.js", "__tests__/types/**" ], "reporter": [ diff --git a/packages/common/src/type-utils.ts b/packages/common/src/type-utils.ts index aaaeeb39d..7ec28ab0d 100644 --- a/packages/common/src/type-utils.ts +++ b/packages/common/src/type-utils.ts @@ -1,21 +1,3 @@ -/** - * isDefined - * - * Utility function to check if a variable is neither null nor undefined. - * This function helps in making TypeScript infer the type of the variable - * as being defined, excluding `null` and `undefined`. - * - * The function uses strict equality (`!==`) for the comparison, ensuring - * that the variable is not just falsy (like an empty string or zero), - * but is truly either `null` or `undefined`. - * - * @param arg - The variable to be checked - * @returns true if the variable is neither `null` nor `undefined` - */ -export function isDefined(arg: T): arg is Exclude { - return arg !== null && typeof arg !== 'undefined'; -} - /** * isArrayBufferSlice * @@ -35,6 +17,24 @@ export function isArrayBufferSlice(arrayBufferView: ArrayBufferView): boolean { return arrayBufferView.byteOffset !== 0 || arrayBufferView.byteLength !== arrayBufferView.buffer.byteLength; } +/** + * isDefined + * + * Utility function to check if a variable is neither null nor undefined. + * This function helps in making TypeScript infer the type of the variable + * as being defined, excluding `null` and `undefined`. + * + * The function uses strict equality (`!==`) for the comparison, ensuring + * that the variable is not just falsy (like an empty string or zero), + * but is truly either `null` or `undefined`. + * + * @param arg - The variable to be checked + * @returns true if the variable is neither `null` nor `undefined` + */ +export function isDefined(arg: T): arg is Exclude { + return arg !== null && typeof arg !== 'undefined'; +} + /** * universalTypeOf * diff --git a/packages/crypto/src/utils-new.ts b/packages/crypto/src/utils-new.ts index ee521cd75..c24dee818 100644 --- a/packages/crypto/src/utils-new.ts +++ b/packages/crypto/src/utils-new.ts @@ -3,6 +3,27 @@ import type { BufferKeyPair, ManagedKey, ManagedKeyPair, Web5Crypto } from './ty import { universalTypeOf } from '@tbd54566975/common'; import { bytesToHex, randomBytes } from '@noble/hashes/utils'; +/** + * Checks whether the properties object provided contains the specified property. + * + * @param property Property key to check for. + * @param properties Properties object to check within. + * @returns void + * @throws {SyntaxError} If the property is not a key in the properties object. + */ +export function checkRequiredProperty(options: { + property: string, + inObject: object +}): void { + if (!options || options.property === undefined || options.inObject === undefined) { + throw new TypeError(`One or more required arguments missing: 'property, properties'`); + } + const { property, inObject } = options; + if (!(property in inObject)) { + throw new TypeError(`Required parameter was missing: '${property}'`); + } +} + /** * Checks whether the property specified is a member of the list of valid properties. * @@ -29,24 +50,16 @@ export function checkValidProperty(options: { } /** - * Checks whether the properties object provided contains the specified property. + * Type guard function to check if the given key is a raw key pair + * of ArrayBuffers. * - * @param property Property key to check for. - * @param properties Properties object to check within. - * @returns void - * @throws {SyntaxError} If the property is not a key in the properties object. + * @param key The key to check. + * @returns True if the key is a pair of key ArrayBuffers, false otherwise. */ -export function checkRequiredProperty(options: { - property: string, - inObject: object -}): void { - if (!options || options.property === undefined || options.inObject === undefined) { - throw new TypeError(`One or more required arguments missing: 'property, properties'`); - } - const { property, inObject } = options; - if (!(property in inObject)) { - throw new TypeError(`Required parameter was missing: '${property}'`); - } +export function isBufferKeyPair(key: BufferKeyPair | undefined): key is BufferKeyPair { + return (key && 'privateKey' in key && 'publicKey' in key && + universalTypeOf(key.privateKey) === 'ArrayBuffer' && + universalTypeOf(key.publicKey) === 'ArrayBuffer') ? true : false; } /** @@ -80,19 +93,6 @@ export function isManagedKeyPair(key: ManagedKey | ManagedKeyPair | undefined): return key !== undefined && 'privateKey' in key && 'publicKey' in key; } -/** - * Type guard function to check if the given key is a raw key pair - * of ArrayBuffers. - * - * @param key The key to check. - * @returns True if the key is a pair of key ArrayBuffers, false otherwise. - */ -export function isBufferKeyPair(key: BufferKeyPair | undefined): key is BufferKeyPair { - return (key && 'privateKey' in key && 'publicKey' in key && - universalTypeOf(key.privateKey) === 'ArrayBuffer' && - universalTypeOf(key.publicKey) === 'ArrayBuffer') ? true : false; -} - /** * Generates a UUID (Universally Unique Identifier) using a * cryptographically strong random number generator following diff --git a/packages/web5/examples/alice.html b/packages/web5/examples/alice.html deleted file mode 100644 index 5909f0c30..000000000 --- a/packages/web5/examples/alice.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - client1 sender - - - - - -

{TBD logo}

- - - - \ No newline at end of file