Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcoin-org/bstring
String encodings for javascript
https://github.com/bcoin-org/bstring
Last synced: 6 days ago
JSON representation
String encodings for javascript
- Host: GitHub
- URL: https://github.com/bcoin-org/bstring
- Owner: bcoin-org
- License: other
- Created: 2017-11-02T14:31:51.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-03T01:38:37.000Z (over 5 years ago)
- Last Synced: 2024-09-19T00:57:11.203Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 325 KB
- Stars: 4
- Watchers: 9
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bstring
String encodings for javascript.
## Usage
``` js
'use strict';const assert = require('assert');
const {base58, bech32, cashaddr} = require('bstring');// Base58
const b58 = base58.encode(Buffer.from([1,2,3]));
assert(base58.test(b58));
const data = base58.decode(b58);
console.log(data);// Bech32
const b32 = bech32.encode('bc', 0, Buffer.alloc(20, 0x10));
assert(bech32.test(b32));
const {hrp, version, hash} = bech32.decode(b32);
console.log([hrp, version, hash]);// CashAddr
const address = cashaddr.encode('bitcoincash', 0, Buffer.alloc(20, 0x10));
assert(cashaddr.test(address));
const res1 = cashaddr.decode(address);
console.log([res1.prefix, res1.type, res1.hash]);const noPrefixAddress = address.split(':')[1];
assert(cashaddr.test(noPrefixAddress, 'bitcoincash'));
const res2 = cashaddr.decode(noPrefixAddress, 'bitcoincash');
console.log([res2.prefix, res2.type, res2.hash]);
```## Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. ``## License
- Copyright (c) 2017, Christopher Jeffrey (MIT License).
See LICENSE for more info.