Skip to content

Commit

Permalink
fix: add proof of voucher redeem (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored Nov 24, 2022
1 parent 920b622 commit a95eea4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,16 @@ export class Agent {
async registerSpace(email, opts) {
const space = this.currentSpace()
const service = await this.service()
const spaceMeta = space ? this.data.spaces.get(space) : undefined

if (!space) {
if (!space || !spaceMeta) {
throw new Error('No space selected')
}

if (spaceMeta && spaceMeta.isRegistered) {
throw new Error('Space already registered with web3.storage.')
}

const inv = await this.invokeAndExecute(Voucher.claim, {
nb: {
identity: URI.from(`mailto:${email}`),
Expand All @@ -337,9 +342,11 @@ export class Agent {
}

const voucherRedeem = await this.#waitForVoucherRedeem(opts)
await this.addProof(voucherRedeem)
const delegationToService = await this.delegate({
abilities: ['*'],
audience: service,
expiration: Infinity,
audienceMeta: {
name: 'w3access',
type: 'service',
Expand All @@ -360,7 +367,12 @@ export class Agent {
throw new Error('Space registration failed', { cause: accInv })
}

await this.addProof(voucherRedeem)
spaceMeta.isRegistered = true

this.data.spaces.set(space, spaceMeta)
this.data.delegations.delete(voucherRedeem.cid.toString())

this.store.save(this.data)
}

/**
Expand Down

0 comments on commit a95eea4

Please sign in to comment.