@@ -5,7 +5,6 @@ import type {
55import { getAddress } from "ethers"
66import type { AuthSigner } from "./types"
77
8- const DEFAULT_AUTH_BASE_URL = "https://auth.opensea.io"
98const DEFAULT_API_BASE_URL = "https://api.opensea.io"
109const 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
5049export 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 */
256257export 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 } )
0 commit comments