@skillzmarket/sdk 0.1.1 → 0.1.3
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 +143 -14
- package/dist/bin/init.d.ts +3 -0
- package/dist/bin/init.d.ts.map +1 -0
- package/dist/bin/init.js +7 -0
- package/dist/bin/init.js.map +1 -0
- package/dist/creator/index.d.ts +2 -1
- package/dist/creator/index.d.ts.map +1 -1
- package/dist/creator/index.js +2 -1
- package/dist/creator/index.js.map +1 -1
- package/dist/creator/init.d.ts +24 -0
- package/dist/creator/init.d.ts.map +1 -0
- package/dist/creator/init.js +226 -0
- package/dist/creator/init.js.map +1 -0
- package/dist/creator/register.d.ts +11 -13
- package/dist/creator/register.d.ts.map +1 -1
- package/dist/creator/register.js +21 -30
- package/dist/creator/register.js.map +1 -1
- package/dist/creator/serve.d.ts.map +1 -1
- package/dist/creator/serve.js +30 -31
- package/dist/creator/serve.js.map +1 -1
- package/dist/creator/types.d.ts +9 -4
- package/dist/creator/types.d.ts.map +1 -1
- package/dist/creator/utils/wallet.d.ts +18 -0
- package/dist/creator/utils/wallet.d.ts.map +1 -1
- package/dist/creator/utils/wallet.js +40 -0
- package/dist/creator/utils/wallet.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ SDK for discovering and calling paid AI skills with automatic x402 crypto paymen
|
|
|
10
10
|
- **Discover skills** - Search and explore the Skillz Market registry
|
|
11
11
|
- **Automatic payments** - x402 protocol handles USDC payments seamlessly
|
|
12
12
|
- **Create skills** - Monetize your AI services with zero crypto knowledge
|
|
13
|
+
- **Simple auth** - API key authentication (no wallet signing on each start)
|
|
13
14
|
- **Type-safe** - Full TypeScript support with comprehensive types
|
|
14
15
|
- **Base network** - Fast, low-cost transactions on Base mainnet
|
|
15
16
|
|
|
@@ -23,22 +24,44 @@ pnpm add @skillzmarket/sdk viem
|
|
|
23
24
|
|
|
24
25
|
## Quick Start
|
|
25
26
|
|
|
26
|
-
###
|
|
27
|
+
### Creator: Monetize Your Skills
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
import { SkillzMarket } from '@skillzmarket/sdk';
|
|
29
|
+
The fastest way to get started is with the interactive setup:
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npx @skillzmarket/sdk init
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
This will:
|
|
36
|
+
1. Guide you through getting an API key from the dashboard
|
|
37
|
+
2. Configure your wallet address for receiving payments
|
|
38
|
+
3. Save configuration to `.env`
|
|
39
|
+
|
|
40
|
+
Then create your skills:
|
|
36
41
|
|
|
37
42
|
```typescript
|
|
38
43
|
import { skill, serve } from '@skillzmarket/sdk/creator';
|
|
39
44
|
|
|
40
|
-
const echo = skill({
|
|
41
|
-
|
|
45
|
+
const echo = skill({
|
|
46
|
+
price: '$0.001',
|
|
47
|
+
description: 'Echoes input back',
|
|
48
|
+
}, async (input) => ({ echo: input }));
|
|
49
|
+
|
|
50
|
+
serve({ echo }, {
|
|
51
|
+
register: {
|
|
52
|
+
endpoint: 'https://your-server.com',
|
|
53
|
+
enabled: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Consumer: Call Paid Skills
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { SkillzMarket } from '@skillzmarket/sdk';
|
|
62
|
+
|
|
63
|
+
const market = new SkillzMarket({ wallet: '0x...' });
|
|
64
|
+
const result = await market.call('text-to-image', { prompt: 'A sunset' });
|
|
42
65
|
```
|
|
43
66
|
|
|
44
67
|
## Documentation
|
|
@@ -145,6 +168,37 @@ Payments use the [x402 protocol](https://x402.org):
|
|
|
145
168
|
|
|
146
169
|
The creator API lets you monetize your AI skills.
|
|
147
170
|
|
|
171
|
+
### Getting Started
|
|
172
|
+
|
|
173
|
+
#### 1. Interactive Setup (Recommended)
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
npx @skillzmarket/sdk init
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
This guides you through:
|
|
180
|
+
- Getting an API key from [skillz.market/dashboard](https://skillz.market/dashboard)
|
|
181
|
+
- Configuring your wallet address
|
|
182
|
+
- Saving to `.env`
|
|
183
|
+
|
|
184
|
+
#### 2. Manual Setup
|
|
185
|
+
|
|
186
|
+
Set environment variables:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
export SKILLZ_API_KEY="sk_..." # API key from dashboard
|
|
190
|
+
export SKILLZ_WALLET_ADDRESS="0x..." # Your wallet address
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Or pass them directly:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
serve({ echo }, {
|
|
197
|
+
apiKey: 'sk_...',
|
|
198
|
+
wallet: '0x...',
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
148
202
|
### Functions
|
|
149
203
|
|
|
150
204
|
| Function | Description |
|
|
@@ -152,6 +206,8 @@ The creator API lets you monetize your AI skills.
|
|
|
152
206
|
| `skill(options, handler)` | Define a monetized skill |
|
|
153
207
|
| `serve(skills, options?)` | Start the skill server |
|
|
154
208
|
| `register(skills, options)` | Register skills with marketplace |
|
|
209
|
+
| `init()` | Interactive CLI setup |
|
|
210
|
+
| `checkConfig()` | Validate SDK configuration |
|
|
155
211
|
|
|
156
212
|
### Example
|
|
157
213
|
|
|
@@ -189,6 +245,45 @@ serve({ summarize, translate }, {
|
|
|
189
245
|
});
|
|
190
246
|
```
|
|
191
247
|
|
|
248
|
+
### Configuration Helpers
|
|
249
|
+
|
|
250
|
+
#### init()
|
|
251
|
+
|
|
252
|
+
Interactive CLI setup that guides you through configuration:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { init } from '@skillzmarket/sdk/creator';
|
|
256
|
+
|
|
257
|
+
await init();
|
|
258
|
+
// Prompts for API key, wallet address, saves to .env
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Or run directly:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
npx @skillzmarket/sdk init
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### checkConfig()
|
|
268
|
+
|
|
269
|
+
Validate that required configuration is present:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { checkConfig } from '@skillzmarket/sdk/creator';
|
|
273
|
+
|
|
274
|
+
const config = checkConfig();
|
|
275
|
+
|
|
276
|
+
if (!config.configured) {
|
|
277
|
+
console.error('Configuration issues:');
|
|
278
|
+
config.issues.forEach(issue => console.error(` - ${issue}`));
|
|
279
|
+
process.exit(1);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// config.apiKey - boolean, true if SKILLZ_API_KEY is valid
|
|
283
|
+
// config.walletAddress - boolean, true if wallet is configured
|
|
284
|
+
// config.issues - string[], list of configuration problems
|
|
285
|
+
```
|
|
286
|
+
|
|
192
287
|
### Price Formats
|
|
193
288
|
|
|
194
289
|
Creators can specify prices in multiple formats:
|
|
@@ -216,7 +311,10 @@ interface SkillOptions {
|
|
|
216
311
|
```typescript
|
|
217
312
|
interface ServeOptions {
|
|
218
313
|
port?: number; // Port to listen on (default: 3002)
|
|
219
|
-
wallet?:
|
|
314
|
+
wallet?: string; // Wallet address (42-char) or private key (66-char)
|
|
315
|
+
// Falls back to SKILLZ_WALLET_ADDRESS or SKILLZ_WALLET_KEY env
|
|
316
|
+
apiKey?: string; // API key for registration
|
|
317
|
+
// Falls back to SKILLZ_API_KEY env
|
|
220
318
|
network?: string; // Network (default: 'eip155:8453')
|
|
221
319
|
register?: {
|
|
222
320
|
endpoint: string; // Your public server URL
|
|
@@ -230,13 +328,30 @@ interface ServeOptions {
|
|
|
230
328
|
|
|
231
329
|
---
|
|
232
330
|
|
|
331
|
+
## Authentication Flow
|
|
332
|
+
|
|
333
|
+
The SDK uses API key authentication for skill registration:
|
|
334
|
+
|
|
335
|
+
1. **One-time setup**: Sign with your wallet on [skillz.market/dashboard](https://skillz.market/dashboard) to create your account
|
|
336
|
+
2. **Get API key**: Create an API key in the dashboard's "API Keys" section
|
|
337
|
+
3. **Use in SDK**: The API key authenticates registration requests - no signing required
|
|
338
|
+
|
|
339
|
+
Benefits over wallet signing on every start:
|
|
340
|
+
- No private key needed in your skill server
|
|
341
|
+
- Can rotate/revoke keys without changing wallet
|
|
342
|
+
- Same security (wallet verified at account creation)
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
233
346
|
## Environment Variables
|
|
234
347
|
|
|
235
348
|
| Variable | Description | Required |
|
|
236
349
|
|----------|-------------|----------|
|
|
237
|
-
| `
|
|
350
|
+
| `SKILLZ_API_KEY` | API key for registration | Yes (creator) |
|
|
351
|
+
| `SKILLZ_WALLET_ADDRESS` | Wallet address for receiving payments | Yes (creator) |
|
|
352
|
+
| `SKILLZ_WALLET_KEY` | Private key (legacy, address is derived) | No* |
|
|
238
353
|
|
|
239
|
-
|
|
354
|
+
*`SKILLZ_WALLET_KEY` is supported for backwards compatibility but `SKILLZ_WALLET_ADDRESS` is preferred since you don't need the private key for serving skills.
|
|
240
355
|
|
|
241
356
|
## Security Considerations
|
|
242
357
|
|
|
@@ -246,9 +361,16 @@ All API URLs must use HTTPS. The SDK rejects HTTP URLs (except localhost for dev
|
|
|
246
361
|
|
|
247
362
|
### Wallet Security
|
|
248
363
|
|
|
249
|
-
|
|
250
|
-
-
|
|
251
|
-
-
|
|
364
|
+
With API key authentication, your skill server only needs a wallet **address** (not private key) for receiving payments. The private key is only used when:
|
|
365
|
+
- Creating your account (one-time signature in dashboard)
|
|
366
|
+
- Making payments as a consumer
|
|
367
|
+
|
|
368
|
+
### API Key Security
|
|
369
|
+
|
|
370
|
+
- Store API keys securely (environment variables, secrets manager)
|
|
371
|
+
- Never commit API keys to source control
|
|
372
|
+
- Rotate keys if compromised via the dashboard
|
|
373
|
+
- Use separate keys for development/production
|
|
252
374
|
|
|
253
375
|
### Error Handling
|
|
254
376
|
|
|
@@ -299,6 +421,13 @@ interface ParsedPrice {
|
|
|
299
421
|
amount: string;
|
|
300
422
|
currency: 'USDC';
|
|
301
423
|
}
|
|
424
|
+
|
|
425
|
+
interface RegistrationResult {
|
|
426
|
+
name: string;
|
|
427
|
+
success: boolean;
|
|
428
|
+
slug?: string;
|
|
429
|
+
error?: string;
|
|
430
|
+
}
|
|
302
431
|
```
|
|
303
432
|
|
|
304
433
|
---
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/bin/init.ts"],"names":[],"mappings":""}
|
package/dist/bin/init.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/bin/init.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/creator/index.d.ts
CHANGED
|
@@ -20,10 +20,11 @@ export { skill } from './skill.js';
|
|
|
20
20
|
export { serve } from './serve.js';
|
|
21
21
|
export { register } from './register.js';
|
|
22
22
|
export type { RegisterOptions } from './register.js';
|
|
23
|
+
export { init, checkConfig } from './init.js';
|
|
23
24
|
export { authenticate, refreshAccessToken } from './auth.js';
|
|
24
25
|
export type { AuthResult, RefreshResult } from './auth.js';
|
|
25
26
|
export type { SkillOptions, SkillHandler, SkillDefinition, SkillsMap, ServeOptions, ParsedPrice, JsonSchema, RegistrationOptions, RegistrationResult, } from './types.js';
|
|
26
27
|
export { parsePrice, formatPriceForX402 } from './utils/price.js';
|
|
27
|
-
export { resolveWallet, maskPrivateKey, verifyWalletMatch } from './utils/wallet.js';
|
|
28
|
+
export { resolveWalletToAddress, resolveWallet, maskPrivateKey, verifyWalletMatch } from './utils/wallet.js';
|
|
28
29
|
export type { WalletConfig } from './utils/wallet.js';
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/creator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG3D,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/creator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG3D,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/creator/index.js
CHANGED
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
export { skill } from './skill.js';
|
|
20
20
|
export { serve } from './serve.js';
|
|
21
21
|
export { register } from './register.js';
|
|
22
|
+
export { init, checkConfig } from './init.js';
|
|
22
23
|
export { authenticate, refreshAccessToken } from './auth.js';
|
|
23
24
|
// Re-export utilities for advanced usage
|
|
24
25
|
export { parsePrice, formatPriceForX402 } from './utils/price.js';
|
|
25
|
-
export { resolveWallet, maskPrivateKey, verifyWalletMatch } from './utils/wallet.js';
|
|
26
|
+
export { resolveWalletToAddress, resolveWallet, maskPrivateKey, verifyWalletMatch } from './utils/wallet.js';
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/creator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAgB7D,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/creator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAgB7D,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive setup for Skillz Market SDK.
|
|
3
|
+
* Guides the user through getting and configuring their API key.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { init } from '@skillzmarket/sdk/creator';
|
|
8
|
+
*
|
|
9
|
+
* // Run interactive setup
|
|
10
|
+
* await init();
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function init(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if the SDK is configured with necessary credentials.
|
|
16
|
+
* Returns an object with configuration status and any issues found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkConfig(): {
|
|
19
|
+
configured: boolean;
|
|
20
|
+
apiKey: boolean;
|
|
21
|
+
walletAddress: boolean;
|
|
22
|
+
issues: string[];
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/creator/init.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAiN1C;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAwBA"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as readline from 'readline';
|
|
4
|
+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
5
|
+
const DASHBOARD_URL = 'https://skillz.market/dashboard';
|
|
6
|
+
/**
|
|
7
|
+
* Interactive setup for Skillz Market SDK.
|
|
8
|
+
* Guides the user through getting and configuring their API key.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { init } from '@skillzmarket/sdk/creator';
|
|
13
|
+
*
|
|
14
|
+
* // Run interactive setup
|
|
15
|
+
* await init();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export async function init() {
|
|
19
|
+
const rl = readline.createInterface({
|
|
20
|
+
input: process.stdin,
|
|
21
|
+
output: process.stdout,
|
|
22
|
+
});
|
|
23
|
+
const question = (prompt) => {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
rl.question(prompt, (answer) => {
|
|
26
|
+
resolve(answer.trim());
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
console.log('');
|
|
31
|
+
console.log('='.repeat(60));
|
|
32
|
+
console.log(' Skillz Market SDK - Setup');
|
|
33
|
+
console.log('='.repeat(60));
|
|
34
|
+
console.log('');
|
|
35
|
+
// Check for existing API key
|
|
36
|
+
const existingKey = process.env.SKILLZ_API_KEY;
|
|
37
|
+
if (existingKey) {
|
|
38
|
+
console.log('✓ Found existing API key in environment: SKILLZ_API_KEY');
|
|
39
|
+
console.log(` Key prefix: ${existingKey.slice(0, 11)}...`);
|
|
40
|
+
console.log('');
|
|
41
|
+
const overwrite = await question('Do you want to set up a new key? (y/N): ');
|
|
42
|
+
if (overwrite.toLowerCase() !== 'y') {
|
|
43
|
+
console.log('');
|
|
44
|
+
console.log('Setup complete! Your existing API key will be used.');
|
|
45
|
+
rl.close();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log('');
|
|
49
|
+
}
|
|
50
|
+
// Instructions for getting an API key
|
|
51
|
+
console.log('To register skills, you need an API key from Skillz Market.');
|
|
52
|
+
console.log('');
|
|
53
|
+
console.log('Steps to get your API key:');
|
|
54
|
+
console.log('');
|
|
55
|
+
console.log(' 1. Go to: ' + DASHBOARD_URL);
|
|
56
|
+
console.log(' 2. Connect your wallet');
|
|
57
|
+
console.log(' 3. Sign to authenticate (one-time)');
|
|
58
|
+
console.log(' 4. Find the "API Keys" section');
|
|
59
|
+
console.log(' 5. Click "Create Key" and copy the key');
|
|
60
|
+
console.log('');
|
|
61
|
+
// Wait for user to get the key
|
|
62
|
+
const apiKey = await question('Paste your API key here (sk_...): ');
|
|
63
|
+
if (!apiKey) {
|
|
64
|
+
console.log('');
|
|
65
|
+
console.log('No API key provided. Setup cancelled.');
|
|
66
|
+
rl.close();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!apiKey.startsWith('sk_')) {
|
|
70
|
+
console.log('');
|
|
71
|
+
console.log('⚠️ Warning: API keys should start with "sk_"');
|
|
72
|
+
console.log(' The key you entered might be invalid.');
|
|
73
|
+
console.log('');
|
|
74
|
+
}
|
|
75
|
+
// Ask about wallet setup
|
|
76
|
+
console.log('');
|
|
77
|
+
let walletAddress;
|
|
78
|
+
let generatedPrivateKey = null;
|
|
79
|
+
const hasWallet = await question('Do you have a wallet set up to receive payments? (y/N): ');
|
|
80
|
+
if (hasWallet.toLowerCase() === 'y') {
|
|
81
|
+
// User has existing wallet
|
|
82
|
+
const inputAddress = await question('Enter your wallet address (0x...): ');
|
|
83
|
+
if (!inputAddress) {
|
|
84
|
+
console.log('');
|
|
85
|
+
console.log('No wallet address provided. Setup cancelled.');
|
|
86
|
+
rl.close();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!inputAddress.startsWith('0x') || inputAddress.length !== 42) {
|
|
90
|
+
console.log('');
|
|
91
|
+
console.log('⚠️ Warning: Wallet address should be 42 characters starting with "0x"');
|
|
92
|
+
console.log('');
|
|
93
|
+
}
|
|
94
|
+
walletAddress = inputAddress;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// User doesn't have a wallet
|
|
98
|
+
console.log('');
|
|
99
|
+
const generateWallet = await question('Would you like to generate a new wallet? (y/N): ');
|
|
100
|
+
if (generateWallet.toLowerCase() !== 'y') {
|
|
101
|
+
console.log('');
|
|
102
|
+
console.log('You need a wallet to receive payments for your skills.');
|
|
103
|
+
console.log('Run this setup again when you have a wallet ready.');
|
|
104
|
+
rl.close();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Generate new wallet
|
|
108
|
+
generatedPrivateKey = generatePrivateKey();
|
|
109
|
+
const account = privateKeyToAccount(generatedPrivateKey);
|
|
110
|
+
walletAddress = account.address;
|
|
111
|
+
console.log('');
|
|
112
|
+
console.log('╔════════════════════════════════════════════════════════════════╗');
|
|
113
|
+
console.log('║ ⚠️ IMPORTANT: SAVE YOUR PRIVATE KEY NOW! ║');
|
|
114
|
+
console.log('║ ║');
|
|
115
|
+
console.log('║ You will NOT be able to retrieve it later. ║');
|
|
116
|
+
console.log('║ Store it securely (password manager, hardware wallet). ║');
|
|
117
|
+
console.log('╚════════════════════════════════════════════════════════════════╝');
|
|
118
|
+
console.log('');
|
|
119
|
+
console.log(` Private Key: ${generatedPrivateKey}`);
|
|
120
|
+
console.log(` Wallet Address: ${walletAddress}`);
|
|
121
|
+
console.log('');
|
|
122
|
+
await question('Press Enter once you have saved your private key...');
|
|
123
|
+
}
|
|
124
|
+
// Ask where to save
|
|
125
|
+
console.log('');
|
|
126
|
+
console.log('Where would you like to save the configuration?');
|
|
127
|
+
console.log('');
|
|
128
|
+
console.log(' 1. Create/update .env file (recommended)');
|
|
129
|
+
console.log(' 2. Show commands to set environment variables');
|
|
130
|
+
console.log(' 3. Cancel');
|
|
131
|
+
console.log('');
|
|
132
|
+
const choice = await question('Choose an option (1/2/3): ');
|
|
133
|
+
console.log('');
|
|
134
|
+
if (choice === '1') {
|
|
135
|
+
// Write to .env file
|
|
136
|
+
const envPath = path.resolve(process.cwd(), '.env');
|
|
137
|
+
let envContent = '';
|
|
138
|
+
// Read existing .env if it exists
|
|
139
|
+
if (fs.existsSync(envPath)) {
|
|
140
|
+
envContent = fs.readFileSync(envPath, 'utf-8');
|
|
141
|
+
// Remove existing SKILLZ_ variables
|
|
142
|
+
envContent = envContent
|
|
143
|
+
.split('\n')
|
|
144
|
+
.filter((line) => !line.startsWith('SKILLZ_API_KEY=') &&
|
|
145
|
+
!line.startsWith('SKILLZ_WALLET_ADDRESS=') &&
|
|
146
|
+
!line.startsWith('SKILLZ_WALLET_KEY='))
|
|
147
|
+
.join('\n');
|
|
148
|
+
if (envContent && !envContent.endsWith('\n')) {
|
|
149
|
+
envContent += '\n';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Add new variables
|
|
153
|
+
envContent += `\n# Skillz Market SDK Configuration\n`;
|
|
154
|
+
envContent += `SKILLZ_API_KEY=${apiKey}\n`;
|
|
155
|
+
envContent += `SKILLZ_WALLET_ADDRESS=${walletAddress}\n`;
|
|
156
|
+
if (generatedPrivateKey) {
|
|
157
|
+
envContent += `SKILLZ_WALLET_KEY=${generatedPrivateKey}\n`;
|
|
158
|
+
}
|
|
159
|
+
fs.writeFileSync(envPath, envContent);
|
|
160
|
+
console.log('✓ Configuration saved to .env');
|
|
161
|
+
console.log('');
|
|
162
|
+
console.log('Make sure .env is in your .gitignore!');
|
|
163
|
+
}
|
|
164
|
+
else if (choice === '2') {
|
|
165
|
+
console.log('Add these to your environment:');
|
|
166
|
+
console.log('');
|
|
167
|
+
console.log(` export SKILLZ_API_KEY="${apiKey}"`);
|
|
168
|
+
console.log(` export SKILLZ_WALLET_ADDRESS="${walletAddress}"`);
|
|
169
|
+
if (generatedPrivateKey) {
|
|
170
|
+
console.log(` export SKILLZ_WALLET_KEY="${generatedPrivateKey}"`);
|
|
171
|
+
}
|
|
172
|
+
console.log('');
|
|
173
|
+
console.log('Or add to your shell profile (~/.bashrc, ~/.zshrc, etc.)');
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
console.log('Setup cancelled.');
|
|
177
|
+
rl.close();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
console.log('');
|
|
181
|
+
console.log('='.repeat(60));
|
|
182
|
+
console.log(' Setup Complete!');
|
|
183
|
+
console.log('='.repeat(60));
|
|
184
|
+
console.log('');
|
|
185
|
+
console.log('You can now use the SDK:');
|
|
186
|
+
console.log('');
|
|
187
|
+
console.log(' import { skill, serve } from "@skillzmarket/sdk/creator";');
|
|
188
|
+
console.log('');
|
|
189
|
+
console.log(' const mySkill = skill({ price: "$0.001" }, async (input) => {');
|
|
190
|
+
console.log(' return { result: "Hello!" };');
|
|
191
|
+
console.log(' });');
|
|
192
|
+
console.log('');
|
|
193
|
+
console.log(' serve({ mySkill }, {');
|
|
194
|
+
console.log(' register: { endpoint: "https://your-server.com", enabled: true }');
|
|
195
|
+
console.log(' });');
|
|
196
|
+
console.log('');
|
|
197
|
+
rl.close();
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Check if the SDK is configured with necessary credentials.
|
|
201
|
+
* Returns an object with configuration status and any issues found.
|
|
202
|
+
*/
|
|
203
|
+
export function checkConfig() {
|
|
204
|
+
const issues = [];
|
|
205
|
+
const apiKey = process.env.SKILLZ_API_KEY;
|
|
206
|
+
const walletAddress = process.env.SKILLZ_WALLET_ADDRESS || process.env.SKILLZ_WALLET_KEY;
|
|
207
|
+
if (!apiKey) {
|
|
208
|
+
issues.push('SKILLZ_API_KEY is not set. Run `npx @skillzmarket/sdk init` to configure.');
|
|
209
|
+
}
|
|
210
|
+
else if (!apiKey.startsWith('sk_')) {
|
|
211
|
+
issues.push('SKILLZ_API_KEY should start with "sk_"');
|
|
212
|
+
}
|
|
213
|
+
if (!walletAddress) {
|
|
214
|
+
issues.push('SKILLZ_WALLET_ADDRESS is not set. This is required for receiving payments.');
|
|
215
|
+
}
|
|
216
|
+
else if (!walletAddress.startsWith('0x')) {
|
|
217
|
+
issues.push('Wallet address should start with "0x"');
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
configured: issues.length === 0,
|
|
221
|
+
apiKey: !!apiKey && apiKey.startsWith('sk_'),
|
|
222
|
+
walletAddress: !!walletAddress && walletAddress.startsWith('0x'),
|
|
223
|
+
issues,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/creator/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAExE,MAAM,aAAa,GAAG,iCAAiC,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,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CAAC,CAAC,aAAa,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC;QAChE,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import type { PrivateKeyAccount } from 'viem/accounts';
|
|
2
1
|
import type { Address } from 'viem';
|
|
3
2
|
import type { SkillsMap, RegistrationResult, RegistrationOptions } from './types.js';
|
|
4
3
|
export interface RegisterOptions {
|
|
5
|
-
|
|
4
|
+
/** API key for authentication */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** Payment address to receive skill payments */
|
|
7
|
+
paymentAddress: Address;
|
|
8
|
+
/** Public endpoint URL where skills are accessible */
|
|
6
9
|
endpoint: string;
|
|
10
|
+
/** API URL for the Skillz Market registry */
|
|
7
11
|
apiUrl?: string;
|
|
12
|
+
/** Error handling mode */
|
|
8
13
|
onError?: 'throw' | 'warn' | 'silent';
|
|
9
|
-
/**
|
|
10
|
-
* Optional expected payment address for verification.
|
|
11
|
-
* If provided, registration will fail if the account address
|
|
12
|
-
* doesn't match this expected address.
|
|
13
|
-
*/
|
|
14
|
-
expectedPaymentAddress?: Address;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
|
-
* Register skills with the Skillz Market registry.
|
|
16
|
+
* Register skills with the Skillz Market registry using API key authentication.
|
|
18
17
|
*
|
|
19
18
|
* @example
|
|
20
19
|
* ```typescript
|
|
21
20
|
* import { skill, register } from '@skillzmarket/sdk/creator';
|
|
22
|
-
* import { privateKeyToAccount } from 'viem/accounts';
|
|
23
21
|
*
|
|
24
22
|
* const echo = skill({ price: '$0.001' }, async (input) => ({ echo: input }));
|
|
25
23
|
*
|
|
26
|
-
* const account = privateKeyToAccount('0x...');
|
|
27
24
|
* const results = await register({ echo }, {
|
|
28
|
-
*
|
|
25
|
+
* apiKey: 'sk_abc123...', // or process.env.SKILLZ_API_KEY
|
|
26
|
+
* paymentAddress: '0x4554A88d9e4D1bef5338F65A3Cd335C6A27E5368',
|
|
29
27
|
* endpoint: 'https://my-skills.example.com',
|
|
30
28
|
* });
|
|
31
29
|
* ```
|
|
@@ -38,5 +36,5 @@ export declare function register(skills: SkillsMap, options: RegisterOptions): P
|
|
|
38
36
|
/**
|
|
39
37
|
* Build registration options from ServeOptions.register
|
|
40
38
|
*/
|
|
41
|
-
export declare function buildRegisterOptions(registerOpts: RegistrationOptions,
|
|
39
|
+
export declare function buildRegisterOptions(registerOpts: RegistrationOptions, apiKey: string, paymentAddress: Address): RegisterOptions;
|
|
42
40
|
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/creator/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/creator/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAMrF,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,cAAc,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;CACvC;AA0BD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAyC/B;AAoHD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,OAAO,GACtB,eAAe,CAQjB"}
|
package/dist/creator/register.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { authenticate, authenticatedFetch } from './auth.js';
|
|
2
1
|
const DEFAULT_API_URL = 'https://api.skillz.market';
|
|
3
2
|
const MAX_RETRIES = 3;
|
|
4
3
|
const BASE_DELAY_MS = 1000;
|
|
@@ -15,18 +14,17 @@ function getBackoffDelay(attempt) {
|
|
|
15
14
|
return BASE_DELAY_MS * Math.pow(2, attempt);
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
|
-
* Register skills with the Skillz Market registry.
|
|
17
|
+
* Register skills with the Skillz Market registry using API key authentication.
|
|
19
18
|
*
|
|
20
19
|
* @example
|
|
21
20
|
* ```typescript
|
|
22
21
|
* import { skill, register } from '@skillzmarket/sdk/creator';
|
|
23
|
-
* import { privateKeyToAccount } from 'viem/accounts';
|
|
24
22
|
*
|
|
25
23
|
* const echo = skill({ price: '$0.001' }, async (input) => ({ echo: input }));
|
|
26
24
|
*
|
|
27
|
-
* const account = privateKeyToAccount('0x...');
|
|
28
25
|
* const results = await register({ echo }, {
|
|
29
|
-
*
|
|
26
|
+
* apiKey: 'sk_abc123...', // or process.env.SKILLZ_API_KEY
|
|
27
|
+
* paymentAddress: '0x4554A88d9e4D1bef5338F65A3Cd335C6A27E5368',
|
|
30
28
|
* endpoint: 'https://my-skills.example.com',
|
|
31
29
|
* });
|
|
32
30
|
* ```
|
|
@@ -36,32 +34,20 @@ function getBackoffDelay(attempt) {
|
|
|
36
34
|
* @returns Array of registration results for each skill
|
|
37
35
|
*/
|
|
38
36
|
export async function register(skills, options) {
|
|
39
|
-
const {
|
|
37
|
+
const { apiKey, paymentAddress, endpoint, apiUrl = DEFAULT_API_URL, onError = 'warn' } = options;
|
|
40
38
|
const skillNames = Object.keys(skills);
|
|
41
39
|
if (skillNames.length === 0) {
|
|
42
40
|
return [];
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return handleRegistrationError(message, skillNames, onError);
|
|
51
|
-
}
|
|
42
|
+
if (!apiKey) {
|
|
43
|
+
const message = 'API key required for registration. Either:\n' +
|
|
44
|
+
'1. Pass `apiKey` option to serve()\n' +
|
|
45
|
+
'2. Set SKILLZ_API_KEY environment variable\n\n' +
|
|
46
|
+
'Get an API key from https://skillz.market/dashboard';
|
|
47
|
+
return handleRegistrationError(message, skillNames, onError);
|
|
52
48
|
}
|
|
53
49
|
// Normalize endpoint (remove trailing slash)
|
|
54
50
|
const normalizedEndpoint = endpoint.replace(/\/$/, '');
|
|
55
|
-
// Authenticate with the API
|
|
56
|
-
let token;
|
|
57
|
-
try {
|
|
58
|
-
const authResult = await authenticate(account, { apiUrl });
|
|
59
|
-
token = authResult.token;
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
const message = `Failed to authenticate for registration: ${error instanceof Error ? error.message : String(error)}`;
|
|
63
|
-
return handleRegistrationError(message, skillNames, onError);
|
|
64
|
-
}
|
|
65
51
|
// Register each skill
|
|
66
52
|
const results = [];
|
|
67
53
|
for (const [name, definition] of Object.entries(skills)) {
|
|
@@ -70,12 +56,12 @@ export async function register(skills, options) {
|
|
|
70
56
|
name,
|
|
71
57
|
endpoint: skillEndpoint,
|
|
72
58
|
price: definition.parsedPrice.amount,
|
|
73
|
-
paymentAddress
|
|
59
|
+
paymentAddress,
|
|
74
60
|
description: definition.options.description,
|
|
75
61
|
inputSchema: definition.options.inputSchema,
|
|
76
62
|
outputSchema: definition.options.outputSchema,
|
|
77
63
|
};
|
|
78
|
-
const result = await registerSkillWithRetry(name, payload,
|
|
64
|
+
const result = await registerSkillWithRetry(name, payload, apiKey, apiUrl, onError);
|
|
79
65
|
results.push(result);
|
|
80
66
|
}
|
|
81
67
|
return results;
|
|
@@ -83,12 +69,16 @@ export async function register(skills, options) {
|
|
|
83
69
|
/**
|
|
84
70
|
* Register a single skill with retry logic
|
|
85
71
|
*/
|
|
86
|
-
async function registerSkillWithRetry(name, payload,
|
|
72
|
+
async function registerSkillWithRetry(name, payload, apiKey, apiUrl, onError) {
|
|
87
73
|
let lastError;
|
|
88
74
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
89
75
|
try {
|
|
90
|
-
const response = await
|
|
76
|
+
const response = await fetch(`${apiUrl}/skills`, {
|
|
91
77
|
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
81
|
+
},
|
|
92
82
|
body: JSON.stringify(payload),
|
|
93
83
|
});
|
|
94
84
|
if (response.ok) {
|
|
@@ -163,9 +153,10 @@ function handleRegistrationError(message, skillNames, onError) {
|
|
|
163
153
|
/**
|
|
164
154
|
* Build registration options from ServeOptions.register
|
|
165
155
|
*/
|
|
166
|
-
export function buildRegisterOptions(registerOpts,
|
|
156
|
+
export function buildRegisterOptions(registerOpts, apiKey, paymentAddress) {
|
|
167
157
|
return {
|
|
168
|
-
|
|
158
|
+
apiKey,
|
|
159
|
+
paymentAddress,
|
|
169
160
|
endpoint: registerOpts.endpoint,
|
|
170
161
|
apiUrl: registerOpts.apiUrl,
|
|
171
162
|
onError: registerOpts.onError,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/creator/register.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/creator/register.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACpD,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,aAAa,GAAG,IAAI,CAAC;AAyB3B;;GAEG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC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AAC,IAAI,CAAC,iCAAiC,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;KACf,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAC9B,OAAe,EACf,UAAoB,EACpB,OAAoC;IAEpC,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/B,IAAI;QACJ,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;KACf,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,YAAiC,EACjC,MAAc,EACd,cAAuB;IAEvB,OAAO;QACL,MAAM;QACN,cAAc;QACd,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,OAAO,EAAE,YAAY,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/creator/serve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/creator/serve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAW1D;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,KAAK,CACzB,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAuLf"}
|
package/dist/creator/serve.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
import { cors } from 'hono/cors';
|
|
3
3
|
import { serve as honoServe } from '@hono/node-server';
|
|
4
|
-
import {
|
|
4
|
+
import { resolveWalletToAddress } from './utils/wallet.js';
|
|
5
5
|
import { createPaymentMiddleware } from './payment.js';
|
|
6
6
|
import { register, buildRegisterOptions } from './register.js';
|
|
7
7
|
const DEFAULT_PORT = 3002;
|
|
@@ -26,24 +26,16 @@ const DEFAULT_API_URL = 'https://api.skillz.market';
|
|
|
26
26
|
* @param options - Server configuration options
|
|
27
27
|
*/
|
|
28
28
|
export async function serve(skills, options = {}) {
|
|
29
|
-
const { port = DEFAULT_PORT, wallet, network = DEFAULT_NETWORK, facilitatorUrl = DEFAULT_FACILITATOR_URL, appName = DEFAULT_APP_NAME, onCall, onError, register: registerOpts, trackCalls = true, apiUrl = DEFAULT_API_URL, } = options;
|
|
29
|
+
const { port = DEFAULT_PORT, wallet, apiKey, network = DEFAULT_NETWORK, facilitatorUrl = DEFAULT_FACILITATOR_URL, appName = DEFAULT_APP_NAME, onCall, onError, register: registerOpts, trackCalls = true, apiUrl = DEFAULT_API_URL, } = options;
|
|
30
30
|
// Validate skills
|
|
31
31
|
const skillNames = Object.keys(skills);
|
|
32
32
|
if (skillNames.length === 0) {
|
|
33
33
|
throw new Error('No skills provided. Pass at least one skill to serve().');
|
|
34
34
|
}
|
|
35
|
-
// Resolve wallet
|
|
36
|
-
const
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
const registerAccount = buildRegisterOptions(registerOpts, account).account;
|
|
40
|
-
const verification = verifyWalletMatch(registerAccount, walletAddress);
|
|
41
|
-
if (!verification.match) {
|
|
42
|
-
throw new Error(`Wallet mismatch: serve wallet (${verification.address2}) differs from ` +
|
|
43
|
-
`registration wallet (${verification.address1}). ` +
|
|
44
|
-
`Use the same wallet for both to ensure payments are received correctly.`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
35
|
+
// Resolve wallet to address (no private key needed now!)
|
|
36
|
+
const walletAddress = resolveWalletToAddress(wallet);
|
|
37
|
+
// Resolve API key
|
|
38
|
+
const resolvedApiKey = apiKey ?? process.env.SKILLZ_API_KEY ?? '';
|
|
47
39
|
// Create Hono app
|
|
48
40
|
const app = new Hono();
|
|
49
41
|
// Enable CORS
|
|
@@ -144,26 +136,33 @@ export async function serve(skills, options = {}) {
|
|
|
144
136
|
console.log('');
|
|
145
137
|
// Auto-register skills if registration is configured
|
|
146
138
|
if (registerOpts && registerOpts.enabled !== false) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const results = await register(skills, registerOptions);
|
|
151
|
-
// Log registration results
|
|
152
|
-
const successful = results.filter((r) => r.success);
|
|
153
|
-
const failed = results.filter((r) => !r.success);
|
|
154
|
-
if (successful.length > 0) {
|
|
155
|
-
console.log(' ✓ Registered skills:');
|
|
156
|
-
for (const result of successful) {
|
|
157
|
-
console.log(` - ${result.name} (${result.slug})`);
|
|
158
|
-
}
|
|
139
|
+
if (!resolvedApiKey) {
|
|
140
|
+
console.warn(' ⚠️ No API key provided. Skills will not be registered.');
|
|
141
|
+
console.warn(' Get an API key from https://skillz.market/dashboard');
|
|
159
142
|
console.log('');
|
|
160
143
|
}
|
|
161
|
-
|
|
162
|
-
console.log('
|
|
163
|
-
for (const result of failed) {
|
|
164
|
-
console.log(` - ${result.name}: ${result.error}`);
|
|
165
|
-
}
|
|
144
|
+
else {
|
|
145
|
+
console.log(' Registering skills with Skillz Market...');
|
|
166
146
|
console.log('');
|
|
147
|
+
const registerOptions = buildRegisterOptions(registerOpts, resolvedApiKey, walletAddress);
|
|
148
|
+
const results = await register(skills, registerOptions);
|
|
149
|
+
// Log registration results
|
|
150
|
+
const successful = results.filter((r) => r.success);
|
|
151
|
+
const failed = results.filter((r) => !r.success);
|
|
152
|
+
if (successful.length > 0) {
|
|
153
|
+
console.log(' ✓ Registered skills:');
|
|
154
|
+
for (const result of successful) {
|
|
155
|
+
console.log(` - ${result.name} (${result.slug})`);
|
|
156
|
+
}
|
|
157
|
+
console.log('');
|
|
158
|
+
}
|
|
159
|
+
if (failed.length > 0 && registerOpts.onError !== 'silent') {
|
|
160
|
+
console.log(' ✗ Failed to register:');
|
|
161
|
+
for (const result of failed) {
|
|
162
|
+
console.log(` - ${result.name}: ${result.error}`);
|
|
163
|
+
}
|
|
164
|
+
console.log('');
|
|
165
|
+
}
|
|
167
166
|
}
|
|
168
167
|
console.log('='.repeat(50));
|
|
169
168
|
console.log('');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/creator/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/creator/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,eAAe,GAAG,aAAsB,CAAC;AAC/C,MAAM,uBAAuB,GAAG,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dist/creator/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Hex } from 'viem';
|
|
2
1
|
/**
|
|
3
2
|
* JSON Schema type for describing skill input/output
|
|
4
3
|
*/
|
|
@@ -110,10 +109,16 @@ export interface ServeOptions {
|
|
|
110
109
|
*/
|
|
111
110
|
port?: number;
|
|
112
111
|
/**
|
|
113
|
-
* Wallet
|
|
114
|
-
*
|
|
112
|
+
* Wallet address for receiving payments.
|
|
113
|
+
* Accepts either a 42-char address or a 66-char private key (derives address).
|
|
114
|
+
* Falls back to SKILLZ_WALLET_ADDRESS or SKILLZ_WALLET_KEY environment variables.
|
|
115
115
|
*/
|
|
116
|
-
wallet?:
|
|
116
|
+
wallet?: string;
|
|
117
|
+
/**
|
|
118
|
+
* API key for registration. Get one from the Skillz Market dashboard.
|
|
119
|
+
* Falls back to SKILLZ_API_KEY environment variable.
|
|
120
|
+
*/
|
|
121
|
+
apiKey?: string;
|
|
117
122
|
/**
|
|
118
123
|
* Network identifier for x402 payments.
|
|
119
124
|
* Default: 'eip155:8453' (Base mainnet)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/creator/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/creator/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,WAAW,CAAC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olved to an address
|
|
5
5
|
*/
|
|
6
6
|
export type WalletConfig = Hex | PrivateKeyAccount;
|
|
7
|
+
/**
|
|
8
|
+
* Resolve wallet input to an address.
|
|
9
|
+
* Accepts either a 42-char address or 66-char private key.
|
|
10
|
+
*
|
|
11
|
+
* Priority:
|
|
12
|
+
* 1. Explicit wallet option
|
|
13
|
+
* 2. SKILLZ_WALLET_ADDRESS environment variable
|
|
14
|
+
* 3. SKILLZ_WALLET_KEY environment variable (derives address)
|
|
15
|
+
*
|
|
16
|
+
* @param wallet - Optional explicit wallet address or private key
|
|
17
|
+
* @returns The wallet address
|
|
18
|
+
* @throws Error if no wallet is configured or invalid format
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveWalletToAddress(wallet?: string): Address;
|
|
7
21
|
/**
|
|
8
22
|
* Resolve wallet configuration from options or environment.
|
|
23
|
+
* Returns a full account (with private key) for signing operations.
|
|
9
24
|
*
|
|
10
25
|
* Priority:
|
|
11
26
|
* 1. Explicit wallet option
|
|
12
27
|
* 2. SKILLZ_WALLET_KEY environment variable
|
|
13
28
|
*
|
|
29
|
+
* @deprecated Use resolveWalletToAddress when you only need the address.
|
|
30
|
+
* This function requires the private key and should only be used
|
|
31
|
+
* when signing is needed.
|
|
14
32
|
* @param wallet - Optional explicit wallet private key
|
|
15
33
|
* @returns Object with account and address
|
|
16
34
|
* @throws Error if no wallet is configured
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/creator/utils/wallet.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,GAAG,iBAAiB,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/creator/utils/wallet.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,GAAG,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CA+B/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG;IAC3C,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB,CA8BA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAK/C;AAYD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,YAAY,GAAG,OAAO,GAC9B;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAY1D"}
|
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve wallet input to an address.
|
|
4
|
+
* Accepts either a 42-char address or 66-char private key.
|
|
5
|
+
*
|
|
6
|
+
* Priority:
|
|
7
|
+
* 1. Explicit wallet option
|
|
8
|
+
* 2. SKILLZ_WALLET_ADDRESS environment variable
|
|
9
|
+
* 3. SKILLZ_WALLET_KEY environment variable (derives address)
|
|
10
|
+
*
|
|
11
|
+
* @param wallet - Optional explicit wallet address or private key
|
|
12
|
+
* @returns The wallet address
|
|
13
|
+
* @throws Error if no wallet is configured or invalid format
|
|
14
|
+
*/
|
|
15
|
+
export function resolveWalletToAddress(wallet) {
|
|
16
|
+
const input = wallet ?? process.env.SKILLZ_WALLET_ADDRESS ?? process.env.SKILLZ_WALLET_KEY;
|
|
17
|
+
if (!input) {
|
|
18
|
+
throw new Error('No wallet configured. Either:\n' +
|
|
19
|
+
'1. Pass `wallet` option with an address: serve({ skills }, { wallet: "0x..." })\n' +
|
|
20
|
+
'2. Set SKILLZ_WALLET_ADDRESS environment variable\n\n' +
|
|
21
|
+
'The wallet address receives payments from skill calls.');
|
|
22
|
+
}
|
|
23
|
+
if (!input.startsWith('0x')) {
|
|
24
|
+
throw new Error('Invalid wallet format. Must start with "0x"');
|
|
25
|
+
}
|
|
26
|
+
// 42 chars = address (0x + 40 hex chars)
|
|
27
|
+
if (input.length === 42) {
|
|
28
|
+
return input;
|
|
29
|
+
}
|
|
30
|
+
// 66 chars = private key (0x + 64 hex chars) - derive address
|
|
31
|
+
if (input.length === 66) {
|
|
32
|
+
return privateKeyToAccount(input).address;
|
|
33
|
+
}
|
|
34
|
+
throw new Error('Invalid wallet: must be 42-char address or 66-char private key.\n' +
|
|
35
|
+
'Address example: 0x4554A88d9e4D1bef5338F65A3Cd335C6A27E5368\n' +
|
|
36
|
+
'Private key example: 0x1234567890abcdef...');
|
|
37
|
+
}
|
|
2
38
|
/**
|
|
3
39
|
* Resolve wallet configuration from options or environment.
|
|
40
|
+
* Returns a full account (with private key) for signing operations.
|
|
4
41
|
*
|
|
5
42
|
* Priority:
|
|
6
43
|
* 1. Explicit wallet option
|
|
7
44
|
* 2. SKILLZ_WALLET_KEY environment variable
|
|
8
45
|
*
|
|
46
|
+
* @deprecated Use resolveWalletToAddress when you only need the address.
|
|
47
|
+
* This function requires the private key and should only be used
|
|
48
|
+
* when signing is needed.
|
|
9
49
|
* @param wallet - Optional explicit wallet private key
|
|
10
50
|
* @returns Object with account and address
|
|
11
51
|
* @throws Error if no wallet is configured
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/creator/utils/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M,KAAK,EAAE;QAClD,CAAC,CAAE,OAAmB;QACtB,CAAC,CAAC,oBAAoB,CAAC,OAAuB,CAAC,CAAC;IAEpD,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,WAAW,EAAE;QACxD,QAAQ;QACR,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillzmarket/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "SDK for discovering and calling paid AI skills with automatic x402 payments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"default": "./dist/creator/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"skillz-init": "./dist/bin/init.js"
|
|
23
|
+
},
|
|
21
24
|
"files": [
|
|
22
25
|
"dist",
|
|
23
26
|
"README.md",
|