Skip to content

Commit 074f0ad

Browse files
committed
feat(crypto): restore ripemd160, sha1 and sha256 hash helpers
1 parent 248789d commit 074f0ad

File tree

6 files changed

+57
-7
lines changed

6 files changed

+57
-7
lines changed

src/cjs/crypto.cjs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ var __importStar =
4444
return result;
4545
};
4646
Object.defineProperty(exports, '__esModule', { value: true });
47-
exports.TAGGED_HASH_PREFIXES = exports.TAGS = void 0;
47+
exports.TAGGED_HASH_PREFIXES =
48+
exports.TAGS =
49+
exports.sha1 =
50+
exports.sha256 =
51+
exports.ripemd160 =
52+
void 0;
4853
exports.hash160 = hash160;
4954
exports.hash256 = hash256;
5055
exports.taggedHash = taggedHash;
@@ -55,8 +60,27 @@ exports.taggedHash = taggedHash;
5560
* @packageDocumentation
5661
*/
5762
const ripemd160_1 = require('@noble/hashes/ripemd160');
63+
Object.defineProperty(exports, 'ripemd160', {
64+
enumerable: true,
65+
get: function () {
66+
return ripemd160_1.ripemd160;
67+
},
68+
});
5869
const sha256_1 = require('@noble/hashes/sha256');
70+
Object.defineProperty(exports, 'sha256', {
71+
enumerable: true,
72+
get: function () {
73+
return sha256_1.sha256;
74+
},
75+
});
5976
const tools = __importStar(require('uint8array-tools'));
77+
var sha1_1 = require('@noble/hashes/sha1');
78+
Object.defineProperty(exports, 'sha1', {
79+
enumerable: true,
80+
get: function () {
81+
return sha1_1.sha1;
82+
},
83+
});
6084
/**
6185
* Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
6286
*

src/cjs/crypto.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* A module for hashing functions.
3+
* include ripemd160、sha1、sha256、hash160、hash256、taggedHash
4+
*
5+
* @packageDocumentation
6+
*/
7+
import { ripemd160 } from '@noble/hashes/ripemd160';
8+
import { sha256 } from '@noble/hashes/sha256';
9+
export { ripemd160, sha256 };
10+
export { sha1 } from '@noble/hashes/sha1';
111
/**
212
* Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
313
*
@@ -43,4 +53,3 @@ export declare const TAGGED_HASH_PREFIXES: TaggedHashPrefixes;
4353
* @returns The resulting tagged hash as a `Uint8Array`.
4454
*/
4555
export declare function taggedHash(prefix: TaggedHashPrefix, data: Uint8Array): Uint8Array;
46-
export {};

src/esm/crypto.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import { ripemd160 } from '@noble/hashes/ripemd160';
88
import { sha256 } from '@noble/hashes/sha256';
99
import * as tools from 'uint8array-tools';
10+
export { ripemd160, sha256 };
11+
export { sha1 } from '@noble/hashes/sha1';
1012
/**
1113
* Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
1214
*

test/crypto.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TAGS, TAGGED_HASH_PREFIXES } from 'bitcoinjs-lib/src/crypto';
88
import { sha256 } from '@noble/hashes/sha256';
99

1010
describe('crypto', () => {
11-
['hash160', 'hash256'].forEach(algorithm => {
11+
['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach(algorithm => {
1212
describe(algorithm, () => {
1313
fixtures.hashes.forEach(f => {
1414
const fn = (bcrypto as any)[algorithm];

test/fixtures/crypto.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@
33
{
44
"hex": "0000000000000001",
55
"hash160": "cdb00698f02afd929ffabea308340fa99ac2afa8",
6-
"hash256": "3ae5c198d17634e79059c2cd735491553d22c4e09d1d9fea3ecf214565df2284"
6+
"hash256": "3ae5c198d17634e79059c2cd735491553d22c4e09d1d9fea3ecf214565df2284",
7+
"ripemd160": "8d1a05d1bc08870968eb8a81ad4393fd3aac6633",
8+
"sha1": "cb473678976f425d6ec1339838f11011007ad27d",
9+
"sha256": "cd2662154e6d76b2b2b92e70c0cac3ccf534f9b74eb5b89819ec509083d00a50"
710
},
811
{
912
"hex": "0101010101010101",
1013
"hash160": "abaf1119f83e384210fe8e222eac76e2f0da39dc",
11-
"hash256": "728338d99f356175c4945ef5cccfa61b7b56143cbbf426ddd0e0fc7cfe8c3c23"
14+
"hash256": "728338d99f356175c4945ef5cccfa61b7b56143cbbf426ddd0e0fc7cfe8c3c23",
15+
"ripemd160": "5825701b4b9767fd35063b286dca3582853e0630",
16+
"sha1": "c0357a32ed1f6a03be92dd094476f7f1a2e214ec",
17+
"sha256": "04abc8821a06e5a30937967d11ad10221cb5ac3b5273e434f1284ee87129a061"
1218
},
1319
{
1420
"hex": "ffffffffffffffff",
1521
"hash160": "f86221f5a1fca059a865c0b7d374dfa9d5f3aeb4",
16-
"hash256": "752adad0a7b9ceca853768aebb6965eca126a62965f698a0c1bc43d83db632ad"
22+
"hash256": "752adad0a7b9ceca853768aebb6965eca126a62965f698a0c1bc43d83db632ad",
23+
"ripemd160": "cb760221600ed34337ca3ab70016b5f58c838120",
24+
"sha1": "be673e8a56eaa9d8c1d35064866701c11ef8e089",
25+
"sha256": "12a3ae445661ce5dee78d0650d33362dec29c4f82af05e7e57fb595bbbacf0ca"
1726
},
1827
{
1928
"hex": "4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20446f6e65632061742066617563696275732073617069656e2c2076656c20666163696c6973697320617263752e20536564207574206d61737361206e6962682e205574206d6f6c6c69732070756c76696e6172206d617373612e20557420756c6c616d636f7270657220646f6c6f7220656e696d2c20696e206d6f6c657374696520656e696d20636f6e64696d656e74756d2061632e20416c697175616d206572617420766f6c75747061742e204e756c6c6120736f64616c657320617420647569206e656320",
2029
"hash160": "9763e6b367c363bd6b88a7b361c98e6beee243a5",
21-
"hash256": "033588797115feb3545052670cac2a46584ab3cb460de63756ee0275e66b5799"
30+
"hash256": "033588797115feb3545052670cac2a46584ab3cb460de63756ee0275e66b5799",
31+
"ripemd160": "cad8593dcdef12ee334c97bab9787f07b3f3a1a5",
32+
"sha1": "10d96fb43aca84e342206887bbeed3065d4e4344",
33+
"sha256": "a7fb8276035057ed6479c5f2305a96da100ac43f0ac10f277e5ab8c5457429da"
2234
}
2335
],
2436
"taggedHash": [

ts_src/crypto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { ripemd160 } from '@noble/hashes/ripemd160';
88
import { sha256 } from '@noble/hashes/sha256';
99
import * as tools from 'uint8array-tools';
1010

11+
export { ripemd160, sha256 };
12+
export { sha1 } from '@noble/hashes/sha1';
13+
1114
/**
1215
* Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
1316
*

0 commit comments

Comments
 (0)