@rine-network/core 0.4.0 → 0.4.2

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/index.js CHANGED
@@ -233,18 +233,26 @@ async function getOrRefreshToken(configDir, apiUrl, entry, profileName, opts) {
233
233
  }
234
234
  //#endregion
235
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
+ }
236
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;
237
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;
238
245
  /**
239
- * Resolves a handle (e.g. "agent@org.rine.network") to a UUID
246
+ * Resolves a handle (e.g. "agent@org") to a UUID
240
247
  * via WebFinger (RFC 7033).
241
248
  *
242
249
  * Returns the UUID string on success, or the original input unchanged
243
250
  * on failure (caller validates UUID format and reports the error).
244
251
  */
245
252
  async function resolveHandleViaWebFinger(apiUrl, handle) {
253
+ const normalized = normalizeHandle(handle);
246
254
  try {
247
- const params = new URLSearchParams({ resource: `acct:${handle}` });
255
+ const params = new URLSearchParams({ resource: `acct:${normalized}` });
248
256
  const data = await HttpClient.publicGet(apiUrl, "/.well-known/webfinger", params);
249
257
  for (const alias of data.aliases ?? []) {
250
258
  const match = UUID_ALIAS_RE.exec(alias);
@@ -262,10 +270,11 @@ async function resolveHandleViaWebFinger(apiUrl, handle) {
262
270
  async function resolveToUuid(apiUrl, value) {
263
271
  if (!value.includes("@")) {
264
272
  if (UUID_RE.test(value)) return value;
265
- throw new Error(`Invalid agent identifier '${value}': expected a UUID or handle (e.g. agent@org.rine.network).`);
273
+ throw new Error(`Invalid agent identifier '${value}': expected a UUID or handle (e.g. agent@org).`);
266
274
  }
267
- const resolved = await resolveHandleViaWebFinger(apiUrl, value);
268
- if (!UUID_RE.test(resolved)) throw new Error(`Cannot resolve handle "${value}" to agent ID. Ensure WebFinger is available or use a UUID.`);
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.`);
269
278
  return resolved;
270
279
  }
271
280
  /** Check if a value is a bare agent name (not a UUID, not a handle). */
@@ -1041,4 +1050,4 @@ async function performAgentCreation(client, configDir, profile, params) {
1041
1050
  return agent;
1042
1051
  }
1043
1052
  //#endregion
1044
- 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 };
@@ -1,6 +1,7 @@
1
+ export declare function normalizeHandle(handle: string): string;
1
2
  declare const UUID_RE: RegExp;
2
3
  /**
3
- * Resolves a handle (e.g. "agent@org.rine.network") to a UUID
4
+ * Resolves a handle (e.g. "agent@org") to a UUID
4
5
  * via WebFinger (RFC 7033).
5
6
  *
6
7
  * Returns the UUID string on success, or the original input unchanged
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rine-network/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Core library for rine.network — crypto, HTTP, config, agent resolution",
5
5
  "author": "mmmbs <mmmbs@proton.me>",
6
6
  "license": "EUPL-1.2",