thirdweb 5.32.3 → 5.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth/constants.js +30 -0
- package/dist/cjs/auth/constants.js.map +1 -0
- package/dist/cjs/auth/core/verify-jwt.js +2 -2
- package/dist/cjs/auth/core/verify-jwt.js.map +1 -1
- package/dist/cjs/auth/core/verify-login-payload.js +2 -2
- package/dist/cjs/auth/core/verify-login-payload.js.map +1 -1
- package/dist/cjs/auth/is-erc6492-signature.js +25 -0
- package/dist/cjs/auth/is-erc6492-signature.js.map +1 -0
- package/dist/cjs/auth/parse-erc6492-signature.js +28 -0
- package/dist/cjs/auth/parse-erc6492-signature.js.map +1 -0
- package/dist/cjs/auth/serialize-erc6492-signature.js +36 -0
- package/dist/cjs/auth/serialize-erc6492-signature.js.map +1 -0
- package/dist/cjs/auth/types.js +3 -0
- package/dist/cjs/auth/types.js.map +1 -0
- package/dist/cjs/auth/verify-signature.js +196 -0
- package/dist/cjs/auth/verify-signature.js.map +1 -0
- package/dist/cjs/exports/auth.js +11 -5
- package/dist/cjs/exports/auth.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js +3 -0
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/WalletSelector.js +3 -0
- package/dist/cjs/react/web/ui/ConnectWallet/WalletSelector.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/coinbase/coinbaseWebSDK.js +2 -2
- package/dist/cjs/wallets/coinbase/coinbaseWebSDK.js.map +1 -1
- package/dist/cjs/wallets/injected/index.js +2 -2
- package/dist/cjs/wallets/injected/index.js.map +1 -1
- package/dist/cjs/wallets/smart/index.js +0 -1
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/esm/auth/constants.js +27 -0
- package/dist/esm/auth/constants.js.map +1 -0
- package/dist/esm/auth/core/verify-jwt.js +1 -1
- package/dist/esm/auth/core/verify-jwt.js.map +1 -1
- package/dist/esm/auth/core/verify-login-payload.js +1 -1
- package/dist/esm/auth/core/verify-login-payload.js.map +1 -1
- package/dist/esm/auth/is-erc6492-signature.js +22 -0
- package/dist/esm/auth/is-erc6492-signature.js.map +1 -0
- package/dist/esm/auth/parse-erc6492-signature.js +25 -0
- package/dist/esm/auth/parse-erc6492-signature.js.map +1 -0
- package/dist/esm/auth/serialize-erc6492-signature.js +33 -0
- package/dist/esm/auth/serialize-erc6492-signature.js.map +1 -0
- package/dist/esm/auth/types.js +2 -0
- package/dist/esm/auth/types.js.map +1 -0
- package/dist/esm/auth/verify-signature.js +191 -0
- package/dist/esm/auth/verify-signature.js.map +1 -0
- package/dist/esm/exports/auth.js +4 -1
- package/dist/esm/exports/auth.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js +3 -0
- package/dist/esm/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/WalletSelector.js +3 -0
- package/dist/esm/react/web/ui/ConnectWallet/WalletSelector.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/coinbase/coinbaseWebSDK.js +2 -2
- package/dist/esm/wallets/coinbase/coinbaseWebSDK.js.map +1 -1
- package/dist/esm/wallets/injected/index.js +2 -2
- package/dist/esm/wallets/injected/index.js.map +1 -1
- package/dist/esm/wallets/smart/index.js +0 -1
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/types/auth/constants.d.ts +20 -0
- package/dist/types/auth/constants.d.ts.map +1 -0
- package/dist/types/auth/is-erc6492-signature.d.ts +19 -0
- package/dist/types/auth/is-erc6492-signature.d.ts.map +1 -0
- package/dist/types/auth/parse-erc6492-signature.d.ts +24 -0
- package/dist/types/auth/parse-erc6492-signature.d.ts.map +1 -0
- package/dist/types/auth/serialize-erc6492-signature.d.ts +27 -0
- package/dist/types/auth/serialize-erc6492-signature.d.ts.map +1 -0
- package/dist/types/auth/types.d.ts +7 -0
- package/dist/types/auth/types.d.ts.map +1 -0
- package/dist/types/auth/verify-signature.d.ts +70 -0
- package/dist/types/auth/verify-signature.d.ts.map +1 -0
- package/dist/types/exports/auth.d.ts +5 -1
- package/dist/types/exports/auth.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/AllWalletsUI.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/WalletSelector.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/auth/constants.ts +30 -0
- package/src/auth/core/verify-jwt.ts +1 -1
- package/src/auth/core/verify-login-payload.ts +1 -1
- package/src/auth/is-erc6492-signature.test.ts +26 -0
- package/src/auth/is-erc6492-signature.ts +23 -0
- package/src/auth/parse-erc6492-signature.test.ts +30 -0
- package/src/auth/parse-erc6492-signature.ts +38 -0
- package/src/auth/serialize-erc6492-signature.test.ts +23 -0
- package/src/auth/serialize-erc6492-signature.ts +42 -0
- package/src/auth/types.ts +7 -0
- package/src/auth/verify-signature.test.ts +97 -0
- package/src/auth/verify-signature.ts +245 -0
- package/src/exports/auth.ts +9 -1
- package/src/react/web/ui/ConnectWallet/Modal/AllWalletsUI.tsx +3 -0
- package/src/react/web/ui/ConnectWallet/WalletSelector.tsx +3 -1
- package/src/version.ts +1 -1
- package/src/wallets/coinbase/coinbaseWebSDK.ts +2 -2
- package/src/wallets/injected/index.ts +2 -2
- package/src/wallets/smart/index.ts +0 -3
- package/src/wallets/smart/smart-wallet-integration.test.ts +1 -1
- package/dist/cjs/auth/verifySignature.js +0 -137
- package/dist/cjs/auth/verifySignature.js.map +0 -1
- package/dist/esm/auth/verifySignature.js +0 -132
- package/dist/esm/auth/verifySignature.js.map +0 -1
- package/dist/types/auth/verifySignature.d.ts +0 -53
- package/dist/types/auth/verifySignature.d.ts.map +0 -1
- package/src/auth/verifySignature.test.ts +0 -53
- package/src/auth/verifySignature.ts +0 -166
@@ -203,9 +203,6 @@ async function createSmartAccount(
|
|
203
203
|
]);
|
204
204
|
const isDeployed = await isContractDeployed(accountContract);
|
205
205
|
if (!isDeployed) {
|
206
|
-
console.log(
|
207
|
-
"Account contract not deployed yet. Deploying account before signing message",
|
208
|
-
);
|
209
206
|
await _deployAccount({
|
210
207
|
options,
|
211
208
|
account,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { beforeAll, describe, expect, it } from "vitest";
|
2
2
|
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
|
3
3
|
import { typedData } from "../../../test/src/typed-data.js";
|
4
|
-
import { verifySignature } from "../../auth/
|
4
|
+
import { verifySignature } from "../../auth/verify-signature.js";
|
5
5
|
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
|
6
6
|
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
|
7
7
|
import { parseEventLogs } from "../../event/actions/parse-logs.js";
|
@@ -1,137 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.verifyEOASignature = verifyEOASignature;
|
4
|
-
exports.verifyContractWalletSignature = verifyContractWalletSignature;
|
5
|
-
exports.verifySignature = verifySignature;
|
6
|
-
const viem_1 = require("viem");
|
7
|
-
const contract_js_1 = require("../contract/contract.js");
|
8
|
-
const isValidSignature_js_1 = require("../extensions/erc1271/__generated__/isValidSignature/read/isValidSignature.js");
|
9
|
-
const hex_js_1 = require("../utils/encoding/hex.js");
|
10
|
-
const hashMessage_js_1 = require("../utils/hashing/hashMessage.js");
|
11
|
-
/**
|
12
|
-
* Verifies the signature of a message using an Ethereum account's EOA (Externally Owned Account).
|
13
|
-
* @param options - The options for verifying the signature.
|
14
|
-
* @returns A boolean indicating whether the signature is valid.
|
15
|
-
* @throws An error if the signature is invalid.
|
16
|
-
* @example
|
17
|
-
* ```ts
|
18
|
-
* import { verifyEOASignature } from 'thirdweb/auth';
|
19
|
-
*
|
20
|
-
* const isValid = await verifyEOASignature({
|
21
|
-
* message: '0x1234567890123456789012345678901234567890',
|
22
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
23
|
-
* address: '0x1234567890123456789012345678901234567890',
|
24
|
-
* });
|
25
|
-
* ```
|
26
|
-
* @auth
|
27
|
-
*/
|
28
|
-
async function verifyEOASignature(options) {
|
29
|
-
const messageHash = (0, hashMessage_js_1.hashMessage)(options.message);
|
30
|
-
if (!(0, hex_js_1.isHex)(options.signature)) {
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
const recoveredAddress = await (0, viem_1.recoverAddress)({
|
34
|
-
hash: messageHash,
|
35
|
-
signature: options.signature,
|
36
|
-
});
|
37
|
-
if (recoveredAddress.toLowerCase() === options.address.toLowerCase()) {
|
38
|
-
return true;
|
39
|
-
}
|
40
|
-
return false;
|
41
|
-
}
|
42
|
-
const EIP1271_MAGICVALUE = "0x1626ba7e";
|
43
|
-
/**
|
44
|
-
* Verifies the signature of a contract wallet.
|
45
|
-
* @param options - The parameters for verifying the signature.
|
46
|
-
* @returns A boolean indicating whether the signature is valid.
|
47
|
-
* @throws An error if the signature is invalid.
|
48
|
-
* @example
|
49
|
-
* ```ts
|
50
|
-
* import { verifyContractWalletSignature } from 'thirdweb/auth';
|
51
|
-
*
|
52
|
-
* const isValid = await verifyContractWalletSignature({
|
53
|
-
* message: '0x1234567890123456789012345678901234567890',
|
54
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
55
|
-
* address: '0x1234567890123456789012345678901234567890',
|
56
|
-
* chain: ...,
|
57
|
-
* client: ...,
|
58
|
-
* });
|
59
|
-
* ```
|
60
|
-
* @auth
|
61
|
-
*/
|
62
|
-
async function verifyContractWalletSignature(options) {
|
63
|
-
if (!(0, hex_js_1.isHex)(options.signature)) {
|
64
|
-
throw new Error("Invalid signature");
|
65
|
-
}
|
66
|
-
const contract = (0, contract_js_1.getContract)({
|
67
|
-
address: options.address,
|
68
|
-
chain: options.chain,
|
69
|
-
client: options.client,
|
70
|
-
});
|
71
|
-
const messageHash = (0, hashMessage_js_1.hashMessage)(options.message);
|
72
|
-
const result = await (0, isValidSignature_js_1.isValidSignature)({
|
73
|
-
contract,
|
74
|
-
hash: messageHash,
|
75
|
-
signature: options.signature,
|
76
|
-
});
|
77
|
-
return result === EIP1271_MAGICVALUE;
|
78
|
-
}
|
79
|
-
/**
|
80
|
-
* Verifies the signature based on the provided options.
|
81
|
-
* Handles smart contract wallet signatures and EOA signatures.
|
82
|
-
* **IMPORTANT: in order to check smart contract signatures, a chain and client must be provided.**
|
83
|
-
* @param options - The options for signature verification.
|
84
|
-
* @returns A boolean indicating whether the signature is valid or not.
|
85
|
-
* @example
|
86
|
-
* ```ts
|
87
|
-
* import { verifySignature } from 'thirdweb/auth';
|
88
|
-
*
|
89
|
-
* const isValid = await verifySignature({
|
90
|
-
* message: 'Your message to sign',
|
91
|
-
* signature: '0x91db0222ec371a8c18d3b187a6d2e77789bffca1b96826ef6b8708e0d4a66c80312fc3ae95b8fbc147265abf539bb6f360152be61a0e1411d7f5771a599e769a1c',
|
92
|
-
* address: '0xda9C7A86AeE76701FC1c23ae548e8E93Ba3e42A5',
|
93
|
-
* client: thirdwebClient,
|
94
|
-
* chain: chain
|
95
|
-
* });
|
96
|
-
* ```
|
97
|
-
* @auth
|
98
|
-
*/
|
99
|
-
let warningTriggered = false;
|
100
|
-
async function verifySignature(options) {
|
101
|
-
try {
|
102
|
-
const isValidEOASig = await verifyEOASignature(options);
|
103
|
-
if (isValidEOASig) {
|
104
|
-
return true;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
catch {
|
108
|
-
// no-op, we skip to contract signature check
|
109
|
-
}
|
110
|
-
if (isVerifyContractWalletSignatureParams(options)) {
|
111
|
-
try {
|
112
|
-
return await verifyContractWalletSignature(options);
|
113
|
-
}
|
114
|
-
catch {
|
115
|
-
// no-op we skip to return false
|
116
|
-
}
|
117
|
-
}
|
118
|
-
else if (!warningTriggered) {
|
119
|
-
// We only trigger this warning once
|
120
|
-
warningTriggered = true;
|
121
|
-
console.error(`
|
122
|
-
Failed to verify EOA signature and no chain or client provided.
|
123
|
-
|
124
|
-
If you mean to use a smart account, please provide a chain and client.
|
125
|
-
For more information on how to setup a smart account with Auth, see https://portal.thirdweb.com/connect/auth
|
126
|
-
`);
|
127
|
-
}
|
128
|
-
// if we reach here, we have no way to verify the signature
|
129
|
-
return false;
|
130
|
-
}
|
131
|
-
function isVerifyContractWalletSignatureParams(options) {
|
132
|
-
return ("chain" in options &&
|
133
|
-
options.chain !== undefined &&
|
134
|
-
"client" in options &&
|
135
|
-
options.client !== undefined);
|
136
|
-
}
|
137
|
-
//# sourceMappingURL=verifySignature.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"verifySignature.js","sourceRoot":"","sources":["../../../src/auth/verifySignature.ts"],"names":[],"mappings":";;AAgCA,gDAgBC;AA8BD,sEAsBC;AA2BD,0CA2BC;AA1JD,+BAAsC;AAGtC,yDAAsD;AACtD,uHAAiH;AACjH,qDAAiD;AACjD,oEAA8D;AAS9D;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAiC;IACxE,MAAM,WAAW,GAAG,IAAA,4BAAW,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjD,IAAI,CAAC,IAAA,cAAK,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,IAAA,qBAAc,EAAC;QAC5C,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,IAAI,gBAAgB,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QACrE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AASD,MAAM,kBAAkB,GAAG,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CAAC;QACxB,OAAO,CAAC,KAAK,CAAC;;;;;KAKb,CAAC,CAAC;IACL,CAAC;IACD,2DAA2D;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,qCAAqC,CAC5C,OAA8B;IAE9B,OAAO,CACL,OAAO,IAAI,OAAO;QAClB,OAAO,CAAC,KAAK,KAAK,SAAS;QAC3B,QAAQ,IAAI,OAAO;QACnB,OAAO,CAAC,MAAM,KAAK,SAAS,CAC7B,CAAC;AACJ,CAAC"}
|
@@ -1,132 +0,0 @@
|
|
1
|
-
import { recoverAddress } from "viem";
|
2
|
-
import { getContract } from "../contract/contract.js";
|
3
|
-
import { isValidSignature } from "../extensions/erc1271/__generated__/isValidSignature/read/isValidSignature.js";
|
4
|
-
import { isHex } from "../utils/encoding/hex.js";
|
5
|
-
import { hashMessage } from "../utils/hashing/hashMessage.js";
|
6
|
-
/**
|
7
|
-
* Verifies the signature of a message using an Ethereum account's EOA (Externally Owned Account).
|
8
|
-
* @param options - The options for verifying the signature.
|
9
|
-
* @returns A boolean indicating whether the signature is valid.
|
10
|
-
* @throws An error if the signature is invalid.
|
11
|
-
* @example
|
12
|
-
* ```ts
|
13
|
-
* import { verifyEOASignature } from 'thirdweb/auth';
|
14
|
-
*
|
15
|
-
* const isValid = await verifyEOASignature({
|
16
|
-
* message: '0x1234567890123456789012345678901234567890',
|
17
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
18
|
-
* address: '0x1234567890123456789012345678901234567890',
|
19
|
-
* });
|
20
|
-
* ```
|
21
|
-
* @auth
|
22
|
-
*/
|
23
|
-
export async function verifyEOASignature(options) {
|
24
|
-
const messageHash = hashMessage(options.message);
|
25
|
-
if (!isHex(options.signature)) {
|
26
|
-
return false;
|
27
|
-
}
|
28
|
-
const recoveredAddress = await recoverAddress({
|
29
|
-
hash: messageHash,
|
30
|
-
signature: options.signature,
|
31
|
-
});
|
32
|
-
if (recoveredAddress.toLowerCase() === options.address.toLowerCase()) {
|
33
|
-
return true;
|
34
|
-
}
|
35
|
-
return false;
|
36
|
-
}
|
37
|
-
const EIP1271_MAGICVALUE = "0x1626ba7e";
|
38
|
-
/**
|
39
|
-
* Verifies the signature of a contract wallet.
|
40
|
-
* @param options - The parameters for verifying the signature.
|
41
|
-
* @returns A boolean indicating whether the signature is valid.
|
42
|
-
* @throws An error if the signature is invalid.
|
43
|
-
* @example
|
44
|
-
* ```ts
|
45
|
-
* import { verifyContractWalletSignature } from 'thirdweb/auth';
|
46
|
-
*
|
47
|
-
* const isValid = await verifyContractWalletSignature({
|
48
|
-
* message: '0x1234567890123456789012345678901234567890',
|
49
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
50
|
-
* address: '0x1234567890123456789012345678901234567890',
|
51
|
-
* chain: ...,
|
52
|
-
* client: ...,
|
53
|
-
* });
|
54
|
-
* ```
|
55
|
-
* @auth
|
56
|
-
*/
|
57
|
-
export async function verifyContractWalletSignature(options) {
|
58
|
-
if (!isHex(options.signature)) {
|
59
|
-
throw new Error("Invalid signature");
|
60
|
-
}
|
61
|
-
const contract = getContract({
|
62
|
-
address: options.address,
|
63
|
-
chain: options.chain,
|
64
|
-
client: options.client,
|
65
|
-
});
|
66
|
-
const messageHash = hashMessage(options.message);
|
67
|
-
const result = await isValidSignature({
|
68
|
-
contract,
|
69
|
-
hash: messageHash,
|
70
|
-
signature: options.signature,
|
71
|
-
});
|
72
|
-
return result === EIP1271_MAGICVALUE;
|
73
|
-
}
|
74
|
-
/**
|
75
|
-
* Verifies the signature based on the provided options.
|
76
|
-
* Handles smart contract wallet signatures and EOA signatures.
|
77
|
-
* **IMPORTANT: in order to check smart contract signatures, a chain and client must be provided.**
|
78
|
-
* @param options - The options for signature verification.
|
79
|
-
* @returns A boolean indicating whether the signature is valid or not.
|
80
|
-
* @example
|
81
|
-
* ```ts
|
82
|
-
* import { verifySignature } from 'thirdweb/auth';
|
83
|
-
*
|
84
|
-
* const isValid = await verifySignature({
|
85
|
-
* message: 'Your message to sign',
|
86
|
-
* signature: '0x91db0222ec371a8c18d3b187a6d2e77789bffca1b96826ef6b8708e0d4a66c80312fc3ae95b8fbc147265abf539bb6f360152be61a0e1411d7f5771a599e769a1c',
|
87
|
-
* address: '0xda9C7A86AeE76701FC1c23ae548e8E93Ba3e42A5',
|
88
|
-
* client: thirdwebClient,
|
89
|
-
* chain: chain
|
90
|
-
* });
|
91
|
-
* ```
|
92
|
-
* @auth
|
93
|
-
*/
|
94
|
-
let warningTriggered = false;
|
95
|
-
export async function verifySignature(options) {
|
96
|
-
try {
|
97
|
-
const isValidEOASig = await verifyEOASignature(options);
|
98
|
-
if (isValidEOASig) {
|
99
|
-
return true;
|
100
|
-
}
|
101
|
-
}
|
102
|
-
catch {
|
103
|
-
// no-op, we skip to contract signature check
|
104
|
-
}
|
105
|
-
if (isVerifyContractWalletSignatureParams(options)) {
|
106
|
-
try {
|
107
|
-
return await verifyContractWalletSignature(options);
|
108
|
-
}
|
109
|
-
catch {
|
110
|
-
// no-op we skip to return false
|
111
|
-
}
|
112
|
-
}
|
113
|
-
else if (!warningTriggered) {
|
114
|
-
// We only trigger this warning once
|
115
|
-
warningTriggered = true;
|
116
|
-
console.error(`
|
117
|
-
Failed to verify EOA signature and no chain or client provided.
|
118
|
-
|
119
|
-
If you mean to use a smart account, please provide a chain and client.
|
120
|
-
For more information on how to setup a smart account with Auth, see https://portal.thirdweb.com/connect/auth
|
121
|
-
`);
|
122
|
-
}
|
123
|
-
// if we reach here, we have no way to verify the signature
|
124
|
-
return false;
|
125
|
-
}
|
126
|
-
function isVerifyContractWalletSignatureParams(options) {
|
127
|
-
return ("chain" in options &&
|
128
|
-
options.chain !== undefined &&
|
129
|
-
"client" in options &&
|
130
|
-
options.client !== undefined);
|
131
|
-
}
|
132
|
-
//# sourceMappingURL=verifySignature.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"verifySignature.js","sourceRoot":"","sources":["../../../src/auth/verifySignature.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AO,CAAC,OAAO,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC;QACpC,QAAQ;QACR,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,kBAAkB,CAAC;AACvC,CAAC;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAC7B,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA8B;IAClE,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;IAC/C,CAAC;IACD,IAAI,qCAAqC,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC;YACH,OAAO,MAAM,6BAA6B,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;QAAC,MAAM,CAAC;YACP,gCAAgC;QAClC,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC7B,oCAAoC;QACpC,gBAAgB,GAAG,IAAI,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC;;;;;KAKb,CAAC,CAAC;IACL,CAAC;IACD,2DAA2D;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,qCAAqC,CAC5C,OAA8B;IAE9B,OAAO,CACL,OAAO,IAAI,OAAO;QAClB,OAAO,CAAC,KAAK,KAAK,SAAS;QAC3B,QAAQ,IAAI,OAAO;QACnB,OAAO,CAAC,MAAM,KAAK,SAAS,CAC7B,CAAC;AACJ,CAAC"}
|
@@ -1,53 +0,0 @@
|
|
1
|
-
import type { Chain } from "../chains/types.js";
|
2
|
-
import type { ThirdwebClient } from "../client/client.js";
|
3
|
-
import type { Prettify } from "../utils/type-utils.js";
|
4
|
-
export type VerifyEOASignatureParams = {
|
5
|
-
message: string;
|
6
|
-
signature: string;
|
7
|
-
address: string;
|
8
|
-
};
|
9
|
-
/**
|
10
|
-
* Verifies the signature of a message using an Ethereum account's EOA (Externally Owned Account).
|
11
|
-
* @param options - The options for verifying the signature.
|
12
|
-
* @returns A boolean indicating whether the signature is valid.
|
13
|
-
* @throws An error if the signature is invalid.
|
14
|
-
* @example
|
15
|
-
* ```ts
|
16
|
-
* import { verifyEOASignature } from 'thirdweb/auth';
|
17
|
-
*
|
18
|
-
* const isValid = await verifyEOASignature({
|
19
|
-
* message: '0x1234567890123456789012345678901234567890',
|
20
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
21
|
-
* address: '0x1234567890123456789012345678901234567890',
|
22
|
-
* });
|
23
|
-
* ```
|
24
|
-
* @auth
|
25
|
-
*/
|
26
|
-
export declare function verifyEOASignature(options: VerifyEOASignatureParams): Promise<boolean>;
|
27
|
-
export type VerifyContractWalletSignatureParams = Prettify<VerifyEOASignatureParams & {
|
28
|
-
chain: Chain;
|
29
|
-
client: ThirdwebClient;
|
30
|
-
}>;
|
31
|
-
/**
|
32
|
-
* Verifies the signature of a contract wallet.
|
33
|
-
* @param options - The parameters for verifying the signature.
|
34
|
-
* @returns A boolean indicating whether the signature is valid.
|
35
|
-
* @throws An error if the signature is invalid.
|
36
|
-
* @example
|
37
|
-
* ```ts
|
38
|
-
* import { verifyContractWalletSignature } from 'thirdweb/auth';
|
39
|
-
*
|
40
|
-
* const isValid = await verifyContractWalletSignature({
|
41
|
-
* message: '0x1234567890123456789012345678901234567890',
|
42
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
43
|
-
* address: '0x1234567890123456789012345678901234567890',
|
44
|
-
* chain: ...,
|
45
|
-
* client: ...,
|
46
|
-
* });
|
47
|
-
* ```
|
48
|
-
* @auth
|
49
|
-
*/
|
50
|
-
export declare function verifyContractWalletSignature(options: VerifyContractWalletSignatureParams): Promise<boolean>;
|
51
|
-
export type VerifySignatureParams = Prettify<VerifyEOASignatureParams & Partial<VerifyContractWalletSignatureParams>>;
|
52
|
-
export declare function verifySignature(options: VerifySignatureParams): Promise<boolean>;
|
53
|
-
//# sourceMappingURL=verifySignature.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"verifySignature.d.ts","sourceRoot":"","sources":["../../../src/auth/verifySignature.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,wBAAwB,oBAgBzE;AAED,MAAM,MAAM,mCAAmC,GAAG,QAAQ,CACxD,wBAAwB,GAAG;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,cAAc,CAAC;CACxB,CACF,CAAC;AAIF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,mCAAmC,oBAqB7C;AAED,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAC1C,wBAAwB,GAAG,OAAO,CAAC,mCAAmC,CAAC,CACxE,CAAC;AAuBF,wBAAsB,eAAe,CAAC,OAAO,EAAE,qBAAqB,oBA2BnE"}
|
@@ -1,53 +0,0 @@
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
2
|
-
import { TEST_ACCOUNT_A } from "../../test/src/test-wallets.js";
|
3
|
-
import { verifyEOASignature } from "./verifySignature.js";
|
4
|
-
|
5
|
-
describe("verifyEOASignature", () => {
|
6
|
-
test("should return true for a valid signature", async () => {
|
7
|
-
const message = "Hello world!";
|
8
|
-
|
9
|
-
const signature = await TEST_ACCOUNT_A.signMessage({ message });
|
10
|
-
|
11
|
-
const result = await verifyEOASignature({
|
12
|
-
address: TEST_ACCOUNT_A.address,
|
13
|
-
message,
|
14
|
-
signature,
|
15
|
-
});
|
16
|
-
expect(result).toBe(true);
|
17
|
-
});
|
18
|
-
|
19
|
-
test("should return false for an invalid signature", async () => {
|
20
|
-
const options = {
|
21
|
-
message: "Hello, world!",
|
22
|
-
signature: "invalid",
|
23
|
-
address: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
24
|
-
};
|
25
|
-
|
26
|
-
const result = await verifyEOASignature(options);
|
27
|
-
expect(result).toBe(false);
|
28
|
-
});
|
29
|
-
|
30
|
-
test("should return false for a different address", async () => {
|
31
|
-
const message = "Hello, world!";
|
32
|
-
const signature = await TEST_ACCOUNT_A.signMessage({ message });
|
33
|
-
|
34
|
-
const result = await verifyEOASignature({
|
35
|
-
address: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
36
|
-
message,
|
37
|
-
signature,
|
38
|
-
});
|
39
|
-
expect(result).toBe(false);
|
40
|
-
});
|
41
|
-
|
42
|
-
test("should return false for a different message", async () => {
|
43
|
-
const message = "Hello, world!";
|
44
|
-
const signature = await TEST_ACCOUNT_A.signMessage({ message });
|
45
|
-
|
46
|
-
const result = await verifyEOASignature({
|
47
|
-
address: TEST_ACCOUNT_A.address,
|
48
|
-
message: "Hello, world",
|
49
|
-
signature,
|
50
|
-
});
|
51
|
-
expect(result).toBe(false);
|
52
|
-
});
|
53
|
-
});
|
@@ -1,166 +0,0 @@
|
|
1
|
-
import { recoverAddress } from "viem";
|
2
|
-
import type { Chain } from "../chains/types.js";
|
3
|
-
import type { ThirdwebClient } from "../client/client.js";
|
4
|
-
import { getContract } from "../contract/contract.js";
|
5
|
-
import { isValidSignature } from "../extensions/erc1271/__generated__/isValidSignature/read/isValidSignature.js";
|
6
|
-
import { isHex } from "../utils/encoding/hex.js";
|
7
|
-
import { hashMessage } from "../utils/hashing/hashMessage.js";
|
8
|
-
import type { Prettify } from "../utils/type-utils.js";
|
9
|
-
|
10
|
-
export type VerifyEOASignatureParams = {
|
11
|
-
message: string;
|
12
|
-
signature: string;
|
13
|
-
address: string;
|
14
|
-
};
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Verifies the signature of a message using an Ethereum account's EOA (Externally Owned Account).
|
18
|
-
* @param options - The options for verifying the signature.
|
19
|
-
* @returns A boolean indicating whether the signature is valid.
|
20
|
-
* @throws An error if the signature is invalid.
|
21
|
-
* @example
|
22
|
-
* ```ts
|
23
|
-
* import { verifyEOASignature } from 'thirdweb/auth';
|
24
|
-
*
|
25
|
-
* const isValid = await verifyEOASignature({
|
26
|
-
* message: '0x1234567890123456789012345678901234567890',
|
27
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
28
|
-
* address: '0x1234567890123456789012345678901234567890',
|
29
|
-
* });
|
30
|
-
* ```
|
31
|
-
* @auth
|
32
|
-
*/
|
33
|
-
export async function verifyEOASignature(options: VerifyEOASignatureParams) {
|
34
|
-
const messageHash = hashMessage(options.message);
|
35
|
-
|
36
|
-
if (!isHex(options.signature)) {
|
37
|
-
return false;
|
38
|
-
}
|
39
|
-
|
40
|
-
const recoveredAddress = await recoverAddress({
|
41
|
-
hash: messageHash,
|
42
|
-
signature: options.signature,
|
43
|
-
});
|
44
|
-
|
45
|
-
if (recoveredAddress.toLowerCase() === options.address.toLowerCase()) {
|
46
|
-
return true;
|
47
|
-
}
|
48
|
-
return false;
|
49
|
-
}
|
50
|
-
|
51
|
-
export type VerifyContractWalletSignatureParams = Prettify<
|
52
|
-
VerifyEOASignatureParams & {
|
53
|
-
chain: Chain;
|
54
|
-
client: ThirdwebClient;
|
55
|
-
}
|
56
|
-
>;
|
57
|
-
|
58
|
-
const EIP1271_MAGICVALUE = "0x1626ba7e";
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Verifies the signature of a contract wallet.
|
62
|
-
* @param options - The parameters for verifying the signature.
|
63
|
-
* @returns A boolean indicating whether the signature is valid.
|
64
|
-
* @throws An error if the signature is invalid.
|
65
|
-
* @example
|
66
|
-
* ```ts
|
67
|
-
* import { verifyContractWalletSignature } from 'thirdweb/auth';
|
68
|
-
*
|
69
|
-
* const isValid = await verifyContractWalletSignature({
|
70
|
-
* message: '0x1234567890123456789012345678901234567890',
|
71
|
-
* signature: '0x1234567890123456789012345678901234567890',
|
72
|
-
* address: '0x1234567890123456789012345678901234567890',
|
73
|
-
* chain: ...,
|
74
|
-
* client: ...,
|
75
|
-
* });
|
76
|
-
* ```
|
77
|
-
* @auth
|
78
|
-
*/
|
79
|
-
export async function verifyContractWalletSignature(
|
80
|
-
options: VerifyContractWalletSignatureParams,
|
81
|
-
) {
|
82
|
-
if (!isHex(options.signature)) {
|
83
|
-
throw new Error("Invalid signature");
|
84
|
-
}
|
85
|
-
|
86
|
-
const contract = getContract({
|
87
|
-
address: options.address,
|
88
|
-
chain: options.chain,
|
89
|
-
client: options.client,
|
90
|
-
});
|
91
|
-
|
92
|
-
const messageHash = hashMessage(options.message);
|
93
|
-
|
94
|
-
const result = await isValidSignature({
|
95
|
-
contract,
|
96
|
-
hash: messageHash,
|
97
|
-
signature: options.signature,
|
98
|
-
});
|
99
|
-
|
100
|
-
return result === EIP1271_MAGICVALUE;
|
101
|
-
}
|
102
|
-
|
103
|
-
export type VerifySignatureParams = Prettify<
|
104
|
-
VerifyEOASignatureParams & Partial<VerifyContractWalletSignatureParams>
|
105
|
-
>;
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Verifies the signature based on the provided options.
|
109
|
-
* Handles smart contract wallet signatures and EOA signatures.
|
110
|
-
* **IMPORTANT: in order to check smart contract signatures, a chain and client must be provided.**
|
111
|
-
* @param options - The options for signature verification.
|
112
|
-
* @returns A boolean indicating whether the signature is valid or not.
|
113
|
-
* @example
|
114
|
-
* ```ts
|
115
|
-
* import { verifySignature } from 'thirdweb/auth';
|
116
|
-
*
|
117
|
-
* const isValid = await verifySignature({
|
118
|
-
* message: 'Your message to sign',
|
119
|
-
* signature: '0x91db0222ec371a8c18d3b187a6d2e77789bffca1b96826ef6b8708e0d4a66c80312fc3ae95b8fbc147265abf539bb6f360152be61a0e1411d7f5771a599e769a1c',
|
120
|
-
* address: '0xda9C7A86AeE76701FC1c23ae548e8E93Ba3e42A5',
|
121
|
-
* client: thirdwebClient,
|
122
|
-
* chain: chain
|
123
|
-
* });
|
124
|
-
* ```
|
125
|
-
* @auth
|
126
|
-
*/
|
127
|
-
let warningTriggered = false;
|
128
|
-
export async function verifySignature(options: VerifySignatureParams) {
|
129
|
-
try {
|
130
|
-
const isValidEOASig = await verifyEOASignature(options);
|
131
|
-
if (isValidEOASig) {
|
132
|
-
return true;
|
133
|
-
}
|
134
|
-
} catch {
|
135
|
-
// no-op, we skip to contract signature check
|
136
|
-
}
|
137
|
-
if (isVerifyContractWalletSignatureParams(options)) {
|
138
|
-
try {
|
139
|
-
return await verifyContractWalletSignature(options);
|
140
|
-
} catch {
|
141
|
-
// no-op we skip to return false
|
142
|
-
}
|
143
|
-
} else if (!warningTriggered) {
|
144
|
-
// We only trigger this warning once
|
145
|
-
warningTriggered = true;
|
146
|
-
console.error(`
|
147
|
-
Failed to verify EOA signature and no chain or client provided.
|
148
|
-
|
149
|
-
If you mean to use a smart account, please provide a chain and client.
|
150
|
-
For more information on how to setup a smart account with Auth, see https://portal.thirdweb.com/connect/auth
|
151
|
-
`);
|
152
|
-
}
|
153
|
-
// if we reach here, we have no way to verify the signature
|
154
|
-
return false;
|
155
|
-
}
|
156
|
-
|
157
|
-
function isVerifyContractWalletSignatureParams(
|
158
|
-
options: VerifySignatureParams,
|
159
|
-
): options is VerifyContractWalletSignatureParams {
|
160
|
-
return (
|
161
|
-
"chain" in options &&
|
162
|
-
options.chain !== undefined &&
|
163
|
-
"client" in options &&
|
164
|
-
options.client !== undefined
|
165
|
-
);
|
166
|
-
}
|