
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.
Exposes a way to enforce an interface on classes.
npm install --save interface
To enforce an interface, first create a new Interface
and pass it the function names that you want to enforce.
const MyInterface = Interface.create('myMethodA', 'myMethodB')
or alternatively
const MyInterface = new Interface('myMethodA', 'myMethodB')
Next, just make your class extend from the interface. Make sure you call super()
within your class's constructor.
class MyClass extends MyInterface {
constructor () {
super()
}
myMethodA () {
// ...implementation goes here
}
}
Now, whenever you try to instantiate MyClass
, the interface will be enforced.
let instance = new MyClass()
// throws a new error with the message:
// 'The following function(s) need to be implemented for class MyClass: myMethodB'
Of course, the interface is enforced on all subclasses as well.
class MySubClass extends MyClass {
constructor () {
super()
}
myMethodA () {
// override 'myMethodA'
}
}
let instance = new MySubClass()
// still throws an error with the message:
// 'The following function(s) need to be implemented for class MyClass: myMethodB'
Interfaces can be enforced for classes defined the old way too.
const inherits = require('util').inherits
var MyInterface = new Interface('myMethodA', 'myMethodB', 'myMethodC')
function MyClass () {
MyInterface.call(this)
}
inherits(MyClass, MyInterface)
MyClass.prototype.myMethodA = function () {
// implementation
}
function MySubClass () {
MyClass.call(this)
}
// inherit prototype of parent class
inherits(MySubClass, MyClass)
MySubClass.prototype.myMethodB = function () {
// implementation
}
var instance = new MySubClass()
// throws an error with the message:
// 'The following function(s) need to be implemented for class MyClass: myMethodC'
FAQs
Enforce an interface on classes
The npm package interface receives a total of 4,191 weekly downloads. As such, interface popularity was classified as popular.
We found that interface demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.