Skip to content

Commit

Permalink
chore: move js into doc.gno
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Nov 22, 2024
1 parent 1307fa3 commit 7907ff2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 747 deletions.
17 changes: 17 additions & 0 deletions examples/gno.land/p/demo/airdrop/grc20_merkle_airdrop/doc.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Package airdrop implements a Merkle airdrop mechanism in Gno.
//
// A Merkle airdrop is a secure and efficient way to distribute tokens or rewards to a list of recipients
// using a Merkle tree for proof verification. This implementation is compliant with the `merkletreejs`
// JavaScript package, ensuring compatibility with proofs generated off-chain.
//
// Note:
// This package expects data to adhere to the structure defined in `gno.land/p/demo/airdrop.AirdropData`.
//
// Compatibility:
// - Proofs and trees generated using the `merkletreejs` package (https://www.npmjs.com/package/merkletreejs) are supported.
// - Uses SHA256 as the hash function with a sorted-pair configuration.
//
// Reference:
// For more information on Merkle trees, refer to the documentation for the `merkletreejs` package:
// https://www.npmjs.com/package/merkletreejs
package grc20_merkle_airdrop
63 changes: 63 additions & 0 deletions examples/gno.land/r/demo/foo20_airdrop/doc.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Package foo20_airdrop implements an airdrop mechanism for the Foo20 GRC20 in Gno.
//
// This package extends the functionality of `gno.land/p/demo/airdrop` to support Foo20 token distribution.
// It enables secure and efficient token distribution to recipients using Merkle proofs.
//
// Usage:
// To execute an airdrop, use the claim function and provide the necessary proof and recipient data.
//
// const { MerkleTree } = require("merkletreejs");
// const crypto = require("crypto");
// const SHA256 = require("crypto-js/sha256");
// const secp256k1 = require("secp256k1");
// const { bech32 } = require("bech32");
//
// Example of using the ClaimJSON function:
//
// // This function reproduce the output of std.DerivePkgAddr
//
// function derive_pkg_addr(str) {
// const hash = crypto
// .createHash("sha256")
// .update("pkgPath:" + str)
// .digest();
//
// let hash_bytes = new Uint8Array(hash).slice(0, 20);
//
// const words = bech32.toWords(hash_bytes);
// return bech32.encode("g", words);
// }
//
// const addresses = Array.from({ length: 10 }, (_, i) =>
//
// derive_pkg_addr(`gno.land/r/test/${i}`),
//
// );
//
// const leaves = addresses.map((addr) =>
//
// SHA256(JSON.stringify({ address: addr, amount: "10000" })),
//
// );
//
// const tree = new MerkleTree(leaves, SHA256);
// const root = tree.getRoot().toString("hex");
//
// const proof = tree.getProof(leaves[5]).map((p) => ({
// data: p.data.toString("hex"),
// position: p.position === "left" ? 1 : 0,
// }));
//
// console.log("proof", proof); // This as JSON can be sent
//
// Data Structure:
// This package relies on the AirdropData structure from `gno.land/p/demo/airdrop`:
//
// Reference Implementation:
// The `foo20_airdrop` package builds on the `airdrop` package's foundation. Refer to its documentation for
// additional details: gno.land/p/demo/airdrop/doc.gno
//
// Notes:
// - Ensure your Merkle tree and proofs are generated off-chain using a compatible library such as `merkletreejs`.
// - Hash function: SHA256
package foo20_airdrop
17 changes: 0 additions & 17 deletions misc/js-merkletree/package.json

This file was deleted.

36 changes: 0 additions & 36 deletions misc/js-merkletree/src/index.js

This file was deleted.

47 changes: 0 additions & 47 deletions misc/js-merkletree/test/test.js

This file was deleted.

Loading

0 comments on commit 7907ff2

Please sign in to comment.