diff --git a/.github/workflows/main_ci.yml b/.github/workflows/main_ci.yml new file mode 100644 index 0000000..4f7d04b --- /dev/null +++ b/.github/workflows/main_ci.yml @@ -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 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f6f1ffb..369f77f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 7e6957c..ca0aa19 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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**: @@ -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 ``` diff --git a/package.json b/package.json index 7a51767..84665db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bs58", - "version": "4.0.2", + "version": "5.0.0", "description": "Base 58 encoding / decoding", "keywords": [ "base58", @@ -15,7 +15,7 @@ ], "license": "MIT", "devDependencies": { - "standard": "*", + "standard": "^16.0.4", "tape": "^4.6.3" }, "repository": { @@ -34,6 +34,6 @@ "unit": "tape test/index.js" }, "dependencies": { - "base-x": "^3.0.7" + "base-x": "^4.0.0" } } diff --git a/test/index.js b/test/index.js index 88a87cc..f4500cb 100644 --- a/test/index.js +++ b/test/index.js @@ -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() })