Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: utility exports for better UX #1505

Merged
merged 2 commits into from
Jun 13, 2024
Merged

feat: utility exports for better UX #1505

merged 2 commits into from
Jun 13, 2024

Conversation

alanshaw
Copy link
Member

This PR re-exports some ucanto exports and a utility function to parse a proof (in any current or legacy format). This should make working with the client easier as all the things you need are available (no additional deps to install), makes the docs much more succinct and easier to follow, and actually allows you to import a base64 encoded delegation successfully from any period in time you obtained it.

Here's one of many code snippets from the docs site that will be improved by this PR:

Before

import * as Client from '@web3-storage/w3up-client'
import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'
import { importDAG } from '@ucanto/core/delegation'
import { CarReader } from '@ipld/car'
import * as Signer from '@ucanto/principal/ed25519'
 
async function main () {
  // Load client with specific private key
  const principal = Signer.parse(process.env.KEY)
  const store = new StoreMemory()
  const client = await Client.create({ principal, store })
  // Add proof that this agent has been delegated capabilities on the space
  const proof = await parseProof(process.env.PROOF)
  const space = await client.addSpace(proof)
  await client.setCurrentSpace(space.did())
  // READY to go!
}
 
/** @param {string} data Base64 encoded CAR file */
async function parseProof (data) {
  const blocks = []
  const reader = await CarReader.fromBytes(Buffer.from(data, 'base64'))
  for await (const block of reader.blocks()) {
    blocks.push(block)
  }
  return importDAG(blocks)
}

After

import * as Client from '@web3-storage/w3up-client'
import { Signer } from '@web3-storage/w3up-client/principal/ed25519'
import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'
import * as Proof from '@web3-storage/w3up-client/proof'
 
async function main () {
  // Load client with specific private key
  const principal = Signer.parse(process.env.KEY)
  const store = new StoreMemory()
  const client = await Client.create({ principal, store })
  // Add proof that this agent has been delegated capabilities on the space
  const proof = await Proof.parse(process.env.PROOF)
  const space = await client.addSpace(proof)
  await client.setCurrentSpace(space.did())
  // READY to go!
}

@alanshaw alanshaw merged commit 54b0d93 into main Jun 13, 2024
3 checks passed
@alanshaw alanshaw deleted the feat/utility-exports branch June 13, 2024 22:18
alanshaw pushed a commit that referenced this pull request Jun 13, 2024
🤖 I have created a release *beep* *boop*
---


##
[15.0.0](w3up-client-v14.1.1...w3up-client-v15.0.0)
(2024-06-13)


### ⚠ BREAKING CHANGES

* `AllocationsStorage` and `BlobsStorage` methods not take
`MultihashDigest` types instead of `Uint8Array`s.

### Features

* utility exports for better UX
([#1505](#1505))
([54b0d93](54b0d93))


### Fixes

* use MultihashDigest type in stores
([#1474](#1474))
([6c6a3bd](6c6a3bd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants