@coffre/client 0.14.5 → 0.14.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,4 @@
1
1
  //#region src/credential.d.ts
2
- /**
3
- * A credential through coffre's credential proxy, for an app `coffre run`
4
- * started with placeholders (docs/design/credential-proxy.md): where its
5
- * client takes no base URL to point at the proxy, or the code is new.
6
- *
7
- * import { credential } from '@coffre/client/credential';
8
- * const schumann = credential('schumann');
9
- * const companies = await (await schumann.fetch('/companies?q=acme')).json();
10
- *
11
- * `coffre run` sets `COFFRE_CREDENTIALS`, each credential's URL on the
12
- * proxy by name, its environment's (`…/use/market/dev/schumann`), and
13
- * `COFFRE_HANDLE`, the handle that stands in for the environment's values;
14
- * the proxy injects the key, and the app never holds it.
15
- */
16
2
  export type ProxiedCredential = {
17
3
  /** The credential's URL on the proxy: `<url>/<path>` is `<upstream>/<path>`. */
18
4
  url: string;
@@ -37,7 +23,10 @@ export type ProxiedCredential = {
37
23
  * A signature of `message` (a string signs as its UTF-8) by a signer's
38
24
  * key, which stays in coffre: a private key's, what Node's
39
25
  * `crypto.sign(undefined, message, key)` gives, base64url, each one use
40
- * in coffre's log; an HMAC secret's, as its `hmac()` writes it.
26
+ * in coffre's log; an HMAC secret's, as its `hmac()` writes it. A message
27
+ * past 1 MiB goes raw, its bytes as the request's body, which coffre
28
+ * signs as they come, never held: an `hmac()` signer's whose `maxBytes`
29
+ * takes it, SumSub's document upload say.
41
30
  */
42
31
  sign(message: Uint8Array | string): Promise<string>;
43
32
  /**
@@ -1,4 +1,19 @@
1
+ import "./dpop.js";
1
2
  //#region src/credential.ts
3
+ /**
4
+ * A credential through coffre's credential proxy, for an app `coffre run`
5
+ * started with placeholders (docs/design/credential-proxy.md): where its
6
+ * client takes no base URL to point at the proxy, or the code is new.
7
+ *
8
+ * import { credential } from '@coffre/client/credential';
9
+ * const schumann = credential('schumann');
10
+ * const companies = await (await schumann.fetch('/companies?q=acme')).json();
11
+ *
12
+ * `coffre run` sets `COFFRE_CREDENTIALS`, each credential's URL on the
13
+ * proxy by name, its environment's (`…/use/market/dev/schumann`), and
14
+ * `COFFRE_HANDLE`, the handle that stands in for the environment's values;
15
+ * the proxy injects the key, and the app never holds it.
16
+ */
2
17
  /** The credential `name`, as `coffre run` gave the app it; `env` and `fetcher` for tests and odd runtimes. */
3
18
  function credential(name, env = globalThis.process?.env ?? {}, fetcher = (input, init) => fetch(input, init)) {
4
19
  let urls;
@@ -25,6 +40,24 @@ function credential(name, env = globalThis.process?.env ?? {}, fetcher = (input,
25
40
  body: await answer.json()
26
41
  };
27
42
  };
43
+ /** A message past what JSON takes, signed raw: its bytes as the body, with the SHA-256 that `coffre serve` streams it by, and coffre checks. */
44
+ const raw = async (bytes) => {
45
+ const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
46
+ const answer = await fetcher(`${url.slice(0, url.lastIndexOf("/"))}?sign=${encodeURIComponent(name)}`, {
47
+ method: "POST",
48
+ headers: {
49
+ authorization: `Bearer ${handle}`,
50
+ "content-type": "application/octet-stream",
51
+ "content-length": String(bytes.length),
52
+ "content-digest": `sha-256=:${btoa(String.fromCharCode(...digest))}:`
53
+ },
54
+ body: bytes
55
+ });
56
+ return {
57
+ answer,
58
+ body: await answer.json()
59
+ };
60
+ };
28
61
  const bytesOf = (message) => {
29
62
  const bytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
30
63
  let binary = "";
@@ -54,9 +87,10 @@ function credential(name, env = globalThis.process?.env ?? {}, fetcher = (input,
54
87
  };
55
88
  },
56
89
  sign: async (message) => {
57
- const { answer, body } = await compute({ sign: {
90
+ const bytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
91
+ const { answer, body } = bytes.length > 1048576 ? await raw(bytes) : await compute({ sign: {
58
92
  credential: name,
59
- message: bytesOf(message)
93
+ message: bytesOf(bytes)
60
94
  } });
61
95
  if (!answer.ok || body.signature === void 0) throw new Error(`coffre signed nothing: ${body.message ?? answer.status}`);
62
96
  return body.signature;
@@ -97,6 +97,8 @@ declare function bodyDigest(body: Uint8Array | string): Promise<string>;
97
97
  * not the zone's.
98
98
  */
99
99
  declare const MAX_DIGESTED_BODY: number;
100
+ /** The longest message `sign` sends as JSON, base64url: what coffre reads whole. A longer one goes raw, the body itself. */
101
+ declare const JSON_MESSAGE_BYTES: number;
100
102
  /** A body's `Content-Digest` (RFC 9530) from its SHA-256 in hex, as the SDK and `coffre serve` send it: `sha-256=:<base64>:`. */
101
103
  declare function contentDigest(sha256: string): string;
102
104
  /**
@@ -207,4 +209,4 @@ declare function createProof(key: ProofKey, request: {
207
209
  jti?: string;
208
210
  }): Promise<string>;
209
211
  //#endregion
210
- export { signedHeaders as C, sentTarget as S, tokenDigest as T, declaredDigest as _, ProofClaims as a, generateProofKey as b, UNSIGNED_BODY as c, bodyDigest as d, bodyLine as f, createProof as g, contentDigest as h, METHOD_TOKEN as i, UNSIGNED_HEADERS as l, canonicalRequest as m, MAX_PROOF_LENGTH as n, ProofKey as o, canonicalHtu as p, MAX_SIGNED_HEADERS as r, PublicJwk as s, MAX_DIGESTED_BODY as t, base64url as u, fetchMethod as v, thumbprint as w, requestDigest as x, fromBase64url as y };
212
+ export { sentTarget as C, tokenDigest as E, requestDigest as S, thumbprint as T, createProof as _, METHOD_TOKEN as a, fromBase64url as b, PublicJwk as c, base64url as d, bodyDigest as f, contentDigest as g, canonicalRequest as h, MAX_SIGNED_HEADERS as i, UNSIGNED_BODY as l, canonicalHtu as m, MAX_DIGESTED_BODY as n, ProofClaims as o, bodyLine as p, MAX_PROOF_LENGTH as r, ProofKey as s, JSON_MESSAGE_BYTES as t, UNSIGNED_HEADERS as u, declaredDigest as v, signedHeaders as w, generateProofKey as x, fetchMethod as y };
package/dist/dpop.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as signedHeaders, S as sentTarget, T as tokenDigest, _ as declaredDigest, a as ProofClaims, b as generateProofKey, c as UNSIGNED_BODY, d as bodyDigest, f as bodyLine, g as createProof, h as contentDigest, i as METHOD_TOKEN, l as UNSIGNED_HEADERS, m as canonicalRequest, n as MAX_PROOF_LENGTH, o as ProofKey, p as canonicalHtu, r as MAX_SIGNED_HEADERS, s as PublicJwk, t as MAX_DIGESTED_BODY, u as base64url, v as fetchMethod, w as thumbprint, x as requestDigest, y as fromBase64url } from "./dpop-CYJtAnvD.js";
2
- export { MAX_DIGESTED_BODY, MAX_PROOF_LENGTH, MAX_SIGNED_HEADERS, METHOD_TOKEN, ProofClaims, ProofKey, PublicJwk, UNSIGNED_BODY, UNSIGNED_HEADERS, base64url, bodyDigest, bodyLine, canonicalHtu, canonicalRequest, contentDigest, createProof, declaredDigest, fetchMethod, fromBase64url, generateProofKey, requestDigest, sentTarget, signedHeaders, thumbprint, tokenDigest };
1
+ import { C as sentTarget, E as tokenDigest, S as requestDigest, T as thumbprint, _ as createProof, a as METHOD_TOKEN, b as fromBase64url, c as PublicJwk, d as base64url, f as bodyDigest, g as contentDigest, h as canonicalRequest, i as MAX_SIGNED_HEADERS, l as UNSIGNED_BODY, m as canonicalHtu, n as MAX_DIGESTED_BODY, o as ProofClaims, p as bodyLine, r as MAX_PROOF_LENGTH, s as ProofKey, t as JSON_MESSAGE_BYTES, u as UNSIGNED_HEADERS, v as declaredDigest, w as signedHeaders, x as generateProofKey, y as fetchMethod } from "./dpop-C9EOdNCi.js";
2
+ export { JSON_MESSAGE_BYTES, MAX_DIGESTED_BODY, MAX_PROOF_LENGTH, MAX_SIGNED_HEADERS, METHOD_TOKEN, ProofClaims, ProofKey, PublicJwk, UNSIGNED_BODY, UNSIGNED_HEADERS, base64url, bodyDigest, bodyLine, canonicalHtu, canonicalRequest, contentDigest, createProof, declaredDigest, fetchMethod, fromBase64url, generateProofKey, requestDigest, sentTarget, signedHeaders, thumbprint, tokenDigest };
package/dist/dpop.js CHANGED
@@ -167,6 +167,8 @@ async function bodyDigest(body) {
167
167
  * not the zone's.
168
168
  */
169
169
  const MAX_DIGESTED_BODY = 99614720;
170
+ /** The longest message `sign` sends as JSON, base64url: what coffre reads whole. A longer one goes raw, the body itself. */
171
+ const JSON_MESSAGE_BYTES = 1048576;
170
172
  /** A body's `Content-Digest` (RFC 9530) from its SHA-256 in hex, as the SDK and `coffre serve` send it: `sha-256=:<base64>:`. */
171
173
  function contentDigest(sha256) {
172
174
  if (!SHA256_HEX.test(sha256)) throw new TypeError("a Content-Digest is made from a SHA-256 in hex");
@@ -324,4 +326,4 @@ async function createProof(key, request) {
324
326
  return `${input}.${base64url(new Uint8Array(signature))}`;
325
327
  }
326
328
  //#endregion
327
- export { MAX_DIGESTED_BODY, MAX_PROOF_LENGTH, MAX_SIGNED_HEADERS, METHOD_TOKEN, UNSIGNED_BODY, UNSIGNED_HEADERS, base64url, bodyDigest, bodyLine, canonicalHtu, canonicalRequest, contentDigest, createProof, declaredDigest, fetchMethod, fromBase64url, generateProofKey, requestDigest, sentTarget, signedHeaders, thumbprint, tokenDigest };
329
+ export { JSON_MESSAGE_BYTES, MAX_DIGESTED_BODY, MAX_PROOF_LENGTH, MAX_SIGNED_HEADERS, METHOD_TOKEN, UNSIGNED_BODY, UNSIGNED_HEADERS, base64url, bodyDigest, bodyLine, canonicalHtu, canonicalRequest, contentDigest, createProof, declaredDigest, fetchMethod, fromBase64url, generateProofKey, requestDigest, sentTarget, signedHeaders, thumbprint, tokenDigest };
@@ -1,4 +1,4 @@
1
- import { s as PublicJwk } from "./dpop-CYJtAnvD.js";
1
+ import { c as PublicJwk } from "./dpop-C9EOdNCi.js";
2
2
  //#region src/workload-proofs.d.ts
3
3
  /**
4
4
  * How a workload proves who it is, once per session (docs/design/workload-access.md,
@@ -201,7 +201,10 @@ interface Workload {
201
201
  interface UsedCredential {
202
202
  /** `<credential's URL>/<path>`, signed: the proxy forwards it to the upstream with the real key. */
203
203
  fetch(path: string, init?: RequestInit): Promise<Response>;
204
- /** A signature by a signer's key, which stays in coffre: a private key's base64url, an HMAC secret's as its `hmac()` writes it. */
204
+ /**
205
+ * A signature by a signer's key, which stays in coffre: a private key's base64url, an HMAC secret's as its `hmac()` writes it.
206
+ * A message past 1 MiB goes raw, its bytes as the body, signed as they come and never held: an `hmac()` signer's whose `maxBytes` takes it.
207
+ */
205
208
  sign(message: string | Uint8Array): Promise<string>;
206
209
  /** Whether `signature`, as its header carried it, is a verifier's HMAC of `message`, an inbound webhook's body as it came: checked without reading its secret. */
207
210
  verify(message: string | Uint8Array, signature: string): Promise<boolean>;
@@ -754,14 +754,15 @@ function surface(core) {
754
754
  const placeUrl = () => `${origin}/use/${placeOf().split("/").map(encodeURIComponent).join("/")}`;
755
755
  const url = (name) => core.places().length === 1 ? `${origin}/use/${encodeURIComponent(name)}` : `${placeUrl()}/${encodeURIComponent(name)}`;
756
756
  /** What coffre makes with the environment's values, at the environment's URL: a signature, a verdict, a presigned URL, a minted child. */
757
- const compute = async (asked, what) => {
758
- const response = await signed(placeUrl(), {
757
+ const compute = (asked, what) => computed(placeUrl(), { "content-type": "application/json" }, JSON.stringify(asked), what);
758
+ const computed = async (at, headers, sent, what) => {
759
+ const response = await signed(at, {
759
760
  method: "POST",
760
761
  headers: {
761
- "content-type": "application/json",
762
+ ...headers,
762
763
  accept: "application/json"
763
764
  },
764
- body: JSON.stringify(asked)
765
+ body: sent
765
766
  });
766
767
  const body = await response.json().catch(() => null);
767
768
  if (!response.ok || body === null) throw refusal(response.status, body, `coffre ${what} nothing`);
@@ -783,10 +784,11 @@ function surface(core) {
783
784
  return signed(target.href, init);
784
785
  },
785
786
  sign: async (message) => {
786
- const body = await compute({ sign: {
787
+ const bytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
788
+ const body = await (bytes.length > 1048576 ? computed(`${placeUrl()}?sign=${encodeURIComponent(name)}`, { "content-type": "application/octet-stream" }, bytes, "signed") : compute({ sign: {
787
789
  credential: name,
788
- message: bytesOf(message)
789
- } }, "signed");
790
+ message: bytesOf(bytes)
791
+ } }, "signed"));
790
792
  if (typeof body.signature !== "string") throw new Error("coffre signed nothing");
791
793
  return body.signature;
792
794
  },
@@ -1,4 +1,4 @@
1
- import { r as Workload } from "./workload-DwWrQQg1.js";
1
+ import { r as Workload } from "./workload-BSw5PIp4.js";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { Duplex } from "node:stream";
4
4
  //#region src/workload-postgres.d.ts
@@ -1,4 +1,4 @@
1
- import { i as upgradeRefused, r as upgradeHeaders } from "./workload-BuKb9O4W.js";
1
+ import { i as upgradeRefused, r as upgradeHeaders } from "./workload-BbOYoYzX.js";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { Duplex } from "node:stream";
4
4
  //#region src/workload-postgres.ts
@@ -1,3 +1,3 @@
1
1
  import { r as CoffreError } from "./index-CURF99SB.js";
2
- import { C as oidc, S as kubernetes, _ as enrollment, a as askedNonce, b as github, c as upgradeRefused, d as KUBERNETES_TOKEN, f as PlatformProof, g as azure, h as aws, i as WorkloadOptions, l as workload, m as ProofContext, n as UsedCredential, o as fromCoffre, p as Proof, r as Workload, s as upgradeHeaders, t as NarrowOptions, u as AwsCredentials, v as fly, w as vercel, x as keyAudience, y as gcp } from "./workload-DwWrQQg1.js";
2
+ import { C as oidc, S as kubernetes, _ as enrollment, a as askedNonce, b as github, c as upgradeRefused, d as KUBERNETES_TOKEN, f as PlatformProof, g as azure, h as aws, i as WorkloadOptions, l as workload, m as ProofContext, n as UsedCredential, o as fromCoffre, p as Proof, r as Workload, s as upgradeHeaders, t as NarrowOptions, u as AwsCredentials, v as fly, w as vercel, x as keyAudience, y as gcp } from "./workload-BSw5PIp4.js";
3
3
  export { type AwsCredentials, CoffreError, KUBERNETES_TOKEN, NarrowOptions, type PlatformProof, type Proof, type ProofContext, UsedCredential, Workload, WorkloadOptions, askedNonce, aws, azure, enrollment, fly, fromCoffre, gcp, github, keyAudience, kubernetes, oidc, upgradeHeaders, upgradeRefused, vercel, workload };
package/dist/workload.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as CoffreError } from "./src-BCKSeCER.js";
2
- import { a as workload, c as azure, d as gcp, f as github, g as vercel, h as oidc, i as upgradeRefused, l as enrollment, m as kubernetes, n as fromCoffre, o as KUBERNETES_TOKEN, p as keyAudience, r as upgradeHeaders, s as aws, t as askedNonce, u as fly } from "./workload-BuKb9O4W.js";
2
+ import { a as workload, c as azure, d as gcp, f as github, g as vercel, h as oidc, i as upgradeRefused, l as enrollment, m as kubernetes, n as fromCoffre, o as KUBERNETES_TOKEN, p as keyAudience, r as upgradeHeaders, s as aws, t as askedNonce, u as fly } from "./workload-BbOYoYzX.js";
3
3
  export { CoffreError, KUBERNETES_TOKEN, askedNonce, aws, azure, enrollment, fly, fromCoffre, gcp, github, keyAudience, kubernetes, oidc, upgradeHeaders, upgradeRefused, vercel, workload };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/client",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "description": "The coffre API as typed function calls.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/credential.ts CHANGED
@@ -12,6 +12,8 @@
12
12
  * `COFFRE_HANDLE`, the handle that stands in for the environment's values;
13
13
  * the proxy injects the key, and the app never holds it.
14
14
  */
15
+ import { JSON_MESSAGE_BYTES } from './dpop.ts';
16
+
15
17
  export type ProxiedCredential = {
16
18
  /** The credential's URL on the proxy: `<url>/<path>` is `<upstream>/<path>`. */
17
19
  url: string;
@@ -29,7 +31,10 @@ export type ProxiedCredential = {
29
31
  * A signature of `message` (a string signs as its UTF-8) by a signer's
30
32
  * key, which stays in coffre: a private key's, what Node's
31
33
  * `crypto.sign(undefined, message, key)` gives, base64url, each one use
32
- * in coffre's log; an HMAC secret's, as its `hmac()` writes it.
34
+ * in coffre's log; an HMAC secret's, as its `hmac()` writes it. A message
35
+ * past 1 MiB goes raw, its bytes as the request's body, which coffre
36
+ * signs as they come, never held: an `hmac()` signer's whose `maxBytes`
37
+ * takes it, SumSub's document upload say.
33
38
  */
34
39
  sign(message: Uint8Array | string): Promise<string>;
35
40
  /**
@@ -69,6 +74,16 @@ export function credential(
69
74
  });
70
75
  return { answer, body: (await answer.json()) as { url?: string; expiresAt?: string; signature?: string; valid?: boolean; message?: string } };
71
76
  };
77
+ /** A message past what JSON takes, signed raw: its bytes as the body, with the SHA-256 that `coffre serve` streams it by, and coffre checks. */
78
+ const raw = async (bytes: Uint8Array) => {
79
+ const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', bytes as Uint8Array<ArrayBuffer>));
80
+ const answer = await fetcher(`${url.slice(0, url.lastIndexOf('/'))}?sign=${encodeURIComponent(name)}`, {
81
+ method: 'POST',
82
+ headers: { authorization: `Bearer ${handle}`, 'content-type': 'application/octet-stream', 'content-length': String(bytes.length), 'content-digest': `sha-256=:${btoa(String.fromCharCode(...digest))}:` },
83
+ body: bytes as Uint8Array<ArrayBuffer>,
84
+ });
85
+ return { answer, body: (await answer.json()) as { signature?: string; message?: string } };
86
+ };
72
87
  const bytesOf = (message: Uint8Array | string) => {
73
88
  const bytes = typeof message === 'string' ? new TextEncoder().encode(message) : message;
74
89
  let binary = '';
@@ -88,7 +103,8 @@ export function credential(
88
103
  return { url: body.url, expiresAt: body.expiresAt! };
89
104
  },
90
105
  sign: async (message) => {
91
- const { answer, body } = await compute({ sign: { credential: name, message: bytesOf(message) } });
106
+ const bytes = typeof message === 'string' ? new TextEncoder().encode(message) : message;
107
+ const { answer, body } = bytes.length > JSON_MESSAGE_BYTES ? await raw(bytes) : await compute({ sign: { credential: name, message: bytesOf(bytes) } });
92
108
  if (!answer.ok || body.signature === undefined) throw new Error(`coffre signed nothing: ${body.message ?? answer.status}`);
93
109
  return body.signature;
94
110
  },
package/src/dpop.ts CHANGED
@@ -183,6 +183,9 @@ export async function bodyDigest(body: Uint8Array | string): Promise<string> {
183
183
  */
184
184
  export const MAX_DIGESTED_BODY = 95 * 1024 * 1024;
185
185
 
186
+ /** The longest message `sign` sends as JSON, base64url: what coffre reads whole. A longer one goes raw, the body itself. */
187
+ export const JSON_MESSAGE_BYTES = 1024 * 1024;
188
+
186
189
  /** A body's `Content-Digest` (RFC 9530) from its SHA-256 in hex, as the SDK and `coffre serve` send it: `sha-256=:<base64>:`. */
187
190
  export function contentDigest(sha256: string): string {
188
191
  if (!SHA256_HEX.test(sha256)) throw new TypeError('a Content-Digest is made from a SHA-256 in hex');
package/src/workload.ts CHANGED
@@ -27,7 +27,7 @@
27
27
  * once if the gate asks for a fresh one;
28
28
  * - logout on `close()`, and on SIGTERM.
29
29
  */
30
- import { base64url, bodyDigest, bodyLine, contentDigest, createProof, declaredDigest, generateProofKey, thumbprint, type ProofKey, type PublicJwk } from './dpop.ts';
30
+ import { base64url, bodyDigest, bodyLine, contentDigest, createProof, declaredDigest, generateProofKey, JSON_MESSAGE_BYTES, thumbprint, type ProofKey, type PublicJwk } from './dpop.ts';
31
31
  import { CoffreError } from './index.ts';
32
32
  import type { Proof, ProofContext } from './workload-proofs.ts';
33
33
 
@@ -94,7 +94,10 @@ export interface Workload {
94
94
  export interface UsedCredential {
95
95
  /** `<credential's URL>/<path>`, signed: the proxy forwards it to the upstream with the real key. */
96
96
  fetch(path: string, init?: RequestInit): Promise<Response>;
97
- /** A signature by a signer's key, which stays in coffre: a private key's base64url, an HMAC secret's as its `hmac()` writes it. */
97
+ /**
98
+ * A signature by a signer's key, which stays in coffre: a private key's base64url, an HMAC secret's as its `hmac()` writes it.
99
+ * A message past 1 MiB goes raw, its bytes as the body, signed as they come and never held: an `hmac()` signer's whose `maxBytes` takes it.
100
+ */
98
101
  sign(message: string | Uint8Array): Promise<string>;
99
102
  /** Whether `signature`, as its header carried it, is a verifier's HMAC of `message`, an inbound webhook's body as it came: checked without reading its secret. */
100
103
  verify(message: string | Uint8Array, signature: string): Promise<boolean>;
@@ -491,8 +494,9 @@ function surface(core: Core): Workload {
491
494
  const url = (name: string) => (core.places().length === 1 ? `${origin}/use/${encodeURIComponent(name)}` : `${placeUrl()}/${encodeURIComponent(name)}`);
492
495
 
493
496
  /** What coffre makes with the environment's values, at the environment's URL: a signature, a verdict, a presigned URL, a minted child. */
494
- const compute = async (asked: Record<string, unknown>, what: string): Promise<Record<string, unknown>> => {
495
- const response = await signed(placeUrl(), { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, body: JSON.stringify(asked) });
497
+ const compute = (asked: Record<string, unknown>, what: string) => computed(placeUrl(), { 'content-type': 'application/json' }, JSON.stringify(asked), what);
498
+ const computed = async (at: string, headers: Record<string, string>, sent: BodyInit, what: string): Promise<Record<string, unknown>> => {
499
+ const response = await signed(at, { method: 'POST', headers: { ...headers, accept: 'application/json' }, body: sent });
496
500
  const body = (await response.json().catch(() => null)) as Record<string, unknown> | null;
497
501
  if (!response.ok || body === null) throw refusal(response.status, body, `coffre ${what} nothing`);
498
502
  return body;
@@ -515,7 +519,11 @@ function surface(core: Core): Workload {
515
519
  return signed(target.href, init);
516
520
  },
517
521
  sign: async (message) => {
518
- const body = await compute({ sign: { credential: name, message: bytesOf(message) } }, 'signed');
522
+ const bytes = typeof message === 'string' ? new TextEncoder().encode(message) : message;
523
+ // Past what JSON takes, raw: its bytes as the body, which the proof binds by the Content-Digest `signed` declares.
524
+ const body = await (bytes.length > JSON_MESSAGE_BYTES
525
+ ? computed(`${placeUrl()}?sign=${encodeURIComponent(name)}`, { 'content-type': 'application/octet-stream' }, bytes as Uint8Array<ArrayBuffer>, 'signed')
526
+ : compute({ sign: { credential: name, message: bytesOf(bytes) } }, 'signed'));
519
527
  if (typeof body.signature !== 'string') throw new Error('coffre signed nothing');
520
528
  return body.signature;
521
529
  },