@neuraiproject/neurai-key 2.8.1 → 2.8.3

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/dist/main.js ADDED
@@ -0,0 +1,140 @@
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
+ evr: (0, $g5Y9E$hyperbitjschains.chains).evr.mainnet.versions,
43
+ "evr-test": (0, $g5Y9E$hyperbitjschains.chains).evr.testnet?.versions
44
+ };
45
+ const network = map[c];
46
+ if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
47
+ return network;
48
+ }
49
+ function $80bd448eb6ea085b$export$23109f16a8a07245(network) {
50
+ const chain = $80bd448eb6ea085b$var$getNetwork(network);
51
+ return chain.bip44;
52
+ }
53
+ function $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position) {
54
+ const hdKey = $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic);
55
+ const coin_type = $80bd448eb6ea085b$export$23109f16a8a07245(network);
56
+ //https://github.com/satoshilabs/slips/blob/master/slip-0044.md
57
+ //Syntax of BIP44
58
+ //m / purpose' / coin_type' / account' / change / address_index
59
+ const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;
60
+ const externalAddress = $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, externalPath);
61
+ //change address
62
+ const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;
63
+ const internalAddress = $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, internalPath);
64
+ return {
65
+ internal: internalAddress,
66
+ external: externalAddress,
67
+ position: position
68
+ };
69
+ }
70
+ function $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic) {
71
+ const chain = $80bd448eb6ea085b$var$getNetwork(network);
72
+ const seed = $g5Y9E$bip39.mnemonicToSeedSync(mnemonic).toString("hex");
73
+ //From the seed, get a hdKey, can we use CoinKey instead?
74
+ const hdKey = (0, ($parcel$interopDefault($g5Y9E$hdkey))).fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
75
+ return hdKey;
76
+ }
77
+ function $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, path) {
78
+ const chain = $80bd448eb6ea085b$var$getNetwork(network);
79
+ const derived = hdKey.derive(path);
80
+ var ck2 = new $g5Y9E$coinkey(derived.privateKey, chain);
81
+ return {
82
+ address: ck2.publicAddress,
83
+ path: path,
84
+ privateKey: ck2.privateKey.toString("hex"),
85
+ WIF: ck2.privateWif
86
+ };
87
+ }
88
+ function $80bd448eb6ea085b$export$9f993213e5806bf0() {
89
+ return $g5Y9E$bip39.generateMnemonic();
90
+ }
91
+ function $80bd448eb6ea085b$export$2b99b9ff149202f3(mnemonic) {
92
+ //Check all languages
93
+ const wordlists = Object.values($g5Y9E$bip39.wordlists);
94
+ //If mnemonic is valid in any language, return true, otherwise false
95
+ for (const wordlist of wordlists){
96
+ const v = $g5Y9E$bip39.validateMnemonic(mnemonic, wordlist);
97
+ if (v === true) return true;
98
+ }
99
+ return false;
100
+ }
101
+ function $80bd448eb6ea085b$export$f43d70cb4ddd5664(network, privateKeyWIF) {
102
+ const coinKey = $g5Y9E$coinkey.fromWif(privateKeyWIF);
103
+ coinKey.versions = $80bd448eb6ea085b$var$getNetwork(network);
104
+ return {
105
+ address: coinKey.publicAddress,
106
+ privateKey: coinKey.privateKey.toString("hex"),
107
+ WIF: coinKey.privateWif
108
+ };
109
+ }
110
+ const $80bd448eb6ea085b$export$4becd65eb23312e6 = $g5Y9E$bip39.entropyToMnemonic;
111
+ function $80bd448eb6ea085b$export$de190b37be25f71b(network = "xna") {
112
+ const mnemonic = $80bd448eb6ea085b$export$9f993213e5806bf0();
113
+ const account = 0;
114
+ const position = 0;
115
+ const addressPair = $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position);
116
+ const addressObject = addressPair.external;
117
+ const result = {
118
+ ...addressObject,
119
+ mnemonic: mnemonic,
120
+ network: network
121
+ };
122
+ return result;
123
+ }
124
+ function $80bd448eb6ea085b$export$e2e336010351d8a8(network = "xna") {
125
+ return $80bd448eb6ea085b$export$de190b37be25f71b(network);
126
+ }
127
+ var $80bd448eb6ea085b$export$2e2bcd8739ae039 = {
128
+ entropyToMnemonic: $80bd448eb6ea085b$export$4becd65eb23312e6,
129
+ generateAddress: $80bd448eb6ea085b$export$e2e336010351d8a8,
130
+ generateMnemonic: $80bd448eb6ea085b$export$9f993213e5806bf0,
131
+ getAddressByPath: $80bd448eb6ea085b$export$6fc951b76952b95e,
132
+ getAddressByWIF: $80bd448eb6ea085b$export$f43d70cb4ddd5664,
133
+ getAddressPair: $80bd448eb6ea085b$export$6e3ac79f8c0a2892,
134
+ getCoinType: $80bd448eb6ea085b$export$23109f16a8a07245,
135
+ getHDKey: $80bd448eb6ea085b$export$6c78ccde21ad48f6,
136
+ isMnemonicValid: $80bd448eb6ea085b$export$2b99b9ff149202f3
137
+ };
138
+
139
+
140
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuC;;;;;AAgBvC,SAAS,iCAAW,IAAa;IAC/B,MAAM,IAAI,KAAK,WAAW,IAAI,iBAAiB;IAC/C,MAAM,MAAM;QACV,KAAK,CAAA,GAAA,8BAAK,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ;QAChC,YAAY,CAAA,GAAA,8BAAK,EAAE,GAAG,CAAC,OAAO,EAAE;QAChC,KAAK,CAAA,GAAA,8BAAK,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ;QAChC,YAAY,CAAA,GAAA,8BAAK,EAAE,GAAG,CAAC,OAAO,EAAE;IAClC;IAEA,MAAM,UAAU,GAAG,CAAC,EAAE;IACtB,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8BAA8B,OAAO,IAAI,CAAC,KAAK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oEAAoE;IACpE,KAAK,MAAM,YAAY,UAAW;QAChC,MAAM,IAAI,8BAAuB,UAAU;QAC3C,IAAI,MAAM,MACR,OAAO;IAEX;IACA,OAAO;AACT;AAQO,SAAS,0CAAgB,OAAgB,EAAE,aAAqB;IACrE,MAAM,UAAU,eAAQ,OAAO,CAAC;IAChC,QAAQ,QAAQ,GAAG,iCAAW;IAE9B,OAAO;QACL,SAAS,QAAQ,aAAa;QAC9B,YAAY,QAAQ,UAAU,CAAC,QAAQ,CAAC;QACxC,KAAK,QAAQ,UAAU;IACzB;AACF;AAEO,MAAM,4CAAoB;AAE1B,SAAS,0CACd,UAAmB,KAAK;IAExB,MAAM,WAAW;IACjB,MAAM,UAAU;IAChB,MAAM,WAAW;IACjB,MAAM,cAAc,0CAAe,SAAS,UAAU,SAAS;IAC/D,MAAM,gBAAgB,YAAY,QAAQ;IAE1C,MAAM,SAAS;QACb,GAAG,aAAa;kBAChB;iBACA;IACF;IACA,OAAO;AACT;AASO,SAAS,0CAAgB,UAAmB,KAAK;IACtD,OAAO,0CAAsB;AAC/B;IACA,2CAAe;uBACb;qBACA;sBACA;sBACA;qBACA;oBACA;iBACA;cACA;qBACA;AACF","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\" | \"evr\" | \"evr-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 evr: chains.evr.mainnet.versions,\n \"evr-test\": chains.evr.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 */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number\n) {\n const hdKey = getHDKey(network, mnemonic);\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): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic).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): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position);\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,115 @@
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
+ evr: (0, $hCgyA$chains).evr.mainnet.versions,
17
+ "evr-test": (0, $hCgyA$chains).evr.testnet?.versions
18
+ };
19
+ const network = map[c];
20
+ if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
21
+ return network;
22
+ }
23
+ function $c3f6c693698dc7cd$export$23109f16a8a07245(network) {
24
+ const chain = $c3f6c693698dc7cd$var$getNetwork(network);
25
+ return chain.bip44;
26
+ }
27
+ function $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position) {
28
+ const hdKey = $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic);
29
+ const coin_type = $c3f6c693698dc7cd$export$23109f16a8a07245(network);
30
+ //https://github.com/satoshilabs/slips/blob/master/slip-0044.md
31
+ //Syntax of BIP44
32
+ //m / purpose' / coin_type' / account' / change / address_index
33
+ const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;
34
+ const externalAddress = $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, externalPath);
35
+ //change address
36
+ const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;
37
+ const internalAddress = $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, internalPath);
38
+ return {
39
+ internal: internalAddress,
40
+ external: externalAddress,
41
+ position: position
42
+ };
43
+ }
44
+ function $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic) {
45
+ const chain = $c3f6c693698dc7cd$var$getNetwork(network);
46
+ const seed = $hCgyA$mnemonicToSeedSync(mnemonic).toString("hex");
47
+ //From the seed, get a hdKey, can we use CoinKey instead?
48
+ const hdKey = (0, $hCgyA$hdkey).fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
49
+ return hdKey;
50
+ }
51
+ function $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, path) {
52
+ const chain = $c3f6c693698dc7cd$var$getNetwork(network);
53
+ const derived = hdKey.derive(path);
54
+ var ck2 = new $hCgyA$coinkey(derived.privateKey, chain);
55
+ return {
56
+ address: ck2.publicAddress,
57
+ path: path,
58
+ privateKey: ck2.privateKey.toString("hex"),
59
+ WIF: ck2.privateWif
60
+ };
61
+ }
62
+ function $c3f6c693698dc7cd$export$9f993213e5806bf0() {
63
+ return $hCgyA$generateMnemonic();
64
+ }
65
+ function $c3f6c693698dc7cd$export$2b99b9ff149202f3(mnemonic) {
66
+ //Check all languages
67
+ const wordlists = Object.values($hCgyA$wordlists);
68
+ //If mnemonic is valid in any language, return true, otherwise false
69
+ for (const wordlist of wordlists){
70
+ const v = $hCgyA$validateMnemonic(mnemonic, wordlist);
71
+ if (v === true) return true;
72
+ }
73
+ return false;
74
+ }
75
+ function $c3f6c693698dc7cd$export$f43d70cb4ddd5664(network, privateKeyWIF) {
76
+ const coinKey = $hCgyA$coinkey.fromWif(privateKeyWIF);
77
+ coinKey.versions = $c3f6c693698dc7cd$var$getNetwork(network);
78
+ return {
79
+ address: coinKey.publicAddress,
80
+ privateKey: coinKey.privateKey.toString("hex"),
81
+ WIF: coinKey.privateWif
82
+ };
83
+ }
84
+ const $c3f6c693698dc7cd$export$4becd65eb23312e6 = $hCgyA$entropyToMnemonic;
85
+ function $c3f6c693698dc7cd$export$de190b37be25f71b(network = "xna") {
86
+ const mnemonic = $c3f6c693698dc7cd$export$9f993213e5806bf0();
87
+ const account = 0;
88
+ const position = 0;
89
+ const addressPair = $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position);
90
+ const addressObject = addressPair.external;
91
+ const result = {
92
+ ...addressObject,
93
+ mnemonic: mnemonic,
94
+ network: network
95
+ };
96
+ return result;
97
+ }
98
+ function $c3f6c693698dc7cd$export$e2e336010351d8a8(network = "xna") {
99
+ return $c3f6c693698dc7cd$export$de190b37be25f71b(network);
100
+ }
101
+ var $c3f6c693698dc7cd$export$2e2bcd8739ae039 = {
102
+ entropyToMnemonic: $c3f6c693698dc7cd$export$4becd65eb23312e6,
103
+ generateAddress: $c3f6c693698dc7cd$export$e2e336010351d8a8,
104
+ generateMnemonic: $c3f6c693698dc7cd$export$9f993213e5806bf0,
105
+ getAddressByPath: $c3f6c693698dc7cd$export$6fc951b76952b95e,
106
+ getAddressByWIF: $c3f6c693698dc7cd$export$f43d70cb4ddd5664,
107
+ getAddressPair: $c3f6c693698dc7cd$export$6e3ac79f8c0a2892,
108
+ getCoinType: $c3f6c693698dc7cd$export$23109f16a8a07245,
109
+ getHDKey: $c3f6c693698dc7cd$export$6c78ccde21ad48f6,
110
+ isMnemonicValid: $c3f6c693698dc7cd$export$2b99b9ff149202f3
111
+ };
112
+
113
+
114
+ 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};
115
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA,uCAAuC;;;;;AAgBvC,SAAS,iCAAW,IAAa;IAC/B,MAAM,IAAI,KAAK,WAAW,IAAI,iBAAiB;IAC/C,MAAM,MAAM;QACV,KAAK,CAAA,GAAA,aAAK,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ;QAChC,YAAY,CAAA,GAAA,aAAK,EAAE,GAAG,CAAC,OAAO,EAAE;QAChC,KAAK,CAAA,GAAA,aAAK,E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AAa;QAC1B,MAAM;QACN,YAAY,IAAI,UAAU,CAAC,QAAQ,CAAC;QACpC,KAAK,IAAI,UAAU;IACrB;AACF;AAEO,SAAS;IACd,OAAO;AACT;AAEO,SAAS,0CAAgB,QAAgB;IAC9C,qBAAqB;IACrB,MAAM,YAAY,OAAO,MAAM,CAAC;IAEhC,oEAAoE;IACpE,KAAK,MAAM,YAAY,UAAW;QAChC,MAAM,IAAI,wBAAuB,UAAU;QAC3C,IAAI,MAAM,MACR,OAAO;IAEX;IACA,OAAO;AACT;AAQO,SAAS,0CAAgB,OAAgB,EAAE,aAAqB;IACrE,MAAM,UAAU,eAAQ,OAAO,CAAC;IAChC,QAAQ,QAAQ,GAAG,iCAAW;IAE9B,OAAO;QACL,SAAS,QAAQ,aAAa;QAC9B,YAAY,QAAQ,UAAU,CAAC,QAAQ,CAAC;QACxC,KAAK,QAAQ,UAAU;IACzB;AACF;AAEO,MAAM,4CAAoB;AAE1B,SAAS,0CACd,UAAmB,KAAK;IAExB,MAAM,WAAW;IACjB,MAAM,UAAU;IAChB,MAAM,WAAW;IACjB,MAAM,cAAc,0CAAe,SAAS,UAAU,SAAS;IAC/D,MAAM,gBAAgB,YAAY,QAAQ;IAE1C,MAAM,SAAS;QACb,GAAG,aAAa;kBAChB;iBACA;IACF;IACA,OAAO;AACT;AASO,SAAS,0CAAgB,UAAmB,KAAK;IACtD,OAAO,0CAAsB;AAC/B;IACA,2CAAe;uBACb;qBACA;sBACA;sBACA;qBACA;oBACA;iBACA;cACA;qBACA;AACF","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\" | \"evr\" | \"evr-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 evr: chains.evr.mainnet.versions,\n \"evr-test\": chains.evr.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 */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number\n) {\n const hdKey = getHDKey(network, mnemonic);\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): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic).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): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position);\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"}
@@ -0,0 +1,65 @@
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" | "evr" | "evr-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
+ */
22
+ export function getAddressPair(network: Network, mnemonic: string, account: number, position: number): {
23
+ internal: IAddressObject;
24
+ external: IAddressObject;
25
+ position: number;
26
+ };
27
+ export function getHDKey(network: Network, mnemonic: string): any;
28
+ export function getAddressByPath(network: Network, hdKey: any, path: string): IAddressObject;
29
+ export function generateMnemonic(): string;
30
+ export function isMnemonicValid(mnemonic: string): boolean;
31
+ /**
32
+ *
33
+ * @param privateKeyWIF
34
+ * @param network should be "xna" or "xna-test"
35
+ * @returns object {address, privateKey (hex), WIF}
36
+ */
37
+ export function getAddressByWIF(network: Network, privateKeyWIF: string): {
38
+ address: any;
39
+ privateKey: any;
40
+ WIF: any;
41
+ };
42
+ export const entropyToMnemonic: typeof bip39.entropyToMnemonic;
43
+ export function generateAddressObject(network?: Network): IAddressObject;
44
+ /**
45
+ * Generates a random Address Object
46
+ *
47
+ * @deprecated use generateAddressObject
48
+ * @param network
49
+ * @returns
50
+ */
51
+ export function generateAddress(network?: Network): IAddressObject;
52
+ declare const _default: {
53
+ entropyToMnemonic: typeof bip39.entropyToMnemonic;
54
+ generateAddress: typeof generateAddress;
55
+ generateMnemonic: typeof generateMnemonic;
56
+ getAddressByPath: typeof getAddressByPath;
57
+ getAddressByWIF: typeof getAddressByWIF;
58
+ getAddressPair: typeof getAddressPair;
59
+ getCoinType: typeof getCoinType;
60
+ getHDKey: typeof getHDKey;
61
+ isMnemonicValid: typeof isMnemonicValid;
62
+ };
63
+ export default _default;
64
+
65
+ //# 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,GAAG,KAAK,GAAG,UAAU,CAAC;AAiB9D;;;;GAIG;AACH,4BAA4B,OAAO,EAAE,OAAO,OAG3C;AACD;;;;;GAKG;AACH,+BACE,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM;;;;EAoBjB;AAED,yBAAyB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,CAMhE;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,GACvB,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\" | \"evr\" | \"evr-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 evr: chains.evr.mainnet.versions,\n \"evr-test\": chains.evr.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 */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number\n) {\n const hdKey = getHDKey(network, mnemonic);\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): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic).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): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position);\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-key",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
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": "Raven Rebels / Dick Henrik Larsson",
23
+ "author": "Neuraiproject",
24
24
  "license": "MIT",
25
25
  "bugs": {
26
26
  "url": "https://github.com/neuraiproject/neurai-key/issues"