@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.
Files changed (2) hide show
  1. package/dist/client.js +10 -6
  2. 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
- const publicKeyHex = Buffer.from(keyPair.publicKey).toString('hex');
16
- const privateKeyHex = Buffer.from(keyPair.privateKey).toString('hex');
17
- const accountHash = Buffer.from(keyPair.accountHash()).toString('hex');
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: `02${publicKeyHex}`,
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 = `02${Buffer.from(keyPair.publicKey).toString('hex')}`;
33
- const accountHash = Buffer.from(keyPair.accountHash()).toString('hex');
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suxinmin/plugin-casper",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Casper blockchain plugin for Eliza AI agent framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",