@@ -157,4 +157,69 @@ describe('NEAR Token Enablement Validation', function () {
157157 // and prevent the user from being tricked into enabling tokens for the wrong address
158158 await basecoin . verifyTransaction ( verifyOptions ) . should . be . rejectedWith ( 'Address mismatch: wrong.address.near' ) ;
159159 } ) ;
160+
161+ /**
162+ * TEST 4: Security Test - Spoofed TxHex Detection
163+ *
164+ * This test simulates what happens when the wallet platform tries to send a token enablement
165+ * transaction but receives a spoofed TxHex from a malicious actor. This test verifies that
166+ * our validation catches the spoofed transaction and prevents the user from being tricked.
167+ */
168+ it ( 'should reject spoofed TxHex in token enablement transaction' , async function ( ) {
169+ // Create valid transaction parameters for token enablement
170+ const txParams = createValidTxParams ( ) ;
171+
172+ // Create a SPOOFED transaction hex that looks like a valid NEAR transaction
173+ // but contains malicious data (e.g., different recipient, wrong token contract, etc.)
174+ const spoofedTxHex = testData . rawTx . fungibleTokenTransfer . unsigned ; // Using transfer instead of storage deposit
175+
176+ const txPrebuild = createTxPrebuild ( spoofedTxHex ) ;
177+
178+ const verifyOptions : VerifyTransactionOptions = {
179+ txParams, // User thinks they're enabling a token
180+ txPrebuild, // But the hex is for a different transaction type (fungible token transfer)
181+ wallet : { id : 'test-wallet' } as any ,
182+ } ;
183+
184+ // This SHOULD throw an error because the spoofed hex doesn't match the expected
185+ // token enablement transaction. The validation will detect that this is not a
186+ // proper storage deposit transaction for token enablement.
187+ // The storage deposit amount validation catches this first
188+ await basecoin . verifyTransaction ( verifyOptions ) . should . be . rejectedWith ( 'Storage deposit amount not matching!' ) ;
189+ } ) ;
190+
191+ /**
192+ * TEST 5: Wallet Platform Integration Test
193+ *
194+ * This test verifies that transactions sent from the wallet platform are properly
195+ * validated and pass through our security checks. This ensures that legitimate
196+ * wallet platform operations work correctly.
197+ */
198+ it ( 'should validate token enablement transaction from wallet platform' , async function ( ) {
199+ // Simulate a transaction that would be sent from the wallet platform
200+ // This uses the same valid storage deposit transaction but with wallet platform context
201+ const txParams = {
202+ type : 'enabletoken' as const ,
203+ recipients : [
204+ {
205+ address : testData . accounts . account1 . address , // Wallet platform controlled address
206+ amount : '0' ,
207+ tokenName : 'tnear:tnep24dp' ,
208+ } ,
209+ ] ,
210+ } ;
211+
212+ // Use the legitimate storage deposit transaction hex from wallet platform
213+ const txPrebuild = createTxPrebuild ( testData . rawTx . selfStorageDeposit . unsigned ) ;
214+
215+ const verifyOptions : VerifyTransactionOptions = {
216+ txParams, // Wallet platform transaction parameters
217+ txPrebuild, // Legitimate transaction hex from wallet platform
218+ wallet : { id : 'wallet-platform-wallet' } as any , // Wallet platform wallet
219+ } ;
220+
221+ // This should NOT throw an error - legitimate wallet platform transactions
222+ // should pass validation and be processed successfully
223+ await basecoin . verifyTransaction ( verifyOptions ) ;
224+ } ) ;
160225} ) ;
0 commit comments