@941design/marmot-engine 0.0.0-stage → 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 +477 -0
- package/LICENSE +53 -0
- package/README.md +33 -2
- package/dist/audit/emitter.d.ts +17 -0
- package/dist/audit/emitter.js +30 -0
- package/dist/audit/helpers.d.ts +16 -0
- package/dist/audit/helpers.js +103 -0
- package/dist/audit/index.d.ts +6 -0
- package/dist/audit/index.js +6 -0
- package/dist/audit/recorder.d.ts +13 -0
- package/dist/audit/recorder.js +24 -0
- package/dist/audit/sink.d.ts +16 -0
- package/dist/audit/sink.js +27 -0
- package/dist/audit/types-internal.d.ts +7 -0
- package/dist/audit/types-internal.js +1 -0
- package/dist/audit/types.d.ts +289 -0
- package/dist/audit/types.js +2 -0
- package/dist/core/account-identity-proof.d.ts +165 -0
- package/dist/core/account-identity-proof.js +277 -0
- package/dist/core/application-rumor.d.ts +45 -0
- package/dist/core/application-rumor.js +120 -0
- package/dist/core/auth-service.d.ts +2 -0
- package/dist/core/auth-service.js +52 -0
- package/dist/core/binary.d.ts +142 -0
- package/dist/core/binary.js +363 -0
- package/dist/core/capabilities.d.ts +51 -0
- package/dist/core/capabilities.js +102 -0
- package/dist/core/client-state.d.ts +119 -0
- package/dist/core/client-state.js +226 -0
- package/dist/core/commit-authorization.d.ts +26 -0
- package/dist/core/commit-authorization.js +26 -0
- package/dist/core/components/admin-policy.d.ts +4 -0
- package/dist/core/components/admin-policy.js +69 -0
- package/dist/core/components/agent-text-stream.d.ts +51 -0
- package/dist/core/components/agent-text-stream.js +112 -0
- package/dist/core/components/app-components-list.d.ts +17 -0
- package/dist/core/components/app-components-list.js +35 -0
- package/dist/core/components/avatar-url.d.ts +12 -0
- package/dist/core/components/avatar-url.js +85 -0
- package/dist/core/components/bytes.d.ts +5 -0
- package/dist/core/components/bytes.js +18 -0
- package/dist/core/components/dictionary.d.ts +80 -0
- package/dist/core/components/dictionary.js +175 -0
- package/dist/core/components/disband-validation.d.ts +21 -0
- package/dist/core/components/disband-validation.js +173 -0
- package/dist/core/components/encrypted-media.d.ts +44 -0
- package/dist/core/components/encrypted-media.js +210 -0
- package/dist/core/components/group-lifecycle.d.ts +10 -0
- package/dist/core/components/group-lifecycle.js +32 -0
- package/dist/core/components/group-profile.d.ts +24 -0
- package/dist/core/components/group-profile.js +35 -0
- package/dist/core/components/host-safety.d.ts +9 -0
- package/dist/core/components/host-safety.js +148 -0
- package/dist/core/components/ids.d.ts +93 -0
- package/dist/core/components/ids.js +92 -0
- package/dist/core/components/index.d.ts +14 -0
- package/dist/core/components/index.js +14 -0
- package/dist/core/components/integrity.d.ts +141 -0
- package/dist/core/components/integrity.js +293 -0
- package/dist/core/components/message-retention.d.ts +17 -0
- package/dist/core/components/message-retention.js +26 -0
- package/dist/core/components/nostr-routing.d.ts +8 -0
- package/dist/core/components/nostr-routing.js +92 -0
- package/dist/core/components/url.d.ts +26 -0
- package/dist/core/components/url.js +44 -0
- package/dist/core/convergence-status.d.ts +84 -0
- package/dist/core/convergence-status.js +82 -0
- package/dist/core/convergence.d.ts +567 -0
- package/dist/core/convergence.js +1150 -0
- package/dist/core/credential.d.ts +16 -0
- package/dist/core/credential.js +64 -0
- package/dist/core/default-capabilities.d.ts +9 -0
- package/dist/core/default-capabilities.js +34 -0
- package/dist/core/extensions.d.ts +9 -0
- package/dist/core/extensions.js +5 -0
- package/dist/core/grease.d.ts +2 -0
- package/dist/core/grease.js +6 -0
- package/dist/core/group-event.d.ts +18 -0
- package/dist/core/group-event.js +30 -0
- package/dist/core/group-lifecycle.d.ts +42 -0
- package/dist/core/group-lifecycle.js +66 -0
- package/dist/core/group-members.d.ts +37 -0
- package/dist/core/group-members.js +99 -0
- package/dist/core/group-message-classify.d.ts +42 -0
- package/dist/core/group-message-classify.js +57 -0
- package/dist/core/group-message-crypto.d.ts +53 -0
- package/dist/core/group-message-crypto.js +140 -0
- package/dist/core/group-message.d.ts +5 -0
- package/dist/core/group-message.js +11 -0
- package/dist/core/group.d.ts +56 -0
- package/dist/core/group.js +95 -0
- package/dist/core/inbound.d.ts +102 -0
- package/dist/core/inbound.js +79 -0
- package/dist/core/index.d.ts +29 -0
- package/dist/core/index.js +27 -0
- package/dist/core/key-package-eligibility.d.ts +31 -0
- package/dist/core/key-package-eligibility.js +116 -0
- package/dist/core/key-package-event-decode.d.ts +43 -0
- package/dist/core/key-package-event-decode.js +118 -0
- package/dist/core/key-package-event-delete.d.ts +16 -0
- package/dist/core/key-package-event-delete.js +46 -0
- package/dist/core/key-package-event-encode.d.ts +28 -0
- package/dist/core/key-package-event-encode.js +117 -0
- package/dist/core/key-package-event.d.ts +4 -0
- package/dist/core/key-package-event.js +8 -0
- package/dist/core/key-package.d.ts +66 -0
- package/dist/core/key-package.js +147 -0
- package/dist/core/leaf-succession.d.ts +83 -0
- package/dist/core/leaf-succession.js +97 -0
- package/dist/core/media/canonical.d.ts +34 -0
- package/dist/core/media/canonical.js +57 -0
- package/dist/core/media/crypto.d.ts +79 -0
- package/dist/core/media/crypto.js +215 -0
- package/dist/core/media/imeta.d.ts +33 -0
- package/dist/core/media/imeta.js +188 -0
- package/dist/core/media/locator.d.ts +44 -0
- package/dist/core/media/locator.js +69 -0
- package/dist/core/media/types.d.ts +83 -0
- package/dist/core/media/types.js +12 -0
- package/dist/core/media.d.ts +6 -0
- package/dist/core/media.js +12 -0
- package/dist/core/protocol-profile.d.ts +262 -0
- package/dist/core/protocol-profile.js +535 -0
- package/dist/core/protocol.d.ts +51 -0
- package/dist/core/protocol.js +41 -0
- package/dist/core/relay-lists.d.ts +52 -0
- package/dist/core/relay-lists.js +86 -0
- package/dist/core/retained-history.d.ts +78 -0
- package/dist/core/retained-history.js +59 -0
- package/dist/core/transport.d.ts +43 -0
- package/dist/core/transport.js +21 -0
- package/dist/core/welcome-event.d.ts +61 -0
- package/dist/core/welcome-event.js +116 -0
- package/dist/core/welcome-join.d.ts +155 -0
- package/dist/core/welcome-join.js +243 -0
- package/dist/core/welcome.d.ts +3 -0
- package/dist/core/welcome.js +6 -0
- package/dist/engine/admin-policy.d.ts +75 -0
- package/dist/engine/admin-policy.js +137 -0
- package/dist/engine/auto-committer.d.ts +39 -0
- package/dist/engine/auto-committer.js +42 -0
- package/dist/engine/delivered-payloads.d.ts +61 -0
- package/dist/engine/delivered-payloads.js +84 -0
- package/dist/engine/disband-request.d.ts +41 -0
- package/dist/engine/disband-request.js +86 -0
- package/dist/engine/disband-tombstone.d.ts +14 -0
- package/dist/engine/disband-tombstone.js +66 -0
- package/dist/engine/fork-recovery.d.ts +672 -0
- package/dist/engine/fork-recovery.js +1615 -0
- package/dist/engine/group-engine.d.ts +571 -0
- package/dist/engine/group-engine.js +5134 -0
- package/dist/engine/history-tree.d.ts +232 -0
- package/dist/engine/history-tree.js +651 -0
- package/dist/engine/index.d.ts +16 -0
- package/dist/engine/index.js +15 -0
- package/dist/engine/ingest-disposition.d.ts +5 -0
- package/dist/engine/ingest-disposition.js +63 -0
- package/dist/engine/ingest.d.ts +390 -0
- package/dist/engine/ingest.js +1258 -0
- package/dist/engine/ingestion-pool.d.ts +74 -0
- package/dist/engine/ingestion-pool.js +95 -0
- package/dist/engine/message-dedup.d.ts +16 -0
- package/dist/engine/message-dedup.js +20 -0
- package/dist/engine/own-commit-stamp.d.ts +30 -0
- package/dist/engine/own-commit-stamp.js +71 -0
- package/dist/engine/retained-store.d.ts +79 -0
- package/dist/engine/retained-store.js +133 -0
- package/dist/engine/sender-ratchet.d.ts +50 -0
- package/dist/engine/sender-ratchet.js +196 -0
- package/dist/engine/state-notifications.d.ts +122 -0
- package/dist/engine/state-notifications.js +173 -0
- package/dist/engine/tree-convergence.d.ts +41 -0
- package/dist/engine/tree-convergence.js +90 -0
- package/dist/engine/types.d.ts +366 -0
- package/dist/engine/types.js +14 -0
- package/dist/engine/wire-format.d.ts +77 -0
- package/dist/engine/wire-format.js +120 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -0
- package/dist/mls.d.ts +11 -0
- package/dist/mls.js +11 -0
- package/dist/utils/debug.d.ts +3 -0
- package/dist/utils/debug.js +3 -0
- package/dist/utils/encoding.d.ts +38 -0
- package/dist/utils/encoding.js +91 -0
- package/dist/utils/key-value.d.ts +18 -0
- package/dist/utils/key-value.js +2 -0
- package/dist/utils/nostr.d.ts +35 -0
- package/dist/utils/nostr.js +26 -0
- package/dist/utils/relay-url.d.ts +10 -0
- package/dist/utils/relay-url.js +23 -0
- package/dist/utils/tag-cardinality.d.ts +50 -0
- package/dist/utils/tag-cardinality.js +91 -0
- package/dist/utils/timestamp.d.ts +50 -0
- package/dist/utils/timestamp.js +95 -0
- package/dist/version.d.ts +112 -0
- package/dist/version.js +112 -0
- package/package.json +68 -3
|
@@ -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;
|