@openkey/sdk 0.10.0 → 0.10.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.d.mts +32 -18
- package/dist/index.d.ts +32 -18
- package/dist/index.js +48 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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:
|
|
324
|
-
//
|
|
325
|
-
// Set by `setExpectedCorrelation`
|
|
326
|
-
//
|
|
327
|
-
//
|
|
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
|
|
410
|
-
* request
|
|
411
|
-
*
|
|
412
|
-
*
|
|
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;
|
|
@@ -547,14 +552,13 @@ var OpenKey = class {
|
|
|
547
552
|
popup = null;
|
|
548
553
|
lastAuth = null;
|
|
549
554
|
discoveredProviders = [];
|
|
550
|
-
sessionToken = null;
|
|
551
555
|
/** Cancels widget flows that could outlive a sign-out on this instance. */
|
|
552
556
|
activeFlowCancellations = /* @__PURE__ */ new Set();
|
|
553
557
|
/**
|
|
554
558
|
* Nostr identity custody + signing (secp256k1 Schnorr / BIP-340). Kept
|
|
555
559
|
* fully separate from the Ethereum flows above: it never reuses
|
|
556
|
-
* `lastAuth
|
|
557
|
-
*
|
|
560
|
+
* `lastAuth`, and its widget messages never carry a session token -
|
|
561
|
+
* the OpenKey session and any signing grants stay inside
|
|
558
562
|
* the OpenKey-origin iframe for the whole lifetime of this client.
|
|
559
563
|
*/
|
|
560
564
|
nostr;
|
|
@@ -636,25 +640,22 @@ var OpenKey = class {
|
|
|
636
640
|
/**
|
|
637
641
|
* Signs the active OpenKey account out through the OpenKey-owned widget.
|
|
638
642
|
*
|
|
639
|
-
* The
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
+
* The OpenKey-owned widget revokes the OpenKey session it holds itself;
|
|
644
|
+
* the SDK never holds an OpenKey session token. Local SDK state is cleared
|
|
645
|
+
* before opening the widget, including when remote revocation is
|
|
646
|
+
* unavailable.
|
|
643
647
|
*/
|
|
644
648
|
async signOut(opts) {
|
|
645
649
|
const requestId = `ok-signout-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
646
|
-
const sessionToken = this.sessionToken || void 0;
|
|
647
650
|
const mode = this.resolveMode(opts?.mode) === "redirect" ? "popup" : opts?.mode;
|
|
648
651
|
this.cancelActiveFlows();
|
|
649
652
|
this.lastAuth = null;
|
|
650
|
-
this.sessionToken = null;
|
|
651
653
|
const acknowledgement = await this.openFlow(
|
|
652
654
|
"sign-out",
|
|
653
655
|
{
|
|
654
656
|
type: "openkey:sign-out:request",
|
|
655
657
|
requestId,
|
|
656
|
-
protocolVersion: 1
|
|
657
|
-
sessionToken
|
|
658
|
+
protocolVersion: 1
|
|
658
659
|
},
|
|
659
660
|
mode
|
|
660
661
|
);
|
|
@@ -664,22 +665,26 @@ var OpenKey = class {
|
|
|
664
665
|
return acknowledgement;
|
|
665
666
|
}
|
|
666
667
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
668
|
+
* Always null. OpenKey no longer gives its session token to the embedding
|
|
669
|
+
* page (TC-688): the token unlocked OpenKey's key and account APIs, not
|
|
670
|
+
* just the requesting app's flows.
|
|
671
|
+
*
|
|
672
|
+
* @deprecated Kept so existing callers compile. Third-party server-side
|
|
673
|
+
* signing uses an OAuth access token from the OpenKey OAuth flow.
|
|
670
674
|
*/
|
|
671
675
|
getSessionToken() {
|
|
672
|
-
return
|
|
676
|
+
return null;
|
|
673
677
|
}
|
|
674
678
|
/**
|
|
675
|
-
* Endpoint
|
|
676
|
-
*
|
|
677
|
-
*
|
|
679
|
+
* Endpoint for a TinyCloud auto-sign signing strategy. `token` is always
|
|
680
|
+
* null; see {@link OpenKey.getSessionToken}.
|
|
681
|
+
*
|
|
682
|
+
* @deprecated The endpoint accepts an OAuth access token as its bearer.
|
|
678
683
|
*/
|
|
679
684
|
tinycloudSigningOptions() {
|
|
680
685
|
return {
|
|
681
686
|
endpoint: `${this.oauthHost}/api/delegate/sign`,
|
|
682
|
-
token:
|
|
687
|
+
token: null
|
|
683
688
|
};
|
|
684
689
|
}
|
|
685
690
|
/**
|
|
@@ -764,8 +769,7 @@ var OpenKey = class {
|
|
|
764
769
|
// context. The envelope is display-only; the widget transport
|
|
765
770
|
// validates and size-bounds it before use and NEVER treats it as
|
|
766
771
|
// verified unless the server actually origin-binds a manifest.
|
|
767
|
-
presentation: request.presentation
|
|
768
|
-
sessionToken: this.sessionToken || void 0
|
|
772
|
+
presentation: request.presentation
|
|
769
773
|
},
|
|
770
774
|
opts?.mode
|
|
771
775
|
);
|
|
@@ -842,7 +846,6 @@ var OpenKey = class {
|
|
|
842
846
|
// bounded at the transport, never treated as verified without
|
|
843
847
|
// server-side origin-binding.
|
|
844
848
|
presentation: request.presentation,
|
|
845
|
-
sessionToken: this.sessionToken || void 0,
|
|
846
849
|
// Sol MAJOR-3 (continuation): tell the widget to hand us back
|
|
847
850
|
// the previewApproval instead of asking OpenKey to sign
|
|
848
851
|
// server-side with a managed key. The widget will still render
|
|
@@ -996,15 +999,13 @@ var OpenKey = class {
|
|
|
996
999
|
return this.openFlow("sign", {
|
|
997
1000
|
type: "openkey:sign:request",
|
|
998
1001
|
message: request.message,
|
|
999
|
-
keyId: request.keyId
|
|
1000
|
-
sessionToken: this.sessionToken || void 0
|
|
1002
|
+
keyId: request.keyId
|
|
1001
1003
|
}, mode);
|
|
1002
1004
|
}
|
|
1003
1005
|
signTypedDataWithOpenKey(request, mode) {
|
|
1004
1006
|
return this.openFlow("sign-typed-data", {
|
|
1005
1007
|
type: "openkey:signTypedData:request",
|
|
1006
|
-
data: request
|
|
1007
|
-
sessionToken: this.sessionToken || void 0
|
|
1008
|
+
data: request
|
|
1008
1009
|
}, mode);
|
|
1009
1010
|
}
|
|
1010
1011
|
toHex(str) {
|
|
@@ -1260,12 +1261,6 @@ var OpenKey = class {
|
|
|
1260
1261
|
onMessage: (data) => {
|
|
1261
1262
|
if (data.type === "openkey:ready") {
|
|
1262
1263
|
readyReceived = true;
|
|
1263
|
-
if (isVersionedRequest && modal) {
|
|
1264
|
-
modal.setExpectedCorrelation(
|
|
1265
|
-
outgoingRequestId,
|
|
1266
|
-
outgoingProtocolVersion
|
|
1267
|
-
);
|
|
1268
|
-
}
|
|
1269
1264
|
modal?.postMessage(message);
|
|
1270
1265
|
return;
|
|
1271
1266
|
}
|
|
@@ -1296,7 +1291,6 @@ var OpenKey = class {
|
|
|
1296
1291
|
cleanup();
|
|
1297
1292
|
if (data.success) {
|
|
1298
1293
|
if (data.type === "openkey:auth:response") {
|
|
1299
|
-
if (data.sessionToken) this.sessionToken = data.sessionToken;
|
|
1300
1294
|
resolve({ address: data.address, keyId: data.keyId, keyType: data.keyType || "MANAGED" });
|
|
1301
1295
|
} else if (data.type === "openkey:link-wallet:response") {
|
|
1302
1296
|
resolve({ address: data.address, keyId: data.keyId });
|
|
@@ -1326,6 +1320,12 @@ var OpenKey = class {
|
|
|
1326
1320
|
}
|
|
1327
1321
|
}
|
|
1328
1322
|
});
|
|
1323
|
+
if (isVersionedRequest) {
|
|
1324
|
+
modal.setExpectedCorrelation(
|
|
1325
|
+
outgoingRequestId,
|
|
1326
|
+
outgoingProtocolVersion
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
1329
|
const readyTimeout = setTimeout(() => {
|
|
1330
1330
|
if (readyReceived || settled) return;
|
|
1331
1331
|
cleanup();
|
|
@@ -1513,7 +1513,6 @@ var OpenKey = class {
|
|
|
1513
1513
|
popup.close();
|
|
1514
1514
|
if (data.success) {
|
|
1515
1515
|
if (data.type === "openkey:auth:response") {
|
|
1516
|
-
if (data.sessionToken) this.sessionToken = data.sessionToken;
|
|
1517
1516
|
resolve({ address: data.address, keyId: data.keyId, keyType: data.keyType || "MANAGED" });
|
|
1518
1517
|
} else if (data.type === "openkey:link-wallet:response") {
|
|
1519
1518
|
resolve({ address: data.address, keyId: data.keyId });
|