@calimero-network/mero-js 22.7.0 → 22.9.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 (76) hide show
  1. package/dist/account/account.d.ts +99 -4
  2. package/dist/account/account.js +0 -0
  3. package/dist/account/index.d.ts +6 -2
  4. package/dist/account/index.js +3 -1
  5. package/dist/admin-api/admin-client.d.ts +154 -2
  6. package/dist/admin-api/admin-client.js +255 -1
  7. package/dist/admin-api/admin-types.d.ts +193 -5
  8. package/dist/cloud/cloud-client.d.ts +38 -8
  9. package/dist/cloud/cloud-client.js +38 -21
  10. package/dist/cloud/connect.d.ts +101 -2
  11. package/dist/cloud/connect.js +84 -8
  12. package/dist/cloud/enrol-redirect.d.ts +195 -0
  13. package/dist/cloud/enrol-redirect.js +236 -0
  14. package/dist/cloud/index.d.ts +6 -2
  15. package/dist/cloud/index.js +7 -1
  16. package/dist/cloud/link-redirect.d.ts +85 -0
  17. package/dist/cloud/link-redirect.js +105 -0
  18. package/dist/crypto/internal.d.ts +15 -0
  19. package/dist/crypto/internal.js +18 -0
  20. package/dist/device-cert/device-cert.d.ts +96 -2
  21. package/dist/device-cert/device-cert.js +101 -11
  22. package/dist/device-cert/device-scope.d.ts +58 -0
  23. package/dist/device-cert/device-scope.js +76 -0
  24. package/dist/device-cert/index.d.ts +4 -2
  25. package/dist/device-cert/index.js +2 -1
  26. package/dist/events/sse.d.ts +22 -2
  27. package/dist/events/sse.js +20 -11
  28. package/dist/http-client/http-types.d.ts +18 -0
  29. package/dist/http-client/web-client.js +21 -1
  30. package/dist/index.browser.mjs +2 -2
  31. package/dist/index.browser.mjs.map +4 -4
  32. package/dist/index.cjs +1955 -496
  33. package/dist/index.cjs.map +4 -4
  34. package/dist/index.d.ts +13 -4
  35. package/dist/index.js +21 -2
  36. package/dist/index.mjs +1955 -496
  37. package/dist/index.mjs.map +4 -4
  38. package/dist/invitation/index.d.ts +2 -0
  39. package/dist/invitation/index.js +2 -0
  40. package/dist/invitation/invitation.d.ts +106 -0
  41. package/dist/invitation/invitation.js +104 -0
  42. package/dist/login/login.d.ts +11 -1
  43. package/dist/login/login.js +5 -4
  44. package/dist/login/session.d.ts +21 -5
  45. package/dist/login/session.js +7 -15
  46. package/dist/namespace-op/namespace-op.d.ts +14 -2
  47. package/dist/namespace-op/namespace-op.js +13 -19
  48. package/dist/relay/index.d.ts +2 -2
  49. package/dist/relay/index.js +1 -1
  50. package/dist/relay/nonce-source.d.ts +135 -0
  51. package/dist/relay/nonce-source.js +187 -19
  52. package/dist/relay/relay-client.d.ts +60 -5
  53. package/dist/relay/relay-client.js +84 -4
  54. package/dist/relay-attestation/attest-node-key.d.ts +66 -0
  55. package/dist/relay-attestation/attest-node-key.js +110 -0
  56. package/dist/relay-attestation/index.d.ts +1 -0
  57. package/dist/relay-attestation/index.js +1 -0
  58. package/dist/request-proof/authorizer.d.ts +48 -0
  59. package/dist/request-proof/authorizer.js +65 -0
  60. package/dist/request-proof/index.d.ts +4 -0
  61. package/dist/request-proof/index.js +2 -0
  62. package/dist/request-proof/request-proof.d.ts +56 -0
  63. package/dist/request-proof/request-proof.js +111 -0
  64. package/dist/rpc/index.d.ts +21 -0
  65. package/dist/rpc/index.js +20 -0
  66. package/dist/transport/index.d.ts +6 -0
  67. package/dist/transport/index.js +3 -0
  68. package/dist/transport/mero-client.d.ts +286 -0
  69. package/dist/transport/mero-client.js +379 -0
  70. package/dist/transport/relay-observer.d.ts +152 -0
  71. package/dist/transport/relay-observer.js +173 -0
  72. package/dist/transport/relay-transport.d.ts +73 -0
  73. package/dist/transport/relay-transport.js +94 -0
  74. package/dist/transport/types.d.ts +100 -0
  75. package/dist/transport/types.js +32 -0
  76. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { type Signer } from '../signer/signer.js';
1
2
  /** An account root: the secret, the key it derives, and the account it names. */
2
3
  export interface AccountRoot {
3
4
  /**
@@ -51,10 +52,98 @@ export declare function generateAccountRoot(): Promise<RecoverableAccountRoot>;
51
52
  export declare function accountRootFromPhrase(phrase: string): Promise<RecoverableAccountRoot>;
52
53
  /** The public half of a root you already hold, without re-deriving it by hand. */
53
54
  export declare function accountRootFromSecret(secret: string): Promise<AccountRoot>;
55
+ /** An account root held as a key this page may use and cannot read. */
56
+ export interface AccountRootSigner {
57
+ /** The root's ed25519 public key, 64 hex. Safe to publish. */
58
+ readonly publicKey: string;
59
+ /** The account this root names, 64 hex. */
60
+ readonly accountId: string;
61
+ /**
62
+ * Signs for the root. Pass it to `signDeviceCert({ signer })`.
63
+ *
64
+ * There is deliberately no `secret` beside this: the point of the shape is
65
+ * that nothing downstream of here can be handed the account.
66
+ */
67
+ readonly signer: Signer;
68
+ }
69
+ /** A freshly minted root, with the phrase that is its only backup. */
70
+ export interface NewAccountRootSigner extends AccountRootSigner {
71
+ /**
72
+ * The 24-word phrase. Show it **once**, and store it nowhere.
73
+ *
74
+ * Unlike {@link RecoverableAccountRoot.phrase} this is the only copy that will
75
+ * ever exist: the signer beside it cannot be exported, so a holder who does
76
+ * not write these words down has no path back to the account from another
77
+ * browser — and neither does anyone else, which is the trade.
78
+ */
79
+ readonly phrase: string;
80
+ }
81
+ /**
82
+ * Mint a root that stays in this page and hand back its recovery phrase.
83
+ *
84
+ * The enrolment-time counterpart to {@link generateAccountRoot}: same BIP39
85
+ * entropy, same account derivation, but the secret never leaves as a string a
86
+ * caller could persist. What survives a reload is the `CryptoKey` inside the
87
+ * signer — structured-clone it into IndexedDB — and what survives losing the
88
+ * browser is the phrase.
89
+ *
90
+ * **On scrubbing.** The entropy is zeroed and the seed is imported
91
+ * unexportable, but deriving the public half needs the seed as hex for an
92
+ * instant, and a JS string cannot be wiped. So this narrows the window from
93
+ * "for as long as the account exists" to "during this call" — a real
94
+ * improvement, and not the same claim as "the secret never exists".
95
+ */
96
+ export declare function createAccountRootSigner(): Promise<NewAccountRootSigner>;
97
+ /**
98
+ * Restore the same root in another browser from its phrase.
99
+ *
100
+ * This is what makes the design portable: the phrase names the entropy, the
101
+ * entropy names the root, and the root names the account — so the same 24 words
102
+ * reach the same account id on any device, with no server involved and nothing
103
+ * to migrate.
104
+ *
105
+ * Throws on a bad word count, an unknown word, or a failed checksum rather than
106
+ * returning some other account — see {@link accountRootFromPhrase}.
107
+ */
108
+ export declare function accountRootSignerFromPhrase(phrase: string): Promise<AccountRootSigner>;
109
+ /**
110
+ * The account root, in either form a caller may hold it.
111
+ *
112
+ * Exists because the cloud entry points take the root **positionally** — the
113
+ * whole argument is "the root" — so the two forms cannot be separate optional
114
+ * fields the way {@link AccountLinkInput} has them.
115
+ *
116
+ * A `string` is the 64-hex secret. A {@link Signer} is a root this process may
117
+ * use and cannot read: pass the `signer` from
118
+ * {@link accountRootSignerFromPhrase}.
119
+ */
120
+ export type RootSource = string | Signer;
121
+ /** A root's identity and how it signs, however the caller supplied it. */
122
+ export interface ResolvedRoot {
123
+ signer: Signer;
124
+ /** The root's ed25519 public key, 64 hex. */
125
+ publicKey: string;
126
+ /** The account it names, 64 hex. */
127
+ accountId: string;
128
+ }
129
+ /** What a root is, however it was supplied: who it is, and how it signs. */
130
+ export declare function resolveRoot(source: RootSource): Promise<ResolvedRoot>;
131
+ /**
132
+ * The same, for entry points that take the two forms as separate optional
133
+ * fields. Exactly one must be present — see {@link resolveSigner}.
134
+ */
135
+ export declare function resolveRootPair(rootSecret: string | undefined, signer: Signer | undefined): Promise<ResolvedRoot>;
54
136
  /** What {@link signAccountLink} needs. */
55
137
  export interface AccountLinkInput {
56
- /** The account root's signing secret, 64 hex. */
57
- rootSecret: string;
138
+ /**
139
+ * The account root's signing secret, 64 hex.
140
+ *
141
+ * Mutually exclusive with {@link AccountLinkInput.signer}. Prefer the signer
142
+ * in a browser: this is the account, and nothing above it can revoke it.
143
+ */
144
+ rootSecret?: string;
145
+ /** The root's signer — use instead of {@link AccountLinkInput.rootSecret}. */
146
+ signer?: Signer;
58
147
  /**
59
148
  * The challenge from `GET /api/cloud/me/accounts/challenge`, verbatim.
60
149
  *
@@ -76,8 +165,14 @@ export interface AccountLinkInput {
76
165
  export declare function signAccountLink(input: AccountLinkInput): Promise<string>;
77
166
  /** What {@link signAccountLogin} needs. */
78
167
  export interface AccountLoginInput {
79
- /** The account root's signing secret, 64 hex. */
80
- rootSecret: string;
168
+ /**
169
+ * The account root's signing secret, 64 hex.
170
+ *
171
+ * Mutually exclusive with {@link AccountLoginInput.signer}.
172
+ */
173
+ rootSecret?: string;
174
+ /** The root's signer — use instead of {@link AccountLoginInput.rootSecret}. */
175
+ signer?: Signer;
81
176
  /** The challenge from `GET /api/auth/account/challenge`, verbatim UTF-8. */
82
177
  nonce: string;
83
178
  }
Binary file
@@ -1,2 +1,6 @@
1
- export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, signAccountLink, signAccountLogin, } from './account.js';
2
- export type { AccountRoot, RecoverableAccountRoot, AccountLinkInput, AccountLoginInput, } from './account.js';
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';
@@ -1,2 +1,4 @@
1
1
  // Account roots — minting one, restoring it from a phrase, and proving you hold it.
2
- export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, signAccountLink, signAccountLogin, } from './account.js';
2
+ export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, createAccountRootSigner, accountRootSignerFromPhrase, signAccountLink, signAccountLogin, } from './account.js';
3
+ export { resolveRoot } from './account.js';
4
+ export { resolveRootPair } from './account.js';
@@ -1,6 +1,37 @@
1
- import { HttpClient } from '../http-client/index.js';
2
- import type { HealthStatus, ReadinessStatus, AdminAuthStatus, InstallApplicationRequest, InstallApplicationResponseData, InstallDevApplicationRequest, UninstallApplicationResponseData, ListApplicationsResponseData, GetApplicationResponseData, ApplicationVersionEntry, GetApplicationAbiResponseData, GetLatestVersionResponseData, ListPackagesResponseData, ListVersionsResponseData, CreateContextRequest, CreateContextResponseData, DeleteContextResponseData, GetContextsResponseData, Context, GenerateContextIdentityResponseData, GetContextIdentitiesResponseData, JoinContextResponseData, JoinSubgroupInheritanceResponseData, ContextGroupResponseData, ContextStorageResponseData, InviteSpecializedNodeRequest, InviteSpecializedNodeResponseData, UpdateContextApplicationRequest, ResyncContextRequest, ResyncContextResponseData, ContextsWithExecutorsResponseData, UploadBlobRequest, UploadBlobResponseData, DeleteBlobResponseData, ListBlobsResponseData, GetBlobInfoResponseData, BlobReadOptions, CreateContextAliasRequest, CreateApplicationAliasRequest, CreateDeviceAliasRequest, CreateAliasResponseData, LookupAliasResponseData, DeleteAliasResponseData, ListAliasesResponseData, ListNamespacesResponseData, CreateNamespaceRequest, CreateNamespaceResponseData, DeleteNamespaceResponseData, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, JoinNamespaceRequest, JoinNamespaceResponseData, CreateGroupInNamespaceRequest, CreateGroupInNamespaceResponseData, SubgroupEntry, Namespace, NamespaceIdentity, NodeIdentity, AccountPairInitRequest, AccountPairInitResponseData, AccountPairCompleteRequest, AccountPairCompleteResponseData, AccountSignWithRootRequest, AccountSignWithRootResponseData, RelinkDeviceRequest, RelinkDeviceResponseData, RescopeDeviceRequest, RescopeDeviceResponseData, LabelDeviceRequest, LabelDeviceResponseData, AccountDeviceEntry, AccountApplicationEntry, RevokeAccountDeviceRequest, RevokeAccountDeviceResponseData, GroupInfoResponseData, CreateGroupRequest, CreateGroupResponseData, DeleteGroupResponseData, ListGroupMembersResponseData, ListGroupContextsResponseData, AddGroupMembersRequest, RemoveGroupMembersRequest, UpdateMemberRoleRequest, MemberCapabilities, SetMemberCapabilitiesRequest, SetDefaultCapabilitiesRequest, SetMemberAutoFollowRequest, SetSubgroupVisibilityRequest, SetTeeAdmissionPolicyRequest, GetTeeAdmissionPolicyResponseData, SetTeeAuthoringPolicyRequest, SetGroupMetadataRequest, SetMemberMetadataRequest, SetContextMetadataRequest, MetadataRecord, SyncGroupResponseData, UpgradeGroupRequest, UpgradeGroupResponseData, GroupUpgradeStatusResponseData, MigrationStatus, CascadeStatusEntry, RetryGroupUpgradeResponseData, ReparentGroupRequest, ReparentGroupResponseData, IssueOwnershipProofRequest, IssueNamespaceOwnershipProofRequest, IssueOwnershipProofResponseData, CreateGroupInvitationRequest, CreateGroupInvitationResponseData, CreateRecursiveGroupInvitationResponseData, JoinGroupRequest, JoinGroupResponseData, TeeInfoResponseData, TeeAttestRequest, TeeAttestResponseData, TeeVerifyQuoteRequest, TeeVerifyQuoteResponseData, PerformIntentRequest, PerformIntentResponseData, IntentRelayInfo, QueryContextRequest, QueryContextResponseData, ListMemberDevicesOptions, ListMemberDevicesResponseData, SealToAccountRequest, SealedEnvelope, AdmitJoinRequest, AdmitJoinResponseData } from './admin-types.js';
1
+ import { HttpClient, HTTPError } from '../http-client/index.js';
2
+ import type { HealthStatus, ReadinessStatus, AdminAuthStatus, InstallApplicationRequest, InstallApplicationResponseData, InstallDevApplicationRequest, UninstallApplicationResponseData, ListApplicationsResponseData, GetApplicationResponseData, ApplicationVersionEntry, GetApplicationAbiResponseData, GetLatestVersionResponseData, ListPackagesResponseData, ListVersionsResponseData, CreateContextRequest, CreateContextResponseData, DeleteContextResponseData, GetContextsResponseData, Context, GenerateContextIdentityResponseData, GetContextIdentitiesResponseData, JoinContextResponseData, JoinSubgroupInheritanceResponseData, ContextGroupResponseData, ContextStorageResponseData, InviteSpecializedNodeRequest, InviteSpecializedNodeResponseData, UpdateContextApplicationRequest, ResyncContextRequest, ResyncContextResponseData, ContextsWithExecutorsResponseData, UploadBlobRequest, UploadBlobResponseData, DeleteBlobResponseData, ListBlobsResponseData, GetBlobInfoResponseData, BlobReadOptions, CreateContextAliasRequest, CreateApplicationAliasRequest, CreateDeviceAliasRequest, CreateAliasResponseData, LookupAliasResponseData, DeleteAliasResponseData, ListAliasesResponseData, ListNamespacesResponseData, CreateNamespaceRequest, CreateNamespaceResponseData, DeleteNamespaceResponseData, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, JoinNamespaceRequest, JoinNamespaceResponseData, CreateGroupInNamespaceRequest, CreateGroupInNamespaceResponseData, SubgroupEntry, Namespace, NamespaceIdentity, NodeIdentity, AccountPairInitRequest, AccountPairInitResponseData, AccountPairCompleteRequest, AccountPairCompleteResponseData, AccountSignWithRootRequest, AccountSignWithRootResponseData, RelinkDeviceRequest, RelinkDeviceResponseData, RescopeDeviceRequest, RescopeDeviceResponseData, LabelDeviceRequest, LabelDeviceResponseData, AccountDeviceEntry, AccountApplicationEntry, RevokeAccountDeviceRequest, LinkAccountDeviceRequest, LinkAccountDeviceResponseData, RevokeAccountDeviceResponseData, MemberDevicesEntry, ListMemberDevicesOptions, GroupInfoResponseData, CreateGroupRequest, CreateGroupResponseData, DeleteGroupResponseData, ListGroupMembersResponseData, ListGroupContextsResponseData, AddGroupMembersRequest, RemoveGroupMembersRequest, UpdateMemberRoleRequest, MemberCapabilities, SetMemberCapabilitiesRequest, SetDefaultCapabilitiesRequest, SetMemberAutoFollowRequest, SetSubgroupVisibilityRequest, SetTeeAdmissionPolicyRequest, GetTeeAdmissionPolicyResponseData, SetTeeAuthoringPolicyRequest, SetGroupMetadataRequest, SetMemberMetadataRequest, SetContextMetadataRequest, MetadataRecord, SyncGroupResponseData, UpgradeGroupRequest, UpgradeGroupResponseData, GroupUpgradeStatusResponseData, MigrationStatus, CascadeStatusEntry, RetryGroupUpgradeResponseData, ReparentGroupRequest, ReparentGroupResponseData, IssueOwnershipProofRequest, IssueNamespaceOwnershipProofRequest, IssueOwnershipProofResponseData, CreateGroupInvitationRequest, CreateGroupInvitationResponseData, CreateRecursiveGroupInvitationResponseData, JoinGroupRequest, JoinGroupResponseData, TeeInfoResponseData, TeeAttestRequest, TeeAttestResponseData, TeeVerifyQuoteRequest, TeeVerifyQuoteResponseData, PerformIntentRequest, PerformIntentResponseData, IntentRelayInfo, QueryContextRequest, QueryContextResponseData, ListMemberDevicesResponseData, SealToAccountRequest, SealedEnvelope, AdmitJoinRequest, AdmitJoinResponseData, WarrantNonceState } from './admin-types.js';
3
3
  import { type RedeemOutcome } from './redeem-invitation.js';
4
+ /**
5
+ * Thrown when a node answers the warrant-nonce route with a 404.
6
+ *
7
+ * Its own type because the meaning is unambiguous and not "not found": the
8
+ * handler never 404s — an unknown device is a `200` with `seen: false`, a
9
+ * malformed id is a `400` — so a 404 says the route is not mounted on this
10
+ * node. It is new on core and absent from `master` builds. A caller that sees
11
+ * this should fall back to its own counter (or refuse to write) rather than
12
+ * retry, because no amount of retrying adds a route to a running node.
13
+ */
14
+ export declare class WarrantNonceRouteUnavailableError extends Error {
15
+ /** The path that answered 404. */
16
+ readonly path: string;
17
+ /** The underlying HTTP failure, kept for logs. */
18
+ readonly cause: HTTPError;
19
+ name: string;
20
+ constructor(
21
+ /** The path that answered 404. */
22
+ path: string,
23
+ /** The underlying HTTP failure, kept for logs. */
24
+ cause: HTTPError);
25
+ }
26
+ /**
27
+ * Shape the node's answer into the union, which is where the exhausted case
28
+ * stops being a missing field and starts being something the compiler asks
29
+ * about.
30
+ *
31
+ * Exported for tests: it is the whole client-side contract of the route, and
32
+ * testing it needs no transport.
33
+ */
34
+ export declare function parseWarrantNonce(body: string): WarrantNonceState;
4
35
  /**
5
36
  * Compare two version strings by SemVer 2.0 precedence, ascending: negative if
6
37
  * `a < b`, positive if `a > b`, `0` if equal. Build metadata (`+...`) is stripped
@@ -397,8 +428,31 @@ export declare class AdminApiClient {
397
428
  * `namespaceId` names where to publish from, not the extent of the revocation:
398
429
  * a device belongs to the account, so every namespace holding a binding for it
399
430
  * is withdrawn from and reported back.
431
+ *
432
+ * **Revocation is forward-only.** It withdraws the device's authority from
433
+ * here on and does NOT retract past authorship: ops the device already signed
434
+ * keep verifying and stay in the DAG, because the certificate that authorised
435
+ * them was valid when the signature was made. Nothing in this system can
436
+ * un-author what a device wrote, so a UI built on this call must not offer
437
+ * that - "this device can no longer act" is the only claim it supports.
400
438
  */
401
439
  revokeAccountDevice(namespaceId: string, request: RevokeAccountDeviceRequest): Promise<RevokeAccountDeviceResponseData>;
440
+ /**
441
+ * Carry the device link of an account **this node does not hold**, so the
442
+ * namespace binds that device's key to the account.
443
+ *
444
+ * The relay half of a nodeless account minting invitations. An account added
445
+ * to a group by account holds its grants but has no device bound, so peers
446
+ * refuse whatever its device signs as "bound to no account". The credential
447
+ * and scope are root-signed and self-certifying; this node adds its own
448
+ * member endorsement and publishes the `AccountDeviceLinked`. After that the
449
+ * device signs invitations itself — see `signGroupInvitation`.
450
+ *
451
+ * Refusals: `400` when a proof does not verify or the scope does not reach
452
+ * this namespace (re-sign it), `403` when the device was revoked here or the
453
+ * account is a member of nothing in the namespace (add it first).
454
+ */
455
+ linkAccountDevice(namespaceId: string, request: LinkAccountDeviceRequest): Promise<LinkAccountDeviceResponseData>;
402
456
  getGroupInfo(groupId: string): Promise<GroupInfoResponseData>;
403
457
  /** Thin wrapper over {@link getGroupInfo}: returns the group's `defaultCapabilities` bitmask. */
404
458
  getDefaultCapabilities(groupId: string): Promise<number>;
@@ -406,6 +460,104 @@ export declare class AdminApiClient {
406
460
  getSubgroupVisibility(groupId: string): Promise<string>;
407
461
  deleteGroup(groupId: string): Promise<DeleteGroupResponseData>;
408
462
  listGroupMembers(groupId: string): Promise<ListGroupMembersResponseData>;
463
+ /**
464
+ * Account -> devices for the members of a group, as its live bindings record
465
+ * them.
466
+ *
467
+ * The join between a group member listing, which names accounts, and a
468
+ * context's identities, which name bare signing keys - both 64 hex, and
469
+ * nothing but the source tells them apart. Batch rather than per-account
470
+ * because the key -> account direction gets asked about arbitrary authors,
471
+ * which a per-account route would answer in N calls.
472
+ *
473
+ * What comes back is **caller-scoped by the node**: an admin of the group sees
474
+ * every member's devices, a plain member only its own entry. A single-entry
475
+ * answer is therefore a statement about this caller's role, not about the
476
+ * group's size.
477
+ *
478
+ * Only live bindings appear, so a revoked device is absent here - use
479
+ * {@link listAccountDevices} for the account's own devices, which keeps a
480
+ * revoked one with `revoked: true`. Absence here never means the device never
481
+ * acted: revocation is forward-only and its past ops remain in the DAG.
482
+ *
483
+ * Wrapped in `members` on the wire rather than `data`, unwrapped here for the
484
+ * same reason {@link listAccountDevices} unwraps `devices`.
485
+ */
486
+ listGroupMemberDevices(groupId: string, options?: ListMemberDevicesOptions): Promise<MemberDevicesEntry[]>;
487
+ /**
488
+ * Where `authorDeviceKey` stands in its warrant-nonce sequence in `contextId`.
489
+ *
490
+ * # What this is for
491
+ *
492
+ * The nonce is the one input to a warrant that is stateful on the *client*.
493
+ * Everything else an author needs it either holds (its keys, the method, the
494
+ * args) or can read from the relay ({@link RelayClient.describe} gives the
495
+ * executor account and the grant). So an author that has lost its counter —
496
+ * a browser keyholder in partitioned or periodically cleared storage, which
497
+ * is its normal lifecycle rather than a fault — otherwise has exactly one
498
+ * strategy: guess upward and burn a refused round trip per wrong guess, with
499
+ * each refusal indistinguishable at the API from a genuinely spent nonce.
500
+ *
501
+ * Read {@link WarrantNonceOpen.nextNonce} and mint there. If you still hold
502
+ * your own counter, mint at `max(ownNext, nextNonce)`: nonce state folds per
503
+ * peer, so a node can only be BEHIND a client whose warrants it has not
504
+ * applied — never ahead of the truth. An author spread across several relays
505
+ * asks each and takes the highest answer. {@link createRecoveringNonceSource}
506
+ * does all of that.
507
+ *
508
+ * Purely a read. It spends nothing and advances nothing, so it may be called
509
+ * as often as you like.
510
+ *
511
+ * # Forward compatibility — this route is NEW
512
+ *
513
+ * It is not on core `master` yet, so a current node answers **404**, which
514
+ * this method surfaces as {@link WarrantNonceRouteUnavailableError} rather
515
+ * than as an opaque {@link HTTPError}. That distinction matters because the
516
+ * handler itself never 404s: a device with no row is a `200` with
517
+ * `seen: false`, and a malformed id is a `400`. So a 404 here means the node
518
+ * does not serve the route at all — an older build, or a deployment that has
519
+ * not re-mounted it — and the answer is to fall back to a local counter, not
520
+ * to retry.
521
+ *
522
+ * # Authentication
523
+ *
524
+ * On the PROTECTED admin router, unlike the two delegated-execution routes it
525
+ * sits beside: it takes another principal's device key as input and reports
526
+ * that principal's activity. A `--public-intents` deployment does not serve
527
+ * this anonymously, so an admin credential is required.
528
+ *
529
+ * @param authorDeviceKey the device's signing key, base58 (43-44 chars) or
530
+ * hex (exactly 64). The node accepts either; the two never collide.
531
+ */
532
+ getWarrantNonce(contextId: string, authorDeviceKey: string): Promise<WarrantNonceState>;
533
+ /**
534
+ * The same answer, asked for the way a delegated client has to ask.
535
+ *
536
+ * {@link getWarrantNonce} is on the protected admin router, so a keyholder
537
+ * writing through a relay — the client this whole facility exists for — is
538
+ * refused it: measured `403` for a session carrying exactly
539
+ * `context:intent`, `context:query`, `context:subscribe`. That client has no
540
+ * admin credential and cannot be given one without defeating the point of the
541
+ * delegated surface.
542
+ *
543
+ * What it does have is the credential proving the device is its own, which it
544
+ * already sends on every write. Presenting it here makes the request
545
+ * self-scoped: you learn a device's position only by proving, at call time,
546
+ * that the device is yours. So there is no oracle to protect against, and no
547
+ * reason for an admin gate.
548
+ *
549
+ * The device key is NOT a parameter. It is read from the verified
550
+ * certificate server-side, which is the only reading that cannot disagree
551
+ * with the signature — a key supplied alongside would be a second spelling of
552
+ * the same fact, and two spellings can differ.
553
+ *
554
+ * Returns the identical shape {@link getWarrantNonce} returns, so a caller can
555
+ * swap one for the other without touching what it does with the answer.
556
+ *
557
+ * @param authorProof hex-encoded borsh `AccountProof<DeviceCert>` — the same
558
+ * value passed as `authorProof` to the relay client.
559
+ */
560
+ getWarrantNonceAsAuthor(contextId: string, authorProof: string): Promise<WarrantNonceState>;
409
561
  /**
410
562
  * Member accounts in the group and the devices bound to each. An admin node
411
563
  * sees every account; a plain member only its own. `403` if this node is not a
@@ -1,6 +1,91 @@
1
- import { withRetry } from '../http-client/index.js';
1
+ import { HTTPError, withRetry } from '../http-client/index.js';
2
2
  import { CAPABILITIES, hasCap, withCap } from '../capabilities.js';
3
3
  import { redeemInvitation } from './redeem-invitation.js';
4
+ /**
5
+ * Thrown when a node answers the warrant-nonce route with a 404.
6
+ *
7
+ * Its own type because the meaning is unambiguous and not "not found": the
8
+ * handler never 404s — an unknown device is a `200` with `seen: false`, a
9
+ * malformed id is a `400` — so a 404 says the route is not mounted on this
10
+ * node. It is new on core and absent from `master` builds. A caller that sees
11
+ * this should fall back to its own counter (or refuse to write) rather than
12
+ * retry, because no amount of retrying adds a route to a running node.
13
+ */
14
+ export class WarrantNonceRouteUnavailableError extends Error {
15
+ constructor(
16
+ /** The path that answered 404. */
17
+ path,
18
+ /** The underlying HTTP failure, kept for logs. */
19
+ cause) {
20
+ super(`this node does not serve warrant-nonce discovery (404 on ${path}); it predates the route, so a client must fall back to its own nonce counter`);
21
+ this.path = path;
22
+ this.cause = cause;
23
+ this.name = 'WarrantNonceRouteUnavailableError';
24
+ }
25
+ }
26
+ /**
27
+ * Recover a `u64` from the response bytes rather than from a parsed `number`.
28
+ *
29
+ * `JSON.parse` has already rounded anything past 2^53 by the time a value is
30
+ * handed over, and it rounds without complaint — so the digits are read back
31
+ * out of the source text and turned straight into a `bigint`.
32
+ *
33
+ * Matching on the quoted key is safe for exactly this response: its only two
34
+ * string fields are a context id and a device key, both of which are hex or
35
+ * base58 and so cannot contain a quote, a colon, or these field names. The
36
+ * parsed object still decides whether a field is *present*; the text is
37
+ * consulted only for its digits.
38
+ */
39
+ function u64FromBody(body, parsed, field) {
40
+ const value = parsed[field];
41
+ if (value === undefined || value === null)
42
+ return undefined;
43
+ const digits = new RegExp(`"${field}"\\s*:\\s*(\\d+)`).exec(body);
44
+ if (digits)
45
+ return BigInt(digits[1]);
46
+ // The field is present but not a bare integer literal in the body — a node
47
+ // that started sending it as a string, say. Accept a decimal string, and
48
+ // refuse anything else loudly instead of coercing a nonce into existence.
49
+ if (typeof value === 'string' && /^\d+$/.test(value))
50
+ return BigInt(value);
51
+ throw new Error(`warrant-nonce response field \`${field}\` is not a u64: ${JSON.stringify(value)}`);
52
+ }
53
+ /**
54
+ * Shape the node's answer into the union, which is where the exhausted case
55
+ * stops being a missing field and starts being something the compiler asks
56
+ * about.
57
+ *
58
+ * Exported for tests: it is the whole client-side contract of the route, and
59
+ * testing it needs no transport.
60
+ */
61
+ export function parseWarrantNonce(body) {
62
+ const parsed = JSON.parse(body);
63
+ const data = parsed?.data;
64
+ if (!data || typeof data !== 'object') {
65
+ throw new Error(`warrant-nonce response had no \`data\`: ${body.slice(0, 200)}`);
66
+ }
67
+ const common = {
68
+ contextId: String(data.contextId ?? ''),
69
+ authorDeviceKey: String(data.authorDeviceKey ?? ''),
70
+ seen: data.seen === true,
71
+ highWaterNonce: u64FromBody(body, data, 'highWaterNonce'),
72
+ // Not defaulted: a node that stopped sending it is a node whose window this
73
+ // client would be guessing at, and the window is not a nonce input anyway.
74
+ windowWidth: u64FromBody(body, data, 'windowWidth') ?? 0n,
75
+ };
76
+ const nextNonce = u64FromBody(body, data, 'nextNonce');
77
+ if (nextNonce === undefined) {
78
+ // The one absence with a meaning: `u64::MAX` is spent. The node omits the
79
+ // field rather than wrapping to `0`, and a client must not fill the gap.
80
+ return {
81
+ ...common,
82
+ kind: 'exhausted',
83
+ seen: true,
84
+ highWaterNonce: common.highWaterNonce ?? 0xffffffffffffffffn,
85
+ };
86
+ }
87
+ return { ...common, kind: 'open', nextNonce };
88
+ }
4
89
  /**
5
90
  * Helper: server wraps most responses in `{ data: T }`.
6
91
  * This extracts `.data` so callers get the inner payload directly. Null-safe so an
@@ -733,10 +818,35 @@ export class AdminApiClient {
733
818
  * `namespaceId` names where to publish from, not the extent of the revocation:
734
819
  * a device belongs to the account, so every namespace holding a binding for it
735
820
  * is withdrawn from and reported back.
821
+ *
822
+ * **Revocation is forward-only.** It withdraws the device's authority from
823
+ * here on and does NOT retract past authorship: ops the device already signed
824
+ * keep verifying and stay in the DAG, because the certificate that authorised
825
+ * them was valid when the signature was made. Nothing in this system can
826
+ * un-author what a device wrote, so a UI built on this call must not offer
827
+ * that - "this device can no longer act" is the only claim it supports.
736
828
  */
737
829
  async revokeAccountDevice(namespaceId, request) {
738
830
  return unwrap(await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/account/revoke`, request));
739
831
  }
832
+ /**
833
+ * Carry the device link of an account **this node does not hold**, so the
834
+ * namespace binds that device's key to the account.
835
+ *
836
+ * The relay half of a nodeless account minting invitations. An account added
837
+ * to a group by account holds its grants but has no device bound, so peers
838
+ * refuse whatever its device signs as "bound to no account". The credential
839
+ * and scope are root-signed and self-certifying; this node adds its own
840
+ * member endorsement and publishes the `AccountDeviceLinked`. After that the
841
+ * device signs invitations itself — see `signGroupInvitation`.
842
+ *
843
+ * Refusals: `400` when a proof does not verify or the scope does not reach
844
+ * this namespace (re-sign it), `403` when the device was revoked here or the
845
+ * account is a member of nothing in the namespace (add it first).
846
+ */
847
+ async linkAccountDevice(namespaceId, request) {
848
+ return unwrap(await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/account/link-device`, request));
849
+ }
740
850
  // ---- Group Management ----
741
851
  async getGroupInfo(groupId) {
742
852
  return unwrap(await this.httpClient.get(`/admin-api/groups/${groupId}`));
@@ -774,6 +884,150 @@ export class AdminApiClient {
774
884
  }
775
885
  return response;
776
886
  }
887
+ /**
888
+ * Account -> devices for the members of a group, as its live bindings record
889
+ * them.
890
+ *
891
+ * The join between a group member listing, which names accounts, and a
892
+ * context's identities, which name bare signing keys - both 64 hex, and
893
+ * nothing but the source tells them apart. Batch rather than per-account
894
+ * because the key -> account direction gets asked about arbitrary authors,
895
+ * which a per-account route would answer in N calls.
896
+ *
897
+ * What comes back is **caller-scoped by the node**: an admin of the group sees
898
+ * every member's devices, a plain member only its own entry. A single-entry
899
+ * answer is therefore a statement about this caller's role, not about the
900
+ * group's size.
901
+ *
902
+ * Only live bindings appear, so a revoked device is absent here - use
903
+ * {@link listAccountDevices} for the account's own devices, which keeps a
904
+ * revoked one with `revoked: true`. Absence here never means the device never
905
+ * acted: revocation is forward-only and its past ops remain in the DAG.
906
+ *
907
+ * Wrapped in `members` on the wire rather than `data`, unwrapped here for the
908
+ * same reason {@link listAccountDevices} unwraps `devices`.
909
+ */
910
+ async listGroupMemberDevices(groupId, options) {
911
+ // Both params are optional on the node, which clamps `limit` to its own
912
+ // maximum; sending them only when asked keeps the node's defaults authoritative
913
+ // rather than freezing today's values into this client.
914
+ const params = new URLSearchParams();
915
+ if (options?.offset !== undefined)
916
+ params.set('offset', String(options.offset));
917
+ if (options?.limit !== undefined)
918
+ params.set('limit', String(options.limit));
919
+ const query = params.toString();
920
+ const base = `/admin-api/groups/${encodeURIComponent(groupId)}/member-devices`;
921
+ const response = await this.httpClient.get(query ? `${base}?${query}` : base);
922
+ return response.members;
923
+ }
924
+ /**
925
+ * Where `authorDeviceKey` stands in its warrant-nonce sequence in `contextId`.
926
+ *
927
+ * # What this is for
928
+ *
929
+ * The nonce is the one input to a warrant that is stateful on the *client*.
930
+ * Everything else an author needs it either holds (its keys, the method, the
931
+ * args) or can read from the relay ({@link RelayClient.describe} gives the
932
+ * executor account and the grant). So an author that has lost its counter —
933
+ * a browser keyholder in partitioned or periodically cleared storage, which
934
+ * is its normal lifecycle rather than a fault — otherwise has exactly one
935
+ * strategy: guess upward and burn a refused round trip per wrong guess, with
936
+ * each refusal indistinguishable at the API from a genuinely spent nonce.
937
+ *
938
+ * Read {@link WarrantNonceOpen.nextNonce} and mint there. If you still hold
939
+ * your own counter, mint at `max(ownNext, nextNonce)`: nonce state folds per
940
+ * peer, so a node can only be BEHIND a client whose warrants it has not
941
+ * applied — never ahead of the truth. An author spread across several relays
942
+ * asks each and takes the highest answer. {@link createRecoveringNonceSource}
943
+ * does all of that.
944
+ *
945
+ * Purely a read. It spends nothing and advances nothing, so it may be called
946
+ * as often as you like.
947
+ *
948
+ * # Forward compatibility — this route is NEW
949
+ *
950
+ * It is not on core `master` yet, so a current node answers **404**, which
951
+ * this method surfaces as {@link WarrantNonceRouteUnavailableError} rather
952
+ * than as an opaque {@link HTTPError}. That distinction matters because the
953
+ * handler itself never 404s: a device with no row is a `200` with
954
+ * `seen: false`, and a malformed id is a `400`. So a 404 here means the node
955
+ * does not serve the route at all — an older build, or a deployment that has
956
+ * not re-mounted it — and the answer is to fall back to a local counter, not
957
+ * to retry.
958
+ *
959
+ * # Authentication
960
+ *
961
+ * On the PROTECTED admin router, unlike the two delegated-execution routes it
962
+ * sits beside: it takes another principal's device key as input and reports
963
+ * that principal's activity. A `--public-intents` deployment does not serve
964
+ * this anonymously, so an admin credential is required.
965
+ *
966
+ * @param authorDeviceKey the device's signing key, base58 (43-44 chars) or
967
+ * hex (exactly 64). The node accepts either; the two never collide.
968
+ */
969
+ async getWarrantNonce(contextId, authorDeviceKey) {
970
+ const path = `/admin-api/contexts/${encodeURIComponent(contextId)}/warrant-nonce/${encodeURIComponent(authorDeviceKey)}`;
971
+ // Read as TEXT, not JSON. `JSON.parse` would turn the `u64` nonces into
972
+ // doubles before this code ever sees them, rounding anything past 2^53 into
973
+ // a value that looks ordinary and is refused forever. The digits have to be
974
+ // taken from the bytes.
975
+ let raw;
976
+ try {
977
+ raw = await this.httpClient.get(path, { parse: 'text' });
978
+ }
979
+ catch (error) {
980
+ if (error instanceof HTTPError && error.status === 404) {
981
+ throw new WarrantNonceRouteUnavailableError(path, error);
982
+ }
983
+ throw error;
984
+ }
985
+ return parseWarrantNonce(raw);
986
+ }
987
+ /**
988
+ * The same answer, asked for the way a delegated client has to ask.
989
+ *
990
+ * {@link getWarrantNonce} is on the protected admin router, so a keyholder
991
+ * writing through a relay — the client this whole facility exists for — is
992
+ * refused it: measured `403` for a session carrying exactly
993
+ * `context:intent`, `context:query`, `context:subscribe`. That client has no
994
+ * admin credential and cannot be given one without defeating the point of the
995
+ * delegated surface.
996
+ *
997
+ * What it does have is the credential proving the device is its own, which it
998
+ * already sends on every write. Presenting it here makes the request
999
+ * self-scoped: you learn a device's position only by proving, at call time,
1000
+ * that the device is yours. So there is no oracle to protect against, and no
1001
+ * reason for an admin gate.
1002
+ *
1003
+ * The device key is NOT a parameter. It is read from the verified
1004
+ * certificate server-side, which is the only reading that cannot disagree
1005
+ * with the signature — a key supplied alongside would be a second spelling of
1006
+ * the same fact, and two spellings can differ.
1007
+ *
1008
+ * Returns the identical shape {@link getWarrantNonce} returns, so a caller can
1009
+ * swap one for the other without touching what it does with the answer.
1010
+ *
1011
+ * @param authorProof hex-encoded borsh `AccountProof<DeviceCert>` — the same
1012
+ * value passed as `authorProof` to the relay client.
1013
+ */
1014
+ async getWarrantNonceAsAuthor(contextId, authorProof) {
1015
+ const path = `/admin-api/contexts/${encodeURIComponent(contextId)}/warrant-nonce`;
1016
+ // Text, not JSON, for the reason given in `getWarrantNonce`: `JSON.parse`
1017
+ // rounds a u64 past 2^53 into a nonce that looks ordinary and is refused
1018
+ // for ever.
1019
+ let raw;
1020
+ try {
1021
+ raw = await this.httpClient.post(path, { authorProof }, { parse: 'text' });
1022
+ }
1023
+ catch (error) {
1024
+ if (error instanceof HTTPError && error.status === 404) {
1025
+ throw new WarrantNonceRouteUnavailableError(path, error);
1026
+ }
1027
+ throw error;
1028
+ }
1029
+ return parseWarrantNonce(raw);
1030
+ }
777
1031
  /**
778
1032
  * Member accounts in the group and the devices bound to each. An admin node
779
1033
  * sees every account; a plain member only its own. `403` if this node is not a