Skip to content

Commit

Permalink
Add consumer temporary key exchange retry
Browse files Browse the repository at this point in the history
We can't be certain that users will open a window with the producer before
they request account linking in a consumer. The retry keeps trying until the
consumer receives a session key from a producer.
In addition, retries will be useful in cases where the producer is busy
with another consumer, at least in this version. In a future version,
the producer will queue up consumers that want to be linked.
  • Loading branch information
bgins committed Feb 15, 2022
1 parent 3646cba commit 764e0c8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/auth/linking/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,23 @@ export const createConsumer = async (options: { username: string; timeout?: numb
eventEmitter?.dispatchEvent("done")
eventEmitter = null
channel.close()
clearInterval(rsaExchangeInterval)
// reset linking state?
}

const channel = await auth.createChannel({ username, handleMessage })
const { temporaryRsaPair, temporaryDID } = await generateTemporaryExchangeKey()
ls.temporaryRsaPair = temporaryRsaPair
ls.step = "NEGOTIATION"

await channel.send(temporaryDID)
const rsaExchangeInterval = setInterval(async () => {
if (!ls.sessionKey) {
const { temporaryRsaPair, temporaryDID } = await generateTemporaryExchangeKey()
ls.temporaryRsaPair = temporaryRsaPair
ls.step = "NEGOTIATION"

await channel.send(temporaryDID)
} else {
clearInterval(rsaExchangeInterval)
}
}, 2000)

return {
on: (event: string, listener: EventListener) => { eventEmitter?.addEventListener(event, listener) },
Expand Down

0 comments on commit 764e0c8

Please sign in to comment.