@serfab/cadre-core 1.10.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.
- package/dist/cadre-node.d.ts +0 -27
- package/dist/cadre-node.js +2 -94
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-schema.js +1066 -1066
- package/dist/diagnostics/connection-path.d.ts +1 -18
- package/dist/diagnostics/connection-path.js +1 -20
- package/dist/diagnostics/connection-path.js.map +1 -1
- package/dist/identity-key.d.ts +0 -30
- package/dist/identity-key.js +7 -40
- package/dist/identity-key.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/relay-stun.d.ts +24 -0
- package/dist/relay-stun.js +51 -0
- package/dist/relay-stun.js.map +1 -0
- package/dist/seed-bootstrap.js +4 -4
- package/dist/strand-membership-writer.js +32 -32
- package/package.json +2 -2
- package/src/cadre-node.ts +8654 -8753
- package/src/control-authorization.ts +117 -117
- package/src/control-cohort.ts +128 -128
- package/src/control-formation-recorder.ts +353 -353
- package/src/control-read-retry.ts +216 -216
- package/src/control-schema.ts +1078 -1078
- package/src/control-write-retry.ts +567 -567
- package/src/diagnostics/connection-path.ts +1 -29
- package/src/formation-approval.ts +610 -610
- package/src/hibernation-manager.ts +638 -638
- package/src/identity-key.ts +7 -62
- package/src/index.ts +644 -647
- package/src/invitation-bootstrap.ts +40 -40
- package/src/joined-strand-store.ts +498 -498
- package/src/link-budget.ts +684 -684
- package/src/membership-connection-gater.ts +570 -570
- package/src/node-local-snapshot.ts +298 -298
- package/src/peer-dial.ts +315 -315
- package/src/peer-join-backfill.ts +710 -710
- package/src/pending-join-runner.ts +735 -735
- package/src/relay-reservation.ts +1121 -1121
- package/src/relay-server.ts +98 -98
- package/src/relay-stun.ts +58 -0
- package/src/seed-bootstrap.ts +1448 -1448
- package/src/strand-addr-protocol.ts +547 -547
- package/src/strand-database.ts +287 -287
- package/src/strand-first-sync-gate.ts +391 -391
- package/src/strand-formation-deadlines.ts +227 -227
- package/src/strand-formation-manager.ts +725 -725
- package/src/strand-fret-addrs.ts +145 -145
- package/src/strand-instance-manager.ts +1789 -1789
- package/src/strand-membership-writer.ts +1974 -1974
- package/src/strand-network-state-file.ts +40 -40
- package/src/strand-network-state.ts +243 -243
- package/src/strand-revocation-enforcer.ts +654 -654
- package/src/strand-solicitation.ts +532 -532
- package/src/strand-wake-protocol.ts +401 -401
- package/src/types.ts +2222 -2222
- package/dist/diagnostics/webrtc-turn-tracker.d.ts +0 -50
- package/dist/diagnostics/webrtc-turn-tracker.js +0 -196
- package/dist/diagnostics/webrtc-turn-tracker.js.map +0 -1
- package/src/diagnostics/webrtc-turn-tracker.ts +0 -222
package/src/identity-key.ts
CHANGED
|
@@ -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
|
-
*
|
|
13
|
-
*
|
|
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
|
|
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
|
-
}
|