@omnisat/lasereyes 0.0.55 → 0.0.57

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
@@ -791,20 +791,6 @@ var LaserEyesProvider = ({
791
791
  (0, import_react.useEffect)(() => {
792
792
  setBalance(void 0);
793
793
  }, [network]);
794
- (0, import_react.useEffect)(() => {
795
- if (provider !== UNISAT && provider !== WIZZ && !library) {
796
- return;
797
- }
798
- library.getAccounts().then((accounts2) => {
799
- handleAccountsChanged(accounts2);
800
- });
801
- library.on("accountsChanged", handleAccountsChanged);
802
- library.on("networkChanged", handleNetworkChanged);
803
- return () => {
804
- library.removeListener("accountsChanged", handleAccountsChanged);
805
- library.removeListener("networkChanged", handleNetworkChanged);
806
- };
807
- }, [library]);
808
794
  (0, import_react.useEffect)(() => {
809
795
  if (!isInitializing) {
810
796
  const defaultWallet = localStorage == null ? void 0 : localStorage.getItem(
@@ -820,6 +806,7 @@ var LaserEyesProvider = ({
820
806
  try {
821
807
  localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, UNISAT);
822
808
  const lib = window.unisat;
809
+ setLibrary(lib);
823
810
  const unisatAccounts = yield lib.requestAccounts();
824
811
  if (!unisatAccounts)
825
812
  throw new Error("No accounts found");
@@ -831,7 +818,6 @@ var LaserEyesProvider = ({
831
818
  setPaymentAddress(unisatAccounts[0]);
832
819
  setPublicKey(unisatPubKey);
833
820
  setPaymentPublicKey(unisatPubKey);
834
- setLibrary(lib);
835
821
  yield getNetwork().then((network2) => {
836
822
  if (config.network !== network2) {
837
823
  switchNetwork(network2);
@@ -1557,81 +1543,86 @@ var LaserEyesProvider = ({
1557
1543
  throw error;
1558
1544
  }
1559
1545
  });
1560
- const signMessage = (message, toSignAddress) => __async(void 0, null, function* () {
1561
- var _a;
1562
- try {
1563
- if (!library)
1564
- return;
1565
- if (provider === UNISAT) {
1566
- return yield library == null ? void 0 : library.signMessage(message);
1567
- } else if (provider === XVERSE) {
1568
- const tempAddy = toSignAddress || paymentAddress;
1569
- const response = yield (0, import_sats_connect.request)("signMessage", {
1570
- address: tempAddy,
1571
- message
1572
- });
1573
- if (response.status === "success") {
1574
- return response.result.signature;
1575
- } else {
1576
- if (response.error.code === import_sats_connect.RpcErrorCode.USER_REJECTION) {
1577
- throw new Error("User rejected the request");
1546
+ const signMessage = (0, import_react.useCallback)(
1547
+ (message, toSignAddress) => __async(void 0, null, function* () {
1548
+ var _a;
1549
+ try {
1550
+ if (!library)
1551
+ return;
1552
+ if (provider === UNISAT) {
1553
+ return yield library == null ? void 0 : library.signMessage(message);
1554
+ } else if (provider === XVERSE) {
1555
+ const tempAddy = toSignAddress || paymentAddress;
1556
+ const response = yield (0, import_sats_connect.request)("signMessage", {
1557
+ address: tempAddy,
1558
+ message
1559
+ });
1560
+ if (response.status === "success") {
1561
+ return response.result.signature;
1578
1562
  } else {
1579
- throw new Error("Error signing message: " + response.error.message);
1563
+ if (response.error.code === import_sats_connect.RpcErrorCode.USER_REJECTION) {
1564
+ throw new Error("User rejected the request");
1565
+ } else {
1566
+ throw new Error(
1567
+ "Error signing message: " + response.error.message
1568
+ );
1569
+ }
1580
1570
  }
1581
- }
1582
- } else if (provider === OYL) {
1583
- const tempAddy = toSignAddress || paymentAddress;
1584
- return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1585
- } else if (provider === MAGIC_EDEN) {
1586
- const tempAddy = toSignAddress || paymentAddress;
1587
- let signedMessage;
1588
- yield (0, import_sats_connect.signMessage)({
1589
- getProvider: () => __async(void 0, null, function* () {
1590
- return window.magicEden.bitcoin;
1591
- }),
1592
- payload: {
1593
- network: {
1594
- type: import_sats_connect.BitcoinNetworkType.Mainnet
1571
+ } else if (provider === OYL) {
1572
+ const tempAddy = toSignAddress || paymentAddress;
1573
+ return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1574
+ } else if (provider === MAGIC_EDEN) {
1575
+ const tempAddy = toSignAddress || paymentAddress;
1576
+ let signedMessage;
1577
+ yield (0, import_sats_connect.signMessage)({
1578
+ getProvider: () => __async(void 0, null, function* () {
1579
+ return window.magicEden.bitcoin;
1580
+ }),
1581
+ payload: {
1582
+ network: {
1583
+ type: import_sats_connect.BitcoinNetworkType.Mainnet
1584
+ },
1585
+ address: tempAddy,
1586
+ message,
1587
+ protocol: import_sats_connect.MessageSigningProtocols.BIP322
1595
1588
  },
1596
- address: tempAddy,
1597
- message,
1598
- protocol: import_sats_connect.MessageSigningProtocols.BIP322
1599
- },
1600
- onFinish: (response) => {
1601
- signedMessage = response;
1602
- },
1603
- onCancel: () => {
1604
- alert("Request canceled");
1589
+ onFinish: (response) => {
1590
+ signedMessage = response;
1591
+ },
1592
+ onCancel: () => {
1593
+ alert("Request canceled");
1594
+ }
1595
+ });
1596
+ return signedMessage;
1597
+ } else if (provider === OKX) {
1598
+ return yield library == null ? void 0 : library.signMessage(message);
1599
+ } else if (provider === LEATHER) {
1600
+ const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1601
+ if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1602
+ throw new Error("Invalid address to sign message");
1605
1603
  }
1606
- });
1607
- return signedMessage;
1608
- } else if (provider === OKX) {
1609
- return yield library == null ? void 0 : library.signMessage(message);
1610
- } else if (provider === LEATHER) {
1611
- const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1612
- if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1613
- throw new Error("Invalid address to sign message");
1604
+ const signed = yield library == null ? void 0 : library.request("signMessage", {
1605
+ message,
1606
+ paymentType
1607
+ });
1608
+ return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1609
+ } else if (provider === PHANTOM) {
1610
+ const utf8Bytes = new TextEncoder().encode(message);
1611
+ const uintArray = new Uint8Array(utf8Bytes);
1612
+ const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1613
+ const binaryString = String.fromCharCode(...response.signature);
1614
+ return btoa(binaryString);
1615
+ } else if (provider === WIZZ) {
1616
+ return yield library == null ? void 0 : library.signMessage(message);
1617
+ } else {
1618
+ throw new Error("The connected wallet doesn't support this method..");
1614
1619
  }
1615
- const signed = yield library == null ? void 0 : library.request("signMessage", {
1616
- message,
1617
- paymentType
1618
- });
1619
- return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1620
- } else if (provider === PHANTOM) {
1621
- const utf8Bytes = new TextEncoder().encode(message);
1622
- const uintArray = new Uint8Array(utf8Bytes);
1623
- const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1624
- const binaryString = String.fromCharCode(...response.signature);
1625
- return btoa(binaryString);
1626
- } else if (provider === WIZZ) {
1627
- return yield library == null ? void 0 : library.signMessage(message);
1628
- } else {
1629
- throw new Error("The connected wallet doesn't support this method..");
1620
+ } catch (error) {
1621
+ throw error;
1630
1622
  }
1631
- } catch (error) {
1632
- throw error;
1633
- }
1634
- });
1623
+ }),
1624
+ [library, address2, paymentAddress]
1625
+ );
1635
1626
  const signPsbt = (psbt, finalize = false, broadcast = false) => __async(void 0, null, function* () {
1636
1627
  try {
1637
1628
  let psbtHex, psbtBase64;
package/dist/index.mjs CHANGED
@@ -696,20 +696,6 @@ var LaserEyesProvider = ({
696
696
  useEffect(() => {
697
697
  setBalance(void 0);
698
698
  }, [network]);
699
- useEffect(() => {
700
- if (provider !== UNISAT && provider !== WIZZ && !library) {
701
- return;
702
- }
703
- library.getAccounts().then((accounts2) => {
704
- handleAccountsChanged(accounts2);
705
- });
706
- library.on("accountsChanged", handleAccountsChanged);
707
- library.on("networkChanged", handleNetworkChanged);
708
- return () => {
709
- library.removeListener("accountsChanged", handleAccountsChanged);
710
- library.removeListener("networkChanged", handleNetworkChanged);
711
- };
712
- }, [library]);
713
699
  useEffect(() => {
714
700
  if (!isInitializing) {
715
701
  const defaultWallet = localStorage == null ? void 0 : localStorage.getItem(
@@ -725,6 +711,7 @@ var LaserEyesProvider = ({
725
711
  try {
726
712
  localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, UNISAT);
727
713
  const lib = window.unisat;
714
+ setLibrary(lib);
728
715
  const unisatAccounts = yield lib.requestAccounts();
729
716
  if (!unisatAccounts)
730
717
  throw new Error("No accounts found");
@@ -736,7 +723,6 @@ var LaserEyesProvider = ({
736
723
  setPaymentAddress(unisatAccounts[0]);
737
724
  setPublicKey(unisatPubKey);
738
725
  setPaymentPublicKey(unisatPubKey);
739
- setLibrary(lib);
740
726
  yield getNetwork().then((network2) => {
741
727
  if (config.network !== network2) {
742
728
  switchNetwork(network2);
@@ -1462,81 +1448,86 @@ var LaserEyesProvider = ({
1462
1448
  throw error;
1463
1449
  }
1464
1450
  });
1465
- const signMessage = (message, toSignAddress) => __async(void 0, null, function* () {
1466
- var _a;
1467
- try {
1468
- if (!library)
1469
- return;
1470
- if (provider === UNISAT) {
1471
- return yield library == null ? void 0 : library.signMessage(message);
1472
- } else if (provider === XVERSE) {
1473
- const tempAddy = toSignAddress || paymentAddress;
1474
- const response = yield request("signMessage", {
1475
- address: tempAddy,
1476
- message
1477
- });
1478
- if (response.status === "success") {
1479
- return response.result.signature;
1480
- } else {
1481
- if (response.error.code === RpcErrorCode.USER_REJECTION) {
1482
- throw new Error("User rejected the request");
1451
+ const signMessage = useCallback(
1452
+ (message, toSignAddress) => __async(void 0, null, function* () {
1453
+ var _a;
1454
+ try {
1455
+ if (!library)
1456
+ return;
1457
+ if (provider === UNISAT) {
1458
+ return yield library == null ? void 0 : library.signMessage(message);
1459
+ } else if (provider === XVERSE) {
1460
+ const tempAddy = toSignAddress || paymentAddress;
1461
+ const response = yield request("signMessage", {
1462
+ address: tempAddy,
1463
+ message
1464
+ });
1465
+ if (response.status === "success") {
1466
+ return response.result.signature;
1483
1467
  } else {
1484
- throw new Error("Error signing message: " + response.error.message);
1468
+ if (response.error.code === RpcErrorCode.USER_REJECTION) {
1469
+ throw new Error("User rejected the request");
1470
+ } else {
1471
+ throw new Error(
1472
+ "Error signing message: " + response.error.message
1473
+ );
1474
+ }
1485
1475
  }
1486
- }
1487
- } else if (provider === OYL) {
1488
- const tempAddy = toSignAddress || paymentAddress;
1489
- return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1490
- } else if (provider === MAGIC_EDEN) {
1491
- const tempAddy = toSignAddress || paymentAddress;
1492
- let signedMessage;
1493
- yield signMessageSatsConnect({
1494
- getProvider: () => __async(void 0, null, function* () {
1495
- return window.magicEden.bitcoin;
1496
- }),
1497
- payload: {
1498
- network: {
1499
- type: BitcoinNetworkType.Mainnet
1476
+ } else if (provider === OYL) {
1477
+ const tempAddy = toSignAddress || paymentAddress;
1478
+ return yield library == null ? void 0 : library.signMessage(message, "bip322", tempAddy);
1479
+ } else if (provider === MAGIC_EDEN) {
1480
+ const tempAddy = toSignAddress || paymentAddress;
1481
+ let signedMessage;
1482
+ yield signMessageSatsConnect({
1483
+ getProvider: () => __async(void 0, null, function* () {
1484
+ return window.magicEden.bitcoin;
1485
+ }),
1486
+ payload: {
1487
+ network: {
1488
+ type: BitcoinNetworkType.Mainnet
1489
+ },
1490
+ address: tempAddy,
1491
+ message,
1492
+ protocol: MessageSigningProtocols.BIP322
1500
1493
  },
1501
- address: tempAddy,
1502
- message,
1503
- protocol: MessageSigningProtocols.BIP322
1504
- },
1505
- onFinish: (response) => {
1506
- signedMessage = response;
1507
- },
1508
- onCancel: () => {
1509
- alert("Request canceled");
1494
+ onFinish: (response) => {
1495
+ signedMessage = response;
1496
+ },
1497
+ onCancel: () => {
1498
+ alert("Request canceled");
1499
+ }
1500
+ });
1501
+ return signedMessage;
1502
+ } else if (provider === OKX) {
1503
+ return yield library == null ? void 0 : library.signMessage(message);
1504
+ } else if (provider === LEATHER) {
1505
+ const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1506
+ if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1507
+ throw new Error("Invalid address to sign message");
1510
1508
  }
1511
- });
1512
- return signedMessage;
1513
- } else if (provider === OKX) {
1514
- return yield library == null ? void 0 : library.signMessage(message);
1515
- } else if (provider === LEATHER) {
1516
- const paymentType = toSignAddress === address2 ? P2TR : P2WPKH;
1517
- if (toSignAddress !== address2 && toSignAddress !== paymentAddress) {
1518
- throw new Error("Invalid address to sign message");
1509
+ const signed = yield library == null ? void 0 : library.request("signMessage", {
1510
+ message,
1511
+ paymentType
1512
+ });
1513
+ return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1514
+ } else if (provider === PHANTOM) {
1515
+ const utf8Bytes = new TextEncoder().encode(message);
1516
+ const uintArray = new Uint8Array(utf8Bytes);
1517
+ const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1518
+ const binaryString = String.fromCharCode(...response.signature);
1519
+ return btoa(binaryString);
1520
+ } else if (provider === WIZZ) {
1521
+ return yield library == null ? void 0 : library.signMessage(message);
1522
+ } else {
1523
+ throw new Error("The connected wallet doesn't support this method..");
1519
1524
  }
1520
- const signed = yield library == null ? void 0 : library.request("signMessage", {
1521
- message,
1522
- paymentType
1523
- });
1524
- return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
1525
- } else if (provider === PHANTOM) {
1526
- const utf8Bytes = new TextEncoder().encode(message);
1527
- const uintArray = new Uint8Array(utf8Bytes);
1528
- const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
1529
- const binaryString = String.fromCharCode(...response.signature);
1530
- return btoa(binaryString);
1531
- } else if (provider === WIZZ) {
1532
- return yield library == null ? void 0 : library.signMessage(message);
1533
- } else {
1534
- throw new Error("The connected wallet doesn't support this method..");
1525
+ } catch (error) {
1526
+ throw error;
1535
1527
  }
1536
- } catch (error) {
1537
- throw error;
1538
- }
1539
- });
1528
+ }),
1529
+ [library, address2, paymentAddress]
1530
+ );
1540
1531
  const signPsbt = (psbt, finalize = false, broadcast = false) => __async(void 0, null, function* () {
1541
1532
  try {
1542
1533
  let psbtHex, psbtBase64;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnisat/lasereyes",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",