@omnisat/lasereyes 0.0.56 → 0.0.58

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
@@ -643,7 +643,7 @@ var LaserEyesProvider = ({
643
643
  const [hasWizz, setHasWizz] = (0, import_react.useState)(false);
644
644
  const [network, setNetwork] = (0, import_usehooks_ts.useLocalStorage)("network", (config == null ? void 0 : config.network) || MAINNET);
645
645
  (0, import_react.useEffect)(() => {
646
- if (config && config.network) {
646
+ if (config && config.network && library) {
647
647
  setNetwork(config.network);
648
648
  getNetwork().then((foundNetwork) => {
649
649
  try {
@@ -655,7 +655,7 @@ var LaserEyesProvider = ({
655
655
  }
656
656
  });
657
657
  }
658
- }, [config]);
658
+ }, [config, library]);
659
659
  const checkInitializationComplete = () => {
660
660
  if (hasUnisat !== void 0 && hasXverse !== void 0 && hasOyl !== void 0 && hasMagicEden !== void 0 && hasOkx !== void 0 && hasLeather !== void 0 && hasPhantom !== void 0 && hasWizz !== void 0) {
661
661
  setIsInitializing(false);
@@ -806,6 +806,7 @@ var LaserEyesProvider = ({
806
806
  try {
807
807
  localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, UNISAT);
808
808
  const lib = window.unisat;
809
+ setLibrary(lib);
809
810
  const unisatAccounts = yield lib.requestAccounts();
810
811
  if (!unisatAccounts)
811
812
  throw new Error("No accounts found");
@@ -817,7 +818,6 @@ var LaserEyesProvider = ({
817
818
  setPaymentAddress(unisatAccounts[0]);
818
819
  setPublicKey(unisatPubKey);
819
820
  setPaymentPublicKey(unisatPubKey);
820
- setLibrary(lib);
821
821
  yield getNetwork().then((network2) => {
822
822
  if (config.network !== network2) {
823
823
  switchNetwork(network2);
@@ -1255,7 +1255,8 @@ var LaserEyesProvider = ({
1255
1255
  var _a, _b;
1256
1256
  try {
1257
1257
  if (provider === UNISAT) {
1258
- const unisatNetwork = yield library == null ? void 0 : library.getChain();
1258
+ const lib = window.unisat;
1259
+ const unisatNetwork = yield lib == null ? void 0 : lib.getChain();
1259
1260
  if (!unisatNetwork) {
1260
1261
  return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
1261
1262
  }
@@ -1331,9 +1332,10 @@ var LaserEyesProvider = ({
1331
1332
  if (!library)
1332
1333
  return;
1333
1334
  if (provider === UNISAT) {
1335
+ const lib = window.unisat;
1334
1336
  const wantedNetwork = getUnisatNetwork(network2);
1335
1337
  console.log("wantedNetwork", wantedNetwork);
1336
- yield library == null ? void 0 : library.switchChain(wantedNetwork);
1338
+ yield lib == null ? void 0 : lib.switchChain(wantedNetwork);
1337
1339
  setNetwork(network2);
1338
1340
  yield getBalance();
1339
1341
  } else if (provider === WIZZ) {
@@ -1543,81 +1545,86 @@ var LaserEyesProvider = ({
1543
1545
  throw error;
1544
1546
  }
1545
1547
  });
1546
- const signMessage = (message, toSignAddress) => __async(void 0, null, function* () {
1547
- var _a;
1548
- try {
1549
- if (!library)
1550
- return;
1551
- if (provider === UNISAT) {
1552
- return yield library == null ? void 0 : library.signMessage(message);
1553
- } else if (provider === XVERSE) {
1554
- const tempAddy = toSignAddress || paymentAddress;
1555
- const response = yield (0, import_sats_connect.request)("signMessage", {
1556
- address: tempAddy,
1557
- message
1558
- });
1559
- if (response.status === "success") {
1560
- return response.result.signature;
1561
- } else {
1562
- if (response.error.code === import_sats_connect.RpcErrorCode.USER_REJECTION) {
1563
- throw new Error("User rejected the request");
1548
+ const signMessage = (0, import_react.useCallback)(
1549
+ (message, toSignAddress) => __async(void 0, null, function* () {
1550
+ var _a;
1551
+ try {
1552
+ if (!library)
1553
+ return;
1554
+ if (provider === UNISAT) {
1555
+ return yield library == null ? void 0 : library.signMessage(message);
1556
+ } else if (provider === XVERSE) {
1557
+ const tempAddy = toSignAddress || paymentAddress;
1558
+ const response = yield (0, import_sats_connect.request)("signMessage", {
1559
+ address: tempAddy,
1560
+ message
1561
+ });
1562
+ if (response.status === "success") {
1563
+ return response.result.signature;
1564
1564
  } else {
1565
- throw new Error("Error signing message: " + response.error.message);
1565
+ if (response.error.code === import_sats_connect.RpcErrorCode.USER_REJECTION) {
1566
+ throw new Error("User rejected the request");
1567
+ } else {
1568
+ throw new Error(
1569
+ "Error signing message: " + response.error.message
1570
+ );
1571
+ }
1566
1572
  }
1567
- }
1568
- } else if (provider === OYL) {
1569
- const tempAddy = toSignAddress || paymentAddress;
1570
- return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1571
- } else if (provider === MAGIC_EDEN) {
1572
- const tempAddy = toSignAddress || paymentAddress;
1573
- let signedMessage;
1574
- yield (0, import_sats_connect.signMessage)({
1575
- getProvider: () => __async(void 0, null, function* () {
1576
- return window.magicEden.bitcoin;
1577
- }),
1578
- payload: {
1579
- network: {
1580
- type: import_sats_connect.BitcoinNetworkType.Mainnet
1573
+ } else if (provider === OYL) {
1574
+ const tempAddy = toSignAddress || paymentAddress;
1575
+ return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1576
+ } else if (provider === MAGIC_EDEN) {
1577
+ const tempAddy = toSignAddress || paymentAddress;
1578
+ let signedMessage;
1579
+ yield (0, import_sats_connect.signMessage)({
1580
+ getProvider: () => __async(void 0, null, function* () {
1581
+ return window.magicEden.bitcoin;
1582
+ }),
1583
+ payload: {
1584
+ network: {
1585
+ type: import_sats_connect.BitcoinNetworkType.Mainnet
1586
+ },
1587
+ address: tempAddy,
1588
+ message,
1589
+ protocol: import_sats_connect.MessageSigningProtocols.BIP322
1581
1590
  },
1582
- address: tempAddy,
1583
- message,
1584
- protocol: import_sats_connect.MessageSigningProtocols.BIP322
1585
- },
1586
- onFinish: (response) => {
1587
- signedMessage = response;
1588
- },
1589
- onCancel: () => {
1590
- alert("Request canceled");
1591
+ onFinish: (response) => {
1592
+ signedMessage = response;
1593
+ },
1594
+ onCancel: () => {
1595
+ alert("Request canceled");
1596
+ }
1597
+ });
1598
+ return signedMessage;
1599
+ } else if (provider === OKX) {
1600
+ return yield library == null ? void 0 : library.signMessage(message);
1601
+ } else if (provider === LEATHER) {
1602
+ const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1603
+ if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1604
+ throw new Error("Invalid address to sign message");
1591
1605
  }
1592
- });
1593
- return signedMessage;
1594
- } else if (provider === OKX) {
1595
- return yield library == null ? void 0 : library.signMessage(message);
1596
- } else if (provider === LEATHER) {
1597
- const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1598
- if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1599
- throw new Error("Invalid address to sign message");
1606
+ const signed = yield library == null ? void 0 : library.request("signMessage", {
1607
+ message,
1608
+ paymentType
1609
+ });
1610
+ return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1611
+ } else if (provider === PHANTOM) {
1612
+ const utf8Bytes = new TextEncoder().encode(message);
1613
+ const uintArray = new Uint8Array(utf8Bytes);
1614
+ const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1615
+ const binaryString = String.fromCharCode(...response.signature);
1616
+ return btoa(binaryString);
1617
+ } else if (provider === WIZZ) {
1618
+ return yield library == null ? void 0 : library.signMessage(message);
1619
+ } else {
1620
+ throw new Error("The connected wallet doesn't support this method..");
1600
1621
  }
1601
- const signed = yield library == null ? void 0 : library.request("signMessage", {
1602
- message,
1603
- paymentType
1604
- });
1605
- return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1606
- } else if (provider === PHANTOM) {
1607
- const utf8Bytes = new TextEncoder().encode(message);
1608
- const uintArray = new Uint8Array(utf8Bytes);
1609
- const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1610
- const binaryString = String.fromCharCode(...response.signature);
1611
- return btoa(binaryString);
1612
- } else if (provider === WIZZ) {
1613
- return yield library == null ? void 0 : library.signMessage(message);
1614
- } else {
1615
- throw new Error("The connected wallet doesn't support this method..");
1622
+ } catch (error) {
1623
+ throw error;
1616
1624
  }
1617
- } catch (error) {
1618
- throw error;
1619
- }
1620
- });
1625
+ }),
1626
+ [library, address2, paymentAddress]
1627
+ );
1621
1628
  const signPsbt = (psbt, finalize = false, broadcast = false) => __async(void 0, null, function* () {
1622
1629
  try {
1623
1630
  let psbtHex, psbtBase64;
package/dist/index.mjs CHANGED
@@ -548,7 +548,7 @@ var LaserEyesProvider = ({
548
548
  const [hasWizz, setHasWizz] = useState(false);
549
549
  const [network, setNetwork] = useLocalStorage("network", (config == null ? void 0 : config.network) || MAINNET);
550
550
  useEffect(() => {
551
- if (config && config.network) {
551
+ if (config && config.network && library) {
552
552
  setNetwork(config.network);
553
553
  getNetwork().then((foundNetwork) => {
554
554
  try {
@@ -560,7 +560,7 @@ var LaserEyesProvider = ({
560
560
  }
561
561
  });
562
562
  }
563
- }, [config]);
563
+ }, [config, library]);
564
564
  const checkInitializationComplete = () => {
565
565
  if (hasUnisat !== void 0 && hasXverse !== void 0 && hasOyl !== void 0 && hasMagicEden !== void 0 && hasOkx !== void 0 && hasLeather !== void 0 && hasPhantom !== void 0 && hasWizz !== void 0) {
566
566
  setIsInitializing(false);
@@ -711,6 +711,7 @@ var LaserEyesProvider = ({
711
711
  try {
712
712
  localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, UNISAT);
713
713
  const lib = window.unisat;
714
+ setLibrary(lib);
714
715
  const unisatAccounts = yield lib.requestAccounts();
715
716
  if (!unisatAccounts)
716
717
  throw new Error("No accounts found");
@@ -722,7 +723,6 @@ var LaserEyesProvider = ({
722
723
  setPaymentAddress(unisatAccounts[0]);
723
724
  setPublicKey(unisatPubKey);
724
725
  setPaymentPublicKey(unisatPubKey);
725
- setLibrary(lib);
726
726
  yield getNetwork().then((network2) => {
727
727
  if (config.network !== network2) {
728
728
  switchNetwork(network2);
@@ -1160,7 +1160,8 @@ var LaserEyesProvider = ({
1160
1160
  var _a, _b;
1161
1161
  try {
1162
1162
  if (provider === UNISAT) {
1163
- const unisatNetwork = yield library == null ? void 0 : library.getChain();
1163
+ const lib = window.unisat;
1164
+ const unisatNetwork = yield lib == null ? void 0 : lib.getChain();
1164
1165
  if (!unisatNetwork) {
1165
1166
  return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
1166
1167
  }
@@ -1236,9 +1237,10 @@ var LaserEyesProvider = ({
1236
1237
  if (!library)
1237
1238
  return;
1238
1239
  if (provider === UNISAT) {
1240
+ const lib = window.unisat;
1239
1241
  const wantedNetwork = getUnisatNetwork(network2);
1240
1242
  console.log("wantedNetwork", wantedNetwork);
1241
- yield library == null ? void 0 : library.switchChain(wantedNetwork);
1243
+ yield lib == null ? void 0 : lib.switchChain(wantedNetwork);
1242
1244
  setNetwork(network2);
1243
1245
  yield getBalance();
1244
1246
  } else if (provider === WIZZ) {
@@ -1448,81 +1450,86 @@ var LaserEyesProvider = ({
1448
1450
  throw error;
1449
1451
  }
1450
1452
  });
1451
- const signMessage = (message, toSignAddress) => __async(void 0, null, function* () {
1452
- var _a;
1453
- try {
1454
- if (!library)
1455
- return;
1456
- if (provider === UNISAT) {
1457
- return yield library == null ? void 0 : library.signMessage(message);
1458
- } else if (provider === XVERSE) {
1459
- const tempAddy = toSignAddress || paymentAddress;
1460
- const response = yield request("signMessage", {
1461
- address: tempAddy,
1462
- message
1463
- });
1464
- if (response.status === "success") {
1465
- return response.result.signature;
1466
- } else {
1467
- if (response.error.code === RpcErrorCode.USER_REJECTION) {
1468
- throw new Error("User rejected the request");
1453
+ const signMessage = useCallback(
1454
+ (message, toSignAddress) => __async(void 0, null, function* () {
1455
+ var _a;
1456
+ try {
1457
+ if (!library)
1458
+ return;
1459
+ if (provider === UNISAT) {
1460
+ return yield library == null ? void 0 : library.signMessage(message);
1461
+ } else if (provider === XVERSE) {
1462
+ const tempAddy = toSignAddress || paymentAddress;
1463
+ const response = yield request("signMessage", {
1464
+ address: tempAddy,
1465
+ message
1466
+ });
1467
+ if (response.status === "success") {
1468
+ return response.result.signature;
1469
1469
  } else {
1470
- throw new Error("Error signing message: " + response.error.message);
1470
+ if (response.error.code === RpcErrorCode.USER_REJECTION) {
1471
+ throw new Error("User rejected the request");
1472
+ } else {
1473
+ throw new Error(
1474
+ "Error signing message: " + response.error.message
1475
+ );
1476
+ }
1471
1477
  }
1472
- }
1473
- } else if (provider === OYL) {
1474
- const tempAddy = toSignAddress || paymentAddress;
1475
- return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1476
- } else if (provider === MAGIC_EDEN) {
1477
- const tempAddy = toSignAddress || paymentAddress;
1478
- let signedMessage;
1479
- yield signMessageSatsConnect({
1480
- getProvider: () => __async(void 0, null, function* () {
1481
- return window.magicEden.bitcoin;
1482
- }),
1483
- payload: {
1484
- network: {
1485
- type: BitcoinNetworkType.Mainnet
1478
+ } else if (provider === OYL) {
1479
+ const tempAddy = toSignAddress || paymentAddress;
1480
+ return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1481
+ } else if (provider === MAGIC_EDEN) {
1482
+ const tempAddy = toSignAddress || paymentAddress;
1483
+ let signedMessage;
1484
+ yield signMessageSatsConnect({
1485
+ getProvider: () => __async(void 0, null, function* () {
1486
+ return window.magicEden.bitcoin;
1487
+ }),
1488
+ payload: {
1489
+ network: {
1490
+ type: BitcoinNetworkType.Mainnet
1491
+ },
1492
+ address: tempAddy,
1493
+ message,
1494
+ protocol: MessageSigningProtocols.BIP322
1486
1495
  },
1487
- address: tempAddy,
1488
- message,
1489
- protocol: MessageSigningProtocols.BIP322
1490
- },
1491
- onFinish: (response) => {
1492
- signedMessage = response;
1493
- },
1494
- onCancel: () => {
1495
- alert("Request canceled");
1496
+ onFinish: (response) => {
1497
+ signedMessage = response;
1498
+ },
1499
+ onCancel: () => {
1500
+ alert("Request canceled");
1501
+ }
1502
+ });
1503
+ return signedMessage;
1504
+ } else if (provider === OKX) {
1505
+ return yield library == null ? void 0 : library.signMessage(message);
1506
+ } else if (provider === LEATHER) {
1507
+ const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1508
+ if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1509
+ throw new Error("Invalid address to sign message");
1496
1510
  }
1497
- });
1498
- return signedMessage;
1499
- } else if (provider === OKX) {
1500
- return yield library == null ? void 0 : library.signMessage(message);
1501
- } else if (provider === LEATHER) {
1502
- const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1503
- if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1504
- throw new Error("Invalid address to sign message");
1511
+ const signed = yield library == null ? void 0 : library.request("signMessage", {
1512
+ message,
1513
+ paymentType
1514
+ });
1515
+ return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1516
+ } else if (provider === PHANTOM) {
1517
+ const utf8Bytes = new TextEncoder().encode(message);
1518
+ const uintArray = new Uint8Array(utf8Bytes);
1519
+ const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1520
+ const binaryString = String.fromCharCode(...response.signature);
1521
+ return btoa(binaryString);
1522
+ } else if (provider === WIZZ) {
1523
+ return yield library == null ? void 0 : library.signMessage(message);
1524
+ } else {
1525
+ throw new Error("The connected wallet doesn't support this method..");
1505
1526
  }
1506
- const signed = yield library == null ? void 0 : library.request("signMessage", {
1507
- message,
1508
- paymentType
1509
- });
1510
- return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1511
- } else if (provider === PHANTOM) {
1512
- const utf8Bytes = new TextEncoder().encode(message);
1513
- const uintArray = new Uint8Array(utf8Bytes);
1514
- const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1515
- const binaryString = String.fromCharCode(...response.signature);
1516
- return btoa(binaryString);
1517
- } else if (provider === WIZZ) {
1518
- return yield library == null ? void 0 : library.signMessage(message);
1519
- } else {
1520
- throw new Error("The connected wallet doesn't support this method..");
1527
+ } catch (error) {
1528
+ throw error;
1521
1529
  }
1522
- } catch (error) {
1523
- throw error;
1524
- }
1525
- });
1530
+ }),
1531
+ [library, address2, paymentAddress]
1532
+ );
1526
1533
  const signPsbt = (psbt, finalize = false, broadcast = false) => __async(void 0, null, function* () {
1527
1534
  try {
1528
1535
  let psbtHex, psbtBase64;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnisat/lasereyes",
3
- "version": "0.0.56",
3
+ "version": "0.0.58",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",