@oxy.so/contracts 6.19.0 → 6.20.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/dist/cjs/client/identityProof.js +6 -0
- package/dist/cjs/client/index.js +23 -1
- package/dist/cjs/client/keychain.js +203 -0
- package/dist/cjs/client/signIn.js +2 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/keychain.js +334 -0
- package/dist/esm/client/identityProof.js +6 -0
- package/dist/esm/client/index.js +1 -0
- package/dist/esm/client/keychain.js +200 -0
- package/dist/esm/client/signIn.js +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/keychain.js +317 -0
- package/dist/types/client/identityProof.d.ts +6 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/keychain.d.ts +272 -0
- package/dist/types/client/signIn.d.ts +1 -1
- package/dist/types/identityProof.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/keychain.d.ts +307 -0
- package/dist/types/signIn.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Oxy Keychain's wire contract, without Zod (ADR 0063,
|
|
3
|
+
* `docs/identity/keychain.md`). Schemas: `../keychain.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Oxy stores only ciphertext, public keys, signatures and counters. Every
|
|
6
|
+
* binary value is base64url WITHOUT padding, in its one canonical spelling
|
|
7
|
+
* (the unused low bits of the last character are zero), so no two strings name
|
|
8
|
+
* the same bytes.
|
|
9
|
+
*
|
|
10
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
11
|
+
*/
|
|
12
|
+
import { array, boolean, exact, int, nonnegative, nullable, number, object, oneOf, positive, string, } from './check.js';
|
|
13
|
+
/* -------------------------------------------------------------------------- */
|
|
14
|
+
/* Closed sets and constants */
|
|
15
|
+
/* -------------------------------------------------------------------------- */
|
|
16
|
+
/** The platforms a member may name: a closed set, for display only (ADR 0063 D3). */
|
|
17
|
+
export const KEYCHAIN_PLATFORMS = [
|
|
18
|
+
'oxyos',
|
|
19
|
+
'ios',
|
|
20
|
+
'android',
|
|
21
|
+
'macos',
|
|
22
|
+
'windows',
|
|
23
|
+
'linux',
|
|
24
|
+
'web',
|
|
25
|
+
];
|
|
26
|
+
/** The roster's operations (ADR 0063 D3). */
|
|
27
|
+
export const KEYCHAIN_ROSTER_OPS = ['genesis', 'add', 'remove', 'generation', 'recovery'];
|
|
28
|
+
/** An enrollment's states. An expired pending one is answered `410`, never served as pending. */
|
|
29
|
+
export const KEYCHAIN_ENROLLMENT_STATUSES = ['pending', 'approved', 'denied'];
|
|
30
|
+
/**
|
|
31
|
+
* The recipient of the recovery wrap, and the signer named by a signature made
|
|
32
|
+
* with the recovery signing key.
|
|
33
|
+
*/
|
|
34
|
+
export const KEYCHAIN_RECOVERY = 'recovery';
|
|
35
|
+
/**
|
|
36
|
+
* Every domain string (ADR 0063 D8). Each signing input, AAD and derivation
|
|
37
|
+
* starts with one, so nothing signed or sealed as one kind can be replayed as
|
|
38
|
+
* another.
|
|
39
|
+
*/
|
|
40
|
+
export const KEYCHAIN_DOMAINS = {
|
|
41
|
+
roster: 'oxy.keychain.roster.v1',
|
|
42
|
+
wrap: 'oxy.keychain.wrap.v1',
|
|
43
|
+
item: 'oxy.keychain.item.v1',
|
|
44
|
+
seal: 'oxy.keychain.seal.v1',
|
|
45
|
+
enrollCommit: 'oxy.keychain.enroll.commit.v1',
|
|
46
|
+
enrollCode: 'oxy.keychain.enroll.code.v1',
|
|
47
|
+
recovery: 'oxy.keychain.recovery.v1',
|
|
48
|
+
};
|
|
49
|
+
/** The server's limits (`docs/identity/keychain.md`). */
|
|
50
|
+
export const KEYCHAIN_LIMITS = {
|
|
51
|
+
/** Live (non-deleted) items in one vault. */
|
|
52
|
+
maxLiveItems: 10000,
|
|
53
|
+
/** An item's or a wrap's ciphertext, in base64url characters (64 KiB). */
|
|
54
|
+
maxCiphertextLength: 65536,
|
|
55
|
+
/** Entries in one roster, genesis included. */
|
|
56
|
+
maxRosterEntries: 1000,
|
|
57
|
+
/** Members not removed. */
|
|
58
|
+
maxLiveMembers: 32,
|
|
59
|
+
/** Unexpired pending enrollments per vault. */
|
|
60
|
+
maxPendingEnrollments: 4,
|
|
61
|
+
/** How long an enrollment waits for its approval. */
|
|
62
|
+
enrollmentTtlMs: 10 * 60 * 1000,
|
|
63
|
+
/** Items in one `GET /keychain/items` page. */
|
|
64
|
+
maxItemsPage: 500,
|
|
65
|
+
/** Entries in one roster append. */
|
|
66
|
+
maxEntriesPerAppend: 64,
|
|
67
|
+
/** One roster entry's `body`, in characters. */
|
|
68
|
+
maxEntryBodyLength: 4096,
|
|
69
|
+
/** A member's display name, in bytes of UTF-8 (at least 1; any characters). */
|
|
70
|
+
maxMemberNameBytes: 256,
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Stable error codes the `/keychain` routes answer with (`error` in the API's
|
|
74
|
+
* error body). Clients map these through their localization, never the English
|
|
75
|
+
* message.
|
|
76
|
+
*/
|
|
77
|
+
export const KEYCHAIN_ERROR_CODES = {
|
|
78
|
+
/** Not a personal account acting as itself. */
|
|
79
|
+
notAvailable: 'KEYCHAIN_NOT_AVAILABLE',
|
|
80
|
+
/** The bearer carries no device session, which a member is bound to. */
|
|
81
|
+
deviceRequired: 'KEYCHAIN_DEVICE_REQUIRED',
|
|
82
|
+
/** `POST /keychain`: the account already has a vault. */
|
|
83
|
+
exists: 'KEYCHAIN_EXISTS',
|
|
84
|
+
/** The account has no vault. */
|
|
85
|
+
notFound: 'KEYCHAIN_NOT_FOUND',
|
|
86
|
+
/** The caller's device session is bound to no live member of the vault. */
|
|
87
|
+
notMember: 'KEYCHAIN_NOT_MEMBER',
|
|
88
|
+
/** The caller's device session is already bound to a live member. */
|
|
89
|
+
alreadyMember: 'KEYCHAIN_ALREADY_MEMBER',
|
|
90
|
+
/** The entries do not continue the roster's head (a fork, a race, a stale head). */
|
|
91
|
+
rosterConflict: 'KEYCHAIN_ROSTER_CONFLICT',
|
|
92
|
+
/** An entry is malformed, non-canonical, badly signed, or breaks a roster rule. */
|
|
93
|
+
rosterInvalid: 'KEYCHAIN_ROSTER_INVALID',
|
|
94
|
+
/** A wrap is malformed, badly signed, or not the one the entries require. */
|
|
95
|
+
wrapInvalid: 'KEYCHAIN_WRAP_INVALID',
|
|
96
|
+
/**
|
|
97
|
+
* A `remove` without its `generation`, or a `generation` without a wrap at
|
|
98
|
+
* that generation for every remaining member and `recovery`.
|
|
99
|
+
*/
|
|
100
|
+
rotationIncomplete: 'KEYCHAIN_ROTATION_INCOMPLETE',
|
|
101
|
+
/** A limit of `KEYCHAIN_LIMITS` would be exceeded. */
|
|
102
|
+
limitReached: 'KEYCHAIN_LIMIT_REACHED',
|
|
103
|
+
/** No such enrollment for this vault. */
|
|
104
|
+
enrollmentNotFound: 'KEYCHAIN_ENROLLMENT_NOT_FOUND',
|
|
105
|
+
/** The enrollment's ten minutes are over. */
|
|
106
|
+
enrollmentExpired: 'KEYCHAIN_ENROLLMENT_EXPIRED',
|
|
107
|
+
/** The enrollment is not at the step this request takes (or was decided). */
|
|
108
|
+
enrollmentState: 'KEYCHAIN_ENROLLMENT_STATE',
|
|
109
|
+
/** The revealed device nonce does not open the commitment; the enrollment is denied. */
|
|
110
|
+
commitmentMismatch: 'KEYCHAIN_COMMITMENT_MISMATCH',
|
|
111
|
+
/** No such item, or it is deleted. */
|
|
112
|
+
itemNotFound: 'KEYCHAIN_ITEM_NOT_FOUND',
|
|
113
|
+
/** `baseRevision` is not the item's stored revision: re-read, merge, retry. */
|
|
114
|
+
itemConflict: 'KEYCHAIN_ITEM_CONFLICT',
|
|
115
|
+
/** An item's generation is not between 1 and the vault's. */
|
|
116
|
+
generationInvalid: 'KEYCHAIN_GENERATION_INVALID',
|
|
117
|
+
/** `DELETE /keychain` on an account with a linked root: a root proof is required. */
|
|
118
|
+
resetProofRequired: 'KEYCHAIN_RESET_PROOF_REQUIRED',
|
|
119
|
+
};
|
|
120
|
+
/* -------------------------------------------------------------------------- */
|
|
121
|
+
/* Encodings */
|
|
122
|
+
/* -------------------------------------------------------------------------- */
|
|
123
|
+
/** A lowercase uuid in its 8-4-4-4-12 form, any version: vault, member, item and enrollment ids. */
|
|
124
|
+
export const KEYCHAIN_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
125
|
+
/** A roster timestamp in its one spelling: UTC with milliseconds, as `Date#toISOString` writes it. */
|
|
126
|
+
export const KEYCHAIN_TIMESTAMP_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
127
|
+
/** 32 bytes, canonical base64url (43 characters): keys, enrollment nonces, commitments. */
|
|
128
|
+
export const KEYCHAIN_BYTES32_PATTERN = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
129
|
+
/** 24 bytes, base64url (32 characters): an XChaCha20-Poly1305 nonce. */
|
|
130
|
+
export const KEYCHAIN_NONCE_PATTERN = /^[A-Za-z0-9_-]{32}$/;
|
|
131
|
+
/** 64 bytes, canonical base64url (86 characters): an Ed25519 signature. */
|
|
132
|
+
export const KEYCHAIN_SIGNATURE_PATTERN = /^[A-Za-z0-9_-]{85}[AQgw]$/;
|
|
133
|
+
/** Any length of canonical base64url without padding. */
|
|
134
|
+
export const KEYCHAIN_BASE64URL_PATTERN = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}[AEIMQUYcgkosw048]|[A-Za-z0-9_-][AQgw])?$/;
|
|
135
|
+
/** A roster entry's hash: lowercase hex SHA-256. */
|
|
136
|
+
export const KEYCHAIN_HASH_PATTERN = /^[0-9a-f]{64}$/;
|
|
137
|
+
/* -------------------------------------------------------------------------- */
|
|
138
|
+
/* Response checks */
|
|
139
|
+
/* -------------------------------------------------------------------------- */
|
|
140
|
+
const counter = number(int, nonnegative);
|
|
141
|
+
const generation = number(int, positive);
|
|
142
|
+
const entryCheck = object({
|
|
143
|
+
body: string(),
|
|
144
|
+
signatures: array(object({ signer: string(), signature: string() })),
|
|
145
|
+
});
|
|
146
|
+
const wrapCheck = object({
|
|
147
|
+
recipient: string(),
|
|
148
|
+
generation,
|
|
149
|
+
epk: string(),
|
|
150
|
+
nonce: string(),
|
|
151
|
+
ciphertext: string(),
|
|
152
|
+
signer: string(),
|
|
153
|
+
signature: string(),
|
|
154
|
+
});
|
|
155
|
+
const memberCheck = object({
|
|
156
|
+
id: string(),
|
|
157
|
+
name: string(),
|
|
158
|
+
platform: oneOf(KEYCHAIN_PLATFORMS),
|
|
159
|
+
signingKey: string(),
|
|
160
|
+
boxKey: string(),
|
|
161
|
+
});
|
|
162
|
+
const enrollmentCheck = object({
|
|
163
|
+
id: string(),
|
|
164
|
+
vaultId: string(),
|
|
165
|
+
member: memberCheck,
|
|
166
|
+
commitment: string(),
|
|
167
|
+
approverNonce: nullable(string()),
|
|
168
|
+
approverMemberId: nullable(string()),
|
|
169
|
+
deviceNonce: nullable(string()),
|
|
170
|
+
status: oneOf(KEYCHAIN_ENROLLMENT_STATUSES),
|
|
171
|
+
expiresAt: string(),
|
|
172
|
+
createdAt: string(),
|
|
173
|
+
});
|
|
174
|
+
const itemCheck = object({
|
|
175
|
+
id: string(),
|
|
176
|
+
revision: counter,
|
|
177
|
+
generation,
|
|
178
|
+
nonce: nullable(string()),
|
|
179
|
+
ciphertext: nullable(string()),
|
|
180
|
+
deletedAt: nullable(string()),
|
|
181
|
+
updatedAt: string(),
|
|
182
|
+
});
|
|
183
|
+
export const keychainStateResponseCheck = exact()(object({
|
|
184
|
+
vault: nullable(object({
|
|
185
|
+
id: string(),
|
|
186
|
+
genesisHash: string(),
|
|
187
|
+
rosterSeq: counter,
|
|
188
|
+
rosterHead: string(),
|
|
189
|
+
generation,
|
|
190
|
+
revision: counter,
|
|
191
|
+
})),
|
|
192
|
+
roster: array(entryCheck),
|
|
193
|
+
members: array(object({ id: string(), orphaned: boolean, removed: boolean })),
|
|
194
|
+
self: nullable(string()),
|
|
195
|
+
}));
|
|
196
|
+
export const keychainWrapResponseCheck = exact()(object({ wrap: wrapCheck }));
|
|
197
|
+
export const keychainEnrollmentResponseCheck = exact()(object({ enrollment: enrollmentCheck }));
|
|
198
|
+
export const keychainEnrollmentsResponseCheck = exact()(object({ enrollments: array(enrollmentCheck) }));
|
|
199
|
+
export const keychainItemResponseCheck = exact()(object({ item: itemCheck }));
|
|
200
|
+
export const keychainItemsResponseCheck = exact()(object({ items: array(itemCheck), revision: counter, more: boolean }));
|
|
@@ -71,6 +71,8 @@ export const REAUTH_ACTIONS = [
|
|
|
71
71
|
'credentials_manage',
|
|
72
72
|
'supervision',
|
|
73
73
|
'supervision_purchase',
|
|
74
|
+
/** `DELETE /keychain`: reset the Oxy Keychain, deleting every item (ADR 0063 D6). */
|
|
75
|
+
'reset_keychain',
|
|
74
76
|
];
|
|
75
77
|
/**
|
|
76
78
|
* Stable error codes (`error.code` in the API error body). Clients map these
|
package/dist/esm/index.js
CHANGED
|
@@ -219,3 +219,4 @@ export { integerCheck, safeNumberCheck } from './numberChecks.js';
|
|
|
219
219
|
export { campaignAttributionSchema } from './campaignAttribution.js';
|
|
220
220
|
export { APPLICATION_ACCOUNT_REGISTRATION_BATCH_MAX, APPLICATION_ACCOUNT_TOTAL_MAX_AGE_SECONDS, applicationAccountRegistrationRequestSchema, applicationAccountRegistrationResponseSchema, applicationAccountTotalSchema, } from './applicationAccounts.js';
|
|
221
221
|
export * from './postalAddresses.js';
|
|
222
|
+
export * from './keychain.js';
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Oxy Keychain's wire contract (ADR 0063, `docs/identity/keychain.md`).
|
|
3
|
+
*
|
|
4
|
+
* The API parses every `/keychain` request with these schemas and its answers
|
|
5
|
+
* with the response schemas; clients check answers with the Zod-free checks in
|
|
6
|
+
* `./client/keychain.ts` (`@oxy.so/contracts/client`), which mirror them.
|
|
7
|
+
*
|
|
8
|
+
* Every request object is STRICT (an unknown key is refused). Every binary
|
|
9
|
+
* value is canonical base64url without padding, with its length fixed where the
|
|
10
|
+
* bytes are (keys and enrollment nonces 32, AEAD nonces 24, signatures 64).
|
|
11
|
+
*
|
|
12
|
+
* The roster body schemas TRANSFORM NOTHING: the server requires an entry's
|
|
13
|
+
* `body` to equal the JCS of its own parse, so a parse that trimmed, defaulted
|
|
14
|
+
* or lower-cased a value would refuse a canonical body.
|
|
15
|
+
*
|
|
16
|
+
* Platform-agnostic — zod only, no react/react-native/expo. ESM-safe.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { KEYCHAIN_BASE64URL_PATTERN, KEYCHAIN_BYTES32_PATTERN, KEYCHAIN_ENROLLMENT_STATUSES, KEYCHAIN_HASH_PATTERN, KEYCHAIN_ID_PATTERN, KEYCHAIN_LIMITS, KEYCHAIN_NONCE_PATTERN, KEYCHAIN_PLATFORMS, KEYCHAIN_RECOVERY, KEYCHAIN_SIGNATURE_PATTERN, KEYCHAIN_TIMESTAMP_PATTERN, } from './client/keychain.js';
|
|
20
|
+
import { integerCheck } from './numberChecks.js';
|
|
21
|
+
import { identityProofSchema } from './identityProof.js';
|
|
22
|
+
import { reauthProofSchema, secondFactorCodeSchema } from './signIn.js';
|
|
23
|
+
import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
|
|
24
|
+
export { KEYCHAIN_PLATFORMS, KEYCHAIN_ROSTER_OPS, KEYCHAIN_ENROLLMENT_STATUSES, KEYCHAIN_RECOVERY, KEYCHAIN_DOMAINS, KEYCHAIN_LIMITS, KEYCHAIN_ERROR_CODES, KEYCHAIN_ID_PATTERN, KEYCHAIN_BYTES32_PATTERN, KEYCHAIN_NONCE_PATTERN, KEYCHAIN_SIGNATURE_PATTERN, KEYCHAIN_BASE64URL_PATTERN, KEYCHAIN_HASH_PATTERN, KEYCHAIN_TIMESTAMP_PATTERN, } from './client/keychain.js';
|
|
25
|
+
/* -------------------------------------------------------------------------- */
|
|
26
|
+
/* Building blocks */
|
|
27
|
+
/* -------------------------------------------------------------------------- */
|
|
28
|
+
/** A lowercase uuid: vault, member, item and enrollment ids. */
|
|
29
|
+
export const keychainIdSchema = z.string().regex(KEYCHAIN_ID_PATTERN, 'Expected a lowercase uuid');
|
|
30
|
+
/** A member id or `recovery`: a wrap's recipient, a signature's signer. */
|
|
31
|
+
export const keychainPrincipalSchema = z.union([keychainIdSchema, z.literal(KEYCHAIN_RECOVERY)]);
|
|
32
|
+
/** 32 bytes as canonical base64url: an Ed25519 or X25519 public key, a 32-byte nonce, a commitment. */
|
|
33
|
+
export const keychainBytes32Schema = z
|
|
34
|
+
.string()
|
|
35
|
+
.regex(KEYCHAIN_BYTES32_PATTERN, 'Expected 32 bytes as canonical base64url');
|
|
36
|
+
/** A 24-byte XChaCha20-Poly1305 nonce as base64url. */
|
|
37
|
+
export const keychainNonceSchema = z
|
|
38
|
+
.string()
|
|
39
|
+
.regex(KEYCHAIN_NONCE_PATTERN, 'Expected 24 bytes as base64url');
|
|
40
|
+
/** A 64-byte Ed25519 signature as canonical base64url. */
|
|
41
|
+
export const keychainSignatureValueSchema = z
|
|
42
|
+
.string()
|
|
43
|
+
.regex(KEYCHAIN_SIGNATURE_PATTERN, 'Expected 64 bytes as canonical base64url');
|
|
44
|
+
/** A ciphertext (tag included) as canonical base64url, at most 64 KiB of characters. */
|
|
45
|
+
export const keychainCiphertextSchema = z
|
|
46
|
+
.string()
|
|
47
|
+
.check(utf16MinLength(22))
|
|
48
|
+
.check(utf16MaxLength(KEYCHAIN_LIMITS.maxCiphertextLength))
|
|
49
|
+
.regex(KEYCHAIN_BASE64URL_PATTERN, 'Expected canonical base64url');
|
|
50
|
+
const hashSchema = z.string().regex(KEYCHAIN_HASH_PATTERN, 'Expected a lowercase SHA-256 hex');
|
|
51
|
+
const generationSchema = z.number().check(integerCheck()).min(1).max(Number.MAX_SAFE_INTEGER);
|
|
52
|
+
const revisionSchema = z.number().check(integerCheck()).min(1).max(Number.MAX_SAFE_INTEGER);
|
|
53
|
+
/**
|
|
54
|
+
* A member's name: 1 to 256 bytes of UTF-8, any characters (a device's UI
|
|
55
|
+
* sanitizes it for display), but well-formed: no lone surrogate, which JCS
|
|
56
|
+
* cannot carry.
|
|
57
|
+
*/
|
|
58
|
+
function isMemberName(name) {
|
|
59
|
+
let bytes = 0;
|
|
60
|
+
for (let index = 0; index < name.length; index++) {
|
|
61
|
+
const unit = name.charCodeAt(index);
|
|
62
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
63
|
+
const next = name.charCodeAt(index + 1);
|
|
64
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
65
|
+
return false;
|
|
66
|
+
bytes += 4;
|
|
67
|
+
index++;
|
|
68
|
+
}
|
|
69
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
bytes += unit < 0x80 ? 1 : unit < 0x800 ? 2 : 3;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return bytes >= 1 && bytes <= KEYCHAIN_LIMITS.maxMemberNameBytes;
|
|
77
|
+
}
|
|
78
|
+
/** `Date#toISOString`'s spelling, and a real instant. */
|
|
79
|
+
function isKeychainTimestamp(value) {
|
|
80
|
+
if (!KEYCHAIN_TIMESTAMP_PATTERN.test(value))
|
|
81
|
+
return false;
|
|
82
|
+
const ms = Date.parse(value);
|
|
83
|
+
return Number.isFinite(ms) && new Date(ms).toISOString() === value;
|
|
84
|
+
}
|
|
85
|
+
export const keychainMemberSchema = z
|
|
86
|
+
.object({
|
|
87
|
+
id: keychainIdSchema,
|
|
88
|
+
name: z.string().refine(isMemberName, {
|
|
89
|
+
message: 'A member name is 1 to 256 bytes of well-formed UTF-8',
|
|
90
|
+
}),
|
|
91
|
+
platform: z.enum(KEYCHAIN_PLATFORMS),
|
|
92
|
+
signingKey: keychainBytes32Schema,
|
|
93
|
+
boxKey: keychainBytes32Schema,
|
|
94
|
+
})
|
|
95
|
+
.strict();
|
|
96
|
+
export const keychainRecoveryKeysSchema = z
|
|
97
|
+
.object({ signingKey: keychainBytes32Schema, boxKey: keychainBytes32Schema })
|
|
98
|
+
.strict();
|
|
99
|
+
const rosterBodyBase = {
|
|
100
|
+
v: z.literal(1),
|
|
101
|
+
vaultId: keychainIdSchema,
|
|
102
|
+
seq: z.number().check(integerCheck()).min(0).max(Number.MAX_SAFE_INTEGER),
|
|
103
|
+
prev: hashSchema.nullable(),
|
|
104
|
+
createdAt: z.string().refine(isKeychainTimestamp, {
|
|
105
|
+
message: 'Expected an ISO 8601 UTC timestamp with milliseconds',
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* The parse of an entry's `body` (ADR 0063 D3). `seq`/`prev` continuity, the
|
|
110
|
+
* signatures and the signer rules are the server's and every device's
|
|
111
|
+
* verifier's, not the schema's; the schema only refuses a body that is not
|
|
112
|
+
* one of the five shapes exactly.
|
|
113
|
+
*/
|
|
114
|
+
export const keychainRosterBodySchema = z.discriminatedUnion('op', [
|
|
115
|
+
z
|
|
116
|
+
.object({
|
|
117
|
+
...rosterBodyBase,
|
|
118
|
+
op: z.literal('genesis'),
|
|
119
|
+
member: keychainMemberSchema,
|
|
120
|
+
recovery: keychainRecoveryKeysSchema,
|
|
121
|
+
})
|
|
122
|
+
.strict(),
|
|
123
|
+
z.object({ ...rosterBodyBase, op: z.literal('add'), member: keychainMemberSchema }).strict(),
|
|
124
|
+
z.object({ ...rosterBodyBase, op: z.literal('remove'), memberId: keychainIdSchema }).strict(),
|
|
125
|
+
z
|
|
126
|
+
.object({
|
|
127
|
+
...rosterBodyBase,
|
|
128
|
+
op: z.literal('generation'),
|
|
129
|
+
generation: generationSchema.min(2),
|
|
130
|
+
})
|
|
131
|
+
.strict(),
|
|
132
|
+
z
|
|
133
|
+
.object({ ...rosterBodyBase, op: z.literal('recovery'), recovery: keychainRecoveryKeysSchema })
|
|
134
|
+
.strict(),
|
|
135
|
+
]);
|
|
136
|
+
export const keychainSignatureSchema = z
|
|
137
|
+
.object({ signer: keychainPrincipalSchema, signature: keychainSignatureValueSchema })
|
|
138
|
+
.strict();
|
|
139
|
+
/** A roster entry as it travels. One or two signatures (genesis has exactly two). */
|
|
140
|
+
export const keychainEntrySchema = z
|
|
141
|
+
.object({
|
|
142
|
+
body: z
|
|
143
|
+
.string()
|
|
144
|
+
.check(utf16MinLength(2))
|
|
145
|
+
.check(utf16MaxLength(KEYCHAIN_LIMITS.maxEntryBodyLength)),
|
|
146
|
+
signatures: z.array(keychainSignatureSchema).min(1).max(2),
|
|
147
|
+
})
|
|
148
|
+
.strict();
|
|
149
|
+
export const keychainWrapSchema = z
|
|
150
|
+
.object({
|
|
151
|
+
recipient: keychainPrincipalSchema,
|
|
152
|
+
generation: generationSchema,
|
|
153
|
+
epk: keychainBytes32Schema,
|
|
154
|
+
nonce: keychainNonceSchema,
|
|
155
|
+
ciphertext: keychainCiphertextSchema,
|
|
156
|
+
signer: keychainPrincipalSchema,
|
|
157
|
+
signature: keychainSignatureValueSchema,
|
|
158
|
+
})
|
|
159
|
+
.strict();
|
|
160
|
+
/* -------------------------------------------------------------------------- */
|
|
161
|
+
/* Requests */
|
|
162
|
+
/* -------------------------------------------------------------------------- */
|
|
163
|
+
/** `POST /keychain`: the genesis entry, and the member's and the recovery wraps. */
|
|
164
|
+
export const keychainCreateRequestSchema = z
|
|
165
|
+
.object({
|
|
166
|
+
genesis: keychainEntrySchema,
|
|
167
|
+
wraps: z.array(keychainWrapSchema).length(2),
|
|
168
|
+
})
|
|
169
|
+
.strict();
|
|
170
|
+
/** `POST /keychain/roster`: entries continuing the head, and the wraps they require. */
|
|
171
|
+
export const keychainRosterAppendRequestSchema = z
|
|
172
|
+
.object({
|
|
173
|
+
entries: z.array(keychainEntrySchema).min(1).max(KEYCHAIN_LIMITS.maxEntriesPerAppend),
|
|
174
|
+
wraps: z
|
|
175
|
+
.array(keychainWrapSchema)
|
|
176
|
+
.max(KEYCHAIN_LIMITS.maxLiveMembers + 1)
|
|
177
|
+
.default([]),
|
|
178
|
+
})
|
|
179
|
+
.strict();
|
|
180
|
+
/** `POST /keychain/enrollments`: the new device's member and its commitment. */
|
|
181
|
+
export const keychainEnrollmentCreateRequestSchema = z
|
|
182
|
+
.object({ member: keychainMemberSchema, commitment: keychainBytes32Schema })
|
|
183
|
+
.strict();
|
|
184
|
+
/** `POST /keychain/enrollments/:id/approver-nonce`. */
|
|
185
|
+
export const keychainApproverNonceRequestSchema = z
|
|
186
|
+
.object({ memberId: keychainIdSchema, approverNonce: keychainBytes32Schema })
|
|
187
|
+
.strict();
|
|
188
|
+
/** `POST /keychain/enrollments/:id/reveal`. */
|
|
189
|
+
export const keychainRevealRequestSchema = z
|
|
190
|
+
.object({ deviceNonce: keychainBytes32Schema })
|
|
191
|
+
.strict();
|
|
192
|
+
/** `POST /keychain/enrollments/:id/approve`: the `add` entry and the new member's wrap. */
|
|
193
|
+
export const keychainApproveRequestSchema = z
|
|
194
|
+
.object({ entry: keychainEntrySchema, wrap: keychainWrapSchema })
|
|
195
|
+
.strict();
|
|
196
|
+
/** `PUT /keychain/items/:itemId`. `baseRevision` is `null` only for an item that never existed. */
|
|
197
|
+
export const keychainItemPutRequestSchema = z
|
|
198
|
+
.object({
|
|
199
|
+
baseRevision: revisionSchema.nullable(),
|
|
200
|
+
generation: generationSchema,
|
|
201
|
+
nonce: keychainNonceSchema,
|
|
202
|
+
ciphertext: keychainCiphertextSchema,
|
|
203
|
+
})
|
|
204
|
+
.strict();
|
|
205
|
+
/** `DELETE /keychain/items/:itemId`. */
|
|
206
|
+
export const keychainItemDeleteRequestSchema = z.object({ baseRevision: revisionSchema }).strict();
|
|
207
|
+
/** `GET /keychain/items?since=&limit=`. */
|
|
208
|
+
export const keychainItemsQuerySchema = z
|
|
209
|
+
.object({
|
|
210
|
+
since: z.coerce.number().check(integerCheck()).min(0).max(Number.MAX_SAFE_INTEGER).default(0),
|
|
211
|
+
limit: z.coerce
|
|
212
|
+
.number()
|
|
213
|
+
.check(integerCheck())
|
|
214
|
+
.min(1)
|
|
215
|
+
.max(KEYCHAIN_LIMITS.maxItemsPage)
|
|
216
|
+
.default(KEYCHAIN_LIMITS.maxItemsPage),
|
|
217
|
+
})
|
|
218
|
+
.strict();
|
|
219
|
+
export const keychainEnrollmentParamsSchema = z.object({ id: keychainIdSchema }).strict();
|
|
220
|
+
export const keychainItemParamsSchema = z.object({ itemId: keychainIdSchema }).strict();
|
|
221
|
+
/**
|
|
222
|
+
* `DELETE /keychain` — the reset (ADR 0063 D6), with a fresh re-verification.
|
|
223
|
+
*
|
|
224
|
+
* - An account WITHOUT a linked root: `reauth` for `reset_keychain` (ADR 0030:
|
|
225
|
+
* its email code, or its password when it has no email; plus its
|
|
226
|
+
* authenticator's code when it has one).
|
|
227
|
+
* - An account WITH a linked root (Commons, which has no email or password to
|
|
228
|
+
* re-verify with): `rootProof`, a root proof for the `keychain_reset` action
|
|
229
|
+
* over the payload `{ vaultId }` (ADR 0024 D7, challenge from
|
|
230
|
+
* `POST /identity/proof-challenge`), plus `totpCode` when it has an
|
|
231
|
+
* authenticator.
|
|
232
|
+
*/
|
|
233
|
+
export const keychainResetRequestSchema = z
|
|
234
|
+
.object({
|
|
235
|
+
reauth: reauthProofSchema.optional(),
|
|
236
|
+
rootProof: identityProofSchema.optional(),
|
|
237
|
+
totpCode: secondFactorCodeSchema.optional(),
|
|
238
|
+
})
|
|
239
|
+
.strict();
|
|
240
|
+
/* -------------------------------------------------------------------------- */
|
|
241
|
+
/* Responses (mirrored by the checks in ./client/keychain.ts) */
|
|
242
|
+
/* -------------------------------------------------------------------------- */
|
|
243
|
+
const counterSchema = z.number().check(integerCheck()).nonnegative();
|
|
244
|
+
const positiveIntSchema = z.number().check(integerCheck()).positive();
|
|
245
|
+
const entryResponseSchema = z.object({
|
|
246
|
+
body: z.string(),
|
|
247
|
+
signatures: z.array(z.object({ signer: z.string(), signature: z.string() })),
|
|
248
|
+
});
|
|
249
|
+
const wrapResponseSchema = z.object({
|
|
250
|
+
recipient: z.string(),
|
|
251
|
+
generation: positiveIntSchema,
|
|
252
|
+
epk: z.string(),
|
|
253
|
+
nonce: z.string(),
|
|
254
|
+
ciphertext: z.string(),
|
|
255
|
+
signer: z.string(),
|
|
256
|
+
signature: z.string(),
|
|
257
|
+
});
|
|
258
|
+
const memberResponseSchema = z.object({
|
|
259
|
+
id: z.string(),
|
|
260
|
+
name: z.string(),
|
|
261
|
+
platform: z.enum(KEYCHAIN_PLATFORMS),
|
|
262
|
+
signingKey: z.string(),
|
|
263
|
+
boxKey: z.string(),
|
|
264
|
+
});
|
|
265
|
+
const enrollmentResponseSchema = z.object({
|
|
266
|
+
id: z.string(),
|
|
267
|
+
vaultId: z.string(),
|
|
268
|
+
member: memberResponseSchema,
|
|
269
|
+
commitment: z.string(),
|
|
270
|
+
approverNonce: z.string().nullable(),
|
|
271
|
+
approverMemberId: z.string().nullable(),
|
|
272
|
+
deviceNonce: z.string().nullable(),
|
|
273
|
+
status: z.enum(KEYCHAIN_ENROLLMENT_STATUSES),
|
|
274
|
+
expiresAt: z.string(),
|
|
275
|
+
createdAt: z.string(),
|
|
276
|
+
});
|
|
277
|
+
const itemResponseSchema = z.object({
|
|
278
|
+
id: z.string(),
|
|
279
|
+
revision: counterSchema,
|
|
280
|
+
generation: positiveIntSchema,
|
|
281
|
+
nonce: z.string().nullable(),
|
|
282
|
+
ciphertext: z.string().nullable(),
|
|
283
|
+
deletedAt: z.string().nullable(),
|
|
284
|
+
updatedAt: z.string(),
|
|
285
|
+
});
|
|
286
|
+
export const keychainStateResponseSchema = z.object({
|
|
287
|
+
vault: z
|
|
288
|
+
.object({
|
|
289
|
+
id: z.string(),
|
|
290
|
+
genesisHash: z.string(),
|
|
291
|
+
rosterSeq: counterSchema,
|
|
292
|
+
rosterHead: z.string(),
|
|
293
|
+
generation: positiveIntSchema,
|
|
294
|
+
revision: counterSchema,
|
|
295
|
+
})
|
|
296
|
+
.nullable(),
|
|
297
|
+
roster: z.array(entryResponseSchema),
|
|
298
|
+
members: z.array(z.object({ id: z.string(), orphaned: z.boolean(), removed: z.boolean() })),
|
|
299
|
+
self: z.string().nullable(),
|
|
300
|
+
});
|
|
301
|
+
export const keychainWrapResponseSchema = z.object({
|
|
302
|
+
wrap: wrapResponseSchema,
|
|
303
|
+
});
|
|
304
|
+
export const keychainEnrollmentResponseSchema = z.object({
|
|
305
|
+
enrollment: enrollmentResponseSchema,
|
|
306
|
+
});
|
|
307
|
+
export const keychainEnrollmentsResponseSchema = z.object({
|
|
308
|
+
enrollments: z.array(enrollmentResponseSchema),
|
|
309
|
+
});
|
|
310
|
+
export const keychainItemResponseSchema = z.object({
|
|
311
|
+
item: itemResponseSchema,
|
|
312
|
+
});
|
|
313
|
+
export const keychainItemsResponseSchema = z.object({
|
|
314
|
+
items: z.array(itemResponseSchema),
|
|
315
|
+
revision: counterSchema,
|
|
316
|
+
more: z.boolean(),
|
|
317
|
+
});
|
|
@@ -30,6 +30,12 @@ export declare const IDENTITY_PROOF_ACTIONS: {
|
|
|
30
30
|
* root and the new key, and by the current key when the device holds it.
|
|
31
31
|
*/
|
|
32
32
|
readonly organizationKeyReplace: "organization_key_replace";
|
|
33
|
+
/**
|
|
34
|
+
* Reset the account's Oxy Keychain (`DELETE /keychain`, ADR 0063 D6) on an
|
|
35
|
+
* account whose root is linked: it has no email or password to re-verify
|
|
36
|
+
* with, so its root confirms the reset. The payload is `{ vaultId }`.
|
|
37
|
+
*/
|
|
38
|
+
readonly keychainReset: "keychain_reset";
|
|
33
39
|
};
|
|
34
40
|
export type IdentityProofAction = (typeof IDENTITY_PROOF_ACTIONS)[keyof typeof IDENTITY_PROOF_ACTIONS];
|
|
35
41
|
export declare const IDENTITY_PROOF_ACTION_VALUES: [IdentityProofAction, ...IdentityProofAction[]];
|
|
@@ -53,3 +53,5 @@ export * from '../products/one';
|
|
|
53
53
|
export { CAMPAIGN_LABEL_MAX_LENGTH, CAMPAIGN_CLICK_ID_MAX_LENGTH, hasCampaignControlCharacters, } from './campaignAttribution';
|
|
54
54
|
export type { CampaignAttribution } from './campaignAttribution';
|
|
55
55
|
export { isLanguageTag } from './language';
|
|
56
|
+
export { KEYCHAIN_PLATFORMS, KEYCHAIN_ROSTER_OPS, KEYCHAIN_ENROLLMENT_STATUSES, KEYCHAIN_RECOVERY, KEYCHAIN_DOMAINS, KEYCHAIN_LIMITS, KEYCHAIN_ERROR_CODES, KEYCHAIN_ID_PATTERN, KEYCHAIN_BYTES32_PATTERN, KEYCHAIN_NONCE_PATTERN, KEYCHAIN_SIGNATURE_PATTERN, KEYCHAIN_BASE64URL_PATTERN, KEYCHAIN_HASH_PATTERN, KEYCHAIN_TIMESTAMP_PATTERN, keychainStateResponseCheck, keychainWrapResponseCheck, keychainEnrollmentResponseCheck, keychainEnrollmentsResponseCheck, keychainItemResponseCheck, keychainItemsResponseCheck, } from './keychain';
|
|
57
|
+
export type { KeychainPlatform, KeychainRosterOp, KeychainEnrollmentStatus, KeychainErrorCode, KeychainMember, KeychainRecoveryKeys, KeychainRosterBody, KeychainSignature, KeychainEntry, KeychainWrap, KeychainVaultSummary, KeychainMemberStatus, KeychainStateResponse, KeychainWrapResponse, KeychainEnrollment, KeychainEnrollmentResponse, KeychainEnrollmentsResponse, KeychainItem, KeychainItemResponse, KeychainItemsResponse, } from './keychain';
|