@metamask-previews/eth-json-rpc-provider 5.0.1-preview-3d5a68a → 5.0.1-preview-607c80f8
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/CHANGELOG.md +0 -9
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/internal-provider.cjs +41 -77
- package/dist/internal-provider.cjs.map +1 -1
- package/dist/internal-provider.d.cts +15 -30
- package/dist/internal-provider.d.cts.map +1 -1
- package/dist/internal-provider.d.mts +15 -30
- package/dist/internal-provider.d.mts.map +1 -1
- package/dist/internal-provider.mjs +39 -75
- package/dist/internal-provider.mjs.map +1 -1
- package/dist/provider-from-engine.cjs +15 -0
- package/dist/provider-from-engine.cjs.map +1 -0
- package/dist/provider-from-engine.d.cts +10 -0
- package/dist/provider-from-engine.d.cts.map +1 -0
- package/dist/provider-from-engine.d.mts +10 -0
- package/dist/provider-from-engine.d.mts.map +1 -0
- package/dist/provider-from-engine.mjs +11 -0
- package/dist/provider-from-engine.mjs.map +1 -0
- package/dist/provider-from-middleware.cjs +6 -17
- package/dist/provider-from-middleware.cjs.map +1 -1
- package/dist/provider-from-middleware.d.cts +3 -12
- package/dist/provider-from-middleware.d.cts.map +1 -1
- package/dist/provider-from-middleware.d.mts +3 -12
- package/dist/provider-from-middleware.d.mts.map +1 -1
- package/dist/provider-from-middleware.mjs +6 -16
- package/dist/provider-from-middleware.mjs.map +1 -1
- package/package.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -12,15 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
12
12
|
- **BREAKING:** Replace `SafeEventEmitterProvider` with `InternalProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
|
|
13
13
|
- The new class is behaviorally equivalent to the previous version except it does not extend `SafeEventEmitter`.
|
|
14
14
|
- `SafeEventEmitterProvider` is for now still exported as a deprecated alias of `InternalProvider` for backwards compatibility.
|
|
15
|
-
- **BREAKING:** Use `JsonRpcServer` instead of `JsonRpcEngine` ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
16
|
-
- Adds a new `server` constructor option to the `InternalProvider` class, mutually exclusive with the now deprecated `engine` option.
|
|
17
|
-
- Legacy `JsonRpcEngine` instances are wrapped in a `JsonRpcServer` internally wherever they appear.
|
|
18
|
-
This change should mostly be unobservable. However, due to differences in error handling, this may be breaking for consumers.
|
|
19
|
-
|
|
20
|
-
### Removed
|
|
21
|
-
|
|
22
|
-
- **BREAKING:** Remove `providerFromEngine` ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
23
|
-
- Use `InternalProvider` directly instead.
|
|
24
15
|
|
|
25
16
|
## [5.0.1]
|
|
26
17
|
|
package/dist/index.cjs
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.SafeEventEmitterProvider = exports.InternalProvider = void 0;
|
|
18
18
|
const internal_provider_1 = require("./internal-provider.cjs");
|
|
19
19
|
Object.defineProperty(exports, "InternalProvider", { enumerable: true, get: function () { return internal_provider_1.InternalProvider; } });
|
|
20
|
+
__exportStar(require("./provider-from-engine.cjs"), exports);
|
|
20
21
|
__exportStar(require("./provider-from-middleware.cjs"), exports);
|
|
21
22
|
const SafeEventEmitterProvider = internal_provider_1.InternalProvider;
|
|
22
23
|
exports.SafeEventEmitterProvider = SafeEventEmitterProvider;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+DAAuD;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+DAAuD;AAW9C,iGAXA,oCAAgB,OAWA;AATzB,6DAAuC;AACvC,iEAA2C;AAM3C,MAAM,wBAAwB,GAAG,oCAAgB,CAAC;AAEvB,4DAAwB","sourcesContent":["import { InternalProvider } from './internal-provider';\n\nexport * from './provider-from-engine';\nexport * from './provider-from-middleware';\n\n/**\n * @deprecated Use {@link InternalProvider} instead.\n */\ntype SafeEventEmitterProvider = InternalProvider;\nconst SafeEventEmitterProvider = InternalProvider;\n\nexport { InternalProvider, SafeEventEmitterProvider };\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,+CAA2C;AAE3C;;GAEG;AACH,KAAK,wBAAwB,GAAG,gBAAgB,CAAC;AACjD,QAAA,MAAM,wBAAwB,yBAAmB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,2CAAuC;AACvC,+CAA2C;AAE3C;;GAEG;AACH,KAAK,wBAAwB,GAAG,gBAAgB,CAAC;AACjD,QAAA,MAAM,wBAAwB,yBAAmB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC"}
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,+CAA2C;AAE3C;;GAEG;AACH,KAAK,wBAAwB,GAAG,gBAAgB,CAAC;AACjD,QAAA,MAAM,wBAAwB,yBAAmB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,2CAAuC;AACvC,+CAA2C;AAE3C;;GAEG;AACH,KAAK,wBAAwB,GAAG,gBAAgB,CAAC;AACjD,QAAA,MAAM,wBAAwB,yBAAmB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,+CAA2C;AAM3C,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC","sourcesContent":["import { InternalProvider } from './internal-provider';\n\nexport * from './provider-from-middleware';\n\n/**\n * @deprecated Use {@link InternalProvider} instead.\n */\ntype SafeEventEmitterProvider = InternalProvider;\nconst SafeEventEmitterProvider = InternalProvider;\n\nexport { InternalProvider, SafeEventEmitterProvider };\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,2CAAuC;AACvC,+CAA2C;AAM3C,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAC","sourcesContent":["import { InternalProvider } from './internal-provider';\n\nexport * from './provider-from-engine';\nexport * from './provider-from-middleware';\n\n/**\n * @deprecated Use {@link InternalProvider} instead.\n */\ntype SafeEventEmitterProvider = InternalProvider;\nconst SafeEventEmitterProvider = InternalProvider;\n\nexport { InternalProvider, SafeEventEmitterProvider };\n"]}
|
|
@@ -10,14 +10,33 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _InternalProvider_engine;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
17
|
-
const v2_1 = require("@metamask/json-rpc-engine/v2");
|
|
15
|
+
exports.InternalProvider = exports.convertEip1193RequestToJsonRpcRequest = void 0;
|
|
18
16
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
19
|
-
const utils_1 = require("@metamask/utils");
|
|
20
17
|
const uuid_1 = require("uuid");
|
|
18
|
+
/**
|
|
19
|
+
* Converts an EIP-1193 request to a JSON-RPC request.
|
|
20
|
+
*
|
|
21
|
+
* @param eip1193Request - The EIP-1193 request to convert.
|
|
22
|
+
* @returns The corresponding JSON-RPC request.
|
|
23
|
+
*/
|
|
24
|
+
function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
25
|
+
const { id = (0, uuid_1.v4)(), jsonrpc = '2.0', method, params } = eip1193Request;
|
|
26
|
+
return params
|
|
27
|
+
? {
|
|
28
|
+
id,
|
|
29
|
+
jsonrpc,
|
|
30
|
+
method,
|
|
31
|
+
params,
|
|
32
|
+
}
|
|
33
|
+
: {
|
|
34
|
+
id,
|
|
35
|
+
jsonrpc,
|
|
36
|
+
method,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.convertEip1193RequestToJsonRpcRequest = convertEip1193RequestToJsonRpcRequest;
|
|
21
40
|
/**
|
|
22
41
|
* An Ethereum provider.
|
|
23
42
|
*
|
|
@@ -26,14 +45,13 @@ const uuid_1 = require("uuid");
|
|
|
26
45
|
*/
|
|
27
46
|
class InternalProvider {
|
|
28
47
|
/**
|
|
29
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
48
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
30
49
|
*
|
|
31
50
|
* @param options - Options.
|
|
32
|
-
* @param options.engine -
|
|
33
|
-
* @param options.server - The JSON-RPC server used to process requests. Mutually exclusive with `engine`.
|
|
51
|
+
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
34
52
|
*/
|
|
35
|
-
constructor(
|
|
36
|
-
|
|
53
|
+
constructor({ engine }) {
|
|
54
|
+
_InternalProvider_engine.set(this, void 0);
|
|
37
55
|
/**
|
|
38
56
|
* Send a provider request asynchronously.
|
|
39
57
|
*
|
|
@@ -42,14 +60,14 @@ class InternalProvider {
|
|
|
42
60
|
*
|
|
43
61
|
* @param eip1193Request - The request to send.
|
|
44
62
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
45
|
-
* @deprecated
|
|
63
|
+
* @deprecated Please use `request` instead.
|
|
46
64
|
*/
|
|
47
65
|
this.sendAsync = (eip1193Request,
|
|
48
|
-
//
|
|
66
|
+
// TODO: Replace `any` with type
|
|
49
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
68
|
callback) => {
|
|
51
69
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
52
|
-
__classPrivateFieldGet(this,
|
|
70
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
53
71
|
};
|
|
54
72
|
/**
|
|
55
73
|
* Send a provider request asynchronously.
|
|
@@ -59,7 +77,7 @@ class InternalProvider {
|
|
|
59
77
|
*
|
|
60
78
|
* @param eip1193Request - The request to send.
|
|
61
79
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
62
|
-
* @deprecated
|
|
80
|
+
* @deprecated Please use `request` instead.
|
|
63
81
|
*/
|
|
64
82
|
this.send = (eip1193Request,
|
|
65
83
|
// TODO: Replace `any` with type
|
|
@@ -69,35 +87,9 @@ class InternalProvider {
|
|
|
69
87
|
throw new Error('Must provide callback to "send" method.');
|
|
70
88
|
}
|
|
71
89
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
72
|
-
__classPrivateFieldGet(this,
|
|
90
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
73
91
|
};
|
|
74
|
-
|
|
75
|
-
// This typecast is technicaly unsafe, but we need it to preserve the provider's
|
|
76
|
-
// public interface, which allows you to typecast results.
|
|
77
|
-
return (await __classPrivateFieldGet(this, _InternalProvider_server, "f").handle(jsonRpcRequest));
|
|
78
|
-
});
|
|
79
|
-
_InternalProvider_handleWithCallback.set(this, (jsonRpcRequest, callback) => {
|
|
80
|
-
/* eslint-disable promise/always-return,promise/no-callback-in-promise */
|
|
81
|
-
__classPrivateFieldGet(this, _InternalProvider_handle, "f").call(this, jsonRpcRequest)
|
|
82
|
-
.then((response) => {
|
|
83
|
-
if ((0, utils_1.hasProperty)(response, 'result')) {
|
|
84
|
-
callback(null, response);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
callback(deserializeError(response.error));
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
.catch((error) => {
|
|
91
|
-
callback(error);
|
|
92
|
-
});
|
|
93
|
-
/* eslint-enable promise/always-return,promise/no-callback-in-promise */
|
|
94
|
-
});
|
|
95
|
-
const serverOrLegacyEngine = 'server' in options ? options.server : options.engine;
|
|
96
|
-
__classPrivateFieldSet(this, _InternalProvider_server, 'push' in serverOrLegacyEngine
|
|
97
|
-
? new v2_1.JsonRpcServer({
|
|
98
|
-
middleware: [(0, json_rpc_engine_1.asV2Middleware)(serverOrLegacyEngine)],
|
|
99
|
-
})
|
|
100
|
-
: serverOrLegacyEngine, "f");
|
|
92
|
+
__classPrivateFieldSet(this, _InternalProvider_engine, engine, "f");
|
|
101
93
|
}
|
|
102
94
|
/**
|
|
103
95
|
* Send a provider request asynchronously.
|
|
@@ -107,45 +99,17 @@ class InternalProvider {
|
|
|
107
99
|
*/
|
|
108
100
|
async request(eip1193Request) {
|
|
109
101
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
110
|
-
const response = await __classPrivateFieldGet(this,
|
|
102
|
+
const response = await __classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest);
|
|
111
103
|
if ('result' in response) {
|
|
112
104
|
return response.result;
|
|
113
105
|
}
|
|
114
|
-
|
|
106
|
+
const error = new rpc_errors_1.JsonRpcError(response.error.code, response.error.message, response.error.data);
|
|
107
|
+
if ('stack' in response.error) {
|
|
108
|
+
error.stack = response.error.stack;
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
113
|
exports.InternalProvider = InternalProvider;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
121
|
-
*
|
|
122
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
123
|
-
* @returns The JSON-RPC request.
|
|
124
|
-
*/
|
|
125
|
-
function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
126
|
-
const { id = (0, uuid_1.v4)(), jsonrpc = '2.0', method, params } = eip1193Request;
|
|
127
|
-
return params
|
|
128
|
-
? {
|
|
129
|
-
id,
|
|
130
|
-
jsonrpc,
|
|
131
|
-
method,
|
|
132
|
-
params,
|
|
133
|
-
}
|
|
134
|
-
: {
|
|
135
|
-
id,
|
|
136
|
-
jsonrpc,
|
|
137
|
-
method,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
exports.convertEip1193RequestToJsonRpcRequest = convertEip1193RequestToJsonRpcRequest;
|
|
141
|
-
/**
|
|
142
|
-
* Deserialize a JSON-RPC error. Ignores the possibility of `stack` property, since this is
|
|
143
|
-
* stripped by `JsonRpcServer`.
|
|
144
|
-
*
|
|
145
|
-
* @param error - The JSON-RPC error to deserialize.
|
|
146
|
-
* @returns The deserialized error.
|
|
147
|
-
*/
|
|
148
|
-
function deserializeError(error) {
|
|
149
|
-
return new rpc_errors_1.JsonRpcError(error.code, error.message, error.data);
|
|
150
|
-
}
|
|
114
|
+
_InternalProvider_engine = new WeakMap();
|
|
151
115
|
//# sourceMappingURL=internal-provider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.cjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"internal-provider.cjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qDAAoD;AAQpD,+BAAoC;AAYpC;;;;;GAKG;AACH,SAAgB,qCAAqC,CAGnD,cAAsC;IAEtC,MAAM,EAAE,EAAE,GAAG,IAAA,SAAM,GAAE,EAAE,OAAO,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAC1E,OAAO,MAAM;QACX,CAAC,CAAC;YACE,EAAE;YACF,OAAO;YACP,MAAM;YACN,MAAM;SACP;QACH,CAAC,CAAC;YACE,EAAE;YACF,OAAO;YACP,MAAM;SACP,CAAC;AACR,CAAC;AAlBD,sFAkBC;AAED;;;;;GAKG;AACH,MAAa,gBAAgB;IAG3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAA6B;QARxC,2CAAuB;QA2ChC;;;;;;;;;WASG;QACH,cAAS,GAAG,CACV,cAAsC;QACtC,gCAAgC;QAChC,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC;QAEF;;;;;;;;;WASG;QACH,SAAI,GAAG,CACL,cAAsC;QACtC,gCAAgC;QAChC,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;aAC5D;YACD,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC;QA7EA,uBAAA,IAAI,4BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CACX,cAAsC;QAEtC,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CAGxC,cAAc,CAAC,CAAC;QAElB,IAAI,QAAQ,IAAI,QAAQ,EAAE;YACxB,OAAO,QAAQ,CAAC,MAAM,CAAC;SACxB;QAED,MAAM,KAAK,GAAG,IAAI,yBAAY,CAC5B,QAAQ,CAAC,KAAK,CAAC,IAAI,EACnB,QAAQ,CAAC,KAAK,CAAC,OAAO,EACtB,QAAQ,CAAC,KAAK,CAAC,IAAI,CACpB,CAAC;QACF,IAAI,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE;YAC7B,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;SACpC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;CA8CF;AAxFD,4CAwFC","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport { JsonRpcError } from '@metamask/rpc-errors';\nimport type {\n Json,\n JsonRpcId,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcVersion2,\n} from '@metamask/utils';\nimport { v4 as uuidV4 } from 'uuid';\n\n/**\n * A JSON-RPC request conforming to the EIP-1193 specification.\n */\ntype Eip1193Request<Params extends JsonRpcParams> = {\n id?: JsonRpcId;\n jsonrpc?: JsonRpcVersion2;\n method: string;\n params?: Params;\n};\n\n/**\n * Converts an EIP-1193 request to a JSON-RPC request.\n *\n * @param eip1193Request - The EIP-1193 request to convert.\n * @returns The corresponding JSON-RPC request.\n */\nexport function convertEip1193RequestToJsonRpcRequest<\n Params extends JsonRpcParams,\n>(\n eip1193Request: Eip1193Request<Params>,\n): JsonRpcRequest<Params | Record<never, never>> {\n const { id = uuidV4(), jsonrpc = '2.0', method, params } = eip1193Request;\n return params\n ? {\n id,\n jsonrpc,\n method,\n params,\n }\n : {\n id,\n jsonrpc,\n method,\n };\n}\n\n/**\n * An Ethereum provider.\n *\n * This provider loosely follows conventions that pre-date EIP-1193.\n * It is not compliant with any Ethereum provider standard.\n */\nexport class InternalProvider {\n readonly #engine: JsonRpcEngine;\n\n /**\n * Construct a InternalProvider from a JSON-RPC engine.\n *\n * @param options - Options.\n * @param options.engine - The JSON-RPC engine used to process requests.\n */\n constructor({ engine }: { engine: JsonRpcEngine }) {\n this.#engine = engine;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * @param eip1193Request - The request to send.\n * @returns The JSON-RPC response.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n eip1193Request: Eip1193Request<Params>,\n ): Promise<Result> {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n const response = await this.#engine.handle<\n Params | Record<never, never>,\n Result\n >(jsonRpcRequest);\n\n if ('result' in response) {\n return response.result;\n }\n\n const error = new JsonRpcError(\n response.error.code,\n response.error.message,\n response.error.data,\n );\n if ('stack' in response.error) {\n error.stack = response.error.stack;\n }\n throw error;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Please use `request` instead.\n */\n sendAsync = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#engine.handle(jsonRpcRequest, callback);\n };\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Please use `request` instead.\n */\n send = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n if (typeof callback !== 'function') {\n throw new Error('Must provide callback to \"send\" method.');\n }\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#engine.handle(jsonRpcRequest, callback);\n };\n}\n"]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { JsonRpcServer } from "@metamask/json-rpc-engine/v2";
|
|
4
|
-
import { type Json, type JsonRpcId, type JsonRpcParams, type JsonRpcRequest, type JsonRpcVersion2 } from "@metamask/utils";
|
|
1
|
+
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcId, JsonRpcParams, JsonRpcRequest, JsonRpcVersion2 } from "@metamask/utils";
|
|
5
3
|
/**
|
|
6
4
|
* A JSON-RPC request conforming to the EIP-1193 specification.
|
|
7
5
|
*/
|
|
@@ -12,35 +10,29 @@ type Eip1193Request<Params extends JsonRpcParams> = {
|
|
|
12
10
|
params?: Params;
|
|
13
11
|
};
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Converts an EIP-1193 request to a JSON-RPC request.
|
|
14
|
+
*
|
|
15
|
+
* @param eip1193Request - The EIP-1193 request to convert.
|
|
16
|
+
* @returns The corresponding JSON-RPC request.
|
|
18
17
|
*/
|
|
19
|
-
export
|
|
20
|
-
type Options<Middleware extends InternalProviderMiddleware> = {
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `server` instead.
|
|
23
|
-
*/
|
|
24
|
-
engine: JsonRpcEngine;
|
|
25
|
-
} | {
|
|
26
|
-
server: JsonRpcServer<Middleware>;
|
|
27
|
-
};
|
|
18
|
+
export declare function convertEip1193RequestToJsonRpcRequest<Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>): JsonRpcRequest<Params | Record<never, never>>;
|
|
28
19
|
/**
|
|
29
20
|
* An Ethereum provider.
|
|
30
21
|
*
|
|
31
22
|
* This provider loosely follows conventions that pre-date EIP-1193.
|
|
32
23
|
* It is not compliant with any Ethereum provider standard.
|
|
33
24
|
*/
|
|
34
|
-
export declare class InternalProvider
|
|
25
|
+
export declare class InternalProvider {
|
|
35
26
|
#private;
|
|
36
27
|
/**
|
|
37
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
28
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
38
29
|
*
|
|
39
30
|
* @param options - Options.
|
|
40
|
-
* @param options.engine -
|
|
41
|
-
* @param options.server - The JSON-RPC server used to process requests. Mutually exclusive with `engine`.
|
|
31
|
+
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
42
32
|
*/
|
|
43
|
-
constructor(
|
|
33
|
+
constructor({ engine }: {
|
|
34
|
+
engine: JsonRpcEngine;
|
|
35
|
+
});
|
|
44
36
|
/**
|
|
45
37
|
* Send a provider request asynchronously.
|
|
46
38
|
*
|
|
@@ -56,7 +48,7 @@ export declare class InternalProvider<Middleware extends InternalProviderMiddlew
|
|
|
56
48
|
*
|
|
57
49
|
* @param eip1193Request - The request to send.
|
|
58
50
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
59
|
-
* @deprecated
|
|
51
|
+
* @deprecated Please use `request` instead.
|
|
60
52
|
*/
|
|
61
53
|
sendAsync: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
62
54
|
/**
|
|
@@ -67,16 +59,9 @@ export declare class InternalProvider<Middleware extends InternalProviderMiddlew
|
|
|
67
59
|
*
|
|
68
60
|
* @param eip1193Request - The request to send.
|
|
69
61
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
70
|
-
* @deprecated
|
|
62
|
+
* @deprecated Please use `request` instead.
|
|
71
63
|
*/
|
|
72
64
|
send: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
73
65
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
76
|
-
*
|
|
77
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
78
|
-
* @returns The JSON-RPC request.
|
|
79
|
-
*/
|
|
80
|
-
export declare function convertEip1193RequestToJsonRpcRequest<Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>): JsonRpcRequest<Params | Record<never, never>>;
|
|
81
66
|
export {};
|
|
82
67
|
//# sourceMappingURL=internal-provider.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.d.cts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"internal-provider.d.cts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAE/D,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAGzB;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,aAAa,IAAI;IAClD,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,MAAM,SAAS,aAAa,EAE5B,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GACrC,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAc/C;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;OAKG;gBACS,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,aAAa,CAAA;KAAE;IAIjD;;;;;OAKG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC;IAuBlB;;;;;;;;;OASG;IACH,SAAS,2FAIW,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAKrD;IAEF;;;;;;;;;OASG;IACH,IAAI,2FAIgB,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAQrD;CACH"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { JsonRpcServer } from "@metamask/json-rpc-engine/v2";
|
|
4
|
-
import { type Json, type JsonRpcId, type JsonRpcParams, type JsonRpcRequest, type JsonRpcVersion2 } from "@metamask/utils";
|
|
1
|
+
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcId, JsonRpcParams, JsonRpcRequest, JsonRpcVersion2 } from "@metamask/utils";
|
|
5
3
|
/**
|
|
6
4
|
* A JSON-RPC request conforming to the EIP-1193 specification.
|
|
7
5
|
*/
|
|
@@ -12,35 +10,29 @@ type Eip1193Request<Params extends JsonRpcParams> = {
|
|
|
12
10
|
params?: Params;
|
|
13
11
|
};
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Converts an EIP-1193 request to a JSON-RPC request.
|
|
14
|
+
*
|
|
15
|
+
* @param eip1193Request - The EIP-1193 request to convert.
|
|
16
|
+
* @returns The corresponding JSON-RPC request.
|
|
18
17
|
*/
|
|
19
|
-
export
|
|
20
|
-
type Options<Middleware extends InternalProviderMiddleware> = {
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `server` instead.
|
|
23
|
-
*/
|
|
24
|
-
engine: JsonRpcEngine;
|
|
25
|
-
} | {
|
|
26
|
-
server: JsonRpcServer<Middleware>;
|
|
27
|
-
};
|
|
18
|
+
export declare function convertEip1193RequestToJsonRpcRequest<Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>): JsonRpcRequest<Params | Record<never, never>>;
|
|
28
19
|
/**
|
|
29
20
|
* An Ethereum provider.
|
|
30
21
|
*
|
|
31
22
|
* This provider loosely follows conventions that pre-date EIP-1193.
|
|
32
23
|
* It is not compliant with any Ethereum provider standard.
|
|
33
24
|
*/
|
|
34
|
-
export declare class InternalProvider
|
|
25
|
+
export declare class InternalProvider {
|
|
35
26
|
#private;
|
|
36
27
|
/**
|
|
37
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
28
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
38
29
|
*
|
|
39
30
|
* @param options - Options.
|
|
40
|
-
* @param options.engine -
|
|
41
|
-
* @param options.server - The JSON-RPC server used to process requests. Mutually exclusive with `engine`.
|
|
31
|
+
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
42
32
|
*/
|
|
43
|
-
constructor(
|
|
33
|
+
constructor({ engine }: {
|
|
34
|
+
engine: JsonRpcEngine;
|
|
35
|
+
});
|
|
44
36
|
/**
|
|
45
37
|
* Send a provider request asynchronously.
|
|
46
38
|
*
|
|
@@ -56,7 +48,7 @@ export declare class InternalProvider<Middleware extends InternalProviderMiddlew
|
|
|
56
48
|
*
|
|
57
49
|
* @param eip1193Request - The request to send.
|
|
58
50
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
59
|
-
* @deprecated
|
|
51
|
+
* @deprecated Please use `request` instead.
|
|
60
52
|
*/
|
|
61
53
|
sendAsync: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
62
54
|
/**
|
|
@@ -67,16 +59,9 @@ export declare class InternalProvider<Middleware extends InternalProviderMiddlew
|
|
|
67
59
|
*
|
|
68
60
|
* @param eip1193Request - The request to send.
|
|
69
61
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
70
|
-
* @deprecated
|
|
62
|
+
* @deprecated Please use `request` instead.
|
|
71
63
|
*/
|
|
72
64
|
send: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
73
65
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
76
|
-
*
|
|
77
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
78
|
-
* @returns The JSON-RPC request.
|
|
79
|
-
*/
|
|
80
|
-
export declare function convertEip1193RequestToJsonRpcRequest<Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>): JsonRpcRequest<Params | Record<never, never>>;
|
|
81
66
|
export {};
|
|
82
67
|
//# sourceMappingURL=internal-provider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.d.mts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"internal-provider.d.mts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAE/D,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAGzB;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,aAAa,IAAI;IAClD,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,MAAM,SAAS,aAAa,EAE5B,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GACrC,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAc/C;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;OAKG;gBACS,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,aAAa,CAAA;KAAE;IAIjD;;;;;OAKG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC;IAuBlB;;;;;;;;;OASG;IACH,SAAS,2FAIW,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAKrD;IAEF;;;;;;;;;OASG;IACH,IAAI,2FAIgB,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAQrD;CACH"}
|
|
@@ -9,12 +9,30 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import { asV2Middleware } from "@metamask/json-rpc-engine";
|
|
14
|
-
import { JsonRpcServer } from "@metamask/json-rpc-engine/v2";
|
|
12
|
+
var _InternalProvider_engine;
|
|
15
13
|
import { JsonRpcError } from "@metamask/rpc-errors";
|
|
16
|
-
import { hasProperty } from "@metamask/utils";
|
|
17
14
|
import { v4 as uuidV4 } from "uuid";
|
|
15
|
+
/**
|
|
16
|
+
* Converts an EIP-1193 request to a JSON-RPC request.
|
|
17
|
+
*
|
|
18
|
+
* @param eip1193Request - The EIP-1193 request to convert.
|
|
19
|
+
* @returns The corresponding JSON-RPC request.
|
|
20
|
+
*/
|
|
21
|
+
export function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
22
|
+
const { id = uuidV4(), jsonrpc = '2.0', method, params } = eip1193Request;
|
|
23
|
+
return params
|
|
24
|
+
? {
|
|
25
|
+
id,
|
|
26
|
+
jsonrpc,
|
|
27
|
+
method,
|
|
28
|
+
params,
|
|
29
|
+
}
|
|
30
|
+
: {
|
|
31
|
+
id,
|
|
32
|
+
jsonrpc,
|
|
33
|
+
method,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
18
36
|
/**
|
|
19
37
|
* An Ethereum provider.
|
|
20
38
|
*
|
|
@@ -23,14 +41,13 @@ import { v4 as uuidV4 } from "uuid";
|
|
|
23
41
|
*/
|
|
24
42
|
export class InternalProvider {
|
|
25
43
|
/**
|
|
26
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
44
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
27
45
|
*
|
|
28
46
|
* @param options - Options.
|
|
29
|
-
* @param options.engine -
|
|
30
|
-
* @param options.server - The JSON-RPC server used to process requests. Mutually exclusive with `engine`.
|
|
47
|
+
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
31
48
|
*/
|
|
32
|
-
constructor(
|
|
33
|
-
|
|
49
|
+
constructor({ engine }) {
|
|
50
|
+
_InternalProvider_engine.set(this, void 0);
|
|
34
51
|
/**
|
|
35
52
|
* Send a provider request asynchronously.
|
|
36
53
|
*
|
|
@@ -39,14 +56,14 @@ export class InternalProvider {
|
|
|
39
56
|
*
|
|
40
57
|
* @param eip1193Request - The request to send.
|
|
41
58
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
42
|
-
* @deprecated
|
|
59
|
+
* @deprecated Please use `request` instead.
|
|
43
60
|
*/
|
|
44
61
|
this.sendAsync = (eip1193Request,
|
|
45
|
-
//
|
|
62
|
+
// TODO: Replace `any` with type
|
|
46
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
64
|
callback) => {
|
|
48
65
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
49
|
-
__classPrivateFieldGet(this,
|
|
66
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
50
67
|
};
|
|
51
68
|
/**
|
|
52
69
|
* Send a provider request asynchronously.
|
|
@@ -56,7 +73,7 @@ export class InternalProvider {
|
|
|
56
73
|
*
|
|
57
74
|
* @param eip1193Request - The request to send.
|
|
58
75
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
59
|
-
* @deprecated
|
|
76
|
+
* @deprecated Please use `request` instead.
|
|
60
77
|
*/
|
|
61
78
|
this.send = (eip1193Request,
|
|
62
79
|
// TODO: Replace `any` with type
|
|
@@ -66,35 +83,9 @@ export class InternalProvider {
|
|
|
66
83
|
throw new Error('Must provide callback to "send" method.');
|
|
67
84
|
}
|
|
68
85
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
69
|
-
__classPrivateFieldGet(this,
|
|
86
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
70
87
|
};
|
|
71
|
-
|
|
72
|
-
// This typecast is technicaly unsafe, but we need it to preserve the provider's
|
|
73
|
-
// public interface, which allows you to typecast results.
|
|
74
|
-
return (await __classPrivateFieldGet(this, _InternalProvider_server, "f").handle(jsonRpcRequest));
|
|
75
|
-
});
|
|
76
|
-
_InternalProvider_handleWithCallback.set(this, (jsonRpcRequest, callback) => {
|
|
77
|
-
/* eslint-disable promise/always-return,promise/no-callback-in-promise */
|
|
78
|
-
__classPrivateFieldGet(this, _InternalProvider_handle, "f").call(this, jsonRpcRequest)
|
|
79
|
-
.then((response) => {
|
|
80
|
-
if (hasProperty(response, 'result')) {
|
|
81
|
-
callback(null, response);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
callback(deserializeError(response.error));
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
.catch((error) => {
|
|
88
|
-
callback(error);
|
|
89
|
-
});
|
|
90
|
-
/* eslint-enable promise/always-return,promise/no-callback-in-promise */
|
|
91
|
-
});
|
|
92
|
-
const serverOrLegacyEngine = 'server' in options ? options.server : options.engine;
|
|
93
|
-
__classPrivateFieldSet(this, _InternalProvider_server, 'push' in serverOrLegacyEngine
|
|
94
|
-
? new JsonRpcServer({
|
|
95
|
-
middleware: [asV2Middleware(serverOrLegacyEngine)],
|
|
96
|
-
})
|
|
97
|
-
: serverOrLegacyEngine, "f");
|
|
88
|
+
__classPrivateFieldSet(this, _InternalProvider_engine, engine, "f");
|
|
98
89
|
}
|
|
99
90
|
/**
|
|
100
91
|
* Send a provider request asynchronously.
|
|
@@ -104,43 +95,16 @@ export class InternalProvider {
|
|
|
104
95
|
*/
|
|
105
96
|
async request(eip1193Request) {
|
|
106
97
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
107
|
-
const response = await __classPrivateFieldGet(this,
|
|
98
|
+
const response = await __classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest);
|
|
108
99
|
if ('result' in response) {
|
|
109
100
|
return response.result;
|
|
110
101
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
_InternalProvider_server = new WeakMap(), _InternalProvider_handle = new WeakMap(), _InternalProvider_handleWithCallback = new WeakMap();
|
|
115
|
-
/**
|
|
116
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
117
|
-
*
|
|
118
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
119
|
-
* @returns The JSON-RPC request.
|
|
120
|
-
*/
|
|
121
|
-
export function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
122
|
-
const { id = uuidV4(), jsonrpc = '2.0', method, params } = eip1193Request;
|
|
123
|
-
return params
|
|
124
|
-
? {
|
|
125
|
-
id,
|
|
126
|
-
jsonrpc,
|
|
127
|
-
method,
|
|
128
|
-
params,
|
|
102
|
+
const error = new JsonRpcError(response.error.code, response.error.message, response.error.data);
|
|
103
|
+
if ('stack' in response.error) {
|
|
104
|
+
error.stack = response.error.stack;
|
|
129
105
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
jsonrpc,
|
|
133
|
-
method,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Deserialize a JSON-RPC error. Ignores the possibility of `stack` property, since this is
|
|
138
|
-
* stripped by `JsonRpcServer`.
|
|
139
|
-
*
|
|
140
|
-
* @param error - The JSON-RPC error to deserialize.
|
|
141
|
-
* @returns The deserialized error.
|
|
142
|
-
*/
|
|
143
|
-
function deserializeError(error) {
|
|
144
|
-
return new JsonRpcError(error.code, error.message, error.data);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
145
108
|
}
|
|
109
|
+
_InternalProvider_engine = new WeakMap();
|
|
146
110
|
//# sourceMappingURL=internal-provider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.mjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"internal-provider.mjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,6BAA6B;AAQpD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAYpC;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CAGnD,cAAsC;IAEtC,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAC1E,OAAO,MAAM;QACX,CAAC,CAAC;YACE,EAAE;YACF,OAAO;YACP,MAAM;YACN,MAAM;SACP;QACH,CAAC,CAAC;YACE,EAAE;YACF,OAAO;YACP,MAAM;SACP,CAAC;AACR,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAG3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAA6B;QARxC,2CAAuB;QA2ChC;;;;;;;;;WASG;QACH,cAAS,GAAG,CACV,cAAsC;QACtC,gCAAgC;QAChC,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC;QAEF;;;;;;;;;WASG;QACH,SAAI,GAAG,CACL,cAAsC;QACtC,gCAAgC;QAChC,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;aAC5D;YACD,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC;QA7EA,uBAAA,IAAI,4BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CACX,cAAsC;QAEtC,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CAGxC,cAAc,CAAC,CAAC;QAElB,IAAI,QAAQ,IAAI,QAAQ,EAAE;YACxB,OAAO,QAAQ,CAAC,MAAM,CAAC;SACxB;QAED,MAAM,KAAK,GAAG,IAAI,YAAY,CAC5B,QAAQ,CAAC,KAAK,CAAC,IAAI,EACnB,QAAQ,CAAC,KAAK,CAAC,OAAO,EACtB,QAAQ,CAAC,KAAK,CAAC,IAAI,CACpB,CAAC;QACF,IAAI,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE;YAC7B,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;SACpC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;CA8CF","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport { JsonRpcError } from '@metamask/rpc-errors';\nimport type {\n Json,\n JsonRpcId,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcVersion2,\n} from '@metamask/utils';\nimport { v4 as uuidV4 } from 'uuid';\n\n/**\n * A JSON-RPC request conforming to the EIP-1193 specification.\n */\ntype Eip1193Request<Params extends JsonRpcParams> = {\n id?: JsonRpcId;\n jsonrpc?: JsonRpcVersion2;\n method: string;\n params?: Params;\n};\n\n/**\n * Converts an EIP-1193 request to a JSON-RPC request.\n *\n * @param eip1193Request - The EIP-1193 request to convert.\n * @returns The corresponding JSON-RPC request.\n */\nexport function convertEip1193RequestToJsonRpcRequest<\n Params extends JsonRpcParams,\n>(\n eip1193Request: Eip1193Request<Params>,\n): JsonRpcRequest<Params | Record<never, never>> {\n const { id = uuidV4(), jsonrpc = '2.0', method, params } = eip1193Request;\n return params\n ? {\n id,\n jsonrpc,\n method,\n params,\n }\n : {\n id,\n jsonrpc,\n method,\n };\n}\n\n/**\n * An Ethereum provider.\n *\n * This provider loosely follows conventions that pre-date EIP-1193.\n * It is not compliant with any Ethereum provider standard.\n */\nexport class InternalProvider {\n readonly #engine: JsonRpcEngine;\n\n /**\n * Construct a InternalProvider from a JSON-RPC engine.\n *\n * @param options - Options.\n * @param options.engine - The JSON-RPC engine used to process requests.\n */\n constructor({ engine }: { engine: JsonRpcEngine }) {\n this.#engine = engine;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * @param eip1193Request - The request to send.\n * @returns The JSON-RPC response.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n eip1193Request: Eip1193Request<Params>,\n ): Promise<Result> {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n const response = await this.#engine.handle<\n Params | Record<never, never>,\n Result\n >(jsonRpcRequest);\n\n if ('result' in response) {\n return response.result;\n }\n\n const error = new JsonRpcError(\n response.error.code,\n response.error.message,\n response.error.data,\n );\n if ('stack' in response.error) {\n error.stack = response.error.stack;\n }\n throw error;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Please use `request` instead.\n */\n sendAsync = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#engine.handle(jsonRpcRequest, callback);\n };\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Please use `request` instead.\n */\n send = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n if (typeof callback !== 'function') {\n throw new Error('Must provide callback to \"send\" method.');\n }\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#engine.handle(jsonRpcRequest, callback);\n };\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.providerFromEngine = void 0;
|
|
4
|
+
const internal_provider_1 = require("./internal-provider.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Construct an Ethereum provider from the given JSON-RPC engine.
|
|
7
|
+
*
|
|
8
|
+
* @param engine - The JSON-RPC engine to construct a provider from.
|
|
9
|
+
* @returns An Ethereum provider.
|
|
10
|
+
*/
|
|
11
|
+
function providerFromEngine(engine) {
|
|
12
|
+
return new internal_provider_1.InternalProvider({ engine });
|
|
13
|
+
}
|
|
14
|
+
exports.providerFromEngine = providerFromEngine;
|
|
15
|
+
//# sourceMappingURL=provider-from-engine.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-from-engine.cjs","sourceRoot":"","sources":["../src/provider-from-engine.ts"],"names":[],"mappings":";;;AAEA,+DAAuD;AAEvD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAqB;IACtD,OAAO,IAAI,oCAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1C,CAAC;AAFD,gDAEC","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\n\nimport { InternalProvider } from './internal-provider';\n\n/**\n * Construct an Ethereum provider from the given JSON-RPC engine.\n *\n * @param engine - The JSON-RPC engine to construct a provider from.\n * @returns An Ethereum provider.\n */\nexport function providerFromEngine(engine: JsonRpcEngine): InternalProvider {\n return new InternalProvider({ engine });\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { InternalProvider } from "./internal-provider.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Construct an Ethereum provider from the given JSON-RPC engine.
|
|
5
|
+
*
|
|
6
|
+
* @param engine - The JSON-RPC engine to construct a provider from.
|
|
7
|
+
* @returns An Ethereum provider.
|
|
8
|
+
*/
|
|
9
|
+
export declare function providerFromEngine(engine: JsonRpcEngine): InternalProvider;
|
|
10
|
+
//# sourceMappingURL=provider-from-engine.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-from-engine.d.cts","sourceRoot":"","sources":["../src/provider-from-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAE1E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { InternalProvider } from "./internal-provider.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Construct an Ethereum provider from the given JSON-RPC engine.
|
|
5
|
+
*
|
|
6
|
+
* @param engine - The JSON-RPC engine to construct a provider from.
|
|
7
|
+
* @returns An Ethereum provider.
|
|
8
|
+
*/
|
|
9
|
+
export declare function providerFromEngine(engine: JsonRpcEngine): InternalProvider;
|
|
10
|
+
//# sourceMappingURL=provider-from-engine.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-from-engine.d.mts","sourceRoot":"","sources":["../src/provider-from-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAE1E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InternalProvider } from "./internal-provider.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Construct an Ethereum provider from the given JSON-RPC engine.
|
|
4
|
+
*
|
|
5
|
+
* @param engine - The JSON-RPC engine to construct a provider from.
|
|
6
|
+
* @returns An Ethereum provider.
|
|
7
|
+
*/
|
|
8
|
+
export function providerFromEngine(engine) {
|
|
9
|
+
return new InternalProvider({ engine });
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=provider-from-engine.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-from-engine.mjs","sourceRoot":"","sources":["../src/provider-from-engine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAqB;IACtD,OAAO,IAAI,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\n\nimport { InternalProvider } from './internal-provider';\n\n/**\n * Construct an Ethereum provider from the given JSON-RPC engine.\n *\n * @param engine - The JSON-RPC engine to construct a provider from.\n * @returns An Ethereum provider.\n */\nexport function providerFromEngine(engine: JsonRpcEngine): InternalProvider {\n return new InternalProvider({ engine });\n}\n"]}
|
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.providerFromMiddleware = void 0;
|
|
4
4
|
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
5
|
-
const
|
|
6
|
-
const internal_provider_1 = require("./internal-provider.cjs");
|
|
5
|
+
const provider_from_engine_1 = require("./provider-from-engine.cjs");
|
|
7
6
|
/**
|
|
8
7
|
* Construct an Ethereum provider from the given middleware.
|
|
9
8
|
*
|
|
10
9
|
* @param middleware - The middleware to construct a provider from.
|
|
11
10
|
* @returns An Ethereum provider.
|
|
12
|
-
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
13
11
|
*/
|
|
14
12
|
function providerFromMiddleware(middleware) {
|
|
15
|
-
|
|
13
|
+
const engine = new json_rpc_engine_1.JsonRpcEngine();
|
|
14
|
+
engine.push(middleware);
|
|
15
|
+
const provider = (0, provider_from_engine_1.providerFromEngine)(engine);
|
|
16
|
+
return provider;
|
|
16
17
|
}
|
|
17
18
|
exports.providerFromMiddleware = providerFromMiddleware;
|
|
18
|
-
/**
|
|
19
|
-
* Construct an Ethereum provider from the given middleware.
|
|
20
|
-
*
|
|
21
|
-
* @param middleware - The middleware to construct a provider from.
|
|
22
|
-
* @returns An Ethereum provider.
|
|
23
|
-
*/
|
|
24
|
-
function providerFromMiddlewareV2(middleware) {
|
|
25
|
-
return new internal_provider_1.InternalProvider({
|
|
26
|
-
server: new v2_1.JsonRpcServer({ middleware: [middleware] }),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
exports.providerFromMiddlewareV2 = providerFromMiddlewareV2;
|
|
30
19
|
//# sourceMappingURL=provider-from-middleware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.cjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.cjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAK1D,qEAA4D;AAE5D;;;;;GAKG;AACH,SAAgB,sBAAsB,CAGpC,UAA6C;IAC7C,MAAM,MAAM,GAAkB,IAAI,+BAAa,EAAE,CAAC;IAClD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxB,MAAM,QAAQ,GAAqB,IAAA,yCAAkB,EAAC,MAAM,CAAC,CAAC;IAC9D,OAAO,QAAQ,CAAC;AAClB,CAAC;AARD,wDAQC","sourcesContent":["import { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport type { InternalProvider } from './internal-provider';\nimport { providerFromEngine } from './provider-from-engine';\n\n/**\n * Construct an Ethereum provider from the given middleware.\n *\n * @param middleware - The middleware to construct a provider from.\n * @returns An Ethereum provider.\n */\nexport function providerFromMiddleware<\n Params extends JsonRpcParams,\n Result extends Json,\n>(middleware: JsonRpcMiddleware<Params, Result>): InternalProvider {\n const engine: JsonRpcEngine = new JsonRpcEngine();\n engine.push(middleware);\n const provider: InternalProvider = providerFromEngine(engine);\n return provider;\n}\n"]}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
2
|
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
|
-
import type {
|
|
4
|
-
import { InternalProvider } from "./internal-provider.cjs";
|
|
3
|
+
import type { InternalProvider } from "./internal-provider.cjs";
|
|
5
4
|
/**
|
|
6
5
|
* Construct an Ethereum provider from the given middleware.
|
|
7
6
|
*
|
|
8
7
|
* @param middleware - The middleware to construct a provider from.
|
|
9
8
|
* @returns An Ethereum provider.
|
|
10
|
-
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
11
9
|
*/
|
|
12
|
-
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware:
|
|
13
|
-
/**
|
|
14
|
-
* Construct an Ethereum provider from the given middleware.
|
|
15
|
-
*
|
|
16
|
-
* @param middleware - The middleware to construct a provider from.
|
|
17
|
-
* @returns An Ethereum provider.
|
|
18
|
-
*/
|
|
19
|
-
export declare function providerFromMiddlewareV2<Middleware extends InternalProviderMiddleware>(middleware: Middleware): InternalProvider;
|
|
10
|
+
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware: JsonRpcMiddleware<Params, Result>): InternalProvider;
|
|
20
11
|
//# sourceMappingURL=provider-from-middleware.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.d.cts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.d.cts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAA4B;AAG5D;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,UAAU,EAAE,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAKjE"}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
2
|
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
|
-
import type {
|
|
4
|
-
import { InternalProvider } from "./internal-provider.mjs";
|
|
3
|
+
import type { InternalProvider } from "./internal-provider.mjs";
|
|
5
4
|
/**
|
|
6
5
|
* Construct an Ethereum provider from the given middleware.
|
|
7
6
|
*
|
|
8
7
|
* @param middleware - The middleware to construct a provider from.
|
|
9
8
|
* @returns An Ethereum provider.
|
|
10
|
-
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
11
9
|
*/
|
|
12
|
-
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware:
|
|
13
|
-
/**
|
|
14
|
-
* Construct an Ethereum provider from the given middleware.
|
|
15
|
-
*
|
|
16
|
-
* @param middleware - The middleware to construct a provider from.
|
|
17
|
-
* @returns An Ethereum provider.
|
|
18
|
-
*/
|
|
19
|
-
export declare function providerFromMiddlewareV2<Middleware extends InternalProviderMiddleware>(middleware: Middleware): InternalProvider;
|
|
10
|
+
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware: JsonRpcMiddleware<Params, Result>): InternalProvider;
|
|
20
11
|
//# sourceMappingURL=provider-from-middleware.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.d.mts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.d.mts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAA4B;AAG5D;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,UAAU,EAAE,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAKjE"}
|
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { InternalProvider } from "./internal-provider.mjs";
|
|
1
|
+
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { providerFromEngine } from "./provider-from-engine.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Construct an Ethereum provider from the given middleware.
|
|
6
5
|
*
|
|
7
6
|
* @param middleware - The middleware to construct a provider from.
|
|
8
7
|
* @returns An Ethereum provider.
|
|
9
|
-
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
10
8
|
*/
|
|
11
9
|
export function providerFromMiddleware(middleware) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* @param middleware - The middleware to construct a provider from.
|
|
18
|
-
* @returns An Ethereum provider.
|
|
19
|
-
*/
|
|
20
|
-
export function providerFromMiddlewareV2(middleware) {
|
|
21
|
-
return new InternalProvider({
|
|
22
|
-
server: new JsonRpcServer({ middleware: [middleware] }),
|
|
23
|
-
});
|
|
10
|
+
const engine = new JsonRpcEngine();
|
|
11
|
+
engine.push(middleware);
|
|
12
|
+
const provider = providerFromEngine(engine);
|
|
13
|
+
return provider;
|
|
24
14
|
}
|
|
25
15
|
//# sourceMappingURL=provider-from-middleware.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.mjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.mjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAK1D,OAAO,EAAE,kBAAkB,EAAE,mCAA+B;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAGpC,UAA6C;IAC7C,MAAM,MAAM,GAAkB,IAAI,aAAa,EAAE,CAAC;IAClD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxB,MAAM,QAAQ,GAAqB,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC9D,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport type { InternalProvider } from './internal-provider';\nimport { providerFromEngine } from './provider-from-engine';\n\n/**\n * Construct an Ethereum provider from the given middleware.\n *\n * @param middleware - The middleware to construct a provider from.\n * @returns An Ethereum provider.\n */\nexport function providerFromMiddleware<\n Params extends JsonRpcParams,\n Result extends Json,\n>(middleware: JsonRpcMiddleware<Params, Result>): InternalProvider {\n const engine: JsonRpcEngine = new JsonRpcEngine();\n engine.push(middleware);\n const provider: InternalProvider = providerFromEngine(engine);\n return provider;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/eth-json-rpc-provider",
|
|
3
|
-
"version": "5.0.1-preview-
|
|
3
|
+
"version": "5.0.1-preview-607c80f8",
|
|
4
4
|
"description": "Create an Ethereum provider using a JSON-RPC engine or middleware",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
39
|
-
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
40
39
|
"build:docs": "typedoc",
|
|
41
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-json-rpc-provider",
|
|
42
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-json-rpc-provider",
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
"@metamask/auto-changelog": "^3.4.4",
|
|
64
63
|
"@metamask/eth-query": "^4.0.0",
|
|
65
64
|
"@metamask/ethjs-query": "^0.5.3",
|
|
66
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
67
65
|
"@types/jest": "^27.4.1",
|
|
68
66
|
"deepmerge": "^4.2.2",
|
|
69
67
|
"ethers": "^6.12.0",
|