@suxinmin/plugin-casper 1.0.0 → 1.0.2
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/dist/client.js +10 -6
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -12,12 +12,16 @@ class CasperClient {
|
|
|
12
12
|
*/
|
|
13
13
|
generateWallet() {
|
|
14
14
|
const keyPair = casper_js_sdk_1.Keys.Ed25519.new();
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
15
|
+
// publicKey 是 CLPublicKey 类型,使用 toHex() 方法
|
|
16
|
+
const publicKeyHex = keyPair.publicKey.toHex(false); // false 表示不使用校验和
|
|
17
|
+
// privateKey 是 Uint8Array,转换为 hex 字符串
|
|
18
|
+
const privateKeyHex = Array.from(keyPair.privateKey)
|
|
19
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
20
|
+
.join('');
|
|
21
|
+
const accountHash = keyPair.accountHex(false);
|
|
18
22
|
const address = `account-hash-${accountHash}`;
|
|
19
23
|
return {
|
|
20
|
-
publicKey:
|
|
24
|
+
publicKey: publicKeyHex,
|
|
21
25
|
privateKey: privateKeyHex,
|
|
22
26
|
address
|
|
23
27
|
};
|
|
@@ -29,8 +33,8 @@ class CasperClient {
|
|
|
29
33
|
const privateKeyBytes = Buffer.from(privateKeyHex, 'hex');
|
|
30
34
|
const publicKeyBytes = casper_js_sdk_1.Keys.Ed25519.privateToPublicKey(privateKeyBytes);
|
|
31
35
|
const keyPair = casper_js_sdk_1.Keys.Ed25519.parseKeyPair(publicKeyBytes, privateKeyBytes);
|
|
32
|
-
const publicKey =
|
|
33
|
-
const accountHash =
|
|
36
|
+
const publicKey = keyPair.publicKey.toHex(false);
|
|
37
|
+
const accountHash = keyPair.accountHex(false);
|
|
34
38
|
const address = `account-hash-${accountHash}`;
|
|
35
39
|
return {
|
|
36
40
|
publicKey,
|