Skip to content
/ borsh-js Public
forked from near/borsh-js

TypeScript/JavaScript implementation of Binary Object Representation Serializer for Hashing

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT.txt
Notifications You must be signed in to change notification settings

ansbr/borsh-js

 
 

Repository files navigation

Borsh JS ESM

Borsh ESM is an implementation of the Borsh compatible with ES modules.

That package implemented as experiment, and tested only in browser.

Examples

Serializing an object

const value = new Test({ x: 255, y: 20, z: '123', q: [1, 2, 3] });
const schema = new Map([[Test, { kind: 'struct', fields: [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] }]]);
const buffer = borsh.serialize(schema, value);

Deserializing an object

const newValue = borsh.deserialize(schema, Test, buffer);

Type Mappings

Borsh TypeScript
u8 integer number
u16 integer number
u32 integer number
u64 integer BN
u128 integer BN
u256 integer BN
u512 integer BN
f32 float N/A
f64 float N/A
fixed-size byte array Uint8Array
UTF-8 string string
option null or type
map N/A
set N/A
structs any

Contributing

Install dependencies:

yarn install

Continuously build with:

yarn dev

Run tests:

yarn test

Run linter

yarn lint

Publish

Prepare dist version by running:

yarn build

When publishing to npm use np.

License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for details.

About

TypeScript/JavaScript implementation of Binary Object Representation Serializer for Hashing

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 72.3%
  • TypeScript 27.5%
  • Shell 0.2%