import { catFromIpfs } from '../../storage/ipfs.js' import type { Step } from '../reducer.js' import type { EffectCallbacks } from '../shared/effects/types.js' import { parseRestorableEnvelope } from './envelopes.js' import { assertCandidateCanReadEnvelope, restoreSignatureRequestForStep } from './auth.js' export async function runRestoreFetch( step: Extract, callbacks: EffectCallbacks, ): Promise { const raw = await catFromIpfs(step.apiUrl, step.cid) const envelope = parseRestorableEnvelope(raw) assertCandidateCanReadEnvelope(step.candidate, step.requesterAddress, envelope) const nextStep: Extract = { kind: 'restore-authorizing', cid: step.cid, apiUrl: step.apiUrl, envelope, candidate: step.candidate, requesterAddress: step.requesterAddress, purpose: step.purpose, } restoreSignatureRequestForStep(nextStep) callbacks.onStep(nextStep) }