@neuraiproject/neurai-key 2.8.1 → 2.8.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/LICENSE +1 -1
- package/README.md +6 -7
- package/index.ts +17 -16
- package/package.json +2 -2
- package/test.js +18 -48
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Neurai-key
|
|
2
2
|
|
|
3
3
|
Generate Neurai addresses from a mnemonic phrase following the standards BIP32, BIP39, BIP44.
|
|
4
4
|
|
|
5
|
-
That is, use your 12 words to get addresses for Neurai mainnet
|
|
6
|
-
The library also support Evrmorecoin EVR, both mainnet and testnet.
|
|
5
|
+
That is, use your 12 words to get addresses for Neurai mainnet.
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
## Example get external and internal (change) addresses by path
|
|
@@ -20,7 +19,7 @@ import NeuraiKey from "@neuraiproject/neurai-key";
|
|
|
20
19
|
const mnemonic = NeuraiKey.generateMnemonic();
|
|
21
20
|
const ACCOUNT = 0; //default is zero
|
|
22
21
|
const POSITION = 0; //the first address for this wallet
|
|
23
|
-
const network = "xna"; //or
|
|
22
|
+
const network = "xna"; //or rvn-test for testnet
|
|
24
23
|
const addressPair = NeuraiKey.getAddressPair(
|
|
25
24
|
network,
|
|
26
25
|
mnemonic,
|
|
@@ -33,7 +32,7 @@ console.info("Mnemonic", mnemonic);
|
|
|
33
32
|
console.log(addressPair);
|
|
34
33
|
```
|
|
35
34
|
|
|
36
|
-
Outputs
|
|
35
|
+
Outputs (Old example but you get the point)
|
|
37
36
|
|
|
38
37
|
```
|
|
39
38
|
Mnemonic wrong breeze brick wrestle exotic erode news clown copy install marble promote
|
|
@@ -67,7 +66,7 @@ import NeuraiKey from "@neuraiproject/neurai-key";
|
|
|
67
66
|
const mnemonic =
|
|
68
67
|
"Mnemonic erosion total live dial hamster helmet top response cash obey anger balcony";
|
|
69
68
|
const path = "m/44'/175'/0'/0/0";
|
|
70
|
-
const network = "xna";
|
|
69
|
+
const network = "xna";
|
|
71
70
|
const hdKey = NeuraiKey.getHDKey("xna", mnemonic);
|
|
72
71
|
|
|
73
72
|
const address = NeuraiKey.getAddressByPath(network, hdKey, path);
|
|
@@ -76,7 +75,7 @@ console.log(address);
|
|
|
76
75
|
|
|
77
76
|
```
|
|
78
77
|
|
|
79
|
-
Outputs
|
|
78
|
+
Outputs (Again another old example but you get the point)
|
|
80
79
|
|
|
81
80
|
```
|
|
82
81
|
{
|
package/index.ts
CHANGED
|
@@ -12,34 +12,35 @@ import HDKey from "hdkey";
|
|
|
12
12
|
import { IAddressObject } from "./types";
|
|
13
13
|
|
|
14
14
|
//Could not declare Network as enum, something wrong with parcel bundler
|
|
15
|
-
export type Network = "xna"
|
|
15
|
+
export type Network = "xna";
|
|
16
16
|
|
|
17
17
|
function getNetwork(name: Network) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
xna: chains.xna.mainnet.versions,
|
|
21
|
-
"xna-test": chains.xna.testnet?.versions,
|
|
22
|
-
evr: chains.evr.mainnet.versions,
|
|
23
|
-
"evr-test": chains.evr.testnet?.versions,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const network = map[c];
|
|
27
|
-
if (!network) {
|
|
28
|
-
throw new Error("network must be of value " + Object.keys(map).toString());
|
|
18
|
+
if (name !== "xna") {
|
|
19
|
+
throw new Error("network must be 'xna'");
|
|
29
20
|
}
|
|
30
|
-
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
bip32: {
|
|
24
|
+
private: 0x0488ade4,
|
|
25
|
+
public: 0x0488b21e,
|
|
26
|
+
},
|
|
27
|
+
bip44: 0,
|
|
28
|
+
private: 0x80,
|
|
29
|
+
public: 0x35,
|
|
30
|
+
scripthash: 0x75,
|
|
31
|
+
};
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
*
|
|
34
35
|
* @param network
|
|
35
|
-
* @returns the coin type for the network (blockchain)
|
|
36
|
+
* @returns the coin type for the network (blockchain)
|
|
36
37
|
*/
|
|
37
38
|
export function getCoinType(network: Network) {
|
|
38
39
|
const chain = getNetwork(network);
|
|
39
40
|
return chain.bip44;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
|
-
* @param network - should have value "xna"
|
|
43
|
+
* @param network - should have value "xna"
|
|
43
44
|
* @param mnemonic - your mnemonic
|
|
44
45
|
* @param account - accounts in BIP44 starts from 0, 0 is the default account
|
|
45
46
|
* @param position - starts from 0
|
|
@@ -115,7 +116,7 @@ export function isMnemonicValid(mnemonic: string) {
|
|
|
115
116
|
/**
|
|
116
117
|
*
|
|
117
118
|
* @param privateKeyWIF
|
|
118
|
-
* @param network should be "
|
|
119
|
+
* @param network should be "rvn" or "rvn-test"
|
|
119
120
|
* @returns object {address, privateKey (hex), WIF}
|
|
120
121
|
*/
|
|
121
122
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuraiproject/neurai-key",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Generate Neurai addresses from mnemonic code. BIP32, BIP39, BIP44",
|
|
5
5
|
"source": "index.ts",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"BIP44",
|
|
21
21
|
"BIP39"
|
|
22
22
|
],
|
|
23
|
-
"author": "
|
|
23
|
+
"author": "Neurai Project / Zachary Price",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/neuraiproject/neurai-key/issues"
|
package/test.js
CHANGED
|
@@ -10,15 +10,7 @@ test("Validate address on main-net", () => {
|
|
|
10
10
|
const mnemonic =
|
|
11
11
|
"orphan resemble brain dwarf bus fancy horn among cricket logic duty crater";
|
|
12
12
|
const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
|
|
13
|
-
expect(address.external.address).toBe("
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("Validate address on test-net", () => {
|
|
17
|
-
const network = "xna-test";
|
|
18
|
-
const mnemonic =
|
|
19
|
-
"orphan resemble brain dwarf bus fancy horn among cricket logic duty crater";
|
|
20
|
-
const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
|
|
21
|
-
expect(address.external.address).toBe("n1nUspcdAaDAMfx2ksZJ5cDa7UKVEGstrX");
|
|
13
|
+
expect(address.external.address).toBe("TxSKpGLR58VUFzBJ8pjkDgNnNKmvGyWL4t");
|
|
22
14
|
});
|
|
23
15
|
|
|
24
16
|
test("Validate Wallet Import Format (WIF) main-net ", () => {
|
|
@@ -27,29 +19,16 @@ test("Validate Wallet Import Format (WIF) main-net ", () => {
|
|
|
27
19
|
"orphan resemble brain dwarf bus fancy horn among cricket logic duty crater";
|
|
28
20
|
const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
|
|
29
21
|
|
|
30
|
-
expect(address.internal.address).toBe("
|
|
31
|
-
expect(address.external.WIF).toBe(
|
|
32
|
-
"KyWuYcev1hJ7YJZTjWx8coXNRm4jRbMEhgVVVC8vDcTaKRCMASUE"
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("Validate Wallet Import Format (WIF) test-net ", () => {
|
|
37
|
-
const network = "xna-test";
|
|
38
|
-
const mnemonic =
|
|
39
|
-
"orphan resemble brain dwarf bus fancy horn among cricket logic duty crater";
|
|
40
|
-
const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
|
|
41
|
-
|
|
42
|
-
expect(address.external.WIF).toBe(
|
|
43
|
-
"cPchRRmzZXtPeFLHfrh8qcwaRaziJCS4gcAMBVVQh1EiehNyBtKB"
|
|
44
|
-
);
|
|
22
|
+
expect(address.internal.address).toBe("Td8haX27FhJ1TeTdj9z1DX6296FCqaRRxF");
|
|
23
|
+
expect(address.external.WIF).toBe("KybNCdSZVUdqCdaq95mtcskGd4K2cWvnYNZcJ3mo1gDY9ZtySiR6");
|
|
45
24
|
});
|
|
46
25
|
|
|
47
26
|
test("Validate get public address from Wallet Import Format (WIF) main-net ", () => {
|
|
48
27
|
const network = "xna";
|
|
49
|
-
const WIF = "
|
|
28
|
+
const WIF = "L1CQvWc2hCVdLNKYeWDrMDfWvzUhpxQDGRMHJTBmUc1LpjqFd3qf";
|
|
50
29
|
const addressObject = NeuraiKey.getAddressByWIF(network, WIF);
|
|
51
30
|
|
|
52
|
-
expect(addressObject.address).toBe("
|
|
31
|
+
expect(addressObject.address).toBe("ThYNJX9F4xSdiZMBQXWCTMYLxqpAhrzYV3");
|
|
53
32
|
});
|
|
54
33
|
|
|
55
34
|
test("Valid bytes to mnemonic", () => {
|
|
@@ -95,32 +74,23 @@ it("Should accept Italian mnemonic", () => {
|
|
|
95
74
|
|
|
96
75
|
describe("generateAddress", () => {
|
|
97
76
|
it("should generate an address with a mnemonic", () => {
|
|
98
|
-
// Call the function
|
|
99
77
|
const result = NeuraiKey.generateAddressObject();
|
|
100
78
|
|
|
101
|
-
// Assertions
|
|
102
79
|
expect(result).toHaveProperty("mnemonic");
|
|
103
80
|
expect(result.mnemonic).toBeDefined();
|
|
104
|
-
expect(result.network).toBe("xna");
|
|
105
|
-
expect(result).toHaveProperty("address");
|
|
106
|
-
// ... you can add more assertions based on the expected structure of the result
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("default network should be xna for Neurai", () => {
|
|
110
|
-
const network = "xna-test";
|
|
111
|
-
// Call the function
|
|
112
|
-
const result = NeuraiKey.generateAddressObject(network);
|
|
113
|
-
// Assertions
|
|
114
|
-
expect(result.network).toBe(network); //Test default
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("Should handle xna-test", () => {
|
|
118
|
-
const network = "xna-test";
|
|
119
|
-
// Call the function
|
|
120
|
-
const result = NeuraiKey.generateAddressObject(network);
|
|
121
|
-
// Assertions
|
|
122
|
-
expect(result.network).toBe(network); //Test default
|
|
81
|
+
expect(result.network).toBe("xna");
|
|
82
|
+
expect(result).toHaveProperty("address");
|
|
123
83
|
});
|
|
124
84
|
|
|
125
|
-
//
|
|
85
|
+
// it("default network should be xna for Neurai", () => {
|
|
86
|
+
// const network = "xna-test";
|
|
87
|
+
// const result = NeuraiKey.generateAddressObject(network);
|
|
88
|
+
// expect(result.network).toBe(network);
|
|
89
|
+
// });
|
|
90
|
+
|
|
91
|
+
// it("Should handle xna", () => {
|
|
92
|
+
// const network = "xna-test";
|
|
93
|
+
// const result = NeuraiKey.generateAddressObject(network);
|
|
94
|
+
// expect(result.network).toBe(network);
|
|
95
|
+
// });
|
|
126
96
|
});
|