@941design/marmot-engine 0.2.0-alpha.0 → 0.2.0-alpha.1
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/CHANGELOG.md +43 -0
- package/LICENSE +4 -0
- package/README.md +2 -2
- package/dist/core/components/ids.d.ts +19 -0
- package/dist/core/components/ids.js +19 -0
- package/dist/core/group.d.ts +11 -0
- package/dist/core/group.js +21 -4
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/key-package-event-encode.js +19 -4
- package/dist/core/key-package.d.ts +12 -1
- package/dist/core/key-package.js +33 -1
- package/dist/core/protocol-profile.d.ts +262 -0
- package/dist/core/protocol-profile.js +535 -0
- package/dist/engine/admin-policy.d.ts +17 -0
- package/dist/engine/group-engine.js +24 -2
- package/dist/version.d.ts +4 -4
- package/dist/version.js +3 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @941design/marmot-engine
|
|
2
2
|
|
|
3
|
+
## 0.2.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9659431: The `adminPolicyCallback` factory argument gains an optional `groupContext`: the GroupContext of the state the judged
|
|
8
|
+
message is processed against (for a commit, its parent epoch). The engine passes it on every path that builds the
|
|
9
|
+
callback (ingest, fork recovery, tree replay, witness collection). The vendored rule (`createAdminCommitPolicyCallback`)
|
|
10
|
+
ignores it, so engine behaviour with the default callback is unchanged. An override can now decide against the group
|
|
11
|
+
context of the commit's own epoch, which the ratchet tree alone cannot answer (`@941design/marmot` gates same-account
|
|
12
|
+
commits on `requires0x800d` with it, ADR-023). `ENGINE_STATE_FORMAT` is unchanged.
|
|
13
|
+
- 9659431: Profile-keyed account identity proof (MDK v0.19.0 interop, spec DD-0/DD-7). New in `/core`:
|
|
14
|
+
|
|
15
|
+
- `profileOf(groupContext)` returns `'legacy'`, `'current'` or `{ invalid }`, and `requires0x800d(groupContext)` is
|
|
16
|
+
the protocol-profile seam. A group is Legacy when its `required_capabilities` list `0xf2f1` and its `app_components`
|
|
17
|
+
(`0x0001`) list lacks `0x8009`. It is Current when it is the other way round. Both, neither, or `0x8009` state in the
|
|
18
|
+
GroupContext is invalid.
|
|
19
|
+
- The Current proof codec (`encode`/`decode`/`verifyCurrentAccountIdentityProofForKey`,
|
|
20
|
+
`buildCurrentAccountIdentityProofEvent`, `signCurrentAccountIdentityProof`) uses MDK's byte layout and signed message:
|
|
21
|
+
a 104-byte component `0x8009` (account ‖ created_at u64 BE ‖ BIP-340 signature over the kind-450 Current event).
|
|
22
|
+
- `verifyLeafAccountIdentityProofForProfile` / `checkLeafAccountIdentityProof` accept a leaf only in a single form and
|
|
23
|
+
reject with a typed `AccountIdentityProofFailure` (`both-forms`, `no-proof`, `wrong-form`, `proof-not-advertised`,
|
|
24
|
+
`proof-wrong-length`, `proof-invalid-timestamp`, `proof-account-mismatch`, `proof-signature-invalid`, …).
|
|
25
|
+
- Component ids `ACCOUNT_IDENTITY_PROOF_COMPONENT_ID` (`0x8009`), `GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID` (`0x800b`),
|
|
26
|
+
`ACCOUNT_DEVICES_COMPONENT_ID` (`0x800d`) and `PRIVATE_USE_APP_COMPONENT_ID_START`.
|
|
27
|
+
- `generateKeyPackage({ profile: 'current', currentProof })` builds a Current-form KeyPackage, and
|
|
28
|
+
`createGroup` / `createSimpleGroup` take `{ profile: 'current' }` for a Current group. The default stays
|
|
29
|
+
`'legacy'`, and that path is unchanged.
|
|
30
|
+
|
|
31
|
+
Not breaking for anything this library produced before. Legacy KeyPackages, groups, leaves and their event tags are
|
|
32
|
+
byte-identical, and `verifyLeafAccountIdentityProof` (Legacy only) is unchanged. One behaviour change, for Current-form leaves only: `createKeyPackageEvent` derives the `app_components` tag from the
|
|
33
|
+
leaf's own list and emits `mls_extensions` / `mls_proposals` ascending. The tags then exactly match the KeyPackage
|
|
34
|
+
metadata, as MDK v0.19.0 requires. The library re-emits MDK's own published KeyPackage tags byte for byte. Before, the
|
|
35
|
+
`app_components` tag listed `SUPPORTED_APP_COMPONENT_IDS`.
|
|
36
|
+
`ENGINE_STATE_FORMAT` is unchanged, and the state-format ledger entry records why.
|
|
37
|
+
|
|
38
|
+
New Current groups place the application-data dictionary last in the MLS GroupContext. This lets MDK v0.19.0 and the library derive the same epoch keys after routing updates and account-device activation. The migration guide covers earlier experimental Current groups.
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- c470a67: Report the released package version in the engine build identifier.
|
|
43
|
+
- 9659431: Name the vendored engine's true upstream: the README, LICENSE notice, package description and VENDOR.md now all cite https://github.com/marmot-protocol/marmot-ts at commit 50192e117e986d894c16ea1f8922600dc33a0db3 instead of a `dark-matter` branch that the repository does not have. VENDOR.md records when the pin commit was last confirmed reachable and how to check it again.
|
|
44
|
+
- 9659431: Fix a settle check that could stall after its timer fired early. When the settle timer fires before its cutoff on the engine clock, the engine now re-arms it for the remaining time and does not wake the owner too soon. A `driveConvergence()` call before the cutoff also arms the check if no timer is pending. Before this fix, a held disband (or retained input) waited for some unrelated new input. Now it settles from the timers alone, and `group.disbanded` becomes defined without the disband being delivered again. At most one settle timer per group is ever pending.
|
|
45
|
+
|
|
3
46
|
## 0.2.0-alpha.0
|
|
4
47
|
|
|
5
48
|
### Minor Changes
|
package/LICENSE
CHANGED
|
@@ -2,6 +2,10 @@ MIT License
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026 Markus Rother
|
|
4
4
|
|
|
5
|
+
Vendored portions from marmot-protocol/marmot-ts, commit
|
|
6
|
+
50192e117e986d894c16ea1f8922600dc33a0db3:
|
|
7
|
+
Copyright (c) 2026 Internet Privacy Foundation
|
|
8
|
+
|
|
5
9
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
10
|
of this software and associated documentation files (the "Software"), to deal
|
|
7
11
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# `@941design/marmot-engine`
|
|
2
2
|
|
|
3
3
|
The MLS convergence engine behind `@941design/marmot`: the `core`, `engine`
|
|
4
|
-
and `audit` modules of [`marmot-
|
|
5
|
-
(
|
|
4
|
+
and `audit` modules of [`marmot-protocol/marmot-ts` at commit
|
|
5
|
+
`50192e117e986d894c16ea1f8922600dc33a0db3`](https://github.com/marmot-protocol/marmot-ts/commit/50192e117e986d894c16ea1f8922600dc33a0db3), ported onto the
|
|
6
6
|
[`ts-mls`](https://github.com/LukaJCB/ts-mls) API and patched locally.
|
|
7
7
|
|
|
8
8
|
Most applications should depend on `@941design/marmot` instead; this package
|
|
@@ -43,7 +43,26 @@ export declare const GROUP_MESSAGE_RETENTION_COMPONENT_ID: AppComponentId;
|
|
|
43
43
|
export declare const AGENT_TEXT_STREAM_QUIC_COMPONENT_ID: AppComponentId;
|
|
44
44
|
export declare const GROUP_AVATAR_URL_COMPONENT_ID: AppComponentId;
|
|
45
45
|
export declare const GROUP_ENCRYPTED_MEDIA_COMPONENT_ID: AppComponentId;
|
|
46
|
+
/**
|
|
47
|
+
* `marmot.account-identity-proof` Current form (MDK v0.19.0 `ACCOUNT_IDENTITY_PROOF_COMPONENT_ID`): a LeafNode-only
|
|
48
|
+
* component carrying the 104-byte proof in the leaf's `app_data_dictionary`. A GroupContext lists it only in its
|
|
49
|
+
* `app_components` (`0x0001`) list — that marks the group Current (`protocol-profile.ts`); GroupContext state under
|
|
50
|
+
* this id is invalid.
|
|
51
|
+
*/
|
|
52
|
+
export declare const ACCOUNT_IDENTITY_PROOF_COMPONENT_ID: AppComponentId;
|
|
53
|
+
/** `marmot.group.encrypted-media.v2` (MDK v0.19.0 `GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID`). No codec here. */
|
|
54
|
+
export declare const GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID: AppComponentId;
|
|
46
55
|
export declare const GROUP_LIFECYCLE_COMPONENT_ID: AppComponentId;
|
|
56
|
+
/**
|
|
57
|
+
* `marmot.group.account-devices.v1` (MDK v0.19.0 `ACCOUNT_DEVICES_COMPONENT_ID`): no data anywhere; its id in a
|
|
58
|
+
* Current group's `0x0001` list means the group requires it (same-account commits, `requires0x800d`).
|
|
59
|
+
*/
|
|
60
|
+
export declare const ACCOUNT_DEVICES_COMPONENT_ID: AppComponentId;
|
|
61
|
+
/**
|
|
62
|
+
* The first private-use component id. Kind 30443 KeyPackage events advertise only ids at or above it in their
|
|
63
|
+
* `app_components` tag (MDK `PRIVATE_USE_APP_COMPONENT_ID_START`).
|
|
64
|
+
*/
|
|
65
|
+
export declare const PRIVATE_USE_APP_COMPONENT_ID_START: AppComponentId;
|
|
47
66
|
/** Human-readable component names (the `v1` suffix is part of the name). */
|
|
48
67
|
export declare const GROUP_PROFILE_COMPONENT = "marmot.group.profile.v1";
|
|
49
68
|
export declare const GROUP_BLOSSOM_IMAGE_COMPONENT = "marmot.group.blossom.image.v1";
|
|
@@ -29,7 +29,26 @@ export const GROUP_MESSAGE_RETENTION_COMPONENT_ID = 0x8005;
|
|
|
29
29
|
export const AGENT_TEXT_STREAM_QUIC_COMPONENT_ID = 0x8006;
|
|
30
30
|
export const GROUP_AVATAR_URL_COMPONENT_ID = 0x8007;
|
|
31
31
|
export const GROUP_ENCRYPTED_MEDIA_COMPONENT_ID = 0x8008;
|
|
32
|
+
/**
|
|
33
|
+
* `marmot.account-identity-proof` Current form (MDK v0.19.0 `ACCOUNT_IDENTITY_PROOF_COMPONENT_ID`): a LeafNode-only
|
|
34
|
+
* component carrying the 104-byte proof in the leaf's `app_data_dictionary`. A GroupContext lists it only in its
|
|
35
|
+
* `app_components` (`0x0001`) list — that marks the group Current (`protocol-profile.ts`); GroupContext state under
|
|
36
|
+
* this id is invalid.
|
|
37
|
+
*/
|
|
38
|
+
export const ACCOUNT_IDENTITY_PROOF_COMPONENT_ID = 0x8009;
|
|
39
|
+
/** `marmot.group.encrypted-media.v2` (MDK v0.19.0 `GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID`). No codec here. */
|
|
40
|
+
export const GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID = 0x800b;
|
|
32
41
|
export const GROUP_LIFECYCLE_COMPONENT_ID = 0x800c;
|
|
42
|
+
/**
|
|
43
|
+
* `marmot.group.account-devices.v1` (MDK v0.19.0 `ACCOUNT_DEVICES_COMPONENT_ID`): no data anywhere; its id in a
|
|
44
|
+
* Current group's `0x0001` list means the group requires it (same-account commits, `requires0x800d`).
|
|
45
|
+
*/
|
|
46
|
+
export const ACCOUNT_DEVICES_COMPONENT_ID = 0x800d;
|
|
47
|
+
/**
|
|
48
|
+
* The first private-use component id. Kind 30443 KeyPackage events advertise only ids at or above it in their
|
|
49
|
+
* `app_components` tag (MDK `PRIVATE_USE_APP_COMPONENT_ID_START`).
|
|
50
|
+
*/
|
|
51
|
+
export const PRIVATE_USE_APP_COMPONENT_ID_START = 0x8000;
|
|
33
52
|
/** Human-readable component names (the `v1` suffix is part of the name). */
|
|
34
53
|
export const GROUP_PROFILE_COMPONENT = "marmot.group.profile.v1";
|
|
35
54
|
export const GROUP_BLOSSOM_IMAGE_COMPONENT = "marmot.group.blossom.image.v1";
|
package/dist/core/group.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CiphersuiteImpl, ClientConfig, ClientState, ComponentData, GroupContextExtension } from "ts-mls";
|
|
2
2
|
import { AppComponentId } from "./components/index.js";
|
|
3
3
|
import { CompleteKeyPackage } from "./key-package.js";
|
|
4
|
+
import { type ProtocolProfile } from "./protocol-profile.js";
|
|
4
5
|
export interface CreateGroupParams {
|
|
5
6
|
/** Creator's complete key package (public + private) */
|
|
6
7
|
creatorKeyPackage: CompleteKeyPackage;
|
|
@@ -25,6 +26,14 @@ export interface CreateGroupParams {
|
|
|
25
26
|
* (AC-VENDOR-6). Defaults to ts-mls's own default when omitted.
|
|
26
27
|
*/
|
|
27
28
|
clientConfig?: ClientConfig;
|
|
29
|
+
/**
|
|
30
|
+
* The group's protocol profile (spec DD-0, `protocol-profile.ts`). `"legacy"` (the default): `required_capabilities`
|
|
31
|
+
* lists `0xf2f1`, exactly as before profiles existed. `"current"`: `0x8009` joins the `app_components` (`0x0001`)
|
|
32
|
+
* list and `required_capabilities` omits `0xf2f1`. The creator's KeyPackage must carry the proof in the same form.
|
|
33
|
+
* Throws when the resulting GroupContext does not classify as `profile` (e.g. a Legacy group asked to require
|
|
34
|
+
* `0x8009`, or caller-supplied `required_capabilities` that contradict the profile).
|
|
35
|
+
*/
|
|
36
|
+
profile?: ProtocolProfile;
|
|
28
37
|
}
|
|
29
38
|
export interface CreateGroupResult {
|
|
30
39
|
/** The ClientState for the created group */
|
|
@@ -35,6 +44,8 @@ export type SimpleGroupOptions = {
|
|
|
35
44
|
description?: string;
|
|
36
45
|
adminPubkeys?: string[];
|
|
37
46
|
relays?: string[];
|
|
47
|
+
/** The group's protocol profile ({@link CreateGroupParams.profile}); default `"legacy"`. */
|
|
48
|
+
profile?: ProtocolProfile;
|
|
38
49
|
};
|
|
39
50
|
/**
|
|
40
51
|
* Creates a Marmot v2 group seeded with the default group components: a
|
package/dist/core/group.js
CHANGED
|
@@ -5,17 +5,21 @@ import { marmotAuthService } from "./auth-service.js";
|
|
|
5
5
|
import { marmotRequiredCapabilitiesExtension } from "./capabilities.js";
|
|
6
6
|
import { adminPolicyEntry, appComponentsEntry, DEFAULT_GROUP_COMPONENT_IDS, GROUP_LIFECYCLE_COMPONENT_ID, groupLifecycleEntry, groupProtocolLifecycleValues, groupProfileEntry, makeAppComponentsExtension, nostrRoutingEntry, } from "./components/index.js";
|
|
7
7
|
import { getCredentialPubkey } from "./credential.js";
|
|
8
|
+
import { ACCOUNT_IDENTITY_PROOF_COMPONENT_ID } from "./components/ids.js";
|
|
9
|
+
import { marmotRequiredCapabilitiesExtensionForProfile, profileOf, } from "./protocol-profile.js";
|
|
8
10
|
export async function createGroup(params) {
|
|
9
|
-
const { creatorKeyPackage, components, requiredComponentIds, extensions = [], ciphersuiteImpl, clientConfig, } = params;
|
|
11
|
+
const { creatorKeyPackage, components, requiredComponentIds, extensions = [], ciphersuiteImpl, clientConfig, profile = "legacy", } = params;
|
|
10
12
|
// The MLS group_id MUST be private and distinct from the public
|
|
11
13
|
// nostr_group_id carried by the transport.nostr.routing component.
|
|
12
14
|
const groupId = randomBytes(32);
|
|
13
15
|
// Advertise the required component ids (defaults to whatever was provided),
|
|
14
16
|
// then seed each component's state into the app_data_dictionary extension.
|
|
17
|
+
// A Current group requires the proof component 0x8009 (spec DD-0).
|
|
15
18
|
const requiredIds = [
|
|
16
19
|
...new Set([
|
|
17
20
|
...DEFAULT_GROUP_COMPONENT_IDS,
|
|
18
21
|
...(requiredComponentIds ?? components.map((c) => c.componentId)),
|
|
22
|
+
...(profile === "current" ? [ACCOUNT_IDENTITY_PROOF_COMPONENT_ID] : []),
|
|
19
23
|
]),
|
|
20
24
|
];
|
|
21
25
|
const initialComponents = components.some((component) => component.componentId === GROUP_LIFECYCLE_COMPONENT_ID)
|
|
@@ -29,11 +33,23 @@ export async function createGroup(params) {
|
|
|
29
33
|
// MLS enforces them on every add (capability-negotiation.md §5.2). A caller
|
|
30
34
|
// may override by supplying their own required_capabilities in `extensions`.
|
|
31
35
|
const hasRequiredCapabilities = extensions.some((e) => e.extensionType === marmotRequiredCapabilitiesExtension().extensionType);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
const otherExtensions = [
|
|
37
|
+
...(hasRequiredCapabilities
|
|
38
|
+
? []
|
|
39
|
+
: [marmotRequiredCapabilitiesExtensionForProfile(profile)]),
|
|
35
40
|
...extensions,
|
|
36
41
|
];
|
|
42
|
+
// An AppDataUpdate replaces this extension in place in ts-mls. OpenMLS removes
|
|
43
|
+
// it and appends the updated dictionary. Starting Current groups with the
|
|
44
|
+
// dictionary last keeps their authenticated next-epoch GroupContexts identical.
|
|
45
|
+
const groupExtensions = profile === "current"
|
|
46
|
+
? [...otherExtensions, appDataExtension]
|
|
47
|
+
: [appDataExtension, ...otherExtensions];
|
|
48
|
+
// Checked only when a profile is asked for: a caller that omits it gets exactly the group it got before profiles
|
|
49
|
+
// existed (its own `required_capabilities` included).
|
|
50
|
+
const classified = profileOf({ extensions: groupExtensions });
|
|
51
|
+
if (params.profile !== undefined && classified !== profile)
|
|
52
|
+
throw new Error(`createGroup: the group context classifies as ${typeof classified === "string" ? classified : `invalid (${classified.invalid})`}, not ${profile}`);
|
|
37
53
|
const clientState = await MLSCreateGroup({
|
|
38
54
|
context: {
|
|
39
55
|
cipherSuite: ciphersuiteImpl,
|
|
@@ -74,5 +90,6 @@ export async function createSimpleGroup(creatorKeyPackage, ciphersuiteImpl, grou
|
|
|
74
90
|
creatorKeyPackage,
|
|
75
91
|
components,
|
|
76
92
|
ciphersuiteImpl,
|
|
93
|
+
...(options?.profile === undefined ? {} : { profile: options.profile }),
|
|
77
94
|
});
|
|
78
95
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from "./leaf-succession.js";
|
|
|
23
23
|
export * from "./relay-lists.js";
|
|
24
24
|
export * from "./media.js";
|
|
25
25
|
export * from "./protocol.js";
|
|
26
|
+
export * from "./protocol-profile.js";
|
|
26
27
|
export * from "./transport.js";
|
|
27
28
|
export * from "./retained-history.js";
|
|
28
29
|
export * from "./welcome.js";
|
package/dist/core/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./leaf-succession.js";
|
|
|
21
21
|
export * from "./relay-lists.js";
|
|
22
22
|
export * from "./media.js";
|
|
23
23
|
export * from "./protocol.js";
|
|
24
|
+
export * from "./protocol-profile.js";
|
|
24
25
|
export * from "./transport.js";
|
|
25
26
|
export * from "./retained-history.js";
|
|
26
27
|
export * from "./welcome.js";
|
|
@@ -7,7 +7,8 @@ import { isValidRelayUrl, normalizeRelayUrl } from "../utils/relay-url.js";
|
|
|
7
7
|
import { isGreaseValue } from "./grease.js";
|
|
8
8
|
import { calculateKeyPackageRef } from "./key-package.js";
|
|
9
9
|
import { ADDRESSABLE_KEY_PACKAGE_KIND, KEY_PACKAGE_APP_COMPONENTS_TAG, KEY_PACKAGE_CIPHER_SUITE_TAG, KEY_PACKAGE_CLIENT_TAG, KEY_PACKAGE_EXTENSIONS_TAG, KEY_PACKAGE_MLS_VERSION_TAG, KEY_PACKAGE_PROPOSALS_TAG, KEY_PACKAGE_RELAYS_TAG, } from "./protocol.js";
|
|
10
|
-
import { SUPPORTED_APP_COMPONENT_IDS } from "./components/ids.js";
|
|
10
|
+
import { PRIVATE_USE_APP_COMPONENT_ID_START, SUPPORTED_APP_COMPONENT_IDS } from "./components/ids.js";
|
|
11
|
+
import { leafAppComponents, leafProofForm } from "./protocol-profile.js";
|
|
11
12
|
/**
|
|
12
13
|
* Creates an addressable key package event (kind 30443) from a key package.
|
|
13
14
|
*
|
|
@@ -78,11 +79,25 @@ async function createKeyPackageEventInternal(options) {
|
|
|
78
79
|
const proposalTypes = (keyPackage.leafNode.capabilities?.proposals ?? [])
|
|
79
80
|
.filter((p) => !isGreaseValue(p))
|
|
80
81
|
.map((p) => `0x${p.toString(16).padStart(4, "0")}`);
|
|
81
|
-
//
|
|
82
|
-
|
|
82
|
+
// A Current-form leaf (epic marmot-mdk-interop S7, spec DD-7): the private-use
|
|
83
|
+
// app-component ids the leaf itself advertises in its `app_components`
|
|
84
|
+
// (`0x0001`) list — what MDK's KeyPackage metadata reads and its kind-30443
|
|
85
|
+
// tag check compares against exactly. Any other leaf keeps the previous
|
|
86
|
+
// advertisement (SUPPORTED_APP_COMPONENT_IDS), byte for byte.
|
|
87
|
+
let leafListed;
|
|
88
|
+
try {
|
|
89
|
+
leafListed = leafProofForm(keyPackage.leafNode) === "current" ? leafAppComponents(keyPackage.leafNode) : undefined;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
leafListed = undefined;
|
|
93
|
+
}
|
|
94
|
+
const appComponentIds = (leafListed?.filter((id) => id >= PRIVATE_USE_APP_COMPONENT_ID_START) ??
|
|
95
|
+
SUPPORTED_APP_COMPONENT_IDS).map((id) => `0x${id.toString(16).padStart(4, "0")}`);
|
|
83
96
|
// The spec forbids an `encoding` tag (transports/nostr.md "Transport byte
|
|
84
97
|
// encoding"); content is always standard base64.
|
|
85
|
-
tags.push([KEY_PACKAGE_MLS_VERSION_TAG, version], ["i", bytesToHex(keyPackageRef)], [KEY_PACKAGE_CIPHER_SUITE_TAG, ciphersuiteHex],
|
|
98
|
+
tags.push([KEY_PACKAGE_MLS_VERSION_TAG, version], ["i", bytesToHex(keyPackageRef)], [KEY_PACKAGE_CIPHER_SUITE_TAG, ciphersuiteHex],
|
|
99
|
+
// A Current-form leaf's lists go out ascending, as MDK publishes its own (BTreeSet order; equal-width lowercase hex).
|
|
100
|
+
[KEY_PACKAGE_EXTENSIONS_TAG, ...(leafListed === undefined ? filteredExtensionTypes : [...filteredExtensionTypes].sort())], [KEY_PACKAGE_PROPOSALS_TAG, ...(leafListed === undefined ? proposalTypes : [...proposalTypes].sort())], [KEY_PACKAGE_APP_COMPONENTS_TAG, ...appComponentIds]);
|
|
86
101
|
// Add client tag if provided
|
|
87
102
|
if (client)
|
|
88
103
|
tags.push([KEY_PACKAGE_CLIENT_TAG, client]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @module @category Core - Key Package */
|
|
2
2
|
import { Capabilities, Credential, CryptoProvider, CiphersuiteImpl, CustomExtension, KeyPackage, Lifetime, PrivateKeyPackage } from "ts-mls";
|
|
3
3
|
import { type AccountIdentityProofSigner } from "./account-identity-proof.js";
|
|
4
|
+
import { type CurrentProofProvider, type ProtocolProfile } from "./protocol-profile.js";
|
|
4
5
|
/**
|
|
5
6
|
* A complete key package containing both public and private components.
|
|
6
7
|
*
|
|
@@ -49,7 +50,17 @@ export type GenerateKeyPackageOptions = {
|
|
|
49
50
|
* interop with darkmatter, which validates this proof on every leaf.
|
|
50
51
|
*/
|
|
51
52
|
accountProofSigner?: AccountIdentityProofSigner;
|
|
53
|
+
/**
|
|
54
|
+
* The proof form (spec DD-7, `protocol-profile.ts`). `"legacy"` (the default): the `0xf2f1` LeafNode extension and
|
|
55
|
+
* {@link ensureMarmotCapabilities}, exactly as before profiles existed. `"current"`: the 104-byte proof as component
|
|
56
|
+
* `0x8009` in the leaf's `app_data_dictionary` (advertised in its `app_components`, with
|
|
57
|
+
* `CURRENT_PROFILE_LEAF_APP_COMPONENT_IDS`), no `0xf2f1` capability, no GREASE proposal type. A Current KeyPackage
|
|
58
|
+
* always carries a proof: {@link currentProof}, or else an `accountProofSigner` of the `{ signEvent }` shape.
|
|
59
|
+
*/
|
|
60
|
+
profile?: ProtocolProfile;
|
|
61
|
+
/** The Current proof for the generated leaf key (`profile: "current"` only); see {@link CurrentProofProvider}. */
|
|
62
|
+
currentProof?: CurrentProofProvider;
|
|
52
63
|
ciphersuiteImpl: CiphersuiteImpl;
|
|
53
64
|
};
|
|
54
65
|
/** Generate a marmot key package that is compliant with MIP-00 */
|
|
55
|
-
export declare function generateKeyPackage({ credential, capabilities, lifetime, extensions, isLastResort, accountProofSigner, ciphersuiteImpl, }: GenerateKeyPackageOptions): Promise<CompleteKeyPackage>;
|
|
66
|
+
export declare function generateKeyPackage({ credential, capabilities, lifetime, extensions, isLastResort, accountProofSigner, profile, currentProof, ciphersuiteImpl, }: GenerateKeyPackageOptions): Promise<CompleteKeyPackage>;
|
package/dist/core/key-package.js
CHANGED
|
@@ -7,6 +7,7 @@ import { ensureMarmotCapabilities } from "./capabilities.js";
|
|
|
7
7
|
import { componentEntry, LAST_RESORT_COMPONENT_ID, makeAppComponentsExtension, makeLeafAppComponentsExtension, } from "./components/index.js";
|
|
8
8
|
import { getCredentialPubkey } from "./credential.js";
|
|
9
9
|
import { defaultCapabilities } from "./default-capabilities.js";
|
|
10
|
+
import { makeCurrentLeafAppDataExtension, marmotCapabilitiesForProfile, signCurrentAccountIdentityProof, verifyCurrentAccountIdentityProofForKey, } from "./protocol-profile.js";
|
|
10
11
|
/**
|
|
11
12
|
* Ensures a KeyPackage-level extensions array carries the last-resort marker:
|
|
12
13
|
* the empty-data `0x0004` component inside the KeyPackage-level
|
|
@@ -57,11 +58,42 @@ export async function calculateKeyPackageRef(keyPackage, cryptoProvider) {
|
|
|
57
58
|
return await makeKeyPackageRef(keyPackage, ciphersuiteImpl.hash);
|
|
58
59
|
}
|
|
59
60
|
/** Generate a marmot key package that is compliant with MIP-00 */
|
|
60
|
-
export async function generateKeyPackage({ credential, capabilities, lifetime, extensions, isLastResort = true, accountProofSigner, ciphersuiteImpl, }) {
|
|
61
|
+
export async function generateKeyPackage({ credential, capabilities, lifetime, extensions, isLastResort = true, accountProofSigner, profile = "legacy", currentProof, ciphersuiteImpl, }) {
|
|
61
62
|
if (credential.credentialType !== defaultCredentialTypes.basic)
|
|
62
63
|
throw new Error("Marmot key packages must use a basic credential");
|
|
63
64
|
// Ensure the credential has a valid pubkey
|
|
64
65
|
const accountPubkey = getCredentialPubkey(credential);
|
|
66
|
+
if (profile === "current") {
|
|
67
|
+
const provider = currentProof ??
|
|
68
|
+
(accountProofSigner !== undefined && typeof accountProofSigner !== "function"
|
|
69
|
+
? (key) => signCurrentAccountIdentityProof({ ...key, signer: accountProofSigner })
|
|
70
|
+
: undefined);
|
|
71
|
+
if (provider === undefined)
|
|
72
|
+
throw new Error("generateKeyPackage: a Current-form KeyPackage needs `currentProof` or an `accountProofSigner` with `signEvent`");
|
|
73
|
+
const lifetimeCurrent = lifetime ?? createDefaultKeyPackageLifetime();
|
|
74
|
+
if (!isLifetimeWithinCap(lifetimeCurrent))
|
|
75
|
+
throw new Error(`generateKeyPackage: lifetime range ${lifetimeCurrent.notAfter - lifetimeCurrent.notBefore}s exceeds the 7,261,200s (84-day) cap`);
|
|
76
|
+
const signatureKeyPair = await ciphersuiteImpl.signature.keygen();
|
|
77
|
+
const accountIdentity = hexToBytes(accountPubkey);
|
|
78
|
+
const proof = await provider({
|
|
79
|
+
accountIdentity,
|
|
80
|
+
mlsSignaturePublicKey: signatureKeyPair.publicKey,
|
|
81
|
+
ciphersuite: ciphersuiteImpl.id,
|
|
82
|
+
});
|
|
83
|
+
// Never mint a leaf the group would reject: the provider's proof must bind this account and this key.
|
|
84
|
+
verifyCurrentAccountIdentityProofForKey(proof, accountIdentity, signatureKeyPair.publicKey, ciphersuiteImpl.id);
|
|
85
|
+
return await MLSGenerateKeyPackageWithKey({
|
|
86
|
+
credential,
|
|
87
|
+
capabilities: marmotCapabilitiesForProfile("current", capabilities),
|
|
88
|
+
lifetime: lifetimeCurrent,
|
|
89
|
+
extensions: isLastResort
|
|
90
|
+
? ensureLastResortComponent(extensions ?? [])
|
|
91
|
+
: (extensions ?? []),
|
|
92
|
+
signatureKeyPair,
|
|
93
|
+
leafNodeExtensions: [makeCurrentLeafAppDataExtension(proof)],
|
|
94
|
+
cipherSuite: ciphersuiteImpl,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
65
97
|
const resolvedCapabilities = capabilities
|
|
66
98
|
? ensureMarmotCapabilities(capabilities)
|
|
67
99
|
: defaultCapabilities();
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { type Capabilities, type CustomExtension, type ExtensionRequiredCapabilities, type GroupContextExtension, type LeafNode, type LeafNodeExtension } from "ts-mls";
|
|
2
|
+
import { type UnsignedEvent } from "../utils/nostr.js";
|
|
3
|
+
import { type AccountIdentityProofEventSigner } from "./account-identity-proof.js";
|
|
4
|
+
import { type AppComponentId } from "./components/ids.js";
|
|
5
|
+
/**
|
|
6
|
+
* The S-PROFILE seam (epic marmot-mdk-interop, spec DD-0 / DD-7): a Marmot group's protocol profile, read from its
|
|
7
|
+
* GroupContext, and the account identity proof codec keyed by it. Every proof and same-account decision reads the
|
|
8
|
+
* profile through {@link profileOf} / {@link requires0x800d}; nothing re-derives it.
|
|
9
|
+
*
|
|
10
|
+
* - **Legacy**: MLS `required_capabilities` lists extension `0xf2f1`, and the GroupContext `app_data_dictionary`
|
|
11
|
+
* `app_components` (`0x0001`) list does not contain `0x8009`. Every leaf carries the proof as the `0xf2f1` LeafNode
|
|
12
|
+
* extension ({@link ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE}, `account-identity-proof.ts`, unchanged).
|
|
13
|
+
* - **Current**: the `0x0001` list contains `0x8009`, and `required_capabilities` does not list `0xf2f1`. Every leaf
|
|
14
|
+
* carries the 104-byte proof as component `0x8009` in its own `app_data_dictionary`, with `0x8009` listed in its
|
|
15
|
+
* `app_components`.
|
|
16
|
+
* - Both, or neither, is invalid; so is a GroupContext that carries `0x8009` state (the component is leaf-only).
|
|
17
|
+
*
|
|
18
|
+
* Mirrors MDK v0.19.0 (`3fce954`) `crates/cgka-engine/src/account_identity_proof.rs`:
|
|
19
|
+
* `protocol_profile_of_group_extensions` (L480-528), `validate_leaf_account_identity_proof` (L304-349),
|
|
20
|
+
* `validate_current_proof_for_key` (L379-412), `AccountIdentityProofRequest::proof_event` (L98-157) and
|
|
21
|
+
* `account_identity_proof_component` (L243-272); `capabilities.rs` `leaf_capabilities` /
|
|
22
|
+
* `required_capabilities_extension` for the profile-keyed capability sets.
|
|
23
|
+
*
|
|
24
|
+
* Locally authored (not vendored): `VENDOR.md` "Locally authored (not vendored)".
|
|
25
|
+
*/
|
|
26
|
+
export type ProtocolProfile = "legacy" | "current";
|
|
27
|
+
/** Both profiles, in the order the library introduced them. */
|
|
28
|
+
export declare const PROTOCOL_PROFILES: readonly ProtocolProfile[];
|
|
29
|
+
/** Why a GroupContext classifies as neither profile (spec DD-0: joining it is refused, a commit producing it rejected). */
|
|
30
|
+
export type ProtocolProfileInvalidReason =
|
|
31
|
+
/** The GroupContext `app_data_dictionary` holds an entry under `0x8009`, which is a LeafNode-only component. */
|
|
32
|
+
"group-context-carries-proof-component"
|
|
33
|
+
/** The GroupContext `app_components` (`0x0001`) entry, or the dictionary holding it, does not decode. */
|
|
34
|
+
| "app-components-undecodable"
|
|
35
|
+
/** `required_capabilities` lists `0xf2f1` AND the `0x0001` list contains `0x8009`. */
|
|
36
|
+
| "both-profiles"
|
|
37
|
+
/** Neither marker is present. */
|
|
38
|
+
| "no-profile";
|
|
39
|
+
/** A GroupContext that classifies as no single profile. */
|
|
40
|
+
export interface InvalidProtocolProfile {
|
|
41
|
+
readonly invalid: ProtocolProfileInvalidReason;
|
|
42
|
+
}
|
|
43
|
+
/** What {@link profileOf} answers. */
|
|
44
|
+
export type ProtocolProfileClassification = ProtocolProfile | InvalidProtocolProfile;
|
|
45
|
+
/** Anything carrying GroupContext extensions: a `GroupContext`, a `ClientState["groupContext"]`, a `GroupInfo`'s context. */
|
|
46
|
+
export interface ProfileSource {
|
|
47
|
+
readonly extensions: readonly GroupContextExtension[];
|
|
48
|
+
}
|
|
49
|
+
/** Whether `value` is one of the two protocol profiles (the narrowing companion of {@link profileOf}). */
|
|
50
|
+
export declare function isProtocolProfile(value: unknown): value is ProtocolProfile;
|
|
51
|
+
/**
|
|
52
|
+
* The protocol profile of a group, read from its GroupContext (spec DD-0). Pure and total: never throws.
|
|
53
|
+
*
|
|
54
|
+
* Order of checks as in MDK `protocol_profile_of_group_extensions`: `0x8009` state in the GroupContext first, then the
|
|
55
|
+
* `0x0001` list must decode, then the two markers must name exactly one profile.
|
|
56
|
+
*/
|
|
57
|
+
export declare function profileOf(groupContext: ProfileSource): ProtocolProfileClassification;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a group requires `0x800d` (`marmot.group.account-devices.v1`, spec DD-0): it is Current and its GroupContext
|
|
60
|
+
* `0x0001` list contains `0x800d`. A Legacy group, or a GroupContext of no single profile, never requires it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function requires0x800d(groupContext: ProfileSource): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The private-use app components a Current-form leaf advertises in its `app_components` (`0x0001`) list: every id the
|
|
65
|
+
* Legacy form advertises ({@link SUPPORTED_APP_COMPONENT_IDS}) plus `0x8009` (the proof, MDK requires it to be
|
|
66
|
+
* advertised), `0x800d` (`account-devices-v1`, spec DD-3: listed on every Current-form KeyPackage and leaf) and
|
|
67
|
+
* `0x800b` (`group.encrypted-media.v2`). MDK v0.19.0 groups require `0x8001`, `0x8003`, `0x8004`, `0x8009`, `0x800b`,
|
|
68
|
+
* `0x800c` and `0x800d` (reference-checks.md (e)); a KeyPackage missing any of them is never selected by MDK's
|
|
69
|
+
* inviter. `0x800b` is advertised for that reason only: this library carries an MDK group's `0x800b` state opaquely
|
|
70
|
+
* (it never writes it) and does not implement the v2 media codec.
|
|
71
|
+
*/
|
|
72
|
+
export declare const CURRENT_PROFILE_LEAF_APP_COMPONENT_IDS: readonly AppComponentId[];
|
|
73
|
+
/**
|
|
74
|
+
* The leaf `Capabilities` of a KeyPackage of `profile`. Legacy: {@link ensureMarmotCapabilities} over `base` (the
|
|
75
|
+
* {@link defaultCapabilities} when absent), exactly as before profiles existed. Current: the same, without the
|
|
76
|
+
* `0xf2f1` extension (MDK `leaf_capabilities` advertises it only for Legacy) and without GREASE proposal types — MDK's
|
|
77
|
+
* KeyPackage metadata keeps every advertised proposal type (it drops GREASE only from extensions), and the kind 30443
|
|
78
|
+
* `mls_proposals` tag must match that metadata exactly, so a Current-form leaf advertises no GREASE proposal.
|
|
79
|
+
*/
|
|
80
|
+
export declare function marmotCapabilitiesForProfile(profile: ProtocolProfile, base?: Capabilities): Capabilities;
|
|
81
|
+
/**
|
|
82
|
+
* The `required_capabilities` GroupContext extension of a group of `profile`. Legacy: the unchanged
|
|
83
|
+
* {@link marmotRequiredCapabilitiesExtension} (`0x0006`, `0xf2f1`; proposals `0x0008`, `0x000a`). Current: the same
|
|
84
|
+
* without `0xf2f1` — the Current proof requirement is `0x8009` in the GroupContext `0x0001` list instead (MDK
|
|
85
|
+
* `required_capabilities_extension`).
|
|
86
|
+
*/
|
|
87
|
+
export declare function marmotRequiredCapabilitiesExtensionForProfile(profile: ProtocolProfile): ExtensionRequiredCapabilities;
|
|
88
|
+
/** Byte length of the Current proof component: account identity (32) || created_at (u64 BE, 8) || signature (64). */
|
|
89
|
+
export declare const CURRENT_ACCOUNT_IDENTITY_PROOF_LENGTH = 104;
|
|
90
|
+
/** The largest NIP-01 timestamp a Current proof may carry (`2^53 - 1`); `0` is never valid. */
|
|
91
|
+
export declare const MAX_CURRENT_PROOF_TIMESTAMP: number;
|
|
92
|
+
/** Why a leaf's account identity proof was rejected. */
|
|
93
|
+
export type AccountIdentityProofFailure =
|
|
94
|
+
/** The leaf carries the `0xf2f1` extension AND a `0x8009` component. */
|
|
95
|
+
"both-forms"
|
|
96
|
+
/** The leaf carries neither proof form. */
|
|
97
|
+
| "no-proof"
|
|
98
|
+
/** The leaf's (valid) form is not its group's profile. */
|
|
99
|
+
| "wrong-form"
|
|
100
|
+
/** The credential is not a 32-byte Marmot account identity. */
|
|
101
|
+
| "invalid-credential"
|
|
102
|
+
/** The leaf's `app_data_dictionary`, or its `app_components` list, does not decode. */
|
|
103
|
+
| "leaf-dictionary-undecodable"
|
|
104
|
+
/** A `0x8009` component is present but `0x8009` is not in the leaf's `app_components`. */
|
|
105
|
+
| "proof-not-advertised"
|
|
106
|
+
/** The `0x8009` component is not exactly 104 bytes. */
|
|
107
|
+
| "proof-wrong-length"
|
|
108
|
+
/** The Current proof timestamp is `0` or above `2^53 - 1`. */
|
|
109
|
+
| "proof-invalid-timestamp"
|
|
110
|
+
/** The account the proof names is not the leaf's credential identity. */
|
|
111
|
+
| "proof-account-mismatch"
|
|
112
|
+
/** Legacy: the MLS signature key bound in the proof is not the leaf's. */
|
|
113
|
+
| "proof-signature-key-mismatch"
|
|
114
|
+
/** Legacy: the proof's ciphersuite is not the expected one. */
|
|
115
|
+
| "proof-ciphersuite-mismatch"
|
|
116
|
+
/** Legacy: the proof's signature scheme does not match the ciphersuite. */
|
|
117
|
+
| "proof-signature-scheme-mismatch"
|
|
118
|
+
/** Legacy: the `0xf2f1` bytes do not decode. */
|
|
119
|
+
| "proof-malformed"
|
|
120
|
+
/** The BIP-340 signature does not verify (for a Current proof also: it binds another MLS signature key). */
|
|
121
|
+
| "proof-signature-invalid";
|
|
122
|
+
/** A rejected account identity proof, with its typed {@link AccountIdentityProofFailure} reason. */
|
|
123
|
+
export declare class AccountIdentityProofError extends Error {
|
|
124
|
+
readonly reason: AccountIdentityProofFailure;
|
|
125
|
+
constructor(reason: AccountIdentityProofFailure, message: string);
|
|
126
|
+
}
|
|
127
|
+
/** The values the account key signs to bind a leaf key in the Current profile (MDK `AccountIdentityProofRequest::current`). */
|
|
128
|
+
export interface CurrentAccountIdentityProofRequest {
|
|
129
|
+
/** The 32-byte x-only Nostr account pubkey (the credential identity). */
|
|
130
|
+
readonly accountIdentity: Uint8Array;
|
|
131
|
+
/** The MLS leaf signature public key. */
|
|
132
|
+
readonly mlsSignaturePublicKey: Uint8Array;
|
|
133
|
+
/** The MLS ciphersuite id. */
|
|
134
|
+
readonly ciphersuite: number;
|
|
135
|
+
/** The MLS signature scheme code point ({@link mlsSignatureScheme} of the ciphersuite). */
|
|
136
|
+
readonly signatureScheme: number;
|
|
137
|
+
/** Unix seconds, `1..2^53-1`: the proof's `created_at`, also carried in the 104-byte component. */
|
|
138
|
+
readonly createdAt: number;
|
|
139
|
+
}
|
|
140
|
+
/** A decoded Current proof component. */
|
|
141
|
+
export interface CurrentAccountIdentityProof {
|
|
142
|
+
readonly accountIdentity: Uint8Array;
|
|
143
|
+
readonly createdAt: number;
|
|
144
|
+
readonly signature: Uint8Array;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The canonical, unpublished kind-450 event the account key signs for a Current proof (MDK `proof_event`, Current
|
|
148
|
+
* arm): `created_at` is the proof timestamp, `content` is the fixed authorization sentence, and the tags name the
|
|
149
|
+
* component, the ciphersuite and scheme as lowercase `0x%04x`, and the leaf key. Throws on an invalid timestamp.
|
|
150
|
+
*/
|
|
151
|
+
export declare function buildCurrentAccountIdentityProofEvent(request: CurrentAccountIdentityProofRequest): UnsignedEvent;
|
|
152
|
+
/** The 32-byte digest a Current proof signs: the NIP-01 id of {@link buildCurrentAccountIdentityProofEvent}. */
|
|
153
|
+
export declare function currentAccountIdentityProofSigningDigest(request: CurrentAccountIdentityProofRequest): Uint8Array;
|
|
154
|
+
/** Encodes a Current proof to its 104-byte `0x8009` component data. Throws on a bad length or timestamp. */
|
|
155
|
+
export declare function encodeCurrentAccountIdentityProof(proof: CurrentAccountIdentityProof): Uint8Array;
|
|
156
|
+
/**
|
|
157
|
+
* Decodes 104-byte `0x8009` component data. Throws {@link AccountIdentityProofError} `proof-wrong-length` on any other
|
|
158
|
+
* length and `proof-invalid-timestamp` on a timestamp outside `1..2^53-1` (MDK `validate_current_proof_for_key` order).
|
|
159
|
+
*/
|
|
160
|
+
export declare function decodeCurrentAccountIdentityProof(data: Uint8Array): CurrentAccountIdentityProof;
|
|
161
|
+
/**
|
|
162
|
+
* Verifies a Current proof component for an account and leaf key (MDK `validate_current_proof_for_key`): exact length,
|
|
163
|
+
* timestamp range, the account it names equals `accountIdentity`, and the BIP-340 signature verifies over the event
|
|
164
|
+
* built for `mlsSignaturePublicKey` and `ciphersuite`. Age never invalidates a proof. Throws
|
|
165
|
+
* {@link AccountIdentityProofError}.
|
|
166
|
+
*/
|
|
167
|
+
export declare function verifyCurrentAccountIdentityProofForKey(data: Uint8Array, accountIdentity: Uint8Array, mlsSignaturePublicKey: Uint8Array, ciphersuite: number): void;
|
|
168
|
+
/**
|
|
169
|
+
* Produces a Current proof signature. Two shapes, as for the Legacy `AccountIdentityProofSigner`:
|
|
170
|
+
* - a function over the request returning the 64-byte BIP-340 signature of
|
|
171
|
+
* {@link currentAccountIdentityProofSigningDigest} (the raw-secret-key path, {@link currentProofSignerFromSecretKey});
|
|
172
|
+
* - `{ signEvent }`: an external Nostr signer signs {@link buildCurrentAccountIdentityProofEvent}; the signed event is
|
|
173
|
+
* checked (author, id, signature) before its signature is used.
|
|
174
|
+
*/
|
|
175
|
+
export type CurrentAccountIdentityProofSigner = ((request: CurrentAccountIdentityProofRequest) => Uint8Array | Promise<Uint8Array>) | {
|
|
176
|
+
signEvent: AccountIdentityProofEventSigner;
|
|
177
|
+
};
|
|
178
|
+
/** A {@link CurrentAccountIdentityProofSigner} over a raw 32-byte Nostr secret key. */
|
|
179
|
+
export declare function currentProofSignerFromSecretKey(secretKey: Uint8Array): CurrentAccountIdentityProofSigner;
|
|
180
|
+
/**
|
|
181
|
+
* Signs a Current proof for a leaf key and returns its 104-byte `0x8009` component data (MDK
|
|
182
|
+
* `account_identity_proof_component`). `createdAt` defaults to now (unix seconds).
|
|
183
|
+
*/
|
|
184
|
+
export declare function signCurrentAccountIdentityProof(params: {
|
|
185
|
+
readonly accountIdentity: Uint8Array;
|
|
186
|
+
readonly mlsSignaturePublicKey: Uint8Array;
|
|
187
|
+
readonly ciphersuite: number;
|
|
188
|
+
readonly createdAt?: number;
|
|
189
|
+
readonly signer: CurrentAccountIdentityProofSigner;
|
|
190
|
+
}): Promise<Uint8Array>;
|
|
191
|
+
/**
|
|
192
|
+
* Supplies the 104-byte Current proof component for a freshly generated leaf key. `generateKeyPackage` calls it once
|
|
193
|
+
* per KeyPackage, after drawing the leaf signature key pair. A provider may return a stored proof for that key (a
|
|
194
|
+
* refresh with an unchanged signature key reuses its proof, spec DD-7) or sign a new one.
|
|
195
|
+
*/
|
|
196
|
+
export type CurrentProofProvider = (key: {
|
|
197
|
+
readonly accountIdentity: Uint8Array;
|
|
198
|
+
readonly mlsSignaturePublicKey: Uint8Array;
|
|
199
|
+
readonly ciphersuite: number;
|
|
200
|
+
}) => Promise<Uint8Array>;
|
|
201
|
+
/** Which proof carrier(s) a leaf holds: one profile's, both, or neither. */
|
|
202
|
+
export type LeafProofForm = ProtocolProfile | "both" | "neither";
|
|
203
|
+
/**
|
|
204
|
+
* The proof form a leaf carries, read like MDK: `0xf2f1` LeafNode extension only is Legacy, an `app_data_dictionary`
|
|
205
|
+
* `0x8009` entry only is Current. A dictionary that does not decode counts as no Current entry here; the verifier
|
|
206
|
+
* reports it as `leaf-dictionary-undecodable`.
|
|
207
|
+
*/
|
|
208
|
+
export declare function leafProofForm(leaf: Pick<LeafNode, "extensions">): LeafProofForm;
|
|
209
|
+
/**
|
|
210
|
+
* The `app_components` (`0x0001`) ids a leaf advertises in its own `app_data_dictionary`, or `undefined` when it
|
|
211
|
+
* advertises none. Throws {@link AccountIdentityProofError} `leaf-dictionary-undecodable` when the dictionary or the
|
|
212
|
+
* list does not decode.
|
|
213
|
+
*/
|
|
214
|
+
export declare function leafAppComponents(leaf: Pick<LeafNode, "extensions">): AppComponentId[] | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Verifies a leaf's account identity proof in whichever single form it carries and returns that form's profile (MDK
|
|
217
|
+
* `validate_leaf_account_identity_proof`). With `expected`, a valid proof in the other form is rejected `wrong-form`
|
|
218
|
+
* (MDK `ensure_profile`). Throws {@link AccountIdentityProofError}:
|
|
219
|
+
* `both-forms` / `no-proof` first, then the form's own checks. The Legacy form's checks and their order are exactly
|
|
220
|
+
* those of `verifyLeafAccountIdentityProof` (`account-identity-proof.ts`).
|
|
221
|
+
*/
|
|
222
|
+
export declare function verifyLeafAccountIdentityProofForProfile(leaf: LeafNode, ciphersuite: number, expected?: ProtocolProfile): ProtocolProfile;
|
|
223
|
+
/** Non-throwing {@link verifyLeafAccountIdentityProofForProfile}. */
|
|
224
|
+
export type LeafProofCheck = {
|
|
225
|
+
readonly valid: true;
|
|
226
|
+
readonly profile: ProtocolProfile;
|
|
227
|
+
} | {
|
|
228
|
+
readonly valid: false;
|
|
229
|
+
readonly reason: AccountIdentityProofFailure;
|
|
230
|
+
readonly message: string;
|
|
231
|
+
};
|
|
232
|
+
/** {@link verifyLeafAccountIdentityProofForProfile} as a result instead of a throw. */
|
|
233
|
+
export declare function checkLeafAccountIdentityProof(leaf: LeafNode, ciphersuite: number, expected?: ProtocolProfile): LeafProofCheck;
|
|
234
|
+
/**
|
|
235
|
+
* The `app_data_dictionary` LeafNode extension of a Current-form leaf: the `app_components` (`0x0001`) list
|
|
236
|
+
* (`0x0001` itself plus `supportedIds`, which always gains `0x8009`), the SafeAAD advertisement (`0x0002`, empty
|
|
237
|
+
* list, as the Legacy leaf) and the 104-byte proof under `0x8009` — MDK's Current leaf shape.
|
|
238
|
+
*/
|
|
239
|
+
export declare function makeCurrentLeafAppDataExtension(proofComponent: Uint8Array, supportedIds?: readonly AppComponentId[]): CustomExtension;
|
|
240
|
+
/**
|
|
241
|
+
* The proof a leaf is rewritten with: the Legacy `0xf2f1` extension, or the Current 104-byte component.
|
|
242
|
+
*/
|
|
243
|
+
export type LeafProofMaterial = {
|
|
244
|
+
readonly profile: "legacy";
|
|
245
|
+
readonly extension: CustomExtension;
|
|
246
|
+
} | {
|
|
247
|
+
readonly profile: "current";
|
|
248
|
+
readonly component: Uint8Array;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* `extensions` (a leaf's) with its proof replaced by `material`, every other extension unchanged and in place:
|
|
252
|
+
* - Legacy: the `0xf2f1` extension is replaced (appended when absent) — the rekey behaviour before profiles existed.
|
|
253
|
+
* - Current: the `0x8009` entry of the leaf `app_data_dictionary` is replaced (added when absent, with `0x8009` added
|
|
254
|
+
* to its `app_components`; a leaf with no dictionary gains the Current leaf dictionary), every other entry kept.
|
|
255
|
+
* Throws when the leaf dictionary does not decode.
|
|
256
|
+
*/
|
|
257
|
+
export declare function leafExtensionsWithProof(extensions: readonly LeafNodeExtension[], material: LeafProofMaterial): LeafNodeExtension[];
|
|
258
|
+
/**
|
|
259
|
+
* The 104-byte Current proof a leaf carries, or `undefined` when it carries none (no dictionary entry, or a dictionary
|
|
260
|
+
* that does not decode).
|
|
261
|
+
*/
|
|
262
|
+
export declare function currentProofComponentOf(leaf: Pick<LeafNode, "extensions">): Uint8Array | undefined;
|