@1sat/connect 0.0.4 → 0.0.6
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/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +738 -8
- package/dist/popup.d.ts +1 -1
- package/dist/popup.d.ts.map +1 -1
- package/dist/provider.d.ts +2 -2
- package/dist/provider.d.ts.map +1 -1
- package/dist/transport.d.ts +71 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/types.d.ts +104 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +34 -25
package/dist/errors.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export declare const ErrorCodes: {
|
|
|
17
17
|
readonly TIMEOUT: 4008;
|
|
18
18
|
readonly NETWORK_ERROR: 4009;
|
|
19
19
|
readonly ORIGIN_NOT_ALLOWED: 4010;
|
|
20
|
+
readonly TRANSPORT_UNAVAILABLE: 4011;
|
|
21
|
+
readonly FALLBACK_REQUIRED: 4012;
|
|
22
|
+
readonly AUTHORIZATION_TIMEOUT: 4013;
|
|
23
|
+
readonly STATE_MISMATCH: 4014;
|
|
24
|
+
readonly CODE_REPLAY: 4015;
|
|
20
25
|
};
|
|
21
26
|
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
22
27
|
/**
|
|
@@ -53,6 +58,21 @@ export declare class PopupClosedError extends OneSatError {
|
|
|
53
58
|
export declare class TimeoutError extends OneSatError {
|
|
54
59
|
constructor(message?: string);
|
|
55
60
|
}
|
|
61
|
+
export declare class TransportUnavailableError extends OneSatError {
|
|
62
|
+
constructor(message?: string, data?: unknown);
|
|
63
|
+
}
|
|
64
|
+
export declare class FallbackRequiredError extends OneSatError {
|
|
65
|
+
constructor(message?: string, data?: unknown);
|
|
66
|
+
}
|
|
67
|
+
export declare class AuthorizationTimeoutError extends OneSatError {
|
|
68
|
+
constructor(message?: string, data?: unknown);
|
|
69
|
+
}
|
|
70
|
+
export declare class StateMismatchError extends OneSatError {
|
|
71
|
+
constructor(message?: string, data?: unknown);
|
|
72
|
+
}
|
|
73
|
+
export declare class CodeReplayError extends OneSatError {
|
|
74
|
+
constructor(message?: string, data?: unknown);
|
|
75
|
+
}
|
|
56
76
|
/**
|
|
57
77
|
* Create an error from an error response
|
|
58
78
|
*/
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;CAwBb,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAEpE;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;gBAEX,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAO5D,MAAM;;;;;CAON;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,SAA8B;CAIjD;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,SAAqB;CAIxC;AAED,qBAAa,uBAAwB,SAAQ,WAAW;gBAC3C,OAAO,SAA4B;CAI/C;AAED,qBAAa,sBAAuB,SAAQ,WAAW;gBAC1C,OAAO,SAAuB;CAI1C;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,SAAqC;CAIxD;AAED,qBAAa,gBAAiB,SAAQ,WAAW;gBACpC,OAAO,SAAmD;CAItE;AAED,qBAAa,YAAa,SAAQ,WAAW;gBAChC,OAAO,SAAsB;CAIzC;AAED,qBAAa,yBAA0B,SAAQ,WAAW;gBAExD,OAAO,SAA8C,EACrD,IAAI,CAAC,EAAE,OAAO;CAKf;AAED,qBAAa,qBAAsB,SAAQ,WAAW;gBAEpD,OAAO,SAA+C,EACtD,IAAI,CAAC,EAAE,OAAO;CAKf;AAED,qBAAa,yBAA0B,SAAQ,WAAW;gBAC7C,OAAO,SAAiC,EAAE,IAAI,CAAC,EAAE,OAAO;CAIpE;AAED,qBAAa,kBAAmB,SAAQ,WAAW;gBACtC,OAAO,SAAiC,EAAE,IAAI,CAAC,EAAE,OAAO;CAIpE;AAED,qBAAa,eAAgB,SAAQ,WAAW;gBAE9C,OAAO,SAA6C,EACpD,IAAI,CAAC,EAAE,OAAO;CAKf;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACd,GAAG,WAAW,CA6Bd"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { OneSatConfig, OneSatProvider } from
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
1
|
+
import type { OneSatConfig, OneSatProvider } from "./types";
|
|
2
|
+
export { AuthorizationTimeoutError, CodeReplayError, type ErrorCode, ErrorCodes, FallbackRequiredError, fromErrorResponse, InsufficientFundsError, OneSatError, PopupBlockedError, PopupClosedError, StateMismatchError, TimeoutError, TransportUnavailableError, UserRejectedError, WalletLockedError, WalletNotConnectedError, } from "./errors";
|
|
3
|
+
export { type BaseMessage, createErrorResponse, createRequest, createResponse, isResponse, isValidMessage, type MessageType, MessageTypes, PROTOCOL_VERSION, type ProtocolMessage, type RequestMessage, type ResponseMessage, } from "./messages";
|
|
4
|
+
export { type PendingRequest, type PopupConfig, PopupManager } from "./popup";
|
|
5
|
+
export { OneSatBrowserProvider } from "./provider";
|
|
6
|
+
export { clearConnection, hasStoredConnection, loadConnection, type StoredConnection, saveConnection, } from "./storage";
|
|
7
|
+
export { AutoTransport, createAutoTransport, createEmbedTransport, createRedirectTransport, EmbedTransport, RedirectTransport, } from "./transport";
|
|
8
|
+
export type { BalanceResult, CancelListingRequest, ConnectParams, ConnectResult, CreateListingRequest, CWIHandshakeReason, CWIRequestMessage, CWIResponseMessage, CWIState, CWIStateMessage, CWITransport, CWITransportConfig, CWITransportEvent, CWITransportEventHandler, CWITransportName, CWIWalletStatus, EventHandler, InscribeRequest, InscribeResult, ListingResult, ListOptions, MobileFallbackMode, OneSatConfig, OneSatEvent, OneSatProvider, OrdinalOutput, PurchaseListingRequest, RpcMethod, SendOrdinalsRequest, SendResult, SignMessageResult, SignTransactionRequest, SignTransactionResult, TokenOutput, TransferTokenRequest, TransportMode, Utxo, } from "./types";
|
|
9
|
+
export { RpcMethods } from "./types";
|
|
10
|
+
export { closePopup, getPopupContext, isPopupContext, type PopupParams, parsePopupParams, rejectRequest, sendErrorResponse, sendResponse, walletLockedError, walletNotConnectedError, } from "./wallet";
|
|
10
11
|
/**
|
|
11
12
|
* Check if the OneSat provider is injected by browser extension
|
|
12
13
|
* Extensions inject window.onesat with isOneSat: true
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC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,EACtB,qBAAqB,EACrB,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,IAAI,GACJ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EACN,UAAU,EACV,eAAe,EACf,cAAc,EACd,KAAK,WAAW,EAChB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAM1C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAK9D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,cAAc,CAgBlE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,cAAc,CAE/D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAuBrE"}
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
18
18
|
|
|
19
|
-
// ../../node_modules/eventemitter3/index.js
|
|
19
|
+
// ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.js
|
|
20
20
|
var require_eventemitter3 = __commonJS((exports, module) => {
|
|
21
21
|
var has = Object.prototype.hasOwnProperty;
|
|
22
22
|
var prefix = "~";
|
|
@@ -194,7 +194,7 @@ var require_eventemitter3 = __commonJS((exports, module) => {
|
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
// ../../node_modules/eventemitter3/index.mjs
|
|
197
|
+
// ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.mjs
|
|
198
198
|
var import__ = __toESM(require_eventemitter3(), 1);
|
|
199
199
|
var eventemitter3_default = import__.default;
|
|
200
200
|
|
|
@@ -214,7 +214,12 @@ var ErrorCodes = {
|
|
|
214
214
|
POPUP_CLOSED: 4007,
|
|
215
215
|
TIMEOUT: 4008,
|
|
216
216
|
NETWORK_ERROR: 4009,
|
|
217
|
-
ORIGIN_NOT_ALLOWED: 4010
|
|
217
|
+
ORIGIN_NOT_ALLOWED: 4010,
|
|
218
|
+
TRANSPORT_UNAVAILABLE: 4011,
|
|
219
|
+
FALLBACK_REQUIRED: 4012,
|
|
220
|
+
AUTHORIZATION_TIMEOUT: 4013,
|
|
221
|
+
STATE_MISMATCH: 4014,
|
|
222
|
+
CODE_REPLAY: 4015
|
|
218
223
|
};
|
|
219
224
|
|
|
220
225
|
class OneSatError extends Error {
|
|
@@ -283,6 +288,41 @@ class TimeoutError extends OneSatError {
|
|
|
283
288
|
this.name = "TimeoutError";
|
|
284
289
|
}
|
|
285
290
|
}
|
|
291
|
+
|
|
292
|
+
class TransportUnavailableError extends OneSatError {
|
|
293
|
+
constructor(message = "No available transport for wallet request", data) {
|
|
294
|
+
super(ErrorCodes.TRANSPORT_UNAVAILABLE, message, data);
|
|
295
|
+
this.name = "TransportUnavailableError";
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
class FallbackRequiredError extends OneSatError {
|
|
300
|
+
constructor(message = "Embed transport requires redirect fallback", data) {
|
|
301
|
+
super(ErrorCodes.FALLBACK_REQUIRED, message, data);
|
|
302
|
+
this.name = "FallbackRequiredError";
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
class AuthorizationTimeoutError extends OneSatError {
|
|
307
|
+
constructor(message = "Authorization flow timed out", data) {
|
|
308
|
+
super(ErrorCodes.AUTHORIZATION_TIMEOUT, message, data);
|
|
309
|
+
this.name = "AuthorizationTimeoutError";
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
class StateMismatchError extends OneSatError {
|
|
314
|
+
constructor(message = "Authorization state mismatch", data) {
|
|
315
|
+
super(ErrorCodes.STATE_MISMATCH, message, data);
|
|
316
|
+
this.name = "StateMismatchError";
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
class CodeReplayError extends OneSatError {
|
|
321
|
+
constructor(message = "Authorization code has already been used", data) {
|
|
322
|
+
super(ErrorCodes.CODE_REPLAY, message, data);
|
|
323
|
+
this.name = "CodeReplayError";
|
|
324
|
+
}
|
|
325
|
+
}
|
|
286
326
|
function fromErrorResponse(error) {
|
|
287
327
|
switch (error.code) {
|
|
288
328
|
case ErrorCodes.USER_REJECTED:
|
|
@@ -299,6 +339,16 @@ function fromErrorResponse(error) {
|
|
|
299
339
|
return new PopupClosedError(error.message);
|
|
300
340
|
case ErrorCodes.TIMEOUT:
|
|
301
341
|
return new TimeoutError(error.message);
|
|
342
|
+
case ErrorCodes.TRANSPORT_UNAVAILABLE:
|
|
343
|
+
return new TransportUnavailableError(error.message, error.data);
|
|
344
|
+
case ErrorCodes.FALLBACK_REQUIRED:
|
|
345
|
+
return new FallbackRequiredError(error.message, error.data);
|
|
346
|
+
case ErrorCodes.AUTHORIZATION_TIMEOUT:
|
|
347
|
+
return new AuthorizationTimeoutError(error.message, error.data);
|
|
348
|
+
case ErrorCodes.STATE_MISMATCH:
|
|
349
|
+
return new StateMismatchError(error.message, error.data);
|
|
350
|
+
case ErrorCodes.CODE_REPLAY:
|
|
351
|
+
return new CodeReplayError(error.message, error.data);
|
|
302
352
|
default:
|
|
303
353
|
return new OneSatError(error.code, error.message, error.data);
|
|
304
354
|
}
|
|
@@ -365,7 +415,7 @@ function isResponse(msg) {
|
|
|
365
415
|
}
|
|
366
416
|
|
|
367
417
|
// src/popup.ts
|
|
368
|
-
var DEFAULT_POPUP_URL = "https://
|
|
418
|
+
var DEFAULT_POPUP_URL = "https://www.1satwallet.com";
|
|
369
419
|
var DEFAULT_TIMEOUT = 300000;
|
|
370
420
|
var POPUP_CHECK_INTERVAL = 500;
|
|
371
421
|
|
|
@@ -506,7 +556,7 @@ var RpcMethods = {
|
|
|
506
556
|
};
|
|
507
557
|
|
|
508
558
|
// src/provider.ts
|
|
509
|
-
var DEFAULT_POPUP_URL2 = "https://
|
|
559
|
+
var DEFAULT_POPUP_URL2 = "https://www.1satwallet.com";
|
|
510
560
|
var DEFAULT_TIMEOUT2 = 300000;
|
|
511
561
|
|
|
512
562
|
class OneSatBrowserProvider {
|
|
@@ -551,8 +601,8 @@ class OneSatBrowserProvider {
|
|
|
551
601
|
const requestId = this.generateRequestId();
|
|
552
602
|
return this.popupManager.openPopup(method, requestId, params);
|
|
553
603
|
}
|
|
554
|
-
async connect() {
|
|
555
|
-
const result = await this.sendRequest(RpcMethods.CONNECT);
|
|
604
|
+
async connect(params) {
|
|
605
|
+
const result = await this.sendRequest(RpcMethods.CONNECT, params?.challenge ? { challenge: params.challenge } : undefined);
|
|
556
606
|
this.connection = {
|
|
557
607
|
...result,
|
|
558
608
|
connectedAt: Date.now()
|
|
@@ -650,6 +700,675 @@ class OneSatBrowserProvider {
|
|
|
650
700
|
this.events.removeAllListeners();
|
|
651
701
|
}
|
|
652
702
|
}
|
|
703
|
+
// src/transport.ts
|
|
704
|
+
var DEFAULT_WALLET_URL = "https://1sat.market";
|
|
705
|
+
var DEFAULT_IFRAME_PATH = "/wallet/cwi";
|
|
706
|
+
var DEFAULT_AUTHORIZE_INIT_PATH = "/api/cwi/authorize/init";
|
|
707
|
+
var DEFAULT_TOKEN_PATH = "/api/cwi/token";
|
|
708
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 120000;
|
|
709
|
+
var DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS = 1800;
|
|
710
|
+
var DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS = 900;
|
|
711
|
+
var DEFAULT_DESKTOP_MAX_RETRIES = 2;
|
|
712
|
+
var DEFAULT_MOBILE_MAX_RETRIES = 1;
|
|
713
|
+
var REDIRECT_PENDING_KEY = "onesat:cwi:redirect:pending";
|
|
714
|
+
var isRecord = (value) => typeof value === "object" && value !== null;
|
|
715
|
+
var isLikelyMobileRuntime = () => {
|
|
716
|
+
if (typeof navigator === "undefined")
|
|
717
|
+
return false;
|
|
718
|
+
if ("userAgentData" in navigator && typeof navigator.userAgentData === "object" && navigator.userAgentData !== null && "mobile" in navigator.userAgentData) {
|
|
719
|
+
const maybeMobile = navigator.userAgentData.mobile;
|
|
720
|
+
if (typeof maybeMobile === "boolean") {
|
|
721
|
+
return maybeMobile;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
const userAgent = navigator.userAgent ?? "";
|
|
725
|
+
return /Android|iPhone|iPad|iPod|Mobile/i.test(userAgent);
|
|
726
|
+
};
|
|
727
|
+
var createId = () => {
|
|
728
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
729
|
+
return crypto.randomUUID();
|
|
730
|
+
}
|
|
731
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
|
|
732
|
+
};
|
|
733
|
+
var base64UrlEncodeBytes = (input) => {
|
|
734
|
+
let binary = "";
|
|
735
|
+
for (const byte of input) {
|
|
736
|
+
binary += String.fromCharCode(byte);
|
|
737
|
+
}
|
|
738
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
739
|
+
};
|
|
740
|
+
var randomBase64Url = (length = 64) => {
|
|
741
|
+
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
742
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
743
|
+
const bytes = new Uint8Array(length);
|
|
744
|
+
crypto.getRandomValues(bytes);
|
|
745
|
+
return Array.from(bytes, (byte) => charset[byte % charset.length]).join("");
|
|
746
|
+
}
|
|
747
|
+
return Array.from({ length }, () => {
|
|
748
|
+
const index = Math.floor(Math.random() * charset.length);
|
|
749
|
+
return charset[index];
|
|
750
|
+
}).join("");
|
|
751
|
+
};
|
|
752
|
+
var computeS256 = async (verifier) => {
|
|
753
|
+
if (typeof crypto === "undefined" || typeof crypto.subtle === "undefined" || typeof TextEncoder === "undefined") {
|
|
754
|
+
return verifier;
|
|
755
|
+
}
|
|
756
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
757
|
+
return base64UrlEncodeBytes(new Uint8Array(digest));
|
|
758
|
+
};
|
|
759
|
+
var toSearchParams = (searchParams) => {
|
|
760
|
+
if (searchParams instanceof URLSearchParams) {
|
|
761
|
+
return searchParams;
|
|
762
|
+
}
|
|
763
|
+
if (typeof searchParams === "string") {
|
|
764
|
+
const trimmed = searchParams.startsWith("?") ? searchParams.slice(1) : searchParams;
|
|
765
|
+
return new URLSearchParams(trimmed);
|
|
766
|
+
}
|
|
767
|
+
if (typeof window !== "undefined") {
|
|
768
|
+
return new URLSearchParams(window.location.search);
|
|
769
|
+
}
|
|
770
|
+
return new URLSearchParams;
|
|
771
|
+
};
|
|
772
|
+
var normalizeReason = (value) => {
|
|
773
|
+
if (value === "channel_unavailable" || value === "wallet_tab_unreachable" || value === "wallet_locked") {
|
|
774
|
+
return value;
|
|
775
|
+
}
|
|
776
|
+
return;
|
|
777
|
+
};
|
|
778
|
+
var normalizeState = (state) => ({
|
|
779
|
+
status: state.status === "checking" || state.status === "locked" || state.status === "unlocked" || state.status === "no-wallet" ? state.status : undefined,
|
|
780
|
+
hasPermission: typeof state.hasPermission === "boolean" ? state.hasPermission : undefined,
|
|
781
|
+
transport: state.transport === "embed" ? "embed" : undefined,
|
|
782
|
+
fallbackRecommended: typeof state.fallbackRecommended === "boolean" ? state.fallbackRecommended : undefined,
|
|
783
|
+
reason: normalizeReason(state.reason)
|
|
784
|
+
});
|
|
785
|
+
var isCWIStateMessage = (value) => {
|
|
786
|
+
if (!isRecord(value))
|
|
787
|
+
return false;
|
|
788
|
+
if (value.type !== "CWI")
|
|
789
|
+
return false;
|
|
790
|
+
if (!isRecord(value.cwiState))
|
|
791
|
+
return false;
|
|
792
|
+
return true;
|
|
793
|
+
};
|
|
794
|
+
var isCWIResponseMessage = (value) => {
|
|
795
|
+
if (!isRecord(value))
|
|
796
|
+
return false;
|
|
797
|
+
if (value.type !== "CWI")
|
|
798
|
+
return false;
|
|
799
|
+
if (value.isInvocation !== false)
|
|
800
|
+
return false;
|
|
801
|
+
if (typeof value.id !== "string")
|
|
802
|
+
return false;
|
|
803
|
+
return true;
|
|
804
|
+
};
|
|
805
|
+
var toCWIError = (message) => new OneSatError(ErrorCodes.INTERNAL_ERROR, message.description ?? "Wallet request failed", { code: message.code });
|
|
806
|
+
var extractErrorDescription = (value) => {
|
|
807
|
+
if (!isRecord(value))
|
|
808
|
+
return;
|
|
809
|
+
const description = value.error_description;
|
|
810
|
+
if (typeof description === "string" && description.length > 0) {
|
|
811
|
+
return description;
|
|
812
|
+
}
|
|
813
|
+
const fallback = value.error;
|
|
814
|
+
if (typeof fallback === "string" && fallback.length > 0) {
|
|
815
|
+
return fallback;
|
|
816
|
+
}
|
|
817
|
+
return;
|
|
818
|
+
};
|
|
819
|
+
var emitTransportEvent = (emitter, event) => {
|
|
820
|
+
emitter.emit("transport", event);
|
|
821
|
+
};
|
|
822
|
+
var withFetchTimeout = async (input, init, timeoutMs, onTimeout) => {
|
|
823
|
+
const controller = new AbortController;
|
|
824
|
+
const timeoutId = setTimeout(() => {
|
|
825
|
+
controller.abort();
|
|
826
|
+
}, timeoutMs);
|
|
827
|
+
try {
|
|
828
|
+
return await fetch(input, {
|
|
829
|
+
...init,
|
|
830
|
+
signal: controller.signal
|
|
831
|
+
});
|
|
832
|
+
} catch (error) {
|
|
833
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
834
|
+
throw onTimeout();
|
|
835
|
+
}
|
|
836
|
+
throw error;
|
|
837
|
+
} finally {
|
|
838
|
+
clearTimeout(timeoutId);
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
class EmbedTransport {
|
|
843
|
+
mode = "embed";
|
|
844
|
+
walletOrigin;
|
|
845
|
+
iframeUrl;
|
|
846
|
+
requestTimeoutMs;
|
|
847
|
+
handshakeTimeoutMs;
|
|
848
|
+
iframe = null;
|
|
849
|
+
pendingInvocations = new Map;
|
|
850
|
+
stateWaiters = new Set;
|
|
851
|
+
lastState = null;
|
|
852
|
+
events = new eventemitter3_default;
|
|
853
|
+
isDestroyed = false;
|
|
854
|
+
constructor(config) {
|
|
855
|
+
const walletUrl = config?.walletUrl ?? DEFAULT_WALLET_URL;
|
|
856
|
+
const iframePath = config?.iframePath ?? DEFAULT_IFRAME_PATH;
|
|
857
|
+
this.walletOrigin = new URL(walletUrl).origin;
|
|
858
|
+
this.iframeUrl = new URL(iframePath, walletUrl).toString();
|
|
859
|
+
this.requestTimeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
860
|
+
this.handshakeTimeoutMs = config?.handshakeTimeoutMs ?? (isLikelyMobileRuntime() ? DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS : DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS);
|
|
861
|
+
if (typeof window !== "undefined") {
|
|
862
|
+
window.addEventListener("message", this.handleMessage);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
handleMessage = (event) => {
|
|
866
|
+
if (this.isDestroyed)
|
|
867
|
+
return;
|
|
868
|
+
if (event.origin !== this.walletOrigin)
|
|
869
|
+
return;
|
|
870
|
+
if (!this.iframe || event.source !== this.iframe.contentWindow)
|
|
871
|
+
return;
|
|
872
|
+
if (isCWIStateMessage(event.data)) {
|
|
873
|
+
const state = normalizeState(event.data.cwiState);
|
|
874
|
+
this.lastState = state;
|
|
875
|
+
this.resolveStateWaiters(state);
|
|
876
|
+
this.updateIframeVisibility(state.hasPermission === true);
|
|
877
|
+
if (state.fallbackRecommended) {
|
|
878
|
+
emitTransportEvent(this.events, {
|
|
879
|
+
type: "fallback",
|
|
880
|
+
transport: "embed",
|
|
881
|
+
reason: state.reason ?? "channel_unavailable"
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
if (!isCWIResponseMessage(event.data))
|
|
887
|
+
return;
|
|
888
|
+
const pending = this.pendingInvocations.get(event.data.id);
|
|
889
|
+
if (!pending)
|
|
890
|
+
return;
|
|
891
|
+
this.pendingInvocations.delete(event.data.id);
|
|
892
|
+
clearTimeout(pending.timeoutId);
|
|
893
|
+
if (event.data.status === "error") {
|
|
894
|
+
pending.reject(toCWIError(event.data));
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
pending.resolve(event.data.result);
|
|
898
|
+
};
|
|
899
|
+
ensureIframe() {
|
|
900
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
901
|
+
throw new TransportUnavailableError("Embed transport requires a browser");
|
|
902
|
+
}
|
|
903
|
+
if (this.iframe?.contentWindow) {
|
|
904
|
+
return this.iframe;
|
|
905
|
+
}
|
|
906
|
+
const iframe = document.createElement("iframe");
|
|
907
|
+
iframe.src = this.iframeUrl;
|
|
908
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
909
|
+
iframe.style.position = "fixed";
|
|
910
|
+
iframe.style.top = "0";
|
|
911
|
+
iframe.style.left = "0";
|
|
912
|
+
iframe.style.width = "0";
|
|
913
|
+
iframe.style.height = "0";
|
|
914
|
+
iframe.style.border = "0";
|
|
915
|
+
iframe.style.opacity = "0";
|
|
916
|
+
iframe.style.pointerEvents = "none";
|
|
917
|
+
const parent = document.body ?? document.documentElement;
|
|
918
|
+
if (!parent) {
|
|
919
|
+
throw new TransportUnavailableError("Unable to mount CWI iframe in document");
|
|
920
|
+
}
|
|
921
|
+
parent.appendChild(iframe);
|
|
922
|
+
this.iframe = iframe;
|
|
923
|
+
this.updateIframeVisibility(false);
|
|
924
|
+
return iframe;
|
|
925
|
+
}
|
|
926
|
+
updateIframeVisibility(showPermission) {
|
|
927
|
+
const iframe = this.iframe;
|
|
928
|
+
if (!iframe)
|
|
929
|
+
return;
|
|
930
|
+
iframe.style.zIndex = "2147483647";
|
|
931
|
+
if (showPermission) {
|
|
932
|
+
iframe.style.width = "100%";
|
|
933
|
+
iframe.style.height = "100%";
|
|
934
|
+
iframe.style.opacity = "1";
|
|
935
|
+
iframe.style.pointerEvents = "auto";
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
iframe.style.width = "0";
|
|
939
|
+
iframe.style.height = "0";
|
|
940
|
+
iframe.style.opacity = "0";
|
|
941
|
+
iframe.style.pointerEvents = "none";
|
|
942
|
+
}
|
|
943
|
+
resolveStateWaiters(state) {
|
|
944
|
+
for (const waiter of this.stateWaiters) {
|
|
945
|
+
clearTimeout(waiter.timeoutId);
|
|
946
|
+
waiter.resolve(state);
|
|
947
|
+
}
|
|
948
|
+
this.stateWaiters.clear();
|
|
949
|
+
}
|
|
950
|
+
async waitForState(timeoutMs) {
|
|
951
|
+
if (this.lastState) {
|
|
952
|
+
return this.lastState;
|
|
953
|
+
}
|
|
954
|
+
return new Promise((resolve, reject) => {
|
|
955
|
+
const waiter = {
|
|
956
|
+
resolve,
|
|
957
|
+
reject,
|
|
958
|
+
timeoutId: setTimeout(() => {
|
|
959
|
+
this.stateWaiters.delete(waiter);
|
|
960
|
+
reject(new AuthorizationTimeoutError("Embed handshake timed out"));
|
|
961
|
+
}, timeoutMs)
|
|
962
|
+
};
|
|
963
|
+
this.stateWaiters.add(waiter);
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
async handshake(timeoutMs = this.handshakeTimeoutMs) {
|
|
967
|
+
this.ensureIframe();
|
|
968
|
+
const state = await this.waitForState(timeoutMs);
|
|
969
|
+
if (state.fallbackRecommended) {
|
|
970
|
+
throw new FallbackRequiredError(`Embed fallback recommended${state.reason ? ` (${state.reason})` : ""}`, { reason: state.reason });
|
|
971
|
+
}
|
|
972
|
+
return state;
|
|
973
|
+
}
|
|
974
|
+
async invoke(call, args) {
|
|
975
|
+
if (typeof call !== "string" || call.length === 0) {
|
|
976
|
+
throw new OneSatError(ErrorCodes.INVALID_REQUEST, "Invalid CWI call");
|
|
977
|
+
}
|
|
978
|
+
await this.handshake();
|
|
979
|
+
const iframe = this.ensureIframe();
|
|
980
|
+
const target = iframe.contentWindow;
|
|
981
|
+
if (!target) {
|
|
982
|
+
throw new TransportUnavailableError("CWI iframe is not reachable");
|
|
983
|
+
}
|
|
984
|
+
const requestId = createId();
|
|
985
|
+
const request = {
|
|
986
|
+
type: "CWI",
|
|
987
|
+
isInvocation: true,
|
|
988
|
+
id: requestId,
|
|
989
|
+
call,
|
|
990
|
+
args
|
|
991
|
+
};
|
|
992
|
+
return new Promise((resolve, reject) => {
|
|
993
|
+
const timeoutId = setTimeout(() => {
|
|
994
|
+
this.pendingInvocations.delete(requestId);
|
|
995
|
+
reject(new AuthorizationTimeoutError(`CWI request timed out: ${call}`));
|
|
996
|
+
}, this.requestTimeoutMs);
|
|
997
|
+
this.pendingInvocations.set(requestId, {
|
|
998
|
+
resolve,
|
|
999
|
+
reject,
|
|
1000
|
+
timeoutId
|
|
1001
|
+
});
|
|
1002
|
+
try {
|
|
1003
|
+
target.postMessage(request, this.walletOrigin);
|
|
1004
|
+
emitTransportEvent(this.events, {
|
|
1005
|
+
type: "selected",
|
|
1006
|
+
transport: "embed"
|
|
1007
|
+
});
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
clearTimeout(timeoutId);
|
|
1010
|
+
this.pendingInvocations.delete(requestId);
|
|
1011
|
+
reject(new TransportUnavailableError("Failed to post message to CWI iframe", {
|
|
1012
|
+
cause: error instanceof Error ? error.message : String(error)
|
|
1013
|
+
}));
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
async resume() {
|
|
1018
|
+
return null;
|
|
1019
|
+
}
|
|
1020
|
+
on(event, handler) {
|
|
1021
|
+
this.events.on(event, handler);
|
|
1022
|
+
}
|
|
1023
|
+
off(event, handler) {
|
|
1024
|
+
this.events.off(event, handler);
|
|
1025
|
+
}
|
|
1026
|
+
destroy() {
|
|
1027
|
+
if (this.isDestroyed)
|
|
1028
|
+
return;
|
|
1029
|
+
this.isDestroyed = true;
|
|
1030
|
+
if (typeof window !== "undefined") {
|
|
1031
|
+
window.removeEventListener("message", this.handleMessage);
|
|
1032
|
+
}
|
|
1033
|
+
for (const pending of this.pendingInvocations.values()) {
|
|
1034
|
+
clearTimeout(pending.timeoutId);
|
|
1035
|
+
pending.reject(new TransportUnavailableError("Embed transport destroyed"));
|
|
1036
|
+
}
|
|
1037
|
+
this.pendingInvocations.clear();
|
|
1038
|
+
for (const waiter of this.stateWaiters) {
|
|
1039
|
+
clearTimeout(waiter.timeoutId);
|
|
1040
|
+
waiter.reject(new TransportUnavailableError("Embed transport destroyed"));
|
|
1041
|
+
}
|
|
1042
|
+
this.stateWaiters.clear();
|
|
1043
|
+
const iframe = this.iframe;
|
|
1044
|
+
if (iframe?.parentNode) {
|
|
1045
|
+
iframe.parentNode.removeChild(iframe);
|
|
1046
|
+
}
|
|
1047
|
+
this.iframe = null;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
class RedirectTransport {
|
|
1052
|
+
mode = "redirect";
|
|
1053
|
+
authorizeInitUrl;
|
|
1054
|
+
tokenUrl;
|
|
1055
|
+
redirectUri;
|
|
1056
|
+
timeoutMs;
|
|
1057
|
+
events = new eventemitter3_default;
|
|
1058
|
+
constructor(config) {
|
|
1059
|
+
const walletUrl = config?.walletUrl ?? DEFAULT_WALLET_URL;
|
|
1060
|
+
const authorizeInitPath = config?.authorizeInitPath ?? DEFAULT_AUTHORIZE_INIT_PATH;
|
|
1061
|
+
const tokenPath = config?.tokenPath ?? DEFAULT_TOKEN_PATH;
|
|
1062
|
+
this.authorizeInitUrl = new URL(authorizeInitPath, walletUrl).toString();
|
|
1063
|
+
this.tokenUrl = new URL(tokenPath, walletUrl).toString();
|
|
1064
|
+
this.timeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
1065
|
+
if (config?.redirectUri) {
|
|
1066
|
+
this.redirectUri = config.redirectUri;
|
|
1067
|
+
} else if (typeof window !== "undefined") {
|
|
1068
|
+
this.redirectUri = `${window.location.origin}${window.location.pathname}`;
|
|
1069
|
+
} else {
|
|
1070
|
+
this.redirectUri = null;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
savePendingSession(session) {
|
|
1074
|
+
if (typeof sessionStorage === "undefined")
|
|
1075
|
+
return;
|
|
1076
|
+
sessionStorage.setItem(REDIRECT_PENDING_KEY, JSON.stringify(session));
|
|
1077
|
+
}
|
|
1078
|
+
loadPendingSession() {
|
|
1079
|
+
if (typeof sessionStorage === "undefined")
|
|
1080
|
+
return null;
|
|
1081
|
+
const raw = sessionStorage.getItem(REDIRECT_PENDING_KEY);
|
|
1082
|
+
if (!raw)
|
|
1083
|
+
return null;
|
|
1084
|
+
try {
|
|
1085
|
+
const parsed = JSON.parse(raw);
|
|
1086
|
+
if (typeof parsed.state !== "string" || typeof parsed.codeVerifier !== "string" || typeof parsed.redirectUri !== "string" || typeof parsed.createdAt !== "number") {
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
return parsed;
|
|
1090
|
+
} catch {
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
clearPendingSession() {
|
|
1095
|
+
if (typeof sessionStorage === "undefined")
|
|
1096
|
+
return;
|
|
1097
|
+
sessionStorage.removeItem(REDIRECT_PENDING_KEY);
|
|
1098
|
+
}
|
|
1099
|
+
clearAuthQueryParams() {
|
|
1100
|
+
if (typeof window === "undefined" || typeof history === "undefined")
|
|
1101
|
+
return;
|
|
1102
|
+
const url = new URL(window.location.href);
|
|
1103
|
+
let changed = false;
|
|
1104
|
+
for (const key of ["code", "state", "error", "error_description"]) {
|
|
1105
|
+
if (url.searchParams.has(key)) {
|
|
1106
|
+
url.searchParams.delete(key);
|
|
1107
|
+
changed = true;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
if (changed) {
|
|
1111
|
+
history.replaceState(history.state, "", url.toString());
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
async initializeAuthorization(call, args) {
|
|
1115
|
+
if (typeof window === "undefined") {
|
|
1116
|
+
throw new TransportUnavailableError("Redirect transport requires a browser");
|
|
1117
|
+
}
|
|
1118
|
+
if (!this.redirectUri) {
|
|
1119
|
+
throw new TransportUnavailableError("redirectUri is required for redirect fallback");
|
|
1120
|
+
}
|
|
1121
|
+
const state = randomBase64Url(48);
|
|
1122
|
+
const nonce = randomBase64Url(48);
|
|
1123
|
+
const verifier = randomBase64Url(64);
|
|
1124
|
+
const hasSubtle = typeof crypto !== "undefined" && typeof crypto.subtle !== "undefined" && typeof TextEncoder !== "undefined";
|
|
1125
|
+
const method = hasSubtle ? "S256" : "plain";
|
|
1126
|
+
const codeChallenge = await computeS256(verifier);
|
|
1127
|
+
const body = {
|
|
1128
|
+
call,
|
|
1129
|
+
args: args ?? {},
|
|
1130
|
+
redirect_uri: this.redirectUri,
|
|
1131
|
+
state,
|
|
1132
|
+
nonce,
|
|
1133
|
+
code_challenge: codeChallenge,
|
|
1134
|
+
code_challenge_method: method
|
|
1135
|
+
};
|
|
1136
|
+
const response = await withFetchTimeout(this.authorizeInitUrl, {
|
|
1137
|
+
method: "POST",
|
|
1138
|
+
headers: { "content-type": "application/json" },
|
|
1139
|
+
body: JSON.stringify(body),
|
|
1140
|
+
credentials: "omit"
|
|
1141
|
+
}, this.timeoutMs, () => new AuthorizationTimeoutError("authorize/init timed out"));
|
|
1142
|
+
const payload = await response.json().catch(() => ({}));
|
|
1143
|
+
if (!response.ok || !isRecord(payload)) {
|
|
1144
|
+
const description = extractErrorDescription(payload) ?? "Failed to initialize redirect authorization";
|
|
1145
|
+
throw new OneSatError(ErrorCodes.INVALID_REQUEST, description, payload);
|
|
1146
|
+
}
|
|
1147
|
+
const authorizeUrl = payload.authorizeUrl;
|
|
1148
|
+
if (typeof authorizeUrl !== "string" || authorizeUrl.length === 0) {
|
|
1149
|
+
throw new TransportUnavailableError("authorize/init did not return authorizeUrl");
|
|
1150
|
+
}
|
|
1151
|
+
return {
|
|
1152
|
+
authorizeUrl,
|
|
1153
|
+
session: {
|
|
1154
|
+
state,
|
|
1155
|
+
codeVerifier: verifier,
|
|
1156
|
+
redirectUri: this.redirectUri,
|
|
1157
|
+
createdAt: Date.now()
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
async invoke(call, args) {
|
|
1162
|
+
if (typeof call !== "string" || call.length === 0) {
|
|
1163
|
+
throw new OneSatError(ErrorCodes.INVALID_REQUEST, "Invalid CWI call");
|
|
1164
|
+
}
|
|
1165
|
+
if (typeof window === "undefined") {
|
|
1166
|
+
throw new TransportUnavailableError("Redirect transport requires a browser");
|
|
1167
|
+
}
|
|
1168
|
+
const { authorizeUrl, session } = await this.initializeAuthorization(call, args);
|
|
1169
|
+
this.savePendingSession(session);
|
|
1170
|
+
emitTransportEvent(this.events, {
|
|
1171
|
+
type: "selected",
|
|
1172
|
+
transport: "redirect"
|
|
1173
|
+
});
|
|
1174
|
+
window.location.assign(authorizeUrl);
|
|
1175
|
+
return new Promise(() => {});
|
|
1176
|
+
}
|
|
1177
|
+
async exchangeCode(code, session) {
|
|
1178
|
+
const response = await withFetchTimeout(this.tokenUrl, {
|
|
1179
|
+
method: "POST",
|
|
1180
|
+
headers: { "content-type": "application/json" },
|
|
1181
|
+
body: JSON.stringify({
|
|
1182
|
+
code,
|
|
1183
|
+
code_verifier: session.codeVerifier,
|
|
1184
|
+
redirect_uri: session.redirectUri
|
|
1185
|
+
}),
|
|
1186
|
+
credentials: "omit"
|
|
1187
|
+
}, this.timeoutMs, () => new AuthorizationTimeoutError("token exchange timed out"));
|
|
1188
|
+
const payload = await response.json().catch(() => ({}));
|
|
1189
|
+
if (!response.ok || !isRecord(payload)) {
|
|
1190
|
+
const description = extractErrorDescription(payload) ?? "Authorization code exchange failed";
|
|
1191
|
+
if (/already_consumed|replay|consumed/i.test(description)) {
|
|
1192
|
+
throw new CodeReplayError(description);
|
|
1193
|
+
}
|
|
1194
|
+
throw new OneSatError(ErrorCodes.INTERNAL_ERROR, description, payload);
|
|
1195
|
+
}
|
|
1196
|
+
if ("error" in payload) {
|
|
1197
|
+
const description = extractErrorDescription(payload) ?? "Authorization request failed";
|
|
1198
|
+
if (/already_consumed|replay|consumed/i.test(description)) {
|
|
1199
|
+
throw new CodeReplayError(description);
|
|
1200
|
+
}
|
|
1201
|
+
throw new OneSatError(ErrorCodes.INTERNAL_ERROR, description, payload);
|
|
1202
|
+
}
|
|
1203
|
+
return payload.result;
|
|
1204
|
+
}
|
|
1205
|
+
async resume(searchParams) {
|
|
1206
|
+
const params = toSearchParams(searchParams);
|
|
1207
|
+
const code = params.get("code");
|
|
1208
|
+
const state = params.get("state");
|
|
1209
|
+
const error = params.get("error");
|
|
1210
|
+
const errorDescription = params.get("error_description");
|
|
1211
|
+
if (!code && !error) {
|
|
1212
|
+
return null;
|
|
1213
|
+
}
|
|
1214
|
+
const session = this.loadPendingSession();
|
|
1215
|
+
if (!session || !state || state !== session.state) {
|
|
1216
|
+
this.clearPendingSession();
|
|
1217
|
+
this.clearAuthQueryParams();
|
|
1218
|
+
throw new StateMismatchError("Redirect callback state mismatch");
|
|
1219
|
+
}
|
|
1220
|
+
if (error) {
|
|
1221
|
+
this.clearPendingSession();
|
|
1222
|
+
this.clearAuthQueryParams();
|
|
1223
|
+
const payload = {
|
|
1224
|
+
error,
|
|
1225
|
+
error_description: errorDescription ?? undefined
|
|
1226
|
+
};
|
|
1227
|
+
if (error === "access_denied") {
|
|
1228
|
+
throw new OneSatError(ErrorCodes.USER_REJECTED, errorDescription ?? "User denied authorization", payload);
|
|
1229
|
+
}
|
|
1230
|
+
throw new OneSatError(ErrorCodes.INTERNAL_ERROR, errorDescription ?? `Authorization callback error: ${error}`, payload);
|
|
1231
|
+
}
|
|
1232
|
+
if (!code) {
|
|
1233
|
+
this.clearPendingSession();
|
|
1234
|
+
this.clearAuthQueryParams();
|
|
1235
|
+
throw new TransportUnavailableError("Redirect callback missing authorization code");
|
|
1236
|
+
}
|
|
1237
|
+
const result = await this.exchangeCode(code, session);
|
|
1238
|
+
this.clearPendingSession();
|
|
1239
|
+
this.clearAuthQueryParams();
|
|
1240
|
+
return result;
|
|
1241
|
+
}
|
|
1242
|
+
on(event, handler) {
|
|
1243
|
+
this.events.on(event, handler);
|
|
1244
|
+
}
|
|
1245
|
+
off(event, handler) {
|
|
1246
|
+
this.events.off(event, handler);
|
|
1247
|
+
}
|
|
1248
|
+
destroy() {
|
|
1249
|
+
this.clearPendingSession();
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
class AutoTransport {
|
|
1254
|
+
mode = "auto";
|
|
1255
|
+
embed;
|
|
1256
|
+
redirect;
|
|
1257
|
+
events = new eventemitter3_default;
|
|
1258
|
+
selectedTransport = null;
|
|
1259
|
+
mobileFallback;
|
|
1260
|
+
maxEmbedRetries;
|
|
1261
|
+
constructor(config) {
|
|
1262
|
+
const isMobile = isLikelyMobileRuntime();
|
|
1263
|
+
this.mobileFallback = config?.mobileFallback ?? (isMobile ? "auto" : "embed-only");
|
|
1264
|
+
const handshakeTimeoutMs = config?.handshakeTimeoutMs ?? (isMobile ? DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS : DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS);
|
|
1265
|
+
this.maxEmbedRetries = Math.max(1, config?.maxEmbedRetries ?? (isMobile ? DEFAULT_MOBILE_MAX_RETRIES : DEFAULT_DESKTOP_MAX_RETRIES));
|
|
1266
|
+
this.embed = new EmbedTransport({
|
|
1267
|
+
...config,
|
|
1268
|
+
handshakeTimeoutMs
|
|
1269
|
+
});
|
|
1270
|
+
this.redirect = new RedirectTransport(config);
|
|
1271
|
+
}
|
|
1272
|
+
selectTransport(transport, reason, kind = "selected") {
|
|
1273
|
+
if (this.selectedTransport === transport && kind === "selected")
|
|
1274
|
+
return;
|
|
1275
|
+
const previous = this.selectedTransport;
|
|
1276
|
+
this.selectedTransport = transport;
|
|
1277
|
+
emitTransportEvent(this.events, {
|
|
1278
|
+
type: kind,
|
|
1279
|
+
transport,
|
|
1280
|
+
previousTransport: previous ?? undefined,
|
|
1281
|
+
reason
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
shouldTryRedirect() {
|
|
1285
|
+
return this.mobileFallback !== "embed-only";
|
|
1286
|
+
}
|
|
1287
|
+
shouldUseRedirectDirectly() {
|
|
1288
|
+
return this.mobileFallback === "redirect";
|
|
1289
|
+
}
|
|
1290
|
+
shouldRetryEmbed(error) {
|
|
1291
|
+
return error instanceof AuthorizationTimeoutError || error instanceof TransportUnavailableError;
|
|
1292
|
+
}
|
|
1293
|
+
shouldFallbackToRedirect(error) {
|
|
1294
|
+
return error instanceof FallbackRequiredError || error instanceof AuthorizationTimeoutError || error instanceof TransportUnavailableError;
|
|
1295
|
+
}
|
|
1296
|
+
toFallbackReason(error) {
|
|
1297
|
+
if (error instanceof FallbackRequiredError) {
|
|
1298
|
+
const data = error.data;
|
|
1299
|
+
if (isRecord(data)) {
|
|
1300
|
+
const reason = normalizeReason(data.reason);
|
|
1301
|
+
if (reason) {
|
|
1302
|
+
return reason;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
return "channel_unavailable";
|
|
1306
|
+
}
|
|
1307
|
+
if (error instanceof AuthorizationTimeoutError) {
|
|
1308
|
+
return "wallet_tab_unreachable";
|
|
1309
|
+
}
|
|
1310
|
+
return "channel_unavailable";
|
|
1311
|
+
}
|
|
1312
|
+
async invoke(call, args) {
|
|
1313
|
+
if (this.selectedTransport === "redirect" || this.shouldUseRedirectDirectly()) {
|
|
1314
|
+
this.selectTransport("redirect", this.shouldUseRedirectDirectly() ? "mobile_fallback_redirect" : undefined);
|
|
1315
|
+
return this.redirect.invoke(call, args);
|
|
1316
|
+
}
|
|
1317
|
+
try {
|
|
1318
|
+
const result = await this.embed.invoke(call, args);
|
|
1319
|
+
this.selectTransport("embed");
|
|
1320
|
+
return result;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
let resolvedError = error instanceof Error ? error : new TransportUnavailableError(String(error));
|
|
1323
|
+
if (this.selectedTransport !== "embed" && this.shouldRetryEmbed(resolvedError) && this.maxEmbedRetries > 1) {
|
|
1324
|
+
for (let attempt = 2;attempt <= this.maxEmbedRetries; attempt += 1) {
|
|
1325
|
+
try {
|
|
1326
|
+
const result = await this.embed.invoke(call, args);
|
|
1327
|
+
this.selectTransport("embed", `embed_retry_${attempt}`);
|
|
1328
|
+
return result;
|
|
1329
|
+
} catch (retryError) {
|
|
1330
|
+
if (!(retryError instanceof Error)) {
|
|
1331
|
+
throw retryError;
|
|
1332
|
+
}
|
|
1333
|
+
resolvedError = retryError;
|
|
1334
|
+
if (!this.shouldRetryEmbed(retryError)) {
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
if (!this.shouldFallbackToRedirect(resolvedError)) {
|
|
1341
|
+
throw resolvedError;
|
|
1342
|
+
}
|
|
1343
|
+
if (!this.shouldTryRedirect()) {
|
|
1344
|
+
throw resolvedError;
|
|
1345
|
+
}
|
|
1346
|
+
const reason = this.toFallbackReason(resolvedError);
|
|
1347
|
+
this.selectTransport("redirect", reason, "fallback");
|
|
1348
|
+
return this.redirect.invoke(call, args);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
async resume(searchParams) {
|
|
1352
|
+
const result = await this.redirect.resume(searchParams);
|
|
1353
|
+
if (result !== null) {
|
|
1354
|
+
this.selectTransport("redirect", "redirect_callback");
|
|
1355
|
+
}
|
|
1356
|
+
return result;
|
|
1357
|
+
}
|
|
1358
|
+
on(event, handler) {
|
|
1359
|
+
this.events.on(event, handler);
|
|
1360
|
+
}
|
|
1361
|
+
off(event, handler) {
|
|
1362
|
+
this.events.off(event, handler);
|
|
1363
|
+
}
|
|
1364
|
+
destroy() {
|
|
1365
|
+
this.embed.destroy();
|
|
1366
|
+
this.redirect.destroy();
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
var createEmbedTransport = (config) => new EmbedTransport(config);
|
|
1370
|
+
var createRedirectTransport = (config) => new RedirectTransport(config);
|
|
1371
|
+
var createAutoTransport = (config) => new AutoTransport(config);
|
|
653
1372
|
// src/wallet.ts
|
|
654
1373
|
function parsePopupParams(searchParams) {
|
|
655
1374
|
const requestId = searchParams.get("requestId");
|
|
@@ -786,15 +1505,21 @@ export {
|
|
|
786
1505
|
fromErrorResponse,
|
|
787
1506
|
createResponse,
|
|
788
1507
|
createRequest,
|
|
1508
|
+
createRedirectTransport,
|
|
789
1509
|
createOneSat,
|
|
790
1510
|
createErrorResponse,
|
|
1511
|
+
createEmbedTransport,
|
|
1512
|
+
createAutoTransport,
|
|
791
1513
|
closePopup,
|
|
792
1514
|
clearConnection,
|
|
793
1515
|
WalletNotConnectedError,
|
|
794
1516
|
WalletLockedError,
|
|
795
1517
|
UserRejectedError,
|
|
1518
|
+
TransportUnavailableError,
|
|
796
1519
|
TimeoutError,
|
|
1520
|
+
StateMismatchError,
|
|
797
1521
|
RpcMethods,
|
|
1522
|
+
RedirectTransport,
|
|
798
1523
|
PopupManager,
|
|
799
1524
|
PopupClosedError,
|
|
800
1525
|
PopupBlockedError,
|
|
@@ -803,5 +1528,10 @@ export {
|
|
|
803
1528
|
OneSatBrowserProvider,
|
|
804
1529
|
MessageTypes,
|
|
805
1530
|
InsufficientFundsError,
|
|
806
|
-
|
|
1531
|
+
FallbackRequiredError,
|
|
1532
|
+
ErrorCodes,
|
|
1533
|
+
EmbedTransport,
|
|
1534
|
+
CodeReplayError,
|
|
1535
|
+
AutoTransport,
|
|
1536
|
+
AuthorizationTimeoutError
|
|
807
1537
|
};
|
package/dist/popup.d.ts
CHANGED
package/dist/popup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../src/popup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../src/popup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMzC,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IACzC,eAAe,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,qBAAa,YAAY;IACxB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,eAAe,CAA8C;gBAEzD,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAQzC;;OAEG;IACH,SAAS,CAAC,CAAC,EACV,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,OAAO,GACd,OAAO,CAAC,CAAC,CAAC;IA8Db;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAS3D;;OAEG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO;IASvD;;OAEG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI7C;;OAEG;IACH,OAAO,CAAC,OAAO;IAcf;;OAEG;IACH,OAAO,IAAI,IAAI;CAKf"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BalanceResult, type CancelListingRequest, type ConnectResult, type CreateListingRequest, type EventHandler, type InscribeRequest, type InscribeResult, type
|
|
1
|
+
import { type BalanceResult, type CancelListingRequest, type ConnectParams, type ConnectResult, type CreateListingRequest, type EventHandler, type InscribeRequest, type InscribeResult, type ListingResult, type ListOptions, type OneSatConfig, type OneSatEvent, type OneSatProvider, type OrdinalOutput, type PurchaseListingRequest, type SendOrdinalsRequest, type SendResult, type SignMessageResult, type SignTransactionRequest, type SignTransactionResult, type TokenOutput, type TransferTokenRequest, type Utxo } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Browser implementation of the OneSat wallet provider
|
|
4
4
|
* Uses popup-based communication with the wallet
|
|
@@ -23,7 +23,7 @@ export declare class OneSatBrowserProvider implements OneSatProvider {
|
|
|
23
23
|
* Send a request that requires popup approval
|
|
24
24
|
*/
|
|
25
25
|
private sendRequest;
|
|
26
|
-
connect(): Promise<ConnectResult>;
|
|
26
|
+
connect(params?: ConnectParams): Promise<ConnectResult>;
|
|
27
27
|
disconnect(): Promise<void>;
|
|
28
28
|
isConnected(): boolean;
|
|
29
29
|
/**
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAUA,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,oB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Transport implements CWITransport {
|
|
3
|
+
readonly mode: "embed";
|
|
4
|
+
private walletOrigin;
|
|
5
|
+
private iframeUrl;
|
|
6
|
+
private requestTimeoutMs;
|
|
7
|
+
private handshakeTimeoutMs;
|
|
8
|
+
private iframe;
|
|
9
|
+
private pendingInvocations;
|
|
10
|
+
private stateWaiters;
|
|
11
|
+
private lastState;
|
|
12
|
+
private events;
|
|
13
|
+
private isDestroyed;
|
|
14
|
+
constructor(config?: CWITransportConfig);
|
|
15
|
+
private handleMessage;
|
|
16
|
+
private ensureIframe;
|
|
17
|
+
private updateIframeVisibility;
|
|
18
|
+
private resolveStateWaiters;
|
|
19
|
+
private waitForState;
|
|
20
|
+
handshake(timeoutMs?: number): Promise<CWIState>;
|
|
21
|
+
invoke<TResult = unknown>(call: string, args?: unknown): Promise<TResult>;
|
|
22
|
+
resume<TResult = unknown>(): Promise<TResult | null>;
|
|
23
|
+
on(event: 'transport', handler: CWITransportEventHandler): void;
|
|
24
|
+
off(event: 'transport', handler: CWITransportEventHandler): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class RedirectTransport implements CWITransport {
|
|
28
|
+
readonly mode: "redirect";
|
|
29
|
+
private authorizeInitUrl;
|
|
30
|
+
private tokenUrl;
|
|
31
|
+
private redirectUri;
|
|
32
|
+
private timeoutMs;
|
|
33
|
+
private events;
|
|
34
|
+
constructor(config?: CWITransportConfig);
|
|
35
|
+
private savePendingSession;
|
|
36
|
+
private loadPendingSession;
|
|
37
|
+
private clearPendingSession;
|
|
38
|
+
private clearAuthQueryParams;
|
|
39
|
+
private initializeAuthorization;
|
|
40
|
+
invoke<TResult = unknown>(call: string, args?: unknown): Promise<TResult>;
|
|
41
|
+
private exchangeCode;
|
|
42
|
+
resume<TResult = unknown>(searchParams?: URLSearchParams | string): Promise<TResult | null>;
|
|
43
|
+
on(event: 'transport', handler: CWITransportEventHandler): void;
|
|
44
|
+
off(event: 'transport', handler: CWITransportEventHandler): void;
|
|
45
|
+
destroy(): void;
|
|
46
|
+
}
|
|
47
|
+
export declare class AutoTransport implements CWITransport {
|
|
48
|
+
readonly mode: "auto";
|
|
49
|
+
private embed;
|
|
50
|
+
private redirect;
|
|
51
|
+
private events;
|
|
52
|
+
private selectedTransport;
|
|
53
|
+
private mobileFallback;
|
|
54
|
+
private maxEmbedRetries;
|
|
55
|
+
constructor(config?: CWITransportConfig);
|
|
56
|
+
private selectTransport;
|
|
57
|
+
private shouldTryRedirect;
|
|
58
|
+
private shouldUseRedirectDirectly;
|
|
59
|
+
private shouldRetryEmbed;
|
|
60
|
+
private shouldFallbackToRedirect;
|
|
61
|
+
private toFallbackReason;
|
|
62
|
+
invoke<TResult = unknown>(call: string, args?: unknown): Promise<TResult>;
|
|
63
|
+
resume<TResult = unknown>(searchParams?: URLSearchParams | string): Promise<TResult | null>;
|
|
64
|
+
on(event: 'transport', handler: CWITransportEventHandler): void;
|
|
65
|
+
off(event: 'transport', handler: CWITransportEventHandler): void;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
export declare const createEmbedTransport: (config?: CWITransportConfig) => EmbedTransport;
|
|
69
|
+
export declare const createRedirectTransport: (config?: CWITransportConfig) => RedirectTransport;
|
|
70
|
+
export declare const createAutoTransport: (config?: CWITransportConfig) => AutoTransport;
|
|
71
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAIX,QAAQ,EAER,YAAY,EACZ,kBAAkB,EAElB,wBAAwB,EAGxB,MAAM,SAAS,CAAA;AA8NhB,qBAAa,cAAe,YAAW,YAAY;IAClD,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAS;IAEhC,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,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;IAI/D,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAIhE,OAAO,IAAI,IAAI;CAIf;AAED,eAAO,MAAM,oBAAoB,GAChC,SAAS,kBAAkB,KACzB,cAA4C,CAAA;AAE/C,eAAO,MAAM,uBAAuB,GACnC,SAAS,kBAAkB,KACzB,iBAAkD,CAAA;AAErD,eAAO,MAAM,mBAAmB,GAC/B,SAAS,kBAAkB,KACzB,aAA0C,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional parameters for connect()
|
|
3
|
+
*/
|
|
4
|
+
export interface ConnectParams {
|
|
5
|
+
/**
|
|
6
|
+
* An optional challenge message to sign during connection.
|
|
7
|
+
* When provided, the wallet signs the challenge with BSM in the same popup,
|
|
8
|
+
* avoiding a second popup for signMessage().
|
|
9
|
+
* The result is returned in ConnectResult.signedMessage.
|
|
10
|
+
*/
|
|
11
|
+
challenge?: string;
|
|
12
|
+
}
|
|
1
13
|
/**
|
|
2
14
|
* Connection result returned after successful wallet connection
|
|
3
15
|
*/
|
|
@@ -5,6 +17,11 @@ export interface ConnectResult {
|
|
|
5
17
|
paymentAddress: string;
|
|
6
18
|
ordinalAddress: string;
|
|
7
19
|
identityPubKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* If a challenge was provided to connect(), this contains the BSM signature.
|
|
22
|
+
* Only present when connect() was called with a challenge parameter.
|
|
23
|
+
*/
|
|
24
|
+
signedMessage?: SignMessageResult;
|
|
8
25
|
}
|
|
9
26
|
/**
|
|
10
27
|
* Provider configuration options
|
|
@@ -17,8 +34,38 @@ export interface OneSatConfig {
|
|
|
17
34
|
/** Request timeout in milliseconds (default: 300000 = 5 minutes) */
|
|
18
35
|
timeout?: number;
|
|
19
36
|
/** Network to use (default: main) */
|
|
20
|
-
network?:
|
|
37
|
+
network?: "main" | "test";
|
|
38
|
+
}
|
|
39
|
+
/** Transport mode for CWI requests */
|
|
40
|
+
export type TransportMode = "popup" | "embed" | "redirect" | "auto";
|
|
41
|
+
/** Mobile fallback strategy for CWI transport negotiation */
|
|
42
|
+
export type MobileFallbackMode = "auto" | "redirect" | "embed-only";
|
|
43
|
+
/**
|
|
44
|
+
* Configuration options for CWI transport implementations
|
|
45
|
+
*/
|
|
46
|
+
export interface CWITransportConfig {
|
|
47
|
+
/** Base URL for wallet host (default: https://1sat.market) */
|
|
48
|
+
walletUrl?: string;
|
|
49
|
+
/** Embed iframe path (default: /wallet/cwi) */
|
|
50
|
+
iframePath?: string;
|
|
51
|
+
/** Redirect authorize init endpoint path (default: /api/cwi/authorize/init) */
|
|
52
|
+
authorizeInitPath?: string;
|
|
53
|
+
/** Redirect token exchange endpoint path (default: /api/cwi/token) */
|
|
54
|
+
tokenPath?: string;
|
|
55
|
+
/** dApp callback URI for redirect flow */
|
|
56
|
+
redirectUri?: string;
|
|
57
|
+
/** Request timeout in milliseconds */
|
|
58
|
+
timeout?: number;
|
|
59
|
+
/** Embed handshake timeout in milliseconds */
|
|
60
|
+
handshakeTimeoutMs?: number;
|
|
61
|
+
/** Max embed retries before redirect fallback */
|
|
62
|
+
maxEmbedRetries?: number;
|
|
63
|
+
/** Mobile fallback strategy (default: auto) */
|
|
64
|
+
mobileFallback?: MobileFallbackMode;
|
|
21
65
|
}
|
|
66
|
+
/** CWI handshake reason codes from the wallet iframe */
|
|
67
|
+
export type CWIHandshakeReason = "channel_unavailable" | "wallet_tab_unreachable" | "wallet_locked";
|
|
68
|
+
export type CWIWalletStatus = "checking" | "locked" | "unlocked" | "no-wallet";
|
|
22
69
|
/**
|
|
23
70
|
* RPC method names for wallet communication
|
|
24
71
|
*/
|
|
@@ -39,6 +86,60 @@ export declare const RpcMethods: {
|
|
|
39
86
|
readonly GET_UTXOS: "getUtxos";
|
|
40
87
|
};
|
|
41
88
|
export type RpcMethod = (typeof RpcMethods)[keyof typeof RpcMethods];
|
|
89
|
+
export type CWITransportName = "embed" | "redirect";
|
|
90
|
+
/** State signal posted by wallet CWI iframe */
|
|
91
|
+
export interface CWIState {
|
|
92
|
+
status?: CWIWalletStatus;
|
|
93
|
+
hasPermission?: boolean;
|
|
94
|
+
transport?: "embed";
|
|
95
|
+
fallbackRecommended?: boolean;
|
|
96
|
+
reason?: CWIHandshakeReason;
|
|
97
|
+
}
|
|
98
|
+
/** CWI invocation request sent from dApp to iframe */
|
|
99
|
+
export interface CWIRequestMessage {
|
|
100
|
+
type: "CWI";
|
|
101
|
+
isInvocation: true;
|
|
102
|
+
id: string;
|
|
103
|
+
call: string;
|
|
104
|
+
args?: unknown;
|
|
105
|
+
}
|
|
106
|
+
/** CWI invocation response sent from iframe to dApp */
|
|
107
|
+
export interface CWIResponseMessage {
|
|
108
|
+
type: "CWI";
|
|
109
|
+
isInvocation: false;
|
|
110
|
+
id: string;
|
|
111
|
+
result?: unknown;
|
|
112
|
+
status?: "error";
|
|
113
|
+
description?: string;
|
|
114
|
+
code?: number;
|
|
115
|
+
}
|
|
116
|
+
/** CWI state updates posted by wallet iframe */
|
|
117
|
+
export interface CWIStateMessage {
|
|
118
|
+
type: "CWI";
|
|
119
|
+
cwiState: CWIState;
|
|
120
|
+
}
|
|
121
|
+
/** Transport events for telemetry and UX signaling */
|
|
122
|
+
export interface CWITransportEvent {
|
|
123
|
+
type: "selected" | "fallback";
|
|
124
|
+
transport: CWITransportName;
|
|
125
|
+
previousTransport?: CWITransportName;
|
|
126
|
+
reason?: string;
|
|
127
|
+
}
|
|
128
|
+
export type CWITransportEventHandler = (event: CWITransportEvent) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Generic CWI transport interface
|
|
131
|
+
*
|
|
132
|
+
* - `invoke` executes a CWI call
|
|
133
|
+
* - `resume` completes redirect callback (returns null when no callback is present)
|
|
134
|
+
*/
|
|
135
|
+
export interface CWITransport {
|
|
136
|
+
readonly mode: TransportMode;
|
|
137
|
+
invoke<TResult = unknown>(call: string, args?: unknown): Promise<TResult>;
|
|
138
|
+
resume<TResult = unknown>(searchParams?: URLSearchParams | string): Promise<TResult | null>;
|
|
139
|
+
on(event: "transport", handler: CWITransportEventHandler): void;
|
|
140
|
+
off(event: "transport", handler: CWITransportEventHandler): void;
|
|
141
|
+
destroy(): void;
|
|
142
|
+
}
|
|
42
143
|
/**
|
|
43
144
|
* Request to sign a transaction
|
|
44
145
|
*/
|
|
@@ -169,7 +270,7 @@ export interface ListOptions {
|
|
|
169
270
|
/**
|
|
170
271
|
* Event types emitted by the provider
|
|
171
272
|
*/
|
|
172
|
-
export type OneSatEvent =
|
|
273
|
+
export type OneSatEvent = "connect" | "disconnect" | "accountChange";
|
|
173
274
|
/**
|
|
174
275
|
* Event handler function type
|
|
175
276
|
*/
|
|
@@ -190,7 +291,7 @@ declare global {
|
|
|
190
291
|
export interface OneSatProvider {
|
|
191
292
|
/** Identifies this as the OneSat provider (for detection) */
|
|
192
293
|
readonly isOneSat: true;
|
|
193
|
-
connect(): Promise<ConnectResult>;
|
|
294
|
+
connect(params?: ConnectParams): Promise<ConnectResult>;
|
|
194
295
|
disconnect(): Promise<void>;
|
|
195
296
|
isConnected(): boolean;
|
|
196
297
|
signTransaction(request: SignTransactionRequest): Promise<SignTransactionResult>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,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OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAGlE,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAGlE,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAC7D,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACzD,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAG5B,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACpE,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAGrD,YAAY,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1E,iBAAiB,IAAI,MAAM,GAAG,IAAI,CAAC;CACnC"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
"name": "@1sat/connect",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Connection layer for 1Sat wallet - popup flow, events, session management",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target browser && tsc --emitDeclarationOnly",
|
|
19
|
+
"dev": "tsc --watch"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"1sat",
|
|
23
|
+
"bsv",
|
|
24
|
+
"ordinals",
|
|
25
|
+
"wallet",
|
|
26
|
+
"sdk",
|
|
27
|
+
"connect"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"eventemitter3": "^5.0.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
}
|
|
27
36
|
}
|