Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@ import { Cabinet } from "./repositories/cabinet.js"

import { Account, Agent, Authority, Identifier } from "./components.js"
import { AnnexParentType } from "./components/account/implementation.js"
import { Names } from "./repositories/names.js"

//////////////
// REGISTER //
//////////////

export const register = <Annex extends AnnexParentType, P, R>(
{ account, agent, authority, identifier, cabinet }: {
{ account, agent, authority, identifier, cabinet, names }: {
account: Account.Implementation<Annex>
agent: Agent.Implementation
authority: Authority.Implementation<P, R>
identifier: Identifier.Implementation
cabinet: Cabinet
names: Names
}
) =>
async (formValues: Record<string, string>): Promise<
{ registered: true } | { registered: false; reason: string }
> => {
// Do delegation from identifier to agent
const agentDelegation = await authority.clerk.tickets.misc.identifierToAgentDelegation(identifier, agent)
await cabinet.addTicket("misc", agentDelegation)

// Call account register implementation
const result = await account.register(formValues, agentDelegation)
const result = await account.register(identifier, names, formValues)

if (result.registered) {
// Do delegation from identifier to agent
const agentDelegation = await authority.clerk.tickets.misc.identifierToAgentDelegation(
identifier,
agent,
result.tickets
)

await cabinet.addTicket("agent", agentDelegation)
await cabinet.addTickets("account", result.tickets)
return { registered: true }
} else {
Expand Down
32 changes: 19 additions & 13 deletions src/authority/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isString } from "../common/type-checks.js"
import { isObject, isString } from "../common/type-checks.js"
import * as Path from "../path/index.js"

////////
Expand All @@ -22,7 +22,7 @@ export type FileSystemAbility = typeof ALLOWED_FILE_SYSTEM_ABILITIES[number]
export type FileSystemQuery = {
query: "fileSystem"
ability: FileSystemAbility
did: string
id: { did: string } | { name: string }
path: Path.Distinctive<Path.Partitioned<Path.Partition>>
}

Expand All @@ -35,28 +35,28 @@ export const account: AccountQuery = {
}

export const fileSystem = {
rootAccess(did: string): FileSystemQuery[] {
rootAccess(id: { did: string } | { name: string }): FileSystemQuery[] {
return [{
query: "fileSystem",
ability: "*",
did,
id,
path: Path.directory("public"),
}, {
query: "fileSystem",
ability: "*",
did,
id,
path: Path.directory("private"),
}]
},
limitedAccess(
ability: typeof ALLOWED_FILE_SYSTEM_ABILITIES[number],
did: string,
id: { did: string } | { name: string },
path: Path.Distinctive<Path.Partitioned<Path.Partition>>
): FileSystemQuery {
return {
query: "fileSystem",
did,
ability,
id,
path,
}
},
Expand All @@ -77,7 +77,7 @@ export function isContained({ parent, child }: { parent: Query; child: Query }):
? true
: (child.ability === "*" ? false : parent.ability === child.ability)

const did = parent.did === child.did
const id = JSON.stringify(parent.id) === JSON.stringify(child.id)

const unwrappedParentPath = Path.unwrap(parent.path)
const path = Path.unwrap(child.path).reduce(
Expand All @@ -89,7 +89,7 @@ export function isContained({ parent, child }: { parent: Query; child: Query }):
true
)

return ability && did && path
return ability && id && path
}

// ?
Expand Down Expand Up @@ -139,14 +139,20 @@ function fileSystemQueryFromJSON(obj: Record<string, unknown>): FileSystemQuery
throw new Error(`Expected a path with a partition (private or public), got: ${obj.path}`)
}

if (!isString(obj.did)) {
throw new Error("Expected a `did` property")
if (!isObject(obj.id)) {
throw new Error("Expected a `id` object")
}

if (!isString(obj.id.did) || !isString(obj.id.name)) {
throw new Error("Expected the `id` object to have a `did` or a `name` property")
}

obj.id.did

return {
query: "fileSystem",
ability: obj.ability as FileSystemAbility,
did: obj.did,
id: obj.id.did ? { did: obj.id.did } : { name: obj.id.name },
path: partitionedPath,
}
}
Expand All @@ -162,7 +168,7 @@ export function toJSON(query: Query): object {
return {
query: query.query,
ability: query.ability,
did: query.did,
id: query.id,
path: Path.toPosix(query.path),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/account/fission/data-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function update<FS>(
},

proofs: await Promise.all(proofs.map(
async proof => ticketCID(proof).toString()
async proof => (await ticketCID(proof)).toString()
)),
})
)
Expand Down
Loading