@opensea/sdk 11.9.0 → 12.0.1

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 (50) hide show
  1. package/README.md +5 -2
  2. package/lib/api/types.d.ts +20 -64
  3. package/lib/api/types.js.map +1 -1
  4. package/lib/api/walletAuth.d.ts +95 -8
  5. package/lib/api/walletAuth.js +75 -6
  6. package/lib/api/walletAuth.js.map +1 -1
  7. package/lib/orders/attribution.d.ts +18 -0
  8. package/lib/orders/attribution.js +29 -0
  9. package/lib/orders/attribution.js.map +1 -0
  10. package/lib/orders/erc20Fulfillment.js +67 -4
  11. package/lib/orders/erc20Fulfillment.js.map +1 -1
  12. package/lib/orders/types.d.ts +16 -28
  13. package/lib/orders/types.js.map +1 -1
  14. package/lib/provider/seaport-bridge.js +2 -2
  15. package/lib/provider/seaport-bridge.js.map +1 -1
  16. package/lib/provider/viem-adapter.js +3 -3
  17. package/lib/provider/viem-adapter.js.map +1 -1
  18. package/lib/scopes.d.ts +1 -0
  19. package/lib/scopes.js +1 -0
  20. package/lib/scopes.js.map +1 -1
  21. package/lib/sdk/assets.js +8 -0
  22. package/lib/sdk/assets.js.map +1 -1
  23. package/lib/sdk/cancellation.js +6 -1
  24. package/lib/sdk/cancellation.js.map +1 -1
  25. package/lib/sdk/fulfillment.js +7 -3
  26. package/lib/sdk/fulfillment.js.map +1 -1
  27. package/lib/stream/client.d.ts +14 -1
  28. package/lib/stream/client.js +39 -22
  29. package/lib/stream/client.js.map +1 -1
  30. package/lib/stream/types.d.ts +32 -63
  31. package/lib/stream/types.js +7 -0
  32. package/lib/stream/types.js.map +1 -1
  33. package/lib/utils/eip712.d.ts +21 -0
  34. package/lib/utils/eip712.js +54 -0
  35. package/lib/utils/eip712.js.map +1 -0
  36. package/package.json +2 -2
  37. package/src/api/types.ts +27 -64
  38. package/src/api/walletAuth.ts +100 -13
  39. package/src/orders/attribution.ts +29 -0
  40. package/src/orders/erc20Fulfillment.ts +74 -4
  41. package/src/orders/types.ts +21 -44
  42. package/src/provider/seaport-bridge.ts +2 -3
  43. package/src/provider/viem-adapter.ts +3 -4
  44. package/src/scopes.ts +1 -0
  45. package/src/sdk/assets.ts +9 -0
  46. package/src/sdk/cancellation.ts +6 -1
  47. package/src/sdk/fulfillment.ts +8 -3
  48. package/src/stream/client.ts +45 -23
  49. package/src/stream/types.ts +39 -64
  50. package/src/utils/eip712.ts +57 -0
@@ -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
+ }