Socket
Socket
Sign inDemoInstall

@lens-protocol/bonsai

Package Overview
Dependencies
Maintainers
9
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lens-protocol/bonsai - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

images/bonsai-explorer.jpg

3

lib/client/client-da-proof-gateway.d.ts

@@ -5,4 +5,4 @@ import { DATimestampProofsResponse } from '../data-availability-models/data-availability-timestamp-proofs';

import { TimeoutError } from '../input-output/common';
import { TxValidatedResult } from '../input-output/tx-validated-results';
import { DAProofsGateway } from '../proofs/da-proof-checker';
import { TxValidatedResult } from '../input-output/tx-validated-results';
export declare class ClientDaProofGateway implements DAProofsGateway {

@@ -13,2 +13,3 @@ getBlockRange(blockNumbers: number[], ethereumNode: EthereumNode): Promise<BlockInfo[]>;

getTxResultFromCache(): Promise<TxValidatedResult | null>;
hasSignatureBeenUsedBefore(_signature: string): Promise<boolean>;
}

@@ -25,4 +25,8 @@ "use strict";

}
// No signature usage in the client
hasSignatureBeenUsedBefore(_signature) {
return Promise.resolve(false);
}
}
exports.ClientDaProofGateway = ClientDaProofGateway;
//# sourceMappingURL=client-da-proof-gateway.js.map

@@ -114,2 +114,11 @@ /**

/**
* This means the evm signature has already been used
* Only really starts to be able to be properly used when many submitters
*/
CHAIN_SIGNATURE_ALREADY_USED = "CHAIN_SIGNATURE_ALREADY_USED",
/**
* This means the publication submisson could not pass potentional due to a reorg
*/
POTENTIAL_REORG = "POTENTIAL_REORG",
/**
* unknown error should not happen but catch all

@@ -116,0 +125,0 @@ */

@@ -118,2 +118,11 @@ "use strict";

/**
* This means the evm signature has already been used
* Only really starts to be able to be properly used when many submitters
*/
BonsaiValidatorError["CHAIN_SIGNATURE_ALREADY_USED"] = "CHAIN_SIGNATURE_ALREADY_USED";
/**
* This means the publication submisson could not pass potentional due to a reorg
*/
BonsaiValidatorError["POTENTIAL_REORG"] = "POTENTIAL_REORG";
/**
* unknown error should not happen but catch all

@@ -120,0 +129,0 @@ */

@@ -23,2 +23,9 @@ import { BigNumber, ethers } from 'ethers';

/**
* Check if a block hash exists for potential reorgs
* @param blockHash - The transaction data to be executed.
* @param ethereumNode - The Ethereum node to use for the transaction.
* @returns A `DAResult` with the result of the transaction or an error message.
*/
export declare const blockHashExists: (blockHash: string, ethereumNode: EthereumNode) => PromiseResult<boolean>;
/**
* Parse an Ethereum signature string and add a deadline timestamp to it.

@@ -25,0 +32,0 @@ * @param signature - The signature string to parse.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLensPubCount = exports.DAlensHubInterface = exports.getBlock = exports.getOnChainProfileDetails = exports.parseSignature = exports.executeSimulationTransaction = exports.EMPTY_BYTE = void 0;
exports.getLensPubCount = exports.DAlensHubInterface = exports.getBlock = exports.getOnChainProfileDetails = exports.parseSignature = exports.blockHashExists = exports.executeSimulationTransaction = exports.EMPTY_BYTE = void 0;
const ethereum_multicall_1 = require("ethereum-multicall");

@@ -46,2 +46,26 @@ const ethers_1 = require("ethers");

/**
* Check if a block hash exists for potential reorgs
* @param blockHash - The transaction data to be executed.
* @param ethereumNode - The Ethereum node to use for the transaction.
* @returns A `DAResult` with the result of the transaction or an error message.
*/
const blockHashExists = async (blockHash, ethereumNode) => {
try {
return await (0, helpers_1.retryWithTimeout)(async () => {
// this returns a full block so can extend typings if you need anything more
const block = await (0, json_rpc_with_timeout_1.JSONRPCWithTimeout)(ethereumNode.nodeUrl, jsonrpc_methods_1.JSONRPCMethods.eth_getBlockByHash, [blockHash, false]);
if (!block) {
return (0, da_result_1.success)(false);
}
return (0, da_result_1.success)(true);
}, {
delayMs: json_rpc_with_timeout_1.RATE_LIMIT_TIME,
});
}
catch (_error) {
return (0, da_result_1.failure)(validator_errors_1.BonsaiValidatorError.SIMULATION_NODE_COULD_NOT_RUN);
}
};
exports.blockHashExists = blockHashExists;
/**
* Does this over ethers call as alchemy and some other providers dont like a padding hex number

@@ -48,0 +72,0 @@ * - wont accept 0x01f1a494

@@ -7,3 +7,4 @@ /**

eth_call = "eth_call",
eth_getBlockByHash = "eth_getBlockByHash",
anvil_reset = "anvil_reset"
}

@@ -11,4 +11,5 @@ "use strict";

JSONRPCMethods["eth_call"] = "eth_call";
JSONRPCMethods["eth_getBlockByHash"] = "eth_getBlockByHash";
JSONRPCMethods["anvil_reset"] = "anvil_reset";
})(JSONRPCMethods = exports.JSONRPCMethods || (exports.JSONRPCMethods = {}));
//# sourceMappingURL=jsonrpc-methods.js.map

@@ -30,3 +30,3 @@ "use strict";

if (!result.data) {
throw new Error('No data returned from Bundlr GraphQL API.');
throw new Error('No data returned from Bundlr GraphQL API - normally due to a network drop, will auto retry and 99.9% sort itself out when network is stable again.');
}

@@ -33,0 +33,0 @@ return result.data.transactions;

@@ -10,2 +10,3 @@ import { DATimestampProofsResponse } from '../data-availability-models/data-availability-timestamp-proofs';

tx_timestamp_proof_metadata = "tx_timestamp_proof_metadata",
tx_signature = "tx_signature",
cursor = "cursor"

@@ -49,2 +50,8 @@ }

/**
* Check if a signature has already been used before
*
* @param signature - The number of the block to get.
*/
export declare const hasSignatureBeenUsedBeforeDb: (signature: string) => Promise<boolean>;
/**
* Gets the last end cursor from the database.

@@ -51,0 +58,0 @@ * Returns null if the database is not available or there is no cursor.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTxTimestampProofsMetadataDb = exports.saveTxTimestampProofsMetadataDb = exports.getTxDAMetadataDb = exports.saveTxDAMetadataDb = exports.saveTotalCheckedCountDb = exports.getTotalCheckedCountDb = exports.saveEndCursorDb = exports.getLastEndCursorDb = exports.saveBlockDb = exports.getBlockDb = exports.saveTxDb = exports.getTxDb = exports.deleteDb = exports.startDb = exports.DbReference = void 0;
exports.getTxTimestampProofsMetadataDb = exports.saveTxTimestampProofsMetadataDb = exports.getTxDAMetadataDb = exports.saveTxDAMetadataDb = exports.saveTotalCheckedCountDb = exports.getTotalCheckedCountDb = exports.saveEndCursorDb = exports.getLastEndCursorDb = exports.hasSignatureBeenUsedBeforeDb = exports.saveBlockDb = exports.getBlockDb = exports.saveTxDb = exports.getTxDb = exports.deleteDb = exports.startDb = exports.DbReference = void 0;
const fs_1 = require("fs");

@@ -15,2 +15,3 @@ const level_1 = require("level");

DbReference["tx_timestamp_proof_metadata"] = "tx_timestamp_proof_metadata";
DbReference["tx_signature"] = "tx_signature";
DbReference["cursor"] = "cursor";

@@ -79,2 +80,5 @@ })(DbReference = exports.DbReference || (exports.DbReference = {}));

try {
if (result.dataAvailabilityResult) {
await saveSignatureDb(result.dataAvailabilityResult.chainProofs.thisPublication.signature);
}
await db.put(`${DbReference.tx}:${txId}`, JSON.stringify(result));

@@ -124,2 +128,37 @@ }

/**
* Check if a signature has already been used before
*
* @param signature - The number of the block to get.
*/
const hasSignatureBeenUsedBeforeDb = async (signature) => {
if (!db) {
return false;
}
try {
// if it does not throw its because it exists
await db.get(`${DbReference.tx_signature}:${signature}`);
return true;
}
catch (e) {
return false;
}
};
exports.hasSignatureBeenUsedBeforeDb = hasSignatureBeenUsedBeforeDb;
/**
* Saves a the signature submitted to the database.
*
* @param signature - The signature
*/
const saveSignatureDb = async (signature) => {
if (!db) {
return;
}
try {
await db.put(`${DbReference.tx_signature}:${signature}`, '');
}
catch (error) {
throw new Error('`saveSignatureSubmittedDb` - Could not write to into the db - critical error!');
}
};
/**
* Gets the last end cursor from the database.

@@ -126,0 +165,0 @@ * Returns null if the database is not available or there is no cursor.

@@ -31,2 +31,3 @@ import { Deployment, Environment } from '../common/environment';

getBlockRange(blockNumbers: number[], ethereumNode: EthereumNode): Promise<BlockInfo[]>;
hasSignatureBeenUsedBefore(signature: string): Promise<boolean>;
}

@@ -33,0 +34,0 @@ export declare class DaProofChecker {

@@ -36,2 +36,6 @@ "use strict";

}
const signatureAlreadyUsed = await this.gateway.hasSignatureBeenUsedBefore(daPublicationWithTimestampProofs.daPublication.chainProofs.thisPublication.signature);
if (signatureAlreadyUsed) {
return (0, da_result_1.failureWithContext)(validator_errors_1.BonsaiValidatorError.CHAIN_SIGNATURE_ALREADY_USED, daPublicationWithTimestampProofs.daPublication);
}
}

@@ -38,0 +42,0 @@ if (!(0, submitters_1.isValidSubmitter)(ethereumNode.environment, daPublicationWithTimestampProofs.submitter, ethereumNode.deployment)) {

@@ -8,2 +8,3 @@ import { DATimestampProofsResponse } from '../data-availability-models/data-availability-timestamp-proofs';

export declare class DaProofGateway implements DAProofsGateway {
hasSignatureBeenUsedBefore(signature: string): Promise<boolean>;
getTxResultFromCache(txId: string): Promise<TxValidatedResult | null>;

@@ -10,0 +11,0 @@ getBlockRange(blockNumbers: number[], ethereumNode: EthereumNode): Promise<BlockInfo[]>;

@@ -9,2 +9,5 @@ "use strict";

class DaProofGateway {
hasSignatureBeenUsedBefore(signature) {
return (0, db_1.hasSignatureBeenUsedBeforeDb)(signature);
}
getTxResultFromCache(txId) {

@@ -11,0 +14,0 @@ // Check if the transaction ID exists in the database

@@ -101,2 +101,8 @@ "use strict";

if (!expectedResult.successResult.eq(simulatedResult.successResult)) {
// recheck for `POTENTIAL_REORG`
const exists = await (0, ethereum_1.blockHashExists)(publication.chainProofs.thisPublication.blockHash, ethereumNode);
if (!exists) {
log('block hash now does not exist this could be a potential reorg');
return (0, da_result_1.failure)(validator_errors_1.BonsaiValidatorError.POTENTIAL_REORG);
}
log('signature simulation checking failed');

@@ -103,0 +109,0 @@ return (0, da_result_1.failure)(validator_errors_1.BonsaiValidatorError.SIMULATION_FAILED);

@@ -33,7 +33,33 @@ "use strict";

console.log(`
_ _____ _ _ ____ ____ _
| | | ____| || | ___| | _ \\ / \\
| | | _| | \\| |___ \\ | | | |/ _ \\
| |___| |___| | |___) | | |_| / ___ \\
|_____|_____|_| \\_|____/ |____/_/ \\_\\
BBBBBBBBBBBBBBBBB OOOOOOOOO NNNNNNNN NNNNNNNN SSSSSSSSSSSSSSS AAA IIIIIIIIII
B::::::::::::::::B OO:::::::::OO N:::::::N N::::::N SS:::::::::::::::S A:::A I::::::::I
B::::::BBBBBB:::::B OO:::::::::::::OO N::::::::N N::::::NS:::::SSSSSS::::::S A:::::A I::::::::I
BB:::::B B:::::BO:::::::OOO:::::::ON:::::::::N N::::::NS:::::S SSSSSSS A:::::::A II::::::II
B::::B B:::::BO::::::O O::::::ON::::::::::N N::::::NS:::::S A:::::::::A I::::I
B::::B B:::::BO:::::O O:::::ON:::::::::::N N::::::NS:::::S A:::::A:::::A I::::I
B::::BBBBBB:::::B O:::::O O:::::ON:::::::N::::N N::::::N S::::SSSS A:::::A A:::::A I::::I
B:::::::::::::BB O:::::O O:::::ON::::::N N::::N N::::::N SS::::::SSSSS A:::::A A:::::A I::::I
B::::BBBBBB:::::B O:::::O O:::::ON::::::N N::::N:::::::N SSS::::::::SS A:::::A A:::::A I::::I
B::::B B:::::BO:::::O O:::::ON::::::N N:::::::::::N SSSSSS::::S A:::::AAAAAAAAA:::::A I::::I
B::::B B:::::BO:::::O O:::::ON::::::N N::::::::::N S:::::S A:::::::::::::::::::::A I::::I
B::::B B:::::BO::::::O O::::::ON::::::N N:::::::::N S:::::S A:::::AAAAAAAAAAAAA:::::A I::::I
BB:::::BBBBBB::::::BO:::::::OOO:::::::ON::::::N N::::::::NSSSSSSS S:::::S A:::::A A:::::A II::::::II
B:::::::::::::::::B OO:::::::::::::OO N::::::N N:::::::NS::::::SSSSSS:::::SA:::::A A:::::A I::::::::I
B::::::::::::::::B OO:::::::::OO N::::::N N::::::NS:::::::::::::::SSA:::::A A:::::A I::::::::I
BBBBBBBBBBBBBBBBB OOOOOOOOO NNNNNNNN NNNNNNN SSSSSSSSSSSSSSS AAAAAAA AAAAAAAIIIIIIIIII
`);

@@ -93,3 +119,3 @@ };

if (!lastCheckNothingFound) {
(0, logger_1.consoleLogWithLensNodeFootprint)(`waiting for new data availability to be submitted...`);
(0, logger_1.consoleLogWithLensNodeFootprint)(`waiting for new bonsai transaction...`);
}

@@ -119,5 +145,6 @@ lastCheckNothingFound = true;

if (syncFromHeadOnly) {
const lastSeenTransaction = await (0, get_data_availability_transactions_api_1.getDataAvailabilityTransactionsAPI)(ethereumNode.environment, ethereumNode.deployment, null, get_data_availability_transactions_api_1.DataAvailabilityTransactionsOrderTypes.DESC, 1);
if (lastSeenTransaction.edges.length > 0) {
endCursor = lastSeenTransaction.pageInfo.endCursor;
// try to find the last transactions and start syncing from there again
const lastTransaction = await (0, get_data_availability_transactions_api_1.getDataAvailabilityTransactionsAPI)(ethereumNode.environment, ethereumNode.deployment, null, get_data_availability_transactions_api_1.DataAvailabilityTransactionsOrderTypes.DESC, 1);
if (lastTransaction.edges.length > 0) {
endCursor = lastTransaction.pageInfo.endCursor;
totalChecked = 0;

@@ -152,3 +179,4 @@ }

catch (error) {
(0, logger_1.consoleLogWithLensNodeFootprint)('Error while checking for new submissions', error);
const message = error.message || error;
(0, logger_1.consoleLogWithLensNodeFootprint)('Error while checking for new submissions', message);
await (0, helpers_1.sleep)(100);

@@ -155,0 +183,0 @@ }

{
"name": "@lens-protocol/bonsai",
"version": "0.0.1",
"version": "1.0.0",
"description": "Bonsai node for the Lens protocol",

@@ -15,4 +15,24 @@ "main": "lib/index.js",

"client/**/*",
"images/**/*",
"README.md"
],
"scripts": {
"build": "tsc",
"eslint:fix": "eslint \"src/**/*.ts\" --quiet --fix",
"eslint": "eslint \"src/**/*.ts\" --quiet",
"start:fork": "REQ_TIMEOUT=100000 anvil --fork-url NODE_URL --silent",
"start": "env-cmd -f .env node lib/runnable/da-verifier-node.runnable.js",
"start:failed": "env-cmd -f .env ts-node src/failed-submissons.runnable.ts",
"debug:playground": "npm run build && env-cmd -f .env node lib/__PLAYGROUND__/index.js",
"generate": "graphql-codegen",
"test": "npm run build && env-cmd -f .env jest",
"lint": "pnpm run prettier && pnpm run tsc",
"lint:fix": "pnpm run prettier:fix && pnpm run eslint",
"prettier:fix": "prettier --write .",
"prettier": "prettier --check .",
"tsc": "tsc --noEmit",
"prepublishOnly": "pnpm run build",
"publish": "pnpm publish --access public",
"preinstall": "npx only-allow pnpm"
},
"devDependencies": {

@@ -64,20 +84,3 @@ "@graphql-codegen/cli": "2.11.3",

"url": "git+https://github.com/lens-protocol/bonsai.git"
},
"scripts": {
"build": "tsc",
"eslint:fix": "eslint \"src/**/*.ts\" --quiet --fix",
"eslint": "eslint \"src/**/*.ts\" --quiet",
"start:fork": "REQ_TIMEOUT=100000 anvil --fork-url NODE_URL --silent",
"start": "env-cmd -f .env node lib/runnable/da-verifier-node.runnable.js",
"start:failed": "env-cmd -f .env ts-node src/failed-submissons.runnable.ts",
"debug:playground": "npm run build && env-cmd -f .env node lib/__PLAYGROUND__/index.js",
"generate": "graphql-codegen",
"test": "npm run build && env-cmd -f .env jest",
"lint": "pnpm run prettier && pnpm run tsc",
"lint:fix": "pnpm run prettier:fix && pnpm run eslint",
"prettier:fix": "prettier --write .",
"prettier": "prettier --check .",
"tsc": "tsc --noEmit",
"preinstall": "npx only-allow pnpm"
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc