{"name":"otpauth","version":"9.0.2","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"],"author":{"name":"Héctor Molinero Fernández","email":"hector@molinero.dev"},"license":"MIT","_id":"otpauth@9.0.2","maintainers":[{"name":"hectormolinero","email":"hector@molinero.dev"}],"homepage":"https://github.com/hectorm/otpauth","bugs":{"url":"https://github.com/hectorm/otpauth/issues"},"dist":{"shasum":"5f369bdeb74513fb6c0f25c5ae5ac6b3780ebc89","tarball":"http://registry-npm.ywwl.com/otpauth/download/otpauth-9.0.2.tgz","fileCount":16,"integrity":"sha512-0TzpkJYg24VvIK3/K91HKpTtMlwm73UoThhcGY8fZsXcwHDrqf008rfdOjj3NnQuyuT11+vHyyO//qRzi6OZ9A==","signatures":[{"sig":"MEQCIDZjZwMDMj/424DdT8f0IzAN4UD3yX+pG1tQySABUPHtAiB+jzClQZjtOO5FF15VrtnqcNkRALVpiaS3q+UDpebLhA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":491209,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjbXX1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqxAg//YuaBzf2muOGQHjeK0XmtXmRQiIf8Luh+kT5HPLnYnVqQ4soJ\r\n/wuPYn93aGbKBNeXQiebLuloJDg9smDm1gLxSqVzyfRqPJ0Un8OGcNkY4rlN\r\nIv9UzOLQbRM36A8WCCkHvjy64zKJBMcnrSUNZwR9mdgNTvG9e4HrIPCoiOl4\r\nq/N1aIhG1dmujZcArrNEA+3s59S0g3TimhI8pB/ItyrH8kXWQd3qtqPnaKGo\r\n26nD/jNutuJYBWYfb12flSAem1jOGEaEhBquNQrl6UqBF3mIMuXniLNCCQ2b\r\nm8oKal16WIBuQIhA0UEMZBlV3riIoMcl4STa7TQReiVf74mJBhlkYhHT9/Lm\r\nr5uHV1qR1ahC3VSqp6l4wnkegPx1NDrgRClJut5VxsS7grdoz0pZUiS+XQSB\r\nlKCSyXeUafjppRDuF15YsSwpBw2SNUdDhH+iBCUYpnhjGWRNm0Sndc2zWiPZ\r\nvnAc8s6ofg21zkisTFIGu6BS62tgisHAAHdMqsjXBfKUfTRzf/MTYoBkPJ4m\r\neAEjIQLfnmoL6sjSNUkm2tZc96HE93jmEYZ1D2taX2PhIeBDCGYGc+klpq9W\r\nRkX+uQzcmspCBEcklvo972V6Bc/fVTZk/nOX5qJ3J2WUCf94uMZbe2DZJGI5\r\nI3Y9RSKuz3a23WyhF1h3D5Qat9ElXxOSPy8=\r\n=fSBl\r\n-----END PGP SIGNATURE-----\r\n","size":127509,"noattachment":false,"key":"/otpauth/-/otpauth-9.0.2.tgz"},"main":"./dist/otpauth.node.cjs","type":"module","types":"./dist/otpauth.d.ts","exports":{".":{"node":{"import":"./dist/otpauth.node.mjs","require":"./dist/otpauth.node.cjs"},"types":"./dist/otpauth.d.ts","default":"./dist/otpauth.esm.js"},"./dist/*":{"types":"./dist/otpauth.d.ts","default":"./dist/*"}},"funding":"https://github.com/hectorm/otpauth?sponsor=1","gitHead":"64ac5665f67fd603df0b523a466976e6937d5de2","scripts":{"all":"run-s lint types build docs test","docs":"run-s docs:clean docs:compile","lint":"eslint --ext .js --ext .mjs --ext .cjs ./","test":"run-s test:*","build":"run-s build:clean build:compile","types":"run-s types:clean types:compile","version":"run-s all && git add -A ./types/ ./dist/ ./docs/","test:deno":"run-s test:deno:*","test:node":"run-s test:node:*","docs:clean":"rimraf ./docs/","build:clean":"rimraf ./dist/","types:clean":"rimraf ./types/","docs:compile":"typedoc ./src/index.js --emit docs --readme none --theme default --out ./docs/","test:browser":"run-s test:browser:*","build:compile":"rollup -c","test:deno:esm":"run-s test:deno:esm:*","test:node:cjs":"run-s test:node:cjs:*","test:node:esm":"run-s test:node:esm:*","types:compile":"tsc","test:deno:esm:min":"deno test --allow-read=./dist/ --allow-net=deno.land ./test/test.mjs -- ../dist/otpauth.esm.min.js","test:node:cjs:min":"node ./test/test.mjs ../dist/otpauth.node.min.cjs","test:node:esm:min":"node ./test/test.mjs ../dist/otpauth.node.min.mjs","test:browser:webkit":"run-s test:browser:webkit:*","test:deno:esm:unmin":"deno test --allow-read=./dist/ --allow-net=deno.land ./test/test.mjs -- ../dist/otpauth.esm.js","test:node:cjs:unmin":"node ./test/test.mjs ../dist/otpauth.node.cjs","test:node:esm:unmin":"node ./test/test.mjs ../dist/otpauth.node.mjs","test:browser:firefox":"run-s test:browser:firefox:*","test:browser:chromium":"run-s test:browser:chromium:*","test:browser:webkit:umd":"run-s test:browser:webkit:umd:*","test:browser:firefox:umd":"run-s test:browser:firefox:umd:*","test:browser:chromium:umd":"run-s test:browser:chromium:umd:*","test:browser:webkit:umd:min":"node ./test/playwright.mjs webkit ../dist/otpauth.umd.min.js","test:browser:firefox:umd:min":"node ./test/playwright.mjs firefox ../dist/otpauth.umd.min.js","test:browser:chromium:umd:min":"node ./test/playwright.mjs chromium ../dist/otpauth.umd.min.js","test:browser:webkit:umd:unmin":"node ./test/playwright.mjs webkit ../dist/otpauth.umd.js","test:browser:firefox:umd:unmin":"node ./test/playwright.mjs firefox ../dist/otpauth.umd.js","test:browser:chromium:umd:unmin":"node ./test/playwright.mjs chromium ../dist/otpauth.umd.js"},"_npmUser":{"name":"hectormolinero","email":"hector@molinero.dev"},"repository":{"url":"git+https://github.com/hectorm/otpauth.git","type":"git"},"_npmVersion":"8.19.2","description":"One Time Password (HOTP/TOTP) library for Node.js, Deno and browsers","directories":{},"_nodeVersion":"18.12.0","dependencies":{"jssha":"~3.3.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"~4.3.7","test":"~3.2.1","mocha":"~10.1.0","eslint":"~8.27.0","rimraf":"~3.0.2","rollup":"~3.2.5","typedoc":"~0.23.20","prettier":"~2.7.1","playwright":"~1.27.1","typescript":"~4.7.4","@babel/core":"~7.20.2","@types/node":"~18.11.9","npm-run-all":"~4.1.5","@babel/preset-env":"~7.20.2","rollup-plugin-dts":"~5.0.0","@babel/eslint-parser":"~7.19.1","@babel/eslint-plugin":"~7.19.1","@rollup/plugin-babel":"~6.0.2","rollup-plugin-esbuild":"~5.0.0","@rollup/plugin-replace":"~5.0.1","@rollup/plugin-virtual":"~3.0.1","eslint-config-prettier":"~8.5.0","eslint-plugin-prettier":"~4.2.1","@rollup/plugin-node-resolve":"~15.0.1"},"_npmOperationalInternal":{"tmp":"tmp/otpauth_9.0.2_1668118005518_0.17075728334737827","host":"s3://npm-registry-packages"},"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":1668118005632,"_cnpm_publish_time":1668118005632,"dist-tags":{"latest":"9.6.0"}}