@coin-voyage/crypto 0.0.1 → 0.0.2

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.
Files changed (185) hide show
  1. package/dist/assets/icons.d.ts +1 -0
  2. package/dist/assets/icons.js +16 -0
  3. package/dist/assets/icons.js.map +1 -0
  4. package/dist/evm/base-provider.d.ts +5 -0
  5. package/dist/evm/base-provider.js +12 -0
  6. package/dist/evm/base-provider.js.map +1 -0
  7. package/dist/evm/create-default-evm-config.d.ts +41 -0
  8. package/dist/evm/create-default-evm-config.js +88 -0
  9. package/dist/evm/create-default-evm-config.js.map +1 -0
  10. package/dist/evm/external-context.d.ts +1 -0
  11. package/dist/evm/external-context.js +4 -0
  12. package/dist/evm/external-context.js.map +1 -0
  13. package/dist/evm/use-evm-transaction.d.ts +4 -0
  14. package/{src/evm/use-evm-transaction.ts → dist/evm/use-evm-transaction.js} +12 -17
  15. package/dist/evm/use-evm-transaction.js.map +1 -0
  16. package/dist/evm/use-sign-in-with-evm.d.ts +5 -0
  17. package/{src/evm/use-sign-in-with-evm.ts → dist/evm/use-sign-in-with-evm.js} +13 -22
  18. package/dist/evm/use-sign-in-with-evm.js.map +1 -0
  19. package/dist/evm/verify-message.d.ts +2 -0
  20. package/{src/evm/verify-message.ts → dist/evm/verify-message.js} +1 -1
  21. package/dist/evm/verify-message.js.map +1 -0
  22. package/dist/hooks/index.d.ts +5 -0
  23. package/dist/hooks/index.js +6 -0
  24. package/dist/hooks/index.js.map +1 -0
  25. package/dist/hooks/use-account-disconnect.d.ts +2 -0
  26. package/dist/hooks/use-account-disconnect.js +43 -0
  27. package/dist/hooks/use-account-disconnect.js.map +1 -0
  28. package/dist/hooks/use-account.d.ts +40 -0
  29. package/dist/hooks/use-account.js +117 -0
  30. package/dist/hooks/use-account.js.map +1 -0
  31. package/dist/hooks/use-combined-wallets.d.ts +12 -0
  32. package/dist/hooks/use-combined-wallets.js +113 -0
  33. package/dist/hooks/use-combined-wallets.js.map +1 -0
  34. package/dist/hooks/use-prepare-transaction.d.ts +5 -0
  35. package/dist/hooks/use-prepare-transaction.js +27 -0
  36. package/dist/hooks/use-prepare-transaction.js.map +1 -0
  37. package/dist/hooks/use-universal-connect.d.ts +20 -0
  38. package/dist/hooks/use-universal-connect.js +105 -0
  39. package/dist/hooks/use-universal-connect.js.map +1 -0
  40. package/dist/lib/config/chain.d.ts +2 -0
  41. package/{src/lib/config/chain.ts → dist/lib/config/chain.js} +3 -5
  42. package/dist/lib/config/chain.js.map +1 -0
  43. package/dist/lib/connectors/coinbase.d.ts +2 -0
  44. package/dist/lib/connectors/coinbase.js +4 -0
  45. package/dist/lib/connectors/coinbase.js.map +1 -0
  46. package/dist/lib/connectors/metaMask.d.ts +2 -0
  47. package/dist/lib/connectors/metaMask.js +4 -0
  48. package/dist/lib/connectors/metaMask.js.map +1 -0
  49. package/{src/lib/connectors/types.ts → dist/lib/connectors/types.d.ts} +6 -8
  50. package/dist/lib/connectors/types.js +2 -0
  51. package/dist/lib/connectors/types.js.map +1 -0
  52. package/dist/lib/connectors/utils.d.ts +5 -0
  53. package/dist/lib/connectors/utils.js +12 -0
  54. package/dist/lib/connectors/utils.js.map +1 -0
  55. package/dist/lib/connectors/walletConnect.d.ts +2 -0
  56. package/dist/lib/connectors/walletConnect.js +12 -0
  57. package/dist/lib/connectors/walletConnect.js.map +1 -0
  58. package/dist/lib/utils/connector.d.ts +5 -0
  59. package/dist/lib/utils/connector.js +15 -0
  60. package/dist/lib/utils/connector.js.map +1 -0
  61. package/dist/lib/utils/get-connector-icon.d.ts +2 -0
  62. package/dist/lib/utils/get-connector-icon.js +8 -0
  63. package/dist/lib/utils/get-connector-icon.js.map +1 -0
  64. package/dist/lib/utils/get-wallet-priority.d.ts +1 -0
  65. package/dist/lib/utils/get-wallet-priority.js +15 -0
  66. package/dist/lib/utils/get-wallet-priority.js.map +1 -0
  67. package/dist/lib/utils/is-wallet-installed.d.ts +1 -0
  68. package/dist/lib/utils/is-wallet-installed.js +34 -0
  69. package/dist/lib/utils/is-wallet-installed.js.map +1 -0
  70. package/dist/lib/utils/message.d.ts +2 -0
  71. package/dist/lib/utils/message.js +21 -0
  72. package/dist/lib/utils/message.js.map +1 -0
  73. package/dist/solana/base-provider.d.ts +5 -0
  74. package/dist/solana/base-provider.js +10 -0
  75. package/dist/solana/base-provider.js.map +1 -0
  76. package/dist/solana/external-context.d.ts +1 -0
  77. package/dist/solana/external-context.js +3 -0
  78. package/dist/solana/external-context.js.map +1 -0
  79. package/dist/solana/get-or-create-ata.d.ts +19 -0
  80. package/dist/solana/get-or-create-ata.js +51 -0
  81. package/dist/solana/get-or-create-ata.js.map +1 -0
  82. package/dist/solana/use-solana-transaction.d.ts +4 -0
  83. package/dist/solana/use-solana-transaction.js +48 -0
  84. package/dist/solana/use-solana-transaction.js.map +1 -0
  85. package/dist/sui/base-provider.d.ts +5 -0
  86. package/dist/sui/base-provider.js +9 -0
  87. package/dist/sui/base-provider.js.map +1 -0
  88. package/dist/sui/client.d.ts +2 -0
  89. package/{src/sui/client.ts → dist/sui/client.js} +2 -2
  90. package/dist/sui/client.js.map +1 -0
  91. package/dist/sui/constants.d.ts +1 -0
  92. package/{src/sui/constants.ts → dist/sui/constants.js} +3 -3
  93. package/dist/sui/constants.js.map +1 -0
  94. package/dist/sui/external-context.d.ts +1 -0
  95. package/dist/sui/external-context.js +3 -0
  96. package/dist/sui/external-context.js.map +1 -0
  97. package/dist/sui/use-sign-in-with-sui.d.ts +5 -0
  98. package/dist/sui/use-sign-in-with-sui.js +48 -0
  99. package/dist/sui/use-sign-in-with-sui.js.map +1 -0
  100. package/dist/sui/use-sui-transaction.d.ts +4 -0
  101. package/dist/sui/use-sui-transaction.js +45 -0
  102. package/dist/sui/use-sui-transaction.js.map +1 -0
  103. package/dist/sui/verify-message.d.ts +1 -0
  104. package/{src/sui/verify-message.ts → dist/sui/verify-message.js} +8 -11
  105. package/dist/sui/verify-message.js.map +1 -0
  106. package/{src/types/index.ts → dist/types/index.d.ts} +14 -17
  107. package/dist/types/index.js +2 -0
  108. package/dist/types/index.js.map +1 -0
  109. package/{src/types/sign-in-with.ts → dist/types/sign-in-with.d.ts} +3 -6
  110. package/dist/types/sign-in-with.js +2 -0
  111. package/dist/types/sign-in-with.js.map +1 -0
  112. package/dist/types/utxo-connector-id.d.ts +8 -0
  113. package/dist/types/utxo-connector-id.js +11 -0
  114. package/dist/types/utxo-connector-id.js.map +1 -0
  115. package/dist/types/wallet-connector.d.ts +5 -0
  116. package/dist/types/wallet-connector.js +2 -0
  117. package/dist/types/wallet-connector.js.map +1 -0
  118. package/dist/types/wallet.d.ts +38 -0
  119. package/dist/types/wallet.js +2 -0
  120. package/dist/types/wallet.js.map +1 -0
  121. package/dist/utxo/base-provider.d.ts +5 -0
  122. package/dist/utxo/base-provider.js +17 -0
  123. package/dist/utxo/base-provider.js.map +1 -0
  124. package/dist/utxo/create-default-bigmi-config.d.ts +33 -0
  125. package/dist/utxo/create-default-bigmi-config.js +47 -0
  126. package/dist/utxo/create-default-bigmi-config.js.map +1 -0
  127. package/dist/utxo/create-psbt-tx.d.ts +3 -0
  128. package/{src/utxo/create-psbt-tx.ts → dist/utxo/create-psbt-tx.js} +14 -25
  129. package/dist/utxo/create-psbt-tx.js.map +1 -0
  130. package/dist/utxo/external-context.d.ts +1 -0
  131. package/dist/utxo/external-context.js +3 -0
  132. package/dist/utxo/external-context.js.map +1 -0
  133. package/dist/utxo/get-address-utxo.d.ts +7 -0
  134. package/dist/utxo/get-address-utxo.js +27 -0
  135. package/dist/utxo/get-address-utxo.js.map +1 -0
  136. package/dist/utxo/send-btc.d.ts +23 -0
  137. package/{src/utxo/send-btc.ts → dist/utxo/send-btc.js} +41 -93
  138. package/dist/utxo/send-btc.js.map +1 -0
  139. package/dist/utxo/use-utxo-transaction.d.ts +4 -0
  140. package/dist/utxo/use-utxo-transaction.js +21 -0
  141. package/dist/utxo/use-utxo-transaction.js.map +1 -0
  142. package/dist/utxo/utxo-public-client.d.ts +9 -0
  143. package/dist/utxo/utxo-public-client.js +39 -0
  144. package/dist/utxo/utxo-public-client.js.map +1 -0
  145. package/dist/utxo/verify-message.d.ts +1 -0
  146. package/dist/utxo/verify-message.js +27 -0
  147. package/dist/utxo/verify-message.js.map +1 -0
  148. package/package.json +15 -15
  149. package/src/assets/icons.tsx +0 -16
  150. package/src/evm/base-provider.tsx +0 -22
  151. package/src/evm/create-default-evm-config.ts +0 -123
  152. package/src/evm/external-context.ts +0 -4
  153. package/src/hooks/index.ts +0 -6
  154. package/src/hooks/use-account-disconnect.ts +0 -47
  155. package/src/hooks/use-account.ts +0 -171
  156. package/src/hooks/use-combined-wallets.ts +0 -165
  157. package/src/hooks/use-prepare-transaction.ts +0 -32
  158. package/src/hooks/use-universal-connect.ts +0 -141
  159. package/src/lib/connectors/coinbase.ts +0 -9
  160. package/src/lib/connectors/metaMask.ts +0 -6
  161. package/src/lib/connectors/utils.ts +0 -23
  162. package/src/lib/connectors/walletConnect.ts +0 -18
  163. package/src/lib/utils/connector.ts +0 -22
  164. package/src/lib/utils/get-connector-icon.ts +0 -13
  165. package/src/lib/utils/get-wallet-priority.ts +0 -15
  166. package/src/lib/utils/is-wallet-installed.ts +0 -40
  167. package/src/lib/utils/message.ts +0 -29
  168. package/src/solana/base-provider.tsx +0 -29
  169. package/src/solana/external-context.ts +0 -3
  170. package/src/solana/get-or-create-ata.ts +0 -85
  171. package/src/solana/use-solana-transaction.ts +0 -83
  172. package/src/sui/base-provider.tsx +0 -22
  173. package/src/sui/external-context.ts +0 -3
  174. package/src/sui/use-sign-in-with-sui.ts +0 -55
  175. package/src/sui/use-sui-transaction.ts +0 -56
  176. package/src/types/utxo-connector-id.ts +0 -10
  177. package/src/types/wallet-connector.ts +0 -14
  178. package/src/types/wallet.ts +0 -55
  179. package/src/utxo/base-provider.tsx +0 -24
  180. package/src/utxo/create-default-bigmi-config.ts +0 -69
  181. package/src/utxo/external-context.ts +0 -3
  182. package/src/utxo/get-address-utxo.ts +0 -36
  183. package/src/utxo/use-utxo-transaction.tsx +0 -28
  184. package/src/utxo/utxo-public-client.ts +0 -60
  185. package/src/utxo/verify-message.ts +0 -35
@@ -1,141 +0,0 @@
1
- import { useConfig as useBigmiConfig } from "@bigmi/react"
2
- import { ChainType } from "@coin-voyage/shared/common"
3
- import { useConnectWallet } from "@mysten/dapp-kit"
4
- import { useWallet } from "@solana/wallet-adapter-react"
5
- import type { Connector } from "wagmi"
6
- import {
7
- useConfig as useWagmiConfig,
8
- useConnect as useWagmiConnect,
9
- } from "wagmi"
10
- import type {
11
- CreateConnectorFnExtended,
12
- WalletAdapterExtended,
13
- } from "../lib/connectors/types"
14
- import { ChainTypeWalletConnector } from "../types/wallet"
15
- import type { SuiConnector, WalletConnector } from "../types/wallet-connector"
16
-
17
- interface UseUniversalConnectProps {
18
- onError?: (err: any) => void
19
- onSuccess?: (
20
- data: any,
21
- variables?: {
22
- chainId?: number | undefined
23
- connector: WalletConnector
24
- }
25
- ) => void
26
- onSettled?: (data: any, error?: any) => void
27
- onMutate?: (variables?: {
28
- chainId?: number
29
- connector: any
30
- }) => void,
31
- }
32
-
33
- export const useUniversalConnect = (props?: UseUniversalConnectProps) => {
34
- const utxoConfig = useBigmiConfig()
35
- const evmConfig = useWagmiConfig()
36
- const { select, disconnect, connected } = useWallet()
37
- const { mutateAsync: suiConnectAsync } = useConnectWallet()
38
-
39
-
40
- const { connectAsync } = useWagmiConnect({
41
- config: evmConfig,
42
- mutation: {
43
- ...props,
44
- onSuccess(data, variables) {
45
- const connector =
46
- (variables.connector as CreateConnectorFnExtended) ||
47
- (variables.connector as Connector)
48
- props?.onSuccess?.(data, {
49
- chainId: variables?.chainId,
50
- connector,
51
- })
52
- },
53
- onError(err) {
54
- if (err.message) {
55
- if (err.message !== "User rejected request") {
56
- console.log(err.message, err)
57
- }
58
- } else {
59
- console.log("Could not connect.", err)
60
- }
61
- props?.onError?.(err)
62
- },
63
- },
64
- })
65
-
66
- const { connectAsync: utxoConnectAsync } = useWagmiConnect({
67
- config: utxoConfig,
68
- mutation: {
69
- ...props,
70
- onSuccess(data, variables) {
71
- props?.onSuccess?.(data, {
72
- chainId: variables?.chainId,
73
- connector: variables.connector as CreateConnectorFnExtended,
74
- })
75
- },
76
- onError(err) {
77
- if (err.message) {
78
- if (err.message !== "User rejected request") {
79
- console.log(err.message, err)
80
- }
81
- } else {
82
- console.log("Could not connect.", err)
83
- }
84
- props?.onError?.(err)
85
- },
86
- },
87
- })
88
-
89
- const connect = async ({
90
- walletConnector
91
- }: {
92
- walletConnector: ChainTypeWalletConnector
93
- }) => {
94
- const { connector, chainType } = walletConnector
95
- switch (chainType) {
96
- case ChainType.EVM:
97
- await connectAsync({
98
- connector: connector as Connector,
99
- })
100
- break
101
- case ChainType.UTXO:
102
- await utxoConnectAsync({
103
- connector: connector as Connector,
104
- })
105
- break
106
- case ChainType.SOL:
107
- try {
108
- props?.onMutate?.({ connector })
109
- if (connected) {
110
- await disconnect()
111
- }
112
- const walletAdapter = connector as WalletAdapterExtended
113
- select(walletAdapter.name)
114
- props?.onSuccess?.(undefined, { connector: walletAdapter })
115
- } catch (error: any) {
116
- props?.onError?.(error)
117
- }
118
- break
119
- case ChainType.SUI:
120
- await suiConnectAsync(
121
- {
122
- wallet: connector as SuiConnector,
123
- },
124
- {
125
- onError: props?.onError,
126
- onSuccess: (data) => {
127
- props?.onSuccess?.(data, { connector })
128
- },
129
- onSettled: (data, error) => {
130
- props?.onSettled?.(data, error)
131
- },
132
- }
133
- )
134
- break
135
- default:
136
- break
137
- }
138
- }
139
-
140
- return { connect }
141
- }
@@ -1,9 +0,0 @@
1
- import { type CoinbaseWalletParameters, coinbaseWallet } from "wagmi/connectors"
2
- import { extendConnector } from "./utils"
3
-
4
- export const createCoinbaseConnector = (params: CoinbaseWalletParameters) =>
5
- extendConnector(
6
- coinbaseWallet(params),
7
- "coinbaseWalletSDK",
8
- "Coinbase Wallet"
9
- )
@@ -1,6 +0,0 @@
1
- import type { MetaMaskParameters } from "wagmi/connectors"
2
- import { metaMask } from "wagmi/connectors"
3
- import { extendConnector } from "./utils"
4
-
5
- export const createMetaMaskConnector = (params: MetaMaskParameters) =>
6
- extendConnector(metaMask(params), "metaMaskSDK", "MetaMask")
@@ -1,23 +0,0 @@
1
- import type { WalletAdapter } from "@solana/wallet-adapter-base"
2
- import type { CreateConnectorFn } from "wagmi"
3
- import type { CreateConnectorFnExtended, WalletAdapterExtended } from "./types"
4
-
5
- export const extendConnector = (
6
- connector: CreateConnectorFn,
7
- id: string,
8
- name: string
9
- ): CreateConnectorFnExtended => {
10
- const extendedConnector = connector as CreateConnectorFnExtended
11
- extendedConnector.id = id
12
- extendedConnector.displayName = name
13
- return extendedConnector
14
- }
15
-
16
- export const extendsWalletAdapter = (
17
- adapter: WalletAdapter,
18
- id: string
19
- ): WalletAdapterExtended => {
20
- const extended = adapter as WalletAdapterExtended
21
- extended.id = id
22
- return extended
23
- }
@@ -1,18 +0,0 @@
1
- import type { WalletConnectParameters } from "wagmi/connectors"
2
- import { walletConnect } from "wagmi/connectors"
3
- import { extendConnector } from "./utils"
4
-
5
- export const createWalletConnectConnector = (params: WalletConnectParameters) =>
6
- extendConnector(
7
- walletConnect({
8
- showQrModal: false,
9
- qrModalOptions: {
10
- themeVariables: {
11
- "--wcm-z-index": "3000",
12
- },
13
- },
14
- ...params,
15
- }),
16
- "walletConnect",
17
- "WalletConnect"
18
- )
@@ -1,22 +0,0 @@
1
- import type { ChainType } from "@coin-voyage/shared/common"
2
- import type { ChainTypeWalletConnector } from "../../types/wallet"
3
- import type { WalletConnector } from "../../types/wallet-connector"
4
-
5
- export const getConnectorId = (connector: WalletConnector) => {
6
- if ("id" in connector) {
7
- return connector.id ?? connector.name
8
- }
9
- return connector.name
10
- }
11
-
12
- export const getConnector = (
13
- walletConnector: ChainTypeWalletConnector[],
14
- chainType?: ChainType
15
- ) => {
16
- let connector = walletConnector[0]
17
- if (chainType) {
18
- connector =
19
- walletConnector.find((c) => c.chainType === chainType) ?? connector
20
- }
21
- return connector.connector
22
- }
@@ -1,13 +0,0 @@
1
- import type { Connector } from "wagmi"
2
- import { getWalletIcon } from "../../assets/icons"
3
- import { WalletConnector } from "../../types/wallet-connector"
4
-
5
- export const getConnectorIcon = (
6
- connector?: WalletConnector
7
- ) => {
8
- const connectorId = (connector as Connector)?.id
9
-
10
- return connectorId
11
- ? getWalletIcon(connectorId) || connector?.icon
12
- : connector?.icon
13
- }
@@ -1,15 +0,0 @@
1
- const walletPriority: Record<string, number> = {
2
- metaMaskSDK: 1,
3
- "io.metamask": 1,
4
- "io.metamask.mobile": 1,
5
- "app.phantom": 1,
6
- "Sui Wallet": 1,
7
- coinbaseWalletSDK: 2,
8
- "com.coinbase.wallet": 2,
9
- walletConnect: 3,
10
- safe: 4,
11
- }
12
-
13
- export const getWalletPriority = (id: string) => {
14
- return walletPriority?.[id] || 1000
15
- }
@@ -1,40 +0,0 @@
1
- export const isWalletInstalled = (id: string): boolean => {
2
- const anyWindow = typeof window !== "undefined" ? (window as any) : undefined
3
- switch (id) {
4
- case "metaMask":
5
- return (
6
- anyWindow?.ethereum?.isMetaMask ||
7
- anyWindow?.ethereum?.providers?.some(
8
- (provider: any) => provider.isMetaMask
9
- )
10
- )
11
- case "coinbase":
12
- return (
13
- // Coinbase Browser doesn't inject itself automatically
14
- // We should not consider Coinbase Browser as installed wallet so we can fallback to Coinbase SDK
15
- (anyWindow?.ethereum?.isCoinbaseWallet &&
16
- !anyWindow?.ethereum?.isCoinbaseBrowser) ||
17
- anyWindow?.coinbaseWalletExtension?.isCoinbaseWallet ||
18
- anyWindow?.ethereum?.providers?.some(
19
- (provider: any) => provider.isCoinbaseWallet
20
- )
21
- )
22
- case "app.phantom":
23
- return anyWindow?.phantom?.isPhantom
24
- case "app.phantom.bitcoin":
25
- return anyWindow?.phantom?.bitcoin?.isPhantom
26
- case "com.okex.wallet.bitcoin":
27
- return anyWindow?.okxwallet?.bitcoin?.isOkxWallet
28
- case "XverseProviders.BitcoinProvider":
29
- return anyWindow?.XverseProviders?.BitcoinProvider
30
- case "unisat":
31
- return anyWindow?.unisat
32
- case "io.xdefi.bitcoin":
33
- return anyWindow?.xfi?.bitcoin
34
- default:
35
- /**
36
- * Return true if the wallet is not in the list of explicitly supported or self-injected wallet
37
- */
38
- return true
39
- }
40
- }
@@ -1,29 +0,0 @@
1
- import { SignInMessage } from "../../types";
2
-
3
- export const toMessage = (message: SignInMessage, accountName: string): string => {
4
- const header = `${message.domain} wants you to sign in with your ${accountName} account:\n`;
5
- const uriField = `URI: ${message.uri}`;
6
- let prefix = [header, message.address].join("\n");
7
- const versionField = `Version: ${message.version}`;
8
-
9
- const nonceField = `Nonce: ${message.nonce}`;
10
-
11
- const suffixArray = [uriField, versionField, nonceField];
12
-
13
- message.issuedAt = message.issuedAt || new Date().toISOString();
14
-
15
- suffixArray.push(`Issued At: ${message.issuedAt}`);
16
-
17
- if (message.expirationTime) {
18
- const expiryField = `Expiration Time: ${message.expirationTime}`;
19
-
20
- suffixArray.push(expiryField);
21
- }
22
-
23
- const suffix = suffixArray.join("\n");
24
- prefix = [prefix, message.statement].join("\n\n");
25
- if (message.statement) {
26
- prefix += "\n";
27
- }
28
- return [prefix, suffix].join("\n");
29
- };
@@ -1,29 +0,0 @@
1
- import type { Adapter } from "@solana/wallet-adapter-base"
2
- import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"
3
- import {
4
- ConnectionProvider,
5
- WalletProvider,
6
- } from "@solana/wallet-adapter-react"
7
- import { clusterApiUrl } from "@solana/web3.js"
8
- import type { PropsWithChildren } from "react"
9
- import { WalletConfiguration } from "../types"
10
-
11
- const endpoint = clusterApiUrl(WalletAdapterNetwork.Mainnet)
12
-
13
- const wallets: Adapter[] = []
14
-
15
- export function SolanaBaseProvider({ children, config }: PropsWithChildren<{
16
- config?: WalletConfiguration["solana"]
17
- }>) {
18
- return (
19
- <ConnectionProvider endpoint={config?.rpcUrl ?? endpoint}>
20
- <WalletProvider
21
- {...config?.walletConfiguration}
22
- autoConnect={config?.walletConfiguration?.autoConnect || true}
23
- wallets={config?.walletConfiguration?.wallets || wallets}
24
- >
25
- {children}
26
- </WalletProvider>
27
- </ConnectionProvider>
28
- )
29
- }
@@ -1,3 +0,0 @@
1
- import { createContext } from "react"
2
-
3
- export const SolanaExternalContext = createContext<boolean>(false)
@@ -1,85 +0,0 @@
1
- import {
2
- Account,
3
- ASSOCIATED_TOKEN_PROGRAM_ID,
4
- createAssociatedTokenAccountInstruction,
5
- getAccount,
6
- getAssociatedTokenAddressSync,
7
- TOKEN_PROGRAM_ID,
8
- TokenAccountNotFoundError,
9
- TokenInvalidAccountOwnerError,
10
- TokenInvalidMintError,
11
- TokenInvalidOwnerError
12
- } from "@solana/spl-token";
13
- import type { Commitment, Connection, PublicKey } from "@solana/web3.js";
14
- import { TransactionInstruction } from "@solana/web3.js";
15
-
16
- /**
17
- * Retrieve the associated token account, or create it if it doesn't exist
18
- *
19
- * @param connection Connection to use
20
- * @param payer Payer of the transaction and initialization fees
21
- * @param mint Mint associated with the account to set or verify
22
- * @param owner Owner of the account to set or verify
23
- * @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address)
24
- * @param commitment Desired level of commitment for querying the state
25
- * @param confirmOptions Options for confirming the transaction
26
- * @param programId SPL Token program account
27
- * @param associatedTokenProgramId SPL Associated Token program account
28
- *
29
- * @return Address of the new associated token account
30
- */
31
- export async function getOrCreateAssociatedTokenAccount(
32
- connection: Connection,
33
- payerPubkey: PublicKey,
34
- mint: PublicKey,
35
- owner: PublicKey,
36
- allowOwnerOffCurve = false,
37
- commitment?: Commitment,
38
- programId = TOKEN_PROGRAM_ID,
39
- associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
40
- ): Promise<Account | TransactionInstruction> {
41
- const associatedToken = getAssociatedTokenAddressSync(
42
- mint,
43
- owner,
44
- allowOwnerOffCurve,
45
- programId,
46
- associatedTokenProgramId
47
- );
48
-
49
- // This is the optimal logic, considering TX fee, client-side computation, RPC roundtrips and guaranteed idempotent.
50
- // Sadly we can't do this atomically.
51
- let account: Account;
52
- try {
53
- account = await getAccount(connection, associatedToken, commitment, programId);
54
- } catch (error: unknown) {
55
- // TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
56
- // becoming a system account. Assuming program derived addressing is safe, this is the only case for the
57
- // TokenInvalidAccountOwnerError in this code path.
58
- if (error instanceof TokenAccountNotFoundError || error instanceof TokenInvalidAccountOwnerError) {
59
- // As this isn't atomic, it's possible others can create associated accounts meanwhile.
60
- try {
61
- return createAssociatedTokenAccountInstruction(
62
- payerPubkey,
63
- associatedToken,
64
- owner,
65
- mint,
66
- programId,
67
- associatedTokenProgramId
68
- );
69
- } catch (error: unknown) {
70
- // Ignore all errors; for now there is no API-compatible way to selectively ignore the expected
71
- // instruction error if the associated account exists already.
72
- }
73
-
74
- // Now this should always succeed
75
- account = await getAccount(connection, associatedToken, commitment, programId);
76
- } else {
77
- throw error;
78
- }
79
- }
80
-
81
- if (!account.mint.equals(mint)) throw new TokenInvalidMintError();
82
- if (!account.owner.equals(owner)) throw new TokenInvalidOwnerError();
83
-
84
- return account;
85
- }
@@ -1,83 +0,0 @@
1
- import type { PaymentDetails } from "@coin-voyage/shared/api";
2
- import {
3
- createTransferCheckedInstruction,
4
- getAssociatedTokenAddress,
5
- getAssociatedTokenAddressSync
6
- } from "@solana/spl-token";
7
- import { useConnection, useWallet } from "@solana/wallet-adapter-react";
8
- import {
9
- ComputeBudgetProgram,
10
- PublicKey,
11
- SystemProgram,
12
- Transaction,
13
- TransactionInstruction
14
- } from "@solana/web3.js";
15
- import { getOrCreateAssociatedTokenAccount } from "./get-or-create-ata";
16
-
17
- export function useSolanaTransaction(): {
18
- execute: (paymentDetails: PaymentDetails) => Promise<string | undefined>;
19
- } {
20
- const { connection } = useConnection();
21
- const wallet = useWallet();
22
-
23
- const execute = async (paymentDetails: PaymentDetails) => {
24
- let transaction = new Transaction();
25
-
26
- const receiverPubKey = new PublicKey(paymentDetails.deposit_address);
27
- const senderPubKey = new PublicKey(paymentDetails.refund_address);
28
-
29
- const instructions: TransactionInstruction[] = [
30
- // add priority fees
31
- ComputeBudgetProgram.setComputeUnitPrice({
32
- microLamports: 1_000_000
33
- })
34
- ];
35
-
36
- const value = paymentDetails.source_amount.raw_amount;
37
-
38
- // Native SOL transfer
39
- if (!paymentDetails.source_currency.address) {
40
- instructions.push(
41
- SystemProgram.transfer({
42
- fromPubkey: senderPubKey,
43
- toPubkey: receiverPubKey,
44
- lamports: value
45
- })
46
- );
47
- } else {
48
- const mint = new PublicKey(paymentDetails.source_currency.address);
49
-
50
- const payerAta = await getAssociatedTokenAddress(mint, senderPubKey, false);
51
- const receiverAta = getAssociatedTokenAddressSync(mint, receiverPubKey, false);
52
-
53
- const accountOrTransactionInstruction = await getOrCreateAssociatedTokenAccount(
54
- connection,
55
- senderPubKey,
56
- mint,
57
- receiverPubKey
58
- );
59
- if (accountOrTransactionInstruction instanceof TransactionInstruction) {
60
- instructions.push(accountOrTransactionInstruction);
61
- }
62
-
63
- instructions.push(
64
- createTransferCheckedInstruction(
65
- payerAta, // from
66
- mint,
67
- receiverAta, // to
68
- senderPubKey, // from's owner
69
- value,
70
- paymentDetails.source_currency.decimals
71
- )
72
- );
73
- }
74
-
75
- transaction.instructions = instructions;
76
- return await wallet.sendTransaction(transaction, connection, {
77
- maxRetries: 3,
78
- skipPreflight: true,
79
- });
80
- }
81
-
82
- return { execute }
83
- }
@@ -1,22 +0,0 @@
1
- import { SuiClientProvider, WalletProvider } from "@mysten/dapp-kit"
2
- import type { PropsWithChildren } from "react"
3
- import { WalletConfiguration } from "../types"
4
-
5
- export function SuiBaseProvider({ children, config }: PropsWithChildren<{
6
- config?: WalletConfiguration["sui"]
7
- }>) {
8
- return (
9
- <SuiClientProvider
10
- networks={{
11
- mainnet: { url: config?.rpcUrl ?? "https://fullnode.mainnet.sui.io:443" },
12
- devnet: { url: "https://fullnode.devnet.sui.io:443" },
13
- }}
14
- defaultNetwork={"mainnet"}
15
- >
16
- <WalletProvider
17
- {...config?.walletConfiguration}
18
- autoConnect={config?.walletConfiguration?.autoConnect || true}
19
- >{children}</WalletProvider>
20
- </SuiClientProvider>
21
- )
22
- }
@@ -1,3 +0,0 @@
1
- import { createContext } from "react"
2
-
3
- export const SuiExternalContext = createContext<boolean>(false)
@@ -1,55 +0,0 @@
1
- import { ChainType } from "@coin-voyage/shared/common";
2
- import { useConnectWallet, useSignPersonalMessage } from "@mysten/dapp-kit";
3
- import { toast } from "sonner";
4
- import { useCombinedWallets } from "../hooks/use-combined-wallets";
5
- import { toMessage } from "../lib/utils/message";
6
- import { SignInMessage } from "../types";
7
- import { SignInWith } from "../types/sign-in-with";
8
- import { SuiConnector } from "../types/wallet-connector";
9
-
10
- export function useSignInWithSui({ signIn, callbackUrl }: SignInWith) {
11
- const { mutate: connect } = useConnectWallet();
12
- const { mutate: signPersonalMessage } = useSignPersonalMessage();
13
- const { installedWallets } = useCombinedWallets(ChainType.SUI)
14
-
15
- const handleSignature = async (address: string) => {
16
- const msg = {
17
- domain: window.location.host,
18
- address,
19
- statement: "Sign in with Sui to CoinVoyage.io",
20
- uri: window.location.origin,
21
- nonce: Math.random().toString(),
22
- version: "1"
23
- } as SignInMessage;
24
-
25
- const message = toMessage(msg, "Sui");
26
-
27
- signPersonalMessage({ message: new TextEncoder().encode(message) }, {
28
- onSuccess: (result) => {
29
- signIn("sui", {
30
- address,
31
- message,
32
- domain: window.location.host,
33
- signature: result.signature,
34
- callbackUrl: callbackUrl ?? "/"
35
- });
36
- },
37
- onError: (error) => {
38
- toast.error("Something went wrong!", {
39
- description: error.message
40
- });
41
- }
42
- });
43
- };
44
-
45
- const onSelect = (id: string) => {
46
- const selectedWallet = installedWallets.find((w) => w.id === id);
47
- const connector = selectedWallet?.connectors?.[0].connector as SuiConnector | undefined;
48
- if (!connector) return;
49
- connect({ wallet: connector }, {
50
- onSuccess: (res) => handleSignature(res.accounts[0].address)
51
- })
52
- };
53
-
54
- return { onSelect, installedWallets };
55
- }
@@ -1,56 +0,0 @@
1
- import type { PaymentDetails } from "@coin-voyage/shared/api";
2
- import { useReportTransactionEffects, useSignTransaction, useSuiClient } from "@mysten/dapp-kit";
3
- import { Transaction, } from "@mysten/sui/transactions";
4
- import { SUI_PACKAGE_IDS } from "./constants";
5
-
6
- export function useSUITransaction(): {
7
- execute: (paymentDetails: PaymentDetails) => Promise<string | undefined>;
8
- } {
9
- const client = useSuiClient()
10
- const { mutateAsync: signTransaction } = useSignTransaction();
11
- const { mutate: reportTransactionEffects } = useReportTransactionEffects()
12
-
13
- const execute = async (paymentDetails: PaymentDetails) => {
14
- const isNative = !paymentDetails.source_currency.address || (paymentDetails.source_currency.address.toLowerCase() === SUI_PACKAGE_IDS["sui"].toLowerCase());
15
- const tx = new Transaction();
16
-
17
- if (isNative) {
18
- const balance = await client.getBalance({
19
- owner: paymentDetails.refund_address,
20
- coinType: SUI_PACKAGE_IDS["sui"]
21
- })
22
- const value = paymentDetails.source_amount.raw_amount;
23
- if (BigInt(balance.totalBalance) < value) {
24
- throw new Error(`[CHECKOUT] Insufficient balance: ${balance}`);
25
- }
26
- const [coin] = tx.splitCoins(tx.gas, [value]);
27
- tx.transferObjects([coin], paymentDetails.deposit_address);
28
-
29
- const { bytes, signature } = await signTransaction({
30
- transaction: tx,
31
- });
32
-
33
- const executeResult = await client.executeTransactionBlock({
34
- transactionBlock: bytes,
35
- signature,
36
- options: {
37
- showRawEffects: true,
38
- },
39
- });
40
-
41
- // Always report transaction effects to the wallet after execution
42
- if (executeResult.rawEffects) {
43
- reportTransactionEffects({
44
- effects: executeResult.rawEffects
45
- });
46
- }
47
-
48
- return executeResult.digest;
49
- }
50
-
51
- // TODO: Implement SUI Token transfer
52
- return
53
- }
54
-
55
- return { execute }
56
- }
@@ -1,10 +0,0 @@
1
-
2
- export enum UTXOConnectorId {
3
- PHANTOM_BTC = 'app.phantom.bitcoin',
4
- XVERSE = 'XverseProviders.BitcoinProvider',
5
- UNISAT = 'unisat',
6
- // CTRL = 'io.xdefi.bitcoin',
7
- OKEX = 'com.okex.wallet.bitcoin',
8
- LEATHER = 'LeatherProvider',
9
- ONEKEY = 'so.onekey.app.wallet.bitcoin',
10
- }