multiformats / multiformats/js-multiformats
consider adding `toURL` method to embed best practices of serializing cid to URL
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 268
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
There had been various discussions about the fact that in the wild we see IPFS urls to specific gateways. I think we can bake a best practice into CID implementation by adding a method like:
interface CID {
// ... stuff we already have
/**
* Encodes CID into a URL object.
*
* @example
* ```js
* const cid = CID.parse('QmbrRJJNKmPDUAZ8CGwn1WNx2C7xP4J284VWoAUDaCiLaD')
* cid.toURL().href // 'ipfs://bafybeigizayotjo4whdurcq6ge7nrgfyxox7ji7oviesmnvgrnxn3nakni/'
* ```
*
* Optionally you could provide a gateway URL to encode CID to a URL in that gateway.
* @example
* ```js
* const cid = CID.parse('QmbrRJJNKmPDUAZ8CGwn1WNx2C7xP4J284VWoAUDaCiLaD')
* cid.toURL({ gateway: new URL('https://dweb.link') }).href
* // => 'https://dweb.link/ipfs/bafybeigizayotjo4whdurcq6ge7nrgfyxox7ji7oviesmnvgrnxn3nakni'
* ```
*/
toURL(options?: { gateway?: URL }):URL
}
Note that here we reinforce several of the best practices:
ipfs://${cidv1}is the default that we to see.- We want to encourage CID v1 because it addresses bunch of issues that we have with v0.
Gateways URLs are origin separated.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CID interface and the two URL examples in the issue, then inspect the repository's existing CID implementation and tests to identify the appropriate entry point. Determine the expected behavior for default ipfs URLs, CID version handling, and gateway URLs; the issue is complete when those semantics are agreed and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100