-
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.
feat!: use w3up-client in keyring (#581)
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 I am releasing this as a breaking change - I don't think anything will break, but would prefer to let downstream users opt in to this
- Loading branch information
Showing
12 changed files
with
368 additions
and
298 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { test, expect } from 'vitest' | ||
import 'fake-indexeddb/auto' | ||
|
||
import { createClient } from '../src/index.js' | ||
|
||
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 client = await createClient() | ||
const space = await client.createSpace('test') | ||
expect(space).toBeTruthy() | ||
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.