Skip to content

Commit

Permalink
fix: callbacks in auth flow no longer unsubscribed too early (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell authored Dec 21, 2023
1 parent 3c14dfc commit 2ca4805
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,32 @@ export class Client<ContentTypes> {
'sign',
async (message: { id: string; message: string }) => {
const request: { id: string; message: string } = message
const signatureString = await signer.signMessage(request.message)
const eSig = utils.splitSignature(signatureString)
const r = hexToBytes(eSig.r)
const s = hexToBytes(eSig.s)
const sigBytes = new Uint8Array(65)
sigBytes.set(r)
sigBytes.set(s, r.length)
sigBytes[64] = eSig.recoveryParam

const signature = Buffer.from(sigBytes).toString('base64')

XMTPModule.receiveSignature(request.id, signature)
try {
const signatureString = await signer.signMessage(request.message)
const eSig = utils.splitSignature(signatureString)
const r = hexToBytes(eSig.r)
const s = hexToBytes(eSig.s)
const sigBytes = new Uint8Array(65)
sigBytes.set(r)
sigBytes.set(s, r.length)
sigBytes[64] = eSig.recoveryParam

const signature = Buffer.from(sigBytes).toString('base64')

XMTPModule.receiveSignature(request.id, signature)
} catch (e) {
const errorMessage = 'ERROR in create. User rejected signature'
console.info(errorMessage, e)
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
reject(errorMessage)
}
}
)

XMTPModule.emitter.addListener('authed', async () => {
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
const address = await signer.getAddress()
resolve(new Client(address, opts?.codecs || []))
})
Expand All @@ -89,8 +99,6 @@ export class Client<ContentTypes> {
Boolean(enableSubscription)
)
})()
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
})
}

Expand Down

0 comments on commit 2ca4805

Please sign in to comment.