How can this be done, is it a signed voucher? Any sample code that I can take a look?
Until anyone buys the NFT, it does not exist on the blockchain. It's "just" a record in OpenSea's offchain database.
Only when they buy the NFT through OpenSea, the buyser sends a transaction - effectively paying gas fees to mint the NFT.
Code example of signing a message and validating with ethers.js
const message = "hello";
const [signer] = await ethers.getSigners();
const signature = await signer.signMessage(message);
console.log(
ethers.utils.verifyMessage(message, signature) == signer.address
);