@estiva-app/protocol 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/dist/bridge.d.ts +46 -7
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js +220 -12
- package/dist/bridge.js.map +1 -1
- package/dist/events.d.ts +73 -4
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +87 -4
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bridge.ts +258 -4
- package/src/events.ts +99 -4
- package/src/index.ts +3 -1
package/src/events.ts
CHANGED
|
@@ -125,6 +125,19 @@ export const KIND = {
|
|
|
125
125
|
*/
|
|
126
126
|
RELAY_AUTH: 22242,
|
|
127
127
|
HTTP_AUTH: 27235,
|
|
128
|
+
/**
|
|
129
|
+
* Buzz's message edit (`KIND_STREAM_MESSAGE_EDIT`) — RFC 0.4 §7.2.1.
|
|
130
|
+
*
|
|
131
|
+
* A `kind:9` and a `kind:1111` are both non-replaceable, so an edit cannot
|
|
132
|
+
* overwrite what it edits. It is a separate event naming its target, and what
|
|
133
|
+
* an app shows as "edited" is a fold over the pair.
|
|
134
|
+
*
|
|
135
|
+
* **Channel-scoped.** 40003 is in the relay's `requires_h_channel_scope`, so
|
|
136
|
+
* an edit without an `h` comes back `accepted: false` even when the kind is
|
|
137
|
+
* granted and the signature is fine — two gates, and the kind ceiling is only
|
|
138
|
+
* the first.
|
|
139
|
+
*/
|
|
140
|
+
MESSAGE_EDIT: 40003,
|
|
128
141
|
} as const
|
|
129
142
|
|
|
130
143
|
/** `build_reaction` (builders.rs:463) caps the emoji at 64 chars. */
|
|
@@ -421,10 +434,20 @@ export function buildReaction(
|
|
|
421
434
|
/**
|
|
422
435
|
* kind:5 deletion — mirrors `build_remove_reaction` (builders.rs:495).
|
|
423
436
|
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
437
|
+
* A NIP-09 *request*: it removes the record rather than the work, and a relay
|
|
438
|
+
* may decline it.
|
|
439
|
+
*
|
|
440
|
+
* **It is not author-scoped**, and this comment said it was until 2026-09-07.
|
|
441
|
+
* `validate_standard_deletion_event` accepts the target's **effective** author
|
|
442
|
+
* *or* the NIP-OA owner of an authoring agent, on the `a` branch and the `e`
|
|
443
|
+
* branch alike. And no client can evaluate the second half — ownership is
|
|
444
|
+
* written from the attestation and read server-side only — so an app MUST NOT
|
|
445
|
+
* gate the control on an author check of its own; it offers it, attempts the
|
|
446
|
+
* write, and reports the refusal (SPEC §6.5, corrected).
|
|
447
|
+
*
|
|
448
|
+
* That the wrong rule sat *here* is why it is worth calling out: this package
|
|
449
|
+
* is what a third app reads, so a mistaken MUST propagates to every adopter
|
|
450
|
+
* before anyone notices.
|
|
428
451
|
*/
|
|
429
452
|
export function buildDeletion(
|
|
430
453
|
pubkey: string,
|
|
@@ -442,6 +465,78 @@ export function buildDeletion(
|
|
|
442
465
|
}
|
|
443
466
|
}
|
|
444
467
|
|
|
468
|
+
/**
|
|
469
|
+
* kind:40003 message edit — mirrors `build_edit` (builders.rs:378), plus `ts`.
|
|
470
|
+
*
|
|
471
|
+
* An edit never rewrites. `kind:9` and `kind:1111` are non-replaceable, so this
|
|
472
|
+
* is a separate event naming its target, and what a reader shows as "edited" is
|
|
473
|
+
* a fold over the pair — latest edit wins.
|
|
474
|
+
*
|
|
475
|
+
* ## `ts`, and why this adds a tag Buzz's builder does not
|
|
476
|
+
*
|
|
477
|
+
* `build_edit` emits `h` and `e` only, which leaves two edits published in the
|
|
478
|
+
* same second with no defined order. That is worse here than for a change
|
|
479
|
+
* event: `kind:1851` is last-write-wins **per field**, so a collision costs one
|
|
480
|
+
* field, whereas two disagreeing edits of one message resolve to whichever the
|
|
481
|
+
* reader happens to sort first.
|
|
482
|
+
*
|
|
483
|
+
* So an edit carries `ts` in epoch **milliseconds**, under exactly the rule
|
|
484
|
+
* SPEC §6.2 already gives it: a reader honours `ts` only when it agrees with
|
|
485
|
+
* `created_at` to the second, and ignores it otherwise. An app that does not
|
|
486
|
+
* implement `ts` still folds correctly, at one-second resolution.
|
|
487
|
+
*
|
|
488
|
+
* Adding a tag the relay has no rule for is safe in the direction that matters
|
|
489
|
+
* — it validates the kind, the `h` and the ownership, and ignores the rest.
|
|
490
|
+
*
|
|
491
|
+
* ## Who may edit is the relay's answer
|
|
492
|
+
*
|
|
493
|
+
* `validate_edit_ownership` accepts the target's effective author or the NIP-OA
|
|
494
|
+
* owner of an authoring agent, and on the author path re-checks channel
|
|
495
|
+
* membership — so somebody removed from a private channel cannot go back and
|
|
496
|
+
* rewrite what they said while they were in it. No client can evaluate that, so
|
|
497
|
+
* an app MUST NOT gate the control on an author check of its own. Same rule as
|
|
498
|
+
* `buildDeletion` above, and wrong in the same way until it was corrected.
|
|
499
|
+
*
|
|
500
|
+
* ## The `h` is required
|
|
501
|
+
*
|
|
502
|
+
* 40003 is in the relay's `requires_h_channel_scope`. An edit without one is
|
|
503
|
+
* refused with `accepted: false` while the kind is granted and the signature is
|
|
504
|
+
* fine — which is why it is an argument here rather than an option.
|
|
505
|
+
*/
|
|
506
|
+
export function buildEdit(
|
|
507
|
+
pubkey: string,
|
|
508
|
+
createdAtMs: number,
|
|
509
|
+
args: {
|
|
510
|
+
/** The target's channel. REQUIRED — see above. */
|
|
511
|
+
channelUuid: string
|
|
512
|
+
/** The event being edited. */
|
|
513
|
+
targetEventId: string
|
|
514
|
+
/** The new body, in the target's own format. */
|
|
515
|
+
body: string
|
|
516
|
+
},
|
|
517
|
+
): UnsignedEvent {
|
|
518
|
+
assertHex64(pubkey, 'pubkey')
|
|
519
|
+
assertHex64(args.targetEventId, 'targetEventId')
|
|
520
|
+
const bytes = utf8ToBytes(args.body).length
|
|
521
|
+
if (bytes > MAX_MESSAGE_BYTES) {
|
|
522
|
+
throw new Error(`content is ${bytes} bytes, max ${MAX_MESSAGE_BYTES}`)
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
pubkey,
|
|
526
|
+
created_at: toNostrSeconds(createdAtMs),
|
|
527
|
+
kind: KIND.MESSAGE_EDIT,
|
|
528
|
+
tags: [
|
|
529
|
+
['h', args.channelUuid],
|
|
530
|
+
['e', args.targetEventId],
|
|
531
|
+
// Floor, not round: `created_at` is `toNostrSeconds` of the same instant,
|
|
532
|
+
// and a rounded `ts` could land in the next second and be discarded by
|
|
533
|
+
// its own agreement rule.
|
|
534
|
+
['ts', String(Math.floor(createdAtMs))],
|
|
535
|
+
],
|
|
536
|
+
content: args.body,
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
445
540
|
/**
|
|
446
541
|
* NIP-10 reply context.
|
|
447
542
|
*
|
package/src/index.ts
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
48
48
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
49
49
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
50
|
-
export const PROTOCOL_VERSION = '0.
|
|
50
|
+
export const PROTOCOL_VERSION = '0.15.0'
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
53
|
// types
|
|
@@ -85,6 +85,7 @@ export {
|
|
|
85
85
|
buildAddMember,
|
|
86
86
|
buildReaction,
|
|
87
87
|
buildDeletion,
|
|
88
|
+
buildEdit,
|
|
88
89
|
buildMessage,
|
|
89
90
|
buildResolution,
|
|
90
91
|
buildFile,
|
|
@@ -146,6 +147,7 @@ export {
|
|
|
146
147
|
parseQueryResponse,
|
|
147
148
|
RELAY_PAGE_CEILING,
|
|
148
149
|
DEFAULT_QUERY_CONCURRENCY,
|
|
150
|
+
MAX_FILTERS_PER_QUERY,
|
|
149
151
|
Relay,
|
|
150
152
|
} from './bridge.js'
|
|
151
153
|
|