@dainprotocol/service-sdk 1.2.1 → 1.2.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/dist/client/client-auth.d.ts +65 -31
- package/dist/client/client-auth.js +108 -172
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/service-auth.d.ts +61 -0
- package/dist/client/service-auth.js +93 -0
- package/dist/client/service-auth.js.map +1 -0
- package/dist/client/user-auth.d.ts +74 -0
- package/dist/client/user-auth.js +137 -0
- package/dist/client/user-auth.js.map +1 -0
- package/dist/service/auth.d.ts +25 -35
- package/dist/service/auth.js +76 -77
- package/dist/service/auth.js.map +1 -1
- package/dist/service/server.js +52 -66
- package/dist/service/server.js.map +1 -1
- package/dist/service/types.d.ts +6 -0
- package/package.json +3 -1
|
@@ -1,51 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* CLIENT-SIDE JWT Authentication (Users Only)
|
|
3
|
+
*
|
|
4
|
+
* Users authenticate with JWT tokens from DAIN ID OAuth.
|
|
5
|
+
* NO orgId, NO agentId, NO keypair - completely removed for client-side.
|
|
6
|
+
*
|
|
7
|
+
* For SERVICE-SIDE keypair authentication (services/agents), see /src/service/auth.ts
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* JWT Authentication Config (Users)
|
|
11
|
+
*/
|
|
12
|
+
export interface DainClientAuthConfig {
|
|
13
|
+
/** JWT access token from DAIN ID OAuth */
|
|
14
|
+
jwt: string;
|
|
15
|
+
/** Smart Account ID (optional, will be extracted from JWT if not provided) */
|
|
3
16
|
smartAccountId?: string;
|
|
4
|
-
|
|
5
|
-
agentId?: string;
|
|
6
|
-
orgId?: string;
|
|
7
|
-
apiKey?: string;
|
|
17
|
+
/** Smart Account PDA on Solana (optional) */
|
|
8
18
|
smartAccountPDA?: string;
|
|
19
|
+
/** Webhook URL for async operations (optional) */
|
|
9
20
|
webhookUrl?: string;
|
|
10
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* DainClientAuth - JWT-only authentication for users
|
|
24
|
+
*
|
|
25
|
+
* This class is for CLIENT-SIDE use only (e.g., butterfly-web).
|
|
26
|
+
* Users authenticate with JWT tokens - NO keypairs, NO orgId, NO agentId.
|
|
27
|
+
*
|
|
28
|
+
* For SERVICE-SIDE authentication with keypairs, use the service SDK's built-in auth.
|
|
29
|
+
*/
|
|
11
30
|
export declare class DainClientAuth {
|
|
12
|
-
private jwt
|
|
13
|
-
private smartAccountId
|
|
14
|
-
private privateKey?;
|
|
15
|
-
private agentId?;
|
|
16
|
-
private orgId?;
|
|
17
|
-
private publicKey?;
|
|
31
|
+
private jwt;
|
|
32
|
+
private smartAccountId;
|
|
18
33
|
private smartAccountPDA?;
|
|
19
34
|
private webhookUrl?;
|
|
20
|
-
private readonly authMethod;
|
|
21
35
|
constructor(config: DainClientAuthConfig);
|
|
22
|
-
private parseApiKey;
|
|
23
36
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
37
|
+
* Decode JWT payload (without verification)
|
|
38
|
+
* @private
|
|
26
39
|
*/
|
|
27
|
-
|
|
40
|
+
private decodeJWTPayload;
|
|
41
|
+
/**
|
|
42
|
+
* Sign request - NOT NEEDED for JWT (returns empty for compatibility)
|
|
43
|
+
*/
|
|
44
|
+
signRequest(_method: string, _path: string, _body: string): Promise<{
|
|
28
45
|
signature: string;
|
|
29
46
|
timestamp: string;
|
|
30
47
|
}>;
|
|
31
48
|
/**
|
|
32
|
-
* Get headers for
|
|
33
|
-
|
|
49
|
+
* Get headers for HTTP requests
|
|
50
|
+
*/
|
|
51
|
+
getHeaders(_signature: string, _timestamp: string): Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Check if using JWT authentication (always true for client-side)
|
|
54
|
+
*/
|
|
55
|
+
isJWT(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Get JWT token
|
|
58
|
+
*/
|
|
59
|
+
getJWT(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Get smart account ID
|
|
62
|
+
*/
|
|
63
|
+
getSmartAccountId(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Get smart account PDA
|
|
34
66
|
*/
|
|
35
|
-
getHeaders(signature: string, timestamp: string): Record<string, string>;
|
|
36
|
-
signMessage(message: string): string;
|
|
37
|
-
static verifyMessage(message: string, signature: string, publicKey: Uint8Array): boolean;
|
|
38
|
-
verifyEventSignature(data: string, signature: string, timestamp: string, publicKeyBase58: string): boolean;
|
|
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;
|
|
46
67
|
getSmartAccountPDA(): string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get webhook URL
|
|
70
|
+
*/
|
|
47
71
|
getWebhookUrl(): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Verify SSE event signature from service
|
|
74
|
+
* (Services sign their event responses, users verify them)
|
|
75
|
+
*/
|
|
76
|
+
verifyEventSignature(data: string, signature: string, timestamp: string, publicKeyBase58: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Serialize auth config
|
|
79
|
+
*/
|
|
48
80
|
serialize(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Deserialize auth config
|
|
83
|
+
*/
|
|
49
84
|
static deserialize(serialized: string): DainClientAuth;
|
|
50
85
|
}
|
|
51
|
-
export {};
|
|
@@ -1,225 +1,161 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
//File: src/client/client-auth.ts
|
|
3
|
+
/**
|
|
4
|
+
* CLIENT-SIDE JWT Authentication (Users Only)
|
|
5
|
+
*
|
|
6
|
+
* Users authenticate with JWT tokens from DAIN ID OAuth.
|
|
7
|
+
* NO orgId, NO agentId, NO keypair - completely removed for client-side.
|
|
8
|
+
*
|
|
9
|
+
* For SERVICE-SIDE keypair authentication (services/agents), see /src/service/auth.ts
|
|
10
|
+
*/
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DainClientAuth = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* DainClientAuth - JWT-only authentication for users
|
|
15
|
+
*
|
|
16
|
+
* This class is for CLIENT-SIDE use only (e.g., butterfly-web).
|
|
17
|
+
* Users authenticate with JWT tokens - NO keypairs, NO orgId, NO agentId.
|
|
18
|
+
*
|
|
19
|
+
* For SERVICE-SIDE authentication with keypairs, use the service SDK's built-in auth.
|
|
20
|
+
*/
|
|
10
21
|
class DainClientAuth {
|
|
11
|
-
// JWT fields (user auth)
|
|
12
22
|
jwt;
|
|
13
23
|
smartAccountId;
|
|
14
|
-
// Legacy fields (service auth)
|
|
15
|
-
privateKey;
|
|
16
|
-
agentId;
|
|
17
|
-
orgId;
|
|
18
|
-
publicKey;
|
|
19
24
|
smartAccountPDA;
|
|
20
|
-
// Common
|
|
21
25
|
webhookUrl;
|
|
22
|
-
authMethod;
|
|
23
26
|
constructor(config) {
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
27
|
+
if (!config.jwt) {
|
|
28
|
+
throw new Error('JWT token is required for user authentication');
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
this.agentId = agentId;
|
|
52
|
-
this.orgId = orgId;
|
|
53
|
-
this.publicKey = publicKey;
|
|
54
|
-
this.webhookUrl = config.webhookUrl;
|
|
55
|
-
this.smartAccountPDA = config.smartAccountPDA;
|
|
56
|
-
this.authMethod = 'legacy';
|
|
57
|
-
return;
|
|
30
|
+
this.jwt = config.jwt;
|
|
31
|
+
// Extract smartAccountId from config or decode from JWT
|
|
32
|
+
if (config.smartAccountId) {
|
|
33
|
+
this.smartAccountId = config.smartAccountId;
|
|
58
34
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
this.agentId = config.agentId.replace('agent_', '');
|
|
63
|
-
this.orgId = config.orgId.replace('org_', '');
|
|
64
|
-
this.publicKey = ed25519_1.ed25519.getPublicKey(this.privateKey);
|
|
65
|
-
this.webhookUrl = config.webhookUrl;
|
|
66
|
-
this.smartAccountPDA = config.smartAccountPDA;
|
|
67
|
-
this.authMethod = 'legacy';
|
|
68
|
-
return;
|
|
35
|
+
else {
|
|
36
|
+
const payload = this.decodeJWTPayload(config.jwt);
|
|
37
|
+
this.smartAccountId = payload.smart_account_id || payload.sub;
|
|
69
38
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
' - apiKey OR (privateKeyBase58 + agentId + orgId) (for services)');
|
|
39
|
+
this.smartAccountPDA = config.smartAccountPDA;
|
|
40
|
+
this.webhookUrl = config.webhookUrl;
|
|
73
41
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Decode JWT payload (without verification)
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
decodeJWTPayload(jwt) {
|
|
47
|
+
const parts = jwt.split('.');
|
|
48
|
+
if (parts.length !== 3) {
|
|
49
|
+
throw new Error('Invalid JWT format');
|
|
78
50
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const privateKeyBase58 = parts[4];
|
|
82
|
-
const privateKey = bs58_1.default.decode(privateKeyBase58).slice(0, 32);
|
|
83
|
-
const publicKey = bs58_1.default.decode(privateKeyBase58).slice(32);
|
|
84
|
-
return { privateKey, agentId, orgId, publicKey };
|
|
51
|
+
const payload = Buffer.from(parts[1], 'base64').toString('utf-8');
|
|
52
|
+
return JSON.parse(payload);
|
|
85
53
|
}
|
|
86
54
|
/**
|
|
87
|
-
* Sign request for
|
|
88
|
-
* For JWT auth, returns empty values (not needed)
|
|
55
|
+
* Sign request - NOT NEEDED for JWT (returns empty for compatibility)
|
|
89
56
|
*/
|
|
90
|
-
async signRequest(
|
|
91
|
-
|
|
92
|
-
// JWT doesn't need request signing
|
|
93
|
-
return { signature: '', timestamp: '' };
|
|
94
|
-
}
|
|
95
|
-
// Legacy: Sign request
|
|
96
|
-
const timestamp = Date.now().toString();
|
|
97
|
-
const message = `${method}:${path}:${timestamp}:${body}`;
|
|
98
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
99
|
-
const signature = ed25519_1.ed25519.sign(messageHash, this.privateKey);
|
|
100
|
-
return { signature: (0, utils_1.bytesToHex)(signature), timestamp };
|
|
57
|
+
async signRequest(_method, _path, _body) {
|
|
58
|
+
return { signature: '', timestamp: '' };
|
|
101
59
|
}
|
|
102
60
|
/**
|
|
103
|
-
* Get headers for
|
|
104
|
-
* Returns different headers based on auth method
|
|
61
|
+
* Get headers for HTTP requests
|
|
105
62
|
*/
|
|
106
|
-
getHeaders(
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
119
|
-
return {
|
|
120
|
-
"X-DAIN-SIGNATURE": signature,
|
|
121
|
-
"X-DAIN-TIMESTAMP": timestamp,
|
|
122
|
-
"X-DAIN-AGENT-ID": this.agentId,
|
|
123
|
-
"X-DAIN-ORG-ID": this.orgId,
|
|
124
|
-
"X-DAIN-ADDRESS": bs58_1.default.encode(this.publicKey),
|
|
125
|
-
"X-DAIN-SMART-ACCOUNT-PDA": this.smartAccountPDA || '',
|
|
126
|
-
"X-DAIN-WEBHOOK-URL": this.webhookUrl || '',
|
|
63
|
+
getHeaders(_signature, _timestamp) {
|
|
64
|
+
const headers = {
|
|
65
|
+
"Authorization": `Bearer ${this.jwt}`,
|
|
127
66
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (this.authMethod === 'jwt') {
|
|
131
|
-
throw new Error('JWT auth does not support message signing');
|
|
67
|
+
if (this.smartAccountPDA) {
|
|
68
|
+
headers["X-DAIN-SMART-ACCOUNT-PDA"] = this.smartAccountPDA;
|
|
132
69
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return (0, utils_1.bytesToHex)(signature);
|
|
136
|
-
}
|
|
137
|
-
static verifyMessage(message, signature, publicKey) {
|
|
138
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
139
|
-
return ed25519_1.ed25519.verify(signature, messageHash, publicKey);
|
|
140
|
-
}
|
|
141
|
-
verifyEventSignature(data, signature, timestamp, publicKeyBase58) {
|
|
142
|
-
try {
|
|
143
|
-
const message = `${data}:${timestamp}`;
|
|
144
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
145
|
-
const publicKey = bs58_1.default.decode(publicKeyBase58);
|
|
146
|
-
return ed25519_1.ed25519.verify(signature, messageHash, publicKey);
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
console.error('Error verifying event signature:', error);
|
|
150
|
-
return false;
|
|
70
|
+
if (this.webhookUrl) {
|
|
71
|
+
headers["X-DAIN-WEBHOOK-URL"] = this.webhookUrl;
|
|
151
72
|
}
|
|
73
|
+
return headers;
|
|
152
74
|
}
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
75
|
+
// ===== Getter Methods =====
|
|
76
|
+
/**
|
|
77
|
+
* Check if using JWT authentication (always true for client-side)
|
|
78
|
+
*/
|
|
79
|
+
isJWT() {
|
|
80
|
+
return true;
|
|
156
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Get JWT token
|
|
84
|
+
*/
|
|
157
85
|
getJWT() {
|
|
158
86
|
return this.jwt;
|
|
159
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Get smart account ID
|
|
90
|
+
*/
|
|
160
91
|
getSmartAccountId() {
|
|
161
92
|
return this.smartAccountId;
|
|
162
93
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
getOrgId() {
|
|
167
|
-
return this.orgId;
|
|
168
|
-
}
|
|
169
|
-
getPublicKey() {
|
|
170
|
-
return this.publicKey;
|
|
171
|
-
}
|
|
172
|
-
getPublicKeyBase58() {
|
|
173
|
-
return this.publicKey ? bs58_1.default.encode(this.publicKey) : undefined;
|
|
174
|
-
}
|
|
94
|
+
/**
|
|
95
|
+
* Get smart account PDA
|
|
96
|
+
*/
|
|
175
97
|
getSmartAccountPDA() {
|
|
176
98
|
return this.smartAccountPDA;
|
|
177
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Get webhook URL
|
|
102
|
+
*/
|
|
178
103
|
getWebhookUrl() {
|
|
179
104
|
return this.webhookUrl;
|
|
180
105
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Verify SSE event signature from service
|
|
108
|
+
* (Services sign their event responses, users verify them)
|
|
109
|
+
*/
|
|
110
|
+
verifyEventSignature(data, signature, timestamp, publicKeyBase58) {
|
|
111
|
+
try {
|
|
112
|
+
// This is for verifying SERVICE signatures, not user signatures
|
|
113
|
+
// Import crypto libs only when needed
|
|
114
|
+
const { ed25519 } = require("@noble/curves/ed25519");
|
|
115
|
+
const { sha256 } = require("@noble/hashes/sha256");
|
|
116
|
+
const bs58 = require("bs58");
|
|
117
|
+
const message = `${data}:${timestamp}`;
|
|
118
|
+
const messageHash = sha256(message);
|
|
119
|
+
const publicKey = bs58.decode(publicKeyBase58);
|
|
120
|
+
return ed25519.verify(signature, messageHash, publicKey);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error('Error verifying event signature:', error);
|
|
124
|
+
return false;
|
|
190
125
|
}
|
|
126
|
+
}
|
|
127
|
+
// ===== Serialization =====
|
|
128
|
+
/**
|
|
129
|
+
* Serialize auth config
|
|
130
|
+
*/
|
|
131
|
+
serialize() {
|
|
191
132
|
const data = {
|
|
192
|
-
authMethod: '
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
orgId: this.orgId,
|
|
196
|
-
publicKey: Array.from(this.publicKey),
|
|
133
|
+
authMethod: 'jwt',
|
|
134
|
+
jwt: this.jwt,
|
|
135
|
+
smartAccountId: this.smartAccountId,
|
|
197
136
|
smartAccountPDA: this.smartAccountPDA,
|
|
198
|
-
webhookUrl: this.webhookUrl
|
|
137
|
+
webhookUrl: this.webhookUrl
|
|
199
138
|
};
|
|
200
|
-
return
|
|
139
|
+
return Buffer.from(JSON.stringify(data)).toString('base64');
|
|
201
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Deserialize auth config
|
|
143
|
+
*/
|
|
202
144
|
static deserialize(serialized) {
|
|
203
145
|
try {
|
|
204
|
-
const data = JSON.parse(Buffer.from(
|
|
205
|
-
if (data.authMethod
|
|
206
|
-
|
|
207
|
-
jwt: data.jwt,
|
|
208
|
-
smartAccountId: data.smartAccountId,
|
|
209
|
-
webhookUrl: data.webhookUrl,
|
|
210
|
-
});
|
|
146
|
+
const data = JSON.parse(Buffer.from(serialized, 'base64').toString());
|
|
147
|
+
if (data.authMethod !== 'jwt') {
|
|
148
|
+
throw new Error('Invalid auth method - client-side only supports JWT');
|
|
211
149
|
}
|
|
212
|
-
// Legacy or missing authMethod (backward compatibility)
|
|
213
150
|
return new DainClientAuth({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
orgId: data.orgId,
|
|
151
|
+
jwt: data.jwt,
|
|
152
|
+
smartAccountId: data.smartAccountId,
|
|
217
153
|
smartAccountPDA: data.smartAccountPDA,
|
|
218
|
-
webhookUrl: data.webhookUrl
|
|
154
|
+
webhookUrl: data.webhookUrl
|
|
219
155
|
});
|
|
220
156
|
}
|
|
221
157
|
catch (error) {
|
|
222
|
-
throw new Error(
|
|
158
|
+
throw new Error('Failed to deserialize DainClientAuth: ' + error.message);
|
|
223
159
|
}
|
|
224
160
|
}
|
|
225
161
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-auth.js","sourceRoot":"","sources":["../../src/client/client-auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client-auth.js","sourceRoot":"","sources":["../../src/client/client-auth.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC;;;;;;;GAOG;;;AAmBH;;;;;;;GAOG;AACH,MAAa,cAAc;IACjB,GAAG,CAAS;IACZ,cAAc,CAAS;IACvB,eAAe,CAAU;IACzB,UAAU,CAAU;IAE5B,YAAY,MAA4B;QACtC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,+CAA+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true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./client"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./client-auth"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./client-auth"), exports); // Unified auth: JWT (users) + Keypair (services/agents)
|
|
6
6
|
tslib_1.__exportStar(require("./api-sdk"), exports);
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,wDAA8B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,wDAA8B,CAAE,wDAAwD;AACxF,oDAA0B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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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