@opensea/sdk 12.0.0 → 12.1.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.
Files changed (52) hide show
  1. package/README.md +31 -0
  2. package/lib/api/api.d.ts +17 -1
  3. package/lib/api/api.js +26 -2
  4. package/lib/api/api.js.map +1 -1
  5. package/lib/api/apiPaths.d.ts +4 -0
  6. package/lib/api/apiPaths.js +18 -2
  7. package/lib/api/apiPaths.js.map +1 -1
  8. package/lib/api/listings.d.ts +5 -1
  9. package/lib/api/listings.js +6 -0
  10. package/lib/api/listings.js.map +1 -1
  11. package/lib/api/offers.d.ts +9 -1
  12. package/lib/api/offers.js +12 -0
  13. package/lib/api/offers.js.map +1 -1
  14. package/lib/api/orders.d.ts +5 -1
  15. package/lib/api/orders.js +6 -0
  16. package/lib/api/orders.js.map +1 -1
  17. package/lib/api/types.d.ts +9 -1
  18. package/lib/api/walletAuth.d.ts +21 -1
  19. package/lib/api/walletAuth.js +24 -5
  20. package/lib/api/walletAuth.js.map +1 -1
  21. package/lib/orders/erc20Fulfillment.js +67 -4
  22. package/lib/orders/erc20Fulfillment.js.map +1 -1
  23. package/lib/provider/seaport-bridge.js +2 -2
  24. package/lib/provider/seaport-bridge.js.map +1 -1
  25. package/lib/provider/viem-adapter.js +3 -3
  26. package/lib/provider/viem-adapter.js.map +1 -1
  27. package/lib/sdk/assets.js +8 -0
  28. package/lib/sdk/assets.js.map +1 -1
  29. package/lib/sdk/base.d.ts +1 -0
  30. package/lib/sdk/cancellation.js +6 -1
  31. package/lib/sdk/cancellation.js.map +1 -1
  32. package/lib/utils/eip712.d.ts +21 -0
  33. package/lib/utils/eip712.js +54 -0
  34. package/lib/utils/eip712.js.map +1 -0
  35. package/lib/utils/rateLimit.d.ts +6 -0
  36. package/lib/utils/rateLimit.js +22 -5
  37. package/lib/utils/rateLimit.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/api/api.ts +54 -2
  40. package/src/api/apiPaths.ts +20 -0
  41. package/src/api/listings.ts +15 -0
  42. package/src/api/offers.ts +30 -0
  43. package/src/api/orders.ts +18 -0
  44. package/src/api/types.ts +21 -0
  45. package/src/api/walletAuth.ts +29 -2
  46. package/src/orders/erc20Fulfillment.ts +74 -4
  47. package/src/provider/seaport-bridge.ts +2 -3
  48. package/src/provider/viem-adapter.ts +3 -4
  49. package/src/sdk/assets.ts +9 -0
  50. package/src/sdk/cancellation.ts +6 -1
  51. package/src/utils/eip712.ts +57 -0
  52. package/src/utils/rateLimit.ts +29 -4
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Kept in step with `inferPrimaryType` in @opensea/wallet-adapters
3
+ * (`src/bridges/ethers.ts`). The two are deliberately separate copies: the sdk
4
+ * does not depend on wallet-adapters, and adding that edge would couple the
5
+ * sdk's release to it for one pure function. Change both together.
6
+ */
7
+ /**
8
+ * Infer the EIP-712 primary type: the struct that no other struct references,
9
+ * which is the root of the type graph.
10
+ *
11
+ * Taking the first key in `types` instead is wrong whenever a dependency is
12
+ * declared before the root, and it fails silently by signing the wrong struct.
13
+ * ethers resolves this the same way.
14
+ *
15
+ * Refuses rather than guessing when the graph is circular or has more than one
16
+ * root. Both are invalid EIP-712 and ethers rejects them itself ("circular type
17
+ * reference", "ambiguous primary types or unused types"), so throwing costs
18
+ * nothing where the signer validates and prevents a wrong signature where it
19
+ * does not.
20
+ */
21
+ export function inferPrimaryType(types: Record<string, unknown>): string {
22
+ const named = Object.keys(types).filter(t => t !== "EIP712Domain")
23
+ if (named.length === 0) {
24
+ return ""
25
+ }
26
+
27
+ const referenced = new Set<string>()
28
+ for (const name of named) {
29
+ const fields = types[name]
30
+ if (!Array.isArray(fields)) continue
31
+ for (const field of fields) {
32
+ // Strips trailing array suffixes, including repeated ones: Person[],
33
+ // Person[2] and Mail[2][] all reduce to the struct name. EIP-712 field
34
+ // types are an atomic type, an array of those, or a struct name, so there
35
+ // is no further nesting to unwrap. Solidity tuple syntax is not part of
36
+ // the format.
37
+ const base = String((field as { type?: unknown }).type).replace(
38
+ /(\[\d*\])+$/,
39
+ "",
40
+ )
41
+ if (base in types) referenced.add(base)
42
+ }
43
+ }
44
+
45
+ const roots = named.filter(t => !referenced.has(t))
46
+ if (roots.length === 0) {
47
+ throw new Error(
48
+ `Cannot infer EIP-712 primaryType: every type is referenced by another, so the type graph is circular (${named.join(", ")}). Pass primaryType explicitly.`,
49
+ )
50
+ }
51
+ if (roots.length > 1) {
52
+ throw new Error(
53
+ `Cannot infer EIP-712 primaryType: ${roots.join(", ")} are all unreferenced, so the root is ambiguous. Pass primaryType explicitly.`,
54
+ )
55
+ }
56
+ return roots[0]
57
+ }
@@ -23,6 +23,12 @@ const CUSTOM_RATE_LIMIT_STATUS_CODE = 599
23
23
  export interface RateLimitOptions {
24
24
  /** Logger function for logging progress */
25
25
  logger?: (message: string) => void
26
+ /**
27
+ * Abort signal that cancels a pending retry delay. The operation itself is
28
+ * responsible for its own cancellation; this only stops the wait between
29
+ * attempts so an aborted caller does not sit out the full `Retry-After`.
30
+ */
31
+ signal?: AbortSignal
26
32
  /** Maximum number of retry attempts for rate limit errors */
27
33
  maxRetries?: number
28
34
  /** Base delay in ms to wait after a rate limit error if retry-after header is not present */
@@ -30,11 +36,29 @@ export interface RateLimitOptions {
30
36
  }
31
37
 
32
38
  /**
33
- * Sleep for a specified duration
39
+ * Sleep for a specified duration, optionally cancellable.
34
40
  * @param ms Duration in milliseconds
41
+ * @param signal Optional signal that rejects the sleep early
35
42
  */
36
- function sleep(ms: number): Promise<void> {
37
- return new Promise(resolve => setTimeout(resolve, ms))
43
+ function sleep(ms: number, signal?: AbortSignal): Promise<void> {
44
+ if (!signal) {
45
+ return new Promise(resolve => setTimeout(resolve, ms))
46
+ }
47
+ if (signal.aborted) {
48
+ return Promise.reject(new Error("Request aborted"))
49
+ }
50
+
51
+ return new Promise((resolve, reject) => {
52
+ const onAbort = () => {
53
+ clearTimeout(timeoutId)
54
+ reject(new Error("Request aborted"))
55
+ }
56
+ const timeoutId = setTimeout(() => {
57
+ signal.removeEventListener("abort", onAbort)
58
+ resolve()
59
+ }, ms)
60
+ signal.addEventListener("abort", onAbort, { once: true })
61
+ })
38
62
  }
39
63
 
40
64
  /**
@@ -52,6 +76,7 @@ export async function executeWithRateLimit<T>(
52
76
  ): Promise<T> {
53
77
  const {
54
78
  logger = () => {},
79
+ signal,
55
80
  maxRetries = DEFAULT_MAX_RETRIES,
56
81
  baseRetryDelay = DEFAULT_BASE_RETRY_DELAY_MS,
57
82
  } = options
@@ -92,7 +117,7 @@ export async function executeWithRateLimit<T>(
92
117
  )
93
118
  }
94
119
 
95
- await sleep(delayMs)
120
+ await sleep(delayMs, signal)
96
121
  logger(`Retrying operation...`)
97
122
  }
98
123
  }