@dainprotocol/service-sdk 1.1.48 → 1.2.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/__tests__/context-behavior.test.js +290 -0
- package/dist/__tests__/context-behavior.test.js.map +1 -0
- package/dist/__tests__/oauth2-context.test.js +201 -0
- package/dist/__tests__/oauth2-context.test.js.map +1 -0
- package/dist/__tests__/oauth2-datasource.test.js +251 -0
- package/dist/__tests__/oauth2-datasource.test.js.map +1 -0
- package/dist/client/client-auth.d.ts +24 -8
- package/dist/client/client-auth.js +103 -16
- package/dist/client/client-auth.js.map +1 -1
- package/dist/service/auth.d.ts +38 -1
- package/dist/service/auth.js +77 -5
- package/dist/service/auth.js.map +1 -1
- package/dist/service/core.js.map +1 -1
- package/dist/service/oauth2.d.ts +3 -2
- package/dist/service/oauth2.js +1 -0
- package/dist/service/oauth2.js.map +1 -1
- package/dist/service/oauth2Manager.d.ts +2 -0
- package/dist/service/oauth2Manager.js +5 -2
- package/dist/service/oauth2Manager.js.map +1 -1
- package/dist/service/server.js +54 -11
- package/dist/service/server.js.map +1 -1
- package/dist/service/types.d.ts +9 -0
- package/package.json +3 -3
- package/dist/__tests__/oauth-context-simple.test.js +0 -90
- package/dist/__tests__/oauth-context-simple.test.js.map +0 -1
- package/dist/__tests__/oauth-context.test.js +0 -282
- package/dist/__tests__/oauth-context.test.js.map +0 -1
- package/dist/__tests__/oauth2-client-context.test.js +0 -165
- package/dist/__tests__/oauth2-client-context.test.js.map +0 -1
- package/dist/__tests__/oauth2-client-simple.test.d.ts +0 -1
- package/dist/__tests__/oauth2-client-simple.test.js +0 -144
- package/dist/__tests__/oauth2-client-simple.test.js.map +0 -1
- /package/dist/__tests__/{oauth-context-simple.test.d.ts → context-behavior.test.d.ts} +0 -0
- /package/dist/__tests__/{oauth-context.test.d.ts → oauth2-context.test.d.ts} +0 -0
- /package/dist/__tests__/{oauth2-client-context.test.d.ts → oauth2-datasource.test.d.ts} +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const nodeService_1 = require("../service/nodeService");
|
|
6
|
+
const core_1 = require("../service/core");
|
|
7
|
+
const ed25519_1 = require("@noble/curves/ed25519");
|
|
8
|
+
const bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
9
|
+
const client_auth_1 = require("../client/client-auth");
|
|
10
|
+
const client_1 = require("../client/client");
|
|
11
|
+
const oauth2_token_manager_1 = require("@dainprotocol/oauth2-token-manager");
|
|
12
|
+
describe("OAuth2Client in Datasources", () => {
|
|
13
|
+
let server;
|
|
14
|
+
const port = 4593; // Different port to avoid conflicts
|
|
15
|
+
// Generate keys for the service
|
|
16
|
+
const privateKey = ed25519_1.ed25519.utils.randomPrivateKey();
|
|
17
|
+
const publicKey = ed25519_1.ed25519.getPublicKey(privateKey);
|
|
18
|
+
// Generate keys for the client
|
|
19
|
+
const clientPrivateKey = ed25519_1.ed25519.utils.randomPrivateKey();
|
|
20
|
+
const agentAuth = new client_auth_1.DainClientAuth({
|
|
21
|
+
privateKeyBase58: bs58_1.default.encode(clientPrivateKey),
|
|
22
|
+
agentId: "oauth2-datasource-test-agent",
|
|
23
|
+
orgId: "oauth2-datasource-test-org",
|
|
24
|
+
});
|
|
25
|
+
let dainConnection;
|
|
26
|
+
// Track oauth2Client details in datasources
|
|
27
|
+
const datasourceOAuth2Info = {
|
|
28
|
+
wasPresent: false,
|
|
29
|
+
hadGetAccessTokenMethod: false,
|
|
30
|
+
hadGetValidTokenMethod: false,
|
|
31
|
+
methodsFound: [],
|
|
32
|
+
callCount: 0,
|
|
33
|
+
lastParams: null
|
|
34
|
+
};
|
|
35
|
+
// Create a simple dummy tool (required for service)
|
|
36
|
+
const dummyTool = (0, core_1.createTool)({
|
|
37
|
+
id: "dummy-tool",
|
|
38
|
+
name: "Dummy Tool",
|
|
39
|
+
description: "A dummy tool required for the service",
|
|
40
|
+
input: zod_1.z.object({
|
|
41
|
+
message: zod_1.z.string()
|
|
42
|
+
}),
|
|
43
|
+
output: zod_1.z.object({
|
|
44
|
+
result: zod_1.z.string()
|
|
45
|
+
}),
|
|
46
|
+
handler: async (input) => {
|
|
47
|
+
return {
|
|
48
|
+
text: `Dummy response: ${input.message}`,
|
|
49
|
+
data: {
|
|
50
|
+
result: `Processed: ${input.message}`
|
|
51
|
+
},
|
|
52
|
+
ui: undefined
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// Create a datasource that verifies oauth2Client
|
|
57
|
+
const oauth2VerifyDatasource = (0, core_1.createDatasource)({
|
|
58
|
+
id: "oauth2-verify-datasource",
|
|
59
|
+
name: "OAuth2 Verify Datasource",
|
|
60
|
+
description: "Datasource that verifies oauth2Client is passed",
|
|
61
|
+
type: "json",
|
|
62
|
+
input: zod_1.z.object({
|
|
63
|
+
testParam: zod_1.z.string().optional()
|
|
64
|
+
}),
|
|
65
|
+
getDatasource: async (agentInfo, params, extraData) => {
|
|
66
|
+
datasourceOAuth2Info.callCount++;
|
|
67
|
+
datasourceOAuth2Info.lastParams = params;
|
|
68
|
+
// Check if oauth2Client is present
|
|
69
|
+
datasourceOAuth2Info.wasPresent = !!extraData?.oauth2Client;
|
|
70
|
+
if (extraData?.oauth2Client) {
|
|
71
|
+
// Get all property names including methods from the prototype
|
|
72
|
+
const allProps = [...Object.keys(extraData.oauth2Client)];
|
|
73
|
+
const prototypeMethods = Object.getOwnPropertyNames(Object.getPrototypeOf(extraData.oauth2Client));
|
|
74
|
+
datasourceOAuth2Info.methodsFound = [...new Set([...allProps, ...prototypeMethods])].filter(m => m !== 'constructor');
|
|
75
|
+
// Check for expected methods
|
|
76
|
+
datasourceOAuth2Info.hadGetAccessTokenMethod = typeof extraData.oauth2Client.getAccessToken === 'function';
|
|
77
|
+
datasourceOAuth2Info.hadGetValidTokenMethod = typeof extraData.oauth2Client.getValidToken === 'function';
|
|
78
|
+
console.log("OAuth2Client detected in datasource with methods:", datasourceOAuth2Info.methodsFound);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.log("No OAuth2Client in datasource extraData");
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
oauth2ClientPresent: datasourceOAuth2Info.wasPresent,
|
|
85
|
+
oauth2ClientMethods: datasourceOAuth2Info.methodsFound,
|
|
86
|
+
hasGetAccessToken: datasourceOAuth2Info.hadGetAccessTokenMethod,
|
|
87
|
+
hasGetValidToken: datasourceOAuth2Info.hadGetValidTokenMethod,
|
|
88
|
+
callCount: datasourceOAuth2Info.callCount,
|
|
89
|
+
receivedParams: params
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// Test without OAuth2 configured
|
|
94
|
+
describe("Without OAuth2 configuration", () => {
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
// Reset tracking
|
|
97
|
+
datasourceOAuth2Info.wasPresent = false;
|
|
98
|
+
datasourceOAuth2Info.hadGetAccessTokenMethod = false;
|
|
99
|
+
datasourceOAuth2Info.hadGetValidTokenMethod = false;
|
|
100
|
+
datasourceOAuth2Info.methodsFound = [];
|
|
101
|
+
datasourceOAuth2Info.callCount = 0;
|
|
102
|
+
datasourceOAuth2Info.lastParams = null;
|
|
103
|
+
const serviceWithoutOAuth2 = (0, nodeService_1.defineDAINService)({
|
|
104
|
+
metadata: {
|
|
105
|
+
title: "Datasource OAuth2 Test (No OAuth2)",
|
|
106
|
+
description: "Testing oauth2Client in datasources without OAuth2",
|
|
107
|
+
version: "1.0.0",
|
|
108
|
+
author: "Test",
|
|
109
|
+
tags: ["test", "datasource", "no-oauth2"]
|
|
110
|
+
},
|
|
111
|
+
identity: {
|
|
112
|
+
publicKey: bs58_1.default.encode(publicKey),
|
|
113
|
+
privateKey: bs58_1.default.encode(privateKey),
|
|
114
|
+
agentId: "test-datasource-service-agent",
|
|
115
|
+
orgId: "test-datasource-service-org"
|
|
116
|
+
},
|
|
117
|
+
datasources: [oauth2VerifyDatasource],
|
|
118
|
+
tools: [dummyTool] // At least one tool is required
|
|
119
|
+
});
|
|
120
|
+
server = await serviceWithoutOAuth2.startNode({ port });
|
|
121
|
+
dainConnection = new client_1.DainServiceConnection(`http://localhost:${port}`, agentAuth);
|
|
122
|
+
});
|
|
123
|
+
afterAll(async () => {
|
|
124
|
+
if (server && server.shutdown) {
|
|
125
|
+
await server.shutdown();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
it("should pass undefined oauth2Client when OAuth2 is not configured", async () => {
|
|
129
|
+
const datasourceData = await dainConnection.getDatasource("oauth2-verify-datasource", {
|
|
130
|
+
testParam: "test without oauth2"
|
|
131
|
+
});
|
|
132
|
+
expect(datasourceData.id).toBe("oauth2-verify-datasource");
|
|
133
|
+
expect(datasourceOAuth2Info.wasPresent).toBe(false);
|
|
134
|
+
expect(datasourceData.data.oauth2ClientPresent).toBe(false);
|
|
135
|
+
expect(datasourceData.data.receivedParams.testParam).toBe("test without oauth2");
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
// Test with OAuth2 configured
|
|
139
|
+
describe("With OAuth2 configuration", () => {
|
|
140
|
+
beforeAll(async () => {
|
|
141
|
+
// Shutdown previous server if running
|
|
142
|
+
if (server && server.shutdown) {
|
|
143
|
+
await server.shutdown();
|
|
144
|
+
}
|
|
145
|
+
// Reset tracking
|
|
146
|
+
datasourceOAuth2Info.wasPresent = false;
|
|
147
|
+
datasourceOAuth2Info.hadGetAccessTokenMethod = false;
|
|
148
|
+
datasourceOAuth2Info.hadGetValidTokenMethod = false;
|
|
149
|
+
datasourceOAuth2Info.methodsFound = [];
|
|
150
|
+
datasourceOAuth2Info.callCount = 0;
|
|
151
|
+
datasourceOAuth2Info.lastParams = null;
|
|
152
|
+
const serviceWithOAuth2 = (0, nodeService_1.defineDAINService)({
|
|
153
|
+
metadata: {
|
|
154
|
+
title: "Datasource OAuth2 Test (With OAuth2)",
|
|
155
|
+
description: "Testing oauth2Client in datasources with OAuth2",
|
|
156
|
+
version: "1.0.0",
|
|
157
|
+
author: "Test",
|
|
158
|
+
tags: ["test", "datasource", "oauth2"]
|
|
159
|
+
},
|
|
160
|
+
identity: {
|
|
161
|
+
publicKey: bs58_1.default.encode(publicKey),
|
|
162
|
+
privateKey: bs58_1.default.encode(privateKey),
|
|
163
|
+
agentId: "test-oauth2-datasource-agent",
|
|
164
|
+
orgId: "test-oauth2-datasource-org"
|
|
165
|
+
},
|
|
166
|
+
// Configure OAuth2
|
|
167
|
+
oauth2: {
|
|
168
|
+
baseUrl: `http://localhost:${port}`,
|
|
169
|
+
providers: {
|
|
170
|
+
test: {
|
|
171
|
+
clientId: "test-client-id",
|
|
172
|
+
clientSecret: "test-client-secret",
|
|
173
|
+
authorizationUrl: "https://example.com/oauth/authorize",
|
|
174
|
+
tokenUrl: "https://example.com/oauth/token",
|
|
175
|
+
scopes: ["read", "write"]
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
tokenStore: new oauth2_token_manager_1.InMemoryStorageAdapter()
|
|
179
|
+
},
|
|
180
|
+
datasources: [oauth2VerifyDatasource],
|
|
181
|
+
tools: [dummyTool] // At least one tool is required
|
|
182
|
+
});
|
|
183
|
+
server = await serviceWithOAuth2.startNode({ port: port + 1 }); // Use different port
|
|
184
|
+
dainConnection = new client_1.DainServiceConnection(`http://localhost:${port + 1}`, agentAuth);
|
|
185
|
+
});
|
|
186
|
+
afterAll(async () => {
|
|
187
|
+
if (server && server.shutdown) {
|
|
188
|
+
await server.shutdown();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
beforeEach(() => {
|
|
192
|
+
// Reset tracking before each test
|
|
193
|
+
datasourceOAuth2Info.wasPresent = false;
|
|
194
|
+
datasourceOAuth2Info.hadGetAccessTokenMethod = false;
|
|
195
|
+
datasourceOAuth2Info.hadGetValidTokenMethod = false;
|
|
196
|
+
datasourceOAuth2Info.methodsFound = [];
|
|
197
|
+
datasourceOAuth2Info.callCount = 0;
|
|
198
|
+
datasourceOAuth2Info.lastParams = null;
|
|
199
|
+
});
|
|
200
|
+
it("should pass oauth2Client to datasource when OAuth2 is configured", async () => {
|
|
201
|
+
const datasourceData = await dainConnection.getDatasource("oauth2-verify-datasource", {
|
|
202
|
+
testParam: "test with oauth2"
|
|
203
|
+
});
|
|
204
|
+
expect(datasourceData.id).toBe("oauth2-verify-datasource");
|
|
205
|
+
// Verify oauth2Client was passed
|
|
206
|
+
expect(datasourceOAuth2Info.wasPresent).toBe(true);
|
|
207
|
+
expect(datasourceData.data.oauth2ClientPresent).toBe(true);
|
|
208
|
+
expect(datasourceData.data.receivedParams.testParam).toBe("test with oauth2");
|
|
209
|
+
});
|
|
210
|
+
it("should provide oauth2Client with expected methods to datasource", async () => {
|
|
211
|
+
const datasourceData = await dainConnection.getDatasource("oauth2-verify-datasource", {
|
|
212
|
+
testParam: "test methods"
|
|
213
|
+
});
|
|
214
|
+
// Check that oauth2Client has the expected methods
|
|
215
|
+
expect(datasourceOAuth2Info.hadGetAccessTokenMethod).toBe(true);
|
|
216
|
+
expect(datasourceOAuth2Info.hadGetValidTokenMethod).toBe(true);
|
|
217
|
+
// Verify through the returned data
|
|
218
|
+
expect(datasourceData.data.hasGetAccessToken).toBe(true);
|
|
219
|
+
expect(datasourceData.data.hasGetValidToken).toBe(true);
|
|
220
|
+
// Check that methods array contains expected methods
|
|
221
|
+
expect(datasourceOAuth2Info.methodsFound).toContain('getAccessToken');
|
|
222
|
+
expect(datasourceOAuth2Info.methodsFound).toContain('getValidToken');
|
|
223
|
+
});
|
|
224
|
+
it("should pass oauth2Client on multiple datasource calls", async () => {
|
|
225
|
+
// Reset counter
|
|
226
|
+
datasourceOAuth2Info.callCount = 0;
|
|
227
|
+
// Make multiple calls
|
|
228
|
+
await dainConnection.getDatasource("oauth2-verify-datasource", { testParam: "call 1" });
|
|
229
|
+
await dainConnection.getDatasource("oauth2-verify-datasource", { testParam: "call 2" });
|
|
230
|
+
await dainConnection.getDatasource("oauth2-verify-datasource", { testParam: "call 3" });
|
|
231
|
+
// Should have been called 3 times
|
|
232
|
+
expect(datasourceOAuth2Info.callCount).toBe(3);
|
|
233
|
+
// OAuth2Client should have been present in all calls
|
|
234
|
+
expect(datasourceOAuth2Info.wasPresent).toBe(true);
|
|
235
|
+
// Last params should be from the last call
|
|
236
|
+
expect(datasourceOAuth2Info.lastParams.testParam).toBe("call 3");
|
|
237
|
+
});
|
|
238
|
+
it("should provide a functional oauth2Client object to datasource", async () => {
|
|
239
|
+
const datasourceData = await dainConnection.getDatasource("oauth2-verify-datasource", {});
|
|
240
|
+
// The datasource should report having the oauth2Client
|
|
241
|
+
expect(datasourceData.data.oauth2ClientPresent).toBe(true);
|
|
242
|
+
// Verify the methods are actually functions (checked in our datasource)
|
|
243
|
+
expect(datasourceData.data.hasGetAccessToken).toBe(true);
|
|
244
|
+
expect(datasourceData.data.hasGetValidToken).toBe(true);
|
|
245
|
+
// Verify we found multiple methods
|
|
246
|
+
expect(datasourceOAuth2Info.methodsFound.length).toBeGreaterThan(0);
|
|
247
|
+
expect(datasourceOAuth2Info.methodsFound).toEqual(expect.arrayContaining(['getAccessToken', 'getValidToken']));
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
//# sourceMappingURL=oauth2-datasource.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2-datasource.test.js","sourceRoot":"","sources":["../../src/__tests__/oauth2-datasource.test.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,wDAA2D;AAC3D,0CAA+D;AAC/D,mDAAgD;AAChD,wDAAwB;AACxB,uDAAuD;AACvD,6CAAyD;AACzD,6EAA4E;AAE5E,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,IAAI,MAAW,CAAC;IAChB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC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|
4
6
|
orgId?: string;
|
|
@@ -7,26 +9,40 @@ interface DainClientAuthConfig {
|
|
|
7
9
|
webhookUrl?: string;
|
|
8
10
|
}
|
|
9
11
|
export declare class DainClientAuth {
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
12
|
+
private jwt?;
|
|
13
|
+
private smartAccountId?;
|
|
14
|
+
private privateKey?;
|
|
15
|
+
private agentId?;
|
|
16
|
+
private orgId?;
|
|
17
|
+
private publicKey?;
|
|
14
18
|
private smartAccountPDA?;
|
|
15
19
|
private webhookUrl?;
|
|
20
|
+
private readonly authMethod;
|
|
16
21
|
constructor(config: DainClientAuthConfig);
|
|
17
22
|
private parseApiKey;
|
|
23
|
+
/**
|
|
24
|
+
* Sign request for legacy authentication
|
|
25
|
+
* For JWT auth, returns empty values (not needed)
|
|
26
|
+
*/
|
|
18
27
|
signRequest(method: string, path: string, body: string): Promise<{
|
|
19
28
|
signature: string;
|
|
20
29
|
timestamp: string;
|
|
21
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Get headers for authentication
|
|
33
|
+
* Returns different headers based on auth method
|
|
34
|
+
*/
|
|
22
35
|
getHeaders(signature: string, timestamp: string): Record<string, string>;
|
|
23
36
|
signMessage(message: string): string;
|
|
24
37
|
static verifyMessage(message: string, signature: string, publicKey: Uint8Array): boolean;
|
|
25
38
|
verifyEventSignature(data: string, signature: string, timestamp: string, publicKeyBase58: string): boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
getAuthMethod(): 'jwt' | 'legacy';
|
|
40
|
+
getJWT(): string | undefined;
|
|
41
|
+
getSmartAccountId(): string | undefined;
|
|
42
|
+
getAgentId(): string | undefined;
|
|
43
|
+
getOrgId(): string | undefined;
|
|
44
|
+
getPublicKey(): Uint8Array | undefined;
|
|
45
|
+
getPublicKeyBase58(): string | undefined;
|
|
30
46
|
getSmartAccountPDA(): string | undefined;
|
|
31
47
|
getWebhookUrl(): string | undefined;
|
|
32
48
|
serialize(): string;
|
|
@@ -8,13 +8,43 @@ const sha256_1 = require("@noble/hashes/sha256");
|
|
|
8
8
|
const utils_1 = require("@noble/hashes/utils");
|
|
9
9
|
const bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
10
10
|
class DainClientAuth {
|
|
11
|
+
// JWT fields (user auth)
|
|
12
|
+
jwt;
|
|
13
|
+
smartAccountId;
|
|
14
|
+
// Legacy fields (service auth)
|
|
11
15
|
privateKey;
|
|
12
16
|
agentId;
|
|
13
17
|
orgId;
|
|
14
18
|
publicKey;
|
|
15
19
|
smartAccountPDA;
|
|
20
|
+
// Common
|
|
16
21
|
webhookUrl;
|
|
22
|
+
authMethod;
|
|
17
23
|
constructor(config) {
|
|
24
|
+
// Priority 1: JWT Authentication (Users from DAIN ID)
|
|
25
|
+
if (config.jwt) {
|
|
26
|
+
this.jwt = config.jwt;
|
|
27
|
+
this.authMethod = 'jwt';
|
|
28
|
+
this.webhookUrl = config.webhookUrl;
|
|
29
|
+
// Extract smartAccountId from JWT if not provided
|
|
30
|
+
if (config.smartAccountId) {
|
|
31
|
+
this.smartAccountId = config.smartAccountId;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
try {
|
|
35
|
+
const payload = JSON.parse(Buffer.from(config.jwt.split('.')[1], 'base64').toString());
|
|
36
|
+
this.smartAccountId = payload.smart_account_id || payload.sub;
|
|
37
|
+
if (!this.smartAccountId) {
|
|
38
|
+
throw new Error('JWT missing smart_account_id/sub claim');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`Invalid JWT: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Priority 2: Legacy API Key (Services)
|
|
18
48
|
if (config.apiKey) {
|
|
19
49
|
const { privateKey, agentId, orgId, publicKey } = this.parseApiKey(config.apiKey);
|
|
20
50
|
this.privateKey = privateKey;
|
|
@@ -22,18 +52,24 @@ class DainClientAuth {
|
|
|
22
52
|
this.orgId = orgId;
|
|
23
53
|
this.publicKey = publicKey;
|
|
24
54
|
this.webhookUrl = config.webhookUrl;
|
|
55
|
+
this.smartAccountPDA = config.smartAccountPDA;
|
|
56
|
+
this.authMethod = 'legacy';
|
|
57
|
+
return;
|
|
25
58
|
}
|
|
26
|
-
|
|
59
|
+
// Priority 3: Legacy Keypair (Services)
|
|
60
|
+
if (config.privateKeyBase58 && config.agentId && config.orgId) {
|
|
27
61
|
this.privateKey = bs58_1.default.decode(config.privateKeyBase58);
|
|
28
62
|
this.agentId = config.agentId.replace('agent_', '');
|
|
29
63
|
this.orgId = config.orgId.replace('org_', '');
|
|
30
64
|
this.publicKey = ed25519_1.ed25519.getPublicKey(this.privateKey);
|
|
31
65
|
this.webhookUrl = config.webhookUrl;
|
|
66
|
+
this.smartAccountPDA = config.smartAccountPDA;
|
|
67
|
+
this.authMethod = 'legacy';
|
|
68
|
+
return;
|
|
32
69
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.smartAccountPDA = config.smartAccountPDA;
|
|
70
|
+
throw new Error('Invalid auth config. Provide either:\n' +
|
|
71
|
+
' - jwt (for users)\n' +
|
|
72
|
+
' - apiKey OR (privateKeyBase58 + agentId + orgId) (for services)');
|
|
37
73
|
}
|
|
38
74
|
parseApiKey(apiKey) {
|
|
39
75
|
const parts = apiKey.split('_');
|
|
@@ -47,26 +83,53 @@ class DainClientAuth {
|
|
|
47
83
|
const publicKey = bs58_1.default.decode(privateKeyBase58).slice(32);
|
|
48
84
|
return { privateKey, agentId, orgId, publicKey };
|
|
49
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Sign request for legacy authentication
|
|
88
|
+
* For JWT auth, returns empty values (not needed)
|
|
89
|
+
*/
|
|
50
90
|
async signRequest(method, path, body) {
|
|
91
|
+
if (this.authMethod === 'jwt') {
|
|
92
|
+
// JWT doesn't need request signing
|
|
93
|
+
return { signature: '', timestamp: '' };
|
|
94
|
+
}
|
|
95
|
+
// Legacy: Sign request
|
|
51
96
|
const timestamp = Date.now().toString();
|
|
52
97
|
const message = `${method}:${path}:${timestamp}:${body}`;
|
|
53
|
-
// console.log("signRequest:", { message, timestamp });
|
|
54
98
|
const messageHash = (0, sha256_1.sha256)(message);
|
|
55
99
|
const signature = ed25519_1.ed25519.sign(messageHash, this.privateKey);
|
|
56
100
|
return { signature: (0, utils_1.bytesToHex)(signature), timestamp };
|
|
57
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Get headers for authentication
|
|
104
|
+
* Returns different headers based on auth method
|
|
105
|
+
*/
|
|
58
106
|
getHeaders(signature, timestamp) {
|
|
107
|
+
if (this.authMethod === 'jwt') {
|
|
108
|
+
// JWT Authentication
|
|
109
|
+
const headers = {
|
|
110
|
+
"Authorization": `Bearer ${this.jwt}`,
|
|
111
|
+
"X-DAIN-SMART-ACCOUNT-ID": this.smartAccountId,
|
|
112
|
+
};
|
|
113
|
+
if (this.webhookUrl) {
|
|
114
|
+
headers["X-DAIN-WEBHOOK-URL"] = this.webhookUrl;
|
|
115
|
+
}
|
|
116
|
+
return headers;
|
|
117
|
+
}
|
|
118
|
+
// Legacy Authentication
|
|
59
119
|
return {
|
|
60
120
|
"X-DAIN-SIGNATURE": signature,
|
|
61
121
|
"X-DAIN-TIMESTAMP": timestamp,
|
|
62
122
|
"X-DAIN-AGENT-ID": this.agentId,
|
|
63
123
|
"X-DAIN-ORG-ID": this.orgId,
|
|
64
124
|
"X-DAIN-ADDRESS": bs58_1.default.encode(this.publicKey),
|
|
65
|
-
"X-DAIN-SMART-ACCOUNT-PDA": this.smartAccountPDA,
|
|
66
|
-
"X-DAIN-WEBHOOK-URL": this.webhookUrl,
|
|
125
|
+
"X-DAIN-SMART-ACCOUNT-PDA": this.smartAccountPDA || '',
|
|
126
|
+
"X-DAIN-WEBHOOK-URL": this.webhookUrl || '',
|
|
67
127
|
};
|
|
68
128
|
}
|
|
69
129
|
signMessage(message) {
|
|
130
|
+
if (this.authMethod === 'jwt') {
|
|
131
|
+
throw new Error('JWT auth does not support message signing');
|
|
132
|
+
}
|
|
70
133
|
const messageHash = (0, sha256_1.sha256)(message);
|
|
71
134
|
const signature = ed25519_1.ed25519.sign(messageHash, this.privateKey);
|
|
72
135
|
return (0, utils_1.bytesToHex)(signature);
|
|
@@ -75,14 +138,11 @@ class DainClientAuth {
|
|
|
75
138
|
const messageHash = (0, sha256_1.sha256)(message);
|
|
76
139
|
return ed25519_1.ed25519.verify(signature, messageHash, publicKey);
|
|
77
140
|
}
|
|
78
|
-
// Add a method to verify SSE event signatures
|
|
79
141
|
verifyEventSignature(data, signature, timestamp, publicKeyBase58) {
|
|
80
142
|
try {
|
|
81
|
-
// Combine data and timestamp to create the message that was signed
|
|
82
143
|
const message = `${data}:${timestamp}`;
|
|
83
144
|
const messageHash = (0, sha256_1.sha256)(message);
|
|
84
145
|
const publicKey = bs58_1.default.decode(publicKeyBase58);
|
|
85
|
-
// Verify the signature
|
|
86
146
|
return ed25519_1.ed25519.verify(signature, messageHash, publicKey);
|
|
87
147
|
}
|
|
88
148
|
catch (error) {
|
|
@@ -90,7 +150,16 @@ class DainClientAuth {
|
|
|
90
150
|
return false;
|
|
91
151
|
}
|
|
92
152
|
}
|
|
93
|
-
//
|
|
153
|
+
// Getters
|
|
154
|
+
getAuthMethod() {
|
|
155
|
+
return this.authMethod;
|
|
156
|
+
}
|
|
157
|
+
getJWT() {
|
|
158
|
+
return this.jwt;
|
|
159
|
+
}
|
|
160
|
+
getSmartAccountId() {
|
|
161
|
+
return this.smartAccountId;
|
|
162
|
+
}
|
|
94
163
|
getAgentId() {
|
|
95
164
|
return this.agentId;
|
|
96
165
|
}
|
|
@@ -101,7 +170,7 @@ class DainClientAuth {
|
|
|
101
170
|
return this.publicKey;
|
|
102
171
|
}
|
|
103
172
|
getPublicKeyBase58() {
|
|
104
|
-
return bs58_1.default.encode(this.publicKey);
|
|
173
|
+
return this.publicKey ? bs58_1.default.encode(this.publicKey) : undefined;
|
|
105
174
|
}
|
|
106
175
|
getSmartAccountPDA() {
|
|
107
176
|
return this.smartAccountPDA;
|
|
@@ -110,29 +179,47 @@ class DainClientAuth {
|
|
|
110
179
|
return this.webhookUrl;
|
|
111
180
|
}
|
|
112
181
|
serialize() {
|
|
182
|
+
if (this.authMethod === 'jwt') {
|
|
183
|
+
const data = {
|
|
184
|
+
authMethod: 'jwt',
|
|
185
|
+
jwt: this.jwt,
|
|
186
|
+
smartAccountId: this.smartAccountId,
|
|
187
|
+
webhookUrl: this.webhookUrl,
|
|
188
|
+
};
|
|
189
|
+
return bs58_1.default.encode(Buffer.from(JSON.stringify(data)));
|
|
190
|
+
}
|
|
113
191
|
const data = {
|
|
192
|
+
authMethod: 'legacy',
|
|
114
193
|
privateKey: Array.from(this.privateKey),
|
|
115
194
|
agentId: this.agentId,
|
|
116
195
|
orgId: this.orgId,
|
|
117
196
|
publicKey: Array.from(this.publicKey),
|
|
118
197
|
smartAccountPDA: this.smartAccountPDA,
|
|
119
|
-
webhookUrl: this.webhookUrl
|
|
198
|
+
webhookUrl: this.webhookUrl,
|
|
120
199
|
};
|
|
121
200
|
return bs58_1.default.encode(Buffer.from(JSON.stringify(data)));
|
|
122
201
|
}
|
|
123
202
|
static deserialize(serialized) {
|
|
124
203
|
try {
|
|
125
204
|
const data = JSON.parse(Buffer.from(bs58_1.default.decode(serialized)).toString());
|
|
205
|
+
if (data.authMethod === 'jwt') {
|
|
206
|
+
return new DainClientAuth({
|
|
207
|
+
jwt: data.jwt,
|
|
208
|
+
smartAccountId: data.smartAccountId,
|
|
209
|
+
webhookUrl: data.webhookUrl,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// Legacy or missing authMethod (backward compatibility)
|
|
126
213
|
return new DainClientAuth({
|
|
127
214
|
privateKeyBase58: bs58_1.default.encode(new Uint8Array(data.privateKey)),
|
|
128
215
|
agentId: data.agentId,
|
|
129
216
|
orgId: data.orgId,
|
|
130
217
|
smartAccountPDA: data.smartAccountPDA,
|
|
131
|
-
webhookUrl: data.webhookUrl
|
|
218
|
+
webhookUrl: data.webhookUrl,
|
|
132
219
|
});
|
|
133
220
|
}
|
|
134
221
|
catch (error) {
|
|
135
|
-
throw new Error(
|
|
222
|
+
throw new Error(`Failed to deserialize DainClientAuth: ${error.message}`);
|
|
136
223
|
}
|
|
137
224
|
}
|
|
138
225
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-auth.js","sourceRoot":"","sources":["../../src/client/client-auth.ts"],"names":[],"mappings":";;;;AAAA,iCAAiC;AACjC,mDAAgD;AAChD,iDAA8C;AAC9C,+CAAiD;AACjD,wDAAwB;
|
|
1
|
+
{"version":3,"file":"client-auth.js","sourceRoot":"","sources":["../../src/client/client-auth.ts"],"names":[],"mappings":";;;;AAAA,iCAAiC;AACjC,mDAAgD;AAChD,iDAA8C;AAC9C,+CAAiD;AACjD,wDAAwB;AAkBxB,MAAa,cAAc;IACzB,yBAAyB;IACjB,GAAG,CAAU;IACb,cAAc,CAAU;IAEhC,+BAA+B;IACvB,UAAU,CAAc;IACxB,OAAO,CAAU;IACjB,KAAK,CAAU;IACf,SAAS,CAAc;IACvB,eAAe,CAAU;IAEjC,SAAS;IACD,UAAU,CAAU;IACX,UAAU,CAAmB;IAE9C,YAAY,MAA4B;QACtC,sDAAsD;QACtD,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;YAEpC,kDAAkD;YAClD,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC1B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;YAC9C,CAAC;iBAAM,CAAC;gBACN,IAA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;aAC5B,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yCAAyC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;CACF;AAvQD,wCAuQC"}
|
package/dist/service/auth.d.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT AUTHENTICATION (for users from DAIN ID)
|
|
3
|
+
*/
|
|
4
|
+
export interface JWTPayload {
|
|
5
|
+
sub: string;
|
|
6
|
+
iss: string;
|
|
7
|
+
aud: string;
|
|
8
|
+
iat: number;
|
|
9
|
+
exp: number;
|
|
10
|
+
scope: string[];
|
|
11
|
+
smart_account_id: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AuthResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
smartAccountId?: string;
|
|
16
|
+
scope?: string[];
|
|
17
|
+
agentId?: string;
|
|
18
|
+
orgId?: string;
|
|
19
|
+
address?: string;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Verify JWT token from DAIN ID
|
|
24
|
+
* This should be used with a public key fetched from DAIN ID's JWKS endpoint
|
|
25
|
+
*/
|
|
26
|
+
export declare function verifyJWT(token: string, publicKeyOrJWKS: string | any): Promise<AuthResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Extract Bearer token from Authorization header
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractBearerToken(authHeader: string | undefined): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Check if token has required scope
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasRequiredScope(tokenScopes: string[], requiredScope: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* LEGACY AUTHENTICATION (for service-to-service)
|
|
37
|
+
*/
|
|
1
38
|
export declare function addressToPublicKeyBytes(address: string): Uint8Array;
|
|
2
39
|
export declare function signatureToBytes(signature: string): Uint8Array;
|
|
3
40
|
export declare function verifySignature(signature: string, message: string, address: string): boolean;
|
|
@@ -7,5 +44,5 @@ export declare function signResponse(privateKey: Uint8Array, responseBody: strin
|
|
|
7
44
|
timestamp: string;
|
|
8
45
|
};
|
|
9
46
|
export declare function verifyResponse(publicKey: Uint8Array, responseBody: string, signature: string, timestamp: string): boolean;
|
|
10
|
-
export declare function verifyRequestSignature(signature: string, method: string, path: string, headers: Record<string, string>, body: string, address: string, smartAccountPDA
|
|
47
|
+
export declare function verifyRequestSignature(signature: string, method: string, path: string, headers: Record<string, string>, body: string, address: string, smartAccountPDA?: string): boolean;
|
|
11
48
|
export declare function isValidSolanaAddress(address: string): boolean;
|