bitcoin-wallet-connector 0.1.0 → 0.2.0
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/README.md +24 -21
- package/lib/BitcoinConnectionProvider.d.ts +3 -3
- package/lib/BitcoinWalletConnector-BC92ulXx.js +2 -0
- package/lib/BitcoinWalletConnector-BC92ulXx.js.map +1 -0
- package/lib/{BitcoinWalletAdapterConnector-Bq835yj0.mjs → BitcoinWalletConnector-CS0BshOl.mjs} +11 -19
- package/lib/BitcoinWalletConnector-CS0BshOl.mjs.map +1 -0
- package/lib/{BitcoinWalletAdapterConnector.d.ts → BitcoinWalletConnector.d.ts} +4 -5
- package/lib/BitgetWalletAdapter.impl-D8kqiYDi.mjs +11 -0
- package/lib/BitgetWalletAdapter.impl-D8kqiYDi.mjs.map +1 -0
- package/lib/BitgetWalletAdapter.impl-DiyzNQ9d.js +2 -0
- package/lib/BitgetWalletAdapter.impl-DiyzNQ9d.js.map +1 -0
- package/lib/{LeatherWalletAdapter.impl-RUYx555r.mjs → LeatherWalletAdapter.impl-B1PoZS7z.mjs} +48 -37
- package/lib/LeatherWalletAdapter.impl-B1PoZS7z.mjs.map +1 -0
- package/lib/LeatherWalletAdapter.impl-BIWirus3.js +2 -0
- package/lib/LeatherWalletAdapter.impl-BIWirus3.js.map +1 -0
- package/lib/{MagicEdenWalletAdapter.impl-CrA6SGvG.mjs → MagicEdenWalletAdapter.impl-B3d5lbkD.mjs} +31 -20
- package/lib/MagicEdenWalletAdapter.impl-B3d5lbkD.mjs.map +1 -0
- package/lib/MagicEdenWalletAdapter.impl-DLBP3p4o.js +2 -0
- package/lib/MagicEdenWalletAdapter.impl-DLBP3p4o.js.map +1 -0
- package/lib/OkxWalletAdapter.impl-7cj96tmr.js +2 -0
- package/lib/OkxWalletAdapter.impl-7cj96tmr.js.map +1 -0
- package/lib/{OkxWalletAdapter.impl-BepoUL1B.mjs → OkxWalletAdapter.impl-nRgHsPTn.mjs} +13 -9
- package/lib/OkxWalletAdapter.impl-nRgHsPTn.mjs.map +1 -0
- package/lib/{UnisatCompatibleWalletAdapterImpl-M38FqkZI.mjs → UnisatCompatibleWalletAdapterImpl-8lRRF7Zj.mjs} +18 -10
- package/lib/UnisatCompatibleWalletAdapterImpl-8lRRF7Zj.mjs.map +1 -0
- package/lib/{UnisatCompatibleWalletAdapterImpl-Cq2Oqk1b.js → UnisatCompatibleWalletAdapterImpl-C-JWrc9s.js} +2 -2
- package/lib/UnisatCompatibleWalletAdapterImpl-C-JWrc9s.js.map +1 -0
- package/lib/UnisatWalletAdapter.impl-DXDfnHz_.js +2 -0
- package/lib/UnisatWalletAdapter.impl-DXDfnHz_.js.map +1 -0
- package/lib/UnisatWalletAdapter.impl-DvA33Ikj.mjs +19 -0
- package/lib/UnisatWalletAdapter.impl-DvA33Ikj.mjs.map +1 -0
- package/lib/WalletAdapters.types-CExaiK0o.js +2 -0
- package/lib/WalletAdapters.types-CExaiK0o.js.map +1 -0
- package/lib/WalletAdapters.types-DBvhI1hu.mjs +20 -0
- package/lib/WalletAdapters.types-DBvhI1hu.mjs.map +1 -0
- package/lib/WalletAdapters.types.d.ts +7 -12
- package/lib/{XverseCompatibleWalletAdapterImpl-Bf-BK5VK.js → XverseCompatibleWalletAdapterImpl-Dp_GUxQM.js} +2 -2
- package/lib/XverseCompatibleWalletAdapterImpl-Dp_GUxQM.js.map +1 -0
- package/lib/{XverseCompatibleWalletAdapterImpl-DXKnO_-V.mjs → XverseCompatibleWalletAdapterImpl-bgp9xDYH.mjs} +12 -8
- package/lib/XverseCompatibleWalletAdapterImpl-bgp9xDYH.mjs.map +1 -0
- package/lib/{XverseWalletAdapter.impl-CZO0RQva.mjs → XverseWalletAdapter.impl-BOpY4Vf8.mjs} +15 -15
- package/lib/XverseWalletAdapter.impl-BOpY4Vf8.mjs.map +1 -0
- package/lib/XverseWalletAdapter.impl-D0eOtEOa.js +2 -0
- package/lib/XverseWalletAdapter.impl-D0eOtEOa.js.map +1 -0
- package/lib/adapters/BitgetWalletAdapter.d.ts +6 -2
- package/lib/adapters/LeatherWalletAdapter.d.ts +4 -2
- package/lib/adapters/LeatherWalletAdapter.impl.d.ts +8 -1
- package/lib/adapters/MagicEdenWalletAdapter.d.ts +5 -2
- package/lib/adapters/MagicEdenWalletAdapter.impl.d.ts +1 -1
- package/lib/adapters/MockAddressWalletAdapter.d.ts +8 -32
- package/lib/adapters/OkxWalletAdapter.d.ts +3 -2
- package/lib/adapters/OkxWalletAdapter.impl.d.ts +5 -1
- package/lib/adapters/UnisatWalletAdapter.d.ts +3 -2
- package/lib/adapters/UnisatWalletAdapter.impl.d.ts +4 -0
- package/lib/adapters/XverseWalletAdapter.d.ts +3 -2
- package/lib/adapters/XverseWalletAdapter.impl.d.ts +1 -1
- package/lib/adapters/index.d.ts +6 -6
- package/lib/adapters.js +1 -1
- package/lib/adapters.mjs +8 -8
- package/lib/constants-B7qVf97f.mjs +5 -0
- package/lib/constants-B7qVf97f.mjs.map +1 -0
- package/lib/constants-Dr0_Mix2.js +2 -0
- package/lib/constants-Dr0_Mix2.js.map +1 -0
- package/lib/constants.d.ts +1 -0
- package/lib/{index-D7YwhNAG.mjs → index-DM4G-LJz.mjs} +639 -590
- package/lib/index-DM4G-LJz.mjs.map +1 -0
- package/lib/index-jRY8YhyK.js +2 -0
- package/lib/index-jRY8YhyK.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.mjs +13 -13
- package/lib/react.js +1 -1
- package/lib/react.js.map +1 -1
- package/lib/react.mjs +7 -7
- package/lib/react.mjs.map +1 -1
- package/lib/{transaction-CiLOYSE_.mjs → transaction-4ShhFCwN.mjs} +2 -2
- package/lib/{transaction-CiLOYSE_.mjs.map → transaction-4ShhFCwN.mjs.map} +1 -1
- package/lib/{transaction-CzdnbXSo.js → transaction-B6SlpRzN.js} +2 -2
- package/lib/{transaction-CzdnbXSo.js.map → transaction-B6SlpRzN.js.map} +1 -1
- package/lib/utils/UnisatCompatibleWalletAdapterImpl.d.ts +11 -3
- package/lib/utils/XverseCompatibleWalletAdapterImpl.d.ts +4 -0
- package/lib/utils/XverseCompatibleWalletAdapterImpl_legacy.d.ts +7 -2
- package/package.json +9 -10
- package/src/BitcoinConnectionProvider.stories.tsx +111 -43
- package/src/BitcoinConnectionProvider.tsx +5 -5
- package/src/{BitcoinWalletAdapterConnector.ts → BitcoinWalletConnector.ts} +18 -26
- package/src/WalletAdapters.types.ts +13 -22
- package/src/adapters/BitgetWalletAdapter.impl.ts +2 -1
- package/src/adapters/BitgetWalletAdapter.ts +9 -7
- package/src/adapters/LeatherWalletAdapter.impl.ts +23 -13
- package/src/adapters/LeatherWalletAdapter.ts +11 -8
- package/src/adapters/MagicEdenWalletAdapter.impl.ts +9 -8
- package/src/adapters/MagicEdenWalletAdapter.ts +17 -14
- package/src/adapters/MockAddressWalletAdapter.ts +61 -35
- package/src/adapters/OkxWalletAdapter.impl.ts +12 -7
- package/src/adapters/OkxWalletAdapter.ts +10 -7
- package/src/adapters/UnisatWalletAdapter.impl.ts +8 -2
- package/src/adapters/UnisatWalletAdapter.ts +9 -7
- package/src/adapters/XverseWalletAdapter.impl.ts +6 -6
- package/src/adapters/XverseWalletAdapter.ts +10 -7
- package/src/adapters/index.ts +6 -6
- package/src/constants.ts +1 -0
- package/src/index.ts +1 -1
- package/src/utils/UnisatCompatibleWalletAdapterImpl.ts +11 -2
- package/src/utils/XverseCompatibleWalletAdapterImpl.ts +4 -0
- package/src/utils/XverseCompatibleWalletAdapterImpl_legacy.ts +19 -7
- package/lib/BitcoinWalletAdapterConnector-Bq835yj0.mjs.map +0 -1
- package/lib/BitcoinWalletAdapterConnector-DMef0iHV.js +0 -2
- package/lib/BitcoinWalletAdapterConnector-DMef0iHV.js.map +0 -1
- package/lib/BitgetWalletAdapter.impl-C_HLO7Oi.mjs +0 -10
- package/lib/BitgetWalletAdapter.impl-C_HLO7Oi.mjs.map +0 -1
- package/lib/BitgetWalletAdapter.impl-CxnKMf7U.js +0 -2
- package/lib/BitgetWalletAdapter.impl-CxnKMf7U.js.map +0 -1
- package/lib/LeatherWalletAdapter.impl-B2QgX_tO.js +0 -2
- package/lib/LeatherWalletAdapter.impl-B2QgX_tO.js.map +0 -1
- package/lib/LeatherWalletAdapter.impl-RUYx555r.mjs.map +0 -1
- package/lib/MagicEdenWalletAdapter.impl-CrA6SGvG.mjs.map +0 -1
- package/lib/MagicEdenWalletAdapter.impl-Di3Nu2S5.js +0 -2
- package/lib/MagicEdenWalletAdapter.impl-Di3Nu2S5.js.map +0 -1
- package/lib/OkxWalletAdapter.impl-BepoUL1B.mjs.map +0 -1
- package/lib/OkxWalletAdapter.impl-C8kesjGu.js +0 -2
- package/lib/OkxWalletAdapter.impl-C8kesjGu.js.map +0 -1
- package/lib/UnisatCompatibleWalletAdapterImpl-Cq2Oqk1b.js.map +0 -1
- package/lib/UnisatCompatibleWalletAdapterImpl-M38FqkZI.mjs.map +0 -1
- package/lib/UnisatWalletAdapter.impl-CJB22se8.mjs +0 -14
- package/lib/UnisatWalletAdapter.impl-CJB22se8.mjs.map +0 -1
- package/lib/UnisatWalletAdapter.impl-EISvxdpc.js +0 -2
- package/lib/UnisatWalletAdapter.impl-EISvxdpc.js.map +0 -1
- package/lib/WalletAdapters.types-CnvOqHFH.mjs +0 -32
- package/lib/WalletAdapters.types-CnvOqHFH.mjs.map +0 -1
- package/lib/WalletAdapters.types-De_x1lzr.js +0 -2
- package/lib/WalletAdapters.types-De_x1lzr.js.map +0 -1
- package/lib/XverseCompatibleWalletAdapterImpl-Bf-BK5VK.js.map +0 -1
- package/lib/XverseCompatibleWalletAdapterImpl-DXKnO_-V.mjs.map +0 -1
- package/lib/XverseWalletAdapter.impl-CZO0RQva.mjs.map +0 -1
- package/lib/XverseWalletAdapter.impl-lJwMi-Iv.js +0 -2
- package/lib/XverseWalletAdapter.impl-lJwMi-Iv.js.map +0 -1
- package/lib/index-D7YwhNAG.mjs.map +0 -1
- package/lib/index-Zx0KcpYx.js +0 -2
- package/lib/index-Zx0KcpYx.js.map +0 -1
|
@@ -2,14 +2,15 @@ import type { RequestFn } from "@leather.io/rpc"
|
|
|
2
2
|
import { createAvailability } from "../utils/createAdapterAvailability"
|
|
3
3
|
import type {
|
|
4
4
|
WalletAdapter,
|
|
5
|
-
|
|
5
|
+
WalletAdapterFactory,
|
|
6
|
+
WalletAdapterMetadata,
|
|
6
7
|
} from "../WalletAdapters.types"
|
|
7
8
|
|
|
8
|
-
const adapterId = "LeatherProvider.BitcoinProvider"
|
|
9
|
+
export const adapterId = "LeatherProvider.BitcoinProvider"
|
|
9
10
|
|
|
10
|
-
const metadata = {
|
|
11
|
+
export const metadata: WalletAdapterMetadata = {
|
|
11
12
|
name: "Leather",
|
|
12
|
-
iconUrl: import("../_/leather.svg").then(m => m.default),
|
|
13
|
+
iconUrl: () => import("../_/leather.svg").then(m => m.default),
|
|
13
14
|
websiteUrl: "https://leather.io/",
|
|
14
15
|
downloadUrl: "https://leather.io/wallet",
|
|
15
16
|
}
|
|
@@ -28,8 +29,10 @@ const availability = createAvailability<RequestFn, WalletAdapter>({
|
|
|
28
29
|
},
|
|
29
30
|
})
|
|
30
31
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
export function LeatherWalletAdapterFactory(): WalletAdapterFactory<WalletAdapter> {
|
|
33
|
+
return {
|
|
34
|
+
adapterId,
|
|
35
|
+
metadata,
|
|
36
|
+
getAdapter: () => availability,
|
|
37
|
+
}
|
|
35
38
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { hex } from "@scure/base"
|
|
2
2
|
import { addressToScriptPubKey } from "../utils/bitcoinAddressHelpers"
|
|
3
3
|
import { getBitcoinNetwork } from "../utils/bitcoinNetworkHelpers"
|
|
4
|
+
import {
|
|
5
|
+
XverseCompatibleWalletAdapterImpl_legacy,
|
|
6
|
+
XverseCompatibleWalletAdapterImplAddress,
|
|
7
|
+
} from "../utils/XverseCompatibleWalletAdapterImpl_legacy"
|
|
4
8
|
import {
|
|
5
9
|
WalletAdapter,
|
|
6
10
|
WalletAdapter_onAddressesChanged_callback,
|
|
@@ -8,11 +12,8 @@ import {
|
|
|
8
12
|
WalletAdapterAddressType,
|
|
9
13
|
WalletAdapterBitcoinNetwork,
|
|
10
14
|
} from "../WalletAdapters.types"
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
XverseCompatibleWalletAdapterImplAddress,
|
|
14
|
-
} from "../utils/XverseCompatibleWalletAdapterImpl_legacy"
|
|
15
|
-
import { MAGICEDEN_PROVIDER_ID } from "./MagicEdenWalletAdapter"
|
|
15
|
+
import { MAGICEDEN_PROVIDER_ID, metadata } from "./MagicEdenWalletAdapter"
|
|
16
|
+
import { LOCAL_STORAGE_KEY_PREFIX } from "../constants"
|
|
16
17
|
|
|
17
18
|
interface MagicEdenBitcoinProviderEvents {
|
|
18
19
|
accountsChanged: [
|
|
@@ -34,7 +35,7 @@ export interface MagicEdenBitcoinProvider {
|
|
|
34
35
|
) => void
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
const
|
|
38
|
+
const localStorageKeyPrefix = `${LOCAL_STORAGE_KEY_PREFIX}:${MAGICEDEN_PROVIDER_ID}`
|
|
38
39
|
|
|
39
40
|
export class MagicEdenWalletAdapterImpl
|
|
40
41
|
extends XverseCompatibleWalletAdapterImpl_legacy
|
|
@@ -48,8 +49,8 @@ export class MagicEdenWalletAdapterImpl
|
|
|
48
49
|
) {
|
|
49
50
|
super({
|
|
50
51
|
network,
|
|
51
|
-
|
|
52
|
-
walletDisplayName:
|
|
52
|
+
localStorageKeyPrefix,
|
|
53
|
+
walletDisplayName: metadata.name,
|
|
53
54
|
getProvider: async () => {
|
|
54
55
|
return provider as any
|
|
55
56
|
},
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
WalletAdapter,
|
|
3
3
|
WalletAdapterBitcoinNetwork,
|
|
4
|
-
|
|
4
|
+
WalletAdapterFactory,
|
|
5
|
+
WalletAdapterMetadata,
|
|
5
6
|
} from "../WalletAdapters.types"
|
|
6
7
|
import { createAvailability } from "../utils/createAdapterAvailability"
|
|
7
8
|
import type { MagicEdenBitcoinProvider } from "./MagicEdenWalletAdapter.impl"
|
|
@@ -16,6 +17,16 @@ declare global {
|
|
|
16
17
|
|
|
17
18
|
export const MAGICEDEN_PROVIDER_ID = "magiceden.bitcoin"
|
|
18
19
|
|
|
20
|
+
export const metadata: WalletAdapterMetadata = {
|
|
21
|
+
name: "Magic Eden",
|
|
22
|
+
/**
|
|
23
|
+
* https://docs-wallet.magiceden.io/resources/logos-and-brand-assets
|
|
24
|
+
*/
|
|
25
|
+
iconUrl: () => import("../_/magiceden.png").then(m => m.default),
|
|
26
|
+
websiteUrl: "https://wallet.magiceden.io/",
|
|
27
|
+
downloadUrl: "https://wallet.magiceden.io/download",
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
20
31
|
const buildAvailability = (network: WalletAdapterBitcoinNetwork) =>
|
|
21
32
|
createAvailability<MagicEdenBitcoinProvider, WalletAdapter>({
|
|
@@ -30,22 +41,14 @@ const buildAvailability = (network: WalletAdapterBitcoinNetwork) =>
|
|
|
30
41
|
},
|
|
31
42
|
})
|
|
32
43
|
|
|
33
|
-
export const MagicEdenWalletAdapterFactory = (
|
|
34
|
-
network: WalletAdapterBitcoinNetwork
|
|
35
|
-
):
|
|
36
|
-
const availability = buildAvailability(network)
|
|
44
|
+
export const MagicEdenWalletAdapterFactory = (options: {
|
|
45
|
+
network: WalletAdapterBitcoinNetwork
|
|
46
|
+
}): WalletAdapterFactory<WalletAdapter> => {
|
|
47
|
+
const availability = buildAvailability(options.network)
|
|
37
48
|
|
|
38
49
|
return {
|
|
39
50
|
adapterId: MAGICEDEN_PROVIDER_ID,
|
|
40
|
-
|
|
41
|
-
* https://docs-wallet.magiceden.io/resources/logos-and-brand-assets
|
|
42
|
-
*/
|
|
43
|
-
metadata: {
|
|
44
|
-
name: "Magic Eden",
|
|
45
|
-
iconUrl: import("../_/magiceden.png").then(m => m.default),
|
|
46
|
-
websiteUrl: "https://wallet.magiceden.io/",
|
|
47
|
-
downloadUrl: "https://wallet.magiceden.io/download",
|
|
48
|
-
},
|
|
51
|
+
metadata,
|
|
49
52
|
getAdapter: () => availability,
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -4,7 +4,11 @@ import {
|
|
|
4
4
|
addressToScriptPubKeyHex,
|
|
5
5
|
getAddressType,
|
|
6
6
|
} from "../utils/bitcoinAddressHelpers"
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
BitcoinNetwork,
|
|
9
|
+
getBitcoinNetwork,
|
|
10
|
+
isMainnet,
|
|
11
|
+
} from "../utils/bitcoinNetworkHelpers"
|
|
8
12
|
import { BitcoinWalletAdapterError } from "../utils/error"
|
|
9
13
|
import { checkNever } from "../utils/misc"
|
|
10
14
|
import {
|
|
@@ -15,6 +19,8 @@ import {
|
|
|
15
19
|
WalletAdapterAddressPurpose,
|
|
16
20
|
WalletAdapterAddressType,
|
|
17
21
|
WalletAdapterBitcoinNetwork,
|
|
22
|
+
WalletAdapterFactory,
|
|
23
|
+
WalletAdapterSendBitcoinCapability,
|
|
18
24
|
} from "../WalletAdapters.types"
|
|
19
25
|
|
|
20
26
|
const randomTapInternalKey =
|
|
@@ -27,15 +33,52 @@ const randomRedeemScript = hex.encode(
|
|
|
27
33
|
Script.encode(["OP_1", hex.decode(randomPublicKey), "OP_1", "CHECKMULTISIG"]),
|
|
28
34
|
)
|
|
29
35
|
|
|
30
|
-
export
|
|
36
|
+
export const MockAddressWalletAdapterFactory = (
|
|
37
|
+
network: WalletAdapterBitcoinNetwork,
|
|
38
|
+
mockedAdapter: WalletAdapterFactory<WalletAdapter>,
|
|
39
|
+
mockedAddresses: Partial<{
|
|
40
|
+
bitcoin: Partial<WalletAdapterAddress> & { address: string }
|
|
41
|
+
ordinals: Partial<WalletAdapterAddress> & { address: string }
|
|
42
|
+
}>,
|
|
43
|
+
): WalletAdapterFactory<WalletAdapter> => {
|
|
44
|
+
return {
|
|
45
|
+
adapterId: `mocked.${mockedAdapter.adapterId}`,
|
|
46
|
+
metadata: {
|
|
47
|
+
...mockedAdapter.metadata,
|
|
48
|
+
name: `Mocked ${mockedAdapter.metadata.name}`,
|
|
49
|
+
},
|
|
50
|
+
getAdapter() {
|
|
51
|
+
const availability = mockedAdapter.getAdapter()
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
subscribe(listener) {
|
|
55
|
+
return availability.subscribe(adapter => {
|
|
56
|
+
listener(
|
|
57
|
+
new MockAddressWalletAdapter(network, adapter, mockedAddresses),
|
|
58
|
+
)
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class MockAddressWalletAdapter implements WalletAdapter {
|
|
67
|
+
private network: BitcoinNetwork
|
|
68
|
+
|
|
31
69
|
constructor(
|
|
32
|
-
|
|
70
|
+
network: WalletAdapterBitcoinNetwork,
|
|
33
71
|
private inner: WalletAdapter,
|
|
34
72
|
private addresses: Partial<{
|
|
35
73
|
bitcoin: Partial<WalletAdapterAddress> & { address: string }
|
|
36
74
|
ordinals: Partial<WalletAdapterAddress> & { address: string }
|
|
37
75
|
}>,
|
|
38
|
-
) {
|
|
76
|
+
) {
|
|
77
|
+
this.network =
|
|
78
|
+
network === WalletAdapterBitcoinNetwork.TESTNET
|
|
79
|
+
? getBitcoinNetwork("testnet")
|
|
80
|
+
: getBitcoinNetwork("mainnet")
|
|
81
|
+
}
|
|
39
82
|
|
|
40
83
|
async connect(): Promise<void> {
|
|
41
84
|
await this.inner.connect()
|
|
@@ -149,37 +192,6 @@ export class MockAddressWalletAdapter implements WalletAdapter {
|
|
|
149
192
|
)
|
|
150
193
|
}
|
|
151
194
|
|
|
152
|
-
get sendBitcoinFeeRateCapability(): "unavailable" | "available" | "required" {
|
|
153
|
-
return this.inner.sendBitcoinFeeRateCapability
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
get sendInscriptionFeeRateCapability():
|
|
157
|
-
| "unavailable"
|
|
158
|
-
| "available"
|
|
159
|
-
| "required" {
|
|
160
|
-
return this.inner.sendInscriptionFeeRateCapability
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
sendBitcoin(
|
|
164
|
-
fromAddress: string,
|
|
165
|
-
receiverAddress: string,
|
|
166
|
-
satoshiAmount: bigint,
|
|
167
|
-
): Promise<{ txid: string }> {
|
|
168
|
-
throw new BitcoinWalletAdapterError(
|
|
169
|
-
`[MockAddressWalletAdapter] it's a mock adapter, can't send bitcoin`,
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
sendInscription(
|
|
174
|
-
fromAddress: string,
|
|
175
|
-
receiverAddress: string,
|
|
176
|
-
inscriptionId: string,
|
|
177
|
-
): Promise<{ txid: string }> {
|
|
178
|
-
throw new BitcoinWalletAdapterError(
|
|
179
|
-
`[MockAddressWalletAdapter] it's a mock adapter, can't send inscription`,
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
195
|
signAndFinalizePsbt(psbtHex: string): Promise<{ signedPsbtHex: string }> {
|
|
184
196
|
throw new BitcoinWalletAdapterError(
|
|
185
197
|
`[MockAddressWalletAdapter] it's a mock adapter, can't sign transaction`,
|
|
@@ -196,4 +208,18 @@ export class MockAddressWalletAdapter implements WalletAdapter {
|
|
|
196
208
|
},
|
|
197
209
|
}
|
|
198
210
|
}
|
|
211
|
+
|
|
212
|
+
get sendBitcoinFeeRateCapability(): WalletAdapterSendBitcoinCapability {
|
|
213
|
+
return this.inner.sendBitcoinFeeRateCapability
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
sendBitcoin(
|
|
217
|
+
fromAddress: string,
|
|
218
|
+
receiverAddress: string,
|
|
219
|
+
satoshiAmount: bigint,
|
|
220
|
+
): Promise<{ txid: string }> {
|
|
221
|
+
throw new BitcoinWalletAdapterError(
|
|
222
|
+
`[MockAddressWalletAdapter] it's a mock adapter, can't send bitcoin`,
|
|
223
|
+
)
|
|
224
|
+
}
|
|
199
225
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
SignMessageResult,
|
|
4
|
-
WalletAdapter,
|
|
5
|
-
WalletAdapter_onAddressesChanged_callback,
|
|
6
|
-
} from "../WalletAdapters.types"
|
|
1
|
+
import { BitcoinWalletAdapterError, UserRejectError } from "../utils/error"
|
|
7
2
|
import {
|
|
8
3
|
UniSatEvents,
|
|
9
4
|
UnisatCompatibleProviderAPI,
|
|
10
5
|
UnisatCompatibleWalletAdapterImpl,
|
|
11
6
|
} from "../utils/UnisatCompatibleWalletAdapterImpl"
|
|
7
|
+
import {
|
|
8
|
+
SignMessageResult,
|
|
9
|
+
WalletAdapter,
|
|
10
|
+
WalletAdapter_onAddressesChanged_callback,
|
|
11
|
+
} from "../WalletAdapters.types"
|
|
12
|
+
import { metadata } from "./LeatherWalletAdapter"
|
|
12
13
|
|
|
13
14
|
enum RpcErrorCode {
|
|
14
15
|
PARSE_ERROR = -32700,
|
|
@@ -56,7 +57,7 @@ export class OkxWalletAdapterImpl
|
|
|
56
57
|
*
|
|
57
58
|
* https://web3.okx.com/zh-hans/build/dev-docs/sdks/chains/bitcoin/provider
|
|
58
59
|
*/
|
|
59
|
-
super(provider,
|
|
60
|
+
super(provider, metadata.name)
|
|
60
61
|
this.okxwallet = provider
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -86,6 +87,10 @@ export class OkxWalletAdapterImpl
|
|
|
86
87
|
)
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/**
|
|
91
|
+
* @internal
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
89
94
|
async sendInscription(
|
|
90
95
|
fromAddress: string,
|
|
91
96
|
receiverAddress: string,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
WalletAdapter,
|
|
3
|
-
|
|
3
|
+
WalletAdapterFactory,
|
|
4
|
+
WalletAdapterMetadata,
|
|
4
5
|
} from "../WalletAdapters.types"
|
|
5
6
|
import type { UnisatCompatibleProviderAPI } from "../utils/UnisatCompatibleWalletAdapterImpl"
|
|
6
7
|
import { createAvailability } from "../utils/createAdapterAvailability"
|
|
7
8
|
|
|
8
9
|
const adapterId = "okxwallet.bitcoin"
|
|
9
10
|
|
|
10
|
-
const metadata = {
|
|
11
|
+
export const metadata: WalletAdapterMetadata = {
|
|
11
12
|
name: "OKX Wallet",
|
|
12
|
-
iconUrl: import("../_/okx.png").then(m => m.default),
|
|
13
|
+
iconUrl: () => import("../_/okx.png").then(m => m.default),
|
|
13
14
|
websiteUrl: "https://web3.okx.com/",
|
|
14
15
|
downloadUrl: "https://web3.okx.com/download",
|
|
15
16
|
}
|
|
@@ -30,8 +31,10 @@ const availability = createAvailability<
|
|
|
30
31
|
},
|
|
31
32
|
})
|
|
32
33
|
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
export function OkxWalletAdapterFactory(): WalletAdapterFactory<WalletAdapter> {
|
|
35
|
+
return {
|
|
36
|
+
adapterId,
|
|
37
|
+
metadata,
|
|
38
|
+
getAdapter: () => availability,
|
|
39
|
+
}
|
|
37
40
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
UnisatCompatibleWalletAdapterImpl,
|
|
4
4
|
} from "../utils/UnisatCompatibleWalletAdapterImpl"
|
|
5
5
|
import { WalletAdapter } from "../WalletAdapters.types"
|
|
6
|
+
import { metadata } from "./UnisatWalletAdapter"
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Derivation path (Native SegWit) (BIP-84): m/84'/0'/0'/0/address_index
|
|
@@ -21,12 +22,17 @@ export class UnisatWalletAdapterImpl
|
|
|
21
22
|
*
|
|
22
23
|
* https://docs.unisat.io/dev/unisat-developer-service/unisat-wallet
|
|
23
24
|
*/
|
|
24
|
-
super(provider,
|
|
25
|
+
super(provider, metadata.name)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
sendBitcoinFeeRateCapability = "required" as const
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
* @experimental
|
|
33
|
+
*/
|
|
34
|
+
sendInscriptionFeeRateCapability = "unavailable" as const
|
|
35
|
+
|
|
29
36
|
// The default fee rate of unisat is not aligned with mempool.space, so
|
|
30
37
|
// sometimes the tx will be rejected by mempool due to uneligible network fee.
|
|
31
|
-
sendInscriptionFeeRateCapability = "unavailable" as const
|
|
32
38
|
}
|
|
@@ -3,7 +3,7 @@ import type { UnisatCompatibleProviderAPI } from "../utils/UnisatCompatibleWalle
|
|
|
3
3
|
import type {
|
|
4
4
|
WalletAdapter,
|
|
5
5
|
WalletAdapterMetadata,
|
|
6
|
-
|
|
6
|
+
WalletAdapterFactory,
|
|
7
7
|
} from "../WalletAdapters.types"
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -16,12 +16,12 @@ import type {
|
|
|
16
16
|
|
|
17
17
|
const adapterId = "unisat"
|
|
18
18
|
|
|
19
|
-
const metadata: WalletAdapterMetadata = {
|
|
19
|
+
export const metadata: WalletAdapterMetadata = {
|
|
20
20
|
name: "UniSat",
|
|
21
21
|
/**
|
|
22
22
|
* https://next-cdn.unisat.io/_/2025-v965/UniSat%20Logo.zip
|
|
23
23
|
*/
|
|
24
|
-
iconUrl: import("../_/unisat.svg").then(m => m.default),
|
|
24
|
+
iconUrl: () => import("../_/unisat.svg").then(m => m.default),
|
|
25
25
|
websiteUrl: "https://unisat.io/",
|
|
26
26
|
downloadUrl: "https://unisat.io/download",
|
|
27
27
|
}
|
|
@@ -43,8 +43,10 @@ const availability = createAvailability<
|
|
|
43
43
|
},
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
export function UnisatWalletAdapterFactory(): WalletAdapterFactory<WalletAdapter> {
|
|
47
|
+
return {
|
|
48
|
+
adapterId,
|
|
49
|
+
metadata,
|
|
50
|
+
getAdapter: () => availability,
|
|
51
|
+
}
|
|
50
52
|
}
|
|
@@ -5,17 +5,17 @@ import {
|
|
|
5
5
|
} from "../utils/bitcoinAddressHelpers"
|
|
6
6
|
import { getBitcoinNetwork } from "../utils/bitcoinNetworkHelpers"
|
|
7
7
|
import { checkNever } from "../utils/misc"
|
|
8
|
+
import {
|
|
9
|
+
XverseCompatibleWalletAdapterImpl,
|
|
10
|
+
XverseCompatibleWalletAdapterImplAddress,
|
|
11
|
+
} from "../utils/XverseCompatibleWalletAdapterImpl"
|
|
8
12
|
import {
|
|
9
13
|
WalletAdapter,
|
|
10
14
|
WalletAdapterAddressPurpose,
|
|
11
15
|
WalletAdapterAddressType,
|
|
12
16
|
WalletAdapterBitcoinNetwork,
|
|
13
17
|
} from "../WalletAdapters.types"
|
|
14
|
-
import {
|
|
15
|
-
XverseCompatibleWalletAdapterImpl,
|
|
16
|
-
XverseCompatibleWalletAdapterImplAddress,
|
|
17
|
-
} from "../utils/XverseCompatibleWalletAdapterImpl"
|
|
18
|
-
import { XVERSE_PROVIDER_ID } from "./XverseWalletAdapter"
|
|
18
|
+
import { metadata, XVERSE_PROVIDER_ID } from "./XverseWalletAdapter"
|
|
19
19
|
|
|
20
20
|
declare global {
|
|
21
21
|
interface Window {
|
|
@@ -36,7 +36,7 @@ export class XverseWalletAdapterImpl
|
|
|
36
36
|
{
|
|
37
37
|
constructor() {
|
|
38
38
|
super({
|
|
39
|
-
walletDisplayName:
|
|
39
|
+
walletDisplayName: metadata.name,
|
|
40
40
|
getProviderId: async () => {
|
|
41
41
|
return XVERSE_PROVIDER_ID
|
|
42
42
|
},
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
WalletAdapter,
|
|
3
|
-
|
|
3
|
+
WalletAdapterFactory,
|
|
4
|
+
WalletAdapterMetadata,
|
|
4
5
|
} from "../WalletAdapters.types"
|
|
5
6
|
import { createAvailability } from "../utils/createAdapterAvailability"
|
|
6
7
|
|
|
7
8
|
export const XVERSE_PROVIDER_ID = "XverseProviders.BitcoinProvider"
|
|
8
9
|
|
|
9
|
-
const metadata = {
|
|
10
|
+
export const metadata: WalletAdapterMetadata = {
|
|
10
11
|
name: "Xverse",
|
|
11
|
-
iconUrl: import("../_/xverse.png").then(m => m.default),
|
|
12
|
+
iconUrl: () => import("../_/xverse.png").then(m => m.default),
|
|
12
13
|
websiteUrl: "https://xverse.app/",
|
|
13
14
|
downloadUrl: "https://www.xverse.app/download",
|
|
14
15
|
}
|
|
@@ -30,8 +31,10 @@ const availability = createAvailability<
|
|
|
30
31
|
},
|
|
31
32
|
})
|
|
32
33
|
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
export function XverseWalletAdapterFactory(): WalletAdapterFactory<WalletAdapter> {
|
|
35
|
+
return {
|
|
36
|
+
adapterId: XVERSE_PROVIDER_ID,
|
|
37
|
+
metadata,
|
|
38
|
+
getAdapter: () => availability,
|
|
39
|
+
}
|
|
37
40
|
}
|
package/src/adapters/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { BitgetWalletAdapterFactory } from "./BitgetWalletAdapter"
|
|
2
|
+
export { LeatherWalletAdapterFactory } from "./LeatherWalletAdapter"
|
|
3
3
|
export { MagicEdenWalletAdapterFactory } from "./MagicEdenWalletAdapter"
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
4
|
+
export { MockAddressWalletAdapterFactory } from "./MockAddressWalletAdapter"
|
|
5
|
+
export { OkxWalletAdapterFactory } from "./OkxWalletAdapter"
|
|
6
|
+
export { UnisatWalletAdapterFactory } from "./UnisatWalletAdapter"
|
|
7
|
+
export { XverseWalletAdapterFactory } from "./XverseWalletAdapter"
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LOCAL_STORAGE_KEY_PREFIX = "bitcoin-wallet-connector"
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
WalletAdapterAddressType,
|
|
20
20
|
WalletAdapterBitcoinNetwork,
|
|
21
21
|
WalletAdapterNotConnectedError,
|
|
22
|
+
WalletAdapterSendBitcoinCapability,
|
|
22
23
|
} from "../WalletAdapters.types"
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -214,7 +215,7 @@ export class UnisatCompatibleWalletAdapterImpl implements WalletAdapter {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
sendBitcoinFeeRateCapability:
|
|
218
|
+
sendBitcoinFeeRateCapability: WalletAdapterSendBitcoinCapability =
|
|
218
219
|
"available" as const
|
|
219
220
|
async sendBitcoin(
|
|
220
221
|
fromAddress: string,
|
|
@@ -230,8 +231,16 @@ export class UnisatCompatibleWalletAdapterImpl implements WalletAdapter {
|
|
|
230
231
|
return { txid }
|
|
231
232
|
}
|
|
232
233
|
|
|
233
|
-
|
|
234
|
+
/**
|
|
235
|
+
* @internal
|
|
236
|
+
* @experimental
|
|
237
|
+
*/
|
|
238
|
+
sendInscriptionFeeRateCapability: "unavailable" | "available" | "required" =
|
|
234
239
|
"available" as const
|
|
240
|
+
/**
|
|
241
|
+
* @internal
|
|
242
|
+
* @experimental
|
|
243
|
+
*/
|
|
235
244
|
async sendInscription(
|
|
236
245
|
fromAddress: string,
|
|
237
246
|
receiverAddress: string,
|
|
@@ -33,20 +33,20 @@ export type XverseCompatibleWalletAdapterImplAddress = WalletAdapterAddress & {
|
|
|
33
33
|
|
|
34
34
|
export class XverseCompatibleWalletAdapterImpl_legacy implements WalletAdapter {
|
|
35
35
|
protected readonly network: WalletAdapterBitcoinNetwork
|
|
36
|
-
protected readonly
|
|
36
|
+
protected readonly localStorageKeyPrefix: string
|
|
37
37
|
protected readonly walletDisplayName: string
|
|
38
38
|
protected readonly getProvider: XverseCompatibleWalletAdapterGetProviderFn
|
|
39
39
|
protected readonly parseAddresses: XverseCompatibleWalletAdapterParsedAddressesFn
|
|
40
40
|
|
|
41
41
|
constructor(info: {
|
|
42
42
|
network: WalletAdapterBitcoinNetwork
|
|
43
|
-
|
|
43
|
+
localStorageKeyPrefix: string
|
|
44
44
|
walletDisplayName: string
|
|
45
45
|
getProvider: XverseCompatibleWalletAdapterGetProviderFn
|
|
46
46
|
parseAddresses: XverseCompatibleWalletAdapterParsedAddressesFn
|
|
47
47
|
}) {
|
|
48
48
|
this.network = info.network
|
|
49
|
-
this.
|
|
49
|
+
this.localStorageKeyPrefix = info.localStorageKeyPrefix
|
|
50
50
|
this.walletDisplayName = info.walletDisplayName
|
|
51
51
|
this.getProvider = info.getProvider
|
|
52
52
|
this.parseAddresses = info.parseAddresses
|
|
@@ -56,9 +56,14 @@ export class XverseCompatibleWalletAdapterImpl_legacy implements WalletAdapter {
|
|
|
56
56
|
return import("sats-connect")
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
protected get connectAddresses_localStorageKey(): string {
|
|
60
|
+
return `${this.localStorageKeyPrefix}:connectedAddresses`
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
protected retrieveConnectedAddress(): GetAddressResponse | undefined {
|
|
60
64
|
let resp: GetAddressResponse | undefined
|
|
61
|
-
const stored =
|
|
65
|
+
const stored =
|
|
66
|
+
localStorage.getItem(this.connectAddresses_localStorageKey) || undefined
|
|
62
67
|
if (stored != null) {
|
|
63
68
|
try {
|
|
64
69
|
resp = JSON.parse(stored)
|
|
@@ -70,7 +75,7 @@ export class XverseCompatibleWalletAdapterImpl_legacy implements WalletAdapter {
|
|
|
70
75
|
throw new Error("Invalid stored addresses")
|
|
71
76
|
}
|
|
72
77
|
} catch {
|
|
73
|
-
localStorage.removeItem(this.
|
|
78
|
+
localStorage.removeItem(this.connectAddresses_localStorageKey)
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
return resp
|
|
@@ -78,7 +83,10 @@ export class XverseCompatibleWalletAdapterImpl_legacy implements WalletAdapter {
|
|
|
78
83
|
protected async updateConnectedAddress(
|
|
79
84
|
addresses: GetAddressResponse["addresses"],
|
|
80
85
|
): Promise<void> {
|
|
81
|
-
localStorage.setItem(
|
|
86
|
+
localStorage.setItem(
|
|
87
|
+
this.connectAddresses_localStorageKey,
|
|
88
|
+
JSON.stringify({ addresses }),
|
|
89
|
+
)
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
async connect(): Promise<void> {
|
|
@@ -116,7 +124,7 @@ export class XverseCompatibleWalletAdapterImpl_legacy implements WalletAdapter {
|
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
async disconnect(): Promise<void> {
|
|
119
|
-
localStorage.removeItem(this.
|
|
127
|
+
localStorage.removeItem(this.connectAddresses_localStorageKey)
|
|
120
128
|
return Promise.resolve()
|
|
121
129
|
}
|
|
122
130
|
|
|
@@ -218,6 +226,10 @@ export class XverseCompatibleWalletAdapterImpl_legacy implements WalletAdapter {
|
|
|
218
226
|
})
|
|
219
227
|
}
|
|
220
228
|
|
|
229
|
+
/**
|
|
230
|
+
* @internal
|
|
231
|
+
* @experimental
|
|
232
|
+
*/
|
|
221
233
|
sendInscriptionFeeRateCapability = "unavailable" as const
|
|
222
234
|
|
|
223
235
|
async signAndFinalizePsbt(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinWalletAdapterConnector-Bq835yj0.mjs","sources":["../src/utils/StateChannel.ts","../src/BitcoinWalletAdapterConnector.ts"],"sourcesContent":["export type StateChannelListener<T> = (value: T) => void\n\nexport interface StateChannelSubscription {\n unsubscribe: () => void\n}\n\nexport class StateChannel<T> {\n private listeners = new Set<StateChannelListener<T>>()\n constructor(private value: T) {}\n\n getValue(): T {\n return this.value\n }\n\n setValue(value: T): void {\n this.value = value\n this.emit()\n }\n\n update(updater: (current: T) => T): void {\n this.setValue(updater(this.value))\n }\n\n subscribe(listener: StateChannelListener<T>): StateChannelSubscription {\n this.listeners.add(listener)\n listener(this.value)\n return {\n unsubscribe: () => {\n this.listeners.delete(listener)\n },\n }\n }\n\n private emit(): void {\n for (const listener of this.listeners) {\n listener(this.value)\n }\n }\n}\n","import { AvailabilitySubscription } from \"./utils/createAdapterAvailability\"\nimport { BitcoinWalletAdapterError } from \"./utils/error\"\nimport { StateChannel, StateChannelListener } from \"./utils/StateChannel\"\nimport {\n WalletAdapter,\n WalletAdapterNotConnectedError,\n WalletAdapterStatic,\n} from \"./WalletAdapters.types\"\n\nconst previousConnectWalletAdapterIdLocalStorageKey =\n \"app:BitcoinWalletAdapterConnector:previousConnectWallet\"\n\nexport interface ConnectInfo {\n adapterId: string\n adapter: WalletAdapter\n}\n\nexport type AdapterEntry = readonly [string, WalletAdapter]\n\nexport class BitcoinWalletAdapterConnector {\n private availableAdaptersState = new StateChannel<AdapterEntry[]>([])\n private connectedInfoState = new StateChannel<null | ConnectInfo>(null)\n private autoConnectRunning = false\n private availabilitySubscriptions: AvailabilitySubscription[] = []\n private adapterOrder = new Map<string, number>()\n\n constructor(private Adapters: WalletAdapterStatic<WalletAdapter>[]) {\n this.adapterOrder = new Map(\n Adapters.map((adapter, index) => [adapter.adapterId, index]),\n )\n this.initializeAdapterAvailability()\n }\n\n dispose(): void {\n this.availabilitySubscriptions.forEach(s => s.unsubscribe())\n this.availabilitySubscriptions = []\n this.availableAdaptersState = new StateChannel<AdapterEntry[]>([])\n this.connectedInfoState = new StateChannel<null | ConnectInfo>(null)\n }\n\n subscribeAvailableAdapters(\n listener: StateChannelListener<AdapterEntry[]>,\n ): AvailabilitySubscription {\n return this.availableAdaptersState.subscribe(listener)\n }\n getAvailableAdapters(): AdapterEntry[] {\n return this.availableAdaptersState.getValue()\n }\n\n subscribeConnectedInfo(\n listener: StateChannelListener<null | ConnectInfo>,\n ): AvailabilitySubscription {\n return this.connectedInfoState.subscribe(listener)\n }\n getConnectedInfo(): null | ConnectInfo {\n return this.connectedInfoState.getValue()\n }\n\n private initializeAdapterAvailability(): void {\n this.availabilitySubscriptions = this.Adapters.map(Adapter => {\n return Adapter.getAdapter().subscribe(adapter => {\n this.addOrUpdateAvailableAdapter(Adapter.adapterId, adapter)\n })\n })\n }\n\n private addOrUpdateAvailableAdapter(\n adapterId: string,\n adapter: WalletAdapter,\n ): void {\n this.availableAdaptersState.update(current => {\n const next = [...current]\n const existingIndex = current.findIndex(([id]) => id === adapterId)\n if (existingIndex === -1) {\n next.push([adapterId, adapter] as const)\n } else {\n next[existingIndex] = [adapterId, adapter] as const\n }\n\n next.sort(\n (a, b) =>\n (this.adapterOrder.get(a[0]) ?? Number.MAX_SAFE_INTEGER) -\n (this.adapterOrder.get(b[0]) ?? Number.MAX_SAFE_INTEGER),\n )\n return next\n })\n\n void this.autoConnect()\n }\n\n async connect(adapterId: string, adapter: WalletAdapter): Promise<void> {\n const finalAdapter = adapter\n\n await finalAdapter.connect().catch(err => {\n if (err instanceof BitcoinWalletAdapterError) {\n alert(err.message)\n return\n }\n throw err\n })\n\n localStorage.setItem(\n previousConnectWalletAdapterIdLocalStorageKey,\n adapterId,\n )\n\n this.connectedInfoState.setValue({ adapterId, adapter: finalAdapter })\n }\n\n async disconnect(): Promise<void> {\n const info = this.connectedInfoState.getValue()\n if (info == null) return\n await this.disconnectAdapter(info.adapter)\n this.connectedInfoState.setValue(null)\n }\n private async disconnectAdapter(adapter: WalletAdapter): Promise<void> {\n await adapter.disconnect()\n localStorage.removeItem(previousConnectWalletAdapterIdLocalStorageKey)\n }\n\n private async autoConnect(): Promise<void> {\n if (this.isConnected || this.autoConnectRunning) return\n\n const previousAdapterId = this.previousConnectedWallet\n if (previousAdapterId == null) return\n\n const adapter = this.availableAdaptersState\n .getValue()\n .find(a => a[0] === previousAdapterId)?.[1]\n if (adapter == null) return\n\n this.autoConnectRunning = true\n try {\n await adapter.getAddresses()\n } catch (err: unknown) {\n if (err instanceof WalletAdapterNotConnectedError) {\n this.autoConnectRunning = false\n return\n }\n\n this.autoConnectRunning = false\n throw err\n }\n\n try {\n await this.connect(previousAdapterId, adapter)\n } finally {\n this.autoConnectRunning = false\n }\n }\n\n private get previousConnectedWallet(): string | undefined {\n const adapterId =\n localStorage.getItem(previousConnectWalletAdapterIdLocalStorageKey) ||\n undefined\n\n if (this.Adapters.some(adapter => adapter.adapterId === adapterId)) {\n return adapterId\n }\n return undefined\n }\n\n private get isConnected(): boolean {\n return this.connectedInfoState.getValue() != null\n }\n}\n"],"names":["StateChannel","value","updater","listener","previousConnectWalletAdapterIdLocalStorageKey","BitcoinWalletAdapterConnector","Adapters","adapter","index","s","Adapter","adapterId","current","next","existingIndex","id","a","b","finalAdapter","err","BitcoinWalletAdapterError","info","previousAdapterId","WalletAdapterNotConnectedError"],"mappings":";AAMO,MAAMA,EAAgB;AAAA,EAE3B,YAAoBC,GAAU;AAAV,SAAA,QAAAA;AAAA,EAAW;AAAA,EADvB,gCAAgB,IAAA;AAAA,EAGxB,WAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAASA,GAAgB;AACvB,SAAK,QAAQA,GACb,KAAK,KAAA;AAAA,EACP;AAAA,EAEA,OAAOC,GAAkC;AACvC,SAAK,SAASA,EAAQ,KAAK,KAAK,CAAC;AAAA,EACnC;AAAA,EAEA,UAAUC,GAA6D;AACrE,gBAAK,UAAU,IAAIA,CAAQ,GAC3BA,EAAS,KAAK,KAAK,GACZ;AAAA,MACL,aAAa,MAAM;AACjB,aAAK,UAAU,OAAOA,CAAQ;AAAA,MAChC;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEQ,OAAa;AACnB,eAAWA,KAAY,KAAK;AAC1B,MAAAA,EAAS,KAAK,KAAK;AAAA,EAEvB;AACF;AC7BA,MAAMC,IACJ;AASK,MAAMC,EAA8B;AAAA,EAOzC,YAAoBC,GAAgD;AAAhD,SAAA,WAAAA,GAClB,KAAK,eAAe,IAAI;AAAA,MACtBA,EAAS,IAAI,CAACC,GAASC,MAAU,CAACD,EAAQ,WAAWC,CAAK,CAAC;AAAA,IAAA,GAE7D,KAAK,8BAAA;AAAA,EACP;AAAA,EAXQ,yBAAyB,IAAIR,EAA6B,EAAE;AAAA,EAC5D,qBAAqB,IAAIA,EAAiC,IAAI;AAAA,EAC9D,qBAAqB;AAAA,EACrB,4BAAwD,CAAA;AAAA,EACxD,mCAAmB,IAAA;AAAA,EAS3B,UAAgB;AACd,SAAK,0BAA0B,QAAQ,CAAAS,MAAKA,EAAE,aAAa,GAC3D,KAAK,4BAA4B,CAAA,GACjC,KAAK,yBAAyB,IAAIT,EAA6B,EAAE,GACjE,KAAK,qBAAqB,IAAIA,EAAiC,IAAI;AAAA,EACrE;AAAA,EAEA,2BACEG,GAC0B;AAC1B,WAAO,KAAK,uBAAuB,UAAUA,CAAQ;AAAA,EACvD;AAAA,EACA,uBAAuC;AACrC,WAAO,KAAK,uBAAuB,SAAA;AAAA,EACrC;AAAA,EAEA,uBACEA,GAC0B;AAC1B,WAAO,KAAK,mBAAmB,UAAUA,CAAQ;AAAA,EACnD;AAAA,EACA,mBAAuC;AACrC,WAAO,KAAK,mBAAmB,SAAA;AAAA,EACjC;AAAA,EAEQ,gCAAsC;AAC5C,SAAK,4BAA4B,KAAK,SAAS,IAAI,CAAAO,MAC1CA,EAAQ,WAAA,EAAa,UAAU,CAAAH,MAAW;AAC/C,WAAK,4BAA4BG,EAAQ,WAAWH,CAAO;AAAA,IAC7D,CAAC,CACF;AAAA,EACH;AAAA,EAEQ,4BACNI,GACAJ,GACM;AACN,SAAK,uBAAuB,OAAO,CAAAK,MAAW;AAC5C,YAAMC,IAAO,CAAC,GAAGD,CAAO,GAClBE,IAAgBF,EAAQ,UAAU,CAAC,CAACG,CAAE,MAAMA,MAAOJ,CAAS;AAClE,aAAIG,MAAkB,KACpBD,EAAK,KAAK,CAACF,GAAWJ,CAAO,CAAU,IAEvCM,EAAKC,CAAa,IAAI,CAACH,GAAWJ,CAAO,GAG3CM,EAAK;AAAA,QACH,CAACG,GAAGC,OACD,KAAK,aAAa,IAAID,EAAE,CAAC,CAAC,KAAK,OAAO,qBACtC,KAAK,aAAa,IAAIC,EAAE,CAAC,CAAC,KAAK,OAAO;AAAA,MAAA,GAEpCJ;AAAA,IACT,CAAC,GAEI,KAAK,YAAA;AAAA,EACZ;AAAA,EAEA,MAAM,QAAQF,GAAmBJ,GAAuC;AACtE,UAAMW,IAAeX;AAErB,UAAMW,EAAa,QAAA,EAAU,MAAM,CAAAC,MAAO;AACxC,UAAIA,aAAeC,GAA2B;AAC5C,cAAMD,EAAI,OAAO;AACjB;AAAA,MACF;AACA,YAAMA;AAAA,IACR,CAAC,GAED,aAAa;AAAA,MACXf;AAAA,MACAO;AAAA,IAAA,GAGF,KAAK,mBAAmB,SAAS,EAAE,WAAAA,GAAW,SAASO,GAAc;AAAA,EACvE;AAAA,EAEA,MAAM,aAA4B;AAChC,UAAMG,IAAO,KAAK,mBAAmB,SAAA;AACrC,IAAIA,KAAQ,SACZ,MAAM,KAAK,kBAAkBA,EAAK,OAAO,GACzC,KAAK,mBAAmB,SAAS,IAAI;AAAA,EACvC;AAAA,EACA,MAAc,kBAAkBd,GAAuC;AACrE,UAAMA,EAAQ,WAAA,GACd,aAAa,WAAWH,CAA6C;AAAA,EACvE;AAAA,EAEA,MAAc,cAA6B;AACzC,QAAI,KAAK,eAAe,KAAK,mBAAoB;AAEjD,UAAMkB,IAAoB,KAAK;AAC/B,QAAIA,KAAqB,KAAM;AAE/B,UAAMf,IAAU,KAAK,uBAClB,SAAA,EACA,KAAK,CAAA,MAAK,EAAE,CAAC,MAAMe,CAAiB,IAAI,CAAC;AAC5C,QAAIf,KAAW,MAEf;AAAA,WAAK,qBAAqB;AAC1B,UAAI;AACF,cAAMA,EAAQ,aAAA;AAAA,MAChB,SAASY,GAAc;AACrB,YAAIA,aAAeI,GAAgC;AACjD,eAAK,qBAAqB;AAC1B;AAAA,QACF;AAEA,mBAAK,qBAAqB,IACpBJ;AAAA,MACR;AAEA,UAAI;AACF,cAAM,KAAK,QAAQG,GAAmBf,CAAO;AAAA,MAC/C,UAAA;AACE,aAAK,qBAAqB;AAAA,MAC5B;AAAA;AAAA,EACF;AAAA,EAEA,IAAY,0BAA8C;AACxD,UAAMI,IACJ,aAAa,QAAQP,CAA6C,KAClE;AAEF,QAAI,KAAK,SAAS,KAAK,OAAWG,EAAQ,cAAcI,CAAS;AAC/D,aAAOA;AAAA,EAGX;AAAA,EAEA,IAAY,cAAuB;AACjC,WAAO,KAAK,mBAAmB,SAAA,KAAc;AAAA,EAC/C;AACF;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const l=require("./WalletAdapters.types-De_x1lzr.js");class i{constructor(t){this.value=t}listeners=new Set;getValue(){return this.value}setValue(t){this.value=t,this.emit()}update(t){this.setValue(t(this.value))}subscribe(t){return this.listeners.add(t),t(this.value),{unsubscribe:()=>{this.listeners.delete(t)}}}emit(){for(const t of this.listeners)t(this.value)}}const r="app:BitcoinWalletAdapterConnector:previousConnectWallet";class d{constructor(t){this.Adapters=t,this.adapterOrder=new Map(t.map((e,a)=>[e.adapterId,a])),this.initializeAdapterAvailability()}availableAdaptersState=new i([]);connectedInfoState=new i(null);autoConnectRunning=!1;availabilitySubscriptions=[];adapterOrder=new Map;dispose(){this.availabilitySubscriptions.forEach(t=>t.unsubscribe()),this.availabilitySubscriptions=[],this.availableAdaptersState=new i([]),this.connectedInfoState=new i(null)}subscribeAvailableAdapters(t){return this.availableAdaptersState.subscribe(t)}getAvailableAdapters(){return this.availableAdaptersState.getValue()}subscribeConnectedInfo(t){return this.connectedInfoState.subscribe(t)}getConnectedInfo(){return this.connectedInfoState.getValue()}initializeAdapterAvailability(){this.availabilitySubscriptions=this.Adapters.map(t=>t.getAdapter().subscribe(e=>{this.addOrUpdateAvailableAdapter(t.adapterId,e)}))}addOrUpdateAvailableAdapter(t,e){this.availableAdaptersState.update(a=>{const n=[...a],o=a.findIndex(([s])=>s===t);return o===-1?n.push([t,e]):n[o]=[t,e],n.sort((s,u)=>(this.adapterOrder.get(s[0])??Number.MAX_SAFE_INTEGER)-(this.adapterOrder.get(u[0])??Number.MAX_SAFE_INTEGER)),n}),this.autoConnect()}async connect(t,e){const a=e;await a.connect().catch(n=>{if(n instanceof l.BitcoinWalletAdapterError){alert(n.message);return}throw n}),localStorage.setItem(r,t),this.connectedInfoState.setValue({adapterId:t,adapter:a})}async disconnect(){const t=this.connectedInfoState.getValue();t!=null&&(await this.disconnectAdapter(t.adapter),this.connectedInfoState.setValue(null))}async disconnectAdapter(t){await t.disconnect(),localStorage.removeItem(r)}async autoConnect(){if(this.isConnected||this.autoConnectRunning)return;const t=this.previousConnectedWallet;if(t==null)return;const e=this.availableAdaptersState.getValue().find(a=>a[0]===t)?.[1];if(e!=null){this.autoConnectRunning=!0;try{await e.getAddresses()}catch(a){if(a instanceof l.WalletAdapterNotConnectedError){this.autoConnectRunning=!1;return}throw this.autoConnectRunning=!1,a}try{await this.connect(t,e)}finally{this.autoConnectRunning=!1}}}get previousConnectedWallet(){const t=localStorage.getItem(r)||void 0;if(this.Adapters.some(e=>e.adapterId===t))return t}get isConnected(){return this.connectedInfoState.getValue()!=null}}exports.BitcoinWalletAdapterConnector=d;
|
|
2
|
-
//# sourceMappingURL=BitcoinWalletAdapterConnector-DMef0iHV.js.map
|