@owlmeans/basic-envelope 0.1.18-rc.4 → 0.1.18-rc.40

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 CHANGED
@@ -11,7 +11,7 @@ Type-safe message envelope with TTL, signing, and Base64 encoding for cross-serv
11
11
  ## Installation
12
12
 
13
13
  ```bash
14
- bun add @owlmeans/basic-envelope
14
+ bun add @owlmeans/basic-envelope@^0.1.18-rc.40
15
15
  ```
16
16
 
17
17
  ## Usage
@@ -80,7 +80,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
80
80
  your project's skill store (`.agents/skills/`):
81
81
 
82
82
  ```sh
83
- npx @owlmeans/agent-skills
83
+ npx @owlmeans/agent-skills@^0.1.18-rc.42
84
84
  ```
85
85
 
86
86
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/basic-envelope",
4
- "version": "0.1.18-rc.0",
5
- "generatedAt": "2026-08-16T22:20:50.517Z",
4
+ "version": "0.1.18-rc.40",
5
+ "generatedAt": "2026-09-29T08:01:58.144Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: basic-envelope
3
- description: How to use @owlmeans/basic-envelope — Envelope data model for wrapping payloads with metadata for cryptographic signing/verification. Auto-invoked when importing envelope types or wrapping messages for signing.
3
+ description: How to use @owlmeans/basic-envelope — makeEnvelopeModel for wrapping a payload with a type tag, timestamp and TTL, signing and verifying it with a basic-keys key pair, and serializing it as a wrap or a token. Auto-invoked when importing envelope types, or building a signed challenge or token payload.
4
4
  user-invocable: false
5
5
  ---
6
6
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
@@ -8,25 +8,78 @@ user-invocable: false
8
8
  # @owlmeans/basic-envelope
9
9
 
10
10
  **Layer:** Core
11
- **Install:** `"@owlmeans/basic-envelope": "^0.1.18-rc.0"` in `dependencies`
11
+ **Install:** `"@owlmeans/basic-envelope": "^0.1.18-rc.40"` in `dependencies`
12
+
13
+ An envelope is a signed, self-expiring container: a type tag, an encoded message, a timestamp and a
14
+ TTL, plus the signature over all of it. It is what carries auth challenges and tokens between
15
+ services, because a receiver can check the type, the age and the signature without knowing what the
16
+ message means.
12
17
 
13
18
  ## Key Exports
14
19
 
15
20
  | Export | Description |
16
21
  |--------|-------------|
17
- | `Envelope` types | Wrapped payload shape (header, payload, signature) |
18
- | `EnvelopeModel` | Helpers to build/parse envelopes |
19
- | Constants | Envelope kinds, header field names |
22
+ | `makeEnvelopeModel<T>(type, kind?)` | Build a new envelope, or parse an existing one |
23
+ | `EnvelopeModel<T>` | `envelope` / `send` / `message` / `type` / `wrap` / `tokenize` / `sign` / `verify` |
24
+ | `EnvelopeModel.envelope` | The `Envelope` itself — read `dt`/`ttl` from it, e.g. to size a cache entry |
25
+ | `Envelope` | The wire shape: `{ t, msg, sig?, dt, ttl }` |
26
+ | `EnvelopeKind` | `Wrap` (base64) and `Token` (base64url, no padding) |
27
+ | `DEFAULT_TTL` | 5 minutes, in milliseconds |
28
+
29
+ ## Creating, signing, sending
20
30
 
21
- ## Usage
31
+ Called with a type tag alone, `makeEnvelopeModel` starts a fresh envelope stamped with the current
32
+ time and `DEFAULT_TTL`. `send()` sets the payload — a string is stored as is, anything else is
33
+ JSON-encoded and base64'd — takes an optional TTL where `null` means never expires, and **returns
34
+ the model**, so the chained form is the idiomatic one.
22
35
 
23
36
  ```typescript
24
- import { Envelope, EnvelopeModel } from '@owlmeans/basic-envelope'
37
+ import { makeEnvelopeModel, EnvelopeKind } from '@owlmeans/basic-envelope'
38
+ import { RELY_3RD, type RelyToken } from '@owlmeans/auth'
39
+ import { fromPubKey, makeKeyPairModel } from '@owlmeans/basic-keys'
40
+
41
+ const key = makeKeyPairModel(privateKey)
42
+
43
+ // unsigned, serialized in one expression
44
+ const plain = makeEnvelopeModel<RelyToken>(RELY_3RD).send(rely).tokenize()
25
45
 
26
- const envelope = EnvelopeModel.wrap({ kind: 'auth-token', payload: { entityId: 'abc' } })
27
- // signature is added by basic-keys
46
+ // signed
47
+ const envelope = makeEnvelopeModel<RelyToken>(RELY_3RD)
48
+ envelope.send(rely)
49
+ const token = await envelope.sign(key, EnvelopeKind.Token)
28
50
  ```
29
51
 
52
+ `sign(key, kind?)` stores the signature on the envelope and returns it; pass `EnvelopeKind.Wrap` or
53
+ `EnvelopeKind.Token` to get the whole serialized envelope back instead. `wrap()` and `tokenize()`
54
+ serialize without signing — a token is URL-safe, a wrap is not.
55
+
56
+ The type tag and the payload type are the caller's — the example borrows `RELY_3RD` and `RelyToken`
57
+ from `@owlmeans/auth`, which this package does not depend on. Any string works as a tag.
58
+
59
+ The envelope itself is public as `model.envelope`, which is how a caller reaches `dt` and `ttl` —
60
+ a server that caches a received envelope for exactly as long as it is valid reads
61
+ `envelope.envelope.ttl` and derives the entry's lifetime from it.
62
+
63
+ ## Parsing and verifying
64
+
65
+ Pass the serialized string as the first argument together with the kind it was produced in:
66
+
67
+ ```typescript
68
+ const received = makeEnvelopeModel<RelyToken>(token, EnvelopeKind.Token)
69
+
70
+ if (received.type() !== RELY_3RD) { /* wrong kind of message */ }
71
+ if (!await received.verify(fromPubKey(publicKey))) { /* forged or expired */ }
72
+
73
+ const rely = received.message() // decoded payload
74
+ const raw = received.message(true) // the encoded string, untouched
75
+ ```
76
+
77
+ `verify` answers `false` — it does not throw — when the envelope carries no signature, when
78
+ `dt + ttl` is already in the past, or when the signature does not match. The signature covers the
79
+ envelope with `sig` removed, so re-serializing a verified envelope keeps it verifiable. `message()`
80
+ falls back to returning the raw string when the payload was not JSON.
81
+
30
82
  ## Depends On
31
83
 
32
- - None at runtime — pure model
84
+ - `@owlmeans/basic-keys` — the `KeyPairModel` that signs and verifies
85
+ - `@scure/base`, `@noble/curves`, `@noble/hashes` — encoding and the underlying primitives
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/basic-envelope",
3
- "version": "0.1.18-rc.4",
3
+ "version": "0.1.18-rc.40",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -9,9 +9,6 @@
9
9
  "watch": "tsc -b -w --preserveWatchOutput --pretty",
10
10
  "test": "bun test ./tests"
11
11
  },
12
- "bin": {
13
- "owlkeys": "./build/bin.js"
14
- },
15
12
  "main": "build/index.js",
16
13
  "module": "build/index.js",
17
14
  "types": "build/index.d.ts",
@@ -26,15 +23,15 @@
26
23
  },
27
24
  "devDependencies": {
28
25
  "@owlmeans/dep-config": "workspace:*",
29
- "@owlmeans/test-auth": "^0.1.18-rc.4",
30
- "@types/bun": "^1.3.14",
26
+ "@owlmeans/test-auth": "^0.1.18-rc.40",
27
+ "@types/bun": "^1.4.0",
31
28
  "nodemon": "^3.1.14",
32
29
  "typescript": "^7.0.2"
33
30
  },
34
31
  "dependencies": {
35
32
  "@noble/curves": "^1.6.0",
36
33
  "@noble/hashes": "^1.5.0",
37
- "@owlmeans/basic-keys": "^0.1.18-rc.4",
34
+ "@owlmeans/basic-keys": "^0.1.18-rc.42",
38
35
  "@scure/base": "^2.3.0"
39
36
  },
40
37
  "publishConfig": {
package/build/.gitkeep DELETED
File without changes