@neuraiproject/neurai-key 2.8.3 → 2.8.5
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/.vscode/settings.json +3 -0
- package/README.md +97 -21
- package/dist/NeuraiKey.js +173 -157
- package/dist/main.js +32 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +33 -14
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +8 -4
- package/dist/types.d.ts.map +1 -1
- package/example-passphrase.js +34 -0
- package/index.ts +43 -15
- package/package.json +3 -2
- package/test-html/NeuraiKey.js +60497 -0
- package/test-html/index.html +543 -0
- package/test.js +65 -20
- package/types.ts +1 -0
package/README.md
CHANGED
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
Generate Neurai addresses from a mnemonic phrase following the standards BIP32, BIP39, BIP44.
|
|
4
4
|
|
|
5
5
|
That is, use your 12 words to get addresses for Neurai mainnet and testnet.
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- ✅ Generate HD wallets from mnemonic phrases (BIP39)
|
|
10
|
+
- ✅ Derive addresses using BIP32/BIP44 standards
|
|
11
|
+
- ✅ Support for passphrase (25th word) for additional security
|
|
12
|
+
- ✅ Multi-language mnemonic support (English, Spanish, French, Italian, etc.)
|
|
13
|
+
- ✅ Mainnet and Testnet support for Neurai (XNA)
|
|
14
|
+
- ✅ Convert raw public keys into Neurai mainnet or testnet addresses
|
|
7
15
|
|
|
8
16
|
|
|
9
17
|
## Example get external and internal (change) addresses by path
|
|
@@ -19,7 +27,7 @@ import NeuraiKey from "@neuraiproject/neurai-key";
|
|
|
19
27
|
|
|
20
28
|
const mnemonic = NeuraiKey.generateMnemonic();
|
|
21
29
|
const ACCOUNT = 0; //default is zero
|
|
22
|
-
const POSITION =
|
|
30
|
+
const POSITION = 1; //the second address for this wallet
|
|
23
31
|
const network = "xna"; //or xna-test for testnet
|
|
24
32
|
const addressPair = NeuraiKey.getAddressPair(
|
|
25
33
|
network,
|
|
@@ -36,24 +44,65 @@ console.log(addressPair);
|
|
|
36
44
|
Outputs
|
|
37
45
|
|
|
38
46
|
```
|
|
39
|
-
Mnemonic
|
|
47
|
+
Mnemonic result pact model attract result puzzle final boss private educate luggage era
|
|
40
48
|
{
|
|
41
49
|
internal: {
|
|
42
|
-
address: '
|
|
43
|
-
path: "m/44'/
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
address: 'NQM5zP6jkwDgCZ2UQiUicW4e3YcWc4NY4S',
|
|
51
|
+
path: "m/44'/0'/0'/1/1",
|
|
52
|
+
publicKey: '02fe9a4190973398c54cdea353cb5b18aba4f272324ac3f15f4f204ef0884538e7',
|
|
53
|
+
privateKey: '8ce41bc45958cf3f4124bcd40b940752fbaf9be58ed8dec2dd7551388523f0a9',
|
|
54
|
+
WIF: 'L1was5cU14EbQDfz4BpiWhNAWZdmc4o1VSzv5w5GgKzSJwHpnGzP'
|
|
46
55
|
},
|
|
47
56
|
external: {
|
|
48
|
-
address: '
|
|
49
|
-
path: "m/44'/
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
address: 'NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp',
|
|
58
|
+
path: "m/44'/0'/0'/0/1",
|
|
59
|
+
publicKey: '024108b96e53795cc28fb8b64532e61f17aa3c149e06815958361c5dddba1e7ec0',
|
|
60
|
+
privateKey: '08ae5a08aa6a464619c177a551488c868010b4d2b2249892712be9a4990f9fc3',
|
|
61
|
+
WIF: 'KwWavecys1Qskgzwsyv6CNeTospWkvMeLzx3dLqeV4xAJEMXF8Qq'
|
|
52
62
|
},
|
|
53
|
-
position:
|
|
63
|
+
position: 1
|
|
54
64
|
}
|
|
55
65
|
```
|
|
56
66
|
|
|
67
|
+
## Example with Passphrase (BIP39 25th word)
|
|
68
|
+
|
|
69
|
+
For enhanced security, you can use an optional passphrase (also known as the "25th word").
|
|
70
|
+
This creates a completely different set of addresses from the same mnemonic.
|
|
71
|
+
|
|
72
|
+
**Important**: If you lose your passphrase, you cannot recover your wallet even with the mnemonic!
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
import NeuraiKey from "@neuraiproject/neurai-key";
|
|
76
|
+
|
|
77
|
+
const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
|
|
78
|
+
const passphrase = "my secret passphrase"; // Optional but highly secure
|
|
79
|
+
const network = "xna";
|
|
80
|
+
const ACCOUNT = 0;
|
|
81
|
+
const POSITION = 0;
|
|
82
|
+
|
|
83
|
+
// Generate address with passphrase
|
|
84
|
+
const addressPair = NeuraiKey.getAddressPair(
|
|
85
|
+
network,
|
|
86
|
+
mnemonic,
|
|
87
|
+
ACCOUNT,
|
|
88
|
+
POSITION,
|
|
89
|
+
passphrase // 5th parameter (optional)
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
console.log(addressPair.external.address);
|
|
93
|
+
// This will generate a DIFFERENT address than without the passphrase
|
|
94
|
+
|
|
95
|
+
// Without passphrase (or empty string)
|
|
96
|
+
const addressPairNoPass = NeuraiKey.getAddressPair(network, mnemonic, ACCOUNT, POSITION);
|
|
97
|
+
console.log(addressPairNoPass.external.address);
|
|
98
|
+
// This generates the standard address
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Use cases for passphrase:**
|
|
102
|
+
- Extra layer of security beyond the mnemonic
|
|
103
|
+
- Create multiple wallets from a single mnemonic
|
|
104
|
+
- Plausible deniability (different passphrases = different wallets)
|
|
105
|
+
|
|
57
106
|
## Example get the first public address for a wallet by BIP44 path
|
|
58
107
|
|
|
59
108
|
Note this is the fastest way to generate/derive addresses since we can re-use the hdKey object.
|
|
@@ -65,10 +114,13 @@ import NeuraiKey from "@neuraiproject/neurai-key";
|
|
|
65
114
|
|
|
66
115
|
//use NeuraiKey.generateMnemonic() to generate mnemonic codes
|
|
67
116
|
const mnemonic =
|
|
68
|
-
"
|
|
69
|
-
const path = "m/44'/175'/0'/0/
|
|
117
|
+
"result pact model attract result puzzle final boss private educate luggage era";
|
|
118
|
+
const path = "m/44'/175'/0'/0/1";
|
|
70
119
|
const network = "xna"; //or xna-test for testnet
|
|
71
|
-
|
|
120
|
+
|
|
121
|
+
// Optional: add passphrase as third parameter
|
|
122
|
+
const passphrase = ""; // empty string or omit for no passphrase
|
|
123
|
+
const hdKey = NeuraiKey.getHDKey(network, mnemonic, passphrase);
|
|
72
124
|
|
|
73
125
|
const address = NeuraiKey.getAddressByPath(network, hdKey, path);
|
|
74
126
|
|
|
@@ -80,13 +132,37 @@ Outputs
|
|
|
80
132
|
|
|
81
133
|
```
|
|
82
134
|
{
|
|
83
|
-
address: '
|
|
84
|
-
path: "m/44'/
|
|
85
|
-
|
|
86
|
-
|
|
135
|
+
address: 'NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp',
|
|
136
|
+
path: "m/44'/0'/0'/0/1",
|
|
137
|
+
publicKey: '024108b96e53795cc28fb8b64532e61f17aa3c149e06815958361c5dddba1e7ec0',
|
|
138
|
+
privateKey: '08ae5a08aa6a464619c177a551488c868010b4d2b2249892712be9a4990f9fc3',
|
|
139
|
+
WIF: 'KwWavecys1Qskgzwsyv6CNeTospWkvMeLzx3dLqeV4xAJEMXF8Qq'
|
|
87
140
|
}
|
|
88
141
|
```
|
|
89
142
|
|
|
143
|
+
## Convert a public key into a Neurai address
|
|
144
|
+
|
|
145
|
+
Every derived address now exposes the compressed public key so you can verify or reconstruct the address later. If you only have the raw public key (33-byte compressed or 65-byte uncompressed) you can convert it back into a Neurai address on either network:
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
import NeuraiKey from "@neuraiproject/neurai-key";
|
|
149
|
+
|
|
150
|
+
const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
|
|
151
|
+
const pair = NeuraiKey.getAddressPair("xna", mnemonic, 0, 1);
|
|
152
|
+
|
|
153
|
+
// `publicKey` is a hex string, but Buffers are also accepted
|
|
154
|
+
const reconstructed = NeuraiKey.publicKeyToAddress("xna", pair.external.publicKey);
|
|
155
|
+
|
|
156
|
+
console.log(reconstructed); // NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp
|
|
157
|
+
|
|
158
|
+
// Works the same way for testnet
|
|
159
|
+
const testPair = NeuraiKey.getAddressPair("xna-test", mnemonic, 0, 1);
|
|
160
|
+
const testAddress = NeuraiKey.publicKeyToAddress("xna-test", testPair.external.publicKey);
|
|
161
|
+
console.log(testAddress); // tPXGaMRNwZuV1UKSrD9gABPscrJWUmedQ9
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`publicKeyToAddress` throws if the key length is not 33 or 65 bytes so invalid inputs are surfaced immediately.
|
|
165
|
+
|
|
90
166
|
## How to import into your project
|
|
91
167
|
|
|
92
168
|
### ES6 module
|
|
@@ -157,9 +233,9 @@ Source: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
|
|
|
157
233
|
|
|
158
234
|
`m / purpose' / coin_type' / account' / change / address_index`
|
|
159
235
|
|
|
160
|
-
So in the case of Neurai the path m/44'/
|
|
236
|
+
So in the case of Neurai the path m/44'/0'/0'/0/1 says "give me the second address"
|
|
161
237
|
|
|
162
|
-
The first part m/44'/
|
|
238
|
+
The first part m/44'/0' says that the purpose is to use BIP44 with Neurai (coin_type 0). Consider that static code.
|
|
163
239
|
|
|
164
240
|
Accounts is deprecated and should be 0
|
|
165
241
|
|