p2party 0.6.15

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 (71) hide show
  1. package/LICENSE.md +661 -0
  2. package/README.md +417 -0
  3. package/lib/api/signalingServerApi.d.ts +19 -0
  4. package/lib/api/webrtc/baseQuery.d.ts +11 -0
  5. package/lib/api/webrtc/baseQuery.d.ts.map +1 -0
  6. package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts +9 -0
  7. package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts.map +1 -0
  8. package/lib/api/webrtc/disconnectFromChannelLabelQuery.d.ts +8 -0
  9. package/lib/api/webrtc/disconnectFromChannelLabelQuery.d.ts.map +1 -0
  10. package/lib/api/webrtc/disconnectFromPeerChannelLabelQuery.d.ts +9 -0
  11. package/lib/api/webrtc/disconnectFromPeerChannelLabelQuery.d.ts.map +1 -0
  12. package/lib/api/webrtc/disconnectFromPeerQuery.d.ts +9 -0
  13. package/lib/api/webrtc/disconnectFromPeerQuery.d.ts.map +1 -0
  14. package/lib/api/webrtc/disconnectFromRoomQuery.d.ts +9 -0
  15. package/lib/api/webrtc/disconnectFromRoomQuery.d.ts.map +1 -0
  16. package/lib/api/webrtc/disconnectQuery.d.ts +9 -0
  17. package/lib/api/webrtc/disconnectQuery.d.ts.map +1 -0
  18. package/lib/api/webrtc/index.d.ts +19 -0
  19. package/lib/api/webrtc/index.d.ts.map +1 -0
  20. package/lib/api/webrtc/interfaces.d.ts +101 -0
  21. package/lib/api/webrtc/interfaces.d.ts.map +1 -0
  22. package/lib/api/webrtc/openChannelQuery.d.ts +11 -0
  23. package/lib/api/webrtc/openChannelQuery.d.ts.map +1 -0
  24. package/lib/api/webrtc/sendMessageQuery.d.ts +12 -0
  25. package/lib/api/webrtc/sendMessageQuery.d.ts.map +1 -0
  26. package/lib/api/webrtc/setCandidateQuery.d.ts +9 -0
  27. package/lib/api/webrtc/setCandidateQuery.d.ts.map +1 -0
  28. package/lib/api/webrtc/setDescriptionQuery.d.ts +12 -0
  29. package/lib/api/webrtc/setDescriptionQuery.d.ts.map +1 -0
  30. package/lib/cryptography/chacha20poly1305.d.ts +116 -0
  31. package/lib/cryptography/ed25519.d.ts +12 -0
  32. package/lib/cryptography/hasher.d.ts +11 -0
  33. package/lib/cryptography/interfaces.d.ts +40 -0
  34. package/lib/cryptography/memory.d.ts +15 -0
  35. package/lib/cryptography/merkle.d.ts +43 -0
  36. package/lib/cryptography/mnemonic.d.ts +30 -0
  37. package/lib/cryptography/utils.d.ts +13 -0
  38. package/lib/db/api.d.ts +35 -0
  39. package/lib/db/db.worker.d.ts +2 -0
  40. package/lib/db/src/getDB.d.ts +68 -0
  41. package/lib/db/src/getDB.d.ts.map +1 -0
  42. package/lib/db/types.d.ts +234 -0
  43. package/lib/db.worker.js +2 -0
  44. package/lib/handlers/handleChallenge.d.ts +5 -0
  45. package/lib/handlers/handleConnectToPeer.d.ts +4 -0
  46. package/lib/handlers/handleOpenChannel.d.ts +15 -0
  47. package/lib/handlers/handleQueuedIceCandidates.d.ts +3 -0
  48. package/lib/handlers/handleReadReceipt.d.ts +5 -0
  49. package/lib/handlers/handleReceiveMessage.d.ts +16 -0
  50. package/lib/handlers/handleSendMessage.d.ts +6 -0
  51. package/lib/handlers/handleSendMessageWebsocket.d.ts +4 -0
  52. package/lib/handlers/handleWebSocketMessage.d.ts +7 -0
  53. package/lib/index.d.ts +202 -0
  54. package/lib/index.js +2 -0
  55. package/lib/index.min.js +2 -0
  56. package/lib/index.mjs +2 -0
  57. package/lib/middleware/keyPairListenerMiddleware.d.ts +3 -0
  58. package/lib/middleware/roomListenerMiddleware.d.ts +3 -0
  59. package/lib/reducers/commonSlice.d.ts +9 -0
  60. package/lib/reducers/keyPairSlice.d.ts +33 -0
  61. package/lib/reducers/roomSlice.d.ts +113 -0
  62. package/lib/reducers/signalingServerSlice.d.ts +16 -0
  63. package/lib/store.d.ts +55 -0
  64. package/lib/utils/channelLabel.d.ts +12 -0
  65. package/lib/utils/interfaces.d.ts +138 -0
  66. package/lib/utils/mediasource.d.ts +2 -0
  67. package/lib/utils/messageTypes.d.ts +88 -0
  68. package/lib/utils/metadata.d.ts +17 -0
  69. package/lib/utils/splitToChunks.d.ts +29 -0
  70. package/lib/utils/uint8array.d.ts +21 -0
  71. package/package.json +115 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,eAAe,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,qBAAqB,CA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,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,+BAA+B;IAC9C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mCAAmC;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,uCAAuC;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,11 @@
1
+ import type { BaseQueryFn } from "@reduxjs/toolkit/query";
2
+ import type { RTCOpenChannelParams, IRTCDataChannel, IRTCPeerConnection } from "./interfaces";
3
+ export interface RTCOpenChannelParamsExtention extends RTCOpenChannelParams {
4
+ peerConnections: IRTCPeerConnection[];
5
+ dataChannels: IRTCDataChannel[];
6
+ decryptionWasmMemory: WebAssembly.Memory;
7
+ merkleWasmMemory: WebAssembly.Memory;
8
+ }
9
+ declare const webrtcOpenChannelQuery: BaseQueryFn<RTCOpenChannelParamsExtention, void, unknown>;
10
+ export default webrtcOpenChannelQuery;
11
+ //# sourceMappingURL=openChannelQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openChannelQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/openChannelQuery.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,6BAA8B,SAAQ,oBAAoB;IACzE,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC;IACzC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC;CACtC;AAED,QAAA,MAAM,sBAAsB,EAAE,WAAW,CACvC,6BAA6B,EAC7B,IAAI,EACJ,OAAO,CAsER,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { BaseQueryFn } from "@reduxjs/toolkit/query";
2
+ import type { IRTCDataChannel, IRTCPeerConnection, RTCSendMessageParams } from "./interfaces";
3
+ export interface RTCChannelMessageParamsExtension extends RTCSendMessageParams {
4
+ peerConnections: IRTCPeerConnection[];
5
+ dataChannels: IRTCDataChannel[];
6
+ encryptionWasmMemory: WebAssembly.Memory;
7
+ decryptionWasmMemory: WebAssembly.Memory;
8
+ merkleWasmMemory: WebAssembly.Memory;
9
+ }
10
+ declare const webrtcMessageQuery: BaseQueryFn<RTCChannelMessageParamsExtension, void, unknown>;
11
+ export default webrtcMessageQuery;
12
+ //# sourceMappingURL=sendMessageQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendMessageQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/sendMessageQuery.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,gCAAiC,SAAQ,oBAAoB;IAC5E,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC;IACzC,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC;IACzC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC;CACtC;AAED,QAAA,MAAM,kBAAkB,EAAE,WAAW,CACnC,gCAAgC,EAChC,IAAI,EACJ,OAAO,CAmDR,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { BaseQueryFn } from "@reduxjs/toolkit/query";
2
+ import type { RTCSetCandidateParams, IRTCPeerConnection, IRTCIceCandidate } from "./interfaces";
3
+ export interface RTCSetCandidateParamsExtention extends RTCSetCandidateParams {
4
+ peerConnections: IRTCPeerConnection[];
5
+ iceCandidates: IRTCIceCandidate[];
6
+ }
7
+ declare const webrtcSetIceCandidateQuery: BaseQueryFn<RTCSetCandidateParamsExtention, void, unknown>;
8
+ export default webrtcSetIceCandidateQuery;
9
+ //# sourceMappingURL=setCandidateQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setCandidateQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/setCandidateQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,8BAA+B,SAAQ,qBAAqB;IAC3E,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,aAAa,EAAE,gBAAgB,EAAE,CAAC;CACnC;AAED,QAAA,MAAM,0BAA0B,EAAE,WAAW,CAC3C,8BAA8B,EAC9B,IAAI,EACJ,OAAO,CA6CR,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { BaseQueryFn } from "@reduxjs/toolkit/query";
2
+ import type { RTCSetDescriptionParams, IRTCPeerConnection, IRTCIceCandidate, IRTCDataChannel } from "./interfaces";
3
+ export interface RTCSetDescriptionParamsExtension extends RTCSetDescriptionParams {
4
+ peerConnections: IRTCPeerConnection[];
5
+ iceCandidates: IRTCIceCandidate[];
6
+ dataChannels: IRTCDataChannel[];
7
+ decryptionWasmMemory: WebAssembly.Memory;
8
+ merkleWasmMemory: WebAssembly.Memory;
9
+ }
10
+ declare const webrtcSetDescriptionQuery: BaseQueryFn<RTCSetDescriptionParamsExtension, void, unknown>;
11
+ export default webrtcSetDescriptionQuery;
12
+ //# sourceMappingURL=setDescriptionQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setDescriptionQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/setDescriptionQuery.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,gCACf,SAAQ,uBAAuB;IAC/B,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC;IACzC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC;CACtC;AAED,QAAA,MAAM,yBAAyB,EAAE,WAAW,CAC1C,gCAAgC,EAChC,IAAI,EACJ,OAAO,CAqLR,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
@@ -0,0 +1,116 @@
1
+ import type { LibCrypto } from "./libcrypto";
2
+ /**
3
+ * Encrypts a message with additional data using
4
+ * the crypto_aead_chacha20poly1305_ietf_encrypt operation from
5
+ * libsodium and computes a symmetric key Uint8Array(32) from the sender's
6
+ * Ed25519 secret key and the receiver's Ed25519 public key.
7
+ * The X25519 key counterparts are computed in wasm from the libsodium provided
8
+ * crypto_sign_ed25519_pk_to_curve25519 and crypto_sign_ed25519_sk_to_curve25519
9
+ * functions.
10
+ * The symmetric key for encryption is then computed by crypto_kx_server_session_keys.
11
+ * The nonce is calculated by taking the first half of the
12
+ * sha512 hash of a Uint8Array(3 * 32) array with 32 random bytes, the X25519 public key
13
+ * and the X25519 secret key.
14
+ * The auth tag is generated using Poly1305.
15
+ *
16
+ * If you need to perform bulk encryptions with predictable message
17
+ * and additional data sizes then it will be more efficient to preload
18
+ * the wasm module and reuse it as follows:
19
+ *
20
+ * ```ts
21
+ * const messageLen = message.length;
22
+ * const additionalLen = additionalData.length;
23
+ *
24
+ * const wasmMemory = dcryptoMemory.encryptMemory(messageLen, additionalLen);
25
+ * const wasmModule = await dcryptoMethodsModule({ wasmMemory });
26
+ * ```
27
+ *
28
+ * If not all messages and additional data are equal, you can always just use
29
+ * the largest Uint8Arrays as inputs.
30
+ *
31
+ * ```ts
32
+ * import dcrypto from \"@deliberative/crypto\"
33
+ *
34
+ * const message = new Uint8Array(128).fill(1);
35
+ * const additionalData = new Uint8Array(64).fill(2);
36
+ *
37
+ * const aliceKeyPair = await dcrypto.keyPair();
38
+ * const bobKeyPair = await dcrypto.keyPair();
39
+ *
40
+ * const box = await dcrypto.encrypt(
41
+ * message,
42
+ * bobKeyPair.publicKey,
43
+ * aliceKeyPair.secretKey,
44
+ * additionalData
45
+ * );
46
+ * ```
47
+ *
48
+ * @param message - the message to encrypt
49
+ * @param receiverPublicKey - the receiver's Ed25519 public key
50
+ * @param senderSecretKey - the sender's Ed25519 secret key
51
+ * @param additionalData - the additional data for aead
52
+ * @param module - wasm module in case of bulk encryptions
53
+ *
54
+ * @returns Encrypted box [nonce 16 || encrypted_data || auth tag 12]
55
+ */
56
+ export declare const encryptAsymmetric: (message: Uint8Array, receiverPublicKey: Uint8Array, senderSecretKey: Uint8Array, additionalData: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
57
+ /**
58
+ * Decrypts a box with additional data using the
59
+ * crypto_aead_chacha20poly1305_ietf_decrypt function from libsodium and
60
+ * computes a symmetric key Uint8Array(32) from the sender's
61
+ * Ed25519 public key and the receiver's Ed25519 secret key.
62
+ * The X25519 key counterparts are computed in wasm from the libsodium provided
63
+ * crypto_sign_ed25519_pk_to_curve25519 and crypto_sign_ed25519_sk_to_curve25519
64
+ * functions.
65
+ * The symmetric key for encryption is then computed by crypto_kx_client_session_keys.
66
+ * The encrypted box is a Uint8Array[nonce 16 || encrypted_data || auth tag 12].
67
+ *
68
+ * If you need to perform bulk decryptions with predictable box
69
+ * and additional data sizes then it will be more efficient to preload
70
+ * the wasm module and reuse it as follows:
71
+ *
72
+ * ```ts
73
+ * const messageLen = message.length;
74
+ * const additionalLen = additionalData.length;
75
+ *
76
+ * const wasmMemory = dcryptoMemory.decryptMemory(messageLen, additionalLen);
77
+ * const wasmModule = await dcryptoMethodsModule({ wasmMemory });
78
+ * ```
79
+ *
80
+ * If not all boxes and additional data are equal, you can always just use
81
+ * the largest Uint8Arrays as inputs.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import dcrypto from \"@deliberative/crypto\"
86
+ *
87
+ * const message = new Uint8Array(128).fill(1);
88
+ * const additionalData = new Uint8Array(64).fill(2);
89
+ *
90
+ * const aliceKeyPair = await dcrypto.keyPair();
91
+ * const bobKeyPair = await dcrypto.keyPair();
92
+ *
93
+ * const box = await dcrypto.encrypt(
94
+ * message,
95
+ * bobKeyPair.publicKey,
96
+ * aliceKeyPair.secretKey,
97
+ * additionalData
98
+ * );
99
+ *
100
+ * const decrypted = await dcrypto.decrypt(
101
+ * box,
102
+ * bobKeyPair.secretKey,
103
+ * additionalData
104
+ * );
105
+ *
106
+ * \/\/ message should be equal to decrypted.
107
+ * ```
108
+ *
109
+ * @param encrypted - The encrypted box including sender public key, nonce and auth tag
110
+ * @param receiverSecretKey - The receiver secret key
111
+ * @param additionalData - The additional data for aead
112
+ * @param module - The wasm module in case of bulk decryptions
113
+ * @returns The decrypted message
114
+ */
115
+ export declare const decryptAsymmetric: (encrypted: Uint8Array, publicKey: Uint8Array, secretKey: Uint8Array, additionalData: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
116
+ //# sourceMappingURL=chacha20poly1305.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { SignKeyPair } from "./interfaces";
2
+ import type { LibCrypto } from "./libcrypto";
3
+ export declare const newKeyPair: (module?: LibCrypto) => Promise<SignKeyPair>;
4
+ export declare const keyPairFromSeed: (seed: Uint8Array, module?: LibCrypto) => Promise<SignKeyPair>;
5
+ export declare const keyPairFromSecretKey: (secretKey: Uint8Array, module?: LibCrypto) => Promise<SignKeyPair>;
6
+ /**
7
+ * @function
8
+ * Returns the signature of the data provided.
9
+ */
10
+ export declare const sign: (message: Uint8Array, secretKey: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
11
+ export declare const verify: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array, module?: LibCrypto) => Promise<boolean>;
12
+ //# sourceMappingURL=ed25519.d.ts.map
@@ -0,0 +1,11 @@
1
+ export declare class Hasher {
2
+ private encoder;
3
+ private data;
4
+ private constructor();
5
+ static createHash(): Hasher;
6
+ update(data: string | Uint8Array): Hasher;
7
+ digest(encoding?: "hex" | "base64"): Promise<string>;
8
+ private concatUint8Arrays;
9
+ private encodeBuffer;
10
+ }
11
+ //# sourceMappingURL=hasher.d.ts.map
@@ -0,0 +1,40 @@
1
+ export declare const crypto_auth_hmacsha512_BYTES: number;
2
+ export declare const crypto_auth_hmacsha512_KEYBYTES: number;
3
+ export declare const crypto_hash_sha512_BYTES: number;
4
+ export declare const crypto_sign_ed25519_BYTES: number;
5
+ export declare const crypto_sign_ed25519_SEEDBYTES: number;
6
+ export declare const crypto_sign_ed25519_PUBLICKEYBYTES: number;
7
+ export declare const crypto_sign_ed25519_SECRETKEYBYTES: number;
8
+ export declare const crypto_secretbox_KEYBYTES: number;
9
+ export declare const crypto_secretbox_NONCEBYTES: number;
10
+ export declare const crypto_box_poly1305_AUTHTAGBYTES: number;
11
+ export declare const crypto_box_x25519_PUBLICKEYBYTES: number;
12
+ export declare const crypto_box_x25519_SECRETKEYBYTES: number;
13
+ export declare const crypto_box_x25519_NONCEBYTES: number;
14
+ export declare const crypto_aead_chacha20poly1305_ietf_KEYBYTES: number;
15
+ export declare const crypto_aead_chacha20poly1305_ietf_NPUBBYTES: number;
16
+ export declare const crypto_pwhash_argon2id_SALTBYTES: number;
17
+ export interface SignKeyPair {
18
+ publicKey: Uint8Array;
19
+ secretKey: Uint8Array;
20
+ }
21
+ export declare const getEncryptedLen: (dataLen: number) => number;
22
+ export declare const getDecryptedLen: (encryptedLen: number) => number;
23
+ declare const _default: {
24
+ crypto_hash_sha512_BYTES: number;
25
+ crypto_sign_ed25519_BYTES: number;
26
+ crypto_sign_ed25519_SEEDBYTES: number;
27
+ crypto_sign_ed25519_PUBLICKEYBYTES: number;
28
+ crypto_sign_ed25519_SECRETKEYBYTES: number;
29
+ crypto_secretbox_KEYBYTES: number;
30
+ crypto_secretbox_NONCEBYTES: number;
31
+ crypto_box_poly1305_AUTHTAGBYTES: number;
32
+ crypto_box_x25519_PUBLICKEYBYTES: number;
33
+ crypto_box_x25519_SECRETKEYBYTES: number;
34
+ crypto_box_x25519_NONCEBYTES: number;
35
+ crypto_aead_chacha20poly1305_ietf_KEYBYTES: number;
36
+ getEncryptedLen: (dataLen: number) => number;
37
+ getDecryptedLen: (encryptedLen: number) => number;
38
+ };
39
+ export default _default;
40
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1,15 @@
1
+ declare const _default: {
2
+ newKeyPairMemory: () => WebAssembly.Memory;
3
+ keyPairFromSeedMemory: () => WebAssembly.Memory;
4
+ keyPairFromSecretKeyMemory: () => WebAssembly.Memory;
5
+ signMemory: (messageLen: number) => WebAssembly.Memory;
6
+ verifyMemory: (messageLen: number) => WebAssembly.Memory;
7
+ encryptAsymmetricMemory: (messageLen: number, additionalDataLen: number) => WebAssembly.Memory;
8
+ decryptAsymmetricMemory: (encryptedLen: number, additionalDataLen: number) => WebAssembly.Memory;
9
+ getMerkleRootMemory: (leavesLen: number) => WebAssembly.Memory;
10
+ getMerkleProofMemory: (leavesLen: number) => WebAssembly.Memory;
11
+ verifyMerkleProofMemory: (proofLen: number) => WebAssembly.Memory;
12
+ argon2Memory: (mnemonicLen: number) => WebAssembly.Memory;
13
+ };
14
+ export default _default;
15
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1,43 @@
1
+ import type { LibCrypto } from "./libcrypto";
2
+ /**
3
+ * @function
4
+ * Returns the Merkle root of a tree.
5
+ *
6
+ * @param treeHashes: The tree, hashed.
7
+ * @returns Promise<Uint8Array>
8
+ */
9
+ export declare const getMerkleRoot: (treeHashes: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
10
+ /**
11
+ * @function
12
+ * getMerkleProof
13
+ *
14
+ * @description
15
+ * Returns the Merkle proof of an element of a tree.
16
+ * Can be used as a receipt of a transaction etc.
17
+ *
18
+ * @param {Uint8Array[]} treeHashes: The tree.
19
+ * @param {Uint8Array} elementHash: The element.
20
+ *
21
+ * @returns {Promise<Uint8Array>}: The Merkle proof.
22
+ */
23
+ export declare const getMerkleProof: (treeHashes: Uint8Array, elementHash: Uint8Array, module?: LibCrypto, proofFixedLen?: number) => Promise<Uint8Array>;
24
+ /**
25
+ * @function
26
+ * Calculates the Merkle root from the element hash and its Merkle proof.
27
+ *
28
+ * @param hash: The hash of the base element in question.
29
+ * @param proof: The first element is the first leave that was added for the calculation etc. The last
30
+ * byte is either 0 or 1, indicating whether it is to the left or to the right in the tree.
31
+ *
32
+ * @returns The Merkle root
33
+ */
34
+ export declare const getMerkleRootFromProof: (item: Uint8Array, proof: Uint8Array) => Promise<Uint8Array>;
35
+ /**
36
+ * Verifies that the hash was indeed included in the calculation of the Merkle root.
37
+ * @param hash: The hash of the base element in question.
38
+ * @param root: The Merkle root.
39
+ * @param proof: The first element is the first leave that was added for the calculation etc. The last
40
+ * byte is either 0 or 1, indicating whether it is to the left or to the right in the tree.
41
+ */
42
+ export declare const verifyMerkleProof: (item: Uint8Array, root: Uint8Array, proof: Uint8Array, module?: LibCrypto) => Promise<boolean>;
43
+ //# sourceMappingURL=merkle.d.ts.map
@@ -0,0 +1,30 @@
1
+ import type { LibCrypto } from "./libcrypto";
2
+ export declare const argon2: (mnemonic: string, salt?: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
3
+ /**
4
+ * Generates a sequence of words chosen from a prespecified wordlist
5
+ * that represents a random seed that
6
+ * can be translated later into a cryptographic keypair.
7
+ * With a strength of 128 bits of entropy you get 12 words.
8
+ * In every additional step you get 3 more words. The maximum is
9
+ * set to 512 bits of entropy, or 48 words!
10
+ *
11
+ * @param strength - Entropy bits
12
+ * @returns The mnemonic from the wordlist.
13
+ *
14
+ */
15
+ export declare const generateMnemonic: (strength?: 128 | 160 | 192 | 224 | 256 | 288 | 320 | 352 | 384 | 416 | 448 | 480 | 512) => Promise<string>;
16
+ export declare const mnemonicToEntropy: (mnemonic: string) => Promise<boolean>;
17
+ export declare const validateMnemonic: (mnemonic: string) => Promise<boolean>;
18
+ /**
19
+ * Generates an Ed25519 key pair from the provided mnemonic.
20
+ * Optionally, you can strenthen the generation with a password.
21
+ * The mnemonic is converted into a seed through the use of argon2id.
22
+ * The password is used as a salt for argon2id.
23
+ * From the generated seed we extract the key pair.
24
+ *
25
+ * @param mnemonic - Sequence of words from the predefined wordlist
26
+ * @param password - Optional salt for the seed derivation
27
+ * @returns An Ed25519 key pair
28
+ */
29
+ export declare const keyPairFromMnemonic: (mnemonic: string, password?: string) => Promise<import("./interfaces").SignKeyPair>;
30
+ //# sourceMappingURL=mnemonic.d.ts.map
@@ -0,0 +1,13 @@
1
+ export declare const randomNumberInRange: (min: number, max: number) => Promise<number>;
2
+ export declare const randomBytesToString: (len: number, withAlphabetSmall?: boolean, withAlphabetCapital?: boolean, withNumbers?: boolean) => Promise<string>;
3
+ export declare const generateRandomRoomUrl: (lenMin: number, lenMax?: number, withAlphabetSmall?: boolean, withAlphabetCapital?: boolean, withNumbers?: boolean) => Promise<string>;
4
+ /**
5
+ * @function
6
+ * Fisher-Yates shuffle of array.
7
+ *
8
+ * @param array: The array to randomly shuffle.
9
+ *
10
+ * @returns Promise<T[]>
11
+ */
12
+ export declare const fisherYatesShuffle: <T>(array: T[]) => Promise<T[]>;
13
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,35 @@
1
+ import type { Chunk, NewChunk, SendQueue } from "./types";
2
+ export declare const getDBAddressBookEntry: (peerId?: string, peerPublicKey?: string) => Promise<import("./types").UsernamedPeer | undefined>;
3
+ export declare const getAllDBAddressBookEntries: () => Promise<import("./types").UsernamedPeer[]>;
4
+ export declare const setDBAddressBookEntry: (username: string, peerId: string, peerPublicKey: string) => Promise<void>;
5
+ export declare const deleteDBAddressBookEntry: (username?: string, peerId?: string, peerPublicKey?: string) => Promise<string>;
6
+ export declare const getDBPeerIsBlacklisted: (peerId?: string, peerPublicKey?: string) => Promise<boolean>;
7
+ export declare const getAllDBBlacklisted: () => Promise<import("./types").BlacklistedPeer[]>;
8
+ export declare const setDBPeerInBlacklist: (peerId: string, peerPublicKey: string) => Promise<void>;
9
+ export declare const deleteDBPeerFromBlacklist: (peerId?: string, peerPublicKey?: string) => Promise<void>;
10
+ export declare const getAllDBUniqueRooms: () => Promise<import("./types").UniqueRoom[]>;
11
+ export declare const setDBUniqueRoom: (roomUrl: string, roomId: string) => Promise<void>;
12
+ export declare const getDBMessageData: (merkleRootHex?: string, hashHex?: string) => Promise<import("./types").MessageData | undefined>;
13
+ export declare const getDBRoomMessageData: (roomId: string) => Promise<import("./types").MessageData[]>;
14
+ export declare const setDBRoomMessageData: (roomId: string, merkleRootHex: string, sha512Hex: string, fromPeerId: string, chunkSize: number, totalSize: number, messageType: number, // MessageType,
15
+ filename: string, channelLabel: string, timestamp: number) => Promise<void>;
16
+ export declare const getDBChunk: (hashHex: string, chunkIndex: number) => Promise<ArrayBuffer | undefined>;
17
+ export declare const existsDBChunk: (hashHex: string, chunkIndex: number) => Promise<boolean>;
18
+ export declare const getDBNewChunk: (hashHex: string, chunkIndex?: number) => Promise<NewChunk | undefined>;
19
+ export declare const existsDBNewChunk: (hashHex: string, chunkIndex: number) => Promise<boolean>;
20
+ export declare const getDBSendQueue: (label: string, toPeerId: string) => Promise<SendQueue[]>;
21
+ export declare const getDBAllChunks: (merkleRootHex?: string, hashHex?: string) => Promise<Chunk[]>;
22
+ export declare const getDBAllChunksCount: (merkleRootHex?: string, hashHex?: string) => Promise<number>;
23
+ export declare const setDBChunk: (chunk: Chunk) => Promise<void>;
24
+ export declare const getDBAllNewChunks: (hashHex?: string, merkleRootHex?: string) => Promise<NewChunk[]>;
25
+ export declare const getDBAllNewChunksCount: (hashHex: string) => Promise<number>;
26
+ export declare const setDBNewChunk: (chunk: NewChunk) => Promise<void>;
27
+ export declare const setDBSendQueue: (item: SendQueue) => Promise<void>;
28
+ export declare const countDBSendQueue: (label: string, toPeerId: string) => Promise<number>;
29
+ export declare const deleteDBChunk: (hashHex: string, chunkIndex?: number) => Promise<void>;
30
+ export declare const deleteDBNewChunk: (merkleRootHex?: string, realChunkHashHex?: string, hashHex?: string, chunkIndex?: number) => Promise<void>;
31
+ export declare const deleteDBMessageData: (merkleRootHex: string) => Promise<void>;
32
+ export declare const deleteDBUniqueRoom: (roomId: string) => Promise<void>;
33
+ export declare const deleteDB: () => Promise<void>;
34
+ export declare const deleteDBSendQueue: (label: string, toPeerId: string, position?: number) => Promise<void>;
35
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=db.worker.d.ts.map
@@ -0,0 +1,68 @@
1
+ import type { DBSchema, IDBPDatabase } from "idb";
2
+ import type { MessageData, Chunk, SendQueue, AddressBook, BlacklistedPeer, UniqueRoom, NewChunk } from "../types";
3
+ export declare const dbName = "p2party";
4
+ export declare const dbVersion = 16;
5
+ export interface RepoSchema extends DBSchema {
6
+ addressBook: {
7
+ value: AddressBook;
8
+ key: [string];
9
+ indexes: {
10
+ peerId: string;
11
+ peerPublicKey: string;
12
+ username: string;
13
+ };
14
+ };
15
+ blacklist: {
16
+ value: BlacklistedPeer;
17
+ key: [string];
18
+ indexes: {
19
+ peerId: string;
20
+ peerPublicKey: string;
21
+ username: string;
22
+ };
23
+ };
24
+ uniqueRoom: {
25
+ value: UniqueRoom;
26
+ key: [string];
27
+ indexes: {
28
+ roomId: string;
29
+ roomUrl: string;
30
+ };
31
+ };
32
+ messageData: {
33
+ value: MessageData;
34
+ key: [number, string, string];
35
+ indexes: {
36
+ roomId: string;
37
+ hash: string;
38
+ merkleRoot: string;
39
+ fromPeerId: string;
40
+ };
41
+ };
42
+ chunks: {
43
+ value: Chunk;
44
+ key: [string, number];
45
+ indexes: {
46
+ merkleRoot: string;
47
+ hash: string;
48
+ };
49
+ };
50
+ newChunks: {
51
+ value: NewChunk;
52
+ key: [string, number];
53
+ indexes: {
54
+ hash: string;
55
+ merkleRoot: string;
56
+ realChunkHash: string;
57
+ };
58
+ };
59
+ sendQueue: {
60
+ value: SendQueue;
61
+ key: [number, string, string];
62
+ indexes: {
63
+ labelPeer: string;
64
+ };
65
+ };
66
+ }
67
+ export declare function getDB(): Promise<IDBPDatabase<RepoSchema>>;
68
+ //# sourceMappingURL=getDB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDB.d.ts","sourceRoot":"","sources":["../../../src/db/src/getDB.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AAClD,OAAO,KAAK,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,WAAW,EACX,eAAe,EACf,UAAU,EACV,QAAQ,EACT,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,MAAM,YAAY,CAAC;AAChC,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,MAAM,WAAW,UAAW,SAAQ,QAAQ;IAC1C,WAAW,EAAE;QACX,KAAK,EAAE,WAAW,CAAC;QACnB,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;QACd,OAAO,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC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