{"id":20339139,"url":"https://github.com/nealfennimore/webcrypto-ts","last_synced_at":"2025-04-11T23:13:15.727Z","repository":{"id":57749943,"uuid":"520628225","full_name":"nealfennimore/webcrypto-ts","owner":"nealfennimore","description":"No dependency Web Crypto Typescript wrapper with strict type enforcement. Node + Browser support","archived":false,"fork":false,"pushed_at":"2025-03-29T02:54:52.000Z","size":3379,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T23:13:07.107Z","etag":null,"topics":["aes","aes-cbc","aes-ctr","aes-gcm","aes-kw","ecdh","ecdsa","elliptic-curve","hkdf","hmac","pbkdf","rsa","rsa-oaep","rsa-pkcs1","rsa-pss","sha256","sha384","sha512","webcrypto","webcrypto-api"],"latest_commit_sha":null,"homepage":"https://webcrypto.neal.codes/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nealfennimore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-02T19:39:52.000Z","updated_at":"2025-03-29T02:54:32.000Z","dependencies_parsed_at":"2024-08-22T18:08:55.894Z","dependency_job_id":null,"html_url":"https://github.com/nealfennimore/webcrypto-ts","commit_stats":{"total_commits":73,"total_committers":2,"mean_commits":36.5,"dds":"0.013698630136986356","last_synced_commit":"2927ab2b6fe178c12f13224ee062e2fee4a22df0"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nealfennimore%2Fwebcrypto-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nealfennimore%2Fwebcrypto-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nealfennimore%2Fwebcrypto-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nealfennimore%2Fwebcrypto-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nealfennimore","download_url":"https://codeload.github.com/nealfennimore/webcrypto-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492876,"owners_count":21113163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","aes-cbc","aes-ctr","aes-gcm","aes-kw","ecdh","ecdsa","elliptic-curve","hkdf","hmac","pbkdf","rsa","rsa-oaep","rsa-pkcs1","rsa-pss","sha256","sha384","sha512","webcrypto","webcrypto-api"],"created_at":"2024-11-14T21:15:31.245Z","updated_at":"2025-04-11T23:13:15.707Z","avatar_url":"https://github.com/nealfennimore.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webcrypto TS\n\n[![Test](https://github.com/nealfennimore/webcrypto-ts/actions/workflows/test.yml/badge.svg)](https://github.com/nealfennimore/webcrypto-ts/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/nealfennimore/webcrypto-ts/branch/main/graph/badge.svg?token=DGUV5J0QPR)](https://codecov.io/gh/nealfennimore/webcrypto-ts)\n\nA minimal ESM based, no dependency, typescript wrapper for the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API). Supports both nodejs and browser Web Crypto.\n\nAlgorithms are split into their own modules, which enforces consumption of cryptographic materials from the same algorithm. API follows entirely with the Web Crypto API, but removes the need for specifying every argument (secure defaults and inferred key usages). Keys are also [proxied](#proxied-keys-and-methods) to make it easier to use with cryptographic operations.\n\n- [Documentation](https://webcrypto.neal.codes) 📖\n- [Github](https://github.com/nealfennimore/webcrypto-ts) :octocat:\n- [NPM](https://www.npmjs.com/package/@nfen/webcrypto-ts)\n\n## Install\n\n```sh\nnpm i @nfen/webcrypto-ts\n```\n\n## Proxied Keys and Methods\n\nAll generated keys are wrapped in a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) object, which allows for executing methods specific to each key within a [small wrapper](https://github.com/nealfennimore/webcrypto-ts/blob/main/src/proxy.ts).\n\nFor example, we can generate an ECDSA keypair and `sign` directly off the `privateKey`.\n\n```ts\nimport * as ECDSA from \"@nfen/webcrypto-ts/lib/ec/ecdsa\";\nconst keyPair = await ECDSA.generateKeyPair();\nconst message = new TextEncoder().encode(\"a message\");\nconst signature = await keyPair.privateKey.sign({ hash: \"SHA-512\" }, message);\n```\n\nWe can still use the WebCrypto based API too. Access any CryptoKey or CryptoKeyPair by using `self` on the key.\n\n```ts\nconst signature = await ECDSA.sign(keyPair.privateKey.self, { hash: \"SHA-512\" }, message);\n```\n\n## Examples\n\nMany more examples in the [Documentation](https://webcrypto.neal.codes).\n\n### ECDSA\n\n```ts\nimport * as ECDSA from \"@nfen/webcrypto-ts/lib/ec/ecdsa\";\nconst keyPair = await ECDSA.generateKeyPair();\n\nconst message = new TextEncoder().encode(\"a message\");\nconst signature = await keyPair.privateKey.sign({ hash: \"SHA-512\" }, message);\n\nconst pubJwk = await keyPair.publicKey.exportKey(\"jwk\");\nconst publicKey = await ECDSA.importKey(\n    \"jwk\",\n    pubJwk,\n    { namedCurve: \"P-512\" },\n    true,\n    [\"verify\"]\n);\n\nconst isVerified = await publicKey.verify(\n    { hash: \"SHA-512\" },\n    signature,\n    message\n);\n```\n\n### RSA-OAEP\n\n```ts\nimport * as RSA_OAEP from \"@nfen/webcrypto-ts/lib/rsa/rsa_oaep\";\nimport * as AES_CBC from \"@nfen/webcrypto-ts/lib/aes/aes_cbc\";\nimport * as Random from \"@nfen/webcrypto-ts/lib/random\";\n\nconst kek = await RSA_OAEP.generateKeyPair(\n    {\n        hash: \"SHA-512\",\n        modulusLength: 4096,\n        publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\n    },\n    true,\n    [\"wrapKey\", \"unwrapKey\"]\n);\nconst dek = await AES_CBC.generateKey();\nconst label = await Random.getValues(8);\nconst wrappedCbcKey = await kek.publicKey.wrapKey(\"raw\", dek.self, { label });\n```\n\n### AES-GCM\n\n```ts\nimport * as AES_GCM from \"@nfen/webcrypto-ts/lib/aes/aes_gcm\";\nimport { IV } from \"@nfen/webcrypto-ts/lib/random\";\n\nconst iv = await IV.generate();\nconst key = await AES_GCM.generateKey();\nconst message = \"a message\";\nconst cipherText = await key.encrypt(\n    { iv },\n    new TextEncoder().encode(\"a message\")\n);\nconsole.assert(\n    new TextDecoder().decode(await key.decrypt({ iv }, message)) === message\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnealfennimore%2Fwebcrypto-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnealfennimore%2Fwebcrypto-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnealfennimore%2Fwebcrypto-ts/lists"}