ethereum-bloom-filters
Advanced tools
Comparing version 1.0.2 to 1.0.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ethers_1 = require("ethers"); | ||
const utils_1 = require("./utils"); | ||
/** | ||
@@ -15,3 +15,4 @@ * Returns true if the bloom is a valid bloom | ||
} | ||
if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { | ||
if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || | ||
/^(0x)?[0-9A-F]{512}$/.test(bloom)) { | ||
return true; | ||
@@ -30,5 +31,5 @@ } | ||
if (typeof value === 'object' && value.constructor === Uint8Array) { | ||
value = ethers_1.ethers.utils.hexlify(value); | ||
value = utils_1.bytesToHex(value); | ||
} | ||
const hash = ethers_1.ethers.utils.keccak256(value).replace('0x', ''); | ||
const hash = utils_1.keccak256(value).replace('0x', ''); | ||
for (let i = 0; i < 12; i += 4) { | ||
@@ -50,5 +51,5 @@ // calculate bit position in bloom filter that must be active | ||
/** | ||
* Code points to int | ||
* @param codePoint The code point | ||
*/ | ||
* Code points to int | ||
* @param codePoint The code point | ||
*/ | ||
function codePointToInt(codePoint) { | ||
@@ -87,3 +88,4 @@ if (codePoint >= 48 && codePoint <= 57) { | ||
// hence why we have 2 methods | ||
const address = ethers_1.ethers.utils.padZeros(ethereumAddress, 32); | ||
// (0x is not in the 2nd parameter of padleft so 64 chars is fine) | ||
const address = utils_1.padLeft(ethereumAddress, 64); | ||
return isInBloom(bloom, address); | ||
@@ -135,3 +137,4 @@ } | ||
} | ||
else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { | ||
else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || | ||
/^(0x)?[0-9A-F]{64}$/.test(topic)) { | ||
return true; | ||
@@ -138,0 +141,0 @@ } |
{ | ||
"name": "ethereum-bloom-filters", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Ability to test bloom filters for ethereum.", | ||
@@ -30,3 +30,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"ethers": "^4.0.37" | ||
"js-sha3": "^0.8.0" | ||
}, | ||
@@ -40,2 +40,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
@@ -5,2 +5,4 @@ # ethereum-bloom-filters | ||
This package only has 1 dependency which is on `js-sha3` which has no dependencies on at all. | ||
## Installation | ||
@@ -14,3 +16,3 @@ | ||
### yarn: | ||
### yarn: | ||
@@ -38,8 +40,9 @@ ```js | ||
```js | ||
import { | ||
isBloom, | ||
isUserEthereumAddressInBloom, isContractAddressInBloom, | ||
isTopicInBloom, | ||
isInBloom | ||
} from 'ethereum-bloom-filters' | ||
import { | ||
isBloom, | ||
isUserEthereumAddressInBloom, | ||
isContractAddressInBloom, | ||
isTopicInBloom, | ||
isInBloom | ||
} from 'ethereum-bloom-filters'; | ||
``` | ||
@@ -59,3 +62,3 @@ | ||
A ethereum real life example in where this is useful is if you want to update a users balance on every new block so it stays as close to real time as possible. Without using a bloom filter on every new block you would have to force the balances even if that user may not of had any activity within that block. But if you use the logBlooms from the block you can test the bloom filter against the users ethereum address before you do any more slow operations, this will dramatically decrease the amount of calls you do as you will only be doing those extra operations if that ethereum address is within that block (minus the false positives outcome which will be negligible). This will be highly performant for your app. | ||
A ethereum real life example in where this is useful is if you want to update a users balance on every new block so it stays as close to real time as possible. Without using a bloom filter on every new block you would have to force the balances even if that user may not of had any activity within that block. But if you use the logBlooms from the block you can test the bloom filter against the users ethereum address before you do any more slow operations, this will dramatically decrease the amount of calls you do as you will only be doing those extra operations if that ethereum address is within that block (minus the false positives outcome which will be negligible). This will be highly performant for your app. | ||
@@ -62,0 +65,0 @@ ## Functions |
15739
7
313
140
+ Addedjs-sha3@^0.8.0
+ Addedjs-sha3@0.8.0(transitive)
- Removedethers@^4.0.37
- Removedaes-js@3.0.0(transitive)
- Removedbn.js@4.12.0(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedethers@4.0.49(transitive)
- Removedhash.js@1.1.3(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-sha3@0.5.7(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedscrypt-js@2.0.4(transitive)
- Removedsetimmediate@1.0.4(transitive)
- Removeduuid@2.0.1(transitive)
- Removedxmlhttprequest@1.8.0(transitive)