{"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["import { Keypair } from \"@stellar/stellar-sdk\";\nimport { basicNodeSigner, SignAuthEntry, SignTransaction } from \"@stellar/stellar-sdk/contract\";\nimport { STELLAR_TESTNET_CAIP2 } from \"./constants\";\nimport { getNetworkPassphrase } from \"./utils\";\nimport type { Network } from \"@x402/core/types\";\n\n/**\n * Ed25519 signer for Stellar transactions and auth entries.\n *\n * Implements SEP-43 interface (except signMessage).\n *\n * @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md\n */\nexport type Ed25519Signer = {\n  address: string;\n  signAuthEntry: SignAuthEntry;\n  signTransaction: SignTransaction;\n};\n\n/**\n * Facilitator signer for Stellar transactions.\n *\n * Alias for Ed25519Signer. Used by x402 facilitators to verify and settle payments.\n *\n * @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md\n */\nexport type FacilitatorStellarSigner = Ed25519Signer;\n\n/**\n * Client signer for Stellar transactions.\n *\n * Used by x402 clients to sign auth entries. Supports both classic (G) and contract (C) accounts.\n * signTransaction is optional for client signers.\n *\n * @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md\n */\nexport type ClientStellarSigner = {\n  address: string;\n  signAuthEntry: SignAuthEntry;\n  signTransaction?: SignTransaction;\n};\n\n/**\n * Creates an Ed25519 signer for the given Stellar network.\n *\n * @param privateKey - Stellar classic (G) account private key\n * @param defaultNetwork - Is the network the signTransactiopn method will default to if no network is provided. Must use the CAIP-2 format identifier.\n * @returns Ed25519 signer implementing SEP-43 interface (except signMessage)\n * @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md\n */\nexport function createEd25519Signer(\n  privateKey: string,\n  defaultNetwork: Network = STELLAR_TESTNET_CAIP2,\n): Ed25519Signer {\n  const kp = Keypair.fromSecret(privateKey);\n  const networkPassphrase = getNetworkPassphrase(defaultNetwork);\n\n  const address = kp.publicKey();\n  const { signAuthEntry, signTransaction } = basicNodeSigner(kp, networkPassphrase);\n\n  return {\n    address,\n    signAuthEntry,\n    signTransaction,\n  };\n}\n\n/**\n * Type guard for FacilitatorStellarSigner.\n *\n * Checks for required methods: address, signAuthEntry, signTransaction.\n *\n * @param signer - Value to check\n * @returns `true` if signer is a FacilitatorStellarSigner\n */\nexport function isFacilitatorStellarSigner(signer: unknown): signer is FacilitatorStellarSigner {\n  if (typeof signer !== \"object\" || signer === null) return false;\n  const s = signer as Record<string, unknown>;\n  return (\n    typeof s.address === \"string\" &&\n    typeof s.signAuthEntry === \"function\" &&\n    typeof s.signTransaction === \"function\"\n  );\n}\n\n/**\n * Type guard for ClientStellarSigner.\n *\n * Checks for required methods: address, signAuthEntry. signTransaction is optional.\n *\n * @param signer - Value to check\n * @returns `true` if signer is a ClientStellarSigner\n */\nexport function isClientStellarSigner(signer: unknown): signer is ClientStellarSigner {\n  if (typeof signer !== \"object\" || signer === null) return false;\n  const s = signer as Record<string, unknown>;\n  return (\n    typeof s.address === \"string\" &&\n    typeof s.signAuthEntry === \"function\" &&\n    (s.signTransaction === undefined || typeof s.signTransaction === \"function\")\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,uBAAuD;AAiDzD,SAAS,oBACd,YACA,iBAA0B,uBACX;AACf,QAAM,KAAK,QAAQ,WAAW,UAAU;AACxC,QAAM,oBAAoB,qBAAqB,cAAc;AAE7D,QAAM,UAAU,GAAG,UAAU;AAC7B,QAAM,EAAE,eAAe,gBAAgB,IAAI,gBAAgB,IAAI,iBAAiB;AAEhF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUO,SAAS,2BAA2B,QAAqD;AAC9F,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;AAC1D,QAAM,IAAI;AACV,SACE,OAAO,EAAE,YAAY,YACrB,OAAO,EAAE,kBAAkB,cAC3B,OAAO,EAAE,oBAAoB;AAEjC;AAUO,SAAS,sBAAsB,QAAgD;AACpF,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;AAC1D,QAAM,IAAI;AACV,SACE,OAAO,EAAE,YAAY,YACrB,OAAO,EAAE,kBAAkB,eAC1B,EAAE,oBAAoB,UAAa,OAAO,EAAE,oBAAoB;AAErE;","names":[]}