@bitsongjs/utils
Advanced tools
+2
-18
@@ -1,18 +0,2 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| exports.__esModule = true; | ||
| __exportStar(require("./types"), exports); | ||
| __exportStar(require("./merkledrop"), exports); | ||
| export * from './types'; | ||
| export * from './merkledrop'; |
@@ -1,17 +0,1 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| exports.__esModule = true; | ||
| __exportStar(require("./tree"), exports); | ||
| export * from './tree'; |
+21
-37
@@ -1,20 +0,3 @@ | ||
| "use strict"; | ||
| var __assign = (this && this.__assign) || function () { | ||
| __assign = Object.assign || function(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
| t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| return __assign.apply(this, arguments); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| exports.__esModule = true; | ||
| exports.Merkledrop = void 0; | ||
| var sha256_1 = __importDefault(require("crypto-js/sha256")); | ||
| var merkletreejs_1 = require("merkletreejs"); | ||
| import sha256 from 'crypto-js/sha256'; | ||
| import { MerkleTree } from 'merkletreejs'; | ||
| /* | ||
@@ -33,24 +16,25 @@ Utility class for Merkledrop tree generation. | ||
| */ | ||
| var Merkledrop = /** @class */ (function () { | ||
| function Merkledrop(accounts) { | ||
| export class Merkledrop { | ||
| constructor(accounts) { | ||
| this.accounts = accounts; | ||
| var leaves = accounts.map(function (a, index) { | ||
| return (0, sha256_1["default"])("".concat(index).concat(a.address).concat(a.amount)).toString(); | ||
| const leaves = accounts.map((a, index) => { | ||
| return sha256(`${index}${a.address}${a.amount}`).toString(); | ||
| }); | ||
| this.tree = new merkletreejs_1.MerkleTree(leaves, sha256_1["default"]); | ||
| this.tree = new MerkleTree(leaves, sha256); | ||
| } | ||
| Merkledrop.prototype.getMerkleRoot = function () { | ||
| getMerkleRoot() { | ||
| return this.tree.getHexRoot().replace('0x', ''); | ||
| }; | ||
| Merkledrop.prototype.getMerkleProof = function (account, index) { | ||
| } | ||
| getMerkleProof(account, index) { | ||
| return this.tree | ||
| .getHexProof((0, sha256_1["default"])("".concat(index).concat(account.address).concat(account.amount)).toString()) | ||
| .map(function (v) { return v.replace('0x', ''); }); | ||
| }; | ||
| Merkledrop.prototype.getAccountsWithProofs = function () { | ||
| var _this = this; | ||
| return this.accounts.map(function (account, index) { return (__assign(__assign({}, account), { proofs: _this.getMerkleProof(account, index), index: index })); }); | ||
| }; | ||
| return Merkledrop; | ||
| }()); | ||
| exports.Merkledrop = Merkledrop; | ||
| .getHexProof(sha256(`${index}${account.address}${account.amount}`).toString()) | ||
| .map(v => v.replace('0x', '')); | ||
| } | ||
| getAccountsWithProofs() { | ||
| return this.accounts.map((account, index) => ({ | ||
| ...account, | ||
| proofs: this.getMerkleProof(account, index), | ||
| index, | ||
| })); | ||
| } | ||
| } |
+1
-17
@@ -1,17 +0,1 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| exports.__esModule = true; | ||
| __exportStar(require("./merkledrop"), exports); | ||
| export * from './merkledrop'; |
@@ -1,2 +0,1 @@ | ||
| "use strict"; | ||
| exports.__esModule = true; | ||
| export {}; |
+2
-2
| { | ||
| "name": "@bitsongjs/utils", | ||
| "version": "2.1.0", | ||
| "version": "2.1.1-beta.0", | ||
| "author": "Davide Segullo <davidesegullo@users.noreply.github.com>", | ||
@@ -44,3 +44,3 @@ "description": "A Javascript utility lib for BitSong Blockchain.", | ||
| }, | ||
| "gitHead": "58442cff4c7b7ffd7e366fd6704658469406444b" | ||
| "gitHead": "be6abab661d429ce164d0aa55c1f1898472caa25" | ||
| } |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16153
-16.61%98
-39.88%2
100%