@owlmeans/auth-common 0.1.18 → 0.1.19
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.
- package/README.md +21 -2
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/auth-common/SKILL.md +9 -2
- package/build/guards/basic-ed25519/index.d.ts +1 -0
- package/build/guards/basic-ed25519/index.d.ts.map +1 -1
- package/build/guards/basic-ed25519/index.js +1 -0
- package/build/guards/basic-ed25519/index.js.map +1 -1
- package/build/guards/basic-ed25519/service.d.ts.map +1 -1
- package/build/guards/basic-ed25519/service.js +6 -14
- package/build/guards/basic-ed25519/service.js.map +1 -1
- package/build/guards/basic-ed25519/sign.d.ts +8 -0
- package/build/guards/basic-ed25519/sign.d.ts.map +1 -0
- package/build/guards/basic-ed25519/sign.js +23 -0
- package/build/guards/basic-ed25519/sign.js.map +1 -0
- package/build/guards/basic-ed25519/types.d.ts +17 -0
- package/build/guards/basic-ed25519/types.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/guards/basic-ed25519/index.ts +1 -0
- package/src/guards/basic-ed25519/service.ts +6 -18
- package/src/guards/basic-ed25519/sign.ts +28 -0
- package/src/guards/basic-ed25519/types.ts +19 -0
- package/tests/basic-ed25519.spec.ts +50 -1
- package/build/modules.d.ts +0 -3
- package/build/modules.d.ts.map +0 -1
- package/build/modules.js +0 -38
- package/build/modules.js.map +0 -1
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.
|
|
15
|
+
bun add @owlmeans/auth-common@^0.1.19
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
@@ -77,6 +77,25 @@ BED255_TIME_HEADER // 'X-Auth-Time'
|
|
|
77
77
|
BED255_CASHE_RESOURCE // resource alias for nonce cache
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
### Signing a request outside a context
|
|
81
|
+
|
|
82
|
+
`signBasicEd25519Request({ body, credential, key })` signs a request exactly as the
|
|
83
|
+
`GUARD_ED25519` guard verifies it (the guard's own client side uses it): `credential` is the
|
|
84
|
+
signer's trusted-record `id`, `key` a `KeyPairModel` with the private key. It answers
|
|
85
|
+
`{ authorization, headers }` — send both, with the body unchanged.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { signBasicEd25519Request } from '@owlmeans/auth-common'
|
|
89
|
+
import { makeKeyPairModel } from '@owlmeans/basic-keys'
|
|
90
|
+
|
|
91
|
+
const body = { challenge, pin }
|
|
92
|
+
const signed = await signBasicEd25519Request({ body, credential: recordId, key: makeKeyPairModel(privateKey) })
|
|
93
|
+
await fetch(url, {
|
|
94
|
+
method: 'POST', body: JSON.stringify(body),
|
|
95
|
+
headers: { 'content-type': 'application/json', authorization: signed.authorization, ...signed.headers },
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
80
99
|
## Product-Viable Integration Notes
|
|
81
100
|
|
|
82
101
|
- `DEFAULT_GUARD` protects manager routes after bearer authentication is installed by `@owlmeans/server-auth`.
|
|
@@ -98,7 +117,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
98
117
|
your project's skill store (`.agents/skills/`):
|
|
99
118
|
|
|
100
119
|
```sh
|
|
101
|
-
npx @owlmeans/agent-skills@^0.1.
|
|
120
|
+
npx @owlmeans/agent-skills@^0.1.19
|
|
102
121
|
```
|
|
103
122
|
|
|
104
123
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 3,
|
|
3
3
|
"package": "@owlmeans/auth-common",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.19",
|
|
5
|
+
"generatedAt": "2026-11-01T22:22:22.293Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: auth-common
|
|
3
|
-
description: How to use @owlmeans/auth-common — the auth vocabulary both sides of the wire share, covering guard aliases (DEFAULT_GUARD, GUARD_ED25519), the shared auth protocol trees, the Ed25519 signature guard, the TRUSTED-record trust() helper, and the organization-entity resolver contract (ENTITY_RESOLVER, makeEntityScope). Auto-invoked when importing guard constants, shared auth protocols, or entity-resolution helpers.
|
|
3
|
+
description: How to use @owlmeans/auth-common — the auth vocabulary both sides of the wire share, covering guard aliases (DEFAULT_GUARD, GUARD_ED25519), the shared auth protocol trees, the Ed25519 signature guard and its context-free signer (signBasicEd25519Request), the TRUSTED-record trust() helper, and the organization-entity resolver contract (ENTITY_RESOLVER, makeEntityScope). Auto-invoked when importing guard constants, shared auth protocols, or entity-resolution helpers, or when signing a GUARD_ED25519 request outside a context.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -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.
|
|
11
|
+
**Install:** `"@owlmeans/auth-common": "^0.1.19"` 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
|
|
@@ -38,6 +38,7 @@ entity a token names.
|
|
|
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
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 |
|
|
41
42
|
| `authMiddleware` | Loading-stage context middleware that attaches the guard's token to every guarded backend entrypoint's `invoke`/`call` |
|
|
42
43
|
| `SurrogateQuery`, `SurrogateQuerySchema` | The surrogate window's `intent` / `next` / `method` query |
|
|
43
44
|
|
|
@@ -141,6 +142,12 @@ token's slug only; both write `'-'` when neither is available. Read the gate you
|
|
|
141
142
|
accepts only canonical timestamps inside its symmetric 60-second window and claims the
|
|
142
143
|
credential-and-nonce pair until that timestamp's absolute expiry; a replay-store error refuses
|
|
143
144
|
authentication rather than disabling deduplication.
|
|
145
|
+
- A process that holds a trusted record's private key but no context (a Node test helper, a
|
|
146
|
+
script) signs with `signBasicEd25519Request`, never a re-derived copy: `credential` is the
|
|
147
|
+
record's `id` (OwlMeans deployments use the key's address, `ed25519:<address>`), `key` a
|
|
148
|
+
`KeyPairModel` with the private key. Send `authorization` plus BOTH returned headers (lowercase
|
|
149
|
+
`x-auth-time`, `x-auth-nonce`) and the body byte-for-byte as signed — an absent body is signed as
|
|
150
|
+
`{}`, the time precedes the nonce in the signed payload, and the guard rebuilds exactly that.
|
|
144
151
|
- OIDC used only to sign in authorizes with a product gate, not `OIDC_GATE` (`server-oidc-rp` → Rules).
|
|
145
152
|
- The trust resource (`TRUSTED`, from `@owlmeans/config`) is the system's source of truth for known
|
|
146
153
|
signing identities — the auth service, peer services, wallet providers, supervisors.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,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,
|
|
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"}
|
|
@@ -4,9 +4,9 @@ import { BED255_CASHE_RESOURCE, GUARD_ED25519, BED255_SIG_TTL } from './consts.j
|
|
|
4
4
|
import { nonceKey, timeKey } from './consts.local.js';
|
|
5
5
|
import { trust } from '../../utils/trusted.js';
|
|
6
6
|
import { AuthenPayloadError, AuthroizationType, AuthRole } from '@owlmeans/auth';
|
|
7
|
-
import { createIdOfLength } from '@owlmeans/basic-ids';
|
|
8
7
|
import { extractAuthToken } from '@owlmeans/auth-common/utils';
|
|
9
8
|
import { makeMemorySignedRequestReplayStore, makeResourceSignedRequestReplayStore } from './replay.js';
|
|
9
|
+
import { signBasicEd25519Request } from './sign.js';
|
|
10
10
|
export const makeBasicEd25519Guard = (resource, opts) => {
|
|
11
11
|
const memoryReplay = makeMemorySignedRequestReplayStore();
|
|
12
12
|
const replay = (context) => {
|
|
@@ -23,23 +23,15 @@ export const makeBasicEd25519Guard = (resource, opts) => {
|
|
|
23
23
|
authenticated: async (req) => {
|
|
24
24
|
const context = assertContext(guard.ctx);
|
|
25
25
|
const truested = await trust(context, resource, context.cfg.alias ?? context.cfg.service);
|
|
26
|
-
// req?.body != null
|
|
27
26
|
if (req != null && truested.user.secret != null) {
|
|
27
|
+
const signed = await signBasicEd25519Request({
|
|
28
|
+
body: req.body, credential: truested.user.id, key: truested.key,
|
|
29
|
+
});
|
|
28
30
|
if (req.headers == null) {
|
|
29
31
|
req.headers = {};
|
|
30
32
|
}
|
|
31
|
-
req.headers
|
|
32
|
-
|
|
33
|
-
const payload = {
|
|
34
|
-
body: req.body ?? {},
|
|
35
|
-
headers: { [timeKey]: req.headers[timeKey], [nonceKey]: req.headers[nonceKey] }
|
|
36
|
-
};
|
|
37
|
-
const token = [
|
|
38
|
-
AuthroizationType.Ed25519BasicSignature.toUpperCase(),
|
|
39
|
-
['Credential', truested.user.id],
|
|
40
|
-
['Signature', await truested.key.sign(payload)]
|
|
41
|
-
];
|
|
42
|
-
return token.map(item => Array.isArray(item) ? item.join('=') : item).join(' ');
|
|
33
|
+
Object.assign(req.headers, signed.headers);
|
|
34
|
+
return signed.authorization;
|
|
43
35
|
}
|
|
44
36
|
return null;
|
|
45
37
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAG9C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAG9C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EACL,kCAAkC,EAAE,oCAAoC,EACzE,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAE,IAA+B,EAAqB,EAAE;IAC5G,MAAM,YAAY,GAAG,kCAAkC,EAAE,CAAA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AE,CAAC,KAAK,IAAI,EAAE;QACrB,KAAK,CAAC,WAAW,GAAG,IAAI,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BasicEd25519SignedRequest, BasicEd25519SignInput } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sign a request the way `GUARD_ED25519` verifies it: the body together with a fresh timestamp and
|
|
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.
|
|
6
|
+
*/
|
|
7
|
+
export declare const signBasicEd25519Request: (input: BasicEd25519SignInput) => Promise<BasicEd25519SignedRequest>;
|
|
8
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthroizationType } from '@owlmeans/auth';
|
|
2
|
+
import { createIdOfLength } from '@owlmeans/basic-ids';
|
|
3
|
+
import { nonceKey, timeKey } from './consts.local.js';
|
|
4
|
+
/**
|
|
5
|
+
* Sign a request the way `GUARD_ED25519` verifies it: the body together with a fresh timestamp and
|
|
6
|
+
* 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
|
+
*/
|
|
9
|
+
export const signBasicEd25519Request = async (input) => {
|
|
10
|
+
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
|
+
const token = [
|
|
14
|
+
AuthroizationType.Ed25519BasicSignature.toUpperCase(),
|
|
15
|
+
['Credential', input.credential],
|
|
16
|
+
['Signature', await input.key.sign(payload)]
|
|
17
|
+
];
|
|
18
|
+
return {
|
|
19
|
+
authorization: token.map(item => Array.isArray(item) ? item.join('=') : item).join(' '),
|
|
20
|
+
headers: { ...headers },
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=sign.js.map
|
|
@@ -0,0 +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,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAA;IACzF,kGAAkG;IAClG,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,EAAE,CAAA;IAEnD,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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GuardService } from '@owlmeans/entrypoint';
|
|
2
2
|
import type { ResourceRecord, WriteOptions } from '@owlmeans/resource';
|
|
3
3
|
import type { BasicResource } from '@owlmeans/context';
|
|
4
|
+
import type { KeyPairModel } from '@owlmeans/basic-keys';
|
|
4
5
|
export interface BasicEd25519Guard extends GuardService {
|
|
5
6
|
}
|
|
6
7
|
export interface BasicEd25519GuardOptions {
|
|
@@ -20,4 +21,20 @@ export interface SignedRequestReplayStore {
|
|
|
20
21
|
export interface SignedRequestReplayResource extends BasicResource {
|
|
21
22
|
create: (record: Partial<ResourceRecord>, opts?: WriteOptions) => Promise<ResourceRecord>;
|
|
22
23
|
}
|
|
24
|
+
/** What `signBasicEd25519Request` signs: the request body and the signer's identity. */
|
|
25
|
+
export interface BasicEd25519SignInput {
|
|
26
|
+
/** The body exactly as it will be sent; an absent body is signed as `{}`, as the guard verifies it. */
|
|
27
|
+
body?: unknown;
|
|
28
|
+
/** The signer's trusted-record `id` — the guard loads the verifying key by it. */
|
|
29
|
+
credential: string;
|
|
30
|
+
/** The signer's key pair; it must carry the private key (a `TrustedRecord` with a `secret`). */
|
|
31
|
+
key: KeyPairModel;
|
|
32
|
+
}
|
|
33
|
+
/** A request signature the `GUARD_ED25519` guard accepts. */
|
|
34
|
+
export interface BasicEd25519SignedRequest {
|
|
35
|
+
/** The `authorization` header: `ED25519-BASIC-SIGNATURE Credential=<id> Signature=<signature>`. */
|
|
36
|
+
authorization: string;
|
|
37
|
+
/** The signed time and nonce headers under their lowercase names; send them with the request. */
|
|
38
|
+
headers: Record<string, string>;
|
|
39
|
+
}
|
|
23
40
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;
|
|
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,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,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,uGAAuG;IACvG,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/auth-common",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@owlmeans/auth": "^0.1.
|
|
33
|
-
"@owlmeans/auth-common": "^0.1.
|
|
34
|
-
"@owlmeans/basic-ids": "^0.1.
|
|
35
|
-
"@owlmeans/basic-keys": "^0.1.
|
|
36
|
-
"@owlmeans/client-entrypoint": "^0.1.
|
|
37
|
-
"@owlmeans/context": "^0.1.
|
|
38
|
-
"@owlmeans/entrypoint": "^0.1.
|
|
39
|
-
"@owlmeans/resource": "^0.1.
|
|
40
|
-
"@owlmeans/route": "^0.1.
|
|
32
|
+
"@owlmeans/auth": "^0.1.19",
|
|
33
|
+
"@owlmeans/auth-common": "^0.1.19",
|
|
34
|
+
"@owlmeans/basic-ids": "^0.1.19",
|
|
35
|
+
"@owlmeans/basic-keys": "^0.1.19",
|
|
36
|
+
"@owlmeans/client-entrypoint": "^0.1.19",
|
|
37
|
+
"@owlmeans/context": "^0.1.19",
|
|
38
|
+
"@owlmeans/entrypoint": "^0.1.19",
|
|
39
|
+
"@owlmeans/resource": "^0.1.19",
|
|
40
|
+
"@owlmeans/route": "^0.1.19"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@owlmeans/dep-config": "^0.1.
|
|
44
|
-
"@owlmeans/test-auth": "^0.1.
|
|
45
|
-
"@types/bun": "^1.4.
|
|
43
|
+
"@owlmeans/dep-config": "^0.1.19",
|
|
44
|
+
"@owlmeans/test-auth": "^0.1.19",
|
|
45
|
+
"@types/bun": "^1.4.4",
|
|
46
46
|
"nodemon": "^3.1.14",
|
|
47
47
|
"typescript": "^7.0.2"
|
|
48
48
|
},
|
|
@@ -8,12 +8,12 @@ import type { Config, Context } from '../../utils/types.js'
|
|
|
8
8
|
import type { BasicEd25519Guard, BasicEd25519GuardOptions } from './types.js'
|
|
9
9
|
import { AuthenPayloadError, AuthroizationType, AuthRole } from '@owlmeans/auth'
|
|
10
10
|
import type { Auth } from '@owlmeans/auth'
|
|
11
|
-
import { createIdOfLength } from '@owlmeans/basic-ids'
|
|
12
11
|
import { extractAuthToken } from '@owlmeans/auth-common/utils'
|
|
13
12
|
import {
|
|
14
13
|
makeMemorySignedRequestReplayStore, makeResourceSignedRequestReplayStore
|
|
15
14
|
} from './replay.js'
|
|
16
15
|
import type { SignedRequestReplayResource, SignedRequestReplayStore } from './types.js'
|
|
16
|
+
import { signBasicEd25519Request } from './sign.js'
|
|
17
17
|
|
|
18
18
|
export const makeBasicEd25519Guard = (resource: string, opts?: BasicEd25519GuardOptions): BasicEd25519Guard => {
|
|
19
19
|
const memoryReplay = makeMemorySignedRequestReplayStore()
|
|
@@ -36,28 +36,16 @@ export const makeBasicEd25519Guard = (resource: string, opts?: BasicEd25519Guard
|
|
|
36
36
|
const context = assertContext<Config, Context>(guard.ctx)
|
|
37
37
|
const truested = await trust(context, resource, context.cfg.alias ?? context.cfg.service)
|
|
38
38
|
|
|
39
|
-
// req?.body != null
|
|
40
39
|
if (req != null && truested.user.secret != null) {
|
|
40
|
+
const signed = await signBasicEd25519Request({
|
|
41
|
+
body: req.body, credential: truested.user.id, key: truested.key,
|
|
42
|
+
})
|
|
41
43
|
if (req.headers == null) {
|
|
42
44
|
req.headers = {}
|
|
43
45
|
}
|
|
44
|
-
req.headers
|
|
45
|
-
req.headers[nonceKey] = createIdOfLength(16)
|
|
46
|
+
Object.assign(req.headers, signed.headers)
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
body: req.body ?? {},
|
|
49
|
-
headers: { [timeKey]: req.headers[timeKey], [nonceKey]: req.headers[nonceKey] }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const token = [
|
|
53
|
-
AuthroizationType.Ed25519BasicSignature.toUpperCase()
|
|
54
|
-
, ['Credential', truested.user.id]
|
|
55
|
-
, ['Signature', await truested.key.sign(payload)]
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
return token.map(
|
|
59
|
-
item => Array.isArray(item) ? item.join('=') : item
|
|
60
|
-
).join(' ')
|
|
48
|
+
return signed.authorization
|
|
61
49
|
}
|
|
62
50
|
|
|
63
51
|
return null
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AuthroizationType } from '@owlmeans/auth'
|
|
2
|
+
import { createIdOfLength } from '@owlmeans/basic-ids'
|
|
3
|
+
import { nonceKey, timeKey } from './consts.local.js'
|
|
4
|
+
import type { BasicEd25519SignedRequest, BasicEd25519SignInput } from './types.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sign a request the way `GUARD_ED25519` verifies it: the body together with a fresh timestamp and
|
|
8
|
+
* 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
|
+
*/
|
|
11
|
+
export const signBasicEd25519Request = async (
|
|
12
|
+
input: BasicEd25519SignInput
|
|
13
|
+
): Promise<BasicEd25519SignedRequest> => {
|
|
14
|
+
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
|
+
|
|
18
|
+
const token = [
|
|
19
|
+
AuthroizationType.Ed25519BasicSignature.toUpperCase()
|
|
20
|
+
, ['Credential', input.credential]
|
|
21
|
+
, ['Signature', await input.key.sign(payload)]
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
authorization: token.map(item => Array.isArray(item) ? item.join('=') : item).join(' '),
|
|
26
|
+
headers: { ...headers },
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GuardService } from '@owlmeans/entrypoint'
|
|
2
2
|
import type { ResourceRecord, WriteOptions } from '@owlmeans/resource'
|
|
3
3
|
import type { BasicResource } from '@owlmeans/context'
|
|
4
|
+
import type { KeyPairModel } from '@owlmeans/basic-keys'
|
|
4
5
|
|
|
5
6
|
export interface BasicEd25519Guard extends GuardService {
|
|
6
7
|
}
|
|
@@ -24,3 +25,21 @@ export interface SignedRequestReplayStore {
|
|
|
24
25
|
export interface SignedRequestReplayResource extends BasicResource {
|
|
25
26
|
create: (record: Partial<ResourceRecord>, opts?: WriteOptions) => Promise<ResourceRecord>
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
/** What `signBasicEd25519Request` signs: the request body and the signer's identity. */
|
|
30
|
+
export interface BasicEd25519SignInput {
|
|
31
|
+
/** The body exactly as it will be sent; an absent body is signed as `{}`, as the guard verifies it. */
|
|
32
|
+
body?: unknown
|
|
33
|
+
/** The signer's trusted-record `id` — the guard loads the verifying key by it. */
|
|
34
|
+
credential: string
|
|
35
|
+
/** The signer's key pair; it must carry the private key (a `TrustedRecord` with a `secret`). */
|
|
36
|
+
key: KeyPairModel
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A request signature the `GUARD_ED25519` guard accepts. */
|
|
40
|
+
export interface BasicEd25519SignedRequest {
|
|
41
|
+
/** The `authorization` header: `ED25519-BASIC-SIGNATURE Credential=<id> Signature=<signature>`. */
|
|
42
|
+
authorization: string
|
|
43
|
+
/** The signed time and nonce headers under their lowercase names; send them with the request. */
|
|
44
|
+
headers: Record<string, string>
|
|
45
|
+
}
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'bun:test'
|
|
|
2
2
|
import { AuthenPayloadError, AuthroizationType } from '@owlmeans/auth'
|
|
3
3
|
import {
|
|
4
4
|
BED255_NONCE_HEADER, BED255_SIG_TTL, BED255_TIME_HEADER, makeBasicEd25519Guard,
|
|
5
|
-
makeResourceSignedRequestReplayStore
|
|
5
|
+
makeResourceSignedRequestReplayStore, signBasicEd25519Request
|
|
6
6
|
} from '@owlmeans/auth-common'
|
|
7
7
|
import type { BasicEd25519Guard, SignedRequestReplayResource } from '@owlmeans/auth-common'
|
|
8
8
|
import type { AbstractRequest, AbstractResponse } from '@owlmeans/entrypoint'
|
|
@@ -97,3 +97,52 @@ describe('@owlmeans/auth-common — signed request freshness and replay protecti
|
|
|
97
97
|
expect(await replay.claim('service:nonce', expiresAt)).toBe(false)
|
|
98
98
|
})
|
|
99
99
|
})
|
|
100
|
+
|
|
101
|
+
describe('@owlmeans/auth-common — signBasicEd25519Request', () => {
|
|
102
|
+
const signedRequest = async (signedBody: object, sentBody: object = signedBody) => {
|
|
103
|
+
const fixture = makeTrustFixture({ withSecret: true, name: 'auth-common-tests' })
|
|
104
|
+
const guard = makeBasicEd25519Guard(TRUSTED_ALIAS)
|
|
105
|
+
fixture.ctx.registerService(guard)
|
|
106
|
+
const signed = await signBasicEd25519Request({
|
|
107
|
+
body: signedBody, credential: fixture.authRecord.id, key: fixture.authKey,
|
|
108
|
+
})
|
|
109
|
+
const req = {
|
|
110
|
+
alias: 'signed', body: sentBody, headers: { ...signed.headers, authorization: signed.authorization },
|
|
111
|
+
params: {}, query: {}, path: '/signed'
|
|
112
|
+
} satisfies AbstractRequest
|
|
113
|
+
|
|
114
|
+
return { fixture, guard, req, signed }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
test('a request it signs is accepted by the guard', async () => {
|
|
118
|
+
const { fixture, guard, req, signed } = await signedRequest({ challenge: 'c', pin: '123456' })
|
|
119
|
+
|
|
120
|
+
expect(signed.authorization).toStartWith(`${AuthroizationType.Ed25519BasicSignature.toUpperCase()} Credential=${fixture.authRecord.id} Signature=`)
|
|
121
|
+
expect(Object.keys(signed.headers)).toEqual([timeKey, nonceKey])
|
|
122
|
+
expect((await handle(guard, req))?.userId).toBe(fixture.authRecord.id)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('a tampered body is refused', async () => {
|
|
126
|
+
const { guard, req } = await signedRequest({ challenge: 'c', pin: '123456' }, { challenge: 'c', pin: '654321' })
|
|
127
|
+
const response: AbstractResponse<Auth> = { resolve: () => { throw new Error('resolved') }, reject: error => { throw error } }
|
|
128
|
+
|
|
129
|
+
expect(await guard.handle<boolean>(req, response)).toBe(false)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('the guard signs its own outgoing requests through it', async () => {
|
|
133
|
+
const fixture = makeTrustFixture({ withSecret: true, name: 'auth-common-tests' })
|
|
134
|
+
const guard = makeBasicEd25519Guard(TRUSTED_ALIAS)
|
|
135
|
+
fixture.ctx.registerService(guard)
|
|
136
|
+
const outgoing: Partial<AbstractRequest> = { body: { action: 'publish' } }
|
|
137
|
+
|
|
138
|
+
const authorization = await guard.authenticated(outgoing)
|
|
139
|
+
const req = {
|
|
140
|
+
alias: 'signed', body: outgoing.body, params: {}, query: {}, path: '/signed',
|
|
141
|
+
headers: { ...outgoing.headers, authorization: authorization ?? '' },
|
|
142
|
+
} satisfies AbstractRequest
|
|
143
|
+
|
|
144
|
+
expect(typeof outgoing.headers?.[timeKey]).toBe('string')
|
|
145
|
+
expect(typeof outgoing.headers?.[nonceKey]).toBe('string')
|
|
146
|
+
expect((await handle(guard, req))?.userId).toBe(fixture.authRecord.id)
|
|
147
|
+
})
|
|
148
|
+
})
|
package/build/modules.d.ts
DELETED
package/build/modules.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/build/modules.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
package/build/modules.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"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