@neuraiproject/neurai-key 2.8.2 → 2.8.4
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 +76 -26
- package/dist/NeuraiKey.js +60329 -0
- package/dist/main.js +138 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +113 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/example-passphrase.js +34 -0
- package/index.ts +23 -23
- package/package.json +3 -3
- package/test-html/NeuraiKey.js +60329 -0
- package/test-html/index.html +532 -0
- package/test.js +82 -25
package/dist/main.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var $g5Y9E$hyperbitjschains = require("@hyperbitjs/chains");
|
|
2
|
+
var $g5Y9E$bip39 = require("bip39");
|
|
3
|
+
var $g5Y9E$coinkey = require("coinkey");
|
|
4
|
+
var $g5Y9E$hdkey = require("hdkey");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$interopDefault(a) {
|
|
8
|
+
return a && a.__esModule ? a.default : a;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function $parcel$defineInteropFlag(a) {
|
|
12
|
+
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function $parcel$export(e, n, v, s) {
|
|
16
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
$parcel$defineInteropFlag(module.exports);
|
|
20
|
+
|
|
21
|
+
$parcel$export(module.exports, "getCoinType", () => $80bd448eb6ea085b$export$23109f16a8a07245);
|
|
22
|
+
$parcel$export(module.exports, "getAddressPair", () => $80bd448eb6ea085b$export$6e3ac79f8c0a2892);
|
|
23
|
+
$parcel$export(module.exports, "getHDKey", () => $80bd448eb6ea085b$export$6c78ccde21ad48f6);
|
|
24
|
+
$parcel$export(module.exports, "getAddressByPath", () => $80bd448eb6ea085b$export$6fc951b76952b95e);
|
|
25
|
+
$parcel$export(module.exports, "generateMnemonic", () => $80bd448eb6ea085b$export$9f993213e5806bf0);
|
|
26
|
+
$parcel$export(module.exports, "isMnemonicValid", () => $80bd448eb6ea085b$export$2b99b9ff149202f3);
|
|
27
|
+
$parcel$export(module.exports, "getAddressByWIF", () => $80bd448eb6ea085b$export$f43d70cb4ddd5664);
|
|
28
|
+
$parcel$export(module.exports, "entropyToMnemonic", () => $80bd448eb6ea085b$export$4becd65eb23312e6);
|
|
29
|
+
$parcel$export(module.exports, "generateAddressObject", () => $80bd448eb6ea085b$export$de190b37be25f71b);
|
|
30
|
+
$parcel$export(module.exports, "generateAddress", () => $80bd448eb6ea085b$export$e2e336010351d8a8);
|
|
31
|
+
$parcel$export(module.exports, "default", () => $80bd448eb6ea085b$export$2e2bcd8739ae039);
|
|
32
|
+
//Gives us meta data about coins/chains
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function $80bd448eb6ea085b$var$getNetwork(name) {
|
|
38
|
+
const c = name.toLowerCase(); //Just to be sure
|
|
39
|
+
const map = {
|
|
40
|
+
xna: (0, $g5Y9E$hyperbitjschains.chains).xna.mainnet.versions,
|
|
41
|
+
"xna-test": (0, $g5Y9E$hyperbitjschains.chains).xna.testnet?.versions
|
|
42
|
+
};
|
|
43
|
+
const network = map[c];
|
|
44
|
+
if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
|
|
45
|
+
return network;
|
|
46
|
+
}
|
|
47
|
+
function $80bd448eb6ea085b$export$23109f16a8a07245(network) {
|
|
48
|
+
const chain = $80bd448eb6ea085b$var$getNetwork(network);
|
|
49
|
+
return chain.bip44;
|
|
50
|
+
}
|
|
51
|
+
function $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase = "") {
|
|
52
|
+
const hdKey = $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic, passphrase);
|
|
53
|
+
const coin_type = $80bd448eb6ea085b$export$23109f16a8a07245(network);
|
|
54
|
+
//https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
55
|
+
//Syntax of BIP44
|
|
56
|
+
//m / purpose' / coin_type' / account' / change / address_index
|
|
57
|
+
const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;
|
|
58
|
+
const externalAddress = $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, externalPath);
|
|
59
|
+
//change address
|
|
60
|
+
const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;
|
|
61
|
+
const internalAddress = $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, internalPath);
|
|
62
|
+
return {
|
|
63
|
+
internal: internalAddress,
|
|
64
|
+
external: externalAddress,
|
|
65
|
+
position: position
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic, passphrase = "") {
|
|
69
|
+
const chain = $80bd448eb6ea085b$var$getNetwork(network);
|
|
70
|
+
const seed = $g5Y9E$bip39.mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
|
|
71
|
+
//From the seed, get a hdKey, can we use CoinKey instead?
|
|
72
|
+
const hdKey = (0, ($parcel$interopDefault($g5Y9E$hdkey))).fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
|
|
73
|
+
return hdKey;
|
|
74
|
+
}
|
|
75
|
+
function $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, path) {
|
|
76
|
+
const chain = $80bd448eb6ea085b$var$getNetwork(network);
|
|
77
|
+
const derived = hdKey.derive(path);
|
|
78
|
+
var ck2 = new $g5Y9E$coinkey(derived.privateKey, chain);
|
|
79
|
+
return {
|
|
80
|
+
address: ck2.publicAddress,
|
|
81
|
+
path: path,
|
|
82
|
+
privateKey: ck2.privateKey.toString("hex"),
|
|
83
|
+
WIF: ck2.privateWif
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function $80bd448eb6ea085b$export$9f993213e5806bf0() {
|
|
87
|
+
return $g5Y9E$bip39.generateMnemonic();
|
|
88
|
+
}
|
|
89
|
+
function $80bd448eb6ea085b$export$2b99b9ff149202f3(mnemonic) {
|
|
90
|
+
//Check all languages
|
|
91
|
+
const wordlists = Object.values($g5Y9E$bip39.wordlists);
|
|
92
|
+
//If mnemonic is valid in any language, return true, otherwise false
|
|
93
|
+
for (const wordlist of wordlists){
|
|
94
|
+
const v = $g5Y9E$bip39.validateMnemonic(mnemonic, wordlist);
|
|
95
|
+
if (v === true) return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
function $80bd448eb6ea085b$export$f43d70cb4ddd5664(network, privateKeyWIF) {
|
|
100
|
+
const coinKey = $g5Y9E$coinkey.fromWif(privateKeyWIF);
|
|
101
|
+
coinKey.versions = $80bd448eb6ea085b$var$getNetwork(network);
|
|
102
|
+
return {
|
|
103
|
+
address: coinKey.publicAddress,
|
|
104
|
+
privateKey: coinKey.privateKey.toString("hex"),
|
|
105
|
+
WIF: coinKey.privateWif
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const $80bd448eb6ea085b$export$4becd65eb23312e6 = $g5Y9E$bip39.entropyToMnemonic;
|
|
109
|
+
function $80bd448eb6ea085b$export$de190b37be25f71b(network = "xna", passphrase = "") {
|
|
110
|
+
const mnemonic = $80bd448eb6ea085b$export$9f993213e5806bf0();
|
|
111
|
+
const account = 0;
|
|
112
|
+
const position = 0;
|
|
113
|
+
const addressPair = $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase);
|
|
114
|
+
const addressObject = addressPair.external;
|
|
115
|
+
const result = {
|
|
116
|
+
...addressObject,
|
|
117
|
+
mnemonic: mnemonic,
|
|
118
|
+
network: network
|
|
119
|
+
};
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
function $80bd448eb6ea085b$export$e2e336010351d8a8(network = "xna") {
|
|
123
|
+
return $80bd448eb6ea085b$export$de190b37be25f71b(network);
|
|
124
|
+
}
|
|
125
|
+
var $80bd448eb6ea085b$export$2e2bcd8739ae039 = {
|
|
126
|
+
entropyToMnemonic: $80bd448eb6ea085b$export$4becd65eb23312e6,
|
|
127
|
+
generateAddress: $80bd448eb6ea085b$export$e2e336010351d8a8,
|
|
128
|
+
generateMnemonic: $80bd448eb6ea085b$export$9f993213e5806bf0,
|
|
129
|
+
getAddressByPath: $80bd448eb6ea085b$export$6fc951b76952b95e,
|
|
130
|
+
getAddressByWIF: $80bd448eb6ea085b$export$f43d70cb4ddd5664,
|
|
131
|
+
getAddressPair: $80bd448eb6ea085b$export$6e3ac79f8c0a2892,
|
|
132
|
+
getCoinType: $80bd448eb6ea085b$export$23109f16a8a07245,
|
|
133
|
+
getHDKey: $80bd448eb6ea085b$export$6c78ccde21ad48f6,
|
|
134
|
+
isMnemonicValid: $80bd448eb6ea085b$export$2b99b9ff149202f3
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","sources":["index.ts"],"sourcesContent":["//Gives us meta data about coins/chains\nimport { chains } from \"@hyperbitjs/chains\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\n//const HDKey = require(\"hdkey\");\nimport HDKey from \"hdkey\";\nimport { IAddressObject } from \"./types\";\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase(); //Just to be sure\n const map = {\n xna: chains.xna.mainnet.versions,\n \"xna-test\": chains.xna.testnet?.versions,\n };\n\n const network = map[c];\n if (!network) {\n throw new Error(\"network must be of value \" + Object.keys(map).toString());\n }\n return network;\n}\n/**\n *\n * @param network\n * @returns the coin type for the network (blockchain), for example Neurai has coin type 175\n */\nexport function getCoinType(network: Network) {\n const chain = getNetwork(network);\n return chain.bip44;\n}\n/**\n * @param network - should have value \"xna\", \"xna-test\", \"evr\" or \"evr-test\"\n * @param mnemonic - your mnemonic\n * @param account - accounts in BIP44 starts from 0, 0 is the default account\n * @param position - starts from 0\n * @param passphrase - optional BIP39 passphrase (25th word) for additional security\n */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number,\n passphrase: string = \"\"\n) {\n const hdKey = getHDKey(network, mnemonic, passphrase);\n const coin_type = getCoinType(network);\n\n //https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n\n //Syntax of BIP44\n //m / purpose' / coin_type' / account' / change / address_index\n const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;\n const externalAddress = getAddressByPath(network, hdKey, externalPath);\n\n //change address\n const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;\n const internalAddress = getAddressByPath(network, hdKey, internalPath);\n return {\n internal: internalAddress,\n external: externalAddress,\n position,\n };\n}\n\nexport function getHDKey(network: Network, mnemonic: string, passphrase: string = \"\"): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString(\"hex\");\n //From the seed, get a hdKey, can we use CoinKey instead?\n const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, \"hex\"), chain.bip32);\n return hdKey;\n}\n\nexport function getAddressByPath(\n network: Network,\n hdKey: any,\n path: string\n): IAddressObject {\n const chain = getNetwork(network);\n const derived = hdKey.derive(path);\n var ck2 = new CoinKey(derived.privateKey, chain);\n\n return {\n address: ck2.publicAddress,\n path: path,\n privateKey: ck2.privateKey.toString(\"hex\"),\n WIF: ck2.privateWif,\n };\n}\n\nexport function generateMnemonic() {\n return bip39.generateMnemonic();\n}\n\nexport function isMnemonicValid(mnemonic: string) {\n //Check all languages\n const wordlists = Object.values(bip39.wordlists);\n\n //If mnemonic is valid in any language, return true, otherwise false\n for (const wordlist of wordlists) {\n const v = bip39.validateMnemonic(mnemonic, wordlist);\n if (v === true) {\n return true;\n }\n }\n return false;\n}\n/**\n *\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns object {address, privateKey (hex), WIF}\n */\n\nexport function getAddressByWIF(network: Network, privateKeyWIF: string) {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return {\n address: coinKey.publicAddress,\n privateKey: coinKey.privateKey.toString(\"hex\"),\n WIF: coinKey.privateWif,\n };\n}\n\nexport const entropyToMnemonic = bip39.entropyToMnemonic;\n\nexport function generateAddressObject(\n network: Network = \"xna\",\n passphrase: string = \"\"\n): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);\n const addressObject = addressPair.external;\n\n const result = {\n ...addressObject,\n mnemonic,\n network,\n };\n return result;\n}\n\n/**\n * Generates a random Address Object\n *\n * @deprecated use generateAddressObject\n * @param network\n * @returns\n */\nexport function generateAddress(network: Network = \"xna\") {\n return generateAddressObject(network);\n}\nexport default {\n entropyToMnemonic,\n generateAddress,\n generateMnemonic,\n getAddressByPath,\n getAddressByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n};\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {chains as $hCgyA$chains} from "@hyperbitjs/chains";
|
|
2
|
+
import {mnemonicToSeedSync as $hCgyA$mnemonicToSeedSync, generateMnemonic as $hCgyA$generateMnemonic, wordlists as $hCgyA$wordlists, validateMnemonic as $hCgyA$validateMnemonic, entropyToMnemonic as $hCgyA$entropyToMnemonic} from "bip39";
|
|
3
|
+
import * as $hCgyA$coinkey from "coinkey";
|
|
4
|
+
import $hCgyA$hdkey from "hdkey";
|
|
5
|
+
|
|
6
|
+
//Gives us meta data about coins/chains
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function $c3f6c693698dc7cd$var$getNetwork(name) {
|
|
12
|
+
const c = name.toLowerCase(); //Just to be sure
|
|
13
|
+
const map = {
|
|
14
|
+
xna: (0, $hCgyA$chains).xna.mainnet.versions,
|
|
15
|
+
"xna-test": (0, $hCgyA$chains).xna.testnet?.versions
|
|
16
|
+
};
|
|
17
|
+
const network = map[c];
|
|
18
|
+
if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
|
|
19
|
+
return network;
|
|
20
|
+
}
|
|
21
|
+
function $c3f6c693698dc7cd$export$23109f16a8a07245(network) {
|
|
22
|
+
const chain = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
23
|
+
return chain.bip44;
|
|
24
|
+
}
|
|
25
|
+
function $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase = "") {
|
|
26
|
+
const hdKey = $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic, passphrase);
|
|
27
|
+
const coin_type = $c3f6c693698dc7cd$export$23109f16a8a07245(network);
|
|
28
|
+
//https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
29
|
+
//Syntax of BIP44
|
|
30
|
+
//m / purpose' / coin_type' / account' / change / address_index
|
|
31
|
+
const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;
|
|
32
|
+
const externalAddress = $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, externalPath);
|
|
33
|
+
//change address
|
|
34
|
+
const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;
|
|
35
|
+
const internalAddress = $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, internalPath);
|
|
36
|
+
return {
|
|
37
|
+
internal: internalAddress,
|
|
38
|
+
external: externalAddress,
|
|
39
|
+
position: position
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic, passphrase = "") {
|
|
43
|
+
const chain = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
44
|
+
const seed = $hCgyA$mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
|
|
45
|
+
//From the seed, get a hdKey, can we use CoinKey instead?
|
|
46
|
+
const hdKey = (0, $hCgyA$hdkey).fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
|
|
47
|
+
return hdKey;
|
|
48
|
+
}
|
|
49
|
+
function $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, path) {
|
|
50
|
+
const chain = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
51
|
+
const derived = hdKey.derive(path);
|
|
52
|
+
var ck2 = new $hCgyA$coinkey(derived.privateKey, chain);
|
|
53
|
+
return {
|
|
54
|
+
address: ck2.publicAddress,
|
|
55
|
+
path: path,
|
|
56
|
+
privateKey: ck2.privateKey.toString("hex"),
|
|
57
|
+
WIF: ck2.privateWif
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function $c3f6c693698dc7cd$export$9f993213e5806bf0() {
|
|
61
|
+
return $hCgyA$generateMnemonic();
|
|
62
|
+
}
|
|
63
|
+
function $c3f6c693698dc7cd$export$2b99b9ff149202f3(mnemonic) {
|
|
64
|
+
//Check all languages
|
|
65
|
+
const wordlists = Object.values($hCgyA$wordlists);
|
|
66
|
+
//If mnemonic is valid in any language, return true, otherwise false
|
|
67
|
+
for (const wordlist of wordlists){
|
|
68
|
+
const v = $hCgyA$validateMnemonic(mnemonic, wordlist);
|
|
69
|
+
if (v === true) return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
function $c3f6c693698dc7cd$export$f43d70cb4ddd5664(network, privateKeyWIF) {
|
|
74
|
+
const coinKey = $hCgyA$coinkey.fromWif(privateKeyWIF);
|
|
75
|
+
coinKey.versions = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
76
|
+
return {
|
|
77
|
+
address: coinKey.publicAddress,
|
|
78
|
+
privateKey: coinKey.privateKey.toString("hex"),
|
|
79
|
+
WIF: coinKey.privateWif
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const $c3f6c693698dc7cd$export$4becd65eb23312e6 = $hCgyA$entropyToMnemonic;
|
|
83
|
+
function $c3f6c693698dc7cd$export$de190b37be25f71b(network = "xna", passphrase = "") {
|
|
84
|
+
const mnemonic = $c3f6c693698dc7cd$export$9f993213e5806bf0();
|
|
85
|
+
const account = 0;
|
|
86
|
+
const position = 0;
|
|
87
|
+
const addressPair = $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase);
|
|
88
|
+
const addressObject = addressPair.external;
|
|
89
|
+
const result = {
|
|
90
|
+
...addressObject,
|
|
91
|
+
mnemonic: mnemonic,
|
|
92
|
+
network: network
|
|
93
|
+
};
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function $c3f6c693698dc7cd$export$e2e336010351d8a8(network = "xna") {
|
|
97
|
+
return $c3f6c693698dc7cd$export$de190b37be25f71b(network);
|
|
98
|
+
}
|
|
99
|
+
var $c3f6c693698dc7cd$export$2e2bcd8739ae039 = {
|
|
100
|
+
entropyToMnemonic: $c3f6c693698dc7cd$export$4becd65eb23312e6,
|
|
101
|
+
generateAddress: $c3f6c693698dc7cd$export$e2e336010351d8a8,
|
|
102
|
+
generateMnemonic: $c3f6c693698dc7cd$export$9f993213e5806bf0,
|
|
103
|
+
getAddressByPath: $c3f6c693698dc7cd$export$6fc951b76952b95e,
|
|
104
|
+
getAddressByWIF: $c3f6c693698dc7cd$export$f43d70cb4ddd5664,
|
|
105
|
+
getAddressPair: $c3f6c693698dc7cd$export$6e3ac79f8c0a2892,
|
|
106
|
+
getCoinType: $c3f6c693698dc7cd$export$23109f16a8a07245,
|
|
107
|
+
getHDKey: $c3f6c693698dc7cd$export$6c78ccde21ad48f6,
|
|
108
|
+
isMnemonicValid: $c3f6c693698dc7cd$export$2b99b9ff149202f3
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
export {$c3f6c693698dc7cd$export$23109f16a8a07245 as getCoinType, $c3f6c693698dc7cd$export$6e3ac79f8c0a2892 as getAddressPair, $c3f6c693698dc7cd$export$6c78ccde21ad48f6 as getHDKey, $c3f6c693698dc7cd$export$6fc951b76952b95e as getAddressByPath, $c3f6c693698dc7cd$export$9f993213e5806bf0 as generateMnemonic, $c3f6c693698dc7cd$export$2b99b9ff149202f3 as isMnemonicValid, $c3f6c693698dc7cd$export$f43d70cb4ddd5664 as getAddressByWIF, $c3f6c693698dc7cd$export$4becd65eb23312e6 as entropyToMnemonic, $c3f6c693698dc7cd$export$de190b37be25f71b as generateAddressObject, $c3f6c693698dc7cd$export$e2e336010351d8a8 as generateAddress, $c3f6c693698dc7cd$export$2e2bcd8739ae039 as default};
|
|
113
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","sources":["index.ts"],"sourcesContent":["//Gives us meta data about coins/chains\nimport { chains } from \"@hyperbitjs/chains\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\n//const HDKey = require(\"hdkey\");\nimport HDKey from \"hdkey\";\nimport { IAddressObject } from \"./types\";\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase(); //Just to be sure\n const map = {\n xna: chains.xna.mainnet.versions,\n \"xna-test\": chains.xna.testnet?.versions,\n };\n\n const network = map[c];\n if (!network) {\n throw new Error(\"network must be of value \" + Object.keys(map).toString());\n }\n return network;\n}\n/**\n *\n * @param network\n * @returns the coin type for the network (blockchain), for example Neurai has coin type 175\n */\nexport function getCoinType(network: Network) {\n const chain = getNetwork(network);\n return chain.bip44;\n}\n/**\n * @param network - should have value \"xna\", \"xna-test\", \"evr\" or \"evr-test\"\n * @param mnemonic - your mnemonic\n * @param account - accounts in BIP44 starts from 0, 0 is the default account\n * @param position - starts from 0\n * @param passphrase - optional BIP39 passphrase (25th word) for additional security\n */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number,\n passphrase: string = \"\"\n) {\n const hdKey = getHDKey(network, mnemonic, passphrase);\n const coin_type = getCoinType(network);\n\n //https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n\n //Syntax of BIP44\n //m / purpose' / coin_type' / account' / change / address_index\n const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;\n const externalAddress = getAddressByPath(network, hdKey, externalPath);\n\n //change address\n const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;\n const internalAddress = getAddressByPath(network, hdKey, internalPath);\n return {\n internal: internalAddress,\n external: externalAddress,\n position,\n };\n}\n\nexport function getHDKey(network: Network, mnemonic: string, passphrase: string = \"\"): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString(\"hex\");\n //From the seed, get a hdKey, can we use CoinKey instead?\n const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, \"hex\"), chain.bip32);\n return hdKey;\n}\n\nexport function getAddressByPath(\n network: Network,\n hdKey: any,\n path: string\n): IAddressObject {\n const chain = getNetwork(network);\n const derived = hdKey.derive(path);\n var ck2 = new CoinKey(derived.privateKey, chain);\n\n return {\n address: ck2.publicAddress,\n path: path,\n privateKey: ck2.privateKey.toString(\"hex\"),\n WIF: ck2.privateWif,\n };\n}\n\nexport function generateMnemonic() {\n return bip39.generateMnemonic();\n}\n\nexport function isMnemonicValid(mnemonic: string) {\n //Check all languages\n const wordlists = Object.values(bip39.wordlists);\n\n //If mnemonic is valid in any language, return true, otherwise false\n for (const wordlist of wordlists) {\n const v = bip39.validateMnemonic(mnemonic, wordlist);\n if (v === true) {\n return true;\n }\n }\n return false;\n}\n/**\n *\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns object {address, privateKey (hex), WIF}\n */\n\nexport function getAddressByWIF(network: Network, privateKeyWIF: string) {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return {\n address: coinKey.publicAddress,\n privateKey: coinKey.privateKey.toString(\"hex\"),\n WIF: coinKey.privateWif,\n };\n}\n\nexport const entropyToMnemonic = bip39.entropyToMnemonic;\n\nexport function generateAddressObject(\n network: Network = \"xna\",\n passphrase: string = \"\"\n): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);\n const addressObject = addressPair.external;\n\n const result = {\n ...addressObject,\n mnemonic,\n network,\n };\n return result;\n}\n\n/**\n * Generates a random Address Object\n *\n * @deprecated use generateAddressObject\n * @param network\n * @returns\n */\nexport function generateAddress(network: Network = \"xna\") {\n return generateAddressObject(network);\n}\nexport default {\n entropyToMnemonic,\n generateAddress,\n generateMnemonic,\n getAddressByPath,\n getAddressByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n};\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as bip39 from "bip39";
|
|
2
|
+
interface IAddressObject {
|
|
3
|
+
address: string;
|
|
4
|
+
mnemonic?: string;
|
|
5
|
+
path: string;
|
|
6
|
+
privateKey: string;
|
|
7
|
+
WIF: string;
|
|
8
|
+
}
|
|
9
|
+
export type Network = "xna" | "xna-test";
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param network
|
|
13
|
+
* @returns the coin type for the network (blockchain), for example Neurai has coin type 175
|
|
14
|
+
*/
|
|
15
|
+
export function getCoinType(network: Network): any;
|
|
16
|
+
/**
|
|
17
|
+
* @param network - should have value "xna", "xna-test", "evr" or "evr-test"
|
|
18
|
+
* @param mnemonic - your mnemonic
|
|
19
|
+
* @param account - accounts in BIP44 starts from 0, 0 is the default account
|
|
20
|
+
* @param position - starts from 0
|
|
21
|
+
* @param passphrase - optional BIP39 passphrase (25th word) for additional security
|
|
22
|
+
*/
|
|
23
|
+
export function getAddressPair(network: Network, mnemonic: string, account: number, position: number, passphrase?: string): {
|
|
24
|
+
internal: IAddressObject;
|
|
25
|
+
external: IAddressObject;
|
|
26
|
+
position: number;
|
|
27
|
+
};
|
|
28
|
+
export function getHDKey(network: Network, mnemonic: string, passphrase?: string): any;
|
|
29
|
+
export function getAddressByPath(network: Network, hdKey: any, path: string): IAddressObject;
|
|
30
|
+
export function generateMnemonic(): string;
|
|
31
|
+
export function isMnemonicValid(mnemonic: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param privateKeyWIF
|
|
35
|
+
* @param network should be "xna" or "xna-test"
|
|
36
|
+
* @returns object {address, privateKey (hex), WIF}
|
|
37
|
+
*/
|
|
38
|
+
export function getAddressByWIF(network: Network, privateKeyWIF: string): {
|
|
39
|
+
address: any;
|
|
40
|
+
privateKey: any;
|
|
41
|
+
WIF: any;
|
|
42
|
+
};
|
|
43
|
+
export const entropyToMnemonic: typeof bip39.entropyToMnemonic;
|
|
44
|
+
export function generateAddressObject(network?: Network, passphrase?: string): IAddressObject;
|
|
45
|
+
/**
|
|
46
|
+
* Generates a random Address Object
|
|
47
|
+
*
|
|
48
|
+
* @deprecated use generateAddressObject
|
|
49
|
+
* @param network
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export function generateAddress(network?: Network): IAddressObject;
|
|
53
|
+
declare const _default: {
|
|
54
|
+
entropyToMnemonic: typeof bip39.entropyToMnemonic;
|
|
55
|
+
generateAddress: typeof generateAddress;
|
|
56
|
+
generateMnemonic: typeof generateMnemonic;
|
|
57
|
+
getAddressByPath: typeof getAddressByPath;
|
|
58
|
+
getAddressByWIF: typeof getAddressByWIF;
|
|
59
|
+
getAddressPair: typeof getAddressPair;
|
|
60
|
+
getCoinType: typeof getCoinType;
|
|
61
|
+
getHDKey: typeof getHDKey;
|
|
62
|
+
isMnemonicValid: typeof isMnemonicValid;
|
|
63
|
+
};
|
|
64
|
+
export default _default;
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAAA;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;ACQD,sBAAsB,KAAK,GAAG,UAAU,CAAC;AAezC;;;;GAIG;AACH,4BAA4B,OAAO,EAAE,OAAO,OAG3C;AACD;;;;;;GAMG;AACH,+BACE,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,MAAW;;;;EAoBxB;AAED,yBAAyB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,GAAG,CAMzF;AAED,iCACE,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,MAAM,GACX,cAAc,CAWhB;AAED,2CAEC;AAED,gCAAgC,QAAQ,EAAE,MAAM,WAY/C;AACD;;;;;GAKG;AAEH,gCAAgC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM;;;;EAStE;AAED,OAAO,MAAM,iDAA2C,CAAC;AAEzD,sCACE,OAAO,GAAE,OAAe,EACxB,UAAU,GAAE,MAAW,GACtB,cAAc,CAahB;AAED;;;;;;GAMG;AACH,gCAAgC,OAAO,GAAE,OAAe,kBAEvD;;;;;;;;;;;;AACD,wBAUE","sources":["types.ts","index.ts"],"sourcesContent":["export interface IAddressObject {\n address: string;\n mnemonic?: string;\n path: string;\n privateKey: string;\n WIF: string;\n}\n","//Gives us meta data about coins/chains\nimport { chains } from \"@hyperbitjs/chains\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\n//const HDKey = require(\"hdkey\");\nimport HDKey from \"hdkey\";\nimport { IAddressObject } from \"./types\";\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase(); //Just to be sure\n const map = {\n xna: chains.xna.mainnet.versions,\n \"xna-test\": chains.xna.testnet?.versions,\n };\n\n const network = map[c];\n if (!network) {\n throw new Error(\"network must be of value \" + Object.keys(map).toString());\n }\n return network;\n}\n/**\n *\n * @param network\n * @returns the coin type for the network (blockchain), for example Neurai has coin type 175\n */\nexport function getCoinType(network: Network) {\n const chain = getNetwork(network);\n return chain.bip44;\n}\n/**\n * @param network - should have value \"xna\", \"xna-test\", \"evr\" or \"evr-test\"\n * @param mnemonic - your mnemonic\n * @param account - accounts in BIP44 starts from 0, 0 is the default account\n * @param position - starts from 0\n * @param passphrase - optional BIP39 passphrase (25th word) for additional security\n */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number,\n passphrase: string = \"\"\n) {\n const hdKey = getHDKey(network, mnemonic, passphrase);\n const coin_type = getCoinType(network);\n\n //https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n\n //Syntax of BIP44\n //m / purpose' / coin_type' / account' / change / address_index\n const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;\n const externalAddress = getAddressByPath(network, hdKey, externalPath);\n\n //change address\n const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;\n const internalAddress = getAddressByPath(network, hdKey, internalPath);\n return {\n internal: internalAddress,\n external: externalAddress,\n position,\n };\n}\n\nexport function getHDKey(network: Network, mnemonic: string, passphrase: string = \"\"): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString(\"hex\");\n //From the seed, get a hdKey, can we use CoinKey instead?\n const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, \"hex\"), chain.bip32);\n return hdKey;\n}\n\nexport function getAddressByPath(\n network: Network,\n hdKey: any,\n path: string\n): IAddressObject {\n const chain = getNetwork(network);\n const derived = hdKey.derive(path);\n var ck2 = new CoinKey(derived.privateKey, chain);\n\n return {\n address: ck2.publicAddress,\n path: path,\n privateKey: ck2.privateKey.toString(\"hex\"),\n WIF: ck2.privateWif,\n };\n}\n\nexport function generateMnemonic() {\n return bip39.generateMnemonic();\n}\n\nexport function isMnemonicValid(mnemonic: string) {\n //Check all languages\n const wordlists = Object.values(bip39.wordlists);\n\n //If mnemonic is valid in any language, return true, otherwise false\n for (const wordlist of wordlists) {\n const v = bip39.validateMnemonic(mnemonic, wordlist);\n if (v === true) {\n return true;\n }\n }\n return false;\n}\n/**\n *\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns object {address, privateKey (hex), WIF}\n */\n\nexport function getAddressByWIF(network: Network, privateKeyWIF: string) {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return {\n address: coinKey.publicAddress,\n privateKey: coinKey.privateKey.toString(\"hex\"),\n WIF: coinKey.privateWif,\n };\n}\n\nexport const entropyToMnemonic = bip39.entropyToMnemonic;\n\nexport function generateAddressObject(\n network: Network = \"xna\",\n passphrase: string = \"\"\n): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);\n const addressObject = addressPair.external;\n\n const result = {\n ...addressObject,\n mnemonic,\n network,\n };\n return result;\n}\n\n/**\n * Generates a random Address Object\n *\n * @deprecated use generateAddressObject\n * @param network\n * @returns\n */\nexport function generateAddress(network: Network = \"xna\") {\n return generateAddressObject(network);\n}\nexport default {\n entropyToMnemonic,\n generateAddress,\n generateMnemonic,\n getAddressByPath,\n getAddressByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n};\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const NeuraiKey = require("./dist/main");
|
|
2
|
+
|
|
3
|
+
console.log("=== Neurai Key - Passphrase Example ===\n");
|
|
4
|
+
|
|
5
|
+
const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
|
|
6
|
+
const network = "xna";
|
|
7
|
+
const account = 0;
|
|
8
|
+
const position = 0;
|
|
9
|
+
|
|
10
|
+
console.log("Mnemonic:", mnemonic);
|
|
11
|
+
console.log("\n--- WITHOUT Passphrase ---");
|
|
12
|
+
const addressNoPass = NeuraiKey.getAddressPair(network, mnemonic, account, position);
|
|
13
|
+
console.log("External Address:", addressNoPass.external.address);
|
|
14
|
+
console.log("Internal Address:", addressNoPass.internal.address);
|
|
15
|
+
console.log("WIF:", addressNoPass.external.WIF);
|
|
16
|
+
|
|
17
|
+
console.log("\n--- WITH Passphrase: 'my secret passphrase' ---");
|
|
18
|
+
const passphrase1 = "my secret passphrase";
|
|
19
|
+
const addressWithPass1 = NeuraiKey.getAddressPair(network, mnemonic, account, position, passphrase1);
|
|
20
|
+
console.log("External Address:", addressWithPass1.external.address);
|
|
21
|
+
console.log("Internal Address:", addressWithPass1.internal.address);
|
|
22
|
+
console.log("WIF:", addressWithPass1.external.WIF);
|
|
23
|
+
|
|
24
|
+
console.log("\n--- WITH Different Passphrase: 'another passphrase' ---");
|
|
25
|
+
const passphrase2 = "another passphrase";
|
|
26
|
+
const addressWithPass2 = NeuraiKey.getAddressPair(network, mnemonic, account, position, passphrase2);
|
|
27
|
+
console.log("External Address:", addressWithPass2.external.address);
|
|
28
|
+
console.log("Internal Address:", addressWithPass2.internal.address);
|
|
29
|
+
console.log("WIF:", addressWithPass2.external.WIF);
|
|
30
|
+
|
|
31
|
+
console.log("\n=== Summary ===");
|
|
32
|
+
console.log("✅ Same mnemonic + different passphrases = DIFFERENT wallets");
|
|
33
|
+
console.log("✅ This provides an extra security layer");
|
|
34
|
+
console.log("⚠️ IMPORTANT: You need BOTH mnemonic AND passphrase to recover the wallet!");
|
package/index.ts
CHANGED
|
@@ -12,46 +12,45 @@ 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" | "xna-test";
|
|
16
16
|
|
|
17
17
|
function getNetwork(name: Network) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
bip32: {
|
|
24
|
-
private: 0x0488ade4,
|
|
25
|
-
public: 0x0488b21e,
|
|
26
|
-
},
|
|
27
|
-
bip44: 0,
|
|
28
|
-
private: 0x80,
|
|
29
|
-
public: 0x35,
|
|
30
|
-
scripthash: 0x75,
|
|
18
|
+
const c = name.toLowerCase(); //Just to be sure
|
|
19
|
+
const map = {
|
|
20
|
+
xna: chains.xna.mainnet.versions,
|
|
21
|
+
"xna-test": chains.xna.testnet?.versions,
|
|
31
22
|
};
|
|
23
|
+
|
|
24
|
+
const network = map[c];
|
|
25
|
+
if (!network) {
|
|
26
|
+
throw new Error("network must be of value " + Object.keys(map).toString());
|
|
27
|
+
}
|
|
28
|
+
return network;
|
|
32
29
|
}
|
|
33
30
|
/**
|
|
34
31
|
*
|
|
35
32
|
* @param network
|
|
36
|
-
* @returns the coin type for the network (blockchain)
|
|
33
|
+
* @returns the coin type for the network (blockchain), for example Neurai has coin type 175
|
|
37
34
|
*/
|
|
38
35
|
export function getCoinType(network: Network) {
|
|
39
36
|
const chain = getNetwork(network);
|
|
40
37
|
return chain.bip44;
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
|
-
* @param network - should have value "xna"
|
|
40
|
+
* @param network - should have value "xna", "xna-test", "evr" or "evr-test"
|
|
44
41
|
* @param mnemonic - your mnemonic
|
|
45
42
|
* @param account - accounts in BIP44 starts from 0, 0 is the default account
|
|
46
43
|
* @param position - starts from 0
|
|
44
|
+
* @param passphrase - optional BIP39 passphrase (25th word) for additional security
|
|
47
45
|
*/
|
|
48
46
|
export function getAddressPair(
|
|
49
47
|
network: Network,
|
|
50
48
|
mnemonic: string,
|
|
51
49
|
account: number,
|
|
52
|
-
position: number
|
|
50
|
+
position: number,
|
|
51
|
+
passphrase: string = ""
|
|
53
52
|
) {
|
|
54
|
-
const hdKey = getHDKey(network, mnemonic);
|
|
53
|
+
const hdKey = getHDKey(network, mnemonic, passphrase);
|
|
55
54
|
const coin_type = getCoinType(network);
|
|
56
55
|
|
|
57
56
|
//https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
@@ -71,9 +70,9 @@ export function getAddressPair(
|
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
export function getHDKey(network: Network, mnemonic: string): any {
|
|
73
|
+
export function getHDKey(network: Network, mnemonic: string, passphrase: string = ""): any {
|
|
75
74
|
const chain = getNetwork(network);
|
|
76
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic).toString("hex");
|
|
75
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
|
|
77
76
|
//From the seed, get a hdKey, can we use CoinKey instead?
|
|
78
77
|
const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
|
|
79
78
|
return hdKey;
|
|
@@ -116,7 +115,7 @@ export function isMnemonicValid(mnemonic: string) {
|
|
|
116
115
|
/**
|
|
117
116
|
*
|
|
118
117
|
* @param privateKeyWIF
|
|
119
|
-
* @param network should be "
|
|
118
|
+
* @param network should be "xna" or "xna-test"
|
|
120
119
|
* @returns object {address, privateKey (hex), WIF}
|
|
121
120
|
*/
|
|
122
121
|
|
|
@@ -134,12 +133,13 @@ export function getAddressByWIF(network: Network, privateKeyWIF: string) {
|
|
|
134
133
|
export const entropyToMnemonic = bip39.entropyToMnemonic;
|
|
135
134
|
|
|
136
135
|
export function generateAddressObject(
|
|
137
|
-
network: Network = "xna"
|
|
136
|
+
network: Network = "xna",
|
|
137
|
+
passphrase: string = ""
|
|
138
138
|
): IAddressObject {
|
|
139
139
|
const mnemonic = generateMnemonic();
|
|
140
140
|
const account = 0;
|
|
141
141
|
const position = 0;
|
|
142
|
-
const addressPair = getAddressPair(network, mnemonic, account, position);
|
|
142
|
+
const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);
|
|
143
143
|
const addressObject = addressPair.external;
|
|
144
144
|
|
|
145
145
|
const result = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuraiproject/neurai-key",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
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": "Neuraiproject",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/neuraiproject/neurai-key/issues"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@parcel/packager-ts": "^2.10.3",
|
|
37
|
-
"@parcel/transformer-typescript-types": "
|
|
37
|
+
"@parcel/transformer-typescript-types": "2.16.0",
|
|
38
38
|
"@types/hdkey": "^2.0.3",
|
|
39
39
|
"@types/node": "^18.14.0",
|
|
40
40
|
"browserify": "^17.0.0",
|