
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@coral-xyz/borsh
Advanced tools
@coral-xyz/borsh is a JavaScript library for serializing and deserializing data using the Binary Object Representation Serializer for Hashing (BORSH) format. It is commonly used in blockchain applications, particularly with Solana, to efficiently encode and decode data structures.
Serialization
This feature allows you to serialize a JavaScript object into a binary format using a predefined schema. The code sample demonstrates how to define a schema for a custom class and serialize an instance of that class.
const borsh = require('@coral-xyz/borsh');
class MyStruct {
constructor(fields) {
this.field1 = fields.field1;
this.field2 = fields.field2;
}
}
const schema = new Map([
[MyStruct, { kind: 'struct', fields: [['field1', 'u32'], ['field2', 'string']] }]
]);
const myStruct = new MyStruct({ field1: 123, field2: 'hello' });
const serialized = borsh.serialize(schema, myStruct);
console.log(serialized);
Deserialization
This feature allows you to deserialize a binary format back into a JavaScript object using a predefined schema. The code sample demonstrates how to define a schema for a custom class and deserialize a binary array into an instance of that class.
const borsh = require('@coral-xyz/borsh');
class MyStruct {
constructor(fields) {
this.field1 = fields.field1;
this.field2 = fields.field2;
}
}
const schema = new Map([
[MyStruct, { kind: 'struct', fields: [['field1', 'u32'], ['field2', 'string']] }]
]);
const serialized = new Uint8Array([123, 0, 0, 0, 5, 0, 0, 0, 104, 101, 108, 108, 111]);
const deserialized = borsh.deserialize(schema, MyStruct, serialized);
console.log(deserialized);
buffer-layout is a library for serializing and deserializing binary data in JavaScript. While it is not specifically designed for the BORSH format, it provides similar capabilities for defining and working with binary data structures.
protobufjs is a JavaScript library for working with Protocol Buffers, a different binary serialization format. It offers more features and flexibility compared to BORSH but may be more complex to use.
FAQs
Anchor Borsh
The npm package @coral-xyz/borsh receives a total of 330,155 weekly downloads. As such, @coral-xyz/borsh popularity was classified as popular.
We found that @coral-xyz/borsh 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.