Skip to content

Commit a3b334b

Browse files
committed
Improve diff documentation
1 parent c3ae6b7 commit a3b334b

File tree

18 files changed

+110
-5
lines changed

18 files changed

+110
-5
lines changed

packages/crypto-ie11-detection/lib/CryptoOperation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import {Key} from "./Key";
22

3+
/**
4+
* Represents a cryptographic operation that has been instantiated but not
5+
* necessarily fed all data or finalized.
6+
*
7+
* @see https://msdn.microsoft.com/en-us/library/dn280996(v=vs.85).aspx
8+
*/
39
export interface CryptoOperation {
410
readonly algorithm: string;
511
readonly key: Key;

packages/crypto-ie11-detection/lib/Key.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* The result of a successful KeyOperation.
3+
*
4+
* @see {KeyOperation}
5+
* @see https://msdn.microsoft.com/en-us/library/dn302313(v=vs.85).aspx
6+
*/
17
export interface Key {
28
readonly algorithm: string;
39
readonly extractable: boolean;

packages/crypto-ie11-detection/lib/KeyOperation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import {Key} from "./Key";
22

3+
/**
4+
* Represents the return of a key-related operation that may or may not have
5+
* been completed.
6+
*
7+
* @see https://msdn.microsoft.com/en-us/library/dn302314(v=vs.85).aspx
8+
*/
39
export interface KeyOperation {
410
oncomplete: (event: Event) => void;
511
onerror: (event: Event) => void;

packages/crypto-ie11-detection/lib/MsSubtleCrypto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export interface HmacAlgorithm {
1919

2020
export type SigningAlgorithm = HmacAlgorithm;
2121

22+
/**
23+
* Represent ths SubtleCrypto interface as implemented in Internet Explorer 11.
24+
* This implementation was based on an earlier version of the WebCrypto API and
25+
* differs from the `window.crypto.subtle` object exposed in Chrome, Safari,
26+
* Firefox, and MS Edge.
27+
*
28+
* @see https://msdn.microsoft.com/en-us/library/dn302325(v=vs.85).aspx
29+
*/
2230
export interface MsSubtleCrypto {
2331
decrypt(
2432
algorithm: Ie11EncryptionAlgorithm,

packages/crypto-ie11-detection/lib/MsWindow.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {isNativeCode} from './isNativeCode';
22
import {MsSubtleCrypto} from "./MsSubtleCrypto";
33

4-
export type SubtleCryptoMethod = 'decrypt'|'digest'|'encrypt'|'exportKey'|'generateKey'|'importKey'|'sign'|'verify';
4+
type SubtleCryptoMethod = 'decrypt'|'digest'|'encrypt'|'exportKey'|'generateKey'|'importKey'|'sign'|'verify';
55

66
const msSubtleCryptoMethods: Array<SubtleCryptoMethod> = [
77
'decrypt',
@@ -14,11 +14,18 @@ const msSubtleCryptoMethods: Array<SubtleCryptoMethod> = [
1414
'verify',
1515
];
1616

17+
/**
18+
* The value accessible as `window.msCrypto` in Internet Explorer 11.
19+
*/
1720
export interface MsCrypto {
1821
getRandomValues: (toFill: Uint8Array) => void;
1922
subtle: MsSubtleCrypto;
2023
}
2124

25+
/**
26+
* The `window` object in Internet Explorer 11. This interface does not
27+
* exhaustively document the prefixed features of `window` in IE11.
28+
*/
2229
export interface MsWindow extends Window {
2330
MSInputMethodContext: any;
2431
msCrypto: MsCrypto;

packages/crypto-ie11-detection/lib/isNativeCode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
const nativeCodeRegex = /\[native code]/;
22

3+
/**
4+
* A best-effort check to see if a function is user-defined or provided by the
5+
* browser. This is a heuristic rather than something 100% accurate.
6+
*
7+
* @internal
8+
*/
39
export function isNativeCode(func: Function): boolean {
410
try {
511
if (nativeCodeRegex.test(Function.prototype.toString.call(func))) {

packages/crypto-ie11-detection/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"target": "es5",
55
"strict": true,
66
"sourceMap": true,
7-
"declaration": true
7+
"declaration": true,
8+
"stripInternal": true
89
}
910
}

packages/crypto-random-source-browser/lib/ie11RandomValues.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {MsWindow} from '@aws/crypto-ie11-detection';
2+
import {randomValues as IRandomValues} from '@aws/types';
23

4+
/**
5+
* @implements {IRandomValues}
6+
*/
37
export function randomValues(byteLength: number): Promise<Uint8Array> {
48
return new Promise(resolve => {
59
const randomBytes = new Uint8Array(byteLength);

packages/crypto-random-source-browser/lib/jsRandomValues.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
startCollectors,
66
stopCollectors,
77
} from '@aws/crypto-sjcl-random';
8+
import {randomValues as IRandomValues} from '@aws/types';
89

10+
/**
11+
* @implements {IRandomValues}
12+
*/
913
export function randomValues(byteLength: number): Promise<Uint8Array> {
1014
return new Promise((resolve, reject) => {
1115
if (!isReady()) {

packages/crypto-random-source-browser/lib/webCryptoRandomValues.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {randomValues as IRandomValues} from '@aws/types';
2+
3+
/**
4+
* @implements {IRandomValues}
5+
*/
16
export function randomValues(byteLength: number): Promise<Uint8Array> {
27
return new Promise(resolve => {
38
const randomBytes = new Uint8Array(byteLength);

packages/crypto-random-source-browser/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"@aws/crypto-ie11-detection": "^0.0.1",
1414
"@aws/crypto-sjcl-random": "^0.0.1",
1515
"@aws/crypto-sjcl-codecArrayBuffer": "^0.0.1",
16-
"@aws/crypto-supports-webCrypto": "^0.0.1"
16+
"@aws/crypto-supports-webCrypto": "^0.0.1",
17+
"@aws/types": "^0.0.1"
1718
},
1819
"devDependencies": {
1920
"@types/jest": "^19.2.2",

packages/crypto-random-source-node/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {randomBytes} from 'crypto';
2+
import {randomValues as IRandomValues} from '@aws/types';
23

4+
/**
5+
* @implements {IRandomValues}
6+
*/
37
export function randomValues(byteLength: number): Promise<Uint8Array> {
48
return new Promise<Buffer>((resolve, reject) => {
59
randomBytes(byteLength, (err: Error, buf: Buffer) => {

packages/crypto-random-source-node/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
},
1010
"author": "[email protected]",
1111
"license": "UNLICENSED",
12+
"dependencies": {
13+
"@aws/types": "^0.0.1"
14+
},
1215
"devDependencies": {
1316
"@types/jest": "^19.2.2",
1417
"@types/node": "^7.0.12",

packages/crypto-random-source-universal/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
import {
66
randomValues as nodeRandomValues
77
} from '@aws/crypto-random-source-node';
8+
import {randomValues as IRandomValues} from '@aws/types';
89

10+
/**
11+
* @implements {IRandomValues}
12+
*/
913
export function randomValues(byteLength: number): Promise<Uint8Array> {
1014
if (isNode()) {
1115
return nodeRandomValues(byteLength);

packages/crypto-random-source-universal/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dependencies": {
1313
"@aws/crypto-random-source-browser": "^0.0.1",
1414
"@aws/crypto-random-source-node": "^0.0.1",
15-
"@aws/is-node": "^0.0.1"
15+
"@aws/is-node": "^0.0.1",
16+
"@aws/types": "^0.0.1"
1617
},
1718
"devDependencies": {
1819
"@types/jest": "^19.2.2",

packages/crypto-supports-webCrypto/lib/isNativeCode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
const nativeCodeRegex = /\[native code]/;
22

3+
/**
4+
* A best-effort check to see if a function is user-defined or provided by the
5+
* browser. This is a heuristic rather than something 100% accurate.
6+
*
7+
* @internal
8+
*/
39
export function isNativeCode(func: Function): boolean {
410
try {
511
if (nativeCodeRegex.test(Function.prototype.toString.call(func))) {

packages/is-node/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Detects if the function is invoked within a Node.JS environment based on the
3+
* presence of `process` global variable and its `toString` output.
4+
*/
15
export function isNode(): boolean {
2-
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
6+
return Object.prototype.toString.call(
7+
typeof process !== 'undefined' ? process : 0
8+
) === '[object process]';
39
}

packages/types/crypto.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
export type SourceData = string|ArrayBuffer|ArrayBufferView;
22

3+
/**
4+
* An object that provides a hash of data provided in chunks to `update`. The
5+
* hash may be performed incrementally as chunks are received or all at once
6+
* when the hash is finalized, depending on the underlying implementation.
7+
*/
38
export interface Hash {
9+
/**
10+
* Adds a chunk of data to the hash. If a buffer is provided, the `encoding`
11+
* argument will be ignored. If a string is provided without a specified
12+
* encoding, implementations must assume UTF-8 encoding.
13+
*
14+
* Not all encodings are supported on all platforms, though all must support
15+
* UTF-8.
16+
*/
417
update(toHash: SourceData, encoding?: 'utf8'|'ascii'|'latin1'): void;
18+
19+
/**
20+
* Finalizes the hash and provides a promise that will be fulfilled with the
21+
* raw bytes of the calculated hash.
22+
*/
523
digest(): Promise<Uint8Array>;
624
}
725

26+
/**
27+
* A constructor for a hash that may be used to calculate an HMAC. Implementing
28+
* classes should not directly hold the provided key in memory beyond the
29+
* lexical scope of the constructor.
30+
*/
831
export interface HashConstructor {
932
new (secret?: SourceData): Hash;
1033
}
1134

35+
/**
36+
* A function that returns a promise fulfilled with bytes from a
37+
* cryptographically secure pseudorandom number generator.
38+
*/
1239
export interface randomValues {
1340
(byteLength: number): Promise<Uint8Array>;
1441
}

0 commit comments

Comments
 (0)