@oxy.so/contracts 2.1.0 → 2.2.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/.tsbuildinfo +1 -1
- package/dist/cjs/accountEmail.js +83 -0
- package/dist/cjs/identityLink.js +89 -0
- package/dist/cjs/identityProof.js +6 -29
- package/dist/cjs/index.js +35 -49
- package/dist/cjs/webauthn.js +50 -21
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/accountEmail.js +80 -0
- package/dist/esm/identityLink.js +84 -0
- package/dist/esm/identityProof.js +6 -29
- package/dist/esm/index.js +7 -10
- package/dist/esm/webauthn.js +49 -20
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/accountEmail.d.ts +98 -0
- package/dist/types/accountGraph.d.ts +4 -4
- package/dist/types/agency.d.ts +2 -2
- package/dist/types/deviceSession.d.ts +4 -4
- package/dist/types/externalIdentity.d.ts +8 -8
- package/dist/types/identityLink.d.ts +210 -0
- package/dist/types/identityProof.d.ts +15 -42
- package/dist/types/index.d.ts +6 -8
- package/dist/types/inference/accountBilling.d.ts +2 -2
- package/dist/types/inference/embeddings.d.ts +16 -16
- package/dist/types/inference/errors.d.ts +8 -8
- package/dist/types/inference/inbox.d.ts +8 -8
- package/dist/types/inference/providerConnection.d.ts +20 -20
- package/dist/types/inference/request.d.ts +16 -16
- package/dist/types/inference/streamEvents.d.ts +20 -20
- package/dist/types/keyRecovery.d.ts +4 -4
- package/dist/types/sessionStatus.d.ts +2 -2
- package/dist/types/userResponse.d.ts +4 -4
- package/dist/types/webauthn.d.ts +102 -214
- package/package.json +1 -1
- package/dist/cjs/identityMove.js +0 -156
- package/dist/cjs/identityRecovery.js +0 -51
- package/dist/cjs/webIdentityCarrier.js +0 -181
- package/dist/esm/identityMove.js +0 -148
- package/dist/esm/identityRecovery.js +0 -48
- package/dist/esm/webIdentityCarrier.js +0 -178
- package/dist/types/identityMove.d.ts +0 -185
- package/dist/types/identityRecovery.d.ts +0 -246
- package/dist/types/webIdentityCarrier.d.ts +0 -1130
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webIdentityEnvelopeEstablishSchema = exports.webauthnAssertionResponseSchema = exports.webIdentityEnvelopePutSchema = exports.webIdentityEnvelopeActionSchema = exports.webIdentityEnvelopeProofFieldsSchema = exports.webIdentityEnvelopeResponseSchema = exports.webIdentityHolderSchema = exports.webIdentityEnvelopeUploadSchema = exports.webIdentityEnvelopeSchema = exports.webIdentityWrapSchema = exports.webauthnRpIdSchema = exports.webauthnCredentialIdSchema = exports.webIdentityPublicKeySchema = exports.WEB_IDENTITY_SECRET_KINDS = exports.WEB_IDENTITY_ENVELOPE_VERSION = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Web identity holder contract — the sealed envelope that lets a browser hold an
|
|
6
|
-
* account's self-custody root without Oxy ever being able to use it (ADR 0024).
|
|
7
|
-
*
|
|
8
|
-
* A root is a BIP-39 phrase (12–24 words) whose seed's first 32 bytes are the
|
|
9
|
-
* secp256k1 key — exactly the Commons derivation — or, for a few imported
|
|
10
|
-
* identities, a raw private key that never had a phrase. On the web it travels as:
|
|
11
|
-
*
|
|
12
|
-
* secret ── XChaCha20-Poly1305 under a random DEK ──▶ sealedSecret
|
|
13
|
-
* DEK ── XChaCha20-Poly1305 under KEK_i ──▶ wraps[i]
|
|
14
|
-
* KEK_i = HKDF(PRF output of passkey i)
|
|
15
|
-
*
|
|
16
|
-
* The server stores the envelope and can open NONE of it: the PRF output never
|
|
17
|
-
* leaves the user's authenticator, and the secret is never uploaded. The AEAD
|
|
18
|
-
* associated data binds the secret to the root's public key and kind, and each
|
|
19
|
-
* wrap to its credential and RP ID, so a re-labelled or transplanted envelope
|
|
20
|
-
* fails to open instead of decrypting into the wrong identity.
|
|
21
|
-
*
|
|
22
|
-
* Platform-agnostic — zod only, ESM-safe (no `require()`).
|
|
23
|
-
*/
|
|
24
|
-
const zod_1 = require("zod");
|
|
25
|
-
const identityProof_1 = require("./identityProof");
|
|
26
|
-
/** The envelope scheme. A scheme change is a new literal, never a mutation. */
|
|
27
|
-
exports.WEB_IDENTITY_ENVELOPE_VERSION = 2;
|
|
28
|
-
/**
|
|
29
|
-
* What an envelope seals. A raw-key identity stays a raw-key identity:
|
|
30
|
-
* nothing ever derives or displays a phrase for it.
|
|
31
|
-
*/
|
|
32
|
-
exports.WEB_IDENTITY_SECRET_KINDS = ['mnemonic-entropy', 'raw-private-key'];
|
|
33
|
-
const hex = (bytes, label) => zod_1.z
|
|
34
|
-
.string()
|
|
35
|
-
.trim()
|
|
36
|
-
.regex(new RegExp(`^[0-9a-fA-F]{${bytes * 2}}$`), `${label} must be ${bytes * 2} hex characters`);
|
|
37
|
-
/**
|
|
38
|
-
* The identity's secp256k1 public key in Oxy's canonical form: uncompressed SEC1
|
|
39
|
-
* (`04` + 64 bytes), lowercase hex — what `KeyManager.derivePublicKey` produces
|
|
40
|
-
* and `users.public_key` stores.
|
|
41
|
-
*/
|
|
42
|
-
exports.webIdentityPublicKeySchema = zod_1.z
|
|
43
|
-
.string()
|
|
44
|
-
.trim()
|
|
45
|
-
.regex(/^04[0-9a-f]{128}$/, 'publicKey must be an uncompressed, lowercase secp256k1 key (130 hex characters)');
|
|
46
|
-
/** A WebAuthn credential id, base64url as the browser reports it. */
|
|
47
|
-
exports.webauthnCredentialIdSchema = zod_1.z
|
|
48
|
-
.string()
|
|
49
|
-
.trim()
|
|
50
|
-
.min(16)
|
|
51
|
-
.max(1024)
|
|
52
|
-
.regex(/^[A-Za-z0-9_-]+$/, 'credentialId must be base64url');
|
|
53
|
-
/** A WebAuthn RP ID: a bare registrable host name, lowercase. */
|
|
54
|
-
exports.webauthnRpIdSchema = zod_1.z
|
|
55
|
-
.string()
|
|
56
|
-
.trim()
|
|
57
|
-
.min(1)
|
|
58
|
-
.max(253)
|
|
59
|
-
.regex(/^(localhost|[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+)$/, 'rpId must be a lowercase host name');
|
|
60
|
-
/** One passkey's wrap of the envelope's data key. */
|
|
61
|
-
exports.webIdentityWrapSchema = zod_1.z.object({
|
|
62
|
-
credentialId: exports.webauthnCredentialIdSchema,
|
|
63
|
-
/** 24-byte XChaCha20-Poly1305 nonce. */
|
|
64
|
-
nonce: hex(24, 'nonce'),
|
|
65
|
-
/** The 32-byte DEK sealed under this passkey's KEK, with the 16-byte tag appended (48 bytes). */
|
|
66
|
-
wrappedKey: hex(48, 'wrappedKey'),
|
|
67
|
-
createdAt: zod_1.z.string().datetime(),
|
|
68
|
-
/** The RP ID the passkey was created under, asserted explicitly by every later ceremony (ADR 0024 D2). */
|
|
69
|
-
rpId: exports.webauthnRpIdSchema,
|
|
70
|
-
/**
|
|
71
|
-
* When this passkey's PRF output was shown to open the envelope. A wrap is a
|
|
72
|
-
* root HOLDER only once this is set; a login passkey never is by default.
|
|
73
|
-
*/
|
|
74
|
-
verifiedAt: zod_1.z.string().datetime().optional(),
|
|
75
|
-
});
|
|
76
|
-
/**
|
|
77
|
-
* The sealed identity as it is stored (server copy and local copy alike).
|
|
78
|
-
*
|
|
79
|
-
* `wraps` holds one entry per passkey able to open it; at least one, and a
|
|
80
|
-
* bounded number so an envelope cannot grow without limit.
|
|
81
|
-
*/
|
|
82
|
-
exports.webIdentityEnvelopeSchema = zod_1.z
|
|
83
|
-
.object({
|
|
84
|
-
version: zod_1.z.literal(exports.WEB_IDENTITY_ENVELOPE_VERSION),
|
|
85
|
-
algorithm: zod_1.z.literal('xchacha20poly1305'),
|
|
86
|
-
publicKey: exports.webIdentityPublicKeySchema,
|
|
87
|
-
secretKind: zod_1.z.enum(exports.WEB_IDENTITY_SECRET_KINDS),
|
|
88
|
-
/** 24-byte nonce of the secret seal. */
|
|
89
|
-
secretNonce: hex(24, 'secretNonce'),
|
|
90
|
-
/**
|
|
91
|
-
* The sealed secret, tag appended: 16/20/24/28/32 bytes of BIP-39 entropy
|
|
92
|
-
* (12–24 words) or a 32-byte private key, plus 16.
|
|
93
|
-
*/
|
|
94
|
-
sealedSecret: zod_1.z
|
|
95
|
-
.string()
|
|
96
|
-
.trim()
|
|
97
|
-
.regex(/^(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{72}|[0-9a-fA-F]{80}|[0-9a-fA-F]{88}|[0-9a-fA-F]{96})$/, 'sealedSecret has an unsupported length'),
|
|
98
|
-
wraps: zod_1.z.array(exports.webIdentityWrapSchema).min(1).max(10),
|
|
99
|
-
})
|
|
100
|
-
.refine((envelope) => envelope.secretKind === 'mnemonic-entropy' || envelope.sealedSecret.length === 96, {
|
|
101
|
-
message: 'a raw private key seals to 48 bytes',
|
|
102
|
-
path: ['sealedSecret'],
|
|
103
|
-
});
|
|
104
|
-
/**
|
|
105
|
-
* `PUT /identity/web-envelope` — store or replace the caller's envelope.
|
|
106
|
-
*
|
|
107
|
-
* Refused unless `envelope.publicKey` is the identity key already linked to the
|
|
108
|
-
* account: an envelope can only ever carry the account's own identity.
|
|
109
|
-
*/
|
|
110
|
-
exports.webIdentityEnvelopeUploadSchema = zod_1.z.object({
|
|
111
|
-
envelope: exports.webIdentityEnvelopeSchema,
|
|
112
|
-
});
|
|
113
|
-
/** A root holder as the status read reports it — metadata only, nothing that opens anything. */
|
|
114
|
-
exports.webIdentityHolderSchema = zod_1.z.object({
|
|
115
|
-
credentialId: exports.webauthnCredentialIdSchema,
|
|
116
|
-
rpId: exports.webauthnRpIdSchema,
|
|
117
|
-
verifiedAt: zod_1.z.string().datetime().nullable(),
|
|
118
|
-
createdAt: zod_1.z.string().datetime(),
|
|
119
|
-
});
|
|
120
|
-
/**
|
|
121
|
-
* `GET /identity/web-envelope` — the caller's envelope and the readiness facts
|
|
122
|
-
* ADR 0024 D5 keeps separate. A client decides what to show from these fields
|
|
123
|
-
* WITHOUT decrypting anything.
|
|
124
|
-
*/
|
|
125
|
-
exports.webIdentityEnvelopeResponseSchema = zod_1.z.object({
|
|
126
|
-
envelope: exports.webIdentityEnvelopeSchema.nullable(),
|
|
127
|
-
/** The revision a write must name as `expectedRevision`; `0` when there is no envelope. */
|
|
128
|
-
revision: zod_1.z.number().int().nonnegative(),
|
|
129
|
-
/** Whether the account has a linked root at all (it may live only in Commons). */
|
|
130
|
-
rootLinked: zod_1.z.boolean(),
|
|
131
|
-
/** The web wraps, as metadata. */
|
|
132
|
-
holders: zod_1.z.array(exports.webIdentityHolderSchema),
|
|
133
|
-
/** When the owner confirmed the recovery material is written down, or `null`. */
|
|
134
|
-
phraseConfirmedAt: zod_1.z.string().datetime().nullable(),
|
|
135
|
-
/** When the recovery material was shown to re-derive this root, or `null`. */
|
|
136
|
-
recoveryVerifiedAt: zod_1.z.string().datetime().nullable(),
|
|
137
|
-
updatedAt: zod_1.z.string().datetime().nullable(),
|
|
138
|
-
});
|
|
139
|
-
/** A root proof, plus the envelope revision the write expects to replace. */
|
|
140
|
-
exports.webIdentityEnvelopeProofFieldsSchema = zod_1.z.object({
|
|
141
|
-
proof: identityProof_1.identityProofSchema,
|
|
142
|
-
expectedRevision: zod_1.z.number().int().nonnegative(),
|
|
143
|
-
});
|
|
144
|
-
/**
|
|
145
|
-
* `POST /identity/web-envelope/phrase-confirmed`, `/recovery-verified` and
|
|
146
|
-
* `DELETE /identity/web-envelope` prove control of the root, not just a bearer.
|
|
147
|
-
*/
|
|
148
|
-
exports.webIdentityEnvelopeActionSchema = exports.webIdentityEnvelopeProofFieldsSchema.strict();
|
|
149
|
-
/** `PUT /identity/web-envelope` body. */
|
|
150
|
-
exports.webIdentityEnvelopePutSchema = exports.webIdentityEnvelopeUploadSchema.extend(exports.webIdentityEnvelopeProofFieldsSchema.shape).strict();
|
|
151
|
-
/**
|
|
152
|
-
* A WebAuthn assertion by one of the account's EXISTING passkeys whose
|
|
153
|
-
* `clientDataJSON.challenge` is the proof challenge — the fresh use of the
|
|
154
|
-
* existing factor a keyless account needs before its first root is linked.
|
|
155
|
-
*/
|
|
156
|
-
exports.webauthnAssertionResponseSchema = zod_1.z
|
|
157
|
-
.object({
|
|
158
|
-
id: exports.webauthnCredentialIdSchema,
|
|
159
|
-
rawId: zod_1.z.string().min(1).max(2048),
|
|
160
|
-
type: zod_1.z.literal('public-key'),
|
|
161
|
-
response: zod_1.z
|
|
162
|
-
.object({
|
|
163
|
-
clientDataJSON: zod_1.z.string().min(1).max(8192),
|
|
164
|
-
authenticatorData: zod_1.z.string().min(1).max(8192),
|
|
165
|
-
signature: zod_1.z.string().min(1).max(2048),
|
|
166
|
-
userHandle: zod_1.z.string().max(2048).optional(),
|
|
167
|
-
})
|
|
168
|
-
.passthrough(),
|
|
169
|
-
clientExtensionResults: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
|
|
170
|
-
authenticatorAttachment: zod_1.z.string().optional(),
|
|
171
|
-
})
|
|
172
|
-
.passthrough();
|
|
173
|
-
/**
|
|
174
|
-
* `POST /identity/web-envelope/establish` body — an account's FIRST root, linked
|
|
175
|
-
* and stored with its envelope in ONE transaction: one root proof
|
|
176
|
-
* (`web_envelope_establish`, digest of the envelope) plus a fresh `assertion` by
|
|
177
|
-
* an existing passkey over the same challenge.
|
|
178
|
-
*/
|
|
179
|
-
exports.webIdentityEnvelopeEstablishSchema = exports.webIdentityEnvelopeUploadSchema
|
|
180
|
-
.extend({ proof: identityProof_1.identityProofSchema, assertion: exports.webauthnAssertionResponseSchema })
|
|
181
|
-
.strict();
|
package/dist/esm/identityMove.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Identity move contract — give a web root to Commons (add it, or keep it only in
|
|
3
|
-
* Commons; ADR 0024 D6).
|
|
4
|
-
*
|
|
5
|
-
* The web (holding the root) shows a QR carrying only a move id; Commons scans.
|
|
6
|
-
* The relay in between must not be able to take the root, so:
|
|
7
|
-
*
|
|
8
|
-
* 1. `POST /identity/move { initiatorCommitment }` — the web publishes only
|
|
9
|
-
* `H(initiatorKey, nonce)`, never the key.
|
|
10
|
-
* 2. `POST /identity/move/:moveId/join { responderEphemeralPublicKey }` —
|
|
11
|
-
* Commons, having read the commitment first, joins with its own key.
|
|
12
|
-
* 3. `POST /identity/move/:moveId/reveal` — only then does the web reveal its
|
|
13
|
-
* key and nonce; Commons checks them against the commitment it read.
|
|
14
|
-
* 4. Both screens show a 6-digit code over `(moveId, both keys, commitment)`;
|
|
15
|
-
* the person confirms on the web that they match.
|
|
16
|
-
* 5. `POST /identity/move/:moveId/seal` — the web seals the phrase entropy under
|
|
17
|
-
* `HKDF(ECDH(both keys), moveId)`, authorized by a one-use root proof over the
|
|
18
|
-
* exact sealed bytes.
|
|
19
|
-
* 6. `POST /identity/move/:moveId/receipt` — Commons stores the root, reads it
|
|
20
|
-
* back from its keychain, and signs a receipt over the move, the root, both
|
|
21
|
-
* keys and the digest of the ciphertext it opened. The server verifies it; the
|
|
22
|
-
* web verifies it again from what IT sealed before removing anything.
|
|
23
|
-
*
|
|
24
|
-
* Why the commitment: without it the relay sees both keys before committing to
|
|
25
|
-
* anything and can grind a substituted key until the two codes agree (~10⁶
|
|
26
|
-
* tries, seconds). With it, the relay must fix the key it shows Commons before
|
|
27
|
-
* learning Commons' key, and the key it shows the web before the web reveals.
|
|
28
|
-
*
|
|
29
|
-
* The server holds a commitment, two ephemeral public keys, an opaque ciphertext
|
|
30
|
-
* and a receipt — nothing that decrypts the ciphertext.
|
|
31
|
-
*
|
|
32
|
-
* Platform-agnostic — zod only, ESM-safe (no `require()`).
|
|
33
|
-
*/
|
|
34
|
-
import { z } from 'zod';
|
|
35
|
-
import { canonicalJson, identityProofSchema } from './identityProof.js';
|
|
36
|
-
/** A move lives this long: one interactive handoff. */
|
|
37
|
-
export const IDENTITY_MOVE_TTL_MS = 5 * 60 * 1000;
|
|
38
|
-
/** 128-bit move id, lowercase hex. */
|
|
39
|
-
export const identityMoveIdSchema = z
|
|
40
|
-
.string()
|
|
41
|
-
.trim()
|
|
42
|
-
.regex(/^[0-9a-f]{32}$/, 'moveId must be 32 lowercase hex characters');
|
|
43
|
-
/** An ephemeral secp256k1 public key, uncompressed lowercase hex. */
|
|
44
|
-
export const identityMoveEphemeralKeySchema = z
|
|
45
|
-
.string()
|
|
46
|
-
.trim()
|
|
47
|
-
.regex(/^04[0-9a-f]{128}$/, 'ephemeral public key must be uncompressed, lowercase hex');
|
|
48
|
-
export const IDENTITY_MOVE_STATUSES = ['pending', 'joined', 'sealed', 'completed', 'cancelled', 'expired'];
|
|
49
|
-
/** The QR payload Commons scans. Carries the move id only. */
|
|
50
|
-
export const IDENTITY_MOVE_QR_PREFIX = 'oxycommons://move?id=';
|
|
51
|
-
const hex64 = (label) => z.string().trim().regex(/^[0-9a-f]{64}$/, `${label} must be 64 lowercase hex characters`);
|
|
52
|
-
export const identityMoveCreateRequestSchema = z
|
|
53
|
-
.object({
|
|
54
|
-
/** `H(initiator ephemeral key, nonce)` — the key itself is revealed only after Commons joins. */
|
|
55
|
-
initiatorCommitment: hex64('initiatorCommitment'),
|
|
56
|
-
})
|
|
57
|
-
.strict();
|
|
58
|
-
export const identityMoveCreateResponseSchema = z.object({
|
|
59
|
-
moveId: identityMoveIdSchema,
|
|
60
|
-
expiresAt: z.string().datetime(),
|
|
61
|
-
});
|
|
62
|
-
export const identityMoveJoinRequestSchema = z.object({
|
|
63
|
-
responderEphemeralPublicKey: identityMoveEphemeralKeySchema,
|
|
64
|
-
});
|
|
65
|
-
/** After Commons joined: the committed key and its nonce. */
|
|
66
|
-
export const identityMoveRevealRequestSchema = z
|
|
67
|
-
.object({
|
|
68
|
-
initiatorEphemeralPublicKey: identityMoveEphemeralKeySchema,
|
|
69
|
-
commitmentNonce: hex64('commitmentNonce'),
|
|
70
|
-
})
|
|
71
|
-
.strict();
|
|
72
|
-
export const identityMoveSealRequestSchema = z
|
|
73
|
-
.object({
|
|
74
|
-
/** 24-byte XChaCha20-Poly1305 nonce, hex. */
|
|
75
|
-
nonce: z.string().trim().regex(/^[0-9a-f]{48}$/, 'nonce must be 48 lowercase hex characters'),
|
|
76
|
-
/** The 16–32-byte phrase entropy (12–24 words), tag appended, hex. */
|
|
77
|
-
ciphertext: z
|
|
78
|
-
.string()
|
|
79
|
-
.trim()
|
|
80
|
-
.regex(/^(?:[0-9a-f]{64}|[0-9a-f]{72}|[0-9a-f]{80}|[0-9a-f]{88}|[0-9a-f]{96})$/, 'ciphertext has an unsupported length'),
|
|
81
|
-
/**
|
|
82
|
-
* Root proof (`identity_move_seal`), payload `{ moveId, nonce, ciphertext }`,
|
|
83
|
-
* over a one-use challenge from `POST /identity/proof-challenge`.
|
|
84
|
-
*/
|
|
85
|
-
proof: identityProofSchema,
|
|
86
|
-
})
|
|
87
|
-
.strict();
|
|
88
|
-
export const identityMoveReceiptRequestSchema = z
|
|
89
|
-
.object({
|
|
90
|
-
/** Root signature over `buildMoveReceiptMessage(...)`. */
|
|
91
|
-
signature: z.string().trim().min(1).max(512),
|
|
92
|
-
})
|
|
93
|
-
.strict();
|
|
94
|
-
export const identityMoveStateSchema = z.object({
|
|
95
|
-
moveId: identityMoveIdSchema,
|
|
96
|
-
status: z.enum(IDENTITY_MOVE_STATUSES),
|
|
97
|
-
initiatorCommitment: z.string(),
|
|
98
|
-
initiatorCommitmentNonce: z.string().nullable(),
|
|
99
|
-
publicKey: z.string().regex(/^04[0-9a-f]{128}$/),
|
|
100
|
-
initiatorEphemeralPublicKey: identityMoveEphemeralKeySchema.nullable(),
|
|
101
|
-
responderEphemeralPublicKey: identityMoveEphemeralKeySchema.nullable(),
|
|
102
|
-
nonce: z.string().nullable(),
|
|
103
|
-
ciphertext: z.string().nullable(),
|
|
104
|
-
receiptSignature: z.string().nullable(),
|
|
105
|
-
expiresAt: z.string().datetime(),
|
|
106
|
-
});
|
|
107
|
-
/**
|
|
108
|
-
* The initiator's commitment input, `canonicalJson({ v, purpose, key, nonce })`,
|
|
109
|
-
* which the caller hashes with SHA-256.
|
|
110
|
-
*/
|
|
111
|
-
export function buildMoveCommitmentInput(initiatorEphemeralPublicKey, nonce) {
|
|
112
|
-
return canonicalJson({
|
|
113
|
-
v: 2,
|
|
114
|
-
purpose: 'oxy-identity-move-initiator-commitment',
|
|
115
|
-
initiatorEphemeralPublicKey: initiatorEphemeralPublicKey.toLowerCase(),
|
|
116
|
-
nonce: nonce.toLowerCase(),
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/** The bytes both sides hash for the 6-digit code. */
|
|
120
|
-
export function buildMoveSasInput(input) {
|
|
121
|
-
return canonicalJson({
|
|
122
|
-
v: 'oxy-identity-transfer-sas-v2',
|
|
123
|
-
moveId: input.moveId.toLowerCase(),
|
|
124
|
-
initiator: input.initiatorEphemeralPublicKey.toLowerCase(),
|
|
125
|
-
responder: input.responderEphemeralPublicKey.toLowerCase(),
|
|
126
|
-
commitment: input.initiatorCommitment.toLowerCase(),
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/** The ciphertext digest input the receipt binds: `canonicalJson({ nonce, ciphertext })`. */
|
|
130
|
-
export function buildMoveCiphertextDigestInput(sealed) {
|
|
131
|
-
return canonicalJson({ nonce: sealed.nonce.toLowerCase(), ciphertext: sealed.ciphertext.toLowerCase() });
|
|
132
|
-
}
|
|
133
|
-
/** The payload a seal proof digests. */
|
|
134
|
-
export function buildMoveSealPayload(moveId, sealed) {
|
|
135
|
-
return { moveId: moveId.toLowerCase(), nonce: sealed.nonce.toLowerCase(), ciphertext: sealed.ciphertext.toLowerCase() };
|
|
136
|
-
}
|
|
137
|
-
/** The exact bytes a receipt signs. */
|
|
138
|
-
export function buildMoveReceiptMessage(input) {
|
|
139
|
-
return canonicalJson({
|
|
140
|
-
v: 2,
|
|
141
|
-
domain: 'oxy-identity-move-receipt',
|
|
142
|
-
moveId: input.moveId.toLowerCase(),
|
|
143
|
-
rootPublicKey: input.rootPublicKey.toLowerCase(),
|
|
144
|
-
initiator: input.initiatorEphemeralPublicKey.toLowerCase(),
|
|
145
|
-
responder: input.responderEphemeralPublicKey.toLowerCase(),
|
|
146
|
-
ciphertextDigest: input.ciphertextDigest.toLowerCase(),
|
|
147
|
-
});
|
|
148
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Signed-out recovery contract (ADR 0024 D5) — get an EXISTING account back from
|
|
3
|
-
* its root alone, with no passkey, session or email.
|
|
4
|
-
*
|
|
5
|
-
* 1. `POST /identity/recovery/challenge` → a one-use challenge. It says nothing
|
|
6
|
-
* about any account.
|
|
7
|
-
* 2. The holder derives the root locally from recovery material (12/24 words or a
|
|
8
|
-
* raw key) and signs `recover_account_start` over that challenge:
|
|
9
|
-
* `POST /identity/recovery/start { publicKey, proof }`. Only a valid proof
|
|
10
|
-
* learns which account the root belongs to; the response carries passkey
|
|
11
|
-
* registration options for THAT account and a short-lived ticket.
|
|
12
|
-
* 3. The holder creates the passkey, seals the root under it (PRF), and signs
|
|
13
|
-
* `recover_account_complete` over the registration challenge and the envelope
|
|
14
|
-
* digest: `POST /identity/recovery/complete`. The passkey, the envelope and a
|
|
15
|
-
* session are created in one transaction.
|
|
16
|
-
*
|
|
17
|
-
* The recovery material and the root never leave the holder. Platform-agnostic —
|
|
18
|
-
* zod only, ESM-safe.
|
|
19
|
-
*/
|
|
20
|
-
import { z } from 'zod';
|
|
21
|
-
import { identityProofSchema } from './identityProof.js';
|
|
22
|
-
import { webIdentityEnvelopeSchema, webIdentityPublicKeySchema } from './webIdentityCarrier.js';
|
|
23
|
-
/** A recovery attempt lives this long between steps. */
|
|
24
|
-
export const IDENTITY_RECOVERY_TTL_MS = 5 * 60 * 1000;
|
|
25
|
-
export const identityRecoveryChallengeResponseSchema = z.object({
|
|
26
|
-
challenge: z.string().regex(/^[0-9a-f]{64}$/),
|
|
27
|
-
expiresAt: z.number().int().positive(),
|
|
28
|
-
});
|
|
29
|
-
export const identityRecoveryStartRequestSchema = z
|
|
30
|
-
.object({
|
|
31
|
-
publicKey: webIdentityPublicKeySchema,
|
|
32
|
-
/** `recover_account_start`, subject `root:<publicKey>`, actor `anonymous`. */
|
|
33
|
-
proof: identityProofSchema,
|
|
34
|
-
})
|
|
35
|
-
.strict();
|
|
36
|
-
export const identityRecoveryCompleteRequestSchema = z
|
|
37
|
-
.object({
|
|
38
|
-
ticket: z.string().regex(/^[0-9a-f]{64}$/),
|
|
39
|
-
/** The browser `RegistrationResponseJSON`, verified by the API's WebAuthn library. */
|
|
40
|
-
response: z.record(z.string(), z.unknown()),
|
|
41
|
-
/** The root sealed under the new passkey — exactly one wrap, for that credential. */
|
|
42
|
-
envelope: webIdentityEnvelopeSchema,
|
|
43
|
-
/** `recover_account_complete`, subject = account id, actor `credential:<id>`, challenge = registration challenge (hex). */
|
|
44
|
-
proof: identityProofSchema,
|
|
45
|
-
deviceName: z.string().trim().max(100).optional(),
|
|
46
|
-
deviceFingerprint: z.string().trim().max(512).optional(),
|
|
47
|
-
})
|
|
48
|
-
.strict();
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Web identity holder contract — the sealed envelope that lets a browser hold an
|
|
3
|
-
* account's self-custody root without Oxy ever being able to use it (ADR 0024).
|
|
4
|
-
*
|
|
5
|
-
* A root is a BIP-39 phrase (12–24 words) whose seed's first 32 bytes are the
|
|
6
|
-
* secp256k1 key — exactly the Commons derivation — or, for a few imported
|
|
7
|
-
* identities, a raw private key that never had a phrase. On the web it travels as:
|
|
8
|
-
*
|
|
9
|
-
* secret ── XChaCha20-Poly1305 under a random DEK ──▶ sealedSecret
|
|
10
|
-
* DEK ── XChaCha20-Poly1305 under KEK_i ──▶ wraps[i]
|
|
11
|
-
* KEK_i = HKDF(PRF output of passkey i)
|
|
12
|
-
*
|
|
13
|
-
* The server stores the envelope and can open NONE of it: the PRF output never
|
|
14
|
-
* leaves the user's authenticator, and the secret is never uploaded. The AEAD
|
|
15
|
-
* associated data binds the secret to the root's public key and kind, and each
|
|
16
|
-
* wrap to its credential and RP ID, so a re-labelled or transplanted envelope
|
|
17
|
-
* fails to open instead of decrypting into the wrong identity.
|
|
18
|
-
*
|
|
19
|
-
* Platform-agnostic — zod only, ESM-safe (no `require()`).
|
|
20
|
-
*/
|
|
21
|
-
import { z } from 'zod';
|
|
22
|
-
import { identityProofSchema } from './identityProof.js';
|
|
23
|
-
/** The envelope scheme. A scheme change is a new literal, never a mutation. */
|
|
24
|
-
export const WEB_IDENTITY_ENVELOPE_VERSION = 2;
|
|
25
|
-
/**
|
|
26
|
-
* What an envelope seals. A raw-key identity stays a raw-key identity:
|
|
27
|
-
* nothing ever derives or displays a phrase for it.
|
|
28
|
-
*/
|
|
29
|
-
export const WEB_IDENTITY_SECRET_KINDS = ['mnemonic-entropy', 'raw-private-key'];
|
|
30
|
-
const hex = (bytes, label) => z
|
|
31
|
-
.string()
|
|
32
|
-
.trim()
|
|
33
|
-
.regex(new RegExp(`^[0-9a-fA-F]{${bytes * 2}}$`), `${label} must be ${bytes * 2} hex characters`);
|
|
34
|
-
/**
|
|
35
|
-
* The identity's secp256k1 public key in Oxy's canonical form: uncompressed SEC1
|
|
36
|
-
* (`04` + 64 bytes), lowercase hex — what `KeyManager.derivePublicKey` produces
|
|
37
|
-
* and `users.public_key` stores.
|
|
38
|
-
*/
|
|
39
|
-
export const webIdentityPublicKeySchema = z
|
|
40
|
-
.string()
|
|
41
|
-
.trim()
|
|
42
|
-
.regex(/^04[0-9a-f]{128}$/, 'publicKey must be an uncompressed, lowercase secp256k1 key (130 hex characters)');
|
|
43
|
-
/** A WebAuthn credential id, base64url as the browser reports it. */
|
|
44
|
-
export const webauthnCredentialIdSchema = z
|
|
45
|
-
.string()
|
|
46
|
-
.trim()
|
|
47
|
-
.min(16)
|
|
48
|
-
.max(1024)
|
|
49
|
-
.regex(/^[A-Za-z0-9_-]+$/, 'credentialId must be base64url');
|
|
50
|
-
/** A WebAuthn RP ID: a bare registrable host name, lowercase. */
|
|
51
|
-
export const webauthnRpIdSchema = z
|
|
52
|
-
.string()
|
|
53
|
-
.trim()
|
|
54
|
-
.min(1)
|
|
55
|
-
.max(253)
|
|
56
|
-
.regex(/^(localhost|[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+)$/, 'rpId must be a lowercase host name');
|
|
57
|
-
/** One passkey's wrap of the envelope's data key. */
|
|
58
|
-
export const webIdentityWrapSchema = z.object({
|
|
59
|
-
credentialId: webauthnCredentialIdSchema,
|
|
60
|
-
/** 24-byte XChaCha20-Poly1305 nonce. */
|
|
61
|
-
nonce: hex(24, 'nonce'),
|
|
62
|
-
/** The 32-byte DEK sealed under this passkey's KEK, with the 16-byte tag appended (48 bytes). */
|
|
63
|
-
wrappedKey: hex(48, 'wrappedKey'),
|
|
64
|
-
createdAt: z.string().datetime(),
|
|
65
|
-
/** The RP ID the passkey was created under, asserted explicitly by every later ceremony (ADR 0024 D2). */
|
|
66
|
-
rpId: webauthnRpIdSchema,
|
|
67
|
-
/**
|
|
68
|
-
* When this passkey's PRF output was shown to open the envelope. A wrap is a
|
|
69
|
-
* root HOLDER only once this is set; a login passkey never is by default.
|
|
70
|
-
*/
|
|
71
|
-
verifiedAt: z.string().datetime().optional(),
|
|
72
|
-
});
|
|
73
|
-
/**
|
|
74
|
-
* The sealed identity as it is stored (server copy and local copy alike).
|
|
75
|
-
*
|
|
76
|
-
* `wraps` holds one entry per passkey able to open it; at least one, and a
|
|
77
|
-
* bounded number so an envelope cannot grow without limit.
|
|
78
|
-
*/
|
|
79
|
-
export const webIdentityEnvelopeSchema = z
|
|
80
|
-
.object({
|
|
81
|
-
version: z.literal(WEB_IDENTITY_ENVELOPE_VERSION),
|
|
82
|
-
algorithm: z.literal('xchacha20poly1305'),
|
|
83
|
-
publicKey: webIdentityPublicKeySchema,
|
|
84
|
-
secretKind: z.enum(WEB_IDENTITY_SECRET_KINDS),
|
|
85
|
-
/** 24-byte nonce of the secret seal. */
|
|
86
|
-
secretNonce: hex(24, 'secretNonce'),
|
|
87
|
-
/**
|
|
88
|
-
* The sealed secret, tag appended: 16/20/24/28/32 bytes of BIP-39 entropy
|
|
89
|
-
* (12–24 words) or a 32-byte private key, plus 16.
|
|
90
|
-
*/
|
|
91
|
-
sealedSecret: z
|
|
92
|
-
.string()
|
|
93
|
-
.trim()
|
|
94
|
-
.regex(/^(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{72}|[0-9a-fA-F]{80}|[0-9a-fA-F]{88}|[0-9a-fA-F]{96})$/, 'sealedSecret has an unsupported length'),
|
|
95
|
-
wraps: z.array(webIdentityWrapSchema).min(1).max(10),
|
|
96
|
-
})
|
|
97
|
-
.refine((envelope) => envelope.secretKind === 'mnemonic-entropy' || envelope.sealedSecret.length === 96, {
|
|
98
|
-
message: 'a raw private key seals to 48 bytes',
|
|
99
|
-
path: ['sealedSecret'],
|
|
100
|
-
});
|
|
101
|
-
/**
|
|
102
|
-
* `PUT /identity/web-envelope` — store or replace the caller's envelope.
|
|
103
|
-
*
|
|
104
|
-
* Refused unless `envelope.publicKey` is the identity key already linked to the
|
|
105
|
-
* account: an envelope can only ever carry the account's own identity.
|
|
106
|
-
*/
|
|
107
|
-
export const webIdentityEnvelopeUploadSchema = z.object({
|
|
108
|
-
envelope: webIdentityEnvelopeSchema,
|
|
109
|
-
});
|
|
110
|
-
/** A root holder as the status read reports it — metadata only, nothing that opens anything. */
|
|
111
|
-
export const webIdentityHolderSchema = z.object({
|
|
112
|
-
credentialId: webauthnCredentialIdSchema,
|
|
113
|
-
rpId: webauthnRpIdSchema,
|
|
114
|
-
verifiedAt: z.string().datetime().nullable(),
|
|
115
|
-
createdAt: z.string().datetime(),
|
|
116
|
-
});
|
|
117
|
-
/**
|
|
118
|
-
* `GET /identity/web-envelope` — the caller's envelope and the readiness facts
|
|
119
|
-
* ADR 0024 D5 keeps separate. A client decides what to show from these fields
|
|
120
|
-
* WITHOUT decrypting anything.
|
|
121
|
-
*/
|
|
122
|
-
export const webIdentityEnvelopeResponseSchema = z.object({
|
|
123
|
-
envelope: webIdentityEnvelopeSchema.nullable(),
|
|
124
|
-
/** The revision a write must name as `expectedRevision`; `0` when there is no envelope. */
|
|
125
|
-
revision: z.number().int().nonnegative(),
|
|
126
|
-
/** Whether the account has a linked root at all (it may live only in Commons). */
|
|
127
|
-
rootLinked: z.boolean(),
|
|
128
|
-
/** The web wraps, as metadata. */
|
|
129
|
-
holders: z.array(webIdentityHolderSchema),
|
|
130
|
-
/** When the owner confirmed the recovery material is written down, or `null`. */
|
|
131
|
-
phraseConfirmedAt: z.string().datetime().nullable(),
|
|
132
|
-
/** When the recovery material was shown to re-derive this root, or `null`. */
|
|
133
|
-
recoveryVerifiedAt: z.string().datetime().nullable(),
|
|
134
|
-
updatedAt: z.string().datetime().nullable(),
|
|
135
|
-
});
|
|
136
|
-
/** A root proof, plus the envelope revision the write expects to replace. */
|
|
137
|
-
export const webIdentityEnvelopeProofFieldsSchema = z.object({
|
|
138
|
-
proof: identityProofSchema,
|
|
139
|
-
expectedRevision: z.number().int().nonnegative(),
|
|
140
|
-
});
|
|
141
|
-
/**
|
|
142
|
-
* `POST /identity/web-envelope/phrase-confirmed`, `/recovery-verified` and
|
|
143
|
-
* `DELETE /identity/web-envelope` prove control of the root, not just a bearer.
|
|
144
|
-
*/
|
|
145
|
-
export const webIdentityEnvelopeActionSchema = webIdentityEnvelopeProofFieldsSchema.strict();
|
|
146
|
-
/** `PUT /identity/web-envelope` body. */
|
|
147
|
-
export const webIdentityEnvelopePutSchema = webIdentityEnvelopeUploadSchema.extend(webIdentityEnvelopeProofFieldsSchema.shape).strict();
|
|
148
|
-
/**
|
|
149
|
-
* A WebAuthn assertion by one of the account's EXISTING passkeys whose
|
|
150
|
-
* `clientDataJSON.challenge` is the proof challenge — the fresh use of the
|
|
151
|
-
* existing factor a keyless account needs before its first root is linked.
|
|
152
|
-
*/
|
|
153
|
-
export const webauthnAssertionResponseSchema = z
|
|
154
|
-
.object({
|
|
155
|
-
id: webauthnCredentialIdSchema,
|
|
156
|
-
rawId: z.string().min(1).max(2048),
|
|
157
|
-
type: z.literal('public-key'),
|
|
158
|
-
response: z
|
|
159
|
-
.object({
|
|
160
|
-
clientDataJSON: z.string().min(1).max(8192),
|
|
161
|
-
authenticatorData: z.string().min(1).max(8192),
|
|
162
|
-
signature: z.string().min(1).max(2048),
|
|
163
|
-
userHandle: z.string().max(2048).optional(),
|
|
164
|
-
})
|
|
165
|
-
.passthrough(),
|
|
166
|
-
clientExtensionResults: z.record(z.string(), z.unknown()).optional(),
|
|
167
|
-
authenticatorAttachment: z.string().optional(),
|
|
168
|
-
})
|
|
169
|
-
.passthrough();
|
|
170
|
-
/**
|
|
171
|
-
* `POST /identity/web-envelope/establish` body — an account's FIRST root, linked
|
|
172
|
-
* and stored with its envelope in ONE transaction: one root proof
|
|
173
|
-
* (`web_envelope_establish`, digest of the envelope) plus a fresh `assertion` by
|
|
174
|
-
* an existing passkey over the same challenge.
|
|
175
|
-
*/
|
|
176
|
-
export const webIdentityEnvelopeEstablishSchema = webIdentityEnvelopeUploadSchema
|
|
177
|
-
.extend({ proof: identityProofSchema, assertion: webauthnAssertionResponseSchema })
|
|
178
|
-
.strict();
|