
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.
@loke/context
Advanced tools
A typescript version of the go context package.
npm install @loke/context
import * as context from "@loke/context";
import { Context } from "@loke/context";
async function getUser(cxt: Context, id: string): Promise<unknown> {
const { ctx, abort } = context.withTimeout(cxt, 1000);
try {
const res = await fetch(`/users/${id}`, { signal: ctx.signal });
if (res.ok) {
throw new Error("not ok");
}
return await res.json();
} finally {
abort();
}
}
type Context = {
readonly signal?: AbortSignal;
readonly deadline?: number;
};
type Abortable = {
readonly ctx: Context;
readonly abort: () => void;
};
const background: Context;
const TODO: Context;
parent
- The parent context to extend.Extends the parent context with an abortable signal. The signal is aborted when the returned abort function is called or when the parent context is aborted.
The returned abort
function MUST be called to avoid memory leaks.
parent
- The parent context to extend.duration
- The timeout in milliseconds.Extends the parent context with an abortable signal. The signal is aborted when the returned abort function is called, when the parent context is aborted or when the timeout is reached.
The returned abort
function MUST be called to avoid memory leaks.
parent
- The parent context to extend.deadline
- The deadline as a date or a timestamp in milliseconds.Extends the parent context with an abortable signal. The signal is aborted when the returned abort function is called, when the parent context is aborted or when the deadline is reached.
The returned abort
function MUST be called to avoid memory leaks.
parent
- The parent context to extend.values
- The values to add to the context.Extends the parent context with a set of values. To help with type safety the keys should be symbols, and accessed using custom getters. You can also use a custom setter to ensure that the values are of the correct type, this may be overkill if you only set the values once.
Example
const localeKey = Symbol("locale");
export function withLocale(parent: Context, locale: string): Context {
return context.withValues(parent, {
[localeKey]: locale,
});
}
export function getLocale(ctx: Context): string {
if (localeKey in ctx) {
return ctx[localeKey];
} else {
return "en";
}
}
const requestIdKey: symbol;
Example
const ctx = context.withValues(context.background, {
[context.requestIdKey]: "1234",
});
Example
const requestId = getRequestId(ctx);
FAQs
A typescript version of the go context package.
We found that @loke/context demonstrated a healthy version release cadence and project activity because the last version was released less than 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.