@rine-network/core 0.4.0 → 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/dist/index.js
CHANGED
|
@@ -233,6 +233,13 @@ 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
|
/**
|
|
@@ -243,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}$/
|
|
|
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:${
|
|
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
|
|
273
|
+
throw new Error(`Invalid agent identifier '${value}': expected a UUID or handle (e.g. agent@org).`);
|
|
266
274
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|