@okee-e2ee/protocol 0.1.2 → 0.1.4
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/crypto-core/model/brand.d.ts +4 -0
- package/dist/crypto-core/model/brand.d.ts.map +1 -1
- package/dist/crypto-core/signature/codecs/HybridSignatureCodec.d.ts +10 -0
- package/dist/crypto-core/signature/codecs/HybridSignatureCodec.d.ts.map +1 -0
- package/dist/crypto-core/signature/codecs/HybridSignatureCodec.js +27 -0
- package/dist/crypto-core/signature/codecs/HybridSignaturePublicKeyCodec.d.ts +10 -0
- package/dist/crypto-core/signature/codecs/HybridSignaturePublicKeyCodec.d.ts.map +1 -0
- package/dist/{transport/codecs/RelayIdentityPublicKeyCodec.js → crypto-core/signature/codecs/HybridSignaturePublicKeyCodec.js} +3 -3
- package/dist/crypto-core/signature/codecs/index.d.ts +3 -0
- package/dist/crypto-core/signature/codecs/index.d.ts.map +1 -0
- package/dist/crypto-core/signature/codecs/index.js +2 -0
- package/dist/crypto-core/signature/index.d.ts +1 -0
- package/dist/crypto-core/signature/index.d.ts.map +1 -1
- package/dist/crypto-core/signature/index.js +1 -0
- package/dist/transport/codecs/DestinationSendRequestCodec.d.ts +10 -0
- package/dist/transport/codecs/DestinationSendRequestCodec.d.ts.map +1 -0
- package/dist/transport/codecs/DestinationSendRequestCodec.js +34 -0
- package/dist/transport/codecs/DestinationSendResponseCodec.d.ts +10 -0
- package/dist/transport/codecs/DestinationSendResponseCodec.d.ts.map +1 -0
- package/dist/transport/codecs/DestinationSendResponseCodec.js +65 -0
- package/dist/transport/codecs/TransportPacketCodec.d.ts +15 -0
- package/dist/transport/codecs/TransportPacketCodec.d.ts.map +1 -0
- package/dist/transport/codecs/TransportPacketCodec.js +214 -0
- package/dist/transport/codecs/encode-destination-send-authorization-input.d.ts +4 -0
- package/dist/transport/codecs/encode-destination-send-authorization-input.d.ts.map +1 -0
- package/dist/transport/codecs/encode-destination-send-authorization-input.js +6 -0
- package/dist/transport/codecs/encode-relay-key-bundle-signature-input.d.ts.map +1 -0
- package/dist/transport/{helpers → codecs}/encode-relay-key-bundle-signature-input.js +1 -1
- package/dist/transport/codecs/encode-s2d-associated-data.d.ts +5 -0
- package/dist/transport/codecs/encode-s2d-associated-data.d.ts.map +1 -0
- package/dist/transport/codecs/encode-s2d-associated-data.js +19 -0
- package/dist/transport/codecs/encode-transport-request-authorization-input.d.ts +4 -0
- package/dist/transport/codecs/encode-transport-request-authorization-input.d.ts.map +1 -0
- package/dist/transport/codecs/encode-transport-request-authorization-input.js +35 -0
- package/dist/transport/codecs/index.d.ts +7 -2
- package/dist/transport/codecs/index.d.ts.map +1 -1
- package/dist/transport/codecs/index.js +7 -2
- package/dist/transport/codecs/internal/InternalCodec.d.ts +7 -0
- package/dist/transport/codecs/internal/InternalCodec.d.ts.map +1 -0
- package/dist/transport/codecs/internal/InternalCodec.js +16 -0
- package/dist/transport/codecs/{RelayEncryptionKeyBundleCodec.d.ts → internal/RelayEncryptionKeyBundleCodec.d.ts} +2 -3
- package/dist/transport/codecs/internal/RelayEncryptionKeyBundleCodec.d.ts.map +1 -0
- package/dist/transport/codecs/{RelayEncryptionKeyBundleCodec.js → internal/RelayEncryptionKeyBundleCodec.js} +4 -5
- package/dist/transport/codecs/internal/S2DEncryptedRequestCodec.d.ts +9 -0
- package/dist/transport/codecs/internal/S2DEncryptedRequestCodec.d.ts.map +1 -0
- package/dist/transport/codecs/internal/S2DEncryptedRequestCodec.js +45 -0
- package/dist/transport/codecs/internal/S2DEncryptedResponseCodec.d.ts +9 -0
- package/dist/transport/codecs/internal/S2DEncryptedResponseCodec.d.ts.map +1 -0
- package/dist/transport/codecs/internal/S2DEncryptedResponseCodec.js +38 -0
- package/dist/transport/codecs/internal/SignedRelayEncryptionKeyBundleCodec.d.ts +9 -0
- package/dist/transport/codecs/internal/SignedRelayEncryptionKeyBundleCodec.d.ts.map +1 -0
- package/dist/transport/codecs/internal/SignedRelayEncryptionKeyBundleCodec.js +35 -0
- package/dist/transport/codecs/internal/destination-send-codec-helpers.d.ts +5 -0
- package/dist/transport/codecs/internal/destination-send-codec-helpers.d.ts.map +1 -0
- package/dist/transport/codecs/internal/destination-send-codec-helpers.js +58 -0
- package/dist/transport/codecs/internal/transport-payload-codecs.d.ts +7 -0
- package/dist/transport/codecs/internal/transport-payload-codecs.d.ts.map +1 -0
- package/dist/transport/codecs/internal/transport-payload-codecs.js +128 -0
- package/dist/transport/constants/index.d.ts +1 -0
- package/dist/transport/constants/index.d.ts.map +1 -1
- package/dist/transport/constants/index.js +1 -0
- package/dist/transport/constants/relay-constants.d.ts +5 -0
- package/dist/transport/constants/relay-constants.d.ts.map +1 -1
- package/dist/transport/constants/relay-constants.js +5 -0
- package/dist/transport/constants/transport-packet-constants.d.ts +5 -0
- package/dist/transport/constants/transport-packet-constants.d.ts.map +1 -0
- package/dist/transport/constants/transport-packet-constants.js +4 -0
- package/dist/transport/helpers/derive-relay-identity-fingerprint.d.ts.map +1 -1
- package/dist/transport/helpers/derive-relay-identity-fingerprint.js +2 -3
- package/dist/transport/helpers/derive-s2d-key-material.d.ts +4 -0
- package/dist/transport/helpers/derive-s2d-key-material.d.ts.map +1 -0
- package/dist/transport/helpers/derive-s2d-key-material.js +25 -0
- package/dist/transport/helpers/index.d.ts +1 -1
- package/dist/transport/helpers/index.d.ts.map +1 -1
- package/dist/transport/helpers/index.js +1 -1
- package/dist/transport/model/destination-send.d.ts +44 -0
- package/dist/transport/model/destination-send.d.ts.map +1 -0
- package/dist/transport/model/destination-send.js +14 -0
- package/dist/transport/model/index.d.ts +4 -0
- package/dist/transport/model/index.d.ts.map +1 -1
- package/dist/transport/model/index.js +4 -0
- package/dist/transport/model/queue-model.d.ts +11 -4
- package/dist/transport/model/queue-model.d.ts.map +1 -1
- package/dist/transport/model/relay-key-bundle.d.ts +2 -2
- package/dist/transport/model/relay-key-bundle.d.ts.map +1 -1
- package/dist/transport/model/s2d-envelope.d.ts +28 -0
- package/dist/transport/model/s2d-envelope.d.ts.map +1 -0
- package/dist/transport/model/s2d-envelope.js +1 -0
- package/dist/transport/model/transport-command.d.ts +94 -0
- package/dist/transport/model/transport-command.d.ts.map +1 -0
- package/dist/transport/model/transport-command.js +19 -0
- package/dist/transport/model/transport-packet.d.ts +73 -0
- package/dist/transport/model/transport-packet.d.ts.map +1 -0
- package/dist/transport/model/transport-packet.js +11 -0
- package/package.json +1 -1
- package/dist/transport/codecs/RelayEncryptionKeyBundleCodec.d.ts.map +0 -1
- package/dist/transport/codecs/RelayIdentityPublicKeyCodec.d.ts +0 -10
- package/dist/transport/codecs/RelayIdentityPublicKeyCodec.d.ts.map +0 -1
- package/dist/transport/helpers/encode-relay-key-bundle-signature-input.d.ts.map +0 -1
- /package/dist/transport/{helpers → codecs}/encode-relay-key-bundle-signature-input.d.ts +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ByteReader, ByteWriter } from "../../../crypto-core";
|
|
2
|
+
export function createInternalCodec(write, read) {
|
|
3
|
+
return {
|
|
4
|
+
encode(value) {
|
|
5
|
+
const writer = new ByteWriter();
|
|
6
|
+
write(writer, value);
|
|
7
|
+
return writer.toBytes();
|
|
8
|
+
},
|
|
9
|
+
decode(bytes) {
|
|
10
|
+
const reader = new ByteReader(bytes);
|
|
11
|
+
const value = read(reader);
|
|
12
|
+
reader.assertEnd();
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Result } from "@okee-e2ee/core";
|
|
2
2
|
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
3
|
-
import { CodecContract } from "
|
|
4
|
-
import {
|
|
5
|
-
import { RelayEncryptionKeyBundle } from "../model";
|
|
3
|
+
import { type Bytes, CodecContract } from "../../../crypto-core";
|
|
4
|
+
import { RelayEncryptionKeyBundle } from "../../model";
|
|
6
5
|
export declare class RelayEncryptionKeyBundleCodec implements CodecContract<RelayEncryptionKeyBundle> {
|
|
7
6
|
encode(value: RelayEncryptionKeyBundle): Bytes;
|
|
8
7
|
decode(bytes: Bytes): Result<RelayEncryptionKeyBundle, DecodeError>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelayEncryptionKeyBundleCodec.d.ts","sourceRoot":"","sources":["../../../../src/transport/codecs/internal/RelayEncryptionKeyBundleCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAEN,KAAK,KAAK,EAEV,aAAa,EAGb,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,wBAAwB,EAA2B,MAAM,aAAa,CAAC;AAEhF,qBAAa,6BAA8B,YAAW,aAAa,CAAC,wBAAwB,CAAC;IACrF,MAAM,CAAC,KAAK,EAAE,wBAAwB,GAAG,KAAK,CAYpD;IAEM,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,wBAAwB,EAAE,WAAW,CAAC,CAyBzE;CACD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
2
|
-
import { CRYPTO_SIZES_BYTES } from "
|
|
3
|
-
import {
|
|
4
|
-
import { RELAY_KEY_BUNDLE_FORMAT_VERSION } from "../constants";
|
|
2
|
+
import { ByteReader, ByteWriter, CRYPTO_SIZES_BYTES } from "../../../crypto-core";
|
|
3
|
+
import { RELAY_KEY_BUNDLE_FORMAT_VERSION } from "../../constants";
|
|
5
4
|
export class RelayEncryptionKeyBundleCodec {
|
|
6
5
|
encode(value) {
|
|
7
6
|
if (value.formatVersion !== RELAY_KEY_BUNDLE_FORMAT_VERSION) {
|
|
@@ -9,7 +8,7 @@ export class RelayEncryptionKeyBundleCodec {
|
|
|
9
8
|
}
|
|
10
9
|
return new ByteWriter()
|
|
11
10
|
.writeU8(value.formatVersion)
|
|
12
|
-
.writeU64(value.
|
|
11
|
+
.writeU64(value.epoch)
|
|
13
12
|
.writeFixedBytes(value.publicKey, CRYPTO_SIZES_BYTES.xWingPublicKey)
|
|
14
13
|
.writeU64(value.validFrom)
|
|
15
14
|
.writeU64(value.expiresAt)
|
|
@@ -25,7 +24,7 @@ export class RelayEncryptionKeyBundleCodec {
|
|
|
25
24
|
}
|
|
26
25
|
const value = {
|
|
27
26
|
formatVersion,
|
|
28
|
-
|
|
27
|
+
epoch: reader.readU64(),
|
|
29
28
|
publicKey: reader.readFixedBytes(CRYPTO_SIZES_BYTES.xWingPublicKey),
|
|
30
29
|
validFrom: reader.readU64(),
|
|
31
30
|
expiresAt: reader.readU64()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Result } from "@okee-e2ee/core";
|
|
2
|
+
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
3
|
+
import { type Bytes, CodecContract } from "../../../crypto-core";
|
|
4
|
+
import { S2DEncryptedRequest } from "../../model";
|
|
5
|
+
export declare class S2DEncryptedRequestCodec<T> implements CodecContract<S2DEncryptedRequest<T>> {
|
|
6
|
+
encode(value: S2DEncryptedRequest<T>): Bytes;
|
|
7
|
+
decode(bytes: Bytes): Result<S2DEncryptedRequest<T>, DecodeError>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=S2DEncryptedRequestCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"S2DEncryptedRequestCodec.d.ts","sourceRoot":"","sources":["../../../../src/transport/codecs/internal/S2DEncryptedRequestCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAEN,KAAK,KAAK,EAEV,aAAa,EAIb,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAA2B,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE3E,qBAAa,wBAAwB,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IACjF,MAAM,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,KAAK,CAclD;IAEM,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CA8BvE;CACD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
2
|
+
import { ByteReader, ByteWriter, CRYPTO_SIZES_BYTES } from "../../../crypto-core";
|
|
3
|
+
import { S2D_ENVELOPE_FORMAT_VERSION } from "../../constants";
|
|
4
|
+
export class S2DEncryptedRequestCodec {
|
|
5
|
+
encode(value) {
|
|
6
|
+
if (value.formatVersion !== S2D_ENVELOPE_FORMAT_VERSION) {
|
|
7
|
+
throw new RangeError(`formatVersion must be ${S2D_ENVELOPE_FORMAT_VERSION}`);
|
|
8
|
+
}
|
|
9
|
+
if (value.ciphertext.byteLength < CRYPTO_SIZES_BYTES.aeadTag) {
|
|
10
|
+
throw new RangeError("ciphertext must include an AEAD authentication tag");
|
|
11
|
+
}
|
|
12
|
+
return new ByteWriter()
|
|
13
|
+
.writeU8(value.formatVersion)
|
|
14
|
+
.writeU64(value.epoch)
|
|
15
|
+
.writeFixedBytes(value.encapsulation, CRYPTO_SIZES_BYTES.xWingCiphertext)
|
|
16
|
+
.writeBytes(value.ciphertext)
|
|
17
|
+
.toBytes();
|
|
18
|
+
}
|
|
19
|
+
decode(bytes) {
|
|
20
|
+
const reader = new ByteReader(bytes);
|
|
21
|
+
try {
|
|
22
|
+
const versionOffset = reader.offset;
|
|
23
|
+
const formatVersion = reader.readU8();
|
|
24
|
+
if (formatVersion !== S2D_ENVELOPE_FORMAT_VERSION) {
|
|
25
|
+
throw new DecodeError(`unsupported formatVersion ${formatVersion}`, versionOffset);
|
|
26
|
+
}
|
|
27
|
+
const value = {
|
|
28
|
+
formatVersion,
|
|
29
|
+
epoch: reader.readU64(),
|
|
30
|
+
encapsulation: reader.readFixedBytes(CRYPTO_SIZES_BYTES.xWingCiphertext),
|
|
31
|
+
ciphertext: reader.readBytes()
|
|
32
|
+
};
|
|
33
|
+
if (value.ciphertext.byteLength < CRYPTO_SIZES_BYTES.aeadTag) {
|
|
34
|
+
throw new DecodeError("ciphertext must include an AEAD authentication tag", reader.offset - value.ciphertext.byteLength);
|
|
35
|
+
}
|
|
36
|
+
reader.assertEnd();
|
|
37
|
+
return { ok: true, value };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof DecodeError)
|
|
41
|
+
return { ok: false, error };
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Result } from "@okee-e2ee/core";
|
|
2
|
+
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
3
|
+
import { type Bytes, CodecContract } from "../../../crypto-core";
|
|
4
|
+
import { S2DEncryptedResponse } from "../../model";
|
|
5
|
+
export declare class S2DEncryptedResponseCodec<T> implements CodecContract<S2DEncryptedResponse<T>> {
|
|
6
|
+
encode(value: S2DEncryptedResponse<T>): Bytes;
|
|
7
|
+
decode(bytes: Bytes): Result<S2DEncryptedResponse<T>, DecodeError>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=S2DEncryptedResponseCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"S2DEncryptedResponseCodec.d.ts","sourceRoot":"","sources":["../../../../src/transport/codecs/internal/S2DEncryptedResponseCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAEN,KAAK,KAAK,EAEV,aAAa,EAGb,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,qBAAa,yBAAyB,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACnF,MAAM,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,KAAK,CASnD;IAEM,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CA0BxE;CACD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
2
|
+
import { ByteReader, ByteWriter, CRYPTO_SIZES_BYTES } from "../../../crypto-core";
|
|
3
|
+
import { S2D_ENVELOPE_FORMAT_VERSION } from "../../constants";
|
|
4
|
+
export class S2DEncryptedResponseCodec {
|
|
5
|
+
encode(value) {
|
|
6
|
+
if (value.formatVersion !== S2D_ENVELOPE_FORMAT_VERSION) {
|
|
7
|
+
throw new RangeError(`formatVersion must be ${S2D_ENVELOPE_FORMAT_VERSION}`);
|
|
8
|
+
}
|
|
9
|
+
if (value.ciphertext.byteLength < CRYPTO_SIZES_BYTES.aeadTag) {
|
|
10
|
+
throw new RangeError("ciphertext must include an AEAD authentication tag");
|
|
11
|
+
}
|
|
12
|
+
return new ByteWriter().writeU8(value.formatVersion).writeBytes(value.ciphertext).toBytes();
|
|
13
|
+
}
|
|
14
|
+
decode(bytes) {
|
|
15
|
+
const reader = new ByteReader(bytes);
|
|
16
|
+
try {
|
|
17
|
+
const versionOffset = reader.offset;
|
|
18
|
+
const formatVersion = reader.readU8();
|
|
19
|
+
if (formatVersion !== S2D_ENVELOPE_FORMAT_VERSION) {
|
|
20
|
+
throw new DecodeError(`unsupported formatVersion ${formatVersion}`, versionOffset);
|
|
21
|
+
}
|
|
22
|
+
const value = {
|
|
23
|
+
formatVersion,
|
|
24
|
+
ciphertext: reader.readBytes()
|
|
25
|
+
};
|
|
26
|
+
if (value.ciphertext.byteLength < CRYPTO_SIZES_BYTES.aeadTag) {
|
|
27
|
+
throw new DecodeError("ciphertext must include an AEAD authentication tag", reader.offset - value.ciphertext.byteLength);
|
|
28
|
+
}
|
|
29
|
+
reader.assertEnd();
|
|
30
|
+
return { ok: true, value };
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error instanceof DecodeError)
|
|
34
|
+
return { ok: false, error };
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Result } from "@okee-e2ee/core";
|
|
2
|
+
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
3
|
+
import { type Bytes, CodecContract } from "../../../crypto-core";
|
|
4
|
+
import { SignedRelayEncryptionKeyBundle } from "../../model";
|
|
5
|
+
export declare class SignedRelayEncryptionKeyBundleCodec implements CodecContract<SignedRelayEncryptionKeyBundle> {
|
|
6
|
+
encode(value: SignedRelayEncryptionKeyBundle): Bytes;
|
|
7
|
+
decode(bytes: Bytes): Result<SignedRelayEncryptionKeyBundle, DecodeError>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=SignedRelayEncryptionKeyBundleCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignedRelayEncryptionKeyBundleCodec.d.ts","sourceRoot":"","sources":["../../../../src/transport/codecs/internal/SignedRelayEncryptionKeyBundleCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAEN,KAAK,KAAK,EAEV,aAAa,EAGb,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAS7D,qBAAa,mCAAoC,YAAW,aAAa,CAAC,8BAA8B,CAAC;IACjG,MAAM,CAAC,KAAK,EAAE,8BAA8B,GAAG,KAAK,CAK1D;IAEM,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,8BAA8B,EAAE,WAAW,CAAC,CAqB/E;CACD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DecodeError } from "@okee-e2ee/core/errors";
|
|
2
|
+
import { ByteReader, ByteWriter, CRYPTO_SIZES_BYTES, HybridSignatureCodec } from "../../../crypto-core";
|
|
3
|
+
import { RelayEncryptionKeyBundleCodec } from "./RelayEncryptionKeyBundleCodec";
|
|
4
|
+
const bundleCodec = new RelayEncryptionKeyBundleCodec();
|
|
5
|
+
const signatureCodec = new HybridSignatureCodec();
|
|
6
|
+
const HYBRID_SIGNATURE_SIZE_BYTES = CRYPTO_SIZES_BYTES.ed25519Signature + CRYPTO_SIZES_BYTES.mlDsaSignature;
|
|
7
|
+
export class SignedRelayEncryptionKeyBundleCodec {
|
|
8
|
+
encode(value) {
|
|
9
|
+
return new ByteWriter()
|
|
10
|
+
.writeBytes(bundleCodec.encode(value))
|
|
11
|
+
.writeFixedBytes(signatureCodec.encode(value.signature), HYBRID_SIGNATURE_SIZE_BYTES)
|
|
12
|
+
.toBytes();
|
|
13
|
+
}
|
|
14
|
+
decode(bytes) {
|
|
15
|
+
const reader = new ByteReader(bytes);
|
|
16
|
+
try {
|
|
17
|
+
const bundleResult = bundleCodec.decode(reader.readBytes());
|
|
18
|
+
if (!bundleResult.ok)
|
|
19
|
+
throw bundleResult.error;
|
|
20
|
+
const signatureResult = signatureCodec.decode(reader.readFixedBytes(HYBRID_SIGNATURE_SIZE_BYTES));
|
|
21
|
+
if (!signatureResult.ok)
|
|
22
|
+
throw signatureResult.error;
|
|
23
|
+
reader.assertEnd();
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
value: { ...bundleResult.value, signature: signatureResult.value }
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof DecodeError)
|
|
31
|
+
return { ok: false, error };
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ByteReader } from "../../../crypto-core";
|
|
2
|
+
import { DestinationSendRequestPayload } from "../../model";
|
|
3
|
+
export declare function encodeDestinationSendRequestPayload(payload: DestinationSendRequestPayload): import("../../../crypto-core").Bytes;
|
|
4
|
+
export declare function decodeDestinationSendRequestPayload(reader: ByteReader): DestinationSendRequestPayload;
|
|
5
|
+
//# sourceMappingURL=destination-send-codec-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-send-codec-helpers.d.ts","sourceRoot":"","sources":["../../../../src/transport/codecs/internal/destination-send-codec-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EACN,UAAU,EAIV,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAEN,6BAA6B,EAI7B,MAAM,aAAa,CAAC;AAMrB,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,6BAA6B,mDA4BzF;AAED,wBAAgB,mCAAmC,CAClD,MAAM,EAAE,UAAU,GAChB,6BAA6B,CAqC/B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DecodeError } from "@okee-e2ee/core";
|
|
2
|
+
import { ByteWriter, CRYPTO_SIZES_BYTES, HybridSignaturePublicKeyCodec } from "../../../crypto-core";
|
|
3
|
+
import { DESTINATION_SEND_FORMAT_VERSION, QUEUE_SETUP_CAPABILITY_SIZE_BYTES } from "../../constants";
|
|
4
|
+
const hybridPublicKeyCodec = new HybridSignaturePublicKeyCodec();
|
|
5
|
+
const HYBRID_PUBLIC_KEY_SIZE_BYTES = CRYPTO_SIZES_BYTES.ed25519PublicKey + CRYPTO_SIZES_BYTES.mlDsaPublicKey;
|
|
6
|
+
export function encodeDestinationSendRequestPayload(payload) {
|
|
7
|
+
if (payload.formatVersion !== DESTINATION_SEND_FORMAT_VERSION) {
|
|
8
|
+
throw new RangeError(`formatVersion must be ${DESTINATION_SEND_FORMAT_VERSION}`);
|
|
9
|
+
}
|
|
10
|
+
const writer = new ByteWriter()
|
|
11
|
+
.writeU8(payload.formatVersion)
|
|
12
|
+
.writeString(payload.senderQueueId)
|
|
13
|
+
.writeString(payload.deliveryId)
|
|
14
|
+
.writeBytes(payload.payload);
|
|
15
|
+
const hasSetupCapability = payload.setupCapability !== undefined;
|
|
16
|
+
const hasSenderAuthPublicKey = payload.senderAuthPublicKey !== undefined;
|
|
17
|
+
if (hasSetupCapability !== hasSenderAuthPublicKey) {
|
|
18
|
+
throw new RangeError("setupCapability and senderAuthPublicKey must be provided together");
|
|
19
|
+
}
|
|
20
|
+
if (!hasSetupCapability) {
|
|
21
|
+
return writer.writeU8(0).toBytes();
|
|
22
|
+
}
|
|
23
|
+
return writer
|
|
24
|
+
.writeU8(1)
|
|
25
|
+
.writeFixedBytes(payload.setupCapability, QUEUE_SETUP_CAPABILITY_SIZE_BYTES)
|
|
26
|
+
.writeFixedBytes(hybridPublicKeyCodec.encode(payload.senderAuthPublicKey), HYBRID_PUBLIC_KEY_SIZE_BYTES)
|
|
27
|
+
.toBytes();
|
|
28
|
+
}
|
|
29
|
+
export function decodeDestinationSendRequestPayload(reader) {
|
|
30
|
+
const versionOffset = reader.offset;
|
|
31
|
+
const formatVersion = reader.readU8();
|
|
32
|
+
if (formatVersion !== DESTINATION_SEND_FORMAT_VERSION) {
|
|
33
|
+
throw new DecodeError(`unsupported formatVersion ${formatVersion}`, versionOffset);
|
|
34
|
+
}
|
|
35
|
+
const senderQueueId = reader.readString();
|
|
36
|
+
const deliveryId = reader.readString();
|
|
37
|
+
const payload = reader.readBytes();
|
|
38
|
+
const setupTagOffset = reader.offset;
|
|
39
|
+
const setupTag = reader.readU8();
|
|
40
|
+
if (setupTag === 0) {
|
|
41
|
+
return { formatVersion, senderQueueId, deliveryId, payload };
|
|
42
|
+
}
|
|
43
|
+
if (setupTag !== 1) {
|
|
44
|
+
throw new DecodeError("setup tag must be 0 or 1", setupTagOffset);
|
|
45
|
+
}
|
|
46
|
+
const setupCapability = reader.readFixedBytes(QUEUE_SETUP_CAPABILITY_SIZE_BYTES);
|
|
47
|
+
const publicKeyResult = hybridPublicKeyCodec.decode(reader.readFixedBytes(HYBRID_PUBLIC_KEY_SIZE_BYTES));
|
|
48
|
+
if (!publicKeyResult.ok)
|
|
49
|
+
throw publicKeyResult.error;
|
|
50
|
+
return {
|
|
51
|
+
formatVersion,
|
|
52
|
+
senderQueueId,
|
|
53
|
+
deliveryId,
|
|
54
|
+
payload,
|
|
55
|
+
setupCapability,
|
|
56
|
+
senderAuthPublicKey: publicKeyResult.value
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Bytes } from "../../../crypto-core";
|
|
2
|
+
import { TransportCommandType, type TransportRequestPayloadMap, type TransportResponsePayloadMap } from "../../model";
|
|
3
|
+
export declare function encodeTransportRequestPayload<C extends TransportCommandType>(command: C, payload: TransportRequestPayloadMap[C]): Bytes;
|
|
4
|
+
export declare function decodeTransportRequestPayload<C extends TransportCommandType>(command: C, bytes: Bytes): TransportRequestPayloadMap[C];
|
|
5
|
+
export declare function encodeTransportResponsePayload<C extends TransportCommandType>(command: C, payload: TransportResponsePayloadMap[C]): Bytes;
|
|
6
|
+
export declare function decodeTransportResponsePayload<C extends TransportCommandType>(command: C, bytes: Bytes): TransportResponsePayloadMap[C];
|
|
7
|
+
//# sourceMappingURL=transport-payload-codecs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-payload-codecs.d.ts","sourceRoot":"","sources":["../../../../src/transport/codecs/internal/transport-payload-codecs.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,KAAK,EAMV,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAuBN,oBAAoB,EACpB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAGhC,MAAM,aAAa,CAAC;AAoJrB,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,oBAAoB,EAC3E,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACpC,KAAK,CAEP;AAED,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,oBAAoB,EAC3E,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,KAAK,GACV,0BAA0B,CAAC,CAAC,CAAC,CAE/B;AAED,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,oBAAoB,EAC5E,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,2BAA2B,CAAC,CAAC,CAAC,GACrC,KAAK,CAEP;AAED,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,oBAAoB,EAC5E,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,KAAK,GACV,2BAA2B,CAAC,CAAC,CAAC,CAEhC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { CRYPTO_SIZES_BYTES, HybridSignaturePublicKeyCodec } from "../../../crypto-core";
|
|
2
|
+
import { TransportCommandType } from "../../model";
|
|
3
|
+
import { createInternalCodec } from "./InternalCodec";
|
|
4
|
+
import { S2DEncryptedRequestCodec } from "./S2DEncryptedRequestCodec";
|
|
5
|
+
import { S2DEncryptedResponseCodec } from "./S2DEncryptedResponseCodec";
|
|
6
|
+
import { SignedRelayEncryptionKeyBundleCodec } from "./SignedRelayEncryptionKeyBundleCodec";
|
|
7
|
+
const hybridPublicKeyCodec = new HybridSignaturePublicKeyCodec();
|
|
8
|
+
const signedRelayBundleCodec = new SignedRelayEncryptionKeyBundleCodec();
|
|
9
|
+
const s2dRequestCodec = new S2DEncryptedRequestCodec();
|
|
10
|
+
const s2dResponseCodec = new S2DEncryptedResponseCodec();
|
|
11
|
+
const HYBRID_PUBLIC_KEY_SIZE_BYTES = CRYPTO_SIZES_BYTES.ed25519PublicKey + CRYPTO_SIZES_BYTES.mlDsaPublicKey;
|
|
12
|
+
const emptyPayloadCodec = createInternalCodec((_writer, value) => {
|
|
13
|
+
if (value !== undefined)
|
|
14
|
+
throw new RangeError("payload must be undefined");
|
|
15
|
+
}, () => undefined);
|
|
16
|
+
const createQueueRequestCodec = createInternalCodec((writer, value) => writeQueueRegistration(writer, value.registration), reader => ({ registration: readQueueRegistration(reader) }));
|
|
17
|
+
const createQueueResponseCodec = createInternalCodec((writer, value) => {
|
|
18
|
+
writer.writeString(value.recipientQueueId).writeString(value.senderQueueId);
|
|
19
|
+
}, reader => ({
|
|
20
|
+
recipientQueueId: reader.readString(),
|
|
21
|
+
senderQueueId: reader.readString()
|
|
22
|
+
}));
|
|
23
|
+
const recipientQueueRequestCodec = createInternalCodec((writer, value) => {
|
|
24
|
+
writer.writeString(value.recipientQueueId);
|
|
25
|
+
}, reader => ({ recipientQueueId: reader.readString() }));
|
|
26
|
+
const recipientQueueResponseCodec = createInternalCodec((writer, value) => {
|
|
27
|
+
writer.writeString(value.recipientQueueId);
|
|
28
|
+
}, reader => ({ recipientQueueId: reader.readString() }));
|
|
29
|
+
const getDestinationBundleRequestCodec = createInternalCodec((writer, value) => writeRelayAddress(writer, value.destination), reader => ({ destination: readRelayAddress(reader) }));
|
|
30
|
+
const getDestinationBundleResponseCodec = createInternalCodec((writer, value) => {
|
|
31
|
+
writeRelayAddress(writer, value.destination);
|
|
32
|
+
writer
|
|
33
|
+
.writeFixedBytes(hybridPublicKeyCodec.encode(value.identityPublicKey), HYBRID_PUBLIC_KEY_SIZE_BYTES)
|
|
34
|
+
.writeBytes(signedRelayBundleCodec.encode(value.bundle));
|
|
35
|
+
}, reader => ({
|
|
36
|
+
destination: readRelayAddress(reader),
|
|
37
|
+
identityPublicKey: decodeWithCodec(hybridPublicKeyCodec, reader.readFixedBytes(HYBRID_PUBLIC_KEY_SIZE_BYTES)),
|
|
38
|
+
bundle: decodeWithCodec(signedRelayBundleCodec, reader.readBytes())
|
|
39
|
+
}));
|
|
40
|
+
const sendRequestCodec = createInternalCodec((writer, value) => {
|
|
41
|
+
writeRelayAddress(writer, value.destination);
|
|
42
|
+
writer.writeBytes(s2dRequestCodec.encode(value.encryptedRequest));
|
|
43
|
+
}, reader => ({
|
|
44
|
+
destination: readRelayAddress(reader),
|
|
45
|
+
encryptedRequest: decodeWithCodec(s2dRequestCodec, reader.readBytes())
|
|
46
|
+
}));
|
|
47
|
+
const sendResponseCodec = createInternalCodec((writer, value) => {
|
|
48
|
+
writer.writeBytes(s2dResponseCodec.encode(value.encryptedResponse));
|
|
49
|
+
}, reader => ({
|
|
50
|
+
encryptedResponse: decodeWithCodec(s2dResponseCodec, reader.readBytes())
|
|
51
|
+
}));
|
|
52
|
+
const acknowledgeCodec = createInternalCodec((writer, value) => {
|
|
53
|
+
writer.writeString(value.recipientQueueId).writeU32(value.deliveryIds.length);
|
|
54
|
+
for (const deliveryId of value.deliveryIds)
|
|
55
|
+
writer.writeString(deliveryId);
|
|
56
|
+
}, reader => {
|
|
57
|
+
const recipientQueueId = reader.readString();
|
|
58
|
+
const deliveryCount = reader.readU32();
|
|
59
|
+
const deliveryIds = [];
|
|
60
|
+
for (let index = 0; index < deliveryCount; index += 1) {
|
|
61
|
+
deliveryIds.push(reader.readString());
|
|
62
|
+
}
|
|
63
|
+
return { recipientQueueId, deliveryIds };
|
|
64
|
+
});
|
|
65
|
+
const requestPayloadCodecs = {
|
|
66
|
+
[TransportCommandType.HEALTH]: emptyPayloadCodec,
|
|
67
|
+
[TransportCommandType.CREATE_QUEUE]: createQueueRequestCodec,
|
|
68
|
+
[TransportCommandType.REMOVE_QUEUE]: recipientQueueRequestCodec,
|
|
69
|
+
[TransportCommandType.SUBSCRIBE_QUEUE]: recipientQueueRequestCodec,
|
|
70
|
+
[TransportCommandType.UNSUBSCRIBE_QUEUE]: recipientQueueRequestCodec,
|
|
71
|
+
[TransportCommandType.SEND]: sendRequestCodec,
|
|
72
|
+
[TransportCommandType.ACK]: acknowledgeCodec,
|
|
73
|
+
[TransportCommandType.GET_DESTINATION_BUNDLE]: getDestinationBundleRequestCodec
|
|
74
|
+
};
|
|
75
|
+
const responsePayloadCodecs = {
|
|
76
|
+
[TransportCommandType.HEALTH]: emptyPayloadCodec,
|
|
77
|
+
[TransportCommandType.CREATE_QUEUE]: createQueueResponseCodec,
|
|
78
|
+
[TransportCommandType.REMOVE_QUEUE]: recipientQueueResponseCodec,
|
|
79
|
+
[TransportCommandType.SUBSCRIBE_QUEUE]: recipientQueueResponseCodec,
|
|
80
|
+
[TransportCommandType.UNSUBSCRIBE_QUEUE]: recipientQueueResponseCodec,
|
|
81
|
+
[TransportCommandType.SEND]: sendResponseCodec,
|
|
82
|
+
[TransportCommandType.ACK]: acknowledgeCodec,
|
|
83
|
+
[TransportCommandType.GET_DESTINATION_BUNDLE]: getDestinationBundleResponseCodec
|
|
84
|
+
};
|
|
85
|
+
export function encodeTransportRequestPayload(command, payload) {
|
|
86
|
+
return requestPayloadCodecs[command].encode(payload);
|
|
87
|
+
}
|
|
88
|
+
export function decodeTransportRequestPayload(command, bytes) {
|
|
89
|
+
return requestPayloadCodecs[command].decode(bytes);
|
|
90
|
+
}
|
|
91
|
+
export function encodeTransportResponsePayload(command, payload) {
|
|
92
|
+
return responsePayloadCodecs[command].encode(payload);
|
|
93
|
+
}
|
|
94
|
+
export function decodeTransportResponsePayload(command, bytes) {
|
|
95
|
+
return responsePayloadCodecs[command].decode(bytes);
|
|
96
|
+
}
|
|
97
|
+
function writeRelayAddress(writer, value) {
|
|
98
|
+
writer.writeString(value.address).writeFixedBytes(value.fingerprint, CRYPTO_SIZES_BYTES.sha256);
|
|
99
|
+
}
|
|
100
|
+
function readRelayAddress(reader) {
|
|
101
|
+
return {
|
|
102
|
+
address: reader.readString(),
|
|
103
|
+
fingerprint: reader.readFixedBytes(CRYPTO_SIZES_BYTES.sha256)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function writeQueueRegistration(writer, value) {
|
|
107
|
+
writer
|
|
108
|
+
.writeString(value.recipientQueueId)
|
|
109
|
+
.writeString(value.senderQueueId)
|
|
110
|
+
.writeFixedBytes(hybridPublicKeyCodec.encode(value.recipientAuthPublicKey), HYBRID_PUBLIC_KEY_SIZE_BYTES)
|
|
111
|
+
.writeFixedBytes(value.d2rPublicKey, CRYPTO_SIZES_BYTES.xWingPublicKey)
|
|
112
|
+
.writeFixedBytes(value.setupVerifier, CRYPTO_SIZES_BYTES.sha256);
|
|
113
|
+
}
|
|
114
|
+
function readQueueRegistration(reader) {
|
|
115
|
+
return {
|
|
116
|
+
recipientQueueId: reader.readString(),
|
|
117
|
+
senderQueueId: reader.readString(),
|
|
118
|
+
recipientAuthPublicKey: decodeWithCodec(hybridPublicKeyCodec, reader.readFixedBytes(HYBRID_PUBLIC_KEY_SIZE_BYTES)),
|
|
119
|
+
d2rPublicKey: reader.readFixedBytes(CRYPTO_SIZES_BYTES.xWingPublicKey),
|
|
120
|
+
setupVerifier: reader.readFixedBytes(CRYPTO_SIZES_BYTES.sha256)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function decodeWithCodec(codec, bytes) {
|
|
124
|
+
const result = codec.decode(bytes);
|
|
125
|
+
if (!result.ok)
|
|
126
|
+
throw result.error;
|
|
127
|
+
return result.value;
|
|
128
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export declare const RELAY_KEY_BUNDLE_FORMAT_VERSION = 1;
|
|
2
2
|
export declare const RELAY_IDENTITY_FINGERPRINT_CONTEXT: string;
|
|
3
3
|
export declare const RELAY_KEY_BUNDLE_SIGNATURE_CONTEXT: string;
|
|
4
|
+
export declare const DESTINATION_SEND_AUTHORIZATION_CONTEXT: string;
|
|
5
|
+
export declare const TRANSPORT_REQUEST_AUTHORIZATION_CONTEXT: string;
|
|
6
|
+
export declare const S2D_KEY_MATERIAL_CONTEXT: string;
|
|
7
|
+
export declare const S2D_REQUEST_ASSOCIATED_DATA_CONTEXT: string;
|
|
8
|
+
export declare const S2D_RESPONSE_ASSOCIATED_DATA_CONTEXT: string;
|
|
4
9
|
//# sourceMappingURL=relay-constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-constants.d.ts","sourceRoot":"","sources":["../../../src/transport/constants/relay-constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,eAAO,MAAM,kCAAkC,QAE9C,CAAC;AACF,eAAO,MAAM,kCAAkC,QAE9C,CAAC"}
|
|
1
|
+
{"version":3,"file":"relay-constants.d.ts","sourceRoot":"","sources":["../../../src/transport/constants/relay-constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,eAAO,MAAM,kCAAkC,QAE9C,CAAC;AACF,eAAO,MAAM,kCAAkC,QAE9C,CAAC;AACF,eAAO,MAAM,sCAAsC,QAElD,CAAC;AACF,eAAO,MAAM,uCAAuC,QAEnD,CAAC;AACF,eAAO,MAAM,wBAAwB,QAAmD,CAAC;AACzF,eAAO,MAAM,mCAAmC,QAE/C,CAAC;AACF,eAAO,MAAM,oCAAoC,QAEhD,CAAC"}
|
|
@@ -2,3 +2,8 @@ import { createTransportCryptoContext } from "./transport-context";
|
|
|
2
2
|
export const RELAY_KEY_BUNDLE_FORMAT_VERSION = 1;
|
|
3
3
|
export const RELAY_IDENTITY_FINGERPRINT_CONTEXT = createTransportCryptoContext("relay/identity-fingerprint");
|
|
4
4
|
export const RELAY_KEY_BUNDLE_SIGNATURE_CONTEXT = createTransportCryptoContext("relay/encryption-key-bundle-signature");
|
|
5
|
+
export const DESTINATION_SEND_AUTHORIZATION_CONTEXT = createTransportCryptoContext("relay/destination-send-authorization");
|
|
6
|
+
export const TRANSPORT_REQUEST_AUTHORIZATION_CONTEXT = createTransportCryptoContext("relay/transport-request-authorization");
|
|
7
|
+
export const S2D_KEY_MATERIAL_CONTEXT = createTransportCryptoContext("s2d/key-material");
|
|
8
|
+
export const S2D_REQUEST_ASSOCIATED_DATA_CONTEXT = createTransportCryptoContext("s2d/request-associated-data");
|
|
9
|
+
export const S2D_RESPONSE_ASSOCIATED_DATA_CONTEXT = createTransportCryptoContext("s2d/response-associated-data");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const TRANSPORT_PACKET_FORMAT_VERSION = 1;
|
|
2
|
+
export declare const DESTINATION_SEND_FORMAT_VERSION = 1;
|
|
3
|
+
export declare const S2D_ENVELOPE_FORMAT_VERSION = 1;
|
|
4
|
+
export declare const QUEUE_SETUP_CAPABILITY_SIZE_BYTES = 32;
|
|
5
|
+
//# sourceMappingURL=transport-packet-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-packet-constants.d.ts","sourceRoot":"","sources":["../../../src/transport/constants/transport-packet-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,IAAI,CAAC;AACjD,eAAO,MAAM,+BAA+B,IAAI,CAAC;AACjD,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,eAAO,MAAM,iCAAiC,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-relay-identity-fingerprint.d.ts","sourceRoot":"","sources":["../../../src/transport/helpers/derive-relay-identity-fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,8BAA8B,EAEnC,KAAK,wBAAwB,
|
|
1
|
+
{"version":3,"file":"derive-relay-identity-fingerprint.d.ts","sourceRoot":"","sources":["../../../src/transport/helpers/derive-relay-identity-fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,8BAA8B,EAEnC,KAAK,wBAAwB,EAE7B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAIpD,wBAAsB,8BAA8B,CACnD,MAAM,EAAE,8BAA8B,EACtC,SAAS,EAAE,wBAAwB,GACjC,OAAO,CAAC,wBAAwB,CAAC,CAInC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { encodeSignatureInput } from "../../crypto-core";
|
|
2
|
-
import { RelayIdentityPublicKeyCodec } from "../codecs";
|
|
1
|
+
import { encodeSignatureInput, HybridSignaturePublicKeyCodec } from "../../crypto-core";
|
|
3
2
|
import { RELAY_IDENTITY_FINGERPRINT_CONTEXT } from "../constants";
|
|
4
|
-
const identityCodec = new
|
|
3
|
+
const identityCodec = new HybridSignaturePublicKeyCodec();
|
|
5
4
|
export async function deriveRelayIdentityFingerprint(crypto, publicKey) {
|
|
6
5
|
return (await crypto.sha256(encodeSignatureInput(RELAY_IDENTITY_FINGERPRINT_CONTEXT, identityCodec.encode(publicKey))));
|
|
7
6
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CryptoPrimitivesFacadeContract, type XWingSharedSecret } from "../../crypto-core";
|
|
2
|
+
import { S2DKeyMaterial } from "../model";
|
|
3
|
+
export declare function deriveS2DKeyMaterial(crypto: CryptoPrimitivesFacadeContract, sharedSecret: XWingSharedSecret): Promise<S2DKeyMaterial>;
|
|
4
|
+
//# sourceMappingURL=derive-s2d-key-material.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-s2d-key-material.d.ts","sourceRoot":"","sources":["../../../src/transport/helpers/derive-s2d-key-material.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACtB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAU1C,wBAAsB,oBAAoB,CACzC,MAAM,EAAE,8BAA8B,EACtC,YAAY,EAAE,iBAAiB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAiBzB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { assertByteLength } from "@okee-e2ee/core/helpers";
|
|
2
|
+
import { CRYPTO_SIZES_BYTES } from "../../crypto-core";
|
|
3
|
+
import { S2D_KEY_MATERIAL_CONTEXT } from "../constants";
|
|
4
|
+
const REQUEST_KEY_END = CRYPTO_SIZES_BYTES.aeadKey;
|
|
5
|
+
const REQUEST_NONCE_END = REQUEST_KEY_END + CRYPTO_SIZES_BYTES.aeadNonce;
|
|
6
|
+
const RESPONSE_KEY_END = REQUEST_NONCE_END + CRYPTO_SIZES_BYTES.aeadKey;
|
|
7
|
+
const RESPONSE_NONCE_END = RESPONSE_KEY_END + CRYPTO_SIZES_BYTES.aeadNonce;
|
|
8
|
+
const HKDF_SALT = new Uint8Array(CRYPTO_SIZES_BYTES.sha256);
|
|
9
|
+
const HKDF_INFO = new TextEncoder().encode(S2D_KEY_MATERIAL_CONTEXT);
|
|
10
|
+
export async function deriveS2DKeyMaterial(crypto, sharedSecret) {
|
|
11
|
+
assertByteLength(sharedSecret, CRYPTO_SIZES_BYTES.xWingSharedSecret, "X-Wing sharedSecret");
|
|
12
|
+
const material = await crypto.hkdf({
|
|
13
|
+
inputKeyMaterial: sharedSecret,
|
|
14
|
+
salt: HKDF_SALT,
|
|
15
|
+
info: HKDF_INFO,
|
|
16
|
+
outputLength: RESPONSE_NONCE_END
|
|
17
|
+
});
|
|
18
|
+
assertByteLength(material, RESPONSE_NONCE_END, "S2D key material");
|
|
19
|
+
return {
|
|
20
|
+
requestKey: material.slice(0, REQUEST_KEY_END),
|
|
21
|
+
requestNonce: material.slice(REQUEST_KEY_END, REQUEST_NONCE_END),
|
|
22
|
+
responseKey: material.slice(REQUEST_NONCE_END, RESPONSE_KEY_END),
|
|
23
|
+
responseNonce: material.slice(RESPONSE_KEY_END, RESPONSE_NONCE_END)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./derive-relay-identity-fingerprint";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./derive-s2d-key-material";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Bytes, HybridSignature } from "../../crypto-core";
|
|
2
|
+
import { DESTINATION_SEND_FORMAT_VERSION } from "../constants";
|
|
3
|
+
import { DeliveryId, QueueSetupCapability, SenderHybridAuthPublicKey, SenderQueueId } from "./queue-model";
|
|
4
|
+
type DestinationSendRequestPayloadBase = {
|
|
5
|
+
readonly formatVersion: typeof DESTINATION_SEND_FORMAT_VERSION;
|
|
6
|
+
readonly senderQueueId: SenderQueueId;
|
|
7
|
+
readonly deliveryId: DeliveryId;
|
|
8
|
+
readonly payload: Bytes;
|
|
9
|
+
};
|
|
10
|
+
export type DestinationSendRequestPayload = DestinationSendRequestPayloadBase & ({
|
|
11
|
+
readonly setupCapability: QueueSetupCapability;
|
|
12
|
+
readonly senderAuthPublicKey: SenderHybridAuthPublicKey;
|
|
13
|
+
} | {
|
|
14
|
+
readonly setupCapability?: never;
|
|
15
|
+
readonly senderAuthPublicKey?: never;
|
|
16
|
+
});
|
|
17
|
+
export type DestinationSendRequest = {
|
|
18
|
+
readonly payload: DestinationSendRequestPayload;
|
|
19
|
+
readonly authorization: HybridSignature;
|
|
20
|
+
};
|
|
21
|
+
export declare enum DestinationSendResponseStatus {
|
|
22
|
+
ERROR = 0,
|
|
23
|
+
SUCCESS = 1
|
|
24
|
+
}
|
|
25
|
+
export declare enum DestinationSendErrorCode {
|
|
26
|
+
QUEUE_NOT_FOUND = 0,
|
|
27
|
+
AUTHORIZATION_INVALID = 1,
|
|
28
|
+
SETUP_CAPABILITY_INVALID = 2,
|
|
29
|
+
SENDER_KEY_CONFLICT = 3,
|
|
30
|
+
DELIVERY_CONFLICT = 4,
|
|
31
|
+
PAYLOAD_TOO_LARGE = 5
|
|
32
|
+
}
|
|
33
|
+
type DestinationSendResponseBase = {
|
|
34
|
+
readonly formatVersion: typeof DESTINATION_SEND_FORMAT_VERSION;
|
|
35
|
+
readonly deliveryId: DeliveryId;
|
|
36
|
+
};
|
|
37
|
+
export type DestinationSendResponse = DestinationSendResponseBase & ({
|
|
38
|
+
readonly status: DestinationSendResponseStatus.SUCCESS;
|
|
39
|
+
} | {
|
|
40
|
+
readonly status: DestinationSendResponseStatus.ERROR;
|
|
41
|
+
readonly errorCode: DestinationSendErrorCode;
|
|
42
|
+
});
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=destination-send.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-send.d.ts","sourceRoot":"","sources":["../../../src/transport/model/destination-send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,yBAAyB,EACzB,aAAa,EACb,MAAM,eAAe,CAAC;AAEvB,KAAK,iCAAiC,GAAG;IACxC,QAAQ,CAAC,aAAa,EAAE,OAAO,+BAA+B,CAAC;IAC/D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,iCAAiC,GAC5E,CACG;IACA,QAAQ,CAAC,eAAe,EAAE,oBAAoB,CAAC;IAC/C,QAAQ,CAAC,mBAAmB,EAAE,yBAAyB,CAAC;CACvD,GACD;IACA,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC;IACjC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,KAAK,CAAC;CACpC,CACH,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG;IACpC,QAAQ,CAAC,OAAO,EAAE,6BAA6B,CAAC;IAChD,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC;CACxC,CAAC;AAEF,oBAAY,6BAA6B;IACxC,KAAK,IAAI;IACT,OAAO,IAAI;CACX;AAED,oBAAY,wBAAwB;IACnC,eAAe,IAAI;IACnB,qBAAqB,IAAI;IACzB,wBAAwB,IAAI;IAC5B,mBAAmB,IAAI;IACvB,iBAAiB,IAAI;IACrB,iBAAiB,IAAI;CACrB;AAED,KAAK,2BAA2B,GAAG;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,+BAA+B,CAAC;IAC/D,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,GAChE,CACG;IACA,QAAQ,CAAC,MAAM,EAAE,6BAA6B,CAAC,OAAO,CAAC;CACtD,GACD;IACA,QAAQ,CAAC,MAAM,EAAE,6BAA6B,CAAC,KAAK,CAAC;IACrD,QAAQ,CAAC,SAAS,EAAE,wBAAwB,CAAC;CAC5C,CACH,CAAC"}
|