@dynamic-labs/bitcoin 1.1.0-alpha.11 → 1.1.0-alpha.13

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/CHANGELOG.md CHANGED
@@ -1,4 +1,36 @@
1
1
 
2
+ ## [1.1.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.12...v1.1.0-alpha.13) (2024-01-23)
3
+
4
+
5
+ ### Features
6
+
7
+ * add createWalletClientFromWallet helper function ([#4416](https://github.com/dynamic-labs/DynamicAuth/issues/4416)) ([b384898](https://github.com/dynamic-labs/DynamicAuth/commit/b384898061bb3f9b38b2ed670b6650cfc1d4b429))
8
+ * add hardware wallets to wallet book ([#4445](https://github.com/dynamic-labs/DynamicAuth/issues/4445)) ([66c0f5b](https://github.com/dynamic-labs/DynamicAuth/commit/66c0f5b29a6a700099bb95a6f7622f6178e0bccf))
9
+ * add support for Argent Web and Mobile ([#4328](https://github.com/dynamic-labs/DynamicAuth/issues/4328)) ([bce20b8](https://github.com/dynamic-labs/DynamicAuth/commit/bce20b8f35a8630f2621f53a541a1acb06a38fc0))
10
+ * enable ledger for glow, solflare and backpack ([#4392](https://github.com/dynamic-labs/DynamicAuth/issues/4392)) ([fa7b992](https://github.com/dynamic-labs/DynamicAuth/commit/fa7b992f87ebc43560f87b43ac56f2cd9909b306))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * breaking changes script ([#4440](https://github.com/dynamic-labs/DynamicAuth/issues/4440)) ([446173d](https://github.com/dynamic-labs/DynamicAuth/commit/446173d074d652d81856c6412e304b46b1565320))
16
+ * broken help icon in create passkey view ([#4428](https://github.com/dynamic-labs/DynamicAuth/issues/4428)) ([e0ffc02](https://github.com/dynamic-labs/DynamicAuth/commit/e0ffc02ffea34b7ac3198ff6e1baf7f9907acddd))
17
+ * infinite loop when connecting with trust wallet ([#4448](https://github.com/dynamic-labs/DynamicAuth/issues/4448)) ([4e20edf](https://github.com/dynamic-labs/DynamicAuth/commit/4e20edf9abaabf20e5e9f9167b44d7f691e844f1))
18
+ * render wagmi elements based on react version ([#4453](https://github.com/dynamic-labs/DynamicAuth/issues/4453)) ([43c624c](https://github.com/dynamic-labs/DynamicAuth/commit/43c624ca996b0c51de1454910f19fdf908149938))
19
+
20
+ ## [1.1.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.11...v1.1.0-alpha.12) (2024-01-18)
21
+
22
+
23
+ ### Features
24
+
25
+ * expose setAuthMode method ([#4419](https://github.com/dynamic-labs/DynamicAuth/issues/4419)) ([7d156b3](https://github.com/dynamic-labs/DynamicAuth/commit/7d156b3e0eab9b9a80f70ff1c5201d90693ae755))
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * call onUnlinkSuccess in headless mode too ([#4412](https://github.com/dynamic-labs/DynamicAuth/issues/4412)) ([4c76af9](https://github.com/dynamic-labs/DynamicAuth/commit/4c76af9ac7c7b43883742d1289558dfcb5d612ca))
31
+ * correctly map keplr chain ids from project settings ([#4418](https://github.com/dynamic-labs/DynamicAuth/issues/4418)) ([7046364](https://github.com/dynamic-labs/DynamicAuth/commit/7046364a316f7551f0b995eaae7afea13502eb9b))
32
+ * logging in with an email linked to a third party wallet gets stuck on otp view ([#4407](https://github.com/dynamic-labs/DynamicAuth/issues/4407)) ([35bf142](https://github.com/dynamic-labs/DynamicAuth/commit/35bf142e74efeef866dbd7b8157a049cd36eeccb))
33
+
2
34
  ## [1.1.0-alpha.11](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.10...v1.1.0-alpha.11) (2024-01-17)
3
35
 
4
36
 
@@ -25,6 +25,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
25
25
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
26
  step((generator = generator.apply(thisArg, _arguments || [])).next());
27
27
  });
28
- }
28
+ }
29
+
30
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
31
+ var e = new Error(message);
32
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
33
+ };
29
34
 
30
35
  exports.__awaiter = __awaiter;
@@ -21,6 +21,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
21
21
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
- }
24
+ }
25
+
26
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
27
+ var e = new Error(message);
28
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
29
+ };
25
30
 
26
31
  export { __awaiter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/bitcoin",
3
- "version": "1.1.0-alpha.11",
3
+ "version": "1.1.0-alpha.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -26,12 +26,13 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "dependencies": {
29
+ "@dynamic-labs/sdk-api": "0.0.352",
29
30
  "@wallet-standard/app": "^1.0.1",
30
31
  "@wallet-standard/base": "^1.0.1",
31
32
  "sats-connect": "^1.1.2",
32
- "@dynamic-labs/utils": "1.1.0-alpha.11",
33
- "@dynamic-labs/wallet-book": "1.1.0-alpha.11",
34
- "@dynamic-labs/wallet-connector-core": "1.1.0-alpha.11"
33
+ "@dynamic-labs/utils": "1.1.0-alpha.13",
34
+ "@dynamic-labs/wallet-book": "1.1.0-alpha.13",
35
+ "@dynamic-labs/wallet-connector-core": "1.1.0-alpha.13"
35
36
  },
36
37
  "peerDependencies": {}
37
38
  }
@@ -14,11 +14,11 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector.BitcoinWalletConnect
14
14
  this.btcKit = btcKit;
15
15
  }
16
16
  fetchPublicAddress() {
17
- var _a, _b, _c, _d;
17
+ var _a;
18
18
  return _tslib.__awaiter(this, void 0, void 0, function* () {
19
- const connectedAccount = yield this.cache.getCurrentAccount();
19
+ const [connectedAccount] = yield this.getConnectedAccounts();
20
20
  if (connectedAccount) {
21
- return ((_a = connectedAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : connectedAccount.paymentAddress);
21
+ return connectedAccount;
22
22
  }
23
23
  const response = yield this.btcKit.request('getAddresses', {
24
24
  types: ['p2tr', 'p2wpkh'],
@@ -28,12 +28,11 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector.BitcoinWalletConnect
28
28
  return undefined;
29
29
  }
30
30
  const { addresses } = response.result;
31
- const bitcoinAccount = {
32
- ordinalsAddress: (_b = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2tr')) === null || _b === void 0 ? void 0 : _b.address,
33
- paymentAddress: (_c = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2wpkh')) === null || _c === void 0 ? void 0 : _c.address,
34
- };
35
- yield this.cache.setCurrentAccount(bitcoinAccount);
36
- return (_d = bitcoinAccount.ordinalsAddress) !== null && _d !== void 0 ? _d : bitcoinAccount.paymentAddress;
31
+ const ordinalsAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2tr');
32
+ const paymentAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2wpkh');
33
+ const mainAddress = (_a = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _a !== void 0 ? _a : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
34
+ yield this.setConnectedAccountWithAddresses(mainAddress, ordinalsAccount, paymentAccount, true);
35
+ return mainAddress;
37
36
  });
38
37
  }
39
38
  signMessage(messageToSign) {
@@ -55,10 +54,12 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector.BitcoinWalletConnect
55
54
  return response.result.signature;
56
55
  });
57
56
  }
58
- sendTransaction(transaction) {
57
+ sendBitcoin(transaction) {
59
58
  return _tslib.__awaiter(this, void 0, void 0, function* () {
60
- if (!(yield this.getConnectedAccounts()).length)
61
- return undefined;
59
+ const connectedAddress = yield this.fetchPublicAddress();
60
+ if (!connectedAddress || !this.btcKit) {
61
+ return;
62
+ }
62
63
  const response = yield this.btcKit.request('sendTransfer', {
63
64
  address: transaction.recipientAddress,
64
65
  amount: transaction.amount,
@@ -12,5 +12,5 @@ export declare abstract class BitcoinBtcKitConnector extends BitcoinWalletConnec
12
12
  constructor(opts: BitcoinWalletConnectorOpts, btcKit: BtcKitProvider);
13
13
  fetchPublicAddress(): Promise<string | undefined>;
14
14
  signMessage(messageToSign: string): Promise<string | undefined>;
15
- sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
15
+ sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
16
16
  }
@@ -10,11 +10,11 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector {
10
10
  this.btcKit = btcKit;
11
11
  }
12
12
  fetchPublicAddress() {
13
- var _a, _b, _c, _d;
13
+ var _a;
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
- const connectedAccount = yield this.cache.getCurrentAccount();
15
+ const [connectedAccount] = yield this.getConnectedAccounts();
16
16
  if (connectedAccount) {
17
- return ((_a = connectedAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : connectedAccount.paymentAddress);
17
+ return connectedAccount;
18
18
  }
19
19
  const response = yield this.btcKit.request('getAddresses', {
20
20
  types: ['p2tr', 'p2wpkh'],
@@ -24,12 +24,11 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector {
24
24
  return undefined;
25
25
  }
26
26
  const { addresses } = response.result;
27
- const bitcoinAccount = {
28
- ordinalsAddress: (_b = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2tr')) === null || _b === void 0 ? void 0 : _b.address,
29
- paymentAddress: (_c = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2wpkh')) === null || _c === void 0 ? void 0 : _c.address,
30
- };
31
- yield this.cache.setCurrentAccount(bitcoinAccount);
32
- return (_d = bitcoinAccount.ordinalsAddress) !== null && _d !== void 0 ? _d : bitcoinAccount.paymentAddress;
27
+ const ordinalsAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2tr');
28
+ const paymentAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.type === 'p2wpkh');
29
+ const mainAddress = (_a = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _a !== void 0 ? _a : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
30
+ yield this.setConnectedAccountWithAddresses(mainAddress, ordinalsAccount, paymentAccount, true);
31
+ return mainAddress;
33
32
  });
34
33
  }
35
34
  signMessage(messageToSign) {
@@ -51,10 +50,12 @@ class BitcoinBtcKitConnector extends BitcoinWalletConnector {
51
50
  return response.result.signature;
52
51
  });
53
52
  }
54
- sendTransaction(transaction) {
53
+ sendBitcoin(transaction) {
55
54
  return __awaiter(this, void 0, void 0, function* () {
56
- if (!(yield this.getConnectedAccounts()).length)
57
- return undefined;
55
+ const connectedAddress = yield this.fetchPublicAddress();
56
+ if (!connectedAddress || !this.btcKit) {
57
+ return;
58
+ }
58
59
  const response = yield this.btcKit.request('sendTransfer', {
59
60
  address: transaction.recipientAddress,
60
61
  amount: transaction.amount,
@@ -7,32 +7,58 @@ var utils = require('@dynamic-labs/utils');
7
7
 
8
8
  class BitcoinLocalStorageCache {
9
9
  constructor(key) {
10
- this.CONNECTED_ACCOUNT_KEY = `bitcoin_${key}_connectedAccount`;
10
+ this.CONNECTED_ACCOUNTS_KEY = `bitcoin_${key}_connectedAccounts`;
11
11
  this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
12
12
  }
13
- getCurrentAccount() {
13
+ getActiveAccount() {
14
14
  return _tslib.__awaiter(this, void 0, void 0, function* () {
15
- const account = yield utils.getItemAsync(this.CONNECTED_ACCOUNT_KEY);
16
- return account;
15
+ const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
16
+ if (!connectedAccounts) {
17
+ return;
18
+ }
19
+ const activeAddress = Object.keys(connectedAccounts).find((key) => connectedAccounts[key].active);
20
+ if (!activeAddress) {
21
+ return;
22
+ }
23
+ return {
24
+ additionalAddresses: connectedAccounts[activeAddress].additionalAddresses,
25
+ address: activeAddress,
26
+ };
27
+ });
28
+ }
29
+ getConnectedAccount(address) {
30
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
31
+ const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
32
+ return connectedAccounts === null || connectedAccounts === void 0 ? void 0 : connectedAccounts[address];
17
33
  });
18
34
  }
19
- setCurrentAccount(account) {
35
+ setConnectedAccount(addess, account) {
20
36
  return _tslib.__awaiter(this, void 0, void 0, function* () {
21
- return utils.setItemAsync(this.CONNECTED_ACCOUNT_KEY, account);
37
+ let connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
38
+ if (!connectedAccounts) {
39
+ connectedAccounts = {};
40
+ }
41
+ // if current account is active, reset all other accounts to inactive
42
+ if (account.active) {
43
+ Object.keys(connectedAccounts).forEach((key) => {
44
+ if (connectedAccounts) {
45
+ connectedAccounts[key].active = false;
46
+ }
47
+ });
48
+ }
49
+ // add new account to map or override existing one
50
+ connectedAccounts[addess] = account;
51
+ return utils.setItemAsync(this.CONNECTED_ACCOUNTS_KEY, connectedAccounts);
22
52
  });
23
53
  }
24
- clearCurrentAcccount() {
54
+ clearConnectedAcccounts() {
25
55
  return _tslib.__awaiter(this, void 0, void 0, function* () {
26
- return utils.removeItemAsync(this.CONNECTED_ACCOUNT_KEY);
56
+ return utils.removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
27
57
  });
28
58
  }
29
59
  getLastBalance() {
30
60
  return _tslib.__awaiter(this, void 0, void 0, function* () {
31
- const balance = yield utils.getItemAsync(this.LAST_BALANCE_KEY);
32
- if (!balance) {
33
- return undefined;
34
- }
35
- return balance;
61
+ return utils.getItemAsync(this.LAST_BALANCE_KEY);
36
62
  });
37
63
  }
38
64
  setLastBalance(balance) {
@@ -1,20 +1,28 @@
1
- import { BitcoinAccount } from './types';
1
+ import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api';
2
+ import { BitcoinConnectedAccount } from './types';
3
+ type BitcoinActiveAccount = {
4
+ address: string;
5
+ additionalAddresses: WalletAdditionalAddress[];
6
+ };
2
7
  export declare class BitcoinLocalStorageCache implements IBitcoinSessionCache {
3
- private readonly CONNECTED_ACCOUNT_KEY;
8
+ private readonly CONNECTED_ACCOUNTS_KEY;
4
9
  private readonly LAST_BALANCE_KEY;
5
10
  constructor(key: string);
6
- getCurrentAccount(): Promise<BitcoinAccount | undefined>;
7
- setCurrentAccount(account: BitcoinAccount): Promise<void>;
8
- clearCurrentAcccount(): Promise<void>;
11
+ getActiveAccount(): Promise<BitcoinActiveAccount | undefined>;
12
+ getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
13
+ setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
14
+ clearConnectedAcccounts(): Promise<void>;
9
15
  getLastBalance(): Promise<string | undefined>;
10
16
  setLastBalance(balance: string): Promise<void>;
11
17
  clearLastBalance(): Promise<void>;
12
18
  }
13
19
  export interface IBitcoinSessionCache {
14
- clearCurrentAcccount(): Promise<void>;
15
- getCurrentAccount(): Promise<BitcoinAccount | undefined>;
16
- setCurrentAccount(account: BitcoinAccount): Promise<void>;
20
+ clearConnectedAcccounts(): Promise<void>;
21
+ getActiveAccount(): Promise<BitcoinActiveAccount | undefined>;
22
+ getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
23
+ setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
17
24
  clearLastBalance(): Promise<void>;
18
25
  getLastBalance(): Promise<string | undefined>;
19
26
  setLastBalance(balance: string): Promise<void>;
20
27
  }
28
+ export {};
@@ -3,32 +3,58 @@ import { getItemAsync, setItemAsync, removeItemAsync } from '@dynamic-labs/utils
3
3
 
4
4
  class BitcoinLocalStorageCache {
5
5
  constructor(key) {
6
- this.CONNECTED_ACCOUNT_KEY = `bitcoin_${key}_connectedAccount`;
6
+ this.CONNECTED_ACCOUNTS_KEY = `bitcoin_${key}_connectedAccounts`;
7
7
  this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
8
8
  }
9
- getCurrentAccount() {
9
+ getActiveAccount() {
10
10
  return __awaiter(this, void 0, void 0, function* () {
11
- const account = yield getItemAsync(this.CONNECTED_ACCOUNT_KEY);
12
- return account;
11
+ const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
12
+ if (!connectedAccounts) {
13
+ return;
14
+ }
15
+ const activeAddress = Object.keys(connectedAccounts).find((key) => connectedAccounts[key].active);
16
+ if (!activeAddress) {
17
+ return;
18
+ }
19
+ return {
20
+ additionalAddresses: connectedAccounts[activeAddress].additionalAddresses,
21
+ address: activeAddress,
22
+ };
23
+ });
24
+ }
25
+ getConnectedAccount(address) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
28
+ return connectedAccounts === null || connectedAccounts === void 0 ? void 0 : connectedAccounts[address];
13
29
  });
14
30
  }
15
- setCurrentAccount(account) {
31
+ setConnectedAccount(addess, account) {
16
32
  return __awaiter(this, void 0, void 0, function* () {
17
- return setItemAsync(this.CONNECTED_ACCOUNT_KEY, account);
33
+ let connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
34
+ if (!connectedAccounts) {
35
+ connectedAccounts = {};
36
+ }
37
+ // if current account is active, reset all other accounts to inactive
38
+ if (account.active) {
39
+ Object.keys(connectedAccounts).forEach((key) => {
40
+ if (connectedAccounts) {
41
+ connectedAccounts[key].active = false;
42
+ }
43
+ });
44
+ }
45
+ // add new account to map or override existing one
46
+ connectedAccounts[addess] = account;
47
+ return setItemAsync(this.CONNECTED_ACCOUNTS_KEY, connectedAccounts);
18
48
  });
19
49
  }
20
- clearCurrentAcccount() {
50
+ clearConnectedAcccounts() {
21
51
  return __awaiter(this, void 0, void 0, function* () {
22
- return removeItemAsync(this.CONNECTED_ACCOUNT_KEY);
52
+ return removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
23
53
  });
24
54
  }
25
55
  getLastBalance() {
26
56
  return __awaiter(this, void 0, void 0, function* () {
27
- const balance = yield getItemAsync(this.LAST_BALANCE_KEY);
28
- if (!balance) {
29
- return undefined;
30
- }
31
- return balance;
57
+ return getItemAsync(this.LAST_BALANCE_KEY);
32
58
  });
33
59
  }
34
60
  setLastBalance(balance) {
@@ -16,7 +16,6 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
16
16
  this.currentNetwork = satsConnect.BitcoinNetworkType.Mainnet;
17
17
  }
18
18
  fetchPublicAddress() {
19
- var _a;
20
19
  return _tslib.__awaiter(this, void 0, void 0, function* () {
21
20
  // xverse doesn't support wallet standard, so we won't have a wallet object,
22
21
  // but it's already the default provider for sats-connect, so it's ok
@@ -26,9 +25,9 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
26
25
  if (!supportsSatsConnect.supportsSatsConnect(this)) {
27
26
  return;
28
27
  }
29
- const connectedAccount = yield this.cache.getCurrentAccount();
28
+ const [connectedAccount] = yield this.getConnectedAccounts();
30
29
  if (connectedAccount) {
31
- return ((_a = connectedAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : connectedAccount.paymentAddress);
30
+ return connectedAccount;
32
31
  }
33
32
  return new Promise((resolve, reject) => {
34
33
  satsConnect.getAddress({
@@ -42,14 +41,13 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
42
41
  reject(error);
43
42
  },
44
43
  onFinish: (response) => _tslib.__awaiter(this, void 0, void 0, function* () {
45
- var _c, _d, _e;
44
+ var _c;
46
45
  const { addresses } = response;
47
- const bitcoinAccount = {
48
- ordinalsAddress: (_c = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Ordinals)) === null || _c === void 0 ? void 0 : _c.address,
49
- paymentAddress: (_d = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Payment)) === null || _d === void 0 ? void 0 : _d.address,
50
- };
51
- yield this.cache.setCurrentAccount(bitcoinAccount);
52
- resolve((_e = bitcoinAccount.ordinalsAddress) !== null && _e !== void 0 ? _e : bitcoinAccount.paymentAddress);
46
+ const ordinalsAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Ordinals);
47
+ const paymentAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === satsConnect.AddressPurpose.Payment);
48
+ const mainAddress = (_c = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _c !== void 0 ? _c : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
49
+ yield this.setConnectedAccountWithAddresses(mainAddress, ordinalsAccount, paymentAccount, true);
50
+ resolve(mainAddress);
53
51
  }),
54
52
  payload: {
55
53
  message: 'Address for receiving Ordinals and payments',
@@ -93,10 +91,12 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
93
91
  });
94
92
  });
95
93
  }
96
- sendTransaction(transaction) {
94
+ sendBitcoin(transaction) {
95
+ var _a, _b;
97
96
  return _tslib.__awaiter(this, void 0, void 0, function* () {
98
- const paymentAddress = yield this.getPaymentAddress();
99
- if (!paymentAddress || !supportsSatsConnect.supportsSatsConnect(this)) {
97
+ const mainAddress = yield this.fetchPublicAddress();
98
+ const senderAddress = (_b = (_a = (yield this.getAdditionalAddresses(mainAddress))) === null || _a === void 0 ? void 0 : _a.find((address) => address.type === 'payment')) === null || _b === void 0 ? void 0 : _b.address;
99
+ if (!senderAddress || !supportsSatsConnect.supportsSatsConnect(this)) {
100
100
  return;
101
101
  }
102
102
  return new Promise((resolve, reject) => {
@@ -123,7 +123,7 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
123
123
  amountSats: transaction.amount,
124
124
  },
125
125
  ],
126
- senderAddress: paymentAddress,
126
+ senderAddress,
127
127
  },
128
128
  });
129
129
  });
@@ -6,5 +6,5 @@ export declare abstract class BitcoinSatsConnectConnector extends BitcoinWalletC
6
6
  constructor(opts: BitcoinWalletConnectorOpts);
7
7
  fetchPublicAddress(): Promise<string | undefined>;
8
8
  signMessage(messageToSign: string): Promise<string | undefined>;
9
- sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
9
+ sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
10
10
  }
@@ -12,7 +12,6 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
12
12
  this.currentNetwork = BitcoinNetworkType.Mainnet;
13
13
  }
14
14
  fetchPublicAddress() {
15
- var _a;
16
15
  return __awaiter(this, void 0, void 0, function* () {
17
16
  // xverse doesn't support wallet standard, so we won't have a wallet object,
18
17
  // but it's already the default provider for sats-connect, so it's ok
@@ -22,9 +21,9 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
22
21
  if (!supportsSatsConnect(this)) {
23
22
  return;
24
23
  }
25
- const connectedAccount = yield this.cache.getCurrentAccount();
24
+ const [connectedAccount] = yield this.getConnectedAccounts();
26
25
  if (connectedAccount) {
27
- return ((_a = connectedAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : connectedAccount.paymentAddress);
26
+ return connectedAccount;
28
27
  }
29
28
  return new Promise((resolve, reject) => {
30
29
  getAddress({
@@ -38,14 +37,13 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
38
37
  reject(error);
39
38
  },
40
39
  onFinish: (response) => __awaiter(this, void 0, void 0, function* () {
41
- var _c, _d, _e;
40
+ var _c;
42
41
  const { addresses } = response;
43
- const bitcoinAccount = {
44
- ordinalsAddress: (_c = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === AddressPurpose.Ordinals)) === null || _c === void 0 ? void 0 : _c.address,
45
- paymentAddress: (_d = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === AddressPurpose.Payment)) === null || _d === void 0 ? void 0 : _d.address,
46
- };
47
- yield this.cache.setCurrentAccount(bitcoinAccount);
48
- resolve((_e = bitcoinAccount.ordinalsAddress) !== null && _e !== void 0 ? _e : bitcoinAccount.paymentAddress);
42
+ const ordinalsAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === AddressPurpose.Ordinals);
43
+ const paymentAccount = addresses === null || addresses === void 0 ? void 0 : addresses.find((address) => address.purpose === AddressPurpose.Payment);
44
+ const mainAddress = (_c = ordinalsAccount === null || ordinalsAccount === void 0 ? void 0 : ordinalsAccount.address) !== null && _c !== void 0 ? _c : paymentAccount === null || paymentAccount === void 0 ? void 0 : paymentAccount.address;
45
+ yield this.setConnectedAccountWithAddresses(mainAddress, ordinalsAccount, paymentAccount, true);
46
+ resolve(mainAddress);
49
47
  }),
50
48
  payload: {
51
49
  message: 'Address for receiving Ordinals and payments',
@@ -89,10 +87,12 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
89
87
  });
90
88
  });
91
89
  }
92
- sendTransaction(transaction) {
90
+ sendBitcoin(transaction) {
91
+ var _a, _b;
93
92
  return __awaiter(this, void 0, void 0, function* () {
94
- const paymentAddress = yield this.getPaymentAddress();
95
- if (!paymentAddress || !supportsSatsConnect(this)) {
93
+ const mainAddress = yield this.fetchPublicAddress();
94
+ const senderAddress = (_b = (_a = (yield this.getAdditionalAddresses(mainAddress))) === null || _a === void 0 ? void 0 : _a.find((address) => address.type === 'payment')) === null || _b === void 0 ? void 0 : _b.address;
95
+ if (!senderAddress || !supportsSatsConnect(this)) {
96
96
  return;
97
97
  }
98
98
  return new Promise((resolve, reject) => {
@@ -119,7 +119,7 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
119
119
  amountSats: transaction.amount,
120
120
  },
121
121
  ],
122
- senderAddress: paymentAddress,
122
+ senderAddress,
123
123
  },
124
124
  });
125
125
  });
@@ -6,6 +6,7 @@ var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
7
  var walletBook = require('@dynamic-labs/wallet-book');
8
8
  var utils = require('@dynamic-labs/utils');
9
+ var sdkApi = require('@dynamic-labs/sdk-api');
9
10
  var bitcoinProviderHelper = require('./bitcoinProviderHelper.cjs');
10
11
  var BitcoinLocalStorageCache = require('./BitcoinLocalStorageCache.cjs');
11
12
  var _const = require('./const.cjs');
@@ -29,18 +30,24 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
29
30
  getDeepLink() {
30
31
  return undefined;
31
32
  }
32
- getBalance() {
33
- var _a;
33
+ endSession() {
34
34
  return _tslib.__awaiter(this, void 0, void 0, function* () {
35
- const addresses = yield Promise.all([
36
- this.getPaymentAddress(),
37
- this.getOrdinalsAddress(),
35
+ yield Promise.all([
36
+ this.cache.clearConnectedAcccounts(),
37
+ this.cache.clearLastBalance(),
38
38
  ]);
39
- if (!addresses[0] && !addresses[1]) {
39
+ });
40
+ }
41
+ getBalance() {
42
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
43
+ const [connectedAddress] = yield this.getConnectedAccounts();
44
+ if (!connectedAddress) {
40
45
  throw new utils.DynamicError('getBalance - No connected address found!');
41
46
  }
42
- const fetchAddress = (_a = addresses[0]) !== null && _a !== void 0 ? _a : addresses[1];
43
- const response = yield fetch(`${_const.BALANCE_API_URL}${fetchAddress}`);
47
+ const API_URL = connectedAddress.startsWith('t')
48
+ ? _const.BALANCE_API_URL_TESTNET
49
+ : _const.BALANCE_API_URL;
50
+ const response = yield fetch(`${API_URL}${connectedAddress}`);
44
51
  if (!response.ok) {
45
52
  // if the request fails due to rate limits, return cached value
46
53
  if (response.status === _const.HTTP_STATUS_TOO_MANY_REQUESTS) {
@@ -63,49 +70,64 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
63
70
  return balance.toString();
64
71
  });
65
72
  }
66
- endSession() {
67
- return _tslib.__awaiter(this, void 0, void 0, function* () {
68
- yield Promise.all([
69
- this.cache.clearCurrentAcccount(),
70
- this.cache.clearLastBalance(),
71
- ]);
72
- });
73
- }
74
73
  getConnectedAccounts() {
75
74
  return _tslib.__awaiter(this, void 0, void 0, function* () {
76
- const currentAccount = yield this.cache.getCurrentAccount();
77
- // ordinals address is the preferred address
78
- if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress) {
79
- return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress];
75
+ const currentAccount = yield this.cache.getActiveAccount();
76
+ if (!(currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.address)) {
77
+ return [];
80
78
  }
81
- if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress) {
82
- return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress];
83
- }
84
- return [];
79
+ return [currentAccount.address];
85
80
  });
86
81
  }
87
- getPaymentAddress() {
82
+ getAdditionalAddresses(mainAddress) {
83
+ var _a;
88
84
  return _tslib.__awaiter(this, void 0, void 0, function* () {
89
- const currentAccount = yield this.cache.getCurrentAccount();
90
- if (!currentAccount) {
85
+ if (!mainAddress) {
91
86
  return;
92
87
  }
93
- return currentAccount.paymentAddress;
88
+ const currentAccount = yield this.cache.getConnectedAccount(mainAddress);
89
+ return ((_a = currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.additionalAddresses) === null || _a === void 0 ? void 0 : _a.length)
90
+ ? currentAccount.additionalAddresses
91
+ : undefined;
94
92
  });
95
93
  }
96
- getOrdinalsAddress() {
94
+ setAdditionalAddresses(mainAddress, additionalAddresses) {
97
95
  return _tslib.__awaiter(this, void 0, void 0, function* () {
98
- const currentAccount = yield this.cache.getCurrentAccount();
99
- if (!currentAccount) {
100
- return;
101
- }
102
- return currentAccount.ordinalsAddress;
96
+ return this.cache.setConnectedAccount(mainAddress, {
97
+ additionalAddresses,
98
+ });
103
99
  });
104
100
  }
105
101
  getProvider() {
106
102
  var _a;
107
103
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
108
104
  }
105
+ setConnectedAccountWithAddresses(mainAddress, ordinalsAddress, paymentAddress, active) {
106
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
107
+ if (!mainAddress) {
108
+ return;
109
+ }
110
+ const additionalAddresses = [];
111
+ if (ordinalsAddress) {
112
+ additionalAddresses.push({
113
+ address: ordinalsAddress.address,
114
+ publicKey: ordinalsAddress.publicKey,
115
+ type: sdkApi.WalletAddressType.Ordinals,
116
+ });
117
+ }
118
+ if (paymentAddress) {
119
+ additionalAddresses.push({
120
+ address: paymentAddress.address,
121
+ publicKey: paymentAddress.publicKey,
122
+ type: sdkApi.WalletAddressType.Payment,
123
+ });
124
+ }
125
+ this.cache.setConnectedAccount(mainAddress, {
126
+ active,
127
+ additionalAddresses,
128
+ });
129
+ });
130
+ }
109
131
  }
110
132
 
111
133
  exports.BitcoinWalletConnector = BitcoinWalletConnector;
@@ -1,14 +1,15 @@
1
1
  import type { Wallet } from '@wallet-standard/base';
2
- import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
2
+ import { Chain, IBitcoinWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
3
3
  import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
4
+ import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api';
4
5
  import { IBitcoinSessionCache } from './BitcoinLocalStorageCache';
5
- import { BitcoinTransaction } from './types';
6
+ import { BitcoinAddress, BitcoinTransaction } from './types';
6
7
  export type BitcoinWalletConnectorOpts = {
7
8
  walletBook: WalletBookSchema;
8
9
  walletData: WalletSchema;
9
10
  overrideKey?: string;
10
11
  };
11
- export declare abstract class BitcoinWalletConnector extends WalletConnectorBase {
12
+ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase implements IBitcoinWalletConnector {
12
13
  cache: IBitcoinSessionCache;
13
14
  connectedChain: Chain;
14
15
  supportedChains: Chain[];
@@ -17,11 +18,12 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
17
18
  constructor(opts: BitcoinWalletConnectorOpts);
18
19
  isInstalledOnBrowser(): boolean;
19
20
  getDeepLink(): string | undefined;
20
- getBalance(): Promise<string | undefined>;
21
21
  endSession(): Promise<void>;
22
+ getBalance(): Promise<string | undefined>;
22
23
  getConnectedAccounts(): Promise<string[]>;
23
- getPaymentAddress(): Promise<string | undefined>;
24
- getOrdinalsAddress(): Promise<string | undefined>;
25
- abstract sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
24
+ getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[] | undefined>;
25
+ setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
26
+ abstract sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
26
27
  getProvider<T>(): T;
28
+ setConnectedAccountWithAddresses(mainAddress?: string, ordinalsAddress?: BitcoinAddress, paymentAddress?: BitcoinAddress, active?: boolean): Promise<void>;
27
29
  }
@@ -2,9 +2,10 @@ import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
3
3
  import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
4
4
  import { DynamicError } from '@dynamic-labs/utils';
5
+ import { WalletAddressType } from '@dynamic-labs/sdk-api';
5
6
  import { BitcoinProviderHelper } from './bitcoinProviderHelper.js';
6
7
  import { BitcoinLocalStorageCache } from './BitcoinLocalStorageCache.js';
7
- import { BALANCE_API_URL, HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_NOT_FOUND } from './const.js';
8
+ import { BALANCE_API_URL_TESTNET, BALANCE_API_URL, HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_NOT_FOUND } from './const.js';
8
9
 
9
10
  class BitcoinWalletConnector extends WalletConnectorBase {
10
11
  constructor(opts) {
@@ -25,18 +26,24 @@ class BitcoinWalletConnector extends WalletConnectorBase {
25
26
  getDeepLink() {
26
27
  return undefined;
27
28
  }
28
- getBalance() {
29
- var _a;
29
+ endSession() {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
- const addresses = yield Promise.all([
32
- this.getPaymentAddress(),
33
- this.getOrdinalsAddress(),
31
+ yield Promise.all([
32
+ this.cache.clearConnectedAcccounts(),
33
+ this.cache.clearLastBalance(),
34
34
  ]);
35
- if (!addresses[0] && !addresses[1]) {
35
+ });
36
+ }
37
+ getBalance() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const [connectedAddress] = yield this.getConnectedAccounts();
40
+ if (!connectedAddress) {
36
41
  throw new DynamicError('getBalance - No connected address found!');
37
42
  }
38
- const fetchAddress = (_a = addresses[0]) !== null && _a !== void 0 ? _a : addresses[1];
39
- const response = yield fetch(`${BALANCE_API_URL}${fetchAddress}`);
43
+ const API_URL = connectedAddress.startsWith('t')
44
+ ? BALANCE_API_URL_TESTNET
45
+ : BALANCE_API_URL;
46
+ const response = yield fetch(`${API_URL}${connectedAddress}`);
40
47
  if (!response.ok) {
41
48
  // if the request fails due to rate limits, return cached value
42
49
  if (response.status === HTTP_STATUS_TOO_MANY_REQUESTS) {
@@ -59,49 +66,64 @@ class BitcoinWalletConnector extends WalletConnectorBase {
59
66
  return balance.toString();
60
67
  });
61
68
  }
62
- endSession() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- yield Promise.all([
65
- this.cache.clearCurrentAcccount(),
66
- this.cache.clearLastBalance(),
67
- ]);
68
- });
69
- }
70
69
  getConnectedAccounts() {
71
70
  return __awaiter(this, void 0, void 0, function* () {
72
- const currentAccount = yield this.cache.getCurrentAccount();
73
- // ordinals address is the preferred address
74
- if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress) {
75
- return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.ordinalsAddress];
71
+ const currentAccount = yield this.cache.getActiveAccount();
72
+ if (!(currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.address)) {
73
+ return [];
76
74
  }
77
- if (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress) {
78
- return [currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.paymentAddress];
79
- }
80
- return [];
75
+ return [currentAccount.address];
81
76
  });
82
77
  }
83
- getPaymentAddress() {
78
+ getAdditionalAddresses(mainAddress) {
79
+ var _a;
84
80
  return __awaiter(this, void 0, void 0, function* () {
85
- const currentAccount = yield this.cache.getCurrentAccount();
86
- if (!currentAccount) {
81
+ if (!mainAddress) {
87
82
  return;
88
83
  }
89
- return currentAccount.paymentAddress;
84
+ const currentAccount = yield this.cache.getConnectedAccount(mainAddress);
85
+ return ((_a = currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.additionalAddresses) === null || _a === void 0 ? void 0 : _a.length)
86
+ ? currentAccount.additionalAddresses
87
+ : undefined;
90
88
  });
91
89
  }
92
- getOrdinalsAddress() {
90
+ setAdditionalAddresses(mainAddress, additionalAddresses) {
93
91
  return __awaiter(this, void 0, void 0, function* () {
94
- const currentAccount = yield this.cache.getCurrentAccount();
95
- if (!currentAccount) {
96
- return;
97
- }
98
- return currentAccount.ordinalsAddress;
92
+ return this.cache.setConnectedAccount(mainAddress, {
93
+ additionalAddresses,
94
+ });
99
95
  });
100
96
  }
101
97
  getProvider() {
102
98
  var _a;
103
99
  return (_a = this.bitcoinProviderHelper) === null || _a === void 0 ? void 0 : _a.getProvider();
104
100
  }
101
+ setConnectedAccountWithAddresses(mainAddress, ordinalsAddress, paymentAddress, active) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ if (!mainAddress) {
104
+ return;
105
+ }
106
+ const additionalAddresses = [];
107
+ if (ordinalsAddress) {
108
+ additionalAddresses.push({
109
+ address: ordinalsAddress.address,
110
+ publicKey: ordinalsAddress.publicKey,
111
+ type: WalletAddressType.Ordinals,
112
+ });
113
+ }
114
+ if (paymentAddress) {
115
+ additionalAddresses.push({
116
+ address: paymentAddress.address,
117
+ publicKey: paymentAddress.publicKey,
118
+ type: WalletAddressType.Payment,
119
+ });
120
+ }
121
+ this.cache.setConnectedAccount(mainAddress, {
122
+ active,
123
+ additionalAddresses,
124
+ });
125
+ });
126
+ }
105
127
  }
106
128
 
107
129
  export { BitcoinWalletConnector };
@@ -11,19 +11,18 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
11
11
  this.name = 'OKX Wallet (Bitcoin)';
12
12
  }
13
13
  fetchPublicAddress() {
14
- var _a;
15
14
  return _tslib.__awaiter(this, void 0, void 0, function* () {
16
15
  const provider = this.getProvider();
17
16
  if (!provider) {
18
17
  return;
19
18
  }
20
- const account = yield provider.connect();
21
- const bitcoinAccount = {
22
- ordinalsAddress: account.address,
23
- paymentAddress: account.address,
19
+ const { address, publicKey } = yield provider.connect();
20
+ const bitcoinAddress = {
21
+ address,
22
+ publicKey,
24
23
  };
25
- yield this.cache.setCurrentAccount(bitcoinAccount);
26
- return (_a = bitcoinAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : bitcoinAccount.paymentAddress;
24
+ yield this.setConnectedAccountWithAddresses(address, bitcoinAddress, bitcoinAddress, true);
25
+ return address;
27
26
  });
28
27
  }
29
28
  signMessage(messageToSign) {
@@ -35,11 +34,11 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
35
34
  return provider.signMessage(messageToSign, 'bip322-simple');
36
35
  });
37
36
  }
38
- sendTransaction(transaction) {
37
+ sendBitcoin(transaction) {
39
38
  return _tslib.__awaiter(this, void 0, void 0, function* () {
40
- const paymentAddress = yield this.getPaymentAddress();
41
39
  const provider = this.getProvider();
42
- if (!paymentAddress || !provider) {
40
+ const connectedAddress = yield this.fetchPublicAddress();
41
+ if (!connectedAddress || !provider) {
43
42
  return;
44
43
  }
45
44
  return provider.sendBitcoin(transaction.recipientAddress, transaction.amount);
@@ -5,5 +5,5 @@ export declare class OkxConnector extends BitcoinWalletConnector {
5
5
  constructor(opts: BitcoinWalletConnectorOpts);
6
6
  fetchPublicAddress(): Promise<string | undefined>;
7
7
  signMessage(messageToSign: string): Promise<string | undefined>;
8
- sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
8
+ sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
9
9
  }
@@ -7,19 +7,18 @@ class OkxConnector extends BitcoinWalletConnector {
7
7
  this.name = 'OKX Wallet (Bitcoin)';
8
8
  }
9
9
  fetchPublicAddress() {
10
- var _a;
11
10
  return __awaiter(this, void 0, void 0, function* () {
12
11
  const provider = this.getProvider();
13
12
  if (!provider) {
14
13
  return;
15
14
  }
16
- const account = yield provider.connect();
17
- const bitcoinAccount = {
18
- ordinalsAddress: account.address,
19
- paymentAddress: account.address,
15
+ const { address, publicKey } = yield provider.connect();
16
+ const bitcoinAddress = {
17
+ address,
18
+ publicKey,
20
19
  };
21
- yield this.cache.setCurrentAccount(bitcoinAccount);
22
- return (_a = bitcoinAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : bitcoinAccount.paymentAddress;
20
+ yield this.setConnectedAccountWithAddresses(address, bitcoinAddress, bitcoinAddress, true);
21
+ return address;
23
22
  });
24
23
  }
25
24
  signMessage(messageToSign) {
@@ -31,11 +30,11 @@ class OkxConnector extends BitcoinWalletConnector {
31
30
  return provider.signMessage(messageToSign, 'bip322-simple');
32
31
  });
33
32
  }
34
- sendTransaction(transaction) {
33
+ sendBitcoin(transaction) {
35
34
  return __awaiter(this, void 0, void 0, function* () {
36
- const paymentAddress = yield this.getPaymentAddress();
37
35
  const provider = this.getProvider();
38
- if (!paymentAddress || !provider) {
36
+ const connectedAddress = yield this.fetchPublicAddress();
37
+ if (!connectedAddress || !provider) {
39
38
  return;
40
39
  }
41
40
  return provider.sendBitcoin(transaction.recipientAddress, transaction.amount);
@@ -11,19 +11,19 @@ class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
11
11
  this.name = 'UniSat';
12
12
  }
13
13
  fetchPublicAddress() {
14
- var _a;
15
14
  return _tslib.__awaiter(this, void 0, void 0, function* () {
16
15
  const provider = this.getProvider();
17
16
  if (!provider) {
18
17
  return;
19
18
  }
20
19
  const [address] = yield provider.requestAccounts();
21
- const bitcoinAccount = {
22
- ordinalsAddress: address,
23
- paymentAddress: address,
20
+ const publicKey = yield provider.getPublicKey();
21
+ const bitcoinAddress = {
22
+ address,
23
+ publicKey,
24
24
  };
25
- yield this.cache.setCurrentAccount(bitcoinAccount);
26
- return (_a = bitcoinAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : bitcoinAccount.paymentAddress;
25
+ yield this.setConnectedAccountWithAddresses(address, bitcoinAddress, bitcoinAddress, true);
26
+ return address;
27
27
  });
28
28
  }
29
29
  signMessage(messageToSign) {
@@ -35,11 +35,11 @@ class UnisatConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
35
35
  return provider.signMessage(messageToSign, 'bip322-simple');
36
36
  });
37
37
  }
38
- sendTransaction(transaction) {
38
+ sendBitcoin(transaction) {
39
39
  return _tslib.__awaiter(this, void 0, void 0, function* () {
40
- const paymentAddress = yield this.getPaymentAddress();
41
40
  const provider = this.getProvider();
42
- if (!paymentAddress || !provider) {
41
+ const connectedAddress = yield this.fetchPublicAddress();
42
+ if (!connectedAddress || !provider) {
43
43
  return;
44
44
  }
45
45
  return provider.sendBitcoin(transaction.recipientAddress, transaction.amount);
@@ -5,5 +5,5 @@ export declare class UnisatConnector extends BitcoinWalletConnector {
5
5
  constructor(opts: BitcoinWalletConnectorOpts);
6
6
  fetchPublicAddress(): Promise<string | undefined>;
7
7
  signMessage(messageToSign: string): Promise<string | undefined>;
8
- sendTransaction(transaction: BitcoinTransaction): Promise<string | undefined>;
8
+ sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
9
9
  }
@@ -7,19 +7,19 @@ class UnisatConnector extends BitcoinWalletConnector {
7
7
  this.name = 'UniSat';
8
8
  }
9
9
  fetchPublicAddress() {
10
- var _a;
11
10
  return __awaiter(this, void 0, void 0, function* () {
12
11
  const provider = this.getProvider();
13
12
  if (!provider) {
14
13
  return;
15
14
  }
16
15
  const [address] = yield provider.requestAccounts();
17
- const bitcoinAccount = {
18
- ordinalsAddress: address,
19
- paymentAddress: address,
16
+ const publicKey = yield provider.getPublicKey();
17
+ const bitcoinAddress = {
18
+ address,
19
+ publicKey,
20
20
  };
21
- yield this.cache.setCurrentAccount(bitcoinAccount);
22
- return (_a = bitcoinAccount.ordinalsAddress) !== null && _a !== void 0 ? _a : bitcoinAccount.paymentAddress;
21
+ yield this.setConnectedAccountWithAddresses(address, bitcoinAddress, bitcoinAddress, true);
22
+ return address;
23
23
  });
24
24
  }
25
25
  signMessage(messageToSign) {
@@ -31,11 +31,11 @@ class UnisatConnector extends BitcoinWalletConnector {
31
31
  return provider.signMessage(messageToSign, 'bip322-simple');
32
32
  });
33
33
  }
34
- sendTransaction(transaction) {
34
+ sendBitcoin(transaction) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- const paymentAddress = yield this.getPaymentAddress();
37
36
  const provider = this.getProvider();
38
- if (!paymentAddress || !provider) {
37
+ const connectedAddress = yield this.fetchPublicAddress();
38
+ if (!connectedAddress || !provider) {
39
39
  return;
40
40
  }
41
41
  return provider.sendBitcoin(transaction.recipientAddress, transaction.amount);
package/src/const.cjs CHANGED
@@ -8,8 +8,10 @@ const BTCKIT_INTERFACE = 'btckit';
8
8
  const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
9
9
  const HTTP_STATUS_NOT_FOUND = 404;
10
10
  const BALANCE_API_URL = 'https://mempool.space/api/address/';
11
+ const BALANCE_API_URL_TESTNET = 'https://mempool.space/testnet/api/address/';
11
12
 
12
13
  exports.BALANCE_API_URL = BALANCE_API_URL;
14
+ exports.BALANCE_API_URL_TESTNET = BALANCE_API_URL_TESTNET;
13
15
  exports.BTCKIT_INTERFACE = BTCKIT_INTERFACE;
14
16
  exports.HTTP_STATUS_NOT_FOUND = HTTP_STATUS_NOT_FOUND;
15
17
  exports.HTTP_STATUS_TOO_MANY_REQUESTS = HTTP_STATUS_TOO_MANY_REQUESTS;
package/src/const.js CHANGED
@@ -4,5 +4,6 @@ const BTCKIT_INTERFACE = 'btckit';
4
4
  const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
5
5
  const HTTP_STATUS_NOT_FOUND = 404;
6
6
  const BALANCE_API_URL = 'https://mempool.space/api/address/';
7
+ const BALANCE_API_URL_TESTNET = 'https://mempool.space/testnet/api/address/';
7
8
 
8
- export { BALANCE_API_URL, BTCKIT_INTERFACE, HTTP_STATUS_NOT_FOUND, HTTP_STATUS_TOO_MANY_REQUESTS, SATSCONNECT_FEATURE, XVERSE_KEY };
9
+ export { BALANCE_API_URL, BALANCE_API_URL_TESTNET, BTCKIT_INTERFACE, HTTP_STATUS_NOT_FOUND, HTTP_STATUS_TOO_MANY_REQUESTS, SATSCONNECT_FEATURE, XVERSE_KEY };
package/src/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BitcoinProvider } from 'sats-connect';
2
+ import type { WalletAdditionalAddress } from '@dynamic-labs/sdk-api';
2
3
  import { SATSCONNECT_FEATURE } from './const';
3
4
  export type ErrorWithCode = Error & {
4
5
  code: string;
@@ -8,9 +9,13 @@ export type SatsConnectFeature = {
8
9
  provider: BitcoinProvider;
9
10
  };
10
11
  };
11
- export type BitcoinAccount = {
12
- ordinalsAddress?: string;
13
- paymentAddress?: string;
12
+ export type BitcoinAddress = {
13
+ address: string;
14
+ publicKey?: string;
15
+ };
16
+ export type BitcoinConnectedAccount = {
17
+ additionalAddresses: WalletAdditionalAddress[];
18
+ active?: boolean;
14
19
  };
15
20
  export type BitcoinTransaction = {
16
21
  amount: bigint;
@@ -4,9 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _const = require('../const.cjs');
6
6
  require('@dynamic-labs/utils');
7
+ require('../../_virtual/_tslib.cjs');
7
8
  require('sats-connect');
8
9
  require('@dynamic-labs/wallet-connector-core');
9
10
  require('@dynamic-labs/wallet-book');
11
+ require('@dynamic-labs/sdk-api');
10
12
  require('@wallet-standard/app');
11
13
  var hasSatsConnectFeature = require('./hasSatsConnectFeature.cjs');
12
14
 
@@ -1,8 +1,10 @@
1
1
  import { XVERSE_KEY } from '../const.js';
2
2
  import '@dynamic-labs/utils';
3
+ import '../../_virtual/_tslib.js';
3
4
  import 'sats-connect';
4
5
  import '@dynamic-labs/wallet-connector-core';
5
6
  import '@dynamic-labs/wallet-book';
7
+ import '@dynamic-labs/sdk-api';
6
8
  import '@wallet-standard/app';
7
9
  import { hasSatsConnectFeature } from './hasSatsConnectFeature.js';
8
10