@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,535 @@
|
|
|
1
|
+
/** @module @category Core - Protocol Profile */
|
|
2
|
+
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
3
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
4
|
+
import { appDataDictionaryExtensionType, appDataUpdateProposalType, defaultExtensionTypes, getAppDataDictionary, makeAppDataDictionaryExtension, selfRemoveProposalType, } from "ts-mls";
|
|
5
|
+
import { getEventHash, unixNow } from "../utils/nostr.js";
|
|
6
|
+
import { ACCOUNT_IDENTITY_PROOF_EVENT_KIND, ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE, accountIdentityProofSigningDigest, decodeAccountIdentityProof, mlsSignatureScheme, } from "./account-identity-proof.js";
|
|
7
|
+
import { ensureMarmotCapabilities, marmotRequiredCapabilitiesExtension, } from "./capabilities.js";
|
|
8
|
+
import { decodeComponentsList, encodeComponentsList, } from "./components/app-components-list.js";
|
|
9
|
+
import { ACCOUNT_DEVICES_COMPONENT_ID, ACCOUNT_IDENTITY_PROOF_COMPONENT_ID, APP_COMPONENTS_COMPONENT_ID, GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID, PRIVATE_USE_APP_COMPONENT_ID_START, SAFE_AAD_COMPONENT_ID, SUPPORTED_APP_COMPONENT_IDS, } from "./components/ids.js";
|
|
10
|
+
import { getCredentialPubkey } from "./credential.js";
|
|
11
|
+
import { defaultCapabilities } from "./default-capabilities.js";
|
|
12
|
+
import { isGreaseValue } from "./grease.js";
|
|
13
|
+
/** Both profiles, in the order the library introduced them. */
|
|
14
|
+
export const PROTOCOL_PROFILES = [
|
|
15
|
+
"legacy",
|
|
16
|
+
"current",
|
|
17
|
+
];
|
|
18
|
+
/** Whether `value` is one of the two protocol profiles (the narrowing companion of {@link profileOf}). */
|
|
19
|
+
export function isProtocolProfile(value) {
|
|
20
|
+
return value === "legacy" || value === "current";
|
|
21
|
+
}
|
|
22
|
+
function requiredCapabilitiesListsLegacyProof(extensions) {
|
|
23
|
+
return extensions.some((extension) => {
|
|
24
|
+
if (extension.extensionType !== defaultExtensionTypes.required_capabilities)
|
|
25
|
+
return false;
|
|
26
|
+
const data = extension.extensionData;
|
|
27
|
+
return (data?.extensionTypes ?? []).includes(ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** The decoded GroupContext dictionary, or `"undecodable"`. */
|
|
31
|
+
function groupDictionary(extensions) {
|
|
32
|
+
try {
|
|
33
|
+
return getAppDataDictionary(extensions);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return "undecodable";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The protocol profile of a group, read from its GroupContext (spec DD-0). Pure and total: never throws.
|
|
41
|
+
*
|
|
42
|
+
* Order of checks as in MDK `protocol_profile_of_group_extensions`: `0x8009` state in the GroupContext first, then the
|
|
43
|
+
* `0x0001` list must decode, then the two markers must name exactly one profile.
|
|
44
|
+
*/
|
|
45
|
+
export function profileOf(groupContext) {
|
|
46
|
+
const extensions = groupContext.extensions;
|
|
47
|
+
const legacyRequired = requiredCapabilitiesListsLegacyProof(extensions);
|
|
48
|
+
const dictionary = groupDictionary(extensions);
|
|
49
|
+
if (dictionary === "undecodable")
|
|
50
|
+
return { invalid: "app-components-undecodable" };
|
|
51
|
+
if (dictionary?.some((entry) => entry.componentId === ACCOUNT_IDENTITY_PROOF_COMPONENT_ID))
|
|
52
|
+
return { invalid: "group-context-carries-proof-component" };
|
|
53
|
+
let currentRequired = false;
|
|
54
|
+
const list = dictionary?.find((entry) => entry.componentId === APP_COMPONENTS_COMPONENT_ID);
|
|
55
|
+
if (list !== undefined) {
|
|
56
|
+
let ids;
|
|
57
|
+
try {
|
|
58
|
+
ids = decodeComponentsList(list.data);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return { invalid: "app-components-undecodable" };
|
|
62
|
+
}
|
|
63
|
+
currentRequired = ids.includes(ACCOUNT_IDENTITY_PROOF_COMPONENT_ID);
|
|
64
|
+
}
|
|
65
|
+
if (legacyRequired && !currentRequired)
|
|
66
|
+
return "legacy";
|
|
67
|
+
if (!legacyRequired && currentRequired)
|
|
68
|
+
return "current";
|
|
69
|
+
return { invalid: legacyRequired ? "both-profiles" : "no-profile" };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether a group requires `0x800d` (`marmot.group.account-devices.v1`, spec DD-0): it is Current and its GroupContext
|
|
73
|
+
* `0x0001` list contains `0x800d`. A Legacy group, or a GroupContext of no single profile, never requires it.
|
|
74
|
+
*/
|
|
75
|
+
export function requires0x800d(groupContext) {
|
|
76
|
+
if (profileOf(groupContext) !== "current")
|
|
77
|
+
return false;
|
|
78
|
+
const dictionary = groupDictionary(groupContext.extensions);
|
|
79
|
+
if (dictionary === "undecodable" || dictionary === undefined)
|
|
80
|
+
return false;
|
|
81
|
+
const list = dictionary.find((entry) => entry.componentId === APP_COMPONENTS_COMPONENT_ID);
|
|
82
|
+
if (list === undefined)
|
|
83
|
+
return false;
|
|
84
|
+
return decodeComponentsList(list.data).includes(ACCOUNT_DEVICES_COMPONENT_ID);
|
|
85
|
+
}
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Profile-keyed capabilities
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
/**
|
|
90
|
+
* The private-use app components a Current-form leaf advertises in its `app_components` (`0x0001`) list: every id the
|
|
91
|
+
* Legacy form advertises ({@link SUPPORTED_APP_COMPONENT_IDS}) plus `0x8009` (the proof, MDK requires it to be
|
|
92
|
+
* advertised), `0x800d` (`account-devices-v1`, spec DD-3: listed on every Current-form KeyPackage and leaf) and
|
|
93
|
+
* `0x800b` (`group.encrypted-media.v2`). MDK v0.19.0 groups require `0x8001`, `0x8003`, `0x8004`, `0x8009`, `0x800b`,
|
|
94
|
+
* `0x800c` and `0x800d` (reference-checks.md (e)); a KeyPackage missing any of them is never selected by MDK's
|
|
95
|
+
* inviter. `0x800b` is advertised for that reason only: this library carries an MDK group's `0x800b` state opaquely
|
|
96
|
+
* (it never writes it) and does not implement the v2 media codec.
|
|
97
|
+
*/
|
|
98
|
+
export const CURRENT_PROFILE_LEAF_APP_COMPONENT_IDS = [
|
|
99
|
+
...new Set([
|
|
100
|
+
...SUPPORTED_APP_COMPONENT_IDS,
|
|
101
|
+
ACCOUNT_IDENTITY_PROOF_COMPONENT_ID,
|
|
102
|
+
GROUP_ENCRYPTED_MEDIA_V2_COMPONENT_ID,
|
|
103
|
+
ACCOUNT_DEVICES_COMPONENT_ID,
|
|
104
|
+
]),
|
|
105
|
+
].sort((a, b) => a - b);
|
|
106
|
+
/**
|
|
107
|
+
* The leaf `Capabilities` of a KeyPackage of `profile`. Legacy: {@link ensureMarmotCapabilities} over `base` (the
|
|
108
|
+
* {@link defaultCapabilities} when absent), exactly as before profiles existed. Current: the same, without the
|
|
109
|
+
* `0xf2f1` extension (MDK `leaf_capabilities` advertises it only for Legacy) and without GREASE proposal types — MDK's
|
|
110
|
+
* KeyPackage metadata keeps every advertised proposal type (it drops GREASE only from extensions), and the kind 30443
|
|
111
|
+
* `mls_proposals` tag must match that metadata exactly, so a Current-form leaf advertises no GREASE proposal.
|
|
112
|
+
*/
|
|
113
|
+
export function marmotCapabilitiesForProfile(profile, base) {
|
|
114
|
+
const legacy = base ? ensureMarmotCapabilities(base) : defaultCapabilities();
|
|
115
|
+
if (profile === "legacy")
|
|
116
|
+
return legacy;
|
|
117
|
+
return {
|
|
118
|
+
...legacy,
|
|
119
|
+
extensions: legacy.extensions.filter((type) => type !== ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE),
|
|
120
|
+
proposals: legacy.proposals.filter((type) => !isGreaseValue(type)),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The `required_capabilities` GroupContext extension of a group of `profile`. Legacy: the unchanged
|
|
125
|
+
* {@link marmotRequiredCapabilitiesExtension} (`0x0006`, `0xf2f1`; proposals `0x0008`, `0x000a`). Current: the same
|
|
126
|
+
* without `0xf2f1` — the Current proof requirement is `0x8009` in the GroupContext `0x0001` list instead (MDK
|
|
127
|
+
* `required_capabilities_extension`).
|
|
128
|
+
*/
|
|
129
|
+
export function marmotRequiredCapabilitiesExtensionForProfile(profile) {
|
|
130
|
+
const legacy = marmotRequiredCapabilitiesExtension();
|
|
131
|
+
if (profile === "legacy")
|
|
132
|
+
return legacy;
|
|
133
|
+
return {
|
|
134
|
+
extensionType: legacy.extensionType,
|
|
135
|
+
extensionData: {
|
|
136
|
+
extensionTypes: [appDataDictionaryExtensionType],
|
|
137
|
+
proposalTypes: [appDataUpdateProposalType, selfRemoveProposalType].sort((a, b) => a - b),
|
|
138
|
+
credentialTypes: [],
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// Current proof codec (component 0x8009, 104 bytes)
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
/** Byte length of the Current proof component: account identity (32) || created_at (u64 BE, 8) || signature (64). */
|
|
146
|
+
export const CURRENT_ACCOUNT_IDENTITY_PROOF_LENGTH = 104;
|
|
147
|
+
/** The largest NIP-01 timestamp a Current proof may carry (`2^53 - 1`); `0` is never valid. */
|
|
148
|
+
export const MAX_CURRENT_PROOF_TIMESTAMP = Number.MAX_SAFE_INTEGER;
|
|
149
|
+
const ACCOUNT_IDENTITY_PROOF_DOMAIN = "marmot.account-identity-proof.v2";
|
|
150
|
+
const CURRENT_PROOF_CONTENT = "Authorize this MLS leaf key for my Marmot account";
|
|
151
|
+
const ACCOUNT_IDENTITY_LEN = 32;
|
|
152
|
+
const SIGNATURE_LEN = 64;
|
|
153
|
+
/** A rejected account identity proof, with its typed {@link AccountIdentityProofFailure} reason. */
|
|
154
|
+
export class AccountIdentityProofError extends Error {
|
|
155
|
+
reason;
|
|
156
|
+
constructor(reason, message) {
|
|
157
|
+
super(message);
|
|
158
|
+
this.name = "AccountIdentityProofError";
|
|
159
|
+
this.reason = reason;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function hex4(value) {
|
|
163
|
+
return `0x${value.toString(16).padStart(4, "0")}`;
|
|
164
|
+
}
|
|
165
|
+
function validTimestamp(createdAt) {
|
|
166
|
+
return (Number.isSafeInteger(createdAt) &&
|
|
167
|
+
createdAt >= 1 &&
|
|
168
|
+
createdAt <= MAX_CURRENT_PROOF_TIMESTAMP);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The canonical, unpublished kind-450 event the account key signs for a Current proof (MDK `proof_event`, Current
|
|
172
|
+
* arm): `created_at` is the proof timestamp, `content` is the fixed authorization sentence, and the tags name the
|
|
173
|
+
* component, the ciphersuite and scheme as lowercase `0x%04x`, and the leaf key. Throws on an invalid timestamp.
|
|
174
|
+
*/
|
|
175
|
+
export function buildCurrentAccountIdentityProofEvent(request) {
|
|
176
|
+
if (!validTimestamp(request.createdAt))
|
|
177
|
+
throw new AccountIdentityProofError("proof-invalid-timestamp", `current proof timestamp must be in 1..=${MAX_CURRENT_PROOF_TIMESTAMP}`);
|
|
178
|
+
return {
|
|
179
|
+
pubkey: bytesToHex(request.accountIdentity),
|
|
180
|
+
created_at: request.createdAt,
|
|
181
|
+
kind: ACCOUNT_IDENTITY_PROOF_EVENT_KIND,
|
|
182
|
+
content: CURRENT_PROOF_CONTENT,
|
|
183
|
+
tags: [
|
|
184
|
+
["d", ACCOUNT_IDENTITY_PROOF_DOMAIN],
|
|
185
|
+
["component", hex4(ACCOUNT_IDENTITY_PROOF_COMPONENT_ID)],
|
|
186
|
+
["ciphersuite", hex4(request.ciphersuite)],
|
|
187
|
+
["signature_scheme", hex4(request.signatureScheme)],
|
|
188
|
+
["mls_signature_key", bytesToHex(request.mlsSignaturePublicKey)],
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** The 32-byte digest a Current proof signs: the NIP-01 id of {@link buildCurrentAccountIdentityProofEvent}. */
|
|
193
|
+
export function currentAccountIdentityProofSigningDigest(request) {
|
|
194
|
+
return hexToBytes(getEventHash(buildCurrentAccountIdentityProofEvent(request)));
|
|
195
|
+
}
|
|
196
|
+
/** Encodes a Current proof to its 104-byte `0x8009` component data. Throws on a bad length or timestamp. */
|
|
197
|
+
export function encodeCurrentAccountIdentityProof(proof) {
|
|
198
|
+
if (proof.accountIdentity.length !== ACCOUNT_IDENTITY_LEN)
|
|
199
|
+
throw new AccountIdentityProofError("proof-wrong-length", "account identity must be exactly 32 bytes");
|
|
200
|
+
if (proof.signature.length !== SIGNATURE_LEN)
|
|
201
|
+
throw new AccountIdentityProofError("proof-wrong-length", "proof signature must be exactly 64 bytes");
|
|
202
|
+
if (!validTimestamp(proof.createdAt))
|
|
203
|
+
throw new AccountIdentityProofError("proof-invalid-timestamp", `current proof timestamp must be in 1..=${MAX_CURRENT_PROOF_TIMESTAMP}`);
|
|
204
|
+
const out = new Uint8Array(CURRENT_ACCOUNT_IDENTITY_PROOF_LENGTH);
|
|
205
|
+
out.set(proof.accountIdentity, 0);
|
|
206
|
+
new DataView(out.buffer).setBigUint64(ACCOUNT_IDENTITY_LEN, BigInt(proof.createdAt), false);
|
|
207
|
+
out.set(proof.signature, ACCOUNT_IDENTITY_LEN + 8);
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Decodes 104-byte `0x8009` component data. Throws {@link AccountIdentityProofError} `proof-wrong-length` on any other
|
|
212
|
+
* length and `proof-invalid-timestamp` on a timestamp outside `1..2^53-1` (MDK `validate_current_proof_for_key` order).
|
|
213
|
+
*/
|
|
214
|
+
export function decodeCurrentAccountIdentityProof(data) {
|
|
215
|
+
if (data.length !== CURRENT_ACCOUNT_IDENTITY_PROOF_LENGTH)
|
|
216
|
+
throw new AccountIdentityProofError("proof-wrong-length", `current proof component must be exactly ${CURRENT_ACCOUNT_IDENTITY_PROOF_LENGTH} bytes`);
|
|
217
|
+
const raw = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
218
|
+
const createdAt = raw.getBigUint64(ACCOUNT_IDENTITY_LEN, false);
|
|
219
|
+
if (createdAt < 1n || createdAt > BigInt(MAX_CURRENT_PROOF_TIMESTAMP))
|
|
220
|
+
throw new AccountIdentityProofError("proof-invalid-timestamp", `current proof timestamp must be in 1..=${MAX_CURRENT_PROOF_TIMESTAMP}`);
|
|
221
|
+
return {
|
|
222
|
+
accountIdentity: data.slice(0, ACCOUNT_IDENTITY_LEN),
|
|
223
|
+
createdAt: Number(createdAt),
|
|
224
|
+
signature: data.slice(ACCOUNT_IDENTITY_LEN + 8),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Verifies a Current proof component for an account and leaf key (MDK `validate_current_proof_for_key`): exact length,
|
|
229
|
+
* timestamp range, the account it names equals `accountIdentity`, and the BIP-340 signature verifies over the event
|
|
230
|
+
* built for `mlsSignaturePublicKey` and `ciphersuite`. Age never invalidates a proof. Throws
|
|
231
|
+
* {@link AccountIdentityProofError}.
|
|
232
|
+
*/
|
|
233
|
+
export function verifyCurrentAccountIdentityProofForKey(data, accountIdentity, mlsSignaturePublicKey, ciphersuite) {
|
|
234
|
+
const proof = decodeCurrentAccountIdentityProof(data);
|
|
235
|
+
if (!bytesEqual(proof.accountIdentity, accountIdentity))
|
|
236
|
+
throw new AccountIdentityProofError("proof-account-mismatch", "proof account identity does not match credential identity");
|
|
237
|
+
const digest = currentAccountIdentityProofSigningDigest({
|
|
238
|
+
accountIdentity: proof.accountIdentity,
|
|
239
|
+
mlsSignaturePublicKey,
|
|
240
|
+
ciphersuite,
|
|
241
|
+
signatureScheme: mlsSignatureScheme(ciphersuite),
|
|
242
|
+
createdAt: proof.createdAt,
|
|
243
|
+
});
|
|
244
|
+
let verified = false;
|
|
245
|
+
try {
|
|
246
|
+
verified = schnorr.verify(proof.signature, digest, accountIdentity);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
verified = false;
|
|
250
|
+
}
|
|
251
|
+
if (!verified)
|
|
252
|
+
throw new AccountIdentityProofError("proof-signature-invalid", "proof signature does not verify for credential identity");
|
|
253
|
+
}
|
|
254
|
+
/** A {@link CurrentAccountIdentityProofSigner} over a raw 32-byte Nostr secret key. */
|
|
255
|
+
export function currentProofSignerFromSecretKey(secretKey) {
|
|
256
|
+
return (request) => schnorr.sign(currentAccountIdentityProofSigningDigest(request), secretKey);
|
|
257
|
+
}
|
|
258
|
+
function signatureFromSignedCurrentEvent(request, event) {
|
|
259
|
+
if (event.pubkey.toLowerCase() !== bytesToHex(request.accountIdentity))
|
|
260
|
+
throw new Error("proof event signer does not match account identity");
|
|
261
|
+
const expectedId = getEventHash(buildCurrentAccountIdentityProofEvent(request));
|
|
262
|
+
if (event.id.toLowerCase() !== expectedId)
|
|
263
|
+
throw new Error("signed proof event does not match proof request");
|
|
264
|
+
const signature = hexToBytes(event.sig);
|
|
265
|
+
if (!schnorr.verify(signature, hexToBytes(expectedId), request.accountIdentity))
|
|
266
|
+
throw new Error("invalid signed proof event: signature does not verify");
|
|
267
|
+
return signature;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Signs a Current proof for a leaf key and returns its 104-byte `0x8009` component data (MDK
|
|
271
|
+
* `account_identity_proof_component`). `createdAt` defaults to now (unix seconds).
|
|
272
|
+
*/
|
|
273
|
+
export async function signCurrentAccountIdentityProof(params) {
|
|
274
|
+
const request = {
|
|
275
|
+
accountIdentity: params.accountIdentity,
|
|
276
|
+
mlsSignaturePublicKey: params.mlsSignaturePublicKey,
|
|
277
|
+
ciphersuite: params.ciphersuite,
|
|
278
|
+
signatureScheme: mlsSignatureScheme(params.ciphersuite),
|
|
279
|
+
createdAt: params.createdAt ?? unixNow(),
|
|
280
|
+
};
|
|
281
|
+
// Validates the timestamp before any signer is asked.
|
|
282
|
+
buildCurrentAccountIdentityProofEvent(request);
|
|
283
|
+
const signature = typeof params.signer === "function"
|
|
284
|
+
? await params.signer(request)
|
|
285
|
+
: signatureFromSignedCurrentEvent(request, await params.signer.signEvent(buildCurrentAccountIdentityProofEvent(request)));
|
|
286
|
+
return encodeCurrentAccountIdentityProof({
|
|
287
|
+
accountIdentity: request.accountIdentity,
|
|
288
|
+
createdAt: request.createdAt,
|
|
289
|
+
signature,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function leafDictionary(leaf) {
|
|
293
|
+
return getAppDataDictionary(leaf.extensions);
|
|
294
|
+
}
|
|
295
|
+
function hasLegacyProofExtension(leaf) {
|
|
296
|
+
return leaf.extensions.some((e) => e.extensionType === ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The proof form a leaf carries, read like MDK: `0xf2f1` LeafNode extension only is Legacy, an `app_data_dictionary`
|
|
300
|
+
* `0x8009` entry only is Current. A dictionary that does not decode counts as no Current entry here; the verifier
|
|
301
|
+
* reports it as `leaf-dictionary-undecodable`.
|
|
302
|
+
*/
|
|
303
|
+
export function leafProofForm(leaf) {
|
|
304
|
+
const legacy = hasLegacyProofExtension(leaf);
|
|
305
|
+
let current = false;
|
|
306
|
+
try {
|
|
307
|
+
current =
|
|
308
|
+
leafDictionary(leaf)?.some((entry) => entry.componentId === ACCOUNT_IDENTITY_PROOF_COMPONENT_ID) ?? false;
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
current = false;
|
|
312
|
+
}
|
|
313
|
+
if (legacy && current)
|
|
314
|
+
return "both";
|
|
315
|
+
if (legacy)
|
|
316
|
+
return "legacy";
|
|
317
|
+
if (current)
|
|
318
|
+
return "current";
|
|
319
|
+
return "neither";
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The `app_components` (`0x0001`) ids a leaf advertises in its own `app_data_dictionary`, or `undefined` when it
|
|
323
|
+
* advertises none. Throws {@link AccountIdentityProofError} `leaf-dictionary-undecodable` when the dictionary or the
|
|
324
|
+
* list does not decode.
|
|
325
|
+
*/
|
|
326
|
+
export function leafAppComponents(leaf) {
|
|
327
|
+
let dictionary;
|
|
328
|
+
try {
|
|
329
|
+
dictionary = leafDictionary(leaf);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
throw new AccountIdentityProofError("leaf-dictionary-undecodable", "leaf app_data_dictionary does not decode");
|
|
333
|
+
}
|
|
334
|
+
const list = dictionary?.find((entry) => entry.componentId === APP_COMPONENTS_COMPONENT_ID);
|
|
335
|
+
if (list === undefined)
|
|
336
|
+
return undefined;
|
|
337
|
+
try {
|
|
338
|
+
return decodeComponentsList(list.data);
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
throw new AccountIdentityProofError("leaf-dictionary-undecodable", "leaf app_components list does not decode");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function credentialIdentity(leaf) {
|
|
345
|
+
let pubkey;
|
|
346
|
+
try {
|
|
347
|
+
pubkey = getCredentialPubkey(leaf.credential);
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
throw new AccountIdentityProofError("invalid-credential", `credential is not a Marmot account identity: ${err instanceof Error ? err.message : String(err)}`);
|
|
351
|
+
}
|
|
352
|
+
return hexToBytes(pubkey);
|
|
353
|
+
}
|
|
354
|
+
function verifyLegacyForm(leaf, accountIdentity, ciphersuite) {
|
|
355
|
+
const extension = leaf.extensions.find((e) => e.extensionType === ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE);
|
|
356
|
+
let proof;
|
|
357
|
+
try {
|
|
358
|
+
proof = decodeAccountIdentityProof(extension.extensionData);
|
|
359
|
+
}
|
|
360
|
+
catch (err) {
|
|
361
|
+
throw new AccountIdentityProofError("proof-malformed", `legacy proof extension does not decode: ${err instanceof Error ? err.message : String(err)}`);
|
|
362
|
+
}
|
|
363
|
+
if (!bytesEqual(proof.request.accountIdentity, accountIdentity))
|
|
364
|
+
throw new AccountIdentityProofError("proof-account-mismatch", "proof account identity does not match credential identity");
|
|
365
|
+
if (!bytesEqual(proof.request.mlsSignaturePublicKey, leaf.signaturePublicKey))
|
|
366
|
+
throw new AccountIdentityProofError("proof-signature-key-mismatch", "proof MLS signature key does not match leaf signature key");
|
|
367
|
+
if (proof.request.ciphersuite !== ciphersuite)
|
|
368
|
+
throw new AccountIdentityProofError("proof-ciphersuite-mismatch", "proof ciphersuite does not match expected ciphersuite");
|
|
369
|
+
if (proof.request.signatureScheme !== mlsSignatureScheme(ciphersuite))
|
|
370
|
+
throw new AccountIdentityProofError("proof-signature-scheme-mismatch", "proof signature scheme does not match ciphersuite");
|
|
371
|
+
let verified = false;
|
|
372
|
+
try {
|
|
373
|
+
verified = schnorr.verify(proof.signature, accountIdentityProofSigningDigest(proof.request), accountIdentity);
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
verified = false;
|
|
377
|
+
}
|
|
378
|
+
if (!verified)
|
|
379
|
+
throw new AccountIdentityProofError("proof-signature-invalid", "proof signature does not verify for credential identity");
|
|
380
|
+
}
|
|
381
|
+
function verifyCurrentForm(leaf, accountIdentity, ciphersuite) {
|
|
382
|
+
const advertised = leafAppComponents(leaf) ?? [];
|
|
383
|
+
if (!advertised.includes(ACCOUNT_IDENTITY_PROOF_COMPONENT_ID))
|
|
384
|
+
throw new AccountIdentityProofError("proof-not-advertised", "current proof component 0x8009 is not advertised in leaf app_components");
|
|
385
|
+
const data = leafDictionary(leaf).find((entry) => entry.componentId === ACCOUNT_IDENTITY_PROOF_COMPONENT_ID).data;
|
|
386
|
+
verifyCurrentAccountIdentityProofForKey(data, accountIdentity, leaf.signaturePublicKey, ciphersuite);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Verifies a leaf's account identity proof in whichever single form it carries and returns that form's profile (MDK
|
|
390
|
+
* `validate_leaf_account_identity_proof`). With `expected`, a valid proof in the other form is rejected `wrong-form`
|
|
391
|
+
* (MDK `ensure_profile`). Throws {@link AccountIdentityProofError}:
|
|
392
|
+
* `both-forms` / `no-proof` first, then the form's own checks. The Legacy form's checks and their order are exactly
|
|
393
|
+
* those of `verifyLeafAccountIdentityProof` (`account-identity-proof.ts`).
|
|
394
|
+
*/
|
|
395
|
+
export function verifyLeafAccountIdentityProofForProfile(leaf, ciphersuite, expected) {
|
|
396
|
+
const accountIdentity = credentialIdentity(leaf);
|
|
397
|
+
const form = leafProofForm(leaf);
|
|
398
|
+
if (form === "both")
|
|
399
|
+
throw new AccountIdentityProofError("both-forms", "LeafNode mixes legacy proof extension 0xf2f1 with current proof component 0x8009");
|
|
400
|
+
if (form === "neither") {
|
|
401
|
+
// A dictionary that does not decode is its own reason, not a missing proof.
|
|
402
|
+
leafAppComponents(leaf);
|
|
403
|
+
throw new AccountIdentityProofError("no-proof", "missing account identity proof: LeafNode carries neither legacy proof extension 0xf2f1 nor current proof component 0x8009");
|
|
404
|
+
}
|
|
405
|
+
if (form === "legacy")
|
|
406
|
+
verifyLegacyForm(leaf, accountIdentity, ciphersuite);
|
|
407
|
+
else
|
|
408
|
+
verifyCurrentForm(leaf, accountIdentity, ciphersuite);
|
|
409
|
+
if (expected !== undefined && form !== expected)
|
|
410
|
+
throw new AccountIdentityProofError("wrong-form", `leaf uses the ${form} proof form in a ${expected} group`);
|
|
411
|
+
return form;
|
|
412
|
+
}
|
|
413
|
+
/** {@link verifyLeafAccountIdentityProofForProfile} as a result instead of a throw. */
|
|
414
|
+
export function checkLeafAccountIdentityProof(leaf, ciphersuite, expected) {
|
|
415
|
+
try {
|
|
416
|
+
return {
|
|
417
|
+
valid: true,
|
|
418
|
+
profile: verifyLeafAccountIdentityProofForProfile(leaf, ciphersuite, expected),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
catch (err) {
|
|
422
|
+
if (err instanceof AccountIdentityProofError)
|
|
423
|
+
return { valid: false, reason: err.reason, message: err.message };
|
|
424
|
+
return {
|
|
425
|
+
valid: false,
|
|
426
|
+
reason: "proof-malformed",
|
|
427
|
+
message: err instanceof Error ? err.message : String(err),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// ---------------------------------------------------------------------------
|
|
432
|
+
// Leaf extension builders
|
|
433
|
+
// ---------------------------------------------------------------------------
|
|
434
|
+
function leafDictionaryEntries(proofComponent, supportedIds) {
|
|
435
|
+
const ids = [
|
|
436
|
+
...new Set([...supportedIds, ACCOUNT_IDENTITY_PROOF_COMPONENT_ID]),
|
|
437
|
+
].filter((id) => id >= PRIVATE_USE_APP_COMPONENT_ID_START);
|
|
438
|
+
return [
|
|
439
|
+
{
|
|
440
|
+
componentId: APP_COMPONENTS_COMPONENT_ID,
|
|
441
|
+
data: encodeComponentsList([APP_COMPONENTS_COMPONENT_ID, ...ids]),
|
|
442
|
+
},
|
|
443
|
+
{ componentId: SAFE_AAD_COMPONENT_ID, data: encodeComponentsList([]) },
|
|
444
|
+
{ componentId: ACCOUNT_IDENTITY_PROOF_COMPONENT_ID, data: proofComponent },
|
|
445
|
+
];
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* The `app_data_dictionary` LeafNode extension of a Current-form leaf: the `app_components` (`0x0001`) list
|
|
449
|
+
* (`0x0001` itself plus `supportedIds`, which always gains `0x8009`), the SafeAAD advertisement (`0x0002`, empty
|
|
450
|
+
* list, as the Legacy leaf) and the 104-byte proof under `0x8009` — MDK's Current leaf shape.
|
|
451
|
+
*/
|
|
452
|
+
export function makeCurrentLeafAppDataExtension(proofComponent, supportedIds = CURRENT_PROFILE_LEAF_APP_COMPONENT_IDS) {
|
|
453
|
+
return makeAppDataDictionaryExtension(leafDictionaryEntries(proofComponent, supportedIds));
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* `extensions` (a leaf's) with its proof replaced by `material`, every other extension unchanged and in place:
|
|
457
|
+
* - Legacy: the `0xf2f1` extension is replaced (appended when absent) — the rekey behaviour before profiles existed.
|
|
458
|
+
* - Current: the `0x8009` entry of the leaf `app_data_dictionary` is replaced (added when absent, with `0x8009` added
|
|
459
|
+
* to its `app_components`; a leaf with no dictionary gains the Current leaf dictionary), every other entry kept.
|
|
460
|
+
* Throws when the leaf dictionary does not decode.
|
|
461
|
+
*/
|
|
462
|
+
export function leafExtensionsWithProof(extensions, material) {
|
|
463
|
+
if (material.profile === "legacy") {
|
|
464
|
+
const out = [];
|
|
465
|
+
let replaced = false;
|
|
466
|
+
for (const extension of extensions) {
|
|
467
|
+
if (extension.extensionType === ACCOUNT_IDENTITY_PROOF_EXTENSION_TYPE) {
|
|
468
|
+
if (!replaced)
|
|
469
|
+
out.push(material.extension);
|
|
470
|
+
replaced = true;
|
|
471
|
+
}
|
|
472
|
+
else
|
|
473
|
+
out.push(extension);
|
|
474
|
+
}
|
|
475
|
+
if (!replaced)
|
|
476
|
+
out.push(material.extension);
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
479
|
+
const dictionaryAt = extensions.findIndex((e) => e.extensionType === appDataDictionaryExtensionType);
|
|
480
|
+
if (dictionaryAt < 0)
|
|
481
|
+
return [...extensions, makeCurrentLeafAppDataExtension(material.component)];
|
|
482
|
+
const entries = getAppDataDictionary([
|
|
483
|
+
extensions[dictionaryAt],
|
|
484
|
+
]);
|
|
485
|
+
const next = [];
|
|
486
|
+
for (const entry of entries) {
|
|
487
|
+
if (entry.componentId === ACCOUNT_IDENTITY_PROOF_COMPONENT_ID)
|
|
488
|
+
continue;
|
|
489
|
+
if (entry.componentId === APP_COMPONENTS_COMPONENT_ID) {
|
|
490
|
+
const ids = decodeComponentsList(entry.data);
|
|
491
|
+
next.push({
|
|
492
|
+
componentId: APP_COMPONENTS_COMPONENT_ID,
|
|
493
|
+
data: encodeComponentsList([...ids, ACCOUNT_IDENTITY_PROOF_COMPONENT_ID]),
|
|
494
|
+
});
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
next.push(entry);
|
|
498
|
+
}
|
|
499
|
+
if (!next.some((e) => e.componentId === APP_COMPONENTS_COMPONENT_ID))
|
|
500
|
+
next.push({
|
|
501
|
+
componentId: APP_COMPONENTS_COMPONENT_ID,
|
|
502
|
+
data: encodeComponentsList([
|
|
503
|
+
APP_COMPONENTS_COMPONENT_ID,
|
|
504
|
+
ACCOUNT_IDENTITY_PROOF_COMPONENT_ID,
|
|
505
|
+
]),
|
|
506
|
+
});
|
|
507
|
+
next.push({
|
|
508
|
+
componentId: ACCOUNT_IDENTITY_PROOF_COMPONENT_ID,
|
|
509
|
+
data: material.component,
|
|
510
|
+
});
|
|
511
|
+
next.sort((a, b) => a.componentId - b.componentId);
|
|
512
|
+
const out = [...extensions];
|
|
513
|
+
out[dictionaryAt] = makeAppDataDictionaryExtension(next);
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* The 104-byte Current proof a leaf carries, or `undefined` when it carries none (no dictionary entry, or a dictionary
|
|
518
|
+
* that does not decode).
|
|
519
|
+
*/
|
|
520
|
+
export function currentProofComponentOf(leaf) {
|
|
521
|
+
try {
|
|
522
|
+
return leafDictionary(leaf)?.find((entry) => entry.componentId === ACCOUNT_IDENTITY_PROOF_COMPONENT_ID)?.data;
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
return undefined;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function bytesEqual(a, b) {
|
|
529
|
+
if (a.length !== b.length)
|
|
530
|
+
return false;
|
|
531
|
+
for (let i = 0; i < a.length; i++)
|
|
532
|
+
if (a[i] !== b[i])
|
|
533
|
+
return false;
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NIP-65 relay list event kind. Marmot uses an account's NIP-65 list to
|
|
3
|
+
* discover where it publishes and fetches KeyPackages; there is no dedicated
|
|
4
|
+
* KeyPackage relay list (transports/nostr.md "KeyPackage publication").
|
|
5
|
+
*/
|
|
6
|
+
export declare const NIP65_RELAY_LIST_KIND = 10002;
|
|
7
|
+
/** The NIP-65 relay tag (`r`), optionally followed by a read/write marker. */
|
|
8
|
+
export declare const NIP65_RELAY_TAG = "r";
|
|
9
|
+
/**
|
|
10
|
+
* Marmot inbox relay list event kind (kind 10050). Welcomes are gift-wrapped to
|
|
11
|
+
* the recipient's inbox relay set (transports/nostr.md "Publish targets").
|
|
12
|
+
*/
|
|
13
|
+
export declare const INBOX_RELAY_LIST_KIND = 10050;
|
|
14
|
+
/** The inbox relay-list tag (`relay`) carrying a single relay URL. */
|
|
15
|
+
export declare const INBOX_RELAY_TAG = "relay";
|
|
16
|
+
/** Event kind for addressable key package events */
|
|
17
|
+
export declare const ADDRESSABLE_KEY_PACKAGE_KIND = 30443;
|
|
18
|
+
/** The name of the tag that contains the MLS protocol version */
|
|
19
|
+
export declare const KEY_PACKAGE_MLS_VERSION_TAG = "mls_protocol_version";
|
|
20
|
+
/** The name of the tag that contains the MLS cipher suite */
|
|
21
|
+
export declare const KEY_PACKAGE_CIPHER_SUITE_TAG = "mls_ciphersuite";
|
|
22
|
+
/** The name of the tag that contains the MLS extensions */
|
|
23
|
+
export declare const KEY_PACKAGE_EXTENSIONS_TAG = "mls_extensions";
|
|
24
|
+
/** The name of the tag that contains the supported MLS proposal ids */
|
|
25
|
+
export declare const KEY_PACKAGE_PROPOSALS_TAG = "mls_proposals";
|
|
26
|
+
/** The name of the tag that contains the supported Marmot app-component ids */
|
|
27
|
+
export declare const KEY_PACKAGE_APP_COMPONENTS_TAG = "app_components";
|
|
28
|
+
/** The name of the tag that contains the relays */
|
|
29
|
+
export declare const KEY_PACKAGE_RELAYS_TAG = "relays";
|
|
30
|
+
/** The name of the tag that contains the client */
|
|
31
|
+
export declare const KEY_PACKAGE_CLIENT_TAG = "client";
|
|
32
|
+
/** The possible MLS protocol versions */
|
|
33
|
+
export type MLS_VERSIONS = "1.0";
|
|
34
|
+
/** Parsed client tag from a kind 30443 event */
|
|
35
|
+
export type KeyPackageClient = {
|
|
36
|
+
name: string;
|
|
37
|
+
};
|
|
38
|
+
/** Extended extension types that include Marmot-specific extensions */
|
|
39
|
+
export declare const extendedExtensionTypes: {
|
|
40
|
+
readonly application_id: 1;
|
|
41
|
+
readonly ratchet_tree: 2;
|
|
42
|
+
readonly required_capabilities: 3;
|
|
43
|
+
readonly external_pub: 4;
|
|
44
|
+
readonly external_senders: 5;
|
|
45
|
+
};
|
|
46
|
+
export type ExtendedExtensionTypeName = keyof typeof extendedExtensionTypes;
|
|
47
|
+
export type ExtendedExtensionTypeValue = (typeof extendedExtensionTypes)[ExtendedExtensionTypeName];
|
|
48
|
+
/** Event kind for group events (commits, proposals, application messages) */
|
|
49
|
+
export declare const GROUP_EVENT_KIND = 445;
|
|
50
|
+
/** Event kind for welcome events */
|
|
51
|
+
export declare const WELCOME_EVENT_KIND = 444;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** @module @category Core - Constants */
|
|
2
|
+
import { defaultExtensionTypes } from "ts-mls";
|
|
3
|
+
/**
|
|
4
|
+
* NIP-65 relay list event kind. Marmot uses an account's NIP-65 list to
|
|
5
|
+
* discover where it publishes and fetches KeyPackages; there is no dedicated
|
|
6
|
+
* KeyPackage relay list (transports/nostr.md "KeyPackage publication").
|
|
7
|
+
*/
|
|
8
|
+
export const NIP65_RELAY_LIST_KIND = 10002;
|
|
9
|
+
/** The NIP-65 relay tag (`r`), optionally followed by a read/write marker. */
|
|
10
|
+
export const NIP65_RELAY_TAG = "r";
|
|
11
|
+
/**
|
|
12
|
+
* Marmot inbox relay list event kind (kind 10050). Welcomes are gift-wrapped to
|
|
13
|
+
* the recipient's inbox relay set (transports/nostr.md "Publish targets").
|
|
14
|
+
*/
|
|
15
|
+
export const INBOX_RELAY_LIST_KIND = 10050;
|
|
16
|
+
/** The inbox relay-list tag (`relay`) carrying a single relay URL. */
|
|
17
|
+
export const INBOX_RELAY_TAG = "relay";
|
|
18
|
+
/** Event kind for addressable key package events */
|
|
19
|
+
export const ADDRESSABLE_KEY_PACKAGE_KIND = 30443;
|
|
20
|
+
/** The name of the tag that contains the MLS protocol version */
|
|
21
|
+
export const KEY_PACKAGE_MLS_VERSION_TAG = "mls_protocol_version";
|
|
22
|
+
/** The name of the tag that contains the MLS cipher suite */
|
|
23
|
+
export const KEY_PACKAGE_CIPHER_SUITE_TAG = "mls_ciphersuite";
|
|
24
|
+
/** The name of the tag that contains the MLS extensions */
|
|
25
|
+
export const KEY_PACKAGE_EXTENSIONS_TAG = "mls_extensions";
|
|
26
|
+
/** The name of the tag that contains the supported MLS proposal ids */
|
|
27
|
+
export const KEY_PACKAGE_PROPOSALS_TAG = "mls_proposals";
|
|
28
|
+
/** The name of the tag that contains the supported Marmot app-component ids */
|
|
29
|
+
export const KEY_PACKAGE_APP_COMPONENTS_TAG = "app_components";
|
|
30
|
+
/** The name of the tag that contains the relays */
|
|
31
|
+
export const KEY_PACKAGE_RELAYS_TAG = "relays";
|
|
32
|
+
/** The name of the tag that contains the client */
|
|
33
|
+
export const KEY_PACKAGE_CLIENT_TAG = "client";
|
|
34
|
+
/** Extended extension types that include Marmot-specific extensions */
|
|
35
|
+
export const extendedExtensionTypes = {
|
|
36
|
+
...defaultExtensionTypes,
|
|
37
|
+
};
|
|
38
|
+
/** Event kind for group events (commits, proposals, application messages) */
|
|
39
|
+
export const GROUP_EVENT_KIND = 445;
|
|
40
|
+
/** Event kind for welcome events */
|
|
41
|
+
export const WELCOME_EVENT_KIND = 444;
|