@wopr-network/platform-core 1.61.0 → 1.61.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* - p2pkh: DOGE (D...), TRON (T...) — params: { version }
|
|
11
11
|
* - evm: ETH, ERC-20 (0x...) — params: {}
|
|
12
12
|
*/
|
|
13
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
13
14
|
import { ripemd160 } from "@noble/hashes/legacy.js";
|
|
14
15
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
15
16
|
import { bech32 } from "@scure/base";
|
|
@@ -53,7 +54,13 @@ function encodeP2pkh(pubkey, versionByte) {
|
|
|
53
54
|
return base58encode(full);
|
|
54
55
|
}
|
|
55
56
|
function encodeEvm(pubkey) {
|
|
56
|
-
|
|
57
|
+
// HDKey.publicKey is SEC1 compressed (33 bytes, 02/03 prefix).
|
|
58
|
+
// Ethereum addresses = keccak256(uncompressed_pubkey[1:]).slice(-20).
|
|
59
|
+
// viem's publicKeyToAddress expects uncompressed (65 bytes, 04 prefix).
|
|
60
|
+
// Decompress via secp256k1 point recovery before hashing.
|
|
61
|
+
const hexKey = Array.from(pubkey, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
62
|
+
const uncompressed = secp256k1.Point.fromHex(hexKey).toBytes(false);
|
|
63
|
+
const hexPubKey = `0x${Array.from(uncompressed, (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
57
64
|
return publicKeyToAddress(hexPubKey);
|
|
58
65
|
}
|
|
59
66
|
// ---------- public API ----------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wopr-network/platform-core",
|
|
3
|
-
"version": "1.61.
|
|
3
|
+
"version": "1.61.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -131,6 +131,7 @@
|
|
|
131
131
|
"dependencies": {
|
|
132
132
|
"@aws-sdk/client-ses": "^3.1014.0",
|
|
133
133
|
"@hono/node-server": "^1.19.11",
|
|
134
|
+
"@noble/curves": "^2.0.1",
|
|
134
135
|
"@noble/hashes": "^2.0.1",
|
|
135
136
|
"@scure/base": "^2.0.0",
|
|
136
137
|
"@scure/bip32": "^2.0.1",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* - p2pkh: DOGE (D...), TRON (T...) — params: { version }
|
|
11
11
|
* - evm: ETH, ERC-20 (0x...) — params: {}
|
|
12
12
|
*/
|
|
13
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
13
14
|
import { ripemd160 } from "@noble/hashes/legacy.js";
|
|
14
15
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
15
16
|
import { bech32 } from "@scure/base";
|
|
@@ -64,7 +65,14 @@ function encodeP2pkh(pubkey: Uint8Array, versionByte: number): string {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
function encodeEvm(pubkey: Uint8Array): string {
|
|
67
|
-
|
|
68
|
+
// HDKey.publicKey is SEC1 compressed (33 bytes, 02/03 prefix).
|
|
69
|
+
// Ethereum addresses = keccak256(uncompressed_pubkey[1:]).slice(-20).
|
|
70
|
+
// viem's publicKeyToAddress expects uncompressed (65 bytes, 04 prefix).
|
|
71
|
+
// Decompress via secp256k1 point recovery before hashing.
|
|
72
|
+
const hexKey = Array.from(pubkey, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
73
|
+
const uncompressed = secp256k1.Point.fromHex(hexKey).toBytes(false);
|
|
74
|
+
const hexPubKey =
|
|
75
|
+
`0x${Array.from(uncompressed, (b: number) => b.toString(16).padStart(2, "0")).join("")}` as `0x${string}`;
|
|
68
76
|
return publicKeyToAddress(hexPubKey);
|
|
69
77
|
}
|
|
70
78
|
|