@neuraiproject/neurai-key 2.8.3 → 2.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -38,9 +38,7 @@ function $80bd448eb6ea085b$var$getNetwork(name) {
38
38
  const c = name.toLowerCase(); //Just to be sure
39
39
  const map = {
40
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
41
+ "xna-test": (0, $g5Y9E$hyperbitjschains.chains).xna.testnet?.versions
44
42
  };
45
43
  const network = map[c];
46
44
  if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
@@ -50,8 +48,8 @@ function $80bd448eb6ea085b$export$23109f16a8a07245(network) {
50
48
  const chain = $80bd448eb6ea085b$var$getNetwork(network);
51
49
  return chain.bip44;
52
50
  }
53
- function $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position) {
54
- const hdKey = $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic);
51
+ function $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase = "") {
52
+ const hdKey = $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic, passphrase);
55
53
  const coin_type = $80bd448eb6ea085b$export$23109f16a8a07245(network);
56
54
  //https://github.com/satoshilabs/slips/blob/master/slip-0044.md
57
55
  //Syntax of BIP44
@@ -67,9 +65,9 @@ function $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, p
67
65
  position: position
68
66
  };
69
67
  }
70
- function $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic) {
68
+ function $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic, passphrase = "") {
71
69
  const chain = $80bd448eb6ea085b$var$getNetwork(network);
72
- const seed = $g5Y9E$bip39.mnemonicToSeedSync(mnemonic).toString("hex");
70
+ const seed = $g5Y9E$bip39.mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
73
71
  //From the seed, get a hdKey, can we use CoinKey instead?
74
72
  const hdKey = (0, ($parcel$interopDefault($g5Y9E$hdkey))).fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
75
73
  return hdKey;
@@ -108,11 +106,11 @@ function $80bd448eb6ea085b$export$f43d70cb4ddd5664(network, privateKeyWIF) {
108
106
  };
109
107
  }
110
108
  const $80bd448eb6ea085b$export$4becd65eb23312e6 = $g5Y9E$bip39.entropyToMnemonic;
111
- function $80bd448eb6ea085b$export$de190b37be25f71b(network = "xna") {
109
+ function $80bd448eb6ea085b$export$de190b37be25f71b(network = "xna", passphrase = "") {
112
110
  const mnemonic = $80bd448eb6ea085b$export$9f993213e5806bf0();
113
111
  const account = 0;
114
112
  const position = 0;
115
- const addressPair = $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position);
113
+ const addressPair = $80bd448eb6ea085b$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase);
116
114
  const addressObject = addressPair.external;
117
115
  const result = {
118
116
  ...addressObject,
package/dist/main.js.map CHANGED
@@ -1 +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,CA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AAU;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,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"}
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;IAClC;IAEA,MAAM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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,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,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;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\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase(); //Just to be sure\n const map = {\n xna: chains.xna.mainnet.versions,\n \"xna-test\": chains.xna.testnet?.versions,\n };\n\n const network = map[c];\n if (!network) {\n throw new Error(\"network must be of value \" + Object.keys(map).toString());\n }\n return network;\n}\n/**\n *\n * @param network\n * @returns the coin type for the network (blockchain), for example Neurai has coin type 175\n */\nexport function getCoinType(network: Network) {\n const chain = getNetwork(network);\n return chain.bip44;\n}\n/**\n * @param network - should have value \"xna\", \"xna-test\", \"evr\" or \"evr-test\"\n * @param mnemonic - your mnemonic\n * @param account - accounts in BIP44 starts from 0, 0 is the default account\n * @param position - starts from 0\n * @param passphrase - optional BIP39 passphrase (25th word) for additional security\n */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number,\n passphrase: string = \"\"\n) {\n const hdKey = getHDKey(network, mnemonic, passphrase);\n const coin_type = getCoinType(network);\n\n //https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n\n //Syntax of BIP44\n //m / purpose' / coin_type' / account' / change / address_index\n const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;\n const externalAddress = getAddressByPath(network, hdKey, externalPath);\n\n //change address\n const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;\n const internalAddress = getAddressByPath(network, hdKey, internalPath);\n return {\n internal: internalAddress,\n external: externalAddress,\n position,\n };\n}\n\nexport function getHDKey(network: Network, mnemonic: string, passphrase: string = \"\"): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString(\"hex\");\n //From the seed, get a hdKey, can we use CoinKey instead?\n const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, \"hex\"), chain.bip32);\n return hdKey;\n}\n\nexport function getAddressByPath(\n network: Network,\n hdKey: any,\n path: string\n): IAddressObject {\n const chain = getNetwork(network);\n const derived = hdKey.derive(path);\n var ck2 = new CoinKey(derived.privateKey, chain);\n\n return {\n address: ck2.publicAddress,\n path: path,\n privateKey: ck2.privateKey.toString(\"hex\"),\n WIF: ck2.privateWif,\n };\n}\n\nexport function generateMnemonic() {\n return bip39.generateMnemonic();\n}\n\nexport function isMnemonicValid(mnemonic: string) {\n //Check all languages\n const wordlists = Object.values(bip39.wordlists);\n\n //If mnemonic is valid in any language, return true, otherwise false\n for (const wordlist of wordlists) {\n const v = bip39.validateMnemonic(mnemonic, wordlist);\n if (v === true) {\n return true;\n }\n }\n return false;\n}\n/**\n *\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns object {address, privateKey (hex), WIF}\n */\n\nexport function getAddressByWIF(network: Network, privateKeyWIF: string) {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return {\n address: coinKey.publicAddress,\n privateKey: coinKey.privateKey.toString(\"hex\"),\n WIF: coinKey.privateWif,\n };\n}\n\nexport const entropyToMnemonic = bip39.entropyToMnemonic;\n\nexport function generateAddressObject(\n network: Network = \"xna\",\n passphrase: string = \"\"\n): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);\n const addressObject = addressPair.external;\n\n const result = {\n ...addressObject,\n mnemonic,\n network,\n };\n return result;\n}\n\n/**\n * Generates a random Address Object\n *\n * @deprecated use generateAddressObject\n * @param network\n * @returns\n */\nexport function generateAddress(network: Network = \"xna\") {\n return generateAddressObject(network);\n}\nexport default {\n entropyToMnemonic,\n generateAddress,\n generateMnemonic,\n getAddressByPath,\n getAddressByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n};\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -12,9 +12,7 @@ function $c3f6c693698dc7cd$var$getNetwork(name) {
12
12
  const c = name.toLowerCase(); //Just to be sure
13
13
  const map = {
14
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
15
+ "xna-test": (0, $hCgyA$chains).xna.testnet?.versions
18
16
  };
19
17
  const network = map[c];
20
18
  if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
@@ -24,8 +22,8 @@ function $c3f6c693698dc7cd$export$23109f16a8a07245(network) {
24
22
  const chain = $c3f6c693698dc7cd$var$getNetwork(network);
25
23
  return chain.bip44;
26
24
  }
27
- function $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position) {
28
- const hdKey = $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic);
25
+ function $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase = "") {
26
+ const hdKey = $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic, passphrase);
29
27
  const coin_type = $c3f6c693698dc7cd$export$23109f16a8a07245(network);
30
28
  //https://github.com/satoshilabs/slips/blob/master/slip-0044.md
31
29
  //Syntax of BIP44
@@ -41,9 +39,9 @@ function $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, p
41
39
  position: position
42
40
  };
43
41
  }
44
- function $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic) {
42
+ function $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic, passphrase = "") {
45
43
  const chain = $c3f6c693698dc7cd$var$getNetwork(network);
46
- const seed = $hCgyA$mnemonicToSeedSync(mnemonic).toString("hex");
44
+ const seed = $hCgyA$mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
47
45
  //From the seed, get a hdKey, can we use CoinKey instead?
48
46
  const hdKey = (0, $hCgyA$hdkey).fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
49
47
  return hdKey;
@@ -82,11 +80,11 @@ function $c3f6c693698dc7cd$export$f43d70cb4ddd5664(network, privateKeyWIF) {
82
80
  };
83
81
  }
84
82
  const $c3f6c693698dc7cd$export$4becd65eb23312e6 = $hCgyA$entropyToMnemonic;
85
- function $c3f6c693698dc7cd$export$de190b37be25f71b(network = "xna") {
83
+ function $c3f6c693698dc7cd$export$de190b37be25f71b(network = "xna", passphrase = "") {
86
84
  const mnemonic = $c3f6c693698dc7cd$export$9f993213e5806bf0();
87
85
  const account = 0;
88
86
  const position = 0;
89
- const addressPair = $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position);
87
+ const addressPair = $c3f6c693698dc7cd$export$6e3ac79f8c0a2892(network, mnemonic, account, position, passphrase);
90
88
  const addressObject = addressPair.external;
91
89
  const result = {
92
90
  ...addressObject,
@@ -1 +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,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ;QAChC,YAAY,CAAA,GAAA,aAAK,EAAE,GAAG,CAAC,OAAO,EAAE;IAClC;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;AAOO,SAAS,0CACd,OAAgB,EAChB,QAAgB,EAChB,OAAe,EACf,QAAgB;IAEhB,MAAM,QAAQ,0CAAS,SAAS;IAChC,MAAM,YAAY,0CAAY;IAE9B,+DAA+D;IAE/D,iBAAiB;IACjB,+DAA+D;IAC/D,MAAM,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,QAAQ,IAAI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B;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"}
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;IAClC;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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AM,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;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\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase(); //Just to be sure\n const map = {\n xna: chains.xna.mainnet.versions,\n \"xna-test\": chains.xna.testnet?.versions,\n };\n\n const network = map[c];\n if (!network) {\n throw new Error(\"network must be of value \" + Object.keys(map).toString());\n }\n return network;\n}\n/**\n *\n * @param network\n * @returns the coin type for the network (blockchain), for example Neurai has coin type 175\n */\nexport function getCoinType(network: Network) {\n const chain = getNetwork(network);\n return chain.bip44;\n}\n/**\n * @param network - should have value \"xna\", \"xna-test\", \"evr\" or \"evr-test\"\n * @param mnemonic - your mnemonic\n * @param account - accounts in BIP44 starts from 0, 0 is the default account\n * @param position - starts from 0\n * @param passphrase - optional BIP39 passphrase (25th word) for additional security\n */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number,\n passphrase: string = \"\"\n) {\n const hdKey = getHDKey(network, mnemonic, passphrase);\n const coin_type = getCoinType(network);\n\n //https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n\n //Syntax of BIP44\n //m / purpose' / coin_type' / account' / change / address_index\n const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;\n const externalAddress = getAddressByPath(network, hdKey, externalPath);\n\n //change address\n const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;\n const internalAddress = getAddressByPath(network, hdKey, internalPath);\n return {\n internal: internalAddress,\n external: externalAddress,\n position,\n };\n}\n\nexport function getHDKey(network: Network, mnemonic: string, passphrase: string = \"\"): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString(\"hex\");\n //From the seed, get a hdKey, can we use CoinKey instead?\n const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, \"hex\"), chain.bip32);\n return hdKey;\n}\n\nexport function getAddressByPath(\n network: Network,\n hdKey: any,\n path: string\n): IAddressObject {\n const chain = getNetwork(network);\n const derived = hdKey.derive(path);\n var ck2 = new CoinKey(derived.privateKey, chain);\n\n return {\n address: ck2.publicAddress,\n path: path,\n privateKey: ck2.privateKey.toString(\"hex\"),\n WIF: ck2.privateWif,\n };\n}\n\nexport function generateMnemonic() {\n return bip39.generateMnemonic();\n}\n\nexport function isMnemonicValid(mnemonic: string) {\n //Check all languages\n const wordlists = Object.values(bip39.wordlists);\n\n //If mnemonic is valid in any language, return true, otherwise false\n for (const wordlist of wordlists) {\n const v = bip39.validateMnemonic(mnemonic, wordlist);\n if (v === true) {\n return true;\n }\n }\n return false;\n}\n/**\n *\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns object {address, privateKey (hex), WIF}\n */\n\nexport function getAddressByWIF(network: Network, privateKeyWIF: string) {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return {\n address: coinKey.publicAddress,\n privateKey: coinKey.privateKey.toString(\"hex\"),\n WIF: coinKey.privateWif,\n };\n}\n\nexport const entropyToMnemonic = bip39.entropyToMnemonic;\n\nexport function generateAddressObject(\n network: Network = \"xna\",\n passphrase: string = \"\"\n): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);\n const addressObject = addressPair.external;\n\n const result = {\n ...addressObject,\n mnemonic,\n network,\n };\n return result;\n}\n\n/**\n * Generates a random Address Object\n *\n * @deprecated use generateAddressObject\n * @param network\n * @returns\n */\nexport function generateAddress(network: Network = \"xna\") {\n return generateAddressObject(network);\n}\nexport default {\n entropyToMnemonic,\n generateAddress,\n generateMnemonic,\n getAddressByPath,\n getAddressByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n};\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -6,7 +6,7 @@ interface IAddressObject {
6
6
  privateKey: string;
7
7
  WIF: string;
8
8
  }
9
- export type Network = "xna" | "xna-test" | "evr" | "evr-test";
9
+ export type Network = "xna" | "xna-test";
10
10
  /**
11
11
  *
12
12
  * @param network
@@ -18,13 +18,14 @@ export function getCoinType(network: Network): any;
18
18
  * @param mnemonic - your mnemonic
19
19
  * @param account - accounts in BIP44 starts from 0, 0 is the default account
20
20
  * @param position - starts from 0
21
+ * @param passphrase - optional BIP39 passphrase (25th word) for additional security
21
22
  */
22
- export function getAddressPair(network: Network, mnemonic: string, account: number, position: number): {
23
+ export function getAddressPair(network: Network, mnemonic: string, account: number, position: number, passphrase?: string): {
23
24
  internal: IAddressObject;
24
25
  external: IAddressObject;
25
26
  position: number;
26
27
  };
27
- export function getHDKey(network: Network, mnemonic: string): any;
28
+ export function getHDKey(network: Network, mnemonic: string, passphrase?: string): any;
28
29
  export function getAddressByPath(network: Network, hdKey: any, path: string): IAddressObject;
29
30
  export function generateMnemonic(): string;
30
31
  export function isMnemonicValid(mnemonic: string): boolean;
@@ -40,7 +41,7 @@ export function getAddressByWIF(network: Network, privateKeyWIF: string): {
40
41
  WIF: any;
41
42
  };
42
43
  export const entropyToMnemonic: typeof bip39.entropyToMnemonic;
43
- export function generateAddressObject(network?: Network): IAddressObject;
44
+ export function generateAddressObject(network?: Network, passphrase?: string): IAddressObject;
44
45
  /**
45
46
  * Generates a random Address Object
46
47
  *
@@ -1 +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"}
1
+ {"mappings":";AAAA;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;ACQD,sBAAsB,KAAK,GAAG,UAAU,CAAC;AAezC;;;;GAIG;AACH,4BAA4B,OAAO,EAAE,OAAO,OAG3C;AACD;;;;;;GAMG;AACH,+BACE,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,MAAW;;;;EAoBxB;AAED,yBAAyB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,GAAG,CAMzF;AAED,iCACE,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,MAAM,GACX,cAAc,CAWhB;AAED,2CAEC;AAED,gCAAgC,QAAQ,EAAE,MAAM,WAY/C;AACD;;;;;GAKG;AAEH,gCAAgC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM;;;;EAStE;AAED,OAAO,MAAM,iDAA2C,CAAC;AAEzD,sCACE,OAAO,GAAE,OAAe,EACxB,UAAU,GAAE,MAAW,GACtB,cAAc,CAahB;AAED;;;;;;GAMG;AACH,gCAAgC,OAAO,GAAE,OAAe,kBAEvD;;;;;;;;;;;;AACD,wBAUE","sources":["types.ts","index.ts"],"sourcesContent":["export interface IAddressObject {\n address: string;\n mnemonic?: string;\n path: string;\n privateKey: string;\n WIF: string;\n}\n","//Gives us meta data about coins/chains\nimport { chains } from \"@hyperbitjs/chains\";\n\n//bip39 from mnemonic to seed\nimport * as bip39 from \"bip39\";\n\nconst CoinKey = require(\"coinkey\");\n\n//From seed to key\n//const HDKey = require(\"hdkey\");\nimport HDKey from \"hdkey\";\nimport { IAddressObject } from \"./types\";\n\n//Could not declare Network as enum, something wrong with parcel bundler\nexport type Network = \"xna\" | \"xna-test\";\n\nfunction getNetwork(name: Network) {\n const c = name.toLowerCase(); //Just to be sure\n const map = {\n xna: chains.xna.mainnet.versions,\n \"xna-test\": chains.xna.testnet?.versions,\n };\n\n const network = map[c];\n if (!network) {\n throw new Error(\"network must be of value \" + Object.keys(map).toString());\n }\n return network;\n}\n/**\n *\n * @param network\n * @returns the coin type for the network (blockchain), for example Neurai has coin type 175\n */\nexport function getCoinType(network: Network) {\n const chain = getNetwork(network);\n return chain.bip44;\n}\n/**\n * @param network - should have value \"xna\", \"xna-test\", \"evr\" or \"evr-test\"\n * @param mnemonic - your mnemonic\n * @param account - accounts in BIP44 starts from 0, 0 is the default account\n * @param position - starts from 0\n * @param passphrase - optional BIP39 passphrase (25th word) for additional security\n */\nexport function getAddressPair(\n network: Network,\n mnemonic: string,\n account: number,\n position: number,\n passphrase: string = \"\"\n) {\n const hdKey = getHDKey(network, mnemonic, passphrase);\n const coin_type = getCoinType(network);\n\n //https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n\n //Syntax of BIP44\n //m / purpose' / coin_type' / account' / change / address_index\n const externalPath = `m/44'/${coin_type}'/${account}'/0/${position}`;\n const externalAddress = getAddressByPath(network, hdKey, externalPath);\n\n //change address\n const internalPath = `m/44'/${coin_type}'/${account}'/1/${position}`;\n const internalAddress = getAddressByPath(network, hdKey, internalPath);\n return {\n internal: internalAddress,\n external: externalAddress,\n position,\n };\n}\n\nexport function getHDKey(network: Network, mnemonic: string, passphrase: string = \"\"): any {\n const chain = getNetwork(network);\n const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString(\"hex\");\n //From the seed, get a hdKey, can we use CoinKey instead?\n const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, \"hex\"), chain.bip32);\n return hdKey;\n}\n\nexport function getAddressByPath(\n network: Network,\n hdKey: any,\n path: string\n): IAddressObject {\n const chain = getNetwork(network);\n const derived = hdKey.derive(path);\n var ck2 = new CoinKey(derived.privateKey, chain);\n\n return {\n address: ck2.publicAddress,\n path: path,\n privateKey: ck2.privateKey.toString(\"hex\"),\n WIF: ck2.privateWif,\n };\n}\n\nexport function generateMnemonic() {\n return bip39.generateMnemonic();\n}\n\nexport function isMnemonicValid(mnemonic: string) {\n //Check all languages\n const wordlists = Object.values(bip39.wordlists);\n\n //If mnemonic is valid in any language, return true, otherwise false\n for (const wordlist of wordlists) {\n const v = bip39.validateMnemonic(mnemonic, wordlist);\n if (v === true) {\n return true;\n }\n }\n return false;\n}\n/**\n *\n * @param privateKeyWIF\n * @param network should be \"xna\" or \"xna-test\"\n * @returns object {address, privateKey (hex), WIF}\n */\n\nexport function getAddressByWIF(network: Network, privateKeyWIF: string) {\n const coinKey = CoinKey.fromWif(privateKeyWIF);\n coinKey.versions = getNetwork(network);\n\n return {\n address: coinKey.publicAddress,\n privateKey: coinKey.privateKey.toString(\"hex\"),\n WIF: coinKey.privateWif,\n };\n}\n\nexport const entropyToMnemonic = bip39.entropyToMnemonic;\n\nexport function generateAddressObject(\n network: Network = \"xna\",\n passphrase: string = \"\"\n): IAddressObject {\n const mnemonic = generateMnemonic();\n const account = 0;\n const position = 0;\n const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);\n const addressObject = addressPair.external;\n\n const result = {\n ...addressObject,\n mnemonic,\n network,\n };\n return result;\n}\n\n/**\n * Generates a random Address Object\n *\n * @deprecated use generateAddressObject\n * @param network\n * @returns\n */\nexport function generateAddress(network: Network = \"xna\") {\n return generateAddressObject(network);\n}\nexport default {\n entropyToMnemonic,\n generateAddress,\n generateMnemonic,\n getAddressByPath,\n getAddressByWIF,\n getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n};\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,34 @@
1
+ const NeuraiKey = require("./dist/main");
2
+
3
+ console.log("=== Neurai Key - Passphrase Example ===\n");
4
+
5
+ const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
6
+ const network = "xna";
7
+ const account = 0;
8
+ const position = 0;
9
+
10
+ console.log("Mnemonic:", mnemonic);
11
+ console.log("\n--- WITHOUT Passphrase ---");
12
+ const addressNoPass = NeuraiKey.getAddressPair(network, mnemonic, account, position);
13
+ console.log("External Address:", addressNoPass.external.address);
14
+ console.log("Internal Address:", addressNoPass.internal.address);
15
+ console.log("WIF:", addressNoPass.external.WIF);
16
+
17
+ console.log("\n--- WITH Passphrase: 'my secret passphrase' ---");
18
+ const passphrase1 = "my secret passphrase";
19
+ const addressWithPass1 = NeuraiKey.getAddressPair(network, mnemonic, account, position, passphrase1);
20
+ console.log("External Address:", addressWithPass1.external.address);
21
+ console.log("Internal Address:", addressWithPass1.internal.address);
22
+ console.log("WIF:", addressWithPass1.external.WIF);
23
+
24
+ console.log("\n--- WITH Different Passphrase: 'another passphrase' ---");
25
+ const passphrase2 = "another passphrase";
26
+ const addressWithPass2 = NeuraiKey.getAddressPair(network, mnemonic, account, position, passphrase2);
27
+ console.log("External Address:", addressWithPass2.external.address);
28
+ console.log("Internal Address:", addressWithPass2.internal.address);
29
+ console.log("WIF:", addressWithPass2.external.WIF);
30
+
31
+ console.log("\n=== Summary ===");
32
+ console.log("✅ Same mnemonic + different passphrases = DIFFERENT wallets");
33
+ console.log("✅ This provides an extra security layer");
34
+ console.log("⚠️ IMPORTANT: You need BOTH mnemonic AND passphrase to recover the wallet!");
package/index.ts CHANGED
@@ -12,15 +12,13 @@ import HDKey from "hdkey";
12
12
  import { IAddressObject } from "./types";
13
13
 
14
14
  //Could not declare Network as enum, something wrong with parcel bundler
15
- export type Network = "xna" | "xna-test" | "evr" | "evr-test";
15
+ export type Network = "xna" | "xna-test";
16
16
 
17
17
  function getNetwork(name: Network) {
18
18
  const c = name.toLowerCase(); //Just to be sure
19
19
  const map = {
20
20
  xna: chains.xna.mainnet.versions,
21
21
  "xna-test": chains.xna.testnet?.versions,
22
- evr: chains.evr.mainnet.versions,
23
- "evr-test": chains.evr.testnet?.versions,
24
22
  };
25
23
 
26
24
  const network = map[c];
@@ -43,14 +41,16 @@ export function getCoinType(network: Network) {
43
41
  * @param mnemonic - your mnemonic
44
42
  * @param account - accounts in BIP44 starts from 0, 0 is the default account
45
43
  * @param position - starts from 0
44
+ * @param passphrase - optional BIP39 passphrase (25th word) for additional security
46
45
  */
47
46
  export function getAddressPair(
48
47
  network: Network,
49
48
  mnemonic: string,
50
49
  account: number,
51
- position: number
50
+ position: number,
51
+ passphrase: string = ""
52
52
  ) {
53
- const hdKey = getHDKey(network, mnemonic);
53
+ const hdKey = getHDKey(network, mnemonic, passphrase);
54
54
  const coin_type = getCoinType(network);
55
55
 
56
56
  //https://github.com/satoshilabs/slips/blob/master/slip-0044.md
@@ -70,9 +70,9 @@ export function getAddressPair(
70
70
  };
71
71
  }
72
72
 
73
- export function getHDKey(network: Network, mnemonic: string): any {
73
+ export function getHDKey(network: Network, mnemonic: string, passphrase: string = ""): any {
74
74
  const chain = getNetwork(network);
75
- const seed = bip39.mnemonicToSeedSync(mnemonic).toString("hex");
75
+ const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
76
76
  //From the seed, get a hdKey, can we use CoinKey instead?
77
77
  const hdKey = HDKey.fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
78
78
  return hdKey;
@@ -133,12 +133,13 @@ export function getAddressByWIF(network: Network, privateKeyWIF: string) {
133
133
  export const entropyToMnemonic = bip39.entropyToMnemonic;
134
134
 
135
135
  export function generateAddressObject(
136
- network: Network = "xna"
136
+ network: Network = "xna",
137
+ passphrase: string = ""
137
138
  ): IAddressObject {
138
139
  const mnemonic = generateMnemonic();
139
140
  const account = 0;
140
141
  const position = 0;
141
- const addressPair = getAddressPair(network, mnemonic, account, position);
142
+ const addressPair = getAddressPair(network, mnemonic, account, position, passphrase);
142
143
  const addressObject = addressPair.external;
143
144
 
144
145
  const result = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-key",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "description": "Generate Neurai addresses from mnemonic code. BIP32, BIP39, BIP44",
5
5
  "source": "index.ts",
6
6
  "main": "dist/main.js",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@parcel/packager-ts": "^2.10.3",
37
- "@parcel/transformer-typescript-types": "^2.10.3",
37
+ "@parcel/transformer-typescript-types": "2.16.0",
38
38
  "@types/hdkey": "^2.0.3",
39
39
  "@types/node": "^18.14.0",
40
40
  "browserify": "^17.0.0",