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.
- package/dist/cjs/exports/pay.js +3 -1
- package/dist/cjs/exports/pay.js.map +1 -1
- package/dist/cjs/exports/thirdweb.js +3 -1
- package/dist/cjs/exports/thirdweb.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/commonTypes.js +3 -0
- package/dist/cjs/pay/buyWithCrypto/commonTypes.js.map +1 -0
- package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js +95 -0
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -0
- package/dist/cjs/pay/utils/definitions.js +7 -1
- package/dist/cjs/pay/utils/definitions.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectedButton.js +5 -1
- package/dist/cjs/react/native/ui/connect/ConnectedButton.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectedModal.js +2 -1
- package/dist/cjs/react/native/ui/connect/ConnectedModal.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/TokenListScreen.js +5 -1
- package/dist/cjs/react/native/ui/connect/TokenListScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +28 -22
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js +9 -0
- package/dist/cjs/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js +9 -3
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +34 -2
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +8 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js +118 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js +7 -76
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js +2 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
- package/dist/cjs/stories/ConnectButton.stories.js +28 -0
- package/dist/cjs/stories/ConnectButton.stories.js.map +1 -0
- package/dist/cjs/stories/PayEmbed.stories.js +38 -0
- package/dist/cjs/stories/PayEmbed.stories.js.map +1 -0
- package/dist/cjs/stories/utils.js +27 -0
- package/dist/cjs/stories/utils.js.map +1 -0
- package/dist/cjs/transaction/actions/send-transaction.js.map +1 -1
- package/dist/cjs/utils/signatures/sign-message.js +13 -19
- package/dist/cjs/utils/signatures/sign-message.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +4 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/exports/pay.js +2 -0
- package/dist/esm/exports/pay.js.map +1 -1
- package/dist/esm/exports/thirdweb.js +2 -0
- package/dist/esm/exports/thirdweb.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/commonTypes.js +2 -0
- package/dist/esm/pay/buyWithCrypto/commonTypes.js.map +1 -0
- package/dist/esm/pay/buyWithCrypto/getQuote.js +1 -1
- package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/getTransfer.js +92 -0
- package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -0
- package/dist/esm/pay/utils/definitions.js +5 -0
- package/dist/esm/pay/utils/definitions.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectedButton.js +5 -1
- package/dist/esm/react/native/ui/connect/ConnectedButton.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectedModal.js +2 -1
- package/dist/esm/react/native/ui/connect/ConnectedModal.js.map +1 -1
- package/dist/esm/react/native/ui/connect/TokenListScreen.js +5 -1
- package/dist/esm/react/native/ui/connect/TokenListScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +28 -22
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js +5 -0
- package/dist/esm/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js +8 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +35 -3
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +8 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js +115 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js +8 -77
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js +2 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
- package/dist/esm/stories/ConnectButton.stories.js +25 -0
- package/dist/esm/stories/ConnectButton.stories.js.map +1 -0
- package/dist/esm/stories/PayEmbed.stories.js +35 -0
- package/dist/esm/stories/PayEmbed.stories.js.map +1 -0
- package/dist/esm/stories/utils.js +24 -0
- package/dist/esm/stories/utils.js.map +1 -0
- package/dist/esm/transaction/actions/send-transaction.js.map +1 -1
- package/dist/esm/utils/signatures/sign-message.js +13 -19
- package/dist/esm/utils/signatures/sign-message.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +4 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/types/exports/pay.d.ts +3 -1
- package/dist/types/exports/pay.d.ts.map +1 -1
- package/dist/types/exports/thirdweb.d.ts +3 -1
- package/dist/types/exports/thirdweb.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/commonTypes.d.ts +36 -0
- package/dist/types/pay/buyWithCrypto/commonTypes.d.ts.map +1 -0
- package/dist/types/pay/buyWithCrypto/getQuote.d.ts +1 -24
- package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -1
- package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getTransfer.d.ts +85 -0
- package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -0
- package/dist/types/pay/buyWithFiat/getQuote.d.ts +1 -1
- package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
- package/dist/types/pay/utils/definitions.d.ts +5 -0
- package/dist/types/pay/utils/definitions.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +15 -0
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +3 -0
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/ConnectedButton.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/ConnectedModal.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/TokenListScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +6 -0
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.d.ts +3 -0
- package/dist/types/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.d.ts +2 -2
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts +3 -2
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.d.ts +20 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.d.ts +5 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/formatTokenBalance.d.ts.map +1 -1
- package/dist/types/stories/ConnectButton.stories.d.ts +18 -0
- package/dist/types/stories/ConnectButton.stories.d.ts.map +1 -0
- package/dist/types/stories/PayEmbed.stories.d.ts +19 -0
- package/dist/types/stories/PayEmbed.stories.d.ts.map +1 -0
- package/dist/types/stories/utils.d.ts +5 -0
- package/dist/types/stories/utils.d.ts.map +1 -0
- package/dist/types/transaction/actions/send-transaction.d.ts +12 -2
- package/dist/types/transaction/actions/send-transaction.d.ts.map +1 -1
- package/dist/types/utils/signatures/sign-message.d.ts +26 -3
- package/dist/types/utils/signatures/sign-message.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/package.json +15 -2
- package/src/exports/pay.ts +11 -2
- package/src/exports/thirdweb.ts +11 -2
- package/src/pay/buyWithCrypto/commonTypes.ts +40 -0
- package/src/pay/buyWithCrypto/getQuote.ts +8 -42
- package/src/pay/buyWithCrypto/getStatus.ts +1 -1
- package/src/pay/buyWithCrypto/getTransfer.ts +185 -0
- package/src/pay/buyWithFiat/getQuote.ts +1 -1
- package/src/pay/utils/definitions.ts +7 -0
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +16 -0
- package/src/react/core/hooks/transaction/useSendTransaction.ts +3 -0
- package/src/react/native/ui/connect/ConnectedButton.tsx +6 -1
- package/src/react/native/ui/connect/ConnectedModal.tsx +2 -1
- package/src/react/native/ui/connect/TokenListScreen.tsx +6 -1
- package/src/react/web/ui/ConnectWallet/Details.tsx +93 -77
- package/src/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.tsx +21 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +8 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.tsx +9 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts +47 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx +26 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.tsx +3 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx +284 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.tsx +29 -220
- package/src/react/web/ui/ConnectWallet/screens/formatTokenBalance.ts +3 -1
- package/src/stories/ConnectButton.stories.ts +31 -0
- package/src/stories/PayEmbed.stories.ts +42 -0
- package/src/stories/utils.tsx +29 -0
- package/src/transaction/actions/send-transaction.ts +12 -3
- package/src/utils/signatures/sign-message.test.ts +78 -50
- package/src/utils/signatures/sign-message.ts +44 -9
- package/src/version.ts +1 -1
- 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)
|
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
|
-
|
8
|
+
/** Send transaction options */
|
9
|
+
export interface SendTransactionOptions {
|
10
|
+
/**
|
11
|
+
* The account to send the transaction with
|
12
|
+
*/
|
9
13
|
account: Account;
|
10
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
20
|
-
})
|
21
|
-
|
22
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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:
|
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
|
-
|
35
|
-
|
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
|
+
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;
|