@coin-voyage/crypto 2.3.0 → 2.4.0-beta.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.
Files changed (60) hide show
  1. package/dist/config/index.d.ts +1 -0
  2. package/dist/config/index.js +1 -0
  3. package/dist/{lib/connectors → connectors}/coinbase.d.ts +1 -1
  4. package/dist/{lib/connectors → connectors}/coinbase.js +1 -1
  5. package/dist/connectors/index.d.ts +3 -0
  6. package/dist/connectors/index.js +3 -0
  7. package/dist/{lib/connectors → connectors}/metaMask.d.ts +1 -1
  8. package/dist/{lib/connectors → connectors}/metaMask.js +1 -1
  9. package/dist/{lib/connectors → connectors}/walletConnect.d.ts +1 -1
  10. package/dist/{lib/connectors → connectors}/walletConnect.js +1 -1
  11. package/dist/evm/create-default-evm-config.js +6 -6
  12. package/dist/evm/index.d.ts +7 -0
  13. package/dist/evm/index.js +7 -0
  14. package/dist/evm/use-evm-transaction.js +21 -3
  15. package/dist/evm/use-sign-in-with-evm.d.ts +1 -1
  16. package/dist/evm/use-sign-in-with-evm.js +2 -2
  17. package/dist/hooks/use-account.js +1 -1
  18. package/dist/hooks/use-installed-wallets.js +3 -3
  19. package/dist/hooks/use-last-connector.js +2 -2
  20. package/dist/solana/index.d.ts +6 -0
  21. package/dist/solana/index.js +6 -0
  22. package/dist/solana/provider/provider.d.ts +1 -1
  23. package/dist/solana/use-solana-transaction.js +65 -4
  24. package/dist/sui/index.d.ts +6 -0
  25. package/dist/sui/index.js +6 -0
  26. package/dist/sui/provider/provider.d.ts +1 -1
  27. package/dist/sui/use-sign-in-with-sui.js +1 -1
  28. package/dist/sui/use-sui-transaction.js +31 -5
  29. package/dist/types/index.d.ts +6 -0
  30. package/dist/types/index.js +6 -0
  31. package/dist/types/transaction.d.ts +5 -3
  32. package/dist/{lib/utils → utils}/connector.d.ts +2 -2
  33. package/dist/{lib/utils → utils}/get-connector-icon.d.ts +1 -1
  34. package/dist/{lib/utils → utils}/get-connector-icon.js +1 -1
  35. package/dist/utils/index.d.ts +6 -0
  36. package/dist/utils/index.js +6 -0
  37. package/dist/{lib/utils → utils}/message.d.ts +1 -1
  38. package/dist/utxo/create-psbt-tx.js +1 -3
  39. package/dist/utxo/create-utxo-transport.js +11 -4
  40. package/dist/utxo/index.d.ts +10 -0
  41. package/dist/utxo/index.js +10 -0
  42. package/dist/utxo/provider/provider.d.ts +1 -1
  43. package/dist/utxo/provider/provider.js +2 -2
  44. package/dist/utxo/use-utxo-transaction.js +9 -1
  45. package/dist/wallets/index.d.ts +1 -0
  46. package/dist/wallets/index.js +1 -0
  47. package/dist/wallets/wallet-provider.d.ts +1 -1
  48. package/package.json +63 -7
  49. package/dist/sui/provider.d.ts +0 -9
  50. package/dist/sui/provider.js +0 -17
  51. /package/dist/{lib/config → config}/chain.d.ts +0 -0
  52. /package/dist/{lib/config → config}/chain.js +0 -0
  53. /package/dist/{lib/utils → utils}/connector.js +0 -0
  54. /package/dist/{lib/utils → utils}/conversions.d.ts +0 -0
  55. /package/dist/{lib/utils → utils}/conversions.js +0 -0
  56. /package/dist/{lib/utils → utils}/get-wallet-priority.d.ts +0 -0
  57. /package/dist/{lib/utils → utils}/get-wallet-priority.js +0 -0
  58. /package/dist/{lib/utils → utils}/is-wallet-installed.d.ts +0 -0
  59. /package/dist/{lib/utils → utils}/is-wallet-installed.js +0 -0
  60. /package/dist/{lib/utils → utils}/message.js +0 -0
@@ -0,0 +1 @@
1
+ export * from "./chain";
@@ -0,0 +1 @@
1
+ export * from "./chain";
@@ -1,2 +1,2 @@
1
1
  import { type CoinbaseWalletParameters } from "wagmi/connectors";
2
- export declare const createCoinbaseConnector: (params: CoinbaseWalletParameters) => import("../../evm/types").CreateConnectorFnExtended;
2
+ export declare const createCoinbaseConnector: (params: CoinbaseWalletParameters) => import("../evm").CreateConnectorFnExtended;
@@ -1,3 +1,3 @@
1
1
  import { coinbaseWallet } from "wagmi/connectors";
2
- import { extendConnector } from "../../evm/utils";
2
+ import { extendConnector } from "../evm/utils";
3
3
  export const createCoinbaseConnector = (params) => extendConnector(coinbaseWallet(params), "coinbaseWalletSDK", "Coinbase Wallet");
@@ -0,0 +1,3 @@
1
+ export * from "./coinbase";
2
+ export * from "./metaMask";
3
+ export * from "./walletConnect";
@@ -0,0 +1,3 @@
1
+ export * from "./coinbase";
2
+ export * from "./metaMask";
3
+ export * from "./walletConnect";
@@ -1,2 +1,2 @@
1
1
  import type { MetaMaskParameters } from "wagmi/connectors";
2
- export declare const createMetaMaskConnector: (params: MetaMaskParameters) => import("../../evm/types").CreateConnectorFnExtended;
2
+ export declare const createMetaMaskConnector: (params: MetaMaskParameters) => import("../evm").CreateConnectorFnExtended;
@@ -1,3 +1,3 @@
1
1
  import { metaMask } from "wagmi/connectors";
2
- import { extendConnector } from "../../evm/utils";
2
+ import { extendConnector } from "../evm/utils";
3
3
  export const createMetaMaskConnector = (params) => extendConnector(metaMask(params), "metaMaskSDK", "MetaMask");
@@ -1,2 +1,2 @@
1
1
  import type { WalletConnectParameters } from "wagmi/connectors";
2
- export declare const createWalletConnectConnector: (params: WalletConnectParameters) => import("../../evm/types").CreateConnectorFnExtended;
2
+ export declare const createWalletConnectConnector: (params: WalletConnectParameters) => import("../evm").CreateConnectorFnExtended;
@@ -1,5 +1,5 @@
1
1
  import { walletConnect } from "wagmi/connectors";
2
- import { extendConnector } from "../../evm/utils";
2
+ import { extendConnector } from "../evm/utils";
3
3
  export const createWalletConnectConnector = (params) => extendConnector(walletConnect({
4
4
  showQrModal: false,
5
5
  qrModalOptions: {
@@ -1,12 +1,12 @@
1
- import { getValue } from "@coin-voyage/shared/common";
1
+ import { getValue } from "@coin-voyage/shared/utils";
2
2
  import { fallback, http } from "viem";
3
3
  import { createConfig, injected } from "wagmi";
4
4
  import { safe, } from "wagmi/connectors";
5
- import { DEFAULT_CHAINS } from "../lib/config/chain";
6
- import { createCoinbaseConnector } from "../lib/connectors/coinbase";
7
- import { createMetaMaskConnector } from "../lib/connectors/metaMask";
8
- import { createWalletConnectConnector } from "../lib/connectors/walletConnect";
9
- import { isWalletInstalled } from "../lib/utils/is-wallet-installed";
5
+ import { DEFAULT_CHAINS } from "../config/chain";
6
+ import { createCoinbaseConnector } from "../connectors/coinbase";
7
+ import { createMetaMaskConnector } from "../connectors/metaMask";
8
+ import { createWalletConnectConnector } from "../connectors/walletConnect";
9
+ import { isWalletInstalled } from "../utils/is-wallet-installed";
10
10
  import { extendConnector, fallbackRPCUrls } from "./utils";
11
11
  export function createDefaultEVMConfig(props) {
12
12
  const connectors = [...(props?.connectors ?? [])];
@@ -0,0 +1,7 @@
1
+ export * from "./create-default-evm-config";
2
+ export * from "./types";
3
+ export * from "./use-evm-transaction";
4
+ export * from "./use-sign-in-with-evm";
5
+ export * from "./utils";
6
+ export * from "./verify-message";
7
+ export * from "./provider/provider";
@@ -0,0 +1,7 @@
1
+ export * from "./create-default-evm-config";
2
+ export * from "./types";
3
+ export * from "./use-evm-transaction";
4
+ export * from "./use-sign-in-with-evm";
5
+ export * from "./utils";
6
+ export * from "./verify-message";
7
+ export * from "./provider/provider";
@@ -1,3 +1,4 @@
1
+ import { getEvmPaymentData } from "@coin-voyage/shared/payment";
1
2
  import { estimateFeesPerGas } from "viem/actions";
2
3
  import { useConfig, useSendTransaction, useWriteContract } from "wagmi";
3
4
  export function useEVMTransaction() {
@@ -5,14 +6,31 @@ export function useEVMTransaction() {
5
6
  const { sendTransactionAsync } = useSendTransaction();
6
7
  const config = useConfig();
7
8
  const execute = async (params) => {
8
- const { chainId, toAddress, amount, token } = params;
9
- const value = BigInt(amount);
10
- const to = toAddress;
11
9
  const client = config.getClient();
12
10
  const gasEstimates = await estimateFeesPerGas(client, {
13
11
  chain: client.chain,
14
12
  type: "eip1559",
15
13
  });
14
+ const evmPaymentData = getEvmPaymentData(params.paymentData);
15
+ if (evmPaymentData) {
16
+ const tx = await sendTransactionAsync({
17
+ to: evmPaymentData.to,
18
+ data: evmPaymentData.data,
19
+ value: BigInt(evmPaymentData.value),
20
+ chainId: evmPaymentData.chainId,
21
+ maxFeePerGas: evmPaymentData.maxFeePerGas ? BigInt(evmPaymentData.maxFeePerGas) : gasEstimates.maxFeePerGas,
22
+ maxPriorityFeePerGas: evmPaymentData.maxPriorityFeePerGas
23
+ ? BigInt(evmPaymentData.maxPriorityFeePerGas)
24
+ : gasEstimates.maxPriorityFeePerGas,
25
+ });
26
+ return tx;
27
+ }
28
+ const { chainId, to: toAddress, amount, token } = params;
29
+ if (!toAddress || amount == undefined) {
30
+ throw new Error("Missing EVM transfer target or amount");
31
+ }
32
+ const value = BigInt(amount);
33
+ const to = toAddress;
16
34
  if (!token) {
17
35
  const tx = await sendTransactionAsync({
18
36
  to,
@@ -1,5 +1,5 @@
1
1
  import { SignInWith } from "../types/sign-in-with";
2
2
  export declare function useSignInWithEvm({ signIn, onError, generateNonce }: SignInWith): {
3
3
  onSelect: (id: string) => Promise<void>;
4
- wallets: import("../types/base-connector").BaseConnector[];
4
+ wallets: import("../types").BaseConnector[];
5
5
  };
@@ -1,8 +1,8 @@
1
1
  import { randomStringForEntropy } from "@stablelib/random";
2
2
  import { useCallback, useMemo } from "react";
3
3
  import { useAccount, useConnect, useConnectors, useSignMessage } from "wagmi";
4
- import { isWalletInstalled } from "../lib/utils/is-wallet-installed";
5
- import { toMessage } from "../lib/utils/message";
4
+ import { isWalletInstalled } from "../utils/is-wallet-installed";
5
+ import { toMessage } from "../utils/message";
6
6
  import { toBaseConnector } from "./utils";
7
7
  export function useSignInWithEvm({ signIn, onError, generateNonce }) {
8
8
  const { address, connector, isConnected } = useAccount();
@@ -5,7 +5,7 @@ import { useCurrentAccount, useCurrentWallet } from "@mysten/dapp-kit";
5
5
  import { useWallet } from "@solana/wallet-adapter-react";
6
6
  import { useCallback, useRef, useSyncExternalStore } from "react";
7
7
  import { useAccount as useAccountInternal } from "wagmi";
8
- import { getConnector } from "../lib/utils/connector";
8
+ import { getConnector } from "../utils/connector";
9
9
  import { extendsWalletAdapter } from "../solana/utils";
10
10
  import { useLastConnector } from "./use-last-connector";
11
11
  const defaultAccount = {
@@ -5,9 +5,9 @@ import { WalletReadyState } from "@solana/wallet-adapter-base";
5
5
  import { useWallet } from "@solana/wallet-adapter-react";
6
6
  import { useContext, useMemo } from "react";
7
7
  import { WagmiContext } from "wagmi";
8
- import { getConnectorIcon } from "../lib/utils/get-connector-icon";
9
- import { getWalletPriority } from "../lib/utils/get-wallet-priority";
10
- import { isWalletInstalled } from "../lib/utils/is-wallet-installed";
8
+ import { getConnectorIcon } from "../utils/get-connector-icon";
9
+ import { getWalletPriority } from "../utils/get-wallet-priority";
10
+ import { isWalletInstalled } from "../utils/is-wallet-installed";
11
11
  import { extendsWalletAdapter } from "../solana/utils";
12
12
  // canonical wallet ID for multi-chain wallets
13
13
  const getCanonicalWalletId = (idOrName) => {
@@ -1,6 +1,6 @@
1
- import { getValue, setValue } from "@coin-voyage/shared/common";
1
+ import { getValue, setValue } from "@coin-voyage/shared/utils";
2
2
  import { useCallback, useState } from "react";
3
- import { getConnectorId } from "../lib/utils/connector";
3
+ import { getConnectorId } from "../utils/connector";
4
4
  export const useLastConnector = () => {
5
5
  const [lastConnectorIdWithChain, setLastConnectorIdWithChain] = useState(() => {
6
6
  const stored = getValue("@coin-voyage/recentConnectorId");
@@ -0,0 +1,6 @@
1
+ export * from "./get-or-create-ata";
2
+ export * from "./private-key-wallet";
3
+ export * from "./types";
4
+ export * from "./use-solana-transaction";
5
+ export * from "./utils";
6
+ export * from "./provider/provider";
@@ -0,0 +1,6 @@
1
+ export * from "./get-or-create-ata";
2
+ export * from "./private-key-wallet";
3
+ export * from "./types";
4
+ export * from "./use-solana-transaction";
5
+ export * from "./utils";
6
+ export * from "./provider/provider";
@@ -1,4 +1,4 @@
1
- import { SolanaConfiguration } from "@coin-voyage/crypto/types/wallet";
1
+ import type { SolanaConfiguration } from "../../types/wallet";
2
2
  import { PropsWithChildren } from "react";
3
3
  import { WalletConnectParameters } from "wagmi/connectors";
4
4
  export declare function useInSolanaContext(): boolean;
@@ -1,7 +1,10 @@
1
+ import { getSolanaPaymentData } from "@coin-voyage/shared/payment";
2
+ import { hex } from "@scure/base";
1
3
  import { createTransferCheckedInstruction, getAssociatedTokenAddress } from "@solana/spl-token";
2
4
  import { useConnection, useWallet } from "@solana/wallet-adapter-react";
3
- import { ComputeBudgetProgram, PublicKey, SystemProgram, Transaction, TransactionInstruction, } from "@solana/web3.js";
5
+ import { ComputeBudgetProgram, PublicKey, SystemProgram, Transaction, TransactionInstruction, VersionedTransaction, } from "@solana/web3.js";
4
6
  import { getOrCreateAssociatedTokenAccount } from "./get-or-create-ata";
7
+ const INVALID_TX_PAYLOAD_ERROR = "Invalid Solana transaction payload: expected Transaction, VersionedTransaction, Uint8Array, byte array, hex, or base64";
5
8
  export function useSolanaTransaction() {
6
9
  const { connection } = useConnection();
7
10
  const wallet = useWallet();
@@ -14,10 +17,22 @@ export function useSolanaTransaction() {
14
17
  throw new Error("Wallet not connected. Please reconnect your wallet and try again.");
15
18
  }
16
19
  }
17
- const { fromAddress, toAddress, amount, token } = params;
20
+ const preparedPayment = getSolanaPaymentData(params.paymentData);
21
+ if (preparedPayment) {
22
+ const { context: { slot: minContextSlot }, value: { lastValidBlockHeight }, } = await connection.getLatestBlockhashAndContext();
23
+ const transaction = deserializePreparedSolanaTransaction(preparedPayment.transaction);
24
+ const signature = await wallet.sendTransaction(transaction, connection, {
25
+ minContextSlot,
26
+ });
27
+ return waitForTransactionConfirmation(signature, connection, lastValidBlockHeight);
28
+ }
29
+ const { from, to, amount, token } = params;
30
+ if (!to || amount == undefined) {
31
+ throw new Error("Missing Solana transfer target or amount");
32
+ }
18
33
  const transaction = new Transaction();
19
- const senderPubKey = new PublicKey(fromAddress);
20
- const receiverPubKey = new PublicKey(toAddress);
34
+ const senderPubKey = new PublicKey(from);
35
+ const receiverPubKey = new PublicKey(to);
21
36
  const instructions = [
22
37
  ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 1000000 }),
23
38
  ];
@@ -56,6 +71,52 @@ export function useSolanaTransaction() {
56
71
  };
57
72
  return { execute };
58
73
  }
74
+ function toSerializedTransactionBytes(value) {
75
+ if (value instanceof Uint8Array)
76
+ return value;
77
+ if (Array.isArray(value)) {
78
+ if (!value.every((byte) => Number.isInteger(byte) && byte >= 0 && byte <= 255)) {
79
+ throw new Error("Invalid Solana transaction payload: array must contain byte values");
80
+ }
81
+ return Uint8Array.from(value);
82
+ }
83
+ if (typeof value !== "string") {
84
+ throw new Error(INVALID_TX_PAYLOAD_ERROR);
85
+ }
86
+ const normalized = value.trim();
87
+ if (!normalized) {
88
+ throw new Error("Invalid Solana transaction payload: empty string");
89
+ }
90
+ const hexValue = normalized.startsWith("0x") ? normalized.slice(2) : normalized;
91
+ const looksLikeHex = hexValue.length > 0 && hexValue.length % 2 === 0 && /^[0-9a-fA-F]+$/.test(hexValue);
92
+ if (looksLikeHex) {
93
+ return hex.decode(hexValue);
94
+ }
95
+ try {
96
+ return Uint8Array.from(atob(normalized), (char) => char.charCodeAt(0));
97
+ }
98
+ catch {
99
+ throw new Error(INVALID_TX_PAYLOAD_ERROR);
100
+ }
101
+ }
102
+ function deserializePreparedSolanaTransaction(serialized) {
103
+ if (serialized instanceof Transaction || serialized instanceof VersionedTransaction) {
104
+ return serialized;
105
+ }
106
+ const bytes = toSerializedTransactionBytes(serialized);
107
+ try {
108
+ return VersionedTransaction.deserialize(bytes);
109
+ }
110
+ catch {
111
+ // fall back to legacy Transaction
112
+ }
113
+ try {
114
+ return Transaction.from(bytes);
115
+ }
116
+ catch {
117
+ throw new Error(INVALID_TX_PAYLOAD_ERROR);
118
+ }
119
+ }
59
120
  async function waitForTransactionConfirmation(signature, connection, lastValidBlockHeight) {
60
121
  const maxRetries = 30;
61
122
  const retryDelay = 2000;
@@ -0,0 +1,6 @@
1
+ export * from "./client";
2
+ export * from "./constants";
3
+ export * from "./use-sign-in-with-sui";
4
+ export * from "./use-sui-transaction";
5
+ export * from "./verify-message";
6
+ export * from "./provider/provider";
@@ -0,0 +1,6 @@
1
+ export * from "./client";
2
+ export * from "./constants";
3
+ export * from "./use-sign-in-with-sui";
4
+ export * from "./use-sui-transaction";
5
+ export * from "./verify-message";
6
+ export * from "./provider/provider";
@@ -1,4 +1,4 @@
1
- import { SuiConfiguration } from "@coin-voyage/crypto/types/wallet";
1
+ import type { SuiConfiguration } from "../../types/wallet";
2
2
  import { PropsWithChildren } from "react";
3
3
  export declare function useInSuiContext(): boolean;
4
4
  export declare function SuiProvider({ children, config, }: PropsWithChildren<{
@@ -1,6 +1,6 @@
1
1
  import { useConnectWallet, useCurrentWallet, useSignPersonalMessage, useWallets } from "@mysten/dapp-kit";
2
2
  import { randomStringForEntropy } from "@stablelib/random";
3
- import { toMessage } from "../lib/utils/message";
3
+ import { toMessage } from "../utils/message";
4
4
  export function useSignInWithSui({ signIn, onError, generateNonce }) {
5
5
  const { mutate: connect } = useConnectWallet();
6
6
  const { currentWallet, isConnected } = useCurrentWallet();
@@ -1,3 +1,4 @@
1
+ import { getSuiPaymentData } from "@coin-voyage/shared/payment";
1
2
  import { useReportTransactionEffects, useSignTransaction, useSuiClient } from "@mysten/dapp-kit";
2
3
  import { Transaction } from "@mysten/sui/transactions";
3
4
  import { SUI_PACKAGE_IDS } from "./constants";
@@ -6,25 +7,50 @@ export function useSUITransaction() {
6
7
  const { mutateAsync: signTransaction } = useSignTransaction();
7
8
  const { mutate: reportTransactionEffects } = useReportTransactionEffects();
8
9
  const execute = async (params) => {
9
- const { fromAddress, toAddress, amount, token } = params;
10
+ const preparedPayment = getSuiPaymentData(params.paymentData);
11
+ if (preparedPayment) {
12
+ const transaction = typeof preparedPayment.transaction === "string"
13
+ ? preparedPayment.transaction
14
+ : Transaction.from(preparedPayment.transaction);
15
+ const { bytes, signature } = await signTransaction({
16
+ transaction,
17
+ });
18
+ const executeResult = await client.executeTransactionBlock({
19
+ transactionBlock: bytes,
20
+ signature,
21
+ options: {
22
+ showRawEffects: true,
23
+ },
24
+ });
25
+ if (executeResult.rawEffects) {
26
+ reportTransactionEffects({
27
+ effects: executeResult.rawEffects,
28
+ });
29
+ }
30
+ return executeResult.digest;
31
+ }
32
+ const { from: owner, to, amount, token } = params;
33
+ if (!to || amount == undefined) {
34
+ throw new Error("Missing Sui transfer target or amount");
35
+ }
10
36
  const tokenAddress = token?.address;
11
37
  const isNative = !tokenAddress || tokenAddress.toLowerCase() === SUI_PACKAGE_IDS["sui"].toLowerCase();
12
38
  const tx = new Transaction();
13
39
  const value = BigInt(amount);
14
40
  if (isNative) {
15
41
  const balance = await client.getBalance({
16
- owner: fromAddress,
42
+ owner,
17
43
  coinType: SUI_PACKAGE_IDS["sui"],
18
44
  });
19
45
  if (BigInt(balance.totalBalance) < value) {
20
46
  throw new Error(`[CHECKOUT] Insufficient balance: ${balance}`);
21
47
  }
22
48
  const [coin] = tx.splitCoins(tx.gas, [value]);
23
- tx.transferObjects([coin], toAddress);
49
+ tx.transferObjects([coin], to);
24
50
  }
25
51
  else {
26
52
  const coins = await client.getCoins({
27
- owner: fromAddress,
53
+ owner,
28
54
  coinType: tokenAddress,
29
55
  });
30
56
  let total = BigInt(0);
@@ -42,7 +68,7 @@ export function useSUITransaction() {
42
68
  tx.mergeCoins(coinInput, coinInputs.slice(1));
43
69
  }
44
70
  const [paymentCoin] = tx.splitCoins(coinInput, [value]);
45
- tx.transferObjects([paymentCoin], toAddress);
71
+ tx.transferObjects([paymentCoin], to);
46
72
  }
47
73
  const gasPrice = await client.getReferenceGasPrice();
48
74
  tx.setGasPrice(gasPrice);
@@ -0,0 +1,6 @@
1
+ export * from "./base-connector";
2
+ export * from "./sign-in-with";
3
+ export * from "./transaction";
4
+ export * from "./utxo-connector-id";
5
+ export * from "./wallet";
6
+ export * from "./wallet-connector";
@@ -0,0 +1,6 @@
1
+ export * from "./base-connector";
2
+ export * from "./sign-in-with";
3
+ export * from "./transaction";
4
+ export * from "./utxo-connector-id";
5
+ export * from "./wallet";
6
+ export * from "./wallet-connector";
@@ -1,10 +1,12 @@
1
+ import type { CryptoPaymentData } from "@coin-voyage/shared/types";
1
2
  export type ExecuteTransaction = {
2
- fromAddress: string;
3
- toAddress: string;
4
- amount: bigint;
3
+ from: string;
4
+ to?: string;
5
+ amount?: bigint;
5
6
  chainId?: number;
6
7
  token?: {
7
8
  address: string;
8
9
  decimals: number;
9
10
  };
11
+ paymentData?: CryptoPaymentData;
10
12
  };
@@ -1,5 +1,5 @@
1
1
  import type { ChainType } from "@coin-voyage/shared/types";
2
- import type { ChainTypeWalletConnector } from "../../types/wallet";
3
- import type { WalletConnector } from "../../types/wallet-connector";
2
+ import type { ChainTypeWalletConnector } from "../types/wallet";
3
+ import type { WalletConnector } from "../types/wallet-connector";
4
4
  export declare const getConnectorId: (connector: WalletConnector) => string;
5
5
  export declare const getConnector: (walletConnector: ChainTypeWalletConnector[], chainType?: ChainType) => WalletConnector;
@@ -1,2 +1,2 @@
1
- import { WalletConnector } from "../../types/wallet-connector";
1
+ import { WalletConnector } from "../types/wallet-connector";
2
2
  export declare const getConnectorIcon: (connector?: WalletConnector) => string | undefined;
@@ -1,4 +1,4 @@
1
- import { getWalletIcon } from "../../assets/icons";
1
+ import { getWalletIcon } from "../assets/icons";
2
2
  export const getConnectorIcon = (connector) => {
3
3
  const connectorId = connector?.id;
4
4
  return connectorId ? getWalletIcon(connectorId) || connector?.icon : connector?.icon;
@@ -0,0 +1,6 @@
1
+ export * from "./connector";
2
+ export * from "./conversions";
3
+ export * from "./get-connector-icon";
4
+ export * from "./get-wallet-priority";
5
+ export * from "./is-wallet-installed";
6
+ export * from "./message";
@@ -0,0 +1,6 @@
1
+ export * from "./connector";
2
+ export * from "./conversions";
3
+ export * from "./get-connector-icon";
4
+ export * from "./get-wallet-priority";
5
+ export * from "./is-wallet-installed";
6
+ export * from "./message";
@@ -1,2 +1,2 @@
1
- import { SignInMessage } from "../../types/sign-in-with";
1
+ import { SignInMessage } from "../types/sign-in-with";
2
2
  export declare const toMessage: (message: SignInMessage, accountName: string) => string;
@@ -40,9 +40,7 @@ export async function createPsbtTx(client, fromAddress, toAddress, amountSats) {
40
40
  txid: utxo.txId,
41
41
  index: utxo.vout,
42
42
  sequence: 0xfffffffd, // RBF
43
- ...(addressType === AddressType.p2wpkh ||
44
- addressType === AddressType.p2wsh ||
45
- addressType === AddressType.p2tr
43
+ ...(addressType === AddressType.p2wpkh || addressType === AddressType.p2wsh || addressType === AddressType.p2tr
46
44
  ? {
47
45
  witnessUtxo: {
48
46
  script: scripts.script,
@@ -1,10 +1,17 @@
1
- import { ankr, blockchair, blockcypher, fallback, http, mempool, } from "@bigmi/core";
1
+ import { ankr, blockchair, blockcypher, fallback, http, mempool } from "@bigmi/core";
2
2
  import { ALCHEMY_KEY } from "../evm/utils";
3
3
  export function createUTXOTransport(rpcConfig) {
4
4
  const primaryRpc = rpcConfig
5
5
  ? http(rpcConfig.url, rpcConfig.config)
6
6
  : http(`https://bitcoin-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`);
7
- return fallback([primaryRpc, http(), blockchair(), blockcypher(), mempool(), ankr({
8
- apiKey: "2a2801137db177be9c80522e690ec8b59ffc5260d030b2671b5e3936b917daac"
9
- })]);
7
+ return fallback([
8
+ primaryRpc,
9
+ http(),
10
+ blockchair(),
11
+ blockcypher(),
12
+ mempool(),
13
+ ankr({
14
+ apiKey: "2a2801137db177be9c80522e690ec8b59ffc5260d030b2671b5e3936b917daac",
15
+ }),
16
+ ]);
10
17
  }
@@ -0,0 +1,10 @@
1
+ export * from "./create-default-utxo-config";
2
+ export * from "./create-psbt-tx";
3
+ export * from "./create-utxo-transport";
4
+ export * from "./estimate-fee";
5
+ export * from "./get-address-utxo";
6
+ export * from "./send-btc";
7
+ export * from "./use-utxo-transaction";
8
+ export * from "./utxo-public-client";
9
+ export * from "./verify-message";
10
+ export * from "./provider/provider";
@@ -0,0 +1,10 @@
1
+ export * from "./create-default-utxo-config";
2
+ export * from "./create-psbt-tx";
3
+ export * from "./create-utxo-transport";
4
+ export * from "./estimate-fee";
5
+ export * from "./get-address-utxo";
6
+ export * from "./send-btc";
7
+ export * from "./use-utxo-transaction";
8
+ export * from "./utxo-public-client";
9
+ export * from "./verify-message";
10
+ export * from "./provider/provider";
@@ -1,4 +1,4 @@
1
- import { UTXOConfiguration } from "@coin-voyage/crypto/utxo/create-default-utxo-config";
1
+ import type { UTXOConfiguration } from "../create-default-utxo-config";
2
2
  import { type PropsWithChildren } from "react";
3
3
  export declare function useInBigmiContext(): boolean;
4
4
  export declare function UTXOProvider({ children, config }: PropsWithChildren<{
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { BigmiContext } from "@bigmi/react";
3
- import { UTXOBaseProvider } from "@coin-voyage/crypto/utxo/provider/base-provider";
4
- import { UTXOExternalContext } from "@coin-voyage/crypto/utxo/provider/external-context";
3
+ import { UTXOBaseProvider } from "./base-provider";
4
+ import { UTXOExternalContext } from "./external-context";
5
5
  import { useContext } from "react";
6
6
  export function useInBigmiContext() {
7
7
  try {
@@ -1,12 +1,20 @@
1
1
  import { useAccount } from "@bigmi/react";
2
+ import { getBitcoinPaymentData } from "@coin-voyage/shared/payment";
2
3
  import { sendBtc } from "./send-btc";
3
4
  export function useUTXOTransaction() {
4
5
  const { account, connector } = useAccount();
5
6
  const execute = async (params) => {
6
- const { toAddress, amount } = params;
7
+ const bitcoinPaymentData = getBitcoinPaymentData(params.paymentData);
8
+ if (bitcoinPaymentData) {
9
+ throw new Error("Prepared Bitcoin transactions are not supported in wallet flow yet.");
10
+ }
11
+ const { to: toAddress, amount } = params;
7
12
  if (!connector?.id || !account?.address) {
8
13
  throw new Error("No connection found");
9
14
  }
15
+ if (!toAddress || amount == undefined) {
16
+ throw new Error("Missing Bitcoin transfer target or amount");
17
+ }
10
18
  const txhash = await sendBtc({
11
19
  senderAddress: account.address,
12
20
  recipient: toAddress,
@@ -0,0 +1 @@
1
+ export * from "./wallet-provider";
@@ -0,0 +1 @@
1
+ export * from "./wallet-provider";
@@ -1,4 +1,4 @@
1
- import { type WalletConfiguration } from "@coin-voyage/crypto/types/wallet";
1
+ import type { WalletConfiguration } from "../types";
2
2
  import { type PropsWithChildren } from "react";
3
3
  export declare function WalletProvider({ children, config, }: PropsWithChildren<{
4
4
  config?: WalletConfiguration;
package/package.json CHANGED
@@ -1,19 +1,51 @@
1
1
  {
2
2
  "name": "@coin-voyage/crypto",
3
3
  "description": "Crypto utilities for Coin Voyage",
4
- "version": "2.3.0",
4
+ "version": "2.4.0-beta.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "author": "Lars <lars@coinvoyage.io>",
8
8
  "homepage": "https://coinvoyage.io",
9
9
  "exports": {
10
+ "./config": {
11
+ "types": "./dist/config/index.d.ts",
12
+ "default": "./dist/config/index.js"
13
+ },
14
+ "./connectors": {
15
+ "types": "./dist/connectors/index.d.ts",
16
+ "default": "./dist/connectors/index.js"
17
+ },
18
+ "./evm": {
19
+ "types": "./dist/evm/index.d.ts",
20
+ "default": "./dist/evm/index.js"
21
+ },
10
22
  "./hooks": {
11
23
  "types": "./dist/hooks/index.d.ts",
12
24
  "default": "./dist/hooks/index.js"
13
25
  },
14
- "./*": {
15
- "types": "./dist/*.d.ts",
16
- "default": "./dist/*.js"
26
+ "./solana": {
27
+ "types": "./dist/solana/index.d.ts",
28
+ "default": "./dist/solana/index.js"
29
+ },
30
+ "./sui": {
31
+ "types": "./dist/sui/index.d.ts",
32
+ "default": "./dist/sui/index.js"
33
+ },
34
+ "./types": {
35
+ "types": "./dist/types/index.d.ts",
36
+ "default": "./dist/types/index.js"
37
+ },
38
+ "./utils": {
39
+ "types": "./dist/utils/index.d.ts",
40
+ "default": "./dist/utils/index.js"
41
+ },
42
+ "./utxo": {
43
+ "types": "./dist/utxo/index.d.ts",
44
+ "default": "./dist/utxo/index.js"
45
+ },
46
+ "./wallets": {
47
+ "types": "./dist/wallets/index.d.ts",
48
+ "default": "./dist/wallets/index.js"
17
49
  }
18
50
  },
19
51
  "files": [
@@ -21,11 +53,35 @@
21
53
  ],
22
54
  "typesVersions": {
23
55
  "*": {
56
+ "config": [
57
+ "dist/config/index.d.ts"
58
+ ],
59
+ "connectors": [
60
+ "dist/connectors/index.d.ts"
61
+ ],
62
+ "evm": [
63
+ "dist/evm/index.d.ts"
64
+ ],
24
65
  "hooks": [
25
66
  "dist/hooks/index.d.ts"
26
67
  ],
27
- "*": [
28
- "dist/*.d.ts"
68
+ "solana": [
69
+ "dist/solana/index.d.ts"
70
+ ],
71
+ "sui": [
72
+ "dist/sui/index.d.ts"
73
+ ],
74
+ "types": [
75
+ "dist/types/index.d.ts"
76
+ ],
77
+ "utils": [
78
+ "dist/utils/index.d.ts"
79
+ ],
80
+ "utxo": [
81
+ "dist/utxo/index.d.ts"
82
+ ],
83
+ "wallets": [
84
+ "dist/wallets/index.d.ts"
29
85
  ]
30
86
  }
31
87
  },
@@ -50,7 +106,7 @@
50
106
  "@solana/wallet-adapter-walletconnect": "0.1.21",
51
107
  "@solana/wallet-adapter-base": "0.9.27",
52
108
  "@solana/wallet-adapter-coinbase": "0.1.23",
53
- "@coin-voyage/shared": "2.3.1"
109
+ "@coin-voyage/shared": "2.4.0-beta.0"
54
110
  },
55
111
  "devDependencies": {
56
112
  "@types/elliptic": "6.4.18"
@@ -1,9 +0,0 @@
1
- import { WalletProviderProps } from "@mysten/dapp-kit";
2
- import { PropsWithChildren } from "react";
3
- export declare function useInSuiContext(): boolean;
4
- export declare function SuiProvider({ children, config, }: PropsWithChildren<{
5
- config?: {
6
- rpcUrl?: string;
7
- walletConfiguration?: WalletProviderProps;
8
- };
9
- }>): import("react/jsx-runtime").JSX.Element;
@@ -1,17 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { SuiBaseProvider } from "@coin-voyage/crypto/sui/provider/base-provider";
3
- import { SuiExternalContext } from "@coin-voyage/crypto/sui/provider/external-context";
4
- import { useSuiClientContext } from "@mysten/dapp-kit";
5
- export function useInSuiContext() {
6
- try {
7
- const externalSuiContext = useSuiClientContext();
8
- return Boolean(externalSuiContext.config);
9
- }
10
- catch {
11
- return false;
12
- }
13
- }
14
- export function SuiProvider({ children, config, }) {
15
- const inSUIContext = useInSuiContext();
16
- return inSUIContext ? (_jsx(SuiExternalContext.Provider, { value: inSUIContext, children: children })) : (_jsx(SuiBaseProvider, { config: config, children: children }));
17
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes