@metamask-previews/eth-json-rpc-provider 5.0.1-preview-607c80f8 → 5.0.1-preview-684a40c0
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 +18 -0
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal-provider.cjs +63 -43
- package/dist/internal-provider.cjs.map +1 -1
- package/dist/internal-provider.d.cts +21 -16
- package/dist/internal-provider.d.cts.map +1 -1
- package/dist/internal-provider.d.mts +21 -16
- package/dist/internal-provider.d.mts.map +1 -1
- package/dist/internal-provider.mjs +61 -41
- package/dist/internal-provider.mjs.map +1 -1
- package/dist/provider-from-middleware.cjs +27 -6
- package/dist/provider-from-middleware.cjs.map +1 -1
- package/dist/provider-from-middleware.d.cts +14 -4
- package/dist/provider-from-middleware.d.cts.map +1 -1
- package/dist/provider-from-middleware.d.mts +14 -4
- package/dist/provider-from-middleware.d.mts.map +1 -1
- package/dist/provider-from-middleware.mjs +26 -6
- package/dist/provider-from-middleware.mjs.map +1 -1
- package/package.json +4 -2
- package/dist/provider-from-engine.cjs +0 -15
- package/dist/provider-from-engine.cjs.map +0 -1
- package/dist/provider-from-engine.d.cts +0 -10
- package/dist/provider-from-engine.d.cts.map +0 -1
- package/dist/provider-from-engine.d.mts +0 -10
- package/dist/provider-from-engine.d.mts.map +0 -1
- package/dist/provider-from-engine.mjs +0 -11
- package/dist/provider-from-engine.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,29 @@ 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
|
+
|
|
10
15
|
### Changed
|
|
11
16
|
|
|
12
17
|
- **BREAKING:** Replace `SafeEventEmitterProvider` with `InternalProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
|
|
13
18
|
- The new class is behaviorally equivalent to the previous version except it does not extend `SafeEventEmitter`.
|
|
14
19
|
- `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.
|
|
15
33
|
|
|
16
34
|
## [5.0.1]
|
|
17
35
|
|
package/dist/index.cjs
CHANGED
|
@@ -17,7 +17,6 @@ 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);
|
|
21
20
|
__exportStar(require("./provider-from-middleware.cjs"), exports);
|
|
22
21
|
const SafeEventEmitterProvider = internal_provider_1.InternalProvider;
|
|
23
22
|
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;AAU9C,iGAVA,oCAAgB,OAUA;AARzB,iEAA2C;AAM3C,MAAM,wBAAwB,GAAG,oCAAgB,CAAC;AAEvB,4DAAwB","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"]}
|
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
|
|
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"}
|
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
|
|
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"}
|
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
|
|
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"]}
|
|
@@ -10,33 +10,12 @@ 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, _InternalProvider_handle, _InternalProvider_handleWithCallback;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
const
|
|
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;
|
|
15
|
+
exports.convertEip1193RequestToJsonRpcRequest = exports.InternalProvider = void 0;
|
|
16
|
+
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
17
|
+
const v2_1 = require("@metamask/json-rpc-engine/v2");
|
|
18
|
+
const nanoid_1 = require("nanoid");
|
|
40
19
|
/**
|
|
41
20
|
* An Ethereum provider.
|
|
42
21
|
*
|
|
@@ -45,7 +24,7 @@ exports.convertEip1193RequestToJsonRpcRequest = convertEip1193RequestToJsonRpcRe
|
|
|
45
24
|
*/
|
|
46
25
|
class InternalProvider {
|
|
47
26
|
/**
|
|
48
|
-
* Construct a InternalProvider from a JSON-RPC engine.
|
|
27
|
+
* Construct a InternalProvider from a JSON-RPC server or legacy engine.
|
|
49
28
|
*
|
|
50
29
|
* @param options - Options.
|
|
51
30
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
@@ -60,14 +39,15 @@ class InternalProvider {
|
|
|
60
39
|
*
|
|
61
40
|
* @param eip1193Request - The request to send.
|
|
62
41
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
63
|
-
* @deprecated
|
|
42
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
43
|
+
* compatibility with certain libraries.
|
|
64
44
|
*/
|
|
65
45
|
this.sendAsync = (eip1193Request,
|
|
66
|
-
//
|
|
46
|
+
// Non-polluting `any` that acts like a constraint.
|
|
67
47
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
48
|
callback) => {
|
|
69
49
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
70
|
-
__classPrivateFieldGet(this,
|
|
50
|
+
__classPrivateFieldGet(this, _InternalProvider_handleWithCallback, "f").call(this, jsonRpcRequest, callback);
|
|
71
51
|
};
|
|
72
52
|
/**
|
|
73
53
|
* Send a provider request asynchronously.
|
|
@@ -77,7 +57,8 @@ class InternalProvider {
|
|
|
77
57
|
*
|
|
78
58
|
* @param eip1193Request - The request to send.
|
|
79
59
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
80
|
-
* @deprecated
|
|
60
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
61
|
+
* compatibility with certain libraries.
|
|
81
62
|
*/
|
|
82
63
|
this.send = (eip1193Request,
|
|
83
64
|
// TODO: Replace `any` with type
|
|
@@ -87,9 +68,34 @@ class InternalProvider {
|
|
|
87
68
|
throw new Error('Must provide callback to "send" method.');
|
|
88
69
|
}
|
|
89
70
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
90
|
-
__classPrivateFieldGet(this,
|
|
71
|
+
__classPrivateFieldGet(this, _InternalProvider_handleWithCallback, "f").call(this, jsonRpcRequest, callback);
|
|
91
72
|
};
|
|
92
|
-
|
|
73
|
+
_InternalProvider_handle.set(this, async (jsonRpcRequest) => {
|
|
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");
|
|
93
99
|
}
|
|
94
100
|
/**
|
|
95
101
|
* Send a provider request asynchronously.
|
|
@@ -99,17 +105,31 @@ class InternalProvider {
|
|
|
99
105
|
*/
|
|
100
106
|
async request(eip1193Request) {
|
|
101
107
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
102
|
-
|
|
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;
|
|
108
|
+
return (await __classPrivateFieldGet(this, _InternalProvider_handle, "f").call(this, jsonRpcRequest)).result;
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
exports.InternalProvider = InternalProvider;
|
|
114
|
-
_InternalProvider_engine = new WeakMap();
|
|
112
|
+
_InternalProvider_engine = new WeakMap(), _InternalProvider_handle = new WeakMap(), _InternalProvider_handleWithCallback = 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;
|
|
115
135
|
//# 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":";;;;;;;;;;;;;;;AAAA,+DAA+E;AAK/E,qDAA+D;AAS/D,mCAAgC;AAmBhC;;;;;GAKG;AACH,MAAa,gBAAgB;IAG3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAW;QARtB,2CAA4D;QA+BrE;;;;;;;;;;WAUG;QACH,cAAS,GAAG,CACV,cAAsC;QACtC,mDAAmD;QACnD,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,4CAAoB,MAAxB,IAAI,EAAqB,cAAc,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC;QAEF;;;;;;;;;;WAUG;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,4CAAoB,MAAxB,IAAI,EAAqB,cAAc,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC;QAEO,mCAAU,KAAK,EACtB,cAA8B,EACG,EAAE;YACnC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;YACvC,gFAAgF;YAChF,0DAA0D;YAC1D,MAAM,MAAM,GAAG,CAAC,MAAM,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CACvC,cAAc,CACf,CAAsB,CAAC;YAExB,OAAO;gBACL,EAAE;gBACF,OAAO;gBACP,MAAM;aACP,CAAC;QACJ,CAAC,EAAC;QAEO,+CAAsB,CAC7B,cAA8B,EAC9B,QAAyD,EACnD,EAAE;YACR,mDAAmD;YACnD,uBAAA,IAAI,gCAAQ,MAAZ,IAAI,EAAS,cAAc,CAAC;gBAC1B,oDAAoD;iBACnD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;iBAC5C,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACf,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;YACL,kDAAkD;QACpD,CAAC,EAAC;QAlGA,uBAAA,IAAI,4BACF,MAAM,IAAI,MAAM;YACd,CAAC,CAAC,oBAAe,CAAC,MAAM,CAAC;gBACrB,UAAU,EAAE,CAAC,IAAA,gCAAc,EAAgC,MAAM,CAAC,CAAC;aACpE,CAAC;YACJ,CAAC,CAAC,MAAM,MAAA,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CACX,cAAsC;QAEtC,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;QACxD,OAAO,CAAC,MAAM,uBAAA,IAAI,gCAAQ,MAAZ,IAAI,EAAiB,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7D,CAAC;CA+EF;AA7GD,4CA6GC;;AAED;;;;;GAKG;AACH,SAAgB,qCAAqC,CACnD,cAA8B;IAE9B,MAAM,EAAE,EAAE,GAAG,IAAA,eAAM,GAAE,EAAE,OAAO,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAE1E,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;AAjBD,sFAiBC","sourcesContent":["import { asV2Middleware, type JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type {\n ContextConstraint,\n MiddlewareContext,\n} from '@metamask/json-rpc-engine/v2';\nimport { JsonRpcEngineV2 } from '@metamask/json-rpc-engine/v2';\nimport type { JsonRpcSuccess } from '@metamask/utils';\nimport {\n type Json,\n type JsonRpcId,\n type JsonRpcParams,\n type JsonRpcRequest,\n type JsonRpcVersion2,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\n/**\n * A JSON-RPC request conforming to the EIP-1193 specification.\n */\ntype Eip1193Request<Params extends JsonRpcParams = JsonRpcParams> = {\n id?: JsonRpcId;\n jsonrpc?: JsonRpcVersion2;\n method: string;\n params?: Params;\n};\n\ntype Options<\n Request extends JsonRpcRequest = JsonRpcRequest,\n Context extends ContextConstraint = MiddlewareContext,\n> = {\n engine: JsonRpcEngine | JsonRpcEngineV2<Request, Context>;\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: JsonRpcEngineV2<JsonRpcRequest, MiddlewareContext>;\n\n /**\n * Construct a InternalProvider from a JSON-RPC server or legacy engine.\n *\n * @param options - Options.\n * @param options.engine - The JSON-RPC engine used to process requests.\n */\n constructor({ engine }: Options) {\n this.#engine =\n 'push' in engine\n ? JsonRpcEngineV2.create({\n middleware: [asV2Middleware<JsonRpcParams, JsonRpcRequest>(engine)],\n })\n : 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 return (await this.#handle<Result>(jsonRpcRequest)).result;\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 Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\n */\n sendAsync = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // Non-polluting `any` that acts like a constraint.\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.#handleWithCallback(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 Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\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.#handleWithCallback(jsonRpcRequest, callback);\n };\n\n readonly #handle = async <Result extends Json>(\n jsonRpcRequest: JsonRpcRequest,\n ): Promise<JsonRpcSuccess<Result>> => {\n const { id, jsonrpc } = jsonRpcRequest;\n // This typecast is technicaly unsafe, but we need it to preserve the provider's\n // public interface, which allows you to typecast results.\n const result = (await this.#engine.handle(\n jsonRpcRequest,\n )) as unknown as Result;\n\n return {\n id,\n jsonrpc,\n result,\n };\n };\n\n readonly #handleWithCallback = (\n jsonRpcRequest: JsonRpcRequest,\n callback: (error: unknown, providerRes?: unknown) => void,\n ): void => {\n /* eslint-disable promise/no-callback-in-promise */\n this.#handle(jsonRpcRequest)\n // A resolution will always be a successful response\n .then((response) => callback(null, response))\n .catch((error) => {\n callback(error);\n });\n /* eslint-enable promise/no-callback-in-promise */\n };\n}\n\n/**\n * Convert an EIP-1193 request to a JSON-RPC request.\n *\n * @param eip1193Request - The EIP-1193 request to convert.\n * @returns The JSON-RPC request.\n */\nexport function convertEip1193RequestToJsonRpcRequest(\n eip1193Request: Eip1193Request,\n): JsonRpcRequest {\n const { id = nanoid(), jsonrpc = '2.0', method, params } = eip1193Request;\n\n return params\n ? {\n id,\n jsonrpc,\n method,\n params,\n }\n : {\n id,\n jsonrpc,\n method,\n };\n}\n"]}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import { type JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { ContextConstraint, MiddlewareContext } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import { JsonRpcEngineV2 } from "@metamask/json-rpc-engine/v2";
|
|
4
|
+
import { type Json, type JsonRpcId, type JsonRpcParams, type JsonRpcRequest, type JsonRpcVersion2 } from "@metamask/utils";
|
|
3
5
|
/**
|
|
4
6
|
* A JSON-RPC request conforming to the EIP-1193 specification.
|
|
5
7
|
*/
|
|
6
|
-
type Eip1193Request<Params extends JsonRpcParams> = {
|
|
8
|
+
type Eip1193Request<Params extends JsonRpcParams = JsonRpcParams> = {
|
|
7
9
|
id?: JsonRpcId;
|
|
8
10
|
jsonrpc?: JsonRpcVersion2;
|
|
9
11
|
method: string;
|
|
10
12
|
params?: Params;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
|
|
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>>;
|
|
14
|
+
type Options<Request extends JsonRpcRequest = JsonRpcRequest, Context extends ContextConstraint = MiddlewareContext> = {
|
|
15
|
+
engine: JsonRpcEngine | JsonRpcEngineV2<Request, Context>;
|
|
16
|
+
};
|
|
19
17
|
/**
|
|
20
18
|
* An Ethereum provider.
|
|
21
19
|
*
|
|
@@ -25,14 +23,12 @@ export declare function convertEip1193RequestToJsonRpcRequest<Params extends Jso
|
|
|
25
23
|
export declare class InternalProvider {
|
|
26
24
|
#private;
|
|
27
25
|
/**
|
|
28
|
-
* Construct a InternalProvider from a JSON-RPC engine.
|
|
26
|
+
* Construct a InternalProvider from a JSON-RPC server or legacy engine.
|
|
29
27
|
*
|
|
30
28
|
* @param options - Options.
|
|
31
29
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
32
30
|
*/
|
|
33
|
-
constructor({ engine }:
|
|
34
|
-
engine: JsonRpcEngine;
|
|
35
|
-
});
|
|
31
|
+
constructor({ engine }: Options);
|
|
36
32
|
/**
|
|
37
33
|
* Send a provider request asynchronously.
|
|
38
34
|
*
|
|
@@ -48,7 +44,8 @@ export declare class InternalProvider {
|
|
|
48
44
|
*
|
|
49
45
|
* @param eip1193Request - The request to send.
|
|
50
46
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
51
|
-
* @deprecated
|
|
47
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
48
|
+
* compatibility with certain libraries.
|
|
52
49
|
*/
|
|
53
50
|
sendAsync: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
54
51
|
/**
|
|
@@ -59,9 +56,17 @@ export declare class InternalProvider {
|
|
|
59
56
|
*
|
|
60
57
|
* @param eip1193Request - The request to send.
|
|
61
58
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
62
|
-
* @deprecated
|
|
59
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
60
|
+
* compatibility with certain libraries.
|
|
63
61
|
*/
|
|
64
62
|
send: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
65
63
|
}
|
|
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;
|
|
66
71
|
export {};
|
|
67
72
|
//# 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,KAAK,
|
|
1
|
+
{"version":3,"file":"internal-provider.d.cts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,aAAa,EAAE,kCAAkC;AAC/E,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,qCAAqC;AACtC,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAE/D,OAAO,EACL,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,wBAAwB;AAGzB;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAAI;IAClE,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,KAAK,OAAO,CACV,OAAO,SAAS,cAAc,GAAG,cAAc,EAC/C,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,IACnD;IACF,MAAM,EAAE,aAAa,GAAG,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;OAKG;gBACS,EAAE,MAAM,EAAE,EAAE,OAAO;IAS/B;;;;;OAKG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC;IAMlB;;;;;;;;;;OAUG;IACH,SAAS,2FAIW,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAKrD;IAEF;;;;;;;;;;OAUG;IACH,IAAI,2FAIgB,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAQrD;CAgCH;AAED;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,cAAc,EAAE,cAAc,GAC7B,cAAc,CAehB"}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import { type JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { ContextConstraint, MiddlewareContext } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import { JsonRpcEngineV2 } from "@metamask/json-rpc-engine/v2";
|
|
4
|
+
import { type Json, type JsonRpcId, type JsonRpcParams, type JsonRpcRequest, type JsonRpcVersion2 } from "@metamask/utils";
|
|
3
5
|
/**
|
|
4
6
|
* A JSON-RPC request conforming to the EIP-1193 specification.
|
|
5
7
|
*/
|
|
6
|
-
type Eip1193Request<Params extends JsonRpcParams> = {
|
|
8
|
+
type Eip1193Request<Params extends JsonRpcParams = JsonRpcParams> = {
|
|
7
9
|
id?: JsonRpcId;
|
|
8
10
|
jsonrpc?: JsonRpcVersion2;
|
|
9
11
|
method: string;
|
|
10
12
|
params?: Params;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
|
|
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>>;
|
|
14
|
+
type Options<Request extends JsonRpcRequest = JsonRpcRequest, Context extends ContextConstraint = MiddlewareContext> = {
|
|
15
|
+
engine: JsonRpcEngine | JsonRpcEngineV2<Request, Context>;
|
|
16
|
+
};
|
|
19
17
|
/**
|
|
20
18
|
* An Ethereum provider.
|
|
21
19
|
*
|
|
@@ -25,14 +23,12 @@ export declare function convertEip1193RequestToJsonRpcRequest<Params extends Jso
|
|
|
25
23
|
export declare class InternalProvider {
|
|
26
24
|
#private;
|
|
27
25
|
/**
|
|
28
|
-
* Construct a InternalProvider from a JSON-RPC engine.
|
|
26
|
+
* Construct a InternalProvider from a JSON-RPC server or legacy engine.
|
|
29
27
|
*
|
|
30
28
|
* @param options - Options.
|
|
31
29
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
32
30
|
*/
|
|
33
|
-
constructor({ engine }:
|
|
34
|
-
engine: JsonRpcEngine;
|
|
35
|
-
});
|
|
31
|
+
constructor({ engine }: Options);
|
|
36
32
|
/**
|
|
37
33
|
* Send a provider request asynchronously.
|
|
38
34
|
*
|
|
@@ -48,7 +44,8 @@ export declare class InternalProvider {
|
|
|
48
44
|
*
|
|
49
45
|
* @param eip1193Request - The request to send.
|
|
50
46
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
51
|
-
* @deprecated
|
|
47
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
48
|
+
* compatibility with certain libraries.
|
|
52
49
|
*/
|
|
53
50
|
sendAsync: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
54
51
|
/**
|
|
@@ -59,9 +56,17 @@ export declare class InternalProvider {
|
|
|
59
56
|
*
|
|
60
57
|
* @param eip1193Request - The request to send.
|
|
61
58
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
62
|
-
* @deprecated
|
|
59
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
60
|
+
* compatibility with certain libraries.
|
|
63
61
|
*/
|
|
64
62
|
send: <Params extends JsonRpcParams>(eip1193Request: Eip1193Request<Params>, callback: (error: unknown, providerRes?: any) => void) => void;
|
|
65
63
|
}
|
|
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;
|
|
66
71
|
export {};
|
|
67
72
|
//# 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,KAAK,
|
|
1
|
+
{"version":3,"file":"internal-provider.d.mts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,aAAa,EAAE,kCAAkC;AAC/E,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,qCAAqC;AACtC,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAE/D,OAAO,EACL,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,wBAAwB;AAGzB;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAAI;IAClE,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,KAAK,OAAO,CACV,OAAO,SAAS,cAAc,GAAG,cAAc,EAC/C,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,IACnD;IACF,MAAM,EAAE,aAAa,GAAG,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;OAKG;gBACS,EAAE,MAAM,EAAE,EAAE,OAAO;IAS/B;;;;;OAKG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC;IAMlB;;;;;;;;;;OAUG;IACH,SAAS,2FAIW,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAKrD;IAEF;;;;;;;;;;OAUG;IACH,IAAI,2FAIgB,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAQrD;CAgCH;AAED;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,cAAc,EAAE,cAAc,GAC7B,cAAc,CAehB"}
|
|
@@ -9,30 +9,10 @@ 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
|
-
|
|
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
|
-
}
|
|
12
|
+
var _InternalProvider_engine, _InternalProvider_handle, _InternalProvider_handleWithCallback;
|
|
13
|
+
import { asV2Middleware } from "@metamask/json-rpc-engine";
|
|
14
|
+
import { JsonRpcEngineV2 } from "@metamask/json-rpc-engine/v2";
|
|
15
|
+
import { nanoid } from "nanoid";
|
|
36
16
|
/**
|
|
37
17
|
* An Ethereum provider.
|
|
38
18
|
*
|
|
@@ -41,7 +21,7 @@ export function convertEip1193RequestToJsonRpcRequest(eip1193Request) {
|
|
|
41
21
|
*/
|
|
42
22
|
export class InternalProvider {
|
|
43
23
|
/**
|
|
44
|
-
* Construct a InternalProvider from a JSON-RPC engine.
|
|
24
|
+
* Construct a InternalProvider from a JSON-RPC server or legacy engine.
|
|
45
25
|
*
|
|
46
26
|
* @param options - Options.
|
|
47
27
|
* @param options.engine - The JSON-RPC engine used to process requests.
|
|
@@ -56,14 +36,15 @@ export class InternalProvider {
|
|
|
56
36
|
*
|
|
57
37
|
* @param eip1193Request - The request to send.
|
|
58
38
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
59
|
-
* @deprecated
|
|
39
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
40
|
+
* compatibility with certain libraries.
|
|
60
41
|
*/
|
|
61
42
|
this.sendAsync = (eip1193Request,
|
|
62
|
-
//
|
|
43
|
+
// Non-polluting `any` that acts like a constraint.
|
|
63
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
45
|
callback) => {
|
|
65
46
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
66
|
-
__classPrivateFieldGet(this,
|
|
47
|
+
__classPrivateFieldGet(this, _InternalProvider_handleWithCallback, "f").call(this, jsonRpcRequest, callback);
|
|
67
48
|
};
|
|
68
49
|
/**
|
|
69
50
|
* Send a provider request asynchronously.
|
|
@@ -73,7 +54,8 @@ export class InternalProvider {
|
|
|
73
54
|
*
|
|
74
55
|
* @param eip1193Request - The request to send.
|
|
75
56
|
* @param callback - A function that is called upon the success or failure of the request.
|
|
76
|
-
* @deprecated
|
|
57
|
+
* @deprecated Use {@link request} instead. This method is retained solely for backwards
|
|
58
|
+
* compatibility with certain libraries.
|
|
77
59
|
*/
|
|
78
60
|
this.send = (eip1193Request,
|
|
79
61
|
// TODO: Replace `any` with type
|
|
@@ -83,9 +65,34 @@ export class InternalProvider {
|
|
|
83
65
|
throw new Error('Must provide callback to "send" method.');
|
|
84
66
|
}
|
|
85
67
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
86
|
-
__classPrivateFieldGet(this,
|
|
68
|
+
__classPrivateFieldGet(this, _InternalProvider_handleWithCallback, "f").call(this, jsonRpcRequest, callback);
|
|
87
69
|
};
|
|
88
|
-
|
|
70
|
+
_InternalProvider_handle.set(this, async (jsonRpcRequest) => {
|
|
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");
|
|
89
96
|
}
|
|
90
97
|
/**
|
|
91
98
|
* Send a provider request asynchronously.
|
|
@@ -95,16 +102,29 @@ export class InternalProvider {
|
|
|
95
102
|
*/
|
|
96
103
|
async request(eip1193Request) {
|
|
97
104
|
const jsonRpcRequest = convertEip1193RequestToJsonRpcRequest(eip1193Request);
|
|
98
|
-
|
|
99
|
-
if ('result' in response) {
|
|
100
|
-
return response.result;
|
|
101
|
-
}
|
|
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;
|
|
105
|
+
return (await __classPrivateFieldGet(this, _InternalProvider_handle, "f").call(this, jsonRpcRequest)).result;
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
_InternalProvider_engine = new WeakMap();
|
|
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,
|
|
123
|
+
}
|
|
124
|
+
: {
|
|
125
|
+
id,
|
|
126
|
+
jsonrpc,
|
|
127
|
+
method,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
110
130
|
//# 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":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAsB,kCAAkC;AAK/E,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAS/D,OAAO,EAAE,MAAM,EAAE,eAAe;AAmBhC;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAG3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAW;QARtB,2CAA4D;QA+BrE;;;;;;;;;;WAUG;QACH,cAAS,GAAG,CACV,cAAsC;QACtC,mDAAmD;QACnD,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,4CAAoB,MAAxB,IAAI,EAAqB,cAAc,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC;QAEF;;;;;;;;;;WAUG;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,4CAAoB,MAAxB,IAAI,EAAqB,cAAc,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC;QAEO,mCAAU,KAAK,EACtB,cAA8B,EACG,EAAE;YACnC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;YACvC,gFAAgF;YAChF,0DAA0D;YAC1D,MAAM,MAAM,GAAG,CAAC,MAAM,uBAAA,IAAI,gCAAQ,CAAC,MAAM,CACvC,cAAc,CACf,CAAsB,CAAC;YAExB,OAAO;gBACL,EAAE;gBACF,OAAO;gBACP,MAAM;aACP,CAAC;QACJ,CAAC,EAAC;QAEO,+CAAsB,CAC7B,cAA8B,EAC9B,QAAyD,EACnD,EAAE;YACR,mDAAmD;YACnD,uBAAA,IAAI,gCAAQ,MAAZ,IAAI,EAAS,cAAc,CAAC;gBAC1B,oDAAoD;iBACnD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;iBAC5C,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACf,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;YACL,kDAAkD;QACpD,CAAC,EAAC;QAlGA,uBAAA,IAAI,4BACF,MAAM,IAAI,MAAM;YACd,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC;gBACrB,UAAU,EAAE,CAAC,cAAc,CAAgC,MAAM,CAAC,CAAC;aACpE,CAAC;YACJ,CAAC,CAAC,MAAM,MAAA,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CACX,cAAsC;QAEtC,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;QACxD,OAAO,CAAC,MAAM,uBAAA,IAAI,gCAAQ,MAAZ,IAAI,EAAiB,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7D,CAAC;CA+EF;;AAED;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CACnD,cAA8B;IAE9B,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAE1E,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","sourcesContent":["import { asV2Middleware, type JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type {\n ContextConstraint,\n MiddlewareContext,\n} from '@metamask/json-rpc-engine/v2';\nimport { JsonRpcEngineV2 } from '@metamask/json-rpc-engine/v2';\nimport type { JsonRpcSuccess } from '@metamask/utils';\nimport {\n type Json,\n type JsonRpcId,\n type JsonRpcParams,\n type JsonRpcRequest,\n type JsonRpcVersion2,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\n/**\n * A JSON-RPC request conforming to the EIP-1193 specification.\n */\ntype Eip1193Request<Params extends JsonRpcParams = JsonRpcParams> = {\n id?: JsonRpcId;\n jsonrpc?: JsonRpcVersion2;\n method: string;\n params?: Params;\n};\n\ntype Options<\n Request extends JsonRpcRequest = JsonRpcRequest,\n Context extends ContextConstraint = MiddlewareContext,\n> = {\n engine: JsonRpcEngine | JsonRpcEngineV2<Request, Context>;\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: JsonRpcEngineV2<JsonRpcRequest, MiddlewareContext>;\n\n /**\n * Construct a InternalProvider from a JSON-RPC server or legacy engine.\n *\n * @param options - Options.\n * @param options.engine - The JSON-RPC engine used to process requests.\n */\n constructor({ engine }: Options) {\n this.#engine =\n 'push' in engine\n ? JsonRpcEngineV2.create({\n middleware: [asV2Middleware<JsonRpcParams, JsonRpcRequest>(engine)],\n })\n : 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 return (await this.#handle<Result>(jsonRpcRequest)).result;\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 Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\n */\n sendAsync = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // Non-polluting `any` that acts like a constraint.\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.#handleWithCallback(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 Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\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.#handleWithCallback(jsonRpcRequest, callback);\n };\n\n readonly #handle = async <Result extends Json>(\n jsonRpcRequest: JsonRpcRequest,\n ): Promise<JsonRpcSuccess<Result>> => {\n const { id, jsonrpc } = jsonRpcRequest;\n // This typecast is technicaly unsafe, but we need it to preserve the provider's\n // public interface, which allows you to typecast results.\n const result = (await this.#engine.handle(\n jsonRpcRequest,\n )) as unknown as Result;\n\n return {\n id,\n jsonrpc,\n result,\n };\n };\n\n readonly #handleWithCallback = (\n jsonRpcRequest: JsonRpcRequest,\n callback: (error: unknown, providerRes?: unknown) => void,\n ): void => {\n /* eslint-disable promise/no-callback-in-promise */\n this.#handle(jsonRpcRequest)\n // A resolution will always be a successful response\n .then((response) => callback(null, response))\n .catch((error) => {\n callback(error);\n });\n /* eslint-enable promise/no-callback-in-promise */\n };\n}\n\n/**\n * Convert an EIP-1193 request to a JSON-RPC request.\n *\n * @param eip1193Request - The EIP-1193 request to convert.\n * @returns The JSON-RPC request.\n */\nexport function convertEip1193RequestToJsonRpcRequest(\n eip1193Request: Eip1193Request,\n): JsonRpcRequest {\n const { id = nanoid(), jsonrpc = '2.0', method, params } = eip1193Request;\n\n return params\n ? {\n id,\n jsonrpc,\n method,\n params,\n }\n : {\n id,\n jsonrpc,\n method,\n };\n}\n"]}
|
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.providerFromMiddleware = void 0;
|
|
3
|
+
exports.providerFromMiddlewareV2 = exports.providerFromMiddleware = void 0;
|
|
4
4
|
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
5
|
-
const
|
|
5
|
+
const v2_1 = require("@metamask/json-rpc-engine/v2");
|
|
6
|
+
const internal_provider_1 = require("./internal-provider.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* Construct an Ethereum provider from the given middleware.
|
|
8
9
|
*
|
|
9
10
|
* @param middleware - The middleware to construct a provider from.
|
|
10
11
|
* @returns An Ethereum provider.
|
|
12
|
+
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
11
13
|
*/
|
|
12
14
|
function providerFromMiddleware(middleware) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return providerFromMiddlewareV2(
|
|
16
|
+
// This function is generic on the Params and Result types to match the legacy JsonRpcMiddleware type.
|
|
17
|
+
// However, since the V2 JsonRpcMiddleware type is not generic on the Params, we need to elide this
|
|
18
|
+
// parameter by upcasting the request type to JsonRpcRequest, or we get an error due to contravariance
|
|
19
|
+
// since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.
|
|
20
|
+
(0, json_rpc_engine_1.asV2Middleware)(middleware));
|
|
17
21
|
}
|
|
18
22
|
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;
|
|
19
40
|
//# 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,+DAA2D;AAM3D,qDAGsC;AAGtC,+DAAuD;AAEvD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAGpC,UAAmD;IACnD,OAAO,wBAAwB;IAC7B,sGAAsG;IACtG,mGAAmG;IACnG,sGAAsG;IACtG,oEAAoE;IACpE,IAAA,gCAAc,EAAC,UAAU,CAAsC,CAChE,CAAC;AACJ,CAAC;AAXD,wDAWC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAOtC,UAAsB;IACtB,OAAO,IAAI,oCAAgB,CAAC;QAC1B,MAAM,EAAE,oBAAe,CAAC,MAAM,CAAC;YAC7B,4FAA4F;YAC5F,oGAAoG;YACpG,0DAA0D;YAC1D,UAAU,EAAE,CAAC,UAA+C,CAAC;SAC9D,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAhBD,4DAgBC","sourcesContent":["import { asV2Middleware } from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n JsonRpcMiddleware,\n ResultConstraint,\n} from '@metamask/json-rpc-engine/v2';\nimport {\n JsonRpcEngineV2,\n type ContextConstraint,\n} from '@metamask/json-rpc-engine/v2';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport { InternalProvider } from './internal-provider';\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 * @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.\n */\nexport function providerFromMiddleware<\n Params extends JsonRpcParams,\n Result extends Json,\n>(middleware: LegacyJsonRpcMiddleware<Params, Result>): InternalProvider {\n return providerFromMiddlewareV2(\n // This function is generic on the Params and Result types to match the legacy JsonRpcMiddleware type.\n // However, since the V2 JsonRpcMiddleware type is not generic on the Params, we need to elide this\n // parameter by upcasting the request type to JsonRpcRequest, or we get an error due to contravariance\n // since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.\n asV2Middleware(middleware) as JsonRpcMiddleware<JsonRpcRequest>,\n );\n}\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 providerFromMiddlewareV2<\n Request extends JsonRpcRequest,\n Middleware extends JsonRpcMiddleware<\n Request,\n ResultConstraint<Request>,\n ContextConstraint\n >,\n>(middleware: Middleware): InternalProvider {\n return new InternalProvider({\n engine: JsonRpcEngineV2.create({\n // This function is generic in order to accept middleware functions with narrower types than\n // the plain JsonRpcMiddleware<JsonRpcRequest> type. However, since InternalProvider is non-generic,\n // we need to upcast the middleware to avoid a type error.\n middleware: [middleware as JsonRpcMiddleware<JsonRpcRequest>],\n }),\n });\n}\n"]}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
1
|
+
import type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { JsonRpcMiddleware, ResultConstraint } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import { type ContextConstraint } from "@metamask/json-rpc-engine/v2";
|
|
4
|
+
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
5
|
+
import { InternalProvider } from "./internal-provider.cjs";
|
|
4
6
|
/**
|
|
5
7
|
* Construct an Ethereum provider from the given middleware.
|
|
6
8
|
*
|
|
7
9
|
* @param middleware - The middleware to construct a provider from.
|
|
8
10
|
* @returns An Ethereum provider.
|
|
11
|
+
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
9
12
|
*/
|
|
10
|
-
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware:
|
|
13
|
+
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware: LegacyJsonRpcMiddleware<Params, Result>): InternalProvider;
|
|
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;
|
|
11
21
|
//# 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,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.d.cts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,kCAAkC;AAC9F,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EACjB,qCAAqC;AACtC,OAAO,EAEL,KAAK,iBAAiB,EACvB,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,UAAU,EAAE,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAQvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,SAAS,cAAc,EAC9B,UAAU,SAAS,iBAAiB,CAClC,OAAO,EACP,gBAAgB,CAAC,OAAO,CAAC,EACzB,iBAAiB,CAClB,EACD,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAS1C"}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
1
|
+
import type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { JsonRpcMiddleware, ResultConstraint } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import { type ContextConstraint } from "@metamask/json-rpc-engine/v2";
|
|
4
|
+
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
5
|
+
import { InternalProvider } from "./internal-provider.mjs";
|
|
4
6
|
/**
|
|
5
7
|
* Construct an Ethereum provider from the given middleware.
|
|
6
8
|
*
|
|
7
9
|
* @param middleware - The middleware to construct a provider from.
|
|
8
10
|
* @returns An Ethereum provider.
|
|
11
|
+
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
9
12
|
*/
|
|
10
|
-
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware:
|
|
13
|
+
export declare function providerFromMiddleware<Params extends JsonRpcParams, Result extends Json>(middleware: LegacyJsonRpcMiddleware<Params, Result>): InternalProvider;
|
|
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;
|
|
11
21
|
//# 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,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.d.mts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,kCAAkC;AAC9F,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EACjB,qCAAqC;AACtC,OAAO,EAEL,KAAK,iBAAiB,EACvB,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,UAAU,EAAE,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAQvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,SAAS,cAAc,EAC9B,UAAU,SAAS,iBAAiB,CAClC,OAAO,EACP,gBAAgB,CAAC,OAAO,CAAC,EACzB,iBAAiB,CAClB,EACD,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAS1C"}
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { asV2Middleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { JsonRpcEngineV2 } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import { InternalProvider } from "./internal-provider.mjs";
|
|
3
4
|
/**
|
|
4
5
|
* Construct an Ethereum provider from the given middleware.
|
|
5
6
|
*
|
|
6
7
|
* @param middleware - The middleware to construct a provider from.
|
|
7
8
|
* @returns An Ethereum provider.
|
|
9
|
+
* @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.
|
|
8
10
|
*/
|
|
9
11
|
export function providerFromMiddleware(middleware) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
return providerFromMiddlewareV2(
|
|
13
|
+
// This function is generic on the Params and Result types to match the legacy JsonRpcMiddleware type.
|
|
14
|
+
// However, since the V2 JsonRpcMiddleware type is not generic on the Params, we need to elide this
|
|
15
|
+
// parameter by upcasting the request type to JsonRpcRequest, or we get an error due to contravariance
|
|
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
|
+
});
|
|
14
34
|
}
|
|
15
35
|
//# 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,cAAc,EAAE,kCAAkC;AAM3D,OAAO,EACL,eAAe,EAEhB,qCAAqC;AAGtC,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAGpC,UAAmD;IACnD,OAAO,wBAAwB;IAC7B,sGAAsG;IACtG,mGAAmG;IACnG,sGAAsG;IACtG,oEAAoE;IACpE,cAAc,CAAC,UAAU,CAAsC,CAChE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAOtC,UAAsB;IACtB,OAAO,IAAI,gBAAgB,CAAC;QAC1B,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;YAC7B,4FAA4F;YAC5F,oGAAoG;YACpG,0DAA0D;YAC1D,UAAU,EAAE,CAAC,UAA+C,CAAC;SAC9D,CAAC;KACH,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { asV2Middleware } from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n JsonRpcMiddleware,\n ResultConstraint,\n} from '@metamask/json-rpc-engine/v2';\nimport {\n JsonRpcEngineV2,\n type ContextConstraint,\n} from '@metamask/json-rpc-engine/v2';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport { InternalProvider } from './internal-provider';\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 * @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.\n */\nexport function providerFromMiddleware<\n Params extends JsonRpcParams,\n Result extends Json,\n>(middleware: LegacyJsonRpcMiddleware<Params, Result>): InternalProvider {\n return providerFromMiddlewareV2(\n // This function is generic on the Params and Result types to match the legacy JsonRpcMiddleware type.\n // However, since the V2 JsonRpcMiddleware type is not generic on the Params, we need to elide this\n // parameter by upcasting the request type to JsonRpcRequest, or we get an error due to contravariance\n // since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.\n asV2Middleware(middleware) as JsonRpcMiddleware<JsonRpcRequest>,\n );\n}\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 providerFromMiddlewareV2<\n Request extends JsonRpcRequest,\n Middleware extends JsonRpcMiddleware<\n Request,\n ResultConstraint<Request>,\n ContextConstraint\n >,\n>(middleware: Middleware): InternalProvider {\n return new InternalProvider({\n engine: JsonRpcEngineV2.create({\n // This function is generic in order to accept middleware functions with narrower types than\n // the plain JsonRpcMiddleware<JsonRpcRequest> type. However, since InternalProvider is non-generic,\n // we need to upcast the middleware to avoid a type error.\n middleware: [middleware as JsonRpcMiddleware<JsonRpcRequest>],\n }),\n });\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-684a40c0",
|
|
4
4
|
"description": "Create an Ethereum provider using a JSON-RPC engine or middleware",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -36,6 +36,7 @@
|
|
|
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",
|
|
39
40
|
"build:docs": "typedoc",
|
|
40
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-json-rpc-provider",
|
|
41
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-json-rpc-provider",
|
|
@@ -55,13 +56,14 @@
|
|
|
55
56
|
"@metamask/json-rpc-engine": "^10.1.1",
|
|
56
57
|
"@metamask/rpc-errors": "^7.0.2",
|
|
57
58
|
"@metamask/utils": "^11.8.1",
|
|
58
|
-
"
|
|
59
|
+
"nanoid": "^3.3.8"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@ethersproject/providers": "^5.7.0",
|
|
62
63
|
"@metamask/auto-changelog": "^3.4.4",
|
|
63
64
|
"@metamask/eth-query": "^4.0.0",
|
|
64
65
|
"@metamask/ethjs-query": "^0.5.3",
|
|
66
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
65
67
|
"@types/jest": "^27.4.1",
|
|
66
68
|
"deepmerge": "^4.2.2",
|
|
67
69
|
"ethers": "^6.12.0",
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|