@thyme-sh/sdk 0.2.0 → 0.3.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/dist/index.d.ts +87 -87
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/package.json +10 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,87 +1,24 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { PublicClient, Address, Hex } from 'viem';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
interface ThymeContext<TArgs> {
|
|
8
|
-
/** User-provided arguments validated against schema */
|
|
9
|
-
args: TArgs;
|
|
10
|
-
/** Viem public client for reading blockchain data */
|
|
11
|
-
client: PublicClient;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* A call to be executed on-chain
|
|
15
|
-
*/
|
|
16
|
-
interface Call {
|
|
17
|
-
/** Target contract address */
|
|
18
|
-
to: Address;
|
|
19
|
-
/** Encoded function call data */
|
|
20
|
-
data: Hex;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Result when task determines execution should proceed
|
|
24
|
-
*/
|
|
25
|
-
interface SuccessResult {
|
|
26
|
-
canExec: true;
|
|
27
|
-
/** Array of calls to execute on-chain */
|
|
28
|
-
calls: Call[];
|
|
4
|
+
interface CompressResult {
|
|
5
|
+
zipBuffer: Uint8Array;
|
|
6
|
+
checksum: string;
|
|
29
7
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
interface FailResult {
|
|
34
|
-
canExec: false;
|
|
35
|
-
/** Reason why execution should not proceed */
|
|
36
|
-
message: string;
|
|
8
|
+
interface DecompressResult {
|
|
9
|
+
source: string;
|
|
10
|
+
bundle: string;
|
|
37
11
|
}
|
|
38
12
|
/**
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
type TaskResult = SuccessResult | FailResult;
|
|
42
|
-
/**
|
|
43
|
-
* Task definition with schema and execution logic
|
|
13
|
+
* Compress source and bundle into a ZIP archive
|
|
14
|
+
* Uses fflate for fast, modern compression
|
|
44
15
|
*/
|
|
45
|
-
|
|
46
|
-
/** Zod schema for validating task arguments */
|
|
47
|
-
schema: TSchema;
|
|
48
|
-
/** Main execution function */
|
|
49
|
-
run: (ctx: ThymeContext<z.infer<TSchema>>) => Promise<TaskResult>;
|
|
50
|
-
}
|
|
51
|
-
|
|
16
|
+
declare function compressTask(source: string, bundle: string): CompressResult;
|
|
52
17
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* import { defineTask, z } from '@thyme-sh/sdk'
|
|
58
|
-
* import { encodeFunctionData } from 'viem'
|
|
59
|
-
*
|
|
60
|
-
* const abi = [
|
|
61
|
-
* 'function transfer(address to, uint256 amount) returns (bool)',
|
|
62
|
-
* ] as const
|
|
63
|
-
*
|
|
64
|
-
* export default defineTask({
|
|
65
|
-
* schema: z.object({
|
|
66
|
-
* targetAddress: z.address(),
|
|
67
|
-
* }),
|
|
68
|
-
* async run(ctx) {
|
|
69
|
-
* return {
|
|
70
|
-
* canExec: true,
|
|
71
|
-
* calls: [{
|
|
72
|
-
* to: ctx.args.targetAddress,
|
|
73
|
-
* data: encodeFunctionData({
|
|
74
|
-
* abi,
|
|
75
|
-
* functionName: 'transfer',
|
|
76
|
-
* args: [recipientAddress, 1000n],
|
|
77
|
-
* }),
|
|
78
|
-
* }]
|
|
79
|
-
* }
|
|
80
|
-
* }
|
|
81
|
-
* })
|
|
82
|
-
* ```
|
|
18
|
+
* Decompress ZIP archive and extract source and bundle files
|
|
19
|
+
* Uses fflate for fast decompression
|
|
83
20
|
*/
|
|
84
|
-
declare function
|
|
21
|
+
declare function decompressTask(zipBuffer: Uint8Array | ArrayBuffer): DecompressResult;
|
|
85
22
|
|
|
86
23
|
/**
|
|
87
24
|
* Extended Zod with Ethereum address validation
|
|
@@ -288,23 +225,86 @@ declare const zodExtended: {
|
|
|
288
225
|
*/
|
|
289
226
|
type InferSchema<T extends z.ZodType> = z.infer<T>;
|
|
290
227
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Context provided to task execution
|
|
230
|
+
*/
|
|
231
|
+
interface ThymeContext<TArgs> {
|
|
232
|
+
/** User-provided arguments validated against schema */
|
|
233
|
+
args: TArgs;
|
|
234
|
+
/** Viem public client for reading blockchain data */
|
|
235
|
+
client: PublicClient;
|
|
294
236
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
237
|
+
/**
|
|
238
|
+
* A call to be executed on-chain
|
|
239
|
+
*/
|
|
240
|
+
interface Call {
|
|
241
|
+
/** Target contract address */
|
|
242
|
+
to: Address;
|
|
243
|
+
/** Encoded function call data */
|
|
244
|
+
data: Hex;
|
|
298
245
|
}
|
|
299
246
|
/**
|
|
300
|
-
*
|
|
301
|
-
* Uses fflate for fast, modern compression
|
|
247
|
+
* Result when task determines execution should proceed
|
|
302
248
|
*/
|
|
303
|
-
|
|
249
|
+
interface SuccessResult {
|
|
250
|
+
canExec: true;
|
|
251
|
+
/** Array of calls to execute on-chain */
|
|
252
|
+
calls: Call[];
|
|
253
|
+
}
|
|
304
254
|
/**
|
|
305
|
-
*
|
|
306
|
-
* Uses fflate for fast decompression
|
|
255
|
+
* Result when task determines execution should not proceed
|
|
307
256
|
*/
|
|
308
|
-
|
|
257
|
+
interface FailResult {
|
|
258
|
+
canExec: false;
|
|
259
|
+
/** Reason why execution should not proceed */
|
|
260
|
+
message: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Result returned from task execution
|
|
264
|
+
*/
|
|
265
|
+
type TaskResult = SuccessResult | FailResult;
|
|
266
|
+
/**
|
|
267
|
+
* Task definition with schema and execution logic
|
|
268
|
+
*/
|
|
269
|
+
interface TaskDefinition<TSchema extends z.ZodType> {
|
|
270
|
+
/** Zod schema for validating task arguments */
|
|
271
|
+
schema: TSchema;
|
|
272
|
+
/** Main execution function */
|
|
273
|
+
run: (ctx: ThymeContext<z.infer<TSchema>>) => Promise<TaskResult>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Define a Web3 automation task
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* import { defineTask, z } from '@thyme-sh/sdk'
|
|
282
|
+
* import { encodeFunctionData } from 'viem'
|
|
283
|
+
*
|
|
284
|
+
* const abi = [
|
|
285
|
+
* 'function transfer(address to, uint256 amount) returns (bool)',
|
|
286
|
+
* ] as const
|
|
287
|
+
*
|
|
288
|
+
* export default defineTask({
|
|
289
|
+
* schema: z.object({
|
|
290
|
+
* targetAddress: z.address(),
|
|
291
|
+
* }),
|
|
292
|
+
* async run(ctx) {
|
|
293
|
+
* return {
|
|
294
|
+
* canExec: true,
|
|
295
|
+
* calls: [{
|
|
296
|
+
* to: ctx.args.targetAddress,
|
|
297
|
+
* data: encodeFunctionData({
|
|
298
|
+
* abi,
|
|
299
|
+
* functionName: 'transfer',
|
|
300
|
+
* args: [recipientAddress, 1000n],
|
|
301
|
+
* }),
|
|
302
|
+
* }]
|
|
303
|
+
* }
|
|
304
|
+
* }
|
|
305
|
+
* })
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
declare function defineTask<TSchema extends z.ZodType>(definition: TaskDefinition<TSchema>): TaskDefinition<TSchema>;
|
|
309
309
|
|
|
310
310
|
export { type Call, type CompressResult, type DecompressResult, type FailResult, type InferSchema, type SuccessResult, type TaskDefinition, type TaskResult, type ThymeContext, compressTask, decompressTask, defineTask, zodExtended as z };
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
// src/task.ts
|
|
2
|
-
function defineTask(definition) {
|
|
3
|
-
return definition;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// src/schema.ts
|
|
7
|
-
import { getAddress, isAddress } from "viem";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
var zodExtended = {
|
|
10
|
-
...z,
|
|
11
|
-
/**
|
|
12
|
-
* Validates an Ethereum address and returns viem's Address type
|
|
13
|
-
* Accepts both checksummed and non-checksummed addresses
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* import { zodExtended as z } from '@thyme-sh/sdk'
|
|
18
|
-
*
|
|
19
|
-
* const schema = z.object({
|
|
20
|
-
* targetAddress: z.address(),
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
address: () => z.string().refine((val) => isAddress(val), {
|
|
25
|
-
message: "Invalid Ethereum address"
|
|
26
|
-
}).transform((val) => getAddress(val))
|
|
27
|
-
};
|
|
28
|
-
|
|
29
1
|
// src/archive.ts
|
|
30
2
|
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
31
3
|
function compressTask(source, bundle) {
|
|
@@ -69,6 +41,34 @@ function decompressTask(zipBuffer) {
|
|
|
69
41
|
bundle
|
|
70
42
|
};
|
|
71
43
|
}
|
|
44
|
+
|
|
45
|
+
// src/schema.ts
|
|
46
|
+
import { getAddress, isAddress } from "viem";
|
|
47
|
+
import { z } from "zod";
|
|
48
|
+
var zodExtended = {
|
|
49
|
+
...z,
|
|
50
|
+
/**
|
|
51
|
+
* Validates an Ethereum address and returns viem's Address type
|
|
52
|
+
* Accepts both checksummed and non-checksummed addresses
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { zodExtended as z } from '@thyme-sh/sdk'
|
|
57
|
+
*
|
|
58
|
+
* const schema = z.object({
|
|
59
|
+
* targetAddress: z.address(),
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
address: () => z.string().refine((val) => isAddress(val), {
|
|
64
|
+
message: "Invalid Ethereum address"
|
|
65
|
+
}).transform((val) => getAddress(val))
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/task.ts
|
|
69
|
+
function defineTask(definition) {
|
|
70
|
+
return definition;
|
|
71
|
+
}
|
|
72
72
|
export {
|
|
73
73
|
compressTask,
|
|
74
74
|
decompressTask,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/archive.ts","../src/schema.ts","../src/task.ts"],"sourcesContent":["import { strFromU8, strToU8, unzipSync, zipSync } from 'fflate'\n\nexport interface CompressResult {\n\tzipBuffer: Uint8Array\n\tchecksum: string\n}\n\nexport interface DecompressResult {\n\tsource: string\n\tbundle: string\n}\n\n/**\n * Compress source and bundle into a ZIP archive\n * Uses fflate for fast, modern compression\n */\nexport function compressTask(source: string, bundle: string): CompressResult {\n\t// Create ZIP archive with both files\n\tconst files = {\n\t\t'source.ts': strToU8(source),\n\t\t'bundle.js': strToU8(bundle),\n\t}\n\n\tconst compressed = zipSync(files, {\n\t\tlevel: 6, // Balanced compression\n\t})\n\n\t// Calculate checksum (simple hash for now)\n\tlet hash = 0\n\tfor (let i = 0; i < compressed.length; i++) {\n\t\tconst byte = compressed[i]\n\t\tif (byte !== undefined) {\n\t\t\thash = (hash << 5) - hash + byte\n\t\t\thash = hash & hash // Convert to 32bit integer\n\t\t}\n\t}\n\tconst checksum = Math.abs(hash).toString(16)\n\n\treturn {\n\t\tzipBuffer: compressed,\n\t\tchecksum,\n\t}\n}\n\n/**\n * Decompress ZIP archive and extract source and bundle files\n * Uses fflate for fast decompression\n */\nexport function decompressTask(\n\tzipBuffer: Uint8Array | ArrayBuffer,\n): DecompressResult {\n\t// Convert ArrayBuffer to Uint8Array if needed\n\tconst uint8Array =\n\t\tzipBuffer instanceof ArrayBuffer ? new Uint8Array(zipBuffer) : zipBuffer\n\n\t// Decompress ZIP\n\tconst decompressed = unzipSync(uint8Array)\n\n\t// Extract files\n\tconst sourceBytes = decompressed['source.ts']\n\tconst bundleBytes = decompressed['bundle.js']\n\n\tif (!sourceBytes) {\n\t\tthrow new Error('source.ts not found in ZIP archive')\n\t}\n\n\tif (!bundleBytes) {\n\t\tthrow new Error('bundle.js not found in ZIP archive')\n\t}\n\n\t// Convert bytes to strings\n\tconst source = strFromU8(sourceBytes)\n\tconst bundle = strFromU8(bundleBytes)\n\n\treturn {\n\t\tsource,\n\t\tbundle,\n\t}\n}\n","import { type Address, getAddress, isAddress } from 'viem'\nimport { z } from 'zod'\n\n/**\n * Extended Zod with Ethereum address validation\n */\nexport const zodExtended = {\n\t...z,\n\t/**\n\t * Validates an Ethereum address and returns viem's Address type\n\t * Accepts both checksummed and non-checksummed addresses\n\t *\n\t * @example\n\t * ```typescript\n\t * import { zodExtended as z } from '@thyme-sh/sdk'\n\t *\n\t * const schema = z.object({\n\t * targetAddress: z.address(),\n\t * })\n\t * ```\n\t */\n\taddress: () =>\n\t\tz\n\t\t\t.string()\n\t\t\t.refine((val): val is Address => isAddress(val), {\n\t\t\t\tmessage: 'Invalid Ethereum address',\n\t\t\t})\n\t\t\t.transform((val) => getAddress(val)),\n}\n\n/**\n * Type helper to infer the schema type\n */\nexport type InferSchema<T extends z.ZodType> = z.infer<T>\n","import type { z } from 'zod'\nimport type { TaskDefinition } from './types'\n\n/**\n * Define a Web3 automation task\n *\n * @example\n * ```typescript\n * import { defineTask, z } from '@thyme-sh/sdk'\n * import { encodeFunctionData } from 'viem'\n *\n * const abi = [\n * 'function transfer(address to, uint256 amount) returns (bool)',\n * ] as const\n *\n * export default defineTask({\n * schema: z.object({\n * targetAddress: z.address(),\n * }),\n * async run(ctx) {\n * return {\n * canExec: true,\n * calls: [{\n * to: ctx.args.targetAddress,\n * data: encodeFunctionData({\n * abi,\n * functionName: 'transfer',\n * args: [recipientAddress, 1000n],\n * }),\n * }]\n * }\n * }\n * })\n * ```\n */\nexport function defineTask<TSchema extends z.ZodType>(\n\tdefinition: TaskDefinition<TSchema>,\n): TaskDefinition<TSchema> {\n\treturn definition\n}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AAS;AAAA,EACV,CAAC,EACA,UAAU,CAAC,QAAQ,WAAW,GAAG,CAAC;AACtC;;;ACOO,SAAS,WACf,YAC0B;AAC1B,SAAO;AACR;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thyme-sh/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "SDK for authoring Web3 automation tasks",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/bnhpio/thyme-sdk.git",
|
|
8
|
+
"directory": "packages/sdk"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"types": "./dist/index.d.ts",
|
|
@@ -28,6 +33,10 @@
|
|
|
28
33
|
],
|
|
29
34
|
"author": "",
|
|
30
35
|
"license": "MIT",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
31
40
|
"dependencies": {
|
|
32
41
|
"fflate": "^0.8.2",
|
|
33
42
|
"viem": "^2.21.54",
|