
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@swear-js/core
Advanced tools
Core package of SwearJS state manager
Demo application is runnable via npx:
$ npx swear-demo-agnostic
Don't forget to remove created project directory after
useState
. No way simpler.core
package is for you.$ npm install @swear-js/core
or in case you are using Yarn:
$ yarn add @swear-js/core
First you have to initialize your store.
import { createStore, createSwear } from "@swear-js/core";
const store = createStore();
// Create swear
const countSwear = createSwear('count', 0, (mutate) => ({
increase: () => mutate(prev => prev + 1),
decrease: () => mutate(prev => prev - 1),
}));
// Callback is triggered on every swear update
store.subscribe(countSwear, (newValue) => {
// Handle updates of countSwear
console.log(newValue);
});
// This will return object of actions with default actions: set() and reset(), and your own defined actions.
const actions = store.getSwearActions(countSwear);
const { set, reset, increase, decrease } = actions; // set() and reset() are default actions
increase(); // When you dispatch an action, swear value is mutated, and subscribtion callback is triggered.
store.getSwearActions()
returns an object of combined default actions and your actions.
set()
action implements the same usage interface as React's useState setter. It means you can pass both a payload, and callback with previous value. Example:set((prev) => prev + 10);
You can pass your custom logger to the store, or use @swear-js/logger. Swear-js logger usage:
import { createStore } from "@swear-js/core";
import { swearLogger } from "@swear-js/logger";
const store = createStore({ onPatch: swearLogger });
In order to implement your own logger solution, you just have to keep in mind an API of onPatch
argument of the store.
onPatch
is any callback that get SwearPatch
(you can find it in package) type as an argument.
Simply SwearPatch is:
{
swearId, // String value which gets a name of patched swear state
tag, // String value which gets an optional tag, you want to set
prev, // Previous store state (object)
payload, // Payload passed
next // Current store state
}
Example very-simple implementation of logger:
import { SwearPatch, createStore } from "@swear-js/core";
const logger = ({ swearId, tag, prev, payload, next }: SwearPatch) => {
console.log(`Swear: ${swearId}, Tag: ${tag}, Payload: ${payload}`);
console.log(`Previous state: ${prev}`, `Current state: ${next}`);
};
const store = createStore({ onPatch: logger });
Inspired by @artalar's Reatom.
FAQs
Simple observer state manager
We found that @swear-js/core 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.