@yaks/secrets 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/_dist/graph.d.ts +9 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +67 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/op.d.ts +37 -0
- package/_dist/op.d.ts.map +1 -0
- package/_dist/plugin.d.ts +19 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/records.d.ts +11 -0
- package/_dist/records.d.ts.map +1 -0
- package/_dist/ref.d.ts +4 -0
- package/_dist/ref.d.ts.map +1 -0
- package/_dist/reveal.d.ts +14 -0
- package/_dist/reveal.d.ts.map +1 -0
- package/_dist/sealed.d.ts +10 -0
- package/_dist/sealed.d.ts.map +1 -0
- package/_dist/sentinel.d.ts +9 -0
- package/_dist/sentinel.d.ts.map +1 -0
- package/_dist/signed.d.ts +16 -0
- package/_dist/signed.d.ts.map +1 -0
- package/_dist/vault.d.ts +49 -0
- package/_dist/vault.d.ts.map +1 -0
- package/_dist/views.d.ts +3 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/deno.json +1 -0
- package/graph.js +12 -0
- package/graph.js.map +1 -0
- package/graph.ts +21 -0
- package/mod.js +67 -0
- package/mod.js.map +1 -0
- package/mod.ts +83 -0
- package/op.js +170 -0
- package/op.js.map +1 -0
- package/op.ts +188 -0
- package/package.json +51 -4
- package/plugin.js +429 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +464 -0
- package/reads.js +51 -0
- package/reads.js.map +1 -0
- package/reads.ts +56 -0
- package/records.js +45 -0
- package/records.js.map +1 -0
- package/records.ts +58 -0
- package/ref.js +7 -0
- package/ref.js.map +1 -0
- package/ref.ts +11 -0
- package/reveal.js +50 -0
- package/reveal.js.map +1 -0
- package/reveal.ts +98 -0
- package/sealed.js +35 -0
- package/sealed.js.map +1 -0
- package/sealed.ts +31 -0
- package/sentinel.js +66 -0
- package/sentinel.js.map +1 -0
- package/sentinel.ts +97 -0
- package/signed.js +107 -0
- package/signed.js.map +1 -0
- package/signed.ts +151 -0
- package/vault.js +67 -0
- package/vault.js.map +1 -0
- package/vault.ts +130 -0
- package/views.js +27 -0
- package/views.js.map +1 -0
- package/views.ts +34 -0
- package/vocab.js +16 -0
- package/vocab.js.map +1 -0
- package/vocab.json +36 -0
- package/vocab.ts +17 -0
- package/README.md +0 -3
package/signed.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// A value nobody but the holder of a secret can have written, exported as
|
|
2
|
+
// `@yaks/secrets/signed`: the bearer tokens a server mints and later trusts
|
|
3
|
+
// with no store and no round trip. A token is `<body>.<mac>`: the body is
|
|
4
|
+
// base64url JSON, the mac HMAC-SHA256 over the body text.
|
|
5
|
+
//
|
|
6
|
+
// Every token is signed for a label, and every open names the one label it
|
|
7
|
+
// accepts. Each label signs under its own key, the HMAC of the label under the
|
|
8
|
+
// secret, so one secret serves many kinds of token and a token signed for one
|
|
9
|
+
// label fails the mac as any other. What a token carries is the caller's to
|
|
10
|
+
// shape, and its expiry is the caller's to check.
|
|
11
|
+
//
|
|
12
|
+
// WebCrypto only, so the same file runs in a Worker, in Deno, and in a browser.
|
|
13
|
+
|
|
14
|
+
import { fromBase64url, toBase64url } from '@yaks/fp'
|
|
15
|
+
|
|
16
|
+
let enc = new TextEncoder()
|
|
17
|
+
let dec = new TextDecoder()
|
|
18
|
+
|
|
19
|
+
/** HMAC-SHA256, the one algorithm every key here is for. */
|
|
20
|
+
export let HMAC = { name: 'HMAC', hash: 'SHA-256' }
|
|
21
|
+
|
|
22
|
+
// Keys made once in an isolate and shared by signing and verification: a key
|
|
23
|
+
// is a WebCrypto call or three, and every request with a token needs one. The
|
|
24
|
+
// key is kept, not the promise of it, so no request waits on work another
|
|
25
|
+
// request started.
|
|
26
|
+
let keys = new Map<string, CryptoKey>()
|
|
27
|
+
|
|
28
|
+
let kept = async (id: string, make: () => Promise<CryptoKey>) => {
|
|
29
|
+
let got = keys.get(id)
|
|
30
|
+
if (!got) keys.set(id, got = await make())
|
|
31
|
+
return got
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The secret's own key, kept apart from every label's key made under it. */
|
|
35
|
+
export let secretKey = (secret: string): Promise<CryptoKey> =>
|
|
36
|
+
kept(
|
|
37
|
+
JSON.stringify([secret]),
|
|
38
|
+
() =>
|
|
39
|
+
crypto.subtle.importKey('raw', enc.encode(secret), HMAC, false, [
|
|
40
|
+
'sign',
|
|
41
|
+
'verify',
|
|
42
|
+
]),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
/** The label's own key: HMAC-SHA256 of the label under the secret. */
|
|
46
|
+
export let labelKey = (secret: string, label: string): Promise<CryptoKey> =>
|
|
47
|
+
kept(
|
|
48
|
+
JSON.stringify([label, secret]),
|
|
49
|
+
async () =>
|
|
50
|
+
crypto.subtle.importKey(
|
|
51
|
+
'raw',
|
|
52
|
+
await crypto.subtle.sign(
|
|
53
|
+
'HMAC',
|
|
54
|
+
await secretKey(secret),
|
|
55
|
+
enc.encode(label),
|
|
56
|
+
),
|
|
57
|
+
HMAC,
|
|
58
|
+
false,
|
|
59
|
+
['sign', 'verify'],
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
// Every token a key signed or verified, by its body. Signing is
|
|
64
|
+
// deterministic, so a body has one mac under a key: a repeat signs nothing,
|
|
65
|
+
// and an open of the exact token reuses the verification. Count and length
|
|
66
|
+
// bound the memory per key; the WeakMap lets it go with the key. Values and
|
|
67
|
+
// expiry decisions are never kept.
|
|
68
|
+
let known = new WeakMap<CryptoKey, Map<string, string>>()
|
|
69
|
+
let knownLimit = 256
|
|
70
|
+
let tokenLimit = 4096
|
|
71
|
+
|
|
72
|
+
let remember = (k: CryptoKey, body: string, token: string) => {
|
|
73
|
+
if (token.length > tokenLimit) return
|
|
74
|
+
let seen = known.get(k)
|
|
75
|
+
if (!seen) known.set(k, seen = new Map())
|
|
76
|
+
seen.delete(body)
|
|
77
|
+
seen.set(body, token)
|
|
78
|
+
if (seen.size > knownLimit) seen.delete(seen.keys().next().value!)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A token for `value` under a key from `labelKey` or `secretKey`. */
|
|
82
|
+
export let signedWith = async (
|
|
83
|
+
k: CryptoKey,
|
|
84
|
+
value: unknown,
|
|
85
|
+
): Promise<string> => {
|
|
86
|
+
let body = toBase64url(enc.encode(JSON.stringify(value)))
|
|
87
|
+
let token = known.get(k)?.get(body)
|
|
88
|
+
if (!token) {
|
|
89
|
+
let mac = await crypto.subtle.sign('HMAC', k, enc.encode(body))
|
|
90
|
+
token = `${body}.${toBase64url(new Uint8Array(mac))}`
|
|
91
|
+
}
|
|
92
|
+
remember(k, body, token)
|
|
93
|
+
return token
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The value under a mac this key made, written as signing writes it, or
|
|
97
|
+
* null. A miss uses WebCrypto's constant-time verify; a hit reuses its result
|
|
98
|
+
* and parses the value afresh. */
|
|
99
|
+
export let openedWith = async <T = unknown>(
|
|
100
|
+
k: CryptoKey,
|
|
101
|
+
token: string,
|
|
102
|
+
): Promise<T | null> => {
|
|
103
|
+
let dot = token.lastIndexOf('.')
|
|
104
|
+
if (dot < 0) return null
|
|
105
|
+
let body = token.slice(0, dot)
|
|
106
|
+
try {
|
|
107
|
+
if (known.get(k)?.get(body) != token) {
|
|
108
|
+
// The mac's text must be the one signing wrote. A 32-byte mac is 43
|
|
109
|
+
// characters whose last carries two padding bits the decoder ignores,
|
|
110
|
+
// and the decoder takes padding and spaces too, so several texts name
|
|
111
|
+
// the same bytes: without this, a token with its last character edited
|
|
112
|
+
// still opened.
|
|
113
|
+
let text = token.slice(dot + 1)
|
|
114
|
+
let mac = fromBase64url(text)
|
|
115
|
+
if (toBase64url(mac) != text) return null
|
|
116
|
+
let ok = await crypto.subtle.verify('HMAC', k, mac, enc.encode(body))
|
|
117
|
+
if (!ok) return null
|
|
118
|
+
}
|
|
119
|
+
remember(k, body, token)
|
|
120
|
+
return JSON.parse(dec.decode(fromBase64url(body)))
|
|
121
|
+
} catch {
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A token carrying `value`, signed for `label` under `secret`. */
|
|
127
|
+
export let signed = async (
|
|
128
|
+
label: string,
|
|
129
|
+
value: unknown,
|
|
130
|
+
secret: string,
|
|
131
|
+
): Promise<string> => signedWith(await labelKey(secret, label), value)
|
|
132
|
+
|
|
133
|
+
/** What a token carries, or null for anything but a well-formed token signed
|
|
134
|
+
* for this label under this secret. */
|
|
135
|
+
export let opened = async <T>(
|
|
136
|
+
label: string,
|
|
137
|
+
token: string,
|
|
138
|
+
secret: string,
|
|
139
|
+
): Promise<T | null> => openedWith<T>(await labelKey(secret, label), token)
|
|
140
|
+
|
|
141
|
+
/** What a token says it carries, read without the secret and so unverified:
|
|
142
|
+
* for a client to say whose token it holds and when it dies, never to trust. */
|
|
143
|
+
export let claimed = (token: string): unknown => {
|
|
144
|
+
let dot = token.lastIndexOf('.')
|
|
145
|
+
if (dot < 0) return null
|
|
146
|
+
try {
|
|
147
|
+
return JSON.parse(dec.decode(fromBase64url(token.slice(0, dot))))
|
|
148
|
+
} catch {
|
|
149
|
+
return null
|
|
150
|
+
}
|
|
151
|
+
}
|
package/vault.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Where a secret's value is kept: a vault. The graph holds the name and the
|
|
2
|
+
// handle; the vault holds what the handle stands for, keyed by the secret's
|
|
3
|
+
// entity id, and the salt a handle is hashed under to make its sentinel.
|
|
4
|
+
//
|
|
5
|
+
// A vault is the one thing that differs between the places a graph runs, so
|
|
6
|
+
// this package keeps none but memory (below), for a test or a graph that lasts
|
|
7
|
+
// as long as its process. A vault that stores somewhere lives with that
|
|
8
|
+
// storage and meets this shape: a directory of private files on a box
|
|
9
|
+
// (@yaks/cli), a D1 database on yaks.app (@yaks/d1). The plugin, the reveal and
|
|
10
|
+
// the records store are written against this type alone, and every method may
|
|
11
|
+
// answer now or later, so a vault that has to ask a network is as good as one
|
|
12
|
+
// that reads a file.
|
|
13
|
+
import { locks } from "@yaks/fp";
|
|
14
|
+
/** One lock per key, within this process: each caller waits for the one
|
|
15
|
+
* before it (@yaks/fp `locks`). */ export let queue = ()=>locks();
|
|
16
|
+
/** A vault in memory: its secrets last as long as the process, which is right
|
|
17
|
+
* for a graph that does too, and for a test. */ export let ramVault = ()=>{
|
|
18
|
+
let kept = new Map();
|
|
19
|
+
let trash = new Map();
|
|
20
|
+
let archive = (eid)=>{
|
|
21
|
+
let sealed = kept.get(eid);
|
|
22
|
+
if (sealed) trash.set(crypto.randomUUID(), {
|
|
23
|
+
eid,
|
|
24
|
+
sealed,
|
|
25
|
+
at: Date.now()
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
let seal = (eid, sealed)=>{
|
|
29
|
+
if (JSON.stringify(kept.get(eid)) != JSON.stringify(sealed)) archive(eid);
|
|
30
|
+
kept.set(eid, sealed);
|
|
31
|
+
};
|
|
32
|
+
let salt = crypto.getRandomValues(new Uint8Array(32));
|
|
33
|
+
return {
|
|
34
|
+
salt: ()=>salt,
|
|
35
|
+
read: (eid)=>kept.get(eid),
|
|
36
|
+
seal,
|
|
37
|
+
drop: (eid)=>{
|
|
38
|
+
archive(eid);
|
|
39
|
+
kept.delete(eid);
|
|
40
|
+
},
|
|
41
|
+
trash: ()=>[
|
|
42
|
+
...trash
|
|
43
|
+
].reverse().map(([id, { eid, sealed, at }])=>({
|
|
44
|
+
id,
|
|
45
|
+
eid,
|
|
46
|
+
handle: sealed.handle,
|
|
47
|
+
...sealed.name ? {
|
|
48
|
+
name: sealed.name
|
|
49
|
+
} : {},
|
|
50
|
+
at
|
|
51
|
+
})),
|
|
52
|
+
past: (id)=>trash.get(id)?.sealed,
|
|
53
|
+
restore: (id)=>{
|
|
54
|
+
let found = trash.get(id);
|
|
55
|
+
if (!found) return false;
|
|
56
|
+
seal(found.eid, found.sealed);
|
|
57
|
+
trash.delete(id);
|
|
58
|
+
return true;
|
|
59
|
+
},
|
|
60
|
+
purge: (id)=>void trash.delete(id),
|
|
61
|
+
all: ()=>[
|
|
62
|
+
...kept
|
|
63
|
+
],
|
|
64
|
+
lock: queue()
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=vault.js.map
|
package/vault.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.js","sources":["./vault.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,wEAAwE;AACxE,sEAAsE;AACtE,gFAAgF;AAChF,8EAA8E;AAC9E,8EAA8E;AAC9E,qBAAqB;AAGrB,SAAS,KAAK,wBAA6B;AAqE3C;iCACiC,GACjC,OAAO,IAAI,QAAQ,IAAqB,QAAO;AAE/C;8CAC8C,GAC9C,OAAO,IAAI,WAAW;EACpB,IAAI,OAAO,IAAI;EACf,IAAI,QAAQ,IAAI;EAChB,IAAI,UAAU,CAAC;IACb,IAAI,SAAS,KAAK,GAAG,CAAC;IACtB,IAAI,QAAQ,MAAM,GAAG,CAAC,OAAO,UAAU,IAAI;MAAE;MAAK;MAAQ,IAAI,KAAK,GAAG;IAAG;EAC3E;EACA,IAAI,OAAO,CAAC,KAAU;IACpB,IAAI,KAAK,SAAS,CAAC,KAAK,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,QAAQ;IACrE,KAAK,GAAG,CAAC,KAAK;EAChB;EACA,IAAI,OAAO,OAAO,eAAe,CAAC,IAAI,WAAW;EACjD,OAAO;IACL,MAAM,IAAM;IACZ,MAAM,CAAC,MAAQ,KAAK,GAAG,CAAC;IACxB;IACA,MAAM,CAAC;MACL,QAAQ;MACR,KAAK,MAAM,CAAC;IACd;IACA,OAAO,IACL;WAAI;OAAM,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAK,CAAC;UACvD;UACA;UACA,QAAQ,OAAO,MAAM;UACrB,GAAG,OAAO,IAAI,GAAG;YAAE,MAAM,OAAO,IAAI;UAAC,IAAI,CAAC,CAAC;UAC3C;QACF,CAAC;IACH,MAAM,CAAC,KAAO,MAAM,GAAG,CAAC,KAAK;IAC7B,SAAS,CAAC;MACR,IAAI,QAAQ,MAAM,GAAG,CAAC;MACtB,IAAI,CAAC,OAAO,OAAO;MACnB,KAAK,MAAM,GAAG,EAAE,MAAM,MAAM;MAC5B,MAAM,MAAM,CAAC;MACb,OAAO;IACT;IACA,OAAO,CAAC,KAAO,KAAK,MAAM,MAAM,CAAC;IACjC,KAAK,IAAM;WAAI;OAAK;IACpB,MAAM;EACR;AACF,EAAC"}
|
package/vault.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Where a secret's value is kept: a vault. The graph holds the name and the
|
|
2
|
+
// handle; the vault holds what the handle stands for, keyed by the secret's
|
|
3
|
+
// entity id, and the salt a handle is hashed under to make its sentinel.
|
|
4
|
+
//
|
|
5
|
+
// A vault is the one thing that differs between the places a graph runs, so
|
|
6
|
+
// this package keeps none but memory (below), for a test or a graph that lasts
|
|
7
|
+
// as long as its process. A vault that stores somewhere lives with that
|
|
8
|
+
// storage and meets this shape: a directory of private files on a box
|
|
9
|
+
// (@yaks/cli), a D1 database on yaks.app (@yaks/d1). The plugin, the reveal and
|
|
10
|
+
// the records store are written against this type alone, and every method may
|
|
11
|
+
// answer now or later, so a vault that has to ask a network is as good as one
|
|
12
|
+
// that reads a file.
|
|
13
|
+
|
|
14
|
+
import type { Eid } from 'jsr:@yaks/graph@0.2.36'
|
|
15
|
+
import { locks } from '@yaks/fp'
|
|
16
|
+
|
|
17
|
+
/** What a vault keeps for one secret: the handle the graph holds for it and
|
|
18
|
+
* the value. References are kept separately so they cannot be sent as values. */
|
|
19
|
+
export type Sealed = {
|
|
20
|
+
/** the secret's name, where the write carried it */
|
|
21
|
+
name?: string
|
|
22
|
+
handle: string
|
|
23
|
+
value?: string
|
|
24
|
+
/** An unresolved 1Password reference; runtime readers return no value. */
|
|
25
|
+
op?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Metadata for a retained version; values stay inside the vault. */
|
|
29
|
+
export type Trashed = {
|
|
30
|
+
id: string
|
|
31
|
+
eid: Eid
|
|
32
|
+
handle: string
|
|
33
|
+
name?: string
|
|
34
|
+
at: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Maybe<T> = T | Promise<T>
|
|
38
|
+
|
|
39
|
+
/** A place to keep secrets. A failure trying again may cure throws an error
|
|
40
|
+
* carrying `retryable: true`, and is tried again (./plugin.ts `sealing`); any
|
|
41
|
+
* other is a defect. */
|
|
42
|
+
export type Vault = {
|
|
43
|
+
/** the key every sentinel this vault hands out is hashed under
|
|
44
|
+
* (./sentinel.ts) */
|
|
45
|
+
salt: () => Maybe<Uint8Array>
|
|
46
|
+
read: (eid: Eid) => Maybe<Sealed | undefined>
|
|
47
|
+
/** Read selected secrets together when the storage can share a round trip.
|
|
48
|
+
* An unreadable value can fail independently of the other rows. */
|
|
49
|
+
readMany?: (
|
|
50
|
+
eids: readonly Eid[],
|
|
51
|
+
) => Maybe<Map<Eid, PromiseSettledResult<Sealed>>>
|
|
52
|
+
seal: (eid: Eid, sealed: Sealed) => Maybe<void>
|
|
53
|
+
/** Retain the current value in trash, then remove it from active reads. */
|
|
54
|
+
drop: (eid: Eid) => Maybe<void>
|
|
55
|
+
/** Retained versions, newest first, with no credential values. */
|
|
56
|
+
trash: () => Maybe<Trashed[]>
|
|
57
|
+
/** Read a retained version privately, without changing active values or trash. */
|
|
58
|
+
past: (id: string) => Maybe<Sealed | undefined>
|
|
59
|
+
/** Restore a retained version, preserving any displaced active value. */
|
|
60
|
+
restore: (id: string) => Maybe<boolean>
|
|
61
|
+
/** Permanently remove one retained version after a person's choice. */
|
|
62
|
+
purge: (id: string) => Maybe<void>
|
|
63
|
+
/** every secret it keeps, by entity id */
|
|
64
|
+
all: () => Maybe<[Eid, Sealed][]>
|
|
65
|
+
/** run `fn` with this secret held against every other writer — the other
|
|
66
|
+
* callers in this process, and on a box the other processes too — so a
|
|
67
|
+
* read, a change and the write back are one step */
|
|
68
|
+
lock: <T>(eid: Eid, fn: () => Promise<T>) => Promise<T>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A vault that answers at once: what a config read on the spot needs
|
|
72
|
+
* (./reveal.ts `peek`). A box's files and memory are both this. */
|
|
73
|
+
export type Local =
|
|
74
|
+
& Omit<Vault, 'read' | 'all' | 'trash' | 'past' | 'restore' | 'purge'>
|
|
75
|
+
& {
|
|
76
|
+
read: (eid: Eid) => Sealed | undefined
|
|
77
|
+
all: () => [Eid, Sealed][]
|
|
78
|
+
trash: () => Trashed[]
|
|
79
|
+
past: (id: string) => Sealed | undefined
|
|
80
|
+
restore: (id: string) => boolean
|
|
81
|
+
purge: (id: string) => void
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** One lock per key, within this process: each caller waits for the one
|
|
85
|
+
* before it (@yaks/fp `locks`). */
|
|
86
|
+
export let queue = (): Vault['lock'] => locks()
|
|
87
|
+
|
|
88
|
+
/** A vault in memory: its secrets last as long as the process, which is right
|
|
89
|
+
* for a graph that does too, and for a test. */
|
|
90
|
+
export let ramVault = (): Local => {
|
|
91
|
+
let kept = new Map<Eid, Sealed>()
|
|
92
|
+
let trash = new Map<string, { eid: Eid; sealed: Sealed; at: number }>()
|
|
93
|
+
let archive = (eid: Eid) => {
|
|
94
|
+
let sealed = kept.get(eid)
|
|
95
|
+
if (sealed) trash.set(crypto.randomUUID(), { eid, sealed, at: Date.now() })
|
|
96
|
+
}
|
|
97
|
+
let seal = (eid: Eid, sealed: Sealed) => {
|
|
98
|
+
if (JSON.stringify(kept.get(eid)) != JSON.stringify(sealed)) archive(eid)
|
|
99
|
+
kept.set(eid, sealed)
|
|
100
|
+
}
|
|
101
|
+
let salt = crypto.getRandomValues(new Uint8Array(32))
|
|
102
|
+
return {
|
|
103
|
+
salt: () => salt,
|
|
104
|
+
read: (eid) => kept.get(eid),
|
|
105
|
+
seal,
|
|
106
|
+
drop: (eid) => {
|
|
107
|
+
archive(eid)
|
|
108
|
+
kept.delete(eid)
|
|
109
|
+
},
|
|
110
|
+
trash: () =>
|
|
111
|
+
[...trash].reverse().map(([id, { eid, sealed, at }]) => ({
|
|
112
|
+
id,
|
|
113
|
+
eid,
|
|
114
|
+
handle: sealed.handle,
|
|
115
|
+
...sealed.name ? { name: sealed.name } : {},
|
|
116
|
+
at,
|
|
117
|
+
})),
|
|
118
|
+
past: (id) => trash.get(id)?.sealed,
|
|
119
|
+
restore: (id) => {
|
|
120
|
+
let found = trash.get(id)
|
|
121
|
+
if (!found) return false
|
|
122
|
+
seal(found.eid, found.sealed)
|
|
123
|
+
trash.delete(id)
|
|
124
|
+
return true
|
|
125
|
+
},
|
|
126
|
+
purge: (id) => void trash.delete(id),
|
|
127
|
+
all: () => [...kept],
|
|
128
|
+
lock: queue(),
|
|
129
|
+
}
|
|
130
|
+
}
|
package/views.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// A secret's public face is its config key and optional human title, never
|
|
2
|
+
// its value (not even the vault handle). Shared by browser and terminal lists.
|
|
3
|
+
import { parse } from "@yaks/query/core";
|
|
4
|
+
import { define } from "@yaks/render";
|
|
5
|
+
export let views = define([
|
|
6
|
+
{
|
|
7
|
+
view: 'Title',
|
|
8
|
+
match: parse('.secret'),
|
|
9
|
+
render: (b, h)=>h('span', null, b.secret.name ?? '')
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
view: 'Title',
|
|
13
|
+
match: parse('.secret .doc.title'),
|
|
14
|
+
render: (b, h)=>h('span', null, b.doc.title, ' · ', b.secret.name ?? '')
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
view: 'Tile',
|
|
18
|
+
match: parse('.secret'),
|
|
19
|
+
render: (b, h, ctx)=>h('a', {
|
|
20
|
+
class: 'Tile',
|
|
21
|
+
href: `/${b.entity.eid}`
|
|
22
|
+
}, h('span', {
|
|
23
|
+
class: 'Tile_Title'
|
|
24
|
+
}, ctx.render?.('Title')))
|
|
25
|
+
}
|
|
26
|
+
]);
|
|
27
|
+
//# sourceMappingURL=views.js.map
|
package/views.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.js","sources":["./views.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,+EAA+E;AAC/E,SAAS,KAAK,gCAAqC;AACnD,SAAS,MAAM,4BAAgD;AAE/D,OAAO,IAAI,QAAkB,OAAO;EAClC;IACE,MAAM;IACN,OAAO,MAAM;IACb,QAAQ,CAAC,GAAG,IACV,EAAE,QAAQ,MAAM,AAAC,EAAE,MAAM,CAAuB,IAAI,IAAI;EAC5D;EACA;IACE,MAAM;IACN,OAAO,MAAM;IACb,QAAQ,CAAC,GAAG,IACV,EACE,QACA,MACA,AAAC,EAAE,GAAG,CAAwB,KAAK,EACnC,OACA,AAAC,EAAE,MAAM,CAAuB,IAAI,IAAI;EAE9C;EACA;IACE,MAAM;IACN,OAAO,MAAM;IACb,QAAQ,CAAC,GAAG,GAAG,MACb,EAAE,KAAK;QACL,OAAO;QACP,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE;MAC1B,GAAG,EAAE,QAAQ;QAAE,OAAO;MAAa,GAAG,IAAI,MAAM,GAAG;EACvD;CACD,EAAC"}
|
package/views.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// A secret's public face is its config key and optional human title, never
|
|
2
|
+
// its value (not even the vault handle). Shared by browser and terminal lists.
|
|
3
|
+
import { parse } from '@yaks/query/core'
|
|
4
|
+
import { define, type Registry } from '@yaks/render'
|
|
5
|
+
|
|
6
|
+
export let views: Registry = define([
|
|
7
|
+
{
|
|
8
|
+
view: 'Title',
|
|
9
|
+
match: parse('.secret'),
|
|
10
|
+
render: (b, h) =>
|
|
11
|
+
h('span', null, (b.secret as { name?: string }).name ?? ''),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
view: 'Title',
|
|
15
|
+
match: parse('.secret .doc.title'),
|
|
16
|
+
render: (b, h) =>
|
|
17
|
+
h(
|
|
18
|
+
'span',
|
|
19
|
+
null,
|
|
20
|
+
(b.doc as { title?: string }).title,
|
|
21
|
+
' · ',
|
|
22
|
+
(b.secret as { name?: string }).name ?? '',
|
|
23
|
+
),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
view: 'Tile',
|
|
27
|
+
match: parse('.secret'),
|
|
28
|
+
render: (b, h, ctx) =>
|
|
29
|
+
h('a', {
|
|
30
|
+
class: 'Tile',
|
|
31
|
+
href: `/${b.entity.eid}`,
|
|
32
|
+
}, h('span', { class: 'Tile_Title' }, ctx.render?.('Title'))),
|
|
33
|
+
},
|
|
34
|
+
])
|
package/vocab.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The component definition and nothing else, exported as
|
|
2
|
+
// `@yaks/secrets/vocab`. It imports no storage and no runtime, so a browser tab
|
|
3
|
+
// that loads this vocabulary loads nothing else with it.
|
|
4
|
+
import doc from './vocab.json' with {
|
|
5
|
+
type: 'json'
|
|
6
|
+
};
|
|
7
|
+
import manifest from './package.json' with {
|
|
8
|
+
type: 'json'
|
|
9
|
+
};
|
|
10
|
+
/** The `secret` component. */ export let secretsDoc = doc;
|
|
11
|
+
/** What this package is: its manifest's description, the one place it is
|
|
12
|
+
* written, which a host stamps on each document here. */ export let description = manifest.description;
|
|
13
|
+
/** Every vocabulary document this plugin contributes. */ export let docs = [
|
|
14
|
+
secretsDoc
|
|
15
|
+
];
|
|
16
|
+
//# sourceMappingURL=vocab.js.map
|
package/vocab.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.js","sources":["./vocab.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,gFAAgF;AAChF,yDAAyD;AAGzD,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACpD,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE3D,4BAA4B,GAC5B,OAAO,IAAI,aAAuB,IAAG;AAErC;uDACuD,GACvD,OAAO,IAAI,cAAsB,SAAS,WAAW,CAAA;AAErD,uDAAuD,GACvD,OAAO,IAAI,OAAmB;EAAC;CAAW,CAAA"}
|
package/vocab.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "urn:uuid:03965b9a-d926-4f31-ad5a-beea92ad8de5",
|
|
3
|
+
"$vocabulary": {
|
|
4
|
+
"https://yak.sh/vocab/core": true,
|
|
5
|
+
"https://yak.sh/vocab/id": true
|
|
6
|
+
},
|
|
7
|
+
"title": "secrets",
|
|
8
|
+
"$defs": {
|
|
9
|
+
"secret": {
|
|
10
|
+
"$id": "urn:uuid:f9147070-0515-470a-b6f8-3f7e8762d1bf",
|
|
11
|
+
"component": true,
|
|
12
|
+
"type": "object",
|
|
13
|
+
"description": "a secret the graph names and never holds: written with its value, kept somewhere else, and read back only as [set]",
|
|
14
|
+
"properties": {
|
|
15
|
+
"name": {
|
|
16
|
+
"$id": "urn:uuid:3a403388-7314-4e78-9ce9-f7fb15d4c49a",
|
|
17
|
+
"type": "string",
|
|
18
|
+
"identity": true,
|
|
19
|
+
"description": "what a config or a program asks for it by; the entity id is derived from it, so one name is one secret"
|
|
20
|
+
},
|
|
21
|
+
"value": {
|
|
22
|
+
"$id": "urn:uuid:e41faffa-f35d-464a-8995-f85231f66fe5",
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "written: the value itself; an op:// reference is kept unresolved and supplies no runtime credential. Stored: a random handle retained across rotations. Public graph reads return [set]; trusted native storage reads retain the handle"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"kinds": {
|
|
30
|
+
"secret": {
|
|
31
|
+
"$id": "urn:uuid:f9147070-0515-470a-b6f8-3f7e8762d1bf",
|
|
32
|
+
"description": "a secret the graph names and never holds: written with its value, kept somewhere else, and read back only as [set]",
|
|
33
|
+
"prefix": "X"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/vocab.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The component definition and nothing else, exported as
|
|
2
|
+
// `@yaks/secrets/vocab`. It imports no storage and no runtime, so a browser tab
|
|
3
|
+
// that loads this vocabulary loads nothing else with it.
|
|
4
|
+
|
|
5
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
6
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
7
|
+
import manifest from './package.json' with { type: 'json' }
|
|
8
|
+
|
|
9
|
+
/** The `secret` component. */
|
|
10
|
+
export let secretsDoc: VocabDoc = doc
|
|
11
|
+
|
|
12
|
+
/** What this package is: its manifest's description, the one place it is
|
|
13
|
+
* written, which a host stamps on each document here. */
|
|
14
|
+
export let description: string = manifest.description
|
|
15
|
+
|
|
16
|
+
/** Every vocabulary document this plugin contributes. */
|
|
17
|
+
export let docs: VocabDoc[] = [secretsDoc]
|
package/README.md
DELETED