Socket
Socket
Sign inDemoInstall

borsh

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

borsh

Binary Object Representation Serializer for Hashing


Version published
Weekly downloads
367K
increased by1.36%
Maintainers
3
Weekly downloads
 
Created

What is borsh?

The borsh npm package is a JavaScript implementation of the Binary Object Representation Serializer for Hashing (BORSH) serialization format. It is used to serialize and deserialize complex data structures in a compact binary format, which is particularly useful in blockchain and other performance-critical applications.

What are borsh's main functionalities?

Serialization

This feature allows you to serialize JavaScript objects into a binary format. The code sample demonstrates how to define a schema for a class and serialize an instance of that class.

const borsh = require('borsh');

class Greeting {
  constructor({ message }) {
    this.message = message;
  }
}

const schema = new Map([
  [Greeting, { kind: 'struct', fields: [['message', 'string']] }]
]);

const greeting = new Greeting({ message: 'Hello, world!' });
const serialized = borsh.serialize(schema, greeting);
console.log(serialized);

Deserialization

This feature allows you to deserialize binary data back into JavaScript objects. The code sample shows how to deserialize a binary array into an instance of a class using a predefined schema.

const borsh = require('borsh');

class Greeting {
  constructor({ message }) {
    this.message = message;
  }
}

const schema = new Map([
  [Greeting, { kind: 'struct', fields: [['message', 'string']] }]
]);

const serialized = new Uint8Array([10, 0, 0, 0, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]);
const deserialized = borsh.deserialize(schema, Greeting, serialized);
console.log(deserialized);

Other packages similar to borsh

Keywords

FAQs

Package last updated on 04 Dec 2020

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