{"_id":"@bun-win32/tbs","_rev":"3-1fc00f2dc520a9c455ffb1ca08b3deb8","name":"@bun-win32/tbs","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"@bun-win32/tbs","version":"1.0.0","keywords":["bun","ffi","win32","windows","tbs","bindings","typescript","dll"],"author":"Stev Peifer <stev@bell.net>","license":"MIT","_id":"@bun-win32/tbs@1.0.0","maintainers":[{"name":"obscuritysrl","email":"stev@bell.net"}],"homepage":"https://github.com/ObscuritySRL/bun-win32#readme","bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"dist":{"shasum":"a287ff5d19e79d96d0400a2a8ec86f18a2ac34f5","tarball":"https://registry.npmjs.org/@bun-win32/tbs/-/tbs-1.0.0.tgz","fileCount":6,"integrity":"sha512-EyMVOrtJrypCdJEmWDz1OcEoeLb0YkV/V5f/CVms/w4GNPGz1GJTKNLmfz33izP4GOaaT5F//DVN8LodcVbBtA==","signatures":[{"sig":"MEYCIQCUpH8cVI5c1Pu9RdBrnyWrTuObfFVN3PSG4+hKk/6CLwIhAO4Z9DO2hW3aY4Q+YMu522D8jOAHHWkb4oUU50E0nOHn","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15617},"main":"./index.ts","type":"module","module":"index.ts","shasum":"a287ff5d19e79d96d0400a2a8ec86f18a2ac34f5","engines":{"bun":">=1.1.0"},"exports":{".":"./index.ts"},"private":false,"scripts":{"example:tpm-diagnostic":"bun ./example/tpm-diagnostic.ts","example:tpm-entropy-fountain":"bun ./example/tpm-entropy-fountain.ts"},"_npmUser":{"name":"obscuritysrl","email":"stev@bell.net"},"_integrity":"sha512-EyMVOrtJrypCdJEmWDz1OcEoeLb0YkV/V5f/CVms/w4GNPGz1GJTKNLmfz33izP4GOaaT5F//DVN8LodcVbBtA==","repository":{"url":"git://github.com/ObscuritySRL/bun-win32.git","type":"git","directory":"packages/tbs"},"_npmVersion":"10.8.3","description":"Zero-dependency, zero-overhead Win32 TBS (TPM Base Services) bindings for Bun (FFI) on Windows.","directories":{},"sideEffects":false,"_nodeVersion":"24.3.0","dependencies":{"@bun-win32/core":"1.1.2"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@bun-win32/kernel32":"1.0.21"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/tbs_1.0.0_1779150545203_0.08941995511507961","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@bun-win32/tbs","version":"2.0.0","keywords":["bun","ffi","win32","windows","tbs","bindings","typescript","dll"],"author":"Stev Peifer <stev.p@outlook.com>","license":"MIT","_id":"@bun-win32/tbs@2.0.0","maintainers":[{"name":"obscuritysrl","email":"stev.p@outlook.com"}],"homepage":"https://github.com/ObscuritySRL/bun-win32#readme","bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"dist":{"shasum":"f295083538c48d6b09a7776d37f262af5490e4b9","tarball":"https://registry.npmjs.org/@bun-win32/tbs/-/tbs-2.0.0.tgz","fileCount":6,"integrity":"sha512-8qKlriw4Gg+QZDDwVxq4zzuht1HHrSsX+k0k9qpbwdpHOk4m6nqQIVG6VK2sQ3QXFEM59F82HG/fMy62yPaFow==","signatures":[{"sig":"MEQCIAYs8KTxILb0hH+zWF8isP/9ODgjEOxl0HdAlPec9S/CAiBvocFuV7KyUS4j+ZvVBGgBDkmhZih3zA3pF4OxTi9N6A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":17058},"main":"./index.ts","type":"module","module":"index.ts","shasum":"f295083538c48d6b09a7776d37f262af5490e4b9","engines":{"bun":">=1.1.0"},"exports":{".":"./index.ts"},"private":false,"scripts":{"example:tpm-diagnostic":"bun ./example/tpm-diagnostic.ts","example:tpm-entropy-fountain":"bun ./example/tpm-entropy-fountain.ts"},"_npmUser":{"name":"obscuritysrl","email":"stev.p@outlook.com"},"_integrity":"sha512-8qKlriw4Gg+QZDDwVxq4zzuht1HHrSsX+k0k9qpbwdpHOk4m6nqQIVG6VK2sQ3QXFEM59F82HG/fMy62yPaFow==","repository":{"url":"git://github.com/ObscuritySRL/bun-win32.git","type":"git","directory":"packages/tbs"},"_npmVersion":"10.8.3","description":"Zero-dependency, zero-overhead Win32 TBS (TPM Base Services) bindings for Bun (FFI) on Windows.","directories":{},"sideEffects":false,"_nodeVersion":"26.3.0","dependencies":{"@bun-win32/core":"2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@bun-win32/kernel32":"2.0.0"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/tbs_2.0.0_1782435968875_0.8638337802907745","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"author":"Stev Peifer <stev.p@outlook.com>","bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"dependencies":{"@bun-win32/core":"2.0.1"},"description":"Zero-dependency, zero-overhead Win32 TBS (TPM Base Services) bindings for Bun (FFI) on Windows.","devDependencies":{"@bun-win32/kernel32":"2.0.1","@types/bun":"latest"},"exports":{".":"./index.ts"},"license":"MIT","module":"index.ts","name":"@bun-win32/tbs","peerDependencies":{"typescript":"^5"},"private":false,"homepage":"https://github.com/ObscuritySRL/bun-win32#readme","repository":{"type":"git","url":"git://github.com/ObscuritySRL/bun-win32.git","directory":"packages/tbs"},"type":"module","version":"2.0.1","main":"./index.ts","keywords":["bun","ffi","win32","windows","tbs","bindings","typescript","dll"],"sideEffects":false,"engines":{"bun":">=1.1.0"},"scripts":{"example:tpm-entropy-fountain":"bun ./example/tpm-entropy-fountain.ts","example:tpm-diagnostic":"bun ./example/tpm-diagnostic.ts"},"_id":"@bun-win32/tbs@2.0.1","_integrity":"sha512-BxlRX9fulzQ1oPw7oLYZ7Pil+cI0Q8gueGk2fu6uMOPUs8whyvr2RZBFUlm87upDurLD3y70ZU+eLOfnyOngOw==","_nodeVersion":"26.3.0","_npmVersion":"10.8.3","shasum":"63c200aee863ad3e48d468e713028ab835e67d94","dist":{"integrity":"sha512-BxlRX9fulzQ1oPw7oLYZ7Pil+cI0Q8gueGk2fu6uMOPUs8whyvr2RZBFUlm87upDurLD3y70ZU+eLOfnyOngOw==","shasum":"63c200aee863ad3e48d468e713028ab835e67d94","tarball":"https://registry.npmjs.org/@bun-win32/tbs/-/tbs-2.0.1.tgz","fileCount":6,"unpackedSize":17058,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIA+8J+l2ifu4aFQOmGeEE1eVJPEn80FsLiOuNvUpx38TAiEA5BihW9+9SjSZMfHfGvD7An/72fCjTJ9eaidMjptsuAA="}]},"_npmUser":{"name":"obscuritysrl","email":"stev.p@outlook.com"},"directories":{},"maintainers":[{"name":"obscuritysrl","email":"stev.p@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tbs_2.0.1_1782438175015_0.07485526090102912"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-19T00:29:05.141Z","modified":"2026-06-26T01:42:55.294Z","1.0.0":"2026-05-19T00:29:05.461Z","2.0.0":"2026-06-26T01:06:09.050Z","2.0.1":"2026-06-26T01:42:55.149Z"},"bugs":{"url":"https://github.com/ObscuritySRL/bun-win32/issues"},"author":"Stev Peifer <stev.p@outlook.com>","license":"MIT","homepage":"https://github.com/ObscuritySRL/bun-win32#readme","keywords":["bun","ffi","win32","windows","tbs","bindings","typescript","dll"],"repository":{"type":"git","url":"git://github.com/ObscuritySRL/bun-win32.git","directory":"packages/tbs"},"description":"Zero-dependency, zero-overhead Win32 TBS (TPM Base Services) bindings for Bun (FFI) on Windows.","maintainers":[{"name":"obscuritysrl","email":"stev.p@outlook.com"}],"readme":"# @bun-win32/tbs\n\nZero-dependency, zero-overhead Win32 TBS (TPM Base Services) bindings for [Bun](https://bun.sh) on Windows.\n\n## Overview\n\n`@bun-win32/tbs` exposes the `tbs.dll` exports using [Bun](https://bun.sh)'s FFI. It provides a single class, `Tbs`, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via `Preload()`.\n\nTPM Base Services (TBS) is the supported user-mode gateway to the Trusted Platform Module: open a context, submit raw TPM 2.0 command buffers (`TPM2_GetRandom`, `TPM2_GetCapability`, attestation, …), read the TCG measured-boot event log, fetch the device's Windows AIK ID, and query owner-auth. This is the foundation for attestation, sealing, and compliance tooling.\n\nThe bindings are strongly typed for a smooth DX in TypeScript.\n\n## Features\n\n- [Bun](https://bun.sh)-first ergonomics on Windows 10/11.\n- Direct FFI to `tbs.dll` (TPM context, command submit, TCG log, device ID, owner-auth).\n- In-source docs in `structs/Tbs.ts` with links to Microsoft Docs.\n- Lazy binding on first call; optional eager preload (`Tbs.Preload()`).\n- No wrapper overhead; calls map 1:1 to native APIs.\n- Strongly-typed Win32 aliases (see `types/Tbs.ts`).\n\n## Requirements\n\n- [Bun](https://bun.sh) runtime\n- Windows 10 or later, with a TPM 2.0 device\n\n## Installation\n\n```sh\nbun add @bun-win32/tbs\n```\n\n## Quick Start\n\n```ts\nimport Tbs, { TBS_COMMAND_LOCALITY_ZERO, TBS_COMMAND_PRIORITY_NORMAL, TBS_CONTEXT_VERSION_TWO, TBS_SUCCESS } from '@bun-win32/tbs';\n\n// TBS_CONTEXT_PARAMS2 { version; includeTpm20 }\nconst params = Buffer.alloc(8);\nparams.writeUInt32LE(TBS_CONTEXT_VERSION_TWO, 0);\nparams.writeUInt32LE(0b100, 4); // includeTpm20\n\nconst ctx = Buffer.alloc(8);\nif (Tbs.Tbsi_Context_Create(params.ptr, ctx.ptr) === TBS_SUCCESS) {\n  const hContext = ctx.readBigUInt64LE(0);\n\n  // TPM2_GetRandom(16) — pull 16 bytes from the hardware RNG.\n  const cmd = Buffer.alloc(12);\n  cmd.writeUInt16BE(0x8001, 0); // TPM_ST_NO_SESSIONS\n  cmd.writeUInt32BE(12, 2); // commandSize\n  cmd.writeUInt32BE(0x0000017b, 6); // TPM_CC_GetRandom\n  cmd.writeUInt16BE(16, 10); // bytesRequested\n\n  const resp = Buffer.alloc(64);\n  const respLen = Buffer.alloc(4);\n  respLen.writeUInt32LE(resp.byteLength, 0);\n  Tbs.Tbsip_Submit_Command(hContext, TBS_COMMAND_LOCALITY_ZERO, TBS_COMMAND_PRIORITY_NORMAL, cmd.ptr, cmd.byteLength, resp.ptr, respLen.ptr);\n\n  const size = resp.readUInt16BE(10);\n  console.log('TPM random:', resp.subarray(12, 12 + size).toString('hex'));\n\n  Tbs.Tbsip_Context_Close(hContext); // always pair with Tbsi_Context_Create\n}\n```\n\n> [!NOTE]\n> AI agents: see `AI.md` for the package binding contract and source-navigation guidance. It explains how to use the package without scanning the entire implementation.\n\n## Examples\n\nRun the included examples:\n\n```sh\nbun run example/tpm-entropy-fountain.ts\nbun run example/tpm-diagnostic.ts\n```\n\n## Notes\n\n- Either rely on lazy binding or call `Tbs.Preload()`.\n- Always pair `Tbsi_Context_Create` with `Tbsip_Context_Close`.\n- `Tbsip_Submit_Command` takes a raw TPM command buffer (big-endian) and writes the raw response; you build/parse the TPM wire format yourself.\n- `Tbsi_Get_TCG_Log` / `GetDeviceID` use the sizing-call pattern: call with `NULL` first to learn the required length.\n- Result codes are `TBS_RESULT` (`0` = `TBS_SUCCESS`); `GetDeviceID*` return `HRESULT`.\n- Windows only. Bun runtime required.\n- **SAL types & naming:** nullability is in the **type** — `Optional<T>` (formally optional, SAL `_*opt_`) and `Nullable<T>` (plain `[in]`/`[out]` the docs say can be NULL), the null sentinel derived from `T` (`null` for pointers `LP*`/`P*`, `0n` for handles/by-value addresses); direction is in the **parameter name** — `_out` (`_Out_`), `_in_out` (`_Inout_`), `_In_` bare. See `AI.md` and the repo `AGENTS.md`.\n","readmeFilename":"README.md"}