Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@radixdlt/data-formats
Advanced tools
@radixdlt/data-formats
Without dependencies, using provided taggedStringDecoder:
import { JSONDecoding, taggedStringDecoder } from '@radixdlt/data-formats'
const strTagDecoder = taggedStringDecoder(':str:')((value) => ok(value))
const { fromJSON } = JSONDecoding.withDecoders(strTagDecoder).create()
fromJSON(':str:xyz') // Ok('xyz')
An object with dependencies:
import { JSONDecoding, taggedStringDecoder } from '@radixdlt/data-formats'
import { ok } from 'neverthrow'
const strTagDecoder = taggedStringDecoder(':str:')((value) => ok(value))
const Object1 = {
...JSONDecoding.withDecoders(strTagDecoder).create()
}
const tstTagDecoder = taggedStringDecoder(':tst:')((value) => ok(value))
const { fromJSON } = JSONDecoding
.withDependencies(Object1)
.withDecoders(testTagDecoder)
.create()
fromJSON({
a: ':str:foo',
b: ':tst:bar'
}) // ok({ a: 'foo', b: 'bar' })
JSON decoding takes an object and applies decoder
s to each key-value pair. taggedObjectDecoder
and taggedStringDecoder
are provided, but you can easily define a new decoder. Here is how taggedStringDecoder
is defined:
import { decoder } from '@radixdlt/data-formats'
export const taggedStringDecoder = (tag: string) => <T>(
algorithm: (value: string) => Result<T, Error>,
): Decoder =>
decoder<T>((value) =>
isString(value) && `:${value.split(':')[1]}:` === tag
? algorithm(value.slice(tag.length))
: undefined,
)
A decoder
should supply a function that defines how the decoding should be applied. First it should do some validation logic (does this decoder apply to this value?), in this case checking if the value is a string and if has a matching tag. Then, apply some algorithm
function, which is the actual decoding (create an instance of some object). If the validation fails, the decoder has to return undefined
.
FAQs
Data formats used for serialization.
We found that @radixdlt/data-formats demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.