// Copyright 2019-2026 @pezkuwi/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { KeyringPair } from '@pezkuwi/keyring/types';
import type { TypeRegistry } from '@pezkuwi/types';
import type { SignerPayloadJSON } from '@pezkuwi/types/types';
import type { HexString } from '@pezkuwi/util/types';
import type { RequestSign } from './types.js';

export default class RequestExtrinsicSign implements RequestSign {
  public readonly payload: SignerPayloadJSON;

  constructor (payload: SignerPayloadJSON) {
    this.payload = payload;
  }

  sign (registry: TypeRegistry, pair: KeyringPair): { signature: HexString } {
    return registry
      .createType('ExtrinsicPayload', this.payload, { version: this.payload.version })
      .sign(pair);
  }
}
