@neuraiproject/neurai-key 2.8.6 → 2.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,4 +1,3 @@
1
- var $g5Y9E$hyperbitjschains = require("@hyperbitjs/chains");
2
1
  var $g5Y9E$bip39 = require("bip39");
3
2
  var $g5Y9E$crypto = require("crypto");
4
3
  var $g5Y9E$coinkey = require("coinkey");
@@ -30,6 +29,167 @@ $parcel$export(module.exports, "publicKeyToAddress", () => $80bd448eb6ea085b$exp
30
29
  $parcel$export(module.exports, "generateAddress", () => $80bd448eb6ea085b$export$e2e336010351d8a8);
31
30
  $parcel$export(module.exports, "default", () => $80bd448eb6ea085b$export$2e2bcd8739ae039);
32
31
  //Gives us meta data about coins/chains
32
+ var $af3d93861d966625$exports = {};
33
+ /**
34
+ * Neurai (XNA) chain configuration data
35
+ * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai
36
+ */ const $af3d93861d966625$var$xna = {
37
+ mainnet: {
38
+ name: "Neurai",
39
+ unit: "XNA",
40
+ symbol: "xna",
41
+ decimalPlaces: 100000000,
42
+ messagePrefix: "Neurai Signed Message:\n",
43
+ confirmations: 6,
44
+ website: "https://neurai.org/",
45
+ projectUrl: "https://github.com/NeuraiProject",
46
+ id: "94C49B3B-2C88-4408-B566-3D277C596778",
47
+ network: "mainnet",
48
+ hashGenesisBlock: "00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806",
49
+ port: 19000,
50
+ portRpc: 19001,
51
+ protocol: {
52
+ magic: 1381320014
53
+ },
54
+ seedsDns: [
55
+ "seed1.neurai.org",
56
+ "seed2.neurai.org",
57
+ "neurai-ipv4.neuraiexplorer.com"
58
+ ],
59
+ versions: {
60
+ bip32: {
61
+ private: 76066276,
62
+ public: 76067358
63
+ },
64
+ bip44: 1900,
65
+ private: 128,
66
+ public: 53,
67
+ scripthash: 117
68
+ }
69
+ },
70
+ testnet: {
71
+ name: "Neurai",
72
+ unit: "XNA",
73
+ symbol: "xna",
74
+ decimalPlaces: 100000000,
75
+ messagePrefix: "Neurai Signed Message:\n",
76
+ confirmations: 6,
77
+ website: "https://neurai.org/",
78
+ projectUrl: "https://github.com/NeuraiProject",
79
+ id: "1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6",
80
+ network: "testnet",
81
+ hashGenesisBlock: "0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf",
82
+ port: 19100,
83
+ portRpc: 19101,
84
+ protocol: {
85
+ magic: 1313166674
86
+ },
87
+ seedsDns: [
88
+ "testnet1.neuracrypt.org",
89
+ "testnet2.neuracrypt.org",
90
+ "testnet3.neuracrypt.org"
91
+ ],
92
+ versions: {
93
+ bip32: {
94
+ private: 70615956,
95
+ public: 70617039
96
+ },
97
+ bip44: 1,
98
+ private: 239,
99
+ public: 127,
100
+ scripthash: 196
101
+ }
102
+ }
103
+ };
104
+ const $af3d93861d966625$var$chains = {
105
+ xna: $af3d93861d966625$var$xna
106
+ };
107
+ $af3d93861d966625$exports = {
108
+ xna: $af3d93861d966625$var$xna,
109
+ chains: $af3d93861d966625$var$chains
110
+ };
111
+
112
+
113
+ var $f755b72afc69c754$exports = {};
114
+ /**
115
+ * Neurai Legacy (XNA-LEGACY) chain configuration data
116
+ * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai Legacy
117
+ */ const $f755b72afc69c754$var$xnaLegacy = {
118
+ mainnet: {
119
+ name: "Neurai",
120
+ unit: "XNA",
121
+ symbol: "xna",
122
+ decimalPlaces: 100000000,
123
+ messagePrefix: "Neurai Signed Message:\n",
124
+ confirmations: 6,
125
+ website: "https://neurai.org/",
126
+ projectUrl: "https://github.com/NeuraiProject",
127
+ id: "94C49B3B-2C88-4408-B566-3D277C596778",
128
+ network: "mainnet",
129
+ hashGenesisBlock: "00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806",
130
+ port: 19000,
131
+ portRpc: 19001,
132
+ protocol: {
133
+ magic: 1381320014
134
+ },
135
+ seedsDns: [
136
+ "seed1.neurai.org",
137
+ "seed2.neurai.org",
138
+ "neurai-ipv4.neuraiexplorer.com"
139
+ ],
140
+ versions: {
141
+ bip32: {
142
+ private: 76066276,
143
+ public: 76067358
144
+ },
145
+ bip44: 0,
146
+ private: 128,
147
+ public: 53,
148
+ scripthash: 117
149
+ }
150
+ },
151
+ testnet: {
152
+ name: "Neurai",
153
+ unit: "XNA",
154
+ symbol: "xna",
155
+ decimalPlaces: 100000000,
156
+ messagePrefix: "Neurai Signed Message:\n",
157
+ confirmations: 6,
158
+ website: "https://neurai.org/",
159
+ projectUrl: "https://github.com/NeuraiProject",
160
+ id: "1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6",
161
+ network: "testnet",
162
+ hashGenesisBlock: "0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf",
163
+ port: 19100,
164
+ portRpc: 19101,
165
+ protocol: {
166
+ magic: 1313166674
167
+ },
168
+ seedsDns: [
169
+ "testnet1.neuracrypt.org",
170
+ "testnet2.neuracrypt.org",
171
+ "testnet3.neuracrypt.org"
172
+ ],
173
+ versions: {
174
+ bip32: {
175
+ private: 70615956,
176
+ public: 70617039
177
+ },
178
+ bip44: 1,
179
+ private: 239,
180
+ public: 127,
181
+ scripthash: 196
182
+ }
183
+ }
184
+ };
185
+ const $f755b72afc69c754$var$chains = {
186
+ "xna-legacy": $f755b72afc69c754$var$xnaLegacy
187
+ };
188
+ $f755b72afc69c754$exports = {
189
+ xnaLegacy: $f755b72afc69c754$var$xnaLegacy,
190
+ chains: $f755b72afc69c754$var$chains
191
+ };
192
+
33
193
 
34
194
 
35
195
 
@@ -38,10 +198,13 @@ $parcel$export(module.exports, "default", () => $80bd448eb6ea085b$export$2e2bcd8
38
198
 
39
199
  function $80bd448eb6ea085b$var$getNetwork(name) {
40
200
  const c = name.toLowerCase(); //Just to be sure
41
- const chainData = (0, $g5Y9E$hyperbitjschains.chains);
201
+ const chainData = (0, $af3d93861d966625$exports.chains);
202
+ const legacyChainData = (0, $f755b72afc69c754$exports.chains);
42
203
  const map = {
43
204
  xna: chainData.xna.mainnet.versions,
44
- "xna-test": chainData.xna.testnet?.versions
205
+ "xna-test": chainData.xna.testnet?.versions,
206
+ "xna-legacy": legacyChainData["xna-legacy"].mainnet.versions,
207
+ "xna-legacy-test": legacyChainData["xna-legacy"].testnet?.versions
45
208
  };
46
209
  const network = map[c];
47
210
  if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuC;;;;;;;AAiBvC,SAAS,iCAAW,IAAa;IAC/B,MAAM,IAAI,KAAK,WAAW,IAAe,iBAAiB;IAC1D,MAAM,YAAY,CAAA,GAAA,8BAAK;IACvB,MAAM,MAA4B;QAChC,KAAK,UAAU,GAAG,CAAC,OAAO,CAAC,QAAQ;QACnC,YAAY,UAAU,GAAG,CAAC,OAAO,EAAE;IACrC;IAEA,MAAM,UAAU,GAAG,CAAC,EAAE;IACtB,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8BAA8B,OAAO,IAAI,CAAC,KAAK,QAAQ;IAEzE,OAAO;AACT;AAMO,SAAS,0CAAY,OAAgB;IAC1C,MAAM,QAAQ,iCAAW;IACzB,OAAO,MAAM,KAAK;AACpB;AAQO,SAAS,0CACd,OAAgB,EAChB,QAAgB,EAChB,OAAe,EACf,QAAgB,EAChB,aAAqB,EAAE;IAEvB,MAAM,QAAQ,0CAAS,SAAS,UAAU;IAC1C,MAAM,YAAY,0CAAY;IAE9B,+DAA+D;IAE/D,iBAAiB;IACjB,+DAA+D;IAC/D,MAAM,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,QAAQ,IAAI,EAAE,UAAU;IACpE,MAAM,kBAAkB,0CAAiB,SAAS,OAAO;IAEzD,gBAAgB;IAChB,MAAM,eAAe,CAA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E,MAAM,UAAU,eAAQ,OAAO,CAAC;IAChC,QAAQ,QAAQ,GAAG,iCAAW;IAE9B,OAAO,QAAQ,SAAS,CAAC,QAAQ,CAAC;AACpC;AAEO,MAAM,4CAAoB;AAE1B,SAAS,0CACd,UAAmB,KAAK,EACxB,aAAqB,EAAE;IAEvB,MAAM,WAAW;IACjB,MAAM,UAAU;IAChB,MAAM,WAAW;IACjB,MAAM,cAAc,0CAAe,SAAS,UAAU,SAAS,UAAU;IACzE,MAAM,gBAAgB,YAAY,QAAQ;IAE1C,MAAM,SAAS;QACb,GAAG,aAAa;kBAChB;iBACA;IACF;IACA,OAAO;AACT;AAEO,SAAS,0CACd,OAAgB,EAChB,SAA0B;IAE1B,MAAM,QAAQ,iCAAW;IACzB,MAAM,YAAY,OAAO,QAAQ,CAAC,aAC9B,YACA,OAAO,IAAI,CAAC,WAAW;IAE3B,IAAI,UAAU,MAAM,KAAK,MAAM,UAAU,MAAM,KAAK,IAClD,MAAM,IAAI,MAAM;IAGlB,MAAM,aAAa,CAAA,GAAA,wBAAS,EAAE,UAAU,MAAM,CAAC,WAAW,MAAM;IAChE,MAAM,gBAAgB,CAAA,GAAA,wBAAS,EAAE,aAAa,MAAM,CAAC,YAAY,MAAM;IACvE,MAAM,UAAU,OAAO,MAAM,CAAC;QAC5B,OAAO,IAAI,CAAC;YAAC,MAAM,MAAM;SAAC;QAC1B;KACD;IAED,OAAO,wBAAiB;AAC1B;AASO,SAAS,0CAAgB,UAAmB,KAAK;IACtD,OAAO,0CAAsB;AAC/B;IACA,2CAAe;uBACb;qBACA;sBACA;sBACA;qBACA;oBACA;oBACA;iBACA;cACA;qBACA;wBACA;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\nimport { createHash } from \"crypto\";\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\nconst HDKey = require(\"hdkey\");\nimport { IAddressObject } from \"./types\";\nconst bs58check = require(\"bs58check\");\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() as Network; //Just to be sure\n const chainData = chains as any;\n const map: Record<Network, any> = {\n xna: chainData.xna.mainnet.versions,\n \"xna-test\": chainData.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 publicKey: ck2.publicKey.toString(\"hex\"),\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\n/**\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns the compressed public key as a hex string\n */\nexport function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return coinKey.publicKey.toString(\"hex\");\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\nexport function publicKeyToAddress(\n network: Network,\n publicKey: Buffer | string\n): string {\n const chain = getNetwork(network);\n const keyBuffer = Buffer.isBuffer(publicKey)\n ? publicKey\n : Buffer.from(publicKey, \"hex\");\n\n if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {\n throw new Error(\"Public key must be 33 or 65 bytes\");\n }\n\n const sha256Hash = createHash(\"sha256\").update(keyBuffer).digest();\n const ripemd160Hash = createHash(\"ripemd160\").update(sha256Hash).digest();\n const payload = Buffer.concat([\n Buffer.from([chain.public]),\n ripemd160Hash,\n ]);\n\n return bs58check.encode(payload);\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 getPubkeyByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuC;;ACAvC;;;CAGC,GAED,MAAM,4BAAM;IACV,SAAS;QACP,MAAM;QACN,MAAM;QACN,QAAQ;QACR,eAAe;QACf,eAAe;QACf,eAAe;QACf,SAAS;QACT,YAAY;QACZ,IAAI;QACJ,SAAS;QACT,kBAAkB;QAClB,MAAM;QACN,SAAS;QACT,UAAU;YACR,OAAO;QACT;QACA,UAAU;YACR;YACA;YACA;SACD;QACD,UAAU;YACR,OAAO;gBACL,SAAS;gBACT,QAAQ;YACV;YACA,OAAO;YACP,SAAS;YACT,QAAQ;YACR,YAAY;QACd;IACF;IACA,SAAS;QACP,MAAM;QACN,MAAM;QACN,QAAQ;QACR,eAAe;QACf,eAAe;QACf,eAAe;QACf,SAAS;QACT,YAAY;QACZ,IAAI;QACJ,SAAS;QACT,kBAAkB;QAClB,MAAM;QACN,SAAS;QACT,UAAU;YACR,OAAO;QACT;QACA,UAAU;YACR;YACA;YACA;SACD;QACD,UAAU;YACR,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,IAAI,MAAM;IAGlB,MAAM,aAAa,CAAA,GAAA,wBAAS,EAAE,UAAU,MAAM,CAAC,WAAW,MAAM;IAChE,MAAM,gBAAgB,CAAA,GAAA,wBAAS,EAAE,aAAa,MAAM,CAAC,YAAY,MAAM;IACvE,MAAM,UAAU,OAAO,MAAM,CAAC;QAC5B,OAAO,IAAI,CAAC;YAAC,MAAM,MAAM;SAAC;QAC1B;KACD;IAED,OAAO,wBAAiB;AAC1B;AASO,SAAS,0CAAgB,UAAmB,KAAK;IACtD,OAAO,0CAAsB;AAC/B;IACA,2CAAe;uBACb;qBACA;sBACA;sBACA;qBACA;oBACA;oBACA;iBACA;cACA;qBACA;wBACA;AACF","sources":["index.ts","coins/xna.js","coins/xna-legacy.js"],"sourcesContent":["//Gives us meta data about coins/chains\nimport { chains } from \"./coins/xna.js\";\nimport { chains as legacyChains } from \"./coins/xna-legacy.js\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nimport { createHash } from \"crypto\";\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\nconst HDKey = require(\"hdkey\");\nimport { IAddressObject } from \"./types\";\nconst bs58check = require(\"bs58check\");\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\" | \"xna-legacy\" | \"xna-legacy-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase() as Network; //Just to be sure\n const chainData = chains as any;\n const legacyChainData = legacyChains as any;\n const map: Record<Network, any> = {\n xna: chainData.xna.mainnet.versions,\n \"xna-test\": chainData.xna.testnet?.versions,\n \"xna-legacy\": legacyChainData[\"xna-legacy\"].mainnet.versions,\n \"xna-legacy-test\": legacyChainData[\"xna-legacy\"].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 publicKey: ck2.publicKey.toString(\"hex\"),\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\n/**\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns the compressed public key as a hex string\n */\nexport function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return coinKey.publicKey.toString(\"hex\");\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\nexport function publicKeyToAddress(\n network: Network,\n publicKey: Buffer | string\n): string {\n const chain = getNetwork(network);\n const keyBuffer = Buffer.isBuffer(publicKey)\n ? publicKey\n : Buffer.from(publicKey, \"hex\");\n\n if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {\n throw new Error(\"Public key must be 33 or 65 bytes\");\n }\n\n const sha256Hash = createHash(\"sha256\").update(keyBuffer).digest();\n const ripemd160Hash = createHash(\"ripemd160\").update(sha256Hash).digest();\n const payload = Buffer.concat([\n Buffer.from([chain.public]),\n ripemd160Hash,\n ]);\n\n return bs58check.encode(payload);\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 getPubkeyByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n","/**\n * Neurai (XNA) chain configuration data\n * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai\n */\n\nconst xna = {\n mainnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"94C49B3B-2C88-4408-B566-3D277C596778\",\n network: \"mainnet\",\n hashGenesisBlock: \"00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806\",\n port: 19000,\n portRpc: 19001,\n protocol: {\n magic: 1381320014\n },\n seedsDns: [\n \"seed1.neurai.org\",\n \"seed2.neurai.org\",\n \"neurai-ipv4.neuraiexplorer.com\"\n ],\n versions: {\n bip32: {\n private: 76066276,\n public: 76067358\n },\n bip44: 1900,\n private: 128,\n public: 53,\n scripthash: 117\n }\n },\n testnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6\",\n network: \"testnet\",\n hashGenesisBlock: \"0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf\",\n port: 19100,\n portRpc: 19101,\n protocol: {\n magic: 1313166674\n },\n seedsDns: [\n \"testnet1.neuracrypt.org\",\n \"testnet2.neuracrypt.org\",\n \"testnet3.neuracrypt.org\"\n ],\n versions: {\n bip32: {\n private: 70615956,\n public: 70617039\n },\n bip44: 1,\n private: 239,\n public: 127,\n scripthash: 196\n }\n }\n};\n\nconst chains = {\n xna\n};\n\nmodule.exports = {\n xna,\n chains\n};\n","/**\n * Neurai Legacy (XNA-LEGACY) chain configuration data\n * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai Legacy\n */\n\nconst xnaLegacy = {\n mainnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"94C49B3B-2C88-4408-B566-3D277C596778\",\n network: \"mainnet\",\n hashGenesisBlock: \"00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806\",\n port: 19000,\n portRpc: 19001,\n protocol: {\n magic: 1381320014\n },\n seedsDns: [\n \"seed1.neurai.org\",\n \"seed2.neurai.org\",\n \"neurai-ipv4.neuraiexplorer.com\"\n ],\n versions: {\n bip32: {\n private: 76066276,\n public: 76067358\n },\n bip44: 0,\n private: 128,\n public: 53,\n scripthash: 117\n }\n },\n testnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6\",\n network: \"testnet\",\n hashGenesisBlock: \"0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf\",\n port: 19100,\n portRpc: 19101,\n protocol: {\n magic: 1313166674\n },\n seedsDns: [\n \"testnet1.neuracrypt.org\",\n \"testnet2.neuracrypt.org\",\n \"testnet3.neuracrypt.org\"\n ],\n versions: {\n bip32: {\n private: 70615956,\n public: 70617039\n },\n bip44: 1,\n private: 239,\n public: 127,\n scripthash: 196\n }\n }\n};\n\nconst chains = {\n \"xna-legacy\": xnaLegacy\n};\n\nmodule.exports = {\n xnaLegacy,\n chains\n};\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,3 @@
1
- import {chains as $hCgyA$chains} from "@hyperbitjs/chains";
2
1
  import {mnemonicToSeedSync as $hCgyA$mnemonicToSeedSync, generateMnemonic as $hCgyA$generateMnemonic, wordlists as $hCgyA$wordlists, validateMnemonic as $hCgyA$validateMnemonic, entropyToMnemonic as $hCgyA$entropyToMnemonic} from "bip39";
3
2
  import {createHash as $hCgyA$createHash} from "crypto";
4
3
  import * as $hCgyA$coinkey from "coinkey";
@@ -6,6 +5,167 @@ import {fromMasterSeed as $hCgyA$fromMasterSeed} from "hdkey";
6
5
  import {encode as $hCgyA$encode} from "bs58check";
7
6
 
8
7
  //Gives us meta data about coins/chains
8
+ var $0d42a025c13759a0$exports = {};
9
+ /**
10
+ * Neurai (XNA) chain configuration data
11
+ * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai
12
+ */ const $0d42a025c13759a0$var$xna = {
13
+ mainnet: {
14
+ name: "Neurai",
15
+ unit: "XNA",
16
+ symbol: "xna",
17
+ decimalPlaces: 100000000,
18
+ messagePrefix: "Neurai Signed Message:\n",
19
+ confirmations: 6,
20
+ website: "https://neurai.org/",
21
+ projectUrl: "https://github.com/NeuraiProject",
22
+ id: "94C49B3B-2C88-4408-B566-3D277C596778",
23
+ network: "mainnet",
24
+ hashGenesisBlock: "00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806",
25
+ port: 19000,
26
+ portRpc: 19001,
27
+ protocol: {
28
+ magic: 1381320014
29
+ },
30
+ seedsDns: [
31
+ "seed1.neurai.org",
32
+ "seed2.neurai.org",
33
+ "neurai-ipv4.neuraiexplorer.com"
34
+ ],
35
+ versions: {
36
+ bip32: {
37
+ private: 76066276,
38
+ public: 76067358
39
+ },
40
+ bip44: 1900,
41
+ private: 128,
42
+ public: 53,
43
+ scripthash: 117
44
+ }
45
+ },
46
+ testnet: {
47
+ name: "Neurai",
48
+ unit: "XNA",
49
+ symbol: "xna",
50
+ decimalPlaces: 100000000,
51
+ messagePrefix: "Neurai Signed Message:\n",
52
+ confirmations: 6,
53
+ website: "https://neurai.org/",
54
+ projectUrl: "https://github.com/NeuraiProject",
55
+ id: "1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6",
56
+ network: "testnet",
57
+ hashGenesisBlock: "0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf",
58
+ port: 19100,
59
+ portRpc: 19101,
60
+ protocol: {
61
+ magic: 1313166674
62
+ },
63
+ seedsDns: [
64
+ "testnet1.neuracrypt.org",
65
+ "testnet2.neuracrypt.org",
66
+ "testnet3.neuracrypt.org"
67
+ ],
68
+ versions: {
69
+ bip32: {
70
+ private: 70615956,
71
+ public: 70617039
72
+ },
73
+ bip44: 1,
74
+ private: 239,
75
+ public: 127,
76
+ scripthash: 196
77
+ }
78
+ }
79
+ };
80
+ const $0d42a025c13759a0$var$chains = {
81
+ xna: $0d42a025c13759a0$var$xna
82
+ };
83
+ $0d42a025c13759a0$exports = {
84
+ xna: $0d42a025c13759a0$var$xna,
85
+ chains: $0d42a025c13759a0$var$chains
86
+ };
87
+
88
+
89
+ var $4f57ad7a71fd71ab$exports = {};
90
+ /**
91
+ * Neurai Legacy (XNA-LEGACY) chain configuration data
92
+ * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai Legacy
93
+ */ const $4f57ad7a71fd71ab$var$xnaLegacy = {
94
+ mainnet: {
95
+ name: "Neurai",
96
+ unit: "XNA",
97
+ symbol: "xna",
98
+ decimalPlaces: 100000000,
99
+ messagePrefix: "Neurai Signed Message:\n",
100
+ confirmations: 6,
101
+ website: "https://neurai.org/",
102
+ projectUrl: "https://github.com/NeuraiProject",
103
+ id: "94C49B3B-2C88-4408-B566-3D277C596778",
104
+ network: "mainnet",
105
+ hashGenesisBlock: "00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806",
106
+ port: 19000,
107
+ portRpc: 19001,
108
+ protocol: {
109
+ magic: 1381320014
110
+ },
111
+ seedsDns: [
112
+ "seed1.neurai.org",
113
+ "seed2.neurai.org",
114
+ "neurai-ipv4.neuraiexplorer.com"
115
+ ],
116
+ versions: {
117
+ bip32: {
118
+ private: 76066276,
119
+ public: 76067358
120
+ },
121
+ bip44: 0,
122
+ private: 128,
123
+ public: 53,
124
+ scripthash: 117
125
+ }
126
+ },
127
+ testnet: {
128
+ name: "Neurai",
129
+ unit: "XNA",
130
+ symbol: "xna",
131
+ decimalPlaces: 100000000,
132
+ messagePrefix: "Neurai Signed Message:\n",
133
+ confirmations: 6,
134
+ website: "https://neurai.org/",
135
+ projectUrl: "https://github.com/NeuraiProject",
136
+ id: "1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6",
137
+ network: "testnet",
138
+ hashGenesisBlock: "0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf",
139
+ port: 19100,
140
+ portRpc: 19101,
141
+ protocol: {
142
+ magic: 1313166674
143
+ },
144
+ seedsDns: [
145
+ "testnet1.neuracrypt.org",
146
+ "testnet2.neuracrypt.org",
147
+ "testnet3.neuracrypt.org"
148
+ ],
149
+ versions: {
150
+ bip32: {
151
+ private: 70615956,
152
+ public: 70617039
153
+ },
154
+ bip44: 1,
155
+ private: 239,
156
+ public: 127,
157
+ scripthash: 196
158
+ }
159
+ }
160
+ };
161
+ const $4f57ad7a71fd71ab$var$chains = {
162
+ "xna-legacy": $4f57ad7a71fd71ab$var$xnaLegacy
163
+ };
164
+ $4f57ad7a71fd71ab$exports = {
165
+ xnaLegacy: $4f57ad7a71fd71ab$var$xnaLegacy,
166
+ chains: $4f57ad7a71fd71ab$var$chains
167
+ };
168
+
9
169
 
10
170
 
11
171
 
@@ -14,10 +174,13 @@ import {encode as $hCgyA$encode} from "bs58check";
14
174
 
15
175
  function $c3f6c693698dc7cd$var$getNetwork(name) {
16
176
  const c = name.toLowerCase(); //Just to be sure
17
- const chainData = (0, $hCgyA$chains);
177
+ const chainData = (0, $0d42a025c13759a0$exports.chains);
178
+ const legacyChainData = (0, $4f57ad7a71fd71ab$exports.chains);
18
179
  const map = {
19
180
  xna: chainData.xna.mainnet.versions,
20
- "xna-test": chainData.xna.testnet?.versions
181
+ "xna-test": chainData.xna.testnet?.versions,
182
+ "xna-legacy": legacyChainData["xna-legacy"].mainnet.versions,
183
+ "xna-legacy-test": legacyChainData["xna-legacy"].testnet?.versions
21
184
  };
22
185
  const network = map[c];
23
186
  if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA,uCAAuC;;;;;;;AAiBvC,SAAS,iCAAW,IAAa;IAC/B,MAAM,IAAI,KAAK,WAAW,IAAe,iBAAiB;IAC1D,MAAM,YAAY,CAAA,GAAA,aAAK;IACvB,MAAM,MAA4B;QAChC,KAAK,UAAU,GAAG,CAAC,OAAO,CAAC,QAAQ;QACnC,YAAY,UAAU,GAAG,CAAC,OAAO,EAAE;IACrC;IAEA,MAAM,UAAU,GAAG,CAAC,EAAE;IACtB,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8BAA8B,OAAO,IAAI,CAAC,KAAK,QAAQ;IAEzE,OAAO;AACT;AAMO,SAAS,0CAAY,OAAgB;IAC1C,MAAM,QAAQ,iCAAW;IACzB,OAAO,MAAM,KAAK;AACpB;AAQO,SAAS,0CACd,OAAgB,EAChB,QAAgB,EAChB,OAAe,EACf,QAAgB,EAChB,aAAqB,EAAE;IAEvB,MAAM,QAAQ,0CAAS,SAAS,UAAU;IAC1C,MAAM,YAAY,0CAAY;IAE9B,+DAA+D;IAE/D,iBAAiB;IACjB,+DAA+D;IAC/D,MAAM,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,QAAQ,IAAI,EAAE,UAAU;IACpE,MAAM,kBAAkB,0CAAiB,SAAS,OAAO;IAEzD,gBAAgB;IAChB,MAAM,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,QAAQ,IAAI,EAAE,UAAU;IACpE,MAAM,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E9B,OAAO,QAAQ,SAAS,CAAC,QAAQ,CAAC;AACpC;AAEO,MAAM,4CAAoB;AAE1B,SAAS,0CACd,UAAmB,KAAK,EACxB,aAAqB,EAAE;IAEvB,MAAM,WAAW;IACjB,MAAM,UAAU;IAChB,MAAM,WAAW;IACjB,MAAM,cAAc,0CAAe,SAAS,UAAU,SAAS,UAAU;IACzE,MAAM,gBAAgB,YAAY,QAAQ;IAE1C,MAAM,SAAS;QACb,GAAG,aAAa;kBAChB;iBACA;IACF;IACA,OAAO;AACT;AAEO,SAAS,0CACd,OAAgB,EAChB,SAA0B;IAE1B,MAAM,QAAQ,iCAAW;IACzB,MAAM,YAAY,OAAO,QAAQ,CAAC,aAC9B,YACA,OAAO,IAAI,CAAC,WAAW;IAE3B,IAAI,UAAU,MAAM,KAAK,MAAM,UAAU,MAAM,KAAK,IAClD,MAAM,IAAI,MAAM;IAGlB,MAAM,aAAa,CAAA,GAAA,iBAAS,EAAE,UAAU,MAAM,CAAC,WAAW,MAAM;IAChE,MAAM,gBAAgB,CAAA,GAAA,iBAAS,EAAE,aAAa,MAAM,CAAC,YAAY,MAAM;IACvE,MAAM,UAAU,OAAO,MAAM,CAAC;QAC5B,OAAO,IAAI,CAAC;YAAC,MAAM,MAAM;SAAC;QAC1B;KACD;IAED,OAAO,cAAiB;AAC1B;AASO,SAAS,0CAAgB,UAAmB,KAAK;IACtD,OAAO,0CAAsB;AAC/B;IACA,2CAAe;uBACb;qBACA;sBACA;sBACA;qBACA;oBACA;oBACA;iBACA;cACA;qBACA;wBACA;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\nimport { createHash } from \"crypto\";\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\nconst HDKey = require(\"hdkey\");\nimport { IAddressObject } from \"./types\";\nconst bs58check = require(\"bs58check\");\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() as Network; //Just to be sure\n const chainData = chains as any;\n const map: Record<Network, any> = {\n xna: chainData.xna.mainnet.versions,\n \"xna-test\": chainData.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 publicKey: ck2.publicKey.toString(\"hex\"),\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\n/**\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns the compressed public key as a hex string\n */\nexport function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return coinKey.publicKey.toString(\"hex\");\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\nexport function publicKeyToAddress(\n network: Network,\n publicKey: Buffer | string\n): string {\n const chain = getNetwork(network);\n const keyBuffer = Buffer.isBuffer(publicKey)\n ? publicKey\n : Buffer.from(publicKey, \"hex\");\n\n if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {\n throw new Error(\"Public key must be 33 or 65 bytes\");\n }\n\n const sha256Hash = createHash(\"sha256\").update(keyBuffer).digest();\n const ripemd160Hash = createHash(\"ripemd160\").update(sha256Hash).digest();\n const payload = Buffer.concat([\n Buffer.from([chain.public]),\n ripemd160Hash,\n ]);\n\n return bs58check.encode(payload);\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 getPubkeyByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;AAAA,uCAAuC;;ACAvC;;;CAGC,GAED,MAAM,4BAAM;IACV,SAAS;QACP,MAAM;QACN,MAAM;QACN,QAAQ;QACR,eAAe;QACf,eAAe;QACf,eAAe;QACf,SAAS;QACT,YAAY;QACZ,IAAI;QACJ,SAAS;QACT,kBAAkB;QAClB,MAAM;QACN,SAAS;QACT,UAAU;YACR,OAAO;QACT;QACA,UAAU;YACR;YACA;YACA;SACD;QACD,UAAU;YACR,OAAO;gBACL,SAAS;gBACT,QAAQ;YACV;YACA,OAAO;YACP,SAAS;YACT,QAAQ;YACR,YAAY;QACd;IACF;IACA,SAAS;QACP,MAAM;QACN,MAAM;QACN,QAAQ;QACR,eAAe;QACf,eAAe;QACf,eAAe;QACf,SAAS;QACT,YAAY;QACZ,IAAI;QACJ,SAAS;QACT,kBAAkB;QAClB,MAAM;QACN,SAAS;QACT,UAAU;YACR,OAAO;QACT;QACA,UAAU;YACR;YACA;YACA;SACD;QACD,UAAU;YACR,OAAO;gBACL,SAAS;gBACT,QAAQ;YACV;YACA,OAAO;YACP,SAAS;YACT,QAAQ;YACR,YAAY;QACd;IACF;AACF;AAEA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gBAAgB,CAAA,GAAA,iBAAS,EAAE,aAAa,MAAM,CAAC,YAAY,MAAM;IACvE,MAAM,UAAU,OAAO,MAAM,CAAC;QAC5B,OAAO,IAAI,CAAC;YAAC,MAAM,MAAM;SAAC;QAC1B;KACD;IAED,OAAO,cAAiB;AAC1B;AASO,SAAS,0CAAgB,UAAmB,KAAK;IACtD,OAAO,0CAAsB;AAC/B;IACA,2CAAe;uBACb;qBACA;sBACA;sBACA;qBACA;oBACA;oBACA;iBACA;cACA;qBACA;wBACA;AACF","sources":["index.ts","coins/xna.js","coins/xna-legacy.js"],"sourcesContent":["//Gives us meta data about coins/chains\nimport { chains } from \"./coins/xna.js\";\nimport { chains as legacyChains } from \"./coins/xna-legacy.js\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nimport { createHash } from \"crypto\";\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\nconst HDKey = require(\"hdkey\");\nimport { IAddressObject } from \"./types\";\nconst bs58check = require(\"bs58check\");\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\" | \"xna-legacy\" | \"xna-legacy-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase() as Network; //Just to be sure\n const chainData = chains as any;\n const legacyChainData = legacyChains as any;\n const map: Record<Network, any> = {\n xna: chainData.xna.mainnet.versions,\n \"xna-test\": chainData.xna.testnet?.versions,\n \"xna-legacy\": legacyChainData[\"xna-legacy\"].mainnet.versions,\n \"xna-legacy-test\": legacyChainData[\"xna-legacy\"].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 publicKey: ck2.publicKey.toString(\"hex\"),\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\n/**\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns the compressed public key as a hex string\n */\nexport function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return coinKey.publicKey.toString(\"hex\");\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\nexport function publicKeyToAddress(\n network: Network,\n publicKey: Buffer | string\n): string {\n const chain = getNetwork(network);\n const keyBuffer = Buffer.isBuffer(publicKey)\n ? publicKey\n : Buffer.from(publicKey, \"hex\");\n\n if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {\n throw new Error(\"Public key must be 33 or 65 bytes\");\n }\n\n const sha256Hash = createHash(\"sha256\").update(keyBuffer).digest();\n const ripemd160Hash = createHash(\"ripemd160\").update(sha256Hash).digest();\n const payload = Buffer.concat([\n Buffer.from([chain.public]),\n ripemd160Hash,\n ]);\n\n return bs58check.encode(payload);\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 getPubkeyByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n","/**\n * Neurai (XNA) chain configuration data\n * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai\n */\n\nconst xna = {\n mainnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"94C49B3B-2C88-4408-B566-3D277C596778\",\n network: \"mainnet\",\n hashGenesisBlock: \"00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806\",\n port: 19000,\n portRpc: 19001,\n protocol: {\n magic: 1381320014\n },\n seedsDns: [\n \"seed1.neurai.org\",\n \"seed2.neurai.org\",\n \"neurai-ipv4.neuraiexplorer.com\"\n ],\n versions: {\n bip32: {\n private: 76066276,\n public: 76067358\n },\n bip44: 1900,\n private: 128,\n public: 53,\n scripthash: 117\n }\n },\n testnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6\",\n network: \"testnet\",\n hashGenesisBlock: \"0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf\",\n port: 19100,\n portRpc: 19101,\n protocol: {\n magic: 1313166674\n },\n seedsDns: [\n \"testnet1.neuracrypt.org\",\n \"testnet2.neuracrypt.org\",\n \"testnet3.neuracrypt.org\"\n ],\n versions: {\n bip32: {\n private: 70615956,\n public: 70617039\n },\n bip44: 1,\n private: 239,\n public: 127,\n scripthash: 196\n }\n }\n};\n\nconst chains = {\n xna\n};\n\nmodule.exports = {\n xna,\n chains\n};\n","/**\n * Neurai Legacy (XNA-LEGACY) chain configuration data\n * This replaces the dependency on @hyperbitjs/chains with only the data needed for Neurai Legacy\n */\n\nconst xnaLegacy = {\n mainnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"94C49B3B-2C88-4408-B566-3D277C596778\",\n network: \"mainnet\",\n hashGenesisBlock: \"00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806\",\n port: 19000,\n portRpc: 19001,\n protocol: {\n magic: 1381320014\n },\n seedsDns: [\n \"seed1.neurai.org\",\n \"seed2.neurai.org\",\n \"neurai-ipv4.neuraiexplorer.com\"\n ],\n versions: {\n bip32: {\n private: 76066276,\n public: 76067358\n },\n bip44: 0,\n private: 128,\n public: 53,\n scripthash: 117\n }\n },\n testnet: {\n name: \"Neurai\",\n unit: \"XNA\",\n symbol: \"xna\",\n decimalPlaces: 100000000,\n messagePrefix: \"Neurai Signed Message:\\n\",\n confirmations: 6,\n website: \"https://neurai.org/\",\n projectUrl: \"https://github.com/NeuraiProject\",\n id: \"1EB2ACBA-E8E0-4970-BB20-37DA4B70F6A6\",\n network: \"testnet\",\n hashGenesisBlock: \"0000006af8b8297448605b0283473ec712f9768f81cc7eae6269b875dee3b0cf\",\n port: 19100,\n portRpc: 19101,\n protocol: {\n magic: 1313166674\n },\n seedsDns: [\n \"testnet1.neuracrypt.org\",\n \"testnet2.neuracrypt.org\",\n \"testnet3.neuracrypt.org\"\n ],\n versions: {\n bip32: {\n private: 70615956,\n public: 70617039\n },\n bip44: 1,\n private: 239,\n public: 127,\n scripthash: 196\n }\n }\n};\n\nconst chains = {\n \"xna-legacy\": xnaLegacy\n};\n\nmodule.exports = {\n xnaLegacy,\n chains\n};\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -7,7 +7,7 @@ interface IAddressObject {
7
7
  privateKey: string;
8
8
  WIF: string;
9
9
  }
10
- export type Network = "xna" | "xna-test";
10
+ export type Network = "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test";
11
11
  /**
12
12
  *
13
13
  * @param network
@@ -1 +1 @@
1
- {"mappings":";AAAA;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;ACQD,sBAAsB,KAAK,GAAG,UAAU,CAAC;AAgBzC;;;;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,CAYhB;AAED,2CAEC;AAED,gCAAgC,QAAQ,EAAE,MAAM,WAY/C;AACD;;;;;GAKG;AAEH,gCAAgC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM;;;;EAStE;AAED;;;;GAIG;AACH,+BAA+B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAK9E;AAED,OAAO,MAAM,iDAA2C,CAAC;AAEzD,sCACE,OAAO,GAAE,OAAe,EACxB,UAAU,GAAE,MAAW,GACtB,cAAc,CAahB;AAED,mCACE,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,GAAG,MAAM,GACzB,MAAM,CAkBR;AAED;;;;;;GAMG;AACH,gCAAgC,OAAO,GAAE,OAAe,kBAEvD;;;;;;;;;;;;;;AACD,wBAYE","sources":["types.ts","index.ts"],"sourcesContent":["export interface IAddressObject {\n address: string;\n mnemonic?: string;\n path: string;\n publicKey: 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\nimport { createHash } from \"crypto\";\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\nconst HDKey = require(\"hdkey\");\nimport { IAddressObject } from \"./types\";\nconst bs58check = require(\"bs58check\");\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() as Network; //Just to be sure\n const chainData = chains as any;\n const map: Record<Network, any> = {\n xna: chainData.xna.mainnet.versions,\n \"xna-test\": chainData.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 publicKey: ck2.publicKey.toString(\"hex\"),\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\n/**\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns the compressed public key as a hex string\n */\nexport function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return coinKey.publicKey.toString(\"hex\");\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\nexport function publicKeyToAddress(\n network: Network,\n publicKey: Buffer | string\n): string {\n const chain = getNetwork(network);\n const keyBuffer = Buffer.isBuffer(publicKey)\n ? publicKey\n : Buffer.from(publicKey, \"hex\");\n\n if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {\n throw new Error(\"Public key must be 33 or 65 bytes\");\n }\n\n const sha256Hash = createHash(\"sha256\").update(keyBuffer).digest();\n const ripemd160Hash = createHash(\"ripemd160\").update(sha256Hash).digest();\n const payload = Buffer.concat([\n Buffer.from([chain.public]),\n ripemd160Hash,\n ]);\n\n return bs58check.encode(payload);\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 getPubkeyByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";AAAA;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;ACSD,sBAAsB,KAAK,GAAG,UAAU,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAmB5E;;;;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,CAYhB;AAED,2CAEC;AAED,gCAAgC,QAAQ,EAAE,MAAM,WAY/C;AACD;;;;;GAKG;AAEH,gCAAgC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM;;;;EAStE;AAED;;;;GAIG;AACH,+BAA+B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAK9E;AAED,OAAO,MAAM,iDAA2C,CAAC;AAEzD,sCACE,OAAO,GAAE,OAAe,EACxB,UAAU,GAAE,MAAW,GACtB,cAAc,CAahB;AAED,mCACE,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,GAAG,MAAM,GACzB,MAAM,CAkBR;AAED;;;;;;GAMG;AACH,gCAAgC,OAAO,GAAE,OAAe,kBAEvD;;;;;;;;;;;;;;AACD,wBAYE","sources":["types.ts","index.ts"],"sourcesContent":["export interface IAddressObject {\n address: string;\n mnemonic?: string;\n path: string;\n publicKey: string;\n privateKey: string;\n WIF: string;\n}\n","//Gives us meta data about coins/chains\nimport { chains } from \"./coins/xna.js\";\nimport { chains as legacyChains } from \"./coins/xna-legacy.js\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nimport { createHash } from \"crypto\";\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\nconst HDKey = require(\"hdkey\");\nimport { IAddressObject } from \"./types\";\nconst bs58check = require(\"bs58check\");\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\" | \"xna-legacy\" | \"xna-legacy-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase() as Network; //Just to be sure\n const chainData = chains as any;\n const legacyChainData = legacyChains as any;\n const map: Record<Network, any> = {\n xna: chainData.xna.mainnet.versions,\n \"xna-test\": chainData.xna.testnet?.versions,\n \"xna-legacy\": legacyChainData[\"xna-legacy\"].mainnet.versions,\n \"xna-legacy-test\": legacyChainData[\"xna-legacy\"].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 publicKey: ck2.publicKey.toString(\"hex\"),\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\n/**\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns the compressed public key as a hex string\n */\nexport function getPubkeyByWIF(network: Network, privateKeyWIF: string): string {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return coinKey.publicKey.toString(\"hex\");\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\nexport function publicKeyToAddress(\n network: Network,\n publicKey: Buffer | string\n): string {\n const chain = getNetwork(network);\n const keyBuffer = Buffer.isBuffer(publicKey)\n ? publicKey\n : Buffer.from(publicKey, \"hex\");\n\n if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {\n throw new Error(\"Public key must be 33 or 65 bytes\");\n }\n\n const sha256Hash = createHash(\"sha256\").update(keyBuffer).digest();\n const ripemd160Hash = createHash(\"ripemd160\").update(sha256Hash).digest();\n const payload = Buffer.concat([\n Buffer.from([chain.public]),\n ripemd160Hash,\n ]);\n\n return bs58check.encode(payload);\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 getPubkeyByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  //Gives us meta data about coins/chains
2
- import { chains } from "@hyperbitjs/chains";
2
+ import { chains } from "./coins/xna.js";
3
+ import { chains as legacyChains } from "./coins/xna-legacy.js";
3
4
 
4
5
  //bip39 from mnemonic to seed
5
6
  import * as bip39 from "bip39";
@@ -13,14 +14,17 @@ import { IAddressObject } from "./types";
13
14
  const bs58check = require("bs58check");
14
15
 
15
16
  //Could not declare Network as enum, something wrong with parcel bundler
16
- export type Network = "xna" | "xna-test";
17
+ export type Network = "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test";
17
18
 
18
19
  function getNetwork(name: Network) {
19
20
  const c = name.toLowerCase() as Network; //Just to be sure
20
21
  const chainData = chains as any;
22
+ const legacyChainData = legacyChains as any;
21
23
  const map: Record<Network, any> = {
22
24
  xna: chainData.xna.mainnet.versions,
23
25
  "xna-test": chainData.xna.testnet?.versions,
26
+ "xna-legacy": legacyChainData["xna-legacy"].mainnet.versions,
27
+ "xna-legacy-test": legacyChainData["xna-legacy"].testnet?.versions,
24
28
  };
25
29
 
26
30
  const network = map[c];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-key",
3
- "version": "2.8.6",
3
+ "version": "2.8.7",
4
4
  "description": "Generate Neurai addresses from mnemonic code. BIP32, BIP39, BIP44",
5
5
  "source": "index.ts",
6
6
  "main": "dist/main.js",
@@ -27,7 +27,6 @@
27
27
  },
28
28
  "homepage": "https://github.com/neuraiproject/neurai-key#readme",
29
29
  "dependencies": {
30
- "@hyperbitjs/chains": "^1.2.0",
31
30
  "bip39": "^3.0.4",
32
31
  "bs58check": "^2.1.2",
33
32
  "coinkey": "^3.0.0",
@@ -35,12 +34,12 @@
35
34
  },
36
35
  "devDependencies": {
37
36
  "@parcel/packager-ts": "^2.10.3",
38
- "@parcel/transformer-typescript-types": "^2.16.1",
37
+ "@parcel/transformer-typescript-types": "^2.16.1",
39
38
  "@types/hdkey": "^2.0.3",
40
- "@types/node": "^18.14.0",
39
+ "@types/node": "^20.19.27",
41
40
  "browserify": "^17.0.0",
42
- "jest": "^29.4.0",
41
+ "jest": "^30.2.0",
43
42
  "parcel": "^2.10.3",
44
- "typescript": "^4.9.4"
43
+ "typescript": "^5.9.3"
45
44
  }
46
45
  }
package/test.js CHANGED
@@ -9,7 +9,7 @@ test("Validate address on main-net", () => {
9
9
  const network = "xna";
10
10
  const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
11
11
  const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
12
- expect(address.external.address).toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
12
+ expect(address.external.address).toBe("NLhdtwjgrcEkRqjJZkRY4sjhkJ93EytLeE");
13
13
  });
14
14
 
15
15
  test("Validate address on test-net", () => {
@@ -25,7 +25,7 @@ test("Validate address with passphrase on main-net", () => {
25
25
  const passphrase = "my secret passphrase";
26
26
  const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1, passphrase);
27
27
  // With passphrase, the address should be different from the one without passphrase
28
- expect(address.external.address).not.toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
28
+ expect(address.external.address).not.toBe("NLhdtwjgrcEkRqjJZkRY4sjhkJ93EytLeE");
29
29
  // Verify it generates consistently with the same passphrase
30
30
  const address2 = NeuraiKey.getAddressPair(network, mnemonic, 0, 1, passphrase);
31
31
  expect(address.external.address).toBe(address2.external.address);
@@ -51,7 +51,7 @@ test("Empty passphrase equals no passphrase", () => {
51
51
  const addressWithoutPassphrase = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
52
52
 
53
53
  expect(addressWithEmpty.external.address).toBe(addressWithoutPassphrase.external.address);
54
- expect(addressWithEmpty.external.address).toBe("NLdcSXGQvCVf2RTKhx7GZom34f1JADhBTp");
54
+ expect(addressWithEmpty.external.address).toBe("NLhdtwjgrcEkRqjJZkRY4sjhkJ93EytLeE");
55
55
  });
56
56
 
57
57
  test("Validate Wallet Import Format (WIF) main-net ", () => {
@@ -59,8 +59,8 @@ test("Validate Wallet Import Format (WIF) main-net ", () => {
59
59
  const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
60
60
  const address = NeuraiKey.getAddressPair(network, mnemonic, 0, 1);
61
61
 
62
- expect(address.internal.address).toBe("NQM5zP6jkwDgCZ2UQiUicW4e3YcWc4NY4S");
63
- expect(address.external.WIF).toBe("KwWavecys1Qskgzwsyv6CNeTospWkvMeLzx3dLqeV4xAJEMXF8Qq");
62
+ expect(address.internal.address).toBe("NRYT7zihLQTGpcK4PKHnTFuQsLaTGJYzqm");
63
+ expect(address.external.WIF).toBe("L1FXfT3WjVLERgqiQt3YzqU9F3Z8LmMhxPF4VHW5yd3Q6Q66woRQ");
64
64
  });
65
65
 
66
66
  test("Convert external public key to main-net address", () => {