Skip to content

API Reference


API Reference / DhanAuth

Class: DhanAuth

Defined in: src/auth/DhanAuth.ts:37

Constructors

Constructor

new DhanAuth(): DhanAuth

Returns

DhanAuth

Methods

generateTotp()

static generateTotp(secret, options?): string

Defined in: src/auth/DhanAuth.ts:45

RFC 6238 TOTP from a base32 secret.

Provided so a headless process can log in without a phone, but note that the secret is then as sensitive as the PIN — anything holding both can mint tokens for the account indefinitely.

Parameters

secret

string

options?

TotpOptions = {}

Returns

string


totpSecondsRemaining()

static totpSecondsRemaining(options?): number

Defined in: src/auth/DhanAuth.ts:63

Seconds until the current TOTP window rolls over.

Parameters

options?

Pick<TotpOptions, "timestamp" | "period"> = {}

Returns

number


generateAccessToken()

static generateAccessToken(request, dependencies?): Promise<TokenResponse>

Defined in: src/auth/DhanAuth.ts:72

Exchanges client id + PIN + TOTP for an access token.

Parameters

request

GenerateAccessTokenRequest

dependencies?

DhanAuthDependencies = {}

Returns

Promise<TokenResponse>


renewWebToken()

static renewWebToken(request, dependencies?): Promise<TokenResponse>

Defined in: src/auth/DhanAuth.ts:101

Extends an existing token without a fresh PIN/TOTP round trip.

Only works while the current token is still valid — once it has expired, generateAccessToken is the only way back in.

Parameters

request

RenewWebTokenRequest

dependencies?

DhanAuthDependencies = {}

Returns

Promise<TokenResponse>

Community project — not affiliated with Dhan. MIT License.