import { Connection, PublicKey } from "@solana/web3.js";
import {
TsnHttpClient,
buildPaymentAuthorizationIntentRequest,
createTcapAssetPaymentAuthorization,
} from "@trustlink/tsn-sdk";
const authorization = await createTcapAssetPaymentAuthorization({
connection: new Connection(rpcUrl, "confirmed"),
depositor: new PublicKey(senderWallet),
mint: new PublicKey(tokenMintAddress),
senderWallet,
senderIdentity: senderWallet,
receiverIdentity: `tin:${recipientTin}`,
recipientDisplayName: recipient.displayName,
recipientDisplayNameSource: recipient.displayName.trim() ? "owner-provided" : "not provided",
amount,
senderFeeAmount,
totalTokenRequiredUi: amount + senderFeeAmount,
fundingMode: "tcap_deposit_v2",
});
const signature = await wallet.signMessage(
new TextEncoder().encode(authorization.message),
);
const request = buildPaymentAuthorizationIntentRequest({
paymentId,
recipientHash: recipient.ownerPubkeyHash,
recipientTin,
tokenMintAddress: authorization.asset.mint,
tokenDecimals: authorization.asset.decimals,
senderWallet,
senderAuthorizationMessage: authorization.message,
senderAuthorizationSignature: signatureBase64,
senderAuthorizationNonce: authorization.nonce,
senderAuthorizationIssuedAt: authorization.issuedAt,
senderAuthorizationExpiresAt: authorization.expiresAt,
senderFeeAmount,
senderSignedFundingTransaction,
senderFundingMode: "tcap_deposit_v2",
amount,
});
const client = new TsnHttpClient({ baseUrl: process.env.TSN_NODE_URL! });
const intent = await client.postIntent(request);