@ledgerhq/device-signer-kit-solana 0.0.0-rn-ble-pairing-removed-while-reconnecting-20250807094338 → 0.0.0-web-ble-29-08---20250829104351

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.
@@ -1,4 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var I=(c,e)=>{for(var s in e)d(c,s,{get:e[s],enumerable:!0})},f=(c,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of T(e))!A.call(c,a)&&a!==s&&d(c,a,{get:()=>e[a],enumerable:!(n=m(e,a))||n.enumerable});return c};var g=c=>f(d({},"__esModule",{value:!0}),c);var b={};I(b,{SolanaTransactionTypes:()=>y,TransactionInspector:()=>k});module.exports=g(b);var r=require("@solana/spl-token"),i=require("@solana/web3.js"),p=require("buffer"),y=(s=>(s.STANDARD="Standard",s.SPL="SPL",s))(y||{});class k{constructor(e){this.rawTransactionBytes=e}inspectTransactionType(){try{const e=this.extractMessage(this.rawTransactionBytes);for(const s of e.compiledInstructions){const n=e.staticAccountKeys[s.programIdIndex];if(!n.equals(r.TOKEN_PROGRAM_ID))continue;const a=new i.TransactionInstruction({programId:n,keys:s.accountKeyIndexes.map(t=>({pubkey:e.staticAccountKeys[t],isSigner:e.isAccountSigner(t),isWritable:e.isAccountWritable(t)})),data:p.Buffer.from(s.data)});switch(a.data[0]){case r.TokenInstruction.Transfer:{const{keys:{destination:t}}=(0,r.decodeTransferInstruction)(a);return{transactionType:"SPL",data:{tokenAddress:t.pubkey.toBase58()}}}case r.TokenInstruction.TransferChecked:{const{keys:{destination:t}}=(0,r.decodeTransferCheckedInstruction)(a);return{transactionType:"SPL",data:{tokenAddress:t.pubkey.toBase58()}}}case r.TokenInstruction.InitializeAccount:{const{keys:{account:t,mint:o}}=(0,r.decodeInitializeAccountInstruction)(a);return{transactionType:"SPL",data:{createATA:{address:t.pubkey.toBase58(),mintAddress:o.pubkey.toBase58()}}}}default:continue}}return{transactionType:"Standard",data:{}}}catch{return{transactionType:"Standard",data:{}}}}extractMessage(e){const s=[];try{return i.VersionedTransaction.deserialize(e).message}catch(n){s.push(n.message)}try{return i.VersionedMessage.deserialize(e)}catch(n){s.push(n.message)}try{const n=i.Transaction.from(e),a=[n.feePayer,...n.instructions.flatMap(t=>t.keys.map(o=>o.pubkey))],u=Array.from(new Map(a.filter(Boolean).map(t=>[t.toBase58(),t])).values());return{compiledInstructions:n.instructions.map(t=>({programIdIndex:u.findIndex(o=>o.equals(t.programId)),accountKeyIndexes:t.keys.map(o=>u.findIndex(l=>l.equals(o.pubkey))),data:t.data})),staticAccountKeys:u,isAccountSigner:t=>n.signatures.some(o=>o.publicKey.equals(u[t])),isAccountWritable:()=>!0}}catch(n){s.push(n.message)}throw new Error(`Invalid transaction payload \u2013 all deserializers failed:
2
- `+s.map((n,a)=>`${a+1}) ${n}`).join(`
3
- `))}}0&&(module.exports={SolanaTransactionTypes,TransactionInspector});
1
+ "use strict";var p=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var K=(i,e)=>{for(var n in e)p(i,n,{get:e[n],enumerable:!0})},k=(i,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of f(e))!g.call(i,c)&&c!==n&&p(i,c,{get:()=>e[c],enumerable:!(o=A(e,c))||o.enumerable});return i};var b=i=>k(p({},"__esModule",{value:!0}),i);var x={};K(x,{SolanaTransactionTypes:()=>T,TransactionInspector:()=>P});module.exports=b(x);var s=require("@solana/spl-token"),u=require("@solana/web3.js"),I=require("buffer"),T=(n=>(n.STANDARD="Standard",n.SPL="SPL",n))(T||{});class P{constructor(e){this.rawTransactionBytes=e}inspectTransactionType(){try{const e=this.normaliseMessage(this.rawTransactionBytes);for(const n of e.compiledInstructions){const o=e.allKeys[n.programIdIndex];if(!o)continue;if(o.equals(s.ASSOCIATED_TOKEN_PROGRAM_ID)){const a=n.accountKeyIndexes.map(r=>e.allKeys[r]).filter(Boolean),y=a[1],t=a[3];if(y&&t)return{transactionType:"SPL",data:{createATA:{address:y.toBase58(),mintAddress:t.toBase58()}}};continue}if(!(o.equals(s.TOKEN_PROGRAM_ID)||o.equals(s.TOKEN_2022_PROGRAM_ID)))continue;const d=new u.TransactionInstruction({programId:o,keys:n.accountKeyIndexes.map(a=>{if(!e.allKeys[a])throw new Error(`TransactionInspector: missing key at index ${a} in allKeys`);return{pubkey:e.allKeys[a],isSigner:!1,isWritable:!1}}),data:I.Buffer.from(n.data)}),m=d.data[0];try{switch(m){case s.TokenInstruction.Transfer:{const{keys:{destination:a}}=(0,s.decodeTransferInstruction)(d);return{transactionType:"SPL",data:{tokenAddress:a.pubkey.toBase58()}}}case s.TokenInstruction.TransferChecked:{const{keys:{destination:a,mint:y}}=(0,s.decodeTransferCheckedInstruction)(d);return{transactionType:"SPL",data:{tokenAddress:a.pubkey.toBase58(),mintAddress:y.pubkey.toBase58()}}}case s.TokenInstruction.InitializeAccount:{const{keys:{account:a,mint:y}}=(0,s.decodeInitializeAccountInstruction)(d);return{transactionType:"SPL",data:{createATA:{address:a.pubkey.toBase58(),mintAddress:y.pubkey.toBase58()}}}}default:break}}catch{continue}}return{transactionType:"Standard",data:{}}}catch{return{transactionType:"Standard",data:{}}}}normaliseMessage(e){const n=this.tryDeserialiseVersioned(e);if(n){const t=n.message;let r;return typeof t.getAccountKeys=="function"?r=t.getAccountKeys().keySegments().flat():r=[...t.staticAccountKeys],{compiledInstructions:t.compiledInstructions.map(l=>({programIdIndex:l.programIdIndex,accountKeyIndexes:Array.from(l.accountKeyIndexes??[]),data:l.data instanceof Uint8Array?l.data:I.Buffer.from(l.data??[])})),allKeys:r}}const o=u.Transaction.from(e),c=new Map,d=t=>{if(!t)return;const r=t.toBase58();c.has(r)||c.set(r,t)};d(o.feePayer??null);for(const t of o.instructions){d(t.programId);for(const r of t.keys)d(r.pubkey)}const m=Array.from(c.values()),a=new Map(m.map((t,r)=>[t.toBase58(),r]));return{compiledInstructions:o.instructions.map(t=>({programIdIndex:a.get(t.programId.toBase58())??-1,accountKeyIndexes:t.keys.map(r=>a.get(r.pubkey.toBase58())??-1),data:t.data})),allKeys:m}}tryDeserialiseVersioned(e){try{return u.VersionedTransaction.deserialize(e)}catch{try{return{message:u.VersionedMessage.deserialize(e)}}catch{return null}}}}0&&(module.exports={SolanaTransactionTypes,TransactionInspector});
4
2
  //# sourceMappingURL=TransactionInspector.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/services/TransactionInspector.ts"],
4
- "sourcesContent": ["import {\n decodeInitializeAccountInstruction,\n decodeTransferCheckedInstruction,\n decodeTransferInstruction,\n TOKEN_PROGRAM_ID,\n TokenInstruction,\n} from \"@solana/spl-token\";\nimport {\n type PublicKey,\n Transaction,\n TransactionInstruction,\n VersionedMessage,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\nexport enum SolanaTransactionTypes {\n STANDARD = \"Standard\",\n SPL = \"SPL\",\n}\nexport interface TxInspectorResult {\n transactionType: SolanaTransactionTypes;\n data: {\n tokenAddress?: string;\n createATA?: {\n address: string;\n mintAddress: string;\n };\n };\n}\n\nexport class TransactionInspector {\n constructor(private readonly rawTransactionBytes: Uint8Array) {}\n\n public inspectTransactionType(): TxInspectorResult {\n try {\n const message = this.extractMessage(this.rawTransactionBytes);\n\n for (const ixMeta of message.compiledInstructions) {\n const programId = message.staticAccountKeys[ixMeta.programIdIndex]!;\n if (!programId.equals(TOKEN_PROGRAM_ID)) continue;\n\n const instruction = new TransactionInstruction({\n programId,\n keys: ixMeta.accountKeyIndexes.map((i) => ({\n pubkey: message.staticAccountKeys[i]!,\n isSigner: message.isAccountSigner(i),\n isWritable: message.isAccountWritable(i),\n })),\n data: Buffer.from(ixMeta.data),\n });\n\n const instructionType = instruction.data[0];\n switch (instructionType) {\n case TokenInstruction.Transfer: {\n const {\n keys: { destination },\n } = decodeTransferInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: { tokenAddress: destination.pubkey.toBase58() },\n };\n }\n case TokenInstruction.TransferChecked: {\n const {\n keys: { destination },\n } = decodeTransferCheckedInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: { tokenAddress: destination.pubkey.toBase58() },\n };\n }\n case TokenInstruction.InitializeAccount: {\n const {\n keys: { account, mint },\n } = decodeInitializeAccountInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n createATA: {\n address: account.pubkey.toBase58(),\n mintAddress: mint.pubkey.toBase58(),\n },\n },\n };\n }\n default:\n continue;\n }\n }\n\n return {\n transactionType: SolanaTransactionTypes.STANDARD,\n data: {},\n };\n } catch {\n return {\n transactionType: SolanaTransactionTypes.STANDARD,\n data: {},\n };\n }\n }\n\n private extractMessage(rawBytes: Uint8Array): VersionedMessage {\n const errors: string[] = [];\n try {\n return VersionedTransaction.deserialize(rawBytes).message;\n } catch (e) {\n errors.push((e as Error).message);\n }\n\n try {\n return VersionedMessage.deserialize(rawBytes);\n } catch (e) {\n errors.push((e as Error).message);\n }\n\n try {\n const tx = Transaction.from(rawBytes);\n const allKeys = [\n tx.feePayer,\n ...tx.instructions.flatMap((ix) => ix.keys.map((k) => k.pubkey)),\n ];\n\n const staticAccountKeys = Array.from(\n new Map(\n (allKeys.filter(Boolean) as PublicKey[]).map((pk) => [\n pk.toBase58(),\n pk,\n ]),\n ).values(),\n );\n\n interface CustomCompiledInstruction {\n programIdIndex: number;\n accountKeyIndexes: number[];\n data: Uint8Array;\n }\n\n return {\n compiledInstructions: tx.instructions.map(\n (ix): CustomCompiledInstruction => ({\n programIdIndex: staticAccountKeys.findIndex((k) =>\n k.equals(ix.programId),\n ),\n accountKeyIndexes: ix.keys.map((k) =>\n staticAccountKeys.findIndex((s) => s.equals(k.pubkey)),\n ),\n data: ix.data,\n }),\n ),\n staticAccountKeys,\n isAccountSigner: (i: number) =>\n tx.signatures.some((sig) =>\n sig.publicKey.equals(staticAccountKeys[i]!),\n ),\n isAccountWritable: () => true,\n } as unknown as VersionedMessage;\n } catch (e) {\n errors.push((e as Error).message);\n }\n\n throw new Error(\n \"Invalid transaction payload \u2013 all deserializers failed:\\n\" +\n errors.map((m, i) => `${i + 1}) ${m}`).join(\"\\n\"),\n );\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAMO,6BACPC,EAMO,2BACPC,EAAuB,kBAEXL,OACVA,EAAA,SAAW,WACXA,EAAA,IAAM,MAFIA,OAAA,IAeL,MAAMC,CAAqB,CAChC,YAA6BK,EAAiC,CAAjC,yBAAAA,CAAkC,CAExD,wBAA4C,CACjD,GAAI,CACF,MAAMC,EAAU,KAAK,eAAe,KAAK,mBAAmB,EAE5D,UAAWC,KAAUD,EAAQ,qBAAsB,CACjD,MAAME,EAAYF,EAAQ,kBAAkBC,EAAO,cAAc,EACjE,GAAI,CAACC,EAAU,OAAO,kBAAgB,EAAG,SAEzC,MAAMC,EAAc,IAAI,yBAAuB,CAC7C,UAAAD,EACA,KAAMD,EAAO,kBAAkB,IAAKG,IAAO,CACzC,OAAQJ,EAAQ,kBAAkBI,CAAC,EACnC,SAAUJ,EAAQ,gBAAgBI,CAAC,EACnC,WAAYJ,EAAQ,kBAAkBI,CAAC,CACzC,EAAE,EACF,KAAM,SAAO,KAAKH,EAAO,IAAI,CAC/B,CAAC,EAGD,OADwBE,EAAY,KAAK,CAAC,EACjB,CACvB,KAAK,mBAAiB,SAAU,CAC9B,KAAM,CACJ,KAAM,CAAE,YAAAE,CAAY,CACtB,KAAI,6BAA0BF,CAAW,EACzC,MAAO,CACL,gBAAiB,MACjB,KAAM,CAAE,aAAcE,EAAY,OAAO,SAAS,CA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EAAE,OAAOD,EAAG,SAAS,CACvB,EACA,kBAAmBA,EAAG,KAAK,IAAKC,GAC9BC,EAAkB,UAAWE,GAAMA,EAAE,OAAOH,EAAE,MAAM,CAAC,CACvD,EACA,KAAMD,EAAG,IACX,EACF,EACA,kBAAAE,EACA,gBAAkBX,GAChBO,EAAG,WAAW,KAAMO,GAClBA,EAAI,UAAU,OAAOH,EAAkBX,CAAC,CAAE,CAC5C,EACF,kBAAmB,IAAM,EAC3B,CACF,OAASM,EAAG,CACVD,EAAO,KAAMC,EAAY,OAAO,CAClC,CAEA,MAAM,IAAI,MACR;AAAA,EACED,EAAO,IAAI,CAACU,EAAGf,IAAM,GAAGA,EAAI,CAAC,KAAKe,CAAC,EAAE,EAAE,KAAK;AAAA,CAAI,CACpD,CACF,CACF",
6
- "names": ["TransactionInspector_exports", "__export", "SolanaTransactionTypes", "TransactionInspector", "__toCommonJS", "import_spl_token", "import_web3", "import_buffer", "rawTransactionBytes", "message", "ixMeta", "programId", "instruction", "i", "destination", "account", "mint", "rawBytes", "errors", "e", "tx", "allKeys", "ix", "k", "staticAccountKeys", "pk", "s", "sig", "m"]
4
+ "sourcesContent": ["import {\n ASSOCIATED_TOKEN_PROGRAM_ID,\n decodeInitializeAccountInstruction,\n decodeTransferCheckedInstruction,\n decodeTransferInstruction,\n TOKEN_2022_PROGRAM_ID,\n TOKEN_PROGRAM_ID,\n TokenInstruction,\n} from \"@solana/spl-token\";\nimport {\n type PublicKey,\n Transaction,\n TransactionInstruction,\n VersionedMessage,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\nexport enum SolanaTransactionTypes {\n STANDARD = \"Standard\",\n SPL = \"SPL\",\n}\n\nexport interface TxInspectorResult {\n transactionType: SolanaTransactionTypes;\n data: {\n tokenAddress?: string;\n mintAddress?: string;\n createATA?: {\n address: string;\n mintAddress: string;\n };\n };\n}\n\ntype NormalizedCompiledIx = {\n programIdIndex: number;\n accountKeyIndexes: number[];\n data: Uint8Array;\n};\n\ntype NormalizedMessage = {\n compiledInstructions: NormalizedCompiledIx[];\n allKeys: PublicKey[];\n};\n\ntype LoadedAddresses = { writable: PublicKey[]; readonly: PublicKey[] };\n\nexport class TransactionInspector {\n /**\n * @param rawTransactionBytes - the raw tx bytes (legacy or v0)\n */\n constructor(private readonly rawTransactionBytes: Uint8Array) {}\n\n public inspectTransactionType(): TxInspectorResult {\n try {\n const message = this.normaliseMessage(this.rawTransactionBytes);\n\n for (const ixMeta of message.compiledInstructions) {\n const programId = message.allKeys[ixMeta.programIdIndex];\n if (!programId) continue;\n\n // Associated Token Account (ATA) Program: detect ATA creation\n if (programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {\n // expected accounts: [payer, ata, owner, mint, systemProgram, tokenProgram, rent?]\n const accountPks = ixMeta.accountKeyIndexes\n .map((i) => message.allKeys[i])\n .filter(Boolean) as PublicKey[];\n const ataPk = accountPks[1];\n const mintPk = accountPks[3];\n if (ataPk && mintPk) {\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n createATA: {\n address: ataPk.toBase58(),\n mintAddress: mintPk.toBase58(),\n },\n },\n };\n }\n continue;\n }\n\n // Token Program (classic or 2022)\n const isTokenProgram =\n programId.equals(TOKEN_PROGRAM_ID) ||\n programId.equals(TOKEN_2022_PROGRAM_ID);\n if (!isTokenProgram) continue;\n\n // minimal TransactionInstruction for the decoders\n const instruction = new TransactionInstruction({\n programId,\n keys: ixMeta.accountKeyIndexes.map((i) => {\n if (!message.allKeys[i]) {\n throw new Error(\n `TransactionInspector: missing key at index ${i} in allKeys`,\n );\n }\n return {\n pubkey: message.allKeys[i],\n isSigner: false,\n isWritable: false,\n };\n }),\n data: Buffer.from(ixMeta.data),\n });\n\n const instructionType = instruction.data[0];\n\n try {\n switch (instructionType) {\n case TokenInstruction.Transfer: {\n const {\n keys: { destination },\n } = decodeTransferInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: { tokenAddress: destination.pubkey.toBase58() },\n };\n }\n case TokenInstruction.TransferChecked: {\n const {\n keys: { destination, mint },\n } = decodeTransferCheckedInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n tokenAddress: destination.pubkey.toBase58(),\n mintAddress: mint.pubkey.toBase58(),\n },\n };\n }\n case TokenInstruction.InitializeAccount: {\n // InitializeAccount != ATA creation, ATA is via the Associated Token Account Program above.\n const {\n keys: { account, mint },\n } = decodeInitializeAccountInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n createATA: {\n address: account.pubkey.toBase58(),\n mintAddress: mint.pubkey.toBase58(),\n },\n },\n };\n }\n default:\n // not a token instruction we care about\u2014keep scanning.\n break;\n }\n } catch {\n // if a decoder throws (bad match), keep scanning other instructions.\n continue;\n }\n }\n\n return { transactionType: SolanaTransactionTypes.STANDARD, data: {} };\n } catch {\n return { transactionType: SolanaTransactionTypes.STANDARD, data: {} };\n }\n }\n\n /**\n * normalise any tx (legacy or v0) into { compiledInstructions, allKeys }.\n * if LUT accounts are provided, looked-up keys are included in allKeys.\n */\n private normaliseMessage(rawBytes: Uint8Array): NormalizedMessage {\n const vtx = this.tryDeserialiseVersioned(rawBytes);\n if (vtx) {\n const msg = vtx.message as VersionedMessage & {\n getAccountKeys?: (opts?: {\n accountKeysFromLookups?: LoadedAddresses;\n }) => {\n staticAccountKeys: PublicKey[];\n accountKeysFromLookups?: LoadedAddresses;\n keySegments: () => PublicKey[][];\n };\n compiledInstructions: Array<{\n programIdIndex: number;\n accountKeyIndexes?: number[];\n accounts?: number[];\n data: Uint8Array | string | number[];\n }>;\n staticAccountKeys: PublicKey[];\n };\n\n // build the full key array in the exact index order used by compiledInstructions\n let allKeys: PublicKey[];\n if (typeof msg.getAccountKeys === \"function\") {\n const mak = msg.getAccountKeys();\n allKeys = mak.keySegments().flat();\n } else {\n // very old builds: fall back to concatenation (same order)\n allKeys = [...msg.staticAccountKeys];\n }\n\n const compiledInstructions: NormalizedCompiledIx[] =\n msg.compiledInstructions.map((ix) => ({\n programIdIndex: ix.programIdIndex,\n accountKeyIndexes: Array.from(ix.accountKeyIndexes ?? []),\n data:\n ix.data instanceof Uint8Array\n ? ix.data\n : Buffer.from(ix.data ?? []),\n }));\n\n return { compiledInstructions, allKeys };\n }\n\n // legacy fallback\n const legacy = Transaction.from(rawBytes);\n\n const allKeyMap = new Map<string, PublicKey>();\n const add = (pk?: PublicKey | null) => {\n if (!pk) return;\n const k = pk.toBase58();\n if (!allKeyMap.has(k)) allKeyMap.set(k, pk);\n };\n\n add(legacy.feePayer ?? null);\n for (const ix of legacy.instructions) {\n add(ix.programId);\n for (const k of ix.keys) add(k.pubkey);\n }\n const allKeys = Array.from(allKeyMap.values());\n const indexByB58 = new Map(allKeys.map((pk, i) => [pk.toBase58(), i]));\n\n const compiledInstructions: NormalizedCompiledIx[] =\n legacy.instructions.map((ix) => ({\n programIdIndex: indexByB58.get(ix.programId.toBase58()) ?? -1,\n accountKeyIndexes: ix.keys.map(\n (k) => indexByB58.get(k.pubkey.toBase58()) ?? -1,\n ),\n data: ix.data,\n }));\n\n return { compiledInstructions, allKeys };\n }\n\n private tryDeserialiseVersioned(\n rawBytes: Uint8Array,\n ): VersionedTransaction | null {\n try {\n return VersionedTransaction.deserialize(rawBytes);\n } catch {\n try {\n const msg = VersionedMessage.deserialize(rawBytes);\n // wrap in a dummy VersionedTransaction-like shape just for uniform handling\n return { message: msg } as VersionedTransaction;\n } catch {\n return null;\n }\n }\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAQO,6BACPC,EAMO,2BACPC,EAAuB,kBAEXL,OACVA,EAAA,SAAW,WACXA,EAAA,IAAM,MAFIA,OAAA,IA8BL,MAAMC,CAAqB,CAIhC,YAA6BK,EAAiC,CAAjC,yBAAAA,CAAkC,CAExD,wBAA4C,CACjD,GAAI,C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AD,EAAIF,EAAO,UAAY,IAAI,EAC3B,UAAWD,KAAMC,EAAO,aAAc,CACpCE,EAAIH,EAAG,SAAS,EAChB,UAAWK,KAAKL,EAAG,KAAMG,EAAIE,EAAE,MAAM,CACvC,CACA,MAAMN,EAAU,MAAM,KAAKG,EAAU,OAAO,CAAC,EACvCI,EAAa,IAAI,IAAIP,EAAQ,IAAI,CAACK,EAAIhB,IAAM,CAACgB,EAAG,SAAS,EAAGhB,CAAC,CAAC,CAAC,EAWrE,MAAO,CAAE,qBARPa,EAAO,aAAa,IAAKD,IAAQ,CAC/B,eAAgBM,EAAW,IAAIN,EAAG,UAAU,SAAS,CAAC,GAAK,GAC3D,kBAAmBA,EAAG,KAAK,IACxBK,GAAMC,EAAW,IAAID,EAAE,OAAO,SAAS,CAAC,GAAK,EAChD,EACA,KAAML,EAAG,IACX,EAAE,EAE2B,QAAAD,CAAQ,CACzC,CAEQ,wBACNH,EAC6B,CAC7B,GAAI,CACF,OAAO,uBAAqB,YAAYA,CAAQ,CAClD,MAAQ,CACN,GAAI,CAGF,MAAO,CAAE,QAFG,mBAAiB,YAAYA,CAAQ,CAE3B,CACxB,MAAQ,CACN,OAAO,IACT,CACF,CACF,CACF",
6
+ "names": ["TransactionInspector_exports", "__export", "SolanaTransactionTypes", "TransactionInspector", "__toCommonJS", "import_spl_token", "import_web3", "import_buffer", "rawTransactionBytes", "message", "ixMeta", "programId", "accountPks", "i", "ataPk", "mintPk", "instruction", "instructionType", "destination", "mint", "account", "rawBytes", "vtx", "msg", "allKeys", "ix", "legacy", "allKeyMap", "add", "pk", "k", "indexByB58"]
7
7
  }
@@ -1,4 +1,2 @@
1
- import{decodeInitializeAccountInstruction as u,decodeTransferCheckedInstruction as d,decodeTransferInstruction as p,TOKEN_PROGRAM_ID as y,TokenInstruction as c}from"@solana/spl-token";import{Transaction as l,TransactionInstruction as m,VersionedMessage as T,VersionedTransaction as A}from"@solana/web3.js";import{Buffer as I}from"buffer";var f=(n=>(n.STANDARD="Standard",n.SPL="SPL",n))(f||{});class x{constructor(s){this.rawTransactionBytes=s}inspectTransactionType(){try{const s=this.extractMessage(this.rawTransactionBytes);for(const n of s.compiledInstructions){const t=s.staticAccountKeys[n.programIdIndex];if(!t.equals(y))continue;const r=new m({programId:t,keys:n.accountKeyIndexes.map(e=>({pubkey:s.staticAccountKeys[e],isSigner:s.isAccountSigner(e),isWritable:s.isAccountWritable(e)})),data:I.from(n.data)});switch(r.data[0]){case c.Transfer:{const{keys:{destination:e}}=p(r);return{transactionType:"SPL",data:{tokenAddress:e.pubkey.toBase58()}}}case c.TransferChecked:{const{keys:{destination:e}}=d(r);return{transactionType:"SPL",data:{tokenAddress:e.pubkey.toBase58()}}}case c.InitializeAccount:{const{keys:{account:e,mint:a}}=u(r);return{transactionType:"SPL",data:{createATA:{address:e.pubkey.toBase58(),mintAddress:a.pubkey.toBase58()}}}}default:continue}}return{transactionType:"Standard",data:{}}}catch{return{transactionType:"Standard",data:{}}}}extractMessage(s){const n=[];try{return A.deserialize(s).message}catch(t){n.push(t.message)}try{return T.deserialize(s)}catch(t){n.push(t.message)}try{const t=l.from(s),r=[t.feePayer,...t.instructions.flatMap(e=>e.keys.map(a=>a.pubkey))],o=Array.from(new Map(r.filter(Boolean).map(e=>[e.toBase58(),e])).values());return{compiledInstructions:t.instructions.map(e=>({programIdIndex:o.findIndex(a=>a.equals(e.programId)),accountKeyIndexes:e.keys.map(a=>o.findIndex(i=>i.equals(a.pubkey))),data:e.data})),staticAccountKeys:o,isAccountSigner:e=>t.signatures.some(a=>a.publicKey.equals(o[e])),isAccountWritable:()=>!0}}catch(t){n.push(t.message)}throw new Error(`Invalid transaction payload \u2013 all deserializers failed:
2
- `+n.map((t,r)=>`${r+1}) ${t}`).join(`
3
- `))}}export{f as SolanaTransactionTypes,x as TransactionInspector};
1
+ import{ASSOCIATED_TOKEN_PROGRAM_ID as m,decodeInitializeAccountInstruction as p,decodeTransferCheckedInstruction as I,decodeTransferInstruction as T,TOKEN_2022_PROGRAM_ID as A,TOKEN_PROGRAM_ID as f,TokenInstruction as y}from"@solana/spl-token";import{Transaction as g,TransactionInstruction as K,VersionedMessage as k,VersionedTransaction as b}from"@solana/web3.js";import{Buffer as l}from"buffer";var P=(a=>(a.STANDARD="Standard",a.SPL="SPL",a))(P||{});class D{constructor(s){this.rawTransactionBytes=s}inspectTransactionType(){try{const s=this.normaliseMessage(this.rawTransactionBytes);for(const a of s.compiledInstructions){const r=s.allKeys[a.programIdIndex];if(!r)continue;if(r.equals(m)){const t=a.accountKeyIndexes.map(n=>s.allKeys[n]).filter(Boolean),c=t[1],e=t[3];if(c&&e)return{transactionType:"SPL",data:{createATA:{address:c.toBase58(),mintAddress:e.toBase58()}}};continue}if(!(r.equals(f)||r.equals(A)))continue;const o=new K({programId:r,keys:a.accountKeyIndexes.map(t=>{if(!s.allKeys[t])throw new Error(`TransactionInspector: missing key at index ${t} in allKeys`);return{pubkey:s.allKeys[t],isSigner:!1,isWritable:!1}}),data:l.from(a.data)}),u=o.data[0];try{switch(u){case y.Transfer:{const{keys:{destination:t}}=T(o);return{transactionType:"SPL",data:{tokenAddress:t.pubkey.toBase58()}}}case y.TransferChecked:{const{keys:{destination:t,mint:c}}=I(o);return{transactionType:"SPL",data:{tokenAddress:t.pubkey.toBase58(),mintAddress:c.pubkey.toBase58()}}}case y.InitializeAccount:{const{keys:{account:t,mint:c}}=p(o);return{transactionType:"SPL",data:{createATA:{address:t.pubkey.toBase58(),mintAddress:c.pubkey.toBase58()}}}}default:break}}catch{continue}}return{transactionType:"Standard",data:{}}}catch{return{transactionType:"Standard",data:{}}}}normaliseMessage(s){const a=this.tryDeserialiseVersioned(s);if(a){const e=a.message;let n;return typeof e.getAccountKeys=="function"?n=e.getAccountKeys().keySegments().flat():n=[...e.staticAccountKeys],{compiledInstructions:e.compiledInstructions.map(i=>({programIdIndex:i.programIdIndex,accountKeyIndexes:Array.from(i.accountKeyIndexes??[]),data:i.data instanceof Uint8Array?i.data:l.from(i.data??[])})),allKeys:n}}const r=g.from(s),d=new Map,o=e=>{if(!e)return;const n=e.toBase58();d.has(n)||d.set(n,e)};o(r.feePayer??null);for(const e of r.instructions){o(e.programId);for(const n of e.keys)o(n.pubkey)}const u=Array.from(d.values()),t=new Map(u.map((e,n)=>[e.toBase58(),n]));return{compiledInstructions:r.instructions.map(e=>({programIdIndex:t.get(e.programId.toBase58())??-1,accountKeyIndexes:e.keys.map(n=>t.get(n.pubkey.toBase58())??-1),data:e.data})),allKeys:u}}tryDeserialiseVersioned(s){try{return b.deserialize(s)}catch{try{return{message:k.deserialize(s)}}catch{return null}}}}export{P as SolanaTransactionTypes,D as TransactionInspector};
4
2
  //# sourceMappingURL=TransactionInspector.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/services/TransactionInspector.ts"],
4
- "sourcesContent": ["import {\n decodeInitializeAccountInstruction,\n decodeTransferCheckedInstruction,\n decodeTransferInstruction,\n TOKEN_PROGRAM_ID,\n TokenInstruction,\n} from \"@solana/spl-token\";\nimport {\n type PublicKey,\n Transaction,\n TransactionInstruction,\n VersionedMessage,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\nexport enum SolanaTransactionTypes {\n STANDARD = \"Standard\",\n SPL = \"SPL\",\n}\nexport interface TxInspectorResult {\n transactionType: SolanaTransactionTypes;\n data: {\n tokenAddress?: string;\n createATA?: {\n address: string;\n mintAddress: string;\n };\n };\n}\n\nexport class TransactionInspector {\n constructor(private readonly rawTransactionBytes: Uint8Array) {}\n\n public inspectTransactionType(): TxInspectorResult {\n try {\n const message = this.extractMessage(this.rawTransactionBytes);\n\n for (const ixMeta of message.compiledInstructions) {\n const programId = message.staticAccountKeys[ixMeta.programIdIndex]!;\n if (!programId.equals(TOKEN_PROGRAM_ID)) continue;\n\n const instruction = new TransactionInstruction({\n programId,\n keys: ixMeta.accountKeyIndexes.map((i) => ({\n pubkey: message.staticAccountKeys[i]!,\n isSigner: message.isAccountSigner(i),\n isWritable: message.isAccountWritable(i),\n })),\n data: Buffer.from(ixMeta.data),\n });\n\n const instructionType = instruction.data[0];\n switch (instructionType) {\n case TokenInstruction.Transfer: {\n const {\n keys: { destination },\n } = decodeTransferInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: { tokenAddress: destination.pubkey.toBase58() },\n };\n }\n case TokenInstruction.TransferChecked: {\n const {\n keys: { destination },\n } = decodeTransferCheckedInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: { tokenAddress: destination.pubkey.toBase58() },\n };\n }\n case TokenInstruction.InitializeAccount: {\n const {\n keys: { account, mint },\n } = decodeInitializeAccountInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n createATA: {\n address: account.pubkey.toBase58(),\n mintAddress: mint.pubkey.toBase58(),\n },\n },\n };\n }\n default:\n continue;\n }\n }\n\n return {\n transactionType: SolanaTransactionTypes.STANDARD,\n data: {},\n };\n } catch {\n return {\n transactionType: SolanaTransactionTypes.STANDARD,\n data: {},\n };\n }\n }\n\n private extractMessage(rawBytes: Uint8Array): VersionedMessage {\n const errors: string[] = [];\n try {\n return VersionedTransaction.deserialize(rawBytes).message;\n } catch (e) {\n errors.push((e as Error).message);\n }\n\n try {\n return VersionedMessage.deserialize(rawBytes);\n } catch (e) {\n errors.push((e as Error).message);\n }\n\n try {\n const tx = Transaction.from(rawBytes);\n const allKeys = [\n tx.feePayer,\n ...tx.instructions.flatMap((ix) => ix.keys.map((k) => k.pubkey)),\n ];\n\n const staticAccountKeys = Array.from(\n new Map(\n (allKeys.filter(Boolean) as PublicKey[]).map((pk) => [\n pk.toBase58(),\n pk,\n ]),\n ).values(),\n );\n\n interface CustomCompiledInstruction {\n programIdIndex: number;\n accountKeyIndexes: number[];\n data: Uint8Array;\n }\n\n return {\n compiledInstructions: tx.instructions.map(\n (ix): CustomCompiledInstruction => ({\n programIdIndex: staticAccountKeys.findIndex((k) =>\n k.equals(ix.programId),\n ),\n accountKeyIndexes: ix.keys.map((k) =>\n staticAccountKeys.findIndex((s) => s.equals(k.pubkey)),\n ),\n data: ix.data,\n }),\n ),\n staticAccountKeys,\n isAccountSigner: (i: number) =>\n tx.signatures.some((sig) =>\n sig.publicKey.equals(staticAccountKeys[i]!),\n ),\n isAccountWritable: () => true,\n } as unknown as VersionedMessage;\n } catch (e) {\n errors.push((e as Error).message);\n }\n\n throw new Error(\n \"Invalid transaction payload \u2013 all deserializers failed:\\n\" +\n errors.map((m, i) => `${i + 1}) ${m}`).join(\"\\n\"),\n );\n }\n}\n"],
5
- "mappings": "AAAA,OACE,sCAAAA,EACA,oCAAAC,EACA,6BAAAC,EACA,oBAAAC,EACA,oBAAAC,MACK,oBACP,OAEE,eAAAC,EACA,0BAAAC,EACA,oBAAAC,EACA,wBAAAC,MACK,kBACP,OAAS,UAAAC,MAAc,SAEhB,IAAKC,OACVA,EAAA,SAAW,WACXA,EAAA,IAAM,MAFIA,OAAA,IAeL,MAAMC,CAAqB,CAChC,YAA6BC,EAAiC,CAAjC,yBAAAA,CAAkC,CAExD,wBAA4C,CACjD,GAAI,CACF,MAAMC,EAAU,KAAK,eAAe,KAAK,mBAAmB,EAE5D,UAAWC,KAAUD,EAAQ,qBAAsB,CACjD,MAAME,EAAYF,EAAQ,kBAAkBC,EAAO,cAAc,EACjE,GAAI,CAACC,EAAU,OAAOZ,CAAgB,EAAG,SAEzC,MAAMa,EAAc,IAAIV,EAAuB,CAC7C,UAAAS,EACA,KAAMD,EAAO,kBAAkB,IAAKG,IAAO,CACzC,OAAQJ,EAAQ,kBAAkBI,CAAC,EACnC,SAAUJ,EAAQ,gBAAgBI,CAAC,EACnC,WAAYJ,EAAQ,kBAAkBI,CAAC,CACzC,EAAE,EACF,KAAMR,EAAO,KAAKK,EAAO,IAAI,CAC/B,CAAC,EAGD,OADwBE,EAAY,KAAK,CAAC,EACjB,CACvB,KAAKZ,EAAiB,SAAU,CAC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,CACnDA,EAAG,SAAS,EACZA,CACF,CAAC,CACH,EAAE,OAAO,CACX,EAQA,MAAO,CACL,qBAAsBL,EAAG,aAAa,IACnCE,IAAmC,CAClC,eAAgBE,EAAkB,UAAWD,GAC3CA,EAAE,OAAOD,EAAG,SAAS,CACvB,EACA,kBAAmBA,EAAG,KAAK,IAAKC,GAC9BC,EAAkB,UAAWE,GAAMA,EAAE,OAAOH,EAAE,MAAM,CAAC,CACvD,EACA,KAAMD,EAAG,IACX,EACF,EACA,kBAAAE,EACA,gBAAkBX,GAChBO,EAAG,WAAW,KAAMO,GAClBA,EAAI,UAAU,OAAOH,EAAkBX,CAAC,CAAE,CAC5C,EACF,kBAAmB,IAAM,EAC3B,CACF,OAASM,EAAG,CACVD,EAAO,KAAMC,EAAY,OAAO,CAClC,CAEA,MAAM,IAAI,MACR;AAAA,EACED,EAAO,IAAI,CAACU,EAAGf,IAAM,GAAGA,EAAI,CAAC,KAAKe,CAAC,EAAE,EAAE,KAAK;AAAA,CAAI,CACpD,CACF,CACF",
6
- "names": ["decodeInitializeAccountInstruction", "decodeTransferCheckedInstruction", "decodeTransferInstruction", "TOKEN_PROGRAM_ID", "TokenInstruction", "Transaction", "TransactionInstruction", "VersionedMessage", "VersionedTransaction", "Buffer", "SolanaTransactionTypes", "TransactionInspector", "rawTransactionBytes", "message", "ixMeta", "programId", "instruction", "i", "destination", "account", "mint", "rawBytes", "errors", "e", "tx", "allKeys", "ix", "k", "staticAccountKeys", "pk", "s", "sig", "m"]
4
+ "sourcesContent": ["import {\n ASSOCIATED_TOKEN_PROGRAM_ID,\n decodeInitializeAccountInstruction,\n decodeTransferCheckedInstruction,\n decodeTransferInstruction,\n TOKEN_2022_PROGRAM_ID,\n TOKEN_PROGRAM_ID,\n TokenInstruction,\n} from \"@solana/spl-token\";\nimport {\n type PublicKey,\n Transaction,\n TransactionInstruction,\n VersionedMessage,\n VersionedTransaction,\n} from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\nexport enum SolanaTransactionTypes {\n STANDARD = \"Standard\",\n SPL = \"SPL\",\n}\n\nexport interface TxInspectorResult {\n transactionType: SolanaTransactionTypes;\n data: {\n tokenAddress?: string;\n mintAddress?: string;\n createATA?: {\n address: string;\n mintAddress: string;\n };\n };\n}\n\ntype NormalizedCompiledIx = {\n programIdIndex: number;\n accountKeyIndexes: number[];\n data: Uint8Array;\n};\n\ntype NormalizedMessage = {\n compiledInstructions: NormalizedCompiledIx[];\n allKeys: PublicKey[];\n};\n\ntype LoadedAddresses = { writable: PublicKey[]; readonly: PublicKey[] };\n\nexport class TransactionInspector {\n /**\n * @param rawTransactionBytes - the raw tx bytes (legacy or v0)\n */\n constructor(private readonly rawTransactionBytes: Uint8Array) {}\n\n public inspectTransactionType(): TxInspectorResult {\n try {\n const message = this.normaliseMessage(this.rawTransactionBytes);\n\n for (const ixMeta of message.compiledInstructions) {\n const programId = message.allKeys[ixMeta.programIdIndex];\n if (!programId) continue;\n\n // Associated Token Account (ATA) Program: detect ATA creation\n if (programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {\n // expected accounts: [payer, ata, owner, mint, systemProgram, tokenProgram, rent?]\n const accountPks = ixMeta.accountKeyIndexes\n .map((i) => message.allKeys[i])\n .filter(Boolean) as PublicKey[];\n const ataPk = accountPks[1];\n const mintPk = accountPks[3];\n if (ataPk && mintPk) {\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n createATA: {\n address: ataPk.toBase58(),\n mintAddress: mintPk.toBase58(),\n },\n },\n };\n }\n continue;\n }\n\n // Token Program (classic or 2022)\n const isTokenProgram =\n programId.equals(TOKEN_PROGRAM_ID) ||\n programId.equals(TOKEN_2022_PROGRAM_ID);\n if (!isTokenProgram) continue;\n\n // minimal TransactionInstruction for the decoders\n const instruction = new TransactionInstruction({\n programId,\n keys: ixMeta.accountKeyIndexes.map((i) => {\n if (!message.allKeys[i]) {\n throw new Error(\n `TransactionInspector: missing key at index ${i} in allKeys`,\n );\n }\n return {\n pubkey: message.allKeys[i],\n isSigner: false,\n isWritable: false,\n };\n }),\n data: Buffer.from(ixMeta.data),\n });\n\n const instructionType = instruction.data[0];\n\n try {\n switch (instructionType) {\n case TokenInstruction.Transfer: {\n const {\n keys: { destination },\n } = decodeTransferInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: { tokenAddress: destination.pubkey.toBase58() },\n };\n }\n case TokenInstruction.TransferChecked: {\n const {\n keys: { destination, mint },\n } = decodeTransferCheckedInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n tokenAddress: destination.pubkey.toBase58(),\n mintAddress: mint.pubkey.toBase58(),\n },\n };\n }\n case TokenInstruction.InitializeAccount: {\n // InitializeAccount != ATA creation, ATA is via the Associated Token Account Program above.\n const {\n keys: { account, mint },\n } = decodeInitializeAccountInstruction(instruction);\n return {\n transactionType: SolanaTransactionTypes.SPL,\n data: {\n createATA: {\n address: account.pubkey.toBase58(),\n mintAddress: mint.pubkey.toBase58(),\n },\n },\n };\n }\n default:\n // not a token instruction we care about\u2014keep scanning.\n break;\n }\n } catch {\n // if a decoder throws (bad match), keep scanning other instructions.\n continue;\n }\n }\n\n return { transactionType: SolanaTransactionTypes.STANDARD, data: {} };\n } catch {\n return { transactionType: SolanaTransactionTypes.STANDARD, data: {} };\n }\n }\n\n /**\n * normalise any tx (legacy or v0) into { compiledInstructions, allKeys }.\n * if LUT accounts are provided, looked-up keys are included in allKeys.\n */\n private normaliseMessage(rawBytes: Uint8Array): NormalizedMessage {\n const vtx = this.tryDeserialiseVersioned(rawBytes);\n if (vtx) {\n const msg = vtx.message as VersionedMessage & {\n getAccountKeys?: (opts?: {\n accountKeysFromLookups?: LoadedAddresses;\n }) => {\n staticAccountKeys: PublicKey[];\n accountKeysFromLookups?: LoadedAddresses;\n keySegments: () => PublicKey[][];\n };\n compiledInstructions: Array<{\n programIdIndex: number;\n accountKeyIndexes?: number[];\n accounts?: number[];\n data: Uint8Array | string | number[];\n }>;\n staticAccountKeys: PublicKey[];\n };\n\n // build the full key array in the exact index order used by compiledInstructions\n let allKeys: PublicKey[];\n if (typeof msg.getAccountKeys === \"function\") {\n const mak = msg.getAccountKeys();\n allKeys = mak.keySegments().flat();\n } else {\n // very old builds: fall back to concatenation (same order)\n allKeys = [...msg.staticAccountKeys];\n }\n\n const compiledInstructions: NormalizedCompiledIx[] =\n msg.compiledInstructions.map((ix) => ({\n programIdIndex: ix.programIdIndex,\n accountKeyIndexes: Array.from(ix.accountKeyIndexes ?? []),\n data:\n ix.data instanceof Uint8Array\n ? ix.data\n : Buffer.from(ix.data ?? []),\n }));\n\n return { compiledInstructions, allKeys };\n }\n\n // legacy fallback\n const legacy = Transaction.from(rawBytes);\n\n const allKeyMap = new Map<string, PublicKey>();\n const add = (pk?: PublicKey | null) => {\n if (!pk) return;\n const k = pk.toBase58();\n if (!allKeyMap.has(k)) allKeyMap.set(k, pk);\n };\n\n add(legacy.feePayer ?? null);\n for (const ix of legacy.instructions) {\n add(ix.programId);\n for (const k of ix.keys) add(k.pubkey);\n }\n const allKeys = Array.from(allKeyMap.values());\n const indexByB58 = new Map(allKeys.map((pk, i) => [pk.toBase58(), i]));\n\n const compiledInstructions: NormalizedCompiledIx[] =\n legacy.instructions.map((ix) => ({\n programIdIndex: indexByB58.get(ix.programId.toBase58()) ?? -1,\n accountKeyIndexes: ix.keys.map(\n (k) => indexByB58.get(k.pubkey.toBase58()) ?? -1,\n ),\n data: ix.data,\n }));\n\n return { compiledInstructions, allKeys };\n }\n\n private tryDeserialiseVersioned(\n rawBytes: Uint8Array,\n ): VersionedTransaction | null {\n try {\n return VersionedTransaction.deserialize(rawBytes);\n } catch {\n try {\n const msg = VersionedMessage.deserialize(rawBytes);\n // wrap in a dummy VersionedTransaction-like shape just for uniform handling\n return { message: msg } as VersionedTransaction;\n } catch {\n return null;\n }\n }\n }\n}\n"],
5
+ "mappings": "AAAA,OACE,+BAAAA,EACA,sCAAAC,EACA,oCAAAC,EACA,6BAAAC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AAG,gBAAgB,WACfA,EAAG,KACHpB,EAAO,KAAKoB,EAAG,MAAQ,CAAC,CAAC,CACjC,EAAE,EAE2B,QAAAD,CAAQ,CACzC,CAGA,MAAME,EAASzB,EAAY,KAAKoB,CAAQ,EAElCM,EAAY,IAAI,IAChBC,EAAOC,GAA0B,CACrC,GAAI,CAACA,EAAI,OACT,MAAMC,EAAID,EAAG,SAAS,EACjBF,EAAU,IAAIG,CAAC,GAAGH,EAAU,IAAIG,EAAGD,CAAE,CAC5C,EAEAD,EAAIF,EAAO,UAAY,IAAI,EAC3B,UAAWD,KAAMC,EAAO,aAAc,CACpCE,EAAIH,EAAG,SAAS,EAChB,UAAWK,KAAKL,EAAG,KAAMG,EAAIE,EAAE,MAAM,CACvC,CACA,MAAMN,EAAU,MAAM,KAAKG,EAAU,OAAO,CAAC,EACvCI,EAAa,IAAI,IAAIP,EAAQ,IAAI,CAACK,EAAIhB,IAAM,CAACgB,EAAG,SAAS,EAAGhB,CAAC,CAAC,CAAC,EAWrE,MAAO,CAAE,qBARPa,EAAO,aAAa,IAAKD,IAAQ,CAC/B,eAAgBM,EAAW,IAAIN,EAAG,UAAU,SAAS,CAAC,GAAK,GAC3D,kBAAmBA,EAAG,KAAK,IACxBK,GAAMC,EAAW,IAAID,EAAE,OAAO,SAAS,CAAC,GAAK,EAChD,EACA,KAAML,EAAG,IACX,EAAE,EAE2B,QAAAD,CAAQ,CACzC,CAEQ,wBACNH,EAC6B,CAC7B,GAAI,CACF,OAAOjB,EAAqB,YAAYiB,CAAQ,CAClD,MAAQ,CACN,GAAI,CAGF,MAAO,CAAE,QAFGlB,EAAiB,YAAYkB,CAAQ,CAE3B,CACxB,MAAQ,CACN,OAAO,IACT,CACF,CACF,CACF",
6
+ "names": ["ASSOCIATED_TOKEN_PROGRAM_ID", "decodeInitializeAccountInstruction", "decodeTransferCheckedInstruction", "decodeTransferInstruction", "TOKEN_2022_PROGRAM_ID", "TOKEN_PROGRAM_ID", "TokenInstruction", "Transaction", "TransactionInstruction", "VersionedMessage", "VersionedTransaction", "Buffer", "SolanaTransactionTypes", "TransactionInspector", "rawTransactionBytes", "message", "ixMeta", "programId", "accountPks", "i", "ataPk", "mintPk", "instruction", "instructionType", "destination", "mint", "account", "rawBytes", "vtx", "msg", "allKeys", "ix", "legacy", "allKeyMap", "add", "pk", "k", "indexByB58"]
7
7
  }
@@ -6,6 +6,7 @@ export interface TxInspectorResult {
6
6
  transactionType: SolanaTransactionTypes;
7
7
  data: {
8
8
  tokenAddress?: string;
9
+ mintAddress?: string;
9
10
  createATA?: {
10
11
  address: string;
11
12
  mintAddress: string;
@@ -14,8 +15,16 @@ export interface TxInspectorResult {
14
15
  }
15
16
  export declare class TransactionInspector {
16
17
  private readonly rawTransactionBytes;
18
+ /**
19
+ * @param rawTransactionBytes - the raw tx bytes (legacy or v0)
20
+ */
17
21
  constructor(rawTransactionBytes: Uint8Array);
18
22
  inspectTransactionType(): TxInspectorResult;
19
- private extractMessage;
23
+ /**
24
+ * normalise any tx (legacy or v0) into { compiledInstructions, allKeys }.
25
+ * if LUT accounts are provided, looked-up keys are included in allKeys.
26
+ */
27
+ private normaliseMessage;
28
+ private tryDeserialiseVersioned;
20
29
  }
21
30
  //# sourceMappingURL=TransactionInspector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionInspector.d.ts","sourceRoot":"","sources":["../../../../../src/internal/app-binder/services/TransactionInspector.ts"],"names":[],"mappings":"AAgBA,oBAAY,sBAAsB;IAChC,QAAQ,aAAa;IACrB,GAAG,QAAQ;CACZ;AACD,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,sBAAsB,CAAC;IACxC,IAAI,EAAE;QACJ,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE;YACV,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC;KACH,CAAC;CACH;AAED,qBAAa,oBAAoB;IACnB,OAAO,CAAC,QAAQ,CAAC,mBAAmB;gBAAnB,mBAAmB,EAAE,UAAU;IAErD,sBAAsB,IAAI,iBAAiB;IAqElD,OAAO,CAAC,cAAc;CAgEvB"}
1
+ {"version":3,"file":"TransactionInspector.d.ts","sourceRoot":"","sources":["../../../../../src/internal/app-binder/services/TransactionInspector.ts"],"names":[],"mappings":"AAkBA,oBAAY,sBAAsB;IAChC,QAAQ,aAAa;IACrB,GAAG,QAAQ;CACZ;AAED,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,sBAAsB,CAAC;IACxC,IAAI,EAAE;QACJ,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE;YACV,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC;KACH,CAAC;CACH;AAeD,qBAAa,oBAAoB;IAInB,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAHhD;;OAEG;gBAC0B,mBAAmB,EAAE,UAAU;IAErD,sBAAsB,IAAI,iBAAiB;IA8GlD;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAyExB,OAAO,CAAC,uBAAuB;CAehC"}