This library provides functionality to work with OTP (One-Time Password) tokens. It includes methods for registering new secrets, generating OTP tokens, stopping the token generation process, adding event listeners, and emitting events.
To use this library, you can import it using the following statement:
import { OtpToken } from 'path/to/OtpToken';
To initialize the OtpToken class, you can use the init method:
const otpToken = OtpToken.init({
hostUrl: 'https://example.com',
origin: 'example',
timeout: 300,
});
To register a new secret, you can call the register method:
otpToken.register({
referenceId: 'exampleId',
bearerToken: 'exampleToken'
onSuccess: (secret) => {
console.log('Secret registered:', secret);
},
onError: (error) => {
console.error('Error:', error);
},
});
To generate an OTP token, you can use the run method:
otpToken.run('yourSecretKey');
You can add event listeners for 'tick' and 'update' events using the on method:
const unsubscribe = otpToken.on('tick', (data) => {
console.log('Tick event:', data);
});
You can stop the token generation process by calling the stop method:
otpToken.stop();