Create session Time (allowSessionTimeWalletWithJWT)
A function Create JWT Session Token
The allowSessionTimeWalletWithJWT function creates a JWT session token from encrypted wallet data. It creates a time-limited JWT token with encrypted credentials for secure session management, allowing users to perform transactions without entering their password every time for convenience.
Import
import { allowSessionTimeWalletWithJWT } from "dacc-js";Usage
import { allowSessionTimeWalletWithJWT } from "dacc-js";
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'myPassword#123..',
jwtSecret: 'jwt-secret-to-app',
maxAgeSeconds: 3600 // 1 hour
});
console.log(jwt); // eyJhZGRyZXNz...Arguments
| Parameter | Type | Description |
|---|---|---|
daccPublickey | string | The encrypted wallet data. |
passwordSecretkey | string | User password for decrypting the wallet. |
jwtSecret | string | Secret key for JWT signing and encryption. |
maxAgeSeconds | number | Optional: Token expiration time in seconds (default: 3600). |
Return Value
Returns a JWT token string for session authentication.
Parameters
daccPublickey
- Type:
string
The encrypted wallet data returned from createDaccWallet.
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'jwt-secret-to-app',
maxAgeSeconds: 3600
});passwordSecretkey
- Type:
string
User password for decrypting the wallet.
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'jwt-secret-to-app',
maxAgeSeconds: 3600
});jwtSecret
- Type:
string
Secret key for JWT signing and encryption.
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'jwt-secret-to-app',
maxAgeSeconds: 3600
});maxAgeSeconds (optional)
- Type:
number - Default:
3600(1 hour)
Token expiration time in seconds.
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'jwt-secret-to-app',
maxAgeSeconds: 7200 // 2 hours
});Examples
Create short-term session (15 minutes)
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'your-jwt-secret-key',
maxAgeSeconds: 900 // 15 minutes
});
console.log(`Short session JWT: ${jwt}`);Create long-term session (24 hours)
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'your-jwt-secret-key',
maxAgeSeconds: 86400 // 24 hours
});
console.log(`Long session JWT: ${jwt}`);Default session (1 hour)
const jwt = await allowSessionTimeWalletWithJWT({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'your-jwt-secret-key'
// maxAgeSeconds will default to 3600 (1 hour)
});
console.log(`Default session JWT: ${jwt}`);