
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.
@diagonal-finance/sdk-be
Advanced tools
SDK for easier interaction with the Diagonal backend (webhooks).
Diagonal SDK backend is a collection of classes which enables developers easier interaction with the Diagonal backend. |
---|
♜ Jest tests & common test coverage for all packages (npm test
)
♞ ESLint & Prettier to keep the code neat and well organized (npm run format
& npm run lint
)
♝ Automatic deployment of documentation generated with typedocs
Package | Version | Downloads | Size |
---|---|---|---|
@diagonal-finance/sdk-be (docs) |
|
|
|
yarn add @diagonal-finance/sdk-be
import {
IWebhookEvent,
WebhookEvent,
DiagonalError,
} from '@diagonal-finance/sdk-be'
import express from 'express'
const app = express()
const endpointSecret = '78...b1'
// Parse body into JSON
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
let payload = req.body
let signatureHeader = req.headers['diagonal-signature'] as string
let event: IWebhookEvent
try {
event = WebhookEvent.construct(payload, signatureHeader, endpointSecret)
} catch (e) {
if (e instanceof DiagonalError.InvalidPayloadError) {
// handle invalid payload error
} else if (e instanceof DiagonalError.InvalidEndpointSecretError) {
// handle invalid endpoint secret error
} else if (e instanceof DiagonalError.InvalidSignatureHeaderError) {
// handle invalid signature header
} else if (e instanceof DiagonalError.InvalidSignatureError) {
// handle invalid signature error
} else {
// handle another type of error
}
return res.sendStatus(400)
}
// Handle the event
switch (event.type) {
case WebhookEvent.Type.SubscriptionAcknowledged:
console.log(
`Account ${event.customerAddress} subscription was acknowledged!`,
)
// Then define and call a method to handle the acknowledged event
// handleAcknowledged(data);
break
case WebhookEvent.Type.SubscriptionFinalized:
console.log(
`Account ${event.customerAddress} subscription was finalized!`,
)
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handleFinalized(event);
break
case WebhookEvent.Type.SubscriptionReorged:
console.log(`Account ${event.customerAddress} subscription was re-orged!`)
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handleReorg(event);
break
case WebhookEvent.Type.SubscriptionCanceled:
console.log(`Account ${event.customerAddress} has canceled the subscription!`)
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handleUnsubscribe(event);
break
default:
// Unexpected event type
console.log(`Unhandled event type ${event.type}.`)
}
// Return a 200 response to acknowledge receipt of the event
res.sendStatus(200)
})
...
app.listen(3000, () => console.log('Running on port 3000'));
import {
Diagonal,
Config,
ICreateCheckoutSessionInput,
} from "@diagonal-finance/sdk-be";
const express = require("express");
const app = express();
const apiKey = "abc...";
const diagonal = new Diagonal(apiKey);
const YOUR_DOMAIN = "http://example.com";
app.post("/create-checkout-session", async (req, res) => {
const checkoutSessionInput: ICreateCheckoutSessionInput = {
customerId: "de49e7f2-bc33-4f4f-a3ae-c1207b02819c", // Immutable ID of your customer.
packageId: "ff4e1d23-54ab-4385-9ea9-02c58ec5e32a",
allowedChains: [Config.ChainId.Mumbai], // Optional. Can be used to limit to specific chains on runtime.
cancelUrl: new URL(`${YOUR_DOMAIN}/cancel`),
successUrl: new URL(`${YOUR_DOMAIN}/success`),
optimisticRedirect: true, // Optional. Used to redirect to the success url if TX has been confirmed (no waiting for long confirmation).
};
const checkoutSession = await diagonal.checkout.sessions.create(
checkoutSessionInput
);
console.info(`Checkout session created, UUID: ${checkoutSession.id}`);
res.redirect(303, checkoutSession.url);
});
import {
Diagonal,
Config,
ICreatePortalSessionInput,
} from "@diagonal-finance/sdk-be";
const express = require("express");
const app = express();
const apiKey = "abc...";
const diagonal = new Diagonal(apiKey);
const YOUR_DOMAIN = "http://example.com";
app.post("/create-portal-session", async (req, res) => {
const portalSessionInput: ICreatePortalSessionInput = {
customerId: "de49e7f2-bc33-4f4f-a3ae-c1207b02819c", // Immutable ID of your customer. Should not be email nor phone number.
configuration: {
availableChains: [Config.ChainId.Polygon],
availablePackages: ["de49e7f2-bc33-4f4f-a3ae-c1207b02819c"],
},
returnUrl: new URL(`${YOUR_DOMAIN}/return`),
};
const portalSession = await diagonal.portal.sessions.create(
portalSessionInput
);
console.info(`Portal session created, UUID: ${portalSession.id}`);
res.redirect(303, portalSession.url);
});
Clone this repository and install the dependencies:
git clone https://github.com/diagonal-finance/sdk-be.git
cd sdk-be && npm i
npm run lint # Syntax check with ESLint (yarn lint:fix to fix errors).
npm run prettier # Syntax check with Prettier (yarn prettier:fix to fix errors).
npm test # Run tests (with common coverage).
npm run build # Create a JS build.
npm run publish # Publish a package on npm.
FAQs
Diagonal finance Backend SDK
The npm package @diagonal-finance/sdk-be receives a total of 0 weekly downloads. As such, @diagonal-finance/sdk-be popularity was classified as not popular.
We found that @diagonal-finance/sdk-be 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.