Skip to content

Commit 7679fd6

Browse files
committed
chore: Wrangle various usages of create/open session, and rename to better match their purpose.
1 parent 8a4157a commit 7679fd6

File tree

6 files changed

+26
-46
lines changed

6 files changed

+26
-46
lines changed

background-charm-service/cast-admin.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
storage,
88
} from "@commontools/runner";
99
import { type DID, Identity } from "@commontools/identity";
10-
import { openSession } from "@commontools/identity";
10+
import { createAdminSession } from "@commontools/identity";
1111
import {
1212
bgUpdaterCharmsSchema,
1313
CELL_CAUSE,
@@ -37,7 +37,10 @@ if (!recipePath) {
3737
const toolshedUrl = Deno.env.get("TOOLSHED_API_URL") ??
3838
"https://toolshed.saga-castor.ts.net/";
3939

40-
const identity = await getIdentity(Deno.env.get("IDENTITY"), Deno.env.get("OPERATOR_PASS"));
40+
const identity = await getIdentity(
41+
Deno.env.get("IDENTITY"),
42+
Deno.env.get("OPERATOR_PASS"),
43+
);
4144

4245
storage.setRemoteStorage(new URL(toolshedUrl));
4346
setBobbyServerUrl(toolshedUrl);
@@ -89,7 +92,7 @@ async function castRecipe() {
8992
console.log("Casting recipe...");
9093

9194
// Create session and charm manager (matching main.ts pattern)
92-
const session = await openSession({
95+
const session = await createAdminSession({
9396
identity,
9497
name: "recipe-caster",
9598
space: spaceId as DID,

background-charm-service/src/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
storage,
1010
} from "@commontools/runner";
1111
import {
12+
createAdminSession,
1213
type DID,
1314
Identity,
1415
KeyPairRaw,
15-
openSession,
1616
} from "@commontools/identity";
1717

1818
let initialized = false;
@@ -58,7 +58,7 @@ async function setup(
5858

5959
// Initialize session
6060
spaceId = did as DID;
61-
currentSession = await openSession({
61+
currentSession = await createAdminSession({
6262
identity,
6363
name: "~background-service-worker",
6464
space: spaceId,

cli/cast-recipe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
setBobbyServerUrl,
77
storage,
88
} from "@commontools/runner";
9-
import { type DID, Identity, openSessionFromPassphrase } from "@commontools/identity";
9+
import { createAdminSession, type DID, Identity } from "@commontools/identity";
1010

1111
const { spaceId, targetCellCause, recipePath, cause, name, quit } = parseArgs(
1212
Deno.args,
@@ -64,8 +64,8 @@ async function castRecipe() {
6464
console.log("Recipe compiled successfully");
6565

6666
// Create session and charm manager (matching main.ts pattern)
67-
const session = await openSessionFromPassphrase({
68-
passphrase: OPERATOR_PASS,
67+
const session = await createAdminSession({
68+
identity: signer,
6969
name: name!,
7070
space: spaceId as DID,
7171
});

cli/main.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
setBobbyServerUrl,
88
storage,
99
} from "@commontools/runner";
10-
import { createSessionFromPassphrase } from "@commontools/identity";
10+
import { createSession, Identity } from "@commontools/identity";
1111

1212
const { name, charmId, recipeFile, cause, quit } = parseArgs(Deno.args, {
1313
string: ["name", "charmId", "recipeFile", "cause"],
@@ -24,8 +24,9 @@ storage.setRemoteStorage(new URL(toolshedUrl));
2424
setBobbyServerUrl(toolshedUrl);
2525

2626
async function main() {
27-
const session = await createSessionFromPassphrase({
28-
passphrase: OPERATOR_PASS,
27+
const identity = await Identity.fromPassphrase(OPERATOR_PASS);
28+
const session = await createSession({
29+
identity,
2930
name: name!,
3031
});
3132

identity/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export { PassKey } from "./pass-key.ts";
22
export { Identity, VerifierIdentity } from "./identity.ts";
33
export { KeyStore } from "./key-store.ts";
44
export * from "./interface.ts";
5-
export { createSession, openSession, createSessionFromPassphrase, openSessionFromPassphrase, type Session } from "./session.ts";
5+
export { createAdminSession, createSession, type Session } from "./session.ts";

identity/src/session.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,22 @@ export type Session = {
99
as: Identity;
1010
};
1111

12-
export const openSessionFromPassphrase = async (
13-
{ passphrase, space, name }: {
14-
passphrase: string;
15-
space: DID;
16-
name: string;
17-
},
18-
) => ({
19-
private: name.startsWith("~"),
20-
name,
21-
space,
22-
as: await Identity.fromPassphrase(passphrase),
23-
});
24-
25-
export const createSessionFromPassphrase = async (
26-
{ passphrase, name }: { passphrase: string; name: string },
27-
) => {
28-
const account = await Identity.fromPassphrase(passphrase);
29-
const space = await account.derive(name);
30-
31-
return {
32-
private: name.startsWith("~"),
33-
name,
34-
space: space.did(),
35-
as: space,
36-
};
37-
};
38-
39-
export const openSession = async (
12+
// Create a session where `Identity` is used directly and not derived.
13+
export const createAdminSession = async (
4014
{ identity, space, name }: {
4115
identity: Identity;
4216
space: DID;
4317
name: string;
4418
},
45-
) => await ({
46-
private: name.startsWith("~"),
47-
name,
48-
space,
49-
as: identity,
50-
});
19+
) =>
20+
await ({
21+
private: name.startsWith("~"),
22+
name,
23+
space,
24+
as: identity,
25+
});
5126

27+
// Create a session where `Identity` is used to derive a space key.
5228
export const createSession = async (
5329
{ identity, name }: { identity: Identity; name: string },
5430
) => {

0 commit comments

Comments
 (0)