4.9.83 • Published 9 months ago

@hishprorg/cum-assumenda v4.9.83

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

OTP io

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

Test Status Downloads last commit codecov GitHub @hishprorg/cum-assumenda Known Vulnerabilities Quality npm license MIT Size

Example API Reference

Why use this lib?

Install

  • npm
    npm i @hishprorg/cum-assumenda
  • Yarn
    yarn add @hishprorg/cum-assumenda

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 "@hishprorg/cum-assumenda";
// 2. Import crypto adapter. Either `crypto-node` or `crypto-web` - API is identical
import { hmac, randomBytes } from "@hishprorg/cum-assumenda/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

protoECMAScript 2015parseryamllocationemrtimeiteratorjsdom0pnpm9utilitiestsArraystableES2018hookscall-bindidentifiersbinarywindowfeedfolderbusyoptimistroutingserializersqsfindLastrangeerrorrssReactiveExtensionshttpsbinreverseinputtermsyntaxjsonES5redux-toolkitcomputed-typesbyteLengthfastcopyURLSearchParamsgetPrototypeOfArray.prototype.containsyuparktypeinferenceequalityES2019assertscolumnES2016cjkpropthreeobjectomitreduxdom-testing-libraryawstypesafespinnerstructuredCloneeslint-pluginhigher-orderreadablestreamRxSymboltapindicatorelasticachereact animationrouterconsolecompilereventDispatchersharedenderweaksetfprulesebsbabel-coreacornpinoelectrontransportObject.ispackage managermkdirtc39fastifycolourdescriptorsprivatemobilebytecloudsearchexecutemkdirsmergeunicodeRegExp#flagsecmascriptvestcolorskeysjestmakexmlio-tsdiffObject.valuesuser-streamsvaluesECMAScript 5qsdefinePropertypatchtrimisConcatSpreadablestreamsarraybufferairbnbpluginargsbindisUint32Arrayloadinghas-owntrimRightimportexportavaemitTypeScriptsameValueZeroparentparentsuuidcsswaitutil.inspectfast-deep-clonelistenerses-shimsroute53ES2020urlec2karmaredacttoStringTagdataViewqueueprocesscloudformationtoobjectclonedirajaxfunction.lengthstyleguiderm -frschemeES7ECMAScript 2022class-validator6to5typedarrayxhrregular expressiondefineArrayBuffer#sliceestreeescloudwatchprotocol-buffersansisyntaxerrorECMAScript 2019propertyformatflatfastclonelocalbddgenericsES3Pushmovees7es2016rmlengthform-validationgetintrinsicforkgroupdebugdeep-clonemapreducestarterownchannelObject.definePropertystylesconsumehasOwnfast-copyasciishimtestinstrumentationbinariesparsees2018callprotobufredirectflattencommand-linenpmignoreUint8ClampedArrayeffect-tseast-asian-widthpureextrarandomTypeBoxinternal slotreducerobust$.extendtrimEndmanipulationsetImmediateconstgesturesWebSocketsworkspace:*sideArray.prototype.flattenpathfullwidthmonorepoECMAScript 2018seswalkingqueueMicrotaskdirectorysymlinksreact poserequestrecursivetoArrayInt16ArrayworkerflagReflect.getPrototypeOfdataviewbundlinges-abstractefficientsimpledbArray.prototype.flatMapcircularlogargvsource mapequaldeepclienttelephoneObject.entriescode pointsmkdirpquerybrowserslistUint8Arraypushsliceapideterministictypesignore@@toStringTagfixed-widthcallbackenvironmentsrfc4122performanceinvarianteventEmitterentriescurriedcolorwaapiaccessibilityastRegExp.prototype.flagsfile systemgetterObject.assigni18npipe.envObservablestranspilerpostcsscoveragel10ntyped-0multi-packagebabelponyfillarraypyyamlECMAScript 2017reusematchjsforEachexectestingcloudfrontsubprocessregexresolvelogginglruclassnameshtmlbrowserlistperformantcreateemojitddvariablesnegativeflatMapdependency managershebangspringreact-hooksjsxnpmglobal objectschemanamesstoragegatewaystringifychromiumgraphqlchildgetoptfsswfsharedarraybuffercodesjson-schema-validationESnextformstyled-componentsmochaFloat64Arraytypeofsettingscryptofigletuninstalltslibiefunctiontyped arraywhichStyleSheetmomentquerystringinternalargumenttoolsmanagerprototypeconfigurablefullnodeBigUint64Arrayjsonschemaglacierfast-deep-copybuffersglobalsHyBiprettyRFC-6455endpointkinesiswritefromjQuerycachedescriptorincludessymbolsbyteOffsethashremoveboundchineseidlecensorhelpersfantasy-landterminaldescription3dsetterzodfps256toolkitagentvpchelperUnderscoresinatrawarningFloat32Arrays3globales8ArrayBuffer.prototype.sliceformattingObject.keysYAMLArrayBufferflagslibphonenumberstylemapArray.prototype.includesexpressionrgbquotemruwalkajvsomeamazonrm -rfasynchardlinksttypreprocessorArray.prototype.findLastpackageswhatwgdependenciesECMAScript 2021AsyncIteratorenvinspectnamedeepclonejsdiffstylingmetadatahaschromedeepcopyglobal this valueECMAScript 3resttransformObservablecharacterstreamregularCSShasOwnPropertyscheme-validationmodulesglobalThisintrinsicES2015json-schemaselfpropertieseventsvalidatorfilereducerloggereslintpluginassertionnativevaliddynamodbjson-schema-validatoreslintsetPrototypeOffindjapaneseECMAScript 2020jasmineStreamses2015functionalserializationutilString.prototype.trimfunctionsappfindLastIndexkeywritableTypedArray.gitignoreUint16ArraytypeharmonystringmodulecollectionproxygdprshamES6requiretypanionsafeObject.getPrototypeOfobjlookES2022upbannerrestfulwafvarswebtapeanimationPromiseObject.fromEntriesfilterautoprefixertouchartviewpicomatchistanbules-shim APIbeanstalkaccessorconfigreadableiteratenodejsdragsortedstringifierinstallsortutilityenvironmentiamSetcharacterscallboundfull-widthtraverseSymbol.toStringTaggetspawntranspilearraysshellmatchesdotenvreadmake dirSystem.globalset_.extendfindupeveryasteriskswgetWebSocketES2017Function.prototype.namesearchArray.prototype.flatcore-jsfast-clonea11ycss-in-jsexpressMapimportRxJSInt32ArrayprogresslintECMAScript 6reversedString.prototype.matchAllcommandonceassertreacterrorextendcontainsslotsuperstructECMAScript 7BigInt64ArraycolumnsnumberES2023execfilevarspecnopespinnersenumerabledroppositiveReactiveXescapekorean
4.9.83

9 months ago

4.9.82

9 months ago

3.9.82

9 months ago

3.8.82

9 months ago

3.8.81

9 months ago

3.8.80

9 months ago

3.8.79

9 months ago

3.8.78

9 months ago

3.8.77

9 months ago

3.8.76

9 months ago

3.8.75

9 months ago

3.8.74

9 months ago

3.8.73

9 months ago

3.8.72

9 months ago

2.8.72

9 months ago

2.8.71

9 months ago

2.8.70

9 months ago

2.8.69

9 months ago

2.8.68

9 months ago

2.8.67

9 months ago

2.8.66

9 months ago

2.8.65

9 months ago

2.8.64

9 months ago

2.8.63

9 months ago

2.8.62

9 months ago

2.8.61

9 months ago

2.8.60

9 months ago

2.8.59

9 months ago

2.8.58

10 months ago

2.7.58

10 months ago

2.6.58

10 months ago

2.6.57

10 months ago

2.6.56

10 months ago

2.6.55

10 months ago

2.6.54

10 months ago

2.6.53

10 months ago

2.6.52

10 months ago

2.6.51

10 months ago

2.6.50

10 months ago

2.6.49

10 months ago

2.6.48

10 months ago

2.6.47

10 months ago

2.6.46

10 months ago

2.6.45

10 months ago

2.6.44

10 months ago

2.5.44

10 months ago

2.5.43

10 months ago

2.5.42

10 months ago

2.4.42

10 months ago

2.4.41

10 months ago

2.4.40

10 months ago

2.4.39

10 months ago

2.4.38

10 months ago

2.4.37

10 months ago

2.4.36

10 months ago

2.4.35

10 months ago

2.4.34

10 months ago

2.4.33

10 months ago

2.4.32

11 months ago

2.4.31

11 months ago

2.3.31

11 months ago

2.2.31

11 months ago

2.2.30

11 months ago

2.2.29

11 months ago

2.2.28

11 months ago

2.2.27

11 months ago

2.2.26

11 months ago

2.2.25

11 months ago

2.2.24

11 months ago

2.2.23

11 months ago

2.2.22

11 months ago

2.2.21

11 months ago

2.2.20

11 months ago

2.2.19

11 months ago

2.2.18

11 months ago

2.2.17

11 months ago

2.2.16

11 months ago

2.2.15

11 months ago

2.2.14

11 months ago

2.2.13

11 months ago

2.2.12

11 months ago

2.2.11

11 months ago

2.1.11

11 months ago

2.1.10

11 months ago

2.1.9

11 months ago

2.1.8

11 months ago

2.1.7

11 months ago

2.1.6

11 months ago

2.1.5

12 months ago

2.1.4

12 months ago

1.1.4

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago