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 / pem-to-did.go
Last active June 2, 2025 10:09
PEM to DID, libp2p peer ID and base64pad private key.
package main
import (
crypto_ed25519 "crypto/ed25519"
"crypto/x509"
"encoding/pem"
"fmt"
"os"
"github.com/libp2p/go-libp2p/core/crypto"
@alanshaw
alanshaw / test.sh
Last active May 29, 2025 10:56
Is IPNI working yet?
echo 'alantest 2025-05-29' > test.txt
storacha up test.txt --verbose
# Should get:
# bafybeidamzcqbpfirdtrbjjhhybp5nfyl5vnjudbsoszg3jnbrwrjupetm
# Does IPNI have the info?
curl https://staging.ipni.storacha.network/cid/bafybeidamzcqbpfirdtrbjjhhybp5nfyl5vnjudbsoszg3jnbrwrjupetm
# Currently:
@alanshaw
alanshaw / slow.sh
Created May 12, 2025 15:37
Slow w3up
$ echo 'alantest 2025-05-12-1' | w3 up
created shard: 4.414ms
hashing shard: 0.013ms
invoking blob/add: 1.522s
invoking http/put: 181.018ms
invoking ucan/conclude http/put: 935.68ms
polling for receipt: 1.081s
hashing piece: 54.925ms
invoking filecoin/offer: 460.332ms
invoking blob/add: 1.216s
@alanshaw
alanshaw / decode-telegram-stripped-thumb.js
Last active April 10, 2025 15:36
Decode Telegram stripped thumb
// Ported from https://github.com/telegramdesktop/tdesktop/blob/1757dd856b84d23f83d4e562c94dde825f6eb40c/Telegram/SourceFiles/ui/image/image.cpp#L43
const decodeStrippedThumb = (bytes: Uint8Array) => {
if (bytes.length < 3 || bytes[0] !== 1) throw new Error('invalid thumb')
const real = new Uint8Array(header.length + (bytes.length - 2) + footer.length)
real.set(header)
real[164] = bytes[1]
real[166] = bytes[2]
real.set(bytes.subarray(3), header.length)
real.set(footer, header.length + (bytes.length - 2))
return real
@alanshaw
alanshaw / auth-flow.md
Last active March 20, 2025 17:37
Notes for the w3up auth flow

To login...

Client issues:

iss: did:key:agent
aud: did:web:web3.storage
can: access/authorize
with: did:key:agent
nb:
@alanshaw
alanshaw / priv-to-peer.go
Created March 12, 2025 12:28
Ucanto private key to libp2p Peer ID
package main
import (
"fmt"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
ed25519 "github.com/storacha/go-ucanto/principal/ed25519/signer"
)
@alanshaw
alanshaw / cli.sh
Last active June 4, 2025 11:03
env vars for w3cli
# dev
export STORACHA_SERVICE_DID=did:web:alan.up.storacha.network
export STORACHA_SERVICE_URL=https://n7js8smi24.execute-api.us-west-2.amazonaws.com
export STORACHA_STORE_NAME=storacha-cli-alan
export STORACHA_RECEIPTS_URL=https://n7js8smi24.execute-api.us-west-2.amazonaws.com/receipt/
export W3UP_SERVICE_DID=did:web:alan.up.storacha.network
export W3_STORE_NAME=storacha-cli-alan
export W3UP_SERVICE_URL=https://n7js8smi24.execute-api.us-west-2.amazonaws.com
export W3UP_RECEIPTS_ENDPOINT=https://n7js8smi24.execute-api.us-west-2.amazonaws.com/receipt/
@alanshaw
alanshaw / delegation-vis.js
Created February 6, 2025 17:34
Visualise a delegation
import fs from 'node:fs'
import { Readable } from 'node:stream'
import { CARReaderStream } from 'carstream'
import * as dagCBOR from '@ipld/dag-cbor'
import * as dagJSON from '@ipld/dag-json'
import * as DID from '@ipld/dag-ucan/did'
Readable.toWeb(fs.createReadStream('proof.car'))
.pipeThrough(new CARReaderStream())
.pipeTo(new WritableStream({
@alanshaw
alanshaw / bafkqaaa.txt
Created November 29, 2024 16:14
zero-length "identity" multihash with "raw" codec
\x01\x55\x00\x00
bafkqaaa
@alanshaw
alanshaw / cli.sh
Last active February 6, 2025 12:43
Env for storacha CLI STAGING
export STORACHA_SERVICE_DID=did:web:staging.up.storacha.network
export STORACHA_SERVICE_URL=https://staging.up.storacha.network
export STORACHA_STORE_NAME=storacha-cli-staging
export STORACHA_RECEIPTS_URL=https://staging.up.storacha.network/receipt/