Skip to content

Instantly share code, notes, and snippets.

@konstantin24121
konstantin24121 / verifyTelegramWebAppData.tsx
Last active July 22, 2024 12:15
Telegram Bot 6.0 Validating data received via the Web App node implementation
const TELEGRAM_BOT_TOKEN = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw'; // https://core.telegram.org/bots#creating-a-new-bot
export const verifyTelegramWebAppData = async (telegramInitData: string): boolean => {
// The data is a query string, which is composed of a series of field-value pairs.
const encoded = decodeURIComponent(telegramInitData);
// HMAC-SHA-256 signature of the bot's token with the constant string WebAppData used as a key.
const secret = crypto
@egargan-ft
egargan-ft / better-error.ts
Created April 8, 2023 21:02
Snippers for better error handling in Typescript
/**
* Base error class that all application errors should extend.
*
* Like the native `Error`, but ensures subclasses are properly initialised and correctly typed.
*/
export class BaseError extends Error {
constructor(message: string) {
super(message);
Object.defineProperty(this, "name", { value: new.target.name });
Object.setPrototypeOf(this, new.target.prototype);
@ZigBalthazar
ZigBalthazar / UTXO.ts
Created March 9, 2024 15:56
implementatiton of UTXO in typescript
type UTXO = {
id: string;
amount: number;
};
type Wallet = {
address: string;
utxos: UTXO[];
};