
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@codama/dynamic-parsers
Advanced tools
Helpers to dynamically identify and parse accounts and instructions
This package provides a set of helpers that, given any Codama IDL, dynamically identifies and parses any byte array into deserialized accounts and instructions.
pnpm install @codama/dynamic-parsers
[!NOTE] This package is not included in the main
codama
package.
ParsedData<TNode>
This type represents the result of identifying and parsing a byte array from a given root node. It provides us with the full NodePath
of the identified node, as well as the data deserialized from the provided bytes.
type ParsedData<TNode extends AccountNode | InstructionNode> = {
data: unknown;
path: NodePath<TNode>;
};
parseAccountData(rootNode, bytes)
Given a RootNode
and a byte array, this function will attempt to identify the correct account node and use it to deserialize the provided bytes. Therefore, it returns a ParsedData<AccountNode>
object if the parsing was successful, or undefined
otherwise.
const parsedData = parseAccountData(rootNode, bytes);
// ^ ParsedData<AccountNode> | undefined
if (parsedData) {
const accountNode: AccountNode = getLastNodeFromPath(parsedData.path);
const decodedData: unknown = parsedData.data;
}
parseInstructionData(rootNode, bytes)
Similarly to parseAccountData
, this function will match the provided bytes to an instruction node and deserialize them accordingly. It returns a ParsedData<InstructionNode>
object if the parsing was successful, or undefined
otherwise.
const parsedData = parseInstructionData(rootNode, bytes);
// ^ ParsedData<InstructionNode> | undefined
if (parsedData) {
const instructionNode: InstructionNode = getLastNodeFromPath(parsedData.path);
const decodedData: unknown = parsedData.data;
}
parseInstruction(rootNode, instruction)
This function accepts a RootNode
and an Instruction
type — as defined in @solana/instructions
— in order to return a ParsedData<InstructionNode>
object that also includes an accounts
array that match each AccountMeta
with its corresponding account name.
const parsedData = parseInstruction(rootNode, instruction);
if (parsedData) {
const namedAccounts = parsedData.accounts;
// ^ Array<AccountMeta & { name: string }>
}
identifyAccountData
This function tries to match the provided bytes to an account node, returning a NodePath<AccountNode>
object if the identification was successful, or undefined
otherwise. It is used by the parseAccountData
function under the hood.
const path = identifyAccountData(root, bytes);
// ^ NodePath<AccountNode> | undefined
if (path) {
const accountNode: AccountNode = getLastNodeFromPath(path);
}
identifyInstructionData
This function tries to match the provided bytes to an instruction node, returning a NodePath<InstructionNode>
object if the identification was successful, or undefined
otherwise. It is used by the parseInstructionData
function under the hood.
const path = identifyInstructionData(root, bytes);
// ^ NodePath<InstructionNode> | undefined
if (path) {
const instructionNode: InstructionNode = getLastNodeFromPath(path);
}
FAQs
Helpers to dynamically identify and parse accounts and instructions
The npm package @codama/dynamic-parsers receives a total of 80 weekly downloads. As such, @codama/dynamic-parsers popularity was classified as not popular.
We found that @codama/dynamic-parsers 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.