@owlmeans/auth-common 0.1.20-rc.1 → 0.1.22-rc.0

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.
Files changed (31) hide show
  1. package/README.md +7 -2
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/auth-common/SKILL.md +10 -3
  4. package/build/guards/basic-ed25519/payload.d.ts +12 -0
  5. package/build/guards/basic-ed25519/payload.d.ts.map +1 -0
  6. package/build/guards/basic-ed25519/payload.js +22 -0
  7. package/build/guards/basic-ed25519/payload.js.map +1 -0
  8. package/build/guards/basic-ed25519/service.d.ts.map +1 -1
  9. package/build/guards/basic-ed25519/service.js +3 -5
  10. package/build/guards/basic-ed25519/service.js.map +1 -1
  11. package/build/guards/basic-ed25519/sign.d.ts +2 -1
  12. package/build/guards/basic-ed25519/sign.d.ts.map +1 -1
  13. package/build/guards/basic-ed25519/sign.js +5 -3
  14. package/build/guards/basic-ed25519/sign.js.map +1 -1
  15. package/build/guards/basic-ed25519/types.d.ts +5 -1
  16. package/build/guards/basic-ed25519/types.d.ts.map +1 -1
  17. package/build/guards/basic-ed25519/types.local.d.ts +8 -0
  18. package/build/guards/basic-ed25519/types.local.d.ts.map +1 -0
  19. package/build/guards/basic-ed25519/types.local.js +2 -0
  20. package/build/guards/basic-ed25519/types.local.js.map +1 -0
  21. package/build/modules.d.ts +3 -0
  22. package/build/modules.d.ts.map +1 -0
  23. package/build/modules.js +38 -0
  24. package/build/modules.js.map +1 -0
  25. package/package.json +12 -12
  26. package/src/guards/basic-ed25519/payload.ts +27 -0
  27. package/src/guards/basic-ed25519/service.ts +3 -6
  28. package/src/guards/basic-ed25519/sign.ts +5 -3
  29. package/src/guards/basic-ed25519/types.local.ts +7 -0
  30. package/src/guards/basic-ed25519/types.ts +5 -1
  31. package/tests/basic-ed25519.spec.ts +22 -0
package/README.md CHANGED
@@ -12,7 +12,7 @@ Predefined authentication protocols, guards, and constants shared between server
12
12
  ## Installation
13
13
 
14
14
  ```bash
15
- bun add @owlmeans/auth-common@^0.1.20-rc.1
15
+ bun add @owlmeans/auth-common@^0.1.22-rc.0
16
16
  ```
17
17
 
18
18
  ## Usage
@@ -84,6 +84,11 @@ BED255_CASHE_RESOURCE // resource alias for nonce cache
84
84
  signer's trusted-record `id`, `key` a `KeyPairModel` with the private key. It answers
85
85
  `{ authorization, headers }` — send both, with the body unchanged.
86
86
 
87
+ A body of raw bytes (a `Blob`, an `ArrayBuffer`, a typed array, a Node stream — what a streamed-body
88
+ route carries) is signed as `{}` by both the signer and the guard: the signature proves the caller and
89
+ the moment, never the bytes. A route that must prove its bytes declares their digest (in the query)
90
+ and checks it against what it stores.
91
+
87
92
  ```typescript
88
93
  import { signBasicEd25519Request } from '@owlmeans/auth-common'
89
94
  import { makeKeyPairModel } from '@owlmeans/basic-keys'
@@ -117,7 +122,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
117
122
  your project's skill store (`.agents/skills/`):
118
123
 
119
124
  ```sh
120
- npx @owlmeans/agent-skills@^0.1.20-rc.1
125
+ npx @owlmeans/agent-skills@^0.1.22-rc.0
121
126
  ```
122
127
 
123
128
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 3,
3
3
  "package": "@owlmeans/auth-common",
4
- "version": "0.1.20-rc.1",
5
- "generatedAt": "2026-11-04T18:40:59.858Z",
4
+ "version": "0.1.22-rc.0",
5
+ "generatedAt": "2026-11-11T20:57:15.686Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/auth-common
9
9
 
10
10
  **Layer:** Core
11
- **Install:** `"@owlmeans/auth-common": "^0.1.20-rc.1"` in `dependencies`
11
+ **Install:** `"@owlmeans/auth-common": "^0.1.22-rc.0"` in `dependencies`
12
12
 
13
13
  Everything a server and a browser must agree on to talk authentication: aliases, the shared
14
14
  protocol declarations, the signature guard, and the contract for resolving the organization
@@ -37,8 +37,8 @@ entity a token names.
37
37
  |--------|-------------|
38
38
  | `authProtocols` | The shared auth protocol tree — `AUTHEN*`, `CAUTHEN*`, `DISPATCHER`, `DISPATCHER_SURROGATE`, `DISPATCHER_AUTHEN`. Server and client packages bind the entries they serve |
39
39
  | `managerProtocols` | The auth-manager web API protocol tree (profile → entity slug, auth delegation) |
40
- | `makeBasicEd25519Guard(resource, opts?)` | The `GUARD_ED25519` guard service: signs outgoing requests as a client, verifies time/nonce/signature as a server |
41
- | `signBasicEd25519Request({ body?, credential, key })` | The guard's signing half as a pure helper: `{ authorization, headers }` for a request the guard accepts — no context needed |
40
+ | `makeBasicEd25519Guard(resource, opts?)` | The `GUARD_ED25519` guard service: signs outgoing requests as a client, verifies time/nonce/signature as a server; raw bytes sign as `{}` |
41
+ | `signBasicEd25519Request({ body?, credential, key })` | The guard's signing half as a pure helper: `{ authorization, headers }` for a request the guard accepts — no context needed; raw bytes sign as `{}` |
42
42
  | `authMiddleware` | Loading-stage context middleware that attaches the guard's token to every guarded backend entrypoint's `invoke`/`call` |
43
43
  | `SurrogateQuery`, `SurrogateQuerySchema` | The surrogate window's `intent` / `next` / `method` query |
44
44
 
@@ -148,6 +148,13 @@ token's slug only; both write `'-'` when neither is available. Read the gate you
148
148
  `KeyPairModel` with the private key. Send `authorization` plus BOTH returned headers (lowercase
149
149
  `x-auth-time`, `x-auth-nonce`) and the body byte-for-byte as signed — an absent body is signed as
150
150
  `{}`, the time precedes the nonce in the signed payload, and the guard rebuilds exactly that.
151
+ - **Raw bytes are never signed.** A body of raw bytes — a `Blob`, an `ArrayBuffer`, a typed array or
152
+ `Buffer`, a Node stream: what a streamed-body route (`streamBody()`, `@owlmeans/route`) carries — is
153
+ signed as `{}` by both halves (one private `signedPayloadOf`), because the caller cannot read its
154
+ stream twice and the server's guard runs before the body is read. Such a call passes the guard
155
+ as it is (never dress the stream with a `toJSON`); the signature proves the caller and the moment,
156
+ not the bytes, and — as on every route — not the path or query. A route that must prove its bytes
157
+ takes their digest in the query and refuses a stored body whose digest differs.
151
158
  - OIDC used only to sign in authorizes with a product gate, not `OIDC_GATE` (`server-oidc-rp` → Rules).
152
159
  - The trust resource (`TRUSTED`, from `@owlmeans/config`) is the system's source of truth for known
153
160
  signing identities — the auth service, peer services, wallet providers, supervisors.
@@ -0,0 +1,12 @@
1
+ import type { BasicEd25519Payload } from './types.local.js';
2
+ /**
3
+ * The value both halves of `GUARD_ED25519` sign: the body, then the time and the nonce.
4
+ *
5
+ * An absent body and a body of raw bytes are both `{}`. The bytes of a streamed-body route
6
+ * (`streamBody()` of `@owlmeans/route`) are therefore never covered by the signature: the caller
7
+ * holds a stream it cannot read twice, and the server has not read the body when its guard runs. The
8
+ * signature still proves who called and when (time, nonce, replay claim); a route that must prove its
9
+ * bytes declares their digest (in the query) and checks it against what it stored.
10
+ */
11
+ export declare const signedPayloadOf: (body: unknown, time: unknown, nonce: unknown) => BasicEd25519Payload;
12
+ //# sourceMappingURL=payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAa3D;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,SAAU,OAAO,QAAQ,OAAO,SAAS,OAAO,KAAG,mBAG7E,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { nonceKey, timeKey } from './consts.local.js';
2
+ /**
3
+ * Raw bytes, as `@owlmeans/api` sends them unserialized: a `Blob`, an `ArrayBuffer`, a typed array or
4
+ * a `Buffer`, a Node stream.
5
+ */
6
+ const isBinary = (body) => typeof body === 'object' && body != null && ((typeof Blob !== 'undefined' && body instanceof Blob)
7
+ || body instanceof ArrayBuffer || ArrayBuffer.isView(body)
8
+ || typeof body.pipe === 'function');
9
+ /**
10
+ * The value both halves of `GUARD_ED25519` sign: the body, then the time and the nonce.
11
+ *
12
+ * An absent body and a body of raw bytes are both `{}`. The bytes of a streamed-body route
13
+ * (`streamBody()` of `@owlmeans/route`) are therefore never covered by the signature: the caller
14
+ * holds a stream it cannot read twice, and the server has not read the body when its guard runs. The
15
+ * signature still proves who called and when (time, nonce, replay claim); a route that must prove its
16
+ * bytes declares their digest (in the query) and checks it against what it stored.
17
+ */
18
+ export const signedPayloadOf = (body, time, nonce) => ({
19
+ body: body == null || isBinary(body) ? {} : body,
20
+ headers: { [timeKey]: time, [nonceKey]: nonce },
21
+ });
22
+ //# sourceMappingURL=payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAGrD;;;GAGG;AACH,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAW,EAAE,CAC1C,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI,CAC1C,CAAC,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,YAAY,IAAI,CAAC;OAClD,IAAI,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;OACvD,OAAQ,IAA2B,CAAC,IAAI,KAAK,UAAU,CAC3D,CAAA;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAa,EAAE,IAAa,EAAE,KAAc,EAAuB,EAAE,CAAC,CAAC;IACrG,IAAI,EAAE,IAAI,IAAI,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI;IAChD,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE;CAChD,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAU7E,eAAO,MAAM,qBAAqB,aAAc,MAAM,SAAS,wBAAwB,KAAG,iBAmIzF,CAAA"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAW7E,eAAO,MAAM,qBAAqB,aAAc,MAAM,SAAS,wBAAwB,KAAG,iBA+HzF,CAAA"}
@@ -7,6 +7,7 @@ import { AuthenPayloadError, AuthroizationType, AuthRole } from '@owlmeans/auth'
7
7
  import { extractAuthToken } from '@owlmeans/auth-common/utils';
8
8
  import { makeMemorySignedRequestReplayStore, makeResourceSignedRequestReplayStore } from './replay.js';
9
9
  import { signBasicEd25519Request } from './sign.js';
10
+ import { signedPayloadOf } from './payload.js';
10
11
  export const makeBasicEd25519Guard = (resource, opts) => {
11
12
  const memoryReplay = makeMemorySignedRequestReplayStore();
12
13
  const replay = (context) => {
@@ -59,11 +60,8 @@ export const makeBasicEd25519Guard = (resource, opts) => {
59
60
  }
60
61
  const timestamp = req.headers?.[timeKey];
61
62
  const nonce = req.headers?.[nonceKey];
62
- const payload = {
63
- body: req.body ?? {},
64
- headers: { [timeKey]: timestamp, [nonceKey]: nonce }
65
- };
66
- if (!await trusted.key.verify(payload, signature.signature)) {
63
+ // A streamed-body route reaches its guard with no parsed body: verified as `{}`, as signed.
64
+ if (!await trusted.key.verify(signedPayloadOf(req.body, timestamp, nonce), signature.signature)) {
67
65
  return false;
68
66
  }
69
67
  if (typeof timestamp !== 'string') {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AAA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AqB;gBAC7C,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;gBAC3B;;mBAEG;gBACH,IAAI,EAAE,QAAQ,CAAC,OAAO;gBACtB,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,IAAI,IAAI,EAAE;aACtB,CAAC,CAAA;YAEF,OAAO,IAAS,CAAA;QAClB,CAAC;KACF,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;QACrB,KAAK,CAAC,WAAW,GAAG,IAAI,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
@@ -2,7 +2,8 @@ import type { BasicEd25519SignedRequest, BasicEd25519SignInput } from './types.j
2
2
  /**
3
3
  * Sign a request the way `GUARD_ED25519` verifies it: the body together with a fresh timestamp and
4
4
  * nonce. The guard's own client side signs through it, and so can any process holding a trusted
5
- * record's private key (a Node test helper, a service) without a context.
5
+ * record's private key (a Node test helper, a service) without a context. A body of raw bytes (a
6
+ * streamed-body route's) is signed as `{}`, exactly as the guard verifies it (`signedPayloadOf`).
6
7
  */
7
8
  export declare const signBasicEd25519Request: (input: BasicEd25519SignInput) => Promise<BasicEd25519SignedRequest>;
8
9
  //# sourceMappingURL=sign.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/sign.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,UAC3B,qBAAqB,KAC3B,OAAO,CAAC,yBAAyB,CAenC,CAAA"}
1
+ {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/sign.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,qBAAqB,KAC3B,OAAO,CAAC,yBAAyB,CAenC,CAAA"}
@@ -1,15 +1,17 @@
1
1
  import { AuthroizationType } from '@owlmeans/auth';
2
2
  import { createIdOfLength } from '@owlmeans/basic-ids';
3
3
  import { nonceKey, timeKey } from './consts.local.js';
4
+ import { signedPayloadOf } from './payload.js';
4
5
  /**
5
6
  * Sign a request the way `GUARD_ED25519` verifies it: the body together with a fresh timestamp and
6
7
  * nonce. The guard's own client side signs through it, and so can any process holding a trusted
7
- * record's private key (a Node test helper, a service) without a context.
8
+ * record's private key (a Node test helper, a service) without a context. A body of raw bytes (a
9
+ * streamed-body route's) is signed as `{}`, exactly as the guard verifies it (`signedPayloadOf`).
8
10
  */
9
11
  export const signBasicEd25519Request = async (input) => {
10
12
  const headers = { [timeKey]: new Date().toISOString(), [nonceKey]: createIdOfLength(16) };
11
- // Key order is part of the signed bytes: time first, then nonce — exactly what `handle` rebuilds.
12
- const payload = { body: input.body ?? {}, headers };
13
+ // The one payload `handle` rebuilds: the body (`{}` when absent or raw bytes), the time, the nonce.
14
+ const payload = signedPayloadOf(input.body, headers[timeKey], headers[nonceKey]);
13
15
  const token = [
14
16
  AuthroizationType.Ed25519BasicSignature.toUpperCase(),
15
17
  ['Credential', input.credential],
@@ -1 +1 @@
1
- {"version":3,"file":"sign.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAGrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC1C,KAA4B,EACQ,EAAE;IACtC,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW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CAAC,EAAE,CAAA;IACzF,oGAAoG;IACpG,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEhF,MAAM,KAAK,GAAG;QACZ,iBAAiB,CAAC,qBAAqB,CAAC,WAAW,EAAE;QACnD,CAAC,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC;QAChC,CAAC,WAAW,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAC/C,CAAA;IAED,OAAO;QACL,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QACvF,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE;KACxB,CAAA;AACH,CAAC,CAAA"}
@@ -23,7 +23,11 @@ export interface SignedRequestReplayResource extends BasicResource {
23
23
  }
24
24
  /** What `signBasicEd25519Request` signs: the request body and the signer's identity. */
25
25
  export interface BasicEd25519SignInput {
26
- /** The body exactly as it will be sent; an absent body is signed as `{}`, as the guard verifies it. */
26
+ /**
27
+ * The body exactly as it will be sent. An absent body and raw bytes (a `Blob`, an `ArrayBuffer`, a
28
+ * typed array, a stream — a streamed-body route's) are signed as `{}`, as the guard verifies them:
29
+ * such bytes are not covered by the signature.
30
+ */
27
31
  body?: unknown;
28
32
  /** The signer's trusted-record `id` — the guard loads the verifying key by it. */
29
33
  credential: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,K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oB,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,MAAM,WAAW,iBAAkB,SAAQ,YAAY;CACtD;AAED,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2FAA2F;IAC3F,MAAM,CAAC,EAAE,wBAAwB,CAAA;CAClC;AAED,4DAA4D;AAC5D,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACzD;AAED,gFAAgF;AAChF,MAAM,WAAW,2BAA4B,SAAQ,aAAa;IAChE,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,cAAc,CAAC,CAAA;CAC1F;AAED,wFAAwF;AACxF,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAA;IAClB,gGAAgG;IAChG,GAAG,EAAE,YAAY,CAAA;CAClB;AAED,6DAA6D;AAC7D,MAAM,WAAW,yBAAyB;IACxC,mGAAmG;IACnG,aAAa,EAAE,MAAM,CAAA;IACrB,iGAAiG;IACjG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC"}
@@ -0,0 +1,8 @@
1
+ /** What `GUARD_ED25519` signs and verifies — built by `signedPayloadOf` on both halves. */
2
+ export interface BasicEd25519Payload {
3
+ /** The JSON body as sent; `{}` for an absent body and for raw bytes (a streamed-body route). */
4
+ body: unknown;
5
+ /** The time, then the nonce — key order is part of the signed bytes. */
6
+ headers: Record<string, unknown>;
7
+ }
8
+ //# sourceMappingURL=types.local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/types.local.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,WAAW,mBAAmB;IAClC,gGAAgG;IAChG,IAAI,EAAE,OAAO,CAAA;IACb,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/types.local.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare const modules: import("@owlmeans/entrypoint").CommonEntrypoint[];
2
+ export declare const managerModules: import("@owlmeans/entrypoint").CommonEntrypoint[];
3
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO,mDAuBnB,CAAA;AAED,eAAO,MAAM,cAAc,mDAW1B,CAAA"}
@@ -0,0 +1,38 @@
1
+ import { AUTHEN, AUTHEN_AUTHEN, AUTHEN_INIT, AUTHEN_RELY, AllowanceRequestSchema, AuthCredentialsSchema, AuthTokenSchema, CAUTHEN, CAUTHEN_AUTHEN, CAUTHEN_AUTHEN_DEFAULT, CAUTHEN_AUTHEN_TYPED, DISPATCHER, DISPATCHER_AUTHEN, OptionalAuthTokenSchema, CAUTHEN_FLOW_ENTER } from '@owlmeans/auth';
2
+ // import { AppType } from '@owlmeans/context'
3
+ import { body, filter, entrypoint, query } from '@owlmeans/entrypoint';
4
+ import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route';
5
+ import { DISPATCHER_PATH, WEB_API, authApi } from './consts.js';
6
+ export const modules = [
7
+ entrypoint(route(AUTHEN, '/authentication', backend())),
8
+ entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
9
+ entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
10
+ entrypoint(route(AUTHEN_RELY, '/rely', socket(AUTHEN)), filter(query(OptionalAuthTokenSchema))),
11
+ entrypoint(route(CAUTHEN, '/authentication', frontend())),
12
+ entrypoint(route(CAUTHEN_AUTHEN, '/login', frontend(CAUTHEN))),
13
+ entrypoint(route(CAUTHEN_AUTHEN_DEFAULT, '/', frontend(CAUTHEN_AUTHEN, true))),
14
+ entrypoint(route(CAUTHEN_AUTHEN_TYPED, '/:type', frontend(CAUTHEN_AUTHEN))),
15
+ // This is a helper route that is used by service providers to redirect to an external authentication service.
16
+ entrypoint(route(CAUTHEN_FLOW_ENTER, '/', frontend())),
17
+ // This is a helper route that is useb by service providres to process authentication provisioning via redirect.
18
+ // Also it can be default starting point to be redirected to an external identity provider.
19
+ entrypoint(route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
20
+ // This module is sticky - it means it's always attach to client router.
21
+ // It's required here cause every web app needs dispatcher route to authorize
22
+ // rediected users.
23
+ filter(query(AuthTokenSchema), { sticky: true })),
24
+ // This is a helper route that representes a API endpoint of service provider that wants to authenticate
25
+ // a user with OwlMeans server-auth library.
26
+ entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
27
+ ];
28
+ export const managerModules = [
29
+ entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
30
+ entrypoint(route(authApi.profile.toEntityId, '/to-entity-id', backend(authApi.profile.base, RouteMethod.POST))),
31
+ entrypoint(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
32
+ entrypoint(route(authApi.auth.delegate, '/delegate', backend(authApi.auth.base, RouteMethod.POST))),
33
+ ];
34
+ // const skipModules = [DISPATCHER]
35
+ // export const authBackendModules = modules.filter(
36
+ // module => !skipModules.includes(module.alias) && module.route.route.type === AppType.Backend
37
+ // ).map(module => module.alias)
38
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,qBAAqB,EAC9F,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,UAAU,EAClG,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAC/D,MAAM,gBAAgB,CAAA;AACvB,8CAA8C;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE/D,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,CAAC;IACvD,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAChH,UAAU,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,EAAE,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACzH,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,MA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OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,eAAe,EAC3C,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAChD,CAAC;IACF,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC5E,UAAU,CAAC,KAAK,CACd,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAClC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAC7C,CAAC;CACH,CAAA;AAED,mCAAmC;AACnC,oDAAoD;AACpD,iGAAiG;AACjG,gCAAgC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/auth-common",
3
- "version": "0.1.20-rc.1",
3
+ "version": "0.1.22-rc.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://owlmeans.com/docs/",
6
6
  "repository": {
@@ -39,19 +39,19 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@owlmeans/auth": "^0.1.20-rc.1",
43
- "@owlmeans/auth-common": "^0.1.20-rc.1",
44
- "@owlmeans/basic-ids": "^0.1.20-rc.1",
45
- "@owlmeans/basic-keys": "^0.1.20-rc.1",
46
- "@owlmeans/client-entrypoint": "^0.1.20-rc.1",
47
- "@owlmeans/context": "^0.1.20-rc.1",
48
- "@owlmeans/entrypoint": "^0.1.20-rc.1",
49
- "@owlmeans/resource": "^0.1.20-rc.1",
50
- "@owlmeans/route": "^0.1.20-rc.1"
42
+ "@owlmeans/auth": "^0.1.21",
43
+ "@owlmeans/auth-common": "^0.1.22-rc.0",
44
+ "@owlmeans/basic-ids": "^0.1.21",
45
+ "@owlmeans/basic-keys": "^0.1.22-rc.0",
46
+ "@owlmeans/client-entrypoint": "^0.1.22-rc.0",
47
+ "@owlmeans/context": "^0.1.21",
48
+ "@owlmeans/entrypoint": "^0.1.22-rc.0",
49
+ "@owlmeans/resource": "^0.1.21",
50
+ "@owlmeans/route": "^0.1.22-rc.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@owlmeans/dep-config": "^0.1.20-rc.1",
54
- "@owlmeans/test-auth": "^0.1.20-rc.1",
53
+ "@owlmeans/dep-config": "^0.1.21",
54
+ "@owlmeans/test-auth": "^0.1.22-rc.0",
55
55
  "@types/bun": "^1.4.4",
56
56
  "nodemon": "^3.1.14",
57
57
  "typescript": "^7.0.2"
@@ -0,0 +1,27 @@
1
+ import { nonceKey, timeKey } from './consts.local.js'
2
+ import type { BasicEd25519Payload } from './types.local.js'
3
+
4
+ /**
5
+ * Raw bytes, as `@owlmeans/api` sends them unserialized: a `Blob`, an `ArrayBuffer`, a typed array or
6
+ * a `Buffer`, a Node stream.
7
+ */
8
+ const isBinary = (body: unknown): boolean =>
9
+ typeof body === 'object' && body != null && (
10
+ (typeof Blob !== 'undefined' && body instanceof Blob)
11
+ || body instanceof ArrayBuffer || ArrayBuffer.isView(body)
12
+ || typeof (body as { pipe?: unknown }).pipe === 'function'
13
+ )
14
+
15
+ /**
16
+ * The value both halves of `GUARD_ED25519` sign: the body, then the time and the nonce.
17
+ *
18
+ * An absent body and a body of raw bytes are both `{}`. The bytes of a streamed-body route
19
+ * (`streamBody()` of `@owlmeans/route`) are therefore never covered by the signature: the caller
20
+ * holds a stream it cannot read twice, and the server has not read the body when its guard runs. The
21
+ * signature still proves who called and when (time, nonce, replay claim); a route that must prove its
22
+ * bytes declares their digest (in the query) and checks it against what it stored.
23
+ */
24
+ export const signedPayloadOf = (body: unknown, time: unknown, nonce: unknown): BasicEd25519Payload => ({
25
+ body: body == null || isBinary(body) ? {} : body,
26
+ headers: { [timeKey]: time, [nonceKey]: nonce },
27
+ })
@@ -14,6 +14,7 @@ import {
14
14
  } from './replay.js'
15
15
  import type { SignedRequestReplayResource, SignedRequestReplayStore } from './types.js'
16
16
  import { signBasicEd25519Request } from './sign.js'
17
+ import { signedPayloadOf } from './payload.js'
17
18
 
18
19
  export const makeBasicEd25519Guard = (resource: string, opts?: BasicEd25519GuardOptions): BasicEd25519Guard => {
19
20
  const memoryReplay = makeMemorySignedRequestReplayStore()
@@ -82,12 +83,8 @@ export const makeBasicEd25519Guard = (resource: string, opts?: BasicEd25519Guard
82
83
  const timestamp = req.headers?.[timeKey]
83
84
  const nonce = req.headers?.[nonceKey]
84
85
 
85
- const payload = {
86
- body: req.body ?? {},
87
- headers: { [timeKey]: timestamp, [nonceKey]: nonce }
88
- }
89
-
90
- if (!await trusted.key.verify(payload, signature.signature)) {
86
+ // A streamed-body route reaches its guard with no parsed body: verified as `{}`, as signed.
87
+ if (!await trusted.key.verify(signedPayloadOf(req.body, timestamp, nonce), signature.signature)) {
91
88
  return false as T
92
89
  }
93
90
 
@@ -1,19 +1,21 @@
1
1
  import { AuthroizationType } from '@owlmeans/auth'
2
2
  import { createIdOfLength } from '@owlmeans/basic-ids'
3
3
  import { nonceKey, timeKey } from './consts.local.js'
4
+ import { signedPayloadOf } from './payload.js'
4
5
  import type { BasicEd25519SignedRequest, BasicEd25519SignInput } from './types.js'
5
6
 
6
7
  /**
7
8
  * Sign a request the way `GUARD_ED25519` verifies it: the body together with a fresh timestamp and
8
9
  * nonce. The guard's own client side signs through it, and so can any process holding a trusted
9
- * record's private key (a Node test helper, a service) without a context.
10
+ * record's private key (a Node test helper, a service) without a context. A body of raw bytes (a
11
+ * streamed-body route's) is signed as `{}`, exactly as the guard verifies it (`signedPayloadOf`).
10
12
  */
11
13
  export const signBasicEd25519Request = async (
12
14
  input: BasicEd25519SignInput
13
15
  ): Promise<BasicEd25519SignedRequest> => {
14
16
  const headers = { [timeKey]: new Date().toISOString(), [nonceKey]: createIdOfLength(16) }
15
- // Key order is part of the signed bytes: time first, then nonce — exactly what `handle` rebuilds.
16
- const payload = { body: input.body ?? {}, headers }
17
+ // The one payload `handle` rebuilds: the body (`{}` when absent or raw bytes), the time, the nonce.
18
+ const payload = signedPayloadOf(input.body, headers[timeKey], headers[nonceKey])
17
19
 
18
20
  const token = [
19
21
  AuthroizationType.Ed25519BasicSignature.toUpperCase()
@@ -0,0 +1,7 @@
1
+ /** What `GUARD_ED25519` signs and verifies — built by `signedPayloadOf` on both halves. */
2
+ export interface BasicEd25519Payload {
3
+ /** The JSON body as sent; `{}` for an absent body and for raw bytes (a streamed-body route). */
4
+ body: unknown
5
+ /** The time, then the nonce — key order is part of the signed bytes. */
6
+ headers: Record<string, unknown>
7
+ }
@@ -28,7 +28,11 @@ export interface SignedRequestReplayResource extends BasicResource {
28
28
 
29
29
  /** What `signBasicEd25519Request` signs: the request body and the signer's identity. */
30
30
  export interface BasicEd25519SignInput {
31
- /** The body exactly as it will be sent; an absent body is signed as `{}`, as the guard verifies it. */
31
+ /**
32
+ * The body exactly as it will be sent. An absent body and raw bytes (a `Blob`, an `ArrayBuffer`, a
33
+ * typed array, a stream — a streamed-body route's) are signed as `{}`, as the guard verifies them:
34
+ * such bytes are not covered by the signature.
35
+ */
32
36
  body?: unknown
33
37
  /** The signer's trusted-record `id` — the guard loads the verifying key by it. */
34
38
  credential: string
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
+ import { Readable } from 'node:stream'
2
3
  import { AuthenPayloadError, AuthroizationType } from '@owlmeans/auth'
3
4
  import {
4
5
  BED255_NONCE_HEADER, BED255_SIG_TTL, BED255_TIME_HEADER, makeBasicEd25519Guard,
@@ -145,4 +146,25 @@ describe('@owlmeans/auth-common — signBasicEd25519Request', () => {
145
146
  expect(typeof outgoing.headers?.[nonceKey]).toBe('string')
146
147
  expect((await handle(guard, req))?.userId).toBe(fixture.authRecord.id)
147
148
  })
149
+
150
+ test('raw bytes sign as `{}`: accepted where a streamed route\'s server sees no body', async () => {
151
+ const fixture = makeTrustFixture({ withSecret: true, name: 'auth-common-tests' })
152
+ const guard = makeBasicEd25519Guard(TRUSTED_ALIAS)
153
+ fixture.ctx.registerService(guard)
154
+ const bodies: unknown[] = [
155
+ Readable.from([Buffer.from('streamed bytes')]), new Uint8Array([1, 2, 3]), new Blob(['blob']), new ArrayBuffer(4),
156
+ ]
157
+
158
+ for (const body of bodies) {
159
+ const outgoing: Partial<AbstractRequest> = { body }
160
+ const authorization = await guard.authenticated(outgoing)
161
+ // The server half of a streamed-body route: the parser leaves the body unread.
162
+ const req = {
163
+ alias: 'streamed', body: undefined, params: {}, query: {}, path: '/streamed',
164
+ headers: { ...outgoing.headers, authorization: authorization ?? '' },
165
+ } satisfies AbstractRequest
166
+
167
+ expect((await handle(guard, req))?.userId).toBe(fixture.authRecord.id)
168
+ }
169
+ })
148
170
  })