Skip to content

Commit

Permalink
remove callback subscriptions when user rejects signature auth requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 21, 2023
1 parent 84e5796 commit 417a130
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,26 @@ 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)
}
}
)

Expand Down

0 comments on commit 417a130

Please sign in to comment.