@digitalworld/digital-world-sdk 16.0.0 → 16.0.1

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.
Files changed (166) hide show
  1. package/README.md +5 -5
  2. package/dist/digital-world-sdk-axios.js +52 -47
  3. package/dist/digital-world-sdk-axios.js.map +1 -1
  4. package/dist/digital-world-sdk-axios.min.js +1 -1
  5. package/dist/digital-world-sdk-axios.min.js.map +1 -1
  6. package/dist/digital-world-sdk.js +52 -47
  7. package/dist/digital-world-sdk.js.map +1 -1
  8. package/dist/digital-world-sdk.min.js +6 -6
  9. package/dist/digital-world-sdk.min.js.map +1 -1
  10. package/lib/axios/cjs/base/contract.js +2 -2
  11. package/lib/axios/cjs/base/contract.js.map +1 -1
  12. package/lib/axios/cjs/base/invocation.js.map +1 -1
  13. package/lib/axios/cjs/base/numbers/sc_int.js +1 -1
  14. package/lib/axios/cjs/base/numbers/sc_int.js.map +1 -1
  15. package/lib/axios/cjs/base/operation.js +1 -1
  16. package/lib/axios/cjs/base/operation.js.map +1 -1
  17. package/lib/axios/cjs/base/operations/invoke_host_function.js +2 -2
  18. package/lib/axios/cjs/base/operations/invoke_host_function.js.map +1 -1
  19. package/lib/axios/cjs/base/operations/revoke_sponsorship.js.map +1 -1
  20. package/lib/axios/cjs/bindings/config.js +4 -4
  21. package/lib/axios/cjs/bindings/config.js.map +1 -1
  22. package/lib/axios/cjs/bindings/generator.js +4 -4
  23. package/lib/axios/cjs/bindings/generator.js.map +1 -1
  24. package/lib/axios/cjs/bindings/types.js.map +1 -1
  25. package/lib/axios/cjs/bindings/utils.js +2 -2
  26. package/lib/axios/cjs/bindings/utils.js.map +1 -1
  27. package/lib/axios/cjs/bindings/wasm_fetcher.js +2 -2
  28. package/lib/axios/cjs/bindings/wasm_fetcher.js.map +1 -1
  29. package/lib/axios/cjs/contract/assembled_transaction.js.map +1 -1
  30. package/lib/axios/cjs/contract/spec.js +1 -1
  31. package/lib/axios/cjs/contract/spec.js.map +1 -1
  32. package/lib/axios/cjs/contract/types.js.map +1 -1
  33. package/lib/axios/cjs/gateway/gateway_axios_client.js +1 -1
  34. package/lib/axios/cjs/gateway/server_api.js.map +1 -1
  35. package/lib/axios/cjs/rpc/api.js.map +1 -1
  36. package/lib/axios/cjs/rpc/axios.js +1 -1
  37. package/lib/axios/cjs/rpc/server.js +32 -27
  38. package/lib/axios/cjs/rpc/server.js.map +1 -1
  39. package/lib/axios/cjs/webauth/utils.js.map +1 -1
  40. package/lib/axios/esm/base/contract.d.ts +4 -4
  41. package/lib/axios/esm/base/contract.js +2 -2
  42. package/lib/axios/esm/base/contract.js.map +1 -1
  43. package/lib/axios/esm/base/invocation.d.ts +2 -2
  44. package/lib/axios/esm/base/invocation.js.map +1 -1
  45. package/lib/axios/esm/base/numbers/sc_int.d.ts +2 -2
  46. package/lib/axios/esm/base/numbers/sc_int.js +1 -1
  47. package/lib/axios/esm/base/numbers/sc_int.js.map +1 -1
  48. package/lib/axios/esm/base/operation.d.ts +2 -2
  49. package/lib/axios/esm/base/operation.js +2 -2
  50. package/lib/axios/esm/base/operation.js.map +1 -1
  51. package/lib/axios/esm/base/operations/index.d.ts +1 -1
  52. package/lib/axios/esm/base/operations/invoke_host_function.d.ts +5 -5
  53. package/lib/axios/esm/base/operations/invoke_host_function.js +2 -2
  54. package/lib/axios/esm/base/operations/invoke_host_function.js.map +1 -1
  55. package/lib/axios/esm/base/operations/revoke_sponsorship.d.ts +1 -1
  56. package/lib/axios/esm/base/operations/revoke_sponsorship.js.map +1 -1
  57. package/lib/axios/esm/base/operations/types.d.ts +2 -2
  58. package/lib/axios/esm/bindings/config.js +4 -4
  59. package/lib/axios/esm/bindings/config.js.map +1 -1
  60. package/lib/axios/esm/bindings/generator.d.ts +7 -7
  61. package/lib/axios/esm/bindings/generator.js +4 -4
  62. package/lib/axios/esm/bindings/generator.js.map +1 -1
  63. package/lib/axios/esm/bindings/types.d.ts +1 -1
  64. package/lib/axios/esm/bindings/types.js.map +1 -1
  65. package/lib/axios/esm/bindings/utils.d.ts +4 -4
  66. package/lib/axios/esm/bindings/utils.js +2 -2
  67. package/lib/axios/esm/bindings/utils.js.map +1 -1
  68. package/lib/axios/esm/bindings/wasm_fetcher.js +2 -2
  69. package/lib/axios/esm/bindings/wasm_fetcher.js.map +1 -1
  70. package/lib/axios/esm/contract/assembled_transaction.d.ts +1 -1
  71. package/lib/axios/esm/contract/assembled_transaction.js.map +1 -1
  72. package/lib/axios/esm/contract/spec.js +1 -1
  73. package/lib/axios/esm/contract/spec.js.map +1 -1
  74. package/lib/axios/esm/contract/types.d.ts +2 -2
  75. package/lib/axios/esm/contract/types.js.map +1 -1
  76. package/lib/axios/esm/gateway/gateway_axios_client.js +1 -1
  77. package/lib/axios/esm/gateway/server_api.d.ts +2 -2
  78. package/lib/axios/esm/gateway/server_api.js.map +1 -1
  79. package/lib/axios/esm/rpc/api.d.ts +1 -1
  80. package/lib/axios/esm/rpc/api.js.map +1 -1
  81. package/lib/axios/esm/rpc/axios.js +1 -1
  82. package/lib/axios/esm/rpc/browser.d.ts +1 -1
  83. package/lib/axios/esm/rpc/server.d.ts +26 -26
  84. package/lib/axios/esm/rpc/server.js +32 -27
  85. package/lib/axios/esm/rpc/server.js.map +1 -1
  86. package/lib/axios/esm/webauth/utils.d.ts +2 -2
  87. package/lib/axios/esm/webauth/utils.js.map +1 -1
  88. package/lib/cjs/base/contract.js +2 -2
  89. package/lib/cjs/base/contract.js.map +1 -1
  90. package/lib/cjs/base/invocation.js.map +1 -1
  91. package/lib/cjs/base/numbers/sc_int.js +1 -1
  92. package/lib/cjs/base/numbers/sc_int.js.map +1 -1
  93. package/lib/cjs/base/operation.js +1 -1
  94. package/lib/cjs/base/operation.js.map +1 -1
  95. package/lib/cjs/base/operations/invoke_host_function.js +2 -2
  96. package/lib/cjs/base/operations/invoke_host_function.js.map +1 -1
  97. package/lib/cjs/base/operations/revoke_sponsorship.js.map +1 -1
  98. package/lib/cjs/bindings/config.js +4 -4
  99. package/lib/cjs/bindings/config.js.map +1 -1
  100. package/lib/cjs/bindings/generator.js +4 -4
  101. package/lib/cjs/bindings/generator.js.map +1 -1
  102. package/lib/cjs/bindings/types.js.map +1 -1
  103. package/lib/cjs/bindings/utils.js +2 -2
  104. package/lib/cjs/bindings/utils.js.map +1 -1
  105. package/lib/cjs/bindings/wasm_fetcher.js +2 -2
  106. package/lib/cjs/bindings/wasm_fetcher.js.map +1 -1
  107. package/lib/cjs/contract/assembled_transaction.js.map +1 -1
  108. package/lib/cjs/contract/spec.js +1 -1
  109. package/lib/cjs/contract/spec.js.map +1 -1
  110. package/lib/cjs/contract/types.js.map +1 -1
  111. package/lib/cjs/gateway/gateway_axios_client.js +1 -1
  112. package/lib/cjs/gateway/server_api.js.map +1 -1
  113. package/lib/cjs/rpc/api.js.map +1 -1
  114. package/lib/cjs/rpc/axios.js +1 -1
  115. package/lib/cjs/rpc/server.js +32 -27
  116. package/lib/cjs/rpc/server.js.map +1 -1
  117. package/lib/cjs/webauth/utils.js.map +1 -1
  118. package/lib/esm/base/contract.d.ts +4 -4
  119. package/lib/esm/base/contract.js +2 -2
  120. package/lib/esm/base/contract.js.map +1 -1
  121. package/lib/esm/base/invocation.d.ts +2 -2
  122. package/lib/esm/base/invocation.js.map +1 -1
  123. package/lib/esm/base/numbers/sc_int.d.ts +2 -2
  124. package/lib/esm/base/numbers/sc_int.js +1 -1
  125. package/lib/esm/base/numbers/sc_int.js.map +1 -1
  126. package/lib/esm/base/operation.d.ts +2 -2
  127. package/lib/esm/base/operation.js +2 -2
  128. package/lib/esm/base/operation.js.map +1 -1
  129. package/lib/esm/base/operations/index.d.ts +1 -1
  130. package/lib/esm/base/operations/invoke_host_function.d.ts +5 -5
  131. package/lib/esm/base/operations/invoke_host_function.js +2 -2
  132. package/lib/esm/base/operations/invoke_host_function.js.map +1 -1
  133. package/lib/esm/base/operations/revoke_sponsorship.d.ts +1 -1
  134. package/lib/esm/base/operations/revoke_sponsorship.js.map +1 -1
  135. package/lib/esm/base/operations/types.d.ts +2 -2
  136. package/lib/esm/bindings/config.js +4 -4
  137. package/lib/esm/bindings/config.js.map +1 -1
  138. package/lib/esm/bindings/generator.d.ts +7 -7
  139. package/lib/esm/bindings/generator.js +4 -4
  140. package/lib/esm/bindings/generator.js.map +1 -1
  141. package/lib/esm/bindings/types.d.ts +1 -1
  142. package/lib/esm/bindings/types.js.map +1 -1
  143. package/lib/esm/bindings/utils.d.ts +4 -4
  144. package/lib/esm/bindings/utils.js +2 -2
  145. package/lib/esm/bindings/utils.js.map +1 -1
  146. package/lib/esm/bindings/wasm_fetcher.js +2 -2
  147. package/lib/esm/bindings/wasm_fetcher.js.map +1 -1
  148. package/lib/esm/contract/assembled_transaction.d.ts +1 -1
  149. package/lib/esm/contract/assembled_transaction.js.map +1 -1
  150. package/lib/esm/contract/spec.js +1 -1
  151. package/lib/esm/contract/spec.js.map +1 -1
  152. package/lib/esm/contract/types.d.ts +2 -2
  153. package/lib/esm/contract/types.js.map +1 -1
  154. package/lib/esm/gateway/gateway_axios_client.js +1 -1
  155. package/lib/esm/gateway/server_api.d.ts +2 -2
  156. package/lib/esm/gateway/server_api.js.map +1 -1
  157. package/lib/esm/rpc/api.d.ts +1 -1
  158. package/lib/esm/rpc/api.js.map +1 -1
  159. package/lib/esm/rpc/axios.js +1 -1
  160. package/lib/esm/rpc/browser.d.ts +1 -1
  161. package/lib/esm/rpc/server.d.ts +26 -26
  162. package/lib/esm/rpc/server.js +32 -27
  163. package/lib/esm/rpc/server.js.map +1 -1
  164. package/lib/esm/webauth/utils.d.ts +2 -2
  165. package/lib/esm/webauth/utils.js.map +1 -1
  166. package/package.json +41 -39
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../../src/bindings/config.ts"],"sourcesContent":["// The SDK version is baked in at build time via babel-plugin-transform-define.\n// Previously this was `import packageJson from \"../../package.json\"`, which\n// failed at runtime in deeper build outputs (e.g. lib/axios) because the\n// relative path `../../package.json` resolved into the output tree rather\n// than the project root.\n\ndeclare const __PACKAGE_VERSION__: string;\n\nexport interface ConfigGenerateOptions {\n contractName: string;\n}\n\nexport interface Configs {\n packageJson: string;\n tsConfig: string;\n gitignore: string;\n readme: string;\n}\n\n/**\n * Generates a complete TypeScript project structure with contract bindings\n */\nexport class ConfigGenerator {\n /**\n * Generate the complete TypeScript project\n */\n generate(options: ConfigGenerateOptions): Configs {\n const { contractName } = options;\n\n // Generate all project files\n return {\n packageJson: this.generatePackageJson(contractName),\n tsConfig: this.generateTsConfig(),\n gitignore: this.generateGitignore(),\n readme: this.generateReadme(contractName),\n };\n }\n\n /**\n * Generate package.json\n */\n private generatePackageJson(contractName: string): string {\n const generatedPackageJson = {\n name: contractName.toLowerCase().replace(/[^a-z0-9-]/g, \"-\"),\n version: \"0.0.1\",\n description: `Generated TypeScript bindings for ${contractName} Stellar contract`,\n type: \"module\",\n main: \"dist/index.js\",\n types: \"dist/index.d.ts\",\n scripts: {\n build: \"tsc\",\n },\n dependencies: {\n \"@stellar/stellar-sdk\": `^${__PACKAGE_VERSION__}`,\n buffer: \"6.0.3\",\n },\n devDependencies: {\n typescript: \"^5.6.3\",\n },\n };\n\n return JSON.stringify(generatedPackageJson, null, 2);\n }\n\n /**\n * Generate tsconfig.json\n */\n private generateTsConfig(): string {\n const tsConfig = {\n compilerOptions: {\n target: \"ESNext\",\n module: \"NodeNext\",\n moduleResolution: \"nodenext\",\n declaration: true,\n outDir: \"./dist\",\n strictNullChecks: true,\n skipLibCheck: true,\n },\n include: [\"src/*\"],\n };\n\n return JSON.stringify(tsConfig, null, 2);\n }\n\n /**\n * Generate .gitignore\n */\n private generateGitignore(): string {\n const gitignore = [\n \"# Dependencies\",\n \"node_modules/\",\n \"\",\n \"# Build outputs\",\n \"dist/\",\n \"*.tgz\",\n \"\",\n \"# IDE\",\n \".vscode/\",\n \".idea/\",\n \"\",\n \"# OS\",\n \".DS_Store\",\n \"Thumbs.db\",\n \"\",\n \"# Logs\",\n \"*.log\",\n \"npm-debug.log*\",\n \"\",\n \"# Runtime data\",\n \"*.pid\",\n \"*.seed\",\n ].join(\"\\n\");\n\n return gitignore;\n }\n\n /**\n * Generate README.md\n */\n private generateReadme(contractName: string): string {\n const readme = [\n `# ${contractName} Contract Bindings`,\n \"\",\n `TypeScript bindings for the ${contractName} Stellar smart contract.`,\n \"\",\n \"## Installation\",\n \"\",\n \"```bash\",\n \"npm install\",\n \"```\",\n \"\",\n \"## Build\",\n \"\",\n \"```bash\",\n \"npm run build\",\n \"```\",\n \"\",\n \"## Usage\",\n \"\",\n \"```typescript\",\n 'import { Client } from \"./src\";',\n \"\",\n \"const client = new Client({\",\n ' contractId: \"YOUR_CONTRACT_ID\",',\n ' rpcUrl: \"https://soroban-testnet.stellar.org:443\",',\n ' networkPassphrase: \"Test SDF Network ; September 2015\",',\n \"});\",\n \"\",\n \"// Call contract methods\",\n \"// const result = await client.methodName();\",\n \"```\",\n \"\",\n \"## Generated Files\",\n \"\",\n \"- `src/index.ts` - Entry point exporting the Client\",\n \"- `src/types.ts` - Type definitions for contract structs, enums, and unions\",\n \"- `src/contract.ts` - Client implementation\",\n \"- `tsconfig.json` - TypeScript configuration\",\n \"- `package.json` - NPM package configuration\",\n \"\",\n \"This package was generated using the Js-Stellar-SDK contract binding generator.\",\n ].join(\"\\n\");\n\n return readme;\n }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,eAAA,CAAgB;AAAA;AAAA;AAAA;AAAA,EAI3B,SAAS,OAAA,EAAyC;AAChD,IAAA,MAAM,EAAE,cAAa,GAAI,OAAA;AAGzB,IAAA,OAAO;AAAA,MACL,WAAA,EAAa,IAAA,CAAK,mBAAA,CAAoB,YAAY,CAAA;AAAA,MAClD,QAAA,EAAU,KAAK,gBAAA,EAAiB;AAAA,MAChC,SAAA,EAAW,KAAK,iBAAA,EAAkB;AAAA,MAClC,MAAA,EAAQ,IAAA,CAAK,cAAA,CAAe,YAAY;AAAA,KAC1C;AAAA,EACF;AAAA;AAAA;AAAA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AK,IAAI,CAAA;AAEX,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../../src/bindings/config.ts"],"sourcesContent":["// The SDK version is baked in at build time via babel-plugin-transform-define.\n// Previously this was `import packageJson from \"../../package.json\"`, which\n// failed at runtime in deeper build outputs (e.g. lib/axios) because the\n// relative path `../../package.json` resolved into the output tree rather\n// than the project root.\n\ndeclare const __PACKAGE_VERSION__: string;\n\nexport interface ConfigGenerateOptions {\n contractName: string;\n}\n\nexport interface Configs {\n packageJson: string;\n tsConfig: string;\n gitignore: string;\n readme: string;\n}\n\n/**\n * Generates a complete TypeScript project structure with contract bindings\n */\nexport class ConfigGenerator {\n /**\n * Generate the complete TypeScript project\n */\n generate(options: ConfigGenerateOptions): Configs {\n const { contractName } = options;\n\n // Generate all project files\n return {\n packageJson: this.generatePackageJson(contractName),\n tsConfig: this.generateTsConfig(),\n gitignore: this.generateGitignore(),\n readme: this.generateReadme(contractName),\n };\n }\n\n /**\n * Generate package.json\n */\n private generatePackageJson(contractName: string): string {\n const generatedPackageJson = {\n name: contractName.toLowerCase().replace(/[^a-z0-9-]/g, \"-\"),\n version: \"0.0.1\",\n description: `Generated TypeScript bindings for ${contractName} Digital World contract`,\n type: \"module\",\n main: \"dist/index.js\",\n types: \"dist/index.d.ts\",\n scripts: {\n build: \"tsc\",\n },\n dependencies: {\n \"@stellar/stellar-sdk\": `^${__PACKAGE_VERSION__}`,\n buffer: \"6.0.3\",\n },\n devDependencies: {\n typescript: \"^5.6.3\",\n },\n };\n\n return JSON.stringify(generatedPackageJson, null, 2);\n }\n\n /**\n * Generate tsconfig.json\n */\n private generateTsConfig(): string {\n const tsConfig = {\n compilerOptions: {\n target: \"ESNext\",\n module: \"NodeNext\",\n moduleResolution: \"nodenext\",\n declaration: true,\n outDir: \"./dist\",\n strictNullChecks: true,\n skipLibCheck: true,\n },\n include: [\"src/*\"],\n };\n\n return JSON.stringify(tsConfig, null, 2);\n }\n\n /**\n * Generate .gitignore\n */\n private generateGitignore(): string {\n const gitignore = [\n \"# Dependencies\",\n \"node_modules/\",\n \"\",\n \"# Build outputs\",\n \"dist/\",\n \"*.tgz\",\n \"\",\n \"# IDE\",\n \".vscode/\",\n \".idea/\",\n \"\",\n \"# OS\",\n \".DS_Store\",\n \"Thumbs.db\",\n \"\",\n \"# Logs\",\n \"*.log\",\n \"npm-debug.log*\",\n \"\",\n \"# Runtime data\",\n \"*.pid\",\n \"*.seed\",\n ].join(\"\\n\");\n\n return gitignore;\n }\n\n /**\n * Generate README.md\n */\n private generateReadme(contractName: string): string {\n const readme = [\n `# ${contractName} Contract Bindings`,\n \"\",\n `TypeScript bindings for the ${contractName} Digital World smart contract.`,\n \"\",\n \"## Installation\",\n \"\",\n \"```bash\",\n \"npm install\",\n \"```\",\n \"\",\n \"## Build\",\n \"\",\n \"```bash\",\n \"npm run build\",\n \"```\",\n \"\",\n \"## Usage\",\n \"\",\n \"```typescript\",\n 'import { Client } from \"./src\";',\n \"\",\n \"const client = new Client({\",\n ' contractId: \"YOUR_CONTRACT_ID\",',\n ' rpcUrl: \"https://soroban-testnet.stellar.org:443\",',\n ' networkPassphrase: \"Test SDF Network ; September 2015\",',\n \"});\",\n \"\",\n \"// Call contract methods\",\n \"// const result = await client.methodName();\",\n \"```\",\n \"\",\n \"## Generated Files\",\n \"\",\n \"- `src/index.ts` - Entry point exporting the Client\",\n \"- `src/types.ts` - Type definitions for contract structs, enums, and unions\",\n \"- `src/contract.ts` - Client implementation\",\n \"- `tsconfig.json` - TypeScript configuration\",\n \"- `package.json` - NPM package configuration\",\n \"\",\n \"This package was generated using the Digital World JS SDK contract binding generator.\",\n ].join(\"\\n\");\n\n return readme;\n }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,eAAA,CAAgB;AAAA;AAAA;AAAA;AAAA,EAI3B,SAAS,OAAA,EAAyC;AAChD,IAAA,MAAM,EAAE,cAAa,GAAI,OAAA;AAGzB,IAAA,OAAO;AAAA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AAAA,MACA,0BAAA;AAAA,MACA,8CAAA;AAAA,MACA,KAAA;AAAA,MACA,EAAA;AAAA,MACA,oBAAA;AAAA,MACA,EAAA;AAAA,MACA,qDAAA;AAAA,MACA,6EAAA;AAAA,MACA,6CAAA;AAAA,MACA,8CAAA;AAAA,MACA,8CAAA;AAAA,MACA,EAAA;AAAA,MACA;AAAA,KACF,CAAE,KAAK,IAAI,CAAA;AAEX,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
@@ -80,12 +80,12 @@ class BindingGenerator {
80
80
  /**
81
81
  * Creates a BindingGenerator by fetching WASM from the network using its hash.
82
82
  *
83
- * Retrieves the WASM bytecode from Stellar RPC using the WASM hash,
83
+ * Retrieves the WASM bytecode from Digital World RPC using the WASM hash,
84
84
  * then parses the contract specification from it. Useful when you know
85
85
  * the hash of an installed WASM but don't have the binary locally.
86
86
  *
87
87
  * @param wasmHash - The hex-encoded hash of the installed WASM blob
88
- * @param rpcServer - The Stellar RPC server instance
88
+ * @param rpcServer - The Digital World RPC server instance
89
89
  * @returns A Promise resolving to a new BindingGenerator instance
90
90
  * @throws If the WASM cannot be fetched or doesn't contain a valid spec
91
91
  *
@@ -109,11 +109,11 @@ class BindingGenerator {
109
109
  * Creates a BindingGenerator by fetching contract info from a deployed contract ID.
110
110
  *
111
111
  * Retrieves the contract's WASM from the network using the contract ID,
112
- * then parses the specification. If the contract is a Stellar Asset Contract (SAC),
112
+ * then parses the specification. If the contract is a Digital World Asset Contract (SAC),
113
113
  * returns a generator with the standard SAC specification.
114
114
  *
115
115
  * @param contractId - The contract ID (C... address) of the deployed contract
116
- * @param rpcServer - The Stellar RPC server instance
116
+ * @param rpcServer - The Digital World RPC server instance
117
117
  * @returns A Promise resolving to a new BindingGenerator instance
118
118
  * @throws If the contract cannot be found or fetched
119
119
  *
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sources":["../../../../src/bindings/generator.ts"],"sourcesContent":["import { Spec } from \"../contract/index.js\";\nimport { ConfigGenerator } from \"./config.js\";\nimport { TypeGenerator } from \"./types.js\";\nimport { ClientGenerator } from \"./client.js\";\nimport { specFromWasm } from \"../contract/wasm_spec_parser.js\";\nimport { fetchFromContractId, fetchFromWasmHash } from \"./wasm_fetcher.js\";\nimport { SAC_SPEC } from \"./sac-spec.js\";\nimport { Server } from \"../rpc/index.js\";\n\n/**\n * Options for generating TypeScript bindings.\n */\nexport type GenerateOptions = {\n /**\n * The name used for the generated package and client class.\n * Should be in kebab-case (e.g., \"my-contract\").\n */\n contractName: string;\n};\n\n/**\n * The output of the binding generation process.\n *\n * Contains all generated TypeScript source files and configuration files\n * needed to create a standalone npm package for interacting with a Stellar contract.\n */\nexport type GeneratedBindings = {\n /** The index.ts barrel export file that re-exports Client and types */\n index: string;\n /** The types.ts file containing TypeScript interfaces for contract structs, enums, and unions */\n types: string;\n /** The client.ts file containing the generated Client class with typed methods */\n client: string;\n /** The package.json for the generated npm package */\n packageJson: string;\n /** The tsconfig.json for TypeScript compilation */\n tsConfig: string;\n /** The README.md with usage documentation */\n readme: string;\n /** The .gitignore file for the generated package */\n gitignore: string;\n};\n\n/**\n * Generates TypeScript bindings for Stellar smart contracts.\n *\n * This class creates fully-typed TypeScript client code from a contract's specification,\n * allowing developers to interact with Stellar smart contracts with full IDE support\n * and compile-time type checking.\n *\n * @example\n * ```ts\n * // Create from a local WASM file\n * const wasmBuffer = fs.readFileSync(\"./my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a contract deployed on the network\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC...XYZ\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a Spec object directly\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n */\nexport class BindingGenerator {\n private spec: Spec;\n\n /**\n * Private constructor - use static factory methods instead.\n *\n * @param spec - The parsed contract specification\n */\n private constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Creates a BindingGenerator from an existing Spec object.\n *\n * Use this when you already have a parsed contract specification,\n * such as from manually constructed spec entries or from another source.\n *\n * @param spec - The contract specification containing function and type definitions\n * @returns A new BindingGenerator instance\n *\n * @example\n * ```ts\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * ```\n */\n static fromSpec(spec: Spec): BindingGenerator {\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator from a WASM binary buffer.\n *\n * Parses the contract specification directly from the WASM file's custom section.\n * This is the most common method when working with locally compiled contracts.\n *\n * @param wasmBuffer - The raw WASM binary as a Buffer\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM file doesn't contain a valid contract spec\n *\n * @example\n * ```ts\n * const wasmBuffer = fs.readFileSync(\"./target/wasm32-unknown-unknown/release/my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * ```\n */\n static fromWasm(wasmBuffer: Buffer): BindingGenerator {\n const spec = new Spec(specFromWasm(wasmBuffer));\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator by fetching WASM from the network using its hash.\n *\n * Retrieves the WASM bytecode from Stellar RPC using the WASM hash,\n * then parses the contract specification from it. Useful when you know\n * the hash of an installed WASM but don't have the binary locally.\n *\n * @param wasmHash - The hex-encoded hash of the installed WASM blob\n * @param rpcServer - The Stellar RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM cannot be fetched or doesn't contain a valid spec\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromWasmHash(\n * \"a1b2c3...xyz\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * ```\n */\n static async fromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const wasm = await fetchFromWasmHash(wasmHash, rpcServer);\n if (wasm.type !== \"wasm\") {\n throw new Error(\"Fetched contract is not of type 'wasm'\");\n }\n return BindingGenerator.fromWasm(wasm.wasmBytes);\n }\n\n /**\n * Creates a BindingGenerator by fetching contract info from a deployed contract ID.\n *\n * Retrieves the contract's WASM from the network using the contract ID,\n * then parses the specification. If the contract is a Stellar Asset Contract (SAC),\n * returns a generator with the standard SAC specification.\n *\n * @param contractId - The contract ID (C... address) of the deployed contract\n * @param rpcServer - The Stellar RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the contract cannot be found or fetched\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC123...XYZ\",\n * rpcServer\n * );\n * ```\n */\n static async fromContractId(\n contractId: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const result = await fetchFromContractId(contractId, rpcServer);\n if (result.type === \"wasm\") {\n return BindingGenerator.fromWasm(result.wasmBytes);\n }\n // Stellar Asset Contract\n const spec = new Spec(SAC_SPEC);\n return BindingGenerator.fromSpec(spec);\n }\n\n /**\n * Generates TypeScript bindings for the contract.\n *\n * Produces all the files needed for a standalone npm package:\n * - `client.ts`: A typed Client class with methods for each contract function\n * - `types.ts`: TypeScript interfaces for all contract types (structs, enums, unions)\n * - `index.ts`: Barrel export file\n * - `package.json`, `tsconfig.json`, `README.md`, `.gitignore`: Package configuration\n *\n * The generated code does not write to disk - use the returned strings\n * to write files as needed.\n *\n * @param options - Configuration options for generation\n * - `contractName`: Required. The name for the generated package (kebab-case recommended)\n * @returns An object containing all generated file contents as strings\n * @throws If contractName is missing or empty\n *\n * @example\n * ```ts\n * const bindings = generator.generate({\n * contractName: \"my-token\",\n * contractAddress: \"CABC...XYZ\",\n * rpcUrl: \"https://soroban-testnet.stellar.org\",\n * networkPassphrase: Networks.TESTNET\n * });\n *\n * // Write files to disk\n * fs.writeFileSync(\"./src/client.ts\", bindings.client);\n * fs.writeFileSync(\"./src/types.ts\", bindings.types);\n * ```\n */\n generate(options: GenerateOptions): GeneratedBindings {\n this.validateOptions(options);\n\n const typeGenerator = new TypeGenerator(this.spec);\n const clientGenerator = new ClientGenerator(this.spec);\n\n const types = typeGenerator.generate();\n const client = clientGenerator.generate();\n\n let index = `export { Client } from \"./client.js\";`;\n if (types.trim() !== \"\") {\n index = index.concat(`\\nexport * from \"./types.js\";`);\n }\n\n // Generate config files\n const configGenerator = new ConfigGenerator();\n const { packageJson, tsConfig, readme, gitignore } =\n configGenerator.generate(options);\n\n return {\n index,\n types,\n client,\n packageJson,\n tsConfig,\n readme,\n gitignore,\n };\n }\n\n /**\n * Validates that required generation options are provided.\n *\n * @param options - The options to validate\n * @throws If contractName is missing or empty\n */\n private validateOptions(options: GenerateOptions): void {\n if (!options.contractName || options.contractName.trim() === \"\") {\n throw new Error(\"contractName is required and cannot be empty\");\n }\n }\n}\n"],"names":["spec","Spec","specFromWasm","fetchFromWasmHash","fetchFromContractId","SAC_SPEC","TypeGenerator","ClientGenerator","types","client","ConfigGenerator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EO,MAAM,gBAAA,CAAiB;AAAA,EACpB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,IAAA,EAAY;AAC9B,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,OAAO,SAAS,IAAA,EAA8B;AAC5C,IAAA,OAAO,IAAI,iBAAiB,IAAI,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,OAAO,SAAS,UAAA,EAAsC;AACpD,IAAA,MAAMA,MAAA,GAAO,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AAAA;AAAA;AAAA;AAAA;AAAA,EAiCA,SAAS,OAAA,EAA6C;AACpD,IAAA,IAAA,CAAK,gBAAgB,OAAO,CAAA;AAE5B,IAAA,MAAM,aAAA,GAAgB,IAAIM,mBAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACjD,IAAA,MAAM,eAAA,GAAkB,IAAIC,sBAAA,CAAgB,IAAA,CAAK,IAAI,CAAA;AAErD,IAAA,MAAMC,OAAA,GAAQ,cAAc,QAAA,EAAS;AACrC,IAAA,MAAMC,QAAA,GAAS,gBAAgB,QAAA,EAAS;AAExC,IAAA,IAAI,KAAA,GAAQ,CAAA,qCAAA,CAAA;AACZ,IAAA,IAAID,OAAA,CAAM,IAAA,EAAK,KAAM,EAAA,EAAI;AACvB,MAAA,KAAA,GAAQ,MAAM,MAAA,CAAO;AAAA,2BAAA,CAA+B,CAAA;AAAA,IACtD;AAGA,IAAA,MAAM,eAAA,GAAkB,IAAIE,sBAAA,EAAgB;AAC5C,IAAA,MAAM,EAAE,aAAa,QAAA,EAAU,MAAA,EAAQ,WAAU,GAC/C,eAAA,CAAgB,SAAS,OAAO,CAAA;AAElC,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,aACAF,OAAA;AAAA,cACAC,QAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,gBAAgB,OAAA,EAAgC;AACtD,IAAA,IAAI,CAAC,OAAA,CAAQ,YAAA,IAAgB,QAAQ,YAAA,CAAa,IAAA,OAAW,EAAA,EAAI;AAC/D,MAAA,MAAM,IAAI,MAAM,8CAA8C,CAAA;AAAA,IAChE;AAAA,EACF;AACF;;;;"}
1
+ {"version":3,"file":"generator.js","sources":["../../../../src/bindings/generator.ts"],"sourcesContent":["import { Spec } from \"../contract/index.js\";\nimport { ConfigGenerator } from \"./config.js\";\nimport { TypeGenerator } from \"./types.js\";\nimport { ClientGenerator } from \"./client.js\";\nimport { specFromWasm } from \"../contract/wasm_spec_parser.js\";\nimport { fetchFromContractId, fetchFromWasmHash } from \"./wasm_fetcher.js\";\nimport { SAC_SPEC } from \"./sac-spec.js\";\nimport { Server } from \"../rpc/index.js\";\n\n/**\n * Options for generating TypeScript bindings.\n */\nexport type GenerateOptions = {\n /**\n * The name used for the generated package and client class.\n * Should be in kebab-case (e.g., \"my-contract\").\n */\n contractName: string;\n};\n\n/**\n * The output of the binding generation process.\n *\n * Contains all generated TypeScript source files and configuration files\n * needed to create a standalone npm package for interacting with a Digital World contract.\n */\nexport type GeneratedBindings = {\n /** The index.ts barrel export file that re-exports Client and types */\n index: string;\n /** The types.ts file containing TypeScript interfaces for contract structs, enums, and unions */\n types: string;\n /** The client.ts file containing the generated Client class with typed methods */\n client: string;\n /** The package.json for the generated npm package */\n packageJson: string;\n /** The tsconfig.json for TypeScript compilation */\n tsConfig: string;\n /** The README.md with usage documentation */\n readme: string;\n /** The .gitignore file for the generated package */\n gitignore: string;\n};\n\n/**\n * Generates TypeScript bindings for Digital World smart contracts.\n *\n * This class creates fully-typed TypeScript client code from a contract's specification,\n * allowing developers to interact with Digital World smart contracts with full IDE support\n * and compile-time type checking.\n *\n * @example\n * ```ts\n * // Create from a local WASM file\n * const wasmBuffer = fs.readFileSync(\"./my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a contract deployed on the network\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC...XYZ\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a Spec object directly\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n */\nexport class BindingGenerator {\n private spec: Spec;\n\n /**\n * Private constructor - use static factory methods instead.\n *\n * @param spec - The parsed contract specification\n */\n private constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Creates a BindingGenerator from an existing Spec object.\n *\n * Use this when you already have a parsed contract specification,\n * such as from manually constructed spec entries or from another source.\n *\n * @param spec - The contract specification containing function and type definitions\n * @returns A new BindingGenerator instance\n *\n * @example\n * ```ts\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * ```\n */\n static fromSpec(spec: Spec): BindingGenerator {\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator from a WASM binary buffer.\n *\n * Parses the contract specification directly from the WASM file's custom section.\n * This is the most common method when working with locally compiled contracts.\n *\n * @param wasmBuffer - The raw WASM binary as a Buffer\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM file doesn't contain a valid contract spec\n *\n * @example\n * ```ts\n * const wasmBuffer = fs.readFileSync(\"./target/wasm32-unknown-unknown/release/my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * ```\n */\n static fromWasm(wasmBuffer: Buffer): BindingGenerator {\n const spec = new Spec(specFromWasm(wasmBuffer));\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator by fetching WASM from the network using its hash.\n *\n * Retrieves the WASM bytecode from Digital World RPC using the WASM hash,\n * then parses the contract specification from it. Useful when you know\n * the hash of an installed WASM but don't have the binary locally.\n *\n * @param wasmHash - The hex-encoded hash of the installed WASM blob\n * @param rpcServer - The Digital World RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM cannot be fetched or doesn't contain a valid spec\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromWasmHash(\n * \"a1b2c3...xyz\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * ```\n */\n static async fromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const wasm = await fetchFromWasmHash(wasmHash, rpcServer);\n if (wasm.type !== \"wasm\") {\n throw new Error(\"Fetched contract is not of type 'wasm'\");\n }\n return BindingGenerator.fromWasm(wasm.wasmBytes);\n }\n\n /**\n * Creates a BindingGenerator by fetching contract info from a deployed contract ID.\n *\n * Retrieves the contract's WASM from the network using the contract ID,\n * then parses the specification. If the contract is a Digital World Asset Contract (SAC),\n * returns a generator with the standard SAC specification.\n *\n * @param contractId - The contract ID (C... address) of the deployed contract\n * @param rpcServer - The Digital World RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the contract cannot be found or fetched\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC123...XYZ\",\n * rpcServer\n * );\n * ```\n */\n static async fromContractId(\n contractId: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const result = await fetchFromContractId(contractId, rpcServer);\n if (result.type === \"wasm\") {\n return BindingGenerator.fromWasm(result.wasmBytes);\n }\n // Digital World Asset Contract\n const spec = new Spec(SAC_SPEC);\n return BindingGenerator.fromSpec(spec);\n }\n\n /**\n * Generates TypeScript bindings for the contract.\n *\n * Produces all the files needed for a standalone npm package:\n * - `client.ts`: A typed Client class with methods for each contract function\n * - `types.ts`: TypeScript interfaces for all contract types (structs, enums, unions)\n * - `index.ts`: Barrel export file\n * - `package.json`, `tsconfig.json`, `README.md`, `.gitignore`: Package configuration\n *\n * The generated code does not write to disk - use the returned strings\n * to write files as needed.\n *\n * @param options - Configuration options for generation\n * - `contractName`: Required. The name for the generated package (kebab-case recommended)\n * @returns An object containing all generated file contents as strings\n * @throws If contractName is missing or empty\n *\n * @example\n * ```ts\n * const bindings = generator.generate({\n * contractName: \"my-token\",\n * contractAddress: \"CABC...XYZ\",\n * rpcUrl: \"https://soroban-testnet.stellar.org\",\n * networkPassphrase: Networks.TESTNET\n * });\n *\n * // Write files to disk\n * fs.writeFileSync(\"./src/client.ts\", bindings.client);\n * fs.writeFileSync(\"./src/types.ts\", bindings.types);\n * ```\n */\n generate(options: GenerateOptions): GeneratedBindings {\n this.validateOptions(options);\n\n const typeGenerator = new TypeGenerator(this.spec);\n const clientGenerator = new ClientGenerator(this.spec);\n\n const types = typeGenerator.generate();\n const client = clientGenerator.generate();\n\n let index = `export { Client } from \"./client.js\";`;\n if (types.trim() !== \"\") {\n index = index.concat(`\\nexport * from \"./types.js\";`);\n }\n\n // Generate config files\n const configGenerator = new ConfigGenerator();\n const { packageJson, tsConfig, readme, gitignore } =\n configGenerator.generate(options);\n\n return {\n index,\n types,\n client,\n packageJson,\n tsConfig,\n readme,\n gitignore,\n };\n }\n\n /**\n * Validates that required generation options are provided.\n *\n * @param options - The options to validate\n * @throws If contractName is missing or empty\n */\n private validateOptions(options: GenerateOptions): void {\n if (!options.contractName || options.contractName.trim() === \"\") {\n throw new Error(\"contractName is required and cannot be empty\");\n }\n }\n}\n"],"names":["spec","Spec","specFromWasm","fetchFromWasmHash","fetchFromContractId","SAC_SPEC","TypeGenerator","ClientGenerator","types","client","ConfigGenerator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EO,MAAM,gBAAA,CAAiB;AAAA,EACpB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,IAAA,EAAY;AAC9B,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,OAAO,SAAS,IAAA,EAA8B;AAC5C,IAAA,OAAO,IAAI,iBAAiB,IAAI,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,OAAO,SAAS,UAAA,EAAsC;AACpD,IAAA,MAAMA,MAAA,GAAO,IAAIC,SAAA,CAAKC,6BAAA,CAAa,UAA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SAAS,OAAA,EAA6C;AACpD,IAAA,IAAA,CAAK,gBAAgB,OAAO,CAAA;AAE5B,IAAA,MAAM,aAAA,GAAgB,IAAIM,mBAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACjD,IAAA,MAAM,eAAA,GAAkB,IAAIC,sBAAA,CAAgB,IAAA,CAAK,IAAI,CAAA;AAErD,IAAA,MAAMC,OAAA,GAAQ,cAAc,QAAA,EAAS;AACrC,IAAA,MAAMC,QAAA,GAAS,gBAAgB,QAAA,EAAS;AAExC,IAAA,IAAI,KAAA,GAAQ,CAAA,qCAAA,CAAA;AACZ,IAAA,IAAID,OAAA,CAAM,IAAA,EAAK,KAAM,EAAA,EAAI;AACvB,MAAA,KAAA,GAAQ,MAAM,MAAA,CAAO;AAAA,2BAAA,CAA+B,CAAA;AAAA,IACtD;AAGA,IAAA,MAAM,eAAA,GAAkB,IAAIE,sBAAA,EAAgB;AAC5C,IAAA,MAAM,EAAE,aAAa,QAAA,EAAU,MAAA,EAAQ,WAAU,GAC/C,eAAA,CAAgB,SAAS,OAAO,CAAA;AAElC,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,aACAF,OAAA;AAAA,cACAC,QAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,gBAAgB,OAAA,EAAgC;AACtD,IAAA,IAAI,CAAC,OAAA,CAAQ,YAAA,IAAgB,QAAQ,YAAA,CAAa,IAAA,OAAW,EAAA,EAAI;AAC/D,MAAA,MAAM,IAAI,MAAM,8CAA8C,CAAA;AAAA,IAChE;AAAA,EACF;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../../src/bindings/types.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport { Spec } from \"../contract/index.js\";\nimport {\n parseTypeFromTypeDef,\n generateTypeImports,\n sanitizeIdentifier,\n escapeStringLiteral,\n formatJSDocComment,\n formatImports,\n isTupleStruct,\n} from \"./utils.js\";\n\n/**\n * Interface for struct fields\n */\nexport interface StructField {\n doc: string;\n name: string;\n type: string;\n}\n\n/**\n * Interface for union cases\n */\nexport interface UnionCase {\n doc: string;\n name: string;\n types: string[];\n}\n\n/**\n * Interface for enum cases\n */\nexport interface EnumCase {\n doc: string;\n name: string;\n value: number;\n}\n\n/**\n * Generates TypeScript type definitions from Stellar contract specs\n */\nexport class TypeGenerator {\n private spec: Spec;\n\n constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Generate all TypeScript type definitions\n */\n generate(): string {\n // Generate types for each entry in the spec\n const types = this.spec.entries\n .map((entry) => this.generateEntry(entry))\n .filter((t) => t)\n .join(\"\\n\\n\");\n // Generate imports for all types\n const imports = this.generateImports();\n\n return `${imports}\n\n ${types}\n `;\n }\n\n /**\n * Generate TypeScript for a single spec entry\n */\n private generateEntry(entry: xdr.ScSpecEntry): string | null {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n if (isTupleStruct(entry.udtStructV0())) {\n return this.generateTupleStruct(entry.udtStructV0());\n }\n return this.generateStruct(entry.udtStructV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return this.generateUnion(entry.udtUnionV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n return this.generateEnum(entry.udtEnumV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n return this.generateErrorEnum(entry.udtErrorEnumV0());\n default:\n return null;\n }\n }\n\n private generateImports(): string {\n const imports = generateTypeImports(\n this.spec.entries.flatMap((entry) => {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n return entry\n .udtStructV0()\n .fields()\n .map((field) => field.type());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return entry\n .udtUnionV0()\n .cases()\n .flatMap((unionCase) => {\n if (\n unionCase.switch() ===\n xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0()\n ) {\n return unionCase.tupleCase().type();\n }\n return [];\n });\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n // Enums do not have associated types\n return [];\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n // Enums do not have associated types\n return [];\n default:\n return [];\n }\n }),\n );\n\n return formatImports(imports, {\n includeTypeFileImports: false, // Types file doesn't import from itself\n });\n }\n\n /**\n * Generate TypeScript interface for a struct\n */\n private generateStruct(struct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(struct.name().toString());\n const doc = formatJSDocComment(\n struct.doc().toString() || `Struct: ${name}`,\n 0,\n );\n\n const fields = struct\n .fields()\n .map((field) => {\n const fieldName = sanitizeIdentifier(field.name().toString());\n const fieldType = parseTypeFromTypeDef(field.type());\n const fieldDoc = formatJSDocComment(field.doc().toString(), 2);\n\n return `${fieldDoc} ${fieldName}: ${fieldType};`;\n })\n .join(\"\\n\");\n\n return `${doc}export interface ${name} {\n${fields}\n}`;\n }\n\n /**\n * Generate TypeScript union type\n */\n private generateUnion(union: xdr.ScSpecUdtUnionV0): string {\n const name = sanitizeIdentifier(union.name().toString());\n const doc = formatJSDocComment(\n union.doc().toString() || `Union: ${name}`,\n 0,\n );\n const cases = union\n .cases()\n .map((unionCase) => this.generateUnionCase(unionCase));\n\n const caseTypes = cases\n .map((c) => {\n if (c.types.length > 0) {\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: readonly [${c.types.join(\", \")}] }`;\n }\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: void }`;\n })\n .join(\" |\\n\");\n\n return `${doc} export type ${name} =\n${caseTypes};`;\n }\n\n /**\n * Generate TypeScript enum\n */\n private generateEnum(enumEntry: xdr.ScSpecUdtEnumV0): string {\n const name = sanitizeIdentifier(enumEntry.name().toString());\n const doc = formatJSDocComment(\n enumEntry.doc().toString() || `Enum: ${name}`,\n 0,\n );\n\n const members = enumEntry\n .cases()\n .map((enumCase) => {\n const caseName = sanitizeIdentifier(enumCase.name().toString());\n const caseValue = enumCase.value();\n const caseDoc = enumCase.doc().toString() || `Enum Case: ${caseName}`;\n\n return `${formatJSDocComment(caseDoc, 2)} ${caseName} = ${caseValue}`;\n })\n .join(\",\\n\");\n\n return `${doc}export enum ${name} {\n${members}\n}`;\n }\n\n /**\n * Generate TypeScript error enum\n */\n private generateErrorEnum(errorEnum: xdr.ScSpecUdtErrorEnumV0): string {\n const name = sanitizeIdentifier(errorEnum.name().toString());\n const doc = formatJSDocComment(\n errorEnum.doc().toString() || `Error Enum: ${name}`,\n 0,\n );\n const cases = errorEnum\n .cases()\n .map((enumCase) => this.generateEnumCase(enumCase));\n\n const members = cases\n .map((c) => {\n return `${formatJSDocComment(c.doc, 2)} ${c.value} : { message: \"${escapeStringLiteral(c.name)}\" }`;\n })\n .join(\",\\n\");\n\n return `${doc}export const ${name} = {\n${members}\n}`;\n }\n\n /**\n * Generate union case\n */\n private generateUnionCase(unionCase: xdr.ScSpecUdtUnionCaseV0): UnionCase {\n switch (unionCase.switch()) {\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseVoidV0(): {\n const voidCase = unionCase.voidCase();\n return {\n doc: voidCase.doc().toString(),\n name: voidCase.name().toString(),\n types: [],\n };\n }\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0(): {\n const tupleCase = unionCase.tupleCase();\n return {\n doc: tupleCase.doc().toString(),\n name: tupleCase.name().toString(),\n types: tupleCase.type().map((t) => parseTypeFromTypeDef(t)),\n };\n }\n default:\n throw new Error(`Unknown union case kind: ${unionCase.switch()}`);\n }\n }\n\n /**\n * Generate enum case\n */\n private generateEnumCase(enumCase: xdr.ScSpecUdtEnumCaseV0): EnumCase {\n return {\n doc: enumCase.doc().toString(),\n name: enumCase.name().toString(),\n value: enumCase.value(),\n };\n }\n\n private generateTupleStruct(udtStruct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(udtStruct.name().toString());\n const doc = formatJSDocComment(\n udtStruct.doc().toString() || `Tuple Struct: ${name}`,\n 0,\n );\n\n const types = udtStruct\n .fields()\n .map((field) => parseTypeFromTypeDef(field.type()))\n .join(\", \");\n\n return `${doc}export type ${name} = readonly [${types}];`;\n }\n}\n"],"names":["xdr","isTupleStruct","generateTypeImports","formatImports","sanitizeIdentifier","formatJSDocComment","parseTypeFromTypeDef","escapeStringLiteral"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAM,aAAA,CAAc;AAAA,EACjB,IAAA;AAAA,EAER,YAAY,IAAA,EAAY;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAAmB;AAEjB,IAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,CAAK,QACrB,GAAA,CAAI,CAAC,UAAU,IAAA,CAAK,aAAA,CAAc,KAAK,CAAC,EACxC,MAAA,CAAO,CAAC,MAAM,CAAC,CAAA,CACf,KAAK,MAAM,CAAA;AAEd,IAAA,MAAM,OAAA,GAAU,KAAK,eAAA,EAAgB;AAErC,IAAA,OAAO,GAAG,OAAO;;AAAA,IAAA,EAEf,KAAK;AAAA,IAAA,CAAA;AAAA,EAET;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAc,KAAA,EAAuC;AAC3D,IAAA,QAAQ,KAAA,CAAM,QAAO;AAAG,MACtB,KAAKA,sBAAA,CAAI,eAAA,CAAgB,sBAAA,EAAuB;AAC9C,QAAA,IAAIC,mBAAA,CAAc,KAAA,CAAM,WAAA,EAAa,CAAA,EAAG;AACtC,UAAA,OAAO,IAAA,CAAK,mBAAA,CAAoB,KAAA,CAAM,WAAA,EAAa,CAAA;AAAA,QACrD;AACA,QAAA,OAAO,IAAA,CAAK,cAAA,CAAe,KAAA,CAAM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,IAAA,OAAO;AAAA,MACL,GAAA,EAAK,QAAA,CAAS,GAAA,EAAI,CAAE,QAAA,EAAS;AAAA,MAC7B,IAAA,EAAM,QAAA,CAAS,IAAA,EAAK,CAAE,QAAA,EAAS;AAAA,MAC/B,KAAA,EAAO,SAAS,KAAA;AAAM,KACxB;AAAA,EACF;AAAA,EAEQ,oBAAoB,SAAA,EAA0C;AACpE,IAAA,MAAM,OAAOF,wBAAA,CAAmB,SAAA,CAAU,IAAA,EAAK,CAAE,UAAU,CAAA;AAC3D,IAAA,MAAM,GAAA,GAAMC,wBAAA;AAAA,MACV,UAAU,GAAA,EAAI,CAAE,QAAA,EAAS,IAAK,iBAAiB,IAAI,CAAA,CAAA;AAAA,MACnD;AAAA,KACF;AAEA,IAAA,MAAM,KAAA,GAAQ,SAAA,CACX,MAAA,EAAO,CACP,IAAI,CAAC,KAAA,KAAUC,0BAAA,CAAqB,KAAA,CAAM,IAAA,EAAM,CAAC,CAAA,CACjD,KAAK,IAAI,CAAA;AAEZ,IAAA,OAAO,CAAA,EAAG,GAAG,CAAA,YAAA,EAAe,IAAI,gBAAgB,KAAK,CAAA,EAAA,CAAA;AAAA,EACvD;AACF;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../../src/bindings/types.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport { Spec } from \"../contract/index.js\";\nimport {\n parseTypeFromTypeDef,\n generateTypeImports,\n sanitizeIdentifier,\n escapeStringLiteral,\n formatJSDocComment,\n formatImports,\n isTupleStruct,\n} from \"./utils.js\";\n\n/**\n * Interface for struct fields\n */\nexport interface StructField {\n doc: string;\n name: string;\n type: string;\n}\n\n/**\n * Interface for union cases\n */\nexport interface UnionCase {\n doc: string;\n name: string;\n types: string[];\n}\n\n/**\n * Interface for enum cases\n */\nexport interface EnumCase {\n doc: string;\n name: string;\n value: number;\n}\n\n/**\n * Generates TypeScript type definitions from Digital World contract specs\n */\nexport class TypeGenerator {\n private spec: Spec;\n\n constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Generate all TypeScript type definitions\n */\n generate(): string {\n // Generate types for each entry in the spec\n const types = this.spec.entries\n .map((entry) => this.generateEntry(entry))\n .filter((t) => t)\n .join(\"\\n\\n\");\n // Generate imports for all types\n const imports = this.generateImports();\n\n return `${imports}\n\n ${types}\n `;\n }\n\n /**\n * Generate TypeScript for a single spec entry\n */\n private generateEntry(entry: xdr.ScSpecEntry): string | null {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n if (isTupleStruct(entry.udtStructV0())) {\n return this.generateTupleStruct(entry.udtStructV0());\n }\n return this.generateStruct(entry.udtStructV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return this.generateUnion(entry.udtUnionV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n return this.generateEnum(entry.udtEnumV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n return this.generateErrorEnum(entry.udtErrorEnumV0());\n default:\n return null;\n }\n }\n\n private generateImports(): string {\n const imports = generateTypeImports(\n this.spec.entries.flatMap((entry) => {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n return entry\n .udtStructV0()\n .fields()\n .map((field) => field.type());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return entry\n .udtUnionV0()\n .cases()\n .flatMap((unionCase) => {\n if (\n unionCase.switch() ===\n xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0()\n ) {\n return unionCase.tupleCase().type();\n }\n return [];\n });\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n // Enums do not have associated types\n return [];\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n // Enums do not have associated types\n return [];\n default:\n return [];\n }\n }),\n );\n\n return formatImports(imports, {\n includeTypeFileImports: false, // Types file doesn't import from itself\n });\n }\n\n /**\n * Generate TypeScript interface for a struct\n */\n private generateStruct(struct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(struct.name().toString());\n const doc = formatJSDocComment(\n struct.doc().toString() || `Struct: ${name}`,\n 0,\n );\n\n const fields = struct\n .fields()\n .map((field) => {\n const fieldName = sanitizeIdentifier(field.name().toString());\n const fieldType = parseTypeFromTypeDef(field.type());\n const fieldDoc = formatJSDocComment(field.doc().toString(), 2);\n\n return `${fieldDoc} ${fieldName}: ${fieldType};`;\n })\n .join(\"\\n\");\n\n return `${doc}export interface ${name} {\n${fields}\n}`;\n }\n\n /**\n * Generate TypeScript union type\n */\n private generateUnion(union: xdr.ScSpecUdtUnionV0): string {\n const name = sanitizeIdentifier(union.name().toString());\n const doc = formatJSDocComment(\n union.doc().toString() || `Union: ${name}`,\n 0,\n );\n const cases = union\n .cases()\n .map((unionCase) => this.generateUnionCase(unionCase));\n\n const caseTypes = cases\n .map((c) => {\n if (c.types.length > 0) {\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: readonly [${c.types.join(\", \")}] }`;\n }\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: void }`;\n })\n .join(\" |\\n\");\n\n return `${doc} export type ${name} =\n${caseTypes};`;\n }\n\n /**\n * Generate TypeScript enum\n */\n private generateEnum(enumEntry: xdr.ScSpecUdtEnumV0): string {\n const name = sanitizeIdentifier(enumEntry.name().toString());\n const doc = formatJSDocComment(\n enumEntry.doc().toString() || `Enum: ${name}`,\n 0,\n );\n\n const members = enumEntry\n .cases()\n .map((enumCase) => {\n const caseName = sanitizeIdentifier(enumCase.name().toString());\n const caseValue = enumCase.value();\n const caseDoc = enumCase.doc().toString() || `Enum Case: ${caseName}`;\n\n return `${formatJSDocComment(caseDoc, 2)} ${caseName} = ${caseValue}`;\n })\n .join(\",\\n\");\n\n return `${doc}export enum ${name} {\n${members}\n}`;\n }\n\n /**\n * Generate TypeScript error enum\n */\n private generateErrorEnum(errorEnum: xdr.ScSpecUdtErrorEnumV0): string {\n const name = sanitizeIdentifier(errorEnum.name().toString());\n const doc = formatJSDocComment(\n errorEnum.doc().toString() || `Error Enum: ${name}`,\n 0,\n );\n const cases = errorEnum\n .cases()\n .map((enumCase) => this.generateEnumCase(enumCase));\n\n const members = cases\n .map((c) => {\n return `${formatJSDocComment(c.doc, 2)} ${c.value} : { message: \"${escapeStringLiteral(c.name)}\" }`;\n })\n .join(\",\\n\");\n\n return `${doc}export const ${name} = {\n${members}\n}`;\n }\n\n /**\n * Generate union case\n */\n private generateUnionCase(unionCase: xdr.ScSpecUdtUnionCaseV0): UnionCase {\n switch (unionCase.switch()) {\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseVoidV0(): {\n const voidCase = unionCase.voidCase();\n return {\n doc: voidCase.doc().toString(),\n name: voidCase.name().toString(),\n types: [],\n };\n }\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0(): {\n const tupleCase = unionCase.tupleCase();\n return {\n doc: tupleCase.doc().toString(),\n name: tupleCase.name().toString(),\n types: tupleCase.type().map((t) => parseTypeFromTypeDef(t)),\n };\n }\n default:\n throw new Error(`Unknown union case kind: ${unionCase.switch()}`);\n }\n }\n\n /**\n * Generate enum case\n */\n private generateEnumCase(enumCase: xdr.ScSpecUdtEnumCaseV0): EnumCase {\n return {\n doc: enumCase.doc().toString(),\n name: enumCase.name().toString(),\n value: enumCase.value(),\n };\n }\n\n private generateTupleStruct(udtStruct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(udtStruct.name().toString());\n const doc = formatJSDocComment(\n udtStruct.doc().toString() || `Tuple Struct: ${name}`,\n 0,\n );\n\n const types = udtStruct\n .fields()\n .map((field) => parseTypeFromTypeDef(field.type()))\n .join(\", \");\n\n return `${doc}export type ${name} = readonly [${types}];`;\n }\n}\n"],"names":["xdr","isTupleStruct","generateTypeImports","formatImports","sanitizeIdentifier","formatJSDocComment","parseTypeFromTyp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AM,GAAA,GAAMC,wBAAA;AAAA,MACV,UAAU,GAAA,EAAI,CAAE,QAAA,EAAS,IAAK,iBAAiB,IAAI,CAAA,CAAA;AAAA,MACnD;AAAA,KACF;AAEA,IAAA,MAAM,KAAA,GAAQ,SAAA,CACX,MAAA,EAAO,CACP,IAAI,CAAC,KAAA,KAAUC,0BAAA,CAAqB,KAAA,CAAM,IAAA,EAAM,CAAC,CAAA,CACjD,KAAK,IAAI,CAAA;AAEZ,IAAA,OAAO,CAAA,EAAG,GAAG,CAAA,YAAA,EAAe,IAAI,gBAAgB,KAAK,CAAA,EAAA,CAAA;AAAA,EACvD;AACF;;;;"}
@@ -272,13 +272,13 @@ function formatImports(imports, options) {
272
272
  if (stellarContractImports.length > 0) {
273
273
  const uniqueContractImports = Array.from(new Set(stellarContractImports));
274
274
  importLines.push(
275
- `import {${uniqueContractImports.join(", ")}} from '@stellar/stellar-sdk/contract';`
275
+ `import {${uniqueContractImports.join(", ")}} from '@digitalworld/digital-world-sdk/contract';`
276
276
  );
277
277
  }
278
278
  if (stellarImports.length > 0) {
279
279
  const uniqueStellarImports = Array.from(new Set(stellarImports));
280
280
  importLines.push(
281
- `import {${uniqueStellarImports.join(", ")}} from '@stellar/stellar-sdk';`
281
+ `import {${uniqueStellarImports.join(", ")}} from '@digitalworld/digital-world-sdk';`
282
282
  );
283
283
  }
284
284
  if (imports.needsBufferImport) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/bindings/utils.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nexport function isNameReserved(name: string): boolean {\n const reservedNames = [\n // Keywords\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"export\",\n \"extends\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n // Future reserved words\n \"enum\",\n // Strict mode reserved words\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n // Contextual keywords\n \"async\",\n \"await\",\n \"constructor\",\n // Literals\n \"null\",\n \"true\",\n \"false\",\n ];\n return reservedNames.includes(name);\n}\n/**\n * Sanitize a name to avoid reserved keywords\n * @param identifier - The identifier to sanitize\n * @returns The sanitized identifier\n */\nexport function sanitizeIdentifier(identifier: string): string {\n // Strip any characters outside the ASCII identifier-safe set [a-zA-Z0-9_$]\n const sanitized = identifier.replace(/[^a-zA-Z0-9_$]/g, \"_\");\n\n if (isNameReserved(sanitized)) {\n return sanitized + \"_\";\n }\n\n if (/^\\d/.test(sanitized)) {\n return \"_\" + sanitized;\n }\n\n // If the identifier was entirely special characters, provide a fallback\n if (sanitized === \"\" || /^_+$/.test(sanitized)) {\n return \"_unnamed\";\n }\n\n return sanitized;\n}\n\n/**\n * Escape a string for safe interpolation inside a double-quoted JavaScript string literal.\n */\nexport function escapeStringLiteral(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\n\n/**\n * Generate TypeScript type from XDR type definition\n */\nexport function parseTypeFromTypeDef(\n typeDef: xdr.ScSpecTypeDef,\n isFunctionInput = false,\n): string {\n switch (typeDef.switch()) {\n case xdr.ScSpecType.scSpecTypeVal():\n return \"any\";\n case xdr.ScSpecType.scSpecTypeBool():\n return \"boolean\";\n case xdr.ScSpecType.scSpecTypeVoid():\n return \"null\";\n case xdr.ScSpecType.scSpecTypeError():\n return \"Error\";\n case xdr.ScSpecType.scSpecTypeU32():\n case xdr.ScSpecType.scSpecTypeI32():\n return \"number\";\n case xdr.ScSpecType.scSpecTypeU64():\n case xdr.ScSpecType.scSpecTypeI64():\n case xdr.ScSpecType.scSpecTypeTimepoint():\n case xdr.ScSpecType.scSpecTypeDuration():\n case xdr.ScSpecType.scSpecTypeU128():\n case xdr.ScSpecType.scSpecTypeI128():\n case xdr.ScSpecType.scSpecTypeU256():\n case xdr.ScSpecType.scSpecTypeI256():\n return \"bigint\";\n case xdr.ScSpecType.scSpecTypeBytes():\n case xdr.ScSpecType.scSpecTypeBytesN():\n return \"Buffer\";\n case xdr.ScSpecType.scSpecTypeString():\n return \"string\";\n case xdr.ScSpecType.scSpecTypeSymbol():\n return \"string\";\n case xdr.ScSpecType.scSpecTypeAddress():\n case xdr.ScSpecType.scSpecTypeMuxedAddress(): {\n // function inputs can accept either string or Address\n if (isFunctionInput) {\n return \"string | Address\";\n }\n // Otherwise for backward compatibility use string\n return \"string\";\n }\n case xdr.ScSpecType.scSpecTypeVec(): {\n const vecType = parseTypeFromTypeDef(\n typeDef.vec().elementType(),\n isFunctionInput,\n );\n return `Array<${vecType}>`;\n }\n case xdr.ScSpecType.scSpecTypeMap(): {\n const keyType = parseTypeFromTypeDef(\n typeDef.map().keyType(),\n isFunctionInput,\n );\n const valueType = parseTypeFromTypeDef(\n typeDef.map().valueType(),\n isFunctionInput,\n );\n return `Map<${keyType}, ${valueType}>`;\n }\n case xdr.ScSpecType.scSpecTypeTuple(): {\n const tupleTypes = typeDef\n .tuple()\n .valueTypes()\n .map((t: xdr.ScSpecTypeDef) =>\n parseTypeFromTypeDef(t, isFunctionInput),\n );\n return `[${tupleTypes.join(\", \")}]`;\n }\n case xdr.ScSpecType.scSpecTypeOption(): {\n // Handle nested options\n while (\n typeDef.option().valueType().switch() ===\n xdr.ScSpecType.scSpecTypeOption()\n ) {\n typeDef = typeDef.option().valueType();\n }\n const optionType = parseTypeFromTypeDef(\n typeDef.option().valueType(),\n isFunctionInput,\n );\n\n return `${optionType} | null`;\n }\n case xdr.ScSpecType.scSpecTypeResult(): {\n const okType = parseTypeFromTypeDef(\n typeDef.result().okType(),\n isFunctionInput,\n );\n const errorType = parseTypeFromTypeDef(\n typeDef.result().errorType(),\n isFunctionInput,\n );\n return `Result<${okType}, ${errorType}>`;\n }\n case xdr.ScSpecType.scSpecTypeUdt(): {\n const udtName = sanitizeIdentifier(typeDef.udt().name().toString());\n return udtName;\n }\n default:\n return \"unknown\";\n }\n}\n\n/**\n * Imports needed for generating bindings\n */\nexport interface BindingImports {\n /** Imports needed from type definitions */\n typeFileImports: Set<string>;\n /** Imports needed from the Stellar SDK in the contract namespace */\n stellarContractImports: Set<string>;\n /** Imports needed from Stellar SDK in the global namespace */\n stellarImports: Set<string>;\n /** Whether Buffer import is needed */\n needsBufferImport: boolean;\n}\n\n/**\n * Extract nested type definitions from container types\n */\nfunction extractNestedTypes(typeDef: xdr.ScSpecTypeDef): xdr.ScSpecTypeDef[] {\n switch (typeDef.switch()) {\n case xdr.ScSpecType.scSpecTypeVec():\n return [typeDef.vec().elementType()];\n\n case xdr.ScSpecType.scSpecTypeMap():\n return [typeDef.map().keyType(), typeDef.map().valueType()];\n\n case xdr.ScSpecType.scSpecTypeTuple():\n return typeDef.tuple().valueTypes();\n\n case xdr.ScSpecType.scSpecTypeOption():\n return [typeDef.option().valueType()];\n\n case xdr.ScSpecType.scSpecTypeResult():\n return [typeDef.result().okType(), typeDef.result().errorType()];\n\n default:\n return [];\n }\n}\n\n/**\n * Visitor to collect imports from a single type definition\n */\nfunction visitTypeDef(\n typeDef: xdr.ScSpecTypeDef,\n accumulator: BindingImports,\n): void {\n const typeSwitch = typeDef.switch();\n\n // Handle leaf types (no nested types)\n switch (typeSwitch) {\n case xdr.ScSpecType.scSpecTypeUdt():\n accumulator.typeFileImports.add(\n sanitizeIdentifier(typeDef.udt().name().toString()),\n );\n return;\n\n case xdr.ScSpecType.scSpecTypeAddress():\n case xdr.ScSpecType.scSpecTypeMuxedAddress():\n accumulator.stellarImports.add(\"Address\");\n return;\n\n case xdr.ScSpecType.scSpecTypeBytes():\n case xdr.ScSpecType.scSpecTypeBytesN():\n accumulator.needsBufferImport = true;\n return;\n\n case xdr.ScSpecType.scSpecTypeVal():\n accumulator.stellarImports.add(\"xdr\");\n return;\n\n case xdr.ScSpecType.scSpecTypeResult():\n accumulator.stellarContractImports.add(\"Result\");\n // Fall through to handle nested types\n break;\n\n // Primitive types that need no imports\n case xdr.ScSpecType.scSpecTypeBool():\n case xdr.ScSpecType.scSpecTypeVoid():\n case xdr.ScSpecType.scSpecTypeError():\n case xdr.ScSpecType.scSpecTypeU32():\n case xdr.ScSpecType.scSpecTypeI32():\n case xdr.ScSpecType.scSpecTypeU64():\n case xdr.ScSpecType.scSpecTypeI64():\n case xdr.ScSpecType.scSpecTypeTimepoint():\n case xdr.ScSpecType.scSpecTypeDuration():\n case xdr.ScSpecType.scSpecTypeU128():\n case xdr.ScSpecType.scSpecTypeI128():\n case xdr.ScSpecType.scSpecTypeU256():\n case xdr.ScSpecType.scSpecTypeI256():\n case xdr.ScSpecType.scSpecTypeString():\n case xdr.ScSpecType.scSpecTypeSymbol():\n return;\n }\n\n // Handle container types (have nested types)\n const nestedTypes = extractNestedTypes(typeDef);\n nestedTypes.forEach((nested) => visitTypeDef(nested, accumulator));\n}\n\n/**\n * Generate imports needed for a list of type definitions\n */\nexport function generateTypeImports(\n typeDefs: xdr.ScSpecTypeDef[],\n): BindingImports {\n const imports: BindingImports = {\n typeFileImports: new Set<string>(),\n stellarContractImports: new Set<string>(),\n stellarImports: new Set<string>(),\n needsBufferImport: false,\n };\n\n // Visit each type definition\n typeDefs.forEach((typeDef) => visitTypeDef(typeDef, imports));\n\n return imports;\n}\n\n/**\n * Options for formatting imports\n */\nexport interface FormatImportsOptions {\n /** Whether to include imports from types.ts */\n includeTypeFileImports?: boolean;\n /** Additional imports needed from stellar/stellar-sdk/contract */\n additionalStellarContractImports?: string[];\n /** Additional imports needed from stellar/stellar-sdk */\n additionalStellarImports?: string[];\n}\n\n/**\n * Format imports into import statement strings\n */\nexport function formatImports(\n imports: BindingImports,\n options?: FormatImportsOptions,\n): string {\n const importLines: string[] = [];\n\n const typeFileImports = imports.typeFileImports;\n const stellarContractImports = [\n ...imports.stellarContractImports,\n ...(options?.additionalStellarContractImports || []),\n ];\n const stellarImports = [\n ...imports.stellarImports,\n ...(options?.additionalStellarImports || []),\n ];\n // Type file imports (only if enabled)\n if (options?.includeTypeFileImports && typeFileImports.size > 0) {\n importLines.push(\n `import {${Array.from(typeFileImports).join(\", \")}} from './types.js';`,\n );\n }\n\n // Stellar contract imports\n if (stellarContractImports.length > 0) {\n const uniqueContractImports = Array.from(new Set(stellarContractImports));\n importLines.push(\n `import {${uniqueContractImports.join(\", \")}} from '@stellar/stellar-sdk/contract';`,\n );\n }\n\n // Stellar SDK imports\n if (stellarImports.length > 0) {\n const uniqueStellarImports = Array.from(new Set(stellarImports));\n importLines.push(\n `import {${uniqueStellarImports.join(\", \")}} from '@stellar/stellar-sdk';`,\n );\n }\n\n // Buffer import\n if (imports.needsBufferImport) {\n importLines.push(`import { Buffer } from 'buffer';`);\n }\n\n return importLines.join(\"\\n\");\n}\n\n/**\n * Escape special characters in JSDoc comment content\n */\nfunction escapeJSDocContent(text: string): string {\n return (\n text\n // Escape closing comment sequences that would break the JSDoc block\n .replace(/\\*\\//g, \"* /\")\n // Escape @ symbols at word boundaries to prevent accidental JSDoc tags\n // We allow common JSDoc tags to pass through\n .replace(\n /@(?!(param|returns?|type|throws?|example|deprecated|see|link|since|author|version|description|summary)\\b)/g,\n \"\\\\@\",\n )\n );\n}\n\n/**\n * Format a comment string as JSDoc with proper escaping\n */\nexport function formatJSDocComment(comment: string, indentLevel = 0): string {\n if (comment.trim() === \"\") {\n return \"\";\n }\n const indent = \" \".repeat(indentLevel);\n\n // Escape special characters and split into lines\n const escapedComment = escapeJSDocContent(comment);\n const lines = escapedComment\n .split(\"\\n\")\n .map((line) => `${indent} * ${line}`.trimEnd());\n\n return `${indent}/**\\n${lines.join(\"\\n\")}\\n${indent} */\\n`;\n}\n\nexport function isTupleStruct(udtStruct: xdr.ScSpecUdtStructV0): boolean {\n const fields = udtStruct.fields();\n // A tuple struct has unnamed fields\n return fields.every(\n (field, index) => field.name().toString().trim() === index.toString(),\n );\n}\n"],"names":["xdr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACO,SAAS,eAAe,IAAA,EAAuB;AACpD,EAAA,MAAM,aAAA,GAAgB;AAAA;AAAA,IAEpB,OAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,YAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA;AAAA,IAEA,MAAA;AAAA;AAAA,IAEA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA;AAAA,IAEA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,aAAA;AAAA;AAAA,IAEA,MAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,aAAA,CAAc,SAAS,IAAI,CAAA;AACpC;AAMO,SAAS,mBAAmB,UAAA,EAA4B;AAE7D,EAAA,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7B,IAAA,WAAA,CAAY,KAAK,CAAA,gCAAA,CAAkC,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,WAAA,CAAY,KAAK,IAAI,CAAA;AAC9B;AAKA,SAAS,mBAAmB,IAAA,EAAsB;AAChD,EAAA,OACE,IAAA,CAEG,OAAA,CAAQ,OAAA,EAAS,KAAK,CAAA,CAGtB,OAAA;AAAA,IACC,4GAAA;AAAA,IACA;AAAA,GACF;AAEN;AAKO,SAAS,kBAAA,CAAmB,OAAA,EAAiB,WAAA,GAAc,CAAA,EAAW;AAC3E,EAAA,IAAI,OAAA,CAAQ,IAAA,EAAK,KAAM,EAAA,EAAI;AACzB,IAAA,OAAO,EAAA;AAAA,EACT;AACA,EAAA,MAAM,MAAA,GAAS,GAAA,CAAI,MAAA,CAAO,WAAW,CAAA;AAGrC,EAAA,MAAM,cAAA,GAAiB,mBAAmB,OAAO,CAAA;AACjD,EAAA,MAAM,KAAA,GAAQ,cAAA,CACX,KAAA,CAAM,IAAI,EACV,GAAA,CAAI,CAAC,IAAA,KAAS,CAAA,EAAG,MAAM,CAAA,GAAA,EAAM,IAAI,CAAA,CAAA,CAAG,SAAS,CAAA;AAEhD,EAAA,OAAO,GAAG,MAAM,CAAA;AAAA,EAAQ,KAAA,CAAM,IAAA,CAAK,IAAI,CAAC;AAAA,EAAK,MAAM,CAAA;AAAA,CAAA;AACrD;AAEO,SAAS,cAAc,SAAA,EAA2C;AACvE,EAAA,MAAM,MAAA,GAAS,UAAU,MAAA,EAAO;AAEhC,EAAA,OAAO,MAAA,CAAO,KAAA;AAAA,IACZ,CAAC,KAAA,EAAO,KAAA,KAAU,KAAA,CAAM,IAAA,EAAK,CAAE,QAAA,EAAS,CAAE,IAAA,EAAK,KAAM,KAAA,CAAM,QAAA;AAAS,GACtE;AACF;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/bindings/utils.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nexport function isNameReserved(name: string): boolean {\n const reservedNames = [\n // Keywords\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"export\",\n \"extends\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n // Future reserved words\n \"enum\",\n // Strict mode reserved words\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n // Contextual keywords\n \"async\",\n \"await\",\n \"constructor\",\n // Literals\n \"null\",\n \"true\",\n \"false\",\n ];\n return reservedNames.includes(name);\n}\n/**\n * Sanitize a name to avoid reserved keywords\n * @param identifier - The identifier to sanitize\n * @returns The sanitized identifier\n */\nexport function sanitizeIdentifier(identifier: string): string {\n // Strip any characters outside the ASCII identifier-safe set [a-zA-Z0-9_$]\n const sanitized = identifier.replace(/[^a-zA-Z0-9_$]/g, \"_\");\n\n if (isNameReserved(sanitized)) {\n return sanitized + \"_\";\n }\n\n if (/^\\d/.test(sanitized)) {\n return \"_\" + sanitized;\n }\n\n // If the identifier was entirely special characters, provide a fallback\n if (sanitized === \"\" || /^_+$/.test(sanitized)) {\n return \"_unnamed\";\n }\n\n return sanitized;\n}\n\n/**\n * Escape a string for safe interpolation inside a double-quoted JavaScript string literal.\n */\nexport function escapeStringLiteral(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\n\n/**\n * Generate TypeScript type from XDR type definition\n */\nexport function parseTypeFromTypeDef(\n typeDef: xdr.ScSpecTypeDef,\n isFunctionInput = false,\n): string {\n switch (typeDef.switch()) {\n case xdr.ScSpecType.scSpecTypeVal():\n return \"any\";\n case xdr.ScSpecType.scSpecTypeBool():\n return \"boolean\";\n case xdr.ScSpecType.scSpecTypeVoid():\n return \"null\";\n case xdr.ScSpecType.scSpecTypeError():\n return \"Error\";\n case xdr.ScSpecType.scSpecTypeU32():\n case xdr.ScSpecType.scSpecTypeI32():\n return \"number\";\n case xdr.ScSpecType.scSpecTypeU64():\n case xdr.ScSpecType.scSpecTypeI64():\n case xdr.ScSpecType.scSpecTypeTimepoint():\n case xdr.ScSpecType.scSpecTypeDuration():\n case xdr.ScSpecType.scSpecTypeU128():\n case xdr.ScSpecType.scSpecTypeI128():\n case xdr.ScSpecType.scSpecTypeU256():\n case xdr.ScSpecType.scSpecTypeI256():\n return \"bigint\";\n case xdr.ScSpecType.scSpecTypeBytes():\n case xdr.ScSpecType.scSpecTypeBytesN():\n return \"Buffer\";\n case xdr.ScSpecType.scSpecTypeString():\n return \"string\";\n case xdr.ScSpecType.scSpecTypeSymbol():\n return \"string\";\n case xdr.ScSpecType.scSpecTypeAddress():\n case xdr.ScSpecType.scSpecTypeMuxedAddress(): {\n // function inputs can accept either string or Address\n if (isFunctionInput) {\n return \"string | Address\";\n }\n // Otherwise for backward compatibility use string\n return \"string\";\n }\n case xdr.ScSpecType.scSpecTypeVec(): {\n const vecType = parseTypeFromTypeDef(\n typeDef.vec().elementType(),\n isFunctionInput,\n );\n return `Array<${vecType}>`;\n }\n case xdr.ScSpecType.scSpecTypeMap(): {\n const keyType = parseTypeFromTypeDef(\n typeDef.map().keyType(),\n isFunctionInput,\n );\n const valueType = parseTypeFromTypeDef(\n typeDef.map().valueType(),\n isFunctionInput,\n );\n return `Map<${keyType}, ${valueType}>`;\n }\n case xdr.ScSpecType.scSpecTypeTuple(): {\n const tupleTypes = typeDef\n .tuple()\n .valueTypes()\n .map((t: xdr.ScSpecTypeDef) =>\n parseTypeFromTypeDef(t, isFunctionInput),\n );\n return `[${tupleTypes.join(\", \")}]`;\n }\n case xdr.ScSpecType.scSpecTypeOption(): {\n // Handle nested options\n while (\n typeDef.option().valueType().switch() ===\n xdr.ScSpecType.scSpecTypeOption()\n ) {\n typeDef = typeDef.option().valueType();\n }\n const optionType = parseTypeFromTypeDef(\n typeDef.option().valueType(),\n isFunctionInput,\n );\n\n return `${optionType} | null`;\n }\n case xdr.ScSpecType.scSpecTypeResult(): {\n const okType = parseTypeFromTypeDef(\n typeDef.result().okType(),\n isFunctionInput,\n );\n const errorType = parseTypeFromTypeDef(\n typeDef.result().errorType(),\n isFunctionInput,\n );\n return `Result<${okType}, ${errorType}>`;\n }\n case xdr.ScSpecType.scSpecTypeUdt(): {\n const udtName = sanitizeIdentifier(typeDef.udt().name().toString());\n return udtName;\n }\n default:\n return \"unknown\";\n }\n}\n\n/**\n * Imports needed for generating bindings\n */\nexport interface BindingImports {\n /** Imports needed from type definitions */\n typeFileImports: Set<string>;\n /** Imports needed from the Digital World SDK in the contract namespace */\n stellarContractImports: Set<string>;\n /** Imports needed from Digital World SDK in the global namespace */\n stellarImports: Set<string>;\n /** Whether Buffer import is needed */\n needsBufferImport: boolean;\n}\n\n/**\n * Extract nested type definitions from container types\n */\nfunction extractNestedTypes(typeDef: xdr.ScSpecTypeDef): xdr.ScSpecTypeDef[] {\n switch (typeDef.switch()) {\n case xdr.ScSpecType.scSpecTypeVec():\n return [typeDef.vec().elementType()];\n\n case xdr.ScSpecType.scSpecTypeMap():\n return [typeDef.map().keyType(), typeDef.map().valueType()];\n\n case xdr.ScSpecType.scSpecTypeTuple():\n return typeDef.tuple().valueTypes();\n\n case xdr.ScSpecType.scSpecTypeOption():\n return [typeDef.option().valueType()];\n\n case xdr.ScSpecType.scSpecTypeResult():\n return [typeDef.result().okType(), typeDef.result().errorType()];\n\n default:\n return [];\n }\n}\n\n/**\n * Visitor to collect imports from a single type definition\n */\nfunction visitTypeDef(\n typeDef: xdr.ScSpecTypeDef,\n accumulator: BindingImports,\n): void {\n const typeSwitch = typeDef.switch();\n\n // Handle leaf types (no nested types)\n switch (typeSwitch) {\n case xdr.ScSpecType.scSpecTypeUdt():\n accumulator.typeFileImports.add(\n sanitizeIdentifier(typeDef.udt().name().toString()),\n );\n return;\n\n case xdr.ScSpecType.scSpecTypeAddress():\n case xdr.ScSpecType.scSpecTypeMuxedAddress():\n accumulator.stellarImports.add(\"Address\");\n return;\n\n case xdr.ScSpecType.scSpecTypeBytes():\n case xdr.ScSpecType.scSpecTypeBytesN():\n accumulator.needsBufferImport = true;\n return;\n\n case xdr.ScSpecType.scSpecTypeVal():\n accumulator.stellarImports.add(\"xdr\");\n return;\n\n case xdr.ScSpecType.scSpecTypeResult():\n accumulator.stellarContractImports.add(\"Result\");\n // Fall through to handle nested types\n break;\n\n // Primitive types that need no imports\n case xdr.ScSpecType.scSpecTypeBool():\n case xdr.ScSpecType.scSpecTypeVoid():\n case xdr.ScSpecType.scSpecTypeError():\n case xdr.ScSpecType.scSpecTypeU32():\n case xdr.ScSpecType.scSpecTypeI32():\n case xdr.ScSpecType.scSpecTypeU64():\n case xdr.ScSpecType.scSpecTypeI64():\n case xdr.ScSpecType.scSpecTypeTimepoint():\n case xdr.ScSpecType.scSpecTypeDuration():\n case xdr.ScSpecType.scSpecTypeU128():\n case xdr.ScSpecType.scSpecTypeI128():\n case xdr.ScSpecType.scSpecTypeU256():\n case xdr.ScSpecType.scSpecTypeI256():\n case xdr.ScSpecType.scSpecTypeString():\n case xdr.ScSpecType.scSpecTypeSymbol():\n return;\n }\n\n // Handle container types (have nested types)\n const nestedTypes = extractNestedTypes(typeDef);\n nestedTypes.forEach((nested) => visitTypeDef(nested, accumulator));\n}\n\n/**\n * Generate imports needed for a list of type definitions\n */\nexport function generateTypeImports(\n typeDefs: xdr.ScSpecTypeDef[],\n): BindingImports {\n const imports: BindingImports = {\n typeFileImports: new Set<string>(),\n stellarContractImports: new Set<string>(),\n stellarImports: new Set<string>(),\n needsBufferImport: false,\n };\n\n // Visit each type definition\n typeDefs.forEach((typeDef) => visitTypeDef(typeDef, imports));\n\n return imports;\n}\n\n/**\n * Options for formatting imports\n */\nexport interface FormatImportsOptions {\n /** Whether to include imports from types.ts */\n includeTypeFileImports?: boolean;\n /** Additional imports needed from digital-world-sdk/contract */\n additionalStellarContractImports?: string[];\n /** Additional imports needed from digital-world-sdk */\n additionalStellarImports?: string[];\n}\n\n/**\n * Format imports into import statement strings\n */\nexport function formatImports(\n imports: BindingImports,\n options?: FormatImportsOptions,\n): string {\n const importLines: string[] = [];\n\n const typeFileImports = imports.typeFileImports;\n const stellarContractImports = [\n ...imports.stellarContractImports,\n ...(options?.additionalStellarContractImports || []),\n ];\n const stellarImports = [\n ...imports.stellarImports,\n ...(options?.additionalStellarImports || []),\n ];\n // Type file imports (only if enabled)\n if (options?.includeTypeFileImports && typeFileImports.size > 0) {\n importLines.push(\n `import {${Array.from(typeFileImports).join(\", \")}} from './types.js';`,\n );\n }\n\n // Digital World contract imports\n if (stellarContractImports.length > 0) {\n const uniqueContractImports = Array.from(new Set(stellarContractImports));\n importLines.push(\n `import {${uniqueContractImports.join(\", \")}} from '@digitalworld/digital-world-sdk/contract';`,\n );\n }\n\n // Digital World SDK imports\n if (stellarImports.length > 0) {\n const uniqueStellarImports = Array.from(new Set(stellarImports));\n importLines.push(\n `import {${uniqueStellarImports.join(\", \")}} from '@digitalworld/digital-world-sdk';`,\n );\n }\n\n // Buffer import\n if (imports.needsBufferImport) {\n importLines.push(`import { Buffer } from 'buffer';`);\n }\n\n return importLines.join(\"\\n\");\n}\n\n/**\n * Escape special characters in JSDoc comment content\n */\nfunction escapeJSDocContent(text: string): string {\n return (\n text\n // Escape closing comment sequences that would break the JSDoc block\n .replace(/\\*\\//g, \"* /\")\n // Escape @ symbols at word boundaries to prevent accidental JSDoc tags\n // We allow common JSDoc tags to pass through\n .replace(\n /@(?!(param|returns?|type|throws?|example|deprecated|see|link|since|author|version|description|summary)\\b)/g,\n \"\\\\@\",\n )\n );\n}\n\n/**\n * Format a comment string as JSDoc with proper escaping\n */\nexport function formatJSDocComment(comment: string, indentLevel = 0): string {\n if (comment.trim() === \"\") {\n return \"\";\n }\n const indent = \" \".repeat(indentLevel);\n\n // Escape special characters and split into lines\n const escapedComment = escapeJSDocContent(comment);\n const lines = escapedComment\n .split(\"\\n\")\n .map((line) => `${indent} * ${line}`.trimEnd());\n\n return `${indent}/**\\n${lines.join(\"\\n\")}\\n${indent} */\\n`;\n}\n\nexport function isTupleStruct(udtStruct: xdr.ScSpecUdtStructV0): boolean {\n const fields = udtStruct.fields();\n // A tuple struct has unnamed fields\n return fields.every(\n (field, index) => field.name().toString().trim() === index.toString(),\n );\n}\n"],"names":["xdr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACO,SAAS,eAAe,IAAA,EAAuB;AACpD,EAAA,MAAM,aAAA,GAAgB;AAAA;AAAA,IAEpB,OAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,YAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA;AAAA,IAEA,MAAA;AAAA;AAAA,IAEA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA,WAAA;A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ACZ,CAAC,KAAA,EAAO,KAAA,KAAU,KAAA,CAAM,IAAA,EAAK,CAAE,QAAA,EAAS,CAAE,IAAA,EAAK,KAAM,KAAA,CAAM,QAAA;AAAS,GACtE;AACF;;;;;;;;;;;"}
@@ -55,7 +55,7 @@ async function getRemoteWasmFromHash(server, hashBuffer) {
55
55
  throw new WasmFetchError("Failed to fetch WASM from hash", error);
56
56
  }
57
57
  }
58
- function isStellarAssetContract(instance) {
58
+ function isDigitalWorldAssetContract(instance) {
59
59
  return instance.executable().switch() === curr_generated.default.ContractExecutableType.contractExecutableStellarAsset();
60
60
  }
61
61
  async function fetchWasmFromContract(server, contractAddress) {
@@ -71,7 +71,7 @@ async function fetchWasmFromContract(server, contractAddress) {
71
71
  }
72
72
  const contractData = entry.val.contractData();
73
73
  const instance = contractData.val().instance();
74
- if (isStellarAssetContract(instance)) {
74
+ if (isDigitalWorldAssetContract(instance)) {
75
75
  return { type: "stellar-asset-contract" };
76
76
  }
77
77
  const wasmHash = instance.executable().wasmHash();
@@ -1 +1 @@
1
- {"version":3,"file":"wasm_fetcher.js","sources":["../../../../src/bindings/wasm_fetcher.ts"],"sourcesContent":["import { Address, Contract, StrKey, xdr } from \"../base/index.js\";\nimport { Server } from \"../rpc/index.js\";\n\nimport { RpcServer } from \"../rpc/server.js\";\n\n/**\n * Types of contract data that can be fetched\n */\nexport type ContractData =\n | { type: \"wasm\"; wasmBytes: Buffer }\n | { type: \"stellar-asset-contract\" };\n\n/**\n * Errors that can occur during WASM fetching\n */\nexport class WasmFetchError extends Error {\n constructor(\n message: string,\n public readonly cause?: Error,\n ) {\n super(message);\n this.name = \"WasmFetchError\";\n }\n}\n\n/**\n * Get WASM bytes from a WASM hash on the network\n */\nasync function getRemoteWasmFromHash(\n server: RpcServer,\n hashBuffer: Buffer,\n): Promise<Buffer> {\n try {\n // Create the ledger key for the contract code\n const contractCodeKey = xdr.LedgerKey.contractCode(\n new xdr.LedgerKeyContractCode({\n hash: xdr.Hash.fromXDR(hashBuffer, \"raw\"),\n }),\n );\n\n // Get the ledger entries\n const response = await server.getLedgerEntries(contractCodeKey);\n\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"WASM not found for the given hash\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractCode()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractCode = entry.val.contractCode();\n return Buffer.from(contractCode.code());\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\"Failed to fetch WASM from hash\", error as Error);\n }\n}\n\n/**\n * Check if a contract is a Stellar Asset Contract\n */\nfunction isStellarAssetContract(instance: xdr.ScContractInstance): boolean {\n // Check if it's a Stellar Asset Contract (has no WASM hash)\n return (\n instance.executable().switch() ===\n xdr.ContractExecutableType.contractExecutableStellarAsset()\n );\n}\n\n/**\n * Fetch WASM bytes from a deployed contract\n */\nasync function fetchWasmFromContract(\n server: RpcServer,\n contractAddress: Address,\n): Promise<ContractData> {\n try {\n const contract = new Contract(contractAddress.toString());\n\n const response = await server.getLedgerEntries(contract.getFootprint());\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"Contract instance not found\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractData()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractData = entry.val.contractData();\n const instance = contractData.val().instance();\n\n if (isStellarAssetContract(instance)) {\n return { type: \"stellar-asset-contract\" };\n }\n\n const wasmHash = instance.executable().wasmHash();\n const wasmBytes = await getRemoteWasmFromHash(server, wasmHash);\n return { type: \"wasm\", wasmBytes };\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\n \"Failed to fetch WASM from contract\",\n error as Error,\n );\n }\n}\n\n/**\n * Fetch WASM from network using WASM hash\n */\nexport async function fetchFromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n): Promise<ContractData> {\n try {\n // Validate and decode the hash\n const hashBuffer = Buffer.from(wasmHash, \"hex\");\n if (hashBuffer.length !== 32) {\n throw new WasmFetchError(\n `Invalid WASM hash length: expected 32 bytes, got ${hashBuffer.length}`,\n );\n }\n\n // Get WASM from hash\n const wasmBytes = await getRemoteWasmFromHash(rpcServer, hashBuffer);\n\n return { type: \"wasm\", wasmBytes };\n } catch (error) {\n throw new WasmFetchError(\n `Failed to fetch WASM from hash ${wasmHash}`,\n error as Error,\n );\n }\n}\n\n/**\n * Fetch WASM from network using contract ID\n */\nexport async function fetchFromContractId(\n contractId: string,\n rpcServer: Server,\n): Promise<ContractData> {\n try {\n if (!StrKey.isValidContract(contractId)) {\n throw new WasmFetchError(`Invalid contract ID: ${contractId}`);\n }\n // Parse contract address\n const contractAddress = Address.fromString(contractId);\n\n // Try to get WASM from contract\n return await fetchWasmFromContract(rpcServer, contractAddress);\n } catch (error) {\n throw new WasmFetchError(\n `Failed to fetch WASM from contract ${contractId}`,\n error as Error,\n );\n }\n}\n"],"names":["xdr","Buffer","contract","Contract","StrKey","Address"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,uBAAuB,KAAA,CAAM;AAAA,EACxC,WAAA,CACE,SACgB,KAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AAAA,EAJkB,KAAA;AAKpB;AAKA,eAAe,qBAAA,CACb,QACA,UAAA,EACiB;AACjB,EAAA,IAAI;AAEF,IAAA,MAAM,eAAA,GAAkBA,uBAAI,SAAA,CAAU,YAAA;AAAA,MACpC,IAAIA,uBAAI,qBAAA,CAAsB;AAAA,QAC5B,IAAA,EAAMA,sBAAA,CAAI,IAAA,CAAK,OAAA,CAAQ,YAAY,KAAK;AAAA,OACzC;AAAA,KACH;AAGA,IAAA,MAAM,QAAA,GAAW,MAAM,MAA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AA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAU;AAAA,EACnC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,cAAA;AAAA,MACR,kCAAkC,QAAQ,CAAA,CAAA;AAAA,MAC1C;AAAA,KACF;AAAA,EACF;AACF;AAKA,eAAsB,mBAAA,CACpB,YACA,SAAA,EACuB;AACvB,EAAA,IAAI;AACF,IAAA,IAAI,CAACG,aAAA,CAAO,eAAA,CAAgB,UAAU,CAAA,EAAG;AACvC,MAAA,MAAM,IAAI,cAAA,CAAe,CAAA,qBAAA,EAAwB,UAAU,CAAA,CAAE,CAAA;AAAA,IAC/D;AAEA,IAAA,MAAM,eAAA,GAAkBC,eAAA,CAAQ,UAAA,CAAW,UAAU,CAAA;AAGrD,IAAA,OAAO,MAAM,qBAAA,CAAsB,SAAA,EAAW,eAAe,CAAA;AAAA,EAC/D,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,cAAA;AAAA,MACR,sCAAsC,UAAU,CAAA,CAAA;AAAA,MAChD;AAAA,KACF;AAAA,EACF;AACF;;;;;;"}
1
+ {"version":3,"file":"wasm_fetcher.js","sources":["../../../../src/bindings/wasm_fetcher.ts"],"sourcesContent":["import { Address, Contract, StrKey, xdr } from \"../base/index.js\";\nimport { Server } from \"../rpc/index.js\";\n\nimport { RpcServer } from \"../rpc/server.js\";\n\n/**\n * Types of contract data that can be fetched\n */\nexport type ContractData =\n | { type: \"wasm\"; wasmBytes: Buffer }\n | { type: \"stellar-asset-contract\" };\n\n/**\n * Errors that can occur during WASM fetching\n */\nexport class WasmFetchError extends Error {\n constructor(\n message: string,\n public readonly cause?: Error,\n ) {\n super(message);\n this.name = \"WasmFetchError\";\n }\n}\n\n/**\n * Get WASM bytes from a WASM hash on the network\n */\nasync function getRemoteWasmFromHash(\n server: RpcServer,\n hashBuffer: Buffer,\n): Promise<Buffer> {\n try {\n // Create the ledger key for the contract code\n const contractCodeKey = xdr.LedgerKey.contractCode(\n new xdr.LedgerKeyContractCode({\n hash: xdr.Hash.fromXDR(hashBuffer, \"raw\"),\n }),\n );\n\n // Get the ledger entries\n const response = await server.getLedgerEntries(contractCodeKey);\n\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"WASM not found for the given hash\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractCode()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractCode = entry.val.contractCode();\n return Buffer.from(contractCode.code());\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\"Failed to fetch WASM from hash\", error as Error);\n }\n}\n\n/**\n * Check if a contract is a Digital World Asset Contract\n */\nfunction isDigitalWorldAssetContract(\n instance: xdr.ScContractInstance,\n): boolean {\n // Check if it's a Digital World Asset Contract (has no WASM hash)\n return (\n instance.executable().switch() ===\n xdr.ContractExecutableType.contractExecutableStellarAsset()\n );\n}\n\n/**\n * Fetch WASM bytes from a deployed contract\n */\nasync function fetchWasmFromContract(\n server: RpcServer,\n contractAddress: Address,\n): Promise<ContractData> {\n try {\n const contract = new Contract(contractAddress.toString());\n\n const response = await server.getLedgerEntries(contract.getFootprint());\n if (!response.entries || response.entries.length === 0) {\n throw new WasmFetchError(\"Contract instance not found\");\n }\n\n const entry = response.entries[0];\n if (entry.key.switch() !== xdr.LedgerEntryType.contractData()) {\n throw new WasmFetchError(\"Invalid ledger entry type returned\");\n }\n\n const contractData = entry.val.contractData();\n const instance = contractData.val().instance();\n\n if (isDigitalWorldAssetContract(instance)) {\n return { type: \"stellar-asset-contract\" };\n }\n\n const wasmHash = instance.executable().wasmHash();\n const wasmBytes = await getRemoteWasmFromHash(server, wasmHash);\n return { type: \"wasm\", wasmBytes };\n } catch (error) {\n if (error instanceof WasmFetchError) {\n throw error;\n }\n throw new WasmFetchError(\n \"Failed to fetch WASM from contract\",\n error as Error,\n );\n }\n}\n\n/**\n * Fetch WASM from network using WASM hash\n */\nexport async function fetchFromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n): Promise<ContractData> {\n try {\n // Validate and decode the hash\n const hashBuffer = Buffer.from(wasmHash, \"hex\");\n if (hashBuffer.length !== 32) {\n throw new WasmFetchError(\n `Invalid WASM hash length: expected 32 bytes, got ${hashBuffer.length}`,\n );\n }\n\n // Get WASM from hash\n const wasmBytes = await getRemoteWasmFromHash(rpcServer, hashBuffer);\n\n return { type: \"wasm\", wasmBytes };\n } catch (error) {\n throw new WasmFetchError(\n `Failed to fetch WASM from hash ${wasmHash}`,\n error as Error,\n );\n }\n}\n\n/**\n * Fetch WASM from network using contract ID\n */\nexport async function fetchFromContractId(\n contractId: string,\n rpcServer: Server,\n): Promise<ContractData> {\n try {\n if (!StrKey.isValidContract(contractId)) {\n throw new WasmFetchError(`Invalid contract ID: ${contractId}`);\n }\n // Parse contract address\n const contractAddress = Address.fromString(contractId);\n\n // Try to get WASM from contract\n return await fetchWasmFromContract(rpcServer, contractAddress);\n } catch (error) {\n throw new WasmFetchError(\n `Failed to fetch WASM from contract ${contractId}`,\n error as Error,\n );\n }\n}\n"],"names":["xdr","Buffer","contract","Contract","StrKey","Address"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,uBAAuB,KAAA,CAAM;AAAA,EACxC,WAAA,CACE,SACgB,KAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AAAA,EAJkB,KAAA;AAKpB;AAKA,eAAe,qBAAA,CACb,QACA,UAAA,EACiB;AACjB,EAAA,IAAI;AAEF,IAAA,MAAM,eAAA,GAAkBA,uBAAI,SAAA,CAAU,YAAA;AAAA,MACpC,IAAIA,uBAAI,qBAAA,CAAsB;AAAA,QAC5B,IAAA,EAAMA,sBAAA,CAAI,IAAA,CAAK,OAAA,CAAQ,YAAY,KAAK;AA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