@oxy.so/contracts 6.19.0 → 6.21.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/cjs/platformSession.js +17 -1
- 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/esm/platformSession.js +16 -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/platformSession.d.ts +25 -0
- package/dist/types/signIn.d.ts +1 -0
- package/package.json +1 -1
|
@@ -35,6 +35,12 @@ exports.IDENTITY_PROOF_ACTIONS = {
|
|
|
35
35
|
* root and the new key, and by the current key when the device holds it.
|
|
36
36
|
*/
|
|
37
37
|
organizationKeyReplace: 'organization_key_replace',
|
|
38
|
+
/**
|
|
39
|
+
* Reset the account's Oxy Keychain (`DELETE /keychain`, ADR 0063 D6) on an
|
|
40
|
+
* account whose root is linked: it has no email or password to re-verify
|
|
41
|
+
* with, so its root confirms the reset. The payload is `{ vaultId }`.
|
|
42
|
+
*/
|
|
43
|
+
keychainReset: 'keychain_reset',
|
|
38
44
|
};
|
|
39
45
|
exports.IDENTITY_PROOF_ACTION_VALUES = Object.values(exports.IDENTITY_PROOF_ACTIONS);
|
|
40
46
|
exports.HEX_DIGEST = /^[0-9a-f]{64}$/;
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -34,7 +34,8 @@ exports.ORGANIZATION_KEY_PROOF_ACTION_VALUES = exports.ORGANIZATION_KEY_PROOF_AC
|
|
|
34
34
|
exports.ORGANIZATION_ERROR_CODES = exports.ORGANIZATION_CLAIM_STATUSES = exports.ORGANIZATION_CLAIM_DECISIONS = exports.ORGANIZATION_ALIAS_KINDS = exports.canonicalJson = exports.buildIdentityProofMessage = exports.IDENTITY_PROOF_VERSION = exports.IDENTITY_PROOF_DOMAIN = exports.IDENTITY_PROOF_CHALLENGE_TTL_MS = exports.IDENTITY_PROOF_AUDIENCE = exports.IDENTITY_PROOF_ACTION_VALUES = exports.IDENTITY_PROOF_ACTIONS = exports.IDENTITY_ERROR_CODES = exports.parseIdentityLinkQrPayload = exports.identityLinkStateCheck = exports.identityLinkCreateResponseCheck = exports.buildIdentityLinkQrPayload = exports.IDENTITY_LINK_STATUSES = exports.IDENTITY_LINK_QR_PREFIX = exports.identityKeyHistoryCheck = exports.IDENTITY_KEY_HISTORY_CLAIM_ACTION = exports.sessionAccountsChangedEventCheck = exports.deviceTokenMintResponseCheck = exports.deviceSessionSyncCheck = exports.deviceSessionStateCheck = exports.deviceRegisterResponseCheck = exports.deviceJoinResponseCheck = exports.deviceJoinCodeResponseCheck = exports.holderContextEvidenceV1ResponseCheck = exports.holderContextEvidenceV1RequestCheck = exports.deviceContextTokenV1ResponseCheck = exports.deviceContextTokenV1RequestCheck = exports.deviceBackgroundCredentialResponseCheck = exports.activeTokenCheck = exports.SESSION_ACCOUNTS_CHANGED_EVENT = exports.deviceDirectorySyncCheck = exports.deviceDirectoryCheck = exports.deviceActivateResponseCheck = exports.normalizeDomainName = exports.DOMAIN_NAME_MAX_LENGTH = exports.signedRecordEnvelopeCheck = exports.externalIdentityReferenceCheck = exports.loginResultCheck = exports.isLoopbackOrigin = exports.organizationKeyProofClaims = exports.organizationKeyPayload = exports.organizationKeyChallengeRequestCheck = exports.organizationKeyChallengeCheck = exports.organizationKeyApplyRequestCheck = exports.organizationIdentityKeyStateCheck = void 0;
|
|
35
35
|
exports.supervisionAcceptInputCheck = exports.safetyPeopleResponseCheck = exports.safetyPeopleInputCheck = exports.safetyOrganizationsResponseCheck = exports.safetyOrganizationsInputCheck = exports.purchaseReviewInputCheck = exports.purchaseApprovalListCheck = exports.purchaseApprovalCheck = exports.profileAccessInputCheck = exports.profileAccessDecisionCheck = exports.SUPERVISION_STATUSES = exports.SUPERVISION_INVITATION_STATUSES = exports.SUPERVISION_CONSENT_VERSION = exports.SUPERVISION_CHANGED_EVENT = exports.SUPERVISED_ACTIONS = exports.SAFETY_POLICY_VERSION = exports.PURCHASE_APPROVAL_STATUSES = exports.isFullReputationBalance = exports.recommendationRequestCheck = exports.subscriptionCreditGrantsResponseCheck = exports.subjectProductAccessQueryCheck = exports.subjectProductAccessCheck = exports.productSubscriptionsResponseCheck = exports.productSubscriptionPortalResponseCheck = exports.productSubscriptionPortalRequestCheck = exports.productSubscriptionCancellationResultCheck = exports.productPlanCheckoutRequestCheck = exports.productPlanCatalogueCheck = exports.personalPlanCheckoutResultCheck = exports.personalPlanCheckoutRequestCheck = exports.personalPlanCatalogueCheck = exports.cancelProductSubscriptionCheck = exports.updateOrganizationCheck = exports.organizationNameCheck = exports.organizationListCheck = exports.organizationImportBatchResultCheck = exports.organizationExternalResolutionCheck = exports.organizationExternalCheck = exports.organizationCurationResultCheck = exports.organizationClaimReviewCheck = exports.organizationClaimListCheck = exports.organizationClaimInputCheck = exports.organizationClaimDetailCheck = exports.organizationClaimCheck = exports.organizationCheck = exports.organizationBatchCheck = exports.createOrganizationCheck = exports.ORGANIZATION_TYPES = exports.ORGANIZATION_STATUSES = exports.ORGANIZATION_NAME_MAX_LENGTH = void 0;
|
|
36
36
|
exports.usernameCheck = exports.stripDisallowedUsernameCharacters = exports.botUsernameCheck = exports.applyBotUsernameSuffix = exports.USERNAME_PATTERN_SOURCE = exports.USERNAME_MIN_LENGTH = exports.USERNAME_MAX_LENGTH = exports.USERNAME_INVALID_MESSAGE = exports.RESERVED_USERNAME_MESSAGE = exports.RESERVED_USERNAMES = exports.NUMERIC_USERNAME_MESSAGE = exports.BOT_USERNAME_SUFFIX = exports.BOT_USERNAME_INVALID_MESSAGE = exports.totpEnrollResponseCheck = exports.totpBackupCodesResponseCheck = exports.signInMethodsCheck = exports.secondFactorRequiredCheck = exports.reauthProofCheck = exports.normalizeEmailSignInCode = exports.isSecondFactorRequired = exports.isEmailSignInChooseAccount = exports.emailSignInStartResponseCheck = exports.emailSignInPendingCheck = exports.emailSignInLinkResponseCheck = exports.emailSignInChooseAccountCheck = exports.TOTP_PERIOD_SECONDS = exports.TOTP_DIGITS = exports.TOTP_BACKUP_CODE_COUNT = exports.SIGN_IN_ERROR_CODES = exports.SIGNIN_SECOND_FACTOR_TTL_MS = exports.SIGNIN_SECOND_FACTOR_MAX_ATTEMPTS = exports.SIGN_IN_IDENTIFIER_MAX_LENGTH = exports.SECOND_FACTOR_CODE_MAX_LENGTH = exports.REAUTH_ACTIONS = exports.PASSWORD_MIN_LENGTH = exports.PASSWORD_MAX_LENGTH = exports.EMAIL_SIGNIN_LONG_CODE_LENGTH = exports.EMAIL_SIGNIN_LONG_CODE_ALPHABET = exports.EMAIL_SIGNIN_LINK_TTL_MS = exports.EMAIL_SIGNIN_CHOICE_TTL_MS = exports.EMAIL_ACCOUNTS_MAX = exports.CONSOLE_USE_CASES = exports.CONSOLE_TERMS_VERSION = exports.publicApplicationCheck = exports.supervisionStateCheck = exports.supervisionReviewInputCheck = exports.supervisionInviteInputCheck = exports.supervisionInvitationCheck = exports.supervisionContactsResponseCheck = exports.supervisionContactInputCheck = void 0;
|
|
37
|
-
exports.isLanguageTag = exports.hasCampaignControlCharacters = exports.CAMPAIGN_CLICK_ID_MAX_LENGTH = exports.CAMPAIGN_LABEL_MAX_LENGTH = exports.FREE_USER_PROFILE_COLOR_PRESETS = exports.USER_PROFILE_COLOR_PRESETS = exports.USER_PROFILE_COLORS = exports.deviceAppTokenResponseCheck = exports.PLATFORM_HOSTS = exports.OXYOS_DESKTOP_ENTRY_ID_PATTERN = exports.DEVICE_APP_TOKEN_TTL_SECONDS = exports.DEVICE_APP_TOKEN_ERROR_CODES = exports.APP_TOKEN_DEVICE_ACCESS_DENIED = exports.appAttestKeyResponseCheck = exports.appAssertionResponseCheck = exports.appAssertionChallengeResponseCheck = exports.OXY_APP_ASSERTION_TYPE = exports.OXY_APP_ASSERTION_TTL_SECONDS = exports.OXY_APP_ASSERTION_HEADER = exports.OXY_APP_ASSERTION_AUDIENCE = exports.APP_ASSERTION_PLATFORMS = exports.APP_ASSERTION_ERROR_CODES = exports.APP_ASSERTION_CHALLENGE_PURPOSES = exports.isRightsClaim = exports.isErasureRequest = exports.OPEN_CONTENT_CLAIM_STATES = exports.ERASURE_REQUEST_DEADLINE_DAYS = exports.COUNTER_NOTICE_STATEMENTS = exports.COUNTER_NOTICE_STATEMENT_VERSION = exports.CONTENT_CLAIM_STATES = exports.CONTENT_CLAIM_REFERENCE_PATTERN = exports.CONTENT_CLAIM_LIMITS = exports.CONTENT_CLAIM_KINDS = exports.CONTENT_CLAIM_ERROR_CODES = exports.CONTENT_CLAIM_COUNTER_NOTICE_LIMITS = exports.CLOSED_CONTENT_CLAIM_STATES = exports.CLAIMANT_RELATIONSHIPS = exports.PRONOUNS = exports.PROFILE_LINK_TITLE_MAX = exports.PROFILE_LINKS_MAX = exports.userNameCheck = exports.usernameCheckForAccountKind = void 0;
|
|
37
|
+
exports.KEYCHAIN_ID_PATTERN = exports.KEYCHAIN_ERROR_CODES = exports.KEYCHAIN_LIMITS = exports.KEYCHAIN_DOMAINS = exports.KEYCHAIN_RECOVERY = exports.KEYCHAIN_ENROLLMENT_STATUSES = exports.KEYCHAIN_ROSTER_OPS = exports.KEYCHAIN_PLATFORMS = exports.isLanguageTag = exports.hasCampaignControlCharacters = exports.CAMPAIGN_CLICK_ID_MAX_LENGTH = exports.CAMPAIGN_LABEL_MAX_LENGTH = exports.FREE_USER_PROFILE_COLOR_PRESETS = exports.USER_PROFILE_COLOR_PRESETS = exports.USER_PROFILE_COLORS = exports.deviceAppTokenResponseCheck = exports.PLATFORM_HOSTS = exports.OXYOS_DESKTOP_ENTRY_ID_PATTERN = exports.DEVICE_APP_TOKEN_TTL_SECONDS = exports.DEVICE_APP_TOKEN_ERROR_CODES = exports.APP_TOKEN_DEVICE_ACCESS_DENIED = exports.appAttestKeyResponseCheck = exports.appAssertionResponseCheck = exports.appAssertionChallengeResponseCheck = exports.OXY_APP_ASSERTION_TYPE = exports.OXY_APP_ASSERTION_TTL_SECONDS = exports.OXY_APP_ASSERTION_HEADER = exports.OXY_APP_ASSERTION_AUDIENCE = exports.APP_ASSERTION_PLATFORMS = exports.APP_ASSERTION_ERROR_CODES = exports.APP_ASSERTION_CHALLENGE_PURPOSES = exports.isRightsClaim = exports.isErasureRequest = exports.OPEN_CONTENT_CLAIM_STATES = exports.ERASURE_REQUEST_DEADLINE_DAYS = exports.COUNTER_NOTICE_STATEMENTS = exports.COUNTER_NOTICE_STATEMENT_VERSION = exports.CONTENT_CLAIM_STATES = exports.CONTENT_CLAIM_REFERENCE_PATTERN = exports.CONTENT_CLAIM_LIMITS = exports.CONTENT_CLAIM_KINDS = exports.CONTENT_CLAIM_ERROR_CODES = exports.CONTENT_CLAIM_COUNTER_NOTICE_LIMITS = exports.CLOSED_CONTENT_CLAIM_STATES = exports.CLAIMANT_RELATIONSHIPS = exports.PRONOUNS = exports.PROFILE_LINK_TITLE_MAX = exports.PROFILE_LINKS_MAX = exports.userNameCheck = exports.usernameCheckForAccountKind = void 0;
|
|
38
|
+
exports.keychainItemsResponseCheck = exports.keychainItemResponseCheck = exports.keychainEnrollmentsResponseCheck = exports.keychainEnrollmentResponseCheck = exports.keychainWrapResponseCheck = exports.keychainStateResponseCheck = exports.KEYCHAIN_TIMESTAMP_PATTERN = exports.KEYCHAIN_HASH_PATTERN = exports.KEYCHAIN_BASE64URL_PATTERN = exports.KEYCHAIN_SIGNATURE_PATTERN = exports.KEYCHAIN_NONCE_PATTERN = exports.KEYCHAIN_BYTES32_PATTERN = void 0;
|
|
38
39
|
var check_1 = require("./check");
|
|
39
40
|
Object.defineProperty(exports, "ContractCheckError", { enumerable: true, get: function () { return check_1.ContractCheckError; } });
|
|
40
41
|
Object.defineProperty(exports, "checkContract", { enumerable: true, get: function () { return check_1.checkContract; } });
|
|
@@ -311,3 +312,24 @@ Object.defineProperty(exports, "CAMPAIGN_CLICK_ID_MAX_LENGTH", { enumerable: tru
|
|
|
311
312
|
Object.defineProperty(exports, "hasCampaignControlCharacters", { enumerable: true, get: function () { return campaignAttribution_1.hasCampaignControlCharacters; } });
|
|
312
313
|
var language_1 = require("./language");
|
|
313
314
|
Object.defineProperty(exports, "isLanguageTag", { enumerable: true, get: function () { return language_1.isLanguageTag; } });
|
|
315
|
+
var keychain_1 = require("./keychain");
|
|
316
|
+
Object.defineProperty(exports, "KEYCHAIN_PLATFORMS", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_PLATFORMS; } });
|
|
317
|
+
Object.defineProperty(exports, "KEYCHAIN_ROSTER_OPS", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_ROSTER_OPS; } });
|
|
318
|
+
Object.defineProperty(exports, "KEYCHAIN_ENROLLMENT_STATUSES", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_ENROLLMENT_STATUSES; } });
|
|
319
|
+
Object.defineProperty(exports, "KEYCHAIN_RECOVERY", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_RECOVERY; } });
|
|
320
|
+
Object.defineProperty(exports, "KEYCHAIN_DOMAINS", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_DOMAINS; } });
|
|
321
|
+
Object.defineProperty(exports, "KEYCHAIN_LIMITS", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_LIMITS; } });
|
|
322
|
+
Object.defineProperty(exports, "KEYCHAIN_ERROR_CODES", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_ERROR_CODES; } });
|
|
323
|
+
Object.defineProperty(exports, "KEYCHAIN_ID_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_ID_PATTERN; } });
|
|
324
|
+
Object.defineProperty(exports, "KEYCHAIN_BYTES32_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_BYTES32_PATTERN; } });
|
|
325
|
+
Object.defineProperty(exports, "KEYCHAIN_NONCE_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_NONCE_PATTERN; } });
|
|
326
|
+
Object.defineProperty(exports, "KEYCHAIN_SIGNATURE_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_SIGNATURE_PATTERN; } });
|
|
327
|
+
Object.defineProperty(exports, "KEYCHAIN_BASE64URL_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_BASE64URL_PATTERN; } });
|
|
328
|
+
Object.defineProperty(exports, "KEYCHAIN_HASH_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_HASH_PATTERN; } });
|
|
329
|
+
Object.defineProperty(exports, "KEYCHAIN_TIMESTAMP_PATTERN", { enumerable: true, get: function () { return keychain_1.KEYCHAIN_TIMESTAMP_PATTERN; } });
|
|
330
|
+
Object.defineProperty(exports, "keychainStateResponseCheck", { enumerable: true, get: function () { return keychain_1.keychainStateResponseCheck; } });
|
|
331
|
+
Object.defineProperty(exports, "keychainWrapResponseCheck", { enumerable: true, get: function () { return keychain_1.keychainWrapResponseCheck; } });
|
|
332
|
+
Object.defineProperty(exports, "keychainEnrollmentResponseCheck", { enumerable: true, get: function () { return keychain_1.keychainEnrollmentResponseCheck; } });
|
|
333
|
+
Object.defineProperty(exports, "keychainEnrollmentsResponseCheck", { enumerable: true, get: function () { return keychain_1.keychainEnrollmentsResponseCheck; } });
|
|
334
|
+
Object.defineProperty(exports, "keychainItemResponseCheck", { enumerable: true, get: function () { return keychain_1.keychainItemResponseCheck; } });
|
|
335
|
+
Object.defineProperty(exports, "keychainItemsResponseCheck", { enumerable: true, get: function () { return keychain_1.keychainItemsResponseCheck; } });
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Oxy Keychain's wire contract, without Zod (ADR 0063,
|
|
4
|
+
* `docs/identity/keychain.md`). Schemas: `../keychain.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Oxy stores only ciphertext, public keys, signatures and counters. Every
|
|
7
|
+
* binary value is base64url WITHOUT padding, in its one canonical spelling
|
|
8
|
+
* (the unused low bits of the last character are zero), so no two strings name
|
|
9
|
+
* the same bytes.
|
|
10
|
+
*
|
|
11
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.keychainItemsResponseCheck = exports.keychainItemResponseCheck = exports.keychainEnrollmentsResponseCheck = exports.keychainEnrollmentResponseCheck = exports.keychainWrapResponseCheck = exports.keychainStateResponseCheck = exports.KEYCHAIN_HASH_PATTERN = exports.KEYCHAIN_BASE64URL_PATTERN = exports.KEYCHAIN_SIGNATURE_PATTERN = exports.KEYCHAIN_NONCE_PATTERN = exports.KEYCHAIN_BYTES32_PATTERN = exports.KEYCHAIN_TIMESTAMP_PATTERN = exports.KEYCHAIN_ID_PATTERN = exports.KEYCHAIN_ERROR_CODES = exports.KEYCHAIN_LIMITS = exports.KEYCHAIN_DOMAINS = exports.KEYCHAIN_RECOVERY = exports.KEYCHAIN_ENROLLMENT_STATUSES = exports.KEYCHAIN_ROSTER_OPS = exports.KEYCHAIN_PLATFORMS = void 0;
|
|
15
|
+
const check_1 = require("./check");
|
|
16
|
+
/* -------------------------------------------------------------------------- */
|
|
17
|
+
/* Closed sets and constants */
|
|
18
|
+
/* -------------------------------------------------------------------------- */
|
|
19
|
+
/** The platforms a member may name: a closed set, for display only (ADR 0063 D3). */
|
|
20
|
+
exports.KEYCHAIN_PLATFORMS = [
|
|
21
|
+
'oxyos',
|
|
22
|
+
'ios',
|
|
23
|
+
'android',
|
|
24
|
+
'macos',
|
|
25
|
+
'windows',
|
|
26
|
+
'linux',
|
|
27
|
+
'web',
|
|
28
|
+
];
|
|
29
|
+
/** The roster's operations (ADR 0063 D3). */
|
|
30
|
+
exports.KEYCHAIN_ROSTER_OPS = ['genesis', 'add', 'remove', 'generation', 'recovery'];
|
|
31
|
+
/** An enrollment's states. An expired pending one is answered `410`, never served as pending. */
|
|
32
|
+
exports.KEYCHAIN_ENROLLMENT_STATUSES = ['pending', 'approved', 'denied'];
|
|
33
|
+
/**
|
|
34
|
+
* The recipient of the recovery wrap, and the signer named by a signature made
|
|
35
|
+
* with the recovery signing key.
|
|
36
|
+
*/
|
|
37
|
+
exports.KEYCHAIN_RECOVERY = 'recovery';
|
|
38
|
+
/**
|
|
39
|
+
* Every domain string (ADR 0063 D8). Each signing input, AAD and derivation
|
|
40
|
+
* starts with one, so nothing signed or sealed as one kind can be replayed as
|
|
41
|
+
* another.
|
|
42
|
+
*/
|
|
43
|
+
exports.KEYCHAIN_DOMAINS = {
|
|
44
|
+
roster: 'oxy.keychain.roster.v1',
|
|
45
|
+
wrap: 'oxy.keychain.wrap.v1',
|
|
46
|
+
item: 'oxy.keychain.item.v1',
|
|
47
|
+
seal: 'oxy.keychain.seal.v1',
|
|
48
|
+
enrollCommit: 'oxy.keychain.enroll.commit.v1',
|
|
49
|
+
enrollCode: 'oxy.keychain.enroll.code.v1',
|
|
50
|
+
recovery: 'oxy.keychain.recovery.v1',
|
|
51
|
+
};
|
|
52
|
+
/** The server's limits (`docs/identity/keychain.md`). */
|
|
53
|
+
exports.KEYCHAIN_LIMITS = {
|
|
54
|
+
/** Live (non-deleted) items in one vault. */
|
|
55
|
+
maxLiveItems: 10000,
|
|
56
|
+
/** An item's or a wrap's ciphertext, in base64url characters (64 KiB). */
|
|
57
|
+
maxCiphertextLength: 65536,
|
|
58
|
+
/** Entries in one roster, genesis included. */
|
|
59
|
+
maxRosterEntries: 1000,
|
|
60
|
+
/** Members not removed. */
|
|
61
|
+
maxLiveMembers: 32,
|
|
62
|
+
/** Unexpired pending enrollments per vault. */
|
|
63
|
+
maxPendingEnrollments: 4,
|
|
64
|
+
/** How long an enrollment waits for its approval. */
|
|
65
|
+
enrollmentTtlMs: 10 * 60 * 1000,
|
|
66
|
+
/** Items in one `GET /keychain/items` page. */
|
|
67
|
+
maxItemsPage: 500,
|
|
68
|
+
/** Entries in one roster append. */
|
|
69
|
+
maxEntriesPerAppend: 64,
|
|
70
|
+
/** One roster entry's `body`, in characters. */
|
|
71
|
+
maxEntryBodyLength: 4096,
|
|
72
|
+
/** A member's display name, in bytes of UTF-8 (at least 1; any characters). */
|
|
73
|
+
maxMemberNameBytes: 256,
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Stable error codes the `/keychain` routes answer with (`error` in the API's
|
|
77
|
+
* error body). Clients map these through their localization, never the English
|
|
78
|
+
* message.
|
|
79
|
+
*/
|
|
80
|
+
exports.KEYCHAIN_ERROR_CODES = {
|
|
81
|
+
/** Not a personal account acting as itself. */
|
|
82
|
+
notAvailable: 'KEYCHAIN_NOT_AVAILABLE',
|
|
83
|
+
/** The bearer carries no device session, which a member is bound to. */
|
|
84
|
+
deviceRequired: 'KEYCHAIN_DEVICE_REQUIRED',
|
|
85
|
+
/** `POST /keychain`: the account already has a vault. */
|
|
86
|
+
exists: 'KEYCHAIN_EXISTS',
|
|
87
|
+
/** The account has no vault. */
|
|
88
|
+
notFound: 'KEYCHAIN_NOT_FOUND',
|
|
89
|
+
/** The caller's device session is bound to no live member of the vault. */
|
|
90
|
+
notMember: 'KEYCHAIN_NOT_MEMBER',
|
|
91
|
+
/** The caller's device session is already bound to a live member. */
|
|
92
|
+
alreadyMember: 'KEYCHAIN_ALREADY_MEMBER',
|
|
93
|
+
/** The entries do not continue the roster's head (a fork, a race, a stale head). */
|
|
94
|
+
rosterConflict: 'KEYCHAIN_ROSTER_CONFLICT',
|
|
95
|
+
/** An entry is malformed, non-canonical, badly signed, or breaks a roster rule. */
|
|
96
|
+
rosterInvalid: 'KEYCHAIN_ROSTER_INVALID',
|
|
97
|
+
/** A wrap is malformed, badly signed, or not the one the entries require. */
|
|
98
|
+
wrapInvalid: 'KEYCHAIN_WRAP_INVALID',
|
|
99
|
+
/**
|
|
100
|
+
* A `remove` without its `generation`, or a `generation` without a wrap at
|
|
101
|
+
* that generation for every remaining member and `recovery`.
|
|
102
|
+
*/
|
|
103
|
+
rotationIncomplete: 'KEYCHAIN_ROTATION_INCOMPLETE',
|
|
104
|
+
/** A limit of `KEYCHAIN_LIMITS` would be exceeded. */
|
|
105
|
+
limitReached: 'KEYCHAIN_LIMIT_REACHED',
|
|
106
|
+
/** No such enrollment for this vault. */
|
|
107
|
+
enrollmentNotFound: 'KEYCHAIN_ENROLLMENT_NOT_FOUND',
|
|
108
|
+
/** The enrollment's ten minutes are over. */
|
|
109
|
+
enrollmentExpired: 'KEYCHAIN_ENROLLMENT_EXPIRED',
|
|
110
|
+
/** The enrollment is not at the step this request takes (or was decided). */
|
|
111
|
+
enrollmentState: 'KEYCHAIN_ENROLLMENT_STATE',
|
|
112
|
+
/** The revealed device nonce does not open the commitment; the enrollment is denied. */
|
|
113
|
+
commitmentMismatch: 'KEYCHAIN_COMMITMENT_MISMATCH',
|
|
114
|
+
/** No such item, or it is deleted. */
|
|
115
|
+
itemNotFound: 'KEYCHAIN_ITEM_NOT_FOUND',
|
|
116
|
+
/** `baseRevision` is not the item's stored revision: re-read, merge, retry. */
|
|
117
|
+
itemConflict: 'KEYCHAIN_ITEM_CONFLICT',
|
|
118
|
+
/** An item's generation is not between 1 and the vault's. */
|
|
119
|
+
generationInvalid: 'KEYCHAIN_GENERATION_INVALID',
|
|
120
|
+
/** `DELETE /keychain` on an account with a linked root: a root proof is required. */
|
|
121
|
+
resetProofRequired: 'KEYCHAIN_RESET_PROOF_REQUIRED',
|
|
122
|
+
};
|
|
123
|
+
/* -------------------------------------------------------------------------- */
|
|
124
|
+
/* Encodings */
|
|
125
|
+
/* -------------------------------------------------------------------------- */
|
|
126
|
+
/** A lowercase uuid in its 8-4-4-4-12 form, any version: vault, member, item and enrollment ids. */
|
|
127
|
+
exports.KEYCHAIN_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
128
|
+
/** A roster timestamp in its one spelling: UTC with milliseconds, as `Date#toISOString` writes it. */
|
|
129
|
+
exports.KEYCHAIN_TIMESTAMP_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
130
|
+
/** 32 bytes, canonical base64url (43 characters): keys, enrollment nonces, commitments. */
|
|
131
|
+
exports.KEYCHAIN_BYTES32_PATTERN = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
132
|
+
/** 24 bytes, base64url (32 characters): an XChaCha20-Poly1305 nonce. */
|
|
133
|
+
exports.KEYCHAIN_NONCE_PATTERN = /^[A-Za-z0-9_-]{32}$/;
|
|
134
|
+
/** 64 bytes, canonical base64url (86 characters): an Ed25519 signature. */
|
|
135
|
+
exports.KEYCHAIN_SIGNATURE_PATTERN = /^[A-Za-z0-9_-]{85}[AQgw]$/;
|
|
136
|
+
/** Any length of canonical base64url without padding. */
|
|
137
|
+
exports.KEYCHAIN_BASE64URL_PATTERN = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}[AEIMQUYcgkosw048]|[A-Za-z0-9_-][AQgw])?$/;
|
|
138
|
+
/** A roster entry's hash: lowercase hex SHA-256. */
|
|
139
|
+
exports.KEYCHAIN_HASH_PATTERN = /^[0-9a-f]{64}$/;
|
|
140
|
+
/* -------------------------------------------------------------------------- */
|
|
141
|
+
/* Response checks */
|
|
142
|
+
/* -------------------------------------------------------------------------- */
|
|
143
|
+
const counter = (0, check_1.number)(check_1.int, check_1.nonnegative);
|
|
144
|
+
const generation = (0, check_1.number)(check_1.int, check_1.positive);
|
|
145
|
+
const entryCheck = (0, check_1.object)({
|
|
146
|
+
body: (0, check_1.string)(),
|
|
147
|
+
signatures: (0, check_1.array)((0, check_1.object)({ signer: (0, check_1.string)(), signature: (0, check_1.string)() })),
|
|
148
|
+
});
|
|
149
|
+
const wrapCheck = (0, check_1.object)({
|
|
150
|
+
recipient: (0, check_1.string)(),
|
|
151
|
+
generation,
|
|
152
|
+
epk: (0, check_1.string)(),
|
|
153
|
+
nonce: (0, check_1.string)(),
|
|
154
|
+
ciphertext: (0, check_1.string)(),
|
|
155
|
+
signer: (0, check_1.string)(),
|
|
156
|
+
signature: (0, check_1.string)(),
|
|
157
|
+
});
|
|
158
|
+
const memberCheck = (0, check_1.object)({
|
|
159
|
+
id: (0, check_1.string)(),
|
|
160
|
+
name: (0, check_1.string)(),
|
|
161
|
+
platform: (0, check_1.oneOf)(exports.KEYCHAIN_PLATFORMS),
|
|
162
|
+
signingKey: (0, check_1.string)(),
|
|
163
|
+
boxKey: (0, check_1.string)(),
|
|
164
|
+
});
|
|
165
|
+
const enrollmentCheck = (0, check_1.object)({
|
|
166
|
+
id: (0, check_1.string)(),
|
|
167
|
+
vaultId: (0, check_1.string)(),
|
|
168
|
+
member: memberCheck,
|
|
169
|
+
commitment: (0, check_1.string)(),
|
|
170
|
+
approverNonce: (0, check_1.nullable)((0, check_1.string)()),
|
|
171
|
+
approverMemberId: (0, check_1.nullable)((0, check_1.string)()),
|
|
172
|
+
deviceNonce: (0, check_1.nullable)((0, check_1.string)()),
|
|
173
|
+
status: (0, check_1.oneOf)(exports.KEYCHAIN_ENROLLMENT_STATUSES),
|
|
174
|
+
expiresAt: (0, check_1.string)(),
|
|
175
|
+
createdAt: (0, check_1.string)(),
|
|
176
|
+
});
|
|
177
|
+
const itemCheck = (0, check_1.object)({
|
|
178
|
+
id: (0, check_1.string)(),
|
|
179
|
+
revision: counter,
|
|
180
|
+
generation,
|
|
181
|
+
nonce: (0, check_1.nullable)((0, check_1.string)()),
|
|
182
|
+
ciphertext: (0, check_1.nullable)((0, check_1.string)()),
|
|
183
|
+
deletedAt: (0, check_1.nullable)((0, check_1.string)()),
|
|
184
|
+
updatedAt: (0, check_1.string)(),
|
|
185
|
+
});
|
|
186
|
+
exports.keychainStateResponseCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
187
|
+
vault: (0, check_1.nullable)((0, check_1.object)({
|
|
188
|
+
id: (0, check_1.string)(),
|
|
189
|
+
genesisHash: (0, check_1.string)(),
|
|
190
|
+
rosterSeq: counter,
|
|
191
|
+
rosterHead: (0, check_1.string)(),
|
|
192
|
+
generation,
|
|
193
|
+
revision: counter,
|
|
194
|
+
})),
|
|
195
|
+
roster: (0, check_1.array)(entryCheck),
|
|
196
|
+
members: (0, check_1.array)((0, check_1.object)({ id: (0, check_1.string)(), orphaned: check_1.boolean, removed: check_1.boolean })),
|
|
197
|
+
self: (0, check_1.nullable)((0, check_1.string)()),
|
|
198
|
+
}));
|
|
199
|
+
exports.keychainWrapResponseCheck = (0, check_1.exact)()((0, check_1.object)({ wrap: wrapCheck }));
|
|
200
|
+
exports.keychainEnrollmentResponseCheck = (0, check_1.exact)()((0, check_1.object)({ enrollment: enrollmentCheck }));
|
|
201
|
+
exports.keychainEnrollmentsResponseCheck = (0, check_1.exact)()((0, check_1.object)({ enrollments: (0, check_1.array)(enrollmentCheck) }));
|
|
202
|
+
exports.keychainItemResponseCheck = (0, check_1.exact)()((0, check_1.object)({ item: itemCheck }));
|
|
203
|
+
exports.keychainItemsResponseCheck = (0, check_1.exact)()((0, check_1.object)({ items: (0, check_1.array)(itemCheck), revision: counter, more: check_1.boolean }));
|
|
@@ -77,6 +77,8 @@ exports.REAUTH_ACTIONS = [
|
|
|
77
77
|
'credentials_manage',
|
|
78
78
|
'supervision',
|
|
79
79
|
'supervision_purchase',
|
|
80
|
+
/** `DELETE /keychain`: reset the Oxy Keychain, deleting every item (ADR 0063 D6). */
|
|
81
|
+
'reset_keychain',
|
|
80
82
|
];
|
|
81
83
|
/**
|
|
82
84
|
* Stable error codes (`error.code` in the API error body). Clients map these
|
package/dist/cjs/index.js
CHANGED
|
@@ -939,3 +939,4 @@ Object.defineProperty(exports, "applicationAccountRegistrationRequestSchema", {
|
|
|
939
939
|
Object.defineProperty(exports, "applicationAccountRegistrationResponseSchema", { enumerable: true, get: function () { return applicationAccounts_1.applicationAccountRegistrationResponseSchema; } });
|
|
940
940
|
Object.defineProperty(exports, "applicationAccountTotalSchema", { enumerable: true, get: function () { return applicationAccounts_1.applicationAccountTotalSchema; } });
|
|
941
941
|
__exportStar(require("./postalAddresses"), exports);
|
|
942
|
+
__exportStar(require("./keychain"), exports);
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Oxy Keychain's wire contract (ADR 0063, `docs/identity/keychain.md`).
|
|
4
|
+
*
|
|
5
|
+
* The API parses every `/keychain` request with these schemas and its answers
|
|
6
|
+
* with the response schemas; clients check answers with the Zod-free checks in
|
|
7
|
+
* `./client/keychain.ts` (`@oxy.so/contracts/client`), which mirror them.
|
|
8
|
+
*
|
|
9
|
+
* Every request object is STRICT (an unknown key is refused). Every binary
|
|
10
|
+
* value is canonical base64url without padding, with its length fixed where the
|
|
11
|
+
* bytes are (keys and enrollment nonces 32, AEAD nonces 24, signatures 64).
|
|
12
|
+
*
|
|
13
|
+
* The roster body schemas TRANSFORM NOTHING: the server requires an entry's
|
|
14
|
+
* `body` to equal the JCS of its own parse, so a parse that trimmed, defaulted
|
|
15
|
+
* or lower-cased a value would refuse a canonical body.
|
|
16
|
+
*
|
|
17
|
+
* Platform-agnostic — zod only, no react/react-native/expo. ESM-safe.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.keychainItemsResponseSchema = exports.keychainItemResponseSchema = exports.keychainEnrollmentsResponseSchema = exports.keychainEnrollmentResponseSchema = exports.keychainWrapResponseSchema = exports.keychainStateResponseSchema = exports.keychainResetRequestSchema = exports.keychainItemParamsSchema = exports.keychainEnrollmentParamsSchema = exports.keychainItemsQuerySchema = exports.keychainItemDeleteRequestSchema = exports.keychainItemPutRequestSchema = exports.keychainApproveRequestSchema = exports.keychainRevealRequestSchema = exports.keychainApproverNonceRequestSchema = exports.keychainEnrollmentCreateRequestSchema = exports.keychainRosterAppendRequestSchema = exports.keychainCreateRequestSchema = exports.keychainWrapSchema = exports.keychainEntrySchema = exports.keychainSignatureSchema = exports.keychainRosterBodySchema = exports.keychainRecoveryKeysSchema = exports.keychainMemberSchema = exports.keychainCiphertextSchema = exports.keychainSignatureValueSchema = exports.keychainNonceSchema = exports.keychainBytes32Schema = exports.keychainPrincipalSchema = exports.keychainIdSchema = exports.KEYCHAIN_TIMESTAMP_PATTERN = exports.KEYCHAIN_HASH_PATTERN = exports.KEYCHAIN_BASE64URL_PATTERN = exports.KEYCHAIN_SIGNATURE_PATTERN = exports.KEYCHAIN_NONCE_PATTERN = exports.KEYCHAIN_BYTES32_PATTERN = exports.KEYCHAIN_ID_PATTERN = exports.KEYCHAIN_ERROR_CODES = exports.KEYCHAIN_LIMITS = exports.KEYCHAIN_DOMAINS = exports.KEYCHAIN_RECOVERY = exports.KEYCHAIN_ENROLLMENT_STATUSES = exports.KEYCHAIN_ROSTER_OPS = exports.KEYCHAIN_PLATFORMS = void 0;
|
|
21
|
+
const zod_1 = require("zod");
|
|
22
|
+
const keychain_1 = require("./client/keychain");
|
|
23
|
+
const numberChecks_1 = require("./numberChecks");
|
|
24
|
+
const identityProof_1 = require("./identityProof");
|
|
25
|
+
const signIn_1 = require("./signIn");
|
|
26
|
+
const stringChecks_1 = require("./stringChecks");
|
|
27
|
+
var keychain_2 = require("./client/keychain");
|
|
28
|
+
Object.defineProperty(exports, "KEYCHAIN_PLATFORMS", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_PLATFORMS; } });
|
|
29
|
+
Object.defineProperty(exports, "KEYCHAIN_ROSTER_OPS", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_ROSTER_OPS; } });
|
|
30
|
+
Object.defineProperty(exports, "KEYCHAIN_ENROLLMENT_STATUSES", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_ENROLLMENT_STATUSES; } });
|
|
31
|
+
Object.defineProperty(exports, "KEYCHAIN_RECOVERY", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_RECOVERY; } });
|
|
32
|
+
Object.defineProperty(exports, "KEYCHAIN_DOMAINS", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_DOMAINS; } });
|
|
33
|
+
Object.defineProperty(exports, "KEYCHAIN_LIMITS", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_LIMITS; } });
|
|
34
|
+
Object.defineProperty(exports, "KEYCHAIN_ERROR_CODES", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_ERROR_CODES; } });
|
|
35
|
+
Object.defineProperty(exports, "KEYCHAIN_ID_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_ID_PATTERN; } });
|
|
36
|
+
Object.defineProperty(exports, "KEYCHAIN_BYTES32_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_BYTES32_PATTERN; } });
|
|
37
|
+
Object.defineProperty(exports, "KEYCHAIN_NONCE_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_NONCE_PATTERN; } });
|
|
38
|
+
Object.defineProperty(exports, "KEYCHAIN_SIGNATURE_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_SIGNATURE_PATTERN; } });
|
|
39
|
+
Object.defineProperty(exports, "KEYCHAIN_BASE64URL_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_BASE64URL_PATTERN; } });
|
|
40
|
+
Object.defineProperty(exports, "KEYCHAIN_HASH_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_HASH_PATTERN; } });
|
|
41
|
+
Object.defineProperty(exports, "KEYCHAIN_TIMESTAMP_PATTERN", { enumerable: true, get: function () { return keychain_2.KEYCHAIN_TIMESTAMP_PATTERN; } });
|
|
42
|
+
/* -------------------------------------------------------------------------- */
|
|
43
|
+
/* Building blocks */
|
|
44
|
+
/* -------------------------------------------------------------------------- */
|
|
45
|
+
/** A lowercase uuid: vault, member, item and enrollment ids. */
|
|
46
|
+
exports.keychainIdSchema = zod_1.z.string().regex(keychain_1.KEYCHAIN_ID_PATTERN, 'Expected a lowercase uuid');
|
|
47
|
+
/** A member id or `recovery`: a wrap's recipient, a signature's signer. */
|
|
48
|
+
exports.keychainPrincipalSchema = zod_1.z.union([exports.keychainIdSchema, zod_1.z.literal(keychain_1.KEYCHAIN_RECOVERY)]);
|
|
49
|
+
/** 32 bytes as canonical base64url: an Ed25519 or X25519 public key, a 32-byte nonce, a commitment. */
|
|
50
|
+
exports.keychainBytes32Schema = zod_1.z
|
|
51
|
+
.string()
|
|
52
|
+
.regex(keychain_1.KEYCHAIN_BYTES32_PATTERN, 'Expected 32 bytes as canonical base64url');
|
|
53
|
+
/** A 24-byte XChaCha20-Poly1305 nonce as base64url. */
|
|
54
|
+
exports.keychainNonceSchema = zod_1.z
|
|
55
|
+
.string()
|
|
56
|
+
.regex(keychain_1.KEYCHAIN_NONCE_PATTERN, 'Expected 24 bytes as base64url');
|
|
57
|
+
/** A 64-byte Ed25519 signature as canonical base64url. */
|
|
58
|
+
exports.keychainSignatureValueSchema = zod_1.z
|
|
59
|
+
.string()
|
|
60
|
+
.regex(keychain_1.KEYCHAIN_SIGNATURE_PATTERN, 'Expected 64 bytes as canonical base64url');
|
|
61
|
+
/** A ciphertext (tag included) as canonical base64url, at most 64 KiB of characters. */
|
|
62
|
+
exports.keychainCiphertextSchema = zod_1.z
|
|
63
|
+
.string()
|
|
64
|
+
.check((0, stringChecks_1.utf16MinLength)(22))
|
|
65
|
+
.check((0, stringChecks_1.utf16MaxLength)(keychain_1.KEYCHAIN_LIMITS.maxCiphertextLength))
|
|
66
|
+
.regex(keychain_1.KEYCHAIN_BASE64URL_PATTERN, 'Expected canonical base64url');
|
|
67
|
+
const hashSchema = zod_1.z.string().regex(keychain_1.KEYCHAIN_HASH_PATTERN, 'Expected a lowercase SHA-256 hex');
|
|
68
|
+
const generationSchema = zod_1.z.number().check((0, numberChecks_1.integerCheck)()).min(1).max(Number.MAX_SAFE_INTEGER);
|
|
69
|
+
const revisionSchema = zod_1.z.number().check((0, numberChecks_1.integerCheck)()).min(1).max(Number.MAX_SAFE_INTEGER);
|
|
70
|
+
/**
|
|
71
|
+
* A member's name: 1 to 256 bytes of UTF-8, any characters (a device's UI
|
|
72
|
+
* sanitizes it for display), but well-formed: no lone surrogate, which JCS
|
|
73
|
+
* cannot carry.
|
|
74
|
+
*/
|
|
75
|
+
function isMemberName(name) {
|
|
76
|
+
let bytes = 0;
|
|
77
|
+
for (let index = 0; index < name.length; index++) {
|
|
78
|
+
const unit = name.charCodeAt(index);
|
|
79
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
80
|
+
const next = name.charCodeAt(index + 1);
|
|
81
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
82
|
+
return false;
|
|
83
|
+
bytes += 4;
|
|
84
|
+
index++;
|
|
85
|
+
}
|
|
86
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
bytes += unit < 0x80 ? 1 : unit < 0x800 ? 2 : 3;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return bytes >= 1 && bytes <= keychain_1.KEYCHAIN_LIMITS.maxMemberNameBytes;
|
|
94
|
+
}
|
|
95
|
+
/** `Date#toISOString`'s spelling, and a real instant. */
|
|
96
|
+
function isKeychainTimestamp(value) {
|
|
97
|
+
if (!keychain_1.KEYCHAIN_TIMESTAMP_PATTERN.test(value))
|
|
98
|
+
return false;
|
|
99
|
+
const ms = Date.parse(value);
|
|
100
|
+
return Number.isFinite(ms) && new Date(ms).toISOString() === value;
|
|
101
|
+
}
|
|
102
|
+
exports.keychainMemberSchema = zod_1.z
|
|
103
|
+
.object({
|
|
104
|
+
id: exports.keychainIdSchema,
|
|
105
|
+
name: zod_1.z.string().refine(isMemberName, {
|
|
106
|
+
message: 'A member name is 1 to 256 bytes of well-formed UTF-8',
|
|
107
|
+
}),
|
|
108
|
+
platform: zod_1.z.enum(keychain_1.KEYCHAIN_PLATFORMS),
|
|
109
|
+
signingKey: exports.keychainBytes32Schema,
|
|
110
|
+
boxKey: exports.keychainBytes32Schema,
|
|
111
|
+
})
|
|
112
|
+
.strict();
|
|
113
|
+
exports.keychainRecoveryKeysSchema = zod_1.z
|
|
114
|
+
.object({ signingKey: exports.keychainBytes32Schema, boxKey: exports.keychainBytes32Schema })
|
|
115
|
+
.strict();
|
|
116
|
+
const rosterBodyBase = {
|
|
117
|
+
v: zod_1.z.literal(1),
|
|
118
|
+
vaultId: exports.keychainIdSchema,
|
|
119
|
+
seq: zod_1.z.number().check((0, numberChecks_1.integerCheck)()).min(0).max(Number.MAX_SAFE_INTEGER),
|
|
120
|
+
prev: hashSchema.nullable(),
|
|
121
|
+
createdAt: zod_1.z.string().refine(isKeychainTimestamp, {
|
|
122
|
+
message: 'Expected an ISO 8601 UTC timestamp with milliseconds',
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* The parse of an entry's `body` (ADR 0063 D3). `seq`/`prev` continuity, the
|
|
127
|
+
* signatures and the signer rules are the server's and every device's
|
|
128
|
+
* verifier's, not the schema's; the schema only refuses a body that is not
|
|
129
|
+
* one of the five shapes exactly.
|
|
130
|
+
*/
|
|
131
|
+
exports.keychainRosterBodySchema = zod_1.z.discriminatedUnion('op', [
|
|
132
|
+
zod_1.z
|
|
133
|
+
.object({
|
|
134
|
+
...rosterBodyBase,
|
|
135
|
+
op: zod_1.z.literal('genesis'),
|
|
136
|
+
member: exports.keychainMemberSchema,
|
|
137
|
+
recovery: exports.keychainRecoveryKeysSchema,
|
|
138
|
+
})
|
|
139
|
+
.strict(),
|
|
140
|
+
zod_1.z.object({ ...rosterBodyBase, op: zod_1.z.literal('add'), member: exports.keychainMemberSchema }).strict(),
|
|
141
|
+
zod_1.z.object({ ...rosterBodyBase, op: zod_1.z.literal('remove'), memberId: exports.keychainIdSchema }).strict(),
|
|
142
|
+
zod_1.z
|
|
143
|
+
.object({
|
|
144
|
+
...rosterBodyBase,
|
|
145
|
+
op: zod_1.z.literal('generation'),
|
|
146
|
+
generation: generationSchema.min(2),
|
|
147
|
+
})
|
|
148
|
+
.strict(),
|
|
149
|
+
zod_1.z
|
|
150
|
+
.object({ ...rosterBodyBase, op: zod_1.z.literal('recovery'), recovery: exports.keychainRecoveryKeysSchema })
|
|
151
|
+
.strict(),
|
|
152
|
+
]);
|
|
153
|
+
exports.keychainSignatureSchema = zod_1.z
|
|
154
|
+
.object({ signer: exports.keychainPrincipalSchema, signature: exports.keychainSignatureValueSchema })
|
|
155
|
+
.strict();
|
|
156
|
+
/** A roster entry as it travels. One or two signatures (genesis has exactly two). */
|
|
157
|
+
exports.keychainEntrySchema = zod_1.z
|
|
158
|
+
.object({
|
|
159
|
+
body: zod_1.z
|
|
160
|
+
.string()
|
|
161
|
+
.check((0, stringChecks_1.utf16MinLength)(2))
|
|
162
|
+
.check((0, stringChecks_1.utf16MaxLength)(keychain_1.KEYCHAIN_LIMITS.maxEntryBodyLength)),
|
|
163
|
+
signatures: zod_1.z.array(exports.keychainSignatureSchema).min(1).max(2),
|
|
164
|
+
})
|
|
165
|
+
.strict();
|
|
166
|
+
exports.keychainWrapSchema = zod_1.z
|
|
167
|
+
.object({
|
|
168
|
+
recipient: exports.keychainPrincipalSchema,
|
|
169
|
+
generation: generationSchema,
|
|
170
|
+
epk: exports.keychainBytes32Schema,
|
|
171
|
+
nonce: exports.keychainNonceSchema,
|
|
172
|
+
ciphertext: exports.keychainCiphertextSchema,
|
|
173
|
+
signer: exports.keychainPrincipalSchema,
|
|
174
|
+
signature: exports.keychainSignatureValueSchema,
|
|
175
|
+
})
|
|
176
|
+
.strict();
|
|
177
|
+
/* -------------------------------------------------------------------------- */
|
|
178
|
+
/* Requests */
|
|
179
|
+
/* -------------------------------------------------------------------------- */
|
|
180
|
+
/** `POST /keychain`: the genesis entry, and the member's and the recovery wraps. */
|
|
181
|
+
exports.keychainCreateRequestSchema = zod_1.z
|
|
182
|
+
.object({
|
|
183
|
+
genesis: exports.keychainEntrySchema,
|
|
184
|
+
wraps: zod_1.z.array(exports.keychainWrapSchema).length(2),
|
|
185
|
+
})
|
|
186
|
+
.strict();
|
|
187
|
+
/** `POST /keychain/roster`: entries continuing the head, and the wraps they require. */
|
|
188
|
+
exports.keychainRosterAppendRequestSchema = zod_1.z
|
|
189
|
+
.object({
|
|
190
|
+
entries: zod_1.z.array(exports.keychainEntrySchema).min(1).max(keychain_1.KEYCHAIN_LIMITS.maxEntriesPerAppend),
|
|
191
|
+
wraps: zod_1.z
|
|
192
|
+
.array(exports.keychainWrapSchema)
|
|
193
|
+
.max(keychain_1.KEYCHAIN_LIMITS.maxLiveMembers + 1)
|
|
194
|
+
.default([]),
|
|
195
|
+
})
|
|
196
|
+
.strict();
|
|
197
|
+
/** `POST /keychain/enrollments`: the new device's member and its commitment. */
|
|
198
|
+
exports.keychainEnrollmentCreateRequestSchema = zod_1.z
|
|
199
|
+
.object({ member: exports.keychainMemberSchema, commitment: exports.keychainBytes32Schema })
|
|
200
|
+
.strict();
|
|
201
|
+
/** `POST /keychain/enrollments/:id/approver-nonce`. */
|
|
202
|
+
exports.keychainApproverNonceRequestSchema = zod_1.z
|
|
203
|
+
.object({ memberId: exports.keychainIdSchema, approverNonce: exports.keychainBytes32Schema })
|
|
204
|
+
.strict();
|
|
205
|
+
/** `POST /keychain/enrollments/:id/reveal`. */
|
|
206
|
+
exports.keychainRevealRequestSchema = zod_1.z
|
|
207
|
+
.object({ deviceNonce: exports.keychainBytes32Schema })
|
|
208
|
+
.strict();
|
|
209
|
+
/** `POST /keychain/enrollments/:id/approve`: the `add` entry and the new member's wrap. */
|
|
210
|
+
exports.keychainApproveRequestSchema = zod_1.z
|
|
211
|
+
.object({ entry: exports.keychainEntrySchema, wrap: exports.keychainWrapSchema })
|
|
212
|
+
.strict();
|
|
213
|
+
/** `PUT /keychain/items/:itemId`. `baseRevision` is `null` only for an item that never existed. */
|
|
214
|
+
exports.keychainItemPutRequestSchema = zod_1.z
|
|
215
|
+
.object({
|
|
216
|
+
baseRevision: revisionSchema.nullable(),
|
|
217
|
+
generation: generationSchema,
|
|
218
|
+
nonce: exports.keychainNonceSchema,
|
|
219
|
+
ciphertext: exports.keychainCiphertextSchema,
|
|
220
|
+
})
|
|
221
|
+
.strict();
|
|
222
|
+
/** `DELETE /keychain/items/:itemId`. */
|
|
223
|
+
exports.keychainItemDeleteRequestSchema = zod_1.z.object({ baseRevision: revisionSchema }).strict();
|
|
224
|
+
/** `GET /keychain/items?since=&limit=`. */
|
|
225
|
+
exports.keychainItemsQuerySchema = zod_1.z
|
|
226
|
+
.object({
|
|
227
|
+
since: zod_1.z.coerce.number().check((0, numberChecks_1.integerCheck)()).min(0).max(Number.MAX_SAFE_INTEGER).default(0),
|
|
228
|
+
limit: zod_1.z.coerce
|
|
229
|
+
.number()
|
|
230
|
+
.check((0, numberChecks_1.integerCheck)())
|
|
231
|
+
.min(1)
|
|
232
|
+
.max(keychain_1.KEYCHAIN_LIMITS.maxItemsPage)
|
|
233
|
+
.default(keychain_1.KEYCHAIN_LIMITS.maxItemsPage),
|
|
234
|
+
})
|
|
235
|
+
.strict();
|
|
236
|
+
exports.keychainEnrollmentParamsSchema = zod_1.z.object({ id: exports.keychainIdSchema }).strict();
|
|
237
|
+
exports.keychainItemParamsSchema = zod_1.z.object({ itemId: exports.keychainIdSchema }).strict();
|
|
238
|
+
/**
|
|
239
|
+
* `DELETE /keychain` — the reset (ADR 0063 D6), with a fresh re-verification.
|
|
240
|
+
*
|
|
241
|
+
* - An account WITHOUT a linked root: `reauth` for `reset_keychain` (ADR 0030:
|
|
242
|
+
* its email code, or its password when it has no email; plus its
|
|
243
|
+
* authenticator's code when it has one).
|
|
244
|
+
* - An account WITH a linked root (Commons, which has no email or password to
|
|
245
|
+
* re-verify with): `rootProof`, a root proof for the `keychain_reset` action
|
|
246
|
+
* over the payload `{ vaultId }` (ADR 0024 D7, challenge from
|
|
247
|
+
* `POST /identity/proof-challenge`), plus `totpCode` when it has an
|
|
248
|
+
* authenticator.
|
|
249
|
+
*/
|
|
250
|
+
exports.keychainResetRequestSchema = zod_1.z
|
|
251
|
+
.object({
|
|
252
|
+
reauth: signIn_1.reauthProofSchema.optional(),
|
|
253
|
+
rootProof: identityProof_1.identityProofSchema.optional(),
|
|
254
|
+
totpCode: signIn_1.secondFactorCodeSchema.optional(),
|
|
255
|
+
})
|
|
256
|
+
.strict();
|
|
257
|
+
/* -------------------------------------------------------------------------- */
|
|
258
|
+
/* Responses (mirrored by the checks in ./client/keychain.ts) */
|
|
259
|
+
/* -------------------------------------------------------------------------- */
|
|
260
|
+
const counterSchema = zod_1.z.number().check((0, numberChecks_1.integerCheck)()).nonnegative();
|
|
261
|
+
const positiveIntSchema = zod_1.z.number().check((0, numberChecks_1.integerCheck)()).positive();
|
|
262
|
+
const entryResponseSchema = zod_1.z.object({
|
|
263
|
+
body: zod_1.z.string(),
|
|
264
|
+
signatures: zod_1.z.array(zod_1.z.object({ signer: zod_1.z.string(), signature: zod_1.z.string() })),
|
|
265
|
+
});
|
|
266
|
+
const wrapResponseSchema = zod_1.z.object({
|
|
267
|
+
recipient: zod_1.z.string(),
|
|
268
|
+
generation: positiveIntSchema,
|
|
269
|
+
epk: zod_1.z.string(),
|
|
270
|
+
nonce: zod_1.z.string(),
|
|
271
|
+
ciphertext: zod_1.z.string(),
|
|
272
|
+
signer: zod_1.z.string(),
|
|
273
|
+
signature: zod_1.z.string(),
|
|
274
|
+
});
|
|
275
|
+
const memberResponseSchema = zod_1.z.object({
|
|
276
|
+
id: zod_1.z.string(),
|
|
277
|
+
name: zod_1.z.string(),
|
|
278
|
+
platform: zod_1.z.enum(keychain_1.KEYCHAIN_PLATFORMS),
|
|
279
|
+
signingKey: zod_1.z.string(),
|
|
280
|
+
boxKey: zod_1.z.string(),
|
|
281
|
+
});
|
|
282
|
+
const enrollmentResponseSchema = zod_1.z.object({
|
|
283
|
+
id: zod_1.z.string(),
|
|
284
|
+
vaultId: zod_1.z.string(),
|
|
285
|
+
member: memberResponseSchema,
|
|
286
|
+
commitment: zod_1.z.string(),
|
|
287
|
+
approverNonce: zod_1.z.string().nullable(),
|
|
288
|
+
approverMemberId: zod_1.z.string().nullable(),
|
|
289
|
+
deviceNonce: zod_1.z.string().nullable(),
|
|
290
|
+
status: zod_1.z.enum(keychain_1.KEYCHAIN_ENROLLMENT_STATUSES),
|
|
291
|
+
expiresAt: zod_1.z.string(),
|
|
292
|
+
createdAt: zod_1.z.string(),
|
|
293
|
+
});
|
|
294
|
+
const itemResponseSchema = zod_1.z.object({
|
|
295
|
+
id: zod_1.z.string(),
|
|
296
|
+
revision: counterSchema,
|
|
297
|
+
generation: positiveIntSchema,
|
|
298
|
+
nonce: zod_1.z.string().nullable(),
|
|
299
|
+
ciphertext: zod_1.z.string().nullable(),
|
|
300
|
+
deletedAt: zod_1.z.string().nullable(),
|
|
301
|
+
updatedAt: zod_1.z.string(),
|
|
302
|
+
});
|
|
303
|
+
exports.keychainStateResponseSchema = zod_1.z.object({
|
|
304
|
+
vault: zod_1.z
|
|
305
|
+
.object({
|
|
306
|
+
id: zod_1.z.string(),
|
|
307
|
+
genesisHash: zod_1.z.string(),
|
|
308
|
+
rosterSeq: counterSchema,
|
|
309
|
+
rosterHead: zod_1.z.string(),
|
|
310
|
+
generation: positiveIntSchema,
|
|
311
|
+
revision: counterSchema,
|
|
312
|
+
})
|
|
313
|
+
.nullable(),
|
|
314
|
+
roster: zod_1.z.array(entryResponseSchema),
|
|
315
|
+
members: zod_1.z.array(zod_1.z.object({ id: zod_1.z.string(), orphaned: zod_1.z.boolean(), removed: zod_1.z.boolean() })),
|
|
316
|
+
self: zod_1.z.string().nullable(),
|
|
317
|
+
});
|
|
318
|
+
exports.keychainWrapResponseSchema = zod_1.z.object({
|
|
319
|
+
wrap: wrapResponseSchema,
|
|
320
|
+
});
|
|
321
|
+
exports.keychainEnrollmentResponseSchema = zod_1.z.object({
|
|
322
|
+
enrollment: enrollmentResponseSchema,
|
|
323
|
+
});
|
|
324
|
+
exports.keychainEnrollmentsResponseSchema = zod_1.z.object({
|
|
325
|
+
enrollments: zod_1.z.array(enrollmentResponseSchema),
|
|
326
|
+
});
|
|
327
|
+
exports.keychainItemResponseSchema = zod_1.z.object({
|
|
328
|
+
item: itemResponseSchema,
|
|
329
|
+
});
|
|
330
|
+
exports.keychainItemsResponseSchema = zod_1.z.object({
|
|
331
|
+
items: zod_1.z.array(itemResponseSchema),
|
|
332
|
+
revision: counterSchema,
|
|
333
|
+
more: zod_1.z.boolean(),
|
|
334
|
+
});
|