From f23cf12dae0a0131963c2d5c83ab8408476db1e4 Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Mon, 2 May 2022 17:33:08 -0500 Subject: [PATCH] Change protocol name to ADX (#96) * Name change to ADX * readme updates * use did:example * quick readme edit * typo --- .gitignore | 4 - README.md | 26 +++--- cli/README.md | 4 +- cli/package.json | 4 +- cli/src/commands/dev/spam.ts | 2 +- cli/src/commands/interactions/like.ts | 2 +- cli/src/commands/interactions/unlike.ts | 2 +- cli/src/commands/posts/delete-post.ts | 2 +- cli/src/commands/posts/edit-post.ts | 2 +- cli/src/commands/posts/feed.ts | 2 +- cli/src/commands/posts/timeline.ts | 2 +- cli/src/commands/setup/init.ts | 4 +- cli/src/lib/client.ts | 2 +- cli/src/lib/config.ts | 6 +- cli/src/lib/env.ts | 2 +- cli/src/lib/usage.ts | 4 +- common/package.json | 2 +- ...luesky-capability.ts => adx-capability.ts} | 80 +++++++++---------- common/src/auth/builders.ts | 20 +---- common/src/auth/index.ts | 2 +- common/src/auth/ucan-checks.ts | 16 ++-- common/src/index.ts | 1 + common/src/microblog/const.ts | 2 +- common/src/microblog/delegator.ts | 1 - common/src/microblog/full.ts | 2 - common/src/microblog/reader.ts | 3 +- common/src/repo/delta.ts | 4 +- common/src/repo/index.ts | 10 +-- common/test/auth.ts | 6 +- common/test/delta.ts | 2 +- common/test/repo.ts | 4 +- common/test/sync.ts | 2 +- package.json | 12 +-- server/package.json | 4 +- server/src/auth.ts | 2 +- server/src/db/index.ts | 4 +- server/src/error.ts | 2 +- server/src/index.ts | 2 +- server/src/routes/data/interaction.ts | 2 +- server/src/routes/data/post.ts | 2 +- server/src/routes/data/relationship.ts | 2 +- server/src/routes/data/repo.ts | 2 +- server/src/routes/id.ts | 2 +- server/src/routes/indexer/count.ts | 2 +- server/src/routes/indexer/feed.ts | 2 +- server/src/routes/indexer/post-info.ts | 2 +- server/src/routes/indexer/timeline.ts | 2 +- server/src/server.ts | 4 +- server/src/subscriptions.ts | 2 +- server/src/util.ts | 3 +- server/test/_util.ts | 2 +- server/test/delegator-client.ts | 2 +- server/test/indexer.ts | 2 +- 53 files changed, 132 insertions(+), 154 deletions(-) rename common/src/auth/{bluesky-capability.ts => adx-capability.ts} (58%) diff --git a/.gitignore b/.gitignore index 0d0647ba498..6d105fecc8c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,9 +19,5 @@ analytics.txt /**/*/.data /**/*/yarn-error.log -go/bluesky -go/bsky -go/server - server/blockstore server/dev.sqlite diff --git a/README.md b/README.md index eaaee235965..bc5015e6ba0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Bluesky Experiment ๐Ÿงช +# Authenticated Data eXperiment (ADX) ๐Ÿงช -Welcome ๐Ÿ‘‹ +This is an early proof of concept for Bluesky's data protocol, which we've affectionately termed ADX - Authenticated Data eXperiment. -This is an early proof of concept for the Bluesky data network. We built this for two primary reasons: +We built this for two primary reasons: - To explore and demonstrate some of the core concepts that we're working with: content addressing, user held keys, user generated authority, and a federated network topology - To help identify the sort of interfaces we'll want and the rough edges and pain points that we'll hit along the way @@ -10,7 +10,7 @@ This is an early proof of concept for the Bluesky data network. We built this fo Please do not try to build your next big social network on this. There are many rough edges. Interfaces and data structures are likely to radically change, and we took some shortcuts on concepts that were not in the scope of this demo (key management, schemas, indexing, to name a few). This experiment is primarily confined to the data & authorization layer with hints at some of the other systems. -To learn more about the Bluesky network, and get a fuller picture of what we're building towards check out our docs on [Network architecture]() and the [Blogpost on self-authenticating data structures](https://blueskyweb.xyz/blog/3-6-2022-a-self-authenticating-social-protocol). +To learn more about the ADX network, and get a fuller picture of what we're building towards check out our docs on [Network architecture]() and the [Blogpost on self-authenticating data structures](https://blueskyweb.xyz/blog/3-6-2022-a-self-authenticating-social-protocol). All that being said, we're very excited to share some of the work that we've done here. Please play around with the server & CLI, poke around the code, even build a small demo app to get the feel for it! @@ -22,13 +22,13 @@ And without further ado, let's dive into what you'll find here. This is a monorepo containing three packages: -- `common`: This is the bluesky SDK that contains implementations of: +- `common`: This is the adx SDK that contains implementations of: - the repository data structure - a sample network namespace (microblogging) with both a full client and delegator client implementation - - an authorization library for working with bluesky-capable UCANs - - some helpers for making calls to a bluesky data server + - an authorization library for working with adx-capable UCANs + - some helpers for making calls to a adx data server -- `server`: This is an implementation of a bluesky server. For simplicity's sake, it actually combines the function of three "roles" in the network: +- `server`: This is an implementation of a adx server. For simplicity's sake, it actually combines the function of three "roles" in the network: - **Identity:** - maintains a mapping of username -> DID - **Data:** @@ -41,7 +41,7 @@ This is a monorepo containing three packages: - stores an indexed version of repositories that it is hosting or that its user's are following - returned global view of data including follower lists, aggregated like counts, and user timelines. -- `cli`: This is a basic command line interface for interactions with the bluesky network : +- `cli`: This is a basic command line interface for interactions with the adx network: - creating a local repository - registering a user - creating/editing/deleting posts @@ -81,10 +81,10 @@ From project root: (2) yarn server:alt # runs on localhost:2584 # set an env var to store alice's repo in a scoped dir -(3) export SKY_REPO_PATH="~/.sky-alice" +(3) export ADX_REPO_PATH="~/.adx-alice" # set an env var to store bob's repo in a scoped dir -(4) export SKY_REPO_PATH="~/.sky-bob" +(4) export ADX_REPO_PATH="~/.adx-bob" # register alice (3) yarn cli init @@ -174,13 +174,13 @@ Therefore we try to talk about the general concept as "interactions" and the par ### DIDs and UCANs -In this prototype a user's root DID is a simple `did:key`. In the future, these will be more permanent identifiers such as `did:bsky` (read our proposal in the architecture docs) or `did:ion`. +In this prototype a user's root DID is a simple `did:key`. In the future, these will be more permanent identifiers such as `did:ion` or our currently unnamed consortium-provided DID proposed in the architecture docs. The DID network is outside of the scope of this prototype. However, a DID is the canoncial, unchanging identifier for a user. and is needed in ordcer to enable data/server interop. Therefore we run a very simple DID network that only allows POSTs and GETs (with signature checks). The DID network is run _on_ the data server (`http://localhost:2583/did-network`), however every server that is running communicates with the _same_ data server when it comes to DID network requests. As DIDs are self-describing for resolution, we emulate this by hard coding how to discover a DID (ie "always go to _this particular address_ not your personal data server"). You'll notice that we delegate a UCAN from the root key to the root key (which is a no-op), this is to mirror the process of receiving a fully delegated UCAN _from your actual root key_ to a _fully permissioned device key_. -You'll also notice that the DID for the microblogging namespace is just `did:bsky:microblog` (which is not an actual valid DID). This is a stand in until we have an addressed network for schemas. +You'll also notice that the DID for the microblogging namespace is just `did:example:microblog` (which is not an actual valid DID). This is a stand in until we have an addressed network for schemas. UCAN permissions are also simplified at the current moment, allowing for scoped `WRITE` permission or full-repo `MAINTENANCE` permission. These permissions will be expanding in the future to allow presenting CRUD operations, and more detailed maintenance (ie creation vs merging vs cleanup, etc) diff --git a/cli/README.md b/cli/README.md index 62ad2755bd9..acf5b46ad8a 100644 --- a/cli/README.md +++ b/cli/README.md @@ -1,3 +1,3 @@ -# @bluesky/cli +# @adx/cli -The command line interface for the SKY protocol. \ No newline at end of file +The command line interface for ADX. \ No newline at end of file diff --git a/cli/package.json b/cli/package.json index 85751f3ff43..42b8c625de5 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,5 +1,5 @@ { - "name": "@bluesky/cli", + "name": "@adx/cli", "version": "0.0.1", "type": "module", "scripts": { @@ -7,7 +7,7 @@ "build": "(cd ../common && yarn build) && tsc --project tsconfig.json" }, "dependencies": { - "@bluesky/common": "*", + "@adx/common": "*", "chalk": "^5.0.0", "minimist": "^1.2.5", "multiformats": "^9.6.4", diff --git a/cli/src/commands/dev/spam.ts b/cli/src/commands/dev/spam.ts index 21d10e6812a..36f99a9dab7 100644 --- a/cli/src/commands/dev/spam.ts +++ b/cli/src/commands/dev/spam.ts @@ -1,7 +1,7 @@ import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' function makeRandText(l: number) { const set = ' abcdefghijklmnopqrstuvwxyz ' diff --git a/cli/src/commands/interactions/like.ts b/cli/src/commands/interactions/like.ts index 81c9ac039ae..e134a6bfa87 100644 --- a/cli/src/commands/interactions/like.ts +++ b/cli/src/commands/interactions/like.ts @@ -1,7 +1,7 @@ import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' export default cmd({ name: 'like', diff --git a/cli/src/commands/interactions/unlike.ts b/cli/src/commands/interactions/unlike.ts index 3866fecb4d2..2b9bc3d369f 100644 --- a/cli/src/commands/interactions/unlike.ts +++ b/cli/src/commands/interactions/unlike.ts @@ -1,7 +1,7 @@ import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' export default cmd({ name: 'unlike', diff --git a/cli/src/commands/posts/delete-post.ts b/cli/src/commands/posts/delete-post.ts index c61ac3790b2..987909170f8 100644 --- a/cli/src/commands/posts/delete-post.ts +++ b/cli/src/commands/posts/delete-post.ts @@ -1,7 +1,7 @@ import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' export default cmd({ name: 'delete post', diff --git a/cli/src/commands/posts/edit-post.ts b/cli/src/commands/posts/edit-post.ts index 77e3ab02405..fab63dcdb24 100644 --- a/cli/src/commands/posts/edit-post.ts +++ b/cli/src/commands/posts/edit-post.ts @@ -1,7 +1,7 @@ import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' export default cmd({ name: 'edit post', diff --git a/cli/src/commands/posts/feed.ts b/cli/src/commands/posts/feed.ts index 067ac10e1cf..5f9c54347c1 100644 --- a/cli/src/commands/posts/feed.ts +++ b/cli/src/commands/posts/feed.ts @@ -1,7 +1,7 @@ import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' import chalk from 'chalk' import { formatDate } from '../../lib/util.js' diff --git a/cli/src/commands/posts/timeline.ts b/cli/src/commands/posts/timeline.ts index 5232064b329..3b4c93469f4 100644 --- a/cli/src/commands/posts/timeline.ts +++ b/cli/src/commands/posts/timeline.ts @@ -2,7 +2,7 @@ import chalk from 'chalk' import cmd from '../../lib/command.js' import { loadClient } from '../../lib/client.js' import { REPO_PATH } from '../../lib/env.js' -import { TID } from '@bluesky/common' +import { TID } from '@adx/common' import { formatDate } from '../../lib/util.js' export default cmd({ diff --git a/cli/src/commands/setup/init.ts b/cli/src/commands/setup/init.ts index 06e62bec2e7..e2321ec1677 100644 --- a/cli/src/commands/setup/init.ts +++ b/cli/src/commands/setup/init.ts @@ -10,7 +10,7 @@ prompt.message = '' export default cmd({ name: 'init', category: 'setup', - help: 'Create a new scdb repo.', + help: 'Create a new adx repo.', opts: [ { name: 'server', type: 'string', default: '' }, { name: 'username', type: 'string', default: '' }, @@ -31,7 +31,7 @@ export default cmd({ } if (!username || !server) { - console.log(`This utility will initialize your sky repo.`) + console.log(`This utility will initialize your adx repo.`) console.log(`Press ^C at any time to quit.`) prompt.start() username = ( diff --git a/cli/src/lib/client.ts b/cli/src/lib/client.ts index b12faefc03b..c085e74db3a 100644 --- a/cli/src/lib/client.ts +++ b/cli/src/lib/client.ts @@ -5,7 +5,7 @@ import { MicroblogDelegator, MicroblogFull, Repo, -} from '@bluesky/common' +} from '@adx/common' import * as config from '../lib/config.js' export const loadClient = async ( diff --git a/cli/src/lib/config.ts b/cli/src/lib/config.ts index 917c26ef5ad..0f6cbb0a7f3 100644 --- a/cli/src/lib/config.ts +++ b/cli/src/lib/config.ts @@ -1,7 +1,7 @@ import path from 'path' import { promises as fsp } from 'fs' import * as ucan from 'ucans' -import { auth } from '@bluesky/common' +import { auth } from '@adx/common' import { CID } from 'multiformats/cid' export type AccountJson = { @@ -40,7 +40,7 @@ export const writeCfg = async ( delegator, } await fsp.writeFile( - path.join(repoPath, 'sky.key'), + path.join(repoPath, 'adx.key'), await keypair.export(), 'utf-8', ) @@ -67,7 +67,7 @@ export const cfgExists = async (repoPath: string): Promise => { export const loadCfg = async (repoPath: string): Promise => { const account = await readAccountFile(repoPath, 'account.json') - const secretKeyStr = (await readFile(repoPath, 'sky.key', 'utf-8')) as string + const secretKeyStr = (await readFile(repoPath, 'adx.key', 'utf-8')) as string const keypair = ucan.EdKeypair.fromSecretKey(secretKeyStr) const tokenStr = (await readFile(repoPath, 'full.ucan', 'utf-8')) as string const ucanStore = await ucan.Store.fromTokens([tokenStr]) diff --git a/cli/src/lib/env.ts b/cli/src/lib/env.ts index 774d4c25a36..d19cae5ff8a 100644 --- a/cli/src/lib/env.ts +++ b/cli/src/lib/env.ts @@ -1,7 +1,7 @@ import os from 'os' import path from 'path' -export const REPO_PATH = expandPath(process.env.SKY_REPO_PATH || `~/.sky`) +export const REPO_PATH = expandPath(process.env.ADX_REPO_PATH || `~/.adx`) function expandPath(str: string) { if (str.startsWith('~')) { diff --git a/cli/src/lib/usage.ts b/cli/src/lib/usage.ts index 274729cc3a0..4ad93bd016a 100644 --- a/cli/src/lib/usage.ts +++ b/cli/src/lib/usage.ts @@ -13,7 +13,7 @@ export function usage(err: any) { console.log('') } console.log( - `Usage: ${chalk.bold(`scdb`)} ${chalk.gray(`[opts...]`)}`, + `Usage: ${chalk.bold(`adx`)} ${chalk.gray(`[opts...]`)}`, ) let lhsLength = 0 @@ -47,7 +47,7 @@ export function usage(err: any) { } export function commandUsage(cmd: RegisteredCmd) { - console.log(`${chalk.bold(`scdb ${cmd.name}`)}${cmdArgs(cmd)}${cmdHelp(cmd)}`) + console.log(`${chalk.bold(`adx ${cmd.name}`)}${cmdArgs(cmd)}${cmdHelp(cmd)}`) if (cmd.opts?.length) { console.log('') for (const opt of cmd.opts) { diff --git a/common/package.json b/common/package.json index f3dc5dc8c79..a99543799f1 100644 --- a/common/package.json +++ b/common/package.json @@ -1,5 +1,5 @@ { - "name": "@bluesky/common", + "name": "@adx/common", "version": "0.0.1", "main": "dist/index.js", "type": "module", diff --git a/common/src/auth/bluesky-capability.ts b/common/src/auth/adx-capability.ts similarity index 58% rename from common/src/auth/bluesky-capability.ts rename to common/src/auth/adx-capability.ts index 5d966f97c8b..cabfc41abeb 100644 --- a/common/src/auth/bluesky-capability.ts +++ b/common/src/auth/adx-capability.ts @@ -10,22 +10,22 @@ import TID from '../repo/tid' import { Collection } from '../repo/types' /* -Bluesky Ucans: +ADX Ucans: -Resource name: 'bluesky' +Resource name: 'adx' - Full permission for account: - did:bsky:userDid|* + did:example:userDid|* - Permission to write to particular namespace: - did:bsky:userDid|did:bsky:microblog|* + did:example:userDid|did:example:microblog|* - Permission to make only interactions in a given namespace: - did:bsky:userDid|did:bsky:microblog|interactions|* + did:example:userDid|did:example:microblog|interactions|* - Permission to create a single interaction on user's behalf: - did:bsky:userDid|did:bsky:microblog|interactions|234567abcdefg + did:example:userDid|did:example:microblog|interactions|234567abcdefg Example: { - bluesky: 'did:bsky:abcdefg|did:bsky:microblog|*' + adx: 'did:example:abcdefg|did:example:microblog|*' cap: 'WRITE' } @@ -34,28 +34,26 @@ At the moment, for demonstration purposes, we support only two capability level: - 'MAINTENANCE': this does not allow updates to repo objects, but allows maintenance of the repo, such as repo creation */ -export const BlueskyAbilityLevels = { +export const AdxAbilityLevels = { MAINTENANCE: 0, WRITE: 1, } -export type BlueskyAbility = keyof typeof BlueskyAbilityLevels +export type AdxAbility = keyof typeof AdxAbilityLevels -export const isBlueskyAbility = ( - ability: string, -): ability is BlueskyAbility => { +export const isAdxAbility = (ability: string): ability is AdxAbility => { return ability === 'MAINTENANCE' || ability === 'WRITE' } -export interface BlueskyCapability extends Capability { - bluesky: string - cap: BlueskyAbility +export interface AdxCapability extends Capability { + adx: string + cap: AdxAbility } -export const blueskySemantics: CapabilitySemantics = { - tryParsing(cap: Capability): BlueskyCapability | null { - if (typeof cap.bluesky === 'string' && isBlueskyAbility(cap.cap)) { +export const adxSemantics: CapabilitySemantics = { + tryParsing(cap: Capability): AdxCapability | null { + if (typeof cap.adx === 'string' && isAdxAbility(cap.cap)) { return { - bluesky: cap.bluesky, + adx: cap.adx, cap: cap.cap, } } @@ -63,12 +61,10 @@ export const blueskySemantics: CapabilitySemantics = { }, tryDelegating( - parentCap: BlueskyCapability, - childCap: BlueskyCapability, - ): BlueskyCapability | null | CapabilityEscalation { - if ( - BlueskyAbilityLevels[childCap.cap] > BlueskyAbilityLevels[parentCap.cap] - ) { + parentCap: AdxCapability, + childCap: AdxCapability, + ): AdxCapability | null | CapabilityEscalation { + if (AdxAbilityLevels[childCap.cap] > AdxAbilityLevels[parentCap.cap]) { return { escalation: 'Capability level escalation', capability: childCap, @@ -76,9 +72,9 @@ export const blueskySemantics: CapabilitySemantics = { } const [childDid, childNamespace, childCollection, childTid] = - childCap.bluesky.split('|') + childCap.adx.split('|') const [parentDid, parentNamespace, parentCollection, parentTid] = - parentCap.bluesky.split('|') + parentCap.adx.split('|') if (childDid !== parentDid) { return null @@ -113,30 +109,30 @@ export const blueskySemantics: CapabilitySemantics = { } export const hasPermission = ( - parent: BlueskyCapability, - child: BlueskyCapability, + parent: AdxCapability, + child: AdxCapability, ): boolean => { - const attempt = blueskySemantics.tryDelegating(parent, child) + const attempt = adxSemantics.tryDelegating(parent, child) return attempt !== null && !isCapabilityEscalation(attempt) } -export const namespaceEscalation = (cap: BlueskyCapability) => { +export const namespaceEscalation = (cap: AdxCapability) => { return { - escalation: 'Bluesky namespace esclation', + escalation: 'ADX namespace esclation', capability: cap, } } -export const collectionEscalation = (cap: BlueskyCapability) => { +export const collectionEscalation = (cap: AdxCapability) => { return { - escalation: 'Bluesky collection esclation', + escalation: 'ADX collection esclation', capability: cap, } } -export const tidEscalation = (cap: BlueskyCapability) => { +export const tidEscalation = (cap: AdxCapability) => { return { - escalation: 'Bluesky TID esclation', + escalation: 'ADX TID esclation', capability: cap, } } @@ -146,7 +142,7 @@ export function writeCap( namespace?: string, collection?: Collection, tid?: TID, -): BlueskyCapability { +): AdxCapability { let resource = did if (namespace) { resource += '|' + namespace @@ -160,18 +156,18 @@ export function writeCap( resource += '|*' } return { - bluesky: resource, + adx: resource, cap: 'WRITE', } } -export function maintenanceCap(did: string): BlueskyCapability { +export function maintenanceCap(did: string): AdxCapability { return { - bluesky: `${did}|*`, + adx: `${did}|*`, cap: 'MAINTENANCE', } } -export function blueskyCapabilities(ucan: Chained) { - return capabilities(ucan, blueskySemantics) +export function adxCapabilities(ucan: Chained) { + return capabilities(ucan, adxSemantics) } diff --git a/common/src/auth/builders.ts b/common/src/auth/builders.ts index b39f27450d6..cba8c0386c7 100644 --- a/common/src/auth/builders.ts +++ b/common/src/auth/builders.ts @@ -1,11 +1,7 @@ import * as ucan from 'ucans' import TID from '../repo/tid.js' import { Collection } from '../repo/types.js' -import { - blueskySemantics, - maintenanceCap, - writeCap, -} from './bluesky-capability.js' +import { adxSemantics, maintenanceCap, writeCap } from './adx-capability.js' const MONTH_IN_SECONDS = 60 * 60 * 24 * 30 @@ -23,7 +19,7 @@ export const delegateForPost = async ( .toAudience(serverDid) .withLifetimeInSeconds(30) .delegateCapability( - blueskySemantics, + adxSemantics, writeCap(did, namespace, collection, tid), ucanStore, ) @@ -40,11 +36,7 @@ export const delegateForRelationship = async ( .issuedBy(keypair) .toAudience(serverDid) .withLifetimeInSeconds(30) - .delegateCapability( - blueskySemantics, - writeCap(did, 'relationships'), - ucanStore, - ) + .delegateCapability(adxSemantics, writeCap(did, 'relationships'), ucanStore) .build() } @@ -57,11 +49,7 @@ export const delegateMaintenance = ( .issuedBy(keypair) .toAudience(audience) .withLifetimeInSeconds(30) - .delegateCapability( - blueskySemantics, - maintenanceCap(keypair.did()), - ucanStore, - ) + .delegateCapability(adxSemantics, maintenanceCap(keypair.did()), ucanStore) .build() } diff --git a/common/src/auth/index.ts b/common/src/auth/index.ts index 82a85625404..a381fffdcdc 100644 --- a/common/src/auth/index.ts +++ b/common/src/auth/index.ts @@ -1,3 +1,3 @@ export * from './builders.js' export * from './ucan-checks.js' -export * from './bluesky-capability.js' +export * from './adx-capability.js' diff --git a/common/src/auth/ucan-checks.ts b/common/src/auth/ucan-checks.ts index acde1257328..d083dd0521a 100644 --- a/common/src/auth/ucan-checks.ts +++ b/common/src/auth/ucan-checks.ts @@ -4,11 +4,11 @@ import TID from '../repo/tid.js' import { Collection } from '../repo/types.js' import { writeCap, - blueskyCapabilities, - blueskySemantics, - BlueskyCapability, + adxCapabilities, + adxSemantics, + AdxCapability, maintenanceCap, -} from './bluesky-capability.js' +} from './adx-capability.js' type Check = (ucan: Chained) => Error | null @@ -45,14 +45,14 @@ export const hasAudience = } export const hasValidCapability = - (rootDid: string, needed: BlueskyCapability) => + (rootDid: string, needed: AdxCapability) => (token: Chained): Error | null => { // the capability we need for the given action - for (const cap of blueskyCapabilities(token)) { + for (const cap of adxCapabilities(token)) { // skip over escalations if (isCapabilityEscalation(cap)) continue // check if this capability includes the one we need, if not skip - const attempt = blueskySemantics.tryDelegating(cap.capability, needed) + const attempt = adxSemantics.tryDelegating(cap.capability, needed) if (attempt === null || isCapabilityEscalation(attempt)) continue // check root did matches the repo's did if (cap.info.originator !== rootDid) { @@ -73,7 +73,7 @@ export const hasValidCapability = } // we looped through all options & couldn't find the capability we need return new Error( - `Ucan does not permission the requested capability for user: ${needed.cap} ${needed.bluesky}`, + `Ucan does not permission the requested capability for user: ${needed.cap} ${needed.adx}`, ) } diff --git a/common/src/index.ts b/common/src/index.ts index d27e83fa3e5..91ed6d9a5f4 100644 --- a/common/src/index.ts +++ b/common/src/index.ts @@ -3,6 +3,7 @@ export * from './blockstore/memory-blockstore.js' export * from './blockstore/persistent-blockstore.js' export * from './repo/index.js' export * from './repo/tid.js' +export * from './repo/types.js' export * from './microblog/index.js' export * from './microblog/types.js' export * from './microblog/delegator.js' diff --git a/common/src/microblog/const.ts b/common/src/microblog/const.ts index 6dcb29646ac..ae0a7b2ff44 100644 --- a/common/src/microblog/const.ts +++ b/common/src/microblog/const.ts @@ -1 +1 @@ -export const NAMESPACE = 'did:bsky:microblog' +export const NAMESPACE = 'did:example:microblog' diff --git a/common/src/microblog/delegator.ts b/common/src/microblog/delegator.ts index ff3683068e9..3b4a4268dee 100644 --- a/common/src/microblog/delegator.ts +++ b/common/src/microblog/delegator.ts @@ -22,7 +22,6 @@ export class MicroblogDelegator extends MicroblogReader implements MicroblogClient { - namespace = 'did:bsky:microblog' keypair: Keypair | null ucanStore: ucan.Store | null did: string diff --git a/common/src/microblog/full.ts b/common/src/microblog/full.ts index 34d7b21f505..7d82af3842a 100644 --- a/common/src/microblog/full.ts +++ b/common/src/microblog/full.ts @@ -10,7 +10,6 @@ import { } from './types.js' import TID from '../repo/tid.js' import MicroblogReader from './reader.js' -import { NAMESPACE } from './const.js' import Namespace from '../repo/namespace.js' import { CID } from 'multiformats' import { service } from '../index.js' @@ -22,7 +21,6 @@ type Opts = { } export class MicroblogFull extends MicroblogReader implements MicroblogClient { - namespace = NAMESPACE did: string repo: Repo pushOnUpdate: boolean diff --git a/common/src/microblog/reader.ts b/common/src/microblog/reader.ts index 45063d33f17..495983afbc4 100644 --- a/common/src/microblog/reader.ts +++ b/common/src/microblog/reader.ts @@ -16,9 +16,10 @@ import * as check from '../common/check.js' import { parseAxiosError } from '../network/util.js' import { Follow } from '../repo/types.js' import * as service from '../network/service.js' +import { NAMESPACE } from './const.js' export class MicroblogReader implements MicroblogReaderI { - namespace = 'did:bsky:microblog' + namespace = NAMESPACE url: string did?: string diff --git a/common/src/repo/delta.ts b/common/src/repo/delta.ts index 17bd954d908..13d23581c74 100644 --- a/common/src/repo/delta.ts +++ b/common/src/repo/delta.ts @@ -1,5 +1,5 @@ import { CID } from 'multiformats' -import { BlueskyCapability } from '../auth/bluesky-capability.js' +import { AdxCapability } from '../auth/adx-capability.js' import { Collection, TIDEntry, DIDEntry, IdMapping } from '../repo/types.js' import CidSet from './cid-set.js' import TID from './tid.js' @@ -11,7 +11,7 @@ import * as auth from '../auth/index.js' export const capabilityForEvent = ( did: string, event: Event, -): BlueskyCapability => { +): AdxCapability => { if (isRelationshipEvent(event)) { return auth.writeCap(did, 'relationships') } diff --git a/common/src/repo/index.ts b/common/src/repo/index.ts index 73430d2d857..8c2d3da34c6 100644 --- a/common/src/repo/index.ts +++ b/common/src/repo/index.ts @@ -20,10 +20,10 @@ import Namespace from './namespace.js' import Relationships from './relationships.js' import CidSet from './cid-set.js' import { - blueskySemantics, + adxSemantics, maintenanceCap, writeCap, -} from '../auth/bluesky-capability.js' +} from '../auth/adx-capability.js' import * as auth from '../auth/index.js' import * as service from '../network/service.js' import * as delta from './delta.js' @@ -67,7 +67,7 @@ export class Repo implements CarStreamable { ) { const foundUcan = await ucanStore.findWithCapability( keypair.did(), - blueskySemantics, + adxSemantics, maintenanceCap(did), () => true, ) @@ -287,13 +287,13 @@ export class Repo implements CarStreamable { ) const foundUcan = this.ucanStore.findWithCapability( this.keypair.did(), - blueskySemantics, + adxSemantics, neededCap, () => true, ) if (!foundUcan.success) { throw new Error( - `Could not find a valid ucan for operation: ${neededCap.bluesky}`, + `Could not find a valid ucan for operation: ${neededCap.adx}`, ) } return this.blockstore.put(foundUcan.ucan.encoded()) diff --git a/common/test/auth.ts b/common/test/auth.ts index 62c6b7e629d..ca3982cc44c 100644 --- a/common/test/auth.ts +++ b/common/test/auth.ts @@ -22,9 +22,9 @@ test.beforeEach(async (t) => { const keypair = await ucan.EdKeypair.create() const fullToken = await auth.claimFull(keypair.did(), keypair) const ucanStore = await ucan.Store.fromTokens([fullToken.encoded()]) - const serverDid = 'did:bsky:FAKE_SERVER_DID' + const serverDid = 'did:example:fakeServerDid' const did = keypair.did() - const namespace = 'did:bsky:microblog' + const namespace = 'did:example:microblog' const collection = 'posts' const tid = TID.next() const postToken = await auth.delegateForPost( @@ -68,7 +68,7 @@ test('token does not work for other namespaces', async (t) => { hasAudience(ctx.serverDid), hasPostingPermission( ctx.did, - 'did:bsky:otherNamespace', + 'did:example:otherNamespace', ctx.collection, ctx.tid, ), diff --git a/common/test/delta.ts b/common/test/delta.ts index d18579ad1df..6db379d20aa 100644 --- a/common/test/delta.ts +++ b/common/test/delta.ts @@ -32,7 +32,7 @@ test.beforeEach(async (t) => { const ipldBob = IpldStore.createInMemory() - const namespaceId = 'did:bsky:test' + const namespaceId = 'did:example:test' t.context = { ipldAlice, alice, diff --git a/common/test/repo.ts b/common/test/repo.ts index cb5720c25cf..04e4a49bc59 100644 --- a/common/test/repo.ts +++ b/common/test/repo.ts @@ -23,8 +23,8 @@ test.beforeEach(async (t) => { const token = await auth.claimFull(keypair.did(), keypair) const ucanStore = await ucan.Store.fromTokens([token.encoded()]) const repo = await Repo.create(ipld, keypair.did(), keypair, ucanStore) - const namespaceId = 'did:bsky:test' - const otherNamespace = 'did:bsky:other' + const namespaceId = 'did:example:test' + const otherNamespace = 'did:example:other' t.context = { ipld, keypair, repo, namespaceId, otherNamespace } as Context t.pass('Context setup') }) diff --git a/common/test/sync.ts b/common/test/sync.ts index 16162698ad5..762fccd8a04 100644 --- a/common/test/sync.ts +++ b/common/test/sync.ts @@ -31,7 +31,7 @@ test.beforeEach(async (t) => { const ipldBob = IpldStore.createInMemory() - const namespaceId = 'did:bsky:test' + const namespaceId = 'did:example:test' t.context = { ipldAlice, keypairAlice, diff --git a/package.json b/package.json index b061edffe46..451a9642126 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "bluesky-demo", - "version": "1.0.0", + "name": "auth-data-experiment", + "version": "0.0.1", "main": "index.js", - "repository": "git@github.com:bluesky-social/bluesky-hack.git", + "repository": "git@github.com:bluesky-social/auth-data-experiment.git", "author": "Daniel Holmgren ", "license": "MIT", "private": true, @@ -13,10 +13,10 @@ ], "scripts": { "build": "wsrun -c \"build\"", - "server": "yarn workspace @bluesky/server start", + "server": "yarn workspace @adx/server start", "server:alt": "PORT=5284 yarn server", - "cli": "yarn workspace @bluesky/cli cli", - "wipe-db": "yarn workspace @bluesky/server wipe-db" + "cli": "yarn workspace @adx/cli cli", + "wipe-db": "yarn workspace @adx/server wipe-db" }, "devDependencies": { "rimraf": "^3.0.2", diff --git a/server/package.json b/server/package.json index 22b07138f1c..321ca682fba 100644 --- a/server/package.json +++ b/server/package.json @@ -1,5 +1,5 @@ { - "name": "@bluesky/server", + "name": "@adx/server", "version": "1.0.0", "main": "index.js", "license": "MIT", @@ -25,7 +25,7 @@ "zod": "^3.14.2" }, "devDependencies": { - "@bluesky/common": "*", + "@adx/common": "*", "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "ava": "^4.1.0", diff --git a/server/src/auth.ts b/server/src/auth.ts index d84e3000e7b..0d2cb074fa5 100644 --- a/server/src/auth.ts +++ b/server/src/auth.ts @@ -1,6 +1,6 @@ import { Request } from 'express' import * as ucan from 'ucans' -import { auth } from '@bluesky/common' +import { auth } from '@adx/common' import { ServerError } from './error.js' type Check = (ucan: ucan.Chained) => Error | null diff --git a/server/src/db/index.ts b/server/src/db/index.ts index e25e93eb643..bb6177d5ef9 100644 --- a/server/src/db/index.ts +++ b/server/src/db/index.ts @@ -4,8 +4,8 @@ import { Timeline, AccountInfo, TimelinePost, -} from '@bluesky/common' -import { Follow } from '@bluesky/common/dist/repo/types' + Follow, +} from '@adx/common' import knex from 'knex' import { CID } from 'multiformats' import * as schema from './schema.js' diff --git a/server/src/error.ts b/server/src/error.ts index 252473b9327..f9ea05260f3 100644 --- a/server/src/error.ts +++ b/server/src/error.ts @@ -1,5 +1,5 @@ import { NextFunction, Request, Response } from 'express' -import { check } from '@bluesky/common' +import { check } from '@adx/common' export const handler = ( err: Error, diff --git a/server/src/index.ts b/server/src/index.ts index baf0369526f..6bd4514c5dc 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,5 +1,5 @@ import dotenv from 'dotenv' -import { IpldStore } from '@bluesky/common' +import { IpldStore } from '@adx/common' import Database from './db/index.js' import server from './server.js' diff --git a/server/src/routes/data/interaction.ts b/server/src/routes/data/interaction.ts index 311840618f5..75905698805 100644 --- a/server/src/routes/data/interaction.ts +++ b/server/src/routes/data/interaction.ts @@ -4,7 +4,7 @@ import * as auth from '../../auth.js' import * as util from '../../util.js' import * as subscriptions from '../../subscriptions.js' import { ServerError } from '../../error.js' -import { schema, check, ucanCheck, flattenLike } from '@bluesky/common' +import { schema, check, ucanCheck, flattenLike } from '@adx/common' import { SERVER_DID } from '../../server-identity.js' const router = express.Router() diff --git a/server/src/routes/data/post.ts b/server/src/routes/data/post.ts index 624bc9b787e..29e515c353c 100644 --- a/server/src/routes/data/post.ts +++ b/server/src/routes/data/post.ts @@ -3,7 +3,7 @@ import { z } from 'zod' import * as auth from '../../auth.js' import * as util from '../../util.js' import { ServerError } from '../../error.js' -import { flattenPost, schema, TID, ucanCheck } from '@bluesky/common' +import { flattenPost, schema, TID, ucanCheck } from '@adx/common' import { SERVER_DID } from '../../server-identity.js' import * as subscriptions from '../../subscriptions.js' diff --git a/server/src/routes/data/relationship.ts b/server/src/routes/data/relationship.ts index 25853b4df52..28af92b56fc 100644 --- a/server/src/routes/data/relationship.ts +++ b/server/src/routes/data/relationship.ts @@ -1,7 +1,7 @@ import express from 'express' import { z } from 'zod' -import { service, ucanCheck } from '@bluesky/common' +import { service, ucanCheck } from '@adx/common' import * as auth from '../../auth.js' import * as util from '../../util.js' import * as subscriptions from '../../subscriptions.js' diff --git a/server/src/routes/data/repo.ts b/server/src/routes/data/repo.ts index dd2668308ed..5b2da2163b3 100644 --- a/server/src/routes/data/repo.ts +++ b/server/src/routes/data/repo.ts @@ -1,7 +1,7 @@ import express from 'express' import { z } from 'zod' import * as util from '../../util.js' -import { delta, Repo, schema, service } from '@bluesky/common' +import { delta, Repo, schema, service } from '@adx/common' import Database from '../../db/index.js' import { ServerError } from '../../error.js' import * as subscriptions from '../../subscriptions.js' diff --git a/server/src/routes/id.ts b/server/src/routes/id.ts index e686c6728d2..a091509913c 100644 --- a/server/src/routes/id.ts +++ b/server/src/routes/id.ts @@ -1,7 +1,7 @@ import express from 'express' import { z } from 'zod' -import { Repo, ucanCheck } from '@bluesky/common' +import { Repo, ucanCheck } from '@adx/common' import * as auth from '../auth.js' import { SERVER_DID, SERVER_KEYPAIR } from '../server-identity.js' diff --git a/server/src/routes/indexer/count.ts b/server/src/routes/indexer/count.ts index ed7428e8cda..447fc5c5674 100644 --- a/server/src/routes/indexer/count.ts +++ b/server/src/routes/indexer/count.ts @@ -1,6 +1,6 @@ import express from 'express' import { z } from 'zod' -import { schema } from '@bluesky/common' +import { schema } from '@adx/common' import * as util from '../../util.js' const router = express.Router() diff --git a/server/src/routes/indexer/feed.ts b/server/src/routes/indexer/feed.ts index 0dfb7e546bb..87540660909 100644 --- a/server/src/routes/indexer/feed.ts +++ b/server/src/routes/indexer/feed.ts @@ -1,6 +1,6 @@ import express from 'express' import { z } from 'zod' -import { schema } from '@bluesky/common' +import { schema } from '@adx/common' import * as util from '../../util.js' const router = express.Router() diff --git a/server/src/routes/indexer/post-info.ts b/server/src/routes/indexer/post-info.ts index 943ba5b12df..fff9bc5e8d9 100644 --- a/server/src/routes/indexer/post-info.ts +++ b/server/src/routes/indexer/post-info.ts @@ -1,6 +1,6 @@ import express from 'express' import { z } from 'zod' -import { schema } from '@bluesky/common' +import { schema } from '@adx/common' import * as util from '../../util.js' import { ServerError } from '../../error.js' diff --git a/server/src/routes/indexer/timeline.ts b/server/src/routes/indexer/timeline.ts index d60fc996ef4..2bd26238c35 100644 --- a/server/src/routes/indexer/timeline.ts +++ b/server/src/routes/indexer/timeline.ts @@ -1,6 +1,6 @@ import express from 'express' import { z } from 'zod' -import { schema } from '@bluesky/common' +import { schema } from '@adx/common' import * as util from '../../util.js' const router = express.Router() diff --git a/server/src/server.ts b/server/src/server.ts index 69b7f9267db..8f35e4244f2 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -7,7 +7,7 @@ import 'express-async-errors' import express from 'express' import cors from 'cors' import Routes from './routes/index.js' -import { IpldStore } from '@bluesky/common' +import { IpldStore } from '@adx/common' import Database from './db/index.js' import * as error from './error.js' @@ -27,7 +27,7 @@ const runServer = (blockstore: IpldStore, db: Database, port: number) => { app.use(error.handler) app.listen(port, () => { - console.log(`๐ŸŒž Bluesky server is running at http://localhost:${port}`) + console.log(`๐ŸŒž ADX Data server is running at http://localhost:${port}`) }) } diff --git a/server/src/subscriptions.ts b/server/src/subscriptions.ts index bd78260ac0e..a2ed5a0b739 100644 --- a/server/src/subscriptions.ts +++ b/server/src/subscriptions.ts @@ -1,4 +1,4 @@ -import { Repo, service } from '@bluesky/common' +import { Repo, service } from '@adx/common' import Database from './db' export const attemptNotify = async ( diff --git a/server/src/util.ts b/server/src/util.ts index 6022d4ed863..f8adfbd96b0 100644 --- a/server/src/util.ts +++ b/server/src/util.ts @@ -1,10 +1,9 @@ -import { IpldStore, Repo } from '@bluesky/common' import { Request, Response } from 'express' import { Database } from './db/index.js' import { SERVER_KEYPAIR } from './server-identity.js' import { ServerError } from './error.js' import * as ucan from 'ucans' -import { check } from '@bluesky/common' +import { IpldStore, Repo, check } from '@adx/common' export const readReqBytes = async (req: Request): Promise => { return new Promise((resolve) => { diff --git a/server/test/_util.ts b/server/test/_util.ts index 6de60a27753..5548b6d05e1 100644 --- a/server/test/_util.ts +++ b/server/test/_util.ts @@ -1,5 +1,5 @@ import * as ucan from 'ucans' -import { IpldStore, MicroblogDelegator, auth } from '@bluesky/common' +import { IpldStore, MicroblogDelegator, auth } from '@adx/common' import server from '../src/server.js' import Database from '../src/db/index.js' diff --git a/server/test/delegator-client.ts b/server/test/delegator-client.ts index ae8ccba0c59..91cf3b87f16 100644 --- a/server/test/delegator-client.ts +++ b/server/test/delegator-client.ts @@ -1,6 +1,6 @@ import test from 'ava' -import { MicroblogDelegator, Post, Like } from '@bluesky/common' +import { MicroblogDelegator, Post, Like } from '@adx/common' import { newClient, runTestServer } from './_util.js' diff --git a/server/test/indexer.ts b/server/test/indexer.ts index f99fccd0b50..fdec16b933b 100644 --- a/server/test/indexer.ts +++ b/server/test/indexer.ts @@ -1,6 +1,6 @@ import test from 'ava' -import { MicroblogDelegator, Post, TimelinePost } from '@bluesky/common' +import { MicroblogDelegator, Post, TimelinePost } from '@adx/common' import { newClient, runTestServer } from './_util.js' const USE_TEST_SERVER = true