@neuraiproject/neurai-key 2.8.4 → 2.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/README.md +31 -4
- package/dist/NeuraiKey.js +32279 -32111
- package/dist/main.js +26 -8
- package/dist/main.js.map +1 -1
- package/dist/module.js +27 -6
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/index.ts +33 -6
- package/package.json +3 -2
- package/test-html/NeuraiKey.js +32279 -32111
- package/test-html/index.html +12 -1
- package/test.js +18 -0
- package/types.ts +1 -0
package/dist/main.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
var $g5Y9E$hyperbitjschains = require("@hyperbitjs/chains");
|
|
2
2
|
var $g5Y9E$bip39 = require("bip39");
|
|
3
|
+
var $g5Y9E$crypto = require("crypto");
|
|
3
4
|
var $g5Y9E$coinkey = require("coinkey");
|
|
4
5
|
var $g5Y9E$hdkey = require("hdkey");
|
|
6
|
+
var $g5Y9E$bs58check = require("bs58check");
|
|
5
7
|
|
|
6
8
|
|
|
7
|
-
function $parcel$interopDefault(a) {
|
|
8
|
-
return a && a.__esModule ? a.default : a;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
9
|
function $parcel$defineInteropFlag(a) {
|
|
12
10
|
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
13
11
|
}
|
|
@@ -27,6 +25,7 @@ $parcel$export(module.exports, "isMnemonicValid", () => $80bd448eb6ea085b$export
|
|
|
27
25
|
$parcel$export(module.exports, "getAddressByWIF", () => $80bd448eb6ea085b$export$f43d70cb4ddd5664);
|
|
28
26
|
$parcel$export(module.exports, "entropyToMnemonic", () => $80bd448eb6ea085b$export$4becd65eb23312e6);
|
|
29
27
|
$parcel$export(module.exports, "generateAddressObject", () => $80bd448eb6ea085b$export$de190b37be25f71b);
|
|
28
|
+
$parcel$export(module.exports, "publicKeyToAddress", () => $80bd448eb6ea085b$export$462669520a9d12d1);
|
|
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
|
|
@@ -34,11 +33,14 @@ $parcel$export(module.exports, "default", () => $80bd448eb6ea085b$export$2e2bcd8
|
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
|
|
36
|
+
|
|
37
|
+
|
|
37
38
|
function $80bd448eb6ea085b$var$getNetwork(name) {
|
|
38
39
|
const c = name.toLowerCase(); //Just to be sure
|
|
40
|
+
const chainData = (0, $g5Y9E$hyperbitjschains.chains);
|
|
39
41
|
const map = {
|
|
40
|
-
xna:
|
|
41
|
-
"xna-test":
|
|
42
|
+
xna: chainData.xna.mainnet.versions,
|
|
43
|
+
"xna-test": chainData.xna.testnet?.versions
|
|
42
44
|
};
|
|
43
45
|
const network = map[c];
|
|
44
46
|
if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
|
|
@@ -69,7 +71,7 @@ function $80bd448eb6ea085b$export$6c78ccde21ad48f6(network, mnemonic, passphrase
|
|
|
69
71
|
const chain = $80bd448eb6ea085b$var$getNetwork(network);
|
|
70
72
|
const seed = $g5Y9E$bip39.mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
|
|
71
73
|
//From the seed, get a hdKey, can we use CoinKey instead?
|
|
72
|
-
const hdKey =
|
|
74
|
+
const hdKey = $g5Y9E$hdkey.fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
|
|
73
75
|
return hdKey;
|
|
74
76
|
}
|
|
75
77
|
function $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, path) {
|
|
@@ -79,6 +81,7 @@ function $80bd448eb6ea085b$export$6fc951b76952b95e(network, hdKey, path) {
|
|
|
79
81
|
return {
|
|
80
82
|
address: ck2.publicAddress,
|
|
81
83
|
path: path,
|
|
84
|
+
publicKey: ck2.publicKey.toString("hex"),
|
|
82
85
|
privateKey: ck2.privateKey.toString("hex"),
|
|
83
86
|
WIF: ck2.privateWif
|
|
84
87
|
};
|
|
@@ -119,6 +122,20 @@ function $80bd448eb6ea085b$export$de190b37be25f71b(network = "xna", passphrase =
|
|
|
119
122
|
};
|
|
120
123
|
return result;
|
|
121
124
|
}
|
|
125
|
+
function $80bd448eb6ea085b$export$462669520a9d12d1(network, publicKey) {
|
|
126
|
+
const chain = $80bd448eb6ea085b$var$getNetwork(network);
|
|
127
|
+
const keyBuffer = Buffer.isBuffer(publicKey) ? publicKey : Buffer.from(publicKey, "hex");
|
|
128
|
+
if (keyBuffer.length !== 33 && keyBuffer.length !== 65) throw new Error("Public key must be 33 or 65 bytes");
|
|
129
|
+
const sha256Hash = (0, $g5Y9E$crypto.createHash)("sha256").update(keyBuffer).digest();
|
|
130
|
+
const ripemd160Hash = (0, $g5Y9E$crypto.createHash)("ripemd160").update(sha256Hash).digest();
|
|
131
|
+
const payload = Buffer.concat([
|
|
132
|
+
Buffer.from([
|
|
133
|
+
chain.public
|
|
134
|
+
]),
|
|
135
|
+
ripemd160Hash
|
|
136
|
+
]);
|
|
137
|
+
return $g5Y9E$bs58check.encode(payload);
|
|
138
|
+
}
|
|
122
139
|
function $80bd448eb6ea085b$export$e2e336010351d8a8(network = "xna") {
|
|
123
140
|
return $80bd448eb6ea085b$export$de190b37be25f71b(network);
|
|
124
141
|
}
|
|
@@ -131,7 +148,8 @@ var $80bd448eb6ea085b$export$2e2bcd8739ae039 = {
|
|
|
131
148
|
getAddressPair: $80bd448eb6ea085b$export$6e3ac79f8c0a2892,
|
|
132
149
|
getCoinType: $80bd448eb6ea085b$export$23109f16a8a07245,
|
|
133
150
|
getHDKey: $80bd448eb6ea085b$export$6c78ccde21ad48f6,
|
|
134
|
-
isMnemonicValid: $80bd448eb6ea085b$export$2b99b9ff149202f3
|
|
151
|
+
isMnemonicValid: $80bd448eb6ea085b$export$2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S;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;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\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 getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import {chains as $hCgyA$chains} from "@hyperbitjs/chains";
|
|
2
2
|
import {mnemonicToSeedSync as $hCgyA$mnemonicToSeedSync, generateMnemonic as $hCgyA$generateMnemonic, wordlists as $hCgyA$wordlists, validateMnemonic as $hCgyA$validateMnemonic, entropyToMnemonic as $hCgyA$entropyToMnemonic} from "bip39";
|
|
3
|
+
import {createHash as $hCgyA$createHash} from "crypto";
|
|
3
4
|
import * as $hCgyA$coinkey from "coinkey";
|
|
4
|
-
import $hCgyA$
|
|
5
|
+
import {fromMasterSeed as $hCgyA$fromMasterSeed} from "hdkey";
|
|
6
|
+
import {encode as $hCgyA$encode} from "bs58check";
|
|
5
7
|
|
|
6
8
|
//Gives us meta data about coins/chains
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
|
|
13
|
+
|
|
14
|
+
|
|
11
15
|
function $c3f6c693698dc7cd$var$getNetwork(name) {
|
|
12
16
|
const c = name.toLowerCase(); //Just to be sure
|
|
17
|
+
const chainData = (0, $hCgyA$chains);
|
|
13
18
|
const map = {
|
|
14
|
-
xna:
|
|
15
|
-
"xna-test":
|
|
19
|
+
xna: chainData.xna.mainnet.versions,
|
|
20
|
+
"xna-test": chainData.xna.testnet?.versions
|
|
16
21
|
};
|
|
17
22
|
const network = map[c];
|
|
18
23
|
if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
|
|
@@ -43,7 +48,7 @@ function $c3f6c693698dc7cd$export$6c78ccde21ad48f6(network, mnemonic, passphrase
|
|
|
43
48
|
const chain = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
44
49
|
const seed = $hCgyA$mnemonicToSeedSync(mnemonic, passphrase).toString("hex");
|
|
45
50
|
//From the seed, get a hdKey, can we use CoinKey instead?
|
|
46
|
-
const hdKey =
|
|
51
|
+
const hdKey = $hCgyA$fromMasterSeed(Buffer.from(seed, "hex"), chain.bip32);
|
|
47
52
|
return hdKey;
|
|
48
53
|
}
|
|
49
54
|
function $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, path) {
|
|
@@ -53,6 +58,7 @@ function $c3f6c693698dc7cd$export$6fc951b76952b95e(network, hdKey, path) {
|
|
|
53
58
|
return {
|
|
54
59
|
address: ck2.publicAddress,
|
|
55
60
|
path: path,
|
|
61
|
+
publicKey: ck2.publicKey.toString("hex"),
|
|
56
62
|
privateKey: ck2.privateKey.toString("hex"),
|
|
57
63
|
WIF: ck2.privateWif
|
|
58
64
|
};
|
|
@@ -93,6 +99,20 @@ function $c3f6c693698dc7cd$export$de190b37be25f71b(network = "xna", passphrase =
|
|
|
93
99
|
};
|
|
94
100
|
return result;
|
|
95
101
|
}
|
|
102
|
+
function $c3f6c693698dc7cd$export$462669520a9d12d1(network, publicKey) {
|
|
103
|
+
const chain = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
104
|
+
const keyBuffer = Buffer.isBuffer(publicKey) ? publicKey : Buffer.from(publicKey, "hex");
|
|
105
|
+
if (keyBuffer.length !== 33 && keyBuffer.length !== 65) throw new Error("Public key must be 33 or 65 bytes");
|
|
106
|
+
const sha256Hash = (0, $hCgyA$createHash)("sha256").update(keyBuffer).digest();
|
|
107
|
+
const ripemd160Hash = (0, $hCgyA$createHash)("ripemd160").update(sha256Hash).digest();
|
|
108
|
+
const payload = Buffer.concat([
|
|
109
|
+
Buffer.from([
|
|
110
|
+
chain.public
|
|
111
|
+
]),
|
|
112
|
+
ripemd160Hash
|
|
113
|
+
]);
|
|
114
|
+
return $hCgyA$encode(payload);
|
|
115
|
+
}
|
|
96
116
|
function $c3f6c693698dc7cd$export$e2e336010351d8a8(network = "xna") {
|
|
97
117
|
return $c3f6c693698dc7cd$export$de190b37be25f71b(network);
|
|
98
118
|
}
|
|
@@ -105,9 +125,10 @@ var $c3f6c693698dc7cd$export$2e2bcd8739ae039 = {
|
|
|
105
125
|
getAddressPair: $c3f6c693698dc7cd$export$6e3ac79f8c0a2892,
|
|
106
126
|
getCoinType: $c3f6c693698dc7cd$export$23109f16a8a07245,
|
|
107
127
|
getHDKey: $c3f6c693698dc7cd$export$6c78ccde21ad48f6,
|
|
108
|
-
isMnemonicValid: $c3f6c693698dc7cd$export$2b99b9ff149202f3
|
|
128
|
+
isMnemonicValid: $c3f6c693698dc7cd$export$2b99b9ff149202f3,
|
|
129
|
+
publicKeyToAddress: $c3f6c693698dc7cd$export$462669520a9d12d1
|
|
109
130
|
};
|
|
110
131
|
|
|
111
132
|
|
|
112
|
-
export {$c3f6c693698dc7cd$export$23109f16a8a07245 as getCoinType, $c3f6c693698dc7cd$export$6e3ac79f8c0a2892 as getAddressPair, $c3f6c693698dc7cd$export$6c78ccde21ad48f6 as getHDKey, $c3f6c693698dc7cd$export$6fc951b76952b95e as getAddressByPath, $c3f6c693698dc7cd$export$9f993213e5806bf0 as generateMnemonic, $c3f6c693698dc7cd$export$2b99b9ff149202f3 as isMnemonicValid, $c3f6c693698dc7cd$export$f43d70cb4ddd5664 as getAddressByWIF, $c3f6c693698dc7cd$export$4becd65eb23312e6 as entropyToMnemonic, $c3f6c693698dc7cd$export$de190b37be25f71b as generateAddressObject, $c3f6c693698dc7cd$export$e2e336010351d8a8 as generateAddress, $c3f6c693698dc7cd$export$2e2bcd8739ae039 as default};
|
|
133
|
+
export {$c3f6c693698dc7cd$export$23109f16a8a07245 as getCoinType, $c3f6c693698dc7cd$export$6e3ac79f8c0a2892 as getAddressPair, $c3f6c693698dc7cd$export$6c78ccde21ad48f6 as getHDKey, $c3f6c693698dc7cd$export$6fc951b76952b95e as getAddressByPath, $c3f6c693698dc7cd$export$9f993213e5806bf0 as generateMnemonic, $c3f6c693698dc7cd$export$2b99b9ff149202f3 as isMnemonicValid, $c3f6c693698dc7cd$export$f43d70cb4ddd5664 as getAddressByWIF, $c3f6c693698dc7cd$export$4becd65eb23312e6 as entropyToMnemonic, $c3f6c693698dc7cd$export$de190b37be25f71b as generateAddressObject, $c3f6c693698dc7cd$export$462669520a9d12d1 as publicKeyToAddress, $c3f6c693698dc7cd$export$e2e336010351d8a8 as generateAddress, $c3f6c693698dc7cd$export$2e2bcd8739ae039 as default};
|
|
113
134
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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,kBAAkB,0CAAiB,SAAS,OAAO;IACzD,OAAO;QACL,UAAU;QACV,UAAU;kBACV;IACF;AACF;AAEO,SAAS,0CAAS,OAAgB,EAA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M,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;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\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 getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ interface IAddressObject {
|
|
|
3
3
|
address: string;
|
|
4
4
|
mnemonic?: string;
|
|
5
5
|
path: string;
|
|
6
|
+
publicKey: string;
|
|
6
7
|
privateKey: string;
|
|
7
8
|
WIF: string;
|
|
8
9
|
}
|
|
@@ -42,6 +43,7 @@ export function getAddressByWIF(network: Network, privateKeyWIF: string): {
|
|
|
42
43
|
};
|
|
43
44
|
export const entropyToMnemonic: typeof bip39.entropyToMnemonic;
|
|
44
45
|
export function generateAddressObject(network?: Network, passphrase?: string): IAddressObject;
|
|
46
|
+
export function publicKeyToAddress(network: Network, publicKey: Buffer | string): string;
|
|
45
47
|
/**
|
|
46
48
|
* Generates a random Address Object
|
|
47
49
|
*
|
|
@@ -60,6 +62,7 @@ declare const _default: {
|
|
|
60
62
|
getCoinType: typeof getCoinType;
|
|
61
63
|
getHDKey: typeof getHDKey;
|
|
62
64
|
isMnemonicValid: typeof isMnemonicValid;
|
|
65
|
+
publicKeyToAddress: typeof publicKeyToAddress;
|
|
63
66
|
};
|
|
64
67
|
export default _default;
|
|
65
68
|
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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,CAAC;
|
|
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,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,wBAWE","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\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 getAddressPair,\n getCoinType,\n getHDKey,\n isMnemonicValid,\n publicKeyToAddress,\n};\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/index.ts
CHANGED
|
@@ -4,21 +4,23 @@ import { chains } from "@hyperbitjs/chains";
|
|
|
4
4
|
//bip39 from mnemonic to seed
|
|
5
5
|
import * as bip39 from "bip39";
|
|
6
6
|
|
|
7
|
+
import { createHash } from "crypto";
|
|
7
8
|
const CoinKey = require("coinkey");
|
|
8
9
|
|
|
9
10
|
//From seed to key
|
|
10
|
-
|
|
11
|
-
import HDKey from "hdkey";
|
|
11
|
+
const HDKey = require("hdkey");
|
|
12
12
|
import { IAddressObject } from "./types";
|
|
13
|
+
const bs58check = require("bs58check");
|
|
13
14
|
|
|
14
15
|
//Could not declare Network as enum, something wrong with parcel bundler
|
|
15
16
|
export type Network = "xna" | "xna-test";
|
|
16
17
|
|
|
17
18
|
function getNetwork(name: Network) {
|
|
18
|
-
const c = name.toLowerCase(); //Just to be sure
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const c = name.toLowerCase() as Network; //Just to be sure
|
|
20
|
+
const chainData = chains as any;
|
|
21
|
+
const map: Record<Network, any> = {
|
|
22
|
+
xna: chainData.xna.mainnet.versions,
|
|
23
|
+
"xna-test": chainData.xna.testnet?.versions,
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
const network = map[c];
|
|
@@ -90,6 +92,7 @@ export function getAddressByPath(
|
|
|
90
92
|
return {
|
|
91
93
|
address: ck2.publicAddress,
|
|
92
94
|
path: path,
|
|
95
|
+
publicKey: ck2.publicKey.toString("hex"),
|
|
93
96
|
privateKey: ck2.privateKey.toString("hex"),
|
|
94
97
|
WIF: ck2.privateWif,
|
|
95
98
|
};
|
|
@@ -150,6 +153,29 @@ export function generateAddressObject(
|
|
|
150
153
|
return result;
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
export function publicKeyToAddress(
|
|
157
|
+
network: Network,
|
|
158
|
+
publicKey: Buffer | string
|
|
159
|
+
): string {
|
|
160
|
+
const chain = getNetwork(network);
|
|
161
|
+
const keyBuffer = Buffer.isBuffer(publicKey)
|
|
162
|
+
? publicKey
|
|
163
|
+
: Buffer.from(publicKey, "hex");
|
|
164
|
+
|
|
165
|
+
if (keyBuffer.length !== 33 && keyBuffer.length !== 65) {
|
|
166
|
+
throw new Error("Public key must be 33 or 65 bytes");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const sha256Hash = createHash("sha256").update(keyBuffer).digest();
|
|
170
|
+
const ripemd160Hash = createHash("ripemd160").update(sha256Hash).digest();
|
|
171
|
+
const payload = Buffer.concat([
|
|
172
|
+
Buffer.from([chain.public]),
|
|
173
|
+
ripemd160Hash,
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
return bs58check.encode(payload);
|
|
177
|
+
}
|
|
178
|
+
|
|
153
179
|
/**
|
|
154
180
|
* Generates a random Address Object
|
|
155
181
|
*
|
|
@@ -170,4 +196,5 @@ export default {
|
|
|
170
196
|
getCoinType,
|
|
171
197
|
getHDKey,
|
|
172
198
|
isMnemonicValid,
|
|
199
|
+
publicKeyToAddress,
|
|
173
200
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuraiproject/neurai-key",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.5",
|
|
4
4
|
"description": "Generate Neurai addresses from mnemonic code. BIP32, BIP39, BIP44",
|
|
5
5
|
"source": "index.ts",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@hyperbitjs/chains": "^1.2.0",
|
|
31
31
|
"bip39": "^3.0.4",
|
|
32
|
+
"bs58check": "^2.1.2",
|
|
32
33
|
"coinkey": "^3.0.0",
|
|
33
34
|
"hdkey": "^2.0.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@parcel/packager-ts": "^2.10.3",
|
|
37
|
-
|
|
38
|
+
"@parcel/transformer-typescript-types": "^2.16.1",
|
|
38
39
|
"@types/hdkey": "^2.0.3",
|
|
39
40
|
"@types/node": "^18.14.0",
|
|
40
41
|
"browserify": "^17.0.0",
|