@partylayer/provider 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -220,6 +220,17 @@ function isRpcShaped(err) {
|
|
|
220
220
|
return typeof e.message === "string" && typeof e.code === "number";
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
// src/request-validation.ts
|
|
224
|
+
function validateRequestPayload(payload) {
|
|
225
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload) || !("method" in payload) || typeof payload.method !== "string") {
|
|
226
|
+
throw new ProviderRpcError("Request must be an object with a string method", JSON_RPC_ERRORS.INVALID_REQUEST);
|
|
227
|
+
}
|
|
228
|
+
const params = "params" in payload ? payload.params : void 0;
|
|
229
|
+
if (params !== void 0 && (params === null || typeof params !== "object")) {
|
|
230
|
+
throw new ProviderRpcError("Request params must be an object or array", JSON_RPC_ERRORS.INVALID_PARAMS);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
223
234
|
// src/method-router.ts
|
|
224
235
|
var MethodRouter = class {
|
|
225
236
|
handlers = /* @__PURE__ */ new Map();
|
|
@@ -241,6 +252,7 @@ var MethodRouter = class {
|
|
|
241
252
|
}
|
|
242
253
|
/** Route a request to the appropriate handler */
|
|
243
254
|
async route(payload) {
|
|
255
|
+
validateRequestPayload(payload);
|
|
244
256
|
const { method, params } = payload;
|
|
245
257
|
const handler = this.handlers.get(method);
|
|
246
258
|
if (!handler) {
|
|
@@ -514,7 +526,7 @@ var PartyLayerProvider = class {
|
|
|
514
526
|
};
|
|
515
527
|
|
|
516
528
|
// src/bridge.ts
|
|
517
|
-
var PROVIDER_VERSION = "0.6.
|
|
529
|
+
var PROVIDER_VERSION = "0.6.2" ;
|
|
518
530
|
function createProviderBridge(client) {
|
|
519
531
|
const eventBus = new CIP0103EventBus();
|
|
520
532
|
const pendingEmitted = /* @__PURE__ */ new Set();
|
|
@@ -539,6 +551,7 @@ function createProviderBridge(client) {
|
|
|
539
551
|
return bridge;
|
|
540
552
|
}
|
|
541
553
|
async function handleRequest(client, args, eventBus, pendingEmitted) {
|
|
554
|
+
validateRequestPayload(args);
|
|
542
555
|
const { method, params } = args;
|
|
543
556
|
try {
|
|
544
557
|
switch (method) {
|
|
@@ -845,6 +858,11 @@ function createExtensionChannelProvider(options = {}) {
|
|
|
845
858
|
}
|
|
846
859
|
const provider = {
|
|
847
860
|
request(args) {
|
|
861
|
+
try {
|
|
862
|
+
validateRequestPayload(args);
|
|
863
|
+
} catch (error) {
|
|
864
|
+
return Promise.reject(error);
|
|
865
|
+
}
|
|
848
866
|
if (destroyed) return Promise.reject(new ProviderRpcError("Extension channel was destroyed", RPC_ERRORS.DISCONNECTED));
|
|
849
867
|
if (typeof window === "undefined") {
|
|
850
868
|
return Promise.reject(
|