{"_id":"otpauth@9.5.2","bugs":{"url":"https://github.com/hectorm/otpauth/issues"},"dist":{"shasum":"0d8a4e3e41a215b05c75114d752d9142a0b36c2e","tarball":"http://registry-npm.ywwl.com/otpauth/download/otpauth-9.5.2.tgz","fileCount":23,"integrity":"sha512-GQ5emWR/x1tcExT62IBT0UfO95wZzJZyxYOJOGVeQF47SYEN9vmh0vISvDZaNMuFJRG+IaWCKtfm+t9Bfoal6w==","signatures":[{"sig":"MEUCIQDkMmRjC9KTslrb++DY1+f26JS9nBETosWvRRYM1Wxt9wIgK1vpxzDJ2+BysZFmlZvo49NC9M1Is/W0GdwIezR+/w8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDNA/4pAh/CQlvoeiJ0Faf7I5LY3qULCGWx10jtjbiU7wIhAJAfbcgRe1cJP6jqoATQlH4mzUhSINyKHlJd7QwnSAB+"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/otpauth@9.5.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":997251,"size":243533,"noattachment":false,"key":"/otpauth/-/otpauth-9.5.2.tgz"},"main":"./dist/otpauth.node.cjs","name":"otpauth","type":"module","types":"./dist/otpauth.d.ts","author":{"name":"Héctor Molinero Fernández","email":"hector@molinero.dev"},"browser":"./dist/otpauth.esm.js","exports":{".":{"bun":"./dist/otpauth.esm.js","deno":"./dist/otpauth.esm.js","node":{"import":"./dist/otpauth.node.mjs","require":"./dist/otpauth.node.cjs"},"types":{"import":"./dist/otpauth.d.ts","require":"./dist/otpauth.d.cts"},"default":"./dist/otpauth.esm.js"},"./bare":{"types":{"import":"./dist/otpauth.d.ts","require":"./dist/otpauth.d.cts"},"default":"./dist/otpauth.bare.esm.js"},"./slim":{"types":{"import":"./dist/otpauth.d.ts","require":"./dist/otpauth.d.cts"},"default":"./dist/otpauth.slim.esm.js"},"./dist/*":{"types":{"import":"./dist/otpauth.d.ts","require":"./dist/otpauth.d.cts"},"default":"./dist/*"}},"funding":"https://github.com/hectorm/otpauth?sponsor=1","gitHead":"5a0cb600fae0eb5be476db825f26fbf612a2dffd","license":"MIT","scripts":{"all":"run-s build docs lint test","docs":"run-s docs:clean docs:compile","lint":"run-s lint:eslint lint:prettier lint:tsc","test":"run-s test:node test:deno test:bun test:browser","build":"run-s build:clean build:types build:compile","format":"run-s format:eslint format:prettier","version":"run-s all version:jsr version:git","lint:tsc":"tsc --noEmit","test:bun":"run-s --npm-path bun test:bun:esm","test:deno":"run-s --npm-path deno test:deno:esm","test:node":"run-s test:node:esm test:node:cjs","docs:clean":"rimraf ./docs/","build:clean":"rimraf ./dist/","build:types":"run-s build:types:clean build:types:compile","lint:eslint":"eslint --max-warnings 0 ./","version:git":"git add -A ./jsr.json ./types/ ./dist/ ./docs/","version:jsr":"node ./scripts/jsr.mjs","docs:compile":"typedoc ./src/index.js --readme none --out ./docs/","test:browser":"run-s test:browser:chromium test:browser:firefox test:browser:webkit","test:bun:esm":"run-s --npm-path bun test:bun:esm:unmin test:bun:esm:min","test:quickjs":"run-s test:quickjs:esm","build:compile":"rollup -c","format:eslint":"eslint --fix ./","lint:prettier":"prettier --list-different ./","test:deno:esm":"run-s --npm-path deno test:deno:esm:unmin test:deno:esm:min","test:node:cjs":"run-s test:node:cjs:unmin test:node:cjs:min","test:node:esm":"run-s test:node:esm:unmin test:node:esm:min","format:prettier":"prettier --write ./","test:bun:esm:min":"bun test ./test/bun.test.min.mjs ","test:quickjs:esm":"run-s test:quickjs:esm:unmin test:quickjs:esm:min","build:types:clean":"rimraf ./types/","test:deno:esm:min":"deno test --no-npm --allow-read=./test/,./dist/ ./test/deno.test.min.mjs","test:node:cjs:min":"node ./test/node.test.min.cjs","test:node:esm:min":"node ./test/node.test.min.mjs","test:bun:esm:unmin":"bun test ./test/bun.test.mjs","build:types:compile":"tsc -p ./src/","test:browser:webkit":"run-s test:browser:webkit:umd","test:deno:esm:unmin":"deno test --no-npm --allow-read=./test/,./dist/ ./test/deno.test.mjs","test:node:cjs:unmin":"node ./test/node.test.cjs","test:node:esm:unmin":"node ./test/node.test.mjs","test:browser:firefox":"run-s test:browser:firefox:umd","test:quickjs:esm:min":"qjs ./test/quickjs.test.min.mjs ","test:browser:chromium":"run-s test:browser:chromium:umd","test:quickjs:esm:unmin":"qjs ./test/quickjs.test.mjs","test:browser:webkit:umd":"run-s test:browser:webkit:umd:unmin test:browser:webkit:umd:min","test:browser:firefox:umd":"run-s test:browser:firefox:umd:unmin test:browser:firefox:umd:min","test:browser:chromium:umd":"run-s test:browser:chromium:umd:unmin test:browser:chromium:umd:min","test:browser:webkit:umd:min":"node ./test/browser.test.min.mjs webkit","test:browser:firefox:umd:min":"node ./test/browser.test.min.mjs firefox","test:browser:chromium:umd:min":"node ./test/browser.test.min.mjs chromium","test:browser:webkit:umd:unmin":"node ./test/browser.test.mjs webkit","test:browser:firefox:umd:unmin":"node ./test/browser.test.mjs firefox","test:browser:chromium:umd:unmin":"node ./test/browser.test.mjs chromium"},"version":"9.5.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:20c9e536-fe2b-41c3-ab60-043f5e2b32e5"}},"homepage":"https://github.com/hectorm/otpauth","keywords":["otp","hotp","totp","one time password","2fa","2 factor","two factor","two-factor","2step","2 step","two step","two-step","auth","authenticator","google authenticator"],"repository":{"url":"git+https://github.com/hectorm/otpauth.git","type":"git"},"_npmVersion":"11.19.0","description":"One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers","directories":{},"maintainers":[{"name":"hectormolinero","email":"hector@molinero.dev"}],"_nodeVersion":"24.20.0","dependencies":{"@noble/hashes":"2.4.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"~6.2.2","mocha":"~11.8.0","eslint":"~10.9.1","rimraf":"~6.1.3","rollup":"~4.63.0","globals":"~17.11.0","typedoc":"~0.28.20","prettier":"~3.9.6","@swc/core":"~1.16.1","@eslint/js":"~10.0.1","playwright":"~1.62.1","typescript":"~6.0.3","@types/node":"~26.4.0","@eslint/core":"~1.2.1","npm-run-all2":"~9.0.3","@types/eslint":"~9.6.1","rollup-plugin-dts":"~6.5.1","@rollup/plugin-swc":"~0.4.1","@rollup/plugin-terser":"~1.0.0","@rollup/plugin-replace":"~6.0.3","@rollup/plugin-virtual":"~3.0.2","eslint-config-prettier":"~10.1.8","@rollup/plugin-node-resolve":"~16.0.3","@types/eslint-config-prettier":"~6.11.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/otpauth_9.5.2_1788475163150_0.8562284954785913"},"readme":"[![Last version](https://img.shields.io/github/v/tag/hectorm/otpauth?label=version)](https://github.com/hectorm/otpauth/tags)\n[![npm downloads](https://img.shields.io/npm/dm/otpauth?label=npm%20downloads)](https://www.npmjs.com/package/otpauth)\n\n<p align=\"center\">\n  <img alt=\"OTPAuth\" src=\"./resources/logo/OTPAuth-Color-Reduced.svg\" height=\"192\" />\n</p>\n\n# OTPAuth\n\nOne Time Password library for Node.js, Deno, Bun and browsers.\n\nIt supports the generation and validation of\nHMAC-Based One-Time Passwords (HOTP) as specified in [RFC 4226](https://datatracker.ietf.org/doc/html/rfc4226) and\nTime-Based One-Time Passwords (TOTP) as specified in [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238).\nFrequently used in Multi-Factor Authentication (MFA) / Two-Factor Authentication (2FA) systems.\n\n> [!TIP]\n> You can try the library with the demo application available at [otpauth.molinero.dev](https://otpauth.molinero.dev).\n>\n> If you wish to interact with the library in your browser console, the following snippet can be used:\n>\n> ```javascript\n> const OTPAuth = await import(\"otpauth\");\n> ```\n\n## Usage\n\nThis section presents an overview of the most common usage patterns, along with some security recommendations.\n\n### [Node.js / Bun](https://www.npmjs.com/package/otpauth)\n\n```javascript\nimport * as OTPAuth from \"otpauth\";\n// import * as OTPAuth from \"otpauth/slim\"; // Slim build without bundled dependencies.\n// import * as OTPAuth from \"otpauth/bare\"; // Bare build with no bundled crypto (requires providing a custom HMAC function).\n\n// Create a new TOTP object.\nlet totp = new OTPAuth.TOTP({\n  // Provider or service the account is associated with.\n  issuer: \"ACME\",\n  // Account identifier.\n  label: \"Alice\",\n  // Algorithm used for the HMAC function, possible values are:\n  //   \"SHA1\", \"SHA224\", \"SHA256\", \"SHA384\", \"SHA512\",\n  //   \"SHA3-224\", \"SHA3-256\", \"SHA3-384\" and \"SHA3-512\".\n  algorithm: \"SHA1\",\n  // Length of the generated tokens.\n  digits: 6,\n  // Interval of time for which a token is valid, in seconds.\n  period: 30,\n  // Arbitrary key encoded in base32 or `OTPAuth.Secret` instance\n  // (if omitted, a cryptographically secure random secret is generated).\n  secret: \"US3WHSG7X5KAPV27VANWKQHF3SH3HULL\",\n  //   or: `OTPAuth.Secret.fromBase32(\"US3WHSG7X5KAPV27VANWKQHF3SH3HULL\")`\n  //   or: `new OTPAuth.Secret()`\n  // Custom HMAC function (required for bare build, optional otherwise).\n  // hmac: (algorithm, key, message) => Uint8Array,\n});\n\n// Unless you know what you are doing, it is recommended to use the default\n// values for the algorithm, digits, and period options, as these are the most\n// common values used by most services.\n\n// Generate a cryptographically secure random secret.\n// It is NOT recommended to use less than 128 bits (16 bytes).\nlet secret = new OTPAuth.Secret({ size: 20 });\n\n// Generate a token (returns the current token as a string).\nlet token = totp.generate();\n\n// Validate a token (returns the token delta or null if it is not found in the\n// search window, in which case it should be considered invalid).\n//\n// A search window is useful to account for clock drift between the client and\n// server; however, it should be kept as small as possible to prevent brute\n// force attacks. In most cases, a value of 1 is sufficient. Furthermore, it is\n// essential to implement a throttling mechanism on the server.\n//\n// For further details on the security considerations, it is advised to refer\n// to Section 7 of RFC 4226 and Section 5 of RFC 6238:\n//   https://datatracker.ietf.org/doc/html/rfc4226#section-7\n//   https://datatracker.ietf.org/doc/html/rfc6238#section-5\nlet delta = totp.validate({ token, window: 1 });\n\n// Get the counter value (number of intervals since the Unix epoch).\n// Useful for implementing techniques against token reuse during the validity\n// period.\nlet counter = totp.counter();\n\n// Get the remaining milliseconds until the current token changes.\nlet remaining = totp.remaining();\n\n// Convert to Google Authenticator key URI format.\n// Usually the URI is encoded in a QR code that can be scanned by the user.\n// This functionality is outside the scope of the project, but there are many\n// libraries that can be used for this purpose, such as npmjs.com/package/qr\nlet uri = totp.toString();\n//   or:      `OTPAuth.URI.stringify(totp)`\n//   returns: `otpauth://totp/ACME:Alice?issuer=ACME&secret=US3WHSG7X5KAPV27VANWKQHF3SH3HULL&algorithm=SHA1&digits=6&period=30`\n\n// Convert from Google Authenticator key URI format.\ntotp = OTPAuth.URI.parse(uri);\n```\n\n### [Deno](https://jsr.io/@hectorm/otpauth)\n\n```javascript\nimport * as OTPAuth from \"jsr:@hectorm/otpauth\";\n\n// Same as above.\n```\n\n### [Browsers (ESM)](https://www.jsdelivr.com/package/npm/otpauth)\n\n```html\n<script type=\"importmap\">\n  {\n    \"imports\": { \"otpauth\": \"https://cdn.jsdelivr.net/npm/otpauth@%VERSION%/dist/otpauth.esm.min.js\" },\n    \"integrity\": { \"https://cdn.jsdelivr.net/npm/otpauth@%VERSION%/dist/otpauth.esm.min.js\": \"%HASH%\" }\n  }\n</script>\n<script type=\"module\">\n  import * as OTPAuth from \"otpauth\";\n\n  // Same as above.\n</script>\n```\n\n### [Browsers (UMD)](https://www.jsdelivr.com/package/npm/otpauth)\n\n```html\n<script\n  src=\"https://cdn.jsdelivr.net/npm/otpauth@%VERSION%/dist/otpauth.umd.min.js\"\n  integrity=\"%HASH%\"\n  crossorigin=\"anonymous\"\n  referrerpolicy=\"no-referrer\"\n></script>\n<script>\n  // Same as above.\n</script>\n```\n\n## Documentation\n\nFor additional information, please refer to the documentation page at [hectorm.github.io/otpauth/](https://hectorm.github.io/otpauth/).\n\n## License\n\n[MIT License](https://github.com/hectorm/otpauth/blob/master/LICENSE.md)\n© [Héctor Molinero Fernández](https://hector.molinero.dev/).\n","publish_time":1788475163225,"_cnpm_publish_time":1788475163225,"dist-tags":{"latest":"9.6.0"}}