@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.mjs CHANGED
@@ -219,6 +219,17 @@ function isRpcShaped(err) {
219
219
  return typeof e.message === "string" && typeof e.code === "number";
220
220
  }
221
221
 
222
+ // src/request-validation.ts
223
+ function validateRequestPayload(payload) {
224
+ if (payload === null || typeof payload !== "object" || Array.isArray(payload) || !("method" in payload) || typeof payload.method !== "string") {
225
+ throw new ProviderRpcError("Request must be an object with a string method", JSON_RPC_ERRORS.INVALID_REQUEST);
226
+ }
227
+ const params = "params" in payload ? payload.params : void 0;
228
+ if (params !== void 0 && (params === null || typeof params !== "object")) {
229
+ throw new ProviderRpcError("Request params must be an object or array", JSON_RPC_ERRORS.INVALID_PARAMS);
230
+ }
231
+ }
232
+
222
233
  // src/method-router.ts
223
234
  var MethodRouter = class {
224
235
  handlers = /* @__PURE__ */ new Map();
@@ -240,6 +251,7 @@ var MethodRouter = class {
240
251
  }
241
252
  /** Route a request to the appropriate handler */
242
253
  async route(payload) {
254
+ validateRequestPayload(payload);
243
255
  const { method, params } = payload;
244
256
  const handler = this.handlers.get(method);
245
257
  if (!handler) {
@@ -513,7 +525,7 @@ var PartyLayerProvider = class {
513
525
  };
514
526
 
515
527
  // src/bridge.ts
516
- var PROVIDER_VERSION = "0.6.1" ;
528
+ var PROVIDER_VERSION = "0.6.2" ;
517
529
  function createProviderBridge(client) {
518
530
  const eventBus = new CIP0103EventBus();
519
531
  const pendingEmitted = /* @__PURE__ */ new Set();
@@ -538,6 +550,7 @@ function createProviderBridge(client) {
538
550
  return bridge;
539
551
  }
540
552
  async function handleRequest(client, args, eventBus, pendingEmitted) {
553
+ validateRequestPayload(args);
541
554
  const { method, params } = args;
542
555
  try {
543
556
  switch (method) {
@@ -844,6 +857,11 @@ function createExtensionChannelProvider(options = {}) {
844
857
  }
845
858
  const provider = {
846
859
  request(args) {
860
+ try {
861
+ validateRequestPayload(args);
862
+ } catch (error) {
863
+ return Promise.reject(error);
864
+ }
847
865
  if (destroyed) return Promise.reject(new ProviderRpcError("Extension channel was destroyed", RPC_ERRORS.DISCONNECTED));
848
866
  if (typeof window === "undefined") {
849
867
  return Promise.reject(