Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@markodayan
markodayan / Example.js
Last active June 21, 2024 09:33
EIP-712 Signing
const ethUtil = require('ethereumjs-util');
const abi = require('ethereumjs-abi');
const chai = require('chai');
const typedData = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
@markodayan
markodayan / commands.sh
Last active December 11, 2021 13:03
repetitive stuff with node
npm init -y
echo "node_modules\n.env" > .gitignore
echo "# Node.js Boilerplate Sample" > README.md
touch .env
mkdir -p src/test && touch src/index.js
mkdir -p src/lib
mkdir -p .github/workflows && touch .github/workflows/actions.yaml
mkdir .vscode && touch .vscode/settings.json
touch .prettierrc
git init
@markodayan
markodayan / Dai.sol
Created October 16, 2021 08:00
Dai contract
pragma solidity >=0.5.12;
// FIXME: This contract was altered compared to the production version.
// It doesn't use LibNote anymore.
// New deployments of this contract will need to include custom events (TO DO).
contract Dai {
// --- Auth ---
mapping (address => uint) public wards;
function rely(address guy) external auth { wards[guy] = 1; }
@markodayan
markodayan / package-sub.json
Last active December 30, 2021 15:04
TypeScript Starter script
{
"main": "index.js",
"scripts": {
"clean": "rimraf dist",
"start": "NODE_ENV=production node -r ts-node/register/transpile-only -r tsconfig-paths/register ./dist/index.js",
"build": "npm run clean && tsc",
"dev": "NODE_ENV=development ts-node-dev -r tsconfig-paths/register ./src/index.ts",
"test": "mocha -r ts-node/register \"src/test/**/*.spec.ts\"",
"pm2:dev": "npm run build && pm2 start pm2_dev.config.js",
"pm2:prod": "npm run build && pm2 start pm2_prod.config.js",
@markodayan
markodayan / tsconfig.json
Last active November 8, 2021 18:30
Some common backend Typescript configs
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibC
@markodayan
markodayan / mocha.sh
Created November 12, 2021 19:54
Mocha test location (all wildcard .spec.ts files in a directory which may be nested)
"test": "mocha \"test/**/*.spec.js\""
# TypeScript development
"test": "mocha -r ts-node/register \"src/test/**/*.spec.ts\""
@markodayan
markodayan / timingattackprotect.ts
Created November 17, 2021 20:31
Timing Attack protection in Nestjs project
import { BasicStrategy as Strategy } from 'passport-http';
import { Injectable, InternalServerErrorException, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ConfigService } from '@nestjs/config';
import { timingSafeEqual } from 'crypto';
@Injectable()
export class AdminBasicStrategy extends PassportStrategy(Strategy) {
constructor(private readonly configService: ConfigService) {
@markodayan
markodayan / crack.js
Last active November 23, 2021 08:17
Cracking private key with last 2 mnemonic words absent (18 bits of entropy at play)
const HDWallet = require('ethereum-hdwallet')
const bip39 = require('bip39');
const fs = require('fs')
const seedStart = 'program deny train foot scrap marble anxiety oblige hybrid clean'
const words = fs.readFileSync('./words.txt').toString('utf-8').split('\r\n')
for(let x = 0; x < words.length; x++){
@markodayan
markodayan / async.ts
Last active December 20, 2021 12:03
Asynchronising functional programming pattern example
type Fn = (...args: any[]) => any;
function makeAsync<T extends Fn>(fn: Fn): (...args: Parameters<T>) => Promise<ReturnType<T>> {
return function (this: any, ...args: Parameters<T>): Promise<ReturnType<T>> {
return new Promise<ReturnType<T>>((res, rej) => {
try {
res(fn.call(this, ...args));
} catch (e) {
rej(e);
}
@markodayan
markodayan / ex-1.js
Created December 20, 2021 20:43
Binding this context
const Person = {
firstName: "Lawrence",
lastName: "Eagles",
sayName: function () {
setTimeout(function() {
console.log("my fullname is " + this.firstName + " " + this.lastName)
}.bind(this), 100) // binds this here.
}
}