| 139 | } |
| 140 | |
| 141 | function createPromptWs (promptResponder, options = {}) { |
| 142 | const { |
| 143 | includeConfirmPrompts = false, |
| 144 | defaultConfirmResponse = ['trust'] |
| 145 | } = options |
| 146 | const prompts = [] |
| 147 | let pendingOptions |
| 148 | return { |
| 149 | prompts, |
| 150 | s (payload) { |
| 151 | if (payload && payload.action === 'session-interactive') { |
| 152 | pendingOptions = payload.options |
| 153 | if (includeConfirmPrompts || payload.options?.mode !== 'confirm') { |
| 154 | prompts.push(payload.options) |
| 155 | } |
| 156 | } |
| 157 | }, |
| 158 | once (handler) { |
| 159 | const currentOptions = pendingOptions |
| 160 | queueMicrotask(() => { |
| 161 | handler({ |
| 162 | results: currentOptions?.mode === 'confirm' && !includeConfirmPrompts |
| 163 | ? defaultConfirmResponse |
| 164 | : promptResponder(currentOptions, prompts) |
| 165 | }) |
| 166 | }) |
| 167 | }, |
| 168 | close () {} |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function publicKeyOnlyAuth (publicKey) { |
| 173 | return (ctx) => { |