Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coral-xyz/borsh

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coral-xyz/borsh

Anchor Borsh

  • 0.30.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
189K
increased by15.89%
Maintainers
0
Weekly downloads
 
Created

What is @coral-xyz/borsh?

@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.

What are @coral-xyz/borsh's main functionalities?

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);

Other packages similar to @coral-xyz/borsh

FAQs

Package last updated on 20 Jun 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc