-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR depends on storacha/w3up#504, which will require release and update here. With local symlink it works as expected.
- Loading branch information
Showing
32 changed files
with
16,481 additions
and
20,505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
import { info } from '@web3-storage/capabilities/space' | ||
import * as Space from '@web3-storage/capabilities/space' | ||
import { connect } from '@ucanto/client' | ||
import { Failure } from '@ucanto/server' | ||
import { CAR, CBOR, HTTP } from '@ucanto/transport' | ||
import fetch from '@web-std/fetch' | ||
|
||
/** | ||
* @param {import('@ucanto/interface').Signer} issuer Issuer of UCAN invocations to the Access service. | ||
* @param {import('@ucanto/interface').Principal} serviceDID DID of the Access service. | ||
* @param {URL} serviceURL URL of the Access service. | ||
* @returns {import('./service/types').AccessClient} | ||
* @returns {import('@web3-storage/upload-api').AccessVerifier} | ||
*/ | ||
export function createAccessClient (issuer, serviceDID, serviceURL) { | ||
export function createAccessClient(issuer, serviceDID, serviceURL) { | ||
/** @type {import('@ucanto/server').ConnectionView<import('@web3-storage/access/types').Service>} */ | ||
const conn = connect({ | ||
id: serviceDID, | ||
encoder: CAR, | ||
decoder: CBOR, | ||
channel: HTTP.open({ url: serviceURL, method: 'POST', fetch }) | ||
channel: HTTP.open({ url: serviceURL, method: 'POST', fetch }), | ||
}) | ||
|
||
return { | ||
async verifyInvocation (invocation) { | ||
async allocateSpace(invocation) { | ||
if (!invocation.capabilities.length) return true | ||
// if info capability is derivable from the passed capability, then we'll | ||
// receive a response and know that the invocation issuer has verified | ||
// themselves with w3access. | ||
const res = await info | ||
.invoke({ | ||
issuer, | ||
audience: serviceDID, | ||
// @ts-expect-error | ||
with: invocation.capabilities[0].with, | ||
proofs: [invocation] | ||
}) | ||
.execute(conn) | ||
const info = Space.info.invoke({ | ||
issuer, | ||
audience: serviceDID, | ||
// @ts-expect-error | ||
with: invocation.capabilities[0].with, | ||
proofs: [invocation], | ||
}) | ||
|
||
if (res.error) console.warn('invocation verification failed', res) | ||
return !res.error | ||
} | ||
const result = await info.execute(conn) | ||
|
||
if (result.error) { | ||
return result.error && result.name === 'SpaceUnknown' | ||
? new Failure(`Space has no storage provider`, { cause: result }) | ||
: result | ||
} else { | ||
return {} | ||
} | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.