Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir("./public/")))

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

// web framework
app := echo.New()
// middleware
app.Use(middleware.Logger())
app.Use(middleware.Recover())
// service
accountRepo := accountRepo.NewRepository(pgConn)
as := accountService.NewAccountService(accountRepo)
pragma solidity ^0.7.0;
// 這是一個叫做 Token 的合約
contract Token {
// 貨幣的名稱叫做...
string public name = "My Awesome Token";
// 貨幣的代號是...
string public symbol = "MAT";
@johnson86tw
johnson86tw / MerkleTree.ts
Last active January 10, 2023 05:02
A TypeScript implementation of Merkle Tree rewrite from tornado-core: https://github.com/tornadocash/tornado-core/blob/master/lib/MerkleTree.js
const circomlib = require("circomlib");
const mimcsponge = circomlib.mimcsponge;
export function MiMCSponge(left: string, right: string): string {
return mimcsponge.multiHash([BigInt(left), BigInt(right)]).toString();
}
export interface IMerkleTree {
root: () => string;
proof: (index: number) => {
// prover
const levels = 2;
const leaves = [10, 20 ,30 ,40];
const tree = new MerkleTree(levels, leaves);
const index = 2;
const proof = tree.proof(index);
// verifier
const root = "117086588437903260255921638146322982"
console.log(verify(proof, root)); // true
proof = {
root: "117086588437903260255921638146322982",
pathElements: [
'40',
'1978699832413026196628606142134435304247'
],
pathIndices: [ 0, 1 ],
leaf: '30'
}
const circomlib = require("circomlib");
const mimcsponge = circomlib.mimcsponge;
export function MiMCSponge(left: string, right: string): string {
return mimcsponge.multiHash([BigInt(left), BigInt(right)]).toString();
}
export interface IMerkleTree {
root: () => string;
proof: (index: number) => {
root: string;
pathElements: string[];
...
proof(indexOfLeaf: number) {
let pathElements: string[] = [];
let pathIndices: number[] = [];
const leaf = this.storage.get(MerkleTree.indexToKey(0, indexOfLeaf));
if (!leaf) throw new Error("leaf not found");
// store sibling into pathElements and target's indices into pathIndices
const handleIndex = (level: number, currentIndex: number, siblingIndex: number) => {
const siblingValue = this.storage.get(MerkleTree.indexToKey(level, siblingIndex)) || this.zeros[level];
pathElements.push(siblingValue);
contract WithoutZK {
string greeting = "hello world";
uint256 answer = 1770;
function greet() public view returns (string memory) {
return greeting;
}
function _setGreeting(string memory _greeting) internal {
greeting = _greeting;