@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.d.mts +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +26 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -211,12 +211,23 @@ interface CapabilityPresentationEnvelopeV1 {
|
|
|
211
211
|
/**
|
|
212
212
|
* Sol final continuation contract requirement 5: pure validation of an
|
|
213
213
|
* incoming iframe resize message envelope. Exported so unit tests can
|
|
214
|
-
* exercise every rejection branch — wrong requestId, wrong version,
|
|
215
|
-
*
|
|
216
|
-
*
|
|
214
|
+
* exercise every rejection branch — wrong requestId, wrong version,
|
|
215
|
+
* malformed height — without booting the browser runtime that
|
|
216
|
+
* `IframeModal` requires.
|
|
217
217
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
218
|
+
* Two modes, chosen by the modal's bound correlation:
|
|
219
|
+
* - Versioned request bound (`requestId` AND `protocolVersion` set): the
|
|
220
|
+
* resize MUST carry that exact pair.
|
|
221
|
+
* - No versioned request (both null — `connect`, `signMessage`, and the
|
|
222
|
+
* other unversioned flows): the widget sends a plain
|
|
223
|
+
* `{ type, height }`. It is accepted only when it carries no
|
|
224
|
+
* `requestId`. The caller has already checked that the message came
|
|
225
|
+
* from this modal's iframe (`event.source`) on the OpenKey origin
|
|
226
|
+
* (TC-647).
|
|
227
|
+
* A half-bound correlation (only one of the two set) drops everything.
|
|
228
|
+
*
|
|
229
|
+
* Returns the height clamped to 85% of the viewport when acceptable, or
|
|
230
|
+
* `null` when the message must be dropped.
|
|
220
231
|
*/
|
|
221
232
|
declare function validateIframeResize(incoming: unknown, expected: {
|
|
222
233
|
requestId: string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -211,12 +211,23 @@ interface CapabilityPresentationEnvelopeV1 {
|
|
|
211
211
|
/**
|
|
212
212
|
* Sol final continuation contract requirement 5: pure validation of an
|
|
213
213
|
* incoming iframe resize message envelope. Exported so unit tests can
|
|
214
|
-
* exercise every rejection branch — wrong requestId, wrong version,
|
|
215
|
-
*
|
|
216
|
-
*
|
|
214
|
+
* exercise every rejection branch — wrong requestId, wrong version,
|
|
215
|
+
* malformed height — without booting the browser runtime that
|
|
216
|
+
* `IframeModal` requires.
|
|
217
217
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
218
|
+
* Two modes, chosen by the modal's bound correlation:
|
|
219
|
+
* - Versioned request bound (`requestId` AND `protocolVersion` set): the
|
|
220
|
+
* resize MUST carry that exact pair.
|
|
221
|
+
* - No versioned request (both null — `connect`, `signMessage`, and the
|
|
222
|
+
* other unversioned flows): the widget sends a plain
|
|
223
|
+
* `{ type, height }`. It is accepted only when it carries no
|
|
224
|
+
* `requestId`. The caller has already checked that the message came
|
|
225
|
+
* from this modal's iframe (`event.source`) on the OpenKey origin
|
|
226
|
+
* (TC-647).
|
|
227
|
+
* A half-bound correlation (only one of the two set) drops everything.
|
|
228
|
+
*
|
|
229
|
+
* Returns the height clamped to 85% of the viewport when acceptable, or
|
|
230
|
+
* `null` when the message must be dropped.
|
|
220
231
|
*/
|
|
221
232
|
declare function validateIframeResize(incoming: unknown, expected: {
|
|
222
233
|
requestId: string | null;
|
package/dist/index.js
CHANGED
|
@@ -273,12 +273,16 @@ function validateIframeResize(incoming, expected) {
|
|
|
273
273
|
if (!incoming || typeof incoming !== "object") return null;
|
|
274
274
|
const data = incoming;
|
|
275
275
|
if (data.type !== "openkey:resize") return null;
|
|
276
|
-
if (expected.requestId === null
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
276
|
+
if (expected.requestId === null && expected.protocolVersion === null) {
|
|
277
|
+
if (data.requestId !== void 0) return null;
|
|
278
|
+
} else {
|
|
279
|
+
if (expected.requestId === null || expected.protocolVersion === null) return null;
|
|
280
|
+
if (typeof data.protocolVersion !== "number" || data.protocolVersion !== expected.protocolVersion) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
if (typeof data.requestId !== "string" || data.requestId !== expected.requestId) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
282
286
|
}
|
|
283
287
|
if (typeof data.height !== "number" || !Number.isFinite(data.height) || data.height <= 0) {
|
|
284
288
|
return null;
|
|
@@ -354,11 +358,11 @@ var IframeModal = class {
|
|
|
354
358
|
onMessage;
|
|
355
359
|
messageHandler;
|
|
356
360
|
host;
|
|
357
|
-
// Sol final continuation contract requirement 5:
|
|
358
|
-
//
|
|
359
|
-
// Set by `setExpectedCorrelation`
|
|
360
|
-
//
|
|
361
|
-
//
|
|
361
|
+
// Sol final continuation contract requirement 5: when the modal carries a
|
|
362
|
+
// versioned request, iframe resize traffic MUST correlate to its
|
|
363
|
+
// requestId AND protocolVersion. Set by `setExpectedCorrelation` as soon
|
|
364
|
+
// as the modal is created. When both are null the flow is unversioned and
|
|
365
|
+
// only uncorrelated resizes from this iframe are accepted (TC-647).
|
|
362
366
|
expectedRequestId = null;
|
|
363
367
|
expectedProtocolVersion = null;
|
|
364
368
|
constructor(opts) {
|
|
@@ -440,10 +444,11 @@ var IframeModal = class {
|
|
|
440
444
|
* request correlation so subsequent resize (and future correlated)
|
|
441
445
|
* messages can be verified against `requestId` + `protocolVersion`.
|
|
442
446
|
*
|
|
443
|
-
* The outer flow calls this
|
|
444
|
-
* request
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
+
* The outer flow calls this right after creating the modal for a
|
|
448
|
+
* versioned request, before the iframe can send anything, so no
|
|
449
|
+
* uncorrelated resize is ever accepted for that request. Passing `null`
|
|
450
|
+
* for both arguments means the flow is unversioned; passing `null` for
|
|
451
|
+
* only one drops every resize.
|
|
447
452
|
*/
|
|
448
453
|
setExpectedCorrelation(requestId, protocolVersion) {
|
|
449
454
|
this.expectedRequestId = requestId;
|
|
@@ -1294,12 +1299,6 @@ var OpenKey = class {
|
|
|
1294
1299
|
onMessage: (data) => {
|
|
1295
1300
|
if (data.type === "openkey:ready") {
|
|
1296
1301
|
readyReceived = true;
|
|
1297
|
-
if (isVersionedRequest && modal) {
|
|
1298
|
-
modal.setExpectedCorrelation(
|
|
1299
|
-
outgoingRequestId,
|
|
1300
|
-
outgoingProtocolVersion
|
|
1301
|
-
);
|
|
1302
|
-
}
|
|
1303
1302
|
modal?.postMessage(message);
|
|
1304
1303
|
return;
|
|
1305
1304
|
}
|
|
@@ -1360,6 +1359,12 @@ var OpenKey = class {
|
|
|
1360
1359
|
}
|
|
1361
1360
|
}
|
|
1362
1361
|
});
|
|
1362
|
+
if (isVersionedRequest) {
|
|
1363
|
+
modal.setExpectedCorrelation(
|
|
1364
|
+
outgoingRequestId,
|
|
1365
|
+
outgoingProtocolVersion
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1363
1368
|
const readyTimeout = setTimeout(() => {
|
|
1364
1369
|
if (readyReceived || settled) return;
|
|
1365
1370
|
cleanup();
|