Rename RawAgentID to AgentID
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { CoValueHeader } from './coValue.js';
|
||||
import { CoValueID } from './contentType.js';
|
||||
import { AgentSecret, RecipientID, RecipientSecret, SignatoryID, SignatorySecret, getAgentID, getAgentRecipientID, getAgentRecipientSecret, getAgentSignatoryID, getAgentSignatorySecret } from './crypto.js';
|
||||
import { RawAgentID } from './ids.js';
|
||||
import { AgentID } from './ids.js';
|
||||
import { CoMap, LocalNode } from './index.js';
|
||||
import { Team, TeamContent } from './permissions.js';
|
||||
|
||||
export function accountHeaderForInitialAgentSecret(agentSecret: AgentSecret): CoValueHeader {
|
||||
const rawAgentID = getAgentID(agentSecret);
|
||||
const agent = getAgentID(agentSecret);
|
||||
return {
|
||||
type: "comap",
|
||||
ruleset: {type: "team", initialAdmin: rawAgentID},
|
||||
ruleset: {type: "team", initialAdmin: agent},
|
||||
meta: {
|
||||
type: "account"
|
||||
},
|
||||
@@ -23,8 +23,8 @@ export class Account extends Team {
|
||||
return this.teamMap.id;
|
||||
}
|
||||
|
||||
getCurrentAgentID(): RawAgentID {
|
||||
const agents = this.teamMap.keys().filter((k): k is RawAgentID => k.startsWith("recipient_"));
|
||||
getCurrentAgentID(): AgentID {
|
||||
const agents = this.teamMap.keys().filter((k): k is AgentID => k.startsWith("recipient_"));
|
||||
|
||||
if (agents.length !== 1) {
|
||||
throw new Error("Expected exactly one agent in account, got " + agents.length);
|
||||
@@ -38,7 +38,7 @@ export interface GeneralizedControlledAccount {
|
||||
id: AccountIDOrAgentID;
|
||||
agentSecret: AgentSecret;
|
||||
|
||||
currentAgentID: () => RawAgentID;
|
||||
currentAgentID: () => AgentID;
|
||||
currentSignatoryID: () => SignatoryID;
|
||||
currentSignatorySecret: () => SignatorySecret;
|
||||
currentRecipientID: () => RecipientID;
|
||||
@@ -54,7 +54,7 @@ export class ControlledAccount extends Account implements GeneralizedControlledA
|
||||
this.agentSecret = agentSecret;
|
||||
}
|
||||
|
||||
currentAgentID(): RawAgentID {
|
||||
currentAgentID(): AgentID {
|
||||
return getAgentID(this.agentSecret);
|
||||
}
|
||||
|
||||
@@ -82,11 +82,11 @@ export class AnonymousControlledAccount implements GeneralizedControlledAccount
|
||||
this.agentSecret = agentSecret;
|
||||
}
|
||||
|
||||
get id(): RawAgentID {
|
||||
get id(): AgentID {
|
||||
return getAgentID(this.agentSecret);
|
||||
}
|
||||
|
||||
currentAgentID(): RawAgentID {
|
||||
currentAgentID(): AgentID {
|
||||
return getAgentID(this.agentSecret);
|
||||
}
|
||||
|
||||
@@ -110,6 +110,6 @@ export class AnonymousControlledAccount implements GeneralizedControlledAccount
|
||||
export type AccountMeta = {type: "account"};
|
||||
export type AccountID = CoValueID<CoMap<TeamContent, AccountMeta>>;
|
||||
|
||||
export type AccountIDOrAgentID = RawAgentID | AccountID;
|
||||
export type AccountOrAgentID = RawAgentID | Account;
|
||||
export type AccountIDOrAgentID = AgentID | AccountID;
|
||||
export type AccountOrAgentID = AgentID | Account;
|
||||
export type AccountOrAgentSecret = AgentSecret | Account;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { base58, base64url } from "@scure/base";
|
||||
import stableStringify from "fast-json-stable-stringify";
|
||||
import { blake3 } from "@noble/hashes/blake3";
|
||||
import { randomBytes } from "@noble/ciphers/webcrypto/utils";
|
||||
import { RawAgentID, RawCoValueID, TransactionID } from './ids.js';
|
||||
import { AgentID, RawCoValueID, TransactionID } from './ids.js';
|
||||
|
||||
export type SignatorySecret = `signatorySecret_z${string}`;
|
||||
export type SignatoryID = `signatory_z${string}`;
|
||||
@@ -104,14 +104,14 @@ export function agentSecretFromBytes(bytes: Uint8Array): AgentSecret {
|
||||
return `${recipientSecret}/${signatorySecret}`;
|
||||
}
|
||||
|
||||
export function getAgentID(secret: AgentSecret): RawAgentID {
|
||||
export function getAgentID(secret: AgentSecret): AgentID {
|
||||
const [recipientSecret, signatorySecret] = secret.split("/");
|
||||
return `${getRecipientID(
|
||||
recipientSecret as RecipientSecret
|
||||
)}/${getSignatoryID(signatorySecret as SignatorySecret)}`;
|
||||
}
|
||||
|
||||
export function getAgentSignatoryID(agentId: RawAgentID): SignatoryID {
|
||||
export function getAgentSignatoryID(agentId: AgentID): SignatoryID {
|
||||
return agentId.split("/")[1] as SignatoryID;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ export function getAgentSignatorySecret(agentSecret: AgentSecret): SignatorySecr
|
||||
return agentSecret.split("/")[1] as SignatorySecret;
|
||||
}
|
||||
|
||||
export function getAgentRecipientID(agentId: RawAgentID): RecipientID {
|
||||
export function getAgentRecipientID(agentId: AgentID): RecipientID {
|
||||
return agentId.split("/")[0] as RecipientID;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ export type RawCoValueID = `co_z${string}` | `co_${string}_z${string}`;
|
||||
|
||||
export type TransactionID = { sessionID: SessionID; txIndex: number };
|
||||
|
||||
export type RawAgentID = `recipient_z${string}/signatory_z${string}`;
|
||||
export type AgentID = `recipient_z${string}/signatory_z${string}`;
|
||||
|
||||
export function isRawAgentID(id: string): id is RawAgentID {
|
||||
export function isAgentID(id: string): id is AgentID {
|
||||
return typeof id === "string" && id.startsWith("recipient_") && id.includes("/signatory_");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import { CoValue, CoValueHeader, newRandomSessionID } from "./coValue.js";
|
||||
import { Team, TeamContent, expectTeamContent } from "./permissions.js";
|
||||
import { SyncManager } from "./sync.js";
|
||||
import { RawAgentID, RawCoValueID, SessionID, isRawAgentID } from "./ids.js";
|
||||
import { AgentID, RawCoValueID, SessionID, isAgentID } from "./ids.js";
|
||||
import { CoValueID, ContentType } from "./contentType.js";
|
||||
import {
|
||||
Account,
|
||||
@@ -117,8 +117,8 @@ export class LocalNode {
|
||||
);
|
||||
}
|
||||
|
||||
resolveAccount(id: AccountIDOrAgentID, expectation?: string): RawAgentID {
|
||||
if (isRawAgentID(id)) {
|
||||
resolveAccount(id: AccountIDOrAgentID, expectation?: string): AgentID {
|
||||
if (isAgentID(id)) {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
accountOrAgentIDfromSessionID,
|
||||
} from './coValue.js';
|
||||
import { LocalNode } from "./node.js";
|
||||
import { RawCoValueID, SessionID, TransactionID, isRawAgentID } from './ids.js';
|
||||
import { RawCoValueID, SessionID, TransactionID, isAgentID } from './ids.js';
|
||||
import { AccountIDOrAgentID, GeneralizedControlledAccount } from './account.js';
|
||||
|
||||
export type PermissionsDef =
|
||||
@@ -264,7 +264,7 @@ export class Team {
|
||||
|
||||
rotateReadKey() {
|
||||
const currentlyPermittedReaders = this.teamMap.keys().filter((key) => {
|
||||
if (key.startsWith("co_") || isRawAgentID(key)) {
|
||||
if (key.startsWith("co_") || isAgentID(key)) {
|
||||
const role = this.teamMap.get(key);
|
||||
return (
|
||||
role === "admin" || role === "writer" || role === "reader"
|
||||
|
||||
Reference in New Issue
Block a user