Skip to content

Instantly share code, notes, and snippets.

View alanshaw's full-sized avatar
🌶️
https://storacha.network

ash alanshaw

🌶️
https://storacha.network
View GitHub Profile
@alanshaw
alanshaw / mkdelegate.js
Last active November 7, 2024 22:18
Delegations for the Storacha Network
// node mkdelegate.js <private-key>
import { delegate } from '@ucanto/core'
import * as ed25519 from '@ucanto/principal/ed25519'
import * as Link from 'multiformats/link'
import { identity } from 'multiformats/hashes/identity'
import { base64 } from 'multiformats/bases/base64'
import * as DID from '@ipld/dag-ucan/did'
const indexingServiceDID = 'did:web:staging.indexer.storacha.network'
const uploadServiceDID = 'did:web:staging.upload.storacha.network'
@alanshaw
alanshaw / get-commitments.js
Created October 31, 2024 11:49
Get the commitments
const cids = [
'bafybeiei72mvsmckxh6jliaxtgtmktcucw6zjktmjko6lpdb76uy677nym',
'bafybeige7or65xqaqzbrsrnyf3alrcmr3mbkiwvbevc3hpkpiydbixjcte',
'bafybeidovp3gf6h6aye6vv25o3r6ayc32c3znzgijtvqqmqrnsfcljvz7i',
'bafybeigqhr6wptfw6a2jjvvd6alq73mgnn2ugfmnnzdksmaid44divhnju',
'bafybeicih3gpoxip4n2ozuqqfskdwymxcr27i6xgtdmnivuhy5q76weklu',
'bafybeia2fnngg5gzhc6v6ul23j67m4b4j3ekyxnonvyx5n4uo7jtq236my',
'bafybeieymcyqlnif4rtzt3cfterlyudr6lz6bpt3kkchji7bxgcjq3a4iy',
'bafybeibh4swn5lir77xo3sdxps5h3kl6xygmhutdkqwewnyrdvjz435nue',
'bafybeifef47tawlpfdjlrmvohjrnxgozarrwxkrdcqx3mmwigf4fakfr6a',
@alanshaw
alanshaw / gocov.sh
Last active September 18, 2024 09:21
Golang coverage
go test -coverprofile=c.out -v ./...
go tool cover -html="c.out"
# or
go install github.com/cancue/covreport@latest
go test -coverprofile=c.out -v ./...
~/go/bin/covreport -i c.out
open cover.html
const sumUsage = client => {
const period = getPeriod(new Date())
/** @type {Record<ProviderDID, Record<SpaceDID, number>>} */
let totalBySpace = {}
let total = 0
for (const account of Object.values(client.accounts())) {
const subscriptions = await client.capability.subscriptions.list(account.did())
for (const { consumers } of subscriptions.results) {
for (const space of consumers) {
const report = await client.capability.usage.report(space)
@alanshaw
alanshaw / fx.md
Created September 19, 2023 18:06
How fx invocations work

Want to do an async task of adding two number together? Not problem.

invoke do/async-addition 40, 2
  # create a delegation for the result and get the CID
  result-cid = cid-for(delegate(do/async-addition-result 40, 2))

  # create a receipt for this invocation, including the CID of the result delegation
  receipt = generate-receipt-for(do/async-addition 40, 2, fx.join: result-cid)
@alanshaw
alanshaw / lassie-fetch.sh
Created June 30, 2023 11:17
Lassie fetch from dag.w3s.link
lassie fetch --dag-scope=entity -providers=/dns4/dag.w3s.link/tcp/443/https/p2p/QmUA9D3H7HeCYsirB3KmPSvZh3dNXMZas6Lwgr4fv1HTTp bafybeicuc7vfbxzaperdc6ng2c4ufeulyjpfrmwuxhxrm6cfdamp5hpw5i
@alanshaw
alanshaw / curl.sh
Created May 19, 2023 14:19
curling some dfs carz from dag.w3s.link
$ curl -v -H "Accept: application/vnd.ipld.car;order=dfs" https://dag.w3s.link/ipfs/bafybeibrqc2se2p3k4kfdwg7deigdggamlumemkiggrnqw3edrjosqhvnm --output my.dfs.car
...
> GET /ipfs/bafybeibrqc2se2p3k4kfdwg7deigdggamlumemkiggrnqw3edrjosqhvnm HTTP/2
> Host: dag.w3s.link
> user-agent: curl/7.77.0
> accept: application/vnd.ipld.car;order=dfs
>
...
< HTTP/2 200
< date: Fri, 19 May 2023 14:16:47 GMT
@alanshaw
alanshaw / directory-builder.js
Created March 28, 2023 17:56
Building a directory after uploading individual files async
import { createWriter } from '@ipld/unixfs'
import * as CAR from '@web3-storage/upload-client/car'
import { create } from '@web3-storage/w3up-client'
/**
* @param {import('@web3-storage/w3up-client').Client} client
* @param {import('@web3-storage/w3up-client/types').FileLike} file
*/
async function uploadFile (client, file) {
/** @type {import('@web3-storage/upload-client/types').DirectoryEntryLink[]} */
@alanshaw
alanshaw / create-perma-map-fixture.js
Created March 7, 2023 15:26
Create a fixture for `@perma/map` from a CAR file containing a HAMT sharded directory
import { CarIndexedReader } from '@ipld/car'
import * as pb from '@ipld/dag-pb'
import { UnixFS } from 'ipfs-unixfs'
// usage: node create-perma-map-fixture sharded-dir.car
/** @typedef {{ bitfield: number[], links: Array<Link|Element>, prefix?: string }} Link */
/** @typedef {{ key: string, value: string, prefix: string }} Element */
async function main () {
@alanshaw
alanshaw / upload-large-cars.md
Last active January 11, 2023 18:29
Upload large CAR files to w3up

Install the new CLI:

npm install -g @web3-storage/w3cli

Create and register new space:

w3 space create SPACENAME