Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #61 from microshine/master
Browse files Browse the repository at this point in the history
Update d.ts and module init
  • Loading branch information
alokmenghrajani authored Sep 18, 2017
2 parents 11c32ee + f13718d commit eca0ed8
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 92 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage/
node_modules
.idea
.idea

package-lock.json
4 changes: 3 additions & 1 deletion dist/jose-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ exports.setCrypto = function (cp) {
/**
* Default to the global "crypto" variable
*/
exports.setCrypto(crypto);
if (typeof(crypto) !== 'undefined') {
exports.setCrypto(crypto);
}

/**
* Use Node versions of atob, btoa functions outside the browser
Expand Down
4 changes: 3 additions & 1 deletion dist/jose-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ exports.setCrypto = function (cp) {
/**
* Default to the global "crypto" variable
*/
exports.setCrypto(crypto);
if (typeof(crypto) !== 'undefined') {
exports.setCrypto(crypto);
}

/**
* Use Node versions of atob, btoa functions outside the browser
Expand Down
4 changes: 3 additions & 1 deletion dist/jose.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ exports.setCrypto = function (cp) {
/**
* Default to the global "crypto" variable
*/
exports.setCrypto(crypto);
if (typeof(crypto) !== 'undefined') {
exports.setCrypto(crypto);
}

/**
* Use Node versions of atob, btoa functions outside the browser
Expand Down
2 changes: 1 addition & 1 deletion dist/jose.min.js

Large diffs are not rendered by default.

137 changes: 79 additions & 58 deletions jose-jwe-jws.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
export interface EncryptionResult {
// Type definitions for jose-jwe-jws
// Project: jose-jwe-jws
// Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>

interface IEncryptionResult {
cipher: ArrayBuffer;
tag: ArrayBuffer;
}

export interface VerificationResult {
interface IVerificationResult {
kid: string;
verified: boolean;
payload?: string;
}

export interface WebCryptographer {
new(): WebCryptographer;
setKeyEncryptionAlgorithm(algo: string):void;
setContentSignAlgorithm(algo: string):void;
createIV():ArrayBufferView;
createCek():PromiseLike<CryptoKey>;
wrapCek():PromiseLike<ArrayBuffer>;
unwrapCek():PromiseLike<ArrayBuffer>;
encrypt(iv: Uint8Array, aad: Uint8Array, cek: CryptoKey|PromiseLike<CryptoKey>, plaintext: Uint8Array):PromiseLike<EncryptionResult>;
decrypt(cek: CryptoKey|PromiseLike<CryptoKey>, aad: Uint8Array, iv: Uint8Array, ciphertext: Uint8Array, tag: Uint8Array):PromiseLike<string>;
sign(aad: Object, payload: string|Object, key:CryptoKey|PromiseLike<CryptoKey>):PromiseLike<ArrayBuffer>;
verify(aad: string, payload: string, signature: Uint8Array, key: CryptoKey|PromiseLike<CryptoKey>, kid: string):PromiseLike<VerificationResult>;
type RsaSsaSignAlgorithm = "RS256" | "RS384" | "RS512";
type RsaPssSignAlgorithm = "PS256" | "PS384" | "PS512";
type HmacSignAlgorithm = "HS256" | "HS384" | "HS512";
type EcdsaSignAlgorithm = "ES256" | "ES384" | "ES512";
type SignAlgorithm = RsaSsaSignAlgorithm | RsaPssSignAlgorithm | HmacSignAlgorithm | EcdsaSignAlgorithm;

type RsaOaepEncryptAlgorithm = "RSA-OAEP" | "RSA-OAEP-256";
type AesKwEncryptAlgorithm = "A128KW" | "A256KW";
type AesCbcEncryptAlgorithm = "A128CBC-HS256" | "A256CBC-HS512";
type AesGcmEncryptAlgorithm = "A128GCM" | "A256GCM";
type EncryptAlgorithm = RsaOaepEncryptAlgorithm | AesKwEncryptAlgorithm | AesCbcEncryptAlgorithm | AesGcmEncryptAlgorithm;

type JoseAlgorithm = EncryptAlgorithm | SignAlgorithm;

interface IWebCryptographer {
new(): IWebCryptographer;
setKeyEncryptionAlgorithm(algorithm: EncryptAlgorithm): void;
setContentSignAlgorithm(algorithm: SignAlgorithm): void;
createIV(): ArrayBufferView;
createCek(): PromiseLike<CryptoKey>;
wrapCek(): PromiseLike<ArrayBuffer>;
unwrapCek(): PromiseLike<ArrayBuffer>;
encrypt(iv: Uint8Array, aad: Uint8Array, cek: CryptoKey | PromiseLike<CryptoKey>, plaintext: Uint8Array): PromiseLike<IEncryptionResult>;
decrypt(cek: CryptoKey | PromiseLike<CryptoKey>, aad: Uint8Array, iv: Uint8Array, ciphertext: Uint8Array, tag: Uint8Array): PromiseLike<string>;
sign(aad: Object, payload: string | Object, key: CryptoKey | PromiseLike<CryptoKey>): PromiseLike<ArrayBuffer>;
verify(aad: string, payload: string, signature: Uint8Array, key: CryptoKey | PromiseLike<CryptoKey>, kid: string): PromiseLike<IVerificationResult>;
}

export interface JsonWebKey {
interface IJsonWebKey {
kty: string;
alg?: string;
kid?: string;
Expand All @@ -32,10 +50,10 @@ export interface JsonWebKey {
x5u?: string;
x5c?: string[];
x5t?: string;
'x5t#S256'?: string;
"x5t#S256"?: string;
}

export interface JWKRSA extends JsonWebKey {
interface JWKRSA extends IJsonWebKey {
n?: string;
e?: string;
d?: string;
Expand All @@ -51,14 +69,14 @@ export interface JWKRSA extends JsonWebKey {
}[];
}

export interface JwkSet {
keys: JsonWebKey[];
interface IJwkSet {
keys: IJsonWebKey[];
}

export interface Headers {
interface IHeaders {
alg: string;
jku?: string;
jwk?: JsonWebKey;
jwk?: IJsonWebKey;
kid?: string;
x5u?: string;
x5c?: string[];
Expand All @@ -69,18 +87,18 @@ export interface Headers {
crit?: string[];
}

export interface Utils {
importRsaPublicKey(rsa_key: JWKRSA, alg: string): PromiseLike<CryptoKey>;
importRsaPrivateKey(rsa_key: JWKRSA, alg: string): PromiseLike<CryptoKey>;
interface IUtils {
importRsaPublicKey(rsa_key: JWKRSA, alg: JoseAlgorithm): PromiseLike<CryptoKey>;
importRsaPrivateKey(rsa_key: JWKRSA, alg: JoseAlgorithm): PromiseLike<CryptoKey>;
}

export interface Jose {
Utils: Utils;
caniuse():boolean;
WebCryptographer:WebCryptographer;
interface IJose {
Utils: IUtils;
caniuse(): boolean;
WebCryptographer: IWebCryptographer;
}

export interface SignedJws {
interface ISignedJws {
header: string;
protected: string;
payload: string;
Expand All @@ -89,45 +107,48 @@ export interface SignedJws {
CompactSerialize(): string;
}

export interface Signer {
new(cryptographer: WebCryptographer):Signer;
addSigner(pk: CryptoKey, kid: string, aad?: Object, header?: Object):PromiseLike<string>;
sign(payload: any, aad?: Object, header?: Object):PromiseLike<SignedJws>;
interface ISigner {
new(cryptographer: IWebCryptographer): ISigner;
addSigner(pk: CryptoKey, kid: string, aad?: Object, header?: Object): PromiseLike<string>;
sign(payload: any, aad?: Object, header?: Object): PromiseLike<ISignedJws>;
}

export interface Verifier {
new(cryptographer: WebCryptographer, msg: string,
keyfinder?: (kid: string) => PromiseLike<CryptoKey>):Verifier;
addRecipient(pk: CryptoKey|string|JWKRSA, kid?: string, alg?: string):PromiseLike<string>;
verify(): PromiseLike<VerificationResult[]>;
interface IVerifier {
new(cryptographer: IWebCryptographer, msg: string,
keyfinder?: (kid: string) => PromiseLike<CryptoKey>): IVerifier;
addRecipient(pk: CryptoKey | string | JWKRSA, kid?: string, alg?: SignAlgorithm): PromiseLike<string>;
verify(): PromiseLike<IVerificationResult[]>;
}

export interface JoseJWS {
Signer:Signer;
Verifier:Verifier;
interface IJoseJWS {
Signer: ISigner;
Verifier: IVerifier;
}

export interface Encrypter {
new(cryptographer: WebCryptographer, pubkey: CryptoKey|PromiseLike<CryptoKey>):Encrypter;
addHeader(k: string, v: string):void;
encrypt(plaintext: string):PromiseLike<string>;
interface IEncrypter {
new(cryptographer: IWebCryptographer, pubkey: CryptoKey | PromiseLike<CryptoKey>): IEncrypter;
addHeader(k: string, v: string): void;
encrypt(plaintext: string): PromiseLike<string>;
}

export interface Decrypter {
new(cryptographer: WebCryptographer, key: CryptoKey|PromiseLike<CryptoKey>):Decrypter;
decrypt(ciphertext: string):PromiseLike<string>;
interface IDecrypter {
new(cryptographer: IWebCryptographer, key: CryptoKey | PromiseLike<CryptoKey>): IDecrypter;
decrypt(ciphertext: string): PromiseLike<string>;
}

export interface JoseJWE {
Encrypter:Encrypter;
Decrypter:Decrypter;
interface IJoseJWE {
Encrypter: IEncrypter;
Decrypter: IDecrypter;
}

export interface setCrypto {
(cryptoProvider: any): any;
}
declare function setCrypto(cryptoProvider: Crypto): void;
declare const Jose: IJose;
declare const JoseJWE: IJoseJWE;
declare const JoseJWS: IJoseJWS;

export var setCrypto: setCrypto;
export var Jose: Jose;
export var JoseJWE: JoseJWE;
export var JoseJWS: JoseJWS;
declare module "jose-jwe-jws" {
export function setCrypto(cryptoProvider: Crypto): void;
export const Jose: IJose;
export const JoseJWE: IJoseJWE;
export const JoseJWS: IJoseJWS;
}
4 changes: 3 additions & 1 deletion lib/jose-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ exports.setCrypto = function (cp) {
/**
* Default to the global "crypto" variable
*/
exports.setCrypto(crypto);
if (typeof(crypto) !== 'undefined') {
exports.setCrypto(crypto);
}

/**
* Use Node versions of atob, btoa functions outside the browser
Expand Down
30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
"type": "git",
"url": "https://github.com/square/js-jose.git"
},
"scripts": {
"build": "grunt"
},
"devDependencies": {
"coveralls": "^2.11.1",
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.6.0",
"grunt-karma": "^0.9.0",
"grunt-karma-coveralls": "^2.5.3",
"karma": "^0.12.28",
"karma-chrome-launcher": "^0.1.5",
"karma-coverage": "^0.2.7",
"karma-qunit": "^0.1.4",
"qunitjs": "^1.15.0"
"coveralls": "^2.13.1",
"grunt": "~1.0.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^3.1.0",
"grunt-karma": "^2.0.0",
"grunt-karma-coveralls": "^2.5.4",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-qunit": "^1.2.1",
"qunitjs": "^1.23.1"
},
"typings": "jose-jwe-jws.d.ts",
"main": "dist/jose-commonjs.js"
"main": "dist/jose-commonjs.js",
"dependencies": {}
}
Loading

0 comments on commit eca0ed8

Please sign in to comment.