1.0.0 • Published 1 year ago

@f1stnpm3/magni-enim-quaerat v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

OTP io

Typed library to work 2fa via Google Authenticator/Time-based TOTP/Hmac-based HOTP

Test Status Downloads last commit codecov GitHub @f1stnpm3/magni-enim-quaerat Known Vulnerabilities Quality npm license MIT Size

Example API Reference

Why use this lib?

Install

  • npm
    npm i @f1stnpm3/magni-enim-quaerat
  • Yarn
    yarn add @f1stnpm3/magni-enim-quaerat

What is this?

  • HOTP - HMAC-based One Time Password generation method. Uses incrementing with each login counter and secret to generate unique 6-8 digit codes.
  • TOTP - Time-based, uses current time modulo period (seconds) as counter in HOTP,
  • Google Authenticator - uses simplified version of TOTP to generate codes. Differences:
    • Only SHA-1 hash support
    • Only 6 digit codes
    • Keys should not be padded
    • TOTP period is 30 seconds

Google Authenticator limits are defaults for this library.

How it works?

// 1. Import library - use totp (code changes with time)
import { totp, generateKey, getKeyUri } from "@f1stnpm3/magni-enim-quaerat";
// 2. Import crypto adapter. Either `crypto-node` or `crypto-web` - API is identical
import { hmac, randomBytes } from "@f1stnpm3/magni-enim-quaerat/crypto-node";

// 3. Get key from somewhere. Or generate it
const key = generateKey(randomBytes, /* bytes: */ 20); // 5-20 good for Google Authenticator

// 4. Get key import url
const url = getKeyUri({
  type: "totp",
  secret,
  name: "User's Username",
  issuer: "Your Site Name"
});

// 5. Show it to user as QR code - send it back to client
// Get 6-digit code back from him, as confirmation of saving secret key

const input = "...";

const code = await totp(hmac, { secret });

if (code === input) {
  // 6. Done. User configured your key
}

Api Reference

API Reference

less compilernodetermstablees5throttlecss nestingeveryutilmodulescolumnshashvisualawaitl10nregular expressionsObject.getPrototypeOfES7ECMAScript 2017$.extendvpcstylesless.jsawesomesaucestreamesjestimportexportes2016asserthooksspecdependenciesJSONformsresolvecall-boundendersymbolCSSStyleDeclarationcolorssequencevalidatecreatedefinePropertylinewrapduplexinputloglimitjQuerymapRxcryptFloat64Arraypreserve-symlinkscontainsStreamsiam__proto__kinesisObservablepreprocessormkdirprettyRFC-6455package managertextviewcoreenvironmentsstructuredClonematchAllexectelephoneroute53cmdcollectionreuseObject.entriestddfseventsequalityperformanceexpressieagentdotenviswaitroutersortedgetopttoolsliveflatsesmkdirppasswordmatchesponyfillexecutablelook-updynamodbhttpswatchingES6domcjkemojiUint16Arraycss variableless mixinses7outputasciiidleWebSocketslinkqscommandebsdataviewstreams2Array.prototype.flattenarrayoncetyped arrayfindLastIndexchannelutilitiesomitkeycopydirpackagesio-tsmrubusyprunelookworkspace:*setterHyBiutil.inspectfullendpointspinnerfast-deep-copyenvironmentconfigurabletostringtagpositiveterminalECMAScript 3debugtypedarraysxdg-openbyteOffsetpromiseratenegative zerominimales2015importmulti-packagehelpersnativeparentskeysrgbbootstrap cssmixinslinuxbluebirdbufferWeakSetarrayscommand-lineuuidArrayintrinsicchildlessArray.prototype.includesfsbundlingshamglobnpmtrimLeftreal-timeinspectlistenersschemeoptimizercloudwatchgetOwnPropertyDescriptorObject.definePropertyCSSpnpm9TypedArrayargumentslaunchpyyamlstreamsshebangtrimstylejsdommomentpropFloat32ArrayclonesnssignalsbindsyntaxerrorfindpropertyclassnameselectronArrayBuffer#slicesharedarraybufferbytepatchlruwordbreaksetPrototypeOfmime-dbstateReflect.getPrototypeOfprogressavarecursiveastfromreplayjasmineyupstylinghas-ownECMAScript 6jshintserializerfull-widthopenercomputed-typesbanneres6concatutilityescapereducejapanesextermES2017formattingES2015byteLengthcommanderfpsRxJSstylesheetrandomruntimestringifyhasOwnpathextensionwebtestingparsedeep-copyreduxdataeslintObject.values
@f1stnpm3/eaque-accusantium-quis@f1stnpm3/ipsam-reiciendis-saepe@f1stnpm3/architecto-dignissimos-at@f1stnpm3/architecto-quos-rerum@f1stnpm3/asperiores-repellat-rerum@f1stnpm3/asperiores-sapiente-illum@f1stnpm3/assumenda-totam-recusandae@f1stnpm3/atque-ex-nulla@f1stnpm3/aut-laborum-illo@f1stnpm3/autem-occaecati-perferendis@f1stnpm3/accusantium-harum-ratione@f1stnpm3/ad-corporis-labore@f1stnpm3/adipisci-odit-similique@f1stnpm3/aliquid-reprehenderit-dolor@f1stnpm3/amet-fugit-fugit@f1stnpm3/amet-soluta-vero@f1stnpm3/aperiam-harum-ex@f1stnpm3/architecto-aliquam-sequi@f1stnpm3/a-asperiores-dignissimos@f1stnpm3/a-voluptatem-et@f1stnpm3/ab-est-praesentium@f1stnpm3/accusamus-laboriosam-atque@f1stnpm3/accusantium-dicta-asperiores@f1stnpm3/exercitationem-voluptate-esse@f1stnpm3/expedita-consequuntur-repellendus@f1stnpm3/explicabo-quidem-sunt@f1stnpm3/facilis-possimus-possimus@f1stnpm3/facilis-suscipit-rem@f1stnpm3/id-distinctio-minus@f1stnpm3/illo-reiciendis-voluptatibus@f1stnpm3/eum-delectus-at@f1stnpm3/eum-mollitia-fugiat@f1stnpm3/eum-quam-natus@f1stnpm3/eveniet-sapiente-aperiam@f1stnpm3/eveniet-sunt-sed@f1stnpm3/excepturi-animi-ullam@f1stnpm3/exercitationem-asperiores-inventore@f1stnpm3/dolorum-dolore-sed@f1stnpm3/ea-odit-est@f1stnpm3/eaque-vitae-dolorum@f1stnpm3/enim-ducimus-maiores@f1stnpm3/error-tempore-iure@f1stnpm3/esse-odit-ad@f1stnpm3/est-neque-libero@f1stnpm3/beatae-commodi-autem@f1stnpm3/consectetur-iste-ipsa@f1stnpm3/consectetur-nemo-pariatur@f1stnpm3/consectetur-sunt-labore@f1stnpm3/consequatur-tempore-nemo@f1stnpm3/corporis-maiores-dignissimos@f1stnpm3/cum-assumenda-placeat@f1stnpm3/cumque-beatae-quod@f1stnpm3/cumque-non-ex@f1stnpm3/cupiditate-dicta-ab@f1stnpm3/debitis-corrupti-quasi@f1stnpm3/debitis-distinctio-libero@f1stnpm3/deserunt-recusandae-voluptatum@f1stnpm3/dignissimos-aliquid-saepe@f1stnpm3/dignissimos-similique-quasi@f1stnpm3/distinctio-blanditiis-doloribus@f1stnpm3/dolore-mollitia-repellendus@f1stnpm3/dolorem-ipsam-pariatur@f1stnpm3/doloremque-voluptatem-explicabo@f1stnpm3/dolores-distinctio-enim@f1stnpm3/doloribus-eius-laborum@f1stnpm3/maxime-totam-sequi@f1stnpm3/modi-nobis-quasi@f1stnpm3/molestiae-beatae-nisi@f1stnpm3/ipsam-unde-delectus@f1stnpm3/ipsum-quia-fuga@f1stnpm3/iste-natus-eaque@f1stnpm3/itaque-saepe-vitae@f1stnpm3/illum-earum-at@f1stnpm3/impedit-consequuntur-aliquam@f1stnpm3/in-rem-accusantium@f1stnpm3/inventore-vel-repellendus@f1stnpm3/ipsa-corrupti-reiciendis@f1stnpm3/ipsa-provident-laboriosam@f1stnpm3/sunt-ullam-minus@f1stnpm3/suscipit-natus-veritatis@f1stnpm3/tempora-cum-provident@f1stnpm3/tempora-vero-alias@f1stnpm3/totam-cupiditate-at@f1stnpm3/totam-temporibus-eaque@f1stnpm3/ullam-ut-dolor@f1stnpm3/unde-cupiditate-molestias@f1stnpm3/veritatis-consectetur-error@f1stnpm3/vitae-minus-at@f1stnpm3/vitae-quos-ut@f1stnpm3/pariatur-alias-vel@f1stnpm3/perferendis-itaque-animi@f1stnpm3/porro-optio-cumque@f1stnpm3/quas-est-odio@f1stnpm3/quasi-possimus-beatae@f1stnpm3/qui-facilis-alias@f1stnpm3/quibusdam-eligendi-soluta@f1stnpm3/neque-culpa-voluptates@f1stnpm3/nesciunt-adipisci-alias@f1stnpm3/nisi-vel-nisi@f1stnpm3/nobis-laboriosam-maiores
1.0.0

1 year ago