{"id":18743236,"url":"https://github.com/anthonybudd/tpm2","last_synced_at":"2025-06-16T22:07:35.036Z","repository":{"id":65177596,"uuid":"585595363","full_name":"anthonybudd/TPM2","owner":"anthonybudd","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-17T01:06:45.000Z","size":820,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-20T06:11:15.261Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/anthonybudd.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}},"created_at":"2023-01-05T15:16:15.000Z","updated_at":"2023-01-05T16:10:05.000Z","dependencies_parsed_at":"2023-02-10T07:01:05.380Z","dependency_job_id":null,"html_url":"https://github.com/anthonybudd/TPM2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anthonybudd/TPM2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FTPM2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FTPM2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FTPM2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FTPM2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthonybudd","download_url":"https://codeload.github.com/anthonybudd/TPM2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FTPM2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260249966,"owners_count":22980765,"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":[],"created_at":"2024-11-07T16:10:44.521Z","updated_at":"2025-06-16T22:07:35.017Z","avatar_url":"https://github.com/anthonybudd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TPM2-Node\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/anthonybudd/TPM2/raw/main/docs/images/tpm-icon.png\" width=\"100\" alt=\"tpm icon\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/anthonybudd/TPM2/raw/main/docs/images/geek-pi-tmp2.png\" width=\"300\" alt=\"geekpi tpm\"\u003e\n\u003c/p\u003e\n\nNode JS library for working with the TPM (Trusted Platform Module) 2.0\n\nThe TPM classs is a JS API of the tpm2-tools found here [tpm2-tools.readthedocs.io](https://tpm2-tools.readthedocs.io/en/latest/).\n\n⚠️ This is not a stable API. This repo is just for my personal use. If you would like a stable version reach out and I will release a stable 1.0 ⚠️\n\n\n```\nnpm i trusted-platform-module-2\n```\n\n```js\nconst TPM2 = require('trusted-platform-module-2');\nconst tpm2 = new TPM2;\n\n// Random bytes\nconsole.log(tpm2.getRandom(8));\n\n// Encrypt/decrypt file.\ntpm2.encrypt('path/to/.env', {\n    parentContext: 'key.ctx',\n    output: 'secrets.enc'\n});\ntpm2.decrypt('secrets.enc', {\n    parentContext: 'key.ctx',\n    output: 'decrypted-secrets.txt'\n});\n```\n\n\n### Example\nBelow is a full example on how to use the TPM library to: create a primary hierarchy, create a child object, load the public/private portions of the key into the TPM, then encrypt a file with that key. \n\n```js\ntpm2.createPrimary({\n    keyContext: 'primary.ctx'\n});\ntpm2.create({\n    parentContext: 'primary.ctx',\n    keyAlgorithm: 'aes128',\n    public: 'key.pub',\n    private: 'key.priv',\n});\ntpm2.load({\n    parentContext: 'primary.ctx',\n    keyContext: 'key.ctx',\n    public: 'key.pub',\n    private: 'key.priv',\n});\ntpm2.encrypt('path/to/.env', {\n    parentContext: 'key.ctx',\n    output: 'secrets.enc'\n});\n```\n\n\n### Raspberry Pi Set-up\nI tested this library using the GeekPi TPM2 module which has a Infineon Optiga SLB 9670.\n\n\n```sh\nsudo echo 'dtparam=spi=on' \u003e\u003e /boot/config.txt\nsudo echo 'dtoverlay=tpm-slb9670' \u003e\u003e /boot/config.txt\n\napt-get install tpm2-tools\n# or build from source. Recommended but more complex. https://github.com/tpm2-software\nsudo reboot\n\ngit clone git@github.com:anthonybudd/TPM2.git\ncd TPM2\nnpm i\nnpm run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonybudd%2Ftpm2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonybudd%2Ftpm2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonybudd%2Ftpm2/lists"}