@opensea/sdk 12.3.0 → 12.5.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/src/auth/oauth.ts CHANGED
@@ -443,6 +443,43 @@ export function extractWalletAddress(
443
443
  return undefined
444
444
  }
445
445
 
446
+ /**
447
+ * Read every wallet address the token's account has registered, from the
448
+ * `linked_wallets` claim.
449
+ *
450
+ * Webauth mints the claim from the account's registered wallets and it always
451
+ * contains the token's own {@link extractWalletAddress} wallet, so treat the
452
+ * result as the complete set rather than as "the other wallets". Combining it
453
+ * with the `wallet` claim double-counts the primary; using only the `wallet`
454
+ * claim under-reports every account that has linked more than one.
455
+ *
456
+ * Addresses may be from any chain OpenSea supports, EVM and Solana alike, so
457
+ * no format validation is applied here. An entry that is not a non-empty
458
+ * string is dropped, and everything else is returned for the server to judge.
459
+ * Returns an empty array when the claim is absent, is not an array, or the
460
+ * token is not a JWT.
461
+ *
462
+ * This does not verify the token and must not be used to make an authorization
463
+ * decision.
464
+ */
465
+ export function extractLinkedWallets(accessToken: string): string[] {
466
+ try {
467
+ const claim = decodeJwtPayload(accessToken).linked_wallets
468
+ if (!Array.isArray(claim)) return []
469
+ const wallets = claim.filter(
470
+ (wallet): wallet is string =>
471
+ typeof wallet === "string" && wallet.trim().length > 0,
472
+ )
473
+ // Exact dedupe, not case-folded: EVM addresses differ only by checksum
474
+ // casing, but Solana base58 addresses are case-sensitive, so lowercasing
475
+ // to compare would risk collapsing two distinct Solana wallets into one.
476
+ return [...new Set(wallets)]
477
+ } catch {
478
+ // Opaque access tokens carry no claims to read.
479
+ }
480
+ return []
481
+ }
482
+
446
483
  /**
447
484
  * Decode a JWT payload without verifying the signature. Intended for reading
448
485
  * claims out of a token the authorization server just issued to us over TLS —