btc-wallet 0.5.6-beta → 0.5.7-beta

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -651,16 +651,15 @@ var XverseConnector = class extends BaseConnector {
651
651
  this.loadAccounts = (network) => __async(this, null, function* () {
652
652
  const { AddressPurpose } = yield import("sats-connect");
653
653
  const provider = this.getProvider();
654
- if (!provider) {
655
- throw new Error(`${this.metadata.name} is not install!`);
656
- }
657
654
  yield provider.request("wallet_requestPermissions", void 0);
658
655
  const { result: walletType } = yield provider.request("wallet_getWalletType", void 0);
659
656
  const { result } = yield provider.request("getAddresses", {
660
657
  purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals],
661
658
  message: "Address for receiving Ordinals and payments"
662
659
  });
663
- const addresses = result.addresses.map((item) => __spreadProps(__spreadValues({}, item), { walletType }));
660
+ const addresses = result.addresses.map((item) => __spreadProps(__spreadValues({}, item), {
661
+ walletType
662
+ }));
664
663
  console.log("\u{1F680} ~ XverseConnector ~ loadAccounts ~ res:", addresses);
665
664
  localStorage.setItem("btc-connect-xverse-addresses-" + network, JSON.stringify(addresses));
666
665
  return addresses;
@@ -683,78 +682,76 @@ var XverseConnector = class extends BaseConnector {
683
682
  }
684
683
  requestAccounts() {
685
684
  return __async(this, null, function* () {
686
- if (isMobile() && !this.getProvider()) {
687
- MobileWalletConnect.redirectToWallet(this.metadata.id);
688
- return [];
685
+ if (isMobile()) {
686
+ try {
687
+ this.getProvider();
688
+ } catch (error) {
689
+ MobileWalletConnect.redirectToWallet(this.metadata.id);
690
+ return [];
691
+ }
689
692
  }
690
693
  const addresses = yield this.loadAccounts(__privateGet(this, _network));
691
694
  return addresses.map((item) => item.address);
692
695
  });
693
696
  }
694
- getAccounts() {
697
+ getAddresses() {
695
698
  return __async(this, null, function* () {
696
- if (!this.isReady()) {
697
- throw new Error(`${this.metadata.name} is not install!`);
698
- }
699
699
  const data = localStorage.getItem("btc-connect-xverse-addresses-" + __privateGet(this, _network));
700
700
  if (data) {
701
- const addresses = JSON.parse(data);
702
- return addresses.map((item) => item.address);
703
- } else {
704
- return [];
701
+ return JSON.parse(data);
705
702
  }
703
+ return [];
706
704
  });
707
705
  }
708
- getPublicKey() {
706
+ getCurrentAddress() {
709
707
  return __async(this, null, function* () {
710
- if (!this.isReady()) {
711
- throw new Error(`${this.metadata.name} is not install!`);
712
- }
713
- const data = localStorage.getItem("btc-connect-xverse-addresses-" + __privateGet(this, _network));
714
- if (data) {
715
- const addresses = JSON.parse(data);
716
- return addresses[0].publicKey;
717
- } else {
718
- return "";
708
+ const addresses = yield this.getAddresses();
709
+ const address = addresses == null ? void 0 : addresses[0];
710
+ if (!address) {
711
+ throw new Error(`${this.metadata.name} not connected!`);
719
712
  }
713
+ return address;
720
714
  });
721
715
  }
722
- signMessage(signStr) {
716
+ getAccounts() {
723
717
  return __async(this, null, function* () {
724
718
  if (!this.isReady()) {
725
719
  throw new Error(`${this.metadata.name} is not install!`);
726
720
  }
727
- const addresses = yield this.getAccounts();
728
- if (addresses.length === 0) {
729
- throw new Error(`${this.metadata.name} not connected!`);
730
- }
731
- const { signMessage } = yield import("sats-connect");
732
- const sig = yield new Promise((resolve, reject) => {
733
- const signMessageOptions = {
734
- payload: {
735
- network: {
736
- type: __privateGet(this, _network)
737
- },
738
- address: addresses[0],
739
- message: signStr
740
- },
741
- onFinish: (response) => {
742
- resolve(response);
743
- },
744
- onCancel: () => {
745
- reject({
746
- code: 4001,
747
- message: "User rejected the request."
748
- });
749
- }
750
- };
751
- signMessage(signMessageOptions).catch((e) => {
752
- reject(e);
753
- });
721
+ const addresses = yield this.getAddresses();
722
+ return addresses.map((item) => item.address);
723
+ });
724
+ }
725
+ getPublicKey() {
726
+ return __async(this, null, function* () {
727
+ const address = yield this.getCurrentAddress();
728
+ return address.publicKey;
729
+ });
730
+ }
731
+ signMessage(signStr) {
732
+ return __async(this, null, function* () {
733
+ const address = yield this.getCurrentAddress();
734
+ const provider = this.getProvider();
735
+ const { result } = yield provider.request("signMessage", {
736
+ address: address.address,
737
+ message: signStr,
738
+ protocol: "ECDSA"
754
739
  });
755
- const modifiedSig = Buffer.from(sig, "base64");
756
- modifiedSig[0] = 31 + (modifiedSig[0] - 31) % 4;
757
- return modifiedSig.toString("base64");
740
+ const modifiedSig = Buffer.from(result.signature, "base64");
741
+ console.log("xverse walletType", address.walletType);
742
+ console.log("xverse raw sig", result.signature, modifiedSig.toString("base64"));
743
+ if (address.walletType === "ledger") {
744
+ if (address.addressType === "p2wpkh") {
745
+ modifiedSig[0] = 31 + (modifiedSig[0] - 39);
746
+ } else if (address.addressType === "p2sh") {
747
+ modifiedSig[0] = 31 + (modifiedSig[0] - 35);
748
+ }
749
+ } else {
750
+ modifiedSig[0] = 31 + (modifiedSig[0] - 31) % 4;
751
+ }
752
+ const sig = modifiedSig.toString("base64");
753
+ console.log("xverse modified sig", sig);
754
+ return sig;
758
755
  });
759
756
  }
760
757
  on(event, handler) {
@@ -764,9 +761,11 @@ var XverseConnector = class extends BaseConnector {
764
761
  return __privateGet(this, _event).removeListener(event, handler);
765
762
  }
766
763
  getProvider() {
767
- if (this.isReady()) {
768
- return window.BitcoinProvider;
764
+ const provider = window.BitcoinProvider;
765
+ if (!provider) {
766
+ throw new Error(`${this.metadata.name} is not install!`);
769
767
  }
768
+ return provider;
770
769
  }
771
770
  getNetwork() {
772
771
  return __async(this, null, function* () {
@@ -784,9 +783,6 @@ var XverseConnector = class extends BaseConnector {
784
783
  sendBitcoin(toAddress, satoshis) {
785
784
  return __async(this, null, function* () {
786
785
  const provider = this.getProvider();
787
- if (!provider) {
788
- throw new Error(`${this.metadata.name} is not install!`);
789
- }
790
786
  const { result } = yield provider.request("sendTransfer", {
791
787
  recipients: [{ address: toAddress, amount: satoshis }]
792
788
  });
@@ -3361,6 +3357,16 @@ function getCsnaAccountId(env) {
3361
3357
  return csna;
3362
3358
  });
3363
3359
  }
3360
+ function checkDepositDisabledAddress() {
3361
+ const data = localStorage.getItem("btc-connect-xverse-addresses-Mainnet");
3362
+ if (!data)
3363
+ return;
3364
+ const addresses = JSON.parse(data);
3365
+ const address = addresses == null ? void 0 : addresses[0];
3366
+ if (address.walletType === "ledger" && (address.addressType !== "p2wpkh" || address.addressType !== "p2sh")) {
3367
+ throw new Error("Ledger is only supported for p2wpkh and p2sh address");
3368
+ }
3369
+ }
3364
3370
  function executeBTCDepositAndAction(_0) {
3365
3371
  return __async(this, arguments, function* ({
3366
3372
  action,
@@ -3373,6 +3379,7 @@ function executeBTCDepositAndAction(_0) {
3373
3379
  }) {
3374
3380
  var _a;
3375
3381
  try {
3382
+ checkDepositDisabledAddress();
3376
3383
  const { getPublicKey } = getBtcProvider();
3377
3384
  const config = yield getConfig(env);
3378
3385
  const btcPublicKey = yield getPublicKey();
@@ -4429,7 +4436,7 @@ function setupBTCWallet({
4429
4436
 
4430
4437
  // src/index.ts
4431
4438
  var getVersion = () => {
4432
- return "0.5.6-beta";
4439
+ return "0.5.7-beta";
4433
4440
  };
4434
4441
  if (typeof window !== "undefined") {
4435
4442
  window.__BTC_WALLET_VERSION = getVersion();