try fix verifyKey
This commit is contained in:
		
							parent
							
								
									1c515dcb37
								
							
						
					
					
						commit
						e65fa8fded
					
				
					 2 changed files with 16 additions and 27 deletions
				
			
		|  | @ -12,8 +12,7 @@ import { Collection } from '../utils/collection.ts' | ||||||
| import { Client } from './client.ts' | import { Client } from './client.ts' | ||||||
| import { RESTManager } from './rest.ts' | import { RESTManager } from './rest.ts' | ||||||
| import { SlashModule } from './slashModule.ts' | import { SlashModule } from './slashModule.ts' | ||||||
| import { verify as edverify } from 'https://deno.land/x/ed25519/mod.ts' | import { verify as edverify } from 'https://deno.land/x/ed25519@1.0.1/mod.ts' | ||||||
| import { Buffer } from 'https://deno.land/std@0.80.0/node/buffer.ts' |  | ||||||
| 
 | 
 | ||||||
| export class SlashCommand { | export class SlashCommand { | ||||||
|   slash: SlashCommandsManager |   slash: SlashCommandsManager | ||||||
|  | @ -369,6 +368,8 @@ export interface SlashOptions { | ||||||
|   publicKey?: string |   publicKey?: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | const encoder = new TextEncoder() | ||||||
|  | 
 | ||||||
| export class SlashClient { | export class SlashClient { | ||||||
|   id: string | (() => string) |   id: string | (() => string) | ||||||
|   client?: Client |   client?: Client | ||||||
|  | @ -503,24 +504,21 @@ export class SlashClient { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async verifyKey( |   async verifyKey( | ||||||
|     rawBody: string | Uint8Array | Buffer, |     rawBody: string | Uint8Array, | ||||||
|     signature: string, |     signature: string | Uint8Array, | ||||||
|     timestamp: string |     timestamp: string | Uint8Array | ||||||
|   ): Promise<boolean> { |   ): Promise<boolean> { | ||||||
|     if (this.publicKey === undefined) |     if (this.publicKey === undefined) | ||||||
|       throw new Error('Public Key is not present') |       throw new Error('Public Key is not present') | ||||||
|     return edverify( | 
 | ||||||
|       signature, |     const fullBody = new Uint8Array([ | ||||||
|       Buffer.concat([ |       ...(typeof timestamp === 'string' | ||||||
|         Buffer.from(timestamp, 'utf-8'), |         ? encoder.encode(timestamp) | ||||||
|         Buffer.from( |         : timestamp), | ||||||
|           rawBody instanceof Uint8Array |       ...(typeof rawBody === 'string' ? encoder.encode(rawBody) : rawBody) | ||||||
|             ? new TextDecoder().decode(rawBody) |     ]) | ||||||
|             : rawBody | 
 | ||||||
|         ) |     return edverify(signature, fullBody, this.publicKey).catch(() => false) | ||||||
|       ]), |  | ||||||
|       this.publicKey |  | ||||||
|     ).catch(() => false) |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async verifyOpineRequest(req: any): Promise<boolean> { |   async verifyOpineRequest(req: any): Promise<boolean> { | ||||||
|  |  | ||||||
|  | @ -117,16 +117,7 @@ client.on('messageCreate', async (msg: Message) => { | ||||||
|       msg.channel.send('Failed...') |       msg.channel.send('Failed...') | ||||||
|     } |     } | ||||||
|   } else if (msg.content === '!react') { |   } else if (msg.content === '!react') { | ||||||
|     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
 |     msg.addReaction('a:programming:785013658257195008') | ||||||
|     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)) |  | ||||||
|     }) |  | ||||||
|   } else if (msg.content === '!wait_for') { |   } else if (msg.content === '!wait_for') { | ||||||
|     msg.channel.send('Send anything!') |     msg.channel.send('Send anything!') | ||||||
|     const [receivedMsg] = await client.waitFor( |     const [receivedMsg] = await client.waitFor( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue