Skip to content

Commit

Permalink
Merge pull request #44 from cryptocoinjs/feature/uint8array
Browse files Browse the repository at this point in the history
Use base-x v4 which returns Uint8Arrays
  • Loading branch information
junderw authored Feb 17, 2022
2 parents 6816bc7 + 499611a commit d77eedf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:

jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm run unit
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm run standard
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
5.0.0 / 2022-02-17
------------------
- `decode` and `decodeUnsafe` now return a Uint8Array.

4.0.0 / 2016-12-3
------------------
- `decode` now returns a `Buffer` again, to avoid potential cryptographic errors. [Daniel Cousens / #21](https://github.com/cryptocoinjs/bs58/pull/21)
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ API

### encode(input)

`input` must be a [Buffer](https://nodejs.org/api/buffer.html) or an `Array`. It returns a `string`.
`input` must be a `Uint8Array`, `Buffer`, or an `Array`. It returns a `string`.

**example**:

```js
const bs58 = require('bs58')

const bytes = Buffer.from('003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187', 'hex')
const bytes = Uint8Array.from([
0, 60, 23, 110, 101, 155, 234,
15, 41, 163, 233, 191, 120, 128,
193, 18, 177, 179, 27, 77, 200,
38, 38, 129, 135
])
const address = bs58.encode(bytes)
console.log(address)
// => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS
Expand All @@ -35,7 +40,7 @@ console.log(address)

### decode(input)

`input` must be a base 58 encoded string. Returns a [Buffer](https://nodejs.org/api/buffer.html).
`input` must be a base 58 encoded string. Returns a Uint8Array.

**example**:

Expand All @@ -44,7 +49,8 @@ const bs58 = require('bs58')

const address = '16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS'
const bytes = bs58.decode(address)
console.log(bytes.toString('hex'))
// See uint8array-tools package for helpful hex encoding/decoding/compare tools
console.log(Buffer.from(bytes).toString('hex'))
// => 003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187
```

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bs58",
"version": "4.0.2",
"version": "5.0.0",
"description": "Base 58 encoding / decoding",
"keywords": [
"base58",
Expand All @@ -15,7 +15,7 @@
],
"license": "MIT",
"devDependencies": {
"standard": "*",
"standard": "^16.0.4",
"tape": "^4.6.3"
},
"repository": {
Expand All @@ -34,6 +34,6 @@
"unit": "tape test/index.js"
},
"dependencies": {
"base-x": "^3.0.7"
"base-x": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('base58', function (t) {
t.test('decode', function (t) {
fixtures.valid.forEach(function (f) {
t.test('can decode ' + f.string, function (t) {
const actual = base58.decode(f.string).toString('hex')
const actual = Buffer.from(base58.decode(f.string)).toString('hex')
t.same(actual, f.hex)
t.end()
})
Expand Down

0 comments on commit d77eedf

Please sign in to comment.