Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into upload-example
Browse files Browse the repository at this point in the history
  • Loading branch information
olizilla committed Nov 15, 2023
2 parents 119eda6 + fc4c6c7 commit 9efed54
Show file tree
Hide file tree
Showing 26 changed files with 461 additions and 36 deletions.
10 changes: 5 additions & 5 deletions .github/release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"packages/access-client": "17.1.0",
"packages/filecoin-api": "4.1.0",
"packages/access-client": "18.0.0",
"packages/filecoin-api": "4.1.1",
"packages/filecoin-client": "3.1.1",
"packages/capabilities": "11.4.1",
"packages/upload-api": "7.3.1",
"packages/capabilities": "12.0.0",
"packages/upload-api": "7.3.2",
"packages/upload-client": "12.0.0",
"packages/w3up-client": "10.3.0",
"packages/w3up-client": "11.0.0",
"packages/did-mailto": "2.0.2"
}
16 changes: 16 additions & 0 deletions packages/access-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [18.0.0](https://github.com/web3-storage/w3up/compare/access-v17.1.0...access-v18.0.0) (2023-11-15)


### ⚠ BREAKING CHANGES

* coupon ([#1136](https://github.com/web3-storage/w3up/issues/1136))

### Features

* coupon ([#1136](https://github.com/web3-storage/w3up/issues/1136)) ([1b94f2d](https://github.com/web3-storage/w3up/commit/1b94f2d3f6538d717d38b21dcb76657fd1f3e268))


### Bug Fixes

* upgrade ucanto core ([#1127](https://github.com/web3-storage/w3up/issues/1127)) ([5ce4d22](https://github.com/web3-storage/w3up/commit/5ce4d2292d7e980da4a2ea0f1583f608a81157d2))

## [17.1.0](https://github.com/web3-storage/w3up/compare/access-v17.0.0...access-v17.1.0) (2023-11-14)


Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-storage/access",
"version": "17.1.0",
"version": "18.0.0",
"description": "w3access client",
"homepage": "https://github.com/web3-storage/w3-protocol/tree/main/packages/access-client",
"repository": {
Expand Down
24 changes: 9 additions & 15 deletions packages/access-client/src/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ export const claim = async (
return result
} else {
const delegations = Object.values(result.ok.delegations)
const proofs = delegations.flatMap((proof) => bytesToDelegations(proof))
return { ok: new GrantedAccess({ agent, provider, audience, proofs }) }

const proofs = /** @type {API.Tuple<API.Delegation>} */ (
delegations.flatMap((proof) => bytesToDelegations(proof))
)

return { ok: new GrantedAccess({ agent, proofs }) }
}
}

Expand Down Expand Up @@ -208,9 +212,7 @@ class PendingAccessRequest {
return {
ok: new GrantedAccess({
agent: this.agent,
provider: this.provider,
audience: this.audience,
proofs: result.ok,
proofs: /** @type {API.Tuple<API.Delegation>} */ (result.ok),
}),
}
}
Expand Down Expand Up @@ -255,13 +257,11 @@ class RequestExpired extends Failure {
/**
* View over the UCAN Delegations that grant access to a specific principal.
*/
class GrantedAccess {
export class GrantedAccess {
/**
* @typedef {object} GrantedAccessModel
* @property {API.Agent} agent - Agent that processed the request.
* @property {API.DID} audience - Principal access was granted to.
* @property {API.Delegation[]} proofs - Delegations that grant access.
* @property {API.ProviderDID} provider - Provider that handled the request.
* @property {API.Tuple<API.Delegation>} proofs - Delegations that grant access.
*
* @param {GrantedAccessModel} model
*/
Expand All @@ -271,12 +271,6 @@ class GrantedAccess {
get proofs() {
return this.model.proofs
}
get provider() {
return this.model.provider
}
get authority() {
return this.model.audience
}

/**
* Saves access into the agents proofs store so that it can be retained
Expand Down
5 changes: 2 additions & 3 deletions packages/access-client/src/agent-use-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ export async function authorizeWaitAndClaim(accessAgent, email, opts) {
}

/**
* Invokes voucher/redeem for the free tier, wait on the websocket for the voucher/claim and invokes it
*
* It also adds a full space delegation to the service in the voucher/claim invocation to allow for recovery
* Provisions space with the specified account and sets up a recovery with the
* same account.
*
* @param {AccessAgent} access
* @param {AgentData} agentData
Expand Down
51 changes: 47 additions & 4 deletions packages/access-client/src/space.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as ED25519 from '@ucanto/principal/ed25519'
import { delegate, Schema, UCAN } from '@ucanto/core'
import { delegate, Schema, UCAN, error, fail } from '@ucanto/core'
import * as BIP39 from '@scure/bip39'
import { wordlist } from '@scure/bip39/wordlists/english'
import * as API from './types.js'
import * as Access from './access.js'
import * as Provider from './provider.js'

/**
* Data model for the (owned) space.
Expand Down Expand Up @@ -170,9 +171,7 @@ class OwnedSpace {
*/
async save({ agent = this.model.agent } = {}) {
if (!agent) {
return {
error: new Error('Please provide an agent to save the space into'),
}
return fail('Please provide an agent to save the space into')
}

const proof = await createAuthorization(this, { agent })
Expand All @@ -182,6 +181,19 @@ class OwnedSpace {
return { ok: {} }
}

/**
* @param {Authorization} authorization
* @param {object} options
* @param {API.Agent} [options.agent]
*/
provision({ proofs }, { agent = this.model.agent } = {}) {
if (!agent) {
return fail('Please provide an agent to save the space into')
}

return provision(this, { proofs, agent })
}

/**
* Creates a (UCAN) delegation that gives full access to the space to the
* specified `account`. At the moment we only allow `did:mailto` principal
Expand Down Expand Up @@ -243,6 +255,37 @@ export const fromDelegation = (delegation) => {
return new SharedSpace({ id: result.ok, delegation, meta })
}

/**
* @typedef {object} Authorization
* @property {API.Delegation[]} proofs
*
* @typedef {object} Space
* @property {() => API.SpaceDID} did
*/

/**
* @param {Space} space
* @param {object} options
* @param {API.Delegation[]} options.proofs
* @param {API.Agent} options.agent
*/
export const provision = async (space, { proofs, agent }) => {
const [capability] = proofs[0].capabilities

const { ok: account, error: reason } = Provider.AccountDID.read(
capability.with
)
if (reason) {
return error(reason)
}

return await Provider.add(agent, {
consumer: space.did(),
account,
proofs,
})
}

/**
* Represents a shared space, meaning a space for which we have a delegation
* and consequently have limited authority over.
Expand Down
11 changes: 11 additions & 0 deletions packages/capabilities/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [12.0.0](https://github.com/web3-storage/w3up/compare/capabilities-v11.4.1...capabilities-v12.0.0) (2023-11-15)


### ⚠ BREAKING CHANGES

* coupon ([#1136](https://github.com/web3-storage/w3up/issues/1136))

### Features

* coupon ([#1136](https://github.com/web3-storage/w3up/issues/1136)) ([1b94f2d](https://github.com/web3-storage/w3up/commit/1b94f2d3f6538d717d38b21dcb76657fd1f3e268))

## [11.4.1](https://github.com/web3-storage/w3up/compare/capabilities-v11.4.0...capabilities-v11.4.1) (2023-11-15)


Expand Down
2 changes: 1 addition & 1 deletion packages/capabilities/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-storage/capabilities",
"version": "11.4.1",
"version": "12.0.0",
"description": "Capabilities provided by web3.storage",
"homepage": "https://github.com/web3-storage/w3protocol/tree/main/packages/capabilities",
"repository": {
Expand Down
1 change: 0 additions & 1 deletion packages/capabilities/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import * as Top from '@web3-storage/capabilities/top'
import * as Types from '@web3-storage/capabilities/types'
import * as Upload from '@web3-storage/capabilities/upload'
import * as Utils from '@web3-storage/capabilities/utils'
import * as Voucher from '@web3-storage/capabilities/voucher'
import * as Filecoin from '@web3-storage/capabilities/filecoin'
import * as Aggregator from '@web3-storage/capabilities/filecoin/aggregator'
import * as DealTracker from '@web3-storage/capabilities/filecoin/deal-tracker'
Expand Down
7 changes: 7 additions & 0 deletions packages/filecoin-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [4.1.1](https://github.com/web3-storage/w3up/compare/filecoin-api-v4.1.0...filecoin-api-v4.1.1) (2023-11-15)


### Bug Fixes

* upgrade ucanto core ([#1127](https://github.com/web3-storage/w3up/issues/1127)) ([5ce4d22](https://github.com/web3-storage/w3up/commit/5ce4d2292d7e980da4a2ea0f1583f608a81157d2))

## [4.1.0](https://github.com/web3-storage/w3up/compare/filecoin-api-v4.0.6...filecoin-api-v4.1.0) (2023-11-08)


Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-storage/filecoin-api",
"version": "4.1.0",
"version": "4.1.1",
"type": "module",
"main": "./src/lib.js",
"files": [
Expand Down
7 changes: 7 additions & 0 deletions packages/upload-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [7.3.2](https://github.com/web3-storage/w3up/compare/upload-api-v7.3.1...upload-api-v7.3.2) (2023-11-15)


### Bug Fixes

* upgrade ucanto core ([#1127](https://github.com/web3-storage/w3up/issues/1127)) ([5ce4d22](https://github.com/web3-storage/w3up/commit/5ce4d2292d7e980da4a2ea0f1583f608a81157d2))

## [7.3.1](https://github.com/web3-storage/w3up/compare/upload-api-v7.3.0...upload-api-v7.3.1) (2023-11-09)


Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-storage/upload-api",
"version": "7.3.1",
"version": "7.3.2",
"type": "module",
"main": "./src/lib.js",
"files": [
Expand Down
17 changes: 17 additions & 0 deletions packages/w3up-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## [11.0.0](https://github.com/web3-storage/w3up/compare/w3up-client-v10.3.0...w3up-client-v11.0.0) (2023-11-15)


### ⚠ BREAKING CHANGES

* coupon ([#1136](https://github.com/web3-storage/w3up/issues/1136))

### Features

* coupon ([#1136](https://github.com/web3-storage/w3up/issues/1136)) ([1b94f2d](https://github.com/web3-storage/w3up/commit/1b94f2d3f6538d717d38b21dcb76657fd1f3e268))
* get receipt support in client ([#1135](https://github.com/web3-storage/w3up/issues/1135)) ([660d088](https://github.com/web3-storage/w3up/commit/660d0886e468d373b142470b50282b231e645d19))


### Bug Fixes

* upgrade ucanto core ([#1127](https://github.com/web3-storage/w3up/issues/1127)) ([5ce4d22](https://github.com/web3-storage/w3up/commit/5ce4d2292d7e980da4a2ea0f1583f608a81157d2))

## [10.3.0](https://github.com/web3-storage/w3up/compare/w3up-client-v10.2.0...w3up-client-v10.3.0) (2023-11-15)


Expand Down
3 changes: 2 additions & 1 deletion packages/w3up-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-storage/w3up-client",
"version": "10.3.0",
"version": "11.0.0",
"description": "Client for the w3up API",
"license": "Apache-2.0 OR MIT",
"type": "module",
Expand Down Expand Up @@ -89,6 +89,7 @@
"test:browser": "playwright-test --runner mocha 'test/**/!(*.node).test.js'",
"mock": "run-p mock:*",
"mock:bucket-200": "PORT=9200 STATUS=200 node test/helpers/bucket-server.js",
"mock:receipts-server": "PORT=9201 node test/helpers/receipts-server.js",
"rc": "npm version prerelease --preid rc",
"docs": "npm run build && typedoc --out docs-generated",
"docs:markdown": "npm run build && docusaurus generate-typedoc"
Expand Down
1 change: 1 addition & 0 deletions packages/w3up-client/src/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class Account {
* @param {API.SpaceDID} space
* @param {object} input
* @param {API.ProviderDID} [input.provider]
* @param {API.Agent} [input.agent]
*/
provision(space, input = {}) {
return provision(this.agent, {
Expand Down
4 changes: 3 additions & 1 deletion packages/w3up-client/src/base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Agent } from '@web3-storage/access/agent'
import { serviceConf } from './service.js'
import { serviceConf, receiptsEndpoint } from './service.js'

export class Base {
/**
Expand All @@ -18,6 +18,7 @@ export class Base {
* @param {import('@web3-storage/access').AgentData} agentData
* @param {object} [options]
* @param {import('./types.js').ServiceConf} [options.serviceConf]
* @param {URL} [options.receiptsEndpoint]
*/
constructor(agentData, options = {}) {
this._serviceConf = options.serviceConf ?? serviceConf
Expand All @@ -27,6 +28,7 @@ export class Base {
url: this._serviceConf.access.channel.url,
connection: this._serviceConf.access,
})
this._receiptsEndpoint = options.receiptsEndpoint ?? receiptsEndpoint
}

/**
Expand Down
Loading

0 comments on commit 9efed54

Please sign in to comment.