@1sat/connect 0.0.26 → 0.0.27
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/connectWallet.d.ts +20 -33
- package/dist/connectWallet.d.ts.map +1 -1
- package/dist/index.d.ts +3 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +302 -1655
- package/dist/sigma-oauth.d.ts +23 -21
- package/dist/sigma-oauth.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -69,184 +69,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
69
69
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
// ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.js
|
|
73
|
-
var require_eventemitter3 = __commonJS((exports, module) => {
|
|
74
|
-
var has = Object.prototype.hasOwnProperty;
|
|
75
|
-
var prefix = "~";
|
|
76
|
-
function Events() {}
|
|
77
|
-
if (Object.create) {
|
|
78
|
-
Events.prototype = Object.create(null);
|
|
79
|
-
if (!new Events().__proto__)
|
|
80
|
-
prefix = false;
|
|
81
|
-
}
|
|
82
|
-
function EE(fn, context, once) {
|
|
83
|
-
this.fn = fn;
|
|
84
|
-
this.context = context;
|
|
85
|
-
this.once = once || false;
|
|
86
|
-
}
|
|
87
|
-
function addListener(emitter, event, fn, context, once) {
|
|
88
|
-
if (typeof fn !== "function") {
|
|
89
|
-
throw new TypeError("The listener must be a function");
|
|
90
|
-
}
|
|
91
|
-
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
92
|
-
if (!emitter._events[evt])
|
|
93
|
-
emitter._events[evt] = listener, emitter._eventsCount++;
|
|
94
|
-
else if (!emitter._events[evt].fn)
|
|
95
|
-
emitter._events[evt].push(listener);
|
|
96
|
-
else
|
|
97
|
-
emitter._events[evt] = [emitter._events[evt], listener];
|
|
98
|
-
return emitter;
|
|
99
|
-
}
|
|
100
|
-
function clearEvent(emitter, evt) {
|
|
101
|
-
if (--emitter._eventsCount === 0)
|
|
102
|
-
emitter._events = new Events;
|
|
103
|
-
else
|
|
104
|
-
delete emitter._events[evt];
|
|
105
|
-
}
|
|
106
|
-
function EventEmitter() {
|
|
107
|
-
this._events = new Events;
|
|
108
|
-
this._eventsCount = 0;
|
|
109
|
-
}
|
|
110
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
111
|
-
var names = [], events, name;
|
|
112
|
-
if (this._eventsCount === 0)
|
|
113
|
-
return names;
|
|
114
|
-
for (name in events = this._events) {
|
|
115
|
-
if (has.call(events, name))
|
|
116
|
-
names.push(prefix ? name.slice(1) : name);
|
|
117
|
-
}
|
|
118
|
-
if (Object.getOwnPropertySymbols) {
|
|
119
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
120
|
-
}
|
|
121
|
-
return names;
|
|
122
|
-
};
|
|
123
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
124
|
-
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
125
|
-
if (!handlers)
|
|
126
|
-
return [];
|
|
127
|
-
if (handlers.fn)
|
|
128
|
-
return [handlers.fn];
|
|
129
|
-
for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
|
|
130
|
-
ee[i] = handlers[i].fn;
|
|
131
|
-
}
|
|
132
|
-
return ee;
|
|
133
|
-
};
|
|
134
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
135
|
-
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
136
|
-
if (!listeners)
|
|
137
|
-
return 0;
|
|
138
|
-
if (listeners.fn)
|
|
139
|
-
return 1;
|
|
140
|
-
return listeners.length;
|
|
141
|
-
};
|
|
142
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
143
|
-
var evt = prefix ? prefix + event : event;
|
|
144
|
-
if (!this._events[evt])
|
|
145
|
-
return false;
|
|
146
|
-
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
147
|
-
if (listeners.fn) {
|
|
148
|
-
if (listeners.once)
|
|
149
|
-
this.removeListener(event, listeners.fn, undefined, true);
|
|
150
|
-
switch (len) {
|
|
151
|
-
case 1:
|
|
152
|
-
return listeners.fn.call(listeners.context), true;
|
|
153
|
-
case 2:
|
|
154
|
-
return listeners.fn.call(listeners.context, a1), true;
|
|
155
|
-
case 3:
|
|
156
|
-
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
157
|
-
case 4:
|
|
158
|
-
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
159
|
-
case 5:
|
|
160
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
161
|
-
case 6:
|
|
162
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
163
|
-
}
|
|
164
|
-
for (i = 1, args = new Array(len - 1);i < len; i++) {
|
|
165
|
-
args[i - 1] = arguments[i];
|
|
166
|
-
}
|
|
167
|
-
listeners.fn.apply(listeners.context, args);
|
|
168
|
-
} else {
|
|
169
|
-
var length = listeners.length, j;
|
|
170
|
-
for (i = 0;i < length; i++) {
|
|
171
|
-
if (listeners[i].once)
|
|
172
|
-
this.removeListener(event, listeners[i].fn, undefined, true);
|
|
173
|
-
switch (len) {
|
|
174
|
-
case 1:
|
|
175
|
-
listeners[i].fn.call(listeners[i].context);
|
|
176
|
-
break;
|
|
177
|
-
case 2:
|
|
178
|
-
listeners[i].fn.call(listeners[i].context, a1);
|
|
179
|
-
break;
|
|
180
|
-
case 3:
|
|
181
|
-
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
182
|
-
break;
|
|
183
|
-
case 4:
|
|
184
|
-
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
185
|
-
break;
|
|
186
|
-
default:
|
|
187
|
-
if (!args)
|
|
188
|
-
for (j = 1, args = new Array(len - 1);j < len; j++) {
|
|
189
|
-
args[j - 1] = arguments[j];
|
|
190
|
-
}
|
|
191
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return true;
|
|
196
|
-
};
|
|
197
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
198
|
-
return addListener(this, event, fn, context, false);
|
|
199
|
-
};
|
|
200
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
201
|
-
return addListener(this, event, fn, context, true);
|
|
202
|
-
};
|
|
203
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
204
|
-
var evt = prefix ? prefix + event : event;
|
|
205
|
-
if (!this._events[evt])
|
|
206
|
-
return this;
|
|
207
|
-
if (!fn) {
|
|
208
|
-
clearEvent(this, evt);
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
211
|
-
var listeners = this._events[evt];
|
|
212
|
-
if (listeners.fn) {
|
|
213
|
-
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
214
|
-
clearEvent(this, evt);
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
for (var i = 0, events = [], length = listeners.length;i < length; i++) {
|
|
218
|
-
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
219
|
-
events.push(listeners[i]);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (events.length)
|
|
223
|
-
this._events[evt] = events.length === 1 ? events[0] : events;
|
|
224
|
-
else
|
|
225
|
-
clearEvent(this, evt);
|
|
226
|
-
}
|
|
227
|
-
return this;
|
|
228
|
-
};
|
|
229
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
230
|
-
var evt;
|
|
231
|
-
if (event) {
|
|
232
|
-
evt = prefix ? prefix + event : event;
|
|
233
|
-
if (this._events[evt])
|
|
234
|
-
clearEvent(this, evt);
|
|
235
|
-
} else {
|
|
236
|
-
this._events = new Events;
|
|
237
|
-
this._eventsCount = 0;
|
|
238
|
-
}
|
|
239
|
-
return this;
|
|
240
|
-
};
|
|
241
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
242
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
243
|
-
EventEmitter.prefixed = prefix;
|
|
244
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
245
|
-
if (typeof module !== "undefined") {
|
|
246
|
-
module.exports = EventEmitter;
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
|
|
250
72
|
// node:buffer
|
|
251
73
|
var exports_buffer = {};
|
|
252
74
|
__export(exports_buffer, {
|
|
@@ -1999,13 +1821,13 @@ __export(exports_events, {
|
|
|
1999
1821
|
setMaxListeners: () => setMaxListeners2,
|
|
2000
1822
|
once: () => once2,
|
|
2001
1823
|
listenerCount: () => listenerCount2,
|
|
2002
|
-
init: () =>
|
|
1824
|
+
init: () => EventEmitter,
|
|
2003
1825
|
getMaxListeners: () => getMaxListeners2,
|
|
2004
1826
|
getEventListeners: () => getEventListeners,
|
|
2005
1827
|
default: () => events_default,
|
|
2006
1828
|
captureRejectionSymbol: () => captureRejectionSymbol,
|
|
2007
1829
|
addAbortListener: () => addAbortListener,
|
|
2008
|
-
EventEmitter: () =>
|
|
1830
|
+
EventEmitter: () => EventEmitter
|
|
2009
1831
|
});
|
|
2010
1832
|
function emitError(emitter, args) {
|
|
2011
1833
|
var { _events: events } = emitter;
|
|
@@ -2144,7 +1966,7 @@ function addAbortListener(signal, listener) {
|
|
|
2144
1966
|
removeEventListener?.();
|
|
2145
1967
|
} };
|
|
2146
1968
|
}
|
|
2147
|
-
var SymbolFor, kCapture, kErrorMonitor, kMaxEventTargetListeners, kMaxEventTargetListenersWarned, kRejection, captureRejectionSymbol, ArrayPrototypeSlice, defaultMaxListeners = 10,
|
|
1969
|
+
var SymbolFor, kCapture, kErrorMonitor, kMaxEventTargetListeners, kMaxEventTargetListenersWarned, kRejection, captureRejectionSymbol, ArrayPrototypeSlice, defaultMaxListeners = 10, EventEmitter = function(opts) {
|
|
2148
1970
|
if (this._events === undefined || this._events === this.__proto__._events)
|
|
2149
1971
|
this._events = { __proto__: null }, this._eventsCount = 0;
|
|
2150
1972
|
if (this._maxListeners ??= undefined, this[kCapture] = opts?.captureRejections ? Boolean(opts?.captureRejections) : EventEmitterPrototype[kCapture])
|
|
@@ -2223,14 +2045,14 @@ var init_events = __esm(() => {
|
|
|
2223
2045
|
kRejection = SymbolFor("nodejs.rejection");
|
|
2224
2046
|
captureRejectionSymbol = SymbolFor("nodejs.rejection");
|
|
2225
2047
|
ArrayPrototypeSlice = Array.prototype.slice;
|
|
2226
|
-
EventEmitterPrototype =
|
|
2048
|
+
EventEmitterPrototype = EventEmitter.prototype = {};
|
|
2227
2049
|
EventEmitterPrototype._events = undefined;
|
|
2228
2050
|
EventEmitterPrototype._eventsCount = 0;
|
|
2229
2051
|
EventEmitterPrototype._maxListeners = undefined;
|
|
2230
2052
|
EventEmitterPrototype.setMaxListeners = function(n) {
|
|
2231
2053
|
return validateNumber2(n, "setMaxListeners", 0), this._maxListeners = n, this;
|
|
2232
2054
|
};
|
|
2233
|
-
EventEmitterPrototype.constructor =
|
|
2055
|
+
EventEmitterPrototype.constructor = EventEmitter;
|
|
2234
2056
|
EventEmitterPrototype.getMaxListeners = function() {
|
|
2235
2057
|
return this?._maxListeners ?? defaultMaxListeners;
|
|
2236
2058
|
};
|
|
@@ -2353,7 +2175,7 @@ var init_events = __esm(() => {
|
|
|
2353
2175
|
this.code = "ABORT_ERR", this.name = "AbortError";
|
|
2354
2176
|
}
|
|
2355
2177
|
};
|
|
2356
|
-
Object.defineProperties(
|
|
2178
|
+
Object.defineProperties(EventEmitter, { captureRejections: { get() {
|
|
2357
2179
|
return EventEmitterPrototype[kCapture];
|
|
2358
2180
|
}, set(value) {
|
|
2359
2181
|
validateBoolean(value, "EventEmitter.captureRejections"), EventEmitterPrototype[kCapture] = value;
|
|
@@ -2362,8 +2184,8 @@ var init_events = __esm(() => {
|
|
|
2362
2184
|
}, set: (arg) => {
|
|
2363
2185
|
validateNumber2(arg, "defaultMaxListeners", 0), defaultMaxListeners = arg;
|
|
2364
2186
|
} }, kMaxEventTargetListeners: { value: kMaxEventTargetListeners, enumerable: false, configurable: false, writable: false }, kMaxEventTargetListenersWarned: { value: kMaxEventTargetListenersWarned, enumerable: false, configurable: false, writable: false } });
|
|
2365
|
-
Object.assign(
|
|
2366
|
-
events_default =
|
|
2187
|
+
Object.assign(EventEmitter, { once: once2, getEventListeners, getMaxListeners: getMaxListeners2, setMaxListeners: setMaxListeners2, EventEmitter, usingDomains: false, captureRejectionSymbol, errorMonitor: kErrorMonitor, addAbortListener, init: EventEmitter, listenerCount: listenerCount2 });
|
|
2188
|
+
events_default = EventEmitter;
|
|
2367
2189
|
});
|
|
2368
2190
|
|
|
2369
2191
|
// node:stream
|
|
@@ -21178,7 +21000,7 @@ var init_https = __esm(() => {
|
|
|
21178
21000
|
https_default = https;
|
|
21179
21001
|
});
|
|
21180
21002
|
|
|
21181
|
-
// ../../node_modules/.bun/@bsv+wallet-toolbox@2.1.9+
|
|
21003
|
+
// ../../node_modules/.bun/@bsv+wallet-toolbox@2.1.9+65ab38abbe45c9b2/node_modules/@bsv/wallet-toolbox/out/src/sdk/WalletError.js
|
|
21182
21004
|
var require_WalletError = __commonJS((exports) => {
|
|
21183
21005
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21184
21006
|
exports.WalletError = undefined;
|
|
@@ -21301,539 +21123,6 @@ var require_WalletError = __commonJS((exports) => {
|
|
|
21301
21123
|
exports.WalletError = WalletError3;
|
|
21302
21124
|
});
|
|
21303
21125
|
|
|
21304
|
-
// ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.mjs
|
|
21305
|
-
var import__ = __toESM(require_eventemitter3(), 1);
|
|
21306
|
-
var eventemitter3_default = import__.default;
|
|
21307
|
-
|
|
21308
|
-
// src/errors.ts
|
|
21309
|
-
var ErrorCodes = {
|
|
21310
|
-
PARSE_ERROR: -32700,
|
|
21311
|
-
INVALID_REQUEST: -32600,
|
|
21312
|
-
METHOD_NOT_FOUND: -32601,
|
|
21313
|
-
INVALID_PARAMS: -32602,
|
|
21314
|
-
INTERNAL_ERROR: -32603,
|
|
21315
|
-
USER_REJECTED: 4001,
|
|
21316
|
-
WALLET_LOCKED: 4002,
|
|
21317
|
-
WALLET_NOT_CONNECTED: 4003,
|
|
21318
|
-
INSUFFICIENT_FUNDS: 4004,
|
|
21319
|
-
INVALID_TRANSACTION: 4005,
|
|
21320
|
-
POPUP_BLOCKED: 4006,
|
|
21321
|
-
POPUP_CLOSED: 4007,
|
|
21322
|
-
TIMEOUT: 4008,
|
|
21323
|
-
NETWORK_ERROR: 4009,
|
|
21324
|
-
ORIGIN_NOT_ALLOWED: 4010,
|
|
21325
|
-
TRANSPORT_UNAVAILABLE: 4011,
|
|
21326
|
-
FALLBACK_REQUIRED: 4012,
|
|
21327
|
-
AUTHORIZATION_TIMEOUT: 4013,
|
|
21328
|
-
STATE_MISMATCH: 4014,
|
|
21329
|
-
CODE_REPLAY: 4015
|
|
21330
|
-
};
|
|
21331
|
-
|
|
21332
|
-
class OneSatError extends Error {
|
|
21333
|
-
code;
|
|
21334
|
-
data;
|
|
21335
|
-
constructor(code, message, data) {
|
|
21336
|
-
super(message);
|
|
21337
|
-
this.name = "OneSatError";
|
|
21338
|
-
this.code = code;
|
|
21339
|
-
this.data = data;
|
|
21340
|
-
}
|
|
21341
|
-
toJSON() {
|
|
21342
|
-
return {
|
|
21343
|
-
code: this.code,
|
|
21344
|
-
message: this.message,
|
|
21345
|
-
data: this.data
|
|
21346
|
-
};
|
|
21347
|
-
}
|
|
21348
|
-
}
|
|
21349
|
-
|
|
21350
|
-
class UserRejectedError extends OneSatError {
|
|
21351
|
-
constructor(message = "User rejected the request") {
|
|
21352
|
-
super(ErrorCodes.USER_REJECTED, message);
|
|
21353
|
-
this.name = "UserRejectedError";
|
|
21354
|
-
}
|
|
21355
|
-
}
|
|
21356
|
-
|
|
21357
|
-
class WalletLockedError extends OneSatError {
|
|
21358
|
-
constructor(message = "Wallet is locked") {
|
|
21359
|
-
super(ErrorCodes.WALLET_LOCKED, message);
|
|
21360
|
-
this.name = "WalletLockedError";
|
|
21361
|
-
}
|
|
21362
|
-
}
|
|
21363
|
-
|
|
21364
|
-
class WalletNotConnectedError extends OneSatError {
|
|
21365
|
-
constructor(message = "Wallet is not connected") {
|
|
21366
|
-
super(ErrorCodes.WALLET_NOT_CONNECTED, message);
|
|
21367
|
-
this.name = "WalletNotConnectedError";
|
|
21368
|
-
}
|
|
21369
|
-
}
|
|
21370
|
-
|
|
21371
|
-
class InsufficientFundsError extends OneSatError {
|
|
21372
|
-
constructor(message = "Insufficient funds") {
|
|
21373
|
-
super(ErrorCodes.INSUFFICIENT_FUNDS, message);
|
|
21374
|
-
this.name = "InsufficientFundsError";
|
|
21375
|
-
}
|
|
21376
|
-
}
|
|
21377
|
-
|
|
21378
|
-
class PopupBlockedError extends OneSatError {
|
|
21379
|
-
constructor(message = "Popup was blocked by the browser") {
|
|
21380
|
-
super(ErrorCodes.POPUP_BLOCKED, message);
|
|
21381
|
-
this.name = "PopupBlockedError";
|
|
21382
|
-
}
|
|
21383
|
-
}
|
|
21384
|
-
|
|
21385
|
-
class PopupClosedError extends OneSatError {
|
|
21386
|
-
constructor(message = "Popup was closed before completing the request") {
|
|
21387
|
-
super(ErrorCodes.POPUP_CLOSED, message);
|
|
21388
|
-
this.name = "PopupClosedError";
|
|
21389
|
-
}
|
|
21390
|
-
}
|
|
21391
|
-
|
|
21392
|
-
class TimeoutError extends OneSatError {
|
|
21393
|
-
constructor(message = "Request timed out") {
|
|
21394
|
-
super(ErrorCodes.TIMEOUT, message);
|
|
21395
|
-
this.name = "TimeoutError";
|
|
21396
|
-
}
|
|
21397
|
-
}
|
|
21398
|
-
|
|
21399
|
-
class TransportUnavailableError extends OneSatError {
|
|
21400
|
-
constructor(message = "No available transport for wallet request", data) {
|
|
21401
|
-
super(ErrorCodes.TRANSPORT_UNAVAILABLE, message, data);
|
|
21402
|
-
this.name = "TransportUnavailableError";
|
|
21403
|
-
}
|
|
21404
|
-
}
|
|
21405
|
-
|
|
21406
|
-
class FallbackRequiredError extends OneSatError {
|
|
21407
|
-
constructor(message = "Embed transport requires redirect fallback", data) {
|
|
21408
|
-
super(ErrorCodes.FALLBACK_REQUIRED, message, data);
|
|
21409
|
-
this.name = "FallbackRequiredError";
|
|
21410
|
-
}
|
|
21411
|
-
}
|
|
21412
|
-
|
|
21413
|
-
class AuthorizationTimeoutError extends OneSatError {
|
|
21414
|
-
constructor(message = "Authorization flow timed out", data) {
|
|
21415
|
-
super(ErrorCodes.AUTHORIZATION_TIMEOUT, message, data);
|
|
21416
|
-
this.name = "AuthorizationTimeoutError";
|
|
21417
|
-
}
|
|
21418
|
-
}
|
|
21419
|
-
|
|
21420
|
-
class StateMismatchError extends OneSatError {
|
|
21421
|
-
constructor(message = "Authorization state mismatch", data) {
|
|
21422
|
-
super(ErrorCodes.STATE_MISMATCH, message, data);
|
|
21423
|
-
this.name = "StateMismatchError";
|
|
21424
|
-
}
|
|
21425
|
-
}
|
|
21426
|
-
|
|
21427
|
-
class CodeReplayError extends OneSatError {
|
|
21428
|
-
constructor(message = "Authorization code has already been used", data) {
|
|
21429
|
-
super(ErrorCodes.CODE_REPLAY, message, data);
|
|
21430
|
-
this.name = "CodeReplayError";
|
|
21431
|
-
}
|
|
21432
|
-
}
|
|
21433
|
-
function fromErrorResponse(error) {
|
|
21434
|
-
switch (error.code) {
|
|
21435
|
-
case ErrorCodes.USER_REJECTED:
|
|
21436
|
-
return new UserRejectedError(error.message);
|
|
21437
|
-
case ErrorCodes.WALLET_LOCKED:
|
|
21438
|
-
return new WalletLockedError(error.message);
|
|
21439
|
-
case ErrorCodes.WALLET_NOT_CONNECTED:
|
|
21440
|
-
return new WalletNotConnectedError(error.message);
|
|
21441
|
-
case ErrorCodes.INSUFFICIENT_FUNDS:
|
|
21442
|
-
return new InsufficientFundsError(error.message);
|
|
21443
|
-
case ErrorCodes.POPUP_BLOCKED:
|
|
21444
|
-
return new PopupBlockedError(error.message);
|
|
21445
|
-
case ErrorCodes.POPUP_CLOSED:
|
|
21446
|
-
return new PopupClosedError(error.message);
|
|
21447
|
-
case ErrorCodes.TIMEOUT:
|
|
21448
|
-
return new TimeoutError(error.message);
|
|
21449
|
-
case ErrorCodes.TRANSPORT_UNAVAILABLE:
|
|
21450
|
-
return new TransportUnavailableError(error.message, error.data);
|
|
21451
|
-
case ErrorCodes.FALLBACK_REQUIRED:
|
|
21452
|
-
return new FallbackRequiredError(error.message, error.data);
|
|
21453
|
-
case ErrorCodes.AUTHORIZATION_TIMEOUT:
|
|
21454
|
-
return new AuthorizationTimeoutError(error.message, error.data);
|
|
21455
|
-
case ErrorCodes.STATE_MISMATCH:
|
|
21456
|
-
return new StateMismatchError(error.message, error.data);
|
|
21457
|
-
case ErrorCodes.CODE_REPLAY:
|
|
21458
|
-
return new CodeReplayError(error.message, error.data);
|
|
21459
|
-
default:
|
|
21460
|
-
return new OneSatError(error.code, error.message, error.data);
|
|
21461
|
-
}
|
|
21462
|
-
}
|
|
21463
|
-
|
|
21464
|
-
// src/messages.ts
|
|
21465
|
-
var PROTOCOL_VERSION = "1.0.0";
|
|
21466
|
-
var MessageTypes = {
|
|
21467
|
-
REQUEST: "onesat:request",
|
|
21468
|
-
RESPONSE: "onesat:response"
|
|
21469
|
-
};
|
|
21470
|
-
function createRequest(requestId, method, params, origin) {
|
|
21471
|
-
return {
|
|
21472
|
-
type: MessageTypes.REQUEST,
|
|
21473
|
-
version: PROTOCOL_VERSION,
|
|
21474
|
-
requestId,
|
|
21475
|
-
origin,
|
|
21476
|
-
method,
|
|
21477
|
-
params
|
|
21478
|
-
};
|
|
21479
|
-
}
|
|
21480
|
-
function createResponse(requestId, result, origin) {
|
|
21481
|
-
return {
|
|
21482
|
-
type: MessageTypes.RESPONSE,
|
|
21483
|
-
version: PROTOCOL_VERSION,
|
|
21484
|
-
requestId,
|
|
21485
|
-
origin,
|
|
21486
|
-
result
|
|
21487
|
-
};
|
|
21488
|
-
}
|
|
21489
|
-
function createErrorResponse(requestId, code, message, origin, data) {
|
|
21490
|
-
return {
|
|
21491
|
-
type: MessageTypes.RESPONSE,
|
|
21492
|
-
version: PROTOCOL_VERSION,
|
|
21493
|
-
requestId,
|
|
21494
|
-
origin,
|
|
21495
|
-
error: { code, message, data }
|
|
21496
|
-
};
|
|
21497
|
-
}
|
|
21498
|
-
function isValidMessage(data) {
|
|
21499
|
-
if (typeof data !== "object" || data === null)
|
|
21500
|
-
return false;
|
|
21501
|
-
const msg = data;
|
|
21502
|
-
let type;
|
|
21503
|
-
let version;
|
|
21504
|
-
let requestId;
|
|
21505
|
-
let origin;
|
|
21506
|
-
try {
|
|
21507
|
-
type = msg.type;
|
|
21508
|
-
version = msg.version;
|
|
21509
|
-
requestId = msg.requestId;
|
|
21510
|
-
origin = msg.origin;
|
|
21511
|
-
} catch {
|
|
21512
|
-
return false;
|
|
21513
|
-
}
|
|
21514
|
-
if (typeof type !== "string")
|
|
21515
|
-
return false;
|
|
21516
|
-
if (typeof version !== "string")
|
|
21517
|
-
return false;
|
|
21518
|
-
if (typeof requestId !== "string")
|
|
21519
|
-
return false;
|
|
21520
|
-
if (typeof origin !== "string")
|
|
21521
|
-
return false;
|
|
21522
|
-
if (type === MessageTypes.REQUEST) {
|
|
21523
|
-
let method;
|
|
21524
|
-
try {
|
|
21525
|
-
method = msg.method;
|
|
21526
|
-
} catch {
|
|
21527
|
-
return false;
|
|
21528
|
-
}
|
|
21529
|
-
if (typeof method !== "string")
|
|
21530
|
-
return false;
|
|
21531
|
-
return true;
|
|
21532
|
-
}
|
|
21533
|
-
if (type === MessageTypes.RESPONSE) {
|
|
21534
|
-
return true;
|
|
21535
|
-
}
|
|
21536
|
-
return false;
|
|
21537
|
-
}
|
|
21538
|
-
function isResponse(msg) {
|
|
21539
|
-
return msg.type === MessageTypes.RESPONSE;
|
|
21540
|
-
}
|
|
21541
|
-
|
|
21542
|
-
// src/popup.ts
|
|
21543
|
-
var DEFAULT_POPUP_URL = "https://www.1satwallet.com";
|
|
21544
|
-
var DEFAULT_TIMEOUT = 300000;
|
|
21545
|
-
var POPUP_CHECK_INTERVAL = 500;
|
|
21546
|
-
|
|
21547
|
-
class PopupManager {
|
|
21548
|
-
config;
|
|
21549
|
-
pendingRequests = new Map;
|
|
21550
|
-
constructor(config) {
|
|
21551
|
-
this.config = {
|
|
21552
|
-
popupUrl: config?.popupUrl ?? DEFAULT_POPUP_URL,
|
|
21553
|
-
timeout: config?.timeout ?? DEFAULT_TIMEOUT,
|
|
21554
|
-
appName: config?.appName
|
|
21555
|
-
};
|
|
21556
|
-
}
|
|
21557
|
-
openPopup(method, requestId, params) {
|
|
21558
|
-
return new Promise((resolve, reject) => {
|
|
21559
|
-
const url = new URL(`${this.config.popupUrl}/connect`);
|
|
21560
|
-
url.searchParams.set("method", method);
|
|
21561
|
-
url.searchParams.set("requestId", requestId);
|
|
21562
|
-
url.searchParams.set("origin", window.location.origin);
|
|
21563
|
-
if (this.config.appName) {
|
|
21564
|
-
url.searchParams.set("appName", this.config.appName);
|
|
21565
|
-
}
|
|
21566
|
-
if (params) {
|
|
21567
|
-
url.searchParams.set("params", JSON.stringify(params));
|
|
21568
|
-
}
|
|
21569
|
-
const width = 420;
|
|
21570
|
-
const height = 640;
|
|
21571
|
-
const left = Math.max(0, (window.screen.width - width) / 2);
|
|
21572
|
-
const top = Math.max(0, (window.screen.height - height) / 2);
|
|
21573
|
-
const popup = window.open(url.toString(), "onesat-wallet", `width=${width},height=${height},left=${left},top=${top},popup=1,scrollbars=1`);
|
|
21574
|
-
if (!popup) {
|
|
21575
|
-
reject(new PopupBlockedError);
|
|
21576
|
-
return;
|
|
21577
|
-
}
|
|
21578
|
-
popup.focus();
|
|
21579
|
-
const timeoutId = setTimeout(() => {
|
|
21580
|
-
this.cleanup(requestId);
|
|
21581
|
-
reject(new TimeoutError);
|
|
21582
|
-
}, this.config.timeout);
|
|
21583
|
-
const checkIntervalId = setInterval(() => {
|
|
21584
|
-
if (popup.closed) {
|
|
21585
|
-
this.cleanup(requestId);
|
|
21586
|
-
reject(new PopupClosedError);
|
|
21587
|
-
}
|
|
21588
|
-
}, POPUP_CHECK_INTERVAL);
|
|
21589
|
-
this.pendingRequests.set(requestId, {
|
|
21590
|
-
resolve,
|
|
21591
|
-
reject,
|
|
21592
|
-
popup,
|
|
21593
|
-
timeoutId,
|
|
21594
|
-
checkIntervalId
|
|
21595
|
-
});
|
|
21596
|
-
});
|
|
21597
|
-
}
|
|
21598
|
-
resolveRequest(requestId, result) {
|
|
21599
|
-
const pending = this.pendingRequests.get(requestId);
|
|
21600
|
-
if (!pending)
|
|
21601
|
-
return false;
|
|
21602
|
-
this.cleanup(requestId);
|
|
21603
|
-
pending.resolve(result);
|
|
21604
|
-
return true;
|
|
21605
|
-
}
|
|
21606
|
-
rejectRequest(requestId, error) {
|
|
21607
|
-
const pending = this.pendingRequests.get(requestId);
|
|
21608
|
-
if (!pending)
|
|
21609
|
-
return false;
|
|
21610
|
-
this.cleanup(requestId);
|
|
21611
|
-
pending.reject(error);
|
|
21612
|
-
return true;
|
|
21613
|
-
}
|
|
21614
|
-
hasPendingRequest(requestId) {
|
|
21615
|
-
return this.pendingRequests.has(requestId);
|
|
21616
|
-
}
|
|
21617
|
-
cleanup(requestId) {
|
|
21618
|
-
const pending = this.pendingRequests.get(requestId);
|
|
21619
|
-
if (!pending)
|
|
21620
|
-
return;
|
|
21621
|
-
clearTimeout(pending.timeoutId);
|
|
21622
|
-
clearInterval(pending.checkIntervalId);
|
|
21623
|
-
if (pending.popup && !pending.popup.closed) {
|
|
21624
|
-
pending.popup.close();
|
|
21625
|
-
}
|
|
21626
|
-
this.pendingRequests.delete(requestId);
|
|
21627
|
-
}
|
|
21628
|
-
destroy() {
|
|
21629
|
-
for (const requestId of this.pendingRequests.keys()) {
|
|
21630
|
-
this.cleanup(requestId);
|
|
21631
|
-
}
|
|
21632
|
-
}
|
|
21633
|
-
}
|
|
21634
|
-
|
|
21635
|
-
// src/storage.ts
|
|
21636
|
-
var STORAGE_KEY = "onesat:connection";
|
|
21637
|
-
function saveConnection(connection) {
|
|
21638
|
-
const stored = {
|
|
21639
|
-
...connection,
|
|
21640
|
-
connectedAt: Date.now()
|
|
21641
|
-
};
|
|
21642
|
-
try {
|
|
21643
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(stored));
|
|
21644
|
-
} catch {}
|
|
21645
|
-
}
|
|
21646
|
-
function loadConnection() {
|
|
21647
|
-
try {
|
|
21648
|
-
const data = localStorage.getItem(STORAGE_KEY);
|
|
21649
|
-
if (!data)
|
|
21650
|
-
return null;
|
|
21651
|
-
return JSON.parse(data);
|
|
21652
|
-
} catch {
|
|
21653
|
-
return null;
|
|
21654
|
-
}
|
|
21655
|
-
}
|
|
21656
|
-
function clearConnection() {
|
|
21657
|
-
try {
|
|
21658
|
-
localStorage.removeItem(STORAGE_KEY);
|
|
21659
|
-
} catch {}
|
|
21660
|
-
}
|
|
21661
|
-
function hasStoredConnection() {
|
|
21662
|
-
return loadConnection() !== null;
|
|
21663
|
-
}
|
|
21664
|
-
|
|
21665
|
-
// src/types.ts
|
|
21666
|
-
var RpcMethods = {
|
|
21667
|
-
CONNECT: "connect",
|
|
21668
|
-
DISCONNECT: "disconnect",
|
|
21669
|
-
SIGN_TRANSACTION: "signTransaction",
|
|
21670
|
-
SIGN_MESSAGE: "signMessage",
|
|
21671
|
-
INSCRIBE: "inscribe",
|
|
21672
|
-
SEND_ORDINALS: "sendOrdinals",
|
|
21673
|
-
CREATE_LISTING: "createListing",
|
|
21674
|
-
PURCHASE_LISTING: "purchaseListing",
|
|
21675
|
-
CANCEL_LISTING: "cancelListing",
|
|
21676
|
-
TRANSFER_TOKEN: "transferToken",
|
|
21677
|
-
GET_BALANCE: "getBalance",
|
|
21678
|
-
GET_ORDINALS: "getOrdinals",
|
|
21679
|
-
GET_TOKENS: "getTokens",
|
|
21680
|
-
GET_UTXOS: "getUtxos"
|
|
21681
|
-
};
|
|
21682
|
-
|
|
21683
|
-
// src/provider.ts
|
|
21684
|
-
var DEFAULT_POPUP_URL2 = "https://www.1satwallet.com";
|
|
21685
|
-
var DEFAULT_TIMEOUT2 = 300000;
|
|
21686
|
-
|
|
21687
|
-
class OneSatBrowserProvider {
|
|
21688
|
-
isOneSat = true;
|
|
21689
|
-
popupManager;
|
|
21690
|
-
connection = null;
|
|
21691
|
-
events = new eventemitter3_default;
|
|
21692
|
-
popupOrigin;
|
|
21693
|
-
constructor(config) {
|
|
21694
|
-
const popupUrl = config?.popupUrl ?? DEFAULT_POPUP_URL2;
|
|
21695
|
-
this.popupManager = new PopupManager({
|
|
21696
|
-
popupUrl,
|
|
21697
|
-
timeout: config?.timeout ?? DEFAULT_TIMEOUT2,
|
|
21698
|
-
appName: config?.appName
|
|
21699
|
-
});
|
|
21700
|
-
this.popupOrigin = new URL(popupUrl).origin;
|
|
21701
|
-
this.connection = loadConnection();
|
|
21702
|
-
if (typeof window !== "undefined") {
|
|
21703
|
-
window.addEventListener("message", this.handleMessage);
|
|
21704
|
-
}
|
|
21705
|
-
}
|
|
21706
|
-
handleMessage = (event) => {
|
|
21707
|
-
let eventOrigin;
|
|
21708
|
-
let eventData;
|
|
21709
|
-
try {
|
|
21710
|
-
eventOrigin = event.origin;
|
|
21711
|
-
eventData = event.data;
|
|
21712
|
-
} catch {
|
|
21713
|
-
return;
|
|
21714
|
-
}
|
|
21715
|
-
if (eventOrigin !== this.popupOrigin)
|
|
21716
|
-
return;
|
|
21717
|
-
if (!isValidMessage(eventData))
|
|
21718
|
-
return;
|
|
21719
|
-
if (!isResponse(eventData))
|
|
21720
|
-
return;
|
|
21721
|
-
const { requestId, result, error } = eventData;
|
|
21722
|
-
if (!this.popupManager.hasPendingRequest(requestId))
|
|
21723
|
-
return;
|
|
21724
|
-
if (error) {
|
|
21725
|
-
this.popupManager.rejectRequest(requestId, fromErrorResponse(error));
|
|
21726
|
-
} else {
|
|
21727
|
-
this.popupManager.resolveRequest(requestId, result);
|
|
21728
|
-
}
|
|
21729
|
-
};
|
|
21730
|
-
generateRequestId() {
|
|
21731
|
-
return crypto.randomUUID();
|
|
21732
|
-
}
|
|
21733
|
-
async sendRequest(method, params) {
|
|
21734
|
-
const requestId = this.generateRequestId();
|
|
21735
|
-
return this.popupManager.openPopup(method, requestId, params);
|
|
21736
|
-
}
|
|
21737
|
-
async connect(params) {
|
|
21738
|
-
const result = await this.sendRequest(RpcMethods.CONNECT, params?.challenge ? { challenge: params.challenge } : undefined);
|
|
21739
|
-
this.connection = {
|
|
21740
|
-
...result,
|
|
21741
|
-
connectedAt: Date.now()
|
|
21742
|
-
};
|
|
21743
|
-
saveConnection(result);
|
|
21744
|
-
this.events.emit("connect", result);
|
|
21745
|
-
return result;
|
|
21746
|
-
}
|
|
21747
|
-
async disconnect() {
|
|
21748
|
-
this.connection = null;
|
|
21749
|
-
clearConnection();
|
|
21750
|
-
this.events.emit("disconnect", undefined);
|
|
21751
|
-
}
|
|
21752
|
-
isConnected() {
|
|
21753
|
-
return this.connection !== null;
|
|
21754
|
-
}
|
|
21755
|
-
requireConnection() {
|
|
21756
|
-
if (!this.connection) {
|
|
21757
|
-
throw new WalletNotConnectedError;
|
|
21758
|
-
}
|
|
21759
|
-
return this.connection;
|
|
21760
|
-
}
|
|
21761
|
-
async signTransaction(request) {
|
|
21762
|
-
this.requireConnection();
|
|
21763
|
-
return this.sendRequest(RpcMethods.SIGN_TRANSACTION, request);
|
|
21764
|
-
}
|
|
21765
|
-
async signMessage(message) {
|
|
21766
|
-
this.requireConnection();
|
|
21767
|
-
return this.sendRequest(RpcMethods.SIGN_MESSAGE, {
|
|
21768
|
-
message
|
|
21769
|
-
});
|
|
21770
|
-
}
|
|
21771
|
-
async inscribe(request) {
|
|
21772
|
-
this.requireConnection();
|
|
21773
|
-
return this.sendRequest(RpcMethods.INSCRIBE, request);
|
|
21774
|
-
}
|
|
21775
|
-
async sendOrdinals(request) {
|
|
21776
|
-
this.requireConnection();
|
|
21777
|
-
return this.sendRequest(RpcMethods.SEND_ORDINALS, request);
|
|
21778
|
-
}
|
|
21779
|
-
async createListing(request) {
|
|
21780
|
-
this.requireConnection();
|
|
21781
|
-
return this.sendRequest(RpcMethods.CREATE_LISTING, request);
|
|
21782
|
-
}
|
|
21783
|
-
async purchaseListing(request) {
|
|
21784
|
-
this.requireConnection();
|
|
21785
|
-
return this.sendRequest(RpcMethods.PURCHASE_LISTING, request);
|
|
21786
|
-
}
|
|
21787
|
-
async cancelListing(request) {
|
|
21788
|
-
this.requireConnection();
|
|
21789
|
-
return this.sendRequest(RpcMethods.CANCEL_LISTING, request);
|
|
21790
|
-
}
|
|
21791
|
-
async transferToken(request) {
|
|
21792
|
-
this.requireConnection();
|
|
21793
|
-
return this.sendRequest(RpcMethods.TRANSFER_TOKEN, request);
|
|
21794
|
-
}
|
|
21795
|
-
async getBalance() {
|
|
21796
|
-
this.requireConnection();
|
|
21797
|
-
return this.sendRequest(RpcMethods.GET_BALANCE);
|
|
21798
|
-
}
|
|
21799
|
-
async getOrdinals(options) {
|
|
21800
|
-
this.requireConnection();
|
|
21801
|
-
return this.sendRequest(RpcMethods.GET_ORDINALS, options);
|
|
21802
|
-
}
|
|
21803
|
-
async getTokens(options) {
|
|
21804
|
-
this.requireConnection();
|
|
21805
|
-
return this.sendRequest(RpcMethods.GET_TOKENS, options);
|
|
21806
|
-
}
|
|
21807
|
-
async getUtxos() {
|
|
21808
|
-
this.requireConnection();
|
|
21809
|
-
return this.sendRequest(RpcMethods.GET_UTXOS);
|
|
21810
|
-
}
|
|
21811
|
-
on(event, handler) {
|
|
21812
|
-
this.events.on(event, handler);
|
|
21813
|
-
}
|
|
21814
|
-
off(event, handler) {
|
|
21815
|
-
this.events.off(event, handler);
|
|
21816
|
-
}
|
|
21817
|
-
getAddresses() {
|
|
21818
|
-
if (!this.connection)
|
|
21819
|
-
return null;
|
|
21820
|
-
return {
|
|
21821
|
-
paymentAddress: this.connection.paymentAddress,
|
|
21822
|
-
ordinalAddress: this.connection.ordinalAddress
|
|
21823
|
-
};
|
|
21824
|
-
}
|
|
21825
|
-
getIdentityPubKey() {
|
|
21826
|
-
return this.connection?.identityPubKey ?? null;
|
|
21827
|
-
}
|
|
21828
|
-
destroy() {
|
|
21829
|
-
if (typeof window !== "undefined") {
|
|
21830
|
-
window.removeEventListener("message", this.handleMessage);
|
|
21831
|
-
}
|
|
21832
|
-
this.popupManager.destroy();
|
|
21833
|
-
this.events.removeAllListeners();
|
|
21834
|
-
}
|
|
21835
|
-
}
|
|
21836
|
-
|
|
21837
21126
|
// ../client/dist/errors.js
|
|
21838
21127
|
class HttpError extends Error {
|
|
21839
21128
|
status;
|
|
@@ -38881,7 +38170,7 @@ var MAX_BACKOFF_MS = 60000;
|
|
|
38881
38170
|
var FAILURE_PENALTY_MS = 400;
|
|
38882
38171
|
var SUCCESS_BONUS_MS = 30;
|
|
38883
38172
|
var FAILURE_BACKOFF_GRACE = 2;
|
|
38884
|
-
var
|
|
38173
|
+
var STORAGE_KEY = "bsvsdk_overlay_host_reputation_v1";
|
|
38885
38174
|
|
|
38886
38175
|
class HostReputationTracker {
|
|
38887
38176
|
stats;
|
|
@@ -39013,7 +38302,7 @@ class HostReputationTracker {
|
|
|
39013
38302
|
if (s2 == null)
|
|
39014
38303
|
return;
|
|
39015
38304
|
try {
|
|
39016
|
-
const raw = s2.get(
|
|
38305
|
+
const raw = s2.get(STORAGE_KEY);
|
|
39017
38306
|
if (typeof raw !== "string" || raw.length === 0)
|
|
39018
38307
|
return;
|
|
39019
38308
|
const data = JSON.parse(raw);
|
|
@@ -39048,7 +38337,7 @@ class HostReputationTracker {
|
|
|
39048
38337
|
for (const [host, entry] of this.stats.entries()) {
|
|
39049
38338
|
obj[host] = entry;
|
|
39050
38339
|
}
|
|
39051
|
-
s2.set(
|
|
38340
|
+
s2.set(STORAGE_KEY, JSON.stringify(obj));
|
|
39052
38341
|
} catch {}
|
|
39053
38342
|
}
|
|
39054
38343
|
computeScore(entry, now) {
|
|
@@ -40338,7 +39627,7 @@ class Historian {
|
|
|
40338
39627
|
}
|
|
40339
39628
|
}
|
|
40340
39629
|
}
|
|
40341
|
-
const
|
|
39630
|
+
const history = [];
|
|
40342
39631
|
const visited = new Set;
|
|
40343
39632
|
const traverseHistory = async (transaction) => {
|
|
40344
39633
|
const txid = transaction.id("hex");
|
|
@@ -40356,7 +39645,7 @@ class Historian {
|
|
|
40356
39645
|
try {
|
|
40357
39646
|
const interpretedValue = await Promise.resolve(this.interpreter(transaction, outputIndex, context));
|
|
40358
39647
|
if (interpretedValue !== undefined) {
|
|
40359
|
-
|
|
39648
|
+
history.push(interpretedValue);
|
|
40360
39649
|
if (this.debug) {
|
|
40361
39650
|
console.log("[Historian] Added value to history:", interpretedValue);
|
|
40362
39651
|
}
|
|
@@ -40376,7 +39665,7 @@ class Historian {
|
|
|
40376
39665
|
}
|
|
40377
39666
|
};
|
|
40378
39667
|
await traverseHistory(startTransaction);
|
|
40379
|
-
const chronological =
|
|
39668
|
+
const chronological = history.reverse();
|
|
40380
39669
|
if (this.historyCache != null) {
|
|
40381
39670
|
const cacheKey = this.historyKey(startTransaction, context);
|
|
40382
39671
|
this.historyCache.set(cacheKey, Object.freeze(chronological.slice()));
|
|
@@ -40919,12 +40208,13 @@ var BSocialContext;
|
|
|
40919
40208
|
BSocialContext2["BTC_TX"] = "btcTx";
|
|
40920
40209
|
BSocialContext2["ETH_TX"] = "ethTx";
|
|
40921
40210
|
})(BSocialContext || (BSocialContext = {}));
|
|
40922
|
-
//
|
|
40923
|
-
var
|
|
40924
|
-
((
|
|
40925
|
-
|
|
40926
|
-
|
|
40927
|
-
})(
|
|
40211
|
+
// ../templates/dist/bitcom/sigma.js
|
|
40212
|
+
var SigmaAlgorithm;
|
|
40213
|
+
(function(SigmaAlgorithm2) {
|
|
40214
|
+
SigmaAlgorithm2["BSM"] = "BSM";
|
|
40215
|
+
SigmaAlgorithm2["BRC77"] = "BRC77";
|
|
40216
|
+
})(SigmaAlgorithm || (SigmaAlgorithm = {}));
|
|
40217
|
+
var EMPTY_OUTPOINT = new Array(32).fill(0);
|
|
40928
40218
|
// ../wallet/dist/indexers/Bsv21Indexer.js
|
|
40929
40219
|
var hdKey = HD.fromString(BSV21_FEE_XPUB);
|
|
40930
40220
|
// ../../node_modules/.bun/@bopen-io+templates@1.2.3/node_modules/@bopen-io/templates/dist/esm/src/template/bitcom/B.js
|
|
@@ -41164,7 +40454,7 @@ var DEFAULT_IFRAME_PATH = "/wallet/cwi";
|
|
|
41164
40454
|
var DEFAULT_REQUEST_TIMEOUT_MS = 120000;
|
|
41165
40455
|
var DEFAULT_HANDSHAKE_TIMEOUT_MS = 5000;
|
|
41166
40456
|
var isRecord = (v) => typeof v === "object" && v !== null;
|
|
41167
|
-
var
|
|
40457
|
+
var isResponse = (v) => isRecord(v) && v.type === "CWI" && v.isInvocation === false && typeof v.id === "string";
|
|
41168
40458
|
var isState = (v) => isRecord(v) && v.type === "CWI" && isRecord(v.cwiState);
|
|
41169
40459
|
var createId = () => typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
|
|
41170
40460
|
function createWebCWI(config) {
|
|
@@ -41212,7 +40502,7 @@ function createWebCWI(config) {
|
|
|
41212
40502
|
}
|
|
41213
40503
|
return;
|
|
41214
40504
|
}
|
|
41215
|
-
if (!
|
|
40505
|
+
if (!isResponse(data))
|
|
41216
40506
|
return;
|
|
41217
40507
|
const req = pending.get(data.id);
|
|
41218
40508
|
if (!req)
|
|
@@ -41335,7 +40625,7 @@ var DEFAULT_IFRAME_PATH2 = "/signer";
|
|
|
41335
40625
|
var DEFAULT_REQUEST_TIMEOUT_MS2 = 120000;
|
|
41336
40626
|
var DEFAULT_HANDSHAKE_TIMEOUT_MS2 = 1e4;
|
|
41337
40627
|
var isRecord2 = (v) => typeof v === "object" && v !== null;
|
|
41338
|
-
var
|
|
40628
|
+
var isResponse2 = (v) => isRecord2(v) && v.type === "CWI" && v.isInvocation === false && typeof v.id === "string";
|
|
41339
40629
|
var isState2 = (v) => isRecord2(v) && v.type === "CWI" && isRecord2(v.cwiState);
|
|
41340
40630
|
var createId2 = () => typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
|
|
41341
40631
|
function createSigmaCWI(config) {
|
|
@@ -41406,7 +40696,7 @@ function createSigmaCWI(config) {
|
|
|
41406
40696
|
}
|
|
41407
40697
|
return;
|
|
41408
40698
|
}
|
|
41409
|
-
if (!
|
|
40699
|
+
if (!isResponse2(data))
|
|
41410
40700
|
return;
|
|
41411
40701
|
const req = pending.get(data.id);
|
|
41412
40702
|
if (!req)
|
|
@@ -41515,7 +40805,90 @@ function createSigmaCWI(config) {
|
|
|
41515
40805
|
};
|
|
41516
40806
|
return { wallet: createCWI(transport), destroy, sendCustomMessage };
|
|
41517
40807
|
}
|
|
41518
|
-
//
|
|
40808
|
+
// src/connectWallet.ts
|
|
40809
|
+
var LAST_PROVIDER_KEY = "cwi_last_provider";
|
|
40810
|
+
function saveLastProvider(providerType) {
|
|
40811
|
+
if (typeof window === "undefined")
|
|
40812
|
+
return;
|
|
40813
|
+
try {
|
|
40814
|
+
localStorage.setItem(LAST_PROVIDER_KEY, providerType);
|
|
40815
|
+
} catch {}
|
|
40816
|
+
}
|
|
40817
|
+
function loadLastProvider() {
|
|
40818
|
+
if (typeof window === "undefined")
|
|
40819
|
+
return null;
|
|
40820
|
+
try {
|
|
40821
|
+
return localStorage.getItem(LAST_PROVIDER_KEY);
|
|
40822
|
+
} catch {
|
|
40823
|
+
return null;
|
|
40824
|
+
}
|
|
40825
|
+
}
|
|
40826
|
+
async function connectAutoDetect() {
|
|
40827
|
+
const client = new WalletClient("auto");
|
|
40828
|
+
await client.connectToSubstrate();
|
|
40829
|
+
await client.waitForAuthentication({});
|
|
40830
|
+
const { publicKey } = await client.getPublicKey({ identityKey: true });
|
|
40831
|
+
return {
|
|
40832
|
+
wallet: client,
|
|
40833
|
+
provider: "brc100",
|
|
40834
|
+
identityKey: publicKey,
|
|
40835
|
+
disconnect: () => {}
|
|
40836
|
+
};
|
|
40837
|
+
}
|
|
40838
|
+
function buildConnector(config) {
|
|
40839
|
+
if (config.connect)
|
|
40840
|
+
return config.connect;
|
|
40841
|
+
if (config.url) {
|
|
40842
|
+
return async () => {
|
|
40843
|
+
const webConfig = { walletUrl: config.url };
|
|
40844
|
+
const { wallet: wallet2, destroy } = createWebCWI(webConfig);
|
|
40845
|
+
await wallet2.waitForAuthentication({});
|
|
40846
|
+
const { publicKey } = await wallet2.getPublicKey({ identityKey: true });
|
|
40847
|
+
return { wallet: wallet2, provider: config.type, identityKey: publicKey, disconnect: destroy };
|
|
40848
|
+
};
|
|
40849
|
+
}
|
|
40850
|
+
return () => Promise.reject(new Error(`Provider "${config.type}" has no url or connect function`));
|
|
40851
|
+
}
|
|
40852
|
+
function getAvailableProviders(config) {
|
|
40853
|
+
const providerConfigs = config?.providers ?? [];
|
|
40854
|
+
const lastProvider = loadLastProvider();
|
|
40855
|
+
return providerConfigs.map((p) => ({ ...p, connect: buildConnector(p) })).sort((a, b) => {
|
|
40856
|
+
if (a.type === lastProvider)
|
|
40857
|
+
return -1;
|
|
40858
|
+
if (b.type === lastProvider)
|
|
40859
|
+
return 1;
|
|
40860
|
+
return 0;
|
|
40861
|
+
});
|
|
40862
|
+
}
|
|
40863
|
+
async function connectWallet(config) {
|
|
40864
|
+
const autoDetect = config?.autoDetect ?? true;
|
|
40865
|
+
const providers = config?.providers ?? [];
|
|
40866
|
+
const lastType = loadLastProvider();
|
|
40867
|
+
if (lastType) {
|
|
40868
|
+
const lastConfig = providers.find((p) => p.type === lastType);
|
|
40869
|
+
if (lastConfig) {
|
|
40870
|
+
try {
|
|
40871
|
+
const result2 = await buildConnector(lastConfig)();
|
|
40872
|
+
saveLastProvider(result2.provider);
|
|
40873
|
+
return result2;
|
|
40874
|
+
} catch {}
|
|
40875
|
+
}
|
|
40876
|
+
}
|
|
40877
|
+
const attempts = [];
|
|
40878
|
+
if (autoDetect) {
|
|
40879
|
+
attempts.push(connectAutoDetect());
|
|
40880
|
+
}
|
|
40881
|
+
for (const provider of providers) {
|
|
40882
|
+
attempts.push(buildConnector(provider)());
|
|
40883
|
+
}
|
|
40884
|
+
if (attempts.length === 0) {
|
|
40885
|
+
throw new Error("No wallet providers configured and autoDetect is disabled");
|
|
40886
|
+
}
|
|
40887
|
+
const result = await Promise.any(attempts);
|
|
40888
|
+
saveLastProvider(result.provider);
|
|
40889
|
+
return result;
|
|
40890
|
+
}
|
|
40891
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/utils/error-codes.mjs
|
|
41519
40892
|
function defineErrorCodes(codes) {
|
|
41520
40893
|
return Object.fromEntries(Object.entries(codes).map(([key, value]) => [key, {
|
|
41521
40894
|
code: key,
|
|
@@ -41524,7 +40897,7 @@ function defineErrorCodes(codes) {
|
|
|
41524
40897
|
}]));
|
|
41525
40898
|
}
|
|
41526
40899
|
|
|
41527
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
40900
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/admin/error-codes.mjs
|
|
41528
40901
|
var ADMIN_ERROR_CODES = defineErrorCodes({
|
|
41529
40902
|
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
41530
40903
|
USER_ALREADY_EXISTS: "User already exists.",
|
|
@@ -41549,7 +40922,7 @@ var ADMIN_ERROR_CODES = defineErrorCodes({
|
|
|
41549
40922
|
INVALID_ROLE_TYPE: "Invalid role type"
|
|
41550
40923
|
});
|
|
41551
40924
|
|
|
41552
|
-
// ../../node_modules/.bun/@better-auth+core@1.5.
|
|
40925
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/error/codes.mjs
|
|
41553
40926
|
var BASE_ERROR_CODES = defineErrorCodes({
|
|
41554
40927
|
USER_NOT_FOUND: "User not found",
|
|
41555
40928
|
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
@@ -41715,7 +41088,7 @@ var InternalAPIError = class extends Error {
|
|
|
41715
41088
|
var kAPIErrorHeaderSymbol = Symbol.for("better-call:api-error-headers");
|
|
41716
41089
|
var APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
|
|
41717
41090
|
|
|
41718
|
-
// ../../node_modules/.bun/@better-auth+core@1.5.
|
|
41091
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/error/index.mjs
|
|
41719
41092
|
var BetterAuthError = class extends Error {
|
|
41720
41093
|
constructor(message, options) {
|
|
41721
41094
|
super(message, options);
|
|
@@ -41725,7 +41098,7 @@ var BetterAuthError = class extends Error {
|
|
|
41725
41098
|
}
|
|
41726
41099
|
};
|
|
41727
41100
|
|
|
41728
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41101
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/access/access.mjs
|
|
41729
41102
|
function role(statements) {
|
|
41730
41103
|
return {
|
|
41731
41104
|
authorize(request3, connector = "AND") {
|
|
@@ -41774,7 +41147,7 @@ function createAccessControl(s2) {
|
|
|
41774
41147
|
};
|
|
41775
41148
|
}
|
|
41776
41149
|
|
|
41777
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41150
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/admin/access/statement.mjs
|
|
41778
41151
|
var defaultStatements = {
|
|
41779
41152
|
user: [
|
|
41780
41153
|
"create",
|
|
@@ -41818,7 +41191,7 @@ var userAc = defaultAc.newRole({
|
|
|
41818
41191
|
session: []
|
|
41819
41192
|
});
|
|
41820
41193
|
|
|
41821
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41194
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/anonymous/error-codes.mjs
|
|
41822
41195
|
var ANONYMOUS_ERROR_CODES = defineErrorCodes({
|
|
41823
41196
|
INVALID_EMAIL_FORMAT: "Email was not generated in a valid format",
|
|
41824
41197
|
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
@@ -41829,14 +41202,14 @@ var ANONYMOUS_ERROR_CODES = defineErrorCodes({
|
|
|
41829
41202
|
DELETE_ANONYMOUS_USER_DISABLED: "Deleting anonymous users is disabled"
|
|
41830
41203
|
});
|
|
41831
41204
|
|
|
41832
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41205
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/email-otp/error-codes.mjs
|
|
41833
41206
|
var EMAIL_OTP_ERROR_CODES = defineErrorCodes({
|
|
41834
41207
|
OTP_EXPIRED: "OTP expired",
|
|
41835
41208
|
INVALID_OTP: "Invalid OTP",
|
|
41836
41209
|
TOO_MANY_ATTEMPTS: "Too many attempts"
|
|
41837
41210
|
});
|
|
41838
41211
|
|
|
41839
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41212
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/generic-oauth/error-codes.mjs
|
|
41840
41213
|
var GENERIC_OAUTH_ERROR_CODES = defineErrorCodes({
|
|
41841
41214
|
INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration",
|
|
41842
41215
|
TOKEN_URL_NOT_FOUND: "Invalid OAuth configuration. Token URL not found.",
|
|
@@ -41848,10 +41221,10 @@ var GENERIC_OAUTH_ERROR_CODES = defineErrorCodes({
|
|
|
41848
41221
|
ISSUER_MISSING: "OAuth issuer parameter missing. The authorization server did not include the required iss parameter (RFC 9207)."
|
|
41849
41222
|
});
|
|
41850
41223
|
|
|
41851
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41224
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/multi-session/error-codes.mjs
|
|
41852
41225
|
var MULTI_SESSION_ERROR_CODES = defineErrorCodes({ INVALID_SESSION_TOKEN: "Invalid session token" });
|
|
41853
41226
|
|
|
41854
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41227
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/organization/error-codes.mjs
|
|
41855
41228
|
var ORGANIZATION_ERROR_CODES = defineErrorCodes({
|
|
41856
41229
|
YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION: "You are not allowed to create a new organization",
|
|
41857
41230
|
YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS: "You have reached the maximum number of organizations",
|
|
@@ -42058,7 +41431,7 @@ var onMount = ($store, initialize) => {
|
|
|
42058
41431
|
};
|
|
42059
41432
|
});
|
|
42060
41433
|
};
|
|
42061
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41434
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/query.mjs
|
|
42062
41435
|
var isServer = () => typeof window === "undefined";
|
|
42063
41436
|
var useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
42064
41437
|
const value = atom({
|
|
@@ -42157,7 +41530,7 @@ var useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
|
42157
41530
|
return value;
|
|
42158
41531
|
};
|
|
42159
41532
|
|
|
42160
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41533
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/broadcast-channel.mjs
|
|
42161
41534
|
var kBroadcastChannel = Symbol.for("better-auth:broadcast-channel");
|
|
42162
41535
|
var now = () => Math.floor(Date.now() / 1000);
|
|
42163
41536
|
var WindowBroadcastChannel = class {
|
|
@@ -42205,7 +41578,7 @@ function getGlobalBroadcastChannel(name = "better-auth.message") {
|
|
|
42205
41578
|
return globalThis[kBroadcastChannel];
|
|
42206
41579
|
}
|
|
42207
41580
|
|
|
42208
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41581
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/focus-manager.mjs
|
|
42209
41582
|
var kFocusManager = Symbol.for("better-auth:focus-manager");
|
|
42210
41583
|
var WindowFocusManager = class {
|
|
42211
41584
|
listeners = /* @__PURE__ */ new Set;
|
|
@@ -42237,7 +41610,7 @@ function getGlobalFocusManager() {
|
|
|
42237
41610
|
return globalThis[kFocusManager];
|
|
42238
41611
|
}
|
|
42239
41612
|
|
|
42240
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41613
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/online-manager.mjs
|
|
42241
41614
|
var kOnlineManager = Symbol.for("better-auth:online-manager");
|
|
42242
41615
|
var WindowOnlineManager = class {
|
|
42243
41616
|
listeners = /* @__PURE__ */ new Set;
|
|
@@ -42271,7 +41644,7 @@ function getGlobalOnlineManager() {
|
|
|
42271
41644
|
return globalThis[kOnlineManager];
|
|
42272
41645
|
}
|
|
42273
41646
|
|
|
42274
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41647
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/parser.mjs
|
|
42275
41648
|
var PROTO_POLLUTION_PATTERNS = {
|
|
42276
41649
|
proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
|
|
42277
41650
|
constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
|
|
@@ -42351,8 +41724,16 @@ function parseJSON(value, options = { strict: true }) {
|
|
|
42351
41724
|
return betterJSONParse(value, options);
|
|
42352
41725
|
}
|
|
42353
41726
|
|
|
42354
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
41727
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/session-refresh.mjs
|
|
42355
41728
|
var now2 = () => Math.floor(Date.now() / 1000);
|
|
41729
|
+
function normalizeSessionResponse(res) {
|
|
41730
|
+
if (typeof res === "object" && res !== null && "data" in res && "error" in res)
|
|
41731
|
+
return res;
|
|
41732
|
+
return {
|
|
41733
|
+
data: res,
|
|
41734
|
+
error: null
|
|
41735
|
+
};
|
|
41736
|
+
}
|
|
42356
41737
|
var FOCUS_REFETCH_RATE_LIMIT_SECONDS = 5;
|
|
42357
41738
|
function createSessionRefreshManager(opts) {
|
|
42358
41739
|
const { sessionAtom, sessionSignal, $fetch, options = {} } = opts;
|
|
@@ -42379,13 +41760,11 @@ function createSessionRefreshManager(opts) {
|
|
|
42379
41760
|
const fetchSessionWithRefresh = () => {
|
|
42380
41761
|
state.lastSessionRequest = now2();
|
|
42381
41762
|
$fetch("/get-session").then(async (res) => {
|
|
42382
|
-
let data = res
|
|
42383
|
-
let error = res.error || null;
|
|
41763
|
+
let { data, error } = normalizeSessionResponse(res);
|
|
42384
41764
|
if (data?.needsRefresh)
|
|
42385
41765
|
try {
|
|
42386
41766
|
const refreshRes = await $fetch("/get-session", { method: "POST" });
|
|
42387
|
-
data = refreshRes
|
|
42388
|
-
error = refreshRes.error || null;
|
|
41767
|
+
({ data, error } = normalizeSessionResponse(refreshRes));
|
|
42389
41768
|
} catch {}
|
|
42390
41769
|
const sessionData = data?.session && data?.user ? data : null;
|
|
42391
41770
|
sessionAtom.set({
|
|
@@ -42485,7 +41864,7 @@ function createSessionRefreshManager(opts) {
|
|
|
42485
41864
|
};
|
|
42486
41865
|
}
|
|
42487
41866
|
|
|
42488
|
-
// ../../node_modules/.bun/@better-auth+core@1.5.
|
|
41867
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/env/env-impl.mjs
|
|
42489
41868
|
var _envShim = Object.create(null);
|
|
42490
41869
|
var _getEnv = (useShim) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (useShim ? _envShim : globalThis);
|
|
42491
41870
|
var env = new Proxy(_envShim, {
|
|
@@ -42546,7 +41925,7 @@ var ENV = Object.freeze({
|
|
|
42546
41925
|
}
|
|
42547
41926
|
});
|
|
42548
41927
|
|
|
42549
|
-
// ../../node_modules/.bun/@better-auth+core@1.5.
|
|
41928
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/env/color-depth.mjs
|
|
42550
41929
|
var COLORS_2 = 1;
|
|
42551
41930
|
var COLORS_16 = 4;
|
|
42552
41931
|
var COLORS_256 = 8;
|
|
@@ -42651,7 +42030,7 @@ function getColorDepth() {
|
|
|
42651
42030
|
return COLORS_2;
|
|
42652
42031
|
}
|
|
42653
42032
|
|
|
42654
|
-
// ../../node_modules/.bun/@better-auth+core@1.5.
|
|
42033
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/env/logger.mjs
|
|
42655
42034
|
var TTY_COLORS = {
|
|
42656
42035
|
reset: "\x1B[0m",
|
|
42657
42036
|
bright: "\x1B[1m",
|
|
@@ -42733,7 +42112,7 @@ var createLogger = (options) => {
|
|
|
42733
42112
|
};
|
|
42734
42113
|
var logger = createLogger();
|
|
42735
42114
|
|
|
42736
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
42115
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/utils/url.mjs
|
|
42737
42116
|
function checkHasPath(url) {
|
|
42738
42117
|
try {
|
|
42739
42118
|
return (new URL(url).pathname.replace(/\/+$/, "") || "/") !== "/";
|
|
@@ -42817,7 +42196,7 @@ function getOrigin(url) {
|
|
|
42817
42196
|
}
|
|
42818
42197
|
}
|
|
42819
42198
|
|
|
42820
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
42199
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/fetch-plugins.mjs
|
|
42821
42200
|
var redirectPlugin = {
|
|
42822
42201
|
id: "redirect",
|
|
42823
42202
|
name: "Redirect",
|
|
@@ -42833,7 +42212,7 @@ var redirectPlugin = {
|
|
|
42833
42212
|
} }
|
|
42834
42213
|
};
|
|
42835
42214
|
|
|
42836
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
42215
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/session-atom.mjs
|
|
42837
42216
|
function getSessionAtom($fetch, options) {
|
|
42838
42217
|
const $signal = atom(false);
|
|
42839
42218
|
const session = useAuthQuery($signal, "/get-session", $fetch, { method: "GET" });
|
|
@@ -43489,7 +42868,7 @@ var betterFetch = async (url, options) => {
|
|
|
43489
42868
|
};
|
|
43490
42869
|
};
|
|
43491
42870
|
|
|
43492
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
42871
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/config.mjs
|
|
43493
42872
|
var resolvePublicAuthUrl = (basePath) => {
|
|
43494
42873
|
if (typeof process === "undefined")
|
|
43495
42874
|
return;
|
|
@@ -43599,12 +42978,12 @@ var getClientConfig = (options, loadEnv) => {
|
|
|
43599
42978
|
};
|
|
43600
42979
|
};
|
|
43601
42980
|
|
|
43602
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
42981
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/utils/is-atom.mjs
|
|
43603
42982
|
function isAtom(value) {
|
|
43604
42983
|
return typeof value === "object" && value !== null && "get" in value && typeof value.get === "function" && "lc" in value && typeof value.lc === "number";
|
|
43605
42984
|
}
|
|
43606
42985
|
|
|
43607
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
42986
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/proxy.mjs
|
|
43608
42987
|
function getMethod2(path, knownPathMethods, args) {
|
|
43609
42988
|
const method = knownPathMethods[path];
|
|
43610
42989
|
const { fetchOptions, query: _query, ...body } = args || {};
|
|
@@ -43686,12 +43065,12 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
|
|
|
43686
43065
|
return createProxy();
|
|
43687
43066
|
}
|
|
43688
43067
|
|
|
43689
|
-
// ../../node_modules/.bun/@better-auth+core@1.5.
|
|
43068
|
+
// ../../node_modules/.bun/@better-auth+core@1.5.6+b884d6c866886bb4/node_modules/@better-auth/core/dist/utils/string.mjs
|
|
43690
43069
|
function capitalizeFirstLetter(str) {
|
|
43691
43070
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
43692
43071
|
}
|
|
43693
43072
|
|
|
43694
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
43073
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/client/vanilla.mjs
|
|
43695
43074
|
function createAuthClient(options) {
|
|
43696
43075
|
const { pluginPathMethods, pluginsActions, pluginsAtoms, $fetch, atomListeners, $store } = getClientConfig(options);
|
|
43697
43076
|
const resolvedHooks = {};
|
|
@@ -43705,7 +43084,7 @@ function createAuthClient(options) {
|
|
|
43705
43084
|
}, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
|
|
43706
43085
|
}
|
|
43707
43086
|
|
|
43708
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
43087
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/organization/access/statement.mjs
|
|
43709
43088
|
var defaultStatements2 = {
|
|
43710
43089
|
organization: ["update", "delete"],
|
|
43711
43090
|
member: [
|
|
@@ -43775,7 +43154,7 @@ var memberAc = defaultAc2.newRole({
|
|
|
43775
43154
|
ac: ["read"]
|
|
43776
43155
|
});
|
|
43777
43156
|
|
|
43778
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
43157
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/phone-number/error-codes.mjs
|
|
43779
43158
|
var PHONE_NUMBER_ERROR_CODES = defineErrorCodes({
|
|
43780
43159
|
INVALID_PHONE_NUMBER: "Invalid phone number",
|
|
43781
43160
|
PHONE_NUMBER_EXIST: "Phone number already exists",
|
|
@@ -43791,7 +43170,7 @@ var PHONE_NUMBER_ERROR_CODES = defineErrorCodes({
|
|
|
43791
43170
|
TOO_MANY_ATTEMPTS: "Too many attempts"
|
|
43792
43171
|
});
|
|
43793
43172
|
|
|
43794
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
43173
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/two-factor/error-code.mjs
|
|
43795
43174
|
var TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
43796
43175
|
OTP_NOT_ENABLED: "OTP not enabled",
|
|
43797
43176
|
OTP_HAS_EXPIRED: "OTP has expired",
|
|
@@ -43804,7 +43183,7 @@ var TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
|
43804
43183
|
INVALID_TWO_FACTOR_COOKIE: "Invalid two factor cookie"
|
|
43805
43184
|
});
|
|
43806
43185
|
|
|
43807
|
-
// ../../node_modules/.bun/better-auth@1.5.
|
|
43186
|
+
// ../../node_modules/.bun/better-auth@1.5.6+56d7e2a2950c65d9/node_modules/better-auth/dist/plugins/username/error-codes.mjs
|
|
43808
43187
|
var USERNAME_ERROR_CODES = defineErrorCodes({
|
|
43809
43188
|
INVALID_USERNAME_OR_PASSWORD: "Invalid username or password",
|
|
43810
43189
|
EMAIL_NOT_VERIFIED: "Email not verified",
|
|
@@ -43816,7 +43195,7 @@ var USERNAME_ERROR_CODES = defineErrorCodes({
|
|
|
43816
43195
|
INVALID_DISPLAY_USERNAME: "Display username is invalid"
|
|
43817
43196
|
});
|
|
43818
43197
|
|
|
43819
|
-
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+
|
|
43198
|
+
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+ed409eef1e5e255b/node_modules/@sigma-auth/better-auth-plugin/dist/client/local-signer.js
|
|
43820
43199
|
class LocalServerSigner {
|
|
43821
43200
|
baseUrl;
|
|
43822
43201
|
timeout;
|
|
@@ -44044,9 +43423,9 @@ class LocalServerSigner {
|
|
|
44044
43423
|
}
|
|
44045
43424
|
}
|
|
44046
43425
|
|
|
44047
|
-
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+
|
|
43426
|
+
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+ed409eef1e5e255b/node_modules/@sigma-auth/better-auth-plugin/dist/client/sigma-cwi.js
|
|
44048
43427
|
var isRecord3 = (v) => typeof v === "object" && v !== null;
|
|
44049
|
-
var
|
|
43428
|
+
var isResponse3 = (v) => isRecord3(v) && v.type === "CWI" && v.isInvocation === false && typeof v.id === "string";
|
|
44050
43429
|
var isState3 = (v) => isRecord3(v) && v.type === "CWI" && isRecord3(v.cwiState);
|
|
44051
43430
|
var createId3 = () => typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
|
|
44052
43431
|
var DEFAULT_TIMEOUT_MS = 30000;
|
|
@@ -44133,7 +43512,7 @@ class SigmaCWISigner {
|
|
|
44133
43512
|
}
|
|
44134
43513
|
return;
|
|
44135
43514
|
}
|
|
44136
|
-
if (!
|
|
43515
|
+
if (!isResponse3(data))
|
|
44137
43516
|
return;
|
|
44138
43517
|
const req = this.pending.get(data.id);
|
|
44139
43518
|
if (!req)
|
|
@@ -44285,7 +43664,7 @@ class SigmaCWISigner {
|
|
|
44285
43664
|
this.pending.clear();
|
|
44286
43665
|
}
|
|
44287
43666
|
}
|
|
44288
|
-
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+
|
|
43667
|
+
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+ed409eef1e5e255b/node_modules/@sigma-auth/better-auth-plugin/dist/client/signer.js
|
|
44289
43668
|
class SigmaIframeSigner {
|
|
44290
43669
|
iframe = null;
|
|
44291
43670
|
pendingRequests = new Map;
|
|
@@ -44683,7 +44062,7 @@ class SigmaIframeSigner {
|
|
|
44683
44062
|
this.rejectAllPending(new Error("Signer destroyed"));
|
|
44684
44063
|
}
|
|
44685
44064
|
}
|
|
44686
|
-
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+
|
|
44065
|
+
// ../../node_modules/.bun/@sigma-auth+better-auth-plugin@0.0.84+ed409eef1e5e255b/node_modules/@sigma-auth/better-auth-plugin/dist/client/index.js
|
|
44687
44066
|
var signer = null;
|
|
44688
44067
|
var signerType = null;
|
|
44689
44068
|
var storedBapId = null;
|
|
@@ -45209,13 +44588,11 @@ async function initiateSigmaOAuth(config, options) {
|
|
|
45209
44588
|
async function completeSigmaOAuth(searchParams) {
|
|
45210
44589
|
const result = await sigmaAuthClient.sigma.handleCallback(searchParams);
|
|
45211
44590
|
const bapId = result.user?.bap_id;
|
|
45212
|
-
if (!bapId)
|
|
44591
|
+
if (!bapId)
|
|
45213
44592
|
throw new Error("Sigma callback response missing bap_id");
|
|
45214
|
-
}
|
|
45215
44593
|
const pubkey = result.user?.pubkey;
|
|
45216
|
-
if (!pubkey)
|
|
44594
|
+
if (!pubkey)
|
|
45217
44595
|
throw new Error("Sigma callback response missing pubkey");
|
|
45218
|
-
}
|
|
45219
44596
|
return {
|
|
45220
44597
|
bapId,
|
|
45221
44598
|
pubkey,
|
|
@@ -45226,9 +44603,6 @@ async function completeSigmaOAuth(searchParams) {
|
|
|
45226
44603
|
function setSigmaIdentity(bapId) {
|
|
45227
44604
|
sigmaAuthClient.sigma.setIdentity(bapId);
|
|
45228
44605
|
}
|
|
45229
|
-
|
|
45230
|
-
// src/connectWallet.ts
|
|
45231
|
-
var DEFAULT_ONESAT_URL = "https://1sat.market";
|
|
45232
44606
|
async function connectSigmaWallet(bapId) {
|
|
45233
44607
|
const cwiConfig = { sigmaUrl: SIGMA_URL };
|
|
45234
44608
|
const { wallet: wallet2, destroy, sendCustomMessage } = createSigmaCWI(cwiConfig);
|
|
@@ -45243,71 +44617,6 @@ async function connectSigmaWallet(bapId) {
|
|
|
45243
44617
|
disconnect: destroy
|
|
45244
44618
|
};
|
|
45245
44619
|
}
|
|
45246
|
-
async function connectBrc100AutoDetect() {
|
|
45247
|
-
const client = new WalletClient("auto");
|
|
45248
|
-
await client.connectToSubstrate();
|
|
45249
|
-
await client.waitForAuthentication({});
|
|
45250
|
-
const { publicKey } = await client.getPublicKey({ identityKey: true });
|
|
45251
|
-
return {
|
|
45252
|
-
wallet: client,
|
|
45253
|
-
provider: "brc100",
|
|
45254
|
-
identityKey: publicKey,
|
|
45255
|
-
disconnect: () => {}
|
|
45256
|
-
};
|
|
45257
|
-
}
|
|
45258
|
-
function createProviderConnector(config) {
|
|
45259
|
-
switch (config.type) {
|
|
45260
|
-
case "onesat":
|
|
45261
|
-
return async () => {
|
|
45262
|
-
const webConfig = {};
|
|
45263
|
-
if (config.url)
|
|
45264
|
-
webConfig.walletUrl = config.url;
|
|
45265
|
-
const { wallet: wallet2, destroy } = createWebCWI(webConfig);
|
|
45266
|
-
await wallet2.waitForAuthentication({});
|
|
45267
|
-
const { publicKey } = await wallet2.getPublicKey({
|
|
45268
|
-
identityKey: true
|
|
45269
|
-
});
|
|
45270
|
-
return {
|
|
45271
|
-
wallet: wallet2,
|
|
45272
|
-
provider: "onesat",
|
|
45273
|
-
identityKey: publicKey,
|
|
45274
|
-
disconnect: destroy
|
|
45275
|
-
};
|
|
45276
|
-
};
|
|
45277
|
-
case "sigma":
|
|
45278
|
-
return async () => {
|
|
45279
|
-
const sigmaConfig = config;
|
|
45280
|
-
if (!sigmaConfig.clientId) {
|
|
45281
|
-
throw new Error("Sigma provider requires clientId in config");
|
|
45282
|
-
}
|
|
45283
|
-
return initiateSigmaOAuth({
|
|
45284
|
-
clientId: sigmaConfig.clientId,
|
|
45285
|
-
callbackURL: sigmaConfig.callbackURL
|
|
45286
|
-
});
|
|
45287
|
-
};
|
|
45288
|
-
default:
|
|
45289
|
-
return () => Promise.reject(new Error(`No built-in connector for provider type: ${config.type}`));
|
|
45290
|
-
}
|
|
45291
|
-
}
|
|
45292
|
-
function getAvailableProviders(config) {
|
|
45293
|
-
const providerConfigs = config?.providers ?? [
|
|
45294
|
-
{ type: "onesat", name: "OneSat Wallet", url: DEFAULT_ONESAT_URL }
|
|
45295
|
-
];
|
|
45296
|
-
return providerConfigs.map((p) => ({
|
|
45297
|
-
...p,
|
|
45298
|
-
detected: false,
|
|
45299
|
-
connect: createProviderConnector(p)
|
|
45300
|
-
}));
|
|
45301
|
-
}
|
|
45302
|
-
async function connectWallet(config) {
|
|
45303
|
-
const autoDetect = config?.autoDetect ?? true;
|
|
45304
|
-
if (autoDetect) {
|
|
45305
|
-
try {
|
|
45306
|
-
return await connectBrc100AutoDetect();
|
|
45307
|
-
} catch {}
|
|
45308
|
-
}
|
|
45309
|
-
return null;
|
|
45310
|
-
}
|
|
45311
44620
|
// src/auth.ts
|
|
45312
44621
|
var { toArray: toArray3, toBase64: toBase642, toHex: toHex3 } = exports_utils;
|
|
45313
44622
|
var BRC77_VERSION = [66, 66, 51, 1];
|
|
@@ -45339,845 +44648,189 @@ async function signRequest(wallet2, requestPath, body) {
|
|
|
45339
44648
|
const signatureBase64 = toBase642(envelope);
|
|
45340
44649
|
return `${senderPubKeyHex}|brc77|${timestamp2}|${requestPath}|${signatureBase64}`;
|
|
45341
44650
|
}
|
|
45342
|
-
// src/
|
|
45343
|
-
var
|
|
45344
|
-
|
|
45345
|
-
|
|
45346
|
-
|
|
45347
|
-
|
|
45348
|
-
|
|
45349
|
-
|
|
45350
|
-
|
|
45351
|
-
|
|
45352
|
-
|
|
45353
|
-
|
|
45354
|
-
|
|
45355
|
-
|
|
45356
|
-
|
|
45357
|
-
|
|
45358
|
-
|
|
45359
|
-
|
|
45360
|
-
|
|
45361
|
-
|
|
45362
|
-
|
|
45363
|
-
|
|
45364
|
-
return /Android|iPhone|iPad|iPod|Mobile/i.test(userAgent);
|
|
45365
|
-
};
|
|
45366
|
-
var createId4 = () => {
|
|
45367
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
45368
|
-
return crypto.randomUUID();
|
|
45369
|
-
}
|
|
45370
|
-
return `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
|
|
45371
|
-
};
|
|
45372
|
-
var base64UrlEncodeBytes = (input) => {
|
|
45373
|
-
let binary = "";
|
|
45374
|
-
for (const byte of input) {
|
|
45375
|
-
binary += String.fromCharCode(byte);
|
|
45376
|
-
}
|
|
45377
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
45378
|
-
};
|
|
45379
|
-
var randomBase64Url = (length = 64) => {
|
|
45380
|
-
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
45381
|
-
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
45382
|
-
const bytes2 = new Uint8Array(length);
|
|
45383
|
-
crypto.getRandomValues(bytes2);
|
|
45384
|
-
return Array.from(bytes2, (byte) => charset[byte % charset.length]).join("");
|
|
45385
|
-
}
|
|
45386
|
-
return Array.from({ length }, () => {
|
|
45387
|
-
const index = Math.floor(Math.random() * charset.length);
|
|
45388
|
-
return charset[index];
|
|
45389
|
-
}).join("");
|
|
45390
|
-
};
|
|
45391
|
-
var computeS256 = async (verifier) => {
|
|
45392
|
-
if (typeof crypto === "undefined" || typeof crypto.subtle === "undefined" || typeof TextEncoder === "undefined") {
|
|
45393
|
-
return verifier;
|
|
45394
|
-
}
|
|
45395
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
45396
|
-
return base64UrlEncodeBytes(new Uint8Array(digest));
|
|
45397
|
-
};
|
|
45398
|
-
var toSearchParams = (searchParams) => {
|
|
45399
|
-
if (searchParams instanceof URLSearchParams) {
|
|
45400
|
-
return searchParams;
|
|
45401
|
-
}
|
|
45402
|
-
if (typeof searchParams === "string") {
|
|
45403
|
-
const trimmed = searchParams.startsWith("?") ? searchParams.slice(1) : searchParams;
|
|
45404
|
-
return new URLSearchParams(trimmed);
|
|
45405
|
-
}
|
|
45406
|
-
if (typeof window !== "undefined") {
|
|
45407
|
-
return new URLSearchParams(window.location.search);
|
|
45408
|
-
}
|
|
45409
|
-
return new URLSearchParams;
|
|
45410
|
-
};
|
|
45411
|
-
var normalizeReason = (value) => {
|
|
45412
|
-
if (value === "channel_unavailable" || value === "wallet_tab_unreachable" || value === "wallet_locked") {
|
|
45413
|
-
return value;
|
|
45414
|
-
}
|
|
45415
|
-
return;
|
|
45416
|
-
};
|
|
45417
|
-
var normalizeState = (state) => ({
|
|
45418
|
-
status: state.status === "checking" || state.status === "locked" || state.status === "unlocked" || state.status === "no-wallet" ? state.status : undefined,
|
|
45419
|
-
hasPermission: typeof state.hasPermission === "boolean" ? state.hasPermission : undefined,
|
|
45420
|
-
transport: state.transport === "embed" ? "embed" : undefined,
|
|
45421
|
-
fallbackRecommended: typeof state.fallbackRecommended === "boolean" ? state.fallbackRecommended : undefined,
|
|
45422
|
-
reason: normalizeReason(state.reason)
|
|
45423
|
-
});
|
|
45424
|
-
var isCWIStateMessage = (value) => {
|
|
45425
|
-
if (!isRecord4(value))
|
|
45426
|
-
return false;
|
|
45427
|
-
if (value.type !== "CWI")
|
|
45428
|
-
return false;
|
|
45429
|
-
if (!isRecord4(value.cwiState))
|
|
45430
|
-
return false;
|
|
45431
|
-
return true;
|
|
45432
|
-
};
|
|
45433
|
-
var isCWIResponseMessage = (value) => {
|
|
45434
|
-
if (!isRecord4(value))
|
|
45435
|
-
return false;
|
|
45436
|
-
if (value.type !== "CWI")
|
|
45437
|
-
return false;
|
|
45438
|
-
if (value.isInvocation !== false)
|
|
45439
|
-
return false;
|
|
45440
|
-
if (typeof value.id !== "string")
|
|
45441
|
-
return false;
|
|
45442
|
-
return true;
|
|
45443
|
-
};
|
|
45444
|
-
var toCWIError = (message) => new OneSatError(ErrorCodes.INTERNAL_ERROR, message.description ?? "Wallet request failed", { code: message.code });
|
|
45445
|
-
var extractErrorDescription = (value) => {
|
|
45446
|
-
if (!isRecord4(value))
|
|
45447
|
-
return;
|
|
45448
|
-
const description = value.error_description;
|
|
45449
|
-
if (typeof description === "string" && description.length > 0) {
|
|
45450
|
-
return description;
|
|
45451
|
-
}
|
|
45452
|
-
const fallback = value.error;
|
|
45453
|
-
if (typeof fallback === "string" && fallback.length > 0) {
|
|
45454
|
-
return fallback;
|
|
45455
|
-
}
|
|
45456
|
-
return;
|
|
45457
|
-
};
|
|
45458
|
-
var emitTransportEvent = (emitter, event) => {
|
|
45459
|
-
emitter.emit("transport", event);
|
|
45460
|
-
};
|
|
45461
|
-
var withFetchTimeout = async (input, init, timeoutMs, onTimeout) => {
|
|
45462
|
-
const controller = new AbortController;
|
|
45463
|
-
const timeoutId = setTimeout(() => {
|
|
45464
|
-
controller.abort();
|
|
45465
|
-
}, timeoutMs);
|
|
45466
|
-
try {
|
|
45467
|
-
return await fetch(input, {
|
|
45468
|
-
...init,
|
|
45469
|
-
signal: controller.signal
|
|
45470
|
-
});
|
|
45471
|
-
} catch (error) {
|
|
45472
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
45473
|
-
throw onTimeout();
|
|
45474
|
-
}
|
|
45475
|
-
throw error;
|
|
45476
|
-
} finally {
|
|
45477
|
-
clearTimeout(timeoutId);
|
|
45478
|
-
}
|
|
44651
|
+
// src/errors.ts
|
|
44652
|
+
var ErrorCodes = {
|
|
44653
|
+
PARSE_ERROR: -32700,
|
|
44654
|
+
INVALID_REQUEST: -32600,
|
|
44655
|
+
METHOD_NOT_FOUND: -32601,
|
|
44656
|
+
INVALID_PARAMS: -32602,
|
|
44657
|
+
INTERNAL_ERROR: -32603,
|
|
44658
|
+
USER_REJECTED: 4001,
|
|
44659
|
+
WALLET_LOCKED: 4002,
|
|
44660
|
+
WALLET_NOT_CONNECTED: 4003,
|
|
44661
|
+
INSUFFICIENT_FUNDS: 4004,
|
|
44662
|
+
INVALID_TRANSACTION: 4005,
|
|
44663
|
+
POPUP_BLOCKED: 4006,
|
|
44664
|
+
POPUP_CLOSED: 4007,
|
|
44665
|
+
TIMEOUT: 4008,
|
|
44666
|
+
NETWORK_ERROR: 4009,
|
|
44667
|
+
ORIGIN_NOT_ALLOWED: 4010,
|
|
44668
|
+
TRANSPORT_UNAVAILABLE: 4011,
|
|
44669
|
+
FALLBACK_REQUIRED: 4012,
|
|
44670
|
+
AUTHORIZATION_TIMEOUT: 4013,
|
|
44671
|
+
STATE_MISMATCH: 4014,
|
|
44672
|
+
CODE_REPLAY: 4015
|
|
45479
44673
|
};
|
|
45480
44674
|
|
|
45481
|
-
class
|
|
45482
|
-
|
|
45483
|
-
|
|
45484
|
-
|
|
45485
|
-
|
|
45486
|
-
|
|
45487
|
-
|
|
45488
|
-
|
|
45489
|
-
stateWaiters = new Set;
|
|
45490
|
-
lastState = null;
|
|
45491
|
-
events = new eventemitter3_default;
|
|
45492
|
-
isDestroyed = false;
|
|
45493
|
-
constructor(config) {
|
|
45494
|
-
const walletUrl = config?.walletUrl ?? DEFAULT_WALLET_URL2;
|
|
45495
|
-
const iframePath = config?.iframePath ?? DEFAULT_IFRAME_PATH3;
|
|
45496
|
-
this.walletOrigin = new URL(walletUrl).origin;
|
|
45497
|
-
this.iframeUrl = new URL(iframePath, walletUrl).toString();
|
|
45498
|
-
this.requestTimeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
|
|
45499
|
-
this.handshakeTimeoutMs = config?.handshakeTimeoutMs ?? (isLikelyMobileRuntime() ? DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS : DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS);
|
|
45500
|
-
if (typeof window !== "undefined") {
|
|
45501
|
-
window.addEventListener("message", this.handleMessage);
|
|
45502
|
-
}
|
|
45503
|
-
}
|
|
45504
|
-
handleMessage = (event) => {
|
|
45505
|
-
if (this.isDestroyed)
|
|
45506
|
-
return;
|
|
45507
|
-
let eventOrigin;
|
|
45508
|
-
let eventSource;
|
|
45509
|
-
let eventData;
|
|
45510
|
-
try {
|
|
45511
|
-
eventOrigin = event.origin;
|
|
45512
|
-
eventSource = event.source;
|
|
45513
|
-
eventData = event.data;
|
|
45514
|
-
} catch {
|
|
45515
|
-
return;
|
|
45516
|
-
}
|
|
45517
|
-
if (eventOrigin !== this.walletOrigin)
|
|
45518
|
-
return;
|
|
45519
|
-
const iframeWindow = this.getIframeWindow();
|
|
45520
|
-
if (!iframeWindow || eventSource !== iframeWindow)
|
|
45521
|
-
return;
|
|
45522
|
-
if (isCWIStateMessage(eventData)) {
|
|
45523
|
-
const state = normalizeState(eventData.cwiState);
|
|
45524
|
-
this.lastState = state;
|
|
45525
|
-
this.resolveStateWaiters(state);
|
|
45526
|
-
this.updateIframeVisibility(state.hasPermission === true);
|
|
45527
|
-
if (state.fallbackRecommended) {
|
|
45528
|
-
emitTransportEvent(this.events, {
|
|
45529
|
-
type: "fallback",
|
|
45530
|
-
transport: "embed",
|
|
45531
|
-
reason: state.reason ?? "channel_unavailable"
|
|
45532
|
-
});
|
|
45533
|
-
}
|
|
45534
|
-
return;
|
|
45535
|
-
}
|
|
45536
|
-
if (!isCWIResponseMessage(eventData))
|
|
45537
|
-
return;
|
|
45538
|
-
const pending = this.pendingInvocations.get(eventData.id);
|
|
45539
|
-
if (!pending)
|
|
45540
|
-
return;
|
|
45541
|
-
this.pendingInvocations.delete(eventData.id);
|
|
45542
|
-
clearTimeout(pending.timeoutId);
|
|
45543
|
-
if (eventData.status === "error") {
|
|
45544
|
-
pending.reject(toCWIError(eventData));
|
|
45545
|
-
return;
|
|
45546
|
-
}
|
|
45547
|
-
pending.resolve(eventData.result);
|
|
45548
|
-
};
|
|
45549
|
-
getIframeWindow() {
|
|
45550
|
-
const iframe = this.iframe;
|
|
45551
|
-
if (!iframe)
|
|
45552
|
-
return null;
|
|
45553
|
-
try {
|
|
45554
|
-
return iframe.contentWindow;
|
|
45555
|
-
} catch {
|
|
45556
|
-
return null;
|
|
45557
|
-
}
|
|
45558
|
-
}
|
|
45559
|
-
ensureIframe() {
|
|
45560
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
45561
|
-
throw new TransportUnavailableError("Embed transport requires a browser");
|
|
45562
|
-
}
|
|
45563
|
-
if (this.iframe) {
|
|
45564
|
-
return this.iframe;
|
|
45565
|
-
}
|
|
45566
|
-
const iframe = document.createElement("iframe");
|
|
45567
|
-
iframe.src = this.iframeUrl;
|
|
45568
|
-
iframe.setAttribute("aria-hidden", "true");
|
|
45569
|
-
iframe.style.position = "fixed";
|
|
45570
|
-
iframe.style.top = "0";
|
|
45571
|
-
iframe.style.left = "0";
|
|
45572
|
-
iframe.style.width = "0";
|
|
45573
|
-
iframe.style.height = "0";
|
|
45574
|
-
iframe.style.border = "0";
|
|
45575
|
-
iframe.style.opacity = "0";
|
|
45576
|
-
iframe.style.pointerEvents = "none";
|
|
45577
|
-
const parent = document.body ?? document.documentElement;
|
|
45578
|
-
if (!parent) {
|
|
45579
|
-
throw new TransportUnavailableError("Unable to mount CWI iframe in document");
|
|
45580
|
-
}
|
|
45581
|
-
parent.appendChild(iframe);
|
|
45582
|
-
this.iframe = iframe;
|
|
45583
|
-
this.updateIframeVisibility(false);
|
|
45584
|
-
return iframe;
|
|
45585
|
-
}
|
|
45586
|
-
updateIframeVisibility(showPermission) {
|
|
45587
|
-
const iframe = this.iframe;
|
|
45588
|
-
if (!iframe)
|
|
45589
|
-
return;
|
|
45590
|
-
iframe.style.zIndex = "2147483647";
|
|
45591
|
-
if (showPermission) {
|
|
45592
|
-
iframe.style.width = "100%";
|
|
45593
|
-
iframe.style.height = "100%";
|
|
45594
|
-
iframe.style.opacity = "1";
|
|
45595
|
-
iframe.style.pointerEvents = "auto";
|
|
45596
|
-
return;
|
|
45597
|
-
}
|
|
45598
|
-
iframe.style.width = "0";
|
|
45599
|
-
iframe.style.height = "0";
|
|
45600
|
-
iframe.style.opacity = "0";
|
|
45601
|
-
iframe.style.pointerEvents = "none";
|
|
45602
|
-
}
|
|
45603
|
-
resolveStateWaiters(state) {
|
|
45604
|
-
for (const waiter of this.stateWaiters) {
|
|
45605
|
-
clearTimeout(waiter.timeoutId);
|
|
45606
|
-
waiter.resolve(state);
|
|
45607
|
-
}
|
|
45608
|
-
this.stateWaiters.clear();
|
|
45609
|
-
}
|
|
45610
|
-
async waitForState(timeoutMs) {
|
|
45611
|
-
if (this.lastState) {
|
|
45612
|
-
return this.lastState;
|
|
45613
|
-
}
|
|
45614
|
-
return new Promise((resolve, reject) => {
|
|
45615
|
-
const waiter = {
|
|
45616
|
-
resolve,
|
|
45617
|
-
reject,
|
|
45618
|
-
timeoutId: setTimeout(() => {
|
|
45619
|
-
this.stateWaiters.delete(waiter);
|
|
45620
|
-
reject(new AuthorizationTimeoutError("Embed handshake timed out"));
|
|
45621
|
-
}, timeoutMs)
|
|
45622
|
-
};
|
|
45623
|
-
this.stateWaiters.add(waiter);
|
|
45624
|
-
});
|
|
45625
|
-
}
|
|
45626
|
-
async handshake(timeoutMs = this.handshakeTimeoutMs) {
|
|
45627
|
-
this.ensureIframe();
|
|
45628
|
-
const state = await this.waitForState(timeoutMs);
|
|
45629
|
-
if (state.fallbackRecommended) {
|
|
45630
|
-
throw new FallbackRequiredError(`Embed fallback recommended${state.reason ? ` (${state.reason})` : ""}`, { reason: state.reason });
|
|
45631
|
-
}
|
|
45632
|
-
return state;
|
|
44675
|
+
class OneSatError extends Error {
|
|
44676
|
+
code;
|
|
44677
|
+
data;
|
|
44678
|
+
constructor(code2, message, data) {
|
|
44679
|
+
super(message);
|
|
44680
|
+
this.name = "OneSatError";
|
|
44681
|
+
this.code = code2;
|
|
44682
|
+
this.data = data;
|
|
45633
44683
|
}
|
|
45634
|
-
|
|
45635
|
-
|
|
45636
|
-
|
|
45637
|
-
|
|
45638
|
-
|
|
45639
|
-
this.ensureIframe();
|
|
45640
|
-
const target = this.getIframeWindow();
|
|
45641
|
-
if (!target) {
|
|
45642
|
-
throw new TransportUnavailableError("CWI iframe is not reachable");
|
|
45643
|
-
}
|
|
45644
|
-
const requestId = createId4();
|
|
45645
|
-
const request3 = {
|
|
45646
|
-
type: "CWI",
|
|
45647
|
-
isInvocation: true,
|
|
45648
|
-
id: requestId,
|
|
45649
|
-
call,
|
|
45650
|
-
args
|
|
44684
|
+
toJSON() {
|
|
44685
|
+
return {
|
|
44686
|
+
code: this.code,
|
|
44687
|
+
message: this.message,
|
|
44688
|
+
data: this.data
|
|
45651
44689
|
};
|
|
45652
|
-
return new Promise((resolve, reject) => {
|
|
45653
|
-
const timeoutId = setTimeout(() => {
|
|
45654
|
-
this.pendingInvocations.delete(requestId);
|
|
45655
|
-
reject(new AuthorizationTimeoutError(`CWI request timed out: ${call}`));
|
|
45656
|
-
}, this.requestTimeoutMs);
|
|
45657
|
-
this.pendingInvocations.set(requestId, {
|
|
45658
|
-
resolve,
|
|
45659
|
-
reject,
|
|
45660
|
-
timeoutId
|
|
45661
|
-
});
|
|
45662
|
-
try {
|
|
45663
|
-
target.postMessage(request3, this.walletOrigin);
|
|
45664
|
-
emitTransportEvent(this.events, {
|
|
45665
|
-
type: "selected",
|
|
45666
|
-
transport: "embed"
|
|
45667
|
-
});
|
|
45668
|
-
} catch (error) {
|
|
45669
|
-
clearTimeout(timeoutId);
|
|
45670
|
-
this.pendingInvocations.delete(requestId);
|
|
45671
|
-
reject(new TransportUnavailableError("Failed to post message to CWI iframe", {
|
|
45672
|
-
cause: error instanceof Error ? error.message : String(error)
|
|
45673
|
-
}));
|
|
45674
|
-
}
|
|
45675
|
-
});
|
|
45676
|
-
}
|
|
45677
|
-
async resume() {
|
|
45678
|
-
return null;
|
|
45679
|
-
}
|
|
45680
|
-
on(event, handler) {
|
|
45681
|
-
this.events.on(event, handler);
|
|
45682
|
-
}
|
|
45683
|
-
off(event, handler) {
|
|
45684
|
-
this.events.off(event, handler);
|
|
45685
|
-
}
|
|
45686
|
-
destroy() {
|
|
45687
|
-
if (this.isDestroyed)
|
|
45688
|
-
return;
|
|
45689
|
-
this.isDestroyed = true;
|
|
45690
|
-
if (typeof window !== "undefined") {
|
|
45691
|
-
window.removeEventListener("message", this.handleMessage);
|
|
45692
|
-
}
|
|
45693
|
-
for (const pending of this.pendingInvocations.values()) {
|
|
45694
|
-
clearTimeout(pending.timeoutId);
|
|
45695
|
-
pending.reject(new TransportUnavailableError("Embed transport destroyed"));
|
|
45696
|
-
}
|
|
45697
|
-
this.pendingInvocations.clear();
|
|
45698
|
-
for (const waiter of this.stateWaiters) {
|
|
45699
|
-
clearTimeout(waiter.timeoutId);
|
|
45700
|
-
waiter.reject(new TransportUnavailableError("Embed transport destroyed"));
|
|
45701
|
-
}
|
|
45702
|
-
this.stateWaiters.clear();
|
|
45703
|
-
const iframe = this.iframe;
|
|
45704
|
-
if (iframe?.parentNode) {
|
|
45705
|
-
iframe.parentNode.removeChild(iframe);
|
|
45706
|
-
}
|
|
45707
|
-
this.iframe = null;
|
|
45708
44690
|
}
|
|
45709
44691
|
}
|
|
45710
44692
|
|
|
45711
|
-
class
|
|
45712
|
-
|
|
45713
|
-
|
|
45714
|
-
|
|
45715
|
-
redirectUri;
|
|
45716
|
-
timeoutMs;
|
|
45717
|
-
events = new eventemitter3_default;
|
|
45718
|
-
constructor(config) {
|
|
45719
|
-
const walletUrl = config?.walletUrl ?? DEFAULT_WALLET_URL2;
|
|
45720
|
-
const authorizeInitPath = config?.authorizeInitPath ?? DEFAULT_AUTHORIZE_INIT_PATH;
|
|
45721
|
-
const tokenPath = config?.tokenPath ?? DEFAULT_TOKEN_PATH;
|
|
45722
|
-
this.authorizeInitUrl = new URL(authorizeInitPath, walletUrl).toString();
|
|
45723
|
-
this.tokenUrl = new URL(tokenPath, walletUrl).toString();
|
|
45724
|
-
this.timeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
|
|
45725
|
-
if (config?.redirectUri) {
|
|
45726
|
-
this.redirectUri = config.redirectUri;
|
|
45727
|
-
} else if (typeof window !== "undefined") {
|
|
45728
|
-
this.redirectUri = `${window.location.origin}${window.location.pathname}`;
|
|
45729
|
-
} else {
|
|
45730
|
-
this.redirectUri = null;
|
|
45731
|
-
}
|
|
45732
|
-
}
|
|
45733
|
-
savePendingSession(session) {
|
|
45734
|
-
if (typeof sessionStorage === "undefined")
|
|
45735
|
-
return;
|
|
45736
|
-
sessionStorage.setItem(REDIRECT_PENDING_KEY, JSON.stringify(session));
|
|
45737
|
-
}
|
|
45738
|
-
loadPendingSession() {
|
|
45739
|
-
if (typeof sessionStorage === "undefined")
|
|
45740
|
-
return null;
|
|
45741
|
-
const raw = sessionStorage.getItem(REDIRECT_PENDING_KEY);
|
|
45742
|
-
if (!raw)
|
|
45743
|
-
return null;
|
|
45744
|
-
try {
|
|
45745
|
-
const parsed = JSON.parse(raw);
|
|
45746
|
-
if (typeof parsed.state !== "string" || typeof parsed.codeVerifier !== "string" || typeof parsed.redirectUri !== "string" || typeof parsed.createdAt !== "number") {
|
|
45747
|
-
return null;
|
|
45748
|
-
}
|
|
45749
|
-
return parsed;
|
|
45750
|
-
} catch {
|
|
45751
|
-
return null;
|
|
45752
|
-
}
|
|
45753
|
-
}
|
|
45754
|
-
clearPendingSession() {
|
|
45755
|
-
if (typeof sessionStorage === "undefined")
|
|
45756
|
-
return;
|
|
45757
|
-
sessionStorage.removeItem(REDIRECT_PENDING_KEY);
|
|
45758
|
-
}
|
|
45759
|
-
clearAuthQueryParams() {
|
|
45760
|
-
if (typeof window === "undefined" || typeof history === "undefined")
|
|
45761
|
-
return;
|
|
45762
|
-
const url = new URL(window.location.href);
|
|
45763
|
-
let changed = false;
|
|
45764
|
-
for (const key of ["code", "state", "error", "error_description"]) {
|
|
45765
|
-
if (url.searchParams.has(key)) {
|
|
45766
|
-
url.searchParams.delete(key);
|
|
45767
|
-
changed = true;
|
|
45768
|
-
}
|
|
45769
|
-
}
|
|
45770
|
-
if (changed) {
|
|
45771
|
-
history.replaceState(history.state, "", url.toString());
|
|
45772
|
-
}
|
|
45773
|
-
}
|
|
45774
|
-
async initializeAuthorization(call, args) {
|
|
45775
|
-
if (typeof window === "undefined") {
|
|
45776
|
-
throw new TransportUnavailableError("Redirect transport requires a browser");
|
|
45777
|
-
}
|
|
45778
|
-
if (!this.redirectUri) {
|
|
45779
|
-
throw new TransportUnavailableError("redirectUri is required for redirect fallback");
|
|
45780
|
-
}
|
|
45781
|
-
const state = randomBase64Url(48);
|
|
45782
|
-
const nonce = randomBase64Url(48);
|
|
45783
|
-
const verifier = randomBase64Url(64);
|
|
45784
|
-
const hasSubtle = typeof crypto !== "undefined" && typeof crypto.subtle !== "undefined" && typeof TextEncoder !== "undefined";
|
|
45785
|
-
const method = hasSubtle ? "S256" : "plain";
|
|
45786
|
-
const codeChallenge = await computeS256(verifier);
|
|
45787
|
-
const body = {
|
|
45788
|
-
call,
|
|
45789
|
-
args: args ?? {},
|
|
45790
|
-
redirect_uri: this.redirectUri,
|
|
45791
|
-
state,
|
|
45792
|
-
nonce,
|
|
45793
|
-
code_challenge: codeChallenge,
|
|
45794
|
-
code_challenge_method: method
|
|
45795
|
-
};
|
|
45796
|
-
const response = await withFetchTimeout(this.authorizeInitUrl, {
|
|
45797
|
-
method: "POST",
|
|
45798
|
-
headers: { "content-type": "application/json" },
|
|
45799
|
-
body: JSON.stringify(body),
|
|
45800
|
-
credentials: "omit"
|
|
45801
|
-
}, this.timeoutMs, () => new AuthorizationTimeoutError("authorize/init timed out"));
|
|
45802
|
-
const payload = await response.json().catch(() => ({}));
|
|
45803
|
-
if (!response.ok || !isRecord4(payload)) {
|
|
45804
|
-
const description = extractErrorDescription(payload) ?? "Failed to initialize redirect authorization";
|
|
45805
|
-
throw new OneSatError(ErrorCodes.INVALID_REQUEST, description, payload);
|
|
45806
|
-
}
|
|
45807
|
-
const authorizeUrl = payload.authorizeUrl;
|
|
45808
|
-
if (typeof authorizeUrl !== "string" || authorizeUrl.length === 0) {
|
|
45809
|
-
throw new TransportUnavailableError("authorize/init did not return authorizeUrl");
|
|
45810
|
-
}
|
|
45811
|
-
return {
|
|
45812
|
-
authorizeUrl,
|
|
45813
|
-
session: {
|
|
45814
|
-
state,
|
|
45815
|
-
codeVerifier: verifier,
|
|
45816
|
-
redirectUri: this.redirectUri,
|
|
45817
|
-
createdAt: Date.now()
|
|
45818
|
-
}
|
|
45819
|
-
};
|
|
45820
|
-
}
|
|
45821
|
-
async invoke(call, args) {
|
|
45822
|
-
if (typeof call !== "string" || call.length === 0) {
|
|
45823
|
-
throw new OneSatError(ErrorCodes.INVALID_REQUEST, "Invalid CWI call");
|
|
45824
|
-
}
|
|
45825
|
-
if (typeof window === "undefined") {
|
|
45826
|
-
throw new TransportUnavailableError("Redirect transport requires a browser");
|
|
45827
|
-
}
|
|
45828
|
-
const { authorizeUrl, session } = await this.initializeAuthorization(call, args);
|
|
45829
|
-
this.savePendingSession(session);
|
|
45830
|
-
emitTransportEvent(this.events, {
|
|
45831
|
-
type: "selected",
|
|
45832
|
-
transport: "redirect"
|
|
45833
|
-
});
|
|
45834
|
-
window.location.assign(authorizeUrl);
|
|
45835
|
-
return new Promise(() => {});
|
|
45836
|
-
}
|
|
45837
|
-
async exchangeCode(code2, session) {
|
|
45838
|
-
const response = await withFetchTimeout(this.tokenUrl, {
|
|
45839
|
-
method: "POST",
|
|
45840
|
-
headers: { "content-type": "application/json" },
|
|
45841
|
-
body: JSON.stringify({
|
|
45842
|
-
code: code2,
|
|
45843
|
-
code_verifier: session.codeVerifier,
|
|
45844
|
-
redirect_uri: session.redirectUri
|
|
45845
|
-
}),
|
|
45846
|
-
credentials: "omit"
|
|
45847
|
-
}, this.timeoutMs, () => new AuthorizationTimeoutError("token exchange timed out"));
|
|
45848
|
-
const payload = await response.json().catch(() => ({}));
|
|
45849
|
-
if (!response.ok || !isRecord4(payload)) {
|
|
45850
|
-
const description = extractErrorDescription(payload) ?? "Authorization code exchange failed";
|
|
45851
|
-
if (/already_consumed|replay|consumed/i.test(description)) {
|
|
45852
|
-
throw new CodeReplayError(description);
|
|
45853
|
-
}
|
|
45854
|
-
throw new OneSatError(ErrorCodes.INTERNAL_ERROR, description, payload);
|
|
45855
|
-
}
|
|
45856
|
-
if ("error" in payload) {
|
|
45857
|
-
const description = extractErrorDescription(payload) ?? "Authorization request failed";
|
|
45858
|
-
if (/already_consumed|replay|consumed/i.test(description)) {
|
|
45859
|
-
throw new CodeReplayError(description);
|
|
45860
|
-
}
|
|
45861
|
-
throw new OneSatError(ErrorCodes.INTERNAL_ERROR, description, payload);
|
|
45862
|
-
}
|
|
45863
|
-
return payload.result;
|
|
45864
|
-
}
|
|
45865
|
-
async resume(searchParams) {
|
|
45866
|
-
const params = toSearchParams(searchParams);
|
|
45867
|
-
const code2 = params.get("code");
|
|
45868
|
-
const state = params.get("state");
|
|
45869
|
-
const error = params.get("error");
|
|
45870
|
-
const errorDescription = params.get("error_description");
|
|
45871
|
-
if (!code2 && !error) {
|
|
45872
|
-
return null;
|
|
45873
|
-
}
|
|
45874
|
-
const session = this.loadPendingSession();
|
|
45875
|
-
if (!session || !state || state !== session.state) {
|
|
45876
|
-
this.clearPendingSession();
|
|
45877
|
-
this.clearAuthQueryParams();
|
|
45878
|
-
throw new StateMismatchError("Redirect callback state mismatch");
|
|
45879
|
-
}
|
|
45880
|
-
if (error) {
|
|
45881
|
-
this.clearPendingSession();
|
|
45882
|
-
this.clearAuthQueryParams();
|
|
45883
|
-
const payload = {
|
|
45884
|
-
error,
|
|
45885
|
-
error_description: errorDescription ?? undefined
|
|
45886
|
-
};
|
|
45887
|
-
if (error === "access_denied") {
|
|
45888
|
-
throw new OneSatError(ErrorCodes.USER_REJECTED, errorDescription ?? "User denied authorization", payload);
|
|
45889
|
-
}
|
|
45890
|
-
throw new OneSatError(ErrorCodes.INTERNAL_ERROR, errorDescription ?? `Authorization callback error: ${error}`, payload);
|
|
45891
|
-
}
|
|
45892
|
-
if (!code2) {
|
|
45893
|
-
this.clearPendingSession();
|
|
45894
|
-
this.clearAuthQueryParams();
|
|
45895
|
-
throw new TransportUnavailableError("Redirect callback missing authorization code");
|
|
45896
|
-
}
|
|
45897
|
-
const result = await this.exchangeCode(code2, session);
|
|
45898
|
-
this.clearPendingSession();
|
|
45899
|
-
this.clearAuthQueryParams();
|
|
45900
|
-
return result;
|
|
45901
|
-
}
|
|
45902
|
-
on(event, handler) {
|
|
45903
|
-
this.events.on(event, handler);
|
|
45904
|
-
}
|
|
45905
|
-
off(event, handler) {
|
|
45906
|
-
this.events.off(event, handler);
|
|
45907
|
-
}
|
|
45908
|
-
destroy() {
|
|
45909
|
-
this.clearPendingSession();
|
|
44693
|
+
class UserRejectedError extends OneSatError {
|
|
44694
|
+
constructor(message = "User rejected the request") {
|
|
44695
|
+
super(ErrorCodes.USER_REJECTED, message);
|
|
44696
|
+
this.name = "UserRejectedError";
|
|
45910
44697
|
}
|
|
45911
44698
|
}
|
|
45912
44699
|
|
|
45913
|
-
class
|
|
45914
|
-
|
|
45915
|
-
|
|
45916
|
-
|
|
45917
|
-
events = new eventemitter3_default;
|
|
45918
|
-
selectedTransport = null;
|
|
45919
|
-
mobileFallback;
|
|
45920
|
-
maxEmbedRetries;
|
|
45921
|
-
constructor(config) {
|
|
45922
|
-
const isMobile = isLikelyMobileRuntime();
|
|
45923
|
-
this.mobileFallback = config?.mobileFallback ?? (isMobile ? "auto" : "embed-only");
|
|
45924
|
-
const handshakeTimeoutMs = config?.handshakeTimeoutMs ?? (isMobile ? DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS : DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS);
|
|
45925
|
-
this.maxEmbedRetries = Math.max(1, config?.maxEmbedRetries ?? (isMobile ? DEFAULT_MOBILE_MAX_RETRIES : DEFAULT_DESKTOP_MAX_RETRIES));
|
|
45926
|
-
this.embed = new EmbedTransport({
|
|
45927
|
-
...config,
|
|
45928
|
-
handshakeTimeoutMs
|
|
45929
|
-
});
|
|
45930
|
-
this.redirect = new RedirectTransport(config);
|
|
45931
|
-
}
|
|
45932
|
-
selectTransport(transport, reason, kind = "selected") {
|
|
45933
|
-
if (this.selectedTransport === transport && kind === "selected")
|
|
45934
|
-
return;
|
|
45935
|
-
const previous = this.selectedTransport;
|
|
45936
|
-
this.selectedTransport = transport;
|
|
45937
|
-
emitTransportEvent(this.events, {
|
|
45938
|
-
type: kind,
|
|
45939
|
-
transport,
|
|
45940
|
-
previousTransport: previous ?? undefined,
|
|
45941
|
-
reason
|
|
45942
|
-
});
|
|
45943
|
-
}
|
|
45944
|
-
shouldTryRedirect() {
|
|
45945
|
-
return this.mobileFallback !== "embed-only";
|
|
45946
|
-
}
|
|
45947
|
-
shouldUseRedirectDirectly() {
|
|
45948
|
-
return this.mobileFallback === "redirect";
|
|
45949
|
-
}
|
|
45950
|
-
shouldRetryEmbed(error) {
|
|
45951
|
-
return error instanceof AuthorizationTimeoutError || error instanceof TransportUnavailableError;
|
|
45952
|
-
}
|
|
45953
|
-
shouldFallbackToRedirect(error) {
|
|
45954
|
-
return error instanceof FallbackRequiredError || error instanceof AuthorizationTimeoutError || error instanceof TransportUnavailableError;
|
|
45955
|
-
}
|
|
45956
|
-
toFallbackReason(error) {
|
|
45957
|
-
if (error instanceof FallbackRequiredError) {
|
|
45958
|
-
const data = error.data;
|
|
45959
|
-
if (isRecord4(data)) {
|
|
45960
|
-
const reason = normalizeReason(data.reason);
|
|
45961
|
-
if (reason) {
|
|
45962
|
-
return reason;
|
|
45963
|
-
}
|
|
45964
|
-
}
|
|
45965
|
-
return "channel_unavailable";
|
|
45966
|
-
}
|
|
45967
|
-
if (error instanceof AuthorizationTimeoutError) {
|
|
45968
|
-
return "wallet_tab_unreachable";
|
|
45969
|
-
}
|
|
45970
|
-
return "channel_unavailable";
|
|
45971
|
-
}
|
|
45972
|
-
async invoke(call, args) {
|
|
45973
|
-
if (this.selectedTransport === "redirect" || this.shouldUseRedirectDirectly()) {
|
|
45974
|
-
this.selectTransport("redirect", this.shouldUseRedirectDirectly() ? "mobile_fallback_redirect" : undefined);
|
|
45975
|
-
return this.redirect.invoke(call, args);
|
|
45976
|
-
}
|
|
45977
|
-
try {
|
|
45978
|
-
const result = await this.embed.invoke(call, args);
|
|
45979
|
-
this.selectTransport("embed");
|
|
45980
|
-
return result;
|
|
45981
|
-
} catch (error) {
|
|
45982
|
-
let resolvedError = error instanceof Error ? error : new TransportUnavailableError(String(error));
|
|
45983
|
-
if (this.selectedTransport !== "embed" && this.shouldRetryEmbed(resolvedError) && this.maxEmbedRetries > 1) {
|
|
45984
|
-
for (let attempt = 2;attempt <= this.maxEmbedRetries; attempt += 1) {
|
|
45985
|
-
try {
|
|
45986
|
-
const result = await this.embed.invoke(call, args);
|
|
45987
|
-
this.selectTransport("embed", `embed_retry_${attempt}`);
|
|
45988
|
-
return result;
|
|
45989
|
-
} catch (retryError) {
|
|
45990
|
-
if (!(retryError instanceof Error)) {
|
|
45991
|
-
throw retryError;
|
|
45992
|
-
}
|
|
45993
|
-
resolvedError = retryError;
|
|
45994
|
-
if (!this.shouldRetryEmbed(retryError)) {
|
|
45995
|
-
break;
|
|
45996
|
-
}
|
|
45997
|
-
}
|
|
45998
|
-
}
|
|
45999
|
-
}
|
|
46000
|
-
if (!this.shouldFallbackToRedirect(resolvedError)) {
|
|
46001
|
-
throw resolvedError;
|
|
46002
|
-
}
|
|
46003
|
-
if (!this.shouldTryRedirect()) {
|
|
46004
|
-
throw resolvedError;
|
|
46005
|
-
}
|
|
46006
|
-
const reason = this.toFallbackReason(resolvedError);
|
|
46007
|
-
this.selectTransport("redirect", reason, "fallback");
|
|
46008
|
-
return this.redirect.invoke(call, args);
|
|
46009
|
-
}
|
|
46010
|
-
}
|
|
46011
|
-
async resume(searchParams) {
|
|
46012
|
-
const result = await this.redirect.resume(searchParams);
|
|
46013
|
-
if (result !== null) {
|
|
46014
|
-
this.selectTransport("redirect", "redirect_callback");
|
|
46015
|
-
}
|
|
46016
|
-
return result;
|
|
46017
|
-
}
|
|
46018
|
-
on(event, handler) {
|
|
46019
|
-
this.events.on(event, handler);
|
|
46020
|
-
}
|
|
46021
|
-
off(event, handler) {
|
|
46022
|
-
this.events.off(event, handler);
|
|
46023
|
-
}
|
|
46024
|
-
destroy() {
|
|
46025
|
-
this.embed.destroy();
|
|
46026
|
-
this.redirect.destroy();
|
|
46027
|
-
}
|
|
46028
|
-
}
|
|
46029
|
-
var createRedirectTransport = (config) => new RedirectTransport(config);
|
|
46030
|
-
var createAutoTransport = (config) => new AutoTransport(config);
|
|
46031
|
-
// src/wallet.ts
|
|
46032
|
-
function parsePopupParams(searchParams) {
|
|
46033
|
-
const requestId = searchParams.get("requestId");
|
|
46034
|
-
const origin = searchParams.get("origin");
|
|
46035
|
-
const method = searchParams.get("method");
|
|
46036
|
-
const appName = searchParams.get("appName");
|
|
46037
|
-
const paramsStr = searchParams.get("params");
|
|
46038
|
-
let params = undefined;
|
|
46039
|
-
if (paramsStr) {
|
|
46040
|
-
try {
|
|
46041
|
-
params = JSON.parse(decodeURIComponent(paramsStr));
|
|
46042
|
-
} catch {}
|
|
44700
|
+
class WalletLockedError extends OneSatError {
|
|
44701
|
+
constructor(message = "Wallet is locked") {
|
|
44702
|
+
super(ErrorCodes.WALLET_LOCKED, message);
|
|
44703
|
+
this.name = "WalletLockedError";
|
|
46043
44704
|
}
|
|
46044
|
-
return { requestId, origin, method, appName, params };
|
|
46045
44705
|
}
|
|
46046
|
-
|
|
46047
|
-
|
|
46048
|
-
|
|
46049
|
-
|
|
46050
|
-
|
|
46051
|
-
return;
|
|
44706
|
+
|
|
44707
|
+
class WalletNotConnectedError extends OneSatError {
|
|
44708
|
+
constructor(message = "Wallet is not connected") {
|
|
44709
|
+
super(ErrorCodes.WALLET_NOT_CONNECTED, message);
|
|
44710
|
+
this.name = "WalletNotConnectedError";
|
|
46052
44711
|
}
|
|
46053
|
-
const response = createResponse(requestId, result, origin);
|
|
46054
|
-
window.opener.postMessage(response, origin);
|
|
46055
|
-
window.close();
|
|
46056
44712
|
}
|
|
46057
|
-
|
|
46058
|
-
|
|
46059
|
-
|
|
46060
|
-
|
|
46061
|
-
|
|
46062
|
-
return;
|
|
44713
|
+
|
|
44714
|
+
class InsufficientFundsError extends OneSatError {
|
|
44715
|
+
constructor(message = "Insufficient funds") {
|
|
44716
|
+
super(ErrorCodes.INSUFFICIENT_FUNDS, message);
|
|
44717
|
+
this.name = "InsufficientFundsError";
|
|
46063
44718
|
}
|
|
46064
|
-
const response = createErrorResponse(requestId, code2, message, origin, data);
|
|
46065
|
-
window.opener.postMessage(response, origin);
|
|
46066
|
-
window.close();
|
|
46067
|
-
}
|
|
46068
|
-
function rejectRequest(requestId, origin, reason = "User rejected the request") {
|
|
46069
|
-
sendErrorResponse(requestId, ErrorCodes.USER_REJECTED, reason, origin);
|
|
46070
|
-
}
|
|
46071
|
-
function walletLockedError(requestId, origin) {
|
|
46072
|
-
sendErrorResponse(requestId, ErrorCodes.WALLET_LOCKED, "Wallet is locked. Please unlock your wallet.", origin);
|
|
46073
|
-
}
|
|
46074
|
-
function walletNotConnectedError(requestId, origin) {
|
|
46075
|
-
sendErrorResponse(requestId, ErrorCodes.WALLET_NOT_CONNECTED, "Wallet is not connected", origin);
|
|
46076
44719
|
}
|
|
46077
|
-
|
|
46078
|
-
|
|
46079
|
-
|
|
44720
|
+
|
|
44721
|
+
class PopupBlockedError extends OneSatError {
|
|
44722
|
+
constructor(message = "Popup was blocked by the browser") {
|
|
44723
|
+
super(ErrorCodes.POPUP_BLOCKED, message);
|
|
44724
|
+
this.name = "PopupBlockedError";
|
|
46080
44725
|
}
|
|
46081
44726
|
}
|
|
46082
|
-
|
|
46083
|
-
|
|
46084
|
-
|
|
46085
|
-
|
|
46086
|
-
|
|
46087
|
-
function getPopupContext(searchParams) {
|
|
46088
|
-
const { requestId, origin, method, appName, params } = parsePopupParams(searchParams);
|
|
46089
|
-
if (!requestId) {
|
|
46090
|
-
throw new Error("Missing requestId in popup parameters");
|
|
46091
|
-
}
|
|
46092
|
-
if (!origin) {
|
|
46093
|
-
throw new Error("Missing origin in popup parameters");
|
|
44727
|
+
|
|
44728
|
+
class PopupClosedError extends OneSatError {
|
|
44729
|
+
constructor(message = "Popup was closed before completing the request") {
|
|
44730
|
+
super(ErrorCodes.POPUP_CLOSED, message);
|
|
44731
|
+
this.name = "PopupClosedError";
|
|
46094
44732
|
}
|
|
46095
|
-
return { requestId, origin, method, appName, params };
|
|
46096
44733
|
}
|
|
46097
44734
|
|
|
46098
|
-
|
|
46099
|
-
|
|
46100
|
-
|
|
44735
|
+
class TimeoutError extends OneSatError {
|
|
44736
|
+
constructor(message = "Request timed out") {
|
|
44737
|
+
super(ErrorCodes.TIMEOUT, message);
|
|
44738
|
+
this.name = "TimeoutError";
|
|
44739
|
+
}
|
|
46101
44740
|
}
|
|
46102
|
-
|
|
46103
|
-
|
|
46104
|
-
|
|
44741
|
+
|
|
44742
|
+
class TransportUnavailableError extends OneSatError {
|
|
44743
|
+
constructor(message = "No available transport for wallet request", data) {
|
|
44744
|
+
super(ErrorCodes.TRANSPORT_UNAVAILABLE, message, data);
|
|
44745
|
+
this.name = "TransportUnavailableError";
|
|
46105
44746
|
}
|
|
46106
|
-
return;
|
|
46107
44747
|
}
|
|
46108
|
-
|
|
46109
|
-
|
|
46110
|
-
|
|
46111
|
-
|
|
44748
|
+
|
|
44749
|
+
class FallbackRequiredError extends OneSatError {
|
|
44750
|
+
constructor(message = "Embed transport requires redirect fallback", data) {
|
|
44751
|
+
super(ErrorCodes.FALLBACK_REQUIRED, message, data);
|
|
44752
|
+
this.name = "FallbackRequiredError";
|
|
46112
44753
|
}
|
|
46113
|
-
|
|
46114
|
-
|
|
46115
|
-
|
|
44754
|
+
}
|
|
44755
|
+
|
|
44756
|
+
class AuthorizationTimeoutError extends OneSatError {
|
|
44757
|
+
constructor(message = "Authorization flow timed out", data) {
|
|
44758
|
+
super(ErrorCodes.AUTHORIZATION_TIMEOUT, message, data);
|
|
44759
|
+
this.name = "AuthorizationTimeoutError";
|
|
46116
44760
|
}
|
|
46117
|
-
return provider;
|
|
46118
44761
|
}
|
|
46119
|
-
|
|
46120
|
-
|
|
44762
|
+
|
|
44763
|
+
class StateMismatchError extends OneSatError {
|
|
44764
|
+
constructor(message = "Authorization state mismatch", data) {
|
|
44765
|
+
super(ErrorCodes.STATE_MISMATCH, message, data);
|
|
44766
|
+
this.name = "StateMismatchError";
|
|
44767
|
+
}
|
|
46121
44768
|
}
|
|
46122
|
-
|
|
46123
|
-
|
|
44769
|
+
|
|
44770
|
+
class CodeReplayError extends OneSatError {
|
|
44771
|
+
constructor(message = "Authorization code has already been used", data) {
|
|
44772
|
+
super(ErrorCodes.CODE_REPLAY, message, data);
|
|
44773
|
+
this.name = "CodeReplayError";
|
|
44774
|
+
}
|
|
46124
44775
|
}
|
|
46125
|
-
function
|
|
46126
|
-
|
|
46127
|
-
|
|
46128
|
-
|
|
46129
|
-
|
|
46130
|
-
|
|
46131
|
-
|
|
46132
|
-
|
|
46133
|
-
|
|
46134
|
-
|
|
46135
|
-
|
|
46136
|
-
|
|
46137
|
-
|
|
46138
|
-
|
|
46139
|
-
|
|
46140
|
-
|
|
46141
|
-
|
|
46142
|
-
|
|
46143
|
-
|
|
44776
|
+
function fromErrorResponse(error) {
|
|
44777
|
+
switch (error.code) {
|
|
44778
|
+
case ErrorCodes.USER_REJECTED:
|
|
44779
|
+
return new UserRejectedError(error.message);
|
|
44780
|
+
case ErrorCodes.WALLET_LOCKED:
|
|
44781
|
+
return new WalletLockedError(error.message);
|
|
44782
|
+
case ErrorCodes.WALLET_NOT_CONNECTED:
|
|
44783
|
+
return new WalletNotConnectedError(error.message);
|
|
44784
|
+
case ErrorCodes.INSUFFICIENT_FUNDS:
|
|
44785
|
+
return new InsufficientFundsError(error.message);
|
|
44786
|
+
case ErrorCodes.POPUP_BLOCKED:
|
|
44787
|
+
return new PopupBlockedError(error.message);
|
|
44788
|
+
case ErrorCodes.POPUP_CLOSED:
|
|
44789
|
+
return new PopupClosedError(error.message);
|
|
44790
|
+
case ErrorCodes.TIMEOUT:
|
|
44791
|
+
return new TimeoutError(error.message);
|
|
44792
|
+
case ErrorCodes.TRANSPORT_UNAVAILABLE:
|
|
44793
|
+
return new TransportUnavailableError(error.message, error.data);
|
|
44794
|
+
case ErrorCodes.FALLBACK_REQUIRED:
|
|
44795
|
+
return new FallbackRequiredError(error.message, error.data);
|
|
44796
|
+
case ErrorCodes.AUTHORIZATION_TIMEOUT:
|
|
44797
|
+
return new AuthorizationTimeoutError(error.message, error.data);
|
|
44798
|
+
case ErrorCodes.STATE_MISMATCH:
|
|
44799
|
+
return new StateMismatchError(error.message, error.data);
|
|
44800
|
+
case ErrorCodes.CODE_REPLAY:
|
|
44801
|
+
return new CodeReplayError(error.message, error.data);
|
|
44802
|
+
default:
|
|
44803
|
+
return new OneSatError(error.code, error.message, error.data);
|
|
44804
|
+
}
|
|
46144
44805
|
}
|
|
44806
|
+
// src/types.ts
|
|
44807
|
+
var RpcMethods = {
|
|
44808
|
+
CONNECT: "connect",
|
|
44809
|
+
DISCONNECT: "disconnect",
|
|
44810
|
+
SIGN_TRANSACTION: "signTransaction",
|
|
44811
|
+
SIGN_MESSAGE: "signMessage",
|
|
44812
|
+
INSCRIBE: "inscribe",
|
|
44813
|
+
SEND_ORDINALS: "sendOrdinals",
|
|
44814
|
+
CREATE_LISTING: "createListing",
|
|
44815
|
+
PURCHASE_LISTING: "purchaseListing",
|
|
44816
|
+
CANCEL_LISTING: "cancelListing",
|
|
44817
|
+
TRANSFER_TOKEN: "transferToken",
|
|
44818
|
+
GET_BALANCE: "getBalance",
|
|
44819
|
+
GET_ORDINALS: "getOrdinals",
|
|
44820
|
+
GET_TOKENS: "getTokens",
|
|
44821
|
+
GET_UTXOS: "getUtxos"
|
|
44822
|
+
};
|
|
46145
44823
|
export {
|
|
46146
|
-
walletNotConnectedError,
|
|
46147
|
-
walletLockedError,
|
|
46148
|
-
waitForOneSat,
|
|
46149
44824
|
signRequest,
|
|
46150
44825
|
sigmaAuthClient,
|
|
46151
44826
|
setSigmaIdentity,
|
|
46152
|
-
|
|
46153
|
-
sendErrorResponse,
|
|
46154
|
-
saveConnection,
|
|
46155
|
-
rejectRequest,
|
|
46156
|
-
parsePopupParams,
|
|
46157
|
-
loadConnection,
|
|
46158
|
-
isValidMessage,
|
|
46159
|
-
isResponse,
|
|
46160
|
-
isPopupContext,
|
|
46161
|
-
isOneSatInjected,
|
|
46162
|
-
isOneSatAvailable,
|
|
44827
|
+
loadLastProvider,
|
|
46163
44828
|
initiateSigmaOAuth,
|
|
46164
|
-
hasStoredConnection,
|
|
46165
|
-
getPopupContext,
|
|
46166
|
-
getOneSat,
|
|
46167
|
-
getInjectedOneSat,
|
|
46168
44829
|
getAvailableProviders,
|
|
46169
44830
|
fromErrorResponse,
|
|
46170
|
-
createResponse,
|
|
46171
|
-
createRequest,
|
|
46172
|
-
createRedirectTransport,
|
|
46173
|
-
createOneSat,
|
|
46174
|
-
createErrorResponse,
|
|
46175
|
-
createAutoTransport,
|
|
46176
44831
|
connectWallet,
|
|
46177
44832
|
connectSigmaWallet,
|
|
46178
44833
|
completeSigmaOAuth,
|
|
46179
|
-
closePopup,
|
|
46180
|
-
clearConnection,
|
|
46181
44834
|
WalletNotConnectedError,
|
|
46182
44835
|
WalletLockedError,
|
|
46183
44836
|
UserRejectedError,
|
|
@@ -46186,18 +44839,12 @@ export {
|
|
|
46186
44839
|
StateMismatchError,
|
|
46187
44840
|
SIGMA_URL,
|
|
46188
44841
|
RpcMethods,
|
|
46189
|
-
RedirectTransport,
|
|
46190
|
-
PopupManager,
|
|
46191
44842
|
PopupClosedError,
|
|
46192
44843
|
PopupBlockedError,
|
|
46193
|
-
PROTOCOL_VERSION,
|
|
46194
44844
|
OneSatError,
|
|
46195
|
-
OneSatBrowserProvider,
|
|
46196
|
-
MessageTypes,
|
|
46197
44845
|
InsufficientFundsError,
|
|
46198
44846
|
FallbackRequiredError,
|
|
46199
44847
|
ErrorCodes,
|
|
46200
44848
|
CodeReplayError,
|
|
46201
|
-
AutoTransport,
|
|
46202
44849
|
AuthorizationTimeoutError
|
|
46203
44850
|
};
|