@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.
- package/README.md +5 -5
- package/dist/digital-world-sdk-axios.js +52 -47
- package/dist/digital-world-sdk-axios.js.map +1 -1
- package/dist/digital-world-sdk-axios.min.js +1 -1
- package/dist/digital-world-sdk-axios.min.js.map +1 -1
- package/dist/digital-world-sdk.js +52 -47
- package/dist/digital-world-sdk.js.map +1 -1
- package/dist/digital-world-sdk.min.js +6 -6
- package/dist/digital-world-sdk.min.js.map +1 -1
- package/lib/axios/cjs/base/contract.js +2 -2
- package/lib/axios/cjs/base/contract.js.map +1 -1
- package/lib/axios/cjs/base/invocation.js.map +1 -1
- package/lib/axios/cjs/base/numbers/sc_int.js +1 -1
- package/lib/axios/cjs/base/numbers/sc_int.js.map +1 -1
- package/lib/axios/cjs/base/operation.js +1 -1
- package/lib/axios/cjs/base/operation.js.map +1 -1
- package/lib/axios/cjs/base/operations/invoke_host_function.js +2 -2
- package/lib/axios/cjs/base/operations/invoke_host_function.js.map +1 -1
- package/lib/axios/cjs/base/operations/revoke_sponsorship.js.map +1 -1
- package/lib/axios/cjs/bindings/config.js +4 -4
- package/lib/axios/cjs/bindings/config.js.map +1 -1
- package/lib/axios/cjs/bindings/generator.js +4 -4
- package/lib/axios/cjs/bindings/generator.js.map +1 -1
- package/lib/axios/cjs/bindings/types.js.map +1 -1
- package/lib/axios/cjs/bindings/utils.js +2 -2
- package/lib/axios/cjs/bindings/utils.js.map +1 -1
- package/lib/axios/cjs/bindings/wasm_fetcher.js +2 -2
- package/lib/axios/cjs/bindings/wasm_fetcher.js.map +1 -1
- package/lib/axios/cjs/contract/assembled_transaction.js.map +1 -1
- package/lib/axios/cjs/contract/spec.js +1 -1
- package/lib/axios/cjs/contract/spec.js.map +1 -1
- package/lib/axios/cjs/contract/types.js.map +1 -1
- package/lib/axios/cjs/gateway/gateway_axios_client.js +1 -1
- package/lib/axios/cjs/gateway/server_api.js.map +1 -1
- package/lib/axios/cjs/rpc/api.js.map +1 -1
- package/lib/axios/cjs/rpc/axios.js +1 -1
- package/lib/axios/cjs/rpc/server.js +32 -27
- package/lib/axios/cjs/rpc/server.js.map +1 -1
- package/lib/axios/cjs/webauth/utils.js.map +1 -1
- package/lib/axios/esm/base/contract.d.ts +4 -4
- package/lib/axios/esm/base/contract.js +2 -2
- package/lib/axios/esm/base/contract.js.map +1 -1
- package/lib/axios/esm/base/invocation.d.ts +2 -2
- package/lib/axios/esm/base/invocation.js.map +1 -1
- package/lib/axios/esm/base/numbers/sc_int.d.ts +2 -2
- package/lib/axios/esm/base/numbers/sc_int.js +1 -1
- package/lib/axios/esm/base/numbers/sc_int.js.map +1 -1
- package/lib/axios/esm/base/operation.d.ts +2 -2
- package/lib/axios/esm/base/operation.js +2 -2
- package/lib/axios/esm/base/operation.js.map +1 -1
- package/lib/axios/esm/base/operations/index.d.ts +1 -1
- package/lib/axios/esm/base/operations/invoke_host_function.d.ts +5 -5
- package/lib/axios/esm/base/operations/invoke_host_function.js +2 -2
- package/lib/axios/esm/base/operations/invoke_host_function.js.map +1 -1
- package/lib/axios/esm/base/operations/revoke_sponsorship.d.ts +1 -1
- package/lib/axios/esm/base/operations/revoke_sponsorship.js.map +1 -1
- package/lib/axios/esm/base/operations/types.d.ts +2 -2
- package/lib/axios/esm/bindings/config.js +4 -4
- package/lib/axios/esm/bindings/config.js.map +1 -1
- package/lib/axios/esm/bindings/generator.d.ts +7 -7
- package/lib/axios/esm/bindings/generator.js +4 -4
- package/lib/axios/esm/bindings/generator.js.map +1 -1
- package/lib/axios/esm/bindings/types.d.ts +1 -1
- package/lib/axios/esm/bindings/types.js.map +1 -1
- package/lib/axios/esm/bindings/utils.d.ts +4 -4
- package/lib/axios/esm/bindings/utils.js +2 -2
- package/lib/axios/esm/bindings/utils.js.map +1 -1
- package/lib/axios/esm/bindings/wasm_fetcher.js +2 -2
- package/lib/axios/esm/bindings/wasm_fetcher.js.map +1 -1
- package/lib/axios/esm/contract/assembled_transaction.d.ts +1 -1
- package/lib/axios/esm/contract/assembled_transaction.js.map +1 -1
- package/lib/axios/esm/contract/spec.js +1 -1
- package/lib/axios/esm/contract/spec.js.map +1 -1
- package/lib/axios/esm/contract/types.d.ts +2 -2
- package/lib/axios/esm/contract/types.js.map +1 -1
- package/lib/axios/esm/gateway/gateway_axios_client.js +1 -1
- package/lib/axios/esm/gateway/server_api.d.ts +2 -2
- package/lib/axios/esm/gateway/server_api.js.map +1 -1
- package/lib/axios/esm/rpc/api.d.ts +1 -1
- package/lib/axios/esm/rpc/api.js.map +1 -1
- package/lib/axios/esm/rpc/axios.js +1 -1
- package/lib/axios/esm/rpc/browser.d.ts +1 -1
- package/lib/axios/esm/rpc/server.d.ts +26 -26
- package/lib/axios/esm/rpc/server.js +32 -27
- package/lib/axios/esm/rpc/server.js.map +1 -1
- package/lib/axios/esm/webauth/utils.d.ts +2 -2
- package/lib/axios/esm/webauth/utils.js.map +1 -1
- package/lib/cjs/base/contract.js +2 -2
- package/lib/cjs/base/contract.js.map +1 -1
- package/lib/cjs/base/invocation.js.map +1 -1
- package/lib/cjs/base/numbers/sc_int.js +1 -1
- package/lib/cjs/base/numbers/sc_int.js.map +1 -1
- package/lib/cjs/base/operation.js +1 -1
- package/lib/cjs/base/operation.js.map +1 -1
- package/lib/cjs/base/operations/invoke_host_function.js +2 -2
- package/lib/cjs/base/operations/invoke_host_function.js.map +1 -1
- package/lib/cjs/base/operations/revoke_sponsorship.js.map +1 -1
- package/lib/cjs/bindings/config.js +4 -4
- package/lib/cjs/bindings/config.js.map +1 -1
- package/lib/cjs/bindings/generator.js +4 -4
- package/lib/cjs/bindings/generator.js.map +1 -1
- package/lib/cjs/bindings/types.js.map +1 -1
- package/lib/cjs/bindings/utils.js +2 -2
- package/lib/cjs/bindings/utils.js.map +1 -1
- package/lib/cjs/bindings/wasm_fetcher.js +2 -2
- package/lib/cjs/bindings/wasm_fetcher.js.map +1 -1
- package/lib/cjs/contract/assembled_transaction.js.map +1 -1
- package/lib/cjs/contract/spec.js +1 -1
- package/lib/cjs/contract/spec.js.map +1 -1
- package/lib/cjs/contract/types.js.map +1 -1
- package/lib/cjs/gateway/gateway_axios_client.js +1 -1
- package/lib/cjs/gateway/server_api.js.map +1 -1
- package/lib/cjs/rpc/api.js.map +1 -1
- package/lib/cjs/rpc/axios.js +1 -1
- package/lib/cjs/rpc/server.js +32 -27
- package/lib/cjs/rpc/server.js.map +1 -1
- package/lib/cjs/webauth/utils.js.map +1 -1
- package/lib/esm/base/contract.d.ts +4 -4
- package/lib/esm/base/contract.js +2 -2
- package/lib/esm/base/contract.js.map +1 -1
- package/lib/esm/base/invocation.d.ts +2 -2
- package/lib/esm/base/invocation.js.map +1 -1
- package/lib/esm/base/numbers/sc_int.d.ts +2 -2
- package/lib/esm/base/numbers/sc_int.js +1 -1
- package/lib/esm/base/numbers/sc_int.js.map +1 -1
- package/lib/esm/base/operation.d.ts +2 -2
- package/lib/esm/base/operation.js +2 -2
- package/lib/esm/base/operation.js.map +1 -1
- package/lib/esm/base/operations/index.d.ts +1 -1
- package/lib/esm/base/operations/invoke_host_function.d.ts +5 -5
- package/lib/esm/base/operations/invoke_host_function.js +2 -2
- package/lib/esm/base/operations/invoke_host_function.js.map +1 -1
- package/lib/esm/base/operations/revoke_sponsorship.d.ts +1 -1
- package/lib/esm/base/operations/revoke_sponsorship.js.map +1 -1
- package/lib/esm/base/operations/types.d.ts +2 -2
- package/lib/esm/bindings/config.js +4 -4
- package/lib/esm/bindings/config.js.map +1 -1
- package/lib/esm/bindings/generator.d.ts +7 -7
- package/lib/esm/bindings/generator.js +4 -4
- package/lib/esm/bindings/generator.js.map +1 -1
- package/lib/esm/bindings/types.d.ts +1 -1
- package/lib/esm/bindings/types.js.map +1 -1
- package/lib/esm/bindings/utils.d.ts +4 -4
- package/lib/esm/bindings/utils.js +2 -2
- package/lib/esm/bindings/utils.js.map +1 -1
- package/lib/esm/bindings/wasm_fetcher.js +2 -2
- package/lib/esm/bindings/wasm_fetcher.js.map +1 -1
- package/lib/esm/contract/assembled_transaction.d.ts +1 -1
- package/lib/esm/contract/assembled_transaction.js.map +1 -1
- package/lib/esm/contract/spec.js +1 -1
- package/lib/esm/contract/spec.js.map +1 -1
- package/lib/esm/contract/types.d.ts +2 -2
- package/lib/esm/contract/types.js.map +1 -1
- package/lib/esm/gateway/gateway_axios_client.js +1 -1
- package/lib/esm/gateway/server_api.d.ts +2 -2
- package/lib/esm/gateway/server_api.js.map +1 -1
- package/lib/esm/rpc/api.d.ts +1 -1
- package/lib/esm/rpc/api.js.map +1 -1
- package/lib/esm/rpc/axios.js +1 -1
- package/lib/esm/rpc/browser.d.ts +1 -1
- package/lib/esm/rpc/server.d.ts +26 -26
- package/lib/esm/rpc/server.js +32 -27
- package/lib/esm/rpc/server.js.map +1 -1
- package/lib/esm/webauth/utils.d.ts +2 -2
- package/lib/esm/webauth/utils.js.map +1 -1
- 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}
|
|
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,EA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;AAAA,MACA,sDAAA;AAAA,MACA,2DAAA;AAAA,MACA,KAAA;AAAA,MACA,EAAA;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;;;;"}
|
|
@@ -14,7 +14,7 @@ export type GenerateOptions = {
|
|
|
14
14
|
* The output of the binding generation process.
|
|
15
15
|
*
|
|
16
16
|
* Contains all generated TypeScript source files and configuration files
|
|
17
|
-
* needed to create a standalone npm package for interacting with a
|
|
17
|
+
* needed to create a standalone npm package for interacting with a Digital World contract.
|
|
18
18
|
*/
|
|
19
19
|
export type GeneratedBindings = {
|
|
20
20
|
/** The index.ts barrel export file that re-exports Client and types */
|
|
@@ -33,10 +33,10 @@ export type GeneratedBindings = {
|
|
|
33
33
|
gitignore: string;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
|
-
* Generates TypeScript bindings for
|
|
36
|
+
* Generates TypeScript bindings for Digital World smart contracts.
|
|
37
37
|
*
|
|
38
38
|
* This class creates fully-typed TypeScript client code from a contract's specification,
|
|
39
|
-
* allowing developers to interact with
|
|
39
|
+
* allowing developers to interact with Digital World smart contracts with full IDE support
|
|
40
40
|
* and compile-time type checking.
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
@@ -110,12 +110,12 @@ export declare class BindingGenerator {
|
|
|
110
110
|
/**
|
|
111
111
|
* Creates a BindingGenerator by fetching WASM from the network using its hash.
|
|
112
112
|
*
|
|
113
|
-
* Retrieves the WASM bytecode from
|
|
113
|
+
* Retrieves the WASM bytecode from Digital World RPC using the WASM hash,
|
|
114
114
|
* then parses the contract specification from it. Useful when you know
|
|
115
115
|
* the hash of an installed WASM but don't have the binary locally.
|
|
116
116
|
*
|
|
117
117
|
* @param wasmHash - The hex-encoded hash of the installed WASM blob
|
|
118
|
-
* @param rpcServer - The
|
|
118
|
+
* @param rpcServer - The Digital World RPC server instance
|
|
119
119
|
* @returns A Promise resolving to a new BindingGenerator instance
|
|
120
120
|
* @throws If the WASM cannot be fetched or doesn't contain a valid spec
|
|
121
121
|
*
|
|
@@ -133,11 +133,11 @@ export declare class BindingGenerator {
|
|
|
133
133
|
* Creates a BindingGenerator by fetching contract info from a deployed contract ID.
|
|
134
134
|
*
|
|
135
135
|
* Retrieves the contract's WASM from the network using the contract ID,
|
|
136
|
-
* then parses the specification. If the contract is a
|
|
136
|
+
* then parses the specification. If the contract is a Digital World Asset Contract (SAC),
|
|
137
137
|
* returns a generator with the standard SAC specification.
|
|
138
138
|
*
|
|
139
139
|
* @param contractId - The contract ID (C... address) of the deployed contract
|
|
140
|
-
* @param rpcServer - The
|
|
140
|
+
* @param rpcServer - The Digital World RPC server instance
|
|
141
141
|
* @returns A Promise resolving to a new BindingGenerator instance
|
|
142
142
|
* @throws If the contract cannot be found or fetched
|
|
143
143
|
*
|
|
@@ -78,12 +78,12 @@ class BindingGenerator {
|
|
|
78
78
|
/**
|
|
79
79
|
* Creates a BindingGenerator by fetching WASM from the network using its hash.
|
|
80
80
|
*
|
|
81
|
-
* Retrieves the WASM bytecode from
|
|
81
|
+
* Retrieves the WASM bytecode from Digital World RPC using the WASM hash,
|
|
82
82
|
* then parses the contract specification from it. Useful when you know
|
|
83
83
|
* the hash of an installed WASM but don't have the binary locally.
|
|
84
84
|
*
|
|
85
85
|
* @param wasmHash - The hex-encoded hash of the installed WASM blob
|
|
86
|
-
* @param rpcServer - The
|
|
86
|
+
* @param rpcServer - The Digital World RPC server instance
|
|
87
87
|
* @returns A Promise resolving to a new BindingGenerator instance
|
|
88
88
|
* @throws If the WASM cannot be fetched or doesn't contain a valid spec
|
|
89
89
|
*
|
|
@@ -107,11 +107,11 @@ class BindingGenerator {
|
|
|
107
107
|
* Creates a BindingGenerator by fetching contract info from a deployed contract ID.
|
|
108
108
|
*
|
|
109
109
|
* Retrieves the contract's WASM from the network using the contract ID,
|
|
110
|
-
* then parses the specification. If the contract is a
|
|
110
|
+
* then parses the specification. If the contract is a Digital World Asset Contract (SAC),
|
|
111
111
|
* returns a generator with the standard SAC specification.
|
|
112
112
|
*
|
|
113
113
|
* @param contractId - The contract ID (C... address) of the deployed contract
|
|
114
|
-
* @param rpcServer - The
|
|
114
|
+
* @param rpcServer - The Digital World RPC server instance
|
|
115
115
|
* @returns A Promise resolving to a new BindingGenerator instance
|
|
116
116
|
* @throws If the contract cannot be found or fetched
|
|
117
117
|
*
|
|
@@ -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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EO,MAAM,gBAAA,CAAiB;A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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":[],"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;AA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,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;;;;"}
|
|
@@ -24,7 +24,7 @@ export interface EnumCase {
|
|
|
24
24
|
value: number;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Generates TypeScript type definitions from
|
|
27
|
+
* Generates TypeScript type definitions from Digital World contract specs
|
|
28
28
|
*/
|
|
29
29
|
export declare class TypeGenerator {
|
|
30
30
|
private spec;
|
|
@@ -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"],"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,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../../../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"],"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,KAAA,CAAI,eAAA,CAAgB,sBAAA,EAAuB;AAC9C,QAAA,IAAI,aAAA,CAAc,KAAA,CAAM,WAAA,EAAa,CAAA,EAAG;AACtC,UAAA,OAAO,IAAA,CAAK,mBAAA,CAAoB,KAAA,CAAM,WAAA,EAAa,CAAA;AAAA,QACrD;AACA,QAAA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pE,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,OAAO,kBAAA,CAAmB,SAAA,CAAU,IAAA,EAAK,CAAE,UAAU,CAAA;AAC3D,IAAA,MAAM,GAAA,GAAM,kBAAA;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,KAAU,oBAAA,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;;;;"}
|
|
@@ -20,9 +20,9 @@ export declare function parseTypeFromTypeDef(typeDef: xdr.ScSpecTypeDef, isFunct
|
|
|
20
20
|
export interface BindingImports {
|
|
21
21
|
/** Imports needed from type definitions */
|
|
22
22
|
typeFileImports: Set<string>;
|
|
23
|
-
/** Imports needed from the
|
|
23
|
+
/** Imports needed from the Digital World SDK in the contract namespace */
|
|
24
24
|
stellarContractImports: Set<string>;
|
|
25
|
-
/** Imports needed from
|
|
25
|
+
/** Imports needed from Digital World SDK in the global namespace */
|
|
26
26
|
stellarImports: Set<string>;
|
|
27
27
|
/** Whether Buffer import is needed */
|
|
28
28
|
needsBufferImport: boolean;
|
|
@@ -37,9 +37,9 @@ export declare function generateTypeImports(typeDefs: xdr.ScSpecTypeDef[]): Bind
|
|
|
37
37
|
export interface FormatImportsOptions {
|
|
38
38
|
/** Whether to include imports from types.ts */
|
|
39
39
|
includeTypeFileImports?: boolean;
|
|
40
|
-
/** Additional imports needed from
|
|
40
|
+
/** Additional imports needed from digital-world-sdk/contract */
|
|
41
41
|
additionalStellarContractImports?: string[];
|
|
42
|
-
/** Additional imports needed from
|
|
42
|
+
/** Additional imports needed from digital-world-sdk */
|
|
43
43
|
additionalStellarImports?: string[];
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -270,13 +270,13 @@ function formatImports(imports, options) {
|
|
|
270
270
|
if (stellarContractImports.length > 0) {
|
|
271
271
|
const uniqueContractImports = Array.from(new Set(stellarContractImports));
|
|
272
272
|
importLines.push(
|
|
273
|
-
`import {${uniqueContractImports.join(", ")}} from '@
|
|
273
|
+
`import {${uniqueContractImports.join(", ")}} from '@digitalworld/digital-world-sdk/contract';`
|
|
274
274
|
);
|
|
275
275
|
}
|
|
276
276
|
if (stellarImports.length > 0) {
|
|
277
277
|
const uniqueStellarImports = Array.from(new Set(stellarImports));
|
|
278
278
|
importLines.push(
|
|
279
|
-
`import {${uniqueStellarImports.join(", ")}} from '@
|
|
279
|
+
`import {${uniqueStellarImports.join(", ")}} from '@digitalworld/digital-world-sdk';`
|
|
280
280
|
);
|
|
281
281
|
}
|
|
282
282
|
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,MAAM,SAAA,GAAY,UAAA,CAA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AY,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;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA;AAAA,IAEA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,aAAA;AAAA;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7 @@ async function getRemoteWasmFromHash(server, hashBuffer) {
|
|
|
53
53
|
throw new WasmFetchError("Failed to fetch WASM from hash", error);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function isDigitalWorldAssetContract(instance) {
|
|
57
57
|
return instance.executable().switch() === types.ContractExecutableType.contractExecutableStellarAsset();
|
|
58
58
|
}
|
|
59
59
|
async function fetchWasmFromContract(server, contractAddress) {
|
|
@@ -69,7 +69,7 @@ async function fetchWasmFromContract(server, contractAddress) {
|
|
|
69
69
|
}
|
|
70
70
|
const contractData = entry.val.contractData();
|
|
71
71
|
const instance = contractData.val().instance();
|
|
72
|
-
if (
|
|
72
|
+
if (isDigitalWorldAssetContract(instance)) {
|
|
73
73
|
return { type: "stellar-asset-contract" };
|
|
74
74
|
}
|
|
75
75
|
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
|
|
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"],"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,MAAI,SAAA,CAAU,YAAA;AAAA,MACpC,IAAIA,MAAI,qBAAA,CAAsB;AAAA,QAC5B,IAAA,EAAMA,KAAA,CAAI,IAAA,CAAK,OAAA,CAAQ,YAAY,KAAK;AAAA,OACzC;AAAA,KACH;AAGA,IAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,gBAAA,CAAiB,eAAe,CAAA;AAE9D,IAAA,IAAI,CAAC,QAAA,CAAS,OAAA,IAAW,QAAA,CAAS,OAAA,CAAQ,WAAW,CAAA,EAAG;AACtD,MAAA,MAAM,IAAI,eAAe,mCAAmC,CAAA;AAAA,IAC9D;AAEA,IAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,OAAA,CAAQ,CAAC,CAAA;AAChC,IAAA,IAAI,MAAM,GAAA,CAAI,MAAA,OAAaA,KAAA,CAAI,eAAA,CAAgB,cAAa,EAAG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AA,qBAAA,EAAwB,UAAU,CAAA,CAAE,CAAA;AAAA,IAC/D;AAEA,IAAA,MAAM,eAAA,GAAkB,OAAA,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;;;;"}
|
|
@@ -121,7 +121,7 @@ import { ExpiredStateError, ExternalServiceError, FakeAccountError, InternalWall
|
|
|
121
121
|
*
|
|
122
122
|
* #### 4. Multi-auth workflows
|
|
123
123
|
*
|
|
124
|
-
* Soroban, and
|
|
124
|
+
* Soroban, and Digital World in general, allows multiple parties to sign a
|
|
125
125
|
* transaction.
|
|
126
126
|
*
|
|
127
127
|
* Let's consider an Atomic Swap contract. Alice wants to give 10 of her Token
|