Skip to content

Instantly share code, notes, and snippets.

View bumblefudge's full-sized avatar
👶
baby on board, not sleeping so good

Bumblefudge bumblefudge

👶
baby on board, not sleeping so good
View GitHub Profile
@bumblefudge
bumblefudge / gist:8a28608777699034e893aa4874d1ea31
Created February 20, 2024 21:43
Expressing public keys and blockchain addresses as "street-legal DIDs"
DID syntax can be kind of confusing and arbitrary-seeming but it's basically just like URNs, an heirarchy of arbitrary schemata. Here's a tutorial on expressing public keys (or their hashed "address" forms popular in cryto networks) "as street-legal DIDs".
If it's a public key, the most common syntax is a `did:key`[^1]:
```
did:key:<base58btc multibase(<pub key bytes appropriately multicodeced>)>
```
The magic number in this case is 0xe7 [^2], which you'll want to prepend to the raw bytes.
Note that if you've never used `multiformats` before and you're not using IPFS/Protocol-Labs tooling, there's a step some people miss: you have to pad the raw bytes into an "unsigned varint"[^3] before base58btc-encoding but after prepending the magic number.
One nice sideeffect of this padding + prefacing with a byte or two of sigil is that once ASCII-encoded, there ends up being a one-character prefix that is constant for each major key type to date [^4].
curl 'https://indexer.tzprofiles.com/v1/graphql' -X POST -H 'x-hasura-admin-secret: dEaDbEEF' --data-raw '{"query":"query MyQuery {\n tzprofiles(distinct_on: account, limit: 100000) {\n valid_claims\n account\n }\n}\n","variables":null,"operationName":"MyQuery"}' > /tmp/hasura.json
cat /tmp/hasura.json | jq '.data.tzprofiles[] | .account as $account | select(.valid_claims[][1] | contains($account) | not)'
cat /tmp/hasura.json | jq '.data.tzprofiles[] | .account as $account | select(.valid_claims[][1] | contains("did:web:tzprofiles.com") or contains("BasicProfile") or contains("EthereumAddressControl") or contains("EthereumControl") | not)'

Keybase proof

I hereby claim:

  • I am bumblefudge on github.
  • I am by_caballero (https://keybase.io/by_caballero) on keybase.
  • I have a public key ASBHmmPVqPqk7K5-B9BODVJRwJNWn6kCtV-7RKtLxpF17Ao

To claim this, I am signing this object: