
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
do-counter-sharding
Advanced tools
npm i do-counter-sharding
CounterDurableObject
directly as a durable_object binding.import { CounterDurableObject } from 'do-counter-sharding'
class Metrics extends CounterDurableObject {
static doNamespace = `METRICS_DO` // binding name of your wrangler.toml
static kvNamespace = `KV` // kv_namespace binding name in your wrangler.toml
static kvPrefix = `metrics` // prefix used when storing counters to KV - metrics~counters
static shardCount = 2 // number of shards that you want - can be change anytime - this should handle 200requests/s
static shardMinRequestToGlobal = 100 // higher number will write to global less often
static shardWriteToGlobalAfter = 1000 * 5 // 5s in ms - if the DO does not receive anymore increment after 5s it will write to the global counter
static globalMinWritesToKV = 100 // higher number will write to KV less often
static globalWriteToKVAfter = 1000 * 5// 5s in ms - if the DO does not receive anymore write from shards after 5s it will write to KV
}
export default {
fetch: (request, env) => {
const globalStub = Metrics.globalStub(env)
// globalStub.fetch()
const shardStub = Metrics.shardStub(env, Number(shardNumber))
// shardStub.fetch()
return new Response()
}
}
export { Metrics }
Check the test file ./test/index.ts how to implement in a worker
POST
/global/reset/:counterName
reset specific counter from global
GET
/global/counters
view global counters from global DurableObject storage
GET
/global/writes
display write events from all shards (useful for understanding how it works)
GET
/global/shardWrites
display write counts with sum total
GET
/global/shards
view shards current count
GET
/shard/:shardNumber/counters
view current shard counters
POST
/shard/:shardNumber/write
write to global manually (useful if there was a bug and exceedMaxCount or afterNoIncrement
did not hit)
POST
/increment/:counterName
increment a global counter by dispatching work to other shards
POST
/increments
increment global multiple counters from shards
GET
/counters
view global counters from KV
Using fetch /reset/:counterName
, /write
, /counters
, /writes
, /shardWrites
, /shards
// Metrics is a class extending CounterDurableObject
const globalStub = Metrics.globalStub(env)
globalStub.fetch(`/reset/{counterName}`, { method: `POST` })
you can also use method directly
const globalStub = Metrics.globalStub(env)
globalStub.reset(`{counterName}`)
Using fetch /counters
, /write
, /increment/:counterName
, /increments
const shardStub = Metrics.shardStub(env)
shardStub.fetch(`/increment/{counterName}`, { method: `POST` } )
//you can also use method directly
shardStub.increment(`{counterName}`)
increment multiple counters in one request
const shardStub = Metrics.shardStub(env)
shardStub.fetch(`/increments`, { method: `POST`, body: JSON.stringify({ counter1: 1, counter2: 1 }) } )
//you can also use method directly
shardStub.increments({ counter1: 1, counter2: 1 })
Leaving shardNumber
empty will randomly choose a shard for you
npm run build
build files for publishing npm package
npm run build-test
build test worker - used my miniflare
npm run test
run Worker DO with miniflare
npm run test-counter
run test scripts to send /increment post requests
FAQs
`npm i do-counter-sharding`
We found that do-counter-sharding demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.