@omnisat/lasereyes 0.0.56 → 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
@@ -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);
@@ -1543,81 +1543,86 @@ var LaserEyesProvider = ({
1543
1543
  throw error;
1544
1544
  }
1545
1545
  });
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");
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;
1564
1562
  } else {
1565
- 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
+ }
1566
1570
  }
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
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
1581
1588
  },
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");
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");
1591
1603
  }
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");
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..");
1600
1619
  }
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..");
1620
+ } catch (error) {
1621
+ throw error;
1616
1622
  }
1617
- } catch (error) {
1618
- throw error;
1619
- }
1620
- });
1623
+ }),
1624
+ [library, address2, paymentAddress]
1625
+ );
1621
1626
  const signPsbt = (psbt, finalize = false, broadcast = false) => __async(void 0, null, function* () {
1622
1627
  try {
1623
1628
  let psbtHex, psbtBase64;
package/dist/index.mjs CHANGED
@@ -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);
@@ -1448,81 +1448,86 @@ var LaserEyesProvider = ({
1448
1448
  throw error;
1449
1449
  }
1450
1450
  });
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");
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;
1469
1467
  } else {
1470
- 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
+ }
1471
1475
  }
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
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
1486
1493
  },
1487
- address: tempAddy,
1488
- message,
1489
- protocol: MessageSigningProtocols.BIP322
1490
- },
1491
- onFinish: (response) => {
1492
- signedMessage = response;
1493
- },
1494
- onCancel: () => {
1495
- 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");
1496
1508
  }
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");
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..");
1505
1524
  }
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..");
1525
+ } catch (error) {
1526
+ throw error;
1521
1527
  }
1522
- } catch (error) {
1523
- throw error;
1524
- }
1525
- });
1528
+ }),
1529
+ [library, address2, paymentAddress]
1530
+ );
1526
1531
  const signPsbt = (psbt, finalize = false, broadcast = false) => __async(void 0, null, function* () {
1527
1532
  try {
1528
1533
  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.57",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",