@peerbit/shared-log 13.2.32 → 13.2.34
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/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +613 -123
- package/dist/src/index.js.map +1 -1
- package/dist/src/replication-info-v2-binding.d.ts +16 -0
- package/dist/src/replication-info-v2-binding.d.ts.map +1 -0
- package/dist/src/replication-info-v2-binding.js +30 -0
- package/dist/src/replication-info-v2-binding.js.map +1 -0
- package/dist/src/replication-info-v2-receive.d.ts +250 -0
- package/dist/src/replication-info-v2-receive.d.ts.map +1 -0
- package/dist/src/replication-info-v2-receive.js +1089 -0
- package/dist/src/replication-info-v2-receive.js.map +1 -0
- package/dist/src/replication-info-v2-send.d.ts +25 -17
- package/dist/src/replication-info-v2-send.d.ts.map +1 -1
- package/dist/src/replication-info-v2-send.js +170 -86
- package/dist/src/replication-info-v2-send.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +897 -260
- package/src/replication-info-v2-binding.ts +44 -0
- package/src/replication-info-v2-receive.ts +1577 -0
- package/src/replication-info-v2-send.ts +223 -109
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { serialize } from "@dao-xyz/borsh";
|
|
2
|
+
import { type PublicSignKey, sha256Sync } from "@peerbit/crypto";
|
|
3
|
+
import { concat, fromString } from "uint8arrays";
|
|
4
|
+
|
|
5
|
+
const RECEIVER_BINDING_DOMAIN = fromString(
|
|
6
|
+
"peerbit/shared-log/replication-info-v2/receiver-binding/v1",
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
const lengthPrefixed = (bytes: Uint8Array): Uint8Array => {
|
|
10
|
+
const length = new Uint8Array(4);
|
|
11
|
+
new DataView(length.buffer).setUint32(0, bytes.byteLength, true);
|
|
12
|
+
return concat([length, bytes]);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const u64LittleEndian = (value: bigint): Uint8Array => {
|
|
16
|
+
const bytes = new Uint8Array(8);
|
|
17
|
+
new DataView(bytes.buffer).setBigUint64(0, value, true);
|
|
18
|
+
return bytes;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Derive the token echoed by V2 data frames. Delivery recipients are unsigned,
|
|
23
|
+
* so the receiver's nonce alone is not a destination binding. Folding both
|
|
24
|
+
* authenticated identities and signed transport sessions into the 32-byte
|
|
25
|
+
* field prevents a copied request nonce from creating an interchangeable
|
|
26
|
+
* stream for another receiver.
|
|
27
|
+
*/
|
|
28
|
+
export const deriveReplicationInfoV2ReceiverBinding = (properties: {
|
|
29
|
+
receiverChallenge: Uint8Array;
|
|
30
|
+
receiver: PublicSignKey;
|
|
31
|
+
receiverTransportSession: bigint;
|
|
32
|
+
sender: PublicSignKey;
|
|
33
|
+
senderTransportSession: bigint;
|
|
34
|
+
}): Uint8Array =>
|
|
35
|
+
sha256Sync(
|
|
36
|
+
concat([
|
|
37
|
+
lengthPrefixed(RECEIVER_BINDING_DOMAIN),
|
|
38
|
+
lengthPrefixed(properties.receiverChallenge),
|
|
39
|
+
lengthPrefixed(serialize(properties.receiver)),
|
|
40
|
+
u64LittleEndian(properties.receiverTransportSession),
|
|
41
|
+
lengthPrefixed(serialize(properties.sender)),
|
|
42
|
+
u64LittleEndian(properties.senderTransportSession),
|
|
43
|
+
]),
|
|
44
|
+
);
|