export interface WalletAddressEntity {
  addressId: bigint;
  userId: bigint;
  chainType: string;
  address: string;
  publicKey: string;
  addressDigest: string;
  // 数据库存储格式 (兼容旧格式)
  mpcSignatureR: string;
  mpcSignatureS: string;
  mpcSignatureV: number;
  status: string;
  boundAt: Date;
}

/**
 * 将数据库签名格式转换为应用层格式
 * 数据库: {r, s, v} -> 应用: string (64 bytes hex)
 */
export function toMpcSignatureString(entity: WalletAddressEntity): string {
  // 兼容旧格式: r + s
  return (entity.mpcSignatureR || '') + (entity.mpcSignatureS || '');
}

/**
 * 将应用层签名格式转换为数据库格式
 * 应用: string (64 bytes hex) -> 数据库: {r, s, v}
 */
export function fromMpcSignatureString(signature: string): {
  r: string;
  s: string;
  v: number;
} {
  // 签名格式: R (32 bytes = 64 hex) + S (32 bytes = 64 hex)
  return {
    r: signature.slice(0, 64) || '',
    s: signature.slice(64, 128) || '',
    v: 0, // 默认 v=0，实际验证时尝试 27 和 28
  };
}
