| 97 | }; |
| 98 | |
| 99 | export const getReplicaUrl = async (network: string): Promise<string> => { |
| 100 | const dfxFile = JSON.parse(await readFile(DFX_PATH, 'utf-8')); |
| 101 | |
| 102 | if (!dfxFile?.networks?.[network]) { |
| 103 | throw new Error(`Network '${network}' not found in dfx.json.`); |
| 104 | } |
| 105 | |
| 106 | if (dfxFile.networks[network].providers && dfxFile.networks[network].providers.length > 0) { |
| 107 | return dfxFile.networks[network].providers[0]; |
| 108 | } |
| 109 | |
| 110 | if (dfxFile.networks[network].bind) { |
| 111 | const bind = dfxFile.networks[network].bind.startsWith('http') |
| 112 | ? dfxFile.networks[network].bind |
| 113 | : `http://${dfxFile.networks[network].bind}`; |
| 114 | |
| 115 | const validLocalBinds = ['http://localhost', 'http://127.0.0.1', 'http://[::1]']; |
| 116 | if (!validLocalBinds.some(validLocalBind => bind.startsWith(validLocalBind))) { |
| 117 | throw new Error( |
| 118 | `Network '${network}' has a bind URL that is not a valid local bind: ${bind}.`, |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | return bind; |
| 123 | } |
| 124 | |
| 125 | throw new Error(`Network '${network}' does not have a replica URL.`); |
| 126 | }; |
| 127 | |
| 128 | export const getIdentityPemFilePath = async (identity: string): Promise<string> => { |
| 129 | if (!existsSync(DFX_DEFAULT_IDENTITY_STORE_PATH)) { |