Skip to content

Commit

Permalink
fix: delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Sep 18, 2024
1 parent 4c71b34 commit 08c9d4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/app/space/[did]/share/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { ShareSpace } from '@/share'

export default function SharePage (): JSX.Element {
export default function SharePage ({params}): JSX.Element {
return (
<ShareSpace />
<ShareSpace spaceDID={decodeURIComponent(params.did)}/>
)
}
20 changes: 15 additions & 5 deletions src/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ function isEmail(value: string): boolean {
return !isDID(value) && emailRegex.test(value)
}

export function ShareSpace(): JSX.Element {
export function ShareSpace({spaceDID}: {spaceDID: string}): JSX.Element {
const [{ client }] = useW3()
const [value, setValue] = useState('')
const [downloadUrl, setDownloadUrl] = useState('')
const [sharedEmails, setSharedEmails] = useState<{ email: string, capabilities: string[] }[]>([])

useEffect(() => {
const spaceDid = window.location.pathname.split('/')[2]
if (client && spaceDid) {
if (client) {
const delegations = client.delegations()
.filter(d => d.capabilities.some(c => c.with === spaceDid))
.filter(d => d.capabilities.some(c => c.with === spaceDID))
.map(d => ({
email: d.audience.did(),
capabilities: d.capabilities.map(c => c.can)
Expand Down Expand Up @@ -75,6 +74,18 @@ export function ShareSpace(): JSX.Element {
], {
expiration: Infinity
})

const res = await client.capability.access.delegate({
// @ts-ignore
space: DID.from(spaceDID).did(),
delegations: [delegation],
})
if (res.error) {
throw new Error(
`failed to share account: ${result.error.message}`,
{ cause: result.error }
)
}

const next = { email: audience.did(), capabilities: delegation.capabilities.map(c => c.can) }
setSharedEmails(prev => {
Expand All @@ -101,7 +112,6 @@ export function ShareSpace(): JSX.Element {
}

try {
console.log(audience.did())
const delegation = await client.createDelegation(audience, ['*'], {
expiration: Infinity,
})
Expand Down

0 comments on commit 08c9d4b

Please sign in to comment.