Skip to content

Commit 374c0e0

Browse files
TinyChain --> tiny update in the Secp256k1
1 parent 70f03e9 commit 374c0e0

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/TinyChain/Secp256k1/Btc.mjs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,14 @@ class TinyBtcSecp256k1 extends TinySecp256k1 {
203203
return TinySecp256k1.doubleSha256(fullMessage);
204204
}
205205

206-
/**
207-
* RIPEMD160(SHA256(x))
208-
* @param {Buffer} buffer
209-
* @returns {Buffer}
210-
*/
211-
#hash160(buffer) {
212-
const sha = createHash('sha256').update(buffer).digest();
213-
return createHash('ripemd160').update(sha).digest();
214-
}
215-
216206
/**
217207
* Generates P2PKH address from public key
218208
* @param {Buffer} pubKey
219209
* @returns {string}
220210
*/
221211
#pubkeyToP2pkhAddress(pubKey) {
222212
const bs58check = this.getBs58check();
223-
const pubkeyHash = this.#hash160(pubKey);
213+
const pubkeyHash = TinySecp256k1.hash160(pubKey);
224214
const versioned = Buffer.concat([Buffer.from([0x00]), pubkeyHash]); // Mainnet P2PKH
225215
return bs58check.encode(versioned);
226216
}
@@ -232,7 +222,7 @@ class TinyBtcSecp256k1 extends TinySecp256k1 {
232222
*/
233223
#pubkeyToBech32Address(pubKey) {
234224
const bech32 = this.getBech32();
235-
const ripemd160 = this.#hash160(pubKey);
225+
const ripemd160 = TinySecp256k1.hash160(pubKey);
236226
// Convert for bech32: witness version 0 + program (ripemd160 result)
237227
const words = bech32.toWords(ripemd160);
238228
words.unshift(0x00); // witness version

src/TinyChain/Secp256k1/Eth.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class TinyEthSecp256k1 extends TinySecp256k1 {
8484
}
8585

8686
/**
87-
8887
* Apply EIP-55 checksum to a lowercase address.
8988
* @param {string} address - Hex string without 0x prefix.
9089
* @returns {string}

src/TinyChain/Secp256k1/index.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ class TinySecp256k1 {
6464
return TinySecp256k1.sha256(TinySecp256k1.sha256(buf));
6565
}
6666

67+
/**
68+
* RIPEMD160(SHA256(x))
69+
* @param {Buffer} buffer
70+
* @returns {Buffer}
71+
*/
72+
static hash160(buffer) {
73+
const sha = createHash('sha256').update(buffer).digest();
74+
return createHash('ripemd160').update(sha).digest();
75+
}
76+
6777
/**
6878
* Creates an instance of TinySecp256k1.
6979
*

0 commit comments

Comments
 (0)