@lifestonelabs/tokensales 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/functions/buyNFT.d.ts.map +1 -1
- package/dist/index.esm.js +4 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
______________________________________________________________
|
|
3
|
+
## [1.0.9] - 2026-02-12
|
|
4
|
+
### Changed
|
|
5
|
+
- `buyNFT` increased non-admin miner fee sats
|
|
6
|
+
- `buyNFT` fixed adming buying so price is reset to 1000sats rather than original ticket price
|
|
7
|
+
______________________________________________________________
|
|
3
8
|
## [1.0.8] - 2026-02-10
|
|
4
9
|
### Changed
|
|
5
10
|
- `burn` added additional index check in contract to ensure user-provided MintingNFT must be input0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buyNFT.d.ts","sourceRoot":"","sources":["../../src/functions/buyNFT.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAKxE;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,8BAA8B,CAAC,
|
|
1
|
+
{"version":3,"file":"buyNFT.d.ts","sourceRoot":"","sources":["../../src/functions/buyNFT.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAKxE;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA4V1F"}
|
package/dist/index.esm.js
CHANGED
|
@@ -785,7 +785,7 @@ async function buyNFT(params) {
|
|
|
785
785
|
}
|
|
786
786
|
else {
|
|
787
787
|
// Calculate change amount (userUTXO - ticketPrice - miner fee)
|
|
788
|
-
const changeAmount = userUTXO.satoshis - ticketPrice -
|
|
788
|
+
const changeAmount = userUTXO.satoshis - ticketPrice - 2700n;
|
|
789
789
|
if (changeAmount > 1000n) { // Dust limit
|
|
790
790
|
transaction.addOutput({
|
|
791
791
|
to: normalizedUserAddress,
|
|
@@ -802,6 +802,7 @@ async function buyNFT(params) {
|
|
|
802
802
|
throw new Error(`Error building transaction: ${String(error)}`);
|
|
803
803
|
}
|
|
804
804
|
}
|
|
805
|
+
console.log('Transaction built:', transaction);
|
|
805
806
|
// Build the transaction
|
|
806
807
|
const rawTransactionHex = await transaction.build();
|
|
807
808
|
// Decode transaction for WalletConnect
|
|
@@ -891,6 +892,7 @@ async function buyNFT(params) {
|
|
|
891
892
|
broadcast: false,
|
|
892
893
|
userPrompt: `Purchase Ticket Type ${ticketType} for ${ticketPrice} sats`
|
|
893
894
|
};
|
|
895
|
+
console.log('WalletConnect transaction object:', wcTransactionObj);
|
|
894
896
|
return wcTransactionObj;
|
|
895
897
|
}
|
|
896
898
|
|
|
@@ -1234,7 +1236,7 @@ async function burn(params) {
|
|
|
1234
1236
|
const wcTransactionObj = {
|
|
1235
1237
|
transaction: decodedTransaction,
|
|
1236
1238
|
sourceOutputs: listSourceOutputs,
|
|
1237
|
-
broadcast:
|
|
1239
|
+
broadcast: true,
|
|
1238
1240
|
userPrompt: `Burn TicketMaster and ${tickets.length} tickets`
|
|
1239
1241
|
};
|
|
1240
1242
|
return wcTransactionObj;
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/utils/signTransaction.ts","../src/utils/ticketMaster.ts","../src/utils/toTokenAddress.ts","../src/utils/index.ts","../src/constants/values.ts","../src/config.ts","../src/functions/buyNFT.ts","../src/functions/modifyTokenSale.ts","../src/functions/burn.ts","../src/functions/addSatoshis.ts","../src/functions/createListing.ts","../src/functions/listAvailableTickets.ts","../src/functions/listAllSales.ts","../src/functions/listActiveSales.ts"],"sourcesContent":["import { stringify } from '@bitauth/libauth';\r\n\r\n/**\r\n * Creates a signTransaction function for WalletConnect v2\r\n * This function handles transaction signing through WalletConnect's SignClient\r\n * \r\n * @param signClient - The WalletConnect SignClient instance\r\n * @param connectedChain - The connected chain ID (fallback if not found in session)\r\n * @returns A function that signs transactions via WalletConnect\r\n */\r\nexport function createSignTransaction(\r\n signClient: any,\r\n connectedChain?: string\r\n): (transactionOptions: any) => Promise<any> {\r\n return async (transactionOptions: any) => {\r\n if (!signClient) {\r\n throw new Error('SignClient not available. Please ensure wallet is connected.');\r\n }\r\n \r\n // Get all active sessions\r\n const sessions = signClient.session.getAll();\r\n \r\n if (sessions.length === 0) {\r\n throw new Error('No active wallet session. Please connect your wallet first.');\r\n }\r\n \r\n // Use the first active session\r\n const session = sessions[0];\r\n \r\n // Extract chainId from session\r\n // In WalletConnect v2, chainId is in the accounts array as \"chainId:address\"\r\n let chainId: string | null = null;\r\n \r\n const namespaces = session.namespaces || {};\r\n const bchNamespace = namespaces.bch;\r\n \r\n if (bchNamespace && bchNamespace.accounts && bchNamespace.accounts.length > 0) {\r\n // Extract chainId from first account (format: \"chainId:address\")\r\n const firstAccount = bchNamespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2) {\r\n // Reconstruct chainId (could be \"bch:mainnet\" or \"bch:bchtest:chipnet\")\r\n chainId = accountParts.slice(0, -1).join(':'); // Everything except the address part\r\n }\r\n }\r\n \r\n // Fallback: try to find chainId from any namespace\r\n if (!chainId) {\r\n for (const namespaceKey in namespaces) {\r\n const namespace = namespaces[namespaceKey];\r\n if (namespace.accounts && namespace.accounts.length > 0) {\r\n const firstAccount = namespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2 && accountParts[0].includes('bch')) {\r\n chainId = accountParts.slice(0, -1).join(':');\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n \r\n // Final fallback\r\n if (!chainId) {\r\n chainId = connectedChain || 'bch:mainnet';\r\n }\r\n \r\n // Use the same pattern as the working project: JSON.parse(stringify(obj))\r\n // stringify from @bitauth/libauth handles BigInt and Uint8Array serialization\r\n const serializableTxObj = JSON.parse(stringify(transactionOptions));\r\n \r\n try {\r\n const result = await signClient.request({\r\n chainId,\r\n topic: session.topic,\r\n request: {\r\n method: 'bch_signTransaction',\r\n params: serializableTxObj,\r\n },\r\n });\r\n return result;\r\n } catch (error: any) {\r\n // Handle WalletConnect relay errors gracefully\r\n if (error?.message?.includes('onRelayMessage') || error?.message?.includes('failed to process')) {\r\n // The transaction might still have been signed, so we'll let the caller handle it\r\n }\r\n throw error;\r\n }\r\n };\r\n}\r\n\r\n","/**\r\n * Utility functions for parsing TicketMaster NFT data\r\n */\r\n\r\nexport interface TicketMasterData {\r\n priceType1: bigint;\r\n priceType2: bigint;\r\n priceType3: bigint;\r\n endSale: number;\r\n adminPubKeyHash: string;\r\n}\r\n\r\n/**\r\n * Parses TicketMaster NFT commitment to extract sale data\r\n * Commitment format:\r\n * - bytes5 priceType1 (0-5)\r\n * - bytes5 priceType2 (5-10)\r\n * - bytes5 priceType3 (10-15)\r\n * - bytes4 endSale (15-19)\r\n * - bytes20 adminPubKeyHash (19-39)\r\n */\r\nexport function parseTicketMasterCommitment(commitment: string): TicketMasterData | null {\r\n if (!commitment || commitment.length < 78) { // 39 bytes = 78 hex chars\r\n return null;\r\n }\r\n\r\n try {\r\n // Extract priceType1 (bytes5 = 10 hex chars, positions 0-10)\r\n // CashScript stores numbers in little-endian format\r\n const priceType1Hex = commitment.substring(0, 10);\r\n const priceType1BE = priceType1Hex.match(/.{2}/g)?.reverse().join('') || priceType1Hex;\r\n const priceType1 = BigInt('0x' + priceType1BE);\r\n\r\n // Extract priceType2 (bytes5 = 10 hex chars, positions 10-20)\r\n const priceType2Hex = commitment.substring(10, 20);\r\n const priceType2BE = priceType2Hex.match(/.{2}/g)?.reverse().join('') || priceType2Hex;\r\n const priceType2 = BigInt('0x' + priceType2BE);\r\n\r\n // Extract priceType3 (bytes5 = 10 hex chars, positions 20-30)\r\n const priceType3Hex = commitment.substring(20, 30);\r\n const priceType3BE = priceType3Hex.match(/.{2}/g)?.reverse().join('') || priceType3Hex;\r\n const priceType3 = BigInt('0x' + priceType3BE);\r\n\r\n // Extract endSale (bytes4 = 8 hex chars, positions 30-38)\r\n // CashScript stores numbers in little-endian format\r\n // Contract uses: bytes endSale = tx.inputs[0].nftCommitment.slice(15,19);\r\n // This is bytes 15-19 (0-indexed), which is hex positions 30-38\r\n const endSaleHex = commitment.substring(30, 38);\r\n const endSaleBE = endSaleHex.match(/.{2}/g)?.reverse().join('') || endSaleHex;\r\n const endSale = parseInt(endSaleBE, 16);\r\n\r\n // Extract adminPubKeyHash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHash = commitment.substring(38, 78);\r\n\r\n return {\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash,\r\n };\r\n } catch (error) {\r\n console.error('Failed to parse TicketMaster commitment:', error);\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a TicketMaster (has minting capability)\r\n */\r\nexport function isTicketMaster(utxo: any): boolean {\r\n return (\r\n utxo?.token?.nft?.capability === 'minting' &&\r\n utxo?.token?.nft?.commitment &&\r\n utxo.token.nft.commitment.length >= 78\r\n );\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a ticket (same category as TicketMaster but immutable)\r\n */\r\nexport function isTicket(utxo: any, ticketMasterCategory: string): boolean {\r\n return (\r\n utxo?.token?.category === ticketMasterCategory &&\r\n utxo?.token?.nft?.capability === 'none'\r\n );\r\n}\r\n\r\n/**\r\n * Formats satoshis to BCH\r\n */\r\nexport function formatBCH(satoshis: bigint | number | string): string {\r\n const sats = typeof satoshis === 'string' ? BigInt(satoshis) : BigInt(satoshis);\r\n const bch = Number(sats) / 100000000;\r\n return bch.toFixed(8);\r\n}\r\n\r\n","import { decodeCashAddress, encodeCashAddress } from '@bitauth/libauth';\r\n\r\n/**\r\n * Converts a regular Bitcoin Cash address to its token address equivalent\r\n * @param address - Bitcoin Cash address (p2pkh)\r\n * @returns Token address (p2pkhWithTokens)\r\n */\r\nfunction toTokenAddress(address: string): string {\r\n const addressInfo: any = decodeCashAddress(address);\r\n const pkhPayoutBin = addressInfo.payload;\r\n const prefix = addressInfo.prefix;\r\n const tokenAddressResult = encodeCashAddress({prefix, type: \"p2pkhWithTokens\", payload: pkhPayoutBin});\r\n \r\n // In libauth v3, encodeCashAddress returns a CashAddressResult object\r\n if (typeof tokenAddressResult === 'string') {\r\n return tokenAddressResult;\r\n }\r\n return tokenAddressResult.address;\r\n}\r\n\r\nexport default toTokenAddress;\r\n\r\n","/**\r\n * Shared utility functions\r\n */\r\n\r\nexport { createSignTransaction } from './signTransaction';\r\nexport { parseTicketMasterCommitment, formatBCH, isTicketMaster, isTicket, type TicketMasterData } from './ticketMaster';\r\nexport { default as toTokenAddress } from './toTokenAddress';\r\n\r\n/**\r\n * Ensures an address has the bitcoincash: prefix for libauth functions\r\n * Addresses from AppKit may come without the prefix after normalization\r\n */\r\nexport function ensureAddressPrefix(address: string): string {\r\n // If address already has a prefix, return as-is\r\n if (address.includes(':')) {\r\n return address;\r\n }\r\n \r\n // Add bitcoincash: prefix for mainnet addresses\r\n // Addresses starting with 'q' or 'p' are mainnet\r\n if (address.startsWith('q') || address.startsWith('p')) {\r\n return `bitcoincash:${address}`;\r\n }\r\n \r\n // For testnet addresses starting with 'bchtest:' or 'q'/'p' on testnet\r\n // This is a simple check - you may need to adjust based on your network\r\n return `bitcoincash:${address}`;\r\n}\r\n\r\n/**\r\n * Converts hex string to Uint8Array\r\n */\r\nexport function hexToUint8Array(hexString: string): Uint8Array {\r\n const bytes = new Uint8Array(hexString.length / 2);\r\n for (let i = 0; i < bytes.length; i++) {\r\n bytes[i] = parseInt(hexString.substr(i * 2, 2), 16);\r\n }\r\n return bytes;\r\n}\r\n\r\n/**\r\n * Converts a number to little-endian hex string\r\n * @param number - The number to convert\r\n * @param byteCount - Number of bytes (e.g., 5 for bytes5, 4 for bytes4)\r\n */\r\nexport function toLittleEndianHexString(number: bigint | number, byteCount: number): string {\r\n const num = typeof number === 'bigint' ? number : BigInt(number);\r\n let hex = num.toString(16);\r\n hex = hex.padStart(byteCount * 2, '0'); // Pad with zeros to ensure correct byteCount\r\n // Split into chunks of 2 (bytes), reverse (for little endian), and join back\r\n return hex.match(/../g)?.reverse().join('') ?? '';\r\n}\r\n\r\n","// TokenSales_old1 contract addresses\r\n//export const AddressTicketMaster = 'bitcoincash:pvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryszkdd99zq'; //address hash: 2ef2757e6a8659a54a3a43384764091ac82c05e8d2b5941fdefb551b20564648\r\n//export const AddressTicketMasterToken = 'bitcoincash:rvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryss93vuymt';\r\n\r\n// TokenSales_old2 contract addresses | simplified change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2m4afvzlt'; //address hash: 76bebd71fef3c48ef2fec86b1a24ceaa7fb06f3e1aed923ac8176955c20f5085\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2fxpg4rxq';\r\n\r\n// TokenSales_old3 contract addresses | fixed change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vz3syd0y9'; //address hash: 7ff1e58e69a1346149d6000befea51cf43bf0aefcff02c15c20a477024002f46\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vszv95waw';\r\n\r\n// TokenSales contract addresses | restricted burnTokenSale() so user-provided utxo must be input0\r\nexport const AddressTicketMaster = 'bitcoincash:pwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnwzutlweuk'; //address hash: b6ef29da52497a243a73a70115dede6e38653148ccdbaafa24f7f662b8bc5b37\r\nexport const AddressTicketMasterToken = 'bitcoincash:rwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnws0h7hc9a';\r\n\r\n// Ticket Level Descriptions\r\nexport const TICKET_LEVEL_DESCRIPTIONS = {\r\n '01': {\r\n name: 'Regular',\r\n description: 'Regular tickets provide standard access to the event. This is the base level ticket option.'\r\n },\r\n '02': {\r\n name: 'VIP',\r\n description: 'VIP tickets offer enhanced benefits including priority access, exclusive areas, and additional perks.'\r\n },\r\n '03': {\r\n name: 'Premium',\r\n description: 'Premium tickets provide the highest level of access with all VIP benefits plus additional exclusive features.'\r\n }\r\n};\r\n\r\n","/**\r\n * TokenSales contract addresses\r\n * These are the addresses for the TokenSales (TicketMaster) contract\r\n */\r\nimport { AddressTicketMaster, AddressTicketMasterToken } from './constants/values';\r\n\r\nexport const DEFAULT_CONTRACT_ADDRESSES = {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n} as const;\r\n\r\n/**\r\n * Get contract address\r\n * @returns Contract address\r\n */\r\nexport function getContractAddress(): string {\r\n return AddressTicketMaster;\r\n}\r\n\r\n/**\r\n * Get token address\r\n * @returns Token address\r\n */\r\nexport function getTokenAddress(): string {\r\n return AddressTicketMasterToken;\r\n}\r\n\r\n/**\r\n * Get contract addresses\r\n * @returns Object with contract and token addresses\r\n */\r\nexport function getContractAddresses() {\r\n return {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n };\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction, encodeCashAddress } from '@bitauth/libauth';\r\nimport { BuyNFTParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, hexToUint8Array, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Purchase a ticket NFT from a TicketMaster\r\n * @param params - BuyNFTParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function buyNFT(params: BuyNFTParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n ticketUtxo,\r\n ticketType,\r\n isAdmin\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === ticketUtxo.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n \r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = ticketUtxo.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('ticketUtxo must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Parse TicketMaster commitment to get price and admin address\r\n const commitment = ticketMasterUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TicketMaster commitment');\r\n }\r\n\r\n // Extract price based on ticket type (little-endian format)\r\n let ticketPrice: bigint;\r\n let priceHex: string;\r\n \r\n if (ticketType === '01') {\r\n priceHex = commitment.substring(0, 10);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n } else if (ticketType === '02') {\r\n priceHex = commitment.substring(10, 20);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 2 is not available');\r\n }\r\n } else if (ticketType === '03') {\r\n priceHex = commitment.substring(20, 30);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 3 is not available');\r\n }\r\n } else {\r\n throw new Error('Invalid ticket type');\r\n }\r\n\r\n // Extract admin pubkey hash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHashHex = commitment.substring(38, 78);\r\n \r\n // Convert hex string to Uint8Array\r\n const adminPKHUint8Array = hexToUint8Array(adminPubKeyHashHex);\r\n \r\n // Derive admin address from embedded pubkey hash\r\n const prefix = 'bitcoincash';\r\n const addressType = 'p2pkh';\r\n const adminAddressResult = encodeCashAddress({\r\n prefix,\r\n type: addressType,\r\n payload: adminPKHUint8Array\r\n });\r\n \r\n if (typeof adminAddressResult === 'string') {\r\n throw new Error(`Failed to encode admin address: ${adminAddressResult}`);\r\n }\r\n const adminAddress = adminAddressResult.address;\r\n \r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n \r\n // Convert address to locking bytecode\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Get userUTXO\r\n let userUTXO: Utxo | undefined;\r\n if (isAdmin) {\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.token?.category === ticketMasterUtxo.token?.category && \r\n utxo.token?.nft?.capability === 'minting'\r\n );\r\n } else {\r\n // Find pure BCH payment UTXO (need ticketPrice & 3000+ sats for miner fee)\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (ticketPrice + 3000n) && !utxo.token,\r\n );\r\n\r\n if (!userUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n // If totalSats is enough, then user needs to consolidate\r\n if (totalSats >= ticketPrice + 3000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${ticketPrice + 3000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n }\r\n\r\n if (!userUTXO) {\r\n throw new Error('No suitable UTXO found for transaction');\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(ticketUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(userUTXO, p2pkhUnlocker)\r\n // Ticket master NFT being sent back to contract\r\n .addOutput({\r\n to: ticketMasterContract.tokenAddress, \r\n amount: ticketMasterUtxo.satoshis,\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount!, \r\n category: ticketMasterUtxo.token?.category!, \r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!, \r\n commitment: ticketMasterUtxo.token?.nft?.commitment! \r\n }\r\n },\r\n })\r\n // Ticket being purchased\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: ticketUtxo.satoshis,\r\n token: {\r\n amount: ticketUtxo.token?.amount!, \r\n category: ticketUtxo.token?.category!, \r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!, \r\n commitment: ticketUtxo.token?.nft?.commitment! + ticketType // ticketType appended to commitment\r\n }\r\n },\r\n })\r\n // Ticket price is sent to admin address\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: 1000n,\r\n });\r\n } else {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: ticketPrice,\r\n });\r\n }\r\n\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userUTXO.satoshis - 2700n,\r\n token: {\r\n amount: userUTXO.token?.amount!, \r\n category: userUTXO.token?.category!, \r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!, \r\n commitment: userUTXO.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } else {\r\n // Calculate change amount (userUTXO - ticketPrice - miner fee)\r\n const changeAmount = userUTXO.satoshis - ticketPrice - 1700n;\r\n if (changeAmount > 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress, \r\n amount: changeAmount\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 2)\r\n decodedTransaction.inputs[2].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binTicketCommitment = hexToBin(ticketUtxo.token?.nft?.commitment!);\r\n const binUserCommitment = isAdmin ? hexToBin(userUTXO.token?.nft?.commitment!) : undefined;\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n // Use raw Uint8Arrays and BigInts - stringify from @bitauth/libauth will handle serialization\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!,\r\n commitment: binTicketCommitment\r\n }\r\n }\r\n },\r\n ...(isAdmin ? [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n token: {\r\n amount: userUTXO.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!,\r\n commitment: binUserCommitment!\r\n }\r\n }\r\n }] : [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n }])\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Purchase Ticket Type ${ticketType} for ${ticketPrice} sats`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { ModifyTokenSaleParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Modify TokenSale parameters (prices, endSale)\r\n * @param params - ModifyTokenSaleParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function modifyTokenSale(params: ModifyTokenSaleParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n tokenSaleUtxo,\r\n userMintingUtxo,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const tokenSaleContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Parse TokenSale commitment to validate\r\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TokenSale commitment');\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = tokenSaleContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n const priceType1Hex = toLittleEndianHexString(BigInt(priceType1), 5);\r\n const priceType2Hex = toLittleEndianHexString(BigInt(priceType2), 5);\r\n const priceType3Hex = toLittleEndianHexString(BigInt(priceType3), 5);\r\n const endSaleHex = toLittleEndianHexString(BigInt(endSale), 4);\r\n const adminPkh = tokenSaleUtxo.token?.nft?.commitment!.substring(38, 78);\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(tokenSaleUtxo, tokenSaleContract.unlock.modifyTokenSale(priceType1Hex, priceType2Hex, priceType3Hex, endSaleHex))\r\n .addInput(userMintingUtxo, p2pkhUnlocker)\r\n // TokenSale NFT being sent back to contract with new commitment\r\n .addOutput({\r\n to: tokenSaleContract.tokenAddress, \r\n amount: tokenSaleUtxo.satoshis,\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount!, \r\n category: tokenSaleUtxo.token?.category!, \r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!, \r\n commitment: priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkh\r\n }\r\n },\r\n })\r\n // Admin NFT being sent back to user\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingUtxo.satoshis - 1000n,\r\n token: {\r\n amount: userMintingUtxo.token?.amount!, \r\n category: userMintingUtxo.token?.category!, \r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!, \r\n commitment: userMintingUtxo.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 1)\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(tokenSaleUtxo.token?.category!);\r\n const binTokenSaleCommitment = hexToBin(tokenSaleUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingUtxo.token?.nft?.commitment!);\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((tokenSaleContract.redeemScript as any).bytecode) {\r\n return (tokenSaleContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof tokenSaleContract.redeemScript === 'string') {\r\n return hexToBin(tokenSaleContract.redeemScript);\r\n }\r\n return new Uint8Array(tokenSaleContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(tokenSaleUtxo.satoshis),\r\n contract: {\r\n abiFunction: tokenSaleContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: tokenSaleContract.artifact,\r\n },\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!,\r\n commitment: binTokenSaleCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingUtxo.satoshis),\r\n token: {\r\n amount: userMintingUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Modify TokenSale NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { BurnParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Burn a TicketMaster NFT and all associated tickets\r\n * @param params - BurnParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function burn(params: BurnParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n userMintingNFT,\r\n tickets\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === userMintingNFT.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n \r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = userMintingNFT.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('userMintingNFT must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n // Start building transaction\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add TicketMaster to be burned\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.burnTokenSale());\r\n\r\n // Add all tickets to be burned\r\n for (const ticket of tickets) {\r\n transaction = transaction.addInput(ticket, ticketMasterContract.unlock.burnTokenSale());\r\n }\r\n\r\n // Send admin NFT back to user\r\n transaction = transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingNFT.satoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!, \r\n category: userMintingNFT.token?.category!, \r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!, \r\n commitment: userMintingNFT.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 0)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n // For each ticket, convert hex to Uint8Array\r\n const binTicketCommitments = tickets.map((ticket) => hexToBin(ticket.token?.nft?.commitment!));\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Add all tickets to the list of source outputs\r\n for (let i = 0; i < tickets.length; i++) {\r\n const ticket = tickets[i];\r\n listSourceOutputs.push({\r\n ...decodedTransaction.inputs[i + 2],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticket.satoshis),\r\n token: {\r\n amount: ticket.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticket.token?.nft?.capability!,\r\n commitment: binTicketCommitments[i]\r\n }\r\n }\r\n });\r\n }\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Burn TicketMaster and ${tickets.length} tickets`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { AddSatoshisParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\n\r\n/**\r\n * Add satoshis to a minting NFT\r\n * @param params - AddSatoshisParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function addSatoshis(params: AddSatoshisParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n additionalSatoshis\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n if (additionalSatoshis <= 0n) {\r\n throw new Error('Additional satoshis must be greater than 0');\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs to find a BCH UTXO to fund the additional satoshis\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Find a BCH UTXO with enough satoshis (additionalSatoshis + miner fee ~1000 sats)\r\n const fundingUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (additionalSatoshis + 1000n) && !utxo.token\r\n );\r\n\r\n if (!fundingUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n if (totalSats >= additionalSatoshis + 1000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${additionalSatoshis + 1000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Add the minting NFT as input\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add the funding UTXO to provide additional satoshis\r\n .addInput(fundingUTXO, p2pkhUnlocker)\r\n // Output: minting NFT with additional satoshis\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis + additionalSatoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n\r\n // Calculate change (fundingUTXO - additionalSatoshis - miner fee)\r\n const changeAmount = fundingUTXO.satoshis - additionalSatoshis - 1000n;\r\n if (changeAmount >= 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress,\r\n amount: changeAmount,\r\n });\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user inputs (wallet will sign these)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Get locking bytecode for user address\r\n const userLockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof userLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${userLockingBytecodeResult}`);\r\n }\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(fundingUTXO.satoshis)\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Add ${additionalSatoshis} satoshis to minting NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { CreateListingParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\nimport { AddressTicketMasterToken } from '../constants/values';\r\n\r\n/**\r\n * Create a new TicketMaster listing\r\n * @param params - CreateListingParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function createListing(params: CreateListingParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Validate adminPubKeyHash\r\n const adminPkhHex = adminPubKeyHash.replace(/^0x/i, '').trim();\r\n if (adminPkhHex.length !== 40 || !/^[0-9a-fA-F]+$/.test(adminPkhHex)) {\r\n throw new Error('Admin PubKey Hash must be 40 hex characters (20 bytes)');\r\n }\r\n\r\n // Normalize user address\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get token address from compiled contract\r\n const contractTokenAddr = ticketMasterContract.tokenAddress;\r\nconsole.log('contractTokenAddr', contractTokenAddr);\r\nconsole.log('AddressTicketMasterToken', AddressTicketMasterToken);\r\n // Get locking bytecode for contract token address\r\n const contractTokenLockingBytecodeResult = cashAddressToLockingBytecode(contractTokenAddr);\r\n if (typeof contractTokenLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract token address to locking bytecode: ${contractTokenLockingBytecodeResult}`);\r\n }\r\n\r\n // Build TicketMaster commitment\r\n // Format: bytes5 priceType1 + bytes5 priceType2 + bytes5 priceType3 + bytes4 endSale + bytes20 adminPubKeyHash\r\n // Total: 39 bytes = 78 hex chars\r\n const priceType1Hex = toLittleEndianHexString(priceType1, 5); // 10 hex chars\r\n const priceType2Hex = toLittleEndianHexString(priceType2, 5); // 10 hex chars\r\n const priceType3Hex = toLittleEndianHexString(priceType3, 5); // 10 hex chars\r\n const endSaleHex = toLittleEndianHexString(endSale, 4); // 8 hex chars\r\n const ticketMasterCommitment = priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkhHex;\r\n \r\n if (ticketMasterCommitment.length !== 78) {\r\n throw new Error(`Invalid commitment length: ${ticketMasterCommitment.length}, expected 78`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Input: user's minting NFT\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Output 0: user's minting NFT back to user\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis - 2000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n })\r\n // Output 1: TicketMaster Minting NFT to contract token address\r\n .addOutput({\r\n to: contractTokenAddr,\r\n amount: 1000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: 'minting',\r\n commitment: ticketMasterCommitment\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (wallet will sign this)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binUserCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Create TicketMaster listing`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { Utxo } from 'cashscript';\nimport { ListAvailableTicketsParams } from '../types';\nimport { getTokenAddress } from '../config';\nimport { parseTicketMasterCommitment, isTicketMaster, isTicket } from '../utils/ticketMaster';\n\n/**\n * List available tickets for purchase from a TokenSale\n * @param params - ListAvailableTicketsParams object containing all required parameters\n * @returns Promise resolving to array of ticket UTXOs that are available for purchase\n * @throws Error if validation fails or TokenSale is not found/active\n */\nexport async function listAvailableTickets(params: ListAvailableTicketsParams): Promise<Utxo[]> {\n const {\n electrumProvider,\n categoryID\n } = params;\n\n if (!electrumProvider) {\n throw new Error('Electrum provider not available');\n }\n\n if (!categoryID || categoryID.length === 0) {\n throw new Error('Category ID is required');\n }\n\n // Get the contract token address\n const contractTokenAddress = getTokenAddress();\n\n // Get all UTXOs from the contract token address\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\n\n // Filter UTXOs to only those matching the categoryID\n const categoryUtxos = contractUtxos.filter((utxo: Utxo) => \n utxo?.token?.category === categoryID\n );\n\n if (categoryUtxos.length === 0) {\n return []; // No UTXOs found for this category\n }\n\n // Find the TokenSale minting NFT (capability === 'minting')\n const tokenSaleUtxo = categoryUtxos.find((utxo: Utxo) => \n isTicketMaster(utxo)\n );\n\n if (!tokenSaleUtxo) {\n throw new Error(`No active TokenSale found for category ${categoryID}`);\n }\n\n // Parse the TokenSale commitment to get endSale block height\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\n const tokenSaleData = parseTicketMasterCommitment(commitment);\n\n if (!tokenSaleData) {\n throw new Error('Failed to parse TokenSale commitment');\n }\n\n // Filter to only ticket UTXOs (capability === 'none')\n const availableTickets = categoryUtxos.filter((utxo: Utxo) => \n isTicket(utxo, categoryID)\n );\n\n return availableTickets;\n}\n","import { ListAllSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List all TokenSale NFTs (minting capability & 39-byte commitment)\r\n * @param params - ListAllSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listAllSales(params: ListAllSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only TokenSale NFTs (minting capability with 39-byte commitment)\r\n const tokenSaleUtxos: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n tokenSaleUtxos.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n\r\n return tokenSaleUtxos;\r\n}\r\n","import { ListActiveSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List active TokenSale NFTs (minting capability, 39-byte commitment, sale not ended)\r\n * A sale is active when current blockheight > endSale commitment field\r\n * @param params - ListActiveSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of active TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listActiveSales(params: ListActiveSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get current block height\r\n let currentBlockHeight: number;\r\n if (typeof (electrumProvider as any).getBlockHeight === 'function') {\r\n currentBlockHeight = await (electrumProvider as any).getBlockHeight();\r\n } else if (typeof (electrumProvider as any).performRequest === 'function') {\r\n try {\r\n const header = await (electrumProvider as any).performRequest('blockchain.headers.subscribe');\r\n currentBlockHeight = header?.height || header;\r\n } catch (e) {\r\n // Fallback: try to get block height from getUtxos call\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n } else {\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only active TokenSale NFTs (sale not ended)\r\n const activeSales: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n // Sale is active when current blockheight > endSale\r\n if (currentBlockHeight < tokenSaleData.endSale) {\r\n activeSales.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n return activeSales;\r\n}\r\n"],"names":[],"mappings":";;;AAEA;;;;;;;AAOG;AACG,SAAU,qBAAqB,CACnC,UAAe,EACf,cAAuB,EAAA;AAEvB,IAAA,OAAO,OAAO,kBAAuB,KAAI;QACvC,IAAI,CAAC,UAAU,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC;QACjF;;QAGA,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE;AAE5C,QAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACzB,YAAA,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;QAChF;;AAGA,QAAA,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;;;QAI3B,IAAI,OAAO,GAAkB,IAAI;AAEjC,QAAA,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE;AAC3C,QAAA,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG;AAEnC,QAAA,IAAI,YAAY,IAAI,YAAY,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;;YAE7E,MAAM,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC7C,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC;AAC5C,YAAA,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,EAAE;;AAE5B,gBAAA,OAAO,GAAG,YAAY,CAAC,KAAK,CAA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,"file":"index.esm.js","sources":["../src/utils/signTransaction.ts","../src/utils/ticketMaster.ts","../src/utils/toTokenAddress.ts","../src/utils/index.ts","../src/constants/values.ts","../src/config.ts","../src/functions/buyNFT.ts","../src/functions/modifyTokenSale.ts","../src/functions/burn.ts","../src/functions/addSatoshis.ts","../src/functions/createListing.ts","../src/functions/listAvailableTickets.ts","../src/functions/listAllSales.ts","../src/functions/listActiveSales.ts"],"sourcesContent":["import { stringify } from '@bitauth/libauth';\r\n\r\n/**\r\n * Creates a signTransaction function for WalletConnect v2\r\n * This function handles transaction signing through WalletConnect's SignClient\r\n * \r\n * @param signClient - The WalletConnect SignClient instance\r\n * @param connectedChain - The connected chain ID (fallback if not found in session)\r\n * @returns A function that signs transactions via WalletConnect\r\n */\r\nexport function createSignTransaction(\r\n signClient: any,\r\n connectedChain?: string\r\n): (transactionOptions: any) => Promise<any> {\r\n return async (transactionOptions: any) => {\r\n if (!signClient) {\r\n throw new Error('SignClient not available. Please ensure wallet is connected.');\r\n }\r\n \r\n // Get all active sessions\r\n const sessions = signClient.session.getAll();\r\n \r\n if (sessions.length === 0) {\r\n throw new Error('No active wallet session. Please connect your wallet first.');\r\n }\r\n \r\n // Use the first active session\r\n const session = sessions[0];\r\n \r\n // Extract chainId from session\r\n // In WalletConnect v2, chainId is in the accounts array as \"chainId:address\"\r\n let chainId: string | null = null;\r\n \r\n const namespaces = session.namespaces || {};\r\n const bchNamespace = namespaces.bch;\r\n \r\n if (bchNamespace && bchNamespace.accounts && bchNamespace.accounts.length > 0) {\r\n // Extract chainId from first account (format: \"chainId:address\")\r\n const firstAccount = bchNamespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2) {\r\n // Reconstruct chainId (could be \"bch:mainnet\" or \"bch:bchtest:chipnet\")\r\n chainId = accountParts.slice(0, -1).join(':'); // Everything except the address part\r\n }\r\n }\r\n \r\n // Fallback: try to find chainId from any namespace\r\n if (!chainId) {\r\n for (const namespaceKey in namespaces) {\r\n const namespace = namespaces[namespaceKey];\r\n if (namespace.accounts && namespace.accounts.length > 0) {\r\n const firstAccount = namespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2 && accountParts[0].includes('bch')) {\r\n chainId = accountParts.slice(0, -1).join(':');\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n \r\n // Final fallback\r\n if (!chainId) {\r\n chainId = connectedChain || 'bch:mainnet';\r\n }\r\n \r\n // Use the same pattern as the working project: JSON.parse(stringify(obj))\r\n // stringify from @bitauth/libauth handles BigInt and Uint8Array serialization\r\n const serializableTxObj = JSON.parse(stringify(transactionOptions));\r\n \r\n try {\r\n const result = await signClient.request({\r\n chainId,\r\n topic: session.topic,\r\n request: {\r\n method: 'bch_signTransaction',\r\n params: serializableTxObj,\r\n },\r\n });\r\n return result;\r\n } catch (error: any) {\r\n // Handle WalletConnect relay errors gracefully\r\n if (error?.message?.includes('onRelayMessage') || error?.message?.includes('failed to process')) {\r\n // The transaction might still have been signed, so we'll let the caller handle it\r\n }\r\n throw error;\r\n }\r\n };\r\n}\r\n\r\n","/**\r\n * Utility functions for parsing TicketMaster NFT data\r\n */\r\n\r\nexport interface TicketMasterData {\r\n priceType1: bigint;\r\n priceType2: bigint;\r\n priceType3: bigint;\r\n endSale: number;\r\n adminPubKeyHash: string;\r\n}\r\n\r\n/**\r\n * Parses TicketMaster NFT commitment to extract sale data\r\n * Commitment format:\r\n * - bytes5 priceType1 (0-5)\r\n * - bytes5 priceType2 (5-10)\r\n * - bytes5 priceType3 (10-15)\r\n * - bytes4 endSale (15-19)\r\n * - bytes20 adminPubKeyHash (19-39)\r\n */\r\nexport function parseTicketMasterCommitment(commitment: string): TicketMasterData | null {\r\n if (!commitment || commitment.length < 78) { // 39 bytes = 78 hex chars\r\n return null;\r\n }\r\n\r\n try {\r\n // Extract priceType1 (bytes5 = 10 hex chars, positions 0-10)\r\n // CashScript stores numbers in little-endian format\r\n const priceType1Hex = commitment.substring(0, 10);\r\n const priceType1BE = priceType1Hex.match(/.{2}/g)?.reverse().join('') || priceType1Hex;\r\n const priceType1 = BigInt('0x' + priceType1BE);\r\n\r\n // Extract priceType2 (bytes5 = 10 hex chars, positions 10-20)\r\n const priceType2Hex = commitment.substring(10, 20);\r\n const priceType2BE = priceType2Hex.match(/.{2}/g)?.reverse().join('') || priceType2Hex;\r\n const priceType2 = BigInt('0x' + priceType2BE);\r\n\r\n // Extract priceType3 (bytes5 = 10 hex chars, positions 20-30)\r\n const priceType3Hex = commitment.substring(20, 30);\r\n const priceType3BE = priceType3Hex.match(/.{2}/g)?.reverse().join('') || priceType3Hex;\r\n const priceType3 = BigInt('0x' + priceType3BE);\r\n\r\n // Extract endSale (bytes4 = 8 hex chars, positions 30-38)\r\n // CashScript stores numbers in little-endian format\r\n // Contract uses: bytes endSale = tx.inputs[0].nftCommitment.slice(15,19);\r\n // This is bytes 15-19 (0-indexed), which is hex positions 30-38\r\n const endSaleHex = commitment.substring(30, 38);\r\n const endSaleBE = endSaleHex.match(/.{2}/g)?.reverse().join('') || endSaleHex;\r\n const endSale = parseInt(endSaleBE, 16);\r\n\r\n // Extract adminPubKeyHash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHash = commitment.substring(38, 78);\r\n\r\n return {\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash,\r\n };\r\n } catch (error) {\r\n console.error('Failed to parse TicketMaster commitment:', error);\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a TicketMaster (has minting capability)\r\n */\r\nexport function isTicketMaster(utxo: any): boolean {\r\n return (\r\n utxo?.token?.nft?.capability === 'minting' &&\r\n utxo?.token?.nft?.commitment &&\r\n utxo.token.nft.commitment.length >= 78\r\n );\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a ticket (same category as TicketMaster but immutable)\r\n */\r\nexport function isTicket(utxo: any, ticketMasterCategory: string): boolean {\r\n return (\r\n utxo?.token?.category === ticketMasterCategory &&\r\n utxo?.token?.nft?.capability === 'none'\r\n );\r\n}\r\n\r\n/**\r\n * Formats satoshis to BCH\r\n */\r\nexport function formatBCH(satoshis: bigint | number | string): string {\r\n const sats = typeof satoshis === 'string' ? BigInt(satoshis) : BigInt(satoshis);\r\n const bch = Number(sats) / 100000000;\r\n return bch.toFixed(8);\r\n}\r\n\r\n","import { decodeCashAddress, encodeCashAddress } from '@bitauth/libauth';\r\n\r\n/**\r\n * Converts a regular Bitcoin Cash address to its token address equivalent\r\n * @param address - Bitcoin Cash address (p2pkh)\r\n * @returns Token address (p2pkhWithTokens)\r\n */\r\nfunction toTokenAddress(address: string): string {\r\n const addressInfo: any = decodeCashAddress(address);\r\n const pkhPayoutBin = addressInfo.payload;\r\n const prefix = addressInfo.prefix;\r\n const tokenAddressResult = encodeCashAddress({prefix, type: \"p2pkhWithTokens\", payload: pkhPayoutBin});\r\n \r\n // In libauth v3, encodeCashAddress returns a CashAddressResult object\r\n if (typeof tokenAddressResult === 'string') {\r\n return tokenAddressResult;\r\n }\r\n return tokenAddressResult.address;\r\n}\r\n\r\nexport default toTokenAddress;\r\n\r\n","/**\r\n * Shared utility functions\r\n */\r\n\r\nexport { createSignTransaction } from './signTransaction';\r\nexport { parseTicketMasterCommitment, formatBCH, isTicketMaster, isTicket, type TicketMasterData } from './ticketMaster';\r\nexport { default as toTokenAddress } from './toTokenAddress';\r\n\r\n/**\r\n * Ensures an address has the bitcoincash: prefix for libauth functions\r\n * Addresses from AppKit may come without the prefix after normalization\r\n */\r\nexport function ensureAddressPrefix(address: string): string {\r\n // If address already has a prefix, return as-is\r\n if (address.includes(':')) {\r\n return address;\r\n }\r\n \r\n // Add bitcoincash: prefix for mainnet addresses\r\n // Addresses starting with 'q' or 'p' are mainnet\r\n if (address.startsWith('q') || address.startsWith('p')) {\r\n return `bitcoincash:${address}`;\r\n }\r\n \r\n // For testnet addresses starting with 'bchtest:' or 'q'/'p' on testnet\r\n // This is a simple check - you may need to adjust based on your network\r\n return `bitcoincash:${address}`;\r\n}\r\n\r\n/**\r\n * Converts hex string to Uint8Array\r\n */\r\nexport function hexToUint8Array(hexString: string): Uint8Array {\r\n const bytes = new Uint8Array(hexString.length / 2);\r\n for (let i = 0; i < bytes.length; i++) {\r\n bytes[i] = parseInt(hexString.substr(i * 2, 2), 16);\r\n }\r\n return bytes;\r\n}\r\n\r\n/**\r\n * Converts a number to little-endian hex string\r\n * @param number - The number to convert\r\n * @param byteCount - Number of bytes (e.g., 5 for bytes5, 4 for bytes4)\r\n */\r\nexport function toLittleEndianHexString(number: bigint | number, byteCount: number): string {\r\n const num = typeof number === 'bigint' ? number : BigInt(number);\r\n let hex = num.toString(16);\r\n hex = hex.padStart(byteCount * 2, '0'); // Pad with zeros to ensure correct byteCount\r\n // Split into chunks of 2 (bytes), reverse (for little endian), and join back\r\n return hex.match(/../g)?.reverse().join('') ?? '';\r\n}\r\n\r\n","// TokenSales_old1 contract addresses\r\n//export const AddressTicketMaster = 'bitcoincash:pvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryszkdd99zq'; //address hash: 2ef2757e6a8659a54a3a43384764091ac82c05e8d2b5941fdefb551b20564648\r\n//export const AddressTicketMasterToken = 'bitcoincash:rvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryss93vuymt';\r\n\r\n// TokenSales_old2 contract addresses | simplified change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2m4afvzlt'; //address hash: 76bebd71fef3c48ef2fec86b1a24ceaa7fb06f3e1aed923ac8176955c20f5085\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2fxpg4rxq';\r\n\r\n// TokenSales_old3 contract addresses | fixed change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vz3syd0y9'; //address hash: 7ff1e58e69a1346149d6000befea51cf43bf0aefcff02c15c20a477024002f46\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vszv95waw';\r\n\r\n// TokenSales contract addresses | restricted burnTokenSale() so user-provided utxo must be input0\r\nexport const AddressTicketMaster = 'bitcoincash:pwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnwzutlweuk'; //address hash: b6ef29da52497a243a73a70115dede6e38653148ccdbaafa24f7f662b8bc5b37\r\nexport const AddressTicketMasterToken = 'bitcoincash:rwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnws0h7hc9a';\r\n\r\n// Ticket Level Descriptions\r\nexport const TICKET_LEVEL_DESCRIPTIONS = {\r\n '01': {\r\n name: 'Regular',\r\n description: 'Regular tickets provide standard access to the event. This is the base level ticket option.'\r\n },\r\n '02': {\r\n name: 'VIP',\r\n description: 'VIP tickets offer enhanced benefits including priority access, exclusive areas, and additional perks.'\r\n },\r\n '03': {\r\n name: 'Premium',\r\n description: 'Premium tickets provide the highest level of access with all VIP benefits plus additional exclusive features.'\r\n }\r\n};\r\n\r\n","/**\r\n * TokenSales contract addresses\r\n * These are the addresses for the TokenSales (TicketMaster) contract\r\n */\r\nimport { AddressTicketMaster, AddressTicketMasterToken } from './constants/values';\r\n\r\nexport const DEFAULT_CONTRACT_ADDRESSES = {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n} as const;\r\n\r\n/**\r\n * Get contract address\r\n * @returns Contract address\r\n */\r\nexport function getContractAddress(): string {\r\n return AddressTicketMaster;\r\n}\r\n\r\n/**\r\n * Get token address\r\n * @returns Token address\r\n */\r\nexport function getTokenAddress(): string {\r\n return AddressTicketMasterToken;\r\n}\r\n\r\n/**\r\n * Get contract addresses\r\n * @returns Object with contract and token addresses\r\n */\r\nexport function getContractAddresses() {\r\n return {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n };\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction, encodeCashAddress } from '@bitauth/libauth';\r\nimport { BuyNFTParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, hexToUint8Array, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Purchase a ticket NFT from a TicketMaster\r\n * @param params - BuyNFTParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function buyNFT(params: BuyNFTParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n ticketUtxo,\r\n ticketType,\r\n isAdmin\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === ticketUtxo.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n \r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = ticketUtxo.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('ticketUtxo must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Parse TicketMaster commitment to get price and admin address\r\n const commitment = ticketMasterUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TicketMaster commitment');\r\n }\r\n\r\n // Extract price based on ticket type (little-endian format)\r\n let ticketPrice: bigint;\r\n let priceHex: string;\r\n \r\n if (ticketType === '01') {\r\n priceHex = commitment.substring(0, 10);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n } else if (ticketType === '02') {\r\n priceHex = commitment.substring(10, 20);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 2 is not available');\r\n }\r\n } else if (ticketType === '03') {\r\n priceHex = commitment.substring(20, 30);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 3 is not available');\r\n }\r\n } else {\r\n throw new Error('Invalid ticket type');\r\n }\r\n\r\n // Extract admin pubkey hash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHashHex = commitment.substring(38, 78);\r\n \r\n // Convert hex string to Uint8Array\r\n const adminPKHUint8Array = hexToUint8Array(adminPubKeyHashHex);\r\n \r\n // Derive admin address from embedded pubkey hash\r\n const prefix = 'bitcoincash';\r\n const addressType = 'p2pkh';\r\n const adminAddressResult = encodeCashAddress({\r\n prefix,\r\n type: addressType,\r\n payload: adminPKHUint8Array\r\n });\r\n \r\n if (typeof adminAddressResult === 'string') {\r\n throw new Error(`Failed to encode admin address: ${adminAddressResult}`);\r\n }\r\n const adminAddress = adminAddressResult.address;\r\n \r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n \r\n // Convert address to locking bytecode\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Get userUTXO\r\n let userUTXO: Utxo | undefined;\r\n if (isAdmin) {\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.token?.category === ticketMasterUtxo.token?.category && \r\n utxo.token?.nft?.capability === 'minting'\r\n );\r\n } else {\r\n // Find pure BCH payment UTXO (need ticketPrice & 3000+ sats for miner fee)\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (ticketPrice + 3000n) && !utxo.token,\r\n );\r\n\r\n if (!userUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n // If totalSats is enough, then user needs to consolidate\r\n if (totalSats >= ticketPrice + 3000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${ticketPrice + 3000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n }\r\n\r\n if (!userUTXO) {\r\n throw new Error('No suitable UTXO found for transaction');\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(ticketUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(userUTXO, p2pkhUnlocker)\r\n // Ticket master NFT being sent back to contract\r\n .addOutput({\r\n to: ticketMasterContract.tokenAddress, \r\n amount: ticketMasterUtxo.satoshis,\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount!, \r\n category: ticketMasterUtxo.token?.category!, \r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!, \r\n commitment: ticketMasterUtxo.token?.nft?.commitment! \r\n }\r\n },\r\n })\r\n // Ticket being purchased\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: ticketUtxo.satoshis,\r\n token: {\r\n amount: ticketUtxo.token?.amount!, \r\n category: ticketUtxo.token?.category!, \r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!, \r\n commitment: ticketUtxo.token?.nft?.commitment! + ticketType // ticketType appended to commitment\r\n }\r\n },\r\n })\r\n // Ticket price is sent to admin address\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: 1000n,\r\n });\r\n } else {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: ticketPrice,\r\n });\r\n }\r\n\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userUTXO.satoshis - 2700n,\r\n token: {\r\n amount: userUTXO.token?.amount!, \r\n category: userUTXO.token?.category!, \r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!, \r\n commitment: userUTXO.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } else {\r\n // Calculate change amount (userUTXO - ticketPrice - miner fee)\r\n const changeAmount = userUTXO.satoshis - ticketPrice - 2700n;\r\n if (changeAmount > 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress, \r\n amount: changeAmount\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n console.log('Transaction built:', transaction);\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 2)\r\n decodedTransaction.inputs[2].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binTicketCommitment = hexToBin(ticketUtxo.token?.nft?.commitment!);\r\n const binUserCommitment = isAdmin ? hexToBin(userUTXO.token?.nft?.commitment!) : undefined;\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n // Use raw Uint8Arrays and BigInts - stringify from @bitauth/libauth will handle serialization\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!,\r\n commitment: binTicketCommitment\r\n }\r\n }\r\n },\r\n ...(isAdmin ? [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n token: {\r\n amount: userUTXO.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!,\r\n commitment: binUserCommitment!\r\n }\r\n }\r\n }] : [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n }])\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Purchase Ticket Type ${ticketType} for ${ticketPrice} sats`\r\n };\r\n\r\n console.log('WalletConnect transaction object:', wcTransactionObj);\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { ModifyTokenSaleParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Modify TokenSale parameters (prices, endSale)\r\n * @param params - ModifyTokenSaleParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function modifyTokenSale(params: ModifyTokenSaleParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n tokenSaleUtxo,\r\n userMintingUtxo,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const tokenSaleContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Parse TokenSale commitment to validate\r\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TokenSale commitment');\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = tokenSaleContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n const priceType1Hex = toLittleEndianHexString(BigInt(priceType1), 5);\r\n const priceType2Hex = toLittleEndianHexString(BigInt(priceType2), 5);\r\n const priceType3Hex = toLittleEndianHexString(BigInt(priceType3), 5);\r\n const endSaleHex = toLittleEndianHexString(BigInt(endSale), 4);\r\n const adminPkh = tokenSaleUtxo.token?.nft?.commitment!.substring(38, 78);\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(tokenSaleUtxo, tokenSaleContract.unlock.modifyTokenSale(priceType1Hex, priceType2Hex, priceType3Hex, endSaleHex))\r\n .addInput(userMintingUtxo, p2pkhUnlocker)\r\n // TokenSale NFT being sent back to contract with new commitment\r\n .addOutput({\r\n to: tokenSaleContract.tokenAddress, \r\n amount: tokenSaleUtxo.satoshis,\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount!, \r\n category: tokenSaleUtxo.token?.category!, \r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!, \r\n commitment: priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkh\r\n }\r\n },\r\n })\r\n // Admin NFT being sent back to user\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingUtxo.satoshis - 1000n,\r\n token: {\r\n amount: userMintingUtxo.token?.amount!, \r\n category: userMintingUtxo.token?.category!, \r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!, \r\n commitment: userMintingUtxo.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 1)\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(tokenSaleUtxo.token?.category!);\r\n const binTokenSaleCommitment = hexToBin(tokenSaleUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingUtxo.token?.nft?.commitment!);\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((tokenSaleContract.redeemScript as any).bytecode) {\r\n return (tokenSaleContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof tokenSaleContract.redeemScript === 'string') {\r\n return hexToBin(tokenSaleContract.redeemScript);\r\n }\r\n return new Uint8Array(tokenSaleContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(tokenSaleUtxo.satoshis),\r\n contract: {\r\n abiFunction: tokenSaleContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: tokenSaleContract.artifact,\r\n },\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!,\r\n commitment: binTokenSaleCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingUtxo.satoshis),\r\n token: {\r\n amount: userMintingUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Modify TokenSale NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { BurnParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Burn a TicketMaster NFT and all associated tickets\r\n * @param params - BurnParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function burn(params: BurnParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n userMintingNFT,\r\n tickets\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === userMintingNFT.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = userMintingNFT.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('userMintingNFT must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n // Start building transaction\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add TicketMaster to be burned\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.burnTokenSale());\r\n\r\n // Add all tickets to be burned\r\n for (const ticket of tickets) {\r\n transaction = transaction.addInput(ticket, ticketMasterContract.unlock.burnTokenSale());\r\n }\r\n\r\n // Send admin NFT back to user\r\n transaction = transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingNFT.satoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!, \r\n category: userMintingNFT.token?.category!, \r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!, \r\n commitment: userMintingNFT.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 0)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n // For each ticket, convert hex to Uint8Array\r\n const binTicketCommitments = tickets.map((ticket) => hexToBin(ticket.token?.nft?.commitment!));\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Add all tickets to the list of source outputs\r\n for (let i = 0; i < tickets.length; i++) {\r\n const ticket = tickets[i];\r\n listSourceOutputs.push({\r\n ...decodedTransaction.inputs[i + 2],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticket.satoshis),\r\n token: {\r\n amount: ticket.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticket.token?.nft?.capability!,\r\n commitment: binTicketCommitments[i]\r\n }\r\n }\r\n });\r\n }\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: true,\r\n userPrompt: `Burn TicketMaster and ${tickets.length} tickets`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { AddSatoshisParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\n\r\n/**\r\n * Add satoshis to a minting NFT\r\n * @param params - AddSatoshisParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function addSatoshis(params: AddSatoshisParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n additionalSatoshis\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n if (additionalSatoshis <= 0n) {\r\n throw new Error('Additional satoshis must be greater than 0');\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs to find a BCH UTXO to fund the additional satoshis\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Find a BCH UTXO with enough satoshis (additionalSatoshis + miner fee ~1000 sats)\r\n const fundingUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (additionalSatoshis + 1000n) && !utxo.token\r\n );\r\n\r\n if (!fundingUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n if (totalSats >= additionalSatoshis + 1000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${additionalSatoshis + 1000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Add the minting NFT as input\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add the funding UTXO to provide additional satoshis\r\n .addInput(fundingUTXO, p2pkhUnlocker)\r\n // Output: minting NFT with additional satoshis\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis + additionalSatoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n\r\n // Calculate change (fundingUTXO - additionalSatoshis - miner fee)\r\n const changeAmount = fundingUTXO.satoshis - additionalSatoshis - 1000n;\r\n if (changeAmount >= 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress,\r\n amount: changeAmount,\r\n });\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user inputs (wallet will sign these)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Get locking bytecode for user address\r\n const userLockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof userLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${userLockingBytecodeResult}`);\r\n }\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(fundingUTXO.satoshis)\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Add ${additionalSatoshis} satoshis to minting NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { CreateListingParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\nimport { AddressTicketMasterToken } from '../constants/values';\r\n\r\n/**\r\n * Create a new TicketMaster listing\r\n * @param params - CreateListingParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function createListing(params: CreateListingParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Validate adminPubKeyHash\r\n const adminPkhHex = adminPubKeyHash.replace(/^0x/i, '').trim();\r\n if (adminPkhHex.length !== 40 || !/^[0-9a-fA-F]+$/.test(adminPkhHex)) {\r\n throw new Error('Admin PubKey Hash must be 40 hex characters (20 bytes)');\r\n }\r\n\r\n // Normalize user address\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get token address from compiled contract\r\n const contractTokenAddr = ticketMasterContract.tokenAddress;\r\nconsole.log('contractTokenAddr', contractTokenAddr);\r\nconsole.log('AddressTicketMasterToken', AddressTicketMasterToken);\r\n // Get locking bytecode for contract token address\r\n const contractTokenLockingBytecodeResult = cashAddressToLockingBytecode(contractTokenAddr);\r\n if (typeof contractTokenLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract token address to locking bytecode: ${contractTokenLockingBytecodeResult}`);\r\n }\r\n\r\n // Build TicketMaster commitment\r\n // Format: bytes5 priceType1 + bytes5 priceType2 + bytes5 priceType3 + bytes4 endSale + bytes20 adminPubKeyHash\r\n // Total: 39 bytes = 78 hex chars\r\n const priceType1Hex = toLittleEndianHexString(priceType1, 5); // 10 hex chars\r\n const priceType2Hex = toLittleEndianHexString(priceType2, 5); // 10 hex chars\r\n const priceType3Hex = toLittleEndianHexString(priceType3, 5); // 10 hex chars\r\n const endSaleHex = toLittleEndianHexString(endSale, 4); // 8 hex chars\r\n const ticketMasterCommitment = priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkhHex;\r\n \r\n if (ticketMasterCommitment.length !== 78) {\r\n throw new Error(`Invalid commitment length: ${ticketMasterCommitment.length}, expected 78`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Input: user's minting NFT\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Output 0: user's minting NFT back to user\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis - 2000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n })\r\n // Output 1: TicketMaster Minting NFT to contract token address\r\n .addOutput({\r\n to: contractTokenAddr,\r\n amount: 1000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: 'minting',\r\n commitment: ticketMasterCommitment\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (wallet will sign this)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binUserCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Create TicketMaster listing`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { Utxo } from 'cashscript';\nimport { ListAvailableTicketsParams } from '../types';\nimport { getTokenAddress } from '../config';\nimport { parseTicketMasterCommitment, isTicketMaster, isTicket } from '../utils/ticketMaster';\n\n/**\n * List available tickets for purchase from a TokenSale\n * @param params - ListAvailableTicketsParams object containing all required parameters\n * @returns Promise resolving to array of ticket UTXOs that are available for purchase\n * @throws Error if validation fails or TokenSale is not found/active\n */\nexport async function listAvailableTickets(params: ListAvailableTicketsParams): Promise<Utxo[]> {\n const {\n electrumProvider,\n categoryID\n } = params;\n\n if (!electrumProvider) {\n throw new Error('Electrum provider not available');\n }\n\n if (!categoryID || categoryID.length === 0) {\n throw new Error('Category ID is required');\n }\n\n // Get the contract token address\n const contractTokenAddress = getTokenAddress();\n\n // Get all UTXOs from the contract token address\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\n\n // Filter UTXOs to only those matching the categoryID\n const categoryUtxos = contractUtxos.filter((utxo: Utxo) => \n utxo?.token?.category === categoryID\n );\n\n if (categoryUtxos.length === 0) {\n return []; // No UTXOs found for this category\n }\n\n // Find the TokenSale minting NFT (capability === 'minting')\n const tokenSaleUtxo = categoryUtxos.find((utxo: Utxo) => \n isTicketMaster(utxo)\n );\n\n if (!tokenSaleUtxo) {\n throw new Error(`No active TokenSale found for category ${categoryID}`);\n }\n\n // Parse the TokenSale commitment to get endSale block height\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\n const tokenSaleData = parseTicketMasterCommitment(commitment);\n\n if (!tokenSaleData) {\n throw new Error('Failed to parse TokenSale commitment');\n }\n\n // Filter to only ticket UTXOs (capability === 'none')\n const availableTickets = categoryUtxos.filter((utxo: Utxo) => \n isTicket(utxo, categoryID)\n );\n\n return availableTickets;\n}\n","import { ListAllSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List all TokenSale NFTs (minting capability & 39-byte commitment)\r\n * @param params - ListAllSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listAllSales(params: ListAllSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only TokenSale NFTs (minting capability with 39-byte commitment)\r\n const tokenSaleUtxos: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n tokenSaleUtxos.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n\r\n return tokenSaleUtxos;\r\n}\r\n","import { ListActiveSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List active TokenSale NFTs (minting capability, 39-byte commitment, sale not ended)\r\n * A sale is active when current blockheight > endSale commitment field\r\n * @param params - ListActiveSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of active TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listActiveSales(params: ListActiveSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get current block height\r\n let currentBlockHeight: number;\r\n if (typeof (electrumProvider as any).getBlockHeight === 'function') {\r\n currentBlockHeight = await (electrumProvider as any).getBlockHeight();\r\n } else if (typeof (electrumProvider as any).performRequest === 'function') {\r\n try {\r\n const header = await (electrumProvider as any).performRequest('blockchain.headers.subscribe');\r\n currentBlockHeight = header?.height || header;\r\n } catch (e) {\r\n // Fallback: try to get block height from getUtxos call\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n } else {\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only active TokenSale NFTs (sale not ended)\r\n const activeSales: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n // Sale is active when current blockheight > endSale\r\n if (currentBlockHeight < tokenSaleData.endSale) {\r\n activeSales.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n return activeSales;\r\n}\r\n"],"names":[],"mappings":";;;AAEA;;;;;;;AAOG;AACG,SAAU,qBAAqB,CACnC,UAAe,EACf,cAAuB,EAAA;AAEvB,IAAA,OAAO,OAAO,kBAAuB,KAAI;QACvC,IAAI,CAAC,UAAU,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC;QACjF;;QAGA,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE;AAE5C,QAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACzB,YAAA,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;QAChF;;AAGA,QAAA,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;;;QAI3B,IAAI,OAAO,GAAkB,IAAI;AAEjC,QAAA,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE;AAC3C,QAAA,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG;AAEnC,QAAA,IAAI,YAAY,IAAI,YAAY,CAAC,QAAQ,IAAI,YAAY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CAAC,IAAI,CAAC,EAAE;YACxB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,IAAI,EAAE;AACpD,YAAA,MAAM,aAAa,GAAG,2BAA2B,CAAC,UAAU,CAAC;YAE7D,IAAI,aAAa,EAAE;;AAEjB,gBAAA,IAAI,kBAAkB,GAAG,aAAa,CAAC,OAAO,EAAE;oBAC9C,WAAW,CAAC,IAAI,CAAC;AACf,wBAAA,GAAG,IAAI;wBACP;AACD,qBAAA,CAAC;gBACJ;YACF;QACF;IACF;AAEA,IAAA,OAAO,WAAW;AACpB;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -787,7 +787,7 @@ async function buyNFT(params) {
|
|
|
787
787
|
}
|
|
788
788
|
else {
|
|
789
789
|
// Calculate change amount (userUTXO - ticketPrice - miner fee)
|
|
790
|
-
const changeAmount = userUTXO.satoshis - ticketPrice -
|
|
790
|
+
const changeAmount = userUTXO.satoshis - ticketPrice - 2700n;
|
|
791
791
|
if (changeAmount > 1000n) { // Dust limit
|
|
792
792
|
transaction.addOutput({
|
|
793
793
|
to: normalizedUserAddress,
|
|
@@ -804,6 +804,7 @@ async function buyNFT(params) {
|
|
|
804
804
|
throw new Error(`Error building transaction: ${String(error)}`);
|
|
805
805
|
}
|
|
806
806
|
}
|
|
807
|
+
console.log('Transaction built:', transaction);
|
|
807
808
|
// Build the transaction
|
|
808
809
|
const rawTransactionHex = await transaction.build();
|
|
809
810
|
// Decode transaction for WalletConnect
|
|
@@ -893,6 +894,7 @@ async function buyNFT(params) {
|
|
|
893
894
|
broadcast: false,
|
|
894
895
|
userPrompt: `Purchase Ticket Type ${ticketType} for ${ticketPrice} sats`
|
|
895
896
|
};
|
|
897
|
+
console.log('WalletConnect transaction object:', wcTransactionObj);
|
|
896
898
|
return wcTransactionObj;
|
|
897
899
|
}
|
|
898
900
|
|
|
@@ -1236,7 +1238,7 @@ async function burn(params) {
|
|
|
1236
1238
|
const wcTransactionObj = {
|
|
1237
1239
|
transaction: decodedTransaction,
|
|
1238
1240
|
sourceOutputs: listSourceOutputs,
|
|
1239
|
-
broadcast:
|
|
1241
|
+
broadcast: true,
|
|
1240
1242
|
userPrompt: `Burn TicketMaster and ${tickets.length} tickets`
|
|
1241
1243
|
};
|
|
1242
1244
|
return wcTransactionObj;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils/signTransaction.ts","../src/utils/ticketMaster.ts","../src/utils/toTokenAddress.ts","../src/utils/index.ts","../src/constants/values.ts","../src/config.ts","../src/functions/buyNFT.ts","../src/functions/modifyTokenSale.ts","../src/functions/burn.ts","../src/functions/addSatoshis.ts","../src/functions/createListing.ts","../src/functions/listAvailableTickets.ts","../src/functions/listAllSales.ts","../src/functions/listActiveSales.ts"],"sourcesContent":["import { stringify } from '@bitauth/libauth';\r\n\r\n/**\r\n * Creates a signTransaction function for WalletConnect v2\r\n * This function handles transaction signing through WalletConnect's SignClient\r\n * \r\n * @param signClient - The WalletConnect SignClient instance\r\n * @param connectedChain - The connected chain ID (fallback if not found in session)\r\n * @returns A function that signs transactions via WalletConnect\r\n */\r\nexport function createSignTransaction(\r\n signClient: any,\r\n connectedChain?: string\r\n): (transactionOptions: any) => Promise<any> {\r\n return async (transactionOptions: any) => {\r\n if (!signClient) {\r\n throw new Error('SignClient not available. Please ensure wallet is connected.');\r\n }\r\n \r\n // Get all active sessions\r\n const sessions = signClient.session.getAll();\r\n \r\n if (sessions.length === 0) {\r\n throw new Error('No active wallet session. Please connect your wallet first.');\r\n }\r\n \r\n // Use the first active session\r\n const session = sessions[0];\r\n \r\n // Extract chainId from session\r\n // In WalletConnect v2, chainId is in the accounts array as \"chainId:address\"\r\n let chainId: string | null = null;\r\n \r\n const namespaces = session.namespaces || {};\r\n const bchNamespace = namespaces.bch;\r\n \r\n if (bchNamespace && bchNamespace.accounts && bchNamespace.accounts.length > 0) {\r\n // Extract chainId from first account (format: \"chainId:address\")\r\n const firstAccount = bchNamespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2) {\r\n // Reconstruct chainId (could be \"bch:mainnet\" or \"bch:bchtest:chipnet\")\r\n chainId = accountParts.slice(0, -1).join(':'); // Everything except the address part\r\n }\r\n }\r\n \r\n // Fallback: try to find chainId from any namespace\r\n if (!chainId) {\r\n for (const namespaceKey in namespaces) {\r\n const namespace = namespaces[namespaceKey];\r\n if (namespace.accounts && namespace.accounts.length > 0) {\r\n const firstAccount = namespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2 && accountParts[0].includes('bch')) {\r\n chainId = accountParts.slice(0, -1).join(':');\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n \r\n // Final fallback\r\n if (!chainId) {\r\n chainId = connectedChain || 'bch:mainnet';\r\n }\r\n \r\n // Use the same pattern as the working project: JSON.parse(stringify(obj))\r\n // stringify from @bitauth/libauth handles BigInt and Uint8Array serialization\r\n const serializableTxObj = JSON.parse(stringify(transactionOptions));\r\n \r\n try {\r\n const result = await signClient.request({\r\n chainId,\r\n topic: session.topic,\r\n request: {\r\n method: 'bch_signTransaction',\r\n params: serializableTxObj,\r\n },\r\n });\r\n return result;\r\n } catch (error: any) {\r\n // Handle WalletConnect relay errors gracefully\r\n if (error?.message?.includes('onRelayMessage') || error?.message?.includes('failed to process')) {\r\n // The transaction might still have been signed, so we'll let the caller handle it\r\n }\r\n throw error;\r\n }\r\n };\r\n}\r\n\r\n","/**\r\n * Utility functions for parsing TicketMaster NFT data\r\n */\r\n\r\nexport interface TicketMasterData {\r\n priceType1: bigint;\r\n priceType2: bigint;\r\n priceType3: bigint;\r\n endSale: number;\r\n adminPubKeyHash: string;\r\n}\r\n\r\n/**\r\n * Parses TicketMaster NFT commitment to extract sale data\r\n * Commitment format:\r\n * - bytes5 priceType1 (0-5)\r\n * - bytes5 priceType2 (5-10)\r\n * - bytes5 priceType3 (10-15)\r\n * - bytes4 endSale (15-19)\r\n * - bytes20 adminPubKeyHash (19-39)\r\n */\r\nexport function parseTicketMasterCommitment(commitment: string): TicketMasterData | null {\r\n if (!commitment || commitment.length < 78) { // 39 bytes = 78 hex chars\r\n return null;\r\n }\r\n\r\n try {\r\n // Extract priceType1 (bytes5 = 10 hex chars, positions 0-10)\r\n // CashScript stores numbers in little-endian format\r\n const priceType1Hex = commitment.substring(0, 10);\r\n const priceType1BE = priceType1Hex.match(/.{2}/g)?.reverse().join('') || priceType1Hex;\r\n const priceType1 = BigInt('0x' + priceType1BE);\r\n\r\n // Extract priceType2 (bytes5 = 10 hex chars, positions 10-20)\r\n const priceType2Hex = commitment.substring(10, 20);\r\n const priceType2BE = priceType2Hex.match(/.{2}/g)?.reverse().join('') || priceType2Hex;\r\n const priceType2 = BigInt('0x' + priceType2BE);\r\n\r\n // Extract priceType3 (bytes5 = 10 hex chars, positions 20-30)\r\n const priceType3Hex = commitment.substring(20, 30);\r\n const priceType3BE = priceType3Hex.match(/.{2}/g)?.reverse().join('') || priceType3Hex;\r\n const priceType3 = BigInt('0x' + priceType3BE);\r\n\r\n // Extract endSale (bytes4 = 8 hex chars, positions 30-38)\r\n // CashScript stores numbers in little-endian format\r\n // Contract uses: bytes endSale = tx.inputs[0].nftCommitment.slice(15,19);\r\n // This is bytes 15-19 (0-indexed), which is hex positions 30-38\r\n const endSaleHex = commitment.substring(30, 38);\r\n const endSaleBE = endSaleHex.match(/.{2}/g)?.reverse().join('') || endSaleHex;\r\n const endSale = parseInt(endSaleBE, 16);\r\n\r\n // Extract adminPubKeyHash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHash = commitment.substring(38, 78);\r\n\r\n return {\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash,\r\n };\r\n } catch (error) {\r\n console.error('Failed to parse TicketMaster commitment:', error);\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a TicketMaster (has minting capability)\r\n */\r\nexport function isTicketMaster(utxo: any): boolean {\r\n return (\r\n utxo?.token?.nft?.capability === 'minting' &&\r\n utxo?.token?.nft?.commitment &&\r\n utxo.token.nft.commitment.length >= 78\r\n );\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a ticket (same category as TicketMaster but immutable)\r\n */\r\nexport function isTicket(utxo: any, ticketMasterCategory: string): boolean {\r\n return (\r\n utxo?.token?.category === ticketMasterCategory &&\r\n utxo?.token?.nft?.capability === 'none'\r\n );\r\n}\r\n\r\n/**\r\n * Formats satoshis to BCH\r\n */\r\nexport function formatBCH(satoshis: bigint | number | string): string {\r\n const sats = typeof satoshis === 'string' ? BigInt(satoshis) : BigInt(satoshis);\r\n const bch = Number(sats) / 100000000;\r\n return bch.toFixed(8);\r\n}\r\n\r\n","import { decodeCashAddress, encodeCashAddress } from '@bitauth/libauth';\r\n\r\n/**\r\n * Converts a regular Bitcoin Cash address to its token address equivalent\r\n * @param address - Bitcoin Cash address (p2pkh)\r\n * @returns Token address (p2pkhWithTokens)\r\n */\r\nfunction toTokenAddress(address: string): string {\r\n const addressInfo: any = decodeCashAddress(address);\r\n const pkhPayoutBin = addressInfo.payload;\r\n const prefix = addressInfo.prefix;\r\n const tokenAddressResult = encodeCashAddress({prefix, type: \"p2pkhWithTokens\", payload: pkhPayoutBin});\r\n \r\n // In libauth v3, encodeCashAddress returns a CashAddressResult object\r\n if (typeof tokenAddressResult === 'string') {\r\n return tokenAddressResult;\r\n }\r\n return tokenAddressResult.address;\r\n}\r\n\r\nexport default toTokenAddress;\r\n\r\n","/**\r\n * Shared utility functions\r\n */\r\n\r\nexport { createSignTransaction } from './signTransaction';\r\nexport { parseTicketMasterCommitment, formatBCH, isTicketMaster, isTicket, type TicketMasterData } from './ticketMaster';\r\nexport { default as toTokenAddress } from './toTokenAddress';\r\n\r\n/**\r\n * Ensures an address has the bitcoincash: prefix for libauth functions\r\n * Addresses from AppKit may come without the prefix after normalization\r\n */\r\nexport function ensureAddressPrefix(address: string): string {\r\n // If address already has a prefix, return as-is\r\n if (address.includes(':')) {\r\n return address;\r\n }\r\n \r\n // Add bitcoincash: prefix for mainnet addresses\r\n // Addresses starting with 'q' or 'p' are mainnet\r\n if (address.startsWith('q') || address.startsWith('p')) {\r\n return `bitcoincash:${address}`;\r\n }\r\n \r\n // For testnet addresses starting with 'bchtest:' or 'q'/'p' on testnet\r\n // This is a simple check - you may need to adjust based on your network\r\n return `bitcoincash:${address}`;\r\n}\r\n\r\n/**\r\n * Converts hex string to Uint8Array\r\n */\r\nexport function hexToUint8Array(hexString: string): Uint8Array {\r\n const bytes = new Uint8Array(hexString.length / 2);\r\n for (let i = 0; i < bytes.length; i++) {\r\n bytes[i] = parseInt(hexString.substr(i * 2, 2), 16);\r\n }\r\n return bytes;\r\n}\r\n\r\n/**\r\n * Converts a number to little-endian hex string\r\n * @param number - The number to convert\r\n * @param byteCount - Number of bytes (e.g., 5 for bytes5, 4 for bytes4)\r\n */\r\nexport function toLittleEndianHexString(number: bigint | number, byteCount: number): string {\r\n const num = typeof number === 'bigint' ? number : BigInt(number);\r\n let hex = num.toString(16);\r\n hex = hex.padStart(byteCount * 2, '0'); // Pad with zeros to ensure correct byteCount\r\n // Split into chunks of 2 (bytes), reverse (for little endian), and join back\r\n return hex.match(/../g)?.reverse().join('') ?? '';\r\n}\r\n\r\n","// TokenSales_old1 contract addresses\r\n//export const AddressTicketMaster = 'bitcoincash:pvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryszkdd99zq'; //address hash: 2ef2757e6a8659a54a3a43384764091ac82c05e8d2b5941fdefb551b20564648\r\n//export const AddressTicketMasterToken = 'bitcoincash:rvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryss93vuymt';\r\n\r\n// TokenSales_old2 contract addresses | simplified change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2m4afvzlt'; //address hash: 76bebd71fef3c48ef2fec86b1a24ceaa7fb06f3e1aed923ac8176955c20f5085\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2fxpg4rxq';\r\n\r\n// TokenSales_old3 contract addresses | fixed change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vz3syd0y9'; //address hash: 7ff1e58e69a1346149d6000befea51cf43bf0aefcff02c15c20a477024002f46\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vszv95waw';\r\n\r\n// TokenSales contract addresses | restricted burnTokenSale() so user-provided utxo must be input0\r\nexport const AddressTicketMaster = 'bitcoincash:pwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnwzutlweuk'; //address hash: b6ef29da52497a243a73a70115dede6e38653148ccdbaafa24f7f662b8bc5b37\r\nexport const AddressTicketMasterToken = 'bitcoincash:rwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnws0h7hc9a';\r\n\r\n// Ticket Level Descriptions\r\nexport const TICKET_LEVEL_DESCRIPTIONS = {\r\n '01': {\r\n name: 'Regular',\r\n description: 'Regular tickets provide standard access to the event. This is the base level ticket option.'\r\n },\r\n '02': {\r\n name: 'VIP',\r\n description: 'VIP tickets offer enhanced benefits including priority access, exclusive areas, and additional perks.'\r\n },\r\n '03': {\r\n name: 'Premium',\r\n description: 'Premium tickets provide the highest level of access with all VIP benefits plus additional exclusive features.'\r\n }\r\n};\r\n\r\n","/**\r\n * TokenSales contract addresses\r\n * These are the addresses for the TokenSales (TicketMaster) contract\r\n */\r\nimport { AddressTicketMaster, AddressTicketMasterToken } from './constants/values';\r\n\r\nexport const DEFAULT_CONTRACT_ADDRESSES = {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n} as const;\r\n\r\n/**\r\n * Get contract address\r\n * @returns Contract address\r\n */\r\nexport function getContractAddress(): string {\r\n return AddressTicketMaster;\r\n}\r\n\r\n/**\r\n * Get token address\r\n * @returns Token address\r\n */\r\nexport function getTokenAddress(): string {\r\n return AddressTicketMasterToken;\r\n}\r\n\r\n/**\r\n * Get contract addresses\r\n * @returns Object with contract and token addresses\r\n */\r\nexport function getContractAddresses() {\r\n return {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n };\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction, encodeCashAddress } from '@bitauth/libauth';\r\nimport { BuyNFTParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, hexToUint8Array, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Purchase a ticket NFT from a TicketMaster\r\n * @param params - BuyNFTParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function buyNFT(params: BuyNFTParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n ticketUtxo,\r\n ticketType,\r\n isAdmin\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === ticketUtxo.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n \r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = ticketUtxo.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('ticketUtxo must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Parse TicketMaster commitment to get price and admin address\r\n const commitment = ticketMasterUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TicketMaster commitment');\r\n }\r\n\r\n // Extract price based on ticket type (little-endian format)\r\n let ticketPrice: bigint;\r\n let priceHex: string;\r\n \r\n if (ticketType === '01') {\r\n priceHex = commitment.substring(0, 10);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n } else if (ticketType === '02') {\r\n priceHex = commitment.substring(10, 20);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 2 is not available');\r\n }\r\n } else if (ticketType === '03') {\r\n priceHex = commitment.substring(20, 30);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 3 is not available');\r\n }\r\n } else {\r\n throw new Error('Invalid ticket type');\r\n }\r\n\r\n // Extract admin pubkey hash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHashHex = commitment.substring(38, 78);\r\n \r\n // Convert hex string to Uint8Array\r\n const adminPKHUint8Array = hexToUint8Array(adminPubKeyHashHex);\r\n \r\n // Derive admin address from embedded pubkey hash\r\n const prefix = 'bitcoincash';\r\n const addressType = 'p2pkh';\r\n const adminAddressResult = encodeCashAddress({\r\n prefix,\r\n type: addressType,\r\n payload: adminPKHUint8Array\r\n });\r\n \r\n if (typeof adminAddressResult === 'string') {\r\n throw new Error(`Failed to encode admin address: ${adminAddressResult}`);\r\n }\r\n const adminAddress = adminAddressResult.address;\r\n \r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n \r\n // Convert address to locking bytecode\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Get userUTXO\r\n let userUTXO: Utxo | undefined;\r\n if (isAdmin) {\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.token?.category === ticketMasterUtxo.token?.category && \r\n utxo.token?.nft?.capability === 'minting'\r\n );\r\n } else {\r\n // Find pure BCH payment UTXO (need ticketPrice & 3000+ sats for miner fee)\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (ticketPrice + 3000n) && !utxo.token,\r\n );\r\n\r\n if (!userUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n // If totalSats is enough, then user needs to consolidate\r\n if (totalSats >= ticketPrice + 3000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${ticketPrice + 3000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n }\r\n\r\n if (!userUTXO) {\r\n throw new Error('No suitable UTXO found for transaction');\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(ticketUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(userUTXO, p2pkhUnlocker)\r\n // Ticket master NFT being sent back to contract\r\n .addOutput({\r\n to: ticketMasterContract.tokenAddress, \r\n amount: ticketMasterUtxo.satoshis,\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount!, \r\n category: ticketMasterUtxo.token?.category!, \r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!, \r\n commitment: ticketMasterUtxo.token?.nft?.commitment! \r\n }\r\n },\r\n })\r\n // Ticket being purchased\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: ticketUtxo.satoshis,\r\n token: {\r\n amount: ticketUtxo.token?.amount!, \r\n category: ticketUtxo.token?.category!, \r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!, \r\n commitment: ticketUtxo.token?.nft?.commitment! + ticketType // ticketType appended to commitment\r\n }\r\n },\r\n })\r\n // Ticket price is sent to admin address\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: 1000n,\r\n });\r\n } else {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: ticketPrice,\r\n });\r\n }\r\n\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userUTXO.satoshis - 2700n,\r\n token: {\r\n amount: userUTXO.token?.amount!, \r\n category: userUTXO.token?.category!, \r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!, \r\n commitment: userUTXO.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } else {\r\n // Calculate change amount (userUTXO - ticketPrice - miner fee)\r\n const changeAmount = userUTXO.satoshis - ticketPrice - 1700n;\r\n if (changeAmount > 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress, \r\n amount: changeAmount\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 2)\r\n decodedTransaction.inputs[2].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binTicketCommitment = hexToBin(ticketUtxo.token?.nft?.commitment!);\r\n const binUserCommitment = isAdmin ? hexToBin(userUTXO.token?.nft?.commitment!) : undefined;\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n // Use raw Uint8Arrays and BigInts - stringify from @bitauth/libauth will handle serialization\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!,\r\n commitment: binTicketCommitment\r\n }\r\n }\r\n },\r\n ...(isAdmin ? [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n token: {\r\n amount: userUTXO.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!,\r\n commitment: binUserCommitment!\r\n }\r\n }\r\n }] : [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n }])\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Purchase Ticket Type ${ticketType} for ${ticketPrice} sats`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { ModifyTokenSaleParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Modify TokenSale parameters (prices, endSale)\r\n * @param params - ModifyTokenSaleParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function modifyTokenSale(params: ModifyTokenSaleParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n tokenSaleUtxo,\r\n userMintingUtxo,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const tokenSaleContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Parse TokenSale commitment to validate\r\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TokenSale commitment');\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = tokenSaleContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n const priceType1Hex = toLittleEndianHexString(BigInt(priceType1), 5);\r\n const priceType2Hex = toLittleEndianHexString(BigInt(priceType2), 5);\r\n const priceType3Hex = toLittleEndianHexString(BigInt(priceType3), 5);\r\n const endSaleHex = toLittleEndianHexString(BigInt(endSale), 4);\r\n const adminPkh = tokenSaleUtxo.token?.nft?.commitment!.substring(38, 78);\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(tokenSaleUtxo, tokenSaleContract.unlock.modifyTokenSale(priceType1Hex, priceType2Hex, priceType3Hex, endSaleHex))\r\n .addInput(userMintingUtxo, p2pkhUnlocker)\r\n // TokenSale NFT being sent back to contract with new commitment\r\n .addOutput({\r\n to: tokenSaleContract.tokenAddress, \r\n amount: tokenSaleUtxo.satoshis,\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount!, \r\n category: tokenSaleUtxo.token?.category!, \r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!, \r\n commitment: priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkh\r\n }\r\n },\r\n })\r\n // Admin NFT being sent back to user\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingUtxo.satoshis - 1000n,\r\n token: {\r\n amount: userMintingUtxo.token?.amount!, \r\n category: userMintingUtxo.token?.category!, \r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!, \r\n commitment: userMintingUtxo.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 1)\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(tokenSaleUtxo.token?.category!);\r\n const binTokenSaleCommitment = hexToBin(tokenSaleUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingUtxo.token?.nft?.commitment!);\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((tokenSaleContract.redeemScript as any).bytecode) {\r\n return (tokenSaleContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof tokenSaleContract.redeemScript === 'string') {\r\n return hexToBin(tokenSaleContract.redeemScript);\r\n }\r\n return new Uint8Array(tokenSaleContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(tokenSaleUtxo.satoshis),\r\n contract: {\r\n abiFunction: tokenSaleContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: tokenSaleContract.artifact,\r\n },\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!,\r\n commitment: binTokenSaleCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingUtxo.satoshis),\r\n token: {\r\n amount: userMintingUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Modify TokenSale NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { BurnParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Burn a TicketMaster NFT and all associated tickets\r\n * @param params - BurnParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function burn(params: BurnParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n userMintingNFT,\r\n tickets\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === userMintingNFT.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n \r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = userMintingNFT.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('userMintingNFT must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n // Start building transaction\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add TicketMaster to be burned\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.burnTokenSale());\r\n\r\n // Add all tickets to be burned\r\n for (const ticket of tickets) {\r\n transaction = transaction.addInput(ticket, ticketMasterContract.unlock.burnTokenSale());\r\n }\r\n\r\n // Send admin NFT back to user\r\n transaction = transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingNFT.satoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!, \r\n category: userMintingNFT.token?.category!, \r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!, \r\n commitment: userMintingNFT.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 0)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n // For each ticket, convert hex to Uint8Array\r\n const binTicketCommitments = tickets.map((ticket) => hexToBin(ticket.token?.nft?.commitment!));\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Add all tickets to the list of source outputs\r\n for (let i = 0; i < tickets.length; i++) {\r\n const ticket = tickets[i];\r\n listSourceOutputs.push({\r\n ...decodedTransaction.inputs[i + 2],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticket.satoshis),\r\n token: {\r\n amount: ticket.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticket.token?.nft?.capability!,\r\n commitment: binTicketCommitments[i]\r\n }\r\n }\r\n });\r\n }\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Burn TicketMaster and ${tickets.length} tickets`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { AddSatoshisParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\n\r\n/**\r\n * Add satoshis to a minting NFT\r\n * @param params - AddSatoshisParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function addSatoshis(params: AddSatoshisParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n additionalSatoshis\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n if (additionalSatoshis <= 0n) {\r\n throw new Error('Additional satoshis must be greater than 0');\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs to find a BCH UTXO to fund the additional satoshis\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Find a BCH UTXO with enough satoshis (additionalSatoshis + miner fee ~1000 sats)\r\n const fundingUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (additionalSatoshis + 1000n) && !utxo.token\r\n );\r\n\r\n if (!fundingUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n if (totalSats >= additionalSatoshis + 1000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${additionalSatoshis + 1000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Add the minting NFT as input\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add the funding UTXO to provide additional satoshis\r\n .addInput(fundingUTXO, p2pkhUnlocker)\r\n // Output: minting NFT with additional satoshis\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis + additionalSatoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n\r\n // Calculate change (fundingUTXO - additionalSatoshis - miner fee)\r\n const changeAmount = fundingUTXO.satoshis - additionalSatoshis - 1000n;\r\n if (changeAmount >= 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress,\r\n amount: changeAmount,\r\n });\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user inputs (wallet will sign these)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Get locking bytecode for user address\r\n const userLockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof userLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${userLockingBytecodeResult}`);\r\n }\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(fundingUTXO.satoshis)\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Add ${additionalSatoshis} satoshis to minting NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { CreateListingParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\nimport { AddressTicketMasterToken } from '../constants/values';\r\n\r\n/**\r\n * Create a new TicketMaster listing\r\n * @param params - CreateListingParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function createListing(params: CreateListingParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Validate adminPubKeyHash\r\n const adminPkhHex = adminPubKeyHash.replace(/^0x/i, '').trim();\r\n if (adminPkhHex.length !== 40 || !/^[0-9a-fA-F]+$/.test(adminPkhHex)) {\r\n throw new Error('Admin PubKey Hash must be 40 hex characters (20 bytes)');\r\n }\r\n\r\n // Normalize user address\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get token address from compiled contract\r\n const contractTokenAddr = ticketMasterContract.tokenAddress;\r\nconsole.log('contractTokenAddr', contractTokenAddr);\r\nconsole.log('AddressTicketMasterToken', AddressTicketMasterToken);\r\n // Get locking bytecode for contract token address\r\n const contractTokenLockingBytecodeResult = cashAddressToLockingBytecode(contractTokenAddr);\r\n if (typeof contractTokenLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract token address to locking bytecode: ${contractTokenLockingBytecodeResult}`);\r\n }\r\n\r\n // Build TicketMaster commitment\r\n // Format: bytes5 priceType1 + bytes5 priceType2 + bytes5 priceType3 + bytes4 endSale + bytes20 adminPubKeyHash\r\n // Total: 39 bytes = 78 hex chars\r\n const priceType1Hex = toLittleEndianHexString(priceType1, 5); // 10 hex chars\r\n const priceType2Hex = toLittleEndianHexString(priceType2, 5); // 10 hex chars\r\n const priceType3Hex = toLittleEndianHexString(priceType3, 5); // 10 hex chars\r\n const endSaleHex = toLittleEndianHexString(endSale, 4); // 8 hex chars\r\n const ticketMasterCommitment = priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkhHex;\r\n \r\n if (ticketMasterCommitment.length !== 78) {\r\n throw new Error(`Invalid commitment length: ${ticketMasterCommitment.length}, expected 78`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Input: user's minting NFT\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Output 0: user's minting NFT back to user\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis - 2000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n })\r\n // Output 1: TicketMaster Minting NFT to contract token address\r\n .addOutput({\r\n to: contractTokenAddr,\r\n amount: 1000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: 'minting',\r\n commitment: ticketMasterCommitment\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (wallet will sign this)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binUserCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Create TicketMaster listing`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { Utxo } from 'cashscript';\nimport { ListAvailableTicketsParams } from '../types';\nimport { getTokenAddress } from '../config';\nimport { parseTicketMasterCommitment, isTicketMaster, isTicket } from '../utils/ticketMaster';\n\n/**\n * List available tickets for purchase from a TokenSale\n * @param params - ListAvailableTicketsParams object containing all required parameters\n * @returns Promise resolving to array of ticket UTXOs that are available for purchase\n * @throws Error if validation fails or TokenSale is not found/active\n */\nexport async function listAvailableTickets(params: ListAvailableTicketsParams): Promise<Utxo[]> {\n const {\n electrumProvider,\n categoryID\n } = params;\n\n if (!electrumProvider) {\n throw new Error('Electrum provider not available');\n }\n\n if (!categoryID || categoryID.length === 0) {\n throw new Error('Category ID is required');\n }\n\n // Get the contract token address\n const contractTokenAddress = getTokenAddress();\n\n // Get all UTXOs from the contract token address\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\n\n // Filter UTXOs to only those matching the categoryID\n const categoryUtxos = contractUtxos.filter((utxo: Utxo) => \n utxo?.token?.category === categoryID\n );\n\n if (categoryUtxos.length === 0) {\n return []; // No UTXOs found for this category\n }\n\n // Find the TokenSale minting NFT (capability === 'minting')\n const tokenSaleUtxo = categoryUtxos.find((utxo: Utxo) => \n isTicketMaster(utxo)\n );\n\n if (!tokenSaleUtxo) {\n throw new Error(`No active TokenSale found for category ${categoryID}`);\n }\n\n // Parse the TokenSale commitment to get endSale block height\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\n const tokenSaleData = parseTicketMasterCommitment(commitment);\n\n if (!tokenSaleData) {\n throw new Error('Failed to parse TokenSale commitment');\n }\n\n // Filter to only ticket UTXOs (capability === 'none')\n const availableTickets = categoryUtxos.filter((utxo: Utxo) => \n isTicket(utxo, categoryID)\n );\n\n return availableTickets;\n}\n","import { ListAllSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List all TokenSale NFTs (minting capability & 39-byte commitment)\r\n * @param params - ListAllSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listAllSales(params: ListAllSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only TokenSale NFTs (minting capability with 39-byte commitment)\r\n const tokenSaleUtxos: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n tokenSaleUtxos.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n\r\n return tokenSaleUtxos;\r\n}\r\n","import { ListActiveSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List active TokenSale NFTs (minting capability, 39-byte commitment, sale not ended)\r\n * A sale is active when current blockheight > endSale commitment field\r\n * @param params - ListActiveSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of active TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listActiveSales(params: ListActiveSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get current block height\r\n let currentBlockHeight: number;\r\n if (typeof (electrumProvider as any).getBlockHeight === 'function') {\r\n currentBlockHeight = await (electrumProvider as any).getBlockHeight();\r\n } else if (typeof (electrumProvider as any).performRequest === 'function') {\r\n try {\r\n const header = await (electrumProvider as any).performRequest('blockchain.headers.subscribe');\r\n currentBlockHeight = header?.height || header;\r\n } catch (e) {\r\n // Fallback: try to get block height from getUtxos call\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n } else {\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only active TokenSale NFTs (sale not ended)\r\n const activeSales: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n // Sale is active when current blockheight > endSale\r\n if (currentBlockHeight < tokenSaleData.endSale) {\r\n activeSales.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n return activeSales;\r\n}\r\n"],"names":["stringify","decodeCashAddress","encodeCashAddress","Contract","cashAddressToLockingBytecode","TransactionBuilder","decodeTransaction","hexToBin"],"mappings":";;;;;AAEA;;;;;;;AAOG;AACG,SAAU,qBAAqB,CACnC,UAAe,EACf,cAAuB,EAAA;AAEvB,IAAA,OAAO,OAAO,kBAAuB,KAAI;QACvC,IAAI,CAAC,UAAU,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC;QACjF;;QAGA,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE;AAE5C,QAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACzB,YAAA,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;QACh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C7D;;AAGA,IAAA,MAAM,oBAAoB,GAAG,eAAe,EAAE;;IAG9C,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,oBAAoB,CAAC;;IAG3E,MAAM,WAAW,GAAoB,EAAE;AAEvC,IAAA,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;AAChC,QAAA,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;YACxB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,IAAI,EAAE;AACpD,YAAA,MAAM,aAAa,GAAG,2BAA2B,CAAC,UAAU,CAAC;YAE7D,IAAI,aAAa,EAAE;;AAEjB,gBAAA,IAAI,kBAAkB,GAAG,aAAa,CAAC,OAAO,EAAE;oBAC9C,WAAW,CAAC,IAAI,CAAC;AACf,wBAAA,GAAG,IAAI;wBACP;AACD,qBAAA,CAAC;gBACJ;YACF;QACF;IACF;AAEA,IAAA,OAAO,WAAW;AACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils/signTransaction.ts","../src/utils/ticketMaster.ts","../src/utils/toTokenAddress.ts","../src/utils/index.ts","../src/constants/values.ts","../src/config.ts","../src/functions/buyNFT.ts","../src/functions/modifyTokenSale.ts","../src/functions/burn.ts","../src/functions/addSatoshis.ts","../src/functions/createListing.ts","../src/functions/listAvailableTickets.ts","../src/functions/listAllSales.ts","../src/functions/listActiveSales.ts"],"sourcesContent":["import { stringify } from '@bitauth/libauth';\r\n\r\n/**\r\n * Creates a signTransaction function for WalletConnect v2\r\n * This function handles transaction signing through WalletConnect's SignClient\r\n * \r\n * @param signClient - The WalletConnect SignClient instance\r\n * @param connectedChain - The connected chain ID (fallback if not found in session)\r\n * @returns A function that signs transactions via WalletConnect\r\n */\r\nexport function createSignTransaction(\r\n signClient: any,\r\n connectedChain?: string\r\n): (transactionOptions: any) => Promise<any> {\r\n return async (transactionOptions: any) => {\r\n if (!signClient) {\r\n throw new Error('SignClient not available. Please ensure wallet is connected.');\r\n }\r\n \r\n // Get all active sessions\r\n const sessions = signClient.session.getAll();\r\n \r\n if (sessions.length === 0) {\r\n throw new Error('No active wallet session. Please connect your wallet first.');\r\n }\r\n \r\n // Use the first active session\r\n const session = sessions[0];\r\n \r\n // Extract chainId from session\r\n // In WalletConnect v2, chainId is in the accounts array as \"chainId:address\"\r\n let chainId: string | null = null;\r\n \r\n const namespaces = session.namespaces || {};\r\n const bchNamespace = namespaces.bch;\r\n \r\n if (bchNamespace && bchNamespace.accounts && bchNamespace.accounts.length > 0) {\r\n // Extract chainId from first account (format: \"chainId:address\")\r\n const firstAccount = bchNamespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2) {\r\n // Reconstruct chainId (could be \"bch:mainnet\" or \"bch:bchtest:chipnet\")\r\n chainId = accountParts.slice(0, -1).join(':'); // Everything except the address part\r\n }\r\n }\r\n \r\n // Fallback: try to find chainId from any namespace\r\n if (!chainId) {\r\n for (const namespaceKey in namespaces) {\r\n const namespace = namespaces[namespaceKey];\r\n if (namespace.accounts && namespace.accounts.length > 0) {\r\n const firstAccount = namespace.accounts[0];\r\n const accountParts = firstAccount.split(':');\r\n if (accountParts.length >= 2 && accountParts[0].includes('bch')) {\r\n chainId = accountParts.slice(0, -1).join(':');\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n \r\n // Final fallback\r\n if (!chainId) {\r\n chainId = connectedChain || 'bch:mainnet';\r\n }\r\n \r\n // Use the same pattern as the working project: JSON.parse(stringify(obj))\r\n // stringify from @bitauth/libauth handles BigInt and Uint8Array serialization\r\n const serializableTxObj = JSON.parse(stringify(transactionOptions));\r\n \r\n try {\r\n const result = await signClient.request({\r\n chainId,\r\n topic: session.topic,\r\n request: {\r\n method: 'bch_signTransaction',\r\n params: serializableTxObj,\r\n },\r\n });\r\n return result;\r\n } catch (error: any) {\r\n // Handle WalletConnect relay errors gracefully\r\n if (error?.message?.includes('onRelayMessage') || error?.message?.includes('failed to process')) {\r\n // The transaction might still have been signed, so we'll let the caller handle it\r\n }\r\n throw error;\r\n }\r\n };\r\n}\r\n\r\n","/**\r\n * Utility functions for parsing TicketMaster NFT data\r\n */\r\n\r\nexport interface TicketMasterData {\r\n priceType1: bigint;\r\n priceType2: bigint;\r\n priceType3: bigint;\r\n endSale: number;\r\n adminPubKeyHash: string;\r\n}\r\n\r\n/**\r\n * Parses TicketMaster NFT commitment to extract sale data\r\n * Commitment format:\r\n * - bytes5 priceType1 (0-5)\r\n * - bytes5 priceType2 (5-10)\r\n * - bytes5 priceType3 (10-15)\r\n * - bytes4 endSale (15-19)\r\n * - bytes20 adminPubKeyHash (19-39)\r\n */\r\nexport function parseTicketMasterCommitment(commitment: string): TicketMasterData | null {\r\n if (!commitment || commitment.length < 78) { // 39 bytes = 78 hex chars\r\n return null;\r\n }\r\n\r\n try {\r\n // Extract priceType1 (bytes5 = 10 hex chars, positions 0-10)\r\n // CashScript stores numbers in little-endian format\r\n const priceType1Hex = commitment.substring(0, 10);\r\n const priceType1BE = priceType1Hex.match(/.{2}/g)?.reverse().join('') || priceType1Hex;\r\n const priceType1 = BigInt('0x' + priceType1BE);\r\n\r\n // Extract priceType2 (bytes5 = 10 hex chars, positions 10-20)\r\n const priceType2Hex = commitment.substring(10, 20);\r\n const priceType2BE = priceType2Hex.match(/.{2}/g)?.reverse().join('') || priceType2Hex;\r\n const priceType2 = BigInt('0x' + priceType2BE);\r\n\r\n // Extract priceType3 (bytes5 = 10 hex chars, positions 20-30)\r\n const priceType3Hex = commitment.substring(20, 30);\r\n const priceType3BE = priceType3Hex.match(/.{2}/g)?.reverse().join('') || priceType3Hex;\r\n const priceType3 = BigInt('0x' + priceType3BE);\r\n\r\n // Extract endSale (bytes4 = 8 hex chars, positions 30-38)\r\n // CashScript stores numbers in little-endian format\r\n // Contract uses: bytes endSale = tx.inputs[0].nftCommitment.slice(15,19);\r\n // This is bytes 15-19 (0-indexed), which is hex positions 30-38\r\n const endSaleHex = commitment.substring(30, 38);\r\n const endSaleBE = endSaleHex.match(/.{2}/g)?.reverse().join('') || endSaleHex;\r\n const endSale = parseInt(endSaleBE, 16);\r\n\r\n // Extract adminPubKeyHash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHash = commitment.substring(38, 78);\r\n\r\n return {\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash,\r\n };\r\n } catch (error) {\r\n console.error('Failed to parse TicketMaster commitment:', error);\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a TicketMaster (has minting capability)\r\n */\r\nexport function isTicketMaster(utxo: any): boolean {\r\n return (\r\n utxo?.token?.nft?.capability === 'minting' &&\r\n utxo?.token?.nft?.commitment &&\r\n utxo.token.nft.commitment.length >= 78\r\n );\r\n}\r\n\r\n/**\r\n * Checks if a UTXO is a ticket (same category as TicketMaster but immutable)\r\n */\r\nexport function isTicket(utxo: any, ticketMasterCategory: string): boolean {\r\n return (\r\n utxo?.token?.category === ticketMasterCategory &&\r\n utxo?.token?.nft?.capability === 'none'\r\n );\r\n}\r\n\r\n/**\r\n * Formats satoshis to BCH\r\n */\r\nexport function formatBCH(satoshis: bigint | number | string): string {\r\n const sats = typeof satoshis === 'string' ? BigInt(satoshis) : BigInt(satoshis);\r\n const bch = Number(sats) / 100000000;\r\n return bch.toFixed(8);\r\n}\r\n\r\n","import { decodeCashAddress, encodeCashAddress } from '@bitauth/libauth';\r\n\r\n/**\r\n * Converts a regular Bitcoin Cash address to its token address equivalent\r\n * @param address - Bitcoin Cash address (p2pkh)\r\n * @returns Token address (p2pkhWithTokens)\r\n */\r\nfunction toTokenAddress(address: string): string {\r\n const addressInfo: any = decodeCashAddress(address);\r\n const pkhPayoutBin = addressInfo.payload;\r\n const prefix = addressInfo.prefix;\r\n const tokenAddressResult = encodeCashAddress({prefix, type: \"p2pkhWithTokens\", payload: pkhPayoutBin});\r\n \r\n // In libauth v3, encodeCashAddress returns a CashAddressResult object\r\n if (typeof tokenAddressResult === 'string') {\r\n return tokenAddressResult;\r\n }\r\n return tokenAddressResult.address;\r\n}\r\n\r\nexport default toTokenAddress;\r\n\r\n","/**\r\n * Shared utility functions\r\n */\r\n\r\nexport { createSignTransaction } from './signTransaction';\r\nexport { parseTicketMasterCommitment, formatBCH, isTicketMaster, isTicket, type TicketMasterData } from './ticketMaster';\r\nexport { default as toTokenAddress } from './toTokenAddress';\r\n\r\n/**\r\n * Ensures an address has the bitcoincash: prefix for libauth functions\r\n * Addresses from AppKit may come without the prefix after normalization\r\n */\r\nexport function ensureAddressPrefix(address: string): string {\r\n // If address already has a prefix, return as-is\r\n if (address.includes(':')) {\r\n return address;\r\n }\r\n \r\n // Add bitcoincash: prefix for mainnet addresses\r\n // Addresses starting with 'q' or 'p' are mainnet\r\n if (address.startsWith('q') || address.startsWith('p')) {\r\n return `bitcoincash:${address}`;\r\n }\r\n \r\n // For testnet addresses starting with 'bchtest:' or 'q'/'p' on testnet\r\n // This is a simple check - you may need to adjust based on your network\r\n return `bitcoincash:${address}`;\r\n}\r\n\r\n/**\r\n * Converts hex string to Uint8Array\r\n */\r\nexport function hexToUint8Array(hexString: string): Uint8Array {\r\n const bytes = new Uint8Array(hexString.length / 2);\r\n for (let i = 0; i < bytes.length; i++) {\r\n bytes[i] = parseInt(hexString.substr(i * 2, 2), 16);\r\n }\r\n return bytes;\r\n}\r\n\r\n/**\r\n * Converts a number to little-endian hex string\r\n * @param number - The number to convert\r\n * @param byteCount - Number of bytes (e.g., 5 for bytes5, 4 for bytes4)\r\n */\r\nexport function toLittleEndianHexString(number: bigint | number, byteCount: number): string {\r\n const num = typeof number === 'bigint' ? number : BigInt(number);\r\n let hex = num.toString(16);\r\n hex = hex.padStart(byteCount * 2, '0'); // Pad with zeros to ensure correct byteCount\r\n // Split into chunks of 2 (bytes), reverse (for little endian), and join back\r\n return hex.match(/../g)?.reverse().join('') ?? '';\r\n}\r\n\r\n","// TokenSales_old1 contract addresses\r\n//export const AddressTicketMaster = 'bitcoincash:pvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryszkdd99zq'; //address hash: 2ef2757e6a8659a54a3a43384764091ac82c05e8d2b5941fdefb551b20564648\r\n//export const AddressTicketMasterToken = 'bitcoincash:rvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryss93vuymt';\r\n\r\n// TokenSales_old2 contract addresses | simplified change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2m4afvzlt'; //address hash: 76bebd71fef3c48ef2fec86b1a24ceaa7fb06f3e1aed923ac8176955c20f5085\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2fxpg4rxq';\r\n\r\n// TokenSales_old3 contract addresses | fixed change fee calculation in purchaseNFT()\r\n//export const AddressTicketMaster = 'bitcoincash:pdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vz3syd0y9'; //address hash: 7ff1e58e69a1346149d6000befea51cf43bf0aefcff02c15c20a477024002f46\r\n//export const AddressTicketMasterToken = 'bitcoincash:rdllrevwdxsngc2f6cqqhml2288580c2al8lqtq4cg9ywupyqqh5vszv95waw';\r\n\r\n// TokenSales contract addresses | restricted burnTokenSale() so user-provided utxo must be input0\r\nexport const AddressTicketMaster = 'bitcoincash:pwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnwzutlweuk'; //address hash: b6ef29da52497a243a73a70115dede6e38653148ccdbaafa24f7f662b8bc5b37\r\nexport const AddressTicketMasterToken = 'bitcoincash:rwmw72w62fyh5fp6wwnsz9w7mehrsef3frxdh2h6ynmlvc4ch3dnws0h7hc9a';\r\n\r\n// Ticket Level Descriptions\r\nexport const TICKET_LEVEL_DESCRIPTIONS = {\r\n '01': {\r\n name: 'Regular',\r\n description: 'Regular tickets provide standard access to the event. This is the base level ticket option.'\r\n },\r\n '02': {\r\n name: 'VIP',\r\n description: 'VIP tickets offer enhanced benefits including priority access, exclusive areas, and additional perks.'\r\n },\r\n '03': {\r\n name: 'Premium',\r\n description: 'Premium tickets provide the highest level of access with all VIP benefits plus additional exclusive features.'\r\n }\r\n};\r\n\r\n","/**\r\n * TokenSales contract addresses\r\n * These are the addresses for the TokenSales (TicketMaster) contract\r\n */\r\nimport { AddressTicketMaster, AddressTicketMasterToken } from './constants/values';\r\n\r\nexport const DEFAULT_CONTRACT_ADDRESSES = {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n} as const;\r\n\r\n/**\r\n * Get contract address\r\n * @returns Contract address\r\n */\r\nexport function getContractAddress(): string {\r\n return AddressTicketMaster;\r\n}\r\n\r\n/**\r\n * Get token address\r\n * @returns Token address\r\n */\r\nexport function getTokenAddress(): string {\r\n return AddressTicketMasterToken;\r\n}\r\n\r\n/**\r\n * Get contract addresses\r\n * @returns Object with contract and token addresses\r\n */\r\nexport function getContractAddresses() {\r\n return {\r\n contract: AddressTicketMaster,\r\n token: AddressTicketMasterToken\r\n };\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction, encodeCashAddress } from '@bitauth/libauth';\r\nimport { BuyNFTParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, hexToUint8Array, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Purchase a ticket NFT from a TicketMaster\r\n * @param params - BuyNFTParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function buyNFT(params: BuyNFTParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n ticketUtxo,\r\n ticketType,\r\n isAdmin\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === ticketUtxo.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n \r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = ticketUtxo.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('ticketUtxo must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Parse TicketMaster commitment to get price and admin address\r\n const commitment = ticketMasterUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TicketMaster commitment');\r\n }\r\n\r\n // Extract price based on ticket type (little-endian format)\r\n let ticketPrice: bigint;\r\n let priceHex: string;\r\n \r\n if (ticketType === '01') {\r\n priceHex = commitment.substring(0, 10);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n } else if (ticketType === '02') {\r\n priceHex = commitment.substring(10, 20);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 2 is not available');\r\n }\r\n } else if (ticketType === '03') {\r\n priceHex = commitment.substring(20, 30);\r\n const priceBE = priceHex.match(/.{2}/g)?.reverse().join('') || priceHex;\r\n ticketPrice = BigInt('0x' + priceBE);\r\n if (ticketPrice === 0n) {\r\n throw new Error('Ticket type 3 is not available');\r\n }\r\n } else {\r\n throw new Error('Invalid ticket type');\r\n }\r\n\r\n // Extract admin pubkey hash (bytes20 = 40 hex chars, positions 38-78)\r\n const adminPubKeyHashHex = commitment.substring(38, 78);\r\n \r\n // Convert hex string to Uint8Array\r\n const adminPKHUint8Array = hexToUint8Array(adminPubKeyHashHex);\r\n \r\n // Derive admin address from embedded pubkey hash\r\n const prefix = 'bitcoincash';\r\n const addressType = 'p2pkh';\r\n const adminAddressResult = encodeCashAddress({\r\n prefix,\r\n type: addressType,\r\n payload: adminPKHUint8Array\r\n });\r\n \r\n if (typeof adminAddressResult === 'string') {\r\n throw new Error(`Failed to encode admin address: ${adminAddressResult}`);\r\n }\r\n const adminAddress = adminAddressResult.address;\r\n \r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n \r\n // Convert address to locking bytecode\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Get userUTXO\r\n let userUTXO: Utxo | undefined;\r\n if (isAdmin) {\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.token?.category === ticketMasterUtxo.token?.category && \r\n utxo.token?.nft?.capability === 'minting'\r\n );\r\n } else {\r\n // Find pure BCH payment UTXO (need ticketPrice & 3000+ sats for miner fee)\r\n userUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (ticketPrice + 3000n) && !utxo.token,\r\n );\r\n\r\n if (!userUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n // If totalSats is enough, then user needs to consolidate\r\n if (totalSats >= ticketPrice + 3000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${ticketPrice + 3000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n }\r\n\r\n if (!userUTXO) {\r\n throw new Error('No suitable UTXO found for transaction');\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(ticketUtxo, ticketMasterContract.unlock.purchaseNFT(ticketType))\r\n .addInput(userUTXO, p2pkhUnlocker)\r\n // Ticket master NFT being sent back to contract\r\n .addOutput({\r\n to: ticketMasterContract.tokenAddress, \r\n amount: ticketMasterUtxo.satoshis,\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount!, \r\n category: ticketMasterUtxo.token?.category!, \r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!, \r\n commitment: ticketMasterUtxo.token?.nft?.commitment! \r\n }\r\n },\r\n })\r\n // Ticket being purchased\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: ticketUtxo.satoshis,\r\n token: {\r\n amount: ticketUtxo.token?.amount!, \r\n category: ticketUtxo.token?.category!, \r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!, \r\n commitment: ticketUtxo.token?.nft?.commitment! + ticketType // ticketType appended to commitment\r\n }\r\n },\r\n })\r\n // Ticket price is sent to admin address\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: 1000n,\r\n });\r\n } else {\r\n transaction.addOutput({\r\n to: adminAddress, \r\n amount: ticketPrice,\r\n });\r\n }\r\n\r\n if (isAdmin) {\r\n transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userUTXO.satoshis - 2700n,\r\n token: {\r\n amount: userUTXO.token?.amount!, \r\n category: userUTXO.token?.category!, \r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!, \r\n commitment: userUTXO.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } else {\r\n // Calculate change amount (userUTXO - ticketPrice - miner fee)\r\n const changeAmount = userUTXO.satoshis - ticketPrice - 2700n;\r\n if (changeAmount > 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress, \r\n amount: changeAmount\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n console.log('Transaction built:', transaction);\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 2)\r\n decodedTransaction.inputs[2].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binTicketCommitment = hexToBin(ticketUtxo.token?.nft?.commitment!);\r\n const binUserCommitment = isAdmin ? hexToBin(userUTXO.token?.nft?.commitment!) : undefined;\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n // Use raw Uint8Arrays and BigInts - stringify from @bitauth/libauth will handle serialization\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketUtxo.token?.nft?.capability!,\r\n commitment: binTicketCommitment\r\n }\r\n }\r\n },\r\n ...(isAdmin ? [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n token: {\r\n amount: userUTXO.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userUTXO.token?.nft?.capability!,\r\n commitment: binUserCommitment!\r\n }\r\n }\r\n }] : [{\r\n ...decodedTransaction.inputs[2],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userUTXO.satoshis),\r\n }])\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Purchase Ticket Type ${ticketType} for ${ticketPrice} sats`\r\n };\r\n\r\n console.log('WalletConnect transaction object:', wcTransactionObj);\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { ModifyTokenSaleParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Modify TokenSale parameters (prices, endSale)\r\n * @param params - ModifyTokenSaleParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function modifyTokenSale(params: ModifyTokenSaleParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n tokenSaleUtxo,\r\n userMintingUtxo,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const tokenSaleContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Parse TokenSale commitment to validate\r\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\r\n if (commitment.length !== 78) {\r\n throw new Error('Invalid TokenSale commitment');\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = tokenSaleContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n \r\n const priceType1Hex = toLittleEndianHexString(BigInt(priceType1), 5);\r\n const priceType2Hex = toLittleEndianHexString(BigInt(priceType2), 5);\r\n const priceType3Hex = toLittleEndianHexString(BigInt(priceType3), 5);\r\n const endSaleHex = toLittleEndianHexString(BigInt(endSale), 4);\r\n const adminPkh = tokenSaleUtxo.token?.nft?.commitment!.substring(38, 78);\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(tokenSaleUtxo, tokenSaleContract.unlock.modifyTokenSale(priceType1Hex, priceType2Hex, priceType3Hex, endSaleHex))\r\n .addInput(userMintingUtxo, p2pkhUnlocker)\r\n // TokenSale NFT being sent back to contract with new commitment\r\n .addOutput({\r\n to: tokenSaleContract.tokenAddress, \r\n amount: tokenSaleUtxo.satoshis,\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount!, \r\n category: tokenSaleUtxo.token?.category!, \r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!, \r\n commitment: priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkh\r\n }\r\n },\r\n })\r\n // Admin NFT being sent back to user\r\n .addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingUtxo.satoshis - 1000n,\r\n token: {\r\n amount: userMintingUtxo.token?.amount!, \r\n category: userMintingUtxo.token?.category!, \r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!, \r\n commitment: userMintingUtxo.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 1)\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(tokenSaleUtxo.token?.category!);\r\n const binTokenSaleCommitment = hexToBin(tokenSaleUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingUtxo.token?.nft?.commitment!);\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((tokenSaleContract.redeemScript as any).bytecode) {\r\n return (tokenSaleContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof tokenSaleContract.redeemScript === 'string') {\r\n return hexToBin(tokenSaleContract.redeemScript);\r\n }\r\n return new Uint8Array(tokenSaleContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(tokenSaleUtxo.satoshis),\r\n contract: {\r\n abiFunction: tokenSaleContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: tokenSaleContract.artifact,\r\n },\r\n token: {\r\n amount: tokenSaleUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: tokenSaleUtxo.token?.nft?.capability!,\r\n commitment: binTokenSaleCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingUtxo.satoshis),\r\n token: {\r\n amount: userMintingUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingUtxo.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Modify TokenSale NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { BurnParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\nimport { getTokenAddress } from '../config';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\n\r\n/**\r\n * Burn a TicketMaster NFT and all associated tickets\r\n * @param params - BurnParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function burn(params: BurnParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n ticketMasterUtxo: providedTicketMasterUtxo,\r\n userMintingNFT,\r\n tickets\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract\r\n let ticketMasterUtxo: Utxo;\r\n if (providedTicketMasterUtxo?.token?.category === userMintingNFT.token?.category\r\n && providedTicketMasterUtxo?.token?.nft?.capability === 'minting'\r\n ) {\r\n ticketMasterUtxo = providedTicketMasterUtxo;\r\n } else {\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n \r\n // Filter to find the TicketMaster UTXO with matching category ID\r\n const matchingCategoryId = userMintingNFT.token?.category;\r\n if (!matchingCategoryId) {\r\n throw new Error('userMintingNFT must have a token category');\r\n }\r\n \r\n ticketMasterUtxo = contractUtxos.find(\r\n utxo => utxo.token?.category === matchingCategoryId &&\r\n utxo.token?.nft?.capability === 'minting'\r\n ) as Utxo;\r\n \r\n if (!ticketMasterUtxo) {\r\n throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);\r\n }\r\n }\r\n\r\n // Get contract address from compiled contract\r\n const contractAddr = ticketMasterContract.address;\r\n\r\n // Creating lockingBytecode for contract address\r\n const contractLockingBytecodeResult = cashAddressToLockingBytecode(contractAddr);\r\n if (typeof contractLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract address to locking bytecode: ${contractLockingBytecodeResult}`);\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n // Start building transaction\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add TicketMaster to be burned\r\n .addInput(ticketMasterUtxo, ticketMasterContract.unlock.burnTokenSale());\r\n\r\n // Add all tickets to be burned\r\n for (const ticket of tickets) {\r\n transaction = transaction.addInput(ticket, ticketMasterContract.unlock.burnTokenSale());\r\n }\r\n\r\n // Send admin NFT back to user\r\n transaction = transaction.addOutput({\r\n to: userTokenAddress, \r\n amount: userMintingNFT.satoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!, \r\n category: userMintingNFT.token?.category!, \r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!, \r\n commitment: userMintingNFT.token?.nft?.commitment! \r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (input 0)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(ticketMasterUtxo.token?.category!);\r\n const binTicketMasterCommitment = hexToBin(ticketMasterUtxo.token?.nft?.commitment!);\r\n const binUserMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n // For each ticket, convert hex to Uint8Array\r\n const binTicketCommitments = tickets.map((ticket) => hexToBin(ticket.token?.nft?.commitment!));\r\n\r\n // Get redeemScript as Uint8Array\r\n const getRedeemScript = (): Uint8Array => {\r\n if ((ticketMasterContract.redeemScript as any).bytecode) {\r\n return (ticketMasterContract.redeemScript as any).bytecode;\r\n }\r\n if (typeof ticketMasterContract.redeemScript === 'string') {\r\n return hexToBin(ticketMasterContract.redeemScript);\r\n }\r\n return new Uint8Array(ticketMasterContract.redeemScript as any);\r\n };\r\n\r\n const redeemScript = getRedeemScript();\r\n\r\n // Construct source outputs for WalletConnect\r\n let listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticketMasterUtxo.satoshis),\r\n contract: {\r\n abiFunction: ticketMasterContract.artifact.abi,\r\n redeemScript: redeemScript,\r\n artifact: ticketMasterContract.artifact,\r\n },\r\n token: {\r\n amount: ticketMasterUtxo.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticketMasterUtxo.token?.nft?.capability!,\r\n commitment: binTicketMasterCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Add all tickets to the list of source outputs\r\n for (let i = 0; i < tickets.length; i++) {\r\n const ticket = tickets[i];\r\n listSourceOutputs.push({\r\n ...decodedTransaction.inputs[i + 2],\r\n lockingBytecode: contractLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(ticket.satoshis),\r\n token: {\r\n amount: ticket.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: ticket.token?.nft?.capability!,\r\n commitment: binTicketCommitments[i]\r\n }\r\n }\r\n });\r\n }\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: true,\r\n userPrompt: `Burn TicketMaster and ${tickets.length} tickets`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Utxo, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { AddSatoshisParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toTokenAddress } from '../utils';\r\n\r\n/**\r\n * Add satoshis to a minting NFT\r\n * @param params - AddSatoshisParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function addSatoshis(params: AddSatoshisParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n additionalSatoshis\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n if (additionalSatoshis <= 0n) {\r\n throw new Error('Additional satoshis must be greater than 0');\r\n }\r\n\r\n // Creating lockingBytecode for usersAddress\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get user UTXOs to find a BCH UTXO to fund the additional satoshis\r\n const userUtxos = await electrumProvider.getUtxos(normalizedUserAddress);\r\n\r\n // Find a BCH UTXO with enough satoshis (additionalSatoshis + miner fee ~1000 sats)\r\n const fundingUTXO = userUtxos.find(\r\n utxo => utxo.satoshis >= (additionalSatoshis + 1000n) && !utxo.token\r\n );\r\n\r\n if (!fundingUTXO) {\r\n // Count up all the sats in userUTXOs that do not have a token\r\n const totalSats = userUtxos.reduce((sum: bigint, utxo: Utxo) => {\r\n if (!utxo.token) {\r\n return sum + utxo.satoshis;\r\n }\r\n return sum;\r\n }, 0n);\r\n\r\n if (totalSats >= additionalSatoshis + 1000n) {\r\n throw new Error('No compatible UTXO found in wallet, consolidate?');\r\n } else {\r\n throw new Error(`Not enough BCH in your wallet. Required: ${additionalSatoshis + 1000n} sats, Available: ${totalSats} sats`);\r\n }\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Add the minting NFT as input\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Add the funding UTXO to provide additional satoshis\r\n .addInput(fundingUTXO, p2pkhUnlocker)\r\n // Output: minting NFT with additional satoshis\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis + additionalSatoshis,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n });\r\n\r\n // Calculate change (fundingUTXO - additionalSatoshis - miner fee)\r\n const changeAmount = fundingUTXO.satoshis - additionalSatoshis - 1000n;\r\n if (changeAmount >= 1000n) { // Dust limit\r\n transaction.addOutput({\r\n to: normalizedUserAddress,\r\n amount: changeAmount,\r\n });\r\n }\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user inputs (wallet will sign these)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n decodedTransaction.inputs[1].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binMintingCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Get locking bytecode for user address\r\n const userLockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof userLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${userLockingBytecodeResult}`);\r\n }\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binMintingCommitment\r\n }\r\n }\r\n },\r\n {\r\n ...decodedTransaction.inputs[1],\r\n lockingBytecode: userLockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(fundingUTXO.satoshis)\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Add ${additionalSatoshis} satoshis to minting NFT`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { TransactionBuilder, Contract, Unlocker } from 'cashscript';\r\nimport { hexToBin, cashAddressToLockingBytecode, decodeTransaction } from '@bitauth/libauth';\r\nimport { CreateListingParams, WalletConnectTransactionObject } from '../types';\r\nimport { ensureAddressPrefix, toLittleEndianHexString, toTokenAddress } from '../utils';\r\nimport contractArtifact from '../artifacts/TokenSales.json';\r\nimport { AddressTicketMasterToken } from '../constants/values';\r\n\r\n/**\r\n * Create a new TicketMaster listing\r\n * @param params - CreateListingParams object containing all required parameters\r\n * @returns Promise resolving to WalletConnectTransactionObject ready for signing\r\n * @throws Error if validation fails or transaction building fails\r\n */\r\nexport async function createListing(params: CreateListingParams): Promise<WalletConnectTransactionObject> {\r\n const {\r\n electrumProvider,\r\n usersAddress,\r\n userMintingNFT,\r\n priceType1,\r\n priceType2,\r\n priceType3,\r\n endSale,\r\n adminPubKeyHash\r\n } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Compile the contract using the included artifact\r\n const ticketMasterContract = new Contract(contractArtifact as any, [], {\r\n provider: electrumProvider,\r\n addressType: 'p2sh32'\r\n });\r\n\r\n // Validate adminPubKeyHash\r\n const adminPkhHex = adminPubKeyHash.replace(/^0x/i, '').trim();\r\n if (adminPkhHex.length !== 40 || !/^[0-9a-fA-F]+$/.test(adminPkhHex)) {\r\n throw new Error('Admin PubKey Hash must be 40 hex characters (20 bytes)');\r\n }\r\n\r\n // Normalize user address\r\n const normalizedUserAddress = ensureAddressPrefix(usersAddress);\r\n const userTokenAddress = toTokenAddress(normalizedUserAddress);\r\n const lockingBytecodeResult = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof lockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert user address to locking bytecode: ${lockingBytecodeResult}`);\r\n }\r\n\r\n // Get token address from compiled contract\r\n const contractTokenAddr = ticketMasterContract.tokenAddress;\r\nconsole.log('contractTokenAddr', contractTokenAddr);\r\nconsole.log('AddressTicketMasterToken', AddressTicketMasterToken);\r\n // Get locking bytecode for contract token address\r\n const contractTokenLockingBytecodeResult = cashAddressToLockingBytecode(contractTokenAddr);\r\n if (typeof contractTokenLockingBytecodeResult === 'string') {\r\n throw new Error(`Failed to convert contract token address to locking bytecode: ${contractTokenLockingBytecodeResult}`);\r\n }\r\n\r\n // Build TicketMaster commitment\r\n // Format: bytes5 priceType1 + bytes5 priceType2 + bytes5 priceType3 + bytes4 endSale + bytes20 adminPubKeyHash\r\n // Total: 39 bytes = 78 hex chars\r\n const priceType1Hex = toLittleEndianHexString(priceType1, 5); // 10 hex chars\r\n const priceType2Hex = toLittleEndianHexString(priceType2, 5); // 10 hex chars\r\n const priceType3Hex = toLittleEndianHexString(priceType3, 5); // 10 hex chars\r\n const endSaleHex = toLittleEndianHexString(endSale, 4); // 8 hex chars\r\n const ticketMasterCommitment = priceType1Hex + priceType2Hex + priceType3Hex + endSaleHex + adminPkhHex;\r\n \r\n if (ticketMasterCommitment.length !== 78) {\r\n throw new Error(`Invalid commitment length: ${ticketMasterCommitment.length}, expected 78`);\r\n }\r\n\r\n // Build Transaction\r\n const p2pkhUnlocker: Unlocker = {\r\n generateLockingBytecode: () => {\r\n const result = cashAddressToLockingBytecode(normalizedUserAddress);\r\n if (typeof result === 'string') {\r\n throw new Error(`Failed to convert CashAddress to locking bytecode: ${result}`);\r\n }\r\n return result.bytecode;\r\n },\r\n generateUnlockingBytecode: () => {\r\n return Uint8Array.from([]);\r\n }\r\n };\r\n\r\n let transaction: any;\r\n try {\r\n transaction = await new TransactionBuilder({ provider: electrumProvider })\r\n // Input: user's minting NFT\r\n .addInput(userMintingNFT, p2pkhUnlocker)\r\n // Output 0: user's minting NFT back to user\r\n .addOutput({\r\n to: userTokenAddress,\r\n amount: userMintingNFT.satoshis - 2000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: userMintingNFT.token?.nft?.commitment!\r\n }\r\n },\r\n })\r\n // Output 1: TicketMaster Minting NFT to contract token address\r\n .addOutput({\r\n to: contractTokenAddr,\r\n amount: 1000n,\r\n token: {\r\n amount: userMintingNFT.token?.amount!,\r\n category: userMintingNFT.token?.category!,\r\n nft: {\r\n capability: 'minting',\r\n commitment: ticketMasterCommitment\r\n }\r\n },\r\n });\r\n } catch (error) {\r\n if (error instanceof Error) {\r\n throw new Error(`Error building transaction: ${error.message}`);\r\n } else {\r\n throw new Error(`Error building transaction: ${String(error)}`);\r\n }\r\n }\r\n\r\n // Build the transaction\r\n const rawTransactionHex = await transaction.build();\r\n\r\n // Decode transaction for WalletConnect\r\n const decodedTransaction = decodeTransaction(hexToBin(rawTransactionHex));\r\n if (typeof decodedTransaction === \"string\") {\r\n throw new Error(\"Failed to decode transaction\");\r\n }\r\n\r\n // Clear unlocking bytecode for user input (wallet will sign this)\r\n decodedTransaction.inputs[0].unlockingBytecode = Uint8Array.from([]);\r\n\r\n // Convert hex strings to Uint8Array for token data\r\n const binTokenCategory = hexToBin(userMintingNFT.token?.category!);\r\n const binUserCommitment = hexToBin(userMintingNFT.token?.nft?.commitment!);\r\n\r\n // Construct source outputs for WalletConnect\r\n const listSourceOutputs = [\r\n {\r\n ...decodedTransaction.inputs[0],\r\n lockingBytecode: lockingBytecodeResult.bytecode,\r\n valueSatoshis: BigInt(userMintingNFT.satoshis),\r\n token: {\r\n amount: userMintingNFT.token?.amount,\r\n category: binTokenCategory,\r\n nft: {\r\n capability: userMintingNFT.token?.nft?.capability!,\r\n commitment: binUserCommitment\r\n }\r\n }\r\n }\r\n ];\r\n\r\n // Create transaction object for WalletConnect signing\r\n const wcTransactionObj: WalletConnectTransactionObject = {\r\n transaction: decodedTransaction,\r\n sourceOutputs: listSourceOutputs,\r\n broadcast: false,\r\n userPrompt: `Create TicketMaster listing`\r\n };\r\n\r\n return wcTransactionObj;\r\n}\r\n\r\n","import { Utxo } from 'cashscript';\nimport { ListAvailableTicketsParams } from '../types';\nimport { getTokenAddress } from '../config';\nimport { parseTicketMasterCommitment, isTicketMaster, isTicket } from '../utils/ticketMaster';\n\n/**\n * List available tickets for purchase from a TokenSale\n * @param params - ListAvailableTicketsParams object containing all required parameters\n * @returns Promise resolving to array of ticket UTXOs that are available for purchase\n * @throws Error if validation fails or TokenSale is not found/active\n */\nexport async function listAvailableTickets(params: ListAvailableTicketsParams): Promise<Utxo[]> {\n const {\n electrumProvider,\n categoryID\n } = params;\n\n if (!electrumProvider) {\n throw new Error('Electrum provider not available');\n }\n\n if (!categoryID || categoryID.length === 0) {\n throw new Error('Category ID is required');\n }\n\n // Get the contract token address\n const contractTokenAddress = getTokenAddress();\n\n // Get all UTXOs from the contract token address\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\n\n // Filter UTXOs to only those matching the categoryID\n const categoryUtxos = contractUtxos.filter((utxo: Utxo) => \n utxo?.token?.category === categoryID\n );\n\n if (categoryUtxos.length === 0) {\n return []; // No UTXOs found for this category\n }\n\n // Find the TokenSale minting NFT (capability === 'minting')\n const tokenSaleUtxo = categoryUtxos.find((utxo: Utxo) => \n isTicketMaster(utxo)\n );\n\n if (!tokenSaleUtxo) {\n throw new Error(`No active TokenSale found for category ${categoryID}`);\n }\n\n // Parse the TokenSale commitment to get endSale block height\n const commitment = tokenSaleUtxo.token?.nft?.commitment || '';\n const tokenSaleData = parseTicketMasterCommitment(commitment);\n\n if (!tokenSaleData) {\n throw new Error('Failed to parse TokenSale commitment');\n }\n\n // Filter to only ticket UTXOs (capability === 'none')\n const availableTickets = categoryUtxos.filter((utxo: Utxo) => \n isTicket(utxo, categoryID)\n );\n\n return availableTickets;\n}\n","import { ListAllSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List all TokenSale NFTs (minting capability & 39-byte commitment)\r\n * @param params - ListAllSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listAllSales(params: ListAllSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only TokenSale NFTs (minting capability with 39-byte commitment)\r\n const tokenSaleUtxos: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n tokenSaleUtxos.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n\r\n return tokenSaleUtxos;\r\n}\r\n","import { ListActiveSalesParams, TokenSaleUtxo } from '../types';\r\nimport { getTokenAddress } from '../config';\r\nimport { isTicketMaster, parseTicketMasterCommitment } from '../utils/ticketMaster';\r\n\r\n/**\r\n * List active TokenSale NFTs (minting capability, 39-byte commitment, sale not ended)\r\n * A sale is active when current blockheight > endSale commitment field\r\n * @param params - ListActiveSalesParams object containing the electrum provider\r\n * @returns Promise resolving to array of active TokenSale UTXOs with parsed commitment data\r\n */\r\nexport async function listActiveSales(params: ListActiveSalesParams): Promise<TokenSaleUtxo[]> {\r\n const { electrumProvider } = params;\r\n\r\n if (!electrumProvider) {\r\n throw new Error('Electrum provider not available');\r\n }\r\n\r\n // Get current block height\r\n let currentBlockHeight: number;\r\n if (typeof (electrumProvider as any).getBlockHeight === 'function') {\r\n currentBlockHeight = await (electrumProvider as any).getBlockHeight();\r\n } else if (typeof (electrumProvider as any).performRequest === 'function') {\r\n try {\r\n const header = await (electrumProvider as any).performRequest('blockchain.headers.subscribe');\r\n currentBlockHeight = header?.height || header;\r\n } catch (e) {\r\n // Fallback: try to get block height from getUtxos call\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n } else {\r\n throw new Error('Unable to get block height from provider');\r\n }\r\n\r\n // Get the contract token address\r\n const contractTokenAddress = getTokenAddress();\r\n\r\n // Get all UTXOs from the contract token address\r\n const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);\r\n\r\n // Filter to only active TokenSale NFTs (sale not ended)\r\n const activeSales: TokenSaleUtxo[] = [];\r\n\r\n for (const utxo of contractUtxos) {\r\n if (isTicketMaster(utxo)) {\r\n const commitment = utxo.token?.nft?.commitment || '';\r\n const tokenSaleData = parseTicketMasterCommitment(commitment);\r\n\r\n if (tokenSaleData) {\r\n // Sale is active when current blockheight > endSale\r\n if (currentBlockHeight < tokenSaleData.endSale) {\r\n activeSales.push({\r\n ...utxo,\r\n tokenSaleData\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n return activeSales;\r\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