import {
  PAGE_SIZE,
  RESERVED_SIZE,
  IV_SIZE,
  HMAC_SIZE,
  deriveHmacKey,
} from '../../../../../src/modules/netaclaw/runtime/weixin_db/wcdb_codec.js';

describe('wcdb_codec constants', () => {
  it('matches WCDB cipher_compatibility=4 defaults', () => {
    expect(PAGE_SIZE).toBe(4096);
    expect(RESERVED_SIZE).toBe(80);
    expect(IV_SIZE).toBe(16);
    expect(HMAC_SIZE).toBe(64);
  });
});

describe('deriveHmacKey', () => {
  it('derives hmacKey via PBKDF2-SHA512 with salt XOR 0x3a, 2 rounds', () => {
    const rawKey = Buffer.from(
      '374c4e1a2da5a7bee6e0de020a1ad24e9234c9db709e93e4c01dd1eda9e40b50', 'hex');
    const salt = Buffer.from('91f3c3147a62cd0f9d1b96e8f50004f1', 'hex');
    const hmacKey = deriveHmacKey(rawKey, salt);
    expect(hmacKey.toString('hex'))
      .toBe('2266b72430201a5b412e227461d7d5a596b7addc57ba9ddde9e4becbdff08e01');
  });
});
