safebyok 0.0.0-stage → 0.0.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.
- package/LICENSE +201 -0
- package/README.md +14 -2
- package/dist/device-db-D3SBnJdR.d.cts +326 -0
- package/dist/device-db-D3SBnJdR.d.ts +326 -0
- package/dist/idb.cjs +181 -0
- package/dist/idb.cjs.map +1 -0
- package/dist/idb.d.cts +72 -0
- package/dist/idb.d.ts +72 -0
- package/dist/idb.js +178 -0
- package/dist/idb.js.map +1 -0
- package/dist/index.cjs +541 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +237 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +520 -0
- package/dist/index.js.map +1 -0
- package/dist/vault-db-BJazN5Ht.js +500 -0
- package/dist/vault-db-BJazN5Ht.js.map +1 -0
- package/dist/vault-db-C19pMom1.cjs +697 -0
- package/dist/vault-db-C19pMom1.cjs.map +1 -0
- package/package.json +95 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# safebyok
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bring Your Own Key (BYOK) Browser Vault using E2EE (End-to-end Encryption) and pluggable remote storage
|
|
4
|
+
|
|
5
|
+
`safebyok` gives users a secure "Bring Your Own Key" vault. Secrets are available on their own device and nowhere else.
|
|
6
|
+
|
|
7
|
+
* Secrets are always stored in encrypted form, using keys that never leave the end-user's device
|
|
8
|
+
* Secrets synchronize across multiple devices using a passphrase the user controls
|
|
9
|
+
* The user may change their passphrase without re-entering their information
|
|
10
|
+
* Accessing a vault is prohibitively difficult -- even given the application's database, code and environment.
|
|
11
|
+
|
|
12
|
+
It is react-friendly (`safebyok-react`) and database agnostic: storage adapters implement a small
|
|
13
|
+
abstract seam, IndexedDB adapters ship in `safebyok/idb`, and a Convex adapter is planned.
|
|
14
|
+
`whiteboard/20261013-relic/proposed-README.md` drafts the full README for when the surface
|
|
15
|
+
settles.
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import * as Z from "zod";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The JSON a whisper is made of. `null` is legal here -- inside an array or object -- because
|
|
5
|
+
* real JSON payloads carry it; see {@link Whisper} for why a whisper can't be null as a whole.
|
|
6
|
+
*/
|
|
7
|
+
type WhisperJson = string | number | boolean | null | WhisperJson[] | {
|
|
8
|
+
[ckey: string]: WhisperJson;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The secret kept in a lockbox: a JSON value -- a string, number, boolean, array or plain object.
|
|
12
|
+
* Two shapes are refused rather than silently mangled:
|
|
13
|
+
* * `undefined`, anywhere in the value: JSON cannot carry it.
|
|
14
|
+
* * a bare `null` as the whole whisper: nobody's secret is "nothing here", and emptying a
|
|
15
|
+
* lockbox is `erase`'s job. (`null` inside a structure is fine: {@link WhisperJson}.)
|
|
16
|
+
*
|
|
17
|
+
* @example 'sk-ant-api03-...'
|
|
18
|
+
* @example { apiKey: 'sk-ant-...', orgId: null }
|
|
19
|
+
*/
|
|
20
|
+
type Whisper = Exclude<WhisperJson, null>;
|
|
21
|
+
/**
|
|
22
|
+
* Validator for a {@link Whisper}: accepts exactly what JSON can carry, refuses what JSON would
|
|
23
|
+
* mangle (undefined, functions, class instances such as Date or Map), and refuses a bare null.
|
|
24
|
+
*
|
|
25
|
+
* @example Whisper.parse('sk-ant-...') // a string passes through
|
|
26
|
+
* @example Whisper.safeParse(new Date()).success // false: JSON would flatten it to {}
|
|
27
|
+
* @example Whisper.safeParse(undefined).success // false: undefined cannot be stored
|
|
28
|
+
* @example Whisper.safeParse(null).success // false: emptying a lockbox is erase's job
|
|
29
|
+
* @example Whisper.safeParse({ orgId: null }).success // true: null inside a structure is JSON
|
|
30
|
+
*/
|
|
31
|
+
declare const Whisper: Z.ZodType<Whisper>;
|
|
32
|
+
/**
|
|
33
|
+
* A freely chosen identifier (STYLE.md tag glossary): lowercase words of letters and digits
|
|
34
|
+
* joined by single underscores, starting with a letter, two to forty characters. Shared by every
|
|
35
|
+
* label in the package: `applabel`, `vaultlabel`, `boxlabel`, `userlabel`.
|
|
36
|
+
*
|
|
37
|
+
* @example Label.parse('anthropic_api_key')
|
|
38
|
+
* @example Label.safeParse('ANTHROPIC_API_KEY').success // false: lowercase only
|
|
39
|
+
* @example Label.safeParse('_nope').success // false
|
|
40
|
+
*/
|
|
41
|
+
declare const Label: Z.ZodString;
|
|
42
|
+
/**
|
|
43
|
+
* What names one vault: the host application's label, the authenticated user, and the vault's own
|
|
44
|
+
* label. Two users may each have a vault labelled `main` without collision; so may two apps
|
|
45
|
+
* sharing a backend.
|
|
46
|
+
*/
|
|
47
|
+
declare const VaultScope: Z.ZodObject<{
|
|
48
|
+
applabel: Z.ZodString;
|
|
49
|
+
user_id: Z.ZodString;
|
|
50
|
+
vaultlabel: Z.ZodString;
|
|
51
|
+
}, Z.z.core.$strip>;
|
|
52
|
+
type VaultScope = Z.infer<typeof VaultScope>;
|
|
53
|
+
/**
|
|
54
|
+
* One lockbox as the storage layer holds it: the whisper ciphered under its own lockboxKey, that
|
|
55
|
+
* lockboxKey wrapped under the vaultKey, and the public shell -- boxlabel, note, timestamps --
|
|
56
|
+
* a locked vault may show. Nothing in this record opens without the vaultKey.
|
|
57
|
+
*
|
|
58
|
+
* `revision_id` is minted fresh on every write and bound into both encryptions, so ciphertext
|
|
59
|
+
* moved between revisions (or boxes, or vaults) refuses to open.
|
|
60
|
+
*
|
|
61
|
+
* Stored fields are underbar_case: this record is written to the storage layer as-is, and it is
|
|
62
|
+
* plain JSON -- any backend that can hold text can hold it.
|
|
63
|
+
*/
|
|
64
|
+
declare const Lockbox: Z.ZodObject<{
|
|
65
|
+
format: Z.ZodLiteral<"safebyok-lockbox-v1">;
|
|
66
|
+
boxlabel: Z.ZodString;
|
|
67
|
+
revision_id: Z.ZodString;
|
|
68
|
+
lockbox_key_wrapped: Z.ZodObject<{
|
|
69
|
+
cipher_iv_b64: Z.ZodString;
|
|
70
|
+
ciphertext_b64: Z.ZodString;
|
|
71
|
+
}, Z.z.core.$strip>;
|
|
72
|
+
whisper_ciphered: Z.ZodObject<{
|
|
73
|
+
cipher_iv_b64: Z.ZodString;
|
|
74
|
+
ciphertext_b64: Z.ZodString;
|
|
75
|
+
}, Z.z.core.$strip>;
|
|
76
|
+
note: Z.ZodOptional<Z.ZodString>;
|
|
77
|
+
created_at: Z.ZodString;
|
|
78
|
+
updated_at: Z.ZodString;
|
|
79
|
+
}, Z.z.core.$strip>;
|
|
80
|
+
type Lockbox = Z.infer<typeof Lockbox>;
|
|
81
|
+
/**
|
|
82
|
+
* The public face of a lockbox: everything but its two encrypted fields. This is what `list()`
|
|
83
|
+
* returns and what a locked vault may show.
|
|
84
|
+
*/
|
|
85
|
+
declare const LockboxSummary: Z.ZodObject<{
|
|
86
|
+
boxlabel: Z.ZodString;
|
|
87
|
+
revision_id: Z.ZodString;
|
|
88
|
+
note: Z.ZodOptional<Z.ZodString>;
|
|
89
|
+
created_at: Z.ZodString;
|
|
90
|
+
updated_at: Z.ZodString;
|
|
91
|
+
}, Z.z.core.$strip>;
|
|
92
|
+
type LockboxSummary = Z.infer<typeof LockboxSummary>;
|
|
93
|
+
/**
|
|
94
|
+
* The per-vault record the storage layer holds so any device can unlock the vault: the
|
|
95
|
+
* passphraseSalt, the keyDeriverLabel saying how the passphraseKey is made, and the vaultKey
|
|
96
|
+
* wrapped under that passphraseKey. All of it is safe in the open; none of it opens without
|
|
97
|
+
* the passphrase.
|
|
98
|
+
*
|
|
99
|
+
* `passphrase_epoch` goes up by one on every passphrase change, so other devices and remembered
|
|
100
|
+
* unlocks know to ask again.
|
|
101
|
+
*/
|
|
102
|
+
declare const VaultBundle: Z.ZodObject<{
|
|
103
|
+
format: Z.ZodLiteral<"safebyok-vault-v1">;
|
|
104
|
+
applabel: Z.ZodString;
|
|
105
|
+
user_id: Z.ZodString;
|
|
106
|
+
vaultlabel: Z.ZodString;
|
|
107
|
+
vault_id: Z.ZodString;
|
|
108
|
+
passphrase_epoch: Z.ZodNumber;
|
|
109
|
+
key_deriver_label: Z.ZodString;
|
|
110
|
+
passphrase_salt_b64: Z.ZodString;
|
|
111
|
+
vault_key_passphrase_wrapped: Z.ZodObject<{
|
|
112
|
+
cipher_iv_b64: Z.ZodString;
|
|
113
|
+
ciphertext_b64: Z.ZodString;
|
|
114
|
+
}, Z.z.core.$strip>;
|
|
115
|
+
created_at: Z.ZodString;
|
|
116
|
+
updated_at: Z.ZodString;
|
|
117
|
+
}, Z.z.core.$strip>;
|
|
118
|
+
type VaultBundle = Z.infer<typeof VaultBundle>;
|
|
119
|
+
/**
|
|
120
|
+
* The device-local record of a remembered unlock: this browser's localUnlockKey (a
|
|
121
|
+
* non-extractable handle -- it cannot leave the device even through the code that made it) and
|
|
122
|
+
* the vaultKey wrapped under it. Held only by structured-clone storage (IndexedDB) or memory;
|
|
123
|
+
* it has no JSON form, and nothing in it ever goes to the backend.
|
|
124
|
+
*/
|
|
125
|
+
declare const DeviceUnlock: Z.ZodObject<{
|
|
126
|
+
format: Z.ZodLiteral<"safebyok-unlock-v1">;
|
|
127
|
+
applabel: Z.ZodString;
|
|
128
|
+
user_id: Z.ZodString;
|
|
129
|
+
vaultlabel: Z.ZodString;
|
|
130
|
+
vault_id: Z.ZodString;
|
|
131
|
+
passphrase_epoch: Z.ZodNumber;
|
|
132
|
+
local_unlock_key: Z.ZodCustom<CryptoKey, CryptoKey>;
|
|
133
|
+
vault_key_local_wrapped: Z.ZodObject<{
|
|
134
|
+
cipher_iv_b64: Z.ZodString;
|
|
135
|
+
ciphertext_b64: Z.ZodString;
|
|
136
|
+
}, Z.z.core.$strip>;
|
|
137
|
+
expires_at: Z.ZodNumber;
|
|
138
|
+
}, Z.z.core.$strip>;
|
|
139
|
+
type DeviceUnlock = Z.infer<typeof DeviceUnlock>;
|
|
140
|
+
/** How long an entered passphrase is remembered on the device, unless the caller says otherwise. */
|
|
141
|
+
declare const SevenDaysMs: number;
|
|
142
|
+
/**
|
|
143
|
+
* The largest whisper a vault stores unless the caller says otherwise, in bytes of its JSON:
|
|
144
|
+
* several times the beefiest credential (an RSA-8192 private key as PEM is about 6.4 KB), and
|
|
145
|
+
* well inside what every storage backend can hold. A larger whisper is usually a sign that the
|
|
146
|
+
* wrong value is being stored.
|
|
147
|
+
*/
|
|
148
|
+
declare const MaxWhisperBytes = 40444;
|
|
149
|
+
/** Injected time source, so expiry is testable; defaults to the wall clock. */
|
|
150
|
+
type Clock = {
|
|
151
|
+
now(): number;
|
|
152
|
+
};
|
|
153
|
+
/** The wall clock: the default `Clock`. */
|
|
154
|
+
declare const wallClock: Clock;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/string-store.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* The smallest storage the stub adapters need: strings by string ckey, with change notification
|
|
159
|
+
* so the vault and the demo's inspector can watch it. The browser demo backs one with
|
|
160
|
+
* localStorage; the tests back one with a Map.
|
|
161
|
+
*/
|
|
162
|
+
type StringStore = {
|
|
163
|
+
/** The stored text under `ckey`, or null when there is none. */
|
|
164
|
+
read(ckey: string): string | null;
|
|
165
|
+
write(ckey: string, text: string): void;
|
|
166
|
+
erase(ckey: string): void;
|
|
167
|
+
/** Every ckey currently stored, in no particular order. */
|
|
168
|
+
ckeys(): string[];
|
|
169
|
+
/** Calls `listener` after any write or erase; returns the unsubscribe. */
|
|
170
|
+
subscribe(listener: () => void): () => void;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* In-memory StringStore over a Map: what the tests use, and a fallback anywhere localStorage
|
|
174
|
+
* is missing.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const store = memoryStore()
|
|
178
|
+
* store.write('greeting', 'hi'); store.read('greeting') // 'hi'
|
|
179
|
+
*/
|
|
180
|
+
declare const memoryStore: () => StringStore;
|
|
181
|
+
/**
|
|
182
|
+
* StringStore over a DOM Storage object (localStorage), confined to one prefix: each store sees
|
|
183
|
+
* only its own entries, so the demo can keep a pretend-remote database and a device cache in the
|
|
184
|
+
* same localStorage while showing them as the distinct places they stand in for.
|
|
185
|
+
*
|
|
186
|
+
* Change notification covers this tab's own writes (DOM `storage` events only fire in *other*
|
|
187
|
+
* tabs, which the demo does not chase).
|
|
188
|
+
*
|
|
189
|
+
* @param webStorage - The Storage to write through, usually `window.localStorage`.
|
|
190
|
+
* @param prefix - Namespace for this store's entries, e.g. 'safebyok-demo:db:'.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* const dbStore = domStore(localStorage, 'safebyok-demo:db:')
|
|
194
|
+
* dbStore.write('vault:acme:u1:main', text) // lands at 'safebyok-demo:db:vault:acme:u1:main'
|
|
195
|
+
*/
|
|
196
|
+
declare const domStore: (webStorage: Storage, prefix: string) => StringStore;
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/vault-db.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* Remote storage for vault records, as the host application plugs it in: extend this class and
|
|
201
|
+
* implement the seven `fetch`/`save`/`trash` primitives against your backend. That is the whole
|
|
202
|
+
* job -- you are a shelf, not a safe:
|
|
203
|
+
*
|
|
204
|
+
* * **Store what you are handed, return what you stored.** Every record is plain JSON (binary
|
|
205
|
+
* fields are base64url text), so any backend that can hold JSON can hold a vault, as-is.
|
|
206
|
+
* * **Never look inside.** Every secret field arrives encrypted; nothing you hold can open a
|
|
207
|
+
* vault, and nothing safebyok does ever needs you to understand a record.
|
|
208
|
+
* * **Enforce who may reach which rows.** Your backend should let a signed-in user reach only
|
|
209
|
+
* their own records: safebyok's encryption protects the contents, your authorization decides who
|
|
210
|
+
* may fetch or overwrite them at all.
|
|
211
|
+
* * **Don't repair.** Return a record exactly as stored, or null when there is none. safebyok
|
|
212
|
+
* validates everything it reads back; a damaged record is safebyok's to refuse, never yours to fix
|
|
213
|
+
* or quietly drop.
|
|
214
|
+
*
|
|
215
|
+
* The verbs the vault actually calls -- `readBundle`, `listBoxes`, `eraseVault` and the rest --
|
|
216
|
+
* are built for you on top of your primitives, validation included. Each compound verb documents
|
|
217
|
+
* the default composition; a backend that can do better (a transactional delete, a projected
|
|
218
|
+
* list, a push subscription) overrides that one method and leaves the rest.
|
|
219
|
+
*/
|
|
220
|
+
declare abstract class VaultDB {
|
|
221
|
+
/**
|
|
222
|
+
* The most this backend holds in one record, in bytes: a plain fact about the backend, or
|
|
223
|
+
* `Infinity` when it sets no per-record limit. A vault refuses to open with a `maxWhisperBytes`
|
|
224
|
+
* over half of it, leaving room for encoding and the record's other fields.
|
|
225
|
+
*/
|
|
226
|
+
abstract readonly maxRecordBytes: number;
|
|
227
|
+
/** The stored bundle record for `scope`, exactly as saved, or null when there is none. */
|
|
228
|
+
protected abstract fetchBundle(scope: VaultScope): Promise<unknown>;
|
|
229
|
+
/** Store `bundle`, replacing any bundle already under its scope. */
|
|
230
|
+
protected abstract saveBundle(bundle: VaultBundle): Promise<void>;
|
|
231
|
+
/** Remove the bundle record for `scope`; succeed quietly when there is none. */
|
|
232
|
+
protected abstract trashBundle(scope: VaultScope): Promise<void>;
|
|
233
|
+
/** The stored lockbox record under `boxlabel`, exactly as saved, or null when there is none. */
|
|
234
|
+
protected abstract fetchBox(scope: VaultScope, boxlabel: string): Promise<unknown>;
|
|
235
|
+
/** Store `lockbox`, replacing any lockbox already under its boxlabel. */
|
|
236
|
+
protected abstract saveBox(scope: VaultScope, lockbox: Lockbox): Promise<void>;
|
|
237
|
+
/** Remove the lockbox record under `boxlabel`; succeed quietly when there is none. */
|
|
238
|
+
protected abstract trashBox(scope: VaultScope, boxlabel: string): Promise<void>;
|
|
239
|
+
/** Every stored lockbox record in `scope`, in any order. */
|
|
240
|
+
protected abstract fetchBoxes(scope: VaultScope): Promise<unknown[]>;
|
|
241
|
+
/** The vault's bundle, validated, or null when the vault has never been created. */
|
|
242
|
+
readBundle(scope: VaultScope): Promise<VaultBundle | null>;
|
|
243
|
+
/** Store `bundle`, replacing whatever bundle its scope held. */
|
|
244
|
+
writeBundle(bundle: VaultBundle): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Store `bundle` only if its scope holds none, and return whichever bundle ends up there: the
|
|
247
|
+
* given one, or the one another device got in first with.
|
|
248
|
+
*
|
|
249
|
+
* Default composition: a fetch, then a save -- two devices creating at the same instant can
|
|
250
|
+
* still race between those steps. A backend with an atomic create should override this with
|
|
251
|
+
* one, and resolve the race for real.
|
|
252
|
+
*/
|
|
253
|
+
createBundle(bundle: VaultBundle): Promise<VaultBundle>;
|
|
254
|
+
/** One lockbox record, validated, or null when there is none under that label. */
|
|
255
|
+
readBox(scope: VaultScope, boxlabel: string): Promise<Lockbox | null>;
|
|
256
|
+
/** Store `lockbox`, replacing whatever its boxlabel held. */
|
|
257
|
+
writeBox(scope: VaultScope, lockbox: Lockbox): Promise<void>;
|
|
258
|
+
/** Remove the lockbox under `boxlabel`. */
|
|
259
|
+
eraseBox(scope: VaultScope, boxlabel: string): Promise<void>;
|
|
260
|
+
/**
|
|
261
|
+
* Public faces of every lockbox in the vault -- ciphered fields stripped, sorted by boxlabel --
|
|
262
|
+
* valid while locked.
|
|
263
|
+
*
|
|
264
|
+
* Default composition: fetch every full record and strip it here. A backend that can project
|
|
265
|
+
* away the ciphered fields server-side should override this and skip hauling them.
|
|
266
|
+
*/
|
|
267
|
+
listBoxes(scope: VaultScope): Promise<LockboxSummary[]>;
|
|
268
|
+
/**
|
|
269
|
+
* Remove the bundle and every lockbox: the backend's part of deleting a vault.
|
|
270
|
+
*
|
|
271
|
+
* Default composition: trash each lockbox, then the bundle -- an interruption can strand some
|
|
272
|
+
* rows, though never usable ones. A backend with a transaction or batch delete should override
|
|
273
|
+
* this with one.
|
|
274
|
+
*/
|
|
275
|
+
eraseVault(scope: VaultScope): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Calls `onChange` after any write touching `scope`, from this device or another; returns the
|
|
278
|
+
* unsubscribe. The default never calls: safebyok refreshes after its own writes regardless, so all
|
|
279
|
+
* a silent backend loses is news of *other* devices' writes. A backend with live queries or
|
|
280
|
+
* push (Convex, a websocket) should override this and ring the bell.
|
|
281
|
+
*/
|
|
282
|
+
subscribe(_scope: VaultScope, _onChange: () => void): () => void;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* VaultDB over a {@link StringStore}: rows as JSON text under scope-prefixed ckeys. The demo
|
|
286
|
+
* backs one with localStorage to stand in for a real backend; tests back one with a Map. Every
|
|
287
|
+
* secret field in what it stores is ciphertext, so the only thing pretend about it is reach --
|
|
288
|
+
* rows stay on this device instead of syncing through a shared database.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* const vaultDB = localVaultDB(memoryStore())
|
|
292
|
+
* await vaultDB.readBundle({ applabel: 'acme', user_id: 'u1', vaultlabel: 'main' }) // null
|
|
293
|
+
*/
|
|
294
|
+
declare const localVaultDB: (store: StringStore) => VaultDB;
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/device-db.d.ts
|
|
297
|
+
/**
|
|
298
|
+
* Device-local storage for remembered unlocks: what lets "enter your passphrase once, keep it for
|
|
299
|
+
* seven days" survive a page reload. A {@link DeviceUnlock} record holds this browser's
|
|
300
|
+
* localUnlockKey -- a non-extractable CryptoKey handle, which has no JSON form -- so an adapter
|
|
301
|
+
* must keep records by structured clone (IndexedDB: see `safebyok/idb`) or in memory; nothing here
|
|
302
|
+
* ever goes to the backend.
|
|
303
|
+
*
|
|
304
|
+
* An adapter may answer a damaged or unreadable record with null rather than an error: losing a
|
|
305
|
+
* remembered unlock only means asking for the passphrase again, and that is the safe failure.
|
|
306
|
+
*/
|
|
307
|
+
interface DeviceDB {
|
|
308
|
+
/** The remembered unlock for one vault, or null when there is none. Expiry is the vault's call. */
|
|
309
|
+
readUnlock(scope: VaultScope): Promise<DeviceUnlock | null>;
|
|
310
|
+
writeUnlock(unlock: DeviceUnlock): Promise<void>;
|
|
311
|
+
eraseUnlock(scope: VaultScope): Promise<void>;
|
|
312
|
+
/** Remove every remembered unlock on this device: the device's part of a full reset. */
|
|
313
|
+
eraseAll(): Promise<void>;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* DeviceDB over a Map: what the tests use, and the fallback anywhere without IndexedDB. Remembered
|
|
317
|
+
* unlocks last exactly as long as the page -- which is to say, it remembers nothing, safely.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* const deviceDB = memoryDeviceDB()
|
|
321
|
+
* await deviceDB.readUnlock({ applabel: 'acme', user_id: 'u1', vaultlabel: 'main' }) // null
|
|
322
|
+
*/
|
|
323
|
+
declare const memoryDeviceDB: () => DeviceDB;
|
|
324
|
+
//#endregion
|
|
325
|
+
export { Whisper as _, StringStore as a, Clock as c, Lockbox as d, LockboxSummary as f, VaultScope as g, VaultBundle as h, localVaultDB as i, DeviceUnlock as l, SevenDaysMs as m, memoryDeviceDB as n, domStore as o, MaxWhisperBytes as p, VaultDB as r, memoryStore as s, DeviceDB as t, Label as u, WhisperJson as v, wallClock as y };
|
|
326
|
+
//# sourceMappingURL=device-db-D3SBnJdR.d.cts.map
|