@did-btcr2/method 0.29.0 → 0.32.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.
Files changed (104) hide show
  1. package/README.md +13 -5
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +8174 -7157
  4. package/dist/browser.mjs +8174 -7157
  5. package/dist/cjs/index.js +1845 -455
  6. package/dist/esm/core/aggregation/transport/factory.js +15 -6
  7. package/dist/esm/core/aggregation/transport/factory.js.map +1 -1
  8. package/dist/esm/core/aggregation/transport/http/client.js +350 -0
  9. package/dist/esm/core/aggregation/transport/http/client.js.map +1 -0
  10. package/dist/esm/core/aggregation/transport/http/envelope.js +126 -0
  11. package/dist/esm/core/aggregation/transport/http/envelope.js.map +1 -0
  12. package/dist/esm/core/aggregation/transport/http/errors.js +11 -0
  13. package/dist/esm/core/aggregation/transport/http/errors.js.map +1 -0
  14. package/dist/esm/core/aggregation/transport/http/inbox-buffer.js +45 -0
  15. package/dist/esm/core/aggregation/transport/http/inbox-buffer.js.map +1 -0
  16. package/dist/esm/core/aggregation/transport/http/index.js +12 -0
  17. package/dist/esm/core/aggregation/transport/http/index.js.map +1 -0
  18. package/dist/esm/core/aggregation/transport/http/nonce-cache.js +38 -0
  19. package/dist/esm/core/aggregation/transport/http/nonce-cache.js.map +1 -0
  20. package/dist/esm/core/aggregation/transport/http/protocol.js +28 -0
  21. package/dist/esm/core/aggregation/transport/http/protocol.js.map +1 -0
  22. package/dist/esm/core/aggregation/transport/http/rate-limiter.js +45 -0
  23. package/dist/esm/core/aggregation/transport/http/rate-limiter.js.map +1 -0
  24. package/dist/esm/core/aggregation/transport/http/request-auth.js +100 -0
  25. package/dist/esm/core/aggregation/transport/http/request-auth.js.map +1 -0
  26. package/dist/esm/core/aggregation/transport/http/server.js +481 -0
  27. package/dist/esm/core/aggregation/transport/http/server.js.map +1 -0
  28. package/dist/esm/core/aggregation/transport/http/sse-stream.js +110 -0
  29. package/dist/esm/core/aggregation/transport/http/sse-stream.js.map +1 -0
  30. package/dist/esm/core/aggregation/transport/http/sse-writer.js +25 -0
  31. package/dist/esm/core/aggregation/transport/http/sse-writer.js.map +1 -0
  32. package/dist/esm/core/aggregation/transport/index.js +1 -0
  33. package/dist/esm/core/aggregation/transport/index.js.map +1 -1
  34. package/dist/esm/core/beacon/beacon.js +197 -51
  35. package/dist/esm/core/beacon/beacon.js.map +1 -1
  36. package/dist/esm/core/beacon/cas-beacon.js +3 -3
  37. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  38. package/dist/esm/core/beacon/singleton-beacon.js +3 -3
  39. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  40. package/dist/esm/core/beacon/smt-beacon.js +3 -3
  41. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  42. package/dist/esm/core/updater.js +63 -55
  43. package/dist/esm/core/updater.js.map +1 -1
  44. package/dist/types/core/aggregation/transport/factory.d.ts +22 -7
  45. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -1
  46. package/dist/types/core/aggregation/transport/http/client.d.ts +48 -0
  47. package/dist/types/core/aggregation/transport/http/client.d.ts.map +1 -0
  48. package/dist/types/core/aggregation/transport/http/envelope.d.ts +64 -0
  49. package/dist/types/core/aggregation/transport/http/envelope.d.ts.map +1 -0
  50. package/dist/types/core/aggregation/transport/http/errors.d.ts +9 -0
  51. package/dist/types/core/aggregation/transport/http/errors.d.ts.map +1 -0
  52. package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts +32 -0
  53. package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts.map +1 -0
  54. package/dist/types/core/aggregation/transport/http/index.d.ts +12 -0
  55. package/dist/types/core/aggregation/transport/http/index.d.ts.map +1 -0
  56. package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts +26 -0
  57. package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts.map +1 -0
  58. package/dist/types/core/aggregation/transport/http/protocol.d.ts +53 -0
  59. package/dist/types/core/aggregation/transport/http/protocol.d.ts.map +1 -0
  60. package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts +41 -0
  61. package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts.map +1 -0
  62. package/dist/types/core/aggregation/transport/http/request-auth.d.ts +50 -0
  63. package/dist/types/core/aggregation/transport/http/request-auth.d.ts.map +1 -0
  64. package/dist/types/core/aggregation/transport/http/server.d.ts +110 -0
  65. package/dist/types/core/aggregation/transport/http/server.d.ts.map +1 -0
  66. package/dist/types/core/aggregation/transport/http/sse-stream.d.ts +34 -0
  67. package/dist/types/core/aggregation/transport/http/sse-stream.d.ts.map +1 -0
  68. package/dist/types/core/aggregation/transport/http/sse-writer.d.ts +12 -0
  69. package/dist/types/core/aggregation/transport/http/sse-writer.d.ts.map +1 -0
  70. package/dist/types/core/aggregation/transport/index.d.ts +1 -0
  71. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -1
  72. package/dist/types/core/aggregation/transport/transport.d.ts +1 -1
  73. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -1
  74. package/dist/types/core/beacon/beacon.d.ts +72 -12
  75. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  76. package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
  77. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  78. package/dist/types/core/beacon/singleton-beacon.d.ts +3 -3
  79. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  80. package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
  81. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  82. package/dist/types/core/updater.d.ts +27 -12
  83. package/dist/types/core/updater.d.ts.map +1 -1
  84. package/package.json +5 -5
  85. package/src/core/aggregation/transport/factory.ts +48 -12
  86. package/src/core/aggregation/transport/http/client.ts +409 -0
  87. package/src/core/aggregation/transport/http/envelope.ts +204 -0
  88. package/src/core/aggregation/transport/http/errors.ts +11 -0
  89. package/src/core/aggregation/transport/http/inbox-buffer.ts +53 -0
  90. package/src/core/aggregation/transport/http/index.ts +11 -0
  91. package/src/core/aggregation/transport/http/nonce-cache.ts +43 -0
  92. package/src/core/aggregation/transport/http/protocol.ts +57 -0
  93. package/src/core/aggregation/transport/http/rate-limiter.ts +75 -0
  94. package/src/core/aggregation/transport/http/request-auth.ts +164 -0
  95. package/src/core/aggregation/transport/http/server.ts +615 -0
  96. package/src/core/aggregation/transport/http/sse-stream.ts +121 -0
  97. package/src/core/aggregation/transport/http/sse-writer.ts +23 -0
  98. package/src/core/aggregation/transport/index.ts +1 -0
  99. package/src/core/aggregation/transport/transport.ts +1 -1
  100. package/src/core/beacon/beacon.ts +255 -64
  101. package/src/core/beacon/cas-beacon.ts +4 -4
  102. package/src/core/beacon/singleton-beacon.ts +4 -4
  103. package/src/core/beacon/smt-beacon.ts +4 -4
  104. package/src/core/updater.ts +113 -67
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Bounded anti-replay cache for `(did, nonce)` pairs.
3
+ *
4
+ * Replay windowing is the caller's responsibility — this cache only detects
5
+ * duplicates. Callers are expected to reject envelopes/headers whose timestamp
6
+ * is outside the clock-skew window *before* consulting the cache, so entries
7
+ * here are always within the protocol's acceptable window.
8
+ *
9
+ * Eviction is strict-FIFO (Map insertion order) once `maxEntries` is reached.
10
+ */
11
+ export class NonceCache {
12
+ #maxEntries;
13
+ #entries = new Map();
14
+ constructor(config = {}) {
15
+ this.#maxEntries = config.maxEntries ?? 10_000;
16
+ }
17
+ /**
18
+ * Record a nonce. Returns `true` if it was novel (caller should accept the
19
+ * request) or `false` if it was a replay (caller should reject).
20
+ */
21
+ store(did, nonce, timestampSec) {
22
+ const key = `${did}:${nonce}`;
23
+ if (this.#entries.has(key))
24
+ return false;
25
+ this.#entries.set(key, timestampSec);
26
+ if (this.#entries.size > this.#maxEntries) {
27
+ const oldest = this.#entries.keys().next();
28
+ if (!oldest.done)
29
+ this.#entries.delete(oldest.value);
30
+ }
31
+ return true;
32
+ }
33
+ /** Current cache size. Exposed for observability and tests. */
34
+ size() {
35
+ return this.#entries.size;
36
+ }
37
+ }
38
+ //# sourceMappingURL=nonce-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonce-cache.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/nonce-cache.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACZ,WAAW,CAAS;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE9C,YAAY,SAA2B,EAAE;QACvC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC;IACjD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAW,EAAE,KAAa,EAAE,YAAoB;QACpD,MAAM,GAAG,GAAG,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QAC9B,IAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QACrC,IAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAC3C,IAAG,CAAC,MAAM,CAAC,IAAI;gBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * On-the-wire version of the HTTP transport envelope. Separate from
3
+ * {@link AGGREGATION_WIRE_VERSION} (which versions the aggregation protocol
4
+ * payloads) so transport-layer changes don't force a protocol bump.
5
+ */
6
+ export const HTTP_ENVELOPE_VERSION = 1;
7
+ /**
8
+ * HTTP routes served by {@link HttpServerTransport}. The `{did}` placeholder
9
+ * in {@link HTTP_ROUTE.ACTOR_INBOX} is substituted with a URL-safe DID at
10
+ * request time.
11
+ */
12
+ export const HTTP_ROUTE = {
13
+ ADVERTS: '/v1/adverts',
14
+ MESSAGES: '/v1/messages',
15
+ ACTOR_INBOX: '/v1/actors/{did}/inbox',
16
+ WELL_KNOWN: '/v1/.well-known/aggregation',
17
+ };
18
+ /** Server-Sent Events event names used by the broadcast + inbox streams. */
19
+ export const SSE_EVENT = {
20
+ ADVERT: 'advert',
21
+ MESSAGE: 'message',
22
+ HEARTBEAT: 'heartbeat',
23
+ };
24
+ /** Default clock-skew tolerance for envelope timestamps (seconds). */
25
+ export const DEFAULT_CLOCK_SKEW_SEC = 60;
26
+ /** Default length of the per-envelope anti-replay nonce (bytes). */
27
+ export const DEFAULT_NONCE_LEN_BYTES = 16;
28
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAO,aAAa;IAC3B,QAAQ,EAAM,cAAc;IAC5B,WAAW,EAAG,wBAAwB;IACtC,UAAU,EAAI,6BAA6B;CACnC,CAAC;AAEX,4EAA4E;AAC5E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAM,QAAQ;IACpB,OAAO,EAAK,SAAS;IACrB,SAAS,EAAG,WAAW;CACf,CAAC;AAEX,sEAAsE;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAEzC,oEAAoE;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC"}
@@ -0,0 +1,45 @@
1
+ export class InMemoryRateLimitStore {
2
+ #buckets = new Map();
3
+ get(key) {
4
+ return this.#buckets.get(key);
5
+ }
6
+ set(key, state) {
7
+ this.#buckets.set(key, state);
8
+ }
9
+ }
10
+ /**
11
+ * Token-bucket rate limiter keyed by an opaque string (typically a verified
12
+ * sender DID). Tokens refill linearly at `rps` up to `burst`. Each `consume`
13
+ * call atomically debits one token or returns `false` to reject.
14
+ *
15
+ * The limiter is synchronous and deterministic given `nowMs` — tests can
16
+ * drive it with a fixed clock to exercise exact boundaries.
17
+ */
18
+ export class RateLimiter {
19
+ #rps;
20
+ #burst;
21
+ #store;
22
+ constructor(config = {}) {
23
+ this.#rps = config.rps ?? 10;
24
+ this.#burst = config.burst ?? 30;
25
+ this.#store = config.store ?? new InMemoryRateLimitStore();
26
+ }
27
+ /** Consume one token for `key`. Returns `true` if accepted, `false` if throttled. */
28
+ consume(key, nowMs) {
29
+ const existing = this.#store.get(key);
30
+ const state = existing ?? { tokens: this.#burst, lastRefillMs: nowMs };
31
+ if (existing) {
32
+ const elapsedSec = Math.max(0, (nowMs - existing.lastRefillMs) / 1000);
33
+ state.tokens = Math.min(this.#burst, existing.tokens + elapsedSec * this.#rps);
34
+ state.lastRefillMs = nowMs;
35
+ }
36
+ if (state.tokens < 1) {
37
+ this.#store.set(key, state);
38
+ return false;
39
+ }
40
+ state.tokens -= 1;
41
+ this.#store.set(key, state);
42
+ return true;
43
+ }
44
+ }
45
+ //# sourceMappingURL=rate-limiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/rate-limiter.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,sBAAsB;IACxB,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEnD,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC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AAK,CAAC;QACf,CAAC;QACD,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,100 @@
1
+ import { canonicalHashBytes } from '@did-btcr2/common';
2
+ import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';
3
+ import { HttpTransportError } from './errors.js';
4
+ import { DEFAULT_CLOCK_SKEW_SEC, DEFAULT_NONCE_LEN_BYTES, HTTP_ENVELOPE_VERSION } from './protocol.js';
5
+ /**
6
+ * `Authorization`-header scheme used to authenticate SSE subscription
7
+ * requests. The header value takes the form
8
+ * `BTCR2-Sig v=<n>,did=<did>,ts=<unix>,nonce=<hex>,sig=<hex>`.
9
+ *
10
+ * Used only for GET endpoints (SSE inbox subscribe). POST endpoints carry a
11
+ * full {@link SignedEnvelope} in the request body instead.
12
+ */
13
+ export const REQUEST_AUTH_SCHEME = 'BTCR2-Sig';
14
+ /**
15
+ * Build an `Authorization` header value proving the caller controls the
16
+ * private key for `did`. Covers a specific request path so the signature
17
+ * can't be replayed against a different endpoint.
18
+ */
19
+ export function buildRequestAuth(did, keys, path, opts = {}) {
20
+ const ts = opts.timestamp ?? Math.floor(Date.now() / 1000);
21
+ const nonce = opts.nonce ?? bytesToHex(randomBytes(DEFAULT_NONCE_LEN_BYTES));
22
+ const digest = canonicalHashBytes({
23
+ v: HTTP_ENVELOPE_VERSION,
24
+ did,
25
+ ts,
26
+ nonce,
27
+ path,
28
+ });
29
+ const sig = keys.secretKey.sign(digest, { scheme: 'schnorr' });
30
+ return `${REQUEST_AUTH_SCHEME} v=${HTTP_ENVELOPE_VERSION},did=${did},ts=${ts},nonce=${nonce},sig=${bytesToHex(sig)}`;
31
+ }
32
+ /**
33
+ * Parse a `BTCR2-Sig` auth header value into its structured fields. Does NOT
34
+ * verify the signature — call {@link verifyRequestAuth} for that.
35
+ */
36
+ export function parseRequestAuth(headerValue) {
37
+ const prefix = `${REQUEST_AUTH_SCHEME} `;
38
+ if (!headerValue.startsWith(prefix)) {
39
+ throw new HttpTransportError(`Unexpected auth scheme (want ${REQUEST_AUTH_SCHEME})`, 'REQUEST_AUTH_SCHEME');
40
+ }
41
+ const params = {};
42
+ for (const piece of headerValue.slice(prefix.length).split(',')) {
43
+ const eq = piece.indexOf('=');
44
+ if (eq === -1)
45
+ continue;
46
+ const key = piece.slice(0, eq).trim();
47
+ const val = piece.slice(eq + 1).trim();
48
+ if (key.length > 0)
49
+ params[key] = val;
50
+ }
51
+ const v = Number(params.v);
52
+ const ts = Number(params.ts);
53
+ if (!Number.isInteger(v) || !Number.isInteger(ts) || !params.did || !params.nonce || !params.sig) {
54
+ throw new HttpTransportError('Malformed auth header (missing or invalid field)', 'REQUEST_AUTH_MALFORMED', { received: Object.keys(params) });
55
+ }
56
+ return { v, did: params.did, ts, nonce: params.nonce, sig: params.sig };
57
+ }
58
+ /**
59
+ * Parse + verify an auth header. Throws {@link HttpTransportError} on any
60
+ * failure; returns the parsed fields on success.
61
+ *
62
+ * `expectedPath` must match the path the signature commits to. `senderPk`
63
+ * must correspond to the DID the signer claims.
64
+ */
65
+ export function verifyRequestAuth(headerValue, expectedPath, senderPk, opts = {}) {
66
+ const parsed = parseRequestAuth(headerValue);
67
+ if (parsed.v !== HTTP_ENVELOPE_VERSION) {
68
+ throw new HttpTransportError(`Unsupported auth version: ${parsed.v}`, 'REQUEST_AUTH_VERSION_MISMATCH', { version: parsed.v, expected: HTTP_ENVELOPE_VERSION });
69
+ }
70
+ const skewSec = opts.clockSkewSec ?? DEFAULT_CLOCK_SKEW_SEC;
71
+ const nowMs = opts.now ? opts.now() : Date.now();
72
+ const nowSec = Math.floor(nowMs / 1000);
73
+ const diff = Math.abs(nowSec - parsed.ts);
74
+ if (diff > skewSec) {
75
+ throw new HttpTransportError(`Auth timestamp out of skew: ${diff}s > ${skewSec}s`, 'REQUEST_AUTH_TIMESTAMP_SKEW', { diff, skewSec });
76
+ }
77
+ let sigBytes;
78
+ try {
79
+ sigBytes = hexToBytes(parsed.sig);
80
+ }
81
+ catch {
82
+ throw new HttpTransportError('Auth signature is not valid hex', 'REQUEST_AUTH_SIG_HEX');
83
+ }
84
+ if (sigBytes.length !== 64) {
85
+ throw new HttpTransportError(`Invalid auth signature length: ${sigBytes.length}`, 'REQUEST_AUTH_SIG_LENGTH', { length: sigBytes.length });
86
+ }
87
+ const digest = canonicalHashBytes({
88
+ v: parsed.v,
89
+ did: parsed.did,
90
+ ts: parsed.ts,
91
+ nonce: parsed.nonce,
92
+ path: expectedPath,
93
+ });
94
+ const ok = senderPk.verify(sigBytes, digest, { scheme: 'schnorr' });
95
+ if (!ok) {
96
+ throw new HttpTransportError('Auth signature verification failed', 'REQUEST_AUTH_SIG_INVALID');
97
+ }
98
+ return parsed;
99
+ }
100
+ //# sourceMappingURL=request-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-auth.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/request-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEvG;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAoB/C;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAY,EACZ,IAAoB,EACpB,IAAY,EACZ,OAAgC,EAAE;IAElC,MAAM,EAAE,GAAM,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,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