Skip to content

Commit de7b83a

Browse files
committed
add prism-resolver
1 parent 6f5fda3 commit de7b83a

6 files changed

Lines changed: 67 additions & 7 deletions

File tree

packages/bsky/src/auth-verifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class AuthVerifier {
124124
if (header?.typ === 'at+jwt') {
125125
// we should never use entryway session tokens in the case of flexible auth audiences (namely in the case of getFeed)
126126
if (opts.skipAudCheck) {
127-
console.log('HERE <<------- is the problem1234')
127+
throw new AuthRequiredError('Malformed token', 'InvalidToken')
128128
}
129129
return this.entrywaySession(ctx)
130130
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DidCache } from '../types'
2+
import { BaseResolver } from './base-resolver'
3+
import { timed } from './util'
4+
5+
export class DidPrismResolver extends BaseResolver {
6+
constructor(
7+
public prismUrl: string,
8+
public timeout: number,
9+
public cache?: DidCache,
10+
) {
11+
super(cache)
12+
}
13+
14+
async resolveNoCheck(did: string): Promise<unknown> {
15+
// Extract account ID from did:prism:abc123 -> abc123
16+
console.log('use prism did resolver 🫂')
17+
const accountId = did.split(':')[2]
18+
return timed(this.timeout, async (signal) => {
19+
const res = await fetch(`${this.prismUrl}/get-did-document`, {
20+
method: 'POST',
21+
headers: {
22+
'Content-Type': 'application/json',
23+
Accept: 'application/json',
24+
},
25+
body: JSON.stringify({ id: accountId }),
26+
signal,
27+
})
28+
29+
if (!res.ok) {
30+
throw Object.assign(new Error(res.statusText), { status: res.status })
31+
}
32+
33+
const response = await res.json()
34+
console.log(response)
35+
return response.did_document
36+
})
37+
}
38+
}

packages/pds/src/api/com/atproto/server/createAccount.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export default function (server: Server, ctx: AppContext) {
106106
// @NOTE Until this code and the OAuthStore's `createAccount` are
107107
// refactored together, any change made here must be reflected over there.
108108

109+
console.log(ctx.entrywayAgent, 'entrywayAgent in createAccount')
110+
109111
const requester = auth.credentials?.did ?? null
110112
const {
111113
did,
@@ -120,6 +122,8 @@ export default function (server: Server, ctx: AppContext) {
120122
? await validateInputsForEntrywayPds(ctx, input.body)
121123
: await validateInputsForLocalPds(ctx, input.body, requester)
122124

125+
console.log('request in createAccount', requester)
126+
123127
let didDoc: DidDocument | undefined
124128
let creds: { accessJwt: string; refreshJwt: string }
125129
await ctx.actorStore.create(did, signingKey)
@@ -131,8 +135,6 @@ export default function (server: Server, ctx: AppContext) {
131135
// Generate a real did with Prism
132136
if (plcOp) {
133137
try {
134-
await ctx.plcClient.sendOperation(did, plcOp)
135-
console.log('herer3')
136138
// Extract rotation keys matching the ones used in formatDidAndPlcOp
137139
const rotationKeys = plcOp.rotationKeys || [
138140
ctx.plcRotationKey.did(),
@@ -159,12 +161,9 @@ export default function (server: Server, ctx: AppContext) {
159161
console.log('lets wait for 15 seconds')
160162
await new Promise((resolve) => setTimeout(resolve, 15000))
161163
console.log('waited 15 seconds')
162-
console.log(did)
163164

164165
didDoc = await safeResolveDidDoc(ctx, did, true)
165166

166-
console.log(didDoc)
167-
168167
creds = await ctx.accountManager.createAccountAndSession({
169168
did,
170169
handle,
@@ -176,6 +175,8 @@ export default function (server: Server, ctx: AppContext) {
176175
deactivated,
177176
})
178177

178+
console.log('creds', creds)
179+
179180
if (!deactivated) {
180181
await ctx.sequencer.sequenceIdentityEvt(did, handle)
181182
await ctx.sequencer.sequenceAccountEvt(did, AccountStatus.Active)

packages/pds/src/api/com/atproto/server/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const safeResolveDidDoc = async (
3535
): Promise<DidDocument | undefined> => {
3636
try {
3737
const didDoc = await ctx.idResolver.did.resolve(did, forceRefresh)
38+
console.log('resolved did doc for', did, didDoc)
3839
return didDoc ?? undefined
3940
} catch (err) {
4041
httpLogger.warn({ err, did }, 'failed to resolve did doc')

packages/pds/src/context.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ export class AppContext {
348348
})
349349
: undefined
350350

351-
console.log(oauthProvider, 'OAUTH PROVIDER HERE')
351+
console.log(oauthProvider?.keyset.privateJwks, 'OAUTH PROVIDER HERE')
352+
console.log(oauthProvider?.keyset.publicJwks, 'OAUTH PROVIDER HERE')
353+
console.log(oauthProvider?.keyset.toJSON(), 'OAUTH PROVIDER HERE')
352354

353355
const oauthVerifier: OAuthVerifier =
354356
oauthProvider ?? // OAuthProvider extends OAuthVerifier
@@ -359,6 +361,10 @@ export class AppContext {
359361
redis: redisScratch,
360362
})
361363

364+
console.log(oauthVerifier.keyset.privateJwks, 'OAUTH VERIFIER HERE')
365+
console.log(oauthVerifier.keyset.publicJwks, 'OAUTH VERIFIER HERE')
366+
console.log(oauthVerifier.keyset.toJSON(), 'OAUTH VERIFIER HERE')
367+
362368
const authVerifier = new AuthVerifier(
363369
accountManager,
364370
idResolver,

packages/pds/src/prism-plc.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as plc from '@did-plc/lib'
2+
3+
export async function createOp(input: any) {
4+
const result = await plc.createOp(input)
5+
6+
const prismDid = result.did.replace('did:plc:', 'did:prism:')
7+
8+
return {
9+
...result,
10+
did: prismDid,
11+
}
12+
}
13+
14+
export * from '@did-plc/lib'

0 commit comments

Comments
 (0)