@dainprotocol/service-sdk 1.2.2 → 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 +29 -76
- package/dist/client/client-auth.js +75 -226
- package/dist/client/client-auth.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,15 @@
|
|
|
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
|
+
*/
|
|
1
9
|
/**
|
|
2
10
|
* JWT Authentication Config (Users)
|
|
3
11
|
*/
|
|
4
|
-
export interface
|
|
12
|
+
export interface DainClientAuthConfig {
|
|
5
13
|
/** JWT access token from DAIN ID OAuth */
|
|
6
14
|
jwt: string;
|
|
7
15
|
/** Smart Account ID (optional, will be extracted from JWT if not provided) */
|
|
@@ -12,39 +20,16 @@ export interface DainClientAuthConfigJWT {
|
|
|
12
20
|
webhookUrl?: string;
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
privateKeyBase58?: string;
|
|
20
|
-
/** Agent ID */
|
|
21
|
-
agentId?: string;
|
|
22
|
-
/** Organization ID */
|
|
23
|
-
orgId?: string;
|
|
24
|
-
/** API Key (alternative to privateKeyBase58/agentId/orgId) */
|
|
25
|
-
apiKey?: string;
|
|
26
|
-
/** Smart Account PDA on Solana (optional) */
|
|
27
|
-
smartAccountPDA?: string;
|
|
28
|
-
/** Webhook URL for async operations (optional) */
|
|
29
|
-
webhookUrl?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Union type for authentication config
|
|
33
|
-
*/
|
|
34
|
-
export type DainClientAuthConfig = DainClientAuthConfigJWT | DainClientAuthConfigKeypair;
|
|
35
|
-
/**
|
|
36
|
-
* Unified DainClientAuth class
|
|
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.
|
|
37
27
|
*
|
|
38
|
-
*
|
|
28
|
+
* For SERVICE-SIDE authentication with keypairs, use the service SDK's built-in auth.
|
|
39
29
|
*/
|
|
40
30
|
export declare class DainClientAuth {
|
|
41
|
-
private
|
|
42
|
-
private
|
|
43
|
-
private smartAccountId?;
|
|
44
|
-
private privateKey?;
|
|
45
|
-
private agentId?;
|
|
46
|
-
private orgId?;
|
|
47
|
-
private publicKey?;
|
|
31
|
+
private jwt;
|
|
32
|
+
private smartAccountId;
|
|
48
33
|
private smartAccountPDA?;
|
|
49
34
|
private webhookUrl?;
|
|
50
35
|
constructor(config: DainClientAuthConfig);
|
|
@@ -54,65 +39,28 @@ export declare class DainClientAuth {
|
|
|
54
39
|
*/
|
|
55
40
|
private decodeJWTPayload;
|
|
56
41
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
|
-
private parseApiKey;
|
|
61
|
-
/**
|
|
62
|
-
* Sign request
|
|
63
|
-
* - JWT mode: returns empty (no signing needed)
|
|
64
|
-
* - Keypair mode: signs with Ed25519
|
|
42
|
+
* Sign request - NOT NEEDED for JWT (returns empty for compatibility)
|
|
65
43
|
*/
|
|
66
|
-
signRequest(
|
|
44
|
+
signRequest(_method: string, _path: string, _body: string): Promise<{
|
|
67
45
|
signature: string;
|
|
68
46
|
timestamp: string;
|
|
69
47
|
}>;
|
|
70
48
|
/**
|
|
71
49
|
* Get headers for HTTP requests
|
|
72
|
-
* - JWT mode: returns Authorization Bearer header
|
|
73
|
-
* - Keypair mode: returns signature headers
|
|
74
50
|
*/
|
|
75
|
-
getHeaders(
|
|
51
|
+
getHeaders(_signature: string, _timestamp: string): Record<string, string>;
|
|
76
52
|
/**
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
signMessage(message: string): string;
|
|
80
|
-
/**
|
|
81
|
-
* Verify a message signature (static method)
|
|
82
|
-
*/
|
|
83
|
-
static verifyMessage(message: string, signature: string, publicKey: Uint8Array): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Verify SSE event signature (keypair mode only)
|
|
86
|
-
*/
|
|
87
|
-
verifyEventSignature(data: string, signature: string, timestamp: string, publicKeyBase58: string): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Check if using JWT authentication
|
|
53
|
+
* Check if using JWT authentication (always true for client-side)
|
|
90
54
|
*/
|
|
91
55
|
isJWT(): boolean;
|
|
92
56
|
/**
|
|
93
|
-
* Get JWT token
|
|
94
|
-
*/
|
|
95
|
-
getJWT(): string | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Get smart account ID (JWT mode only)
|
|
57
|
+
* Get JWT token
|
|
98
58
|
*/
|
|
99
|
-
|
|
59
|
+
getJWT(): string;
|
|
100
60
|
/**
|
|
101
|
-
* Get
|
|
61
|
+
* Get smart account ID
|
|
102
62
|
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Get org ID (keypair mode only)
|
|
106
|
-
*/
|
|
107
|
-
getOrgId(): string | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* Get public key (keypair mode only)
|
|
110
|
-
*/
|
|
111
|
-
getPublicKey(): Uint8Array | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Get public key as base58 (keypair mode only)
|
|
114
|
-
*/
|
|
115
|
-
getPublicKeyBase58(): string | undefined;
|
|
63
|
+
getSmartAccountId(): string;
|
|
116
64
|
/**
|
|
117
65
|
* Get smart account PDA
|
|
118
66
|
*/
|
|
@@ -121,6 +69,11 @@ export declare class DainClientAuth {
|
|
|
121
69
|
* Get webhook URL
|
|
122
70
|
*/
|
|
123
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;
|
|
124
77
|
/**
|
|
125
78
|
* Serialize auth config
|
|
126
79
|
*/
|
|
@@ -1,85 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DainClientAuth = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
2
|
//File: src/client/client-auth.ts
|
|
6
3
|
/**
|
|
7
|
-
*
|
|
4
|
+
* CLIENT-SIDE JWT Authentication (Users Only)
|
|
8
5
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
const ed25519_1 = require("@noble/curves/ed25519");
|
|
14
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
15
|
-
const utils_1 = require("@noble/hashes/utils");
|
|
16
|
-
const bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
17
|
-
/**
|
|
18
|
-
* Type guard to check if config is JWT
|
|
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
|
|
19
10
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DainClientAuth = void 0;
|
|
23
13
|
/**
|
|
24
|
-
*
|
|
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.
|
|
25
18
|
*
|
|
26
|
-
*
|
|
19
|
+
* For SERVICE-SIDE authentication with keypairs, use the service SDK's built-in auth.
|
|
27
20
|
*/
|
|
28
21
|
class DainClientAuth {
|
|
29
|
-
// Auth type
|
|
30
|
-
authType;
|
|
31
|
-
// JWT fields (users only)
|
|
32
22
|
jwt;
|
|
33
23
|
smartAccountId;
|
|
34
|
-
// Keypair fields (services/agents only)
|
|
35
|
-
privateKey;
|
|
36
|
-
agentId;
|
|
37
|
-
orgId;
|
|
38
|
-
publicKey;
|
|
39
|
-
// Shared fields
|
|
40
24
|
smartAccountPDA;
|
|
41
25
|
webhookUrl;
|
|
42
26
|
constructor(config) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
// Extract smartAccountId from config or decode from JWT
|
|
51
|
-
if (config.smartAccountId) {
|
|
52
|
-
this.smartAccountId = config.smartAccountId;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
const payload = this.decodeJWTPayload(config.jwt);
|
|
56
|
-
this.smartAccountId = payload.smart_account_id || payload.sub;
|
|
57
|
-
}
|
|
58
|
-
this.smartAccountPDA = config.smartAccountPDA;
|
|
59
|
-
this.webhookUrl = config.webhookUrl;
|
|
27
|
+
if (!config.jwt) {
|
|
28
|
+
throw new Error('JWT token is required for user authentication');
|
|
29
|
+
}
|
|
30
|
+
this.jwt = config.jwt;
|
|
31
|
+
// Extract smartAccountId from config or decode from JWT
|
|
32
|
+
if (config.smartAccountId) {
|
|
33
|
+
this.smartAccountId = config.smartAccountId;
|
|
60
34
|
}
|
|
61
35
|
else {
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
if (config.apiKey) {
|
|
65
|
-
const { privateKey, agentId, orgId, publicKey } = this.parseApiKey(config.apiKey);
|
|
66
|
-
this.privateKey = privateKey;
|
|
67
|
-
this.agentId = agentId;
|
|
68
|
-
this.orgId = orgId;
|
|
69
|
-
this.publicKey = publicKey;
|
|
70
|
-
}
|
|
71
|
-
else if (config.privateKeyBase58 && config.agentId && config.orgId) {
|
|
72
|
-
this.privateKey = bs58_1.default.decode(config.privateKeyBase58);
|
|
73
|
-
this.agentId = config.agentId.replace('agent_', '');
|
|
74
|
-
this.orgId = config.orgId.replace('org_', '');
|
|
75
|
-
this.publicKey = ed25519_1.ed25519.getPublicKey(this.privateKey);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
throw new Error('Invalid configuration. Provide either jwt (for users) or apiKey/privateKeyBase58+agentId+orgId (for services/agents).');
|
|
79
|
-
}
|
|
80
|
-
this.smartAccountPDA = config.smartAccountPDA;
|
|
81
|
-
this.webhookUrl = config.webhookUrl;
|
|
36
|
+
const payload = this.decodeJWTPayload(config.jwt);
|
|
37
|
+
this.smartAccountId = payload.smart_account_id || payload.sub;
|
|
82
38
|
}
|
|
39
|
+
this.smartAccountPDA = config.smartAccountPDA;
|
|
40
|
+
this.webhookUrl = config.webhookUrl;
|
|
83
41
|
}
|
|
84
42
|
/**
|
|
85
43
|
* Decode JWT payload (without verification)
|
|
@@ -94,144 +52,45 @@ class DainClientAuth {
|
|
|
94
52
|
return JSON.parse(payload);
|
|
95
53
|
}
|
|
96
54
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @private
|
|
99
|
-
*/
|
|
100
|
-
parseApiKey(apiKey) {
|
|
101
|
-
const parts = apiKey.split('_');
|
|
102
|
-
if (parts.length !== 5 || parts[0] !== 'sk' || parts[1] !== 'agent') {
|
|
103
|
-
throw new Error('Invalid API key format');
|
|
104
|
-
}
|
|
105
|
-
const orgId = parts[2].replace('org_', '');
|
|
106
|
-
const agentId = parts[3].replace('agent_', '');
|
|
107
|
-
const privateKeyBase58 = parts[4];
|
|
108
|
-
const privateKey = bs58_1.default.decode(privateKeyBase58).slice(0, 32);
|
|
109
|
-
const publicKey = bs58_1.default.decode(privateKeyBase58).slice(32);
|
|
110
|
-
return { privateKey, agentId, orgId, publicKey };
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Sign request
|
|
114
|
-
* - JWT mode: returns empty (no signing needed)
|
|
115
|
-
* - Keypair mode: signs with Ed25519
|
|
55
|
+
* Sign request - NOT NEEDED for JWT (returns empty for compatibility)
|
|
116
56
|
*/
|
|
117
|
-
async signRequest(
|
|
118
|
-
|
|
119
|
-
// JWT doesn't need request signing
|
|
120
|
-
return { signature: '', timestamp: '' };
|
|
121
|
-
}
|
|
122
|
-
// Keypair signing for services/agents
|
|
123
|
-
const timestamp = Date.now().toString();
|
|
124
|
-
const message = `${method}:${path}:${timestamp}:${body}`;
|
|
125
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
126
|
-
const signature = ed25519_1.ed25519.sign(messageHash, this.privateKey);
|
|
127
|
-
return { signature: (0, utils_1.bytesToHex)(signature), timestamp };
|
|
57
|
+
async signRequest(_method, _path, _body) {
|
|
58
|
+
return { signature: '', timestamp: '' };
|
|
128
59
|
}
|
|
129
60
|
/**
|
|
130
61
|
* Get headers for HTTP requests
|
|
131
|
-
* - JWT mode: returns Authorization Bearer header
|
|
132
|
-
* - Keypair mode: returns signature headers
|
|
133
62
|
*/
|
|
134
|
-
getHeaders(
|
|
135
|
-
const
|
|
63
|
+
getHeaders(_signature, _timestamp) {
|
|
64
|
+
const headers = {
|
|
65
|
+
"Authorization": `Bearer ${this.jwt}`,
|
|
66
|
+
};
|
|
136
67
|
if (this.smartAccountPDA) {
|
|
137
|
-
|
|
68
|
+
headers["X-DAIN-SMART-ACCOUNT-PDA"] = this.smartAccountPDA;
|
|
138
69
|
}
|
|
139
70
|
if (this.webhookUrl) {
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
if (this.authType === 'jwt') {
|
|
143
|
-
// JWT authentication headers
|
|
144
|
-
return {
|
|
145
|
-
...baseHeaders,
|
|
146
|
-
"Authorization": `Bearer ${this.jwt}`,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
// Keypair authentication headers
|
|
150
|
-
return {
|
|
151
|
-
...baseHeaders,
|
|
152
|
-
"X-DAIN-SIGNATURE": signature,
|
|
153
|
-
"X-DAIN-TIMESTAMP": timestamp,
|
|
154
|
-
"X-DAIN-AGENT-ID": this.agentId,
|
|
155
|
-
"X-DAIN-ORG-ID": this.orgId,
|
|
156
|
-
"X-DAIN-ADDRESS": bs58_1.default.encode(this.publicKey),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Sign a message (keypair mode only)
|
|
161
|
-
*/
|
|
162
|
-
signMessage(message) {
|
|
163
|
-
if (this.authType === 'jwt') {
|
|
164
|
-
throw new Error('signMessage not available in JWT mode');
|
|
165
|
-
}
|
|
166
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
167
|
-
const signature = ed25519_1.ed25519.sign(messageHash, this.privateKey);
|
|
168
|
-
return (0, utils_1.bytesToHex)(signature);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Verify a message signature (static method)
|
|
172
|
-
*/
|
|
173
|
-
static verifyMessage(message, signature, publicKey) {
|
|
174
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
175
|
-
return ed25519_1.ed25519.verify(signature, messageHash, publicKey);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Verify SSE event signature (keypair mode only)
|
|
179
|
-
*/
|
|
180
|
-
verifyEventSignature(data, signature, timestamp, publicKeyBase58) {
|
|
181
|
-
try {
|
|
182
|
-
const message = `${data}:${timestamp}`;
|
|
183
|
-
const messageHash = (0, sha256_1.sha256)(message);
|
|
184
|
-
const publicKey = bs58_1.default.decode(publicKeyBase58);
|
|
185
|
-
return ed25519_1.ed25519.verify(signature, messageHash, publicKey);
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
console.error('Error verifying event signature:', error);
|
|
189
|
-
return false;
|
|
71
|
+
headers["X-DAIN-WEBHOOK-URL"] = this.webhookUrl;
|
|
190
72
|
}
|
|
73
|
+
return headers;
|
|
191
74
|
}
|
|
192
75
|
// ===== Getter Methods =====
|
|
193
76
|
/**
|
|
194
|
-
* Check if using JWT authentication
|
|
77
|
+
* Check if using JWT authentication (always true for client-side)
|
|
195
78
|
*/
|
|
196
79
|
isJWT() {
|
|
197
|
-
return
|
|
80
|
+
return true;
|
|
198
81
|
}
|
|
199
82
|
/**
|
|
200
|
-
* Get JWT token
|
|
83
|
+
* Get JWT token
|
|
201
84
|
*/
|
|
202
85
|
getJWT() {
|
|
203
86
|
return this.jwt;
|
|
204
87
|
}
|
|
205
88
|
/**
|
|
206
|
-
* Get smart account ID
|
|
89
|
+
* Get smart account ID
|
|
207
90
|
*/
|
|
208
91
|
getSmartAccountId() {
|
|
209
92
|
return this.smartAccountId;
|
|
210
93
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Get agent ID (keypair mode only)
|
|
213
|
-
*/
|
|
214
|
-
getAgentId() {
|
|
215
|
-
return this.agentId;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Get org ID (keypair mode only)
|
|
219
|
-
*/
|
|
220
|
-
getOrgId() {
|
|
221
|
-
return this.orgId;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Get public key (keypair mode only)
|
|
225
|
-
*/
|
|
226
|
-
getPublicKey() {
|
|
227
|
-
return this.publicKey;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Get public key as base58 (keypair mode only)
|
|
231
|
-
*/
|
|
232
|
-
getPublicKeyBase58() {
|
|
233
|
-
return this.publicKey ? bs58_1.default.encode(this.publicKey) : undefined;
|
|
234
|
-
}
|
|
235
94
|
/**
|
|
236
95
|
* Get smart account PDA
|
|
237
96
|
*/
|
|
@@ -244,66 +103,56 @@ class DainClientAuth {
|
|
|
244
103
|
getWebhookUrl() {
|
|
245
104
|
return this.webhookUrl;
|
|
246
105
|
}
|
|
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;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
247
127
|
// ===== Serialization =====
|
|
248
128
|
/**
|
|
249
129
|
* Serialize auth config
|
|
250
130
|
*/
|
|
251
131
|
serialize() {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return Buffer.from(JSON.stringify(data)).toString('base64');
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
const data = {
|
|
264
|
-
authMethod: 'keypair',
|
|
265
|
-
privateKey: Array.from(this.privateKey),
|
|
266
|
-
agentId: this.agentId,
|
|
267
|
-
orgId: this.orgId,
|
|
268
|
-
publicKey: Array.from(this.publicKey),
|
|
269
|
-
smartAccountPDA: this.smartAccountPDA,
|
|
270
|
-
webhookUrl: this.webhookUrl
|
|
271
|
-
};
|
|
272
|
-
return bs58_1.default.encode(Buffer.from(JSON.stringify(data)));
|
|
273
|
-
}
|
|
132
|
+
const data = {
|
|
133
|
+
authMethod: 'jwt',
|
|
134
|
+
jwt: this.jwt,
|
|
135
|
+
smartAccountId: this.smartAccountId,
|
|
136
|
+
smartAccountPDA: this.smartAccountPDA,
|
|
137
|
+
webhookUrl: this.webhookUrl
|
|
138
|
+
};
|
|
139
|
+
return Buffer.from(JSON.stringify(data)).toString('base64');
|
|
274
140
|
}
|
|
275
141
|
/**
|
|
276
142
|
* Deserialize auth config
|
|
277
143
|
*/
|
|
278
144
|
static deserialize(serialized) {
|
|
279
145
|
try {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (data.authMethod === 'jwt') {
|
|
284
|
-
return new DainClientAuth({
|
|
285
|
-
jwt: data.jwt,
|
|
286
|
-
smartAccountId: data.smartAccountId,
|
|
287
|
-
smartAccountPDA: data.smartAccountPDA,
|
|
288
|
-
webhookUrl: data.webhookUrl
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
catch {
|
|
293
|
-
// Not JWT format, try keypair
|
|
294
|
-
}
|
|
295
|
-
// Try keypair format (bs58)
|
|
296
|
-
const data = JSON.parse(Buffer.from(bs58_1.default.decode(serialized)).toString());
|
|
297
|
-
if (data.authMethod === 'keypair') {
|
|
298
|
-
return new DainClientAuth({
|
|
299
|
-
privateKeyBase58: bs58_1.default.encode(new Uint8Array(data.privateKey)),
|
|
300
|
-
agentId: data.agentId,
|
|
301
|
-
orgId: data.orgId,
|
|
302
|
-
smartAccountPDA: data.smartAccountPDA,
|
|
303
|
-
webhookUrl: data.webhookUrl
|
|
304
|
-
});
|
|
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');
|
|
305
149
|
}
|
|
306
|
-
|
|
150
|
+
return new DainClientAuth({
|
|
151
|
+
jwt: data.jwt,
|
|
152
|
+
smartAccountId: data.smartAccountId,
|
|
153
|
+
smartAccountPDA: data.smartAccountPDA,
|
|
154
|
+
webhookUrl: data.webhookUrl
|
|
155
|
+
});
|
|
307
156
|
}
|
|
308
157
|
catch (error) {
|
|
309
158
|
throw new Error('Failed to deserialize DainClientAuth: ' + error.message);
|
|
@@ -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+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,GAAG,MAAM,CAAC,UAAU,CAAC;IACtC,CAAC;IAED;;;OAGG;IACK,gBAAgB,CAAC,GAAW;QAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,CAAC,IA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