@minca/core 0.1.10 → 0.1.11

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 (157) hide show
  1. package/README.md +1 -1
  2. package/dist/identity/abilities.js +1 -1
  3. package/dist/identity/contact-key.d.ts +15 -15
  4. package/dist/identity/contact-key.d.ts.map +1 -1
  5. package/dist/identity/contact-key.js +21 -28
  6. package/dist/identity/contact-key.js.map +1 -1
  7. package/dist/inbox/inbox.d.ts +140 -0
  8. package/dist/inbox/inbox.d.ts.map +1 -0
  9. package/dist/inbox/inbox.js +212 -0
  10. package/dist/inbox/inbox.js.map +1 -0
  11. package/dist/inbox/index.d.ts +9 -0
  12. package/dist/inbox/index.d.ts.map +1 -0
  13. package/dist/inbox/index.js +7 -0
  14. package/dist/inbox/index.js.map +1 -0
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/network/mailbox.d.ts +4 -4
  20. package/dist/network/mailbox.d.ts.map +1 -1
  21. package/dist/network/mailbox.js +5 -5
  22. package/dist/network/mailbox.js.map +1 -1
  23. package/dist/node/actions.d.ts.map +1 -1
  24. package/dist/node/actions.js +28 -18
  25. package/dist/node/actions.js.map +1 -1
  26. package/dist/node/api.d.ts +11 -10
  27. package/dist/node/api.d.ts.map +1 -1
  28. package/dist/node/api.js +11 -10
  29. package/dist/node/api.js.map +1 -1
  30. package/dist/node/carrier.d.ts +11 -5
  31. package/dist/node/carrier.d.ts.map +1 -1
  32. package/dist/node/carrier.js +42 -1
  33. package/dist/node/carrier.js.map +1 -1
  34. package/dist/node/copy.d.ts +1 -1
  35. package/dist/node/copy.d.ts.map +1 -1
  36. package/dist/node/copy.js +10 -4
  37. package/dist/node/copy.js.map +1 -1
  38. package/dist/node/host.d.ts +2 -0
  39. package/dist/node/host.d.ts.map +1 -1
  40. package/dist/node/host.js +2 -0
  41. package/dist/node/host.js.map +1 -1
  42. package/dist/node/index.d.ts +1 -1
  43. package/dist/node/index.d.ts.map +1 -1
  44. package/dist/node/node.d.ts.map +1 -1
  45. package/dist/node/node.js +496 -295
  46. package/dist/node/node.js.map +1 -1
  47. package/dist/node/remote.d.ts.map +1 -1
  48. package/dist/node/remote.js +0 -2
  49. package/dist/node/remote.js.map +1 -1
  50. package/dist/node/space-runtime.d.ts +2 -1
  51. package/dist/node/space-runtime.d.ts.map +1 -1
  52. package/dist/node/space-runtime.js +2 -2
  53. package/dist/node/space-runtime.js.map +1 -1
  54. package/dist/node/types.d.ts +72 -43
  55. package/dist/node/types.d.ts.map +1 -1
  56. package/dist/react/use-invite-link.d.ts +1 -1
  57. package/dist/react/use-invite-link.d.ts.map +1 -1
  58. package/dist/react/use-invite-link.js +18 -11
  59. package/dist/react/use-invite-link.js.map +1 -1
  60. package/dist/records/loose.d.ts +52 -0
  61. package/dist/records/loose.d.ts.map +1 -0
  62. package/dist/records/loose.js +86 -0
  63. package/dist/records/loose.js.map +1 -0
  64. package/dist/schema/version.d.ts +2 -0
  65. package/dist/schema/version.d.ts.map +1 -1
  66. package/dist/schema/version.js +2 -1
  67. package/dist/schema/version.js.map +1 -1
  68. package/dist/schemas/choosing.d.ts +19 -0
  69. package/dist/schemas/choosing.d.ts.map +1 -0
  70. package/dist/schemas/choosing.js +69 -0
  71. package/dist/schemas/choosing.js.map +1 -0
  72. package/dist/schemas/contacts.d.ts +34 -87
  73. package/dist/schemas/contacts.d.ts.map +1 -1
  74. package/dist/schemas/contacts.js +32 -76
  75. package/dist/schemas/contacts.js.map +1 -1
  76. package/dist/schemas/index.d.ts +2 -2
  77. package/dist/schemas/index.d.ts.map +1 -1
  78. package/dist/schemas/index.js +1 -1
  79. package/dist/schemas/index.js.map +1 -1
  80. package/dist/schemas/library/annotations.d.ts +17 -285
  81. package/dist/schemas/library/annotations.d.ts.map +1 -1
  82. package/dist/schemas/library/annotations.js +9 -65
  83. package/dist/schemas/library/annotations.js.map +1 -1
  84. package/dist/schemas/library/community.d.ts +9 -17
  85. package/dist/schemas/library/community.d.ts.map +1 -1
  86. package/dist/schemas/library/community.js +5 -5
  87. package/dist/schemas/library/community.js.map +1 -1
  88. package/dist/schemas/library/life.d.ts +3 -3
  89. package/dist/schemas/library/life.d.ts.map +1 -1
  90. package/dist/schemas/library/life.js +2 -2
  91. package/dist/schemas/library/life.js.map +1 -1
  92. package/dist/schemas/library/media.d.ts +148 -541
  93. package/dist/schemas/library/media.d.ts.map +1 -1
  94. package/dist/schemas/library/media.js +28 -64
  95. package/dist/schemas/library/media.js.map +1 -1
  96. package/dist/schemas/library/money.d.ts +8 -8
  97. package/dist/schemas/library/money.d.ts.map +1 -1
  98. package/dist/schemas/library/money.js +4 -4
  99. package/dist/schemas/library/money.js.map +1 -1
  100. package/dist/schemas/library/planning.d.ts +23 -87
  101. package/dist/schemas/library/planning.d.ts.map +1 -1
  102. package/dist/schemas/library/planning.js +10 -26
  103. package/dist/schemas/library/planning.js.map +1 -1
  104. package/dist/schemas/library/publishing.d.ts +14 -14
  105. package/dist/schemas/library/publishing.d.ts.map +1 -1
  106. package/dist/schemas/library/publishing.js +7 -7
  107. package/dist/schemas/library/publishing.js.map +1 -1
  108. package/dist/schemas/library/social.d.ts +2 -2
  109. package/dist/schemas/library/social.d.ts.map +1 -1
  110. package/dist/schemas/library/social.js +1 -1
  111. package/dist/schemas/library/social.js.map +1 -1
  112. package/dist/schemas/standard.d.ts +1 -1
  113. package/dist/schemas/standard.d.ts.map +1 -1
  114. package/dist/schemas/standard.js +3 -3
  115. package/dist/schemas/standard.js.map +1 -1
  116. package/dist/session/auth.js +1 -1
  117. package/dist/session/auth.js.map +1 -1
  118. package/dist/space/account-registry.d.ts +22 -0
  119. package/dist/space/account-registry.d.ts.map +1 -1
  120. package/dist/space/account-registry.js +18 -0
  121. package/dist/space/account-registry.js.map +1 -1
  122. package/dist/space/invitation.d.ts +61 -0
  123. package/dist/space/invitation.d.ts.map +1 -0
  124. package/dist/space/invitation.js +84 -0
  125. package/dist/space/invitation.js.map +1 -0
  126. package/dist/space/invite-link.d.ts +64 -0
  127. package/dist/space/invite-link.d.ts.map +1 -0
  128. package/dist/space/invite-link.js +212 -0
  129. package/dist/space/invite-link.js.map +1 -0
  130. package/dist/space/space-manager.d.ts +21 -6
  131. package/dist/space/space-manager.d.ts.map +1 -1
  132. package/dist/space/space-manager.js +40 -23
  133. package/dist/space/space-manager.js.map +1 -1
  134. package/dist/types.d.ts +2 -0
  135. package/dist/types.d.ts.map +1 -1
  136. package/dist/types.js.map +1 -1
  137. package/docs/README.md +2 -2
  138. package/docs/actions.md +37 -37
  139. package/docs/automations.md +2 -2
  140. package/docs/blueprints-and-guides.md +44 -3
  141. package/docs/building-an-app.md +2 -2
  142. package/docs/contacts.md +48 -69
  143. package/docs/inbox.md +145 -0
  144. package/docs/node.md +36 -23
  145. package/docs/query-format.md +1 -1
  146. package/docs/spaces.md +33 -5
  147. package/docs/standard-library.md +111 -86
  148. package/package.json +5 -5
  149. package/dist/doors/doors.d.ts +0 -140
  150. package/dist/doors/doors.d.ts.map +0 -1
  151. package/dist/doors/doors.js +0 -226
  152. package/dist/doors/doors.js.map +0 -1
  153. package/dist/doors/index.d.ts +0 -9
  154. package/dist/doors/index.d.ts.map +0 -1
  155. package/dist/doors/index.js +0 -7
  156. package/dist/doors/index.js.map +0 -1
  157. package/docs/doors.md +0 -151
package/README.md CHANGED
@@ -229,7 +229,7 @@ One npm workspace. Everything imports the protocol as `@minca/core`.
229
229
  | Identity: the seed, recovery code, wraps, passkeys, UCAN, root signers | [sign-in](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/sign-in.md), [node](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/node.md#root-signers-and-notes) | [01 Identity](https://github.com/leifriksheim/minca/blob/main/spec/01-identity.md) |
230
230
  | Spaces: the constitution, founders, roles and grants, invites, successors, key changes, profiles | [spaces](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/spaces.md) | [03 Spaces](https://github.com/leifriksheim/minca/blob/main/spec/03-spaces.md) |
231
231
  | Collections, schemas, rules, contracts and computed fields, links, queries, the standard library | [collections](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/collections.md), [contracts](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/contracts.md), [computed fields](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/computed.md), [query format](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/query-format.md), [standard library](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/standard-library.md), [blueprints and guides](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/blueprints-and-guides.md) | [02 Records](https://github.com/leifriksheim/minca/blob/main/spec/02-records.md), [09 Contracts](https://github.com/leifriksheim/minca/blob/main/spec/09-contracts.md) |
232
- | Calls, contacts, doors, direct messages | [calls](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/calls.md), [contacts](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/contacts.md), [doors](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/doors.md), [direct messages](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/direct-messages.md) | [07 Doors](https://github.com/leifriksheim/minca/blob/main/spec/07-doors.md), [04 Network](https://github.com/leifriksheim/minca/blob/main/spec/04-network.md) |
232
+ | Calls, contacts, the inbox, direct messages | [calls](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/calls.md), [contacts](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/contacts.md), [inbox](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/inbox.md), [direct messages](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/direct-messages.md) | [07 Inbox](https://github.com/leifriksheim/minca/blob/main/spec/07-inbox.md), [04 Network](https://github.com/leifriksheim/minca/blob/main/spec/04-network.md) |
233
233
  | Network: the relay, TURN, meeting peers, introductions, pairing a phone | [node](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/node.md#the-network), [packages/relay](https://github.com/leifriksheim/minca/blob/main/packages/relay/README.md) | [04 Network](https://github.com/leifriksheim/minca/blob/main/spec/04-network.md) |
234
234
  | Sync, storage adapters, data folders and locking them, mirrors | [storage](https://github.com/leifriksheim/minca/blob/main/packages/core/docs/storage.md) | [05 Sync and storage](https://github.com/leifriksheim/minca/blob/main/spec/05-sync-and-storage.md) |
235
235
  | Hosting: keeping spaces online, payment, bots a host runs | [packages/cli](https://github.com/leifriksheim/minca/blob/main/packages/cli/README.md) | [08 Hosting](https://github.com/leifriksheim/minca/blob/main/spec/08-hosting.md) |
@@ -13,7 +13,7 @@
13
13
  * invites, revocations, the space's key, relays and keepers;
14
14
  * - `/account/write`, about the whole account: anything about the account
15
15
  * itself — its own spaces (its list of spaces, a carrier's passes, its
16
- * doors), its own place in any space, and its other keys.
16
+ * inbox, its knocks), its own place in any space, and its other keys.
17
17
  *
18
18
  * So a key is a device or an app by what its note says: a note for `/` about
19
19
  * the whole account acts as the account; anything narrower acts in spaces.
@@ -21,31 +21,31 @@ export declare function deriveContactKeyBytes(seed: Uint8Array): Promise<Uint8Ar
21
21
  */
22
22
  export declare function deriveMemberKeyBytes(accountKey: Uint8Array, spaceId: string): Promise<Uint8Array>;
23
23
  /**
24
- * A **door key**: the key a door's knocks are sealed to (`doors/doors.ts`).
25
- * Derived from the contact key and the door's id, so every device and app
26
- * holding the contact key opens the same doors, and a new door is a new id.
24
+ * An **inbox key**: the key knocks on the account's inbox are sealed to
25
+ * (`inbox/inbox.ts`, spec 07 §1). Derived from the contact key and the
26
+ * inbox's generation, so every device and app holding the contact key opens
27
+ * the same inbox, and a new inbox is a new `gen`.
27
28
  *
28
29
  * Not the contact key itself: that one's public half is on your profile in
29
- * every space you write in, and a door is handed to people who may not know
30
- * who you are yet. A door key says nothing about the account behind it.
30
+ * every space you write in, and an inbox is handed to people who may not know
31
+ * who you are yet. An inbox key says nothing about the account behind it.
31
32
  * @param contactKey The contact key's private scalar (`deriveContactKeyBytes`)
32
- * @param doorId The door's id, as its `std.door` record names it
33
33
  */
34
- export declare function deriveDoorKeyBytes(contactKey: Uint8Array, doorId: string): Promise<Uint8Array>;
34
+ export declare function deriveInboxKeyBytes(contactKey: Uint8Array, gen: number): Promise<Uint8Array>;
35
35
  /**
36
- * A door's **signing key**: what proves you own a door, without saying whose
37
- * it is — to a relay, when clearing the door's mailbox, and to someone who
38
- * knocked, when you answer. Separate from the door key, which only opens
39
- * knocks: one key should not both sign and decrypt.
36
+ * An inbox's **signing key**: what signs the inbox, and proves to a relay
37
+ * clearing its mailbox that it is the owner, without saying whose it is.
38
+ * Separate from the inbox key, which only opens knocks: one key should not
39
+ * both sign and decrypt.
40
40
  */
41
- export declare function deriveDoorSignKeyBytes(contactKey: Uint8Array, doorId: string): Promise<Uint8Array>;
41
+ export declare function deriveInboxSignKeyBytes(contactKey: Uint8Array, gen: number): Promise<Uint8Array>;
42
+ /** A private scalar as a key to sign with (ECDSA), for what an inbox's signing key signs as a version */
43
+ export declare function signingKeyOf(secret: Uint8Array): Promise<CryptoKey>;
42
44
  /**
43
45
  * Signs with a P-256 private scalar: ECDSA over SHA-256, 64 bytes r ‖ s,
44
- * base64url — for door signing keys.
46
+ * base64url — for an inbox's signing key.
45
47
  */
46
48
  export declare function signWithScalar(secret: Uint8Array, data: Uint8Array): Promise<string>;
47
- /** Checks what `signWithScalar` signed, against a compressed public key (base64url) */
48
- export declare function verifyWithPoint(publicKey: string, data: Uint8Array, signature: string): Promise<boolean>;
49
49
  /** The public half, from the private scalar */
50
50
  export declare function contactPublicKey(secret: Uint8Array): string;
51
51
  /** Whether a string is a contact key's public half: a point on P-256 */
@@ -1 +1 @@
1
- {"version":3,"file":"contact-key.d.ts","sourceRoot":"","sources":["../../src/identity/contact-key.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,cAAc;IAC7B,oFAAoF;IACpF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wFAAwF;IACxF,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;CAChC;AA8BD;;;GAG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GG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAEjF;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAEvG;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAElG;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAEtG;AAED,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAEnE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1F;AAED,+CAA+C;AAC/C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAE3D;AAED,wEAAwE;AACxE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAQlE;AAED,sEAAsE;AACtE,wBAAsB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAGhF"}
@@ -24,8 +24,8 @@ import { hkdf } from './hkdf.js';
24
24
  /** Domain separation for the contact key. Changing it changes every account's contact key. */
25
25
  const CONTACT_KEY_INFO = 'minca/p256-contact-key/v1';
26
26
  const MEMBER_KEY_INFO = 'minca/p256-member-key/v1';
27
- const DOOR_KEY_INFO = 'minca/p256-door-key/v1';
28
- const DOOR_SIGN_KEY_INFO = 'minca/p256-door-sign-key/v1';
27
+ const INBOX_KEY_INFO = 'minca/p256-inbox-key/v1';
28
+ const INBOX_SIGN_KEY_INFO = 'minca/p256-inbox-sign-key/v1';
29
29
  /** 48 bytes reduce to a P-256 scalar without bias, as for the root key (`crypto-p256.ts`) */
30
30
  const P256_SEED_BYTES = 48;
31
31
  /** A P-256 scalar from key material, under its own label */
@@ -65,47 +65,40 @@ export async function deriveMemberKeyBytes(accountKey, spaceId) {
65
65
  return deriveScalar(accountKey, `${MEMBER_KEY_INFO}|${spaceId}`);
66
66
  }
67
67
  /**
68
- * A **door key**: the key a door's knocks are sealed to (`doors/doors.ts`).
69
- * Derived from the contact key and the door's id, so every device and app
70
- * holding the contact key opens the same doors, and a new door is a new id.
68
+ * An **inbox key**: the key knocks on the account's inbox are sealed to
69
+ * (`inbox/inbox.ts`, spec 07 §1). Derived from the contact key and the
70
+ * inbox's generation, so every device and app holding the contact key opens
71
+ * the same inbox, and a new inbox is a new `gen`.
71
72
  *
72
73
  * Not the contact key itself: that one's public half is on your profile in
73
- * every space you write in, and a door is handed to people who may not know
74
- * who you are yet. A door key says nothing about the account behind it.
74
+ * every space you write in, and an inbox is handed to people who may not know
75
+ * who you are yet. An inbox key says nothing about the account behind it.
75
76
  * @param contactKey The contact key's private scalar (`deriveContactKeyBytes`)
76
- * @param doorId The door's id, as its `std.door` record names it
77
77
  */
78
- export async function deriveDoorKeyBytes(contactKey, doorId) {
79
- return deriveScalar(contactKey, `${DOOR_KEY_INFO}|${doorId}`);
78
+ export async function deriveInboxKeyBytes(contactKey, gen) {
79
+ return deriveScalar(contactKey, `${INBOX_KEY_INFO}|${gen}`);
80
80
  }
81
81
  /**
82
- * A door's **signing key**: what proves you own a door, without saying whose
83
- * it is — to a relay, when clearing the door's mailbox, and to someone who
84
- * knocked, when you answer. Separate from the door key, which only opens
85
- * knocks: one key should not both sign and decrypt.
82
+ * An inbox's **signing key**: what signs the inbox, and proves to a relay
83
+ * clearing its mailbox that it is the owner, without saying whose it is.
84
+ * Separate from the inbox key, which only opens knocks: one key should not
85
+ * both sign and decrypt.
86
86
  */
87
- export async function deriveDoorSignKeyBytes(contactKey, doorId) {
88
- return deriveScalar(contactKey, `${DOOR_SIGN_KEY_INFO}|${doorId}`);
87
+ export async function deriveInboxSignKeyBytes(contactKey, gen) {
88
+ return deriveScalar(contactKey, `${INBOX_SIGN_KEY_INFO}|${gen}`);
89
+ }
90
+ /** A private scalar as a key to sign with (ECDSA), for what an inbox's signing key signs as a version */
91
+ export function signingKeyOf(secret) {
92
+ return importScalar(secret, 'ECDSA', ['sign']);
89
93
  }
90
94
  /**
91
95
  * Signs with a P-256 private scalar: ECDSA over SHA-256, 64 bytes r ‖ s,
92
- * base64url — for door signing keys.
96
+ * base64url — for an inbox's signing key.
93
97
  */
94
98
  export async function signWithScalar(secret, data) {
95
99
  const key = await importScalar(secret, 'ECDSA', ['sign']);
96
100
  return base64UrlEncode(new Uint8Array(await globalThis.crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, key, bufferSource(data))));
97
101
  }
98
- /** Checks what `signWithScalar` signed, against a compressed public key (base64url) */
99
- export async function verifyWithPoint(publicKey, data, signature) {
100
- try {
101
- const point = p256.Point.fromBytes(base64UrlDecode(publicKey)).toBytes(false);
102
- const key = await globalThis.crypto.subtle.importKey('raw', bufferSource(point), { name: 'ECDSA', namedCurve: 'P-256' }, false, ['verify']);
103
- return await globalThis.crypto.subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, key, bufferSource(base64UrlDecode(signature)), bufferSource(data));
104
- }
105
- catch {
106
- return false;
107
- }
108
- }
109
102
  /** The public half, from the private scalar */
110
103
  export function contactPublicKey(secret) {
111
104
  return base64UrlEncode(p256.getPublicKey(secret, true));
@@ -1 +1 @@
1
- {"version":3,"file":"contact-key.js","sourceRoot":"","sources":["../../src/identity/contact-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,eA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,OAAO,eAAe,CACpB,IAAI,UAAU,CACZ,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CACjG,CACF,CAAC;AACJ,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,OAAO,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC;IACjE,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC;QAC9D,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAkB;IACrD,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @module inbox
3
+ * The inbox: how someone you share no space with can ask to become your
4
+ * contact, and the knock they leave there (spec 07).
5
+ *
6
+ * A DID is a name, not an address — knowing it must not be enough to reach
7
+ * you. An account's **inbox** is an address it hands out on purpose: a key
8
+ * knocks are sealed to, a signing key that proves the inbox is its own, and
9
+ * up to three mailboxes that hold knocks. Both keys are derived from the
10
+ * contact key and a generation, `gen`, so every device opens the same inbox,
11
+ * and a new `gen` is a new inbox nobody can tie to the old one. Neither is the
12
+ * contact key, whose public half is on the account's profile in every space:
13
+ * an inbox says nothing about the account behind it.
14
+ *
15
+ * It travels as a **`sys.inbox`** loose version (spec 02 §3.5), signed by its
16
+ * own signing key, in a link, a QR code or a bio. Someone with it **knocks**:
17
+ * makes a private space for the two of them and leaves a **`sys.knock`**,
18
+ * signed under their account's note and carrying the signed invitation to
19
+ * that space, sealed to the inbox key. The same knock, sealed to the contact
20
+ * key instead, goes in a `std.contact-request` in a space both belong to
21
+ * (`packages/core/docs/contacts.md`).
22
+ * Joining the space is the answer: only the holder of the key could open it.
23
+ *
24
+ * ```
25
+ * inbox = sys.inbox { key, sign, gen, places, name? } — author: did:key of sign
26
+ * knock = sys.knock { invite, secret, name, note? }, to — under a note with /account/write
27
+ * sealed = HPKE(to, "minca/mail/v1", { to }, JSON(knock))
28
+ * topic = base64url(SHA-256("minca/inbox-topic/v1|" + sign))
29
+ * ```
30
+ */
31
+ import type { CryptoProvider, Version } from '../types.js';
32
+ import { type LooseSigner } from '../records/loose.js';
33
+ /** The collection an inbox is a loose version in */
34
+ export declare const INBOX_COLLECTION = "sys.inbox";
35
+ /** The collection a knock is a loose version in */
36
+ export declare const KNOCK_COLLECTION = "sys.knock";
37
+ /** An inbox names at most this many mailboxes: enough that one going away doesn't matter */
38
+ export declare const MAX_INBOX_PLACES = 3;
39
+ /** How long a knock waits in a mailbox, and so how old one may be when opened */
40
+ export declare const KNOCK_TTL_SECONDS: number;
41
+ /**
42
+ * How far a knock's own time may be before when the relay took it. A knock is
43
+ * dropped as soon as it is signed, so its time is checked against the relay's
44
+ * — which the knocker can't choose — and a note that ran out can't be used by
45
+ * dating a knock back to when it was good.
46
+ */
47
+ export declare const KNOCK_DROP_WINDOW_SECONDS = 600;
48
+ /** What an inbox says: where to knock, and who the owner says they are */
49
+ export interface InboxBody {
50
+ /** The inbox key's public half: a compressed P-256 point, base64url. Knocks are sealed to it. */
51
+ readonly key: string;
52
+ /** The inbox's signing key's public half, likewise. It signs the inbox; its hash is the topic. */
53
+ readonly sign: string;
54
+ /** Which inbox of the account this is: a new one is a new number */
55
+ readonly gen: number;
56
+ /** Mailboxes that hold its knocks, 1–3 */
57
+ readonly places: ReadonlyArray<string>;
58
+ /** Who the owner says they are — shown to the knocker, and proves nothing */
59
+ readonly name?: string;
60
+ }
61
+ /** What a knock carries */
62
+ export interface KnockBody {
63
+ /** The signed invitation to the space for two (spec 03 §7.4) */
64
+ readonly invite: Version;
65
+ /** Its invite secret, base64url: it opens the editor role there */
66
+ readonly secret: string;
67
+ /** The name the knocker gives; nothing vouches for it */
68
+ readonly name: string;
69
+ readonly note?: string;
70
+ }
71
+ /** A knock that opened and checked out */
72
+ export interface OpenedKnock {
73
+ /** The knocker's account */
74
+ readonly from: string;
75
+ readonly name: string;
76
+ readonly note?: string;
77
+ /** The invite to the space for two, with its secret: what accepting joins */
78
+ readonly invite: string;
79
+ /** The id of the space for two */
80
+ readonly pairSpace: string;
81
+ /** When it was signed, ms */
82
+ readonly at: number;
83
+ }
84
+ /** Cuts text to at most `max` characters without splitting one (a surrogate pair stays whole) */
85
+ export declare function clip(text: string, max: number): string;
86
+ /** The did:key of an inbox's signing key: who an inbox is signed by */
87
+ export declare const inboxAuthor: (sign: string) => string;
88
+ /** Why an inbox's body is not one, or null */
89
+ export declare function inboxProblem(body: unknown): string | null;
90
+ /**
91
+ * Signs an inbox with its own signing key, which signs for itself: no note,
92
+ * so nothing in it names the account.
93
+ * @param signKey The signing key's private scalar
94
+ * @returns The inbox as its code: what goes in a link or a QR code
95
+ */
96
+ export declare function encodeInbox(signKey: Uint8Array, body: InboxBody, provider: CryptoProvider): Promise<string>;
97
+ /**
98
+ * Reads an inbox's code, or a link carrying one after `#inbox=` or `inbox=`,
99
+ * and checks it: signed by the signing key it names, and well formed.
100
+ * @throws When it isn't one, saying why
101
+ */
102
+ export declare function readInbox(text: string, provider: CryptoProvider): Promise<InboxBody>;
103
+ /**
104
+ * The mailbox topic of an inbox: a hash of its signing key. A relay can't tell
105
+ * whose inbox it is, and can check that whoever clears it holds that key.
106
+ */
107
+ export declare function inboxTopic(sign: string): Promise<string>;
108
+ /**
109
+ * What an inbox's owner signs to clear knocks from a relay's mailbox: the
110
+ * topic, the relay's one-time challenge, and which knocks (`*` for all).
111
+ */
112
+ export declare const purgeMessage: (topic: string, nonce: string, ids: ReadonlyArray<string> | null) => Uint8Array<ArrayBuffer>;
113
+ /** Signs a relay's purge challenge with the inbox's signing key */
114
+ export declare function signPurge(signKey: Uint8Array, topic: string, nonce: string, ids: ReadonlyArray<string> | null): Promise<string>;
115
+ /** A mailbox knock's id: the hash of its sealed blob, as relays file it */
116
+ export declare function knockId(blob: string): Promise<string>;
117
+ /**
118
+ * Makes a knock: signed by the session key under its account's note, and
119
+ * sealed to `to`, an inbox key or a contact key.
120
+ * @param invite The signed invitation to the space for two, and its secret
121
+ * @returns The sealed blob, for a mailbox or a contact request
122
+ */
123
+ export declare function sealKnock(to: string, knock: {
124
+ readonly invite: Version;
125
+ readonly secret: Uint8Array;
126
+ readonly name: string;
127
+ readonly note?: string;
128
+ }, signer: LooseSigner, provider: CryptoProvider): Promise<string>;
129
+ /**
130
+ * Opens a knock and checks it through (spec 07 §6): sealed to one of these
131
+ * keys and naming it; signed under a note from its account that may write for
132
+ * the whole account, valid when it was signed; recent; and carrying a signed
133
+ * invitation from the same account to a private space that account alone
134
+ * founded.
135
+ * @param keys The private scalars it may be sealed to: the inbox keys, or the contact key
136
+ * @param receivedAt For a mailbox, when the relay took it, ms; null for a contact request
137
+ * @returns The knock, or null when it is anything less
138
+ */
139
+ export declare function openKnock(keys: ReadonlyArray<Uint8Array>, blob: string, receivedAt: number | null, provider: CryptoProvider): Promise<OpenedKnock | null>;
140
+ //# sourceMappingURL=inbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"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wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE3D;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;IACL,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB,EACD,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAmD7B"}
@@ -0,0 +1,212 @@
1
+ import { contactKeyPair, contactPublicKey, isContactPublicKey, signWithScalar, signingKeyOf, } from '../identity/contact-key.js';
2
+ import { openValueFrom, sealValueTo } from '../identity/hpke.js';
3
+ import { publicKeyToDid, P256_MULTICODEC } from '../identity/did.js';
4
+ import { noteCovers, UCAN_CLOCK_SKEW_SECONDS } from '../identity/ucan.js';
5
+ import { ACCOUNT_REQUIREMENT } from '../identity/abilities.js';
6
+ import { checkLoose, decodeLoose, encodeLoose, signLoose } from '../records/loose.js';
7
+ import { checkInvitation, invitedByOf, writeInvitation } from '../space/invitation.js';
8
+ import { checkSpace, soleFounder } from '../space/constitution.js';
9
+ import { checkRelays } from '../space/roles.js';
10
+ import { sha256 } from '../utils/hash.js';
11
+ import { isRecord } from '../utils/guards.js';
12
+ import { base64UrlDecode, base64UrlEncode, utf8Encode } from '../utils/encoding.js';
13
+ /** The collection an inbox is a loose version in */
14
+ export const INBOX_COLLECTION = 'sys.inbox';
15
+ /** The collection a knock is a loose version in */
16
+ export const KNOCK_COLLECTION = 'sys.knock';
17
+ /** An inbox names at most this many mailboxes: enough that one going away doesn't matter */
18
+ export const MAX_INBOX_PLACES = 3;
19
+ /** How long a knock waits in a mailbox, and so how old one may be when opened */
20
+ export const KNOCK_TTL_SECONDS = 14 * 24 * 3600;
21
+ /**
22
+ * How far a knock's own time may be before when the relay took it. A knock is
23
+ * dropped as soon as it is signed, so its time is checked against the relay's
24
+ * — which the knocker can't choose — and a note that ran out can't be used by
25
+ * dating a knock back to when it was good.
26
+ */
27
+ export const KNOCK_DROP_WINDOW_SECONDS = 600;
28
+ const MAX_NAME = 64;
29
+ const MAX_NOTE = 2000;
30
+ /** The HPKE label a knock is sealed under; bound to `{ to }`, the key it is sealed to */
31
+ const MAIL_LABEL = 'minca/mail/v1';
32
+ /** Cuts text to at most `max` characters without splitting one (a surrogate pair stays whole) */
33
+ export function clip(text, max) {
34
+ const chars = Array.from(text);
35
+ return chars.length <= max ? text : chars.slice(0, max).join('');
36
+ }
37
+ /** The did:key of an inbox's signing key: who an inbox is signed by */
38
+ export const inboxAuthor = (sign) => publicKeyToDid(base64UrlDecode(sign), P256_MULTICODEC);
39
+ /** Why an inbox's body is not one, or null */
40
+ export function inboxProblem(body) {
41
+ if (!isRecord(body))
42
+ return 'it is not an inbox';
43
+ for (const member of Object.keys(body))
44
+ if (!['key', 'sign', 'gen', 'places', 'name'].includes(member))
45
+ return `it has a ${member} it shouldn't`;
46
+ if (!isContactPublicKey(body.key))
47
+ return 'its key is not a P-256 public key';
48
+ if (!isContactPublicKey(body.sign) || body.sign === body.key)
49
+ return 'its signing key is not a P-256 public key of its own';
50
+ if (typeof body.gen !== 'number' || !Number.isSafeInteger(body.gen) || body.gen < 0)
51
+ return 'its gen is a whole number from 0';
52
+ if (!Array.isArray(body.places) || body.places.length === 0 || body.places.length > MAX_INBOX_PLACES)
53
+ return `it names 1–${MAX_INBOX_PLACES} mailboxes`;
54
+ const places = checkRelays(body.places);
55
+ if (places)
56
+ return places;
57
+ if (body.name !== undefined && (typeof body.name !== 'string' || Array.from(body.name).length > MAX_NAME))
58
+ return `its name is text of at most ${MAX_NAME} characters`;
59
+ return null;
60
+ }
61
+ const isInboxBody = (value) => inboxProblem(value) === null;
62
+ /**
63
+ * Signs an inbox with its own signing key, which signs for itself: no note,
64
+ * so nothing in it names the account.
65
+ * @param signKey The signing key's private scalar
66
+ * @returns The inbox as its code: what goes in a link or a QR code
67
+ */
68
+ export async function encodeInbox(signKey, body, provider) {
69
+ const problem = inboxProblem(body);
70
+ if (problem)
71
+ throw new Error(problem);
72
+ const sign = contactPublicKey(signKey);
73
+ if (sign !== body.sign)
74
+ throw new Error('An inbox is signed by its own signing key');
75
+ const signer = { did: inboxAuthor(sign), key: await signingKeyOf(signKey) };
76
+ return encodeLoose(await signLoose(signer, INBOX_COLLECTION, { ...body, places: [...body.places] }, provider));
77
+ }
78
+ /**
79
+ * Reads an inbox's code, or a link carrying one after `#inbox=` or `inbox=`,
80
+ * and checks it: signed by the signing key it names, and well formed.
81
+ * @throws When it isn't one, saying why
82
+ */
83
+ export async function readInbox(text, provider) {
84
+ const trimmed = text.trim();
85
+ const found = /(?:^|[#?&])inbox=([A-Za-z0-9_-]+)/.exec(trimmed);
86
+ const version = decodeLoose(found ? found[1] : trimmed);
87
+ if (!isRecord(version))
88
+ throw new Error('That is not an inbox code — it may be cut short.');
89
+ const body = version.body;
90
+ if (!isInboxBody(body))
91
+ throw new Error(`That inbox code doesn't work: ${inboxProblem(body)}`);
92
+ const checked = await checkLoose(version, INBOX_COLLECTION, provider);
93
+ // Signed by its own signing key, for itself: not by an account, so no account is named.
94
+ if (!checked || checked.note || checked.root !== inboxAuthor(body.sign))
95
+ throw new Error("That inbox code doesn't work: it is not signed by its own key");
96
+ return Object.freeze({
97
+ key: body.key,
98
+ sign: body.sign,
99
+ gen: body.gen,
100
+ places: Object.freeze([...body.places]),
101
+ ...(body.name ? { name: body.name } : {}),
102
+ });
103
+ }
104
+ /**
105
+ * The mailbox topic of an inbox: a hash of its signing key. A relay can't tell
106
+ * whose inbox it is, and can check that whoever clears it holds that key.
107
+ */
108
+ export async function inboxTopic(sign) {
109
+ return base64UrlEncode(await sha256(utf8Encode(`minca/inbox-topic/v1|${sign}`)));
110
+ }
111
+ /**
112
+ * What an inbox's owner signs to clear knocks from a relay's mailbox: the
113
+ * topic, the relay's one-time challenge, and which knocks (`*` for all).
114
+ */
115
+ export const purgeMessage = (topic, nonce, ids) => utf8Encode(`minca/inbox-purge/v1|${topic}|${nonce}|${ids ? [...ids].sort().join(',') : '*'}`);
116
+ /** Signs a relay's purge challenge with the inbox's signing key */
117
+ export function signPurge(signKey, topic, nonce, ids) {
118
+ return signWithScalar(signKey, purgeMessage(topic, nonce, ids));
119
+ }
120
+ /** A mailbox knock's id: the hash of its sealed blob, as relays file it */
121
+ export async function knockId(blob) {
122
+ return base64UrlEncode(await sha256(utf8Encode(blob)));
123
+ }
124
+ /**
125
+ * Makes a knock: signed by the session key under its account's note, and
126
+ * sealed to `to`, an inbox key or a contact key.
127
+ * @param invite The signed invitation to the space for two, and its secret
128
+ * @returns The sealed blob, for a mailbox or a contact request
129
+ */
130
+ export async function sealKnock(to, knock, signer, provider) {
131
+ const note = knock.note ? clip(knock.note.trim(), MAX_NOTE) : undefined;
132
+ const body = {
133
+ invite: knock.invite,
134
+ secret: base64UrlEncode(knock.secret),
135
+ name: clip(knock.name.trim(), MAX_NAME) || 'Someone',
136
+ ...(note ? { note } : {}),
137
+ };
138
+ const version = await signLoose(signer, KNOCK_COLLECTION, body, provider, { to });
139
+ return sealValueTo(to, MAIL_LABEL, { to }, version);
140
+ }
141
+ /**
142
+ * Opens a knock and checks it through (spec 07 §6): sealed to one of these
143
+ * keys and naming it; signed under a note from its account that may write for
144
+ * the whole account, valid when it was signed; recent; and carrying a signed
145
+ * invitation from the same account to a private space that account alone
146
+ * founded.
147
+ * @param keys The private scalars it may be sealed to: the inbox keys, or the contact key
148
+ * @param receivedAt For a mailbox, when the relay took it, ms; null for a contact request
149
+ * @returns The knock, or null when it is anything less
150
+ */
151
+ export async function openKnock(keys, blob, receivedAt, provider) {
152
+ let opened = null;
153
+ let to = '';
154
+ for (const key of keys) {
155
+ to = contactPublicKey(key);
156
+ opened = await openValueFrom(await contactKeyPair(key), MAIL_LABEL, { to }, blob);
157
+ if (opened !== null)
158
+ break;
159
+ }
160
+ if (!isRecord(opened) || opened.to !== to)
161
+ return null;
162
+ const checked = await checkLoose(opened, KNOCK_COLLECTION, provider);
163
+ if (!checked)
164
+ return null;
165
+ // Knocking makes a space and hands out its invite: only the account, or a
166
+ // note that may write for the whole account, may. An app given one space,
167
+ // or a key the account trusts less, may not.
168
+ if (checked.note && !noteCovers(checked.note, ACCOUNT_REQUIREMENT))
169
+ return null;
170
+ // Recent; and from a mailbox, signed when it was dropped, not dated back to when a note was still good.
171
+ const at = Math.floor(checked.at / 1000);
172
+ const now = Math.floor(Date.now() / 1000);
173
+ if (at < now - KNOCK_TTL_SECONDS)
174
+ return null;
175
+ if (receivedAt !== null) {
176
+ if (!Number.isFinite(receivedAt))
177
+ return null;
178
+ const dropped = Math.floor(receivedAt / 1000);
179
+ if (at > dropped + UCAN_CLOCK_SKEW_SECONDS || at < dropped - KNOCK_DROP_WINDOW_SECONDS)
180
+ return null;
181
+ }
182
+ const body = checked.version.body;
183
+ if (!isRecord(body))
184
+ return null;
185
+ if (typeof body.name !== 'string' || Array.from(body.name).length > MAX_NAME)
186
+ return null;
187
+ if (body.note !== undefined && (typeof body.note !== 'string' || Array.from(body.note).length > MAX_NOTE))
188
+ return null;
189
+ if (typeof body.secret !== 'string' || !/^[A-Za-z0-9_-]{43}$/.test(body.secret))
190
+ return null;
191
+ // An invitation from the same account, to a private space it alone founded, with its key and a role.
192
+ if ((await checkInvitation(body.invite, provider, body.secret)) !== null || !isRecord(body.invite))
193
+ return null;
194
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checkInvitation checked it through
195
+ const invite = body.invite;
196
+ const { space, key, role } = invite.body;
197
+ if (invitedByOf(invite) !== checked.root)
198
+ return null;
199
+ if (soleFounder(space) !== checked.root || space.visibility !== 'private' || !key || !role)
200
+ return null;
201
+ if ((await checkSpace(space)) !== null)
202
+ return null;
203
+ return Object.freeze({
204
+ from: checked.root,
205
+ name: clip(body.name, MAX_NAME) || 'Someone',
206
+ ...(typeof body.note === 'string' && body.note ? { note: body.note } : {}),
207
+ invite: writeInvitation(invite, base64UrlDecode(body.secret)),
208
+ pairSpace: space.id,
209
+ at: checked.at,
210
+ });
211
+ }
212
+ //# sourceMappingURL=inbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/inbox/inbox.ts"],"names":[],"mappings":"AA+BA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,YAAY,GACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAuB,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAA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CAAC,KAAK,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEpD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,SAAS;QAC5C,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7D,SAAS,EAAE,KAAK,CAAC,EAAE;QACnB,EAAE,EAAE,OAAO,CAAC,EAAE;KACf,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module inbox
3
+ * The inbox and knocks — see `inbox.ts`, and `node.inbox` for the API an app uses.
4
+ */
5
+ export { encodeInbox, readInbox, inboxProblem, inboxAuthor, inboxTopic, knockId, sealKnock, openKnock, signPurge, purgeMessage, clip, INBOX_COLLECTION, KNOCK_COLLECTION, KNOCK_DROP_WINDOW_SECONDS, MAX_INBOX_PLACES, KNOCK_TTL_SECONDS, } from './inbox.js';
6
+ export type { InboxBody, KnockBody, OpenedKnock } from './inbox.js';
7
+ export { createMailboxClient } from '../network/mailbox.js';
8
+ export type { MailboxClient, MailboxOptions, MailItem } from '../network/mailbox.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inbox/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module inbox
3
+ * The inbox and knocks — see `inbox.ts`, and `node.inbox` for the API an app uses.
4
+ */
5
+ export { encodeInbox, readInbox, inboxProblem, inboxAuthor, inboxTopic, knockId, sealKnock, openKnock, signPurge, purgeMessage, clip, INBOX_COLLECTION, KNOCK_COLLECTION, KNOCK_DROP_WINDOW_SECONDS, MAX_INBOX_PLACES, KNOCK_TTL_SECONDS, } from './inbox.js';
6
+ export { createMailboxClient } from '../network/mailbox.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/inbox/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@ export { createIdentityManager, rootFromSeed } from './identity/identity-manager
19
19
  export { createFolderAccountStore, createBrowserAccountStore, accountDataPath, newAccountId, } from './identity/account-store.js';
20
20
  export type { AccountStore, AccountSummary } from './identity/account-store.js';
21
21
  export { createVault, wrapSeedWithDeviceKey, unwrapSeedWithDeviceKey, wrapSeedWithPassphrase, CLI_PASSPHRASE_LABEL, unwrapSeedWithPassphrase, deriveLocalKey, deriveAccountKey, deviceWrapsFor, withWrap, PASSPHRASE_ITERATIONS, } from './identity/account-vault.js';
22
- export { deriveContactKeyBytes, deriveDoorKeyBytes, deriveDoorSignKeyBytes, contactKeyPair, contactPublicKey, isContactPublicKey, } from './identity/contact-key.js';
22
+ export { deriveContactKeyBytes, deriveInboxKeyBytes, deriveInboxSignKeyBytes, contactKeyPair, contactPublicKey, isContactPublicKey, } from './identity/contact-key.js';
23
23
  export { sealEnvelope, openEnvelope, sealValue, openValue } from './identity/envelope.js';
24
24
  export type { Bound } from './identity/envelope.js';
25
25
  export { sealTo, openFrom, sealValueTo, openValueFrom } from './identity/hpke.js';
@@ -116,7 +116,7 @@ export { createNode, serveNode, remoteNode, serveSigner, remoteSigner, startNode
116
116
  export { MAX_PROPOSALS } from './space/own-automations.js';
117
117
  /** Why an app's "worth hearing about" entry can't be offered, or null */
118
118
  export { checkAppAutomation, checkOwnAutomation, ownQuery } from './space/own-automations.js';
119
- export type { StoreFactory, WriterKeySource, ClaimedWriter, HeadStore, StoreOptions, CopyAccountParams, CopyResult, NodeAction, ActionSchema, P2PNode, NodeConfig, WorkerNodeConfig, WorkerStores, WorkerLike, NodeNetworkConfig, NodeSpaces, NodeRecords, FileRef, NodeRecord, NodeEvent, NodeNetwork, SpaceSummary, SpaceStatus, SpaceAccess, CarrierSummary, SpaceProfile, NewSpace, InvitePreview, ListOptions, InviteOptions, ConnectionState, NodeCollection, NodeCollections, DefineCollection, NodeAccount, AccountProfileView, NodeContacts, NodeDirect, DirectMessage, ContactView, ContactRequest, NodeDoors, DoorView, KnockView, SentKnockView, CarrierConfig, CarrierNode, CarriedSpace, CarrierEvent, HostConfig, HostNode, NodeHosting, HostingView, SpaceHostingView, Subscription, SubscriptionState, Keeper, CacheConfig, NodeAutomations, OwnAutomationView, AutomationProposal, AppAutomation, Wake, WakeView, NotifyMatch, WatchNotificationsOptions, } from './node/index.js';
119
+ export type { StoreFactory, WriterKeySource, ClaimedWriter, HeadStore, StoreOptions, CopyAccountParams, CopyResult, NodeAction, ActionSchema, P2PNode, NodeConfig, WorkerNodeConfig, WorkerStores, WorkerLike, NodeNetworkConfig, NodeSpaces, NodeRecords, FileRef, NodeRecord, NodeEvent, NodeNetwork, SpaceSummary, SpaceStatus, SpaceAccess, CarrierSummary, SpaceProfile, NewSpace, InvitePreview, ListOptions, InviteOptions, ConnectionState, NodeCollection, NodeCollections, DefineCollection, NodeAccount, AccountProfileView, NodeContacts, NodeDirect, DirectMessage, ContactView, ContactRequest, NodeInbox, InboxView, KnockView, SentKnockView, CarrierConfig, CarrierNode, CarriedSpace, CarrierEvent, HostConfig, HostNode, NodeHosting, HostingView, SpaceHostingView, Subscription, SubscriptionState, Keeper, CacheConfig, NodeAutomations, OwnAutomationView, AutomationProposal, AppAutomation, Wake, WakeView, NotifyMatch, WatchNotificationsOptions, } from './node/index.js';
120
120
  export { runQuery } from './query/engine.js';
121
121
  export { checkComputed, computedSchemas } from './query/computed.js';
122
122
  export type { ComputedFields, ComputedValues } from './query/computed.js';