@neuraiproject/neurai-key 2.8.5 → 2.8.7

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/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  //Gives us meta data about coins/chains
2
- import { chains } from "@hyperbitjs/chains";
2
+ import { chains } from "./coins/xna.js";
3
+ import { chains as legacyChains } from "./coins/xna-legacy.js";
3
4
 
4
5
  //bip39 from mnemonic to seed
5
6
  import * as bip39 from "bip39";
@@ -13,14 +14,17 @@ import { IAddressObject } from "./types";
13
14
  const bs58check = require("bs58check");
14
15
 
15
16
  //Could not declare Network as enum, something wrong with parcel bundler
16
- export type Network = "xna" | "xna-test";
17
+ export type Network = "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test";
17
18
 
18
19
  function getNetwork(name: Network) {
19
20
  const c = name.toLowerCase() as Network; //Just to be sure
20
21
  const chainData = chains as any;
22
+ const legacyChainData = legacyChains as any;
21
23
  const map: Record<Network, any> = {
22
24
  xna: chainData.xna.mainnet.versions,
23
25
  "xna-test": chainData.xna.testnet?.versions,
26
+ "xna-legacy": legacyChainData["xna-legacy"].mainnet.versions,
27
+ "xna-legacy-test": legacyChainData["xna-legacy"].testnet?.versions,
24
28
  };
25
29
 
26
30
  const network = map[c];
@@ -133,6 +137,18 @@ export function getAddressByWIF(network: Network, privateKeyWIF: string) {
133
137
  };
134
138
  }
135
139
 
140
+ /**
141
+ * @param privateKeyWIF
142
+ * @param network should be "xna" or "xna-test"
143
+ * @returns the compressed public key as a hex string
144
+ */
145
+ export function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {
146
+ const coinKey = CoinKey.fromWif(privateKeyWIF);
147
+ coinKey.versions = getNetwork(network);
148
+
149
+ return coinKey.publicKey.toString("hex");
150
+ }
151
+
136
152
  export const entropyToMnemonic = bip39.entropyToMnemonic;
137
153
 
138
154
  export function generateAddressObject(
@@ -192,6 +208,7 @@ export default {
192
208
  generateMnemonic,
193
209
  getAddressByPath,
194
210
  getAddressByWIF,
211
+ getPubkeyByWIF,
195
212
  getAddressPair,
196
213
  getCoinType,
197
214
  getHDKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-key",
3
- "version": "2.8.5",
3
+ "version": "2.8.7",
4
4
  "description": "Generate Neurai addresses from mnemonic code. BIP32, BIP39, BIP44",
5
5
  "source": "index.ts",
6
6
  "main": "dist/main.js",
@@ -27,7 +27,6 @@
27
27
  },
28
28
  "homepage": "https://github.com/neuraiproject/neurai-key#readme",
29
29
  "dependencies": {
30
- "@hyperbitjs/chains": "^1.2.0",
31
30
  "bip39": "^3.0.4",
32
31
  "bs58check": "^2.1.2",
33
32
  "coinkey": "^3.0.0",
@@ -35,12 +34,12 @@
35
34
  },
36
35
  "devDependencies": {
37
36
  "@parcel/packager-ts": "^2.10.3",
38
- "@parcel/transformer-typescript-types": "^2.16.1",
37
+ "@parcel/transformer-typescript-types": "^2.16.1",
39
38
  "@types/hdkey": "^2.0.3",
40
- "@types/node": "^18.14.0",
39
+ "@types/node": "^20.19.27",
41
40
  "browserify": "^17.0.0",
42
- "jest": "^29.4.0",
41
+ "jest": "^30.2.0",
43
42
  "parcel": "^2.10.3",
44
- "typescript": "^4.9.4"
43
+ "typescript": "^5.9.3"
45
44
  }
46
45
  }
package/test.js CHANGED
@@ -9,7 +9,7 @@ test("Validate address on main-net", () => {
9
9
  const network = "xna";
10
10
  const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
11
11
  const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
12
- expect(address.external.address).toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
12
+ expect(address.external.address).toBe("NLhdtwjgrcEkRqjJZkRY4sjhkJ93EytLeE");
13
13
  });
14
14
 
15
15
  test("Validate address on test-net", () => {
@@ -25,7 +25,7 @@ test("Validate address with passphrase on main-net", () => {
25
25
  const passphrase = "my secret passphrase";
26
26
  const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1, passphrase);
27
27
  // With passphrase, the address should be different from the one without passphrase
28
- expect(address.external.address).not.toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
28
+ expect(address.external.address).not.toBe("NLhdtwjgrcEkRqjJZkRY4sjhkJ93EytLeE");
29
29
  // Verify it generates consistently with the same passphrase
30
30
  const address2 = NeuraiKey.getAddressPair(network, mnemonic, 0, 1, passphrase);
31
31
  expect(address.external.address).toBe(address2.external.address);
@@ -51,7 +51,7 @@ test("Empty passphrase equals no passphrase", () => {
51
51
  const addressWithoutPassphrase = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
52
52
 
53
53
  expect(addressWithEmpty.external.address).toBe(addressWithoutPassphrase.external.address);
54
- expect(addressWithEmpty.external.address).toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
54
+ expect(addressWithEmpty.external.address).toBe("NLhdtwjgrcEkRqjJZkRY4sjhkJ93EytLeE");
55
55
  });
56
56
 
57
57
  test("Validate Wallet Import Format (WIF) main-net ", () => {
@@ -59,8 +59,8 @@ test("Validate Wallet Import Format (WIF) main-net ", () => {
59
59
  const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
60
60
  const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
61
61
 
62
- expect(address.internal.address).toBe("NQM5zP6jkwDgCZ2UQiUicW4e3YcWc4NY4S");
63
- expect(address.external.WIF).toBe("KwWavecys1Qskgzwsyv6CNeTospWkvMeLzx3dLqeV4xAJEMXF8Qq");
62
+ expect(address.internal.address).toBe("NRYT7zihLQTGpcK4PKHnTFuQsLaTGJYzqm");
63
+ expect(address.external.WIF).toBe("L1FXfT3WjVLERgqiQt3YzqU9F3Z8LmMhxPF4VHW5yd3Q6Q66woRQ");
64
64
  });
65
65
 
66
66
  test("Convert external public key to main-net address", () => {
@@ -97,6 +97,16 @@ test("Validate get public address from Wallet Import Format (WIF) main-net ", ()
97
97
  expect(addressObject.address).toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
98
98
  });
99
99
 
100
+ test("Get compressed public key from Wallet Import Format (WIF) main-net", () => {
101
+ const network = "xna";
102
+ const WIF = "KwWavecys1Qskgzwsyv6CNeTospWkvMeLzx3dLqeV4xAJEMXF8Qq";
103
+ const publicKey = NeuraiKey.getPubkeyByWIF(network, WIF);
104
+
105
+ expect(publicKey).toBe(
106
+ "024108b96e53795cc28fb8b64532e61f17aa3c149e06815958361c5dddba1e7ec0"
107
+ );
108
+ });
109
+
100
110
  test("Valid bytes to mnemonic", () => {
101
111
  const hexString = "a10a95fb55808c5f15dc97ecbcd26cf0";
102
112
  const bytes = Uint8Array.from(Buffer.from(hexString, "hex"));