4.9.83 • Published 2 years ago

@hishprorg/cum-assumenda v4.9.83

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

4.9.82

2 years ago

3.9.82

2 years ago

3.8.82

2 years ago

3.8.81

2 years ago

3.8.80

2 years ago

3.8.79

2 years ago

3.8.78

2 years ago

3.8.77

2 years ago

3.8.76

2 years ago

3.8.75

2 years ago

3.8.74

2 years ago

3.8.73

2 years ago

3.8.72

2 years ago

2.8.72

2 years ago

2.8.71

2 years ago

2.8.70

2 years ago

2.8.69

2 years ago

2.8.68

2 years ago

2.8.67

2 years ago

2.8.66

2 years ago

2.8.65

2 years ago

2.8.64

2 years ago

2.8.63

2 years ago

2.8.62

2 years ago

2.8.61

2 years ago

2.8.60

2 years ago

2.8.59

2 years ago

2.8.58

2 years ago

2.7.58

2 years ago

2.6.58

2 years ago

2.6.57

2 years ago

2.6.56

2 years ago

2.6.55

2 years ago

2.6.54

2 years ago

2.6.53

2 years ago

2.6.52

2 years ago

2.6.51

2 years ago

2.6.50

2 years ago

2.6.49

2 years ago

2.6.48

2 years ago

2.6.47

2 years ago

2.6.46

2 years ago

2.6.45

2 years ago

2.6.44

2 years ago

2.5.44

2 years ago

2.5.43

2 years ago

2.5.42

2 years ago

2.4.42

2 years ago

2.4.41

2 years ago

2.4.40

2 years ago

2.4.39

2 years ago

2.4.38

2 years ago

2.4.37

2 years ago

2.4.36

2 years ago

2.4.35

2 years ago

2.4.34

2 years ago

2.4.33

2 years ago

2.4.32

2 years ago

2.4.31

2 years ago

2.3.31

2 years ago

2.2.31

2 years ago

2.2.30

2 years ago

2.2.29

2 years ago

2.2.28

2 years ago

2.2.27

2 years ago

2.2.26

2 years ago

2.2.25

2 years ago

2.2.24

2 years ago

2.2.23

2 years ago

2.2.22

2 years ago

2.2.21

2 years ago

2.2.20

2 years ago

2.2.19

2 years ago

2.2.18

2 years ago

2.2.17

2 years ago

2.2.16

2 years ago

2.2.15

2 years ago

2.2.14

2 years ago

2.2.13

2 years ago

2.2.12

2 years ago

2.2.11

2 years ago

2.1.11

2 years ago

2.1.10

2 years ago

2.1.9

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

1.1.4

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago