
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.
The purpose of this module was to create a simple dependency injection module for functions. This makes writing unit tests a breeze.
npm i funjector --save
Say I have a scenario where there is a function A
that I want to test, which internally calls another global function B
. For the sake of simplicity lets also assume that both the functions a truly pure.
function B (x) {
return x * 100
}
function A (x, y) {
return B(x + y)
}
There are multiple ways you can test function A()
B()
and let A use the global B function. In this approach you end up testing the B function as well. This is fine if the function is simple and is only being used by A. If the function is complex and say performs some time consuming operations, then its always better to mock B.require
and process
.function B (x) {
return x * 100
}
function A (B, x, y) {
return B(x + y)
}
A(B, 10, 20) // Sample Call for function A
Though this seems like a good solution but it comes with a major drawback — Wherever I am going to use A, I will have to pass an additional param B to it.
This can get out of control pretty easily —
function C (x) {
return x - 1
}
function B (C, x) {
return C(x * 100)
}
function A (B, C, x, y) {
return B(C, x + y)
}
A(B, C, 10 ,20)
As you can, though A only needs three params viz — B, x, y I have to pass C because internally B needs C! This is still an overly simplified version of issues one might face.
import {partial, call} from 'funjector'
function C (x) {
return x - 1
}
// Binds the function B with C as the first param
const B = partial(function (C, x) {
return C(x * 100)
}, C)
// Binds the function A with B as the first param
const A = partial(function (B, x, y) {
return B(x + y)
}, B)
A(10, 20) // Calls the partialized version of the function
call(A, i => i + 1, 10, 20) // Calls the original function A with a custom implementation of B
Creates a function that calls func with args arguments prepended to those provided to the new function.
import {partial} from 'funjector'
const a = partial((x, y) => x * y, 10)
a(3) // OUTPUTS: 30
a(4) // OUTPUTS: 40
calls a partialized function returned by partial(), with the passed args ignoring all the arguments that were passed as the bindings.
import {call, partial} from 'funjector'
const a = partial((x, y) => x * y, 10)
call(a, 9, 3) // OUTPUTS: 27 and not 30
call(a, 9, 4) // OUTPUTS: 36 and not 40
exactly like call() except that the second param is used as the context with which the function func is invoked.
a placeholder that can be used with the function partial() to selectively control the order of arguments that are being passed the function.
import {SKIP, partial} from 'funjector'
const a = partial((a, b, c, d) => [a, b, c, d], 1, SKIP, SKIP, 4)
a(2, 3) // OUTPUTS: [1, 2, 3, 4]
FAQs
dependency injection for functional paradigm
We found that funjector 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.