UNPKG

@adonis-agora/media

Version:

Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a

58 lines • 3.15 kB
/** * Static credentials a SigV4 signature is computed from. Mirrors the resolved shape of an AWS * credential provider (`accessKeyId`/`secretAccessKey` + the optional STS `sessionToken`). */ export interface SigV4Credentials { accessKeyId: string; secretAccessKey: string; sessionToken?: string | undefined; } /** * Input for {@link presignS3Url}. `host` + `path` are given separately (never a pre-built URL) * because the signature covers both and they must be byte-identical between what is signed and what * the client requests: the presigner encodes the raw `path` exactly once and uses that single * encoding for the canonical request AND the returned URL, so the two cannot drift. */ export interface PresignS3UrlInput { /** HTTP method the URL authorizes (`GET`, `PUT`, …). */ method: string; /** URL scheme of the endpoint. */ protocol: 'http:' | 'https:'; /** Host the client will connect to, including a non-default port (`minio.example.com:9000`). */ host: string; /** Absolute, UNENCODED object path (`/bucket/my key.png`). Encoded here, exactly once. */ path: string; /** Extra query parameters to sign into the URL (`uploadId`, `partNumber`, `response-content-type`, …). */ query?: Record<string, string> | undefined; credentials: SigV4Credentials; /** Signing region — must match what the endpoint expects (`us-east-1` for MinIO defaults). */ region: string; /** Signing service. Default `s3`. */ service?: string | undefined; /** Lifetime of the URL, in whole seconds (SigV4 caps this at 7 days / 604800). */ expiresInSeconds: number; /** Signing time. Injectable so tests can pin the signature; defaults to `new Date()`. */ now?: Date | undefined; } /** * Presign an S3 request with AWS Signature Version 4 **query-string authentication** — the * credential, timestamp, TTL and signature all travel as `X-Amz-*` query parameters, so the URL is * self-contained and anyone holding it (a browser `PUT`ting a multipart part, a `<video>` tag * streaming a segment) can perform exactly this one request until it expires. * * Hand-rolled on `node:crypto` — ~60 lines of HMAC chaining — instead of pulling in * `@aws-sdk/s3-request-presigner`: presigning is pure computation (no round-trip to S3), and owning * it lets the signature target ANY host. That is what makes a split internal/public endpoint * trivial: SigV4 signs the `Host` header, so a URL signed for the internal endpoint is invalid on * the public one — with the SDK that means constructing a second client per endpoint, here it is * just a different `host` argument. * * The payload is declared `UNSIGNED-PAYLOAD`, the standard for presigned S3 URLs: the body cannot * be known at signing time (the client hasn't produced it yet), and S3 accepts the literal in the * canonical request for query-auth. * * Verified against AWS's published SigV4 test vector (the documented `examplebucket` presigned GET) * in `test/sigv4.spec.ts`. */ export declare function presignS3Url(input: PresignS3UrlInput): string; //# sourceMappingURL=sigv4.d.ts.map