@opensea/sdk 13.0.2 → 13.0.4
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/README.md +28 -0
- package/lib/utils/case.d.ts +7 -3
- package/package.json +2 -1
- package/src/utils/case.ts +49 -5
package/README.md
CHANGED
|
@@ -159,6 +159,34 @@ const publicClient = createPublicClient({ chain: mainnet, transport: http() })
|
|
|
159
159
|
const sdk = new OpenSeaSDK({ publicClient }, { chain: Chain.Mainnet, apiKey: 'YOUR_API_KEY' })
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
+
### With a wallet adapter
|
|
163
|
+
|
|
164
|
+
To sign with a managed wallet (Privy, Turnkey, Fireblocks, Bankr) or a raw private key, wrap a
|
|
165
|
+
[`@opensea/wallet-adapters`](https://github.com/ProjectOpenSea/wallet-adapters) adapter in its
|
|
166
|
+
ethers bridge and pass the result as the signer. Orders are signed through the adapter's
|
|
167
|
+
`signTypedData`, and fulfillments, approvals and onchain cancels go through its `sendTransaction`.
|
|
168
|
+
The provider is used for reads and receipts only.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { ethers } from "ethers";
|
|
172
|
+
import { OpenSeaSDK, Chain } from "@opensea/sdk";
|
|
173
|
+
import { createWalletFromEnv } from "@opensea/wallet-adapters";
|
|
174
|
+
import { walletAdapterToEthersSigner } from "@opensea/wallet-adapters/ethers";
|
|
175
|
+
|
|
176
|
+
const provider = new ethers.JsonRpcProvider("https://mainnet.base.org");
|
|
177
|
+
const signer = walletAdapterToEthersSigner(createWalletFromEnv(), provider);
|
|
178
|
+
const sdk = new OpenSeaSDK(signer, { chain: Chain.Base, apiKey: "YOUR_API_KEY" });
|
|
179
|
+
|
|
180
|
+
const listing = await sdk.createListing({
|
|
181
|
+
asset: { tokenAddress, tokenId },
|
|
182
|
+
accountAddress: await signer.getAddress(),
|
|
183
|
+
amount: "0.5",
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The adapter has to support typed-data signing (`wallet.capabilities.signTypedData`) to create
|
|
188
|
+
listings and offers.
|
|
189
|
+
|
|
162
190
|
### Wallet-authenticated API helpers
|
|
163
191
|
|
|
164
192
|
For a server-side EVM signer, `OpenSeaAuth` signs in with SIWE, creates a scoped
|
package/lib/utils/case.d.ts
CHANGED
|
@@ -46,11 +46,15 @@ type CamelToSnake<S extends string> = S extends `${infer Head}${infer Tail}` ? I
|
|
|
46
46
|
export type Snakeize<T> = T extends Date ? T : T extends Array<infer U> ? Array<Snakeize<U>> : T extends object ? {
|
|
47
47
|
[K in keyof T as K extends string ? CamelToSnake<K> : K]: Snakeize<T[K]>;
|
|
48
48
|
} : T;
|
|
49
|
+
/** The characters `snakeToCamel`'s `/_([a-z0-9])/` consumes after an underscore. */
|
|
50
|
+
type LowerAlphanumeric = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
49
51
|
/**
|
|
50
|
-
* Maps a snake_case string literal to camelCase at the type level
|
|
51
|
-
* `"is_nsfw"` → `"isNsfw"`.
|
|
52
|
+
* Maps a snake_case string literal to camelCase at the type level, matching
|
|
53
|
+
* {@link snakeToCamel}: `"is_nsfw"` → `"isNsfw"`. Only an underscore followed
|
|
54
|
+
* by a lowercase ASCII letter or digit is consumed, so `"foo__bar"` →
|
|
55
|
+
* `"foo_Bar"` and `"trailing_"` stays as is.
|
|
52
56
|
*/
|
|
53
|
-
type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${
|
|
57
|
+
type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Next}${infer Tail}` ? Next extends LowerAlphanumeric ? `${Head}${Uppercase<Next>}${SnakeToCamel<Tail>}` : `${Head}_${SnakeToCamel<`${Next}${Tail}`>}` : S;
|
|
54
58
|
/**
|
|
55
59
|
* Recursively rewrites object keys from snake_case to camelCase. Preserves
|
|
56
60
|
* arrays, primitives, and non-plain objects (Date, etc.).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensea/sdk",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.4",
|
|
4
4
|
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs, tokens, and our marketplace data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "OpenSea Developers",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
+
"@opensea/wallet-adapters": "^1.2.3",
|
|
63
64
|
"@types/node": "^25.4.0",
|
|
64
65
|
"@vitest/coverage-v8": "^3.2.4",
|
|
65
66
|
"concurrently": "^9.2.1",
|
package/src/utils/case.ts
CHANGED
|
@@ -128,13 +128,57 @@ export type Snakeize<T> = T extends Date
|
|
|
128
128
|
|
|
129
129
|
// ─── Type-level mapper ─────────────────────────────────────────────────────
|
|
130
130
|
|
|
131
|
+
/** The characters `snakeToCamel`'s `/_([a-z0-9])/` consumes after an underscore. */
|
|
132
|
+
type LowerAlphanumeric =
|
|
133
|
+
| "a"
|
|
134
|
+
| "b"
|
|
135
|
+
| "c"
|
|
136
|
+
| "d"
|
|
137
|
+
| "e"
|
|
138
|
+
| "f"
|
|
139
|
+
| "g"
|
|
140
|
+
| "h"
|
|
141
|
+
| "i"
|
|
142
|
+
| "j"
|
|
143
|
+
| "k"
|
|
144
|
+
| "l"
|
|
145
|
+
| "m"
|
|
146
|
+
| "n"
|
|
147
|
+
| "o"
|
|
148
|
+
| "p"
|
|
149
|
+
| "q"
|
|
150
|
+
| "r"
|
|
151
|
+
| "s"
|
|
152
|
+
| "t"
|
|
153
|
+
| "u"
|
|
154
|
+
| "v"
|
|
155
|
+
| "w"
|
|
156
|
+
| "x"
|
|
157
|
+
| "y"
|
|
158
|
+
| "z"
|
|
159
|
+
| "0"
|
|
160
|
+
| "1"
|
|
161
|
+
| "2"
|
|
162
|
+
| "3"
|
|
163
|
+
| "4"
|
|
164
|
+
| "5"
|
|
165
|
+
| "6"
|
|
166
|
+
| "7"
|
|
167
|
+
| "8"
|
|
168
|
+
| "9"
|
|
169
|
+
|
|
131
170
|
/**
|
|
132
|
-
* Maps a snake_case string literal to camelCase at the type level
|
|
133
|
-
* `"is_nsfw"` → `"isNsfw"`.
|
|
171
|
+
* Maps a snake_case string literal to camelCase at the type level, matching
|
|
172
|
+
* {@link snakeToCamel}: `"is_nsfw"` → `"isNsfw"`. Only an underscore followed
|
|
173
|
+
* by a lowercase ASCII letter or digit is consumed, so `"foo__bar"` →
|
|
174
|
+
* `"foo_Bar"` and `"trailing_"` stays as is.
|
|
134
175
|
*/
|
|
135
|
-
type SnakeToCamel<S extends string> =
|
|
136
|
-
|
|
137
|
-
|
|
176
|
+
type SnakeToCamel<S extends string> =
|
|
177
|
+
S extends `${infer Head}_${infer Next}${infer Tail}`
|
|
178
|
+
? Next extends LowerAlphanumeric
|
|
179
|
+
? `${Head}${Uppercase<Next>}${SnakeToCamel<Tail>}`
|
|
180
|
+
: `${Head}_${SnakeToCamel<`${Next}${Tail}`>}`
|
|
181
|
+
: S
|
|
138
182
|
|
|
139
183
|
/**
|
|
140
184
|
* Recursively rewrites object keys from snake_case to camelCase. Preserves
|