Create session Time V2 (allowSessionTimeWalletWithJWT_V2)
The allowSessionTimeWalletWithJWT_V2 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. This V2 version introduces the encryptMode parameter for controlling the encryption strength of the JWT-wrapped private key.
Import
import { allowSessionTimeWalletWithJWT_V2 } from 'dacc-js';Usage
import { allowSessionTimeWalletWithJWT_V2 } from 'dacc-js';
const jwt = await allowSessionTimeWalletWithJWT_V2({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'myPassword#123..',
jwtSecret: 'jwt-secret-to-app',
encryptMode: 'medium',
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). |
encryptMode | 'down' | 'low' | 'fast' | 'medium' | 'high' | Optional: Encryption speed/security preset for the JWT-wrapped private key (default: medium). |
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_V2({
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_V2({
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_V2({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'jwt-secret-to-app',
maxAgeSeconds: 3600
});encryptMode (optional)
- Type:
'down'|'low'|'fast'|'medium'|'high' - Default:
'medium'
Encryption speed and security preset for encrypting the private key inside the JWT token. This does not affect the JWT signature — only the encryption of the wallet data stored within the token.
const jwt = await allowSessionTimeWalletWithJWT_V2({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'jwt-secret-to-app',
encryptMode: 'fast',
maxAgeSeconds: 3600
});maxAgeSeconds (optional)
- Type:
number - Default:
3600(1 hour)
Token expiration time in seconds.
const jwt = await allowSessionTimeWalletWithJWT_V2({
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_V2({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'your-jwt-secret-key',
encryptMode: 'fast',
maxAgeSeconds: 900 // 15 minutes
});
console.log(`Short session JWT: ${jwt}`);Create long-term session (24 hours)
const jwt = await allowSessionTimeWalletWithJWT_V2({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'your-jwt-secret-key',
encryptMode: 'high',
maxAgeSeconds: 86400 // 24 hours
});
console.log(`Long session JWT: ${jwt}`);Default session (1 hour)
const jwt = await allowSessionTimeWalletWithJWT_V2({
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
jwtSecret: 'your-jwt-secret-key'
// encryptMode will default to 'medium'
// maxAgeSeconds will default to 3600 (1 hour)
});
console.log(`Default session JWT: ${jwt}`);