@neuraiproject/neurai-key 2.8.5 → 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/LICENSE +1 -1
- package/README.md +32 -1
- package/coins/xna-legacy.js +82 -0
- package/coins/xna.js +82 -0
- package/dist/NeuraiKey.js +459 -3713
- package/dist/main.js +173 -3
- package/dist/main.js.map +1 -1
- package/dist/module.js +173 -4
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/index.ts +19 -2
- package/package.json +5 -6
- package/test.js +15 -5
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");
|
|
@@ -23,12 +22,174 @@ $parcel$export(module.exports, "getAddressByPath", () => $80bd448eb6ea085b$expor
|
|
|
23
22
|
$parcel$export(module.exports, "generateMnemonic", () => $80bd448eb6ea085b$export$9f993213e5806bf0);
|
|
24
23
|
$parcel$export(module.exports, "isMnemonicValid", () => $80bd448eb6ea085b$export$2b99b9ff149202f3);
|
|
25
24
|
$parcel$export(module.exports, "getAddressByWIF", () => $80bd448eb6ea085b$export$f43d70cb4ddd5664);
|
|
25
|
+
$parcel$export(module.exports, "getPubkeyByWIF", () => $80bd448eb6ea085b$export$6ad4fb7ac7584525);
|
|
26
26
|
$parcel$export(module.exports, "entropyToMnemonic", () => $80bd448eb6ea085b$export$4becd65eb23312e6);
|
|
27
27
|
$parcel$export(module.exports, "generateAddressObject", () => $80bd448eb6ea085b$export$de190b37be25f71b);
|
|
28
28
|
$parcel$export(module.exports, "publicKeyToAddress", () => $80bd448eb6ea085b$export$462669520a9d12d1);
|
|
29
29
|
$parcel$export(module.exports, "generateAddress", () => $80bd448eb6ea085b$export$e2e336010351d8a8);
|
|
30
30
|
$parcel$export(module.exports, "default", () => $80bd448eb6ea085b$export$2e2bcd8739ae039);
|
|
31
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
|
+
|
|
32
193
|
|
|
33
194
|
|
|
34
195
|
|
|
@@ -37,10 +198,13 @@ $parcel$export(module.exports, "default", () => $80bd448eb6ea085b$export$2e2bcd8
|
|
|
37
198
|
|
|
38
199
|
function $80bd448eb6ea085b$var$getNetwork(name) {
|
|
39
200
|
const c = name.toLowerCase(); //Just to be sure
|
|
40
|
-
const chainData = (0, $
|
|
201
|
+
const chainData = (0, $af3d93861d966625$exports.chains);
|
|
202
|
+
const legacyChainData = (0, $f755b72afc69c754$exports.chains);
|
|
41
203
|
const map = {
|
|
42
204
|
xna: chainData.xna.mainnet.versions,
|
|
43
|
-
"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
|
|
44
208
|
};
|
|
45
209
|
const network = map[c];
|
|
46
210
|
if (!network) throw new Error("network must be of value " + Object.keys(map).toString());
|
|
@@ -108,6 +272,11 @@ function $80bd448eb6ea085b$export$f43d70cb4ddd5664(network, privateKeyWIF) {
|
|
|
108
272
|
WIF: coinKey.privateWif
|
|
109
273
|
};
|
|
110
274
|
}
|
|
275
|
+
function $80bd448eb6ea085b$export$6ad4fb7ac7584525(network, privateKeyWIF) {
|
|
276
|
+
const coinKey = $g5Y9E$coinkey.fromWif(privateKeyWIF);
|
|
277
|
+
coinKey.versions = $80bd448eb6ea085b$var$getNetwork(network);
|
|
278
|
+
return coinKey.publicKey.toString("hex");
|
|
279
|
+
}
|
|
111
280
|
const $80bd448eb6ea085b$export$4becd65eb23312e6 = $g5Y9E$bip39.entropyToMnemonic;
|
|
112
281
|
function $80bd448eb6ea085b$export$de190b37be25f71b(network = "xna", passphrase = "") {
|
|
113
282
|
const mnemonic = $80bd448eb6ea085b$export$9f993213e5806bf0();
|
|
@@ -145,6 +314,7 @@ var $80bd448eb6ea085b$export$2e2bcd8739ae039 = {
|
|
|
145
314
|
generateMnemonic: $80bd448eb6ea085b$export$9f993213e5806bf0,
|
|
146
315
|
getAddressByPath: $80bd448eb6ea085b$export$6fc951b76952b95e,
|
|
147
316
|
getAddressByWIF: $80bd448eb6ea085b$export$f43d70cb4ddd5664,
|
|
317
|
+
getPubkeyByWIF: $80bd448eb6ea085b$export$6ad4fb7ac7584525,
|
|
148
318
|
getAddressPair: $80bd448eb6ea085b$export$6e3ac79f8c0a2892,
|
|
149
319
|
getCoinType: $80bd448eb6ea085b$export$23109f16a8a07245,
|
|
150
320
|
getHDKey: $80bd448eb6ea085b$export$6c78ccde21ad48f6,
|
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,CAA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AC,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"}
|
|
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;YAC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AAS;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","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, $
|
|
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());
|
|
@@ -85,6 +248,11 @@ function $c3f6c693698dc7cd$export$f43d70cb4ddd5664(network, privateKeyWIF) {
|
|
|
85
248
|
WIF: coinKey.privateWif
|
|
86
249
|
};
|
|
87
250
|
}
|
|
251
|
+
function $c3f6c693698dc7cd$export$6ad4fb7ac7584525(network, privateKeyWIF) {
|
|
252
|
+
const coinKey = $hCgyA$coinkey.fromWif(privateKeyWIF);
|
|
253
|
+
coinKey.versions = $c3f6c693698dc7cd$var$getNetwork(network);
|
|
254
|
+
return coinKey.publicKey.toString("hex");
|
|
255
|
+
}
|
|
88
256
|
const $c3f6c693698dc7cd$export$4becd65eb23312e6 = $hCgyA$entropyToMnemonic;
|
|
89
257
|
function $c3f6c693698dc7cd$export$de190b37be25f71b(network = "xna", passphrase = "") {
|
|
90
258
|
const mnemonic = $c3f6c693698dc7cd$export$9f993213e5806bf0();
|
|
@@ -122,6 +290,7 @@ var $c3f6c693698dc7cd$export$2e2bcd8739ae039 = {
|
|
|
122
290
|
generateMnemonic: $c3f6c693698dc7cd$export$9f993213e5806bf0,
|
|
123
291
|
getAddressByPath: $c3f6c693698dc7cd$export$6fc951b76952b95e,
|
|
124
292
|
getAddressByWIF: $c3f6c693698dc7cd$export$f43d70cb4ddd5664,
|
|
293
|
+
getPubkeyByWIF: $c3f6c693698dc7cd$export$6ad4fb7ac7584525,
|
|
125
294
|
getAddressPair: $c3f6c693698dc7cd$export$6e3ac79f8c0a2892,
|
|
126
295
|
getCoinType: $c3f6c693698dc7cd$export$23109f16a8a07245,
|
|
127
296
|
getHDKey: $c3f6c693698dc7cd$export$6c78ccde21ad48f6,
|
|
@@ -130,5 +299,5 @@ var $c3f6c693698dc7cd$export$2e2bcd8739ae039 = {
|
|
|
130
299
|
};
|
|
131
300
|
|
|
132
301
|
|
|
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};
|
|
302
|
+
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$6ad4fb7ac7584525 as getPubkeyByWIF, $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};
|
|
134
303
|
//# sourceMappingURL=module.js.map
|
package/dist/module.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,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,EA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,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;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"}
|
|
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,MAAM,+BAAS;SACb;AACF;AAEA,4BAAiB;SACf;YACA;AACF;;;;ACjFA;;;CAGC,GAED,MAAM,kCAAY;IAChB,SAAS;QACP,MAAM;QACN,MAAM;QACN,QAAQ;QACR,eAAe;QACf,eAAe;QACf,eAAe;QACf,SAAS;QACT,YAAY;QACZ,IAAI;Q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B,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
|
|
@@ -41,6 +41,12 @@ export function getAddressByWIF(network: Network, privateKeyWIF: string): {
|
|
|
41
41
|
privateKey: any;
|
|
42
42
|
WIF: any;
|
|
43
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* @param privateKeyWIF
|
|
46
|
+
* @param network should be "xna" or "xna-test"
|
|
47
|
+
* @returns the compressed public key as a hex string
|
|
48
|
+
*/
|
|
49
|
+
export function getPubkeyByWIF(network: Network, privateKeyWIF: string): string;
|
|
44
50
|
export const entropyToMnemonic: typeof bip39.entropyToMnemonic;
|
|
45
51
|
export function generateAddressObject(network?: Network, passphrase?: string): IAddressObject;
|
|
46
52
|
export function publicKeyToAddress(network: Network, publicKey: Buffer | string): string;
|
|
@@ -58,6 +64,7 @@ declare const _default: {
|
|
|
58
64
|
generateMnemonic: typeof generateMnemonic;
|
|
59
65
|
getAddressByPath: typeof getAddressByPath;
|
|
60
66
|
getAddressByWIF: typeof getAddressByWIF;
|
|
67
|
+
getPubkeyByWIF: typeof getPubkeyByWIF;
|
|
61
68
|
getAddressPair: typeof getAddressPair;
|
|
62
69
|
getCoinType: typeof getCoinType;
|
|
63
70
|
getHDKey: typeof getHDKey;
|
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,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;
|
|
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"}
|