Socket
Socket
Sign inDemoInstall

@dashincubator/ripemd160

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dashincubator/ripemd160 - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

21

package.json
{
"name": "@dashincubator/ripemd160",
"version": "2.3.0",
"version": "3.0.0",
"description": "Browser-friendly ripemd160 hasher",

@@ -15,3 +15,3 @@ "keywords": [

"license": "MIT",
"main": "./index.js",
"main": "./ripemd160.js",
"files": [

@@ -30,21 +30,12 @@ "index.js",

"build:types": "tsc --build",
"bump": "npm version -m \"chore(release): bump to v%s\"",
"test": "npm run lint && npm run unit && npm run unit:browser",
"unit": "mocha test/*.js",
"unit:browser": "polendina --runner=mocha --page --worker --serviceworker --cleanup test/index.js",
"unit:browser": "npx polendina@3 --runner=mocha --page --worker --serviceworker --cleanup test/index.js",
"build": "npm run build:types",
"doc": "npx jsdoc@3.x --configure ./jsdoc.conf.json --destination ./docs --package ./package.json --readme ./README.md --access all --private --recurse ./lib/",
"fmt": "npx -p prettier@2.x -- prettier -w '**/*.{js,md}'",
"prepublish": "npx -p jswt@1.x -- reexport",
"version": "npm version -m \"chore(release): bump to v%s\""
"fmt": "npx -p prettier@2.x -- prettier -w '**/*.{js,md}'"
},
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/mocha": "^10.0.0",
"chai": "^4.3.6",
"hash-test-vectors": "^1.3.2",
"mocha": "^10.0.0",
"multiformats": "^9.6.4",
"polendina": "^3.0.0",
"standard": "^17.0.0",
"typescript": "^4.6.3"
"multiformats": "^9.9.0"
},

@@ -51,0 +42,0 @@ "release": {

@@ -32,6 +32,19 @@ # @dashincubator/ripemd160

```js
let hash = RIPEMD160.create();
hash.update("42");
let data = new Uint8Array([52, 50]);
let hex = hash.digest("hex");
let ripemd160 = RIPEMD160.create();
ripemd160.update(data);
let hash = ripemd160.digest();
console.log(hash);
// Uint8Array(20) [ 13, 240, ... 139, 200 ]
```
Uint8Array to Hex:
```js
let hex = hash.reduce(function (hex, byte) {
return hex + byte.toString(16).padStart(2, "0");
}, "");
console.log(hex);

@@ -41,2 +54,10 @@ // "0df020ba32aa9b8b904471ff582ce6b579bf8bc8"

String to Uint8Array:
```js
let message = "42";
let utf8Encoder = new TextEncoder();
let data = utf8Encoder.encode(message);
```
## History

@@ -49,4 +70,6 @@

- Adds TypeScript types exports
- Operates natively on `Uint8Array`s
- Has no dependencies, even in the browser (i.e. no `Buffer`)
- Operates natively on `Uint8Array`s ONLY
- (use `new TextEncoder().encode(str)` encode strings to `Uint8Array`s
- Has no dependencies, even in the browser (i.e. no `Buffer`, no
`TextEncoder`)
- Does not handle streaming operations (i.e. just use `update()` and

@@ -53,0 +76,0 @@ `digest()`)

@@ -1,5 +0,34 @@

(function (exports) {
/**
* @typedef RIPEMD160
* @prop {RipeCreate} create
*/
/**
* @callback RipeCreate
* @returns {ripemd160}
*/
/**
* @typedef ripemd160
* @prop {RipeUpdate} update
* @prop {RipeDigest} digest
*/
/**
* @callback RipeDigest
* @returns {Uint8Array}
*/
/**
* @callback RipeUpdate
* @param {Uint8Array} data
* @returns {ripemd160}
*/
/** @type {RIPEMD160} */
//@ts-ignore
var RIPEMD160 = ("object" === typeof module && exports) || {};
(function (window, RIPEMD160) {
"use strict";
const utf8Encoder = new TextEncoder();
const ARRAY16 = new Array(16);

@@ -40,3 +69,3 @@

class RIPEMD160 {
class _RIPEMD160 {
constructor() {

@@ -68,6 +97,3 @@ // state

/**
* @param {Uint8Array|string} data
* @returns {RIPEMD160}
*/
/** @type {RipeUpdate} */
update(data) {

@@ -77,7 +103,4 @@ if (this._finalized) {

}
if (typeof data === "string") {
data = utf8Encoder.encode(data);
}
if (!(data instanceof Uint8Array)) {
throw new Error("update() requires a Uint8Array or string");
throw new Error("update() requires a Uint8Array");
}

@@ -177,6 +200,2 @@

/**
* @param {'hex'} [encoding]
* @returns {Uint8Array|string}
*/
digest(encoding) {

@@ -189,11 +208,2 @@ if (this._finalized) {

const dig = this._digest();
if (encoding) {
if (encoding === "hex") {
return dig.reduce(
(hex, byte) => hex + byte.toString(16).padStart(2, "0"),
"",
);
}
throw new Error(`Unknown encoding: ${encoding}`); // sorry, we're a one-trick pony here
}
return dig;

@@ -241,3 +251,3 @@ }

RIPEMD160.create = function () {
return new RIPEMD160();
return new _RIPEMD160();
};

@@ -328,10 +338,5 @@

}
//@ts-ignore - for browser
exports.RIPEMD160 = RIPEMD160;
// for node and some bundlers
if ("undefined" !== typeof module) {
module.exports = RIPEMD160;
}
})(("undefined" !== typeof module && module.exports) || window);
})(("object" === typeof window && window) || {}, RIPEMD160);
if ("object" === typeof module) {
module.exports = RIPEMD160;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc