Skip to content

Instantly share code, notes, and snippets.

View chiro-hiro's full-sized avatar
🤖
Bleep bloop, I am a robot. Eh, just kidding.

Chiro Hiro chiro-hiro

🤖
Bleep bloop, I am a robot. Eh, just kidding.
View GitHub Profile
@chiro-hiro
chiro-hiro / mary.bash
Last active November 22, 2023 15:46
SSH Tunneling + SOCKS
#!/usr/bin/env bash
# (C) 2023 Chiro & Mary
echo "Turning IPv6 off..."
networksetup -setv6off "Wi-Fi"
echo "Checking proxy configuration..."
networksetup -getsocksfirewallproxy "Wi-Fi"
echo "Setting proxy configuration..."
networksetup -setsocksfirewallproxy "Wi-Fi" 127.0.0.1 31337 off
echo "Turning proxy on..."
@chiro-hiro
chiro-hiro / merkle-tree.ts
Last active July 11, 2023 07:13
SnarkyJS Merkle tree example
/*
Description:
This example describes how developers can use Merkle Trees as a basic off-chain storage tool.
zkApps on Mina can only store a small amount of data on-chain, but many use cases require your application to at least reference big amounts of data.
Merkle Trees give developers the power of storing large amounts of data off-chain, but proving its integrity to the on-chain smart contract!
! Unfamiliar with Merkle Trees? No problem! Check out https://blog.ethereum.org/2015/11/15/merkling-in-ethereum/
@chiro-hiro
chiro-hiro / concat-uint8array.md
Last active May 19, 2023 16:36
Concat Uint8Array

Searching on the Internet to find a proper way to concat multiple arrays of Uint8Array but the result made me disapointed. "Why you guys so fucking lazy?", I asked.

So, I wrote mine so you can steal it genterly under the witness of MIT License. If you are end up here you are fucking lazy, you should do something about your life. Btw, don't just steal it leave me a damn star, Jesus!!.

TypeScript

function concatUint8Array(input: Uint8Array[], size?: number): Uint8Array {
  let concatedSize = 0;
  if (typeof size === 'undefined') {
@chiro-hiro
chiro-hiro / orandv1.md
Last active February 14, 2023 06:49
Get a private epoch from Orand V1

Orand JSON PRC was published at: https://orand-test-service.orochi.network/

Created new Orand's private epoch with CURL:

curl -X POST --data '{"method":"orand_newPrivateEpoch","params":["56", "0x68bE199e497FAe7ed11339BE388BF4a403CD1698"]}' https://orand-test-service.orochi.network/

Result for a single epoch:

@chiro-hiro
chiro-hiro / fake-provider.ts
Created December 15, 2022 06:16
A wrapper of real JSON RPC provider
import { ethers } from 'ethers';
import { TillSuccess } from 'noqueue';
// Let's consider this is a dirty trick, to force the JSON RPC
// to retries several times before give up
function getFakeProvider(
provider: ethers.providers.StaticJsonRpcProvider,
): ethers.providers.StaticJsonRpcProvider {
const fakeProvider = {};
const injected: string[] = [];
@chiro-hiro
chiro-hiro / recover.ts
Last active December 25, 2022 12:39
Validate ethereum proof
import { ethers } from 'ethers';
(async () => {
let proofs = [
'0x4f54e1c15ca1d7aec6d16fcc8b524ef298a470b5dd61fd4aeccdd2abd4755e437340fe513a8267397ae468cc8643e1ea0d86f78d029ab35871c0d61d81ba32c51c',
'0x6fca48d5a3522f42984dda6ff662c63de7df537c40da53e74fcc77d00a73441c30c222612af565c74faed88830c4a4083fd9a98c46e5aeaae392dfe61c5a14941c',
'0xd3ba49eabe5cc487d012360e2d38c0238666f9ec596be5f3b7e542e67c448a187b09a9a5acda889366eb5789073b0a73961375f336d28beb4d78479405765e361b',
];
for (let i = 0; i < proofs.length; i += 1) {
console.log(
@chiro-hiro
chiro-hiro / crossbeam.rs
Last active October 17, 2022 05:42
Example data sharing and channel
use crossbeam::scope;
use crossbeam_channel::{select, unbounded};
use env_logger::{Builder, Env};
use log::info;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
fn main() {
Builder::from_env(Env::default().default_filter_or("info")).init();
@chiro-hiro
chiro-hiro / crossbeam_http_server.rs
Last active July 20, 2022 10:27
Multithread HTTP server with crossbeam
// Try with
// RUST_LOG=debug cargo run
// [dependencies]
// crossbeam = "0.8.1"
// crossbeam-utils = "0.8.10"
// crossbeam-channel = "0.5"
// log = "0.4.17"
// env_logger = "0.9.0"
use crossbeam;
@chiro-hiro
chiro-hiro / lazy-ass-wallet.md
Last active April 29, 2022 09:28
Ethereum wallet generator

Want to generate a bunch of wallets but your are lazy as fuck?

// MIT Licensed © 2022 chiro@orochi.network
import { ethers } from "ethers";

(async () => {
  const { phrase } = ethers.Wallet.createRandom().mnemonic;
  const dataTable = [];
  console.log("Passphrase:", phrase);
@chiro-hiro
chiro-hiro / ed25519.md
Last active November 18, 2021 07:19
Use ed25519 JWT with jose

Generate keypair:

import { generateKeyPair } from "jose/util/generate_key_pair";
import fs from "fs";
import { KeyObject } from "crypto";

(async () => {
  const { publicKey, privateKey } = await generateKeyPair("EdDSA", {
    crv: "Ed25519",