Skip to content

Commit

Permalink
refactor(webapi): is cryptokey check
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 26, 2022
1 parent b4612f5 commit 2232b18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
13 changes: 1 addition & 12 deletions src/runtime/browser/webcrypto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
export default crypto

export function isCryptoKey(key: unknown): key is CryptoKey {
try {
return (
key != null &&
typeof (<CryptoKey>key).extractable === 'boolean' &&
typeof (<CryptoKey>key).algorithm.name === 'string' &&
typeof (<CryptoKey>key).type === 'string'
)
} catch {
return false
}
}
export const isCryptoKey = (key: unknown): key is CryptoKey => key instanceof CryptoKey
4 changes: 2 additions & 2 deletions src/runtime/node/webcrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const webcrypto = <Crypto>crypto.webcrypto
export default webcrypto

export const isCryptoKey = util.types.isCryptoKey
? (obj: unknown): obj is CryptoKey => util.types.isCryptoKey(obj)
? (key: unknown): key is CryptoKey => util.types.isCryptoKey(key)
: // @ts-expect-error
(obj: unknown): obj is CryptoKey => false
(key: unknown): key is CryptoKey => false

0 comments on commit 2232b18

Please sign in to comment.