Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@equilab/api
Advanced tools
$ npm i --save @equilab/api # if you are using npm or
$ yarn add @equilab/api # for yarn package manager
Use getApiCreator(nodeSpec: "Eq" | "EqNext" | "Genshiro") factory from @equilab/api package
Import modules from equilibrium interfaces to access types from @polkadot/types/lookup
.
Example:
import { EqPrimitivesSignedBalance } from "@polkadot/types/lookup";
import "@equilab/api/equilibrium/interfaces/augment-api";
import "@equilab/api/equilibrium/interfaces/types-lookup";
import { getApiCreator } from "@equilab/api";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import Keyring from "@polkadot/keyring";
async function main() {
await cryptoWaitReady();
const keyring = new Keyring({ ss58Format: 68 });
SEED_PHRASES.forEach((seed) => keyring!.addFromMnemonic(seed, {}, "sr25519"));
const api = await getApiCreator("Eq")(TESTNET_NODE);
const balances = await getBalances(api)(
"cg73qE7Zgu8i8CYEPcFK65iMZ7EAYrV1jJi5dTSiEuHSA9nN7",
);
console.log("balances", balances);
await transfer(
api,
keyring,
)({
token: "eq",
from: "cg7ENkxLYjpXV2QWjw5murokf8ZxUNkjjhCkqqxxAP7svN49A",
to: "cg73qE7Zgu8i8CYEPcFK65iMZ7EAYrV1jJi5dTSiEuHSA9nN7",
amount: "12000000000",
});
process.exit();
}
Storage queries are compliant with Polkadot.JS storage interfaces.
Get balances from storage method is using currencyFromU64
to decode asset u64 id into token name (eg 'eq')
import { currencyFromU64, u64FromCurrency } from "@equilab/api/equilibrium";
function getBalances(api: Api) {
return async function (account: string): Promise<{
ok: boolean;
lock?: string;
balances?: Map<string, string>;
}> {
const accountInfo = await api._api.query.system.account(account);
if (!accountInfo.data.isV0) return { ok: false };
const lock = accountInfo.data.asV0.lock.toString(10);
const balances = accountInfo.data.asV0.balance
.toArray()
.reduce(
(acc, [id, balance]) =>
acc.set(
currencyFromU64(id),
balance.isPositive
? balance.asPositive.toString(10)
: `-${balance.asNegative.toString(10)}`,
),
new Map<string, string>(),
);
return { ok: true, lock, balances };
};
}
Successfull output looks like this:
{ ok: true, lock: '22000000000', balances: { 'eq' => '72000000000', 'dot' => '597056440465' } }
Balance has 1e9 decimals places and thus '72000000000' equals 72 eq.
Transactions are compliant with Polkadot.JS transactions.
Equilibrium palletes and methods can be accessed using _api
ApiPromise interface.
function transfer(api: Api, keyring: Keyring) {
return async function ({
token,
from,
to,
amount,
}: {
token: string;
from: string;
to: string;
amount: string;
}) {
try {
const tx = api._api.tx.eqBalances.transfer(
u64FromCurrency(token),
to,
amount,
);
const keyPair = keyring.getPair(from);
const res = await tx.signAndSend(keyPair, { nonce: -1 });
console.log("tx result: ", res.toJSON());
} catch (e) {
console.error(e);
}
};
}
This example is using keyring to create key pairs from seed phrases. When using wallet on frontend account address can be used instead of key pair.
Our public DEX API contains various examples of rxjs api usage:
FAQs
JS API for Equilibrium and Genshiro parachains.
We found that @equilab/api demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.