jcc_wallet 4.0.2 → 4.0.3
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.
package/lib/hd/plugins.js
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Factory = void 0;
|
|
4
7
|
const address_codec_1 = require("./address-codec");
|
|
5
8
|
const utils_1 = require("./utils");
|
|
6
9
|
const utils_2 = require("@noble/curves/abstract/utils");
|
|
7
|
-
const sha512_1 = require("
|
|
10
|
+
const sha512_1 = __importDefault(require("./sha512"));
|
|
8
11
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
9
12
|
const ripemd160_1 = require("@noble/hashes/ripemd160");
|
|
10
13
|
const ed25519_1 = require("@noble/curves/ed25519");
|
|
11
14
|
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
12
15
|
const utils_3 = require("@noble/hashes/utils");
|
|
13
|
-
const hash = (message) => {
|
|
14
|
-
return sha512_1.sha512
|
|
15
|
-
.create()
|
|
16
|
-
.update(message)
|
|
17
|
-
.digest()
|
|
18
|
-
.slice(0, 32);
|
|
19
|
-
};
|
|
20
|
-
const funcHexToBytes = (hex) => {
|
|
21
|
-
const bytes = [];
|
|
22
|
-
for (let c = 0; c < hex.length; c += 2) {
|
|
23
|
-
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
24
|
-
}
|
|
25
|
-
return bytes;
|
|
26
|
-
};
|
|
27
16
|
function assert(condition, message) {
|
|
28
17
|
if (!condition) {
|
|
29
18
|
throw new Error(message || "Assertion failed");
|
|
@@ -59,7 +48,7 @@ const Factory = (alphabet) => {
|
|
|
59
48
|
return { privateKey: SECP256K1_PREFIX + privateKey, publicKey };
|
|
60
49
|
},
|
|
61
50
|
sign(message, privateKey) {
|
|
62
|
-
const signHash =
|
|
51
|
+
const signHash = sha512_1.default.half(message);
|
|
63
52
|
return secp256k1_1.secp256k1.sign(signHash, privateKey, {
|
|
64
53
|
// "Canonical" signatures
|
|
65
54
|
lowS: true,
|
|
@@ -70,13 +59,13 @@ const Factory = (alphabet) => {
|
|
|
70
59
|
.toUpperCase();
|
|
71
60
|
},
|
|
72
61
|
verify(message, signature, publicKey) {
|
|
73
|
-
const signHash =
|
|
62
|
+
const signHash = sha512_1.default.half(message);
|
|
74
63
|
return secp256k1_1.secp256k1.verify(signature, signHash, publicKey);
|
|
75
64
|
}
|
|
76
65
|
};
|
|
77
66
|
const ed25519 = {
|
|
78
67
|
deriveKeypair: (entropy) => {
|
|
79
|
-
const rawPrivateKey =
|
|
68
|
+
const rawPrivateKey = sha512_1.default.half(entropy);
|
|
80
69
|
const privateKey = (0, utils_2.bytesToHex)(rawPrivateKey);
|
|
81
70
|
const pub = ed25519_1.ed25519.getPublicKey(privateKey);
|
|
82
71
|
return {
|
|
@@ -159,7 +148,7 @@ const Factory = (alphabet) => {
|
|
|
159
148
|
generate,
|
|
160
149
|
fromSecret,
|
|
161
150
|
addressCodec,
|
|
162
|
-
hash,
|
|
151
|
+
hash: sha512_1.default.half,
|
|
163
152
|
sign: (message, privateKey) => {
|
|
164
153
|
const keypair = deriveKeyPair(privateKey);
|
|
165
154
|
if (privateKey.startsWith(ED25519_PREFIX)) {
|