@metamask-previews/eth-json-rpc-provider 5.0.1-preview-6b15e01 → 5.0.1-preview-e983f054
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 -18
- 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 +43 -63
- package/dist/internal-provider.cjs.map +1 -1
- package/dist/internal-provider.d.cts +16 -21
- package/dist/internal-provider.d.cts.map +1 -1
- package/dist/internal-provider.d.mts +16 -21
- package/dist/internal-provider.d.mts.map +1 -1
- package/dist/internal-provider.mjs +41 -61
- 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 -27
- package/dist/provider-from-middleware.cjs.map +1 -1
- package/dist/provider-from-middleware.d.cts +4 -14
- package/dist/provider-from-middleware.d.cts.map +1 -1
- package/dist/provider-from-middleware.d.mts +4 -14
- package/dist/provider-from-middleware.d.mts.map +1 -1
- package/dist/provider-from-middleware.mjs +6 -26
- package/dist/provider-from-middleware.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,29 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `providerFromMiddlewareV2` ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
13
|
-
- This accepts the new middleware from `@metamask/json-rpc-engine/v2`.
|
|
14
|
-
|
|
15
10
|
### Changed
|
|
16
11
|
|
|
17
12
|
- **BREAKING:** Replace `SafeEventEmitterProvider` with `InternalProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
|
|
18
13
|
- The new class is behaviorally equivalent to the previous version except it does not extend `SafeEventEmitter`.
|
|
19
14
|
- `SafeEventEmitterProvider` is for now still exported as a deprecated alias of `InternalProvider` for backwards compatibility.
|
|
20
|
-
- **BREAKING:** Migrate from `JsonRpcEngine` to `JsonRpcEngineV2` ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
21
|
-
- Legacy `JsonRpcEngine` instances are wrapped in a `JsonRpcEngineV2` internally wherever they appear.
|
|
22
|
-
This change should mostly be unobservable. However, due to differences in error handling, this may be breaking for consumers.
|
|
23
|
-
|
|
24
|
-
### Deprecated
|
|
25
|
-
|
|
26
|
-
- Deprecate `providerFromMiddleware` ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
27
|
-
- Use `providerFromMiddlewareV2` instead, which supports the new middleware from `@metamask/json-rpc-engine/v2`.
|
|
28
|
-
|
|
29
|
-
### Removed
|
|
30
|
-
|
|
31
|
-
- **BREAKING:** Remove `providerFromEngine` ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
32
|
-
- Use `InternalProvider` directly instead.
|
|
33
15
|
|
|
34
16
|
## [5.0.1]
|
|
35
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,12 +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 _InternalProvider_engine
|
|
13
|
+
var _InternalProvider_engine;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
15
|
+
exports.InternalProvider = exports.convertEip1193RequestToJsonRpcRequest = void 0;
|
|
16
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
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;
|
|
19
40
|
/**
|
|
20
41
|
* An Ethereum provider.
|
|
21
42
|
*
|
|
@@ -24,7 +45,7 @@ const nanoid_1 = require("nanoid");
|
|
|
24
45
|
*/
|
|
25
46
|
class InternalProvider {
|
|
26
47
|
/**
|
|
27
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
48
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
28
49
|
*
|
|
29
50
|
* @param options - Options.
|
|
30
51
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
@@ -39,15 +60,14 @@ class InternalProvider {
|
|
|
39
60
|
*
|
|
40
61
|
* @param eip1193Request - The request to send.
|
|
41
62
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
42
|
-
* @deprecated
|
|
43
|
-
* compatibility with certain libraries.
|
|
63
|
+
* @deprecated Please use `request` instead.
|
|
44
64
|
*/
|
|
45
65
|
this.sendAsync = (eip1193Request,
|
|
46
|
-
//
|
|
66
|
+
// TODO: Replace `any` with type
|
|
47
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
68
|
callback) => {
|
|
49
69
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
50
|
-
__classPrivateFieldGet(this,
|
|
70
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
51
71
|
};
|
|
52
72
|
/**
|
|
53
73
|
* Send a provider request asynchronously.
|
|
@@ -57,8 +77,7 @@ class InternalProvider {
|
|
|
57
77
|
*
|
|
58
78
|
* @param eip1193Request - The request to send.
|
|
59
79
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
60
|
-
* @deprecated
|
|
61
|
-
* compatibility with certain libraries.
|
|
80
|
+
* @deprecated Please use `request` instead.
|
|
62
81
|
*/
|
|
63
82
|
this.send = (eip1193Request,
|
|
64
83
|
// TODO: Replace `any` with type
|
|
@@ -68,34 +87,9 @@ class InternalProvider {
|
|
|
68
87
|
throw new Error('Must provide callback to "send" method.');
|
|
69
88
|
}
|
|
70
89
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
71
|
-
__classPrivateFieldGet(this,
|
|
90
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
72
91
|
};
|
|
73
|
-
|
|
74
|
-
const { id, jsonrpc } = jsonRpcRequest;
|
|
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
|
-
const result = (await __classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest));
|
|
78
|
-
return {
|
|
79
|
-
id,
|
|
80
|
-
jsonrpc,
|
|
81
|
-
result,
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
_InternalProvider_handleWithCallback.set(this, (jsonRpcRequest, callback) => {
|
|
85
|
-
/* eslint-disable promise/no-callback-in-promise */
|
|
86
|
-
__classPrivateFieldGet(this, _InternalProvider_handle, "f").call(this, jsonRpcRequest)
|
|
87
|
-
// A resolution will always be a successful response
|
|
88
|
-
.then((response) => callback(null, response))
|
|
89
|
-
.catch((error) => {
|
|
90
|
-
callback(error);
|
|
91
|
-
});
|
|
92
|
-
/* eslint-enable promise/no-callback-in-promise */
|
|
93
|
-
});
|
|
94
|
-
__classPrivateFieldSet(this, _InternalProvider_engine, 'push' in engine
|
|
95
|
-
? v2_1.JsonRpcEngineV2.create({
|
|
96
|
-
middleware: [(0, json_rpc_engine_1.asV2Middleware)(engine)],
|
|
97
|
-
})
|
|
98
|
-
: engine, "f");
|
|
92
|
+
__classPrivateFieldSet(this, _InternalProvider_engine, engine, "f");
|
|
99
93
|
}
|
|
100
94
|
/**
|
|
101
95
|
* Send a provider request asynchronously.
|
|
@@ -105,31 +99,17 @@ class InternalProvider {
|
|
|
105
99
|
*/
|
|
106
100
|
async request(eip1193Request) {
|
|
107
101
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
108
|
-
|
|
102
|
+
const response = await __classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest);
|
|
103
|
+
if ('result' in response) {
|
|
104
|
+
return response.result;
|
|
105
|
+
}
|
|
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;
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
exports.InternalProvider = InternalProvider;
|
|
112
|
-
_InternalProvider_engine = new WeakMap()
|
|
113
|
-
/**
|
|
114
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
115
|
-
*
|
|
116
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
117
|
-
* @returns The JSON-RPC request.
|
|
118
|
-
*/
|
|
119
|
-
function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
120
|
-
const { id = (0, nanoid_1.nanoid)(), jsonrpc = '2.0', method, params } = eip1193Request;
|
|
121
|
-
return params
|
|
122
|
-
? {
|
|
123
|
-
id,
|
|
124
|
-
jsonrpc,
|
|
125
|
-
method,
|
|
126
|
-
params,
|
|
127
|
-
}
|
|
128
|
-
: {
|
|
129
|
-
id,
|
|
130
|
-
jsonrpc,
|
|
131
|
-
method,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
exports.convertEip1193RequestToJsonRpcRequest = convertEip1193RequestToJsonRpcRequest;
|
|
114
|
+
_InternalProvider_engine = new WeakMap();
|
|
135
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,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { JsonRpcEngineV2 } 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
|
*/
|
|
8
|
-
type Eip1193Request<Params extends JsonRpcParams
|
|
6
|
+
type Eip1193Request<Params extends JsonRpcParams> = {
|
|
9
7
|
id?: JsonRpcId;
|
|
10
8
|
jsonrpc?: JsonRpcVersion2;
|
|
11
9
|
method: string;
|
|
12
10
|
params?: Params;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/**
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export declare function convertEip1193RequestToJsonRpcRequest<Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>): JsonRpcRequest<Params | Record<never, never>>;
|
|
17
19
|
/**
|
|
18
20
|
* An Ethereum provider.
|
|
19
21
|
*
|
|
@@ -23,12 +25,14 @@ type Options<Request extends JsonRpcRequest = JsonRpcRequest, Context extends Co
|
|
|
23
25
|
export declare class InternalProvider {
|
|
24
26
|
#private;
|
|
25
27
|
/**
|
|
26
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
28
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
27
29
|
*
|
|
28
30
|
* @param options - Options.
|
|
29
31
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
30
32
|
*/
|
|
31
|
-
constructor({ engine }:
|
|
33
|
+
constructor({ engine }: {
|
|
34
|
+
engine: JsonRpcEngine;
|
|
35
|
+
});
|
|
32
36
|
/**
|
|
33
37
|
* Send a provider request asynchronously.
|
|
34
38
|
*
|
|
@@ -44,8 +48,7 @@ export declare class InternalProvider {
|
|
|
44
48
|
*
|
|
45
49
|
* @param eip1193Request - The request to send.
|
|
46
50
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
47
|
-
* @deprecated
|
|
48
|
-
* compatibility with certain libraries.
|
|
51
|
+
* @deprecated Please use `request` instead.
|
|
49
52
|
*/
|
|
50
53
|
sendAsync: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
51
54
|
/**
|
|
@@ -56,17 +59,9 @@ export declare class InternalProvider {
|
|
|
56
59
|
*
|
|
57
60
|
* @param eip1193Request - The request to send.
|
|
58
61
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
59
|
-
* @deprecated
|
|
60
|
-
* compatibility with certain libraries.
|
|
62
|
+
* @deprecated Please use `request` instead.
|
|
61
63
|
*/
|
|
62
64
|
send: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
63
65
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
66
|
-
*
|
|
67
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
68
|
-
* @returns The JSON-RPC request.
|
|
69
|
-
*/
|
|
70
|
-
export declare function convertEip1193RequestToJsonRpcRequest(eip1193Request: Eip1193Request): JsonRpcRequest;
|
|
71
66
|
export {};
|
|
72
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,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { JsonRpcEngineV2 } 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
|
*/
|
|
8
|
-
type Eip1193Request<Params extends JsonRpcParams
|
|
6
|
+
type Eip1193Request<Params extends JsonRpcParams> = {
|
|
9
7
|
id?: JsonRpcId;
|
|
10
8
|
jsonrpc?: JsonRpcVersion2;
|
|
11
9
|
method: string;
|
|
12
10
|
params?: Params;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/**
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export declare function convertEip1193RequestToJsonRpcRequest<Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>): JsonRpcRequest<Params | Record<never, never>>;
|
|
17
19
|
/**
|
|
18
20
|
* An Ethereum provider.
|
|
19
21
|
*
|
|
@@ -23,12 +25,14 @@ type Options<Request extends JsonRpcRequest = JsonRpcRequest, Context extends Co
|
|
|
23
25
|
export declare class InternalProvider {
|
|
24
26
|
#private;
|
|
25
27
|
/**
|
|
26
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
28
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
27
29
|
*
|
|
28
30
|
* @param options - Options.
|
|
29
31
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
30
32
|
*/
|
|
31
|
-
constructor({ engine }:
|
|
33
|
+
constructor({ engine }: {
|
|
34
|
+
engine: JsonRpcEngine;
|
|
35
|
+
});
|
|
32
36
|
/**
|
|
33
37
|
* Send a provider request asynchronously.
|
|
34
38
|
*
|
|
@@ -44,8 +48,7 @@ export declare class InternalProvider {
|
|
|
44
48
|
*
|
|
45
49
|
* @param eip1193Request - The request to send.
|
|
46
50
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
47
|
-
* @deprecated
|
|
48
|
-
* compatibility with certain libraries.
|
|
51
|
+
* @deprecated Please use `request` instead.
|
|
49
52
|
*/
|
|
50
53
|
sendAsync: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
51
54
|
/**
|
|
@@ -56,17 +59,9 @@ export declare class InternalProvider {
|
|
|
56
59
|
*
|
|
57
60
|
* @param eip1193Request - The request to send.
|
|
58
61
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
59
|
-
* @deprecated
|
|
60
|
-
* compatibility with certain libraries.
|
|
62
|
+
* @deprecated Please use `request` instead.
|
|
61
63
|
*/
|
|
62
64
|
send: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
63
65
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
66
|
-
*
|
|
67
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
68
|
-
* @returns The JSON-RPC request.
|
|
69
|
-
*/
|
|
70
|
-
export declare function convertEip1193RequestToJsonRpcRequest(eip1193Request: Eip1193Request): JsonRpcRequest;
|
|
71
66
|
export {};
|
|
72
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,10 +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 _InternalProvider_engine
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
12
|
+
var _InternalProvider_engine;
|
|
13
|
+
import { JsonRpcError } from "@metamask/rpc-errors";
|
|
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
|
+
}
|
|
16
36
|
/**
|
|
17
37
|
* An Ethereum provider.
|
|
18
38
|
*
|
|
@@ -21,7 +41,7 @@ import { nanoid } from "nanoid";
|
|
|
21
41
|
*/
|
|
22
42
|
export class InternalProvider {
|
|
23
43
|
/**
|
|
24
|
-
* Construct a InternalProvider from a JSON-RPC
|
|
44
|
+
* Construct a InternalProvider from a JSON-RPC engine.
|
|
25
45
|
*
|
|
26
46
|
* @param options - Options.
|
|
27
47
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
@@ -36,15 +56,14 @@ export class InternalProvider {
|
|
|
36
56
|
*
|
|
37
57
|
* @param eip1193Request - The request to send.
|
|
38
58
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
39
|
-
* @deprecated
|
|
40
|
-
* compatibility with certain libraries.
|
|
59
|
+
* @deprecated Please use `request` instead.
|
|
41
60
|
*/
|
|
42
61
|
this.sendAsync = (eip1193Request,
|
|
43
|
-
//
|
|
62
|
+
// TODO: Replace `any` with type
|
|
44
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
64
|
callback) => {
|
|
46
65
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
47
|
-
__classPrivateFieldGet(this,
|
|
66
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
48
67
|
};
|
|
49
68
|
/**
|
|
50
69
|
* Send a provider request asynchronously.
|
|
@@ -54,8 +73,7 @@ export class InternalProvider {
|
|
|
54
73
|
*
|
|
55
74
|
* @param eip1193Request - The request to send.
|
|
56
75
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
57
|
-
* @deprecated
|
|
58
|
-
* compatibility with certain libraries.
|
|
76
|
+
* @deprecated Please use `request` instead.
|
|
59
77
|
*/
|
|
60
78
|
this.send = (eip1193Request,
|
|
61
79
|
// TODO: Replace `any` with type
|
|
@@ -65,34 +83,9 @@ export class InternalProvider {
|
|
|
65
83
|
throw new Error('Must provide callback to "send" method.');
|
|
66
84
|
}
|
|
67
85
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
68
|
-
__classPrivateFieldGet(this,
|
|
86
|
+
__classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest, callback);
|
|
69
87
|
};
|
|
70
|
-
|
|
71
|
-
const { id, jsonrpc } = jsonRpcRequest;
|
|
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
|
-
const result = (await __classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest));
|
|
75
|
-
return {
|
|
76
|
-
id,
|
|
77
|
-
jsonrpc,
|
|
78
|
-
result,
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
_InternalProvider_handleWithCallback.set(this, (jsonRpcRequest, callback) => {
|
|
82
|
-
/* eslint-disable promise/no-callback-in-promise */
|
|
83
|
-
__classPrivateFieldGet(this, _InternalProvider_handle, "f").call(this, jsonRpcRequest)
|
|
84
|
-
// A resolution will always be a successful response
|
|
85
|
-
.then((response) => callback(null, response))
|
|
86
|
-
.catch((error) => {
|
|
87
|
-
callback(error);
|
|
88
|
-
});
|
|
89
|
-
/* eslint-enable promise/no-callback-in-promise */
|
|
90
|
-
});
|
|
91
|
-
__classPrivateFieldSet(this, _InternalProvider_engine, 'push' in engine
|
|
92
|
-
? JsonRpcEngineV2.create({
|
|
93
|
-
middleware: [asV2Middleware(engine)],
|
|
94
|
-
})
|
|
95
|
-
: engine, "f");
|
|
88
|
+
__classPrivateFieldSet(this, _InternalProvider_engine, engine, "f");
|
|
96
89
|
}
|
|
97
90
|
/**
|
|
98
91
|
* Send a provider request asynchronously.
|
|
@@ -102,29 +95,16 @@ export class InternalProvider {
|
|
|
102
95
|
*/
|
|
103
96
|
async request(eip1193Request) {
|
|
104
97
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
_InternalProvider_engine = new WeakMap(), _InternalProvider_handle = new WeakMap(), _InternalProvider_handleWithCallback = new WeakMap();
|
|
109
|
-
/**
|
|
110
|
-
* Convert an EIP-1193 request to a JSON-RPC request.
|
|
111
|
-
*
|
|
112
|
-
* @param eip1193Request - The EIP-1193 request to convert.
|
|
113
|
-
* @returns The JSON-RPC request.
|
|
114
|
-
*/
|
|
115
|
-
export function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
116
|
-
const { id = nanoid(), jsonrpc = '2.0', method, params } = eip1193Request;
|
|
117
|
-
return params
|
|
118
|
-
? {
|
|
119
|
-
id,
|
|
120
|
-
jsonrpc,
|
|
121
|
-
method,
|
|
122
|
-
params,
|
|
98
|
+
const response = await __classPrivateFieldGet(this, _InternalProvider_engine, "f").handle(jsonRpcRequest);
|
|
99
|
+
if ('result' in response) {
|
|
100
|
+
return response.result;
|
|
123
101
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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;
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
129
108
|
}
|
|
109
|
+
_InternalProvider_engine = new WeakMap();
|
|
130
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,40 +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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.
|
|
20
|
-
(0, json_rpc_engine_1.asV2Middleware)(middleware));
|
|
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;
|
|
21
17
|
}
|
|
22
18
|
exports.providerFromMiddleware = providerFromMiddleware;
|
|
23
|
-
/**
|
|
24
|
-
* Construct an Ethereum provider from the given middleware.
|
|
25
|
-
*
|
|
26
|
-
* @param middleware - The middleware to construct a provider from.
|
|
27
|
-
* @returns An Ethereum provider.
|
|
28
|
-
*/
|
|
29
|
-
function providerFromMiddlewareV2(middleware) {
|
|
30
|
-
return new internal_provider_1.InternalProvider({
|
|
31
|
-
engine: v2_1.JsonRpcEngineV2.create({
|
|
32
|
-
// This function is generic in order to accept middleware functions with narrower types than
|
|
33
|
-
// the plain JsonRpcMiddleware<JsonRpcRequest> type. However, since InternalProvider is non-generic,
|
|
34
|
-
// we need to upcast the middleware to avoid a type error.
|
|
35
|
-
middleware: [middleware],
|
|
36
|
-
}),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
exports.providerFromMiddlewareV2 = providerFromMiddlewareV2;
|
|
40
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,21 +1,11 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
5
|
-
import { InternalProvider } from "./internal-provider.cjs";
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
|
+
import type { InternalProvider } from "./internal-provider.cjs";
|
|
6
4
|
/**
|
|
7
5
|
* Construct an Ethereum provider from the given middleware.
|
|
8
6
|
*
|
|
9
7
|
* @param middleware - The middleware to construct a provider from.
|
|
10
8
|
* @returns An Ethereum provider.
|
|
11
|
-
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
12
9
|
*/
|
|
13
|
-
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware:
|
|
14
|
-
/**
|
|
15
|
-
* Construct an Ethereum provider from the given middleware.
|
|
16
|
-
*
|
|
17
|
-
* @param middleware - The middleware to construct a provider from.
|
|
18
|
-
* @returns An Ethereum provider.
|
|
19
|
-
*/
|
|
20
|
-
export declare function providerFromMiddlewareV2<Request extends JsonRpcRequest, Middleware extends JsonRpcMiddleware<Request, ResultConstraint<Request>, ContextConstraint>>(middleware: Middleware): InternalProvider;
|
|
10
|
+
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware: JsonRpcMiddleware<Params, Result>): InternalProvider;
|
|
21
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,21 +1,11 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
5
|
-
import { InternalProvider } from "./internal-provider.mjs";
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
|
+
import type { InternalProvider } from "./internal-provider.mjs";
|
|
6
4
|
/**
|
|
7
5
|
* Construct an Ethereum provider from the given middleware.
|
|
8
6
|
*
|
|
9
7
|
* @param middleware - The middleware to construct a provider from.
|
|
10
8
|
* @returns An Ethereum provider.
|
|
11
|
-
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
12
9
|
*/
|
|
13
|
-
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware:
|
|
14
|
-
/**
|
|
15
|
-
* Construct an Ethereum provider from the given middleware.
|
|
16
|
-
*
|
|
17
|
-
* @param middleware - The middleware to construct a provider from.
|
|
18
|
-
* @returns An Ethereum provider.
|
|
19
|
-
*/
|
|
20
|
-
export declare function providerFromMiddlewareV2<Request extends JsonRpcRequest, Middleware extends JsonRpcMiddleware<Request, ResultConstraint<Request>, ContextConstraint>>(middleware: Middleware): InternalProvider;
|
|
10
|
+
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware: JsonRpcMiddleware<Params, Result>): InternalProvider;
|
|
21
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,35 +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
|
-
// since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.
|
|
17
|
-
asV2Middleware(middleware));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Construct an Ethereum provider from the given middleware.
|
|
21
|
-
*
|
|
22
|
-
* @param middleware - The middleware to construct a provider from.
|
|
23
|
-
* @returns An Ethereum provider.
|
|
24
|
-
*/
|
|
25
|
-
export function providerFromMiddlewareV2(middleware) {
|
|
26
|
-
return new InternalProvider({
|
|
27
|
-
engine: JsonRpcEngineV2.create({
|
|
28
|
-
// This function is generic in order to accept middleware functions with narrower types than
|
|
29
|
-
// the plain JsonRpcMiddleware<JsonRpcRequest> type. However, since InternalProvider is non-generic,
|
|
30
|
-
// we need to upcast the middleware to avoid a type error.
|
|
31
|
-
middleware: [middleware],
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
10
|
+
const engine = new JsonRpcEngine();
|
|
11
|
+
engine.push(middleware);
|
|
12
|
+
const provider = providerFromEngine(engine);
|
|
13
|
+
return provider;
|
|
34
14
|
}
|
|
35
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-e983f054",
|
|
4
4
|
"description": "Create an Ethereum provider using a JSON-RPC engine or middleware",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@metamask/json-rpc-engine": "^10.1.1",
|
|
57
57
|
"@metamask/rpc-errors": "^7.0.2",
|
|
58
58
|
"@metamask/utils": "^11.8.1",
|
|
59
|
-
"
|
|
59
|
+
"uuid": "^8.3.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@ethersproject/providers": "^5.7.0",
|