thirdweb 5.45.2-nightly-b15aa4cdff3f3b233025da285780668a18fe29ab-20240813000336 → 5.46.0-nightly-814024ae249141ad1446ce7f21793b1d37b95d13-20240814000405
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/contract/actions/get-compiler-metadata.js +37 -0
- package/dist/cjs/contract/actions/get-compiler-metadata.js.map +1 -0
- package/dist/cjs/exports/contract.js +3 -1
- package/dist/cjs/exports/contract.js.map +1 -1
- package/dist/cjs/exports/extensions/erc1155.js +3 -1
- package/dist/cjs/exports/extensions/erc1155.js.map +1 -1
- package/dist/cjs/exports/extensions/erc721.js +3 -1
- package/dist/cjs/exports/extensions/erc721.js.map +1 -1
- package/dist/cjs/extensions/erc1155/write/updateTokenURI.js +81 -0
- package/dist/cjs/extensions/erc1155/write/updateTokenURI.js.map +1 -0
- package/dist/cjs/extensions/erc721/write/updateTokenURI.js +81 -0
- package/dist/cjs/extensions/erc721/write/updateTokenURI.js.map +1 -0
- package/dist/cjs/utils/any-evm/deploy-metadata.js +2 -27
- package/dist/cjs/utils/any-evm/deploy-metadata.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js +16 -2
- package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/siwe.js +4 -5
- package/dist/cjs/wallets/in-app/core/authentication/siwe.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/types.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js +3 -3
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/native-connector.js +10 -10
- package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +15 -0
- package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +5 -5
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/cjs/wallets/types.js +8 -1
- package/dist/cjs/wallets/types.js.map +1 -1
- package/dist/esm/contract/actions/get-compiler-metadata.js +34 -0
- package/dist/esm/contract/actions/get-compiler-metadata.js.map +1 -0
- package/dist/esm/exports/contract.js +1 -0
- package/dist/esm/exports/contract.js.map +1 -1
- package/dist/esm/exports/extensions/erc1155.js +1 -0
- package/dist/esm/exports/extensions/erc1155.js.map +1 -1
- package/dist/esm/exports/extensions/erc721.js +1 -0
- package/dist/esm/exports/extensions/erc721.js.map +1 -1
- package/dist/esm/extensions/erc1155/write/updateTokenURI.js +77 -0
- package/dist/esm/extensions/erc1155/write/updateTokenURI.js.map +1 -0
- package/dist/esm/extensions/erc721/write/updateTokenURI.js +77 -0
- package/dist/esm/extensions/erc721/write/updateTokenURI.js.map +1 -0
- package/dist/esm/utils/any-evm/deploy-metadata.js +1 -26
- package/dist/esm/utils/any-evm/deploy-metadata.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js +16 -2
- package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/siwe.js +4 -5
- package/dist/esm/wallets/in-app/core/authentication/siwe.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/types.js.map +1 -1
- package/dist/esm/wallets/in-app/native/auth/native-auth.js +3 -3
- package/dist/esm/wallets/in-app/native/auth/native-auth.js.map +1 -1
- package/dist/esm/wallets/in-app/native/native-connector.js +10 -10
- package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +15 -0
- package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +5 -5
- package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/esm/wallets/types.js +7 -0
- package/dist/esm/wallets/types.js.map +1 -1
- package/dist/types/contract/actions/get-compiler-metadata.d.ts +20 -0
- package/dist/types/contract/actions/get-compiler-metadata.d.ts.map +1 -0
- package/dist/types/exports/contract.d.ts +1 -0
- package/dist/types/exports/contract.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc1155.d.ts +1 -0
- package/dist/types/exports/extensions/erc1155.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc721.d.ts +1 -0
- package/dist/types/exports/extensions/erc721.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/write/updateTokenURI.d.ts +37 -0
- package/dist/types/extensions/erc1155/write/updateTokenURI.d.ts.map +1 -0
- package/dist/types/extensions/erc721/write/updateTokenURI.d.ts +37 -0
- package/dist/types/extensions/erc721/write/updateTokenURI.d.ts.map +1 -0
- package/dist/types/react/core/utils/storage.d.ts +1 -1
- package/dist/types/react/core/utils/storage.d.ts.map +1 -1
- package/dist/types/utils/any-evm/deploy-metadata.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts +1 -1
- package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/siwe.d.ts +4 -3
- package/dist/types/wallets/in-app/core/authentication/siwe.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/types.d.ts +5 -4
- package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
- package/dist/types/wallets/in-app/native/auth/native-auth.d.ts +3 -2
- package/dist/types/wallets/in-app/native/auth/native-auth.d.ts.map +1 -1
- package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +15 -0
- package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
- package/dist/types/wallets/types.d.ts +2 -1
- package/dist/types/wallets/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/contract/actions/get-compiler-metadata.ts +40 -0
- package/src/exports/contract.ts +2 -0
- package/src/exports/extensions/erc1155.ts +6 -0
- package/src/exports/extensions/erc721.ts +4 -0
- package/src/extensions/erc1155/write/updateTokenURI.ts +97 -0
- package/src/extensions/erc721/write/updateTokenURI.ts +97 -0
- package/src/extensions/prebuilts/deploy-split.test.ts +1 -1
- package/src/utils/any-evm/deploy-metadata.ts +1 -28
- package/src/version.ts +1 -1
- package/src/wallets/in-app/core/authentication/getLoginPath.ts +17 -3
- package/src/wallets/in-app/core/authentication/siwe.ts +8 -8
- package/src/wallets/in-app/core/authentication/types.ts +5 -4
- package/src/wallets/in-app/native/auth/native-auth.ts +6 -5
- package/src/wallets/in-app/native/native-connector.ts +15 -15
- package/src/wallets/in-app/web/in-app.ts +15 -0
- package/src/wallets/in-app/web/lib/web-connector.ts +5 -5
- package/src/wallets/types.ts +8 -6
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "thirdweb",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.46.0-nightly-814024ae249141ad1446ce7f21793b1d37b95d13-20240814000405",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "git+https://github.com/thirdweb-dev/js.git#main"
|
@@ -297,7 +297,7 @@
|
|
297
297
|
"expo-web-browser": "13.0.3",
|
298
298
|
"happy-dom": "^14.12.0",
|
299
299
|
"msw": "^2.3.4",
|
300
|
-
"react-native": "0.74.
|
300
|
+
"react-native": "0.74.5",
|
301
301
|
"react-native-aes-gcm-crypto": "0.2.2",
|
302
302
|
"react-native-quick-crypto": "0.7.0-rc.6",
|
303
303
|
"react-native-svg": "15.3.0",
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import type { ThirdwebContract } from "../contract.js";
|
2
|
+
import { formatCompilerMetadata } from "./compiler-metadata.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Down the compiled metadata from thirdweb contract api and format it
|
6
|
+
* @param metadata The (json) data returned from https://contract.thirdweb.com/metadata/<chainId>/<contractAddress>
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* ```ts
|
10
|
+
* import { getCompilerMetadata, getContract } from "thirdweb/contracts";
|
11
|
+
*
|
12
|
+
* const contract = getContract({
|
13
|
+
* address: "0x...",
|
14
|
+
* chain: ethereum,
|
15
|
+
* client: "",
|
16
|
+
* });
|
17
|
+
* const metadata = await getCompilerMetadata(contract);
|
18
|
+
* ```
|
19
|
+
* @returns
|
20
|
+
*/
|
21
|
+
export async function getCompilerMetadata(contract: ThirdwebContract) {
|
22
|
+
const { address, chain } = contract;
|
23
|
+
const response = await fetch(
|
24
|
+
`https://contract.thirdweb.com/metadata/${chain.id}/${address}`,
|
25
|
+
{
|
26
|
+
method: "GET",
|
27
|
+
headers: {
|
28
|
+
"Content-Type": "application/json",
|
29
|
+
},
|
30
|
+
},
|
31
|
+
);
|
32
|
+
if (!response.ok) {
|
33
|
+
const errorMsg = await response.json();
|
34
|
+
throw new Error(
|
35
|
+
errorMsg.message || errorMsg.error || "Failed to get compiler metadata",
|
36
|
+
);
|
37
|
+
}
|
38
|
+
const data = await response.json();
|
39
|
+
return formatCompilerMetadata(data);
|
40
|
+
}
|
package/src/exports/contract.ts
CHANGED
@@ -34,3 +34,5 @@ export {
|
|
34
34
|
type PrepareDirectDeployTransactionOptions,
|
35
35
|
} from "../contract/deployment/deploy-with-abi.js";
|
36
36
|
export { prepareAutoFactoryDeployTransaction } from "../contract/deployment/deploy-via-autofactory.js";
|
37
|
+
|
38
|
+
export { getCompilerMetadata } from "../contract/actions/get-compiler-metadata.js";
|
@@ -99,6 +99,12 @@ export {
|
|
99
99
|
updateMetadata,
|
100
100
|
type UpdateMetadataParams,
|
101
101
|
} from "../../extensions/erc1155/drops/write/updateMetadata.js";
|
102
|
+
|
103
|
+
export {
|
104
|
+
updateTokenURI,
|
105
|
+
type UpdateTokenURIParams,
|
106
|
+
} from "../../extensions/erc1155/write/updateTokenURI.js";
|
107
|
+
|
102
108
|
export {
|
103
109
|
getClaimConditionById,
|
104
110
|
type GetClaimConditionByIdParams,
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { upload } from "../../../storage/upload.js";
|
2
|
+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
|
3
|
+
import type { NFTInput } from "../../../utils/nft/parseNft.js";
|
4
|
+
import {
|
5
|
+
type SetTokenURIParams,
|
6
|
+
setTokenURI,
|
7
|
+
} from "../../erc1155/__generated__/INFTMetadata/write/setTokenURI.js";
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @extension ERC1155
|
11
|
+
*/
|
12
|
+
export type UpdateTokenURIParams = {
|
13
|
+
tokenId: bigint;
|
14
|
+
newMetadata: NFTInput;
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* This function is an abstracted layer of the [`setTokenURI` extension](https://portal.thirdweb.com/references/typescript/v5/erc1155/setTokenURI),
|
19
|
+
* which means it uses `setTokenURI` under the hood.
|
20
|
+
* While the `setTokenURI` method only takes in a uri string, this extension takes in a user-friendly [`NFTInput`](https://portal.thirdweb.com/references/typescript/v5/NFTInput),
|
21
|
+
* upload that content to IPFS and pass the IPFS URI (of said `NFTInput`) to the underlying `setTokenURI` method.
|
22
|
+
*
|
23
|
+
* This extension does not validate the NFTInput so make sure you are passing the proper content that you want to update.
|
24
|
+
*
|
25
|
+
* @extension ERC1155
|
26
|
+
* @returns the prepared transaction from `setTokenURI`
|
27
|
+
* @example
|
28
|
+
* ```ts
|
29
|
+
* import { updateTokenURI } from "thirdweb/extensions/erc1155";
|
30
|
+
*
|
31
|
+
* const transaction = updateTokenURI({
|
32
|
+
* tokenId: 0n,
|
33
|
+
* nft: {
|
34
|
+
* name: "new name",
|
35
|
+
* description: "new description",
|
36
|
+
* image: "https://image-host.com/new-image.png",
|
37
|
+
* },
|
38
|
+
* });
|
39
|
+
* ```
|
40
|
+
*/
|
41
|
+
export function updateTokenURI(
|
42
|
+
options: BaseTransactionOptions<UpdateTokenURIParams>,
|
43
|
+
) {
|
44
|
+
const { contract } = options;
|
45
|
+
return setTokenURI({
|
46
|
+
contract,
|
47
|
+
asyncParams: async () => getUpdateTokenParams(options),
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
export async function getUpdateTokenParams(
|
52
|
+
options: BaseTransactionOptions<UpdateTokenURIParams>,
|
53
|
+
): Promise<SetTokenURIParams> {
|
54
|
+
const { tokenId, newMetadata } = options;
|
55
|
+
const batch: Promise<string>[] = [
|
56
|
+
// image URI resolution
|
57
|
+
(async () => {
|
58
|
+
if (!newMetadata.image) {
|
59
|
+
return "";
|
60
|
+
}
|
61
|
+
if (typeof newMetadata.image === "string") {
|
62
|
+
return newMetadata.image;
|
63
|
+
}
|
64
|
+
return await upload({
|
65
|
+
client: options.contract.client,
|
66
|
+
files: [newMetadata.image],
|
67
|
+
});
|
68
|
+
})(),
|
69
|
+
// animation URI resolution
|
70
|
+
(async () => {
|
71
|
+
if (!newMetadata.animation_url) {
|
72
|
+
return "";
|
73
|
+
}
|
74
|
+
if (typeof newMetadata.animation_url === "string") {
|
75
|
+
return newMetadata.animation_url;
|
76
|
+
}
|
77
|
+
return await upload({
|
78
|
+
client: options.contract.client,
|
79
|
+
files: [newMetadata.animation_url],
|
80
|
+
});
|
81
|
+
})(),
|
82
|
+
];
|
83
|
+
|
84
|
+
const [imageURI, animationURI] = await Promise.all(batch);
|
85
|
+
if (newMetadata.image && imageURI) {
|
86
|
+
newMetadata.image = imageURI;
|
87
|
+
}
|
88
|
+
if (newMetadata.animation_url && animationURI) {
|
89
|
+
newMetadata.animation_url = animationURI;
|
90
|
+
}
|
91
|
+
|
92
|
+
const uri = await upload({
|
93
|
+
client: options.contract.client,
|
94
|
+
files: [newMetadata],
|
95
|
+
});
|
96
|
+
return { tokenId, uri };
|
97
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { upload } from "../../../storage/upload.js";
|
2
|
+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
|
3
|
+
import type { NFTInput } from "../../../utils/nft/parseNft.js";
|
4
|
+
import {
|
5
|
+
type SetTokenURIParams,
|
6
|
+
setTokenURI,
|
7
|
+
} from "../../erc721/__generated__/INFTMetadata/write/setTokenURI.js";
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @extension ERC721
|
11
|
+
*/
|
12
|
+
export type UpdateTokenURIParams = {
|
13
|
+
tokenId: bigint;
|
14
|
+
newMetadata: NFTInput;
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* This function is an abstracted layer of the [`setTokenURI` extension](https://portal.thirdweb.com/references/typescript/v5/erc721/setTokenURI),
|
19
|
+
* which means it uses `setTokenURI` under the hood.
|
20
|
+
* While the `setTokenURI` method only takes in a uri string, this extension takes in a user-friendly [`NFTInput`](https://portal.thirdweb.com/references/typescript/v5/NFTInput),
|
21
|
+
* upload that content to IPFS and pass the IPFS URI (of said `NFTInput`) to the underlying `setTokenURI` method.
|
22
|
+
*
|
23
|
+
* This extension does not validate the NFTInput so make sure you are passing the proper content that you want to update.
|
24
|
+
*
|
25
|
+
* @extension ERC721
|
26
|
+
* @returns the prepared transaction from `setTokenURI`
|
27
|
+
* @example
|
28
|
+
* ```ts
|
29
|
+
* import { updateTokenURI } from "thirdweb/extensions/erc721";
|
30
|
+
*
|
31
|
+
* const transaction = updateTokenURI({
|
32
|
+
* tokenId: 0n,
|
33
|
+
* nft: {
|
34
|
+
* name: "new name",
|
35
|
+
* description: "new description",
|
36
|
+
* image: "https://image-host.com/new-image.png",
|
37
|
+
* },
|
38
|
+
* });
|
39
|
+
* ```
|
40
|
+
*/
|
41
|
+
export function updateTokenURI(
|
42
|
+
options: BaseTransactionOptions<UpdateTokenURIParams>,
|
43
|
+
) {
|
44
|
+
const { contract } = options;
|
45
|
+
return setTokenURI({
|
46
|
+
contract,
|
47
|
+
asyncParams: async () => getUpdateTokenParams(options),
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
export async function getUpdateTokenParams(
|
52
|
+
options: BaseTransactionOptions<UpdateTokenURIParams>,
|
53
|
+
): Promise<SetTokenURIParams> {
|
54
|
+
const { tokenId, newMetadata } = options;
|
55
|
+
const batch: Promise<string>[] = [
|
56
|
+
// image URI resolution
|
57
|
+
(async () => {
|
58
|
+
if (!newMetadata.image) {
|
59
|
+
return "";
|
60
|
+
}
|
61
|
+
if (typeof newMetadata.image === "string") {
|
62
|
+
return newMetadata.image;
|
63
|
+
}
|
64
|
+
return await upload({
|
65
|
+
client: options.contract.client,
|
66
|
+
files: [newMetadata.image],
|
67
|
+
});
|
68
|
+
})(),
|
69
|
+
// animation URI resolution
|
70
|
+
(async () => {
|
71
|
+
if (!newMetadata.animation_url) {
|
72
|
+
return "";
|
73
|
+
}
|
74
|
+
if (typeof newMetadata.animation_url === "string") {
|
75
|
+
return newMetadata.animation_url;
|
76
|
+
}
|
77
|
+
return await upload({
|
78
|
+
client: options.contract.client,
|
79
|
+
files: [newMetadata.animation_url],
|
80
|
+
});
|
81
|
+
})(),
|
82
|
+
];
|
83
|
+
|
84
|
+
const [imageURI, animationURI] = await Promise.all(batch);
|
85
|
+
if (newMetadata.image && imageURI) {
|
86
|
+
newMetadata.image = imageURI;
|
87
|
+
}
|
88
|
+
if (newMetadata.animation_url && animationURI) {
|
89
|
+
newMetadata.animation_url = animationURI;
|
90
|
+
}
|
91
|
+
|
92
|
+
const uri = await upload({
|
93
|
+
client: options.contract.client,
|
94
|
+
files: [newMetadata],
|
95
|
+
});
|
96
|
+
return { tokenId, uri };
|
97
|
+
}
|
@@ -5,7 +5,7 @@ import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
|
|
5
5
|
import { isAddress } from "../../utils/address.js";
|
6
6
|
import { deploySplitContract } from "./deploy-split.js";
|
7
7
|
|
8
|
-
describe("deploy-split contract", () => {
|
8
|
+
describe.runIf(process.env.TW_SECRET_KEY)("deploy-split contract", () => {
|
9
9
|
it("should deploy Split contract", async () => {
|
10
10
|
const address = await deploySplitContract({
|
11
11
|
account: TEST_ACCOUNT_A,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { Abi } from "abitype";
|
2
2
|
import type { ThirdwebClient } from "../../client/client.js";
|
3
|
+
import { formatCompilerMetadata } from "../../contract/actions/compiler-metadata.js";
|
3
4
|
import { download } from "../../storage/download.js";
|
4
5
|
import type { Hex } from "../encoding/hex.js";
|
5
6
|
import type { Prettify } from "../type-utils.js";
|
@@ -89,34 +90,6 @@ async function fetchAndParseCompilerMetadata(
|
|
89
90
|
return formatCompilerMetadata(metadata);
|
90
91
|
}
|
91
92
|
|
92
|
-
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix later
|
93
|
-
function formatCompilerMetadata(metadata: any): ParsedCompilerMetadata {
|
94
|
-
const abi = metadata.output.abi;
|
95
|
-
const compilationTarget = metadata.settings.compilationTarget;
|
96
|
-
const targets = Object.keys(compilationTarget);
|
97
|
-
const name = compilationTarget[targets[0] as keyof typeof compilationTarget];
|
98
|
-
const info = {
|
99
|
-
title: metadata.output.devdoc.title,
|
100
|
-
author: metadata.output.devdoc.author,
|
101
|
-
details: metadata.output.devdoc.detail,
|
102
|
-
notice: metadata.output.userdoc.notice,
|
103
|
-
};
|
104
|
-
const licenses: string[] = [
|
105
|
-
...new Set(
|
106
|
-
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix later
|
107
|
-
Object.entries(metadata.sources).map(([, src]) => (src as any).license),
|
108
|
-
),
|
109
|
-
];
|
110
|
-
return {
|
111
|
-
name,
|
112
|
-
abi,
|
113
|
-
metadata,
|
114
|
-
info,
|
115
|
-
licenses,
|
116
|
-
isPartialAbi: metadata.isPartialAbi,
|
117
|
-
};
|
118
|
-
}
|
119
|
-
|
120
93
|
// types
|
121
94
|
|
122
95
|
type RawCompilerMetadata = {
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.
|
1
|
+
export const version = "5.46.0-nightly-814024ae249141ad1446ce7f21793b1d37b95d13-20240814000405";
|
@@ -1,8 +1,20 @@
|
|
1
1
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
2
2
|
import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
|
3
|
-
import type
|
3
|
+
import { type AuthOption, authOptions } from "../../../../wallets/types.js";
|
4
4
|
import type { Ecosystem } from "../../web/types.js";
|
5
5
|
|
6
|
+
const getLoginOptionRoute = (option: AuthOption) => {
|
7
|
+
if (!authOptions.includes(option)) {
|
8
|
+
throw new Error(`Unknown auth option ${option}`);
|
9
|
+
}
|
10
|
+
switch (option) {
|
11
|
+
case "wallet":
|
12
|
+
return "siwe";
|
13
|
+
default:
|
14
|
+
return option;
|
15
|
+
}
|
16
|
+
};
|
17
|
+
|
6
18
|
export const getLoginUrl = ({
|
7
19
|
authOption,
|
8
20
|
client,
|
@@ -16,7 +28,8 @@ export const getLoginUrl = ({
|
|
16
28
|
mode?: "popup" | "redirect" | "mobile";
|
17
29
|
redirectUrl?: string;
|
18
30
|
}) => {
|
19
|
-
|
31
|
+
const route = getLoginOptionRoute(authOption);
|
32
|
+
let baseUrl = `${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/login/${route}?clientId=${client.clientId}`;
|
20
33
|
if (ecosystem?.partnerId) {
|
21
34
|
baseUrl = `${baseUrl}&ecosystemId=${ecosystem.id}&ecosystemPartnerId=${ecosystem.partnerId}`;
|
22
35
|
} else if (ecosystem) {
|
@@ -49,7 +62,8 @@ export const getLoginCallbackUrl = ({
|
|
49
62
|
client: ThirdwebClient;
|
50
63
|
ecosystem?: Ecosystem;
|
51
64
|
}): string => {
|
52
|
-
|
65
|
+
const route = getLoginOptionRoute(authOption);
|
66
|
+
let baseUrl = `${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/login/${route}/callback?clientId=${client.clientId}`;
|
53
67
|
if (ecosystem?.partnerId) {
|
54
68
|
baseUrl = `${baseUrl}&ecosystemId=${ecosystem.id}&ecosystemPartnerId=${ecosystem.partnerId}`;
|
55
69
|
} else if (ecosystem) {
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { signLoginPayload } from "../../../../auth/core/sign-login-payload.js";
|
2
2
|
import type { LoginPayload } from "../../../../auth/core/types.js";
|
3
|
+
import type { Chain } from "../../../../chains/types.js";
|
3
4
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
4
5
|
import { getClientFetch } from "../../../../utils/fetch.js";
|
5
|
-
import type {
|
6
|
-
import { createWallet } from "../../../../wallets/create-wallet.js";
|
6
|
+
import type { Wallet } from "../../../interfaces/wallet.js";
|
7
7
|
import type { Ecosystem } from "../../web/types.js";
|
8
8
|
import { getLoginCallbackUrl, getLoginUrl } from "./getLoginPath.js";
|
9
9
|
import type { AuthStoredTokenWithCookieReturnType } from "./types.js";
|
@@ -12,23 +12,23 @@ import type { AuthStoredTokenWithCookieReturnType } from "./types.js";
|
|
12
12
|
* @internal
|
13
13
|
*/
|
14
14
|
export async function siweAuthenticate(args: {
|
15
|
-
|
16
|
-
|
15
|
+
wallet: Wallet;
|
16
|
+
chain: Chain;
|
17
17
|
client: ThirdwebClient;
|
18
18
|
ecosystem?: Ecosystem;
|
19
19
|
}): Promise<AuthStoredTokenWithCookieReturnType> {
|
20
|
-
const wallet =
|
20
|
+
const { wallet, chain } = args;
|
21
21
|
const account = await wallet.connect({ client: args.client });
|
22
22
|
const clientFetch = getClientFetch(args.client, args.ecosystem);
|
23
23
|
|
24
24
|
const payload = await (async () => {
|
25
25
|
const path = getLoginUrl({
|
26
|
-
authOption: "
|
26
|
+
authOption: "wallet",
|
27
27
|
client: args.client,
|
28
28
|
ecosystem: args.ecosystem,
|
29
29
|
});
|
30
30
|
const res = await clientFetch(
|
31
|
-
`${path}&address=${account.address}&chainId=${
|
31
|
+
`${path}&address=${account.address}&chainId=${chain.id}`,
|
32
32
|
);
|
33
33
|
|
34
34
|
if (!res.ok) throw new Error("Failed to generate SIWE login payload");
|
@@ -39,7 +39,7 @@ export async function siweAuthenticate(args: {
|
|
39
39
|
|
40
40
|
const authResult = await (async () => {
|
41
41
|
const path = getLoginCallbackUrl({
|
42
|
-
authOption: "
|
42
|
+
authOption: "wallet",
|
43
43
|
client: args.client,
|
44
44
|
ecosystem: args.ecosystem,
|
45
45
|
});
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import type { AuthType } from "@passwordless-id/webauthn/dist/esm/types.js";
|
2
|
+
import type { Chain } from "../../../../chains/types.js";
|
2
3
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
3
4
|
import type { Address } from "../../../../utils/address.js";
|
4
|
-
import type { InjectedSupportedWalletIds } from "../../../../wallets/__generated__/wallet-ids.js";
|
5
5
|
import type { Account } from "../../../interfaces/wallet.js";
|
6
|
+
import type { Wallet } from "../../../interfaces/wallet.js";
|
6
7
|
import type { AuthOption, SocialAuthOption } from "../../../types.js";
|
7
8
|
import type { Ecosystem } from "../../web/types.js";
|
8
9
|
|
@@ -42,9 +43,9 @@ export type SingleStepAuthArgsType =
|
|
42
43
|
authenticatorType?: AuthType;
|
43
44
|
}
|
44
45
|
| {
|
45
|
-
strategy: "
|
46
|
-
|
47
|
-
|
46
|
+
strategy: "wallet";
|
47
|
+
wallet: Wallet;
|
48
|
+
chain: Chain;
|
48
49
|
};
|
49
50
|
|
50
51
|
export type AuthArgsType = (MultiStepAuthArgsType | SingleStepAuthArgsType) & {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import * as WebBrowser from "expo-web-browser";
|
2
|
+
import type { Chain } from "../../../../chains/types.js";
|
2
3
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
3
|
-
import type {
|
4
|
+
import type { Wallet } from "../../../interfaces/wallet.js";
|
4
5
|
import { getLoginUrl } from "../../core/authentication/getLoginPath.js";
|
5
6
|
import { siweAuthenticate } from "../../core/authentication/siwe.js";
|
6
7
|
import type {
|
@@ -125,15 +126,15 @@ export async function socialLogin(
|
|
125
126
|
|
126
127
|
export async function siweLogin(
|
127
128
|
client: ThirdwebClient,
|
128
|
-
|
129
|
-
|
129
|
+
wallet: Wallet,
|
130
|
+
chain: Chain,
|
130
131
|
ecosystem?: Ecosystem,
|
131
132
|
): Promise<AuthStoredTokenWithCookieReturnType> {
|
132
133
|
const { storedToken } = await siweAuthenticate({
|
133
134
|
client,
|
134
135
|
ecosystem,
|
135
|
-
|
136
|
-
|
136
|
+
wallet,
|
137
|
+
chain,
|
137
138
|
});
|
138
139
|
try {
|
139
140
|
const toStoreToken: AuthStoredTokenWithCookieReturnType["storedToken"] = {
|
@@ -1,6 +1,6 @@
|
|
1
|
+
import type { Chain } from "../../../chains/types.js";
|
1
2
|
import type { ThirdwebClient } from "../../../client/client.js";
|
2
|
-
import type {
|
3
|
-
import type { Account } from "../../interfaces/wallet.js";
|
3
|
+
import type { Account, Wallet } from "../../interfaces/wallet.js";
|
4
4
|
import { siweAuthenticate } from "../core/authentication/siwe.js";
|
5
5
|
import {
|
6
6
|
type AuthArgsType,
|
@@ -91,11 +91,11 @@ export class InAppNativeConnector implements InAppConnector {
|
|
91
91
|
case "phone": {
|
92
92
|
return verifyOtp(params);
|
93
93
|
}
|
94
|
-
case "
|
94
|
+
case "wallet": {
|
95
95
|
return siweAuthenticate({
|
96
96
|
client: this.options.client,
|
97
|
-
|
98
|
-
|
97
|
+
wallet: params.wallet,
|
98
|
+
chain: params.chain,
|
99
99
|
});
|
100
100
|
}
|
101
101
|
case "google":
|
@@ -145,10 +145,10 @@ export class InAppNativeConnector implements InAppConnector {
|
|
145
145
|
redirectUrl,
|
146
146
|
});
|
147
147
|
}
|
148
|
-
case "
|
148
|
+
case "wallet": {
|
149
149
|
return this.siweLogin({
|
150
|
-
|
151
|
-
|
150
|
+
wallet: params.wallet,
|
151
|
+
chain: params.chain,
|
152
152
|
});
|
153
153
|
}
|
154
154
|
case "jwt": {
|
@@ -230,14 +230,14 @@ export class InAppNativeConnector implements InAppConnector {
|
|
230
230
|
}
|
231
231
|
|
232
232
|
private async siweLogin(options: {
|
233
|
-
|
234
|
-
|
233
|
+
wallet: Wallet;
|
234
|
+
chain: Chain;
|
235
235
|
}): Promise<AuthLoginReturnType> {
|
236
236
|
try {
|
237
237
|
const { storedToken } = await siweLogin(
|
238
238
|
this.options.client,
|
239
|
-
options.
|
240
|
-
options.
|
239
|
+
options.wallet,
|
240
|
+
options.chain,
|
241
241
|
);
|
242
242
|
const account = await this.getAccount();
|
243
243
|
return {
|
@@ -250,15 +250,15 @@ export class InAppNativeConnector implements InAppConnector {
|
|
250
250
|
};
|
251
251
|
} catch (error) {
|
252
252
|
console.error(
|
253
|
-
`Error while signing in with: ${options.
|
253
|
+
`Error while signing in with: ${options.wallet.id}. ${error}`,
|
254
254
|
);
|
255
255
|
if (error instanceof Error) {
|
256
256
|
throw new Error(
|
257
|
-
`Error signing in with ${options.
|
257
|
+
`Error signing in with ${options.wallet.id}: ${error.message}`,
|
258
258
|
);
|
259
259
|
}
|
260
260
|
throw new Error(
|
261
|
-
`An unknown error occurred signing in with ${options.
|
261
|
+
`An unknown error occurred signing in with ${options.wallet.id}`,
|
262
262
|
);
|
263
263
|
}
|
264
264
|
}
|
@@ -63,6 +63,21 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
|
63
63
|
* });
|
64
64
|
* ```
|
65
65
|
*
|
66
|
+
* ### Login with SIWE
|
67
|
+
* ```ts
|
68
|
+
* import { inAppWallet, createWallet } from "thirdweb/wallets";
|
69
|
+
*
|
70
|
+
* const rabby = createWallet("io.rabby");
|
71
|
+
* const inAppWallet = inAppWallet();
|
72
|
+
*
|
73
|
+
* const account = await inAppWallet.connect({
|
74
|
+
* strategy: "wallet",
|
75
|
+
* chain: mainnet,
|
76
|
+
* wallet: rabby,
|
77
|
+
* client: MY_CLIENT
|
78
|
+
* });
|
79
|
+
* ```
|
80
|
+
*
|
66
81
|
* ### Login with phone number
|
67
82
|
* ```ts
|
68
83
|
* import { inAppWallet, preAuthenticate } from "thirdweb/wallets/in-app";
|
@@ -222,12 +222,12 @@ export class InAppWebConnector implements InAppConnector {
|
|
222
222
|
openedWindow: args.openedWindow,
|
223
223
|
});
|
224
224
|
}
|
225
|
-
case "
|
225
|
+
case "wallet": {
|
226
226
|
return siweAuthenticate({
|
227
|
-
client: this.wallet.client,
|
228
227
|
ecosystem: this.wallet.ecosystem,
|
229
|
-
|
230
|
-
|
228
|
+
client: this.wallet.client,
|
229
|
+
wallet: args.wallet,
|
230
|
+
chain: args.chain,
|
231
231
|
});
|
232
232
|
}
|
233
233
|
}
|
@@ -280,7 +280,7 @@ export class InAppWebConnector implements InAppConnector {
|
|
280
280
|
}
|
281
281
|
case "phone":
|
282
282
|
case "email":
|
283
|
-
case "
|
283
|
+
case "wallet":
|
284
284
|
case "apple":
|
285
285
|
case "facebook":
|
286
286
|
case "google":
|
package/src/wallets/types.ts
CHANGED
@@ -29,12 +29,14 @@ export const socialAuthOptions = [
|
|
29
29
|
] as const;
|
30
30
|
export type SocialAuthOption = (typeof socialAuthOptions)[number];
|
31
31
|
|
32
|
-
export
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
export const authOptions = [
|
33
|
+
...socialAuthOptions,
|
34
|
+
"email",
|
35
|
+
"phone",
|
36
|
+
"passkey",
|
37
|
+
"wallet",
|
38
|
+
] as const;
|
39
|
+
export type AuthOption = (typeof authOptions)[number];
|
38
40
|
|
39
41
|
export type DisconnectFn = () => Promise<void>;
|
40
42
|
export type SwitchChainFn = (chain: Chain) => Promise<void>;
|