@dainprotocol/service-sdk 2.0.78 → 2.0.79
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/api-sdk.d.ts +5 -42
- package/dist/client/api-sdk.js +130 -261
- package/dist/client/api-sdk.js.map +1 -1
- package/dist/client/client-auth.d.ts +1 -69
- package/dist/client/client-auth.js +26 -105
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/client.d.ts +25 -116
- package/dist/client/client.js +157 -758
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.js +9 -14
- package/dist/client/types.js.map +1 -1
- package/dist/extensions/telegram-oauth.d.ts +6 -2
- package/dist/extensions/telegram-oauth.js +30 -57
- package/dist/extensions/telegram-oauth.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -26
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/lib/convertToVercelTool.d.ts +11 -3
- package/dist/lib/convertToVercelTool.js +0 -1
- package/dist/lib/convertToVercelTool.js.map +1 -1
- package/dist/lib/payments/index.d.ts +14 -23
- package/dist/lib/payments/index.js +33 -47
- package/dist/lib/payments/index.js.map +1 -1
- package/dist/lib/schemaConversion.d.ts +0 -14
- package/dist/lib/schemaConversion.js +26 -56
- package/dist/lib/schemaConversion.js.map +1 -1
- package/dist/lib/schemaStructure.d.ts +1 -7
- package/dist/lib/schemaStructure.js +26 -57
- package/dist/lib/schemaStructure.js.map +1 -1
- package/dist/plugins/base.d.ts +1 -29
- package/dist/plugins/base.js +1 -33
- package/dist/plugins/base.js.map +1 -1
- package/dist/plugins/citations-plugin.d.ts +6 -81
- package/dist/plugins/citations-plugin.js +46 -161
- package/dist/plugins/citations-plugin.js.map +1 -1
- package/dist/plugins/crypto-plugin.d.ts +18 -123
- package/dist/plugins/crypto-plugin.js +41 -248
- package/dist/plugins/crypto-plugin.js.map +1 -1
- package/dist/plugins/time-plugin.d.ts +8 -90
- package/dist/plugins/time-plugin.js +24 -131
- package/dist/plugins/time-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +5 -36
- package/dist/service/auth.d.ts +1 -49
- package/dist/service/auth.js +21 -99
- package/dist/service/auth.js.map +1 -1
- package/dist/service/cloudflareService.js +5 -6
- package/dist/service/cloudflareService.js.map +1 -1
- package/dist/service/core.js +23 -54
- package/dist/service/core.js.map +1 -1
- package/dist/service/denoService.js +14 -18
- package/dist/service/denoService.js.map +1 -1
- package/dist/service/nextService.d.ts +7 -10
- package/dist/service/nextService.js +18 -65
- package/dist/service/nextService.js.map +1 -1
- package/dist/service/nodeService.d.ts +1 -1
- package/dist/service/nodeService.js +17 -29
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/processes.d.ts +34 -36
- package/dist/service/processes.js +133 -285
- package/dist/service/processes.js.map +1 -1
- package/dist/service/server.d.ts +2 -9
- package/dist/service/server.js +162 -408
- package/dist/service/server.js.map +1 -1
- package/dist/service/webhooks.d.ts +15 -172
- package/dist/service/webhooks.js +52 -184
- package/dist/service/webhooks.js.map +1 -1
- package/package.json +11 -10
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TimePlugin = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* TimePlugin adds timing information to requests and responses for performance measurement.
|
|
7
7
|
*/
|
|
8
8
|
class TimePlugin extends base_1.BaseDainPlugin {
|
|
9
9
|
config;
|
|
@@ -16,39 +16,18 @@ class TimePlugin extends base_1.BaseDainPlugin {
|
|
|
16
16
|
super();
|
|
17
17
|
this.config = config;
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Get plugin input data from a tool context with proper typing
|
|
21
|
-
* Makes it easy for tools to access plugin data
|
|
22
|
-
*/
|
|
23
19
|
getInputData(context) {
|
|
24
20
|
return super.getInputData(context);
|
|
25
21
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Get plugin output data from a response with proper typing
|
|
28
|
-
*/
|
|
29
22
|
getResponseData(response) {
|
|
30
23
|
return super.getResponseData(response);
|
|
31
24
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a standardized response for this plugin with proper typing
|
|
34
|
-
*/
|
|
35
25
|
createResponse(data) {
|
|
36
26
|
return super.createResponse(data);
|
|
37
27
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Helper method to get and validate plugin data from a tool context
|
|
40
|
-
* Returns a default value if plugin data is not found
|
|
41
|
-
*/
|
|
42
28
|
getTimeDataFromContext(context) {
|
|
43
|
-
|
|
44
|
-
if (!pluginData) {
|
|
45
|
-
return { clientTimestamp: Date.now() };
|
|
46
|
-
}
|
|
47
|
-
return pluginData;
|
|
29
|
+
return this.getInputData(context) || { clientTimestamp: Date.now() };
|
|
48
30
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Helper method to create a response with current timestamps
|
|
51
|
-
*/
|
|
52
31
|
createTimestampResponse(pluginInput) {
|
|
53
32
|
const now = Date.now();
|
|
54
33
|
if (!pluginInput) {
|
|
@@ -60,58 +39,42 @@ class TimePlugin extends base_1.BaseDainPlugin {
|
|
|
60
39
|
timezone: pluginInput.timezone
|
|
61
40
|
};
|
|
62
41
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Calculates the elapsed time between two timestamps
|
|
65
|
-
*/
|
|
66
42
|
calculateElapsedTime(startTime, endTime = Date.now()) {
|
|
67
43
|
return endTime - startTime;
|
|
68
44
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Formats a timestamp in ISO format
|
|
71
|
-
*/
|
|
72
45
|
formatTimestamp(timestamp) {
|
|
73
46
|
return new Date(timestamp).toISOString();
|
|
74
47
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Helper method to extract client timezone
|
|
77
|
-
*/
|
|
78
48
|
getClientTimezone(context) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Add client timestamp to the request
|
|
84
|
-
const clientTimestamp = Date.now();
|
|
85
|
-
let pluginData = { clientTimestamp };
|
|
86
|
-
// Add timezone if configured
|
|
49
|
+
return this.getInputData(context)?.timezone;
|
|
50
|
+
}
|
|
51
|
+
async processInputClient(_input) {
|
|
52
|
+
const pluginData = { clientTimestamp: Date.now() };
|
|
87
53
|
if (this.config.includeTimezone) {
|
|
88
54
|
pluginData.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
89
55
|
}
|
|
90
56
|
return pluginData;
|
|
91
57
|
}
|
|
92
58
|
async processInputService(input) {
|
|
93
|
-
// No modifications needed for the service input
|
|
94
59
|
return input;
|
|
95
60
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (!pluginInput && output.context?.extraData?.extraData?.plugins) {
|
|
106
|
-
pluginInput = output.context.extraData.extraData.plugins[this.id];
|
|
61
|
+
findPluginInput(output) {
|
|
62
|
+
const paths = [
|
|
63
|
+
output?.context?.extraData?.plugins,
|
|
64
|
+
output?.context?.request?.plugins,
|
|
65
|
+
output?.context?.extraData?.extraData?.plugins
|
|
66
|
+
];
|
|
67
|
+
for (const plugins of paths) {
|
|
68
|
+
if (plugins?.[this.id])
|
|
69
|
+
return plugins[this.id];
|
|
107
70
|
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
async processOutputService(output) {
|
|
74
|
+
const pluginInput = this.findPluginInput(output);
|
|
108
75
|
if (!pluginInput) {
|
|
109
|
-
return {
|
|
110
|
-
clientTimestamp: 0,
|
|
111
|
-
serviceTimestamp: Date.now()
|
|
112
|
-
};
|
|
76
|
+
return { clientTimestamp: 0, serviceTimestamp: Date.now() };
|
|
113
77
|
}
|
|
114
|
-
// Add service timestamp to the response
|
|
115
78
|
return {
|
|
116
79
|
clientTimestamp: pluginInput.clientTimestamp,
|
|
117
80
|
serviceTimestamp: Date.now(),
|
|
@@ -119,114 +82,44 @@ class TimePlugin extends base_1.BaseDainPlugin {
|
|
|
119
82
|
};
|
|
120
83
|
}
|
|
121
84
|
async processOutputClient(output) {
|
|
122
|
-
// Get the plugin data from the response
|
|
123
85
|
const pluginOutput = this.getResponseData(output);
|
|
124
86
|
if (pluginOutput) {
|
|
125
|
-
|
|
126
|
-
const now = Date.now();
|
|
127
|
-
const roundtripTime = now - pluginOutput.clientTimestamp;
|
|
128
|
-
// Update the plugin data in the response
|
|
87
|
+
const roundtripTime = Date.now() - pluginOutput.clientTimestamp;
|
|
129
88
|
output.plugins = output.plugins || {};
|
|
130
|
-
|
|
131
|
-
output.plugins[this.id] = {
|
|
132
|
-
...pluginOutput,
|
|
133
|
-
roundtripTime
|
|
134
|
-
};
|
|
89
|
+
output.plugins[this.id] = { ...pluginOutput, roundtripTime };
|
|
135
90
|
}
|
|
136
91
|
return output;
|
|
137
92
|
}
|
|
138
93
|
/**
|
|
139
|
-
*
|
|
140
|
-
* This shows real-world usage of createResponse in a service operation.
|
|
141
|
-
*
|
|
142
|
-
* @param startTimestamp When the operation started (usually from client)
|
|
143
|
-
* @param options Additional timing options
|
|
144
|
-
* @returns A properly formatted time plugin response
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* // In a service operation:
|
|
148
|
-
* async function processRequest(req) {
|
|
149
|
-
* const startTime = Date.now();
|
|
150
|
-
*
|
|
151
|
-
* // Do some work...
|
|
152
|
-
* const result = await doExpensiveOperation();
|
|
153
|
-
*
|
|
154
|
-
* // Measure timing and include in response
|
|
155
|
-
* const timing = timePlugin.createTimingResponse(startTime, {
|
|
156
|
-
* operationType: 'database-query',
|
|
157
|
-
* metadata: { rowsProcessed: 1500 }
|
|
158
|
-
* });
|
|
159
|
-
*
|
|
160
|
-
* return {
|
|
161
|
-
* data: result,
|
|
162
|
-
* plugins: {
|
|
163
|
-
* 'time-plugin': timing
|
|
164
|
-
* }
|
|
165
|
-
* };
|
|
166
|
-
* }
|
|
94
|
+
* Measures performance of service operations and returns timing data.
|
|
167
95
|
*/
|
|
168
96
|
createTimingResponse(startTimestamp, options = {}) {
|
|
169
97
|
const now = Date.now();
|
|
170
98
|
const elapsed = this.calculateElapsedTime(startTimestamp, now);
|
|
171
|
-
// Create the base response with timing information
|
|
172
99
|
const response = this.createResponse({
|
|
173
100
|
clientTimestamp: startTimestamp,
|
|
174
101
|
serviceTimestamp: now,
|
|
175
102
|
roundtripTime: elapsed
|
|
176
103
|
});
|
|
177
|
-
// Add timezone if requested
|
|
178
104
|
if (options.includeTimezone) {
|
|
179
105
|
response.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
180
106
|
}
|
|
181
|
-
// Log the timing data for monitoring/debugging
|
|
182
|
-
console.log(`[TimePlugin] ${options.operationType || 'Operation'} completed in ${elapsed}ms`);
|
|
183
|
-
if (options.metadata) {
|
|
184
|
-
console.log(`[TimePlugin] Operation metadata:`, options.metadata);
|
|
185
|
-
}
|
|
186
107
|
return response;
|
|
187
108
|
}
|
|
188
109
|
/**
|
|
189
|
-
* Creates
|
|
190
|
-
* and adds timing information to the response.
|
|
191
|
-
*
|
|
192
|
-
* @param options Timing options for the middleware
|
|
193
|
-
* @returns A middleware function that can wrap tool handlers
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* // Create a timed middleware
|
|
197
|
-
* const timedMiddleware = timePlugin.createTimedMiddleware({
|
|
198
|
-
* includeTimezone: true
|
|
199
|
-
* });
|
|
200
|
-
*
|
|
201
|
-
* // Create a tool with automatic timing
|
|
202
|
-
* const myTool = createTool({
|
|
203
|
-
* id: "my-timed-tool",
|
|
204
|
-
* // ... other tool properties
|
|
205
|
-
* handler: timedMiddleware(async (params, agentInfo, context) => {
|
|
206
|
-
* // Your tool logic here
|
|
207
|
-
* return {
|
|
208
|
-
* text: "Result",
|
|
209
|
-
* data: { ... }
|
|
210
|
-
* };
|
|
211
|
-
* })
|
|
212
|
-
* });
|
|
110
|
+
* Creates middleware that automatically times tool executions.
|
|
213
111
|
*/
|
|
214
112
|
createTimedMiddleware(options = {}) {
|
|
215
113
|
return (handler) => {
|
|
216
114
|
return async (...args) => {
|
|
217
|
-
// Extract the context from the arguments (usually the third argument)
|
|
218
115
|
const context = args[2] || {};
|
|
219
|
-
// Get the client timestamp if available in the plugin data
|
|
220
116
|
const pluginData = this.getTimeDataFromContext(context);
|
|
221
117
|
const startTime = pluginData.clientTimestamp;
|
|
222
|
-
// Execute the wrapped handler function
|
|
223
118
|
const result = await handler(...args);
|
|
224
|
-
// Generate timing information
|
|
225
119
|
const timingData = this.createTimingResponse(startTime, {
|
|
226
120
|
...options,
|
|
227
121
|
operationType: options.operationType || 'tool-execution'
|
|
228
122
|
});
|
|
229
|
-
// Add the timing data to the result
|
|
230
123
|
if (result && typeof result === 'object') {
|
|
231
124
|
result.plugins = result.plugins || {};
|
|
232
125
|
result.plugins[this.id] = timingData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-plugin.js","sourceRoot":"","sources":["../../src/plugins/time-plugin.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;
|
|
1
|
+
{"version":3,"file":"time-plugin.js","sourceRoot":"","sources":["../../src/plugins/time-plugin.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AAwBxC;;GAEG;AACH,MAAa,UAAW,SAAQ,qBAAmE;IAO9E;IANnB,EAAE,GAAG,aAAa,CAAC;IACnB,IAAI,GAAG,aAAa,CAAC;IACrB,OAAO,GAAG,OAAO,CAAC;IAClB,WAAW,GAAG,mDAAmD,CAAC;IAClE,IAAI,GAAG,MAAe,CAAC;IAEvB,YAAmB,SAA2B,EAAE;QAC9C,KAAK,EAAE,CAAC;QADS,WAAM,GAAN,MAAM,CAAuB;IAEhD,CAAC;IAEQ,YAAY,CAAC,OAAY;QAChC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAgC,CAAC;IACpE,CAAC;IAEQ,e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AEH,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;oBACzC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;oBACtC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC;gBACvC,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF;AAvJD,gCAuJC"}
|
package/dist/plugins/types.d.ts
CHANGED
|
@@ -1,56 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Interface for DAIN Service plugins
|
|
3
|
-
* Plugins can intercept and modify tool requests/responses
|
|
2
|
+
* Interface for DAIN Service plugins that intercept and modify tool requests/responses.
|
|
4
3
|
*/
|
|
5
4
|
export interface DainPlugin<TConfig = any, TInput = any, TOutput = any> {
|
|
6
|
-
/** Unique identifier for the plugin */
|
|
7
5
|
id: string;
|
|
8
|
-
/** Human-readable name */
|
|
9
6
|
name: string;
|
|
10
|
-
/** Version string */
|
|
11
7
|
version: string;
|
|
12
|
-
/** Description of what the plugin does */
|
|
13
8
|
description: string;
|
|
14
|
-
/** Where the plugin runs - client, service, or both */
|
|
15
9
|
type: 'service' | 'client' | 'both';
|
|
16
|
-
/** Plugin configuration */
|
|
17
10
|
config: TConfig;
|
|
18
|
-
/**
|
|
19
|
-
* Process input data before sending to service
|
|
20
|
-
* This is called on the client side before making a tool call
|
|
21
|
-
*/
|
|
11
|
+
/** Called on client side before making a tool call */
|
|
22
12
|
processInputClient?(input: any): Promise<TInput>;
|
|
23
|
-
/**
|
|
24
|
-
* Process output data after receiving from service
|
|
25
|
-
* This is called on the client side after receiving a tool response
|
|
26
|
-
*/
|
|
13
|
+
/** Called on client side after receiving a tool response */
|
|
27
14
|
processOutputClient?(output: any): Promise<any>;
|
|
28
|
-
/**
|
|
29
|
-
* Process input data before sending to service
|
|
30
|
-
* This is called on the service side before processing a tool request
|
|
31
|
-
*/
|
|
15
|
+
/** Called on service side before processing a tool request */
|
|
32
16
|
processInputService?(input: any): Promise<any>;
|
|
33
|
-
/**
|
|
34
|
-
* Process output data after receiving from service
|
|
35
|
-
* This is called on the service side after processing a tool response
|
|
36
|
-
*/
|
|
17
|
+
/** Called on service side after processing a tool response */
|
|
37
18
|
processOutputService?(output: any): Promise<TOutput>;
|
|
38
|
-
/**
|
|
39
|
-
* Get input data from context
|
|
40
|
-
*/
|
|
41
19
|
getInputData?(context: any): TInput | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Get response data from response
|
|
44
|
-
*/
|
|
45
20
|
getResponseData?(response: any): TOutput | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Create a response from partial data
|
|
48
|
-
*/
|
|
49
21
|
createResponse?(data: Partial<TOutput>): TOutput;
|
|
50
22
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Standard interface for plugin data in requests and responses
|
|
53
|
-
*/
|
|
54
23
|
export interface PluginData {
|
|
55
24
|
[pluginId: string]: any;
|
|
56
25
|
}
|
package/dist/service/auth.d.ts
CHANGED
|
@@ -7,11 +7,8 @@ export declare function signResponse(privateKey: Uint8Array, responseBody: strin
|
|
|
7
7
|
timestamp: string;
|
|
8
8
|
};
|
|
9
9
|
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,
|
|
10
|
+
export declare function verifyRequestSignature(signature: string, method: string, path: string, headers: Record<string, string>, body: string, address: string, _smartAccountPDA: string): boolean;
|
|
11
11
|
export declare function isValidSolanaAddress(address: string): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* JWT payload structure from DAIN ID OAuth
|
|
14
|
-
*/
|
|
15
12
|
export interface DainIDJWTPayload {
|
|
16
13
|
sub: string;
|
|
17
14
|
iss: string;
|
|
@@ -21,9 +18,6 @@ export interface DainIDJWTPayload {
|
|
|
21
18
|
scope?: string[];
|
|
22
19
|
smart_account_id?: string;
|
|
23
20
|
}
|
|
24
|
-
/**
|
|
25
|
-
* JWT verification result
|
|
26
|
-
*/
|
|
27
21
|
export interface JWTVerificationResult {
|
|
28
22
|
valid: boolean;
|
|
29
23
|
payload?: DainIDJWTPayload;
|
|
@@ -36,58 +30,16 @@ export declare function verifyJWT(token: string, publicKeyPEMOrUrl: string, opti
|
|
|
36
30
|
issuer?: string;
|
|
37
31
|
audience?: string;
|
|
38
32
|
}): Promise<JWTVerificationResult>;
|
|
39
|
-
/**
|
|
40
|
-
* Parsed API key structure
|
|
41
|
-
* Format: sk_agent_{agentId}_{orgId}_{secret}
|
|
42
|
-
*/
|
|
43
33
|
export interface ParsedAPIKey {
|
|
44
34
|
agentId: string;
|
|
45
35
|
orgId: string;
|
|
46
36
|
secret: string;
|
|
47
37
|
raw: string;
|
|
48
38
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Parse DAIN API key and extract agentId/orgId
|
|
51
|
-
* @param apiKey API key in format sk_agent_{agentId}_{orgId}_{secret}
|
|
52
|
-
* @returns Parsed API key or null if invalid
|
|
53
|
-
*/
|
|
54
39
|
export declare function parseAPIKey(apiKey: string): ParsedAPIKey | null;
|
|
55
|
-
/**
|
|
56
|
-
* Validate API key format (does NOT verify with platform)
|
|
57
|
-
* @param apiKey API key to validate
|
|
58
|
-
* @returns true if format is valid
|
|
59
|
-
*/
|
|
60
40
|
export declare function isValidAPIKeyFormat(apiKey: string): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Extract X-DAIN-API-KEY header
|
|
63
|
-
*/
|
|
64
41
|
export declare function extractAPIKey(headers: Record<string, string | undefined>): string | null;
|
|
65
|
-
/**
|
|
66
|
-
* Validate API key with platform
|
|
67
|
-
* @param apiKey API key to validate
|
|
68
|
-
* @param platformBaseUrl Platform base URL (e.g., https://platform.dain.org)
|
|
69
|
-
* @returns true if valid, false otherwise
|
|
70
|
-
*/
|
|
71
42
|
export declare function validateAPIKeyWithPlatform(apiKey: string, platformBaseUrl: string): Promise<boolean>;
|
|
72
|
-
/**
|
|
73
|
-
* Check if a scope array contains a required scope
|
|
74
|
-
* Supports wildcard matching (e.g., "wallets.*" matches "wallets.read")
|
|
75
|
-
* @param scopes User's authorized scopes
|
|
76
|
-
* @param requiredScope Scope to check for
|
|
77
|
-
* @returns true if user has the required scope
|
|
78
|
-
*/
|
|
79
43
|
export declare function hasScope(scopes: string[], requiredScope: string): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Check if user has ALL required scopes
|
|
82
|
-
* @param scopes User's authorized scopes
|
|
83
|
-
* @param requiredScopes Array of required scopes
|
|
84
|
-
* @returns true if user has all required scopes
|
|
85
|
-
*/
|
|
86
44
|
export declare function hasAllScopes(scopes: string[], requiredScopes: string[]): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Check if user has ANY of the required scopes
|
|
89
|
-
* @param scopes User's authorized scopes
|
|
90
|
-
* @param requiredScopes Array of required scopes
|
|
91
|
-
* @returns true if user has at least one required scope
|
|
92
|
-
*/
|
|
93
45
|
export declare function hasAnyScope(scopes: string[], requiredScopes: string[]): boolean;
|