@dainprotocol/service-sdk 2.0.6 → 2.0.8

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 (74) hide show
  1. package/dist/client/client-auth.d.ts +8 -0
  2. package/dist/client/client-auth.js +23 -0
  3. package/dist/client/client-auth.js.map +1 -1
  4. package/dist/client/types.d.ts +3 -0
  5. package/dist/client/types.js +1 -0
  6. package/dist/client/types.js.map +1 -1
  7. package/dist/service/types.d.ts +1 -0
  8. package/package.json +1 -1
  9. package/dist/__tests__/api-sdk.test.d.ts +0 -1
  10. package/dist/__tests__/api-sdk.test.js +0 -102
  11. package/dist/__tests__/api-sdk.test.js.map +0 -1
  12. package/dist/__tests__/auth.test.d.ts +0 -1
  13. package/dist/__tests__/auth.test.js +0 -110
  14. package/dist/__tests__/auth.test.js.map +0 -1
  15. package/dist/__tests__/citations-plugin.test.d.ts +0 -1
  16. package/dist/__tests__/citations-plugin.test.js +0 -491
  17. package/dist/__tests__/citations-plugin.test.js.map +0 -1
  18. package/dist/__tests__/context-behavior.test.d.ts +0 -1
  19. package/dist/__tests__/context-behavior.test.js +0 -290
  20. package/dist/__tests__/context-behavior.test.js.map +0 -1
  21. package/dist/__tests__/convertToVercelTool.test.d.ts +0 -1
  22. package/dist/__tests__/convertToVercelTool.test.js +0 -527
  23. package/dist/__tests__/convertToVercelTool.test.js.map +0 -1
  24. package/dist/__tests__/core.test.d.ts +0 -1
  25. package/dist/__tests__/core.test.js +0 -154
  26. package/dist/__tests__/core.test.js.map +0 -1
  27. package/dist/__tests__/crypto-plugin.test.d.ts +0 -1
  28. package/dist/__tests__/crypto-plugin.test.js +0 -694
  29. package/dist/__tests__/crypto-plugin.test.js.map +0 -1
  30. package/dist/__tests__/humanActions.test.d.ts +0 -1
  31. package/dist/__tests__/humanActions.test.js +0 -221
  32. package/dist/__tests__/humanActions.test.js.map +0 -1
  33. package/dist/__tests__/integration.test.d.ts +0 -1
  34. package/dist/__tests__/integration.test.js +0 -1573
  35. package/dist/__tests__/integration.test.js.map +0 -1
  36. package/dist/__tests__/mealMeSchemas.test.d.ts +0 -576
  37. package/dist/__tests__/mealMeSchemas.test.js +0 -627
  38. package/dist/__tests__/mealMeSchemas.test.js.map +0 -1
  39. package/dist/__tests__/oauth.test.d.ts +0 -1
  40. package/dist/__tests__/oauth.test.js +0 -378
  41. package/dist/__tests__/oauth.test.js.map +0 -1
  42. package/dist/__tests__/oauth2-client-integration.test.d.ts +0 -1
  43. package/dist/__tests__/oauth2-client-integration.test.js +0 -182
  44. package/dist/__tests__/oauth2-client-integration.test.js.map +0 -1
  45. package/dist/__tests__/oauth2-context.test.d.ts +0 -1
  46. package/dist/__tests__/oauth2-context.test.js +0 -201
  47. package/dist/__tests__/oauth2-context.test.js.map +0 -1
  48. package/dist/__tests__/oauth2-datasource.test.d.ts +0 -1
  49. package/dist/__tests__/oauth2-datasource.test.js +0 -251
  50. package/dist/__tests__/oauth2-datasource.test.js.map +0 -1
  51. package/dist/__tests__/plugin.test.d.ts +0 -1
  52. package/dist/__tests__/plugin.test.js +0 -900
  53. package/dist/__tests__/plugin.test.js.map +0 -1
  54. package/dist/__tests__/processes.test.d.ts +0 -1
  55. package/dist/__tests__/processes.test.js +0 -239
  56. package/dist/__tests__/processes.test.js.map +0 -1
  57. package/dist/__tests__/streaming.test.d.ts +0 -1
  58. package/dist/__tests__/streaming.test.js +0 -592
  59. package/dist/__tests__/streaming.test.js.map +0 -1
  60. package/dist/__tests__/testEnums.d.ts +0 -1
  61. package/dist/__tests__/testEnums.js +0 -73
  62. package/dist/__tests__/testEnums.js.map +0 -1
  63. package/dist/__tests__/testOptionals.test.d.ts +0 -1
  64. package/dist/__tests__/testOptionals.test.js +0 -83
  65. package/dist/__tests__/testOptionals.test.js.map +0 -1
  66. package/dist/__tests__/types.test.d.ts +0 -1
  67. package/dist/__tests__/types.test.js +0 -98
  68. package/dist/__tests__/types.test.js.map +0 -1
  69. package/dist/client/service-auth.d.ts +0 -61
  70. package/dist/client/service-auth.js +0 -93
  71. package/dist/client/service-auth.js.map +0 -1
  72. package/dist/client/user-auth.d.ts +0 -74
  73. package/dist/client/user-auth.js +0 -137
  74. package/dist/client/user-auth.js.map +0 -1
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const zod_1 = require("zod");
4
- const schemaStructure_1 = require("../lib/schemaStructure");
5
- const convertToVercelTool_1 = require("../lib/convertToVercelTool");
6
- describe('Enum types conversion', () => {
7
- it('should correctly convert enum types to Vercel AI Tool parameters', () => {
8
- // Define a schema with enum fields
9
- const testSchema = zod_1.z.object({
10
- simpleEnum: zod_1.z.enum(['A', 'B', 'C']),
11
- optionalEnum: zod_1.z.enum(['X', 'Y', 'Z']).optional(),
12
- nestedEnum: zod_1.z.object({
13
- innerEnum: zod_1.z.enum(['inner1', 'inner2', 'inner3'])
14
- })
15
- });
16
- // Create a mock HTTP tool
17
- const httpTool = {
18
- id: 'test-enum-tool',
19
- name: 'Test Enum Tool',
20
- description: 'A tool to test enum field conversion',
21
- inputSchema: (0, schemaStructure_1.getDetailedSchemaStructure)(testSchema),
22
- outputSchema: { type: 'ZodAny' }
23
- };
24
- // Convert the HTTP tool to a Vercel AI Tool
25
- const vercelAITool = (0, convertToVercelTool_1.convertHttpToolToVercelAITool)(httpTool);
26
- // Check if the conversion was successful
27
- expect(vercelAITool.name).toBe('test-enum-tool');
28
- expect(vercelAITool.description).toBe('A tool to test enum field conversion');
29
- expect(vercelAITool.parameters).toBeInstanceOf(zod_1.z.ZodObject);
30
- // Check if the fields are correctly converted
31
- const schemaShape = vercelAITool.parameters._def.shape();
32
- expect(schemaShape.simpleEnum).toBeInstanceOf(zod_1.z.ZodEnum);
33
- expect(schemaShape.optionalEnum).toBeInstanceOf(zod_1.z.ZodOptional);
34
- expect(schemaShape.optionalEnum._def.innerType).toBeInstanceOf(zod_1.z.ZodEnum);
35
- expect(schemaShape.nestedEnum).toBeInstanceOf(zod_1.z.ZodObject);
36
- expect(schemaShape.nestedEnum._def.shape().innerEnum).toBeInstanceOf(zod_1.z.ZodEnum);
37
- // Test parsing with the converted schema
38
- const validInput = {
39
- simpleEnum: 'B',
40
- optionalEnum: 'Y',
41
- numberEnum: 2,
42
- mixedEnum: 'one',
43
- nestedEnum: {
44
- innerEnum: 'inner2'
45
- }
46
- };
47
- const parseResult = vercelAITool.parameters.safeParse(validInput);
48
- expect(parseResult.success).toBe(true);
49
- // Test parsing with invalid enum values
50
- const invalidInput = {
51
- simpleEnum: 'D',
52
- numberEnum: 4,
53
- mixedEnum: false,
54
- nestedEnum: {
55
- innerEnum: 'inner4'
56
- }
57
- };
58
- const invalidParseResult = vercelAITool.parameters.safeParse(invalidInput);
59
- expect(invalidParseResult.success).toBe(false);
60
- // Test parsing with missing optional enum
61
- const minimalInput = {
62
- simpleEnum: 'A',
63
- numberEnum: 1,
64
- mixedEnum: true,
65
- nestedEnum: {
66
- innerEnum: 'inner1'
67
- }
68
- };
69
- const minimalParseResult = vercelAITool.parameters.safeParse(minimalInput);
70
- expect(minimalParseResult.success).toBe(true);
71
- });
72
- });
73
- //# sourceMappingURL=testEnums.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testEnums.js","sourceRoot":"","sources":["../../src/__tests__/testEnums.ts"],"names":[],"mappings":";;AAAA,6BAAwB;AACxB,4DAAoE;AACpE,oEAA2E;AAE3E,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC1E,mCAAmC;QACnC,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC;YAC1B,UAAU,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YACnC,YAAY,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;YAChD,UAAU,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2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const zod_1 = require("zod");
4
- const schemaStructure_1 = require("../lib/schemaStructure");
5
- const convertToVercelTool_1 = require("../lib/convertToVercelTool");
6
- describe('Optional and default types conversion', () => {
7
- it('should correctly convert optional and default types to Vercel AI Tool parameters', () => {
8
- // Define a schema with optional fields and default values
9
- const testSchema = zod_1.z.object({
10
- requiredField: zod_1.z.string(),
11
- optionalString: zod_1.z.string().optional(),
12
- optionalNumberWithDefault: zod_1.z.number().optional().default(42),
13
- optionalBoolean: zod_1.z.boolean().optional(),
14
- defaultString: zod_1.z.string().default('default value'),
15
- nestedOptional: zod_1.z.object({
16
- innerOptional: zod_1.z.string().optional(),
17
- innerDefault: zod_1.z.number().default(10)
18
- }).optional()
19
- });
20
- // Create a mock HTTP tool
21
- const httpTool = {
22
- id: 'test-optional-default-tool',
23
- name: 'Test Optional and Default Tool',
24
- description: 'A tool to test optional and default field conversion',
25
- inputSchema: (0, schemaStructure_1.getDetailedSchemaStructure)(testSchema),
26
- outputSchema: { type: 'ZodAny' }
27
- };
28
- // Convert the HTTP tool to a Vercel AI Tool
29
- const vercelAITool = (0, convertToVercelTool_1.convertHttpToolToVercelAITool)(httpTool);
30
- // Check if the conversion was successful
31
- expect(vercelAITool.name).toBe('test-optional-default-tool');
32
- expect(vercelAITool.description).toBe('A tool to test optional and default field conversion');
33
- expect(vercelAITool.parameters).toBeInstanceOf(zod_1.z.ZodObject);
34
- // Check if the fields are correctly converted
35
- const schemaShape = vercelAITool.parameters._def.shape();
36
- expect(schemaShape.requiredField).toBeInstanceOf(zod_1.z.ZodString);
37
- expect(schemaShape.optionalString).toBeInstanceOf(zod_1.z.ZodOptional);
38
- expect(schemaShape.optionalBoolean).toBeInstanceOf(zod_1.z.ZodOptional);
39
- // Update for fields with default values
40
- expect(schemaShape.optionalNumberWithDefault).toBeInstanceOf(zod_1.z.ZodDefault);
41
- expect(schemaShape.optionalNumberWithDefault._def.innerType).toBeInstanceOf(zod_1.z.ZodOptional);
42
- expect(schemaShape.optionalNumberWithDefault._def.innerType._def.innerType).toBeInstanceOf(zod_1.z.ZodNumber);
43
- expect(schemaShape.defaultString).toBeInstanceOf(zod_1.z.ZodDefault);
44
- expect(schemaShape.defaultString._def.innerType).toBeInstanceOf(zod_1.z.ZodString);
45
- expect(schemaShape.nestedOptional).toBeInstanceOf(zod_1.z.ZodOptional);
46
- // Check nested fields
47
- const nestedShape = schemaShape.nestedOptional._def.innerType._def.shape();
48
- expect(nestedShape.innerOptional).toBeInstanceOf(zod_1.z.ZodOptional);
49
- expect(nestedShape.innerDefault).toBeInstanceOf(zod_1.z.ZodDefault);
50
- expect(nestedShape.innerDefault._def.innerType).toBeInstanceOf(zod_1.z.ZodNumber);
51
- // Test parsing with the converted schema
52
- const validInput = {
53
- requiredField: 'test',
54
- optionalString: 'optional',
55
- nestedOptional: {
56
- innerOptional: 'nested'
57
- }
58
- };
59
- const parseResult = vercelAITool.parameters.safeParse(validInput);
60
- expect(parseResult.success).toBe(true);
61
- // Test parsing with missing optional fields and check default values
62
- const minimalInput = {
63
- requiredField: 'test'
64
- };
65
- const minimalParseResult = vercelAITool.parameters.safeParse(minimalInput);
66
- expect(minimalParseResult.success).toBe(true);
67
- if (minimalParseResult.success) {
68
- expect(minimalParseResult.data.optionalNumberWithDefault).toBe(42);
69
- expect(minimalParseResult.data.defaultString).toBe('default value');
70
- }
71
- // Test nested default values
72
- const nestedInput = {
73
- requiredField: 'test',
74
- nestedOptional: {}
75
- };
76
- const nestedParseResult = vercelAITool.parameters.safeParse(nestedInput);
77
- expect(nestedParseResult.success).toBe(true);
78
- if (nestedParseResult.success) {
79
- expect(nestedParseResult.data.nestedOptional?.innerDefault).toBe(10);
80
- }
81
- });
82
- });
83
- //# sourceMappingURL=testOptionals.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testOptionals.test.js","sourceRoot":"","sources":["../../src/__tests__/testOptionals.test.ts"],"names":[],"mappings":";;AAAA,6BAAwB;AACx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AU,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QACzE,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,iBAAiB,CAAC,OAAO,EAAE,CAAC;YAC9B,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,98 +0,0 @@
1
- "use strict";
2
- // File: src/__tests__/types.test.ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const zod_1 = require("zod");
5
- describe("DAIN Framework Types", () => {
6
- test("AgentInfo type is correctly defined", () => {
7
- const agentInfo = {
8
- agentId: "test-agent",
9
- address: "0x1234567890123456789012345678901234567890",
10
- smartAccountPDA: "1234567890123456789012345678901234567890",
11
- id: "dain_id_1234567890123456789012345678901234567890",
12
- };
13
- expect(agentInfo.agentId).toBe("test-agent");
14
- expect(agentInfo.address).toBe("0x1234567890123456789012345678901234567890");
15
- });
16
- test("PricingInfo type is correctly defined", () => {
17
- const pricingInfo = {
18
- pricePerUse: 0.01,
19
- currency: "USD",
20
- };
21
- expect(pricingInfo.pricePerUse).toBe(0.01);
22
- expect(pricingInfo.currency).toBe("USD");
23
- });
24
- test("ToolConfig type is correctly defined", () => {
25
- const toolConfig = {
26
- id: "get-weather",
27
- name: "Get Weather",
28
- description: "Fetches weather for a city",
29
- input: zod_1.z.object({ city: zod_1.z.string() }),
30
- output: zod_1.z.object({ temperature: zod_1.z.number() }),
31
- pricing: { pricePerUse: 0.01, currency: "USD" },
32
- handler: async (input, agentInfo) => ({
33
- text: `The temperature is 25°C`,
34
- data: { temperature: 25 },
35
- ui: null
36
- }),
37
- };
38
- expect(toolConfig.id).toBe("get-weather");
39
- expect(toolConfig.input.shape.city).toBeInstanceOf(zod_1.z.ZodString);
40
- expect(toolConfig.output.shape.temperature).toBeInstanceOf(zod_1.z.ZodNumber);
41
- });
42
- test("ServiceConfig type is correctly defined", () => {
43
- const serviceConfig = {
44
- id: "weather-service",
45
- name: "Weather Service",
46
- description: "Provides weather information",
47
- metadata: {
48
- capabilities: ["current-weather", "forecast"],
49
- languages: ["en", "es"],
50
- },
51
- recommendedPrompt: "Ask about the weather",
52
- recommendedTools: ["get-weather", "get-forecast"],
53
- };
54
- expect(serviceConfig.id).toBe("weather-service");
55
- expect(serviceConfig.metadata.capabilities).toContain("current-weather");
56
- expect(serviceConfig.recommendedTools).toContain("get-weather");
57
- });
58
- test("ToolboxConfig type is correctly defined", () => {
59
- const toolboxConfig = {
60
- id: "weather-toolbox",
61
- name: "Weather Toolbox",
62
- description: "Collection of weather tools",
63
- tools: ["get-weather", "get-forecast"],
64
- metadata: {
65
- complexity: "Low",
66
- applicableFields: ["Meteorology", "Travel"],
67
- },
68
- recommendedPrompt: "Use these tools for weather-related tasks",
69
- };
70
- expect(toolboxConfig.id).toBe("weather-toolbox");
71
- expect(toolboxConfig.tools).toContain("get-weather");
72
- expect(toolboxConfig.metadata.applicableFields).toContain("Meteorology");
73
- });
74
- test("DAINServiceConfig type is correctly defined", () => {
75
- const serviceConfig = {
76
- metadata: {
77
- title: "Weather Service",
78
- description: "Provides weather information",
79
- version: "1.0.0",
80
- author: "DAIN Developer",
81
- tags: ["weather", "forecast"],
82
- },
83
- identity: {
84
- publicKey: "test-public-key",
85
- agentId: "weather-agent",
86
- orgId: "weather-org",
87
- privateKey: "test-private",
88
- },
89
- services: [],
90
- tools: [],
91
- toolboxes: [],
92
- contexts: [],
93
- };
94
- expect(serviceConfig.metadata.title).toBe("Weather Service");
95
- expect(serviceConfig.identity.agentId).toBe("weather-agent");
96
- });
97
- });
98
- //# sourceMappingURL=types.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.test.js","sourceRoot":"","sources":["../../src/__tests__/types.test.ts"],"names":[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,CAAC"}
@@ -1,61 +0,0 @@
1
- /**
2
- * Service/Agent Authentication - Legacy Keypair-based
3
- *
4
- * This class is for SERVICE and AGENT authentication using legacy keypair-based signatures.
5
- * End users should NOT use this class - they must use DainUserAuth with JWT tokens.
6
- */
7
- import { DainClientAuth } from './client-auth';
8
- export interface DainServiceAuthConfig {
9
- /** Service API key (format: sk_agent_org_<orgId>_<agentId>_<keypair>) */
10
- apiKey?: string;
11
- /** OR provide individual components: */
12
- /** Base58-encoded Ed25519 private key */
13
- privateKeyBase58?: string;
14
- /** Agent ID */
15
- agentId?: string;
16
- /** Organization ID */
17
- orgId?: string;
18
- /** Smart Account PDA on Solana (optional) */
19
- smartAccountPDA?: string;
20
- /** Webhook URL for async operations (optional) */
21
- webhookUrl?: string;
22
- }
23
- /**
24
- * DainServiceAuth - Legacy keypair-based authentication for services and agents
25
- *
26
- * @example
27
- * ```typescript
28
- * // Authenticate as a service with API key
29
- * const serviceAuth = new DainServiceAuth({
30
- * apiKey: "sk_agent_org_123_agent_456_<base58key>"
31
- * });
32
- *
33
- * // OR with individual components
34
- * const serviceAuth = new DainServiceAuth({
35
- * privateKeyBase58: "49bhyNKM...",
36
- * agentId: "agent_456",
37
- * orgId: "org_123"
38
- * });
39
- * ```
40
- */
41
- export declare class DainServiceAuth extends DainClientAuth {
42
- constructor(config: DainServiceAuthConfig);
43
- /**
44
- * Get the service's agent ID
45
- */
46
- getServiceAgentId(): string;
47
- /**
48
- * Get the service's organization ID
49
- */
50
- getServiceOrgId(): string;
51
- /**
52
- * Override to prevent JWT methods
53
- * @deprecated Not supported for service authentication
54
- */
55
- getSmartAccountId(): never;
56
- /**
57
- * Override to prevent JWT methods
58
- * @deprecated Not supported for service authentication
59
- */
60
- getJWT(): never;
61
- }
@@ -1,93 +0,0 @@
1
- "use strict";
2
- //File: src/client/service-auth.ts
3
- /**
4
- * Service/Agent Authentication - Legacy Keypair-based
5
- *
6
- * This class is for SERVICE and AGENT authentication using legacy keypair-based signatures.
7
- * End users should NOT use this class - they must use DainUserAuth with JWT tokens.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.DainServiceAuth = void 0;
11
- const client_auth_1 = require("./client-auth");
12
- /**
13
- * DainServiceAuth - Legacy keypair-based authentication for services and agents
14
- *
15
- * @example
16
- * ```typescript
17
- * // Authenticate as a service with API key
18
- * const serviceAuth = new DainServiceAuth({
19
- * apiKey: "sk_agent_org_123_agent_456_<base58key>"
20
- * });
21
- *
22
- * // OR with individual components
23
- * const serviceAuth = new DainServiceAuth({
24
- * privateKeyBase58: "49bhyNKM...",
25
- * agentId: "agent_456",
26
- * orgId: "org_123"
27
- * });
28
- * ```
29
- */
30
- class DainServiceAuth extends client_auth_1.DainClientAuth {
31
- constructor(config) {
32
- if (!config.apiKey && !(config.privateKeyBase58 && config.agentId && config.orgId)) {
33
- throw new Error('Invalid service authentication configuration.\n' +
34
- 'Provide either:\n' +
35
- ' - apiKey: "sk_agent_org_<orgId>_<agentId>_<keypair>"\n' +
36
- ' OR\n' +
37
- ' - privateKeyBase58, agentId, and orgId\n\n' +
38
- 'Note: This is for SERVICES and AGENTS only.\n' +
39
- 'If you are authenticating as a user, use DainUserAuth with a JWT token instead.');
40
- }
41
- // Call parent with legacy auth config
42
- super({
43
- apiKey: config.apiKey,
44
- privateKeyBase58: config.privateKeyBase58,
45
- agentId: config.agentId,
46
- orgId: config.orgId,
47
- smartAccountPDA: config.smartAccountPDA,
48
- webhookUrl: config.webhookUrl,
49
- });
50
- // Verify auth method is legacy
51
- if (this.getAuthMethod() !== 'legacy') {
52
- throw new Error('DainServiceAuth must use legacy authentication');
53
- }
54
- }
55
- /**
56
- * Get the service's agent ID
57
- */
58
- getServiceAgentId() {
59
- const agentId = this.getAgentId();
60
- if (!agentId) {
61
- throw new Error('Agent ID not available');
62
- }
63
- return agentId;
64
- }
65
- /**
66
- * Get the service's organization ID
67
- */
68
- getServiceOrgId() {
69
- const orgId = this.getOrgId();
70
- if (!orgId) {
71
- throw new Error('Organization ID not available');
72
- }
73
- return orgId;
74
- }
75
- /**
76
- * Override to prevent JWT methods
77
- * @deprecated Not supported for service authentication
78
- */
79
- getSmartAccountId() {
80
- throw new Error('getSmartAccountId() is not supported for service authentication.\n' +
81
- 'Use getServiceAgentId() instead.');
82
- }
83
- /**
84
- * Override to prevent JWT methods
85
- * @deprecated Not supported for service authentication
86
- */
87
- getJWT() {
88
- throw new Error('getJWT() is not supported for service authentication.\n' +
89
- 'Services use keypair-based authentication, not JWT.');
90
- }
91
- }
92
- exports.DainServiceAuth = DainServiceAuth;
93
- //# sourceMappingURL=service-auth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service-auth.js","sourceRoot":"","sources":["../../src/client/service-auth.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC;;;;;GAKG;;;AAEH,+CAA+C;AAqB/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,eAAgB,SAAQ,4BAAc;IACjD,YAAY,MAA6B;QACvC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,gBAAgB,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACnF,MAAM,IAAI,KAAK,CACb,iDAAiD;gBACjD,mBAAmB;gBACnB,0DAA0D;gBAC1D,QAAQ;gBACR,8CAA8C;gBAC9C,+CAA+C;gBAC/C,iFAAiF,CAClF,CAAC;QACJ,CAAC;QAED,sCAAsC;QACtC,KAAK,CAAC;YACJ,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC,CAAC;QAEH,+BAA+B;QAC/B,IAAI,IAAI,CAAC,aAAa,EAAE,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,eAAe;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,iBAAiB;QACf,MAAM,IAAI,KAAK,CACb,oEAAoE;YACpE,kCAAkC,CACnC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,MAAM,IAAI,KAAK,CACb,yDAAyD;YACzD,qDAAqD,CACtD,CAAC;IACJ,CAAC;CACF;AAzED,0CAyEC"}
@@ -1,74 +0,0 @@
1
- /**
2
- * User Authentication - JWT ONLY
3
- *
4
- * Users authenticate with JWT tokens from DAIN ID OAuth.
5
- * NO orgId, NO agentId, NO keypair - completely removed for users.
6
- */
7
- export interface DainUserAuthConfig {
8
- /** JWT access token from DAIN ID OAuth */
9
- jwt: string;
10
- /** Smart Account ID (optional, will be extracted from JWT if not provided) */
11
- smartAccountId?: string;
12
- /** Smart Account PDA on Solana (optional) */
13
- smartAccountPDA?: string;
14
- /** Webhook URL for async operations (optional) */
15
- webhookUrl?: string;
16
- }
17
- /**
18
- * DainUserAuth - JWT-only authentication for end users
19
- *
20
- * Users have:
21
- * - JWT token (for authentication)
22
- * - Smart Account ID (their unique identifier)
23
- * - NO orgId, NO agentId, NO keypair
24
- */
25
- export declare class DainUserAuth {
26
- private jwt;
27
- private smartAccountId;
28
- private smartAccountPDA?;
29
- private webhookUrl?;
30
- constructor(config: DainUserAuthConfig);
31
- /**
32
- * Decode JWT payload (without verification)
33
- */
34
- private decodeJWTPayload;
35
- /**
36
- * Sign request - NOT NEEDED for JWT, returns empty
37
- */
38
- signRequest(_method: string, _path: string, _body: string): Promise<{
39
- signature: string;
40
- timestamp: string;
41
- }>;
42
- /**
43
- * Get headers for HTTP requests
44
- */
45
- getHeaders(_signature: string, _timestamp: string): Record<string, string>;
46
- /**
47
- * Get the user's smart account ID
48
- */
49
- getSmartAccountId(): string;
50
- /**
51
- * Get JWT token
52
- */
53
- getJWT(): string;
54
- /**
55
- * Get smart account PDA
56
- */
57
- getSmartAccountPDA(): string | undefined;
58
- /**
59
- * Get webhook URL
60
- */
61
- getWebhookUrl(): string | undefined;
62
- /**
63
- * Check if using JWT authentication (always true for users)
64
- */
65
- isJWT(): boolean;
66
- /**
67
- * Serialize user auth
68
- */
69
- serialize(): string;
70
- /**
71
- * Deserialize user auth
72
- */
73
- static deserialize(serialized: string): DainUserAuth;
74
- }
@@ -1,137 +0,0 @@
1
- "use strict";
2
- //File: src/client/user-auth.ts
3
- /**
4
- * User Authentication - JWT ONLY
5
- *
6
- * Users authenticate with JWT tokens from DAIN ID OAuth.
7
- * NO orgId, NO agentId, NO keypair - completely removed for users.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.DainUserAuth = void 0;
11
- /**
12
- * DainUserAuth - JWT-only authentication for end users
13
- *
14
- * Users have:
15
- * - JWT token (for authentication)
16
- * - Smart Account ID (their unique identifier)
17
- * - NO orgId, NO agentId, NO keypair
18
- */
19
- class DainUserAuth {
20
- jwt;
21
- smartAccountId;
22
- smartAccountPDA;
23
- webhookUrl;
24
- constructor(config) {
25
- if (!config.jwt) {
26
- throw new Error('JWT token is required for user authentication');
27
- }
28
- this.jwt = config.jwt;
29
- // Extract smartAccountId from config or decode from JWT
30
- if (config.smartAccountId) {
31
- this.smartAccountId = config.smartAccountId;
32
- }
33
- else {
34
- const payload = this.decodeJWTPayload(config.jwt);
35
- this.smartAccountId = payload.smart_account_id || payload.sub;
36
- }
37
- this.smartAccountPDA = config.smartAccountPDA;
38
- this.webhookUrl = config.webhookUrl;
39
- }
40
- /**
41
- * Decode JWT payload (without verification)
42
- */
43
- decodeJWTPayload(jwt) {
44
- const parts = jwt.split('.');
45
- if (parts.length !== 3) {
46
- throw new Error('Invalid JWT format');
47
- }
48
- const payload = Buffer.from(parts[1], 'base64').toString('utf-8');
49
- return JSON.parse(payload);
50
- }
51
- /**
52
- * Sign request - NOT NEEDED for JWT, returns empty
53
- */
54
- async signRequest(_method, _path, _body) {
55
- return { signature: '', timestamp: '' };
56
- }
57
- /**
58
- * Get headers for HTTP requests
59
- */
60
- getHeaders(_signature, _timestamp) {
61
- const headers = {
62
- "Authorization": `Bearer ${this.jwt}`,
63
- };
64
- if (this.smartAccountPDA) {
65
- headers["X-DAIN-SMART-ACCOUNT-PDA"] = this.smartAccountPDA;
66
- }
67
- if (this.webhookUrl) {
68
- headers["X-DAIN-WEBHOOK-URL"] = this.webhookUrl;
69
- }
70
- return headers;
71
- }
72
- /**
73
- * Get the user's smart account ID
74
- */
75
- getSmartAccountId() {
76
- return this.smartAccountId;
77
- }
78
- /**
79
- * Get JWT token
80
- */
81
- getJWT() {
82
- return this.jwt;
83
- }
84
- /**
85
- * Get smart account PDA
86
- */
87
- getSmartAccountPDA() {
88
- return this.smartAccountPDA;
89
- }
90
- /**
91
- * Get webhook URL
92
- */
93
- getWebhookUrl() {
94
- return this.webhookUrl;
95
- }
96
- /**
97
- * Check if using JWT authentication (always true for users)
98
- */
99
- isJWT() {
100
- return true;
101
- }
102
- /**
103
- * Serialize user auth
104
- */
105
- serialize() {
106
- const data = {
107
- authMethod: 'jwt',
108
- jwt: this.jwt,
109
- smartAccountId: this.smartAccountId,
110
- smartAccountPDA: this.smartAccountPDA,
111
- webhookUrl: this.webhookUrl
112
- };
113
- return Buffer.from(JSON.stringify(data)).toString('base64');
114
- }
115
- /**
116
- * Deserialize user auth
117
- */
118
- static deserialize(serialized) {
119
- try {
120
- const data = JSON.parse(Buffer.from(serialized, 'base64').toString());
121
- if (data.authMethod !== 'jwt') {
122
- throw new Error('Invalid auth method for user');
123
- }
124
- return new DainUserAuth({
125
- jwt: data.jwt,
126
- smartAccountId: data.smartAccountId,
127
- smartAccountPDA: data.smartAccountPDA,
128
- webhookUrl: data.webhookUrl
129
- });
130
- }
131
- catch (error) {
132
- throw new Error('Failed to deserialize DainUserAuth: ' + error.message);
133
- }
134
- }
135
- }
136
- exports.DainUserAuth = DainUserAuth;
137
- //# sourceMappingURL=user-auth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user-auth.js","sourceRoot":"","sources":["../../src/client/user-auth.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;;;;;GAKG;;;AAgBH;;;;;;;GAOG;AACH,MAAa,YAAY;IACf,GAAG,CAAS;IACZ,cAAc,CAAS;IACvB,eAAe,CAAU;IACzB,UAAU,CAAU;IAE5B,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QAEtB,wDAAwD;QACxD,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAClD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC9C,IAAI,CAAC,UAAU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