Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@solana/addresses
Advanced tools
This package contains utilities for generating account addresses. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK @solana/web3.js@experimental
.
Base58EncodedAddress
This type represents a string that validates as a Solana address. Functions that require well-formed addresses should specify their inputs in terms of this type.
Whenever you need to validate an arbitrary string as a base58-encoded address, use the assertIsBase58EncodedAddress()
function in this package.
assertIsBase58EncodedAddress()
Client applications primarily deal with addresses and public keys in the form of base58-encoded strings. Addresses returned from the RPC API conform to the type Base58EncodedAddress
. You can use a value of that type wherever a base58-encoded address is expected.
From time to time you might acquire a string, that you expect to validate as an address, from an untrusted network API or user input. To assert that such an arbitrary string is a base58-encoded address, use the assertIsBase58EncodedAddress
function.
import { assertIsBase58EncodedAddress } from '@solana/addresses';
// Imagine a function that fetches an account's balance when a user submits a form.
function handleSubmit() {
// We know only that what the user typed conforms to the `string` type.
const address: string = accountAddressInput.value;
try {
// If this type assertion function doesn't throw, then
// Typescript will upcast `address` to `Base58EncodedAddress`.
assertIsBase58EncodedAddress(address);
// At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC.
const balanceInLamports = await rpc.getBalance(address).send();
} catch (e) {
// `address` turned out not to be a base58-encoded address
}
}
getBase58EncodedAddressFromPublicKey()
Given a public CryptoKey
, this method will return its associated Base58EncodedAddress
.
import { getBase58EncodedAddressFromPublicKey } from '@solana/addresses';
const address = await getBase58EncodedAddressFromPublicKey(publicKey);
getProgramDerivedAddress()
Given a program's Base58EncodedAddress
and up to 16 Seeds
, this method will return the program derived address (PDA) associated with each.
import { getBase58EncodedAddressCodec, getProgramDerivedAddress } from '@solana/addresses';
const { serialize } = getBase58EncodedAddressCodec();
const { bumpSeed, pda } = await getProgramDerivedAddress({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Base58EncodedAddress,
seeds: [
// Owner
serialize('9fYLFVoVqwH37C3dyPi6cpeobfbQ2jtLpN5HgAYDDdkm' as Base58EncodedAddress),
// Token program
serialize('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Base58EncodedAddress),
// Mint
serialize('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' as Base58EncodedAddress),
],
});
FAQs
Helpers for generating account addresses
The npm package @solana/addresses receives a total of 8,674 weekly downloads. As such, @solana/addresses popularity was classified as popular.
We found that @solana/addresses demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 14 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.