Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Mar 5, 2024
2 parents 3a9661f + 514b437 commit d697105
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/bsky/src/auth-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class AuthVerifier {
}
const [did, serviceId] = iss.split('#')
const keyId =
serviceId === 'atproto-labeler' ? 'atproto-label' : 'atproto'
serviceId === 'atproto_labeler' ? 'atproto_label' : 'atproto'
let identity: GetIdentityByDidResponse
try {
identity = await this.dataplane.getIdentityByDid({ did })
Expand Down
11 changes: 2 additions & 9 deletions packages/dev-env/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import * as uint8arrays from 'uint8arrays'
import getPort from 'get-port'
import { wait } from '@atproto/common-web'
import { createServiceJwt } from '@atproto/xrpc-server'
import { Client as PlcClient } from '@did-plc/lib'
import { TestServerParams } from './types'
import { TestPlc } from './plc'
import { TestPds } from './pds'
import { TestBsky } from './bsky'
import { TestOzone } from './ozone'
import { TestOzone, createOzoneDid } from './ozone'
import { mockNetworkUtilities } from './util'
import { TestNetworkNoAppView } from './network-no-appview'
import { Secp256k1Keypair } from '@atproto/crypto'
Expand Down Expand Up @@ -43,13 +42,7 @@ export class TestNetwork extends TestNetworkNoAppView {
const ozonePort = params.ozone?.port ?? (await getPort())

const ozoneKey = await Secp256k1Keypair.create({ exportable: true })
const ozoneDid = await new PlcClient(plc.url).createDid({
signingKey: ozoneKey.did(),
rotationKeys: [ozoneKey.did()],
handle: 'ozone.test',
pds: `http://pds.invalid`,
signer: ozoneKey,
})
const ozoneDid = await createOzoneDid(plc.url, ozoneKey)

const bsky = await TestBsky.create({
port: bskyPort,
Expand Down
44 changes: 33 additions & 11 deletions packages/dev-env/src/ozone.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import getPort from 'get-port'
import * as ui8 from 'uint8arrays'
import * as plc from '@did-plc/lib'
import * as ozone from '@atproto/ozone'
import { AtpAgent } from '@atproto/api'
import { Secp256k1Keypair } from '@atproto/crypto'
import { Client as PlcClient } from '@did-plc/lib'
import { createServiceJwt } from '@atproto/xrpc-server'
import { Keypair, Secp256k1Keypair } from '@atproto/crypto'
import { DidAndKey, OzoneConfig } from './types'
import { ADMIN_PASSWORD } from './const'
import { createDidAndKey } from './util'
import { ModeratorClient } from './moderator-client'
import { createServiceJwt } from '@atproto/xrpc-server'

export class TestOzone {
constructor(
Expand All @@ -27,14 +27,7 @@ export class TestOzone {
const signingKeyHex = ui8.toString(await serviceKeypair.export(), 'hex')
let serverDid = config.serverDid
if (!serverDid) {
const plcClient = new PlcClient(config.plcUrl)
serverDid = await plcClient.createDid({
signingKey: serviceKeypair.did(),
rotationKeys: [serviceKeypair.did()],
handle: 'ozone.test',
pds: `https://pds.invalid`,
signer: serviceKeypair,
})
serverDid = await createOzoneDid(config.plcUrl, serviceKeypair)
}

const admin = await createDidAndKey({
Expand All @@ -57,6 +50,7 @@ export class TestOzone {

const port = config.port || (await getPort())
const url = `http://localhost:${port}`

const env: ozone.OzoneEnvironment = {
devMode: true,
version: '0.0.0',
Expand Down Expand Up @@ -154,3 +148,31 @@ export class TestOzone {
await this.server.destroy()
}
}

export const createOzoneDid = async (
plcUrl: string,
keypair: Keypair,
): Promise<string> => {
const plcClient = new plc.Client(plcUrl)
const plcOp = await plc.signOperation(
{
type: 'plc_operation',
alsoKnownAs: [],
rotationKeys: [keypair.did()],
verificationMethods: {
atproto_label: keypair.did(),
},
services: {
atproto_labeler: {
type: 'AtprotoLabeler',
endpoint: 'https://ozone.public.url',
},
},
prev: null,
},
keypair,
)
const did = await plc.didForCreateOp(plcOp)
await plcClient.sendOperation(did, plcOp)
return did
}
4 changes: 2 additions & 2 deletions packages/ozone/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class AppContext {

const createAuthHeaders = (aud: string) =>
createServiceAuthHeaders({
iss: cfg.service.did,
iss: `${cfg.service.did}#atproto_labeler`,
aud,
keypair: signingKey,
})
Expand Down Expand Up @@ -170,7 +170,7 @@ export class AppContext {
}

async serviceAuthHeaders(aud: string) {
const iss = this.cfg.service.did
const iss = `${this.cfg.service.did}#atproto_labeler`
return createServiceAuthHeaders({
iss,
aud,
Expand Down
24 changes: 15 additions & 9 deletions packages/ozone/src/mod-service/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { REASONOTHER } from '../lexicon/types/com/atproto/moderation/defs'
import { subjectFromEventRow, subjectFromStatusRow } from './subject'
import { formatLabel } from './util'
import { httpLogger as log } from '../logger'

export type AuthHeaders = {
headers: {
Expand All @@ -43,15 +44,20 @@ export class ModerationViews {
if (dids.length === 0) return new Map()
const auth = await this.appviewAuth()
if (!auth) return new Map()
const res = await this.appviewAgent.api.com.atproto.admin.getAccountInfos(
{
dids: dedupeStrs(dids),
},
auth,
)
return res.data.infos.reduce((acc, cur) => {
return acc.set(cur.did, cur)
}, new Map<string, AccountView>())
try {
const res = await this.appviewAgent.api.com.atproto.admin.getAccountInfos(
{
dids: dedupeStrs(dids),
},
auth,
)
return res.data.infos.reduce((acc, cur) => {
return acc.set(cur.did, cur)
}, new Map<string, AccountView>())
} catch (err) {
log.error({ err, dids }, 'failed to resolve account infos from appview')
return new Map()
}
}

async repos(dids: string[]): Promise<Map<string, RepoView>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/pipethrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const doProxy = async (url: URL, reqInit: RequestInit) => {
const isSafeUrl = (url: URL) => {
if (url.protocol !== 'https:') return false
if (!url.hostname || url.hostname === 'localhost') return false
if (net.isIP(url.hostname) === 0) return false
if (net.isIP(url.hostname) !== 0) return false
return true
}

Expand Down

0 comments on commit d697105

Please sign in to comment.