@rine-network/core 0.3.5 → 0.4.1
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/README.md +1 -1
- package/dist/index.js +18 -6
- package/dist/src/http.d.ts +8 -0
- package/dist/src/resolve-handle.d.ts +1 -0
- package/dist/test/normalize-handle.test.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Config directory resolution (`resolveConfigDir`) uses a smart fallback: `RINE_CO
|
|
|
63
63
|
|
|
64
64
|
## License
|
|
65
65
|
|
|
66
|
-
[EUPL-1.2](
|
|
66
|
+
[EUPL-1.2](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
|
|
67
67
|
|
|
68
68
|
## For AI Agents
|
|
69
69
|
|
package/dist/index.js
CHANGED
|
@@ -129,11 +129,13 @@ var HttpClient = class {
|
|
|
129
129
|
tokenFn;
|
|
130
130
|
canRefresh;
|
|
131
131
|
defaultHeaders;
|
|
132
|
+
defaultSignal;
|
|
132
133
|
constructor(opts) {
|
|
133
134
|
this.baseUrl = opts.apiUrl;
|
|
134
135
|
this.tokenFn = opts.tokenFn;
|
|
135
136
|
this.canRefresh = opts.canRefresh ?? true;
|
|
136
137
|
this.defaultHeaders = opts.defaultHeaders ?? {};
|
|
138
|
+
this.defaultSignal = opts.signal;
|
|
137
139
|
}
|
|
138
140
|
async request(method, path, body, params, extraHeaders) {
|
|
139
141
|
let url = this.baseUrl + path;
|
|
@@ -150,7 +152,8 @@ var HttpClient = class {
|
|
|
150
152
|
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
151
153
|
const init = {
|
|
152
154
|
method,
|
|
153
|
-
headers
|
|
155
|
+
headers,
|
|
156
|
+
signal: this.defaultSignal
|
|
154
157
|
};
|
|
155
158
|
if (body !== void 0) init.body = JSON.stringify(body);
|
|
156
159
|
return fetch(url, init);
|
|
@@ -230,6 +233,13 @@ async function getOrRefreshToken(configDir, apiUrl, entry, profileName, opts) {
|
|
|
230
233
|
}
|
|
231
234
|
//#endregion
|
|
232
235
|
//#region src/resolve-handle.ts
|
|
236
|
+
const DEFAULT_DOMAIN = ".rine.network";
|
|
237
|
+
function normalizeHandle(handle) {
|
|
238
|
+
const atIdx = handle.lastIndexOf("@");
|
|
239
|
+
if (atIdx === -1) return handle;
|
|
240
|
+
if (handle.slice(atIdx + 1).includes(".")) return handle;
|
|
241
|
+
return handle + DEFAULT_DOMAIN;
|
|
242
|
+
}
|
|
233
243
|
const UUID_ALIAS_RE = /\/agents\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
|
|
234
244
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
235
245
|
/**
|
|
@@ -240,8 +250,9 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
|
|
240
250
|
* on failure (caller validates UUID format and reports the error).
|
|
241
251
|
*/
|
|
242
252
|
async function resolveHandleViaWebFinger(apiUrl, handle) {
|
|
253
|
+
const normalized = normalizeHandle(handle);
|
|
243
254
|
try {
|
|
244
|
-
const params = new URLSearchParams({ resource: `acct:${
|
|
255
|
+
const params = new URLSearchParams({ resource: `acct:${normalized}` });
|
|
245
256
|
const data = await HttpClient.publicGet(apiUrl, "/.well-known/webfinger", params);
|
|
246
257
|
for (const alias of data.aliases ?? []) {
|
|
247
258
|
const match = UUID_ALIAS_RE.exec(alias);
|
|
@@ -259,10 +270,11 @@ async function resolveHandleViaWebFinger(apiUrl, handle) {
|
|
|
259
270
|
async function resolveToUuid(apiUrl, value) {
|
|
260
271
|
if (!value.includes("@")) {
|
|
261
272
|
if (UUID_RE.test(value)) return value;
|
|
262
|
-
throw new Error(`Invalid agent identifier '${value}': expected a UUID or handle (e.g. agent@org
|
|
273
|
+
throw new Error(`Invalid agent identifier '${value}': expected a UUID or handle (e.g. agent@org).`);
|
|
263
274
|
}
|
|
264
|
-
const
|
|
265
|
-
|
|
275
|
+
const normalized = normalizeHandle(value);
|
|
276
|
+
const resolved = await resolveHandleViaWebFinger(apiUrl, normalized);
|
|
277
|
+
if (!UUID_RE.test(resolved)) throw new Error(`Cannot resolve handle "${normalized}" to agent ID. Ensure WebFinger is available or use a UUID.`);
|
|
266
278
|
return resolved;
|
|
267
279
|
}
|
|
268
280
|
/** Check if a value is a bare agent name (not a UUID, not a handle). */
|
|
@@ -1038,4 +1050,4 @@ async function performAgentCreation(client, configDir, profile, params) {
|
|
|
1038
1050
|
return agent;
|
|
1039
1051
|
}
|
|
1040
1052
|
//#endregion
|
|
1041
|
-
export { DEFAULT_API_URL, HttpClient, RineApiError, UUID_RE, advanceChain, agentIdFromKid, agentKeysExist, bytesToUuid, cacheToken, decodeEnvelope, decryptGroupMessage, decryptMessage, deriveMessageKey, distributeSenderKey, encodeEnvelope, encryptGroupMessage, encryptMessage, encryptionPublicKeyToJWK, fetchAgents, fetchAndIngestPendingSKDistributions, fetchOAuthToken, fetchRecipientEncryptionKey, formatError, fromBase64Url, generateAgentKeys, generateEncryptionKeyPair, generateSenderKey, generateSigningKeyPair, getAgentPublicKeys, getCredentialEntry, getOrCreateSenderKey, getOrRefreshToken, ingestSenderKeyDistribution, isBareAgentName, jwkToPublicKey, loadAgentKeys, loadCredentials, loadSenderKeyStates, loadTokenCache, needsRotation, open, openGroup, performAgentCreation, performRegistration, resolveAgent, resolveApiUrl, resolveConfigDir, resolveHandleViaWebFinger, resolveToUuid, saveAgentKeys, saveCredentials, saveSenderKeyState, saveTokenCache, seal, sealGroup, signPayload, signingPublicKeyToJWK, solveTimeLock, solveTimeLockWithProgress, toBase64Url, uuidToBytes, validateEncryptionKey, validatePathId, validateSigningKey, validateSlug, verifySignature };
|
|
1053
|
+
export { DEFAULT_API_URL, HttpClient, RineApiError, UUID_RE, advanceChain, agentIdFromKid, agentKeysExist, bytesToUuid, cacheToken, decodeEnvelope, decryptGroupMessage, decryptMessage, deriveMessageKey, distributeSenderKey, encodeEnvelope, encryptGroupMessage, encryptMessage, encryptionPublicKeyToJWK, fetchAgents, fetchAndIngestPendingSKDistributions, fetchOAuthToken, fetchRecipientEncryptionKey, formatError, fromBase64Url, generateAgentKeys, generateEncryptionKeyPair, generateSenderKey, generateSigningKeyPair, getAgentPublicKeys, getCredentialEntry, getOrCreateSenderKey, getOrRefreshToken, ingestSenderKeyDistribution, isBareAgentName, jwkToPublicKey, loadAgentKeys, loadCredentials, loadSenderKeyStates, loadTokenCache, needsRotation, normalizeHandle, open, openGroup, performAgentCreation, performRegistration, resolveAgent, resolveApiUrl, resolveConfigDir, resolveHandleViaWebFinger, resolveToUuid, saveAgentKeys, saveCredentials, saveSenderKeyState, saveTokenCache, seal, sealGroup, signPayload, signingPublicKeyToJWK, solveTimeLock, solveTimeLockWithProgress, toBase64Url, uuidToBytes, validateEncryptionKey, validatePathId, validateSigningKey, validateSlug, verifySignature };
|
package/dist/src/http.d.ts
CHANGED
|
@@ -7,12 +7,20 @@ export interface HttpClientOptions {
|
|
|
7
7
|
canRefresh?: boolean;
|
|
8
8
|
/** Headers injected on every request (e.g. X-Rine-Agent). */
|
|
9
9
|
defaultHeaders?: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Default abort signal applied to every request made by this instance.
|
|
12
|
+
* Use one short-lived HttpClient per cancellation scope — e.g. one per
|
|
13
|
+
* SDK crypto operation. A fired signal propagates to fetch() as-is; the
|
|
14
|
+
* resulting AbortError is NOT wrapped in RineApiError.
|
|
15
|
+
*/
|
|
16
|
+
signal?: AbortSignal;
|
|
10
17
|
}
|
|
11
18
|
export declare class HttpClient {
|
|
12
19
|
private readonly baseUrl;
|
|
13
20
|
private readonly tokenFn;
|
|
14
21
|
private readonly canRefresh;
|
|
15
22
|
private readonly defaultHeaders;
|
|
23
|
+
private readonly defaultSignal;
|
|
16
24
|
constructor(opts: HttpClientOptions);
|
|
17
25
|
private request;
|
|
18
26
|
get(path: string, params?: Record<string, string | number | boolean>, extraHeaders?: Record<string, string>): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|