Title: Type of `CryptoKey.algorithm` is incomplete, making usage of `SubtleCrypto` difficult · Issue #21609 · microsoft/TypeScript · GitHub
Open Graph Title: Type of `CryptoKey.algorithm` is incomplete, making usage of `SubtleCrypto` difficult · Issue #21609 · microsoft/TypeScript
X Title: Type of `CryptoKey.algorithm` is incomplete, making usage of `SubtleCrypto` difficult · Issue #21609 · microsoft/TypeScript
Description: Search Terms: cryptokey algorithm Code function sign(key: CryptoKey, message: ArrayBuffer): Promise
Open Graph Description: Search Terms: cryptokey algorithm Code function sign(key: CryptoKey, message: ArrayBuffer): Promise
X Description: Search Terms: cryptokey algorithm Code function sign(key: CryptoKey, message: ArrayBuffer): Promise<ArrayBuffer> { return crypto.subtle.sign( key.algorithm, key, message, ); } Expected behavi...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/21609
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type of `CryptoKey.algorithm` is incomplete, making usage of `SubtleCrypto` difficult","articleBody":"**Search Terms:** \r\n\r\ncryptokey algorithm\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction sign(key: CryptoKey, message: ArrayBuffer): Promise\u003cArrayBuffer> {\r\n return crypto.subtle.sign(\r\n key.algorithm,\r\n key,\r\n message,\r\n );\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n`CryptoKey.algorithm` is an appropriate way to pass the key algorithm to subtle methods such as `sign` and `encrypt`. However, the original definition of the type `CryptoKey` defines the type of `algorithm` as `KeyAlgorithm` which misses extra attributes that could be there.\r\n\r\nTherefor the expected behavior is for the code to now have a type error and compile correctly. Maybe the correct type for `CryptoKey` should be \r\n\r\n```ts\r\ninterface CryptoKey {\r\n readonly algorithm: RsaKeyAlgorithm | EcKeyAlgorithm | AesKeyAlgorithm | HmacKeyAlgorithm | DhKeyAlgorithm;\r\n readonly extractable: boolean;\r\n readonly type: string;\r\n readonly usages: string[];\r\n}\r\n```\r\n\r\nI am not sure how to fully test such a change, since modifying `lib.es6.d.ts` locally and running `tsc` produces the same message.\r\n\r\n**Actual behavior:**\r\nThe following type error:\r\n```\r\nArgument of type 'KeyAlgorithm' is not assignable to parameter of type 'string | RsaPssParams | EcdsaParams | AesCmacParams'.\r\n Type 'KeyAlgorithm' is not assignable to type 'AesCmacParams'.\r\n Property 'length' is missing in type 'KeyAlgorithm'. (2345)\r\n```\r\n\r\n**Playground Link:** [Playground link](https://www.typescriptlang.org/play/#src=function%20sign(key%3A%20CryptoKey%2C%20message%3A%20ArrayBuffer)%3A%20Promise%3CArrayBuffer%3E%20%7B%0D%0A%20%20%20%20return%20crypto.subtle.sign(%0D%0A%20%20%20%20%20%20%20%20key.algorithm%2C%0D%0A%20%20%20%20%20%20%20%20key%2C%0D%0A%20%20%20%20%20%20%20%20message%2C%0D%0A%20%20%20%20)%3B%0D%0A%7D)\r\n\r\n**Related Issues:** Unknown","author":{"url":"https://github.com/LiraNuna","@type":"Person","name":"LiraNuna"},"datePublished":"2018-02-03T21:26:47Z","url":"https://github.com/microsoft/TypeScript/issues/21609"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:94545869-e3e3-e533-3570-c76b6d1402eb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E866:96DDF:327192C:4001B12:6B01CA77 |
| html-safe-nonce | 4eb7a8738f9cc4e7e717259f39b898da861ff32493e7ee46bd6086c4e46761b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODY2Ojk2RERGOjMyNzE5MkM6NDAwMUIxMjo2QjAxQ0E3NyIsInZpc2l0b3JfaWQiOiIxOTY2NjM4ODY3NzcxNjczMjA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 78d5f79d43ec9abad27af3ba26ce129dc8aad0387d96341da1c9a6cf73287845 |
| hovercard-subject-tag | issue:294146445 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/21609/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a05215771f3e74ddfb920f0c5635350ea23114fd6098b3d606fd3c5b64f7bf11/microsoft/TypeScript/issues/21609 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a05215771f3e74ddfb920f0c5635350ea23114fd6098b3d606fd3c5b64f7bf11/microsoft/TypeScript/issues/21609 |
| og:image:alt | Search Terms: cryptokey algorithm Code function sign(key: CryptoKey, message: ArrayBuffer): Promise |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LiraNuna |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width