@calimero-network/mero-js 26.11.0 → 27.0.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 (220) hide show
  1. package/README.md +73 -288
  2. package/dist/cloud-v2/attestation.d.ts +91 -0
  3. package/dist/cloud-v2/attestation.js +135 -0
  4. package/dist/cloud-v2/capabilities.d.ts +30 -0
  5. package/dist/cloud-v2/capabilities.js +31 -0
  6. package/dist/cloud-v2/client.d.ts +426 -0
  7. package/dist/cloud-v2/client.js +646 -0
  8. package/dist/cloud-v2/errors.d.ts +98 -0
  9. package/dist/cloud-v2/errors.js +165 -0
  10. package/dist/cloud-v2/index.d.ts +10 -0
  11. package/dist/cloud-v2/index.js +5 -0
  12. package/dist/cloud-v2/passkey.d.ts +27 -0
  13. package/dist/cloud-v2/passkey.js +73 -0
  14. package/dist/crypto/internal.d.ts +3 -37
  15. package/dist/crypto/internal.js +3 -72
  16. package/dist/index.browser.mjs +4 -2
  17. package/dist/index.browser.mjs.map +4 -4
  18. package/dist/index.cjs +1750 -12772
  19. package/dist/index.cjs.map +4 -4
  20. package/dist/index.d.ts +3 -56
  21. package/dist/index.js +14 -75
  22. package/dist/index.mjs +1750 -12772
  23. package/dist/index.mjs.map +4 -4
  24. package/dist/sealed/index.d.ts +4 -4
  25. package/dist/sealed/index.js +2 -2
  26. package/dist/sealed/release.d.ts +21 -76
  27. package/dist/sealed/release.js +24 -108
  28. package/dist/sealed/sealed.d.ts +8 -56
  29. package/dist/sealed/sealed.js +11 -89
  30. package/dist/sealed/verify.d.ts +7 -13
  31. package/dist/sealed/verify.js +3 -7
  32. package/package.json +8 -13
  33. package/dist/account/account-admin.d.ts +0 -80
  34. package/dist/account/account-admin.js +0 -346
  35. package/dist/account/account.d.ts +0 -196
  36. package/dist/account/account.js +0 -269
  37. package/dist/account/application-id.d.ts +0 -50
  38. package/dist/account/application-id.js +0 -83
  39. package/dist/account/bootstrap-from-invitation.d.ts +0 -110
  40. package/dist/account/bootstrap-from-invitation.js +0 -80
  41. package/dist/account/create-context.d.ts +0 -103
  42. package/dist/account/create-context.js +0 -267
  43. package/dist/account/govern.d.ts +0 -24
  44. package/dist/account/govern.js +0 -50
  45. package/dist/account/index.d.ts +0 -26
  46. package/dist/account/index.js +0 -15
  47. package/dist/account/join-as-account.d.ts +0 -23
  48. package/dist/account/join-as-account.js +0 -34
  49. package/dist/account/join-with-node.d.ts +0 -115
  50. package/dist/account/join-with-node.js +0 -161
  51. package/dist/account/node-admin.d.ts +0 -20
  52. package/dist/account/node-admin.js +0 -33
  53. package/dist/account/relay-from-invitation.d.ts +0 -137
  54. package/dist/account/relay-from-invitation.js +0 -180
  55. package/dist/account/relay-login-error.d.ts +0 -32
  56. package/dist/account/relay-login-error.js +0 -34
  57. package/dist/account/session.d.ts +0 -266
  58. package/dist/account/session.js +0 -915
  59. package/dist/account/wordlist.d.ts +0 -16
  60. package/dist/account/wordlist.js +0 -273
  61. package/dist/admin-api/admin-client.d.ts +0 -688
  62. package/dist/admin-api/admin-client.js +0 -1230
  63. package/dist/admin-api/admin-factory.d.ts +0 -14
  64. package/dist/admin-api/admin-factory.js +0 -22
  65. package/dist/admin-api/admin-types.d.ts +0 -2046
  66. package/dist/admin-api/admin-types.js +0 -12
  67. package/dist/admin-api/index.d.ts +0 -4
  68. package/dist/admin-api/index.js +0 -5
  69. package/dist/admin-api/redeem-invitation.d.ts +0 -101
  70. package/dist/admin-api/redeem-invitation.js +0 -200
  71. package/dist/auth/index.d.ts +0 -34
  72. package/dist/auth/index.js +0 -67
  73. package/dist/auth-api/auth-client.d.ts +0 -31
  74. package/dist/auth-api/auth-client.js +0 -117
  75. package/dist/auth-api/auth-factory.d.ts +0 -7
  76. package/dist/auth-api/auth-factory.js +0 -41
  77. package/dist/auth-api/auth-types.d.ts +0 -130
  78. package/dist/auth-api/auth-types.js +0 -2
  79. package/dist/auth-api/index.d.ts +0 -3
  80. package/dist/auth-api/index.js +0 -4
  81. package/dist/capabilities.d.ts +0 -84
  82. package/dist/capabilities.js +0 -117
  83. package/dist/cloud/account-ownership.d.ts +0 -63
  84. package/dist/cloud/account-ownership.js +0 -87
  85. package/dist/cloud/cloud-client.d.ts +0 -949
  86. package/dist/cloud/cloud-client.js +0 -1068
  87. package/dist/cloud/connect.d.ts +0 -213
  88. package/dist/cloud/connect.js +0 -260
  89. package/dist/cloud/enrol-redirect.d.ts +0 -181
  90. package/dist/cloud/enrol-redirect.js +0 -244
  91. package/dist/cloud/index.d.ts +0 -12
  92. package/dist/cloud/index.js +0 -10
  93. package/dist/cloud/link-redirect.d.ts +0 -95
  94. package/dist/cloud/link-redirect.js +0 -121
  95. package/dist/cloud/link-state.d.ts +0 -36
  96. package/dist/cloud/link-state.js +0 -104
  97. package/dist/cloud/routing-proof.d.ts +0 -113
  98. package/dist/cloud/routing-proof.js +0 -96
  99. package/dist/device-cert/device-cert.d.ts +0 -189
  100. package/dist/device-cert/device-cert.js +0 -239
  101. package/dist/device-cert/device-scope.d.ts +0 -58
  102. package/dist/device-cert/device-scope.js +0 -76
  103. package/dist/device-cert/index.d.ts +0 -4
  104. package/dist/device-cert/index.js +0 -3
  105. package/dist/ephemeral/codec.d.ts +0 -4
  106. package/dist/ephemeral/codec.js +0 -12
  107. package/dist/ephemeral/index.d.ts +0 -57
  108. package/dist/ephemeral/index.js +0 -101
  109. package/dist/ephemeral/types.d.ts +0 -27
  110. package/dist/ephemeral/types.js +0 -1
  111. package/dist/errors/classify.d.ts +0 -65
  112. package/dist/errors/classify.js +0 -117
  113. package/dist/errors/index.d.ts +0 -2
  114. package/dist/errors/index.js +0 -1
  115. package/dist/events/group.d.ts +0 -95
  116. package/dist/events/group.js +0 -10
  117. package/dist/events/index.d.ts +0 -5
  118. package/dist/events/index.js +0 -2
  119. package/dist/events/sse.d.ts +0 -127
  120. package/dist/events/sse.js +0 -469
  121. package/dist/events/ws.d.ts +0 -57
  122. package/dist/events/ws.js +0 -212
  123. package/dist/http-client/api-response.d.ts +0 -15
  124. package/dist/http-client/api-response.js +0 -1
  125. package/dist/http-client/http-factory.d.ts +0 -71
  126. package/dist/http-client/http-factory.js +0 -68
  127. package/dist/http-client/http-types.d.ts +0 -87
  128. package/dist/http-client/http-types.js +0 -1
  129. package/dist/http-client/index.d.ts +0 -7
  130. package/dist/http-client/index.js +0 -11
  131. package/dist/http-client/path-segment.d.ts +0 -1
  132. package/dist/http-client/path-segment.js +0 -8
  133. package/dist/http-client/retry.d.ts +0 -5
  134. package/dist/http-client/retry.js +0 -82
  135. package/dist/http-client/signal-utils.d.ts +0 -2
  136. package/dist/http-client/signal-utils.js +0 -41
  137. package/dist/http-client/web-client.d.ts +0 -80
  138. package/dist/http-client/web-client.js +0 -557
  139. package/dist/invitation/index.d.ts +0 -2
  140. package/dist/invitation/index.js +0 -2
  141. package/dist/invitation/invitation.d.ts +0 -106
  142. package/dist/invitation/invitation.js +0 -104
  143. package/dist/login/index.d.ts +0 -4
  144. package/dist/login/index.js +0 -3
  145. package/dist/login/login.d.ts +0 -111
  146. package/dist/login/login.js +0 -110
  147. package/dist/login/session.d.ts +0 -124
  148. package/dist/login/session.js +0 -141
  149. package/dist/mero-js.d.ts +0 -231
  150. package/dist/mero-js.js +0 -469
  151. package/dist/namespace-op/index.d.ts +0 -2
  152. package/dist/namespace-op/index.js +0 -3
  153. package/dist/namespace-op/namespace-op.d.ts +0 -150
  154. package/dist/namespace-op/namespace-op.js +0 -191
  155. package/dist/nodeDiscovery.d.ts +0 -47
  156. package/dist/nodeDiscovery.js +0 -101
  157. package/dist/owner-op/index.d.ts +0 -2
  158. package/dist/owner-op/index.js +0 -3
  159. package/dist/owner-op/owner-op.d.ts +0 -119
  160. package/dist/owner-op/owner-op.js +0 -214
  161. package/dist/presence/relay-presence.d.ts +0 -56
  162. package/dist/presence/relay-presence.js +0 -107
  163. package/dist/presence/statement.d.ts +0 -12
  164. package/dist/presence/statement.js +0 -17
  165. package/dist/relay/index.d.ts +0 -4
  166. package/dist/relay/index.js +0 -2
  167. package/dist/relay/nonce-source.d.ts +0 -72
  168. package/dist/relay/nonce-source.js +0 -111
  169. package/dist/relay/relay-client.d.ts +0 -472
  170. package/dist/relay/relay-client.js +0 -518
  171. package/dist/relay-attestation/attest-node-key.d.ts +0 -66
  172. package/dist/relay-attestation/attest-node-key.js +0 -110
  173. package/dist/relay-attestation/index.d.ts +0 -1
  174. package/dist/relay-attestation/index.js +0 -1
  175. package/dist/request/caller-proof.d.ts +0 -43
  176. package/dist/request/caller-proof.js +0 -36
  177. package/dist/request/index.d.ts +0 -3
  178. package/dist/request/index.js +0 -3
  179. package/dist/request/proof-signer.d.ts +0 -49
  180. package/dist/request/proof-signer.js +0 -59
  181. package/dist/request/request-sig.d.ts +0 -99
  182. package/dist/request/request-sig.js +0 -95
  183. package/dist/request-proof/authorizer.d.ts +0 -41
  184. package/dist/request-proof/authorizer.js +0 -60
  185. package/dist/request-proof/index.d.ts +0 -4
  186. package/dist/request-proof/index.js +0 -2
  187. package/dist/request-proof/request-proof.d.ts +0 -53
  188. package/dist/request-proof/request-proof.js +0 -95
  189. package/dist/rpc/index.d.ts +0 -64
  190. package/dist/rpc/index.js +0 -78
  191. package/dist/signer/index.d.ts +0 -2
  192. package/dist/signer/index.js +0 -3
  193. package/dist/signer/signer.d.ts +0 -92
  194. package/dist/signer/signer.js +0 -147
  195. package/dist/token-store/index.d.ts +0 -27
  196. package/dist/token-store/index.js +0 -62
  197. package/dist/transport/index.d.ts +0 -6
  198. package/dist/transport/index.js +0 -3
  199. package/dist/transport/mero-client.d.ts +0 -294
  200. package/dist/transport/mero-client.js +0 -386
  201. package/dist/transport/relay-observer.d.ts +0 -152
  202. package/dist/transport/relay-observer.js +0 -173
  203. package/dist/transport/relay-transport.d.ts +0 -73
  204. package/dist/transport/relay-transport.js +0 -94
  205. package/dist/transport/types.d.ts +0 -100
  206. package/dist/transport/types.js +0 -32
  207. package/dist/types/api-response.d.ts +0 -15
  208. package/dist/types/api-response.js +0 -1
  209. package/dist/types/index.d.ts +0 -1
  210. package/dist/types/index.js +0 -1
  211. package/dist/warrant/creation-warrant.d.ts +0 -163
  212. package/dist/warrant/creation-warrant.js +0 -194
  213. package/dist/warrant/governance-op.d.ts +0 -202
  214. package/dist/warrant/governance-op.js +0 -355
  215. package/dist/warrant/governance-warrant.d.ts +0 -124
  216. package/dist/warrant/governance-warrant.js +0 -164
  217. package/dist/warrant/index.d.ts +0 -8
  218. package/dist/warrant/index.js +0 -5
  219. package/dist/warrant/warrant.d.ts +0 -188
  220. package/dist/warrant/warrant.js +0 -202
@@ -1,110 +0,0 @@
1
- /**
2
- * Bootstrapping an account that is a member of nothing, from an invitation.
3
- *
4
- * # The one missing step
5
- *
6
- * A freshly enrolled account holds a certified device and belongs to no
7
- * namespace, so `CloudClient.getAccountRelays` answers `[]` — correctly, because
8
- * nothing serves an account that is a member of nothing. It is still signed in;
9
- * what it has no way to do is write. An invitation is what changes that, and the
10
- * chain is:
11
- *
12
- * invitation → namespaceId → a node URL
13
- * → POST the signed join to that node → the account is a member
14
- * → that same node is the relay, from this moment
15
- * → a fleet relay writes the recovery envelope asynchronously,
16
- * and getAccountRelays() agrees from then on
17
- *
18
- * The session does not wait for the cloud to catch up. The node that carried the
19
- * join is known to serve the namespace now; the lookup will agree later.
20
- *
21
- * # Where the node URL comes from, in preference order
22
- *
23
- * 1. one the caller passes in, such as an operator's or a local rig's;
24
- * 2. the cloud's `/api/cloud/namespaces/{ns}/admitters`, intersected with the
25
- * invitation's signed `admitters`, see `resolveRelayFromInvitation`.
26
- *
27
- * Never from the invitation, signed or not: the inviter may be the attacker.
28
- *
29
- * # Nothing here is minted, weakened or worked around
30
- *
31
- * The credential and the device secret come from the enrolment the wallet
32
- * already performed. The op is signed by that device key, which is what stops an
33
- * admitter substituting a different member. The admitters intersection is done in
34
- * `resolveRelayFromInvitation` and is never relaxed.
35
- */
36
- import type { SignedGroupOpenInvitation } from '../admin-api/index.js';
37
- import type { DelegatedCredential, DelegatedSession } from './session.js';
38
- import { joinWithNode, type JoinWithNodeStep } from './join-with-node.js';
39
- import { resolveRelayFromInvitation, type RelayResolutionStep, type ResolvedInvitationRelay } from './relay-from-invitation.js';
40
- /**
41
- * Which step failed. One exhaustive list to branch on: the relay-resolution
42
- * steps, the two `joinWithNode` reports, and the one only a hook can hit.
43
- *
44
- * - `no-credential` — this tab holds no enrolled account, so there is nothing to
45
- * admit. Only {@link useDelegatedBootstrap} can report it;
46
- * `bootstrapFromInvitation` is handed the credential as an argument.
47
- */
48
- export type BootstrapStep = RelayResolutionStep | JoinWithNodeStep | 'no-credential';
49
- export interface BootstrapSuccess {
50
- readonly ok: true;
51
- /** The session to connect with — hand it straight to `connectWithAccount`. */
52
- readonly session: DelegatedSession;
53
- /**
54
- * How the node was chosen, when the cloud chose it.
55
- *
56
- * `null` when the caller named the node itself, because then there was no
57
- * routing read to report — not because anything was skipped.
58
- */
59
- readonly relay: ResolvedInvitationRelay | null;
60
- /**
61
- * Whether the admitter said it published the op.
62
- *
63
- * NOT "you are a member": membership lands when peers apply the op, which the
64
- * admitter neither performs nor waits for. `false` with no error means the node
65
- * took the call and did not publish — worth surfacing rather than treating as
66
- * success.
67
- */
68
- readonly published: boolean;
69
- }
70
- export interface BootstrapFailure {
71
- readonly ok: false;
72
- readonly step: BootstrapStep;
73
- readonly reason: string;
74
- /** The HTTP status, when the failing step was an HTTP call. */
75
- readonly status?: number;
76
- }
77
- export type BootstrapResult = BootstrapSuccess | BootstrapFailure;
78
- export interface BootstrapFromInvitationInput {
79
- /** The namespace the invitation admits you to, 64 hex. */
80
- readonly namespaceId: string;
81
- /** The invitation, exactly as the inviter's node returned it. */
82
- readonly invitation: SignedGroupOpenInvitation;
83
- /** The enrolled account, its certificate, and the device secret. */
84
- readonly credential: DelegatedCredential;
85
- /**
86
- * A node to present the join to, skipping the cloud lookup.
87
- *
88
- * For a node the caller already knows (an operator's, a local rig); never one
89
- * from the invitation. Without it the cloud's lookup answers, narrowed by the signed admitters.
90
- */
91
- readonly nodeUrl?: string;
92
- /** Point at a cloud other than the hosted manager. For local rigs. */
93
- readonly cloudBaseUrl?: string;
94
- /** Injected in tests. */
95
- readonly deps?: {
96
- readonly resolve?: typeof resolveRelayFromInvitation;
97
- readonly join?: typeof joinWithNode;
98
- readonly fetch?: typeof fetch;
99
- readonly nonce?: () => Promise<bigint>;
100
- };
101
- }
102
- /**
103
- * Resolve a node from the invitation, present the signed join to it, and return
104
- * the session to connect with.
105
- *
106
- * Never throws for an expected failure: every one of them is a different thing
107
- * for the person to do, so they come back as `{ ok: false, step, reason }`. A
108
- * generic "could not join" is exactly what this shape exists to prevent.
109
- */
110
- export declare function bootstrapFromInvitation(input: BootstrapFromInvitationInput): Promise<BootstrapResult>;
@@ -1,80 +0,0 @@
1
- /**
2
- * Bootstrapping an account that is a member of nothing, from an invitation.
3
- *
4
- * # The one missing step
5
- *
6
- * A freshly enrolled account holds a certified device and belongs to no
7
- * namespace, so `CloudClient.getAccountRelays` answers `[]` — correctly, because
8
- * nothing serves an account that is a member of nothing. It is still signed in;
9
- * what it has no way to do is write. An invitation is what changes that, and the
10
- * chain is:
11
- *
12
- * invitation → namespaceId → a node URL
13
- * → POST the signed join to that node → the account is a member
14
- * → that same node is the relay, from this moment
15
- * → a fleet relay writes the recovery envelope asynchronously,
16
- * and getAccountRelays() agrees from then on
17
- *
18
- * The session does not wait for the cloud to catch up. The node that carried the
19
- * join is known to serve the namespace now; the lookup will agree later.
20
- *
21
- * # Where the node URL comes from, in preference order
22
- *
23
- * 1. one the caller passes in, such as an operator's or a local rig's;
24
- * 2. the cloud's `/api/cloud/namespaces/{ns}/admitters`, intersected with the
25
- * invitation's signed `admitters`, see `resolveRelayFromInvitation`.
26
- *
27
- * Never from the invitation, signed or not: the inviter may be the attacker.
28
- *
29
- * # Nothing here is minted, weakened or worked around
30
- *
31
- * The credential and the device secret come from the enrolment the wallet
32
- * already performed. The op is signed by that device key, which is what stops an
33
- * admitter substituting a different member. The admitters intersection is done in
34
- * `resolveRelayFromInvitation` and is never relaxed.
35
- */
36
- import { joinWithNode } from './join-with-node.js';
37
- import { resolveRelayFromInvitation, } from './relay-from-invitation.js';
38
- /**
39
- * Resolve a node from the invitation, present the signed join to it, and return
40
- * the session to connect with.
41
- *
42
- * Never throws for an expected failure: every one of them is a different thing
43
- * for the person to do, so they come back as `{ ok: false, step, reason }`. A
44
- * generic "could not join" is exactly what this shape exists to prevent.
45
- */
46
- export async function bootstrapFromInvitation(input) {
47
- const resolve = input.deps?.resolve ?? resolveRelayFromInvitation;
48
- const join = input.deps?.join ?? joinWithNode;
49
- let relay = null;
50
- let nodeUrl = input.nodeUrl;
51
- let admitUrl;
52
- if (!nodeUrl) {
53
- const resolved = await resolve({
54
- namespaceId: input.namespaceId,
55
- // The signed list, read off the invitation itself rather than passed
56
- // separately: two sources for one fact is how an intersection ends up
57
- // being performed against the wrong list.
58
- admitters: input.invitation.invitation.admitters,
59
- credential: input.credential.credential,
60
- deviceSecret: input.credential.deviceSecret,
61
- cloudBaseUrl: input.cloudBaseUrl,
62
- });
63
- if (resolved.ok === false)
64
- return resolved;
65
- relay = resolved;
66
- nodeUrl = resolved.relayUrl;
67
- admitUrl = resolved.admitUrl;
68
- }
69
- const joined = await join({
70
- nodeUrl,
71
- admitUrl,
72
- namespaceId: input.namespaceId,
73
- invitation: input.invitation,
74
- credential: input.credential,
75
- deps: { fetch: input.deps?.fetch, nonce: input.deps?.nonce },
76
- });
77
- if (joined.ok === false)
78
- return joined;
79
- return { ok: true, published: joined.published, relay, session: joined.session };
80
- }
@@ -1,103 +0,0 @@
1
- import { type GovernanceOp } from '../warrant/index.js';
2
- import { type DelegatedSession } from './session.js';
3
- /**
4
- * What an account asks for when it creates a context: the fields of a node's
5
- * `CreateContextRequest` that have a place in the creation warrant
6
- * (mero-js `CreationWarrantInput`), plus which namespace to find the relay by.
7
- *
8
- * Intentionally NOT here, because the warrant has no field for it:
9
- * `identitySecret` — a node's key for its new member identity; the account IS
10
- * the member identity here (`init` runs as the author's account), so there is
11
- * nothing to derive one from.
12
- */
13
- export interface CreateDelegatedContextRequest {
14
- readonly namespaceId: string;
15
- /** The group to create it in; the namespace itself when omitted. */
16
- readonly groupId?: string;
17
- readonly applicationId: string;
18
- /**
19
- * Which service of a multi-service bundle the context is for; absent for
20
- * the bundle's default service. Signed into the warrant: the relay runs THAT
21
- * service's `init`, so a bundle like mero-docs (`registry`, `docs`) creates
22
- * the right contract.
23
- */
24
- readonly serviceName?: string;
25
- /** The seed the context id is derived from, hex (32 bytes); random when absent. */
26
- readonly contextSeed?: string;
27
- readonly initializationParams?: number[];
28
- readonly name?: string;
29
- }
30
- export declare function createDelegatedContext(s: DelegatedSession, req: CreateDelegatedContextRequest, deps?: {
31
- fetch?: typeof fetch;
32
- }): Promise<{
33
- contextId: string;
34
- }>;
35
- /** Publish one delegable governance op through the namespace's relay. */
36
- export declare function delegatedGovernance(s: DelegatedSession, req: {
37
- namespaceId: string;
38
- group: string;
39
- op: GovernanceOp;
40
- }, deps?: {
41
- fetch?: typeof fetch;
42
- }): Promise<{
43
- groupId: string;
44
- }>;
45
- /**
46
- * A context only the author and `members` are in (a DM, a small room): a
47
- * restricted subgroup of the namespace (a root op, posted to the namespace),
48
- * each member added to it directly — they are in the namespace already, so
49
- * nobody is invited — and the context created inside it. The relay that
50
- * creates the subgroup is seated in it with CAN_AUTHOR_ON_BEHALF by core.
51
- */
52
- export declare function createDelegatedPrivateContext(s: DelegatedSession, req: CreateDelegatedContextRequest & {
53
- readonly members: readonly string[];
54
- }, deps?: {
55
- fetch?: typeof fetch;
56
- }): Promise<{
57
- contextId: string;
58
- groupId: string;
59
- }>;
60
- /**
61
- * Found a namespace as the account, through a relay it already uses. The
62
- * account becomes founder, owner and admin; the relay is seated in it (and a
63
- * TEE relay admits itself as its first TEE), so contexts can be created in it
64
- * through the same relay straight away.
65
- *
66
- * The relay's executor account and key cannot be asked about a namespace that
67
- * does not exist yet; see {@link foundingExecutor} for where they come from.
68
- */
69
- export declare function foundDelegatedNamespace(s: DelegatedSession, req?: {
70
- readonly defaultCapabilities?: number;
71
- /** The application the namespace runs; without one no context can be created in it. */
72
- readonly application?: {
73
- applicationId: string;
74
- package: string;
75
- version: string;
76
- };
77
- }, deps?: {
78
- fetch?: typeof fetch;
79
- /** The cloud to enable HA on; mero-js's default when unset. */
80
- cloudBaseUrl?: string;
81
- }): Promise<FoundedDelegatedNamespace>;
82
- /** What {@link foundDelegatedNamespace} returns. */
83
- export interface FoundedDelegatedNamespace {
84
- namespaceId: string;
85
- teeEnabled: boolean;
86
- /** Whether the cloud agreed to host the namespace (HA) right after founding. */
87
- haEnabled: boolean;
88
- /** Why `haEnabled` is `false`, in words a person can act on. */
89
- haError?: string;
90
- }
91
- /** What an app can tell a person whose account the cloud cannot place. */
92
- export declare const HA_ACCOUNT_NOT_LINKED_MESSAGE = "link this account to your cloud user in the wallet so the cloud can host this namespace on its fleet";
93
- /**
94
- * What to tell a person for each refusal the cloud names, keyed by its code.
95
- * Every one leaves the namespace founded; only hosting was refused.
96
- */
97
- export declare const HA_REFUSAL_MESSAGES: Record<string, string>;
98
- /**
99
- * The latest version of `pkg` the registry publishes. Used when the app names
100
- * its package but not a version. Same selection as the id derivation
101
- * ({@link selectLatestBundle}): the newest version that is not yanked.
102
- */
103
- export declare function latestPublishedVersion(registryUrl: string, pkg: string, fetchFn?: typeof fetch): Promise<string>;
@@ -1,267 +0,0 @@
1
- /**
2
- * An account's governance through the relay that serves its namespace: create
3
- * a context, and the group ops a private context (a DM) needs.
4
- *
5
- * A thin layer over mero-js's `RelayClient.createContext` / `govern` (core's
6
- * `/admin-api/groups/{group}/context-intents` and `.../governance-intents`),
7
- * adding what only this package knows: which relay serves the namespace (the
8
- * relay map), and the nonce bookkeeping across page loads.
9
- *
10
- * Nodes check the AUTHOR's rights (CAN_CREATE_CONTEXT, CAN_CREATE_SUBGROUP,
11
- * MANAGE_MEMBERS…), never the relay's; the relay only needs standing to act.
12
- */
13
- import { AccountHaRefusedError, AccountNotLinkedError, CloudClient, } from '../cloud/index.js';
14
- import { memberAddedOp, subgroupCreation, } from '../warrant/index.js';
15
- import { RelayClient, } from '../relay/index.js';
16
- import { attemptRelayNodeKey, knownRelays, markContextNonceSpent, readRelayMap, relayTransportFetch, rememberRelay, } from './session.js';
17
- import { fetchRegistryBundles, selectLatestBundle } from './application-id.js';
18
- /**
19
- * A governance warrant's nonce, for one (relay, group): spent in a sliding
20
- * per-(group, device) window 64 wide, so it must never go backwards. A stored
21
- * counter, floored at the clock so a cleared storage resumes above anything
22
- * spent before rather than replaying it.
23
- */
24
- function governanceNonce(relay, group) {
25
- return { next: async () => nextGovernanceNonce(relay, group) };
26
- }
27
- function nextGovernanceNonce(relay, group) {
28
- const key = `calimero.governance-nonce.${relay}.${group}`;
29
- let last = 0n;
30
- try {
31
- last = BigInt(localStorage.getItem(key) ?? '0');
32
- }
33
- catch {
34
- /* no storage: the clock floor alone */
35
- }
36
- const next = [last + 1n, BigInt(Date.now())].reduce((a, b) => (a > b ? a : b));
37
- try {
38
- localStorage.setItem(key, String(next));
39
- }
40
- catch {
41
- /* unpersisted */
42
- }
43
- return next;
44
- }
45
- function relayFor(s, namespaceId) {
46
- // The relay that serves this namespace: learned when the account joined it.
47
- const url = readRelayMap(s.account).namespaces[namespaceId] ?? s.relayUrl;
48
- if (!url)
49
- throw new Error('no relay is known for this namespace, so there is nowhere to send this');
50
- return url.replace(/\/+$/, '');
51
- }
52
- /** The `init` arguments as the JSON the route takes, from the bytes a caller may hold. */
53
- function initArgsOf(params) {
54
- if (!params || params.length === 0)
55
- return {};
56
- return JSON.parse(new TextDecoder().decode(Uint8Array.from(params)));
57
- }
58
- /**
59
- * A relay client for these calls: the author's credential, whatever nonces the
60
- * call needs, and the relay's sealed transport unless the caller brings its own
61
- * `fetch` (see `relayTransportFetch`).
62
- */
63
- function client(s, relayUrl, nonces, fetch) {
64
- return new RelayClient({
65
- relayUrl,
66
- authorAccount: s.account,
67
- authorProof: s.credential,
68
- deviceSecret: s.deviceSecret,
69
- nonces,
70
- fetch: fetch ?? relayTransportFetch(relayUrl),
71
- });
72
- }
73
- export async function createDelegatedContext(s, req, deps = {}) {
74
- const relay = relayFor(s, req.namespaceId);
75
- // The creation warrant's nonce is spent in the NEW context's per-device
76
- // window — the one its writes draw from, empty until now — so the first
77
- // number is free, and the context's writes then start above it.
78
- const creationNonce = 0n;
79
- const created = await client(s, relay, { next: async () => creationNonce }, deps.fetch).createContext({
80
- groupId: req.groupId ?? req.namespaceId,
81
- applicationId: req.applicationId,
82
- serviceName: req.serviceName,
83
- seed: req.contextSeed,
84
- initArgs: initArgsOf(req.initializationParams),
85
- name: req.name,
86
- });
87
- markContextNonceSpent(relay, created.contextId, creationNonce);
88
- rememberRelay(s.account, relay, { namespaceId: req.namespaceId, contextId: created.contextId });
89
- return { contextId: created.contextId };
90
- }
91
- /** Publish one delegable governance op through the namespace's relay. */
92
- export async function delegatedGovernance(s, req, deps = {}) {
93
- const relay = relayFor(s, req.namespaceId);
94
- return client(s, relay, governanceNonce(relay, req.group), deps.fetch).govern({ groupId: req.group, op: req.op });
95
- }
96
- /**
97
- * A context only the author and `members` are in (a DM, a small room): a
98
- * restricted subgroup of the namespace (a root op, posted to the namespace),
99
- * each member added to it directly — they are in the namespace already, so
100
- * nobody is invited — and the context created inside it. The relay that
101
- * creates the subgroup is seated in it with CAN_AUTHOR_ON_BEHALF by core.
102
- */
103
- export async function createDelegatedPrivateContext(s, req, deps = {}) {
104
- const { groupId } = await delegatedGovernance(s, {
105
- namespaceId: req.namespaceId,
106
- group: req.namespaceId,
107
- // The id is derived from a fresh salt (core#4244); a node refuses any other.
108
- op: (await subgroupCreation({ parentId: req.namespaceId, restricted: true, admin: s.account })).op,
109
- }, deps);
110
- for (const member of req.members) {
111
- await delegatedGovernance(s, { namespaceId: req.namespaceId, group: groupId, op: memberAddedOp(member, 'Member') }, deps);
112
- }
113
- const { contextId } = await createDelegatedContext(s, { ...req, groupId }, deps);
114
- return { contextId, groupId };
115
- }
116
- /**
117
- * Found a namespace as the account, through a relay it already uses. The
118
- * account becomes founder, owner and admin; the relay is seated in it (and a
119
- * TEE relay admits itself as its first TEE), so contexts can be created in it
120
- * through the same relay straight away.
121
- *
122
- * The relay's executor account and key cannot be asked about a namespace that
123
- * does not exist yet; see {@link foundingExecutor} for where they come from.
124
- */
125
- export async function foundDelegatedNamespace(s, req = {}, deps = {}) {
126
- const relays = knownRelays(s).map((u) => u.replace(/\/+$/, ''));
127
- const relay = relays[0];
128
- if (!relay)
129
- throw new Error('no relay is known for this account, so there is nowhere to found a namespace');
130
- const executor = await foundingExecutor(s, relay, deps.fetch);
131
- // The founding warrant and, with a default mask, a second one are both spent
132
- // in the NEW namespace's window, which is empty: any rising pair will do.
133
- let next = BigInt(Date.now());
134
- const founded = await client(s, relay, { next: async () => next++ }, deps.fetch).foundNamespace({
135
- executor,
136
- ...(req.defaultCapabilities !== undefined ? { defaultCapabilities: req.defaultCapabilities } : {}),
137
- ...(req.application ? { application: req.application } : {}),
138
- });
139
- try {
140
- localStorage.setItem(`calimero.governance-nonce.${relay}.${founded.namespaceId}`, String(next));
141
- }
142
- catch {
143
- /* unpersisted: the clock floor still keeps later warrants above these */
144
- }
145
- rememberRelay(s.account, relay, { namespaceId: founded.namespaceId });
146
- if (req.application && founded.applicationSet !== true) {
147
- // Founded, but no context can be created in it until it has its
148
- // application; the same choice can be retried (it is still the first).
149
- throw new Error(`founded ${founded.namespaceId} but could not give it its application: ${founded.applicationError ?? 'unknown reason'}`);
150
- }
151
- // HA's fleet node is admitted by the founding relay, which can vouch for it
152
- // only once it attested itself as the namespace's first TEE (that also sets
153
- // the admission policy). Without that no fleet node is ever admitted, and the
154
- // request would hold the account's one pending slot in the cloud for good.
155
- const ha = founded.teeEnabled
156
- ? await enableHaBestEffort(s, founded.namespaceId, founded.salt, relay, deps)
157
- : {
158
- haEnabled: false,
159
- haError: `the relay did not attest the founding, so no fleet node could be admitted for HA${founded.teeError ? `: ${founded.teeError}` : ''}`,
160
- };
161
- return { namespaceId: founded.namespaceId, teeEnabled: founded.teeEnabled, ...ha };
162
- }
163
- /**
164
- * The relay's pinned or attested node key, which is the key it signs with, and
165
- * its account: the session's (the cloud names it), else a remembered namespace's.
166
- */
167
- async function foundingExecutor(s, relay, fetch) {
168
- const named = s.executorAccount && s.relayUrl?.replace(/\/+$/, '') === relay ? s.executorAccount : null;
169
- if (named)
170
- return { executorAccount: named, executorKey: await attestedNodeKey(relay) };
171
- const known = Object.entries(readRelayMap(s.account).namespaces).find(([, url]) => url.replace(/\/+$/, '') === relay)?.[0];
172
- if (!known) {
173
- throw new Error("the executor account of this relay is not known: join a namespace on it first, or connect with the relay's executor account (the cloud shows it beside the relay)");
174
- }
175
- const executorKey = await attestedNodeKey(relay);
176
- // Discovery is unauthenticated: it may name the account, never the key.
177
- const described = await client(s, relay, governanceNonce(relay, known), fetch).describeGovernance(known);
178
- if (described.executorKey?.toLowerCase() !== executorKey) {
179
- throw new Error(`the relay's discovery names signing key ${described.executorKey}, not the relay's node key ${executorKey}: refusing to found through it`);
180
- }
181
- return { executorAccount: described.executorAccount, executorKey };
182
- }
183
- /**
184
- * The relay's node key, attested now; any failed attestation throws.
185
- *
186
- * Never the pin alone: the relay founded through becomes the namespace's first
187
- * TEE and holds its keys, so it is checked against the signed release on the
188
- * day it is trusted with them, not on whichever day its key was pinned. A key
189
- * pinned by hand therefore no longer stands in for an attestation here.
190
- */
191
- async function attestedNodeKey(relay) {
192
- const key = await attemptRelayNodeKey(relay, { fresh: true });
193
- if (key.kind === 'learned')
194
- return key.nodeKey;
195
- throw new Error(key.kind === 'unavailable'
196
- ? "the relay's signing key could not be learned: its attestation did not answer, try again"
197
- : "the relay's attestation was refused, so founding through it is not possible: it is not a signed locked-read-only release");
198
- }
199
- /** What an app can tell a person whose account the cloud cannot place. */
200
- export const HA_ACCOUNT_NOT_LINKED_MESSAGE = 'link this account to your cloud user in the wallet so the cloud can host this namespace on its fleet';
201
- /**
202
- * What to tell a person for each refusal the cloud names, keyed by its code.
203
- * Every one leaves the namespace founded; only hosting was refused.
204
- */
205
- export const HA_REFUSAL_MESSAGES = {
206
- account_not_linked: HA_ACCOUNT_NOT_LINKED_MESSAGE,
207
- account_linked_to_several_users: 'this account is linked to more than one cloud user, so the cloud cannot tell whose plan hosts the namespace: unlink it from all but one in the wallet',
208
- ha_request_pending: "another namespace of this account is still waiting to be hosted; the cloud hosts one new namespace at a time without a cloud sign-in. Sign in to the cloud and turn off hosting for the waiting namespace, or wait until it is hosted",
209
- unknown_relay: 'the cloud does not run the relay this namespace was founded on, so it cannot host it',
210
- relay_not_dialable: 'the relay this namespace was founded on has not reported its address to the cloud yet; try enabling hosting again shortly',
211
- };
212
- /** The namespace the cloud says is blocking, when it names one. */
213
- function blockingNamespace(e) {
214
- try {
215
- const body = JSON.parse(e.bodyText ?? '');
216
- const id = body?.detail?.namespace_id ?? body?.namespace_id;
217
- return typeof id === 'string' && /^[0-9a-f]{64}$/i.test(id) ? id.toLowerCase() : null;
218
- }
219
- catch {
220
- return null;
221
- }
222
- }
223
- /**
224
- * Ask the cloud to host a namespace this account just founded, with no cloud
225
- * session: the account proves it is the founder (its id and the salt reproduce
226
- * the namespace id) and the cloud bills the user it is linked to.
227
- *
228
- * Best-effort: the namespace exists whatever the cloud answers, so a refusal is
229
- * reported, never thrown. The cloud records the founding relay before its link
230
- * gate, so invitees find the namespace either way; HA adds fleet hosting.
231
- */
232
- async function enableHaBestEffort(s, namespaceId, salt, relayUrl, deps) {
233
- try {
234
- await new CloudClient({ cloudBaseUrl: deps.cloudBaseUrl, fetch: deps.fetch }).enableHaAsAccount({
235
- namespaceId,
236
- salt,
237
- accountId: s.account,
238
- credential: s.credential,
239
- deviceSecret: s.deviceSecret,
240
- // The relay that founded it: the cloud hands it to the fleet node as its
241
- // admitter, so the node does not have to find it by discovery.
242
- relayUrl,
243
- });
244
- return { haEnabled: true };
245
- }
246
- catch (e) {
247
- if (e instanceof AccountNotLinkedError)
248
- return { haEnabled: false, haError: HA_ACCOUNT_NOT_LINKED_MESSAGE };
249
- if (e instanceof AccountHaRefusedError && HA_REFUSAL_MESSAGES[e.code]) {
250
- const blocking = e.code === 'ha_request_pending' ? blockingNamespace(e) : null;
251
- const message = HA_REFUSAL_MESSAGES[e.code];
252
- return { haEnabled: false, haError: blocking ? `${message} (waiting: ${blocking})` : message };
253
- }
254
- return { haEnabled: false, haError: e instanceof Error ? e.message : String(e) };
255
- }
256
- }
257
- /**
258
- * The latest version of `pkg` the registry publishes. Used when the app names
259
- * its package but not a version. Same selection as the id derivation
260
- * ({@link selectLatestBundle}): the newest version that is not yanked.
261
- */
262
- export async function latestPublishedVersion(registryUrl, pkg, fetchFn = globalThis.fetch) {
263
- const latest = selectLatestBundle(await fetchRegistryBundles(registryUrl, pkg, fetchFn));
264
- if (!latest)
265
- throw new Error(`the registry lists no version of ${pkg}`);
266
- return latest.appVersion;
267
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * An account's group management through a relay: one delegated governance op
3
- * per call (`RelayClient.govern`), posted to the relay that serves the group's
4
- * namespace.
5
- *
6
- * A group op goes to the group it acts on; a root op (create, delete, move a
7
- * subgroup; join an open one) goes to the NAMESPACE. The namespace of a
8
- * subgroup is remembered here per account: when this account created it, and
9
- * when the account admin asked the relay for it (`getGroupInfo`).
10
- */
11
- import { type GovernanceOp } from '../warrant/index.js';
12
- import { type DelegatedSession } from './session.js';
13
- /** Record that `groupId` is a subgroup of `namespaceId`, for this account. */
14
- export declare function rememberGroupNamespace(account: string, groupId: string, namespaceId: string): void;
15
- /** The namespace a group belongs to: itself if it is a namespace this account is in, else what was remembered. */
16
- export declare function namespaceOfGroup(s: DelegatedSession, groupId: string): string | undefined;
17
- /** A group op (member, role, capabilities, metadata, visibility, detach) on `groupId`. */
18
- export declare function governGroup(s: DelegatedSession, groupId: string, op: GovernanceOp): Promise<{
19
- groupId: string;
20
- }>;
21
- /** A root op, posted to the namespace `groupId` belongs to. */
22
- export declare function governRoot(s: DelegatedSession, groupId: string, op: GovernanceOp): Promise<{
23
- groupId: string;
24
- }>;
@@ -1,50 +0,0 @@
1
- import { delegatedGovernance } from './create-context.js';
2
- import { readRelayMap } from './session.js';
3
- const GROUP_NAMESPACE_PREFIX = 'calimero.delegated.group-namespace.';
4
- // What this page has learned, whether or not storage keeps it: a private window
5
- // or blocked site data must not turn a known subgroup back into an unknown one.
6
- const learned = new Map();
7
- function readGroupNamespaces(account) {
8
- let stored = {};
9
- try {
10
- stored = JSON.parse(localStorage.getItem(GROUP_NAMESPACE_PREFIX + account) ?? '{}');
11
- }
12
- catch {
13
- /* no storage: what this page learned still stands */
14
- }
15
- return { ...stored, ...learned.get(account) };
16
- }
17
- /** Record that `groupId` is a subgroup of `namespaceId`, for this account. */
18
- export function rememberGroupNamespace(account, groupId, namespaceId) {
19
- learned.set(account, { ...learned.get(account), [groupId]: namespaceId });
20
- try {
21
- const all = readGroupNamespaces(account);
22
- all[groupId] = namespaceId;
23
- localStorage.setItem(GROUP_NAMESPACE_PREFIX + account, JSON.stringify(all));
24
- }
25
- catch {
26
- /* unpersisted: root ops on this subgroup will ask for its namespace */
27
- }
28
- }
29
- /** The namespace a group belongs to: itself if it is a namespace this account is in, else what was remembered. */
30
- export function namespaceOfGroup(s, groupId) {
31
- if (readRelayMap(s.account).namespaces[groupId])
32
- return groupId;
33
- return readGroupNamespaces(s.account)[groupId];
34
- }
35
- function requireNamespace(s, groupId) {
36
- const ns = namespaceOfGroup(s, groupId);
37
- if (!ns) {
38
- throw new Error(`the namespace of group ${groupId} is not known to this account: it can manage only groups in namespaces it joined or subgroups it created`);
39
- }
40
- return ns;
41
- }
42
- /** A group op (member, role, capabilities, metadata, visibility, detach) on `groupId`. */
43
- export async function governGroup(s, groupId, op) {
44
- return delegatedGovernance(s, { namespaceId: requireNamespace(s, groupId), group: groupId, op });
45
- }
46
- /** A root op, posted to the namespace `groupId` belongs to. */
47
- export async function governRoot(s, groupId, op) {
48
- const namespaceId = requireNamespace(s, groupId);
49
- return delegatedGovernance(s, { namespaceId, group: namespaceId, op });
50
- }
@@ -1,26 +0,0 @@
1
- export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, createAccountRootSigner, accountRootSignerFromPhrase, signAccountLink, signAccountLogin, } from './account.js';
2
- export type { AccountRoot, RecoverableAccountRoot, AccountRootSigner, NewAccountRootSigner, AccountLinkInput, AccountLoginInput, } from './account.js';
3
- export { resolveRoot } from './account.js';
4
- export type { RootSource } from './account.js';
5
- export { resolveRootPair } from './account.js';
6
- export type { ResolvedRoot } from './account.js';
7
- export type { DelegatedCredential, DelegatedSession as DelegatedAccountSession, RelayMap, RelayNodeKeyAttempt, RelayListingFailure } from './session.js';
8
- export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, } from './session.js';
9
- export { resolveRelayFromInvitation, normaliseAccount } from './relay-from-invitation.js';
10
- export type { RelayResolutionStep, RelayResolutionFailure, ResolvedInvitationRelay, ResolveRelayResult, ResolveRelayFromInvitationInput, } from './relay-from-invitation.js';
11
- export { joinWithNode } from './join-with-node.js';
12
- export type { JoinWithNodeInput, JoinWithNodeResult, JoinWithNodeSuccess, JoinWithNodeFailure, JoinWithNodeStep, } from './join-with-node.js';
13
- export { bootstrapFromInvitation } from './bootstrap-from-invitation.js';
14
- export type { BootstrapStep, BootstrapResult, BootstrapSuccess, BootstrapFailure, BootstrapFromInvitationInput, } from './bootstrap-from-invitation.js';
15
- export { joinAsAccount } from './join-as-account.js';
16
- export { createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, } from './create-context.js';
17
- export type { CreateDelegatedContextRequest, FoundedDelegatedNamespace } from './create-context.js';
18
- export { governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace } from './govern.js';
19
- export { applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, } from './application-id.js';
20
- export type { RegistryBundle, ResolvedApplication } from './application-id.js';
21
- export { createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, } from './account-admin.js';
22
- export type { AccountAdminDeps } from './account-admin.js';
23
- export { RelayLoginError } from './relay-login-error.js';
24
- export type { RelayLoginFailureKind } from './relay-login-error.js';
25
- export { createNodeAdmin } from './node-admin.js';
26
- export type { NodeAdminDeps } from './node-admin.js';