Skip to content

Verify session Time V2 (verifySessionTimeWalletWithJWT_V2)

A function Verify JWT Session Token V2

The verifySessionTimeWalletWithJWT_V2 function verifies and extracts wallet data from JWT session token. It validates JWT signature, checks expiration time, and returns decrypted wallet credentials if valid. This V2 version works seamlessly with tokens created by allowSessionTimeWalletWithJWT_V2, automatically handling the encryption mode used during token creation.

Import

import { verifySessionTimeWalletWithJWT_V2 } from 'dacc-js';

Usage

import { verifySessionTimeWalletWithJWT_V2 } from 'dacc-js';
 
const walletJWT = await verifySessionTimeWalletWithJWT_V2({
  jwt: 'eyJhZGRyZXNz...',
  jwtSecret: 'jwt-secret-to-app'
});
 
console.log(walletJWT); // {address: '0x123...', privateKey: '0xabc...'} or null
console.log(walletJWT?.address); // 0x123address...
console.log(walletJWT?.privateKey); // 0xabcprivatekey...

Arguments

ParameterTypeDescription
jwtstringThe JWT token to verify.
jwtSecretstringSecret key used for JWT verification and decryption.

Return Value

Returns wallet object with address and privateKey, or null if invalid/expired.

Parameters

jwt

  • Type: string

The JWT token to verify.

const walletJWT = await verifySessionTimeWalletWithJWT_V2({
  jwt: 'eyJhZGRyZXNz...', 
  jwtSecret: 'jwt-secret-to-app'
});

jwtSecret

  • Type: string

Secret key used for JWT verification and decryption.

const walletJWT = await verifySessionTimeWalletWithJWT_V2({
  jwt: 'eyJhZGRyZXNz...',
  jwtSecret: 'jwt-secret-to-app'
});

Examples

Complete session workflow (Create → Verify)

import { allowSessionTimeWalletWithJWT_V2, verifySessionTimeWalletWithJWT_V2 } from 'dacc-js';
 
// Step 1: Create session token from encrypted wallet
const sessionJWT = await allowSessionTimeWalletWithJWT_V2({
  daccPublickey: 'daccPublickey_0x123_XxX..',
  passwordSecretkey: 'my+Password#123..',
  jwtSecret: 'jwt-secret-to-app',
  encryptMode: 'medium',
  maxAgeSeconds: 3600 // 1 hour
});
 
console.log(`Session created: ${sessionJWT}`); // eyJhZGRyZXNz...
 
// Step 2: Later, verify the session token
const walletJWT = await verifySessionTimeWalletWithJWT_V2({
  jwt: sessionJWT,
  jwtSecret: 'jwt-secret-to-app'
});
 
if (walletJWT) {
  console.log(`Address: ${walletJWT.address}`); // 0x123...
  console.log(`Private Key: ${walletJWT.privateKey}`); // 0xabc...
} else {
  console.log('Session expired or invalid');
}