Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
defender-autotask-utils
Advanced tools
Readme
The Defender Autotasks service allows you to run small code snippets on a regular basis or via webhooks that can make calls to the Ethereum network or to external APIs. Thanks to tight integration to Defender Relayers, you can use Autotasks to automate regular actions on your contracts.
This library provides typings for simplifying the writing of Autotask code when using Typescript.
Note: For programmatically interacting with your Autotasks, such as updating their code from your local workstation, check out the defender-autotask-client
package.
npm install defender-autotask-utils
yarn add defender-autotask-utils
This library includes typings for 1) the event payload injected by Defender when invoking an Autotask, and 2) the result expected by Defender from an Autotask when used as a Sentinel condition.
AutotaskEvent
Event data injected by Defender when invoking an Autotask. Includes credentials for communicating with whitelisted internal services, as well as the main request
object of type AutotaskRequestData
. This data contains a main payload that varies depending on the Autotask trigger:
SentinelConditionRequest
when invoked as a Sentinel condition.SentinelTriggerEvent
when invoked as Sentinel notificationExample usage for a Sentinel trigger event:
import {
AutotaskEvent,
SentinelTriggerEvent,
SubscriberType,
BlockTriggerEvent,
FortaTriggerEvent,
isTxAlert,
isBlockAlert,
} from 'defender-autotask-utils';
export async function handler(event: AutotaskEvent) {
const payload = event.request.body as SentinelTriggerEvent;
// You can either check the payload type to destructure the correct properties
if (payload.type == SubscriberType.BLOCK) {
const { transaction, matchReasons } = payload;
} else if (payload.type == SubscriberType.FORTA) {
const { alert, matchReasons } = payload;
}
// Or if you know what type of sentinel you'll be using
// Contract Sentinel
const contractPayload = event.request.body as BlockTriggerEvent;
const { transaction, matchReasons } = contractPayload;
// Forta Sentinel
const fortaPayload = event.request.body as FortaTriggerEvent;
const { alert, matchReasons } = fortaPayload;
// For forta Alerts you can check whether the alert is related to a transaction or a block
if (isTxAlert(alert)) {
// Do something here
} else if (isBlockAlert(alert)) {
// Do something here
}
// Rest of logic...
}
SentinelConditionResponse
When invoked as a Sentinel condition, the Autotask is expected to return the list of matches, refined from the set of potential transactions initially matched by the Sentinel.
import {
AutotaskEvent,
SentinelConditionRequest,
SentinelConditionResponse,
SentinelConditionMatch,
SubscriberType,
isTxAlert,
isBlockAlert,
} from 'defender-autotask-utils';
export async function handler(event: AutotaskEvent): Promise<SentinelConditionResponse> {
const { events } = event.request.body as SentinelConditionRequest;
const matches: SentinelConditionMatch[] = [];
for (const match of events) {
if (match.type == SubscriberType.BLOCK) {
// Custom logic to decide whether this tx should be matched by the Sentinel
if (!shouldMatch(match.transaction)) continue;
} else if (match.type == SubscriberType.FORTA) {
// For forta alerts you can check whether the alert is related to a transaction or a block
if (isTxAlert(match.alert)) {
// Do something here
} else if (isBlockAlert(match.alert)) {
// Do something here
}
if (!shouldMatch(match.alert)) continue;
}
// Metadata can be any JSON-marshalable object (or undefined)
matches.push({ hash: match.hash, metadata: { id: 'myCustomId' } });
}
return { matches };
}
FAQs
Utils library for writing Defender Autotasks
The npm package defender-autotask-utils receives a total of 972 weekly downloads. As such, defender-autotask-utils popularity was classified as not popular.
We found that defender-autotask-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.