@1sat/connect 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -22360,6 +22360,263 @@ class OneSatBrowserProvider {
22360
22360
  }
22361
22361
  }
22362
22362
 
22363
+ // ../wallet/node_modules/@1sat/client/dist/errors.js
22364
+ class HttpError extends Error {
22365
+ status;
22366
+ constructor(status, message) {
22367
+ super(message);
22368
+ this.status = status;
22369
+ this.name = "HttpError";
22370
+ }
22371
+ }
22372
+ // ../wallet/node_modules/@1sat/client/dist/services/BaseClient.js
22373
+ class BaseClient {
22374
+ baseUrl;
22375
+ timeout;
22376
+ fetchFn;
22377
+ constructor(baseUrl, options = {}) {
22378
+ this.baseUrl = baseUrl.replace(/\/$/, "");
22379
+ this.timeout = options.timeout ?? 30000;
22380
+ this.fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
22381
+ }
22382
+ async request(path, init) {
22383
+ const controller = new AbortController;
22384
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
22385
+ try {
22386
+ const response = await this.fetchFn(`${this.baseUrl}${path}`, {
22387
+ ...init,
22388
+ signal: controller.signal
22389
+ });
22390
+ if (!response.ok) {
22391
+ throw await this.parseError(response);
22392
+ }
22393
+ const text = await response.text();
22394
+ if (!text) {
22395
+ return;
22396
+ }
22397
+ return JSON.parse(text);
22398
+ } finally {
22399
+ clearTimeout(timeoutId);
22400
+ }
22401
+ }
22402
+ async requestBinary(path, init) {
22403
+ const controller = new AbortController;
22404
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
22405
+ try {
22406
+ const response = await this.fetchFn(`${this.baseUrl}${path}`, {
22407
+ ...init,
22408
+ signal: controller.signal
22409
+ });
22410
+ if (!response.ok) {
22411
+ throw await this.parseError(response);
22412
+ }
22413
+ const arrayBuffer = await response.arrayBuffer();
22414
+ return new Uint8Array(arrayBuffer);
22415
+ } finally {
22416
+ clearTimeout(timeoutId);
22417
+ }
22418
+ }
22419
+ async requestRaw(path, init) {
22420
+ const controller = new AbortController;
22421
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
22422
+ try {
22423
+ const response = await this.fetchFn(`${this.baseUrl}${path}`, {
22424
+ ...init,
22425
+ signal: controller.signal
22426
+ });
22427
+ if (!response.ok) {
22428
+ throw await this.parseError(response);
22429
+ }
22430
+ return response;
22431
+ } finally {
22432
+ clearTimeout(timeoutId);
22433
+ }
22434
+ }
22435
+ async parseError(response) {
22436
+ try {
22437
+ const data = await response.json();
22438
+ const message = data.message || data.error || data.detail || response.statusText;
22439
+ return new HttpError(response.status, message);
22440
+ } catch {
22441
+ try {
22442
+ const text = await response.text();
22443
+ return new HttpError(response.status, text || response.statusText);
22444
+ } catch {
22445
+ return new HttpError(response.status, response.statusText);
22446
+ }
22447
+ }
22448
+ }
22449
+ buildQueryString(params) {
22450
+ const entries = [];
22451
+ for (const [key, value] of Object.entries(params)) {
22452
+ if (value === undefined)
22453
+ continue;
22454
+ if (Array.isArray(value)) {
22455
+ if (value.length > 0) {
22456
+ entries.push(`${key}=${encodeURIComponent(value.join(","))}`);
22457
+ }
22458
+ } else if (typeof value === "boolean") {
22459
+ if (value) {
22460
+ entries.push(`${key}=true`);
22461
+ }
22462
+ } else {
22463
+ entries.push(`${key}=${encodeURIComponent(String(value))}`);
22464
+ }
22465
+ }
22466
+ return entries.length > 0 ? `?${entries.join("&")}` : "";
22467
+ }
22468
+ }
22469
+ // ../wallet/node_modules/@1sat/client/dist/services/ChaintracksClient.js
22470
+ function toHex(data) {
22471
+ return Array.from(data).map((b) => b.toString(16).padStart(2, "0")).join("");
22472
+ }
22473
+
22474
+ class ChaintracksClient extends BaseClient {
22475
+ eventSource = null;
22476
+ subscribers = new Set;
22477
+ cachedTip = null;
22478
+ cachedTipTime = 0;
22479
+ static TIP_CACHE_TTL_MS = 30000;
22480
+ constructor(baseUrl, options = {}) {
22481
+ super(`${baseUrl}/1sat/chaintracks`, options);
22482
+ }
22483
+ async currentHeight() {
22484
+ const tip = await this.findChainTipHeader();
22485
+ return tip.height;
22486
+ }
22487
+ async isValidRootForHeight(root, height) {
22488
+ try {
22489
+ const header = await this.findHeaderForHeight(height);
22490
+ return header?.merkleRoot === root;
22491
+ } catch (e) {
22492
+ console.error(`isValidRootForHeight(${height}) failed:`, e);
22493
+ return false;
22494
+ }
22495
+ }
22496
+ async getChain() {
22497
+ const data = await this.request("/network");
22498
+ return data.network;
22499
+ }
22500
+ async getInfo() {
22501
+ const tip = await this.findChainTipHeader();
22502
+ const chain = await this.getChain();
22503
+ return {
22504
+ chain,
22505
+ heightBulk: tip.height,
22506
+ heightLive: tip.height,
22507
+ storage: "remote",
22508
+ bulkIngestors: [],
22509
+ liveIngestors: [],
22510
+ packages: []
22511
+ };
22512
+ }
22513
+ async getPresentHeight() {
22514
+ return this.currentHeight();
22515
+ }
22516
+ async getHeaders(height, count) {
22517
+ const data = await this.requestBinary(`/headers?height=${height}&count=${count}`);
22518
+ return toHex(data);
22519
+ }
22520
+ async findChainTipHeader() {
22521
+ const now = Date.now();
22522
+ if (this.cachedTip && now - this.cachedTipTime < ChaintracksClient.TIP_CACHE_TTL_MS) {
22523
+ return this.cachedTip;
22524
+ }
22525
+ const header = await this.request("/tip");
22526
+ console.log("[ChaintracksClient] findChainTipHeader:", header.height, header.hash);
22527
+ this.cachedTip = header;
22528
+ this.cachedTipTime = now;
22529
+ return header;
22530
+ }
22531
+ async findChainTipHash() {
22532
+ const tip = await this.findChainTipHeader();
22533
+ return tip.hash;
22534
+ }
22535
+ async findHeaderForHeight(height) {
22536
+ try {
22537
+ return await this.request(`/header/height/${height}`);
22538
+ } catch {
22539
+ return;
22540
+ }
22541
+ }
22542
+ async findHeaderForBlockHash(hash) {
22543
+ try {
22544
+ return await this.request(`/header/hash/${hash}`);
22545
+ } catch {
22546
+ return;
22547
+ }
22548
+ }
22549
+ async addHeader(_header) {}
22550
+ async startListening() {}
22551
+ async listening() {}
22552
+ async isListening() {
22553
+ return true;
22554
+ }
22555
+ async isSynchronized() {
22556
+ return true;
22557
+ }
22558
+ async subscribeReorgs(_listener) {
22559
+ throw new Error("Method not implemented.");
22560
+ }
22561
+ async unsubscribe(_subscriptionId) {
22562
+ return false;
22563
+ }
22564
+ async subscribeHeaders(listener) {
22565
+ this.subscribers.add(listener);
22566
+ if (!this.eventSource) {
22567
+ this.eventSource = new EventSource(`${this.baseUrl}/tip/stream`);
22568
+ this.eventSource.onmessage = (event) => {
22569
+ try {
22570
+ const header = JSON.parse(event.data);
22571
+ for (const cb of this.subscribers) {
22572
+ cb(header);
22573
+ }
22574
+ } catch {}
22575
+ };
22576
+ this.eventSource.onerror = () => {
22577
+ this.eventSource?.close();
22578
+ this.eventSource = null;
22579
+ };
22580
+ }
22581
+ return "subscription";
22582
+ }
22583
+ async getHeaderBytes(height, count = 1) {
22584
+ const data = await this.requestBinary(`/headers?height=${height}&count=${count}`);
22585
+ return Array.from(data);
22586
+ }
22587
+ subscribe(callback) {
22588
+ this.subscribers.add(callback);
22589
+ if (!this.eventSource) {
22590
+ this.eventSource = new EventSource(`${this.baseUrl}/tip/stream`);
22591
+ this.eventSource.onmessage = (event) => {
22592
+ try {
22593
+ const header = JSON.parse(event.data);
22594
+ for (const cb of this.subscribers) {
22595
+ cb(header);
22596
+ }
22597
+ } catch {}
22598
+ };
22599
+ this.eventSource.onerror = () => {
22600
+ this.eventSource?.close();
22601
+ this.eventSource = null;
22602
+ };
22603
+ }
22604
+ return () => {
22605
+ this.subscribers.delete(callback);
22606
+ if (this.subscribers.size === 0 && this.eventSource) {
22607
+ this.eventSource.close();
22608
+ this.eventSource = null;
22609
+ }
22610
+ };
22611
+ }
22612
+ close() {
22613
+ if (this.eventSource) {
22614
+ this.eventSource.close();
22615
+ this.eventSource = null;
22616
+ }
22617
+ this.subscribers.clear();
22618
+ }
22619
+ }
22363
22620
  // ../../node_modules/@bsv/sdk/dist/esm/src/primitives/BigNumber.js
22364
22621
  var BufferCtor = typeof globalThis !== "undefined" ? globalThis.Buffer : undefined;
22365
22622
  var CAN_USE_BUFFER = BufferCtor != null && typeof BufferCtor.from === "function";
@@ -24331,7 +24588,7 @@ __export(exports_utils, {
24331
24588
  verifyNotNull: () => verifyNotNull,
24332
24589
  toUint8Array: () => toUint8Array,
24333
24590
  toUTF8: () => toUTF8,
24334
- toHex: () => toHex,
24591
+ toHex: () => toHex2,
24335
24592
  toBase64: () => toBase64,
24336
24593
  toBase58Check: () => toBase58Check,
24337
24594
  toBase58: () => toBase58,
@@ -26321,7 +26578,7 @@ var HEX_BYTE_STRINGS = new Array(256);
26321
26578
  for (let i = 0;i < 256; i++) {
26322
26579
  HEX_BYTE_STRINGS[i] = HEX_DIGITS[i >> 4 & 15] + HEX_DIGITS[i & 15];
26323
26580
  }
26324
- var toHex = (msg) => {
26581
+ var toHex2 = (msg) => {
26325
26582
  if (CAN_USE_BUFFER2) {
26326
26583
  return BufferCtor2.from(msg).toString("hex");
26327
26584
  }
@@ -26433,7 +26690,7 @@ var toUTF8 = (arr) => {
26433
26690
  var encode = (arr, enc) => {
26434
26691
  switch (enc) {
26435
26692
  case "hex":
26436
- return toHex(arr);
26693
+ return toHex2(arr);
26437
26694
  case "utf8":
26438
26695
  return toUTF8(arr);
26439
26696
  default:
@@ -26527,8 +26784,8 @@ var fromBase58Check = (str, enc, prefixLength = 1) => {
26527
26784
  }
26528
26785
  });
26529
26786
  if (enc === "hex") {
26530
- prefix = toHex(prefix);
26531
- data = toHex(data);
26787
+ prefix = toHex2(prefix);
26788
+ data = toHex2(data);
26532
26789
  }
26533
26790
  return { prefix, data };
26534
26791
  };
@@ -26996,7 +27253,7 @@ var toBigInt = (x) => {
26996
27253
  if (typeof x === "string")
26997
27254
  return BigInt("0x" + x);
26998
27255
  if (Array.isArray(x))
26999
- return BigInt("0x" + toHex(x));
27256
+ return BigInt("0x" + toHex2(x));
27000
27257
  return BigInt(x);
27001
27258
  };
27002
27259
  var GX_BIGINT = BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798");
@@ -27246,7 +27503,7 @@ class Point extends BasePoint {
27246
27503
  if (enc !== "hex") {
27247
27504
  return res;
27248
27505
  } else {
27249
- return toHex(res);
27506
+ return toHex2(res);
27250
27507
  }
27251
27508
  }
27252
27509
  toString() {
@@ -28963,7 +29220,7 @@ class Signature {
28963
29220
  constructLength(res, backHalf.length);
28964
29221
  res = res.concat(backHalf);
28965
29222
  if (enc === "hex") {
28966
- return toHex(res);
29223
+ return toHex2(res);
28967
29224
  } else if (enc === "base64") {
28968
29225
  return toBase64(res);
28969
29226
  } else {
@@ -28984,7 +29241,7 @@ class Signature {
28984
29241
  arr = arr.concat(this.r.toArray("be", 32));
28985
29242
  arr = arr.concat(this.s.toArray("be", 32));
28986
29243
  if (enc === "hex") {
28987
- return toHex(arr);
29244
+ return toHex2(arr);
28988
29245
  } else if (enc === "base64") {
28989
29246
  return toBase64(arr);
28990
29247
  } else {
@@ -29076,7 +29333,7 @@ class DRBG {
29076
29333
  }
29077
29334
  const res = temp.slice(0, len);
29078
29335
  this.update();
29079
- return toHex(res);
29336
+ return toHex2(res);
29080
29337
  }
29081
29338
  }
29082
29339
 
@@ -29245,7 +29502,7 @@ class PublicKey extends Point {
29245
29502
  toHash(enc) {
29246
29503
  const pkh = hash160(this.encode(true));
29247
29504
  if (enc === "hex") {
29248
- return toHex(pkh);
29505
+ return toHex2(pkh);
29249
29506
  }
29250
29507
  return pkh;
29251
29508
  }
@@ -30929,7 +31186,7 @@ class Script {
30929
31186
  const val = OP_default[op];
30930
31187
  str = `${str} ${val}`;
30931
31188
  } else {
30932
- str = `${str} ${toHex(chunk.data)}`;
31189
+ str = `${str} ${toHex2(chunk.data)}`;
30933
31190
  }
30934
31191
  return str;
30935
31192
  }
@@ -31257,8 +31514,8 @@ class ScriptEvaluationError extends Error {
31257
31514
  stackMem;
31258
31515
  altStackMem;
31259
31516
  constructor(params) {
31260
- const stackHex = params.stackState.map((s2) => s2 != null && typeof s2.length !== "undefined" ? toHex(s2) : s2 === null || s2 === undefined ? "null/undef" : "INVALID_STACK_ITEM").join(", ");
31261
- const altStackHex = params.altStackState.map((s2) => s2 != null && typeof s2.length !== "undefined" ? toHex(s2) : s2 === null || s2 === undefined ? "null/undef" : "INVALID_STACK_ITEM").join(", ");
31517
+ const stackHex = params.stackState.map((s2) => s2 != null && typeof s2.length !== "undefined" ? toHex2(s2) : s2 === null || s2 === undefined ? "null/undef" : "INVALID_STACK_ITEM").join(", ");
31518
+ const altStackHex = params.altStackState.map((s2) => s2 != null && typeof s2.length !== "undefined" ? toHex2(s2) : s2 === null || s2 === undefined ? "null/undef" : "INVALID_STACK_ITEM").join(", ");
31262
31519
  const pcInfo = `Context: ${params.context}, PC: ${params.programCounter}`;
31263
31520
  const stackInfo = `Stack: [${stackHex}] (len: ${params.stackState.length}, mem: ${params.stackMem})`;
31264
31521
  const altStackInfo = `AltStack: [${altStackHex}] (len: ${params.altStackState.length}, mem: ${params.altStackMem})`;
@@ -32879,7 +33136,7 @@ function defaultHttpClient() {
32879
33136
 
32880
33137
  // ../../node_modules/@bsv/sdk/dist/esm/src/transaction/broadcasters/ARC.js
32881
33138
  function defaultDeploymentId() {
32882
- return `ts-sdk-${toHex(Random_default(16))}`;
33139
+ return `ts-sdk-${toHex2(Random_default(16))}`;
32883
33140
  }
32884
33141
 
32885
33142
  class ARC {
@@ -33132,7 +33389,7 @@ class MerklePath {
33132
33389
  if ((flags & 2) !== 0) {
33133
33390
  leaf.txid = true;
33134
33391
  }
33135
- leaf.hash = toHex(reader.read(32).reverse());
33392
+ leaf.hash = toHex2(reader.read(32).reverse());
33136
33393
  }
33137
33394
  if (!Array.isArray(path[level]) || path[level].length === 0) {
33138
33395
  path[level] = [];
@@ -33221,7 +33478,7 @@ class MerklePath {
33221
33478
  return writer.toUint8Array();
33222
33479
  }
33223
33480
  toHex() {
33224
- return toHex(this.toBinaryUint8Array());
33481
+ return toHex2(this.toBinaryUint8Array());
33225
33482
  }
33226
33483
  indexOf(txid) {
33227
33484
  const leaf = this.path[0].find((l) => l.hash === txid);
@@ -33245,7 +33502,7 @@ class MerklePath {
33245
33502
  if (typeof index !== "number") {
33246
33503
  throw new Error(`This proof does not contain the txid: ${txid ?? "undefined"}`);
33247
33504
  }
33248
- const hash = (m) => toHex(hash256(toArray2(m, "hex").reverse()).reverse());
33505
+ const hash = (m) => toHex2(hash256(toArray2(m, "hex").reverse()).reverse());
33249
33506
  let workingHash = txid;
33250
33507
  if (this.path.length === 1 && this.path[0].length === 1)
33251
33508
  return workingHash;
@@ -33267,7 +33524,7 @@ class MerklePath {
33267
33524
  return workingHash;
33268
33525
  }
33269
33526
  findOrComputeLeaf(height, offset) {
33270
- const hash = (m) => toHex(hash256(toArray2(m, "hex").reverse()).reverse());
33527
+ const hash = (m) => toHex2(hash256(toArray2(m, "hex").reverse()).reverse());
33271
33528
  let leaf = this.path[height].find((l2) => l2.offset === offset);
33272
33529
  if (leaf != null)
33273
33530
  return leaf;
@@ -33410,7 +33667,7 @@ class BeefTx {
33410
33667
  return this._txid;
33411
33668
  }
33412
33669
  if (this._rawTx != null) {
33413
- this._txid = toHex(hash256(this._rawTx));
33670
+ this._txid = toHex2(hash256(this._rawTx));
33414
33671
  return this._txid;
33415
33672
  }
33416
33673
  throw new Error("Internal");
@@ -33530,7 +33787,7 @@ class BeefTx {
33530
33787
  if (version === BEEF_V2) {
33531
33788
  const format = br2.readUInt8();
33532
33789
  if (format === TX_DATA_FORMAT.TXID_ONLY) {
33533
- beefTx = BeefTx.fromTxid(toHex(br2.readReverse(32)));
33790
+ beefTx = BeefTx.fromTxid(toHex2(br2.readReverse(32)));
33534
33791
  } else {
33535
33792
  if (format === TX_DATA_FORMAT.RAWTX_AND_BUMP_INDEX) {
33536
33793
  bumpIndex = br2.readVarIntNum();
@@ -33913,7 +34170,7 @@ class Beef {
33913
34170
  return this.hexCache;
33914
34171
  }
33915
34172
  const bytes2 = this.getSerializedBytes();
33916
- const hex = toHex(bytes2);
34173
+ const hex = toHex2(bytes2);
33917
34174
  this.hexCache = hex;
33918
34175
  return hex;
33919
34176
  }
@@ -33921,7 +34178,7 @@ class Beef {
33921
34178
  let version = br2.readUInt32LE();
33922
34179
  let atomicTxid;
33923
34180
  if (version === ATOMIC_BEEF) {
33924
- atomicTxid = toHex(br2.readReverse(32));
34181
+ atomicTxid = toHex2(br2.readReverse(32));
33925
34182
  version = br2.readUInt32LE();
33926
34183
  }
33927
34184
  if (version !== BEEF_V1 && version !== BEEF_V2) {
@@ -34130,7 +34387,7 @@ ${t.inputTxids.map((it2) => ` '${it2}'`).join(`,
34130
34387
  return log;
34131
34388
  }
34132
34389
  addComputedLeaves() {
34133
- const hash = (m) => toHex(hash256(toArray2(m, "hex").reverse()).reverse());
34390
+ const hash = (m) => toHex2(hash256(toArray2(m, "hex").reverse()).reverse());
34134
34391
  for (const bump of this.bumps) {
34135
34392
  for (let row = 1;row < bump.path.length; row++) {
34136
34393
  for (const leafL of bump.path[row - 1]) {
@@ -34217,13 +34474,13 @@ class Transaction {
34217
34474
  static fromEF(ef2) {
34218
34475
  const br2 = ReaderUint8Array.makeReader(ef2);
34219
34476
  const version = br2.readUInt32LE();
34220
- if (toHex(br2.read(6)) !== "0000000000ef") {
34477
+ if (toHex2(br2.read(6)) !== "0000000000ef") {
34221
34478
  throw new Error("Invalid EF marker");
34222
34479
  }
34223
34480
  const inputsLength = br2.readVarIntNum();
34224
34481
  const inputs = [];
34225
34482
  for (let i = 0;i < inputsLength; i++) {
34226
- const sourceTXID = toHex(br2.readReverse(32));
34483
+ const sourceTXID = toHex2(br2.readReverse(32));
34227
34484
  const sourceOutputIndex = br2.readUInt32LE();
34228
34485
  const scriptLength = br2.readVarIntNum();
34229
34486
  const scriptBin = br2.read(scriptLength);
@@ -34288,7 +34545,7 @@ class Transaction {
34288
34545
  const inputsLength = br2.readVarIntNum();
34289
34546
  const inputs = [];
34290
34547
  for (let i = 0;i < inputsLength; i++) {
34291
- const sourceTXID = toHex(br2.readReverse(32));
34548
+ const sourceTXID = toHex2(br2.readReverse(32));
34292
34549
  const sourceOutputIndex = br2.readUInt32LE();
34293
34550
  const scriptLength = br2.readVarIntNum();
34294
34551
  const scriptBin = br2.read(scriptLength);
@@ -34329,7 +34586,7 @@ class Transaction {
34329
34586
  const br2 = new ReaderUint8Array(rawBytes);
34330
34587
  const tx = Transaction.fromReader(br2);
34331
34588
  tx.rawBytesCache = rawBytes;
34332
- tx.hexCache = toHex(rawBytes);
34589
+ tx.hexCache = toHex2(rawBytes);
34333
34590
  return tx;
34334
34591
  }
34335
34592
  static fromHexEF(hex) {
@@ -34608,29 +34865,29 @@ class Transaction {
34608
34865
  return writer.toUint8Array();
34609
34866
  }
34610
34867
  toHexEF() {
34611
- return toHex(this.toEFUint8Array());
34868
+ return toHex2(this.toEFUint8Array());
34612
34869
  }
34613
34870
  toHex() {
34614
34871
  if (this.hexCache != null) {
34615
34872
  return this.hexCache;
34616
34873
  }
34617
34874
  const bytes2 = this.getSerializedBytes();
34618
- const hex = toHex(bytes2);
34875
+ const hex = toHex2(bytes2);
34619
34876
  this.hexCache = hex;
34620
34877
  return hex;
34621
34878
  }
34622
34879
  toHexBEEF() {
34623
- return toHex(this.toBEEF());
34880
+ return toHex2(this.toBEEF());
34624
34881
  }
34625
34882
  toHexAtomicBEEF() {
34626
- return toHex(this.toAtomicBEEF());
34883
+ return toHex2(this.toAtomicBEEF());
34627
34884
  }
34628
34885
  hash(enc) {
34629
34886
  if (this.cachedHash == null) {
34630
34887
  this.cachedHash = hash256(this.getSerializedBytes());
34631
34888
  }
34632
34889
  if (enc === "hex") {
34633
- return toHex(this.cachedHash);
34890
+ return toHex2(this.cachedHash);
34634
34891
  }
34635
34892
  return this.cachedHash;
34636
34893
  }
@@ -34638,7 +34895,7 @@ class Transaction {
34638
34895
  const id2 = [...this.hash()];
34639
34896
  id2.reverse();
34640
34897
  if (enc === "hex") {
34641
- return toHex(id2);
34898
+ return toHex2(id2);
34642
34899
  }
34643
34900
  return id2;
34644
34901
  }
@@ -35026,7 +35283,7 @@ class HD {
35026
35283
  this.privKey = new PrivateKey(keyBytes.slice(1, 33));
35027
35284
  this.pubKey = this.privKey.toPublicKey();
35028
35285
  } else if (isPublic && (keyBytes[0] === 2 || keyBytes[0] === 3)) {
35029
- this.pubKey = PublicKey.fromString(toHex(keyBytes));
35286
+ this.pubKey = PublicKey.fromString(toHex2(keyBytes));
35030
35287
  } else {
35031
35288
  throw new Error("Invalid key");
35032
35289
  }
@@ -36017,11 +36274,11 @@ class Certificate {
36017
36274
  const serialNumberBytes = reader.read(32);
36018
36275
  const serialNumber = toBase64(serialNumberBytes);
36019
36276
  const subjectBytes = reader.read(33);
36020
- const subject = toHex(subjectBytes);
36277
+ const subject = toHex2(subjectBytes);
36021
36278
  const certifierBytes = reader.read(33);
36022
- const certifier = toHex(certifierBytes);
36279
+ const certifier = toHex2(certifierBytes);
36023
36280
  const txidBytes = reader.read(32);
36024
- const txid = toHex(txidBytes);
36281
+ const txid = toHex2(txidBytes);
36025
36282
  const outputIndex = reader.readVarIntNum();
36026
36283
  const revocationOutpoint = `${txid}.${outputIndex}`;
36027
36284
  const numFields = reader.readVarIntNum();
@@ -36067,7 +36324,7 @@ class Certificate {
36067
36324
  protocolID: [2, "certificate signature"],
36068
36325
  keyID: `${this.type} ${this.serialNumber}`
36069
36326
  });
36070
- this.signature = toHex(signature);
36327
+ this.signature = toHex2(signature);
36071
36328
  }
36072
36329
  static getCertificateFieldEncryptionDetails(fieldName, serialNumber) {
36073
36330
  return {
@@ -36308,7 +36565,7 @@ class WalletWireTransceiver {
36308
36565
  const txidFlag = resultReader.readInt8();
36309
36566
  if (txidFlag === 1) {
36310
36567
  const txidBytes = resultReader.read(32);
36311
- response.txid = toHex(txidBytes);
36568
+ response.txid = toHex2(txidBytes);
36312
36569
  }
36313
36570
  const txFlag = resultReader.readInt8();
36314
36571
  if (txFlag === 1) {
@@ -36328,7 +36585,7 @@ class WalletWireTransceiver {
36328
36585
  response.sendWithResults = [];
36329
36586
  for (let i = 0;i < sendWithResultsLength; i++) {
36330
36587
  const txidBytes = resultReader.read(32);
36331
- const txid = toHex(txidBytes);
36588
+ const txid = toHex2(txidBytes);
36332
36589
  const statusCode = resultReader.readInt8();
36333
36590
  let status = "unproven";
36334
36591
  if (statusCode === 1)
@@ -36407,7 +36664,7 @@ class WalletWireTransceiver {
36407
36664
  const txidFlag = resultReader.readInt8();
36408
36665
  if (txidFlag === 1) {
36409
36666
  const txidBytes = resultReader.read(32);
36410
- response.txid = toHex(txidBytes);
36667
+ response.txid = toHex2(txidBytes);
36411
36668
  }
36412
36669
  const txFlag = resultReader.readInt8();
36413
36670
  if (txFlag === 1) {
@@ -36419,7 +36676,7 @@ class WalletWireTransceiver {
36419
36676
  response.sendWithResults = [];
36420
36677
  for (let i = 0;i < sendWithResultsLength; i++) {
36421
36678
  const txidBytes = resultReader.read(32);
36422
- const txid = toHex(txidBytes);
36679
+ const txid = toHex2(txidBytes);
36423
36680
  const statusCode = resultReader.readInt8();
36424
36681
  let status = "unproven";
36425
36682
  if (statusCode === 1)
@@ -36484,7 +36741,7 @@ class WalletWireTransceiver {
36484
36741
  const actions = [];
36485
36742
  for (let i = 0;i < totalActions; i++) {
36486
36743
  const txidBytes = resultReader.read(32);
36487
- const txid = toHex(txidBytes);
36744
+ const txid = toHex2(txidBytes);
36488
36745
  const satoshis = resultReader.readVarIntNum();
36489
36746
  const statusCode = resultReader.readInt8();
36490
36747
  let status;
@@ -36550,13 +36807,13 @@ class WalletWireTransceiver {
36550
36807
  let sourceLockingScript;
36551
36808
  if (sourceLockingScriptLength >= 0) {
36552
36809
  const sourceLockingScriptBytes = resultReader.read(sourceLockingScriptLength);
36553
- sourceLockingScript = toHex(sourceLockingScriptBytes);
36810
+ sourceLockingScript = toHex2(sourceLockingScriptBytes);
36554
36811
  }
36555
36812
  const unlockingScriptLength = resultReader.readVarIntNum();
36556
36813
  let unlockingScript;
36557
36814
  if (unlockingScriptLength >= 0) {
36558
36815
  const unlockingScriptBytes = resultReader.read(unlockingScriptLength);
36559
- unlockingScript = toHex(unlockingScriptBytes);
36816
+ unlockingScript = toHex2(unlockingScriptBytes);
36560
36817
  }
36561
36818
  const inputDescriptionLength = resultReader.readVarIntNum();
36562
36819
  const inputDescriptionBytes = resultReader.read(inputDescriptionLength);
@@ -36582,7 +36839,7 @@ class WalletWireTransceiver {
36582
36839
  let lockingScript;
36583
36840
  if (lockingScriptLength >= 0) {
36584
36841
  const lockingScriptBytes = resultReader.read(lockingScriptLength);
36585
- lockingScript = toHex(lockingScriptBytes);
36842
+ lockingScript = toHex2(lockingScriptBytes);
36586
36843
  }
36587
36844
  const spendable = resultReader.readInt8() === 1;
36588
36845
  const outputDescriptionLength = resultReader.readVarIntNum();
@@ -36762,7 +37019,7 @@ class WalletWireTransceiver {
36762
37019
  };
36763
37020
  const scriptLength = resultReader.readVarIntNum();
36764
37021
  if (scriptLength >= 0) {
36765
- output.lockingScript = toHex(resultReader.read(scriptLength));
37022
+ output.lockingScript = toHex2(resultReader.read(scriptLength));
36766
37023
  }
36767
37024
  const customInstructionsLength = resultReader.readVarIntNum();
36768
37025
  if (customInstructionsLength >= 0) {
@@ -36811,7 +37068,7 @@ class WalletWireTransceiver {
36811
37068
  return writer.toArray();
36812
37069
  }
36813
37070
  readOutpoint(reader) {
36814
- const txid = toHex(reader.read(32));
37071
+ const txid = toHex2(reader.read(32));
36815
37072
  const index = reader.readVarIntNum();
36816
37073
  return `${txid}.${index}`;
36817
37074
  }
@@ -36831,7 +37088,7 @@ class WalletWireTransceiver {
36831
37088
  paramWriter.writeInt8(typeof args.seekPermission === "boolean" ? args.seekPermission ? 1 : 0 : -1);
36832
37089
  const result = await this.transmit("getPublicKey", originator, paramWriter.toArray());
36833
37090
  return {
36834
- publicKey: toHex(result)
37091
+ publicKey: toHex2(result)
36835
37092
  };
36836
37093
  }
36837
37094
  async revealCounterpartyKeyLinkage(args, originator) {
@@ -36841,9 +37098,9 @@ class WalletWireTransceiver {
36841
37098
  paramWriter.write(toArray2(args.verifier, "hex"));
36842
37099
  const result = await this.transmit("revealCounterpartyKeyLinkage", originator, paramWriter.toArray());
36843
37100
  const resultReader = new Reader(result);
36844
- const prover = toHex(resultReader.read(33));
36845
- const verifier = toHex(resultReader.read(33));
36846
- const counterparty = toHex(resultReader.read(33));
37101
+ const prover = toHex2(resultReader.read(33));
37102
+ const verifier = toHex2(resultReader.read(33));
37103
+ const counterparty = toHex2(resultReader.read(33));
36847
37104
  const revelationTimeLength = resultReader.readVarIntNum();
36848
37105
  const revelationTime = toUTF8(resultReader.read(revelationTimeLength));
36849
37106
  const encryptedLinkageLength = resultReader.readVarIntNum();
@@ -36865,9 +37122,9 @@ class WalletWireTransceiver {
36865
37122
  paramWriter.write(toArray2(args.verifier, "hex"));
36866
37123
  const result = await this.transmit("revealSpecificKeyLinkage", originator, paramWriter.toArray());
36867
37124
  const resultReader = new Reader(result);
36868
- const prover = toHex(resultReader.read(33));
36869
- const verifier = toHex(resultReader.read(33));
36870
- const counterparty = toHex(resultReader.read(33));
37125
+ const prover = toHex2(resultReader.read(33));
37126
+ const verifier = toHex2(resultReader.read(33));
37127
+ const counterparty = toHex2(resultReader.read(33));
36871
37128
  const securityLevel = resultReader.readUInt8();
36872
37129
  const protocolLength = resultReader.readVarIntNum();
36873
37130
  const protocol = toUTF8(resultReader.read(protocolLength));
@@ -37269,7 +37526,7 @@ class WalletWireTransceiver {
37269
37526
  paramWriter.writeVarIntNum(args.height);
37270
37527
  const header = await this.transmit("getHeaderForHeight", originator, paramWriter.toArray());
37271
37528
  return {
37272
- header: toHex(header)
37529
+ header: toHex2(header)
37273
37530
  };
37274
37531
  }
37275
37532
  async getNetwork(args, originator) {
@@ -39373,7 +39630,7 @@ class HTTPSOverlayLookupFacilitator {
39373
39630
  const nOutpoints = r2.readVarIntNum();
39374
39631
  const outpoints = [];
39375
39632
  for (let i = 0;i < nOutpoints; i++) {
39376
- const txid = toHex(r2.read(32));
39633
+ const txid = toHex2(r2.read(32));
39377
39634
  const outputIndex = r2.readVarIntNum();
39378
39635
  const contextLength = r2.readVarIntNum();
39379
39636
  let context;
@@ -40929,7 +41186,7 @@ class GlobalKVStore {
40929
41186
  await anyoneWallet.verifySignature({
40930
41187
  data: decoded.fields.reduce((a, e) => [...a, ...e], []),
40931
41188
  signature,
40932
- counterparty: toHex(decoded.fields[kvProtocol.controller]),
41189
+ counterparty: toHex2(decoded.fields[kvProtocol.controller]),
40933
41190
  protocolID: JSON.parse(toUTF8(decoded.fields[kvProtocol.protocolID])),
40934
41191
  keyID: toUTF8(decoded.fields[kvProtocol.key])
40935
41192
  });
@@ -40947,7 +41204,7 @@ class GlobalKVStore {
40947
41204
  const entry = {
40948
41205
  key: toUTF8(decoded.fields[kvProtocol.key]),
40949
41206
  value: toUTF8(decoded.fields[kvProtocol.value]),
40950
- controller: toHex(decoded.fields[kvProtocol.controller]),
41207
+ controller: toHex2(decoded.fields[kvProtocol.controller]),
40951
41208
  protocolID: JSON.parse(toUTF8(decoded.fields[kvProtocol.protocolID])),
40952
41209
  tags
40953
41210
  };
@@ -40976,263 +41233,6 @@ class GlobalKVStore {
40976
41233
  return await this.topicBroadcaster.broadcast(transaction);
40977
41234
  }
40978
41235
  }
40979
- // ../wallet/node_modules/@1sat/client/dist/errors.js
40980
- class HttpError extends Error {
40981
- status;
40982
- constructor(status, message) {
40983
- super(message);
40984
- this.status = status;
40985
- this.name = "HttpError";
40986
- }
40987
- }
40988
- // ../wallet/node_modules/@1sat/client/dist/services/BaseClient.js
40989
- class BaseClient {
40990
- baseUrl;
40991
- timeout;
40992
- fetchFn;
40993
- constructor(baseUrl, options = {}) {
40994
- this.baseUrl = baseUrl.replace(/\/$/, "");
40995
- this.timeout = options.timeout ?? 30000;
40996
- this.fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
40997
- }
40998
- async request(path, init) {
40999
- const controller = new AbortController;
41000
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
41001
- try {
41002
- const response = await this.fetchFn(`${this.baseUrl}${path}`, {
41003
- ...init,
41004
- signal: controller.signal
41005
- });
41006
- if (!response.ok) {
41007
- throw await this.parseError(response);
41008
- }
41009
- const text = await response.text();
41010
- if (!text) {
41011
- return;
41012
- }
41013
- return JSON.parse(text);
41014
- } finally {
41015
- clearTimeout(timeoutId);
41016
- }
41017
- }
41018
- async requestBinary(path, init) {
41019
- const controller = new AbortController;
41020
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
41021
- try {
41022
- const response = await this.fetchFn(`${this.baseUrl}${path}`, {
41023
- ...init,
41024
- signal: controller.signal
41025
- });
41026
- if (!response.ok) {
41027
- throw await this.parseError(response);
41028
- }
41029
- const arrayBuffer = await response.arrayBuffer();
41030
- return new Uint8Array(arrayBuffer);
41031
- } finally {
41032
- clearTimeout(timeoutId);
41033
- }
41034
- }
41035
- async requestRaw(path, init) {
41036
- const controller = new AbortController;
41037
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
41038
- try {
41039
- const response = await this.fetchFn(`${this.baseUrl}${path}`, {
41040
- ...init,
41041
- signal: controller.signal
41042
- });
41043
- if (!response.ok) {
41044
- throw await this.parseError(response);
41045
- }
41046
- return response;
41047
- } finally {
41048
- clearTimeout(timeoutId);
41049
- }
41050
- }
41051
- async parseError(response) {
41052
- try {
41053
- const data = await response.json();
41054
- const message = data.message || data.error || data.detail || response.statusText;
41055
- return new HttpError(response.status, message);
41056
- } catch {
41057
- try {
41058
- const text = await response.text();
41059
- return new HttpError(response.status, text || response.statusText);
41060
- } catch {
41061
- return new HttpError(response.status, response.statusText);
41062
- }
41063
- }
41064
- }
41065
- buildQueryString(params) {
41066
- const entries = [];
41067
- for (const [key, value] of Object.entries(params)) {
41068
- if (value === undefined)
41069
- continue;
41070
- if (Array.isArray(value)) {
41071
- if (value.length > 0) {
41072
- entries.push(`${key}=${encodeURIComponent(value.join(","))}`);
41073
- }
41074
- } else if (typeof value === "boolean") {
41075
- if (value) {
41076
- entries.push(`${key}=true`);
41077
- }
41078
- } else {
41079
- entries.push(`${key}=${encodeURIComponent(String(value))}`);
41080
- }
41081
- }
41082
- return entries.length > 0 ? `?${entries.join("&")}` : "";
41083
- }
41084
- }
41085
- // ../wallet/node_modules/@1sat/client/dist/services/ChaintracksClient.js
41086
- function toHex2(data) {
41087
- return Array.from(data).map((b3) => b3.toString(16).padStart(2, "0")).join("");
41088
- }
41089
-
41090
- class ChaintracksClient extends BaseClient {
41091
- eventSource = null;
41092
- subscribers = new Set;
41093
- cachedTip = null;
41094
- cachedTipTime = 0;
41095
- static TIP_CACHE_TTL_MS = 30000;
41096
- constructor(baseUrl, options = {}) {
41097
- super(`${baseUrl}/1sat/chaintracks`, options);
41098
- }
41099
- async currentHeight() {
41100
- const tip = await this.findChainTipHeader();
41101
- return tip.height;
41102
- }
41103
- async isValidRootForHeight(root, height) {
41104
- try {
41105
- const header = await this.findHeaderForHeight(height);
41106
- return header?.merkleRoot === root;
41107
- } catch (e) {
41108
- console.error(`isValidRootForHeight(${height}) failed:`, e);
41109
- return false;
41110
- }
41111
- }
41112
- async getChain() {
41113
- const data = await this.request("/network");
41114
- return data.network;
41115
- }
41116
- async getInfo() {
41117
- const tip = await this.findChainTipHeader();
41118
- const chain = await this.getChain();
41119
- return {
41120
- chain,
41121
- heightBulk: tip.height,
41122
- heightLive: tip.height,
41123
- storage: "remote",
41124
- bulkIngestors: [],
41125
- liveIngestors: [],
41126
- packages: []
41127
- };
41128
- }
41129
- async getPresentHeight() {
41130
- return this.currentHeight();
41131
- }
41132
- async getHeaders(height, count) {
41133
- const data = await this.requestBinary(`/headers?height=${height}&count=${count}`);
41134
- return toHex2(data);
41135
- }
41136
- async findChainTipHeader() {
41137
- const now = Date.now();
41138
- if (this.cachedTip && now - this.cachedTipTime < ChaintracksClient.TIP_CACHE_TTL_MS) {
41139
- return this.cachedTip;
41140
- }
41141
- const header = await this.request("/tip");
41142
- console.log("[ChaintracksClient] findChainTipHeader:", header.height, header.hash);
41143
- this.cachedTip = header;
41144
- this.cachedTipTime = now;
41145
- return header;
41146
- }
41147
- async findChainTipHash() {
41148
- const tip = await this.findChainTipHeader();
41149
- return tip.hash;
41150
- }
41151
- async findHeaderForHeight(height) {
41152
- try {
41153
- return await this.request(`/header/height/${height}`);
41154
- } catch {
41155
- return;
41156
- }
41157
- }
41158
- async findHeaderForBlockHash(hash) {
41159
- try {
41160
- return await this.request(`/header/hash/${hash}`);
41161
- } catch {
41162
- return;
41163
- }
41164
- }
41165
- async addHeader(_header) {}
41166
- async startListening() {}
41167
- async listening() {}
41168
- async isListening() {
41169
- return true;
41170
- }
41171
- async isSynchronized() {
41172
- return true;
41173
- }
41174
- async subscribeReorgs(_listener) {
41175
- throw new Error("Method not implemented.");
41176
- }
41177
- async unsubscribe(_subscriptionId) {
41178
- return false;
41179
- }
41180
- async subscribeHeaders(listener) {
41181
- this.subscribers.add(listener);
41182
- if (!this.eventSource) {
41183
- this.eventSource = new EventSource(`${this.baseUrl}/tip/stream`);
41184
- this.eventSource.onmessage = (event) => {
41185
- try {
41186
- const header = JSON.parse(event.data);
41187
- for (const cb of this.subscribers) {
41188
- cb(header);
41189
- }
41190
- } catch {}
41191
- };
41192
- this.eventSource.onerror = () => {
41193
- this.eventSource?.close();
41194
- this.eventSource = null;
41195
- };
41196
- }
41197
- return "subscription";
41198
- }
41199
- async getHeaderBytes(height, count = 1) {
41200
- const data = await this.requestBinary(`/headers?height=${height}&count=${count}`);
41201
- return Array.from(data);
41202
- }
41203
- subscribe(callback) {
41204
- this.subscribers.add(callback);
41205
- if (!this.eventSource) {
41206
- this.eventSource = new EventSource(`${this.baseUrl}/tip/stream`);
41207
- this.eventSource.onmessage = (event) => {
41208
- try {
41209
- const header = JSON.parse(event.data);
41210
- for (const cb of this.subscribers) {
41211
- cb(header);
41212
- }
41213
- } catch {}
41214
- };
41215
- this.eventSource.onerror = () => {
41216
- this.eventSource?.close();
41217
- this.eventSource = null;
41218
- };
41219
- }
41220
- return () => {
41221
- this.subscribers.delete(callback);
41222
- if (this.subscribers.size === 0 && this.eventSource) {
41223
- this.eventSource.close();
41224
- this.eventSource = null;
41225
- }
41226
- };
41227
- }
41228
- close() {
41229
- if (this.eventSource) {
41230
- this.eventSource.close();
41231
- this.eventSource = null;
41232
- }
41233
- this.subscribers.clear();
41234
- }
41235
- }
41236
41236
  // ../wallet/node_modules/@1sat/client/dist/services/Bsv21Client.js
41237
41237
  class Bsv21Client extends BaseClient {
41238
41238
  cache = new Map;
@@ -41352,7 +41352,45 @@ var RoytaltyType;
41352
41352
 
41353
41353
  // ../wallet/node_modules/@1sat/client/dist/services/OneSatServices.js
41354
41354
  var import_WalletError5 = __toESM(require_WalletError(), 1);
41355
- // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bitcom/B.js
41355
+ // ../types/dist/constants.js
41356
+ var ORD_LOCK_PREFIX = "2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000";
41357
+ var ORD_LOCK_SUFFIX = "615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868";
41358
+ var LOCK_PREFIX = "2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000";
41359
+ var LOCK_SUFFIX = "610079040065cd1d9f690079547a75537a537a537a5179537a75527a527a7575615579014161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a7561040065cd1d9f6955796100796100798277517951790128947f755179012c947f77517a75517a756161007901007e81517a7561517a756105ffffffff009f69557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a75615279a2695679a95179876957795779ac7777777777777777";
41360
+ var EXCHANGE_RATE_CACHE_TTL2 = 5 * 60 * 1000;
41361
+
41362
+ // ../types/dist/index.js
41363
+ var TokenType2;
41364
+ (function(TokenType3) {
41365
+ TokenType3["BSV20"] = "bsv20";
41366
+ TokenType3["BSV21"] = "bsv21";
41367
+ })(TokenType2 || (TokenType2 = {}));
41368
+ var TokenSelectionStrategy2;
41369
+ (function(TokenSelectionStrategy3) {
41370
+ TokenSelectionStrategy3["SmallestFirst"] = "smallest";
41371
+ TokenSelectionStrategy3["LargestFirst"] = "largest";
41372
+ TokenSelectionStrategy3["RetainOrder"] = "retain";
41373
+ TokenSelectionStrategy3["Random"] = "random";
41374
+ })(TokenSelectionStrategy2 || (TokenSelectionStrategy2 = {}));
41375
+ var TokenInputMode2;
41376
+ (function(TokenInputMode3) {
41377
+ TokenInputMode3["All"] = "all";
41378
+ TokenInputMode3["Needed"] = "needed";
41379
+ })(TokenInputMode2 || (TokenInputMode2 = {}));
41380
+ var RoytaltyType2;
41381
+ (function(RoytaltyType3) {
41382
+ RoytaltyType3["Paymail"] = "paymail";
41383
+ RoytaltyType3["Address"] = "address";
41384
+ RoytaltyType3["Script"] = "script";
41385
+ })(RoytaltyType2 || (RoytaltyType2 = {}));
41386
+
41387
+ // ../templates/dist/ordlock/ordlock.js
41388
+ var ORDLOCK_PREFIX = exports_utils.toArray(ORD_LOCK_PREFIX, "hex");
41389
+ var ORDLOCK_SUFFIX = exports_utils.toArray(ORD_LOCK_SUFFIX, "hex");
41390
+ // ../templates/dist/lock/lock.js
41391
+ var LOCK_PREFIX2 = exports_utils.toArray(LOCK_PREFIX, "hex");
41392
+ var LOCK_SUFFIX2 = exports_utils.toArray(LOCK_SUFFIX, "hex");
41393
+ // ../templates/dist/bitcom/b.js
41356
41394
  var MediaType;
41357
41395
  (function(MediaType2) {
41358
41396
  MediaType2["TextPlain"] = "text/plain";
@@ -41370,8 +41408,15 @@ var Encoding;
41370
41408
  Encoding2["Base64"] = "base64";
41371
41409
  Encoding2["Hex"] = "hex";
41372
41410
  })(Encoding || (Encoding = {}));
41373
-
41374
- // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bitcom/MAP.js
41411
+ // ../templates/dist/bitcom/bap.js
41412
+ var BAPAttestationType;
41413
+ (function(BAPAttestationType2) {
41414
+ BAPAttestationType2["ID"] = "ID";
41415
+ BAPAttestationType2["ATTEST"] = "ATTEST";
41416
+ BAPAttestationType2["REVOKE"] = "REVOKE";
41417
+ BAPAttestationType2["ALIAS"] = "ALIAS";
41418
+ })(BAPAttestationType || (BAPAttestationType = {}));
41419
+ // ../templates/dist/bitcom/map.js
41375
41420
  var MAPCommand;
41376
41421
  (function(MAPCommand2) {
41377
41422
  MAPCommand2["SET"] = "SET";
@@ -41379,8 +41424,7 @@ var MAPCommand;
41379
41424
  MAPCommand2["ADD"] = "ADD";
41380
41425
  MAPCommand2["SELECT"] = "SELECT";
41381
41426
  })(MAPCommand || (MAPCommand = {}));
41382
-
41383
- // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bsocial/BSocial.js
41427
+ // ../templates/dist/bsocial/bsocial.js
41384
41428
  var BSocialActionType;
41385
41429
  (function(BSocialActionType2) {
41386
41430
  BSocialActionType2["POST"] = "post";
@@ -41402,22 +41446,78 @@ var BSocialContext;
41402
41446
  BSocialContext2["BTC_TX"] = "btcTx";
41403
41447
  BSocialContext2["ETH_TX"] = "ethTx";
41404
41448
  })(BSocialContext || (BSocialContext = {}));
41449
+ // ../../node_modules/sigma-protocol/dist/index.module.js
41450
+ var C;
41451
+ ((W) => {
41452
+ W.BSM = "BSM";
41453
+ W.BRC77 = "BRC77";
41454
+ })(C ||= {});
41455
+ // ../wallet/dist/indexers/Bsv21Indexer.js
41456
+ var hdKey = HD.fromString(BSV21_FEE_XPUB);
41457
+ // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bitcom/B.js
41458
+ var MediaType2;
41459
+ (function(MediaType3) {
41460
+ MediaType3["TextPlain"] = "text/plain";
41461
+ MediaType3["TextMarkdown"] = "text/markdown";
41462
+ MediaType3["TextHTML"] = "text/html";
41463
+ MediaType3["ImagePNG"] = "image/png";
41464
+ MediaType3["ImageJPEG"] = "image/jpeg";
41465
+ MediaType3["ApplicationJSON"] = "application/json";
41466
+ MediaType3["ApplicationPDF"] = "application/pdf";
41467
+ })(MediaType2 || (MediaType2 = {}));
41468
+ var Encoding2;
41469
+ (function(Encoding3) {
41470
+ Encoding3["UTF8"] = "utf-8";
41471
+ Encoding3["Binary"] = "binary";
41472
+ Encoding3["Base64"] = "base64";
41473
+ Encoding3["Hex"] = "hex";
41474
+ })(Encoding2 || (Encoding2 = {}));
41475
+
41476
+ // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bitcom/MAP.js
41477
+ var MAPCommand2;
41478
+ (function(MAPCommand3) {
41479
+ MAPCommand3["SET"] = "SET";
41480
+ MAPCommand3["DEL"] = "DEL";
41481
+ MAPCommand3["ADD"] = "ADD";
41482
+ MAPCommand3["SELECT"] = "SELECT";
41483
+ })(MAPCommand2 || (MAPCommand2 = {}));
41484
+
41485
+ // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bsocial/BSocial.js
41486
+ var BSocialActionType2;
41487
+ (function(BSocialActionType3) {
41488
+ BSocialActionType3["POST"] = "post";
41489
+ BSocialActionType3["LIKE"] = "like";
41490
+ BSocialActionType3["UNLIKE"] = "unlike";
41491
+ BSocialActionType3["FOLLOW"] = "follow";
41492
+ BSocialActionType3["UNFOLLOW"] = "unfollow";
41493
+ BSocialActionType3["MESSAGE"] = "message";
41494
+ BSocialActionType3["VIDEO"] = "video";
41495
+ })(BSocialActionType2 || (BSocialActionType2 = {}));
41496
+ var BSocialContext2;
41497
+ (function(BSocialContext3) {
41498
+ BSocialContext3["TX"] = "tx";
41499
+ BSocialContext3["CHANNEL"] = "channel";
41500
+ BSocialContext3["BAP_ID"] = "bapID";
41501
+ BSocialContext3["PROVIDER"] = "provider";
41502
+ BSocialContext3["VIDEO_ID"] = "videoID";
41503
+ BSocialContext3["GEOHASH"] = "geohash";
41504
+ BSocialContext3["BTC_TX"] = "btcTx";
41505
+ BSocialContext3["ETH_TX"] = "ethTx";
41506
+ })(BSocialContext2 || (BSocialContext2 = {}));
41405
41507
  // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/bitcom/BAP.js
41406
- var BAPAttestationType;
41407
- (function(BAPAttestationType2) {
41408
- BAPAttestationType2["ID"] = "ID";
41409
- BAPAttestationType2["ATTEST"] = "ATTEST";
41410
- BAPAttestationType2["REVOKE"] = "REVOKE";
41411
- BAPAttestationType2["ALIAS"] = "ALIAS";
41412
- })(BAPAttestationType || (BAPAttestationType = {}));
41508
+ var BAPAttestationType2;
41509
+ (function(BAPAttestationType3) {
41510
+ BAPAttestationType3["ID"] = "ID";
41511
+ BAPAttestationType3["ATTEST"] = "ATTEST";
41512
+ BAPAttestationType3["REVOKE"] = "REVOKE";
41513
+ BAPAttestationType3["ALIAS"] = "ALIAS";
41514
+ })(BAPAttestationType2 || (BAPAttestationType2 = {}));
41413
41515
  // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/ordlock/OrdLock.js
41414
- var ORDLOCK_PREFIX = exports_utils.toArray("2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000", "hex");
41415
- var ORDLOCK_SUFFIX = exports_utils.toArray("615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868", "hex");
41516
+ var ORDLOCK_PREFIX2 = exports_utils.toArray("2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000", "hex");
41517
+ var ORDLOCK_SUFFIX2 = exports_utils.toArray("615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868", "hex");
41416
41518
  // ../wallet/node_modules/@bopen-io/templates/dist/esm/src/template/lockup/Lock.js
41417
- var LOCK_PREFIX = exports_utils.toArray("2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000", "hex");
41418
- var LOCK_SUFFIX = exports_utils.toArray("610079040065cd1d9f690079547a75537a537a537a5179537a75527a527a7575615579014161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a7561040065cd1d9f6955796100796100798277517951790128947f755179012c947f77517a75517a756161007901007e81517a7561517a756105ffffffff009f69557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a75615279a2695679a95179876957795779ac7777777777777777", "hex");
41419
- // ../wallet/dist/indexers/Bsv21Indexer.js
41420
- var hdKey = HD.fromString(BSV21_FEE_XPUB);
41519
+ var LOCK_PREFIX3 = exports_utils.toArray("2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000", "hex");
41520
+ var LOCK_SUFFIX3 = exports_utils.toArray("610079040065cd1d9f690079547a75537a537a537a5179537a75527a527a7575615579014161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a7561040065cd1d9f6955796100796100798277517951790128947f755179012c947f77517a75517a756161007901007e81517a7561517a756105ffffffff009f69557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a75615279a2695679a95179876957795779ac7777777777777777", "hex");
41421
41521
  // ../wallet/dist/address-sync/AddressManager.js
41422
41522
  class AddressManager {
41423
41523
  addressMap = new Map;
@@ -41757,50 +41857,277 @@ function createWebCWI(config) {
41757
41857
  };
41758
41858
  return { wallet: createCWI(transport), destroy };
41759
41859
  }
41760
- // src/connectWallet.ts
41761
- async function connectWallet(options) {
41762
- try {
41763
- const client = new WalletClient("auto");
41764
- await client.connectToSubstrate();
41765
- await client.waitForAuthentication({});
41766
- const { publicKey } = await client.getPublicKey({ identityKey: true });
41767
- return {
41768
- wallet: client,
41769
- provider: "brc100",
41770
- identityKey: publicKey,
41771
- disconnect: () => {}
41772
- };
41773
- } catch {}
41774
- try {
41775
- const config = {};
41776
- if (options?.walletUrl)
41777
- config.walletUrl = options.walletUrl;
41778
- if (options?.handshakeTimeout)
41779
- config.handshakeTimeout = options.handshakeTimeout;
41780
- const { wallet: wallet2, destroy } = createWebCWI(config);
41781
- await wallet2.waitForAuthentication({});
41782
- const { publicKey } = await wallet2.getPublicKey({ identityKey: true });
41783
- return {
41784
- wallet: wallet2,
41785
- provider: "onesat",
41786
- identityKey: publicKey,
41787
- disconnect: destroy
41860
+ // ../wallet/dist/cwi/sigma.js
41861
+ var DEFAULT_IFRAME_PATH2 = "/signer";
41862
+ var DEFAULT_REQUEST_TIMEOUT_MS2 = 30000;
41863
+ var DEFAULT_HANDSHAKE_TIMEOUT_MS2 = 1e4;
41864
+ var isRecord2 = (v) => typeof v === "object" && v !== null;
41865
+ var isResponse3 = (v) => isRecord2(v) && v.type === "CWI" && v.isInvocation === false && typeof v.id === "string";
41866
+ var isState2 = (v) => isRecord2(v) && v.type === "CWI" && isRecord2(v.cwiState);
41867
+ var createId2 = () => typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
41868
+ function createSigmaCWI(config) {
41869
+ if (typeof window === "undefined" || typeof document === "undefined") {
41870
+ throw new Error("createSigmaCWI requires a browser environment");
41871
+ }
41872
+ const { sigmaUrl } = config;
41873
+ const iframePath = config.iframePath ?? DEFAULT_IFRAME_PATH2;
41874
+ const requestTimeout = config.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS2;
41875
+ const handshakeTimeout = config.handshakeTimeout ?? DEFAULT_HANDSHAKE_TIMEOUT_MS2;
41876
+ const sigmaOrigin = new URL(sigmaUrl).origin;
41877
+ const iframeUrl = new URL(iframePath, sigmaUrl).toString();
41878
+ const pending = new Map;
41879
+ let iframe = null;
41880
+ let destroyed = false;
41881
+ let handshakeResolve = null;
41882
+ let handshakeReject = null;
41883
+ let handshakeComplete = false;
41884
+ const updateIframeVisibility = (show) => {
41885
+ if (!iframe)
41886
+ return;
41887
+ if (show) {
41888
+ iframe.style.width = "100%";
41889
+ iframe.style.height = "100%";
41890
+ iframe.style.opacity = "1";
41891
+ iframe.style.pointerEvents = "auto";
41892
+ } else {
41893
+ iframe.style.width = "0";
41894
+ iframe.style.height = "0";
41895
+ iframe.style.opacity = "0";
41896
+ iframe.style.pointerEvents = "none";
41897
+ }
41898
+ };
41899
+ const rejectAllPending = (error) => {
41900
+ for (const req of pending.values()) {
41901
+ clearTimeout(req.timeoutId);
41902
+ req.reject(error);
41903
+ }
41904
+ pending.clear();
41905
+ };
41906
+ const handleMessage = (event) => {
41907
+ if (destroyed)
41908
+ return;
41909
+ if (event.origin !== sigmaOrigin)
41910
+ return;
41911
+ const data = event.data;
41912
+ if (isState2(data)) {
41913
+ const { status, hasPermission } = data.cwiState;
41914
+ if (status === "need_password" || hasPermission) {
41915
+ updateIframeVisibility(true);
41916
+ } else {
41917
+ updateIframeVisibility(false);
41918
+ }
41919
+ if (!handshakeComplete) {
41920
+ handshakeComplete = true;
41921
+ handshakeResolve?.();
41922
+ handshakeResolve = null;
41923
+ handshakeReject = null;
41924
+ }
41925
+ if (status === "error") {
41926
+ rejectAllPending(new Error("Signer error. Please sign in to Sigma Identity."));
41927
+ }
41928
+ return;
41929
+ }
41930
+ if (!isResponse3(data))
41931
+ return;
41932
+ const req = pending.get(data.id);
41933
+ if (!req)
41934
+ return;
41935
+ pending.delete(data.id);
41936
+ clearTimeout(req.timeoutId);
41937
+ if (data.status === "error") {
41938
+ req.reject(new Error(data.description ?? "Sigma CWI request failed"));
41939
+ } else {
41940
+ req.resolve(data.result);
41941
+ }
41942
+ };
41943
+ const ensureIframe = () => {
41944
+ if (iframe)
41945
+ return iframe;
41946
+ const el2 = document.createElement("iframe");
41947
+ el2.src = iframeUrl;
41948
+ el2.setAttribute("aria-hidden", "true");
41949
+ el2.style.cssText = [
41950
+ "position: fixed",
41951
+ "top: 0",
41952
+ "left: 0",
41953
+ "width: 0",
41954
+ "height: 0",
41955
+ "border: 0",
41956
+ "opacity: 0",
41957
+ "pointer-events: none",
41958
+ "z-index: 2147483647"
41959
+ ].join("; ");
41960
+ const parent = document.body ?? document.documentElement;
41961
+ if (!parent)
41962
+ throw new Error("Unable to mount Sigma CWI iframe");
41963
+ parent.appendChild(el2);
41964
+ iframe = el2;
41965
+ return el2;
41966
+ };
41967
+ const waitForHandshake = () => {
41968
+ if (handshakeComplete)
41969
+ return Promise.resolve();
41970
+ return new Promise((resolve, reject) => {
41971
+ handshakeResolve = resolve;
41972
+ handshakeReject = reject;
41973
+ setTimeout(() => {
41974
+ if (!handshakeComplete) {
41975
+ handshakeReject?.(new Error("Sigma signer handshake timed out"));
41976
+ handshakeResolve = null;
41977
+ handshakeReject = null;
41978
+ }
41979
+ }, handshakeTimeout);
41980
+ });
41981
+ };
41982
+ window.addEventListener("message", handleMessage);
41983
+ ensureIframe();
41984
+ const transport = async (action, params) => {
41985
+ if (destroyed)
41986
+ throw new Error("SigmaCWI has been destroyed");
41987
+ await waitForHandshake();
41988
+ const target = iframe?.contentWindow;
41989
+ if (!target)
41990
+ throw new Error("Sigma iframe is not reachable");
41991
+ const id2 = createId2();
41992
+ const request = {
41993
+ type: "CWI",
41994
+ isInvocation: true,
41995
+ id: id2,
41996
+ call: action,
41997
+ args: params
41788
41998
  };
41789
- } catch {}
41999
+ return new Promise((resolve, reject) => {
42000
+ const timeoutId = setTimeout(() => {
42001
+ pending.delete(id2);
42002
+ reject(new Error(`Sigma CWI request timed out: ${action}`));
42003
+ }, requestTimeout);
42004
+ pending.set(id2, {
42005
+ resolve,
42006
+ reject,
42007
+ timeoutId
42008
+ });
42009
+ try {
42010
+ target.postMessage(request, sigmaOrigin);
42011
+ } catch (err) {
42012
+ clearTimeout(timeoutId);
42013
+ pending.delete(id2);
42014
+ reject(new Error(`Failed to post message to Sigma signer: ${err instanceof Error ? err.message : String(err)}`));
42015
+ }
42016
+ });
42017
+ };
42018
+ const sendCustomMessage = (type, payload) => {
42019
+ const target = iframe?.contentWindow;
42020
+ if (!target)
42021
+ return;
42022
+ target.postMessage({ type, payload }, sigmaOrigin);
42023
+ };
42024
+ const destroy = () => {
42025
+ if (destroyed)
42026
+ return;
42027
+ destroyed = true;
42028
+ window.removeEventListener("message", handleMessage);
42029
+ rejectAllPending(new Error("SigmaCWI destroyed"));
42030
+ if (iframe?.parentNode) {
42031
+ iframe.parentNode.removeChild(iframe);
42032
+ }
42033
+ iframe = null;
42034
+ };
42035
+ return { wallet: createCWI(transport), destroy, sendCustomMessage };
42036
+ }
42037
+ // src/connectWallet.ts
42038
+ var DEFAULT_ONESAT_URL = "https://1sat.market";
42039
+ var DEFAULT_SIGMA_URL = "https://auth.sigmaidentity.com";
42040
+ async function connectBrc100AutoDetect() {
42041
+ const client = new WalletClient("auto");
42042
+ await client.connectToSubstrate();
42043
+ await client.waitForAuthentication({});
42044
+ const { publicKey } = await client.getPublicKey({ identityKey: true });
42045
+ return {
42046
+ wallet: client,
42047
+ provider: "brc100",
42048
+ identityKey: publicKey,
42049
+ disconnect: () => {}
42050
+ };
42051
+ }
42052
+ function createProviderConnector(config) {
42053
+ switch (config.type) {
42054
+ case "onesat":
42055
+ return async () => {
42056
+ const webConfig = {};
42057
+ if (config.url)
42058
+ webConfig.walletUrl = config.url;
42059
+ const { wallet: wallet2, destroy } = createWebCWI(webConfig);
42060
+ await wallet2.waitForAuthentication({});
42061
+ const { publicKey } = await wallet2.getPublicKey({
42062
+ identityKey: true
42063
+ });
42064
+ return {
42065
+ wallet: wallet2,
42066
+ provider: "onesat",
42067
+ identityKey: publicKey,
42068
+ disconnect: destroy
42069
+ };
42070
+ };
42071
+ case "sigma":
42072
+ return async () => {
42073
+ const sigmaConfig = {
42074
+ sigmaUrl: config.url ?? DEFAULT_SIGMA_URL
42075
+ };
42076
+ const { wallet: wallet2, destroy } = createSigmaCWI(sigmaConfig);
42077
+ await wallet2.waitForAuthentication({});
42078
+ const { publicKey } = await wallet2.getPublicKey({
42079
+ identityKey: true
42080
+ });
42081
+ return {
42082
+ wallet: wallet2,
42083
+ provider: "sigma",
42084
+ identityKey: publicKey,
42085
+ disconnect: destroy
42086
+ };
42087
+ };
42088
+ default:
42089
+ return () => Promise.reject(new Error(`No built-in connector for provider type: ${config.type}`));
42090
+ }
42091
+ }
42092
+ function getAvailableProviders(config) {
42093
+ const providerConfigs = config?.providers ?? [
42094
+ { type: "onesat", name: "OneSat Wallet", url: DEFAULT_ONESAT_URL }
42095
+ ];
42096
+ return providerConfigs.map((p) => ({
42097
+ ...p,
42098
+ detected: false,
42099
+ connect: createProviderConnector(p)
42100
+ }));
42101
+ }
42102
+ async function connectWallet(config) {
42103
+ const autoDetect = config?.autoDetect ?? true;
42104
+ if (autoDetect) {
42105
+ try {
42106
+ return await connectBrc100AutoDetect();
42107
+ } catch {}
42108
+ }
42109
+ const providers = config?.providers ?? [
42110
+ { type: "onesat", name: "OneSat Wallet", url: DEFAULT_ONESAT_URL }
42111
+ ];
42112
+ for (const provider of providers) {
42113
+ try {
42114
+ return await createProviderConnector(provider)();
42115
+ } catch {}
42116
+ }
41790
42117
  return null;
41791
42118
  }
41792
42119
  // src/transport.ts
41793
42120
  var DEFAULT_WALLET_URL2 = "https://1sat.market";
41794
- var DEFAULT_IFRAME_PATH2 = "/wallet/cwi";
42121
+ var DEFAULT_IFRAME_PATH3 = "/wallet/cwi";
41795
42122
  var DEFAULT_AUTHORIZE_INIT_PATH = "/api/cwi/authorize/init";
41796
42123
  var DEFAULT_TOKEN_PATH = "/api/cwi/token";
41797
- var DEFAULT_REQUEST_TIMEOUT_MS2 = 120000;
42124
+ var DEFAULT_REQUEST_TIMEOUT_MS3 = 120000;
41798
42125
  var DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS = 1800;
41799
42126
  var DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS = 900;
41800
42127
  var DEFAULT_DESKTOP_MAX_RETRIES = 2;
41801
42128
  var DEFAULT_MOBILE_MAX_RETRIES = 1;
41802
42129
  var REDIRECT_PENDING_KEY = "onesat:cwi:redirect:pending";
41803
- var isRecord2 = (value) => typeof value === "object" && value !== null;
42130
+ var isRecord3 = (value) => typeof value === "object" && value !== null;
41804
42131
  var isLikelyMobileRuntime = () => {
41805
42132
  if (typeof navigator === "undefined")
41806
42133
  return false;
@@ -41813,7 +42140,7 @@ var isLikelyMobileRuntime = () => {
41813
42140
  const userAgent = navigator.userAgent ?? "";
41814
42141
  return /Android|iPhone|iPad|iPod|Mobile/i.test(userAgent);
41815
42142
  };
41816
- var createId2 = () => {
42143
+ var createId3 = () => {
41817
42144
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
41818
42145
  return crypto.randomUUID();
41819
42146
  }
@@ -41872,16 +42199,16 @@ var normalizeState = (state) => ({
41872
42199
  reason: normalizeReason(state.reason)
41873
42200
  });
41874
42201
  var isCWIStateMessage = (value) => {
41875
- if (!isRecord2(value))
42202
+ if (!isRecord3(value))
41876
42203
  return false;
41877
42204
  if (value.type !== "CWI")
41878
42205
  return false;
41879
- if (!isRecord2(value.cwiState))
42206
+ if (!isRecord3(value.cwiState))
41880
42207
  return false;
41881
42208
  return true;
41882
42209
  };
41883
42210
  var isCWIResponseMessage = (value) => {
41884
- if (!isRecord2(value))
42211
+ if (!isRecord3(value))
41885
42212
  return false;
41886
42213
  if (value.type !== "CWI")
41887
42214
  return false;
@@ -41893,7 +42220,7 @@ var isCWIResponseMessage = (value) => {
41893
42220
  };
41894
42221
  var toCWIError = (message) => new OneSatError(ErrorCodes.INTERNAL_ERROR, message.description ?? "Wallet request failed", { code: message.code });
41895
42222
  var extractErrorDescription = (value) => {
41896
- if (!isRecord2(value))
42223
+ if (!isRecord3(value))
41897
42224
  return;
41898
42225
  const description = value.error_description;
41899
42226
  if (typeof description === "string" && description.length > 0) {
@@ -41942,10 +42269,10 @@ class EmbedTransport {
41942
42269
  isDestroyed = false;
41943
42270
  constructor(config) {
41944
42271
  const walletUrl = config?.walletUrl ?? DEFAULT_WALLET_URL2;
41945
- const iframePath = config?.iframePath ?? DEFAULT_IFRAME_PATH2;
42272
+ const iframePath = config?.iframePath ?? DEFAULT_IFRAME_PATH3;
41946
42273
  this.walletOrigin = new URL(walletUrl).origin;
41947
42274
  this.iframeUrl = new URL(iframePath, walletUrl).toString();
41948
- this.requestTimeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS2;
42275
+ this.requestTimeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
41949
42276
  this.handshakeTimeoutMs = config?.handshakeTimeoutMs ?? (isLikelyMobileRuntime() ? DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS : DEFAULT_DESKTOP_HANDSHAKE_TIMEOUT_MS);
41950
42277
  if (typeof window !== "undefined") {
41951
42278
  window.addEventListener("message", this.handleMessage);
@@ -42091,7 +42418,7 @@ class EmbedTransport {
42091
42418
  if (!target) {
42092
42419
  throw new TransportUnavailableError("CWI iframe is not reachable");
42093
42420
  }
42094
- const requestId = createId2();
42421
+ const requestId = createId3();
42095
42422
  const request = {
42096
42423
  type: "CWI",
42097
42424
  isInvocation: true,
@@ -42171,7 +42498,7 @@ class RedirectTransport {
42171
42498
  const tokenPath = config?.tokenPath ?? DEFAULT_TOKEN_PATH;
42172
42499
  this.authorizeInitUrl = new URL(authorizeInitPath, walletUrl).toString();
42173
42500
  this.tokenUrl = new URL(tokenPath, walletUrl).toString();
42174
- this.timeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS2;
42501
+ this.timeoutMs = config?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
42175
42502
  if (config?.redirectUri) {
42176
42503
  this.redirectUri = config.redirectUri;
42177
42504
  } else if (typeof window !== "undefined") {
@@ -42250,7 +42577,7 @@ class RedirectTransport {
42250
42577
  credentials: "omit"
42251
42578
  }, this.timeoutMs, () => new AuthorizationTimeoutError("authorize/init timed out"));
42252
42579
  const payload = await response.json().catch(() => ({}));
42253
- if (!response.ok || !isRecord2(payload)) {
42580
+ if (!response.ok || !isRecord3(payload)) {
42254
42581
  const description = extractErrorDescription(payload) ?? "Failed to initialize redirect authorization";
42255
42582
  throw new OneSatError(ErrorCodes.INVALID_REQUEST, description, payload);
42256
42583
  }
@@ -42296,7 +42623,7 @@ class RedirectTransport {
42296
42623
  credentials: "omit"
42297
42624
  }, this.timeoutMs, () => new AuthorizationTimeoutError("token exchange timed out"));
42298
42625
  const payload = await response.json().catch(() => ({}));
42299
- if (!response.ok || !isRecord2(payload)) {
42626
+ if (!response.ok || !isRecord3(payload)) {
42300
42627
  const description = extractErrorDescription(payload) ?? "Authorization code exchange failed";
42301
42628
  if (/already_consumed|replay|consumed/i.test(description)) {
42302
42629
  throw new CodeReplayError(description);
@@ -42406,7 +42733,7 @@ class AutoTransport {
42406
42733
  toFallbackReason(error) {
42407
42734
  if (error instanceof FallbackRequiredError) {
42408
42735
  const data = error.data;
42409
- if (isRecord2(data)) {
42736
+ if (isRecord3(data)) {
42410
42737
  const reason = normalizeReason(data.reason);
42411
42738
  if (reason) {
42412
42739
  return reason;
@@ -42611,6 +42938,7 @@ export {
42611
42938
  getPopupContext,
42612
42939
  getOneSat,
42613
42940
  getInjectedOneSat,
42941
+ getAvailableProviders,
42614
42942
  fromErrorResponse,
42615
42943
  createResponse,
42616
42944
  createRequest,