-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
per #295 rework the keyring to use w3up-client rather than the lower level access library I'd like to refactor these APIs soon, but for now I'm keeping them unchanged to minimize downstream changes
- Loading branch information
Showing
9 changed files
with
229 additions
and
205 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Service as AccessService } from '@web3-storage/access/types' | ||
import type { Service as UploadService } from '@web3-storage/upload-client/types' | ||
import type { StorefrontService } from '@web3-storage/filecoin-client/storefront' | ||
import { connect } from '@ucanto/client' | ||
import { CAR, HTTP } from '@ucanto/transport' | ||
import type { | ||
ConnectionView, | ||
Principal | ||
} from '@ucanto/interface' | ||
import * as DID from '@ipld/dag-ucan/did' | ||
import { ServiceConf } from '@web3-storage/w3up-client/dist/src/types' | ||
|
||
type Service = AccessService & UploadService & StorefrontService | ||
|
||
export interface ServiceConfig { | ||
servicePrincipal?: Principal | ||
connection?: ConnectionView<Service> | ||
} | ||
|
||
export function createServiceConf ({ servicePrincipal, connection }: ServiceConfig): ServiceConf { | ||
const id = servicePrincipal != null ? servicePrincipal : DID.parse('did:web:web3.storage') | ||
const serviceConnection = (connection != null) | ||
? connection | ||
: connect<Service>({ | ||
id, | ||
codec: CAR.outbound, | ||
channel: HTTP.open<Service>({ | ||
url: new URL('https://up.web3.storage'), | ||
method: 'POST' | ||
}) | ||
}) | ||
return { | ||
access: serviceConnection, | ||
upload: serviceConnection, | ||
filecoin: serviceConnection | ||
} | ||
} |
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,23 +1,18 @@ | ||
import { test, expect } from 'vitest' | ||
import 'fake-indexeddb/auto' | ||
|
||
import { createAgent } from '../src/index.js' | ||
import { createClient } from '../src/index.js' | ||
|
||
test('createAgent', async () => { | ||
const agent = await createAgent() | ||
expect(agent).toBeTruthy() | ||
expect(agent.did().startsWith('did:key')).toBe(true) | ||
expect(agent.spaces.size).to.eql(0) | ||
test('createClient', async () => { | ||
const client = await createClient() | ||
expect(client).toBeTruthy() | ||
expect(client.did().startsWith('did:key')).toBe(true) | ||
expect(client.spaces().length).to.eql(0) | ||
}) | ||
|
||
test('createSpace', async () => { | ||
const agent = await createAgent() | ||
const space = await agent.createSpace('test') | ||
const client = await createClient() | ||
const space = await client.createSpace('test') | ||
expect(space).toBeTruthy() | ||
expect(space.did.startsWith('did:key:')).toBe(true) | ||
}) | ||
|
||
test('registerSpace fails if no current space is set', async () => { | ||
const agent = await createAgent() | ||
await expect(agent.registerSpace('[email protected]')).rejects.toThrowError() | ||
expect(space.did().startsWith('did:key:')).toBe(true) | ||
}) |
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.