Skip to content

Commit b1da82e

Browse files
committed
Release v11.4.4
Origin-SHA: a3a8e10acb515886af62d6b886a9da23447aead3
1 parent eb15b6f commit b1da82e

4 files changed

Lines changed: 32 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @opensea/sdk
22

3+
## 11.4.4
4+
5+
### Patch Changes
6+
7+
- d846160: Use the current OpenSea API endpoints for SIWE login, scoped-token exchange, refresh, revocation, and wallet-link nonces.
8+
39
## 11.4.3
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opensea/sdk",
3-
"version": "11.4.3",
3+
"version": "11.4.4",
44
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs, tokens, and our marketplace data",
55
"license": "MIT",
66
"author": "OpenSea Developers",

src/auth/siwx.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
import { getAddress } from "ethers"
66
import type { AuthSigner } from "./types"
77

8-
const DEFAULT_AUTH_BASE_URL = "https://auth.opensea.io"
98
const DEFAULT_API_BASE_URL = "https://api.opensea.io"
109
const DEFAULT_STATEMENT =
1110
"Click to sign in and accept the OpenSea Terms of Service (https://opensea.io/tos) and Privacy Policy (https://opensea.io/privacy)."
@@ -49,8 +48,10 @@ export interface ParseSiwxMessageResult {
4948

5049
export interface LinkWalletWithSiwxOptions
5150
extends Omit<CreateSiwxMessageOptions, "address" | "chainId" | "nonce"> {
51+
/** @deprecated Nonces now come from apiBaseUrl. */
5252
authBaseUrl?: string
5353
apiBaseUrl?: string
54+
apiKey?: string
5455
authToken: string
5556
chainArch: ChainArch
5657
chainId: number
@@ -251,15 +252,18 @@ export function parseSiwxMessage(message: string): ParseSiwxMessageResult {
251252
}
252253

253254
/**
254-
* Request a single-use nonce from the auth service.
255+
* Request a single-use nonce from the OpenSea API.
255256
*/
256257
export async function requestSiwxNonce(
257-
authBaseUrl = DEFAULT_AUTH_BASE_URL,
258+
apiBaseUrl = DEFAULT_API_BASE_URL,
258259
): Promise<string> {
259-
const response = await fetch(`${stripTrailingSlash(authBaseUrl)}/api/nonce`, {
260-
method: "GET",
261-
headers: { Accept: "application/json" },
262-
})
260+
const response = await fetch(
261+
`${stripTrailingSlash(apiBaseUrl)}/api/v2/auth/siwe/nonce`,
262+
{
263+
method: "POST",
264+
headers: { Accept: "application/json" },
265+
},
266+
)
263267
if (!response.ok) {
264268
throw new Error(
265269
`Auth server error (${response.status}): ${response.statusText}`,
@@ -283,13 +287,10 @@ export async function linkWalletWithSiwx(
283287
throw new Error("authToken is required to link a wallet")
284288
}
285289

286-
const authBaseUrl = stripTrailingSlash(
287-
options.authBaseUrl ?? DEFAULT_AUTH_BASE_URL,
288-
)
289290
const apiBaseUrl = stripTrailingSlash(
290291
options.apiBaseUrl ?? DEFAULT_API_BASE_URL,
291292
)
292-
const nonce = await requestSiwxNonce(authBaseUrl)
293+
const nonce = await requestSiwxNonce(apiBaseUrl)
293294
const address = await signer.getAddress()
294295
const message = createSiwxMessage({
295296
address,
@@ -319,6 +320,7 @@ export async function linkWalletWithSiwx(
319320
headers: {
320321
Authorization: `Bearer ${options.authToken}`,
321322
"Content-Type": "application/json",
323+
...(options.apiKey ? { "X-API-KEY": options.apiKey } : {}),
322324
},
323325
body: JSON.stringify(payload),
324326
})

test/auth/siwx.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,18 @@ describe("SIWX wallet-link helpers", () => {
119119

120120
const result = await linkWalletWithSiwx(signer, {
121121
authToken: "token-123",
122+
apiKey: "api-key",
122123
chainArch: "EVM",
123124
chainId: 1,
124-
authBaseUrl: "https://auth.opensea.io",
125125
apiBaseUrl: "https://api.opensea.io",
126126
})
127127

128128
expect(result.linkedWalletAddress).toBe(address)
129129
expect(fetchSpy).toHaveBeenCalledTimes(2)
130130

131131
const [nonceUrl] = fetchSpy.mock.calls[0] as [string]
132-
expect(nonceUrl).toBe("https://auth.opensea.io/api/nonce")
132+
expect(nonceUrl).toBe("https://api.opensea.io/api/v2/auth/siwe/nonce")
133+
expect(fetchSpy.mock.calls[0][1]).toMatchObject({ method: "POST" })
133134

134135
const [linkUrl, linkInit] = fetchSpy.mock.calls[1] as [
135136
string,
@@ -138,6 +139,7 @@ describe("SIWX wallet-link helpers", () => {
138139
expect(linkUrl).toBe("https://api.opensea.io/api/v2/accounts/wallets/siwx")
139140
expect(linkInit.method).toBe("POST")
140141
expect(linkInit.headers.Authorization).toBe("Bearer token-123")
142+
expect(linkInit.headers["X-API-KEY"]).toBe("api-key")
141143

142144
const body = JSON.parse(linkInit.body as string) as {
143145
message: {
@@ -164,14 +166,17 @@ describe("SIWX wallet-link helpers", () => {
164166
new Response(JSON.stringify({ nonce: "nonce-123" }), { status: 200 }),
165167
)
166168

167-
await expect(requestSiwxNonce("https://auth.opensea.io/")).resolves.toBe(
169+
await expect(requestSiwxNonce("https://api.opensea.io/")).resolves.toBe(
168170
"nonce-123",
169171
)
170172

171-
expect(fetchSpy).toHaveBeenCalledWith("https://auth.opensea.io/api/nonce", {
172-
method: "GET",
173-
headers: { Accept: "application/json" },
174-
})
173+
expect(fetchSpy).toHaveBeenCalledWith(
174+
"https://api.opensea.io/api/v2/auth/siwe/nonce",
175+
{
176+
method: "POST",
177+
headers: { Accept: "application/json" },
178+
},
179+
)
175180
})
176181

177182
it("rejects empty auth tokens", async () => {
@@ -214,7 +219,6 @@ describe("SIWX wallet-link helpers", () => {
214219
authToken: "token-123",
215220
chainArch: "EVM",
216221
chainId: 1,
217-
authBaseUrl: "https://auth.opensea.io",
218222
apiBaseUrl: "https://api.opensea.io",
219223
expirationTime: new Date("2026-01-02T00:00:00.000Z"),
220224
notBefore: new Date("2026-01-01T12:00:00.000Z"),

0 commit comments

Comments
 (0)