@wireapp/core-crypto 0.4.0 → 0.5.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/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.0",
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
  }
@@ -216,7 +216,7 @@ export interface ProposalBundle {
216
216
  */
217
217
  proposal: Uint8Array;
218
218
  /**
219
- * Unique identifier of a proposal. Use this in {@link CoreCrypto.clear_pending_proposal} to roll back (delete) the proposal
219
+ * Unique identifier of a proposal. Use this in {@link CoreCrypto.clearPendingProposal} to roll back (delete) the proposal
220
220
  *
221
221
  * @readonly
222
222
  */
@@ -225,7 +225,7 @@ export interface ProposalBundle {
225
225
  /**
226
226
  * MLS Proposal type
227
227
  */
228
- export declare const enum ProposalType {
228
+ export declare enum ProposalType {
229
229
  /**
230
230
  * This allows to propose the addition of other clients to the MLS group/conversation
231
231
  */
@@ -269,7 +269,7 @@ export interface RemoveProposalArgs extends ProposalArgs {
269
269
  /**
270
270
  * MLS External Proposal type
271
271
  */
272
- export declare const enum ExternalProposalType {
272
+ export declare enum ExternalProposalType {
273
273
  /**
274
274
  * This allows to propose the addition of other clients to the MLS group/conversation
275
275
  */
@@ -296,6 +296,25 @@ export interface ExternalRemoveProposalArgs extends ExternalProposalArgs {
296
296
  */
297
297
  keyPackageRef: Uint8Array;
298
298
  }
299
+ export interface CoreCryptoCallbacks {
300
+ /**
301
+ * This callback is called by CoreCrypto to know whether a given clientId is authorized to "write"
302
+ * in the given conversationId. Think of it as a "isAdmin" callback conceptually
303
+ *
304
+ * This callback exists because there are many business cases where CoreCrypto doesn't have enough knowledge
305
+ * (such as what can exists on a backend) to inform the decision
306
+ *
307
+ * @param conversationId - id of the group/conversation
308
+ * @param clientId - id of the client performing an operation requiring authorization
309
+ * @returns whether the user is authorized by the logic layer to perform the operation
310
+ */
311
+ authorize: (conversationId: Uint8Array, clientId: Uint8Array) => boolean;
312
+ /**
313
+ * Callback to ensure that the given `clientId` belongs to one of the provided `otherClients`
314
+ * This basically allows to defer the client ID parsing logic to the caller - because CoreCrypto is oblivious to such things
315
+ */
316
+ clientIdBelongsToOneOf: (clientId: Uint8Array, otherClients: Uint8Array[]) => boolean;
317
+ }
299
318
  /**
300
319
  * Wrapper for the WASM-compiled version of CoreCrypto
301
320
  */
@@ -349,6 +368,12 @@ export declare class CoreCrypto {
349
368
  * **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
369
  */
351
370
  close(): Promise<void>;
371
+ /**
372
+ * Registers the callbacks for CoreCrypto to use in order to gain additional information
373
+ *
374
+ * @param callbacks - Any interface following the {@link CoreCryptoCallbacks} interface
375
+ */
376
+ registerCallbacks(callbacks: CoreCryptoCallbacks): void;
352
377
  /**
353
378
  * Checks if the Client is member of a given conversation and if the MLS Group is loaded up
354
379
  *
@@ -402,7 +427,7 @@ export declare class CoreCrypto {
402
427
  * @param conversationId - The ID of the conversation
403
428
  * @param payload - The encrypted message buffer
404
429
  *
405
- * @returns Either a {@link DecryptedMessage} payload or `undefined` - This happens when the encrypted payload contains a system message such a proposal or commit
430
+ * @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
431
  */
407
432
  decryptMessage(conversationId: ConversationId, payload: Uint8Array): Promise<DecryptedMessage>;
408
433
  /**
@@ -460,7 +485,7 @@ export declare class CoreCrypto {
460
485
  * @param conversationId - The ID of the conversation
461
486
  * @param clientIds - Array of Client IDs to remove.
462
487
  *
463
- * @returns A {@link CommitBundle}, or `undefined` if for any reason, the operation would result in an empty commit
488
+ * @returns A {@link CommitBundle}
464
489
  */
465
490
  removeClientsFromConversation(conversationId: ConversationId, clientIds: ClientId[]): Promise<CommitBundle>;
466
491
  /**
@@ -484,9 +509,9 @@ export declare class CoreCrypto {
484
509
  *
485
510
  * @param conversationId - The ID of the conversation
486
511
  *
487
- * @returns A {@link CommitBundle}
512
+ * @returns A {@link CommitBundle} or `undefined` when there was no pending proposal to commit
488
513
  */
489
- commitPendingProposals(conversationId: ConversationId): Promise<CommitBundle>;
514
+ commitPendingProposals(conversationId: ConversationId): Promise<CommitBundle | undefined>;
490
515
  /**
491
516
  * Adds new clients to a conversation, assuming the current client has the right to add new clients to the conversation.
492
517
  * 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 +575,9 @@ export declare class CoreCrypto {
550
575
  *
551
576
  * @param conversationId - The ID of the conversation
552
577
  *
553
- * @returns A {@link CommitBundle} byte array to fan out to the Delivery Service
578
+ * @returns A {@link CommitBundle} byte array to fan out to the Delivery Service or `undefined` when there was no pending proposal to commit
554
579
  */
555
- finalCommitPendingProposals(conversationId: ConversationId): Promise<TlsCommitBundle>;
580
+ finalCommitPendingProposals(conversationId: ConversationId): Promise<TlsCommitBundle | undefined>;
556
581
  /**
557
582
  * Creates a new proposal for the provided Conversation ID
558
583
  *
@@ -595,21 +620,6 @@ export declare class CoreCrypto {
595
620
  * @param conversationId - The group's ID
596
621
  */
597
622
  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
623
  /**
614
624
  * Allows to remove a pending proposal (rollback). Use this when backend rejects the proposal you just sent e.g. if permissions
615
625
  * have changed meanwhile.
@@ -620,7 +630,7 @@ export declare class CoreCrypto {
620
630
  * @param conversationId - The group's ID
621
631
  * @param proposalRef - A reference to the proposal to delete. You get one when using {@link CoreCrypto.newProposal}
622
632
  */
623
- clear_pending_proposal(conversationId: ConversationId, proposalRef: ProposalRef): Promise<void>;
633
+ clearPendingProposal(conversationId: ConversationId, proposalRef: ProposalRef): Promise<void>;
624
634
  /**
625
635
  * Allows to remove a pending commit (rollback). Use this when backend rejects the commit you just sent e.g. if permissions
626
636
  * have changed meanwhile.
@@ -632,7 +642,22 @@ export declare class CoreCrypto {
632
642
  *
633
643
  * @param conversationId - The group's ID
634
644
  */
635
- clear_pending_commit(conversationId: ConversationId): Promise<void>;
645
+ clearPendingCommit(conversationId: ConversationId): Promise<void>;
646
+ /**
647
+ * Allows {@link CoreCrypto} to act as a CSPRNG provider
648
+ * @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}
649
+ *
650
+ * @param length - The number of bytes to be returned in the `Uint8Array`
651
+ *
652
+ * @returns A `Uint8Array` buffer that contains `length` cryptographically-secure random bytes
653
+ */
654
+ randomBytes(length: number): Promise<Uint8Array>;
655
+ /**
656
+ * Allows to reseed {@link CoreCrypto}'s internal CSPRNG with a new seed.
657
+ *
658
+ * @param seed - **exactly 32** bytes buffer seed
659
+ */
660
+ reseedRng(seed: Uint8Array): Promise<void>;
636
661
  /**
637
662
  * Returns the current version of {@link CoreCrypto}
638
663
  *