try fix verifyKey

This commit is contained in:
DjDeveloperr 2021-03-14 14:20:15 +05:30
parent 1c515dcb37
commit e65fa8fded
2 changed files with 16 additions and 27 deletions

View File

@ -12,8 +12,7 @@ import { Collection } from '../utils/collection.ts'
import { Client } from './client.ts'
import { RESTManager } from './rest.ts'
import { SlashModule } from './slashModule.ts'
import { verify as edverify } from 'https://deno.land/x/ed25519/mod.ts'
import { Buffer } from 'https://deno.land/std@0.80.0/node/buffer.ts'
import { verify as edverify } from 'https://deno.land/x/ed25519@1.0.1/mod.ts'
export class SlashCommand {
slash: SlashCommandsManager
@ -369,6 +368,8 @@ export interface SlashOptions {
publicKey?: string
}
const encoder = new TextEncoder()
export class SlashClient {
id: string | (() => string)
client?: Client
@ -503,24 +504,21 @@ export class SlashClient {
}
async verifyKey(
rawBody: string | Uint8Array | Buffer,
signature: string,
timestamp: string
rawBody: string | Uint8Array,
signature: string | Uint8Array,
timestamp: string | Uint8Array
): Promise<boolean> {
if (this.publicKey === undefined)
throw new Error('Public Key is not present')
return edverify(
signature,
Buffer.concat([
Buffer.from(timestamp, 'utf-8'),
Buffer.from(
rawBody instanceof Uint8Array
? new TextDecoder().decode(rawBody)
: rawBody
)
]),
this.publicKey
).catch(() => false)
const fullBody = new Uint8Array([
...(typeof timestamp === 'string'
? encoder.encode(timestamp)
: timestamp),
...(typeof rawBody === 'string' ? encoder.encode(rawBody) : rawBody)
])
return edverify(signature, fullBody, this.publicKey).catch(() => false)
}
async verifyOpineRequest(req: any): Promise<boolean> {

View File

@ -117,16 +117,7 @@ client.on('messageCreate', async (msg: Message) => {
msg.channel.send('Failed...')
}
} else if (msg.content === '!react') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
msg.addReaction('😂')
msg.channel.send('x'.repeat(6969), {
embed: new Embed()
.setTitle('pepega'.repeat(6969))
.setDescription('pepega'.repeat(6969))
.addField('uwu', 'uwu'.repeat(6969))
.addField('uwu', 'uwu'.repeat(6969))
.setFooter('uwu'.repeat(6969))
})
msg.addReaction('a:programming:785013658257195008')
} else if (msg.content === '!wait_for') {
msg.channel.send('Send anything!')
const [receivedMsg] = await client.waitFor(