@wireapp/core-crypto 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wireapp/core-crypto",
3
- "version": "0.4.0",
4
- "description": "CoreCrypto bindings for the Web - Dev version",
3
+ "version": "0.5.1",
4
+ "description": "CoreCrypto bindings for the Web",
5
5
  "type": "module",
6
6
  "module": "platforms/web/corecrypto.js",
7
7
  "types": "platforms/web/corecrypto.d.js",
@@ -40,24 +40,24 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@rollup/plugin-html": "^0.2.4",
43
- "@types/jest": "^28.1.6",
43
+ "@types/jest": "^29.0.1",
44
44
  "@types/jest-dev-server": "^5.0.0",
45
- "@typescript-eslint/eslint-plugin": "^5.33.0",
46
- "@typescript-eslint/parser": "^5.33.0",
47
- "@wasm-tool/rollup-plugin-rust": "^2.2.2",
48
- "dts-bundle-generator": "^6.12.0",
49
- "eslint": "^8.21.0",
45
+ "@typescript-eslint/eslint-plugin": "^5.36.2",
46
+ "@typescript-eslint/parser": "^5.36.2",
47
+ "@wasm-tool/rollup-plugin-rust": "^2.3.1",
48
+ "dts-bundle-generator": "^6.13.0",
49
+ "eslint": "^8.23.1",
50
50
  "eslint-config-prettier": "^8.5.0",
51
51
  "eslint-plugin-prettier": "^4.2.1",
52
- "jest": "^28.1.3",
52
+ "jest": "^29.0.3",
53
53
  "jest-dev-server": "^6.1.1",
54
54
  "prettier": "^2.7.1",
55
- "puppeteer": "^16.1.0",
56
- "rollup": "^2.77.2",
55
+ "puppeteer": "^17.1.3",
56
+ "rollup": "^2.79.0",
57
57
  "rollup-jest": "^3.0.0",
58
58
  "rollup-plugin-ts": "^3.0.2",
59
- "ts-jest": "^28.0.7",
59
+ "ts-jest": "^29.0.0",
60
60
  "ts-loader": "^9.3.1",
61
- "typescript": "^4.7.4"
61
+ "typescript": "^4.8.3"
62
62
  }
63
63
  }
@@ -189,7 +189,10 @@ export interface DecryptedMessage {
189
189
  */
190
190
  message?: Uint8Array;
191
191
  /**
192
- * List of proposals that were retrieved from the decrypted message, in addition to the pending local proposals
192
+ * Only when decrypted message is a commit, CoreCrypto will renew local proposal which could not make it in the commit.
193
+ * This will contain either:
194
+ * * local pending proposal not in the accepted commit
195
+ * * If there is a pending commit, its proposals which are not in the accepted commit
193
196
  */
194
197
  proposals: ProposalBundle[];
195
198
  /**
@@ -216,7 +219,7 @@ export interface ProposalBundle {
216
219
  */
217
220
  proposal: Uint8Array;
218
221
  /**
219
- * Unique identifier of a proposal. Use this in {@link CoreCrypto.clear_pending_proposal} to roll back (delete) the proposal
222
+ * Unique identifier of a proposal. Use this in {@link CoreCrypto.clearPendingProposal} to roll back (delete) the proposal
220
223
  *
221
224
  * @readonly
222
225
  */
@@ -225,7 +228,7 @@ export interface ProposalBundle {
225
228
  /**
226
229
  * MLS Proposal type
227
230
  */
228
- export declare const enum ProposalType {
231
+ export declare enum ProposalType {
229
232
  /**
230
233
  * This allows to propose the addition of other clients to the MLS group/conversation
231
234
  */
@@ -269,7 +272,7 @@ export interface RemoveProposalArgs extends ProposalArgs {
269
272
  /**
270
273
  * MLS External Proposal type
271
274
  */
272
- export declare const enum ExternalProposalType {
275
+ export declare enum ExternalProposalType {
273
276
  /**
274
277
  * This allows to propose the addition of other clients to the MLS group/conversation
275
278
  */
@@ -296,6 +299,25 @@ export interface ExternalRemoveProposalArgs extends ExternalProposalArgs {
296
299
  */
297
300
  keyPackageRef: Uint8Array;
298
301
  }
302
+ export interface CoreCryptoCallbacks {
303
+ /**
304
+ * This callback is called by CoreCrypto to know whether a given clientId is authorized to "write"
305
+ * in the given conversationId. Think of it as a "isAdmin" callback conceptually
306
+ *
307
+ * This callback exists because there are many business cases where CoreCrypto doesn't have enough knowledge
308
+ * (such as what can exists on a backend) to inform the decision
309
+ *
310
+ * @param conversationId - id of the group/conversation
311
+ * @param clientId - id of the client performing an operation requiring authorization
312
+ * @returns whether the user is authorized by the logic layer to perform the operation
313
+ */
314
+ authorize: (conversationId: Uint8Array, clientId: Uint8Array) => boolean;
315
+ /**
316
+ * Callback to ensure that the given `clientId` belongs to one of the provided `otherClients`
317
+ * This basically allows to defer the client ID parsing logic to the caller - because CoreCrypto is oblivious to such things
318
+ */
319
+ clientIdBelongsToOneOf: (clientId: Uint8Array, otherClients: Uint8Array[]) => boolean;
320
+ }
299
321
  /**
300
322
  * Wrapper for the WASM-compiled version of CoreCrypto
301
323
  */
@@ -349,6 +371,12 @@ export declare class CoreCrypto {
349
371
  * **CAUTION**: This {@link CoreCrypto} instance won't be useable after a call to this method, but there's no way to express this requirement in TypeScript so you'll get errors instead!
350
372
  */
351
373
  close(): Promise<void>;
374
+ /**
375
+ * Registers the callbacks for CoreCrypto to use in order to gain additional information
376
+ *
377
+ * @param callbacks - Any interface following the {@link CoreCryptoCallbacks} interface
378
+ */
379
+ registerCallbacks(callbacks: CoreCryptoCallbacks): void;
352
380
  /**
353
381
  * Checks if the Client is member of a given conversation and if the MLS Group is loaded up
354
382
  *
@@ -402,7 +430,7 @@ export declare class CoreCrypto {
402
430
  * @param conversationId - The ID of the conversation
403
431
  * @param payload - The encrypted message buffer
404
432
  *
405
- * @returns Either a {@link DecryptedMessage} payload or `undefined` - This happens when the encrypted payload contains a system message such a proposal or commit
433
+ * @returns a {@link DecryptedMessage}. Note that {@link DecryptedMessage#message} is `undefined` when the encrypted payload contains a system message such a proposal or commit
406
434
  */
407
435
  decryptMessage(conversationId: ConversationId, payload: Uint8Array): Promise<DecryptedMessage>;
408
436
  /**
@@ -460,7 +488,7 @@ export declare class CoreCrypto {
460
488
  * @param conversationId - The ID of the conversation
461
489
  * @param clientIds - Array of Client IDs to remove.
462
490
  *
463
- * @returns A {@link CommitBundle}, or `undefined` if for any reason, the operation would result in an empty commit
491
+ * @returns A {@link CommitBundle}
464
492
  */
465
493
  removeClientsFromConversation(conversationId: ConversationId, clientIds: ClientId[]): Promise<CommitBundle>;
466
494
  /**
@@ -484,9 +512,9 @@ export declare class CoreCrypto {
484
512
  *
485
513
  * @param conversationId - The ID of the conversation
486
514
  *
487
- * @returns A {@link CommitBundle}
515
+ * @returns A {@link CommitBundle} or `undefined` when there was no pending proposal to commit
488
516
  */
489
- commitPendingProposals(conversationId: ConversationId): Promise<CommitBundle>;
517
+ commitPendingProposals(conversationId: ConversationId): Promise<CommitBundle | undefined>;
490
518
  /**
491
519
  * Adds new clients to a conversation, assuming the current client has the right to add new clients to the conversation.
492
520
  * The returned {@link CommitBundle} is a TLS struct that needs to be fanned out to Delivery Service in order to validate the commit.
@@ -550,9 +578,9 @@ export declare class CoreCrypto {
550
578
  *
551
579
  * @param conversationId - The ID of the conversation
552
580
  *
553
- * @returns A {@link CommitBundle} byte array to fan out to the Delivery Service
581
+ * @returns A {@link CommitBundle} byte array to fan out to the Delivery Service or `undefined` when there was no pending proposal to commit
554
582
  */
555
- finalCommitPendingProposals(conversationId: ConversationId): Promise<TlsCommitBundle>;
583
+ finalCommitPendingProposals(conversationId: ConversationId): Promise<TlsCommitBundle | undefined>;
556
584
  /**
557
585
  * Creates a new proposal for the provided Conversation ID
558
586
  *
@@ -595,21 +623,6 @@ export declare class CoreCrypto {
595
623
  * @param conversationId - The group's ID
596
624
  */
597
625
  commitAccepted(conversationId: ConversationId): Promise<void>;
598
- /**
599
- * Allows {@link CoreCrypto} to act as a CSPRNG provider
600
- * @note The underlying CSPRNG algorithm is ChaCha20 and takes in account the external seed provider either at init time or provided with {@link CoreCrypto.reseedRng}
601
- *
602
- * @param length - The number of bytes to be returned in the `Uint8Array`
603
- *
604
- * @returns A `Uint8Array` buffer that contains `length` cryptographically-secure random bytes
605
- */
606
- randomBytes(length: number): Promise<Uint8Array>;
607
- /**
608
- * Allows to reseed {@link CoreCrypto}'s internal CSPRNG with a new seed.
609
- *
610
- * @param seed - **exactly 32** bytes buffer seed
611
- */
612
- reseedRng(seed: Uint8Array): Promise<void>;
613
626
  /**
614
627
  * Allows to remove a pending proposal (rollback). Use this when backend rejects the proposal you just sent e.g. if permissions
615
628
  * have changed meanwhile.
@@ -620,7 +633,7 @@ export declare class CoreCrypto {
620
633
  * @param conversationId - The group's ID
621
634
  * @param proposalRef - A reference to the proposal to delete. You get one when using {@link CoreCrypto.newProposal}
622
635
  */
623
- clear_pending_proposal(conversationId: ConversationId, proposalRef: ProposalRef): Promise<void>;
636
+ clearPendingProposal(conversationId: ConversationId, proposalRef: ProposalRef): Promise<void>;
624
637
  /**
625
638
  * Allows to remove a pending commit (rollback). Use this when backend rejects the commit you just sent e.g. if permissions
626
639
  * have changed meanwhile.
@@ -632,7 +645,22 @@ export declare class CoreCrypto {
632
645
  *
633
646
  * @param conversationId - The group's ID
634
647
  */
635
- clear_pending_commit(conversationId: ConversationId): Promise<void>;
648
+ clearPendingCommit(conversationId: ConversationId): Promise<void>;
649
+ /**
650
+ * Allows {@link CoreCrypto} to act as a CSPRNG provider
651
+ * @note The underlying CSPRNG algorithm is ChaCha20 and takes in account the external seed provider either at init time or provided with {@link CoreCrypto.reseedRng}
652
+ *
653
+ * @param length - The number of bytes to be returned in the `Uint8Array`
654
+ *
655
+ * @returns A `Uint8Array` buffer that contains `length` cryptographically-secure random bytes
656
+ */
657
+ randomBytes(length: number): Promise<Uint8Array>;
658
+ /**
659
+ * Allows to reseed {@link CoreCrypto}'s internal CSPRNG with a new seed.
660
+ *
661
+ * @param seed - **exactly 32** bytes buffer seed
662
+ */
663
+ reseedRng(seed: Uint8Array): Promise<void>;
636
664
  /**
637
665
  * Returns the current version of {@link CoreCrypto}
638
666
  *