npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@guardian-network/policy-variables

v0.3.6

Published

Variables scrapping and encoding for policies infrastructure

Downloads

868

Readme

Helper library to populate Policy Variables offchain

DO NOT USE IN PRODUCTION.
This implementation is in early development. It has not been reviewed or audited. It is not suitable to be used in production. Expect bugs!

Policy may have variables values of which need to be provided during the evaluation step.
These values must be formatted and encoded into specific form that onchain Policy handler understands. This package is dedicated to help with it.


Variables can be injected or inserted.
Inserted variables are those that are just set by the user in a regular manner. They are only associated with their onchain name (in an artifact scope).
Injected variables, along with all the properties inserted have, also contain an attribute tag. Attribute tag is a simple string that contains the name of a property/field/variable existing internally in a middleware. We can consider any program having some internal attributes (time, tx_count, balance) and willing to automatically fill in these attributes being middleware.

Backend with a property server_time can be considered being middleware with an attribute server_time. Any policy containing injected variable with injection tag server_time can be automatically filled with the value of this property on the backend.


Usage

The main class needed is VariablesPopulator, exported from ./src.
It needs description of variables of a policy, returned by the onchain method of PolicyHandler.getVariablesList.
The populator can then be built:

const populator = new VariablesPopulator(rawOnchainVariables);

The populator instance now can be receive inserted variables via method insert:

populator.insert('argA_bool_0x084e6d675B4F24854f351f5A4E39E65E017d2954_2', true); // isAdmin

Or can automatically map injected variables, given the values source:

const internalAttributes = new Map();
internalAttributes.set('allowance', new Promise((resolve) => resolve(13_000)));
await populator.inject(internalAttributes);

The final encoded values can be obtained with the help of getVariablesEncoded method:

const vars = populator.getVariablesEncoded();

And then provided directely into evaluate onchain PolicyHandler method.

To list variables, use getVarsDescriptions method.

Validation

Except setters and getters, validation methods are provided.
validateAllFilled ensures all variable values (both inserted and injected) are filled.
validateAllFilledExceptInjections ensures inserted variable values are filled - ignoring injected consistency.

Interrupted flow

To fill the variables partially and then continue with other VariablesPopulator instance (but having same state), dump and import methods exist.
To dump already filled values, use dumpState method.
To import values filled previously into fresh VariablesPopulator instance use importState methods.

const oldPopulator = new VariablesPopulator(rawOnchainVariables);
// insert/inject
intermediateFillingResult = oldPopulator.dumpState();

// switching scope

const newPopulator = new VariablesPopulator(rawOnchainVariables);
newPopulator.importState(intermediateFillingResult);

// now oldPopulator is equivalent to newPopulator

Format details


Insertion operation uses unique variables names that is constructed in this way:
<name of the parameter on the artifact>_<its type>_<artifact address>_<index of the node in the policy graph>
This value is guaranteed to be unique for every variable in one policy and can be used to index them/grasp/select/etc.


Injection needs values source of the interface:

interface IAsyncMapGetter<ValueType> {
  get(key: string): Promise<ValueType> | ValueType | undefined;
}

So it can be a regular Map with string key and value/promise mappings, or more complex classes and objects.