@serfab/cadre-core 1.9.0 → 1.11.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 (119) hide show
  1. package/dist/cadre-node.d.ts +148 -44
  2. package/dist/cadre-node.js +363 -139
  3. package/dist/cadre-node.js.map +1 -1
  4. package/dist/control-authorization.d.ts +2 -2
  5. package/dist/control-authorization.js +1 -0
  6. package/dist/control-authorization.js.map +1 -1
  7. package/dist/control-cohort.d.ts +1 -1
  8. package/dist/control-cohort.js +1 -1
  9. package/dist/control-database.d.ts +105 -14
  10. package/dist/control-database.js +242 -73
  11. package/dist/control-database.js.map +1 -1
  12. package/dist/control-formation-recorder.d.ts +6 -6
  13. package/dist/control-formation-recorder.js +7 -8
  14. package/dist/control-formation-recorder.js.map +1 -1
  15. package/dist/control-schema.d.ts +1 -1
  16. package/dist/control-schema.js +1066 -979
  17. package/dist/control-schema.js.map +1 -1
  18. package/dist/control-write-retry.d.ts +21 -15
  19. package/dist/control-write-retry.js +21 -15
  20. package/dist/control-write-retry.js.map +1 -1
  21. package/dist/diagnostics/connection-path.d.ts +1 -18
  22. package/dist/diagnostics/connection-path.js +1 -20
  23. package/dist/diagnostics/connection-path.js.map +1 -1
  24. package/dist/identity-key.d.ts +0 -30
  25. package/dist/identity-key.js +7 -40
  26. package/dist/identity-key.js.map +1 -1
  27. package/dist/index.d.ts +8 -5
  28. package/dist/index.js +12 -6
  29. package/dist/index.js.map +1 -1
  30. package/dist/invitation-bootstrap.d.ts +32 -0
  31. package/dist/invitation-bootstrap.js +30 -0
  32. package/dist/invitation-bootstrap.js.map +1 -0
  33. package/dist/link-budget.d.ts +204 -119
  34. package/dist/link-budget.js +208 -120
  35. package/dist/link-budget.js.map +1 -1
  36. package/dist/membership-connection-gater.d.ts +3 -3
  37. package/dist/membership-connection-gater.js +3 -3
  38. package/dist/peer-dial.d.ts +18 -14
  39. package/dist/peer-dial.js +18 -14
  40. package/dist/peer-dial.js.map +1 -1
  41. package/dist/peer-join-backfill.d.ts +3 -3
  42. package/dist/pending-join-runner.d.ts +186 -0
  43. package/dist/pending-join-runner.js +649 -0
  44. package/dist/pending-join-runner.js.map +1 -0
  45. package/dist/push-fanout.d.ts +1 -1
  46. package/dist/push-fanout.js +1 -1
  47. package/dist/relay-stun.d.ts +24 -0
  48. package/dist/relay-stun.js +51 -0
  49. package/dist/relay-stun.js.map +1 -0
  50. package/dist/seed-bootstrap.d.ts +2 -2
  51. package/dist/seed-bootstrap.js +5 -5
  52. package/dist/strand-addr-protocol.js +2 -2
  53. package/dist/strand-formation-deadlines.d.ts +5 -5
  54. package/dist/strand-formation-deadlines.js +5 -5
  55. package/dist/strand-formation-manager.d.ts +18 -4
  56. package/dist/strand-formation-manager.js +48 -33
  57. package/dist/strand-formation-manager.js.map +1 -1
  58. package/dist/strand-formation-protocol.d.ts +71 -14
  59. package/dist/strand-formation-protocol.js +222 -47
  60. package/dist/strand-formation-protocol.js.map +1 -1
  61. package/dist/strand-formation-rejection.d.ts +94 -0
  62. package/dist/strand-formation-rejection.js +77 -0
  63. package/dist/strand-formation-rejection.js.map +1 -0
  64. package/dist/strand-instance-manager.js +4 -1
  65. package/dist/strand-instance-manager.js.map +1 -1
  66. package/dist/strand-membership-writer.js +32 -32
  67. package/dist/strand-solicitation.d.ts +11 -3
  68. package/dist/strand-solicitation.js +9 -0
  69. package/dist/strand-solicitation.js.map +1 -1
  70. package/dist/types.d.ts +103 -17
  71. package/dist/types.js +5 -9
  72. package/dist/types.js.map +1 -1
  73. package/package.json +22 -22
  74. package/src/cadre-node.ts +8654 -8400
  75. package/src/control-authorization.ts +2 -1
  76. package/src/control-cohort.ts +128 -128
  77. package/src/control-database.ts +303 -82
  78. package/src/control-formation-recorder.ts +353 -354
  79. package/src/control-read-retry.ts +216 -216
  80. package/src/control-schema.ts +1078 -991
  81. package/src/control-write-retry.ts +567 -561
  82. package/src/diagnostics/connection-path.ts +1 -29
  83. package/src/formation-approval.ts +610 -610
  84. package/src/hibernation-manager.ts +638 -638
  85. package/src/identity-key.ts +7 -62
  86. package/src/index.ts +644 -627
  87. package/src/invitation-bootstrap.ts +40 -0
  88. package/src/joined-strand-store.ts +498 -498
  89. package/src/link-budget.ts +684 -583
  90. package/src/membership-connection-gater.ts +570 -570
  91. package/src/node-local-snapshot.ts +298 -298
  92. package/src/peer-dial.ts +315 -311
  93. package/src/peer-join-backfill.ts +710 -710
  94. package/src/pending-join-runner.ts +735 -0
  95. package/src/push-fanout.ts +1 -1
  96. package/src/relay-reservation.ts +1121 -1121
  97. package/src/relay-server.ts +98 -98
  98. package/src/relay-stun.ts +58 -0
  99. package/src/seed-bootstrap.ts +1448 -1448
  100. package/src/strand-addr-protocol.ts +547 -547
  101. package/src/strand-database.ts +287 -287
  102. package/src/strand-first-sync-gate.ts +391 -391
  103. package/src/strand-formation-deadlines.ts +227 -227
  104. package/src/strand-formation-manager.ts +725 -700
  105. package/src/strand-formation-protocol.ts +1036 -802
  106. package/src/strand-formation-rejection.ts +129 -0
  107. package/src/strand-fret-addrs.ts +145 -145
  108. package/src/strand-instance-manager.ts +1789 -1786
  109. package/src/strand-membership-writer.ts +1974 -1974
  110. package/src/strand-network-state-file.ts +40 -40
  111. package/src/strand-network-state.ts +243 -243
  112. package/src/strand-revocation-enforcer.ts +654 -654
  113. package/src/strand-solicitation.ts +532 -519
  114. package/src/strand-wake-protocol.ts +401 -401
  115. package/src/types.ts +2222 -2140
  116. package/dist/diagnostics/webrtc-turn-tracker.d.ts +0 -50
  117. package/dist/diagnostics/webrtc-turn-tracker.js +0 -196
  118. package/dist/diagnostics/webrtc-turn-tracker.js.map +0 -1
  119. package/src/diagnostics/webrtc-turn-tracker.ts +0 -222
@@ -1,20 +1,16 @@
1
1
  /**
2
2
  * identity-key — the load-or-create rule for a {@link KeyStore}-backed node
3
- * identity, plus the "prove you hold this node key" signer built on top of it.
4
- *
5
- * Both live here because both are needed *outside* `CadreNode`: an embedding app
6
- * (the React Native reference app) has to resolve its identity key before the node
7
- * is constructed, so it can sign an out-of-band HTTP request with the same key the
8
- * node will then load. Keeping one copy of the load-or-create rule is load-bearing
9
- * — a second copy that drifted could generate a fresh key and orphan the real
10
3
  * identity.
11
4
  *
12
- * Dependency-free beyond `@libp2p/crypto` + `uint8arrays` (both already core
13
- * dependencies), so this module is safe in every (RN / browser / Node) entry graph.
5
+ * Exported beyond `CadreNode` because an embedding app may need its identity key
6
+ * before the node is constructed. Keeping one copy of the rule is load-bearing — a
7
+ * second copy that drifted could generate a fresh key and orphan the real identity.
8
+ *
9
+ * Dependency-free beyond `@libp2p/crypto` (already a core dependency), so this
10
+ * module is safe in every (RN / browser / Node) entry graph.
14
11
  */
15
12
  import debug from 'debug';
16
- import { generateKeyPair, privateKeyToProtobuf, privateKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys';
17
- import { toString as uint8ArrayToString } from 'uint8arrays';
13
+ import { generateKeyPair, privateKeyToProtobuf, privateKeyFromProtobuf } from '@libp2p/crypto/keys';
18
14
  import type { PrivateKey } from '@libp2p/interface';
19
15
  import { DEFAULT_IDENTITY_KEY_ID, type KeyId, type KeyStore } from './key-store.js';
20
16
 
@@ -56,54 +52,3 @@ export async function loadOrCreateIdentityKey(
56
52
  log('Identity key generated and persisted to key store (first run)');
57
53
  return generated;
58
54
  }
59
-
60
- /**
61
- * Proof-of-possession signer for a node key, for out-of-band HTTP services that
62
- * want to attribute a request to a peer id.
63
- *
64
- * Deliberately generic — it carries no ICE/TURN vocabulary, and the message it
65
- * signs is the caller's business. The one consumer today is the reference apps'
66
- * `loadIceConfig`, which signs the TURN credential issuer's peer assertion; those
67
- * files mirror this interface structurally rather than importing it, so they stay
68
- * dependency-free.
69
- */
70
- export interface PeerKeySigner {
71
- /** base58btc peer id — the same string libp2p reports for this node. */
72
- readonly peerId: string;
73
- /** base64url of the libp2p protobuf-encoded public key. */
74
- readonly publicKeyB64: string;
75
- /** Sign the UTF-8 bytes of `message`; resolves to a base64url signature. */
76
- sign(message: string): Promise<string>;
77
- }
78
-
79
- /**
80
- * Wrap a libp2p private key as a {@link PeerKeySigner}.
81
- *
82
- * Ed25519 only: the peer id is derived as an identity multihash (so
83
- * `publicKey.toString()` already *is* the base58btc peer id — no `@libp2p/peer-id`
84
- * round trip needed), and verifiers of this proof accept nothing else.
85
- *
86
- * @param privateKey - The node's libp2p Ed25519 private key.
87
- * @returns A signer exposing the peer id, the encoded public key, and `sign`.
88
- * @throws If the key is not Ed25519.
89
- */
90
- export function peerKeySigner(privateKey: PrivateKey): PeerKeySigner {
91
- if (privateKey.type !== 'Ed25519') {
92
- throw new Error(`peerKeySigner requires an Ed25519 key, got ${privateKey.type}`);
93
- }
94
-
95
- const publicKey = privateKey.publicKey;
96
- // For Ed25519 the public key's digest is an identity multihash, so its string
97
- // form is the peer id itself — the same value `peerIdFromPrivateKey` produces.
98
- const peerId = publicKey.toString();
99
- const publicKeyB64 = uint8ArrayToString(publicKeyToProtobuf(publicKey), 'base64url');
100
-
101
- return {
102
- peerId,
103
- publicKeyB64,
104
- async sign(message: string): Promise<string> {
105
- const signature = await privateKey.sign(new TextEncoder().encode(message));
106
- return uint8ArrayToString(signature, 'base64url');
107
- }
108
- };
109
- }