https://github.com/hazae41/pendule
Time-based one-time passcodes (TOTP) for the web
https://github.com/hazae41/pendule
Last synced: about 2 months ago
JSON representation
Time-based one-time passcodes (TOTP) for the web
- Host: GitHub
- URL: https://github.com/hazae41/pendule
- Owner: hazae41
- License: mit
- Created: 2026-04-02T05:06:13.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-06-03T08:41:09.000Z (about 2 months ago)
- Last Synced: 2026-06-03T10:22:01.597Z (about 2 months ago)
- Language: TypeScript
- Size: 29.3 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
- awesome-ccamel - hazae41/pendule - Time-based one-time passcodes (TOTP) for the web (TypeScript)
README
# Pendule
Time-based one-time passcodes (TOTP) for the web
```bash
npm install @hazae41/pendule
```
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/pendule)
## Features
### Current features
- 100% TypeScript and ESM
- Minimal dependencies
- SHA-1 TOTP
## Usage
### SHA-1 TOTP
Parse generator secret
```tsx
const totp = Sha1Totp.parse("JBSWY3DPEHPK3PXP")
```
Parse generator url
```tsx
const totp = Sha1Totp.parse("otpauth://totp/?secret=AAAABBBB22223333YYYYZZZZ66667777")
```
### Codes
Generate the current code
```tsx
const code = await totp.generate()
```
Automatically update code (with a margin of error of 1 second)
```tsx
setInterval(() => {
code = await totp.generate()
}, 1000)
```
Log codes every time there is a new one
```tsx
const period = totp.period * 1000
const elapsed = Date.now() % period
const remaining = period - elapsed
setTimeout(() => {
console.log(await totp.generate())
setInterval(() => {
console.log(await totp.generate())
}, period)
// New codes will now be displayed
}, remaining)
```