@openkey/sdk 0.10.0 → 0.10.1

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
@@ -239,12 +239,16 @@ function validateIframeResize(incoming, expected) {
239
239
  if (!incoming || typeof incoming !== "object") return null;
240
240
  const data = incoming;
241
241
  if (data.type !== "openkey:resize") return null;
242
- if (expected.requestId === null || expected.protocolVersion === null) return null;
243
- if (typeof data.protocolVersion !== "number" || data.protocolVersion !== expected.protocolVersion) {
244
- return null;
245
- }
246
- if (typeof data.requestId !== "string" || data.requestId !== expected.requestId) {
247
- return null;
242
+ if (expected.requestId === null && expected.protocolVersion === null) {
243
+ if (data.requestId !== void 0) return null;
244
+ } else {
245
+ if (expected.requestId === null || expected.protocolVersion === null) return null;
246
+ if (typeof data.protocolVersion !== "number" || data.protocolVersion !== expected.protocolVersion) {
247
+ return null;
248
+ }
249
+ if (typeof data.requestId !== "string" || data.requestId !== expected.requestId) {
250
+ return null;
251
+ }
248
252
  }
249
253
  if (typeof data.height !== "number" || !Number.isFinite(data.height) || data.height <= 0) {
250
254
  return null;
@@ -320,11 +324,11 @@ var IframeModal = class {
320
324
  onMessage;
321
325
  messageHandler;
322
326
  host;
323
- // Sol final continuation contract requirement 5: iframe resize traffic
324
- // MUST correlate to the active request's requestId AND protocolVersion.
325
- // Set by `setExpectedCorrelation` after the outer flow decides which
326
- // request this modal is bound to. When both are null, resize messages
327
- // are dropped (no active request → no resize authority).
327
+ // Sol final continuation contract requirement 5: when the modal carries a
328
+ // versioned request, iframe resize traffic MUST correlate to its
329
+ // requestId AND protocolVersion. Set by `setExpectedCorrelation` as soon
330
+ // as the modal is created. When both are null the flow is unversioned and
331
+ // only uncorrelated resizes from this iframe are accepted (TC-647).
328
332
  expectedRequestId = null;
329
333
  expectedProtocolVersion = null;
330
334
  constructor(opts) {
@@ -406,10 +410,11 @@ var IframeModal = class {
406
410
  * request correlation so subsequent resize (and future correlated)
407
411
  * messages can be verified against `requestId` + `protocolVersion`.
408
412
  *
409
- * The outer flow calls this immediately BEFORE posting the sign
410
- * request into the iframe, so a resize that arrives synchronously
411
- * after ready is correlated correctly. Passing `null` for either
412
- * argument disables correlation (resize is dropped).
413
+ * The outer flow calls this right after creating the modal for a
414
+ * versioned request, before the iframe can send anything, so no
415
+ * uncorrelated resize is ever accepted for that request. Passing `null`
416
+ * for both arguments means the flow is unversioned; passing `null` for
417
+ * only one drops every resize.
413
418
  */
414
419
  setExpectedCorrelation(requestId, protocolVersion) {
415
420
  this.expectedRequestId = requestId;
@@ -1260,12 +1265,6 @@ var OpenKey = class {
1260
1265
  onMessage: (data) => {
1261
1266
  if (data.type === "openkey:ready") {
1262
1267
  readyReceived = true;
1263
- if (isVersionedRequest && modal) {
1264
- modal.setExpectedCorrelation(
1265
- outgoingRequestId,
1266
- outgoingProtocolVersion
1267
- );
1268
- }
1269
1268
  modal?.postMessage(message);
1270
1269
  return;
1271
1270
  }
@@ -1326,6 +1325,12 @@ var OpenKey = class {
1326
1325
  }
1327
1326
  }
1328
1327
  });
1328
+ if (isVersionedRequest) {
1329
+ modal.setExpectedCorrelation(
1330
+ outgoingRequestId,
1331
+ outgoingProtocolVersion
1332
+ );
1333
+ }
1329
1334
  const readyTimeout = setTimeout(() => {
1330
1335
  if (readyReceived || settled) return;
1331
1336
  cleanup();