Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920import type {} from '@atcute/atproto';import type { Did } from '@atcute/lexicons';import { serviceDid } from '../identity.ts';import type { Session } from '../session.ts';import { assertSecureKnot, TangledError } from './errors.ts';
/** `did:web:<host>`, which is what a knot's `org.tangled.knot.describeKnot` reports as its DID. */export const knotServiceDid = (knot: string): Did<'web'> => serviceDid(knot);
/** Mints a 60-second service-auth token that authorizes a git push to `knot`. */export async function pushToken(session: Session, knot: string, options: { now?: () => number } = {}): Promise<string> { assertSecureKnot(/^https?:\/\//.test(knot) ? knot : `https://${knot}`); const now = options.now ?? Date.now; const res = await session.client.get('com.atproto.server.getServiceAuth', { params: { aud: knotServiceDid(knot), lxm: 'org.tangled.git.receivePack', exp: Math.floor(now() / 1000) + 60 }, }); if (!res.ok) throw new TangledError('token-failed', `getServiceAuth: ${res.data.error}${res.data.message ? ` (${res.data.message})` : ''}`); return res.data.token;}