{"version":3,"file":"TransactionMessage.cjs","sources":["../../src/TransactionMessage.ts"],"sourcesContent":["import {\n  base58,\n  TransactionInput,\n  TransactionMessage,\n} from '@metaplex-foundation/umi';\nimport {\n  AddressLookupTableAccount as Web3JsAddressLookupTableAccount,\n  Message as Web3JsMessageLegacy,\n  MessageV0 as Web3JsMessageV0,\n} from '@solana/web3.js';\nimport { toWeb3JsInstruction } from './Instruction';\nimport { fromWeb3JsPublicKey, toWeb3JsPublicKey } from './PublicKey';\n\nexport function fromWeb3JsMessage(\n  message: Web3JsMessageLegacy | Web3JsMessageV0\n): TransactionMessage {\n  return {\n    version: message.version,\n    header: message.header,\n    accounts: message.staticAccountKeys.map(fromWeb3JsPublicKey),\n    blockhash: message.recentBlockhash,\n    instructions: message.compiledInstructions.map((instruction) => ({\n      programIndex: instruction.programIdIndex,\n      accountIndexes: instruction.accountKeyIndexes,\n      data: new Uint8Array(instruction.data),\n    })),\n    addressLookupTables: message.addressTableLookups.map((lookup) => ({\n      publicKey: fromWeb3JsPublicKey(lookup.accountKey),\n      writableIndexes: lookup.writableIndexes,\n      readonlyIndexes: lookup.readonlyIndexes,\n    })),\n  };\n}\n\nexport function toWeb3JsMessage(\n  message: TransactionMessage\n): Web3JsMessageLegacy | Web3JsMessageV0 {\n  if (message.version === 'legacy') {\n    return new Web3JsMessageLegacy({\n      header: message.header,\n      accountKeys: message.accounts.map(toWeb3JsPublicKey),\n      recentBlockhash: message.blockhash,\n      instructions: message.instructions.map((instruction) => ({\n        programIdIndex: instruction.programIndex,\n        accounts: instruction.accountIndexes,\n        data: base58.deserialize(instruction.data)[0],\n      })),\n    });\n  }\n\n  return new Web3JsMessageV0({\n    header: message.header,\n    staticAccountKeys: message.accounts.map(toWeb3JsPublicKey),\n    recentBlockhash: message.blockhash,\n    compiledInstructions: message.instructions.map((instruction) => ({\n      programIdIndex: instruction.programIndex,\n      accountKeyIndexes: instruction.accountIndexes,\n      data: instruction.data,\n    })),\n    addressTableLookups: message.addressLookupTables.map((lookup) => ({\n      accountKey: toWeb3JsPublicKey(lookup.publicKey),\n      writableIndexes: lookup.writableIndexes,\n      readonlyIndexes: lookup.readonlyIndexes,\n    })),\n  });\n}\n\nexport function toWeb3JsMessageFromInput(\n  input: TransactionInput\n): Web3JsMessageLegacy | Web3JsMessageV0 {\n  if (input.version === 'legacy') {\n    return Web3JsMessageLegacy.compile({\n      payerKey: toWeb3JsPublicKey(input.payer),\n      instructions: input.instructions.map(toWeb3JsInstruction),\n      recentBlockhash: input.blockhash,\n    });\n  }\n\n  return Web3JsMessageV0.compile({\n    payerKey: toWeb3JsPublicKey(input.payer),\n    instructions: input.instructions.map(toWeb3JsInstruction),\n    recentBlockhash: input.blockhash,\n    addressLookupTableAccounts: input.addressLookupTables?.map(\n      (account) =>\n        new Web3JsAddressLookupTableAccount({\n          key: toWeb3JsPublicKey(account.publicKey),\n          state: {\n            addresses: account.addresses.map(toWeb3JsPublicKey),\n            authority: undefined,\n            deactivationSlot: BigInt(`0x${'ff'.repeat(8)}`),\n            lastExtendedSlot: 0,\n            lastExtendedSlotStartIndex: 0,\n          },\n        })\n    ),\n  });\n}\n"],"names":["fromWeb3JsMessage","message","version","header","accounts","staticAccountKeys","map","fromWeb3JsPublicKey","blockhash","recentBlockhash","instructions","compiledInstructions","instruction","programIndex","programIdIndex","accountIndexes","accountKeyIndexes","data","Uint8Array","addressLookupTables","addressTableLookups","lookup","publicKey","accountKey","writableIndexes","readonlyIndexes","toWeb3JsMessage","Web3JsMessageLegacy","accountKeys","toWeb3JsPublicKey","base58","deserialize","Web3JsMessageV0","toWeb3JsMessageFromInput","input","compile","payerKey","payer","toWeb3JsInstruction","addressLookupTableAccounts","account","Web3JsAddressLookupTableAccount","key","state","addresses","authority","undefined","deactivationSlot","BigInt","repeat","lastExtendedSlot","lastExtendedSlotStartIndex"],"mappings":";;;;;;;;;AAaO,SAASA,iBAAiB,CAC/BC,OAA8C,EAC1B;EACpB,OAAO;IACLC,OAAO,EAAED,OAAO,CAAC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