-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make crypto functionality tree-shakable
We move the crypto functionality into a tree-shakable Crypto module. Then, we split the decodeMessage* functions introduced in 601b46b in two; we introduce new decodeEncryptedMessage* variants which import the Crypto module and are hence able to decrypt encrypted messages, and we change the existing functions to not import the Crypto module and to fail if they are given cipher options. Resolves #1396.
- Loading branch information
1 parent
601b46b
commit 63f5524
Showing
12 changed files
with
191 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { Rest } from './rest'; | ||
import { IUntypedCryptoStatic } from '../../types/ICryptoStatic'; | ||
|
||
export interface ModulesMap { | ||
Rest?: typeof Rest; | ||
Crypto?: IUntypedCryptoStatic; | ||
} | ||
|
||
export const allCommonModules: ModulesMap = { Rest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import BufferUtils from '../lib/util/bufferutils'; | ||
import { createCryptoClass } from '../lib/util/crypto'; | ||
import Config from '../config'; | ||
import * as API from '../../../../ably'; | ||
import Platform from 'common/platform'; | ||
|
||
export const Crypto = /* @__PURE__@ */ createCryptoClass(Config, BufferUtils); | ||
|
||
export const generateRandomKey: API.Types.Crypto['generateRandomKey'] = (keyLength) => { | ||
return Platform.Crypto!.generateRandomKey(keyLength); | ||
return Crypto.generateRandomKey(keyLength); | ||
}; | ||
|
||
export const getDefaultCryptoParams: API.Types.Crypto['getDefaultParams'] = (params) => { | ||
return Platform.Crypto!.getDefaultParams(params); | ||
return Crypto.getDefaultParams(params); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import * as API from '../../../../ably'; | ||
import Platform from 'common/platform'; | ||
import { Crypto } from './crypto'; | ||
import { fromEncoded, fromEncodedArray } from '../../../common/lib/types/message'; | ||
|
||
// The type assertions for the decode* functions below are due to https://github.com/ably/ably-js/issues/1421 | ||
|
||
export const decodeMessage = ((obj, options) => { | ||
return fromEncoded(Platform.Crypto, obj, options); | ||
return fromEncoded(null, obj, options); | ||
}) as API.Types.MessageStatic['fromEncoded']; | ||
|
||
export const decodeEncryptedMessage = ((obj, options) => { | ||
return fromEncoded(Crypto, obj, options); | ||
}) as API.Types.MessageStatic['fromEncoded']; | ||
|
||
export const decodeMessages = ((obj, options) => { | ||
return fromEncodedArray(Platform.Crypto, obj, options); | ||
return fromEncodedArray(null, obj, options); | ||
}) as API.Types.MessageStatic['fromEncodedArray']; | ||
|
||
export const decodeEncryptedMessages = ((obj, options) => { | ||
return fromEncodedArray(Crypto, obj, options); | ||
}) as API.Types.MessageStatic['fromEncodedArray']; |
Oops, something went wrong.