/**
 * Pacifica签名提供者实现
 * 封装Pacifica平台的Ed25519签名逻辑
 */

import { ISignatureProvider } from '../interfaces/ISignatureProvider'
import { PacificaSignatureAdapter } from '../../core/signature-adapters/pacifica'
import { SignatureResult, PacificaSignData } from '../../shared/credential-types'

export class PacificaSignatureProvider implements ISignatureProvider {
  private _adapter: PacificaSignatureAdapter

  constructor() {
    this._adapter = new PacificaSignatureAdapter()
  }

  get platformId(): string {
    return this._adapter.platformId
  }

  get algorithm(): string {
    return this._adapter.algorithm
  }

  async sign(data: PacificaSignData, credentials: any): Promise<SignatureResult> {
    return await this._adapter.sign(data, credentials)
  }

  async verify(signature: string, data: PacificaSignData, publicKey: string): Promise<boolean> {
    if (!this._adapter.verify) {
      throw new Error('Verification not supported by this provider')
    }
    return await this._adapter.verify(signature, data, publicKey)
  }

  derivePublicKey(privateKey: string): string {
    return this._adapter.derivePublicKey(privateKey)
  }

  getInfo() {
    const adapterInfo = this._adapter.getInfo()
    return {
      platformId: this.platformId,
      algorithm: this.algorithm,
      supportedOperations: adapterInfo.supportedOrderTypes,
      performance: {
        maxSigningTime: adapterInfo.maxSignatureTime,
      },
    }
  }
}
