thirdweb 5.48.1 → 5.48.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 (184) hide show
  1. package/dist/cjs/exports/pay.js +3 -1
  2. package/dist/cjs/exports/pay.js.map +1 -1
  3. package/dist/cjs/exports/thirdweb.js +3 -1
  4. package/dist/cjs/exports/thirdweb.js.map +1 -1
  5. package/dist/cjs/pay/buyWithCrypto/commonTypes.js +3 -0
  6. package/dist/cjs/pay/buyWithCrypto/commonTypes.js.map +1 -0
  7. package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
  8. package/dist/cjs/pay/buyWithCrypto/getTransfer.js +95 -0
  9. package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -0
  10. package/dist/cjs/pay/utils/definitions.js +7 -1
  11. package/dist/cjs/pay/utils/definitions.js.map +1 -1
  12. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  13. package/dist/cjs/react/native/ui/connect/ConnectedButton.js +5 -1
  14. package/dist/cjs/react/native/ui/connect/ConnectedButton.js.map +1 -1
  15. package/dist/cjs/react/native/ui/connect/ConnectedModal.js +2 -1
  16. package/dist/cjs/react/native/ui/connect/ConnectedModal.js.map +1 -1
  17. package/dist/cjs/react/native/ui/connect/TokenListScreen.js +5 -1
  18. package/dist/cjs/react/native/ui/connect/TokenListScreen.js.map +1 -1
  19. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +28 -22
  20. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  21. package/dist/cjs/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js +9 -0
  22. package/dist/cjs/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js.map +1 -0
  23. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -1
  24. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  25. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js +9 -3
  26. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js.map +1 -1
  27. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +34 -2
  28. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
  29. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +8 -0
  30. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
  31. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
  33. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js +118 -0
  34. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js.map +1 -0
  35. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js +7 -76
  36. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js.map +1 -1
  37. package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js +2 -1
  38. package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
  39. package/dist/cjs/stories/ConnectButton.stories.js +28 -0
  40. package/dist/cjs/stories/ConnectButton.stories.js.map +1 -0
  41. package/dist/cjs/stories/PayEmbed.stories.js +38 -0
  42. package/dist/cjs/stories/PayEmbed.stories.js.map +1 -0
  43. package/dist/cjs/stories/utils.js +27 -0
  44. package/dist/cjs/stories/utils.js.map +1 -0
  45. package/dist/cjs/transaction/actions/send-transaction.js.map +1 -1
  46. package/dist/cjs/utils/signatures/sign-message.js +13 -19
  47. package/dist/cjs/utils/signatures/sign-message.js.map +1 -1
  48. package/dist/cjs/version.js +1 -1
  49. package/dist/cjs/wallets/in-app/core/wallet/index.js +4 -1
  50. package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
  51. package/dist/esm/exports/pay.js +2 -0
  52. package/dist/esm/exports/pay.js.map +1 -1
  53. package/dist/esm/exports/thirdweb.js +2 -0
  54. package/dist/esm/exports/thirdweb.js.map +1 -1
  55. package/dist/esm/pay/buyWithCrypto/commonTypes.js +2 -0
  56. package/dist/esm/pay/buyWithCrypto/commonTypes.js.map +1 -0
  57. package/dist/esm/pay/buyWithCrypto/getQuote.js +1 -1
  58. package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
  59. package/dist/esm/pay/buyWithCrypto/getTransfer.js +92 -0
  60. package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -0
  61. package/dist/esm/pay/utils/definitions.js +5 -0
  62. package/dist/esm/pay/utils/definitions.js.map +1 -1
  63. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  64. package/dist/esm/react/native/ui/connect/ConnectedButton.js +5 -1
  65. package/dist/esm/react/native/ui/connect/ConnectedButton.js.map +1 -1
  66. package/dist/esm/react/native/ui/connect/ConnectedModal.js +2 -1
  67. package/dist/esm/react/native/ui/connect/ConnectedModal.js.map +1 -1
  68. package/dist/esm/react/native/ui/connect/TokenListScreen.js +5 -1
  69. package/dist/esm/react/native/ui/connect/TokenListScreen.js.map +1 -1
  70. package/dist/esm/react/web/ui/ConnectWallet/Details.js +28 -22
  71. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  72. package/dist/esm/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js +5 -0
  73. package/dist/esm/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js.map +1 -0
  74. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -1
  75. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  76. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js +8 -2
  77. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js.map +1 -1
  78. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +35 -3
  79. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
  80. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +8 -0
  81. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
  82. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
  83. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
  84. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js +115 -0
  85. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js.map +1 -0
  86. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js +8 -77
  87. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js.map +1 -1
  88. package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js +2 -1
  89. package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
  90. package/dist/esm/stories/ConnectButton.stories.js +25 -0
  91. package/dist/esm/stories/ConnectButton.stories.js.map +1 -0
  92. package/dist/esm/stories/PayEmbed.stories.js +35 -0
  93. package/dist/esm/stories/PayEmbed.stories.js.map +1 -0
  94. package/dist/esm/stories/utils.js +24 -0
  95. package/dist/esm/stories/utils.js.map +1 -0
  96. package/dist/esm/transaction/actions/send-transaction.js.map +1 -1
  97. package/dist/esm/utils/signatures/sign-message.js +13 -19
  98. package/dist/esm/utils/signatures/sign-message.js.map +1 -1
  99. package/dist/esm/version.js +1 -1
  100. package/dist/esm/wallets/in-app/core/wallet/index.js +4 -1
  101. package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
  102. package/dist/types/exports/pay.d.ts +3 -1
  103. package/dist/types/exports/pay.d.ts.map +1 -1
  104. package/dist/types/exports/thirdweb.d.ts +3 -1
  105. package/dist/types/exports/thirdweb.d.ts.map +1 -1
  106. package/dist/types/pay/buyWithCrypto/commonTypes.d.ts +36 -0
  107. package/dist/types/pay/buyWithCrypto/commonTypes.d.ts.map +1 -0
  108. package/dist/types/pay/buyWithCrypto/getQuote.d.ts +1 -24
  109. package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
  110. package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -1
  111. package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
  112. package/dist/types/pay/buyWithCrypto/getTransfer.d.ts +85 -0
  113. package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -0
  114. package/dist/types/pay/buyWithFiat/getQuote.d.ts +1 -1
  115. package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
  116. package/dist/types/pay/utils/definitions.d.ts +5 -0
  117. package/dist/types/pay/utils/definitions.d.ts.map +1 -1
  118. package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +15 -0
  119. package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
  120. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +3 -0
  121. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  122. package/dist/types/react/native/ui/connect/ConnectedButton.d.ts.map +1 -1
  123. package/dist/types/react/native/ui/connect/ConnectedModal.d.ts.map +1 -1
  124. package/dist/types/react/native/ui/connect/TokenListScreen.d.ts.map +1 -1
  125. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +6 -0
  126. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  127. package/dist/types/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.d.ts +3 -0
  128. package/dist/types/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.d.ts.map +1 -0
  129. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.d.ts +2 -2
  130. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.d.ts.map +1 -1
  131. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts +3 -2
  132. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts.map +1 -1
  133. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.d.ts.map +1 -1
  134. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts +1 -1
  135. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts.map +1 -1
  136. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.d.ts +20 -0
  137. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.d.ts.map +1 -0
  138. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.d.ts +5 -1
  139. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.d.ts.map +1 -1
  140. package/dist/types/react/web/ui/ConnectWallet/screens/formatTokenBalance.d.ts.map +1 -1
  141. package/dist/types/stories/ConnectButton.stories.d.ts +18 -0
  142. package/dist/types/stories/ConnectButton.stories.d.ts.map +1 -0
  143. package/dist/types/stories/PayEmbed.stories.d.ts +19 -0
  144. package/dist/types/stories/PayEmbed.stories.d.ts.map +1 -0
  145. package/dist/types/stories/utils.d.ts +5 -0
  146. package/dist/types/stories/utils.d.ts.map +1 -0
  147. package/dist/types/transaction/actions/send-transaction.d.ts +12 -2
  148. package/dist/types/transaction/actions/send-transaction.d.ts.map +1 -1
  149. package/dist/types/utils/signatures/sign-message.d.ts +26 -3
  150. package/dist/types/utils/signatures/sign-message.d.ts.map +1 -1
  151. package/dist/types/version.d.ts +1 -1
  152. package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
  153. package/package.json +15 -2
  154. package/src/exports/pay.ts +11 -2
  155. package/src/exports/thirdweb.ts +11 -2
  156. package/src/pay/buyWithCrypto/commonTypes.ts +40 -0
  157. package/src/pay/buyWithCrypto/getQuote.ts +8 -42
  158. package/src/pay/buyWithCrypto/getStatus.ts +1 -1
  159. package/src/pay/buyWithCrypto/getTransfer.ts +185 -0
  160. package/src/pay/buyWithFiat/getQuote.ts +1 -1
  161. package/src/pay/utils/definitions.ts +7 -0
  162. package/src/react/core/hooks/connection/ConnectButtonProps.ts +16 -0
  163. package/src/react/core/hooks/transaction/useSendTransaction.ts +3 -0
  164. package/src/react/native/ui/connect/ConnectedButton.tsx +6 -1
  165. package/src/react/native/ui/connect/ConnectedModal.tsx +2 -1
  166. package/src/react/native/ui/connect/TokenListScreen.tsx +6 -1
  167. package/src/react/web/ui/ConnectWallet/Details.tsx +93 -77
  168. package/src/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.tsx +21 -0
  169. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +8 -1
  170. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.tsx +9 -3
  171. package/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts +47 -3
  172. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx +26 -0
  173. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.tsx +3 -3
  174. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx +284 -0
  175. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.tsx +29 -220
  176. package/src/react/web/ui/ConnectWallet/screens/formatTokenBalance.ts +3 -1
  177. package/src/stories/ConnectButton.stories.ts +31 -0
  178. package/src/stories/PayEmbed.stories.ts +42 -0
  179. package/src/stories/utils.tsx +29 -0
  180. package/src/transaction/actions/send-transaction.ts +12 -3
  181. package/src/utils/signatures/sign-message.test.ts +78 -50
  182. package/src/utils/signatures/sign-message.ts +44 -9
  183. package/src/version.ts +1 -1
  184. package/src/wallets/in-app/core/wallet/index.ts +2 -0
@@ -1,3 +1,5 @@
1
+ import { formatNumber } from "../../../../../utils/formatNumber.js";
2
+
1
3
  /**
2
4
  * @internal
3
5
  * @param balanceData
@@ -13,7 +15,7 @@ export function formatTokenBalance(
13
15
  showSymbol = true,
14
16
  ) {
15
17
  return (
16
- Number(balanceData.displayValue).toFixed(3) +
18
+ formatNumber(Number(balanceData.displayValue), 5) +
17
19
  (showSymbol ? ` ${balanceData.symbol}` : "")
18
20
  );
19
21
  }
@@ -0,0 +1,31 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { ConnectButton } from "../react/web/ui/ConnectWallet/ConnectButton.js";
3
+ import { storyClient } from "./utils.js";
4
+
5
+ const meta = {
6
+ title: "Connect/ConnectButton",
7
+ component: ConnectButton,
8
+ parameters: {
9
+ layout: "centered",
10
+ },
11
+ tags: ["autodocs"],
12
+ args: {
13
+ client: storyClient,
14
+ },
15
+ } satisfies Meta<typeof ConnectButton>;
16
+
17
+ type Story = StoryObj<typeof meta>;
18
+
19
+ export const Dark: Story = {
20
+ args: {
21
+ theme: "dark",
22
+ },
23
+ };
24
+
25
+ export const Light: Story = {
26
+ args: {
27
+ theme: "light",
28
+ },
29
+ };
30
+
31
+ export default meta;
@@ -0,0 +1,42 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { PayEmbed } from "../react/web/ui/PayEmbed.js";
3
+ import { storyClient } from "./utils.js";
4
+
5
+ const meta = {
6
+ title: "Connect/PayEmbed",
7
+ component: PayEmbed,
8
+ parameters: {
9
+ layout: "centered",
10
+ },
11
+ tags: ["autodocs"],
12
+ args: {
13
+ client: storyClient,
14
+ },
15
+ } satisfies Meta<typeof PayEmbed>;
16
+
17
+ type Story = StoryObj<typeof meta>;
18
+
19
+ export const Dark: Story = {
20
+ args: {
21
+ theme: "dark",
22
+ },
23
+ };
24
+
25
+ export const FiatTestMode: Story = {
26
+ args: {
27
+ theme: "dark",
28
+ payOptions: {
29
+ buyWithFiat: {
30
+ testMode: true,
31
+ },
32
+ },
33
+ },
34
+ };
35
+
36
+ export const Light: Story = {
37
+ args: {
38
+ theme: "light",
39
+ },
40
+ };
41
+
42
+ export default meta;
@@ -0,0 +1,29 @@
1
+ import { generatePrivateKey } from "viem/accounts";
2
+ import { createWalletAdapter } from "../adapters/wallet-adapter.js";
3
+ import { ethereum } from "../chains/chain-definitions/ethereum.js";
4
+ import { createThirdwebClient } from "../client/client.js";
5
+ import type { Account } from "../wallets/interfaces/wallet.js";
6
+ import { privateKeyToAccount } from "../wallets/private-key.js";
7
+
8
+ const clientId = process.env.STORYBOOK_CLIENT_ID;
9
+
10
+ if (!clientId) {
11
+ throw new Error("STORYBOOK_CLIENT_ID env is not configured");
12
+ }
13
+
14
+ export const storyClient = createThirdwebClient({
15
+ clientId: clientId,
16
+ });
17
+
18
+ export const storyAccount: Account = privateKeyToAccount({
19
+ client: storyClient,
20
+ privateKey: process.env.STORYBOOK_ACCOUNT_PRIVATE_KEY || generatePrivateKey(),
21
+ });
22
+
23
+ export const storyWallet = createWalletAdapter({
24
+ adaptedAccount: storyAccount,
25
+ client: storyClient,
26
+ chain: ethereum,
27
+ onDisconnect: () => {},
28
+ switchChain: () => {},
29
+ });
@@ -5,13 +5,22 @@ import type { GaslessOptions } from "./gasless/types.js";
5
5
  import { toSerializableTransaction } from "./to-serializable-transaction.js";
6
6
  import type { WaitForReceiptOptions } from "./wait-for-tx-receipt.js";
7
7
 
8
- export type SendTransactionOptions = {
8
+ /** Send transaction options */
9
+ export interface SendTransactionOptions {
10
+ /**
11
+ * The account to send the transaction with
12
+ */
9
13
  account: Account;
10
- // TODO: update this to `Transaction<"prepared">` once the type is available to ensure only prepared transactions are accepted
14
+ /**
15
+ * The prepared transaction to send
16
+ */
11
17
  // biome-ignore lint/suspicious/noExplicitAny: library function that accepts any prepared transaction type
12
18
  transaction: PreparedTransaction<any>;
19
+ /**
20
+ * Gasless options for the transaction, if applicable
21
+ */
13
22
  gasless?: GaslessOptions;
14
- };
23
+ }
15
24
 
16
25
  /**
17
26
  * Sends a transaction using the provided account.
@@ -1,57 +1,85 @@
1
- import { expect, test } from "vitest";
1
+ import { describe, expect, test } from "vitest";
2
2
 
3
- import { ANVIL_PKEY_A } from "~test/test-wallets.js";
3
+ import { ANVIL_PKEY_A, TEST_ACCOUNT_A } from "~test/test-wallets.js";
4
4
  import { signMessage } from "./sign-message.js";
5
5
 
6
- test("default", async () => {
7
- expect(
8
- signMessage({
6
+ describe("signMessage", async () => {
7
+ test("privateKey", async () => {
8
+ expect(
9
+ signMessage({
10
+ message: "hello world",
11
+ privateKey: ANVIL_PKEY_A,
12
+ }),
13
+ ).toMatchInlineSnapshot(
14
+ '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
15
+ );
16
+
17
+ expect(
18
+ signMessage({
19
+ message: "🤯",
20
+ privateKey: ANVIL_PKEY_A,
21
+ }),
22
+ ).toMatchInlineSnapshot(
23
+ '"0xc0cd7599731c37aa4c0815a89dc8dcb4ce479f83df7ee8ffc606a9ef29323e814b54bb8935b56e7c690f1ee4c6290da5c2f6df6fc3443fbe96bb1846a2c4fefc1c"',
24
+ );
25
+
26
+ expect(
27
+ signMessage({
28
+ message: "0x787037Ba5b7eA8a8737627FfB67d35FdCaAd9A18",
29
+ privateKey: ANVIL_PKEY_A,
30
+ }),
31
+ ).toMatchInlineSnapshot(
32
+ '"0x151436da0ef734f06ae71f4b907a062fa5683b40af4221e86dfe5f2fc9f09ffa40c90fee4a0e48311506b84dc6f20e513dc4dc434f0f70a03af6ff3e22c7b7591c"',
33
+ );
34
+ });
35
+
36
+ test("raw", async () => {
37
+ expect(
38
+ signMessage({
39
+ message: { raw: "0x68656c6c6f20776f726c64" },
40
+ privateKey: ANVIL_PKEY_A,
41
+ }),
42
+ ).toMatchInlineSnapshot(
43
+ '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
44
+ );
45
+
46
+ expect(
47
+ signMessage({
48
+ message: {
49
+ raw: Uint8Array.from([
50
+ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,
51
+ ]),
52
+ },
53
+ privateKey: ANVIL_PKEY_A,
54
+ }),
55
+ ).toMatchInlineSnapshot(
56
+ '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
57
+ );
58
+ });
59
+
60
+ test("account", async () => {
61
+ const basicSignature = await signMessage({
9
62
  message: "hello world",
10
- privateKey: ANVIL_PKEY_A,
11
- }),
12
- ).toMatchInlineSnapshot(
13
- '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
14
- );
15
-
16
- expect(
17
- signMessage({
63
+ account: TEST_ACCOUNT_A,
64
+ });
65
+ expect(basicSignature).toMatchInlineSnapshot(
66
+ '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
67
+ );
68
+
69
+ const emojiSignature = await signMessage({
18
70
  message: "🤯",
19
- privateKey: ANVIL_PKEY_A,
20
- }),
21
- ).toMatchInlineSnapshot(
22
- '"0xc0cd7599731c37aa4c0815a89dc8dcb4ce479f83df7ee8ffc606a9ef29323e814b54bb8935b56e7c690f1ee4c6290da5c2f6df6fc3443fbe96bb1846a2c4fefc1c"',
23
- );
24
-
25
- expect(
26
- signMessage({
27
- message: "0x787037Ba5b7eA8a8737627FfB67d35FdCaAd9A18",
28
- privateKey: ANVIL_PKEY_A,
29
- }),
30
- ).toMatchInlineSnapshot(
31
- '"0x151436da0ef734f06ae71f4b907a062fa5683b40af4221e86dfe5f2fc9f09ffa40c90fee4a0e48311506b84dc6f20e513dc4dc434f0f70a03af6ff3e22c7b7591c"',
32
- );
33
- });
71
+ account: TEST_ACCOUNT_A,
72
+ });
73
+ expect(emojiSignature).toMatchInlineSnapshot(
74
+ '"0xc0cd7599731c37aa4c0815a89dc8dcb4ce479f83df7ee8ffc606a9ef29323e814b54bb8935b56e7c690f1ee4c6290da5c2f6df6fc3443fbe96bb1846a2c4fefc1c"',
75
+ );
34
76
 
35
- test("raw", async () => {
36
- expect(
37
- signMessage({
38
- message: { raw: "0x68656c6c6f20776f726c64" },
39
- privateKey: ANVIL_PKEY_A,
40
- }),
41
- ).toMatchInlineSnapshot(
42
- '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
43
- );
44
-
45
- expect(
46
- signMessage({
47
- message: {
48
- raw: Uint8Array.from([
49
- 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,
50
- ]),
51
- },
52
- privateKey: ANVIL_PKEY_A,
53
- }),
54
- ).toMatchInlineSnapshot(
55
- '"0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"',
56
- );
77
+ const addressSignature = await signMessage({
78
+ message: "0x787037Ba5b7eA8a8737627FfB67d35FdCaAd9A18",
79
+ account: TEST_ACCOUNT_A,
80
+ });
81
+ expect(addressSignature).toMatchInlineSnapshot(
82
+ '"0x151436da0ef734f06ae71f4b907a062fa5683b40af4221e86dfe5f2fc9f09ffa40c90fee4a0e48311506b84dc6f20e513dc4dc434f0f70a03af6ff3e22c7b7591c"',
83
+ );
84
+ });
57
85
  });
@@ -1,16 +1,18 @@
1
+ import type { Account } from "../../wallets/interfaces/wallet.js";
1
2
  import type { Hex } from "../encoding/hex.js";
2
3
  import { hashMessage } from "../hashing/hashMessage.js";
3
4
  import type { Prettify } from "../type-utils.js";
4
5
  import { sign } from "./sign.js";
5
6
  import { signatureToHex } from "./signature-to-hex.js";
6
7
 
8
+ type Message = Prettify<
9
+ | string
10
+ | {
11
+ raw: Hex | Uint8Array;
12
+ }
13
+ >;
7
14
  export type SignMessageOptions = {
8
- message: Prettify<
9
- | string
10
- | {
11
- raw: Hex | Uint8Array;
12
- }
13
- >;
15
+ message: Message;
14
16
  privateKey: Hex;
15
17
  };
16
18
 
@@ -30,7 +32,40 @@ export type SignMessageOptions = {
30
32
  * ```
31
33
  * @utils
32
34
  */
33
- export function signMessage({ message, privateKey }: SignMessageOptions): Hex {
34
- const signature = sign({ hash: hashMessage(message), privateKey });
35
- return signatureToHex(signature);
35
+ export function signMessage({ message, privateKey }: SignMessageOptions): Hex;
36
+
37
+ /**
38
+ * Signs a string message with a given account.
39
+ * @param options The options for signing.
40
+ * @param options.message The message to be signed as a string or object containing raw hex or bytes
41
+ * @param options.account The account to be used
42
+ * @returns The signature as a hex string
43
+ * @example
44
+ * ```ts
45
+ * import { signMessage } from "thirdweb/utils";
46
+ * await signMessage({
47
+ * message: "Hello, world!",
48
+ * account
49
+ * });
50
+ * ```
51
+ * @walletUtils
52
+ */
53
+ export function signMessage({
54
+ message,
55
+ account,
56
+ }: { message: Message; account: Account }): Promise<Hex>;
57
+
58
+ export function signMessage(
59
+ options: SignMessageOptions | { message: Message; account: Account },
60
+ ): Hex | Promise<Hex> {
61
+ if ("privateKey" in options) {
62
+ const { message, privateKey } = options;
63
+ const signature = sign({ hash: hashMessage(message), privateKey });
64
+ return signatureToHex(signature);
65
+ } else if ("account" in options) {
66
+ const { message, account } = options;
67
+ return account.signMessage({ message });
68
+ } else {
69
+ throw new Error("Either privateKey or account is required");
70
+ }
36
71
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.48.1";
1
+ export const version = "5.48.2";
@@ -40,7 +40,9 @@ export async function connectInAppWallet(
40
40
  connector: InAppConnector,
41
41
  ): Promise<[Account, Chain]> {
42
42
  if (
43
+ // if auth mode is not specified, the default is popup
43
44
  createOptions?.auth?.mode !== "popup" &&
45
+ createOptions?.auth?.mode !== undefined &&
44
46
  connector.authenticateWithRedirect
45
47
  ) {
46
48
  const strategy = options.strategy;