var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { createSignMetadataInstruction } from '@metaplex-solarti/mpl-token-metadata';
import { useOperation, } from '../../../types';
import { TransactionBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'VerifyNftCreatorOperation';
/**
 * Verifies the creator of an NFT or SFT.
 *
 * ```ts
 * await metaplex
 *   .nfts()
 *   .verifyCreator({ mintAddress, creator };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const verifyNftCreatorOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const verifyNftCreatorOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        return verifyNftCreatorBuilder(metaplex, operation.input, scope).sendAndConfirm(metaplex, scope.confirmOptions);
    }),
};
/**
 * Verifies the creator of an NFT or SFT.
 *
 * ```ts
 * const transactionBuilder = metaplex
 *   .nfts()
 *   .builders()
 *   .verifyCreator({ mintAddress, creator });
 * ```
 *
 * @group Transaction Builders
 * @category Constructors
 */
export const verifyNftCreatorBuilder = (metaplex, params, options = {}) => {
    var _a;
    const { programs, payer = metaplex.rpc().getDefaultFeePayer() } = options;
    const { mintAddress, creator = metaplex.identity() } = params;
    // Programs.
    const tokenMetadataProgram = metaplex.programs().getTokenMetadata(programs);
    return (TransactionBuilder.make()
        .setFeePayer(payer)
        // Verify the creator.
        .add({
        instruction: createSignMetadataInstruction({
            metadata: metaplex.nfts().pdas().metadata({
                mint: mintAddress,
                programs,
            }),
            creator: creator.publicKey,
        }, tokenMetadataProgram.address),
        signers: [creator],
        key: (_a = params.instructionKey) !== null && _a !== void 0 ? _a : 'verifyCreator',
    }));
};
//# sourceMappingURL=verifyNftCreator.js.map