Go to file
Bo Yao 6db74764ce
add build to ci and fix build (#58)
* add build to ci

* fix build by upgrade typescript to 4

* prettier deleted, eslint updated

* lint fix

* js files formatted

* d.ts files ignored

* ts files filtered

* index formatted

* return type added to all functions

* no-explicit-any turned of

* ban-types set to 1

Co-authored-by: Serhii Volovyk <sergeyvolovyk@gmail.com>
2022-06-16 15:02:54 +08:00
.github/workflows add build to ci and fix build (#58) 2022-06-16 15:02:54 +08:00
borsh-ts add build to ci and fix build (#58) 2022-06-16 15:02:54 +08:00
lib add build to ci and fix build (#58) 2022-06-16 15:02:54 +08:00
.eslintignore add build to ci and fix build (#58) 2022-06-16 15:02:54 +08:00
.eslintrc.yml rust related things deleted 2020-12-01 00:20:20 +02:00
.gitignore rust related things deleted 2020-12-01 00:20:20 +02:00
.prettierignore Add Prettier to keep code consistent. (#33) 2021-09-21 10:36:27 +03:00
.travis.yml feat(travis): run on all branches 2021-01-27 13:49:53 +00:00
CNAME Missing CNAME file 2019-09-02 18:10:47 -07:00
CODEOWNERS code owners updated 2020-12-03 14:04:36 +02:00
LICENSE-APACHE standardize to be dual license MIT and Apache (#63) 2020-05-19 08:59:06 -07:00
LICENSE-MIT.txt standardize to be dual license MIT and Apache (#63) 2020-05-19 08:59:06 -07:00
README.md Add option support to deserialize (#16) 2021-05-05 15:18:29 +03:00
package.json add build to ci and fix build (#58) 2022-06-16 15:02:54 +08:00
tsconfig.json Updates from near-api-js (#105) 2020-11-30 17:59:59 +02:00

README.md

Borsh JS

Project license Project license Discord Travis status NPM version Size on NPM

Borsh JS is an implementation of the Borsh binary serialization format for JavaScript and TypeScript projects.

Borsh stands for Binary Object Representation Serializer for Hashing. It is meant to be used in security-critical projects as it prioritizes consistency, safety, speed, and comes with a strict specification.

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.