@microsoft/ccf-app 3.0.0-rc0 → 3.0.0-rc1

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/consensus.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @inheritDoc CCFConsensus.getLastCommittedTxId;
2
+ * @inheritDoc global!CCFConsensus.getLastCommittedTxId
3
3
  */
4
4
  export declare const getLastCommittedTxId: () => import("./global.js").TransactionId;
5
5
  /**
6
- * @inheritDoc CCFConsensus.getStatusForTxId;
6
+ * @inheritDoc global!CCFConsensus.getStatusForTxId
7
7
  */
8
8
  export declare const getStatusForTxId: (view: number, seqno: number) => import("./global.js").TransactionStatus;
9
9
  /**
10
- * @inheritDoc CCFConsensus.getViewForSeqno;
10
+ * @inheritDoc global!CCFConsensus.getViewForSeqno
11
11
  */
12
12
  export declare const getViewForSeqno: (seqno: number) => number | null;
13
13
  export { TransactionStatus } from "./global";
package/consensus.js CHANGED
@@ -8,14 +8,14 @@
8
8
  */
9
9
  import { ccf } from "./global.js";
10
10
  /**
11
- * @inheritDoc CCFConsensus.getLastCommittedTxId;
11
+ * @inheritDoc global!CCFConsensus.getLastCommittedTxId
12
12
  */
13
13
  export const getLastCommittedTxId = ccf.consensus.getLastCommittedTxId.bind(ccf.consensus);
14
14
  /**
15
- * @inheritDoc CCFConsensus.getStatusForTxId;
15
+ * @inheritDoc global!CCFConsensus.getStatusForTxId
16
16
  */
17
17
  export const getStatusForTxId = ccf.consensus.getStatusForTxId.bind(ccf.consensus);
18
18
  /**
19
- * @inheritDoc CCFConsensus.getViewForSeqno;
19
+ * @inheritDoc global!CCFConsensus.getViewForSeqno
20
20
  */
21
21
  export const getViewForSeqno = ccf.consensus.getViewForSeqno.bind(ccf.consensus);
package/crypto.d.ts CHANGED
@@ -1,53 +1,57 @@
1
1
  /**
2
- * @inheritDoc CCF.generateAesKey
2
+ * @inheritDoc global!CCF.generateAesKey
3
3
  */
4
4
  export declare const generateAesKey: (size: number) => ArrayBuffer;
5
5
  /**
6
- * @inheritDoc CCF.generateRsaKeyPair
6
+ * @inheritDoc global!CCF.generateRsaKeyPair
7
7
  */
8
8
  export declare const generateRsaKeyPair: (size: number, exponent?: number | undefined) => import("./global.js").CryptoKeyPair;
9
9
  /**
10
- * @inheritDoc CCF.generateEcdsaKeyPair
10
+ * @inheritDoc global!CCF.generateEcdsaKeyPair
11
11
  */
12
12
  export declare const generateEcdsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
13
13
  /**
14
- * @inheritDoc CCFCrypto.generateEcdsaKeyPair
14
+ * @inheritDoc global!CCF.generateEcdsaKeyPair
15
15
  */
16
16
  export declare const generateEddsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
17
17
  /**
18
- * @inheritDoc CCF.wrapKey
18
+ * @inheritDoc global!CCF.wrapKey
19
19
  */
20
20
  export declare const wrapKey: (key: ArrayBuffer, wrappingKey: ArrayBuffer, wrapAlgo: import("./global.js").WrapAlgoParams) => ArrayBuffer;
21
21
  /**
22
- * @inheritDoc CCFCrypto.verifySignature
22
+ * @inheritDoc global!CCFCrypto.verifySignature
23
23
  */
24
- export declare const verifySignature: (algorithm: import("./global.js").SigningAlgorithm, key: string, signature: ArrayBuffer, data: ArrayBuffer) => boolean;
24
+ export declare const sign: (algorithm: import("./global.js").SigningAlgorithm, key: string, plaintext: ArrayBuffer) => ArrayBuffer;
25
25
  /**
26
- * @inheritDoc CCF.digest
26
+ * @inheritDoc global!CCFCrypto.verifySignature
27
27
  */
28
- export declare const digest: (algorithm: "SHA-256", data: ArrayBuffer) => ArrayBuffer;
28
+ export declare const verifySignature: (algorithm: import("./global.js").SigningAlgorithm, key: string, signature: ArrayBuffer, plaintext: ArrayBuffer) => boolean;
29
29
  /**
30
- * @inheritDoc CCF.isValidX509CertBundle
30
+ * @inheritDoc global!CCFCrypto.digest
31
+ */
32
+ export declare const digest: (algorithm: "SHA-256", plaintext: ArrayBuffer) => ArrayBuffer;
33
+ /**
34
+ * @inheritDoc global!CCFCrypto.isValidX509CertBundle
31
35
  */
32
36
  export declare const isValidX509CertBundle: (pem: string) => boolean;
33
37
  /**
34
- * @inheritDoc CCF.isValidX509CertChain
38
+ * @inheritDoc global!CCFCrypto.isValidX509CertChain
35
39
  */
36
40
  export declare const isValidX509CertChain: (chain: string, trusted: string) => boolean;
37
41
  /**
38
- * @inheritDoc CCF.pubPemToJwk
42
+ * @inheritDoc global!CCFCrypto.pubPemToJwk
39
43
  */
40
44
  export declare const pubPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyECPublic;
41
45
  /**
42
- * @inheritDoc CCF.pemToJwk
46
+ * @inheritDoc global!CCFCrypto.pemToJwk
43
47
  */
44
48
  export declare const pemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyECPrivate;
45
49
  /**
46
- * @inheritDoc CCF.pubRsaPemToJwk
50
+ * @inheritDoc global!CCFCrypto.pubRsaPemToJwk
47
51
  */
48
52
  export declare const pubRsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyRSAPublic;
49
53
  /**
50
- * @inheritDoc CCF.rsaPemToJwk
54
+ * @inheritDoc global!CCFCrypto.rsaPemToJwk
51
55
  */
52
56
  export declare const rsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyRSAPrivate;
53
- export { WrapAlgoParams, AesKwpParams, RsaOaepParams, RsaOaepAesKwpParams, CryptoKeyPair, DigestAlgorithm, SigningAlgorithm, RsaPkcsParams, EcdsaParams, } from "./global";
57
+ export { WrapAlgoParams, AesKwpParams, RsaOaepParams, RsaOaepAesKwpParams, CryptoKeyPair, DigestAlgorithm, SigningAlgorithm, } from "./global";
package/crypto.js CHANGED
@@ -15,54 +15,58 @@
15
15
  */
16
16
  import { ccf } from "./global.js";
17
17
  /**
18
- * @inheritDoc CCF.generateAesKey
18
+ * @inheritDoc global!CCF.generateAesKey
19
19
  */
20
20
  export const generateAesKey = ccf.crypto.generateAesKey;
21
21
  /**
22
- * @inheritDoc CCF.generateRsaKeyPair
22
+ * @inheritDoc global!CCF.generateRsaKeyPair
23
23
  */
24
24
  export const generateRsaKeyPair = ccf.crypto.generateRsaKeyPair;
25
25
  /**
26
- * @inheritDoc CCF.generateEcdsaKeyPair
26
+ * @inheritDoc global!CCF.generateEcdsaKeyPair
27
27
  */
28
28
  export const generateEcdsaKeyPair = ccf.crypto.generateEcdsaKeyPair;
29
29
  /**
30
- * @inheritDoc CCFCrypto.generateEcdsaKeyPair
30
+ * @inheritDoc global!CCF.generateEcdsaKeyPair
31
31
  */
32
32
  export const generateEddsaKeyPair = ccf.crypto.generateEddsaKeyPair;
33
33
  /**
34
- * @inheritDoc CCF.wrapKey
34
+ * @inheritDoc global!CCF.wrapKey
35
35
  */
36
36
  export const wrapKey = ccf.crypto.wrapKey;
37
37
  /**
38
- * @inheritDoc CCFCrypto.verifySignature
38
+ * @inheritDoc global!CCFCrypto.verifySignature
39
+ */
40
+ export const sign = ccf.crypto.sign;
41
+ /**
42
+ * @inheritDoc global!CCFCrypto.verifySignature
39
43
  */
40
44
  export const verifySignature = ccf.crypto.verifySignature;
41
45
  /**
42
- * @inheritDoc CCF.digest
46
+ * @inheritDoc global!CCFCrypto.digest
43
47
  */
44
48
  export const digest = ccf.crypto.digest;
45
49
  /**
46
- * @inheritDoc CCF.isValidX509CertBundle
50
+ * @inheritDoc global!CCFCrypto.isValidX509CertBundle
47
51
  */
48
52
  export const isValidX509CertBundle = ccf.crypto.isValidX509CertBundle;
49
53
  /**
50
- * @inheritDoc CCF.isValidX509CertChain
54
+ * @inheritDoc global!CCFCrypto.isValidX509CertChain
51
55
  */
52
56
  export const isValidX509CertChain = ccf.crypto.isValidX509CertChain;
53
57
  /**
54
- * @inheritDoc CCF.pubPemToJwk
58
+ * @inheritDoc global!CCFCrypto.pubPemToJwk
55
59
  */
56
60
  export const pubPemToJwk = ccf.crypto.pubPemToJwk;
57
61
  /**
58
- * @inheritDoc CCF.pemToJwk
62
+ * @inheritDoc global!CCFCrypto.pemToJwk
59
63
  */
60
64
  export const pemToJwk = ccf.crypto.pemToJwk;
61
65
  /**
62
- * @inheritDoc CCF.pubRsaPemToJwk
66
+ * @inheritDoc global!CCFCrypto.pubRsaPemToJwk
63
67
  */
64
68
  export const pubRsaPemToJwk = ccf.crypto.pubRsaPemToJwk;
65
69
  /**
66
- * @inheritDoc CCF.rsaPemToJwk
70
+ * @inheritDoc global!CCFCrypto.rsaPemToJwk
67
71
  */
68
72
  export const rsaPemToJwk = ccf.crypto.rsaPemToJwk;
package/endpoints.d.ts CHANGED
@@ -221,11 +221,11 @@ export interface Response<T extends ResponseBodyType<T> = any> {
221
221
  */
222
222
  export declare type EndpointFn<A extends JsonCompatible<A> = any, B extends ResponseBodyType<B> = any> = (request: Request<A>) => Response<B>;
223
223
  /**
224
- * @inheritDoc CCF.rpc.setApplyWrites
224
+ * @inheritDoc global!CCFRpc.setApplyWrites
225
225
  */
226
226
  export declare const setApplyWrites: (force: boolean) => void;
227
227
  /**
228
- * @inheritDoc CCF.rpc.setClaimsDigest
228
+ * @inheritDoc global!CCFRpc.setClaimsDigest
229
229
  */
230
230
  export declare const setClaimsDigest: (digest: ArrayBuffer) => void;
231
231
  export {};
package/endpoints.js CHANGED
@@ -8,10 +8,10 @@
8
8
  */
9
9
  import { ccf } from "./global.js";
10
10
  /**
11
- * @inheritDoc CCF.rpc.setApplyWrites
11
+ * @inheritDoc global!CCFRpc.setApplyWrites
12
12
  */
13
13
  export const setApplyWrites = ccf.rpc.setApplyWrites.bind(ccf.rpc);
14
14
  /**
15
- * @inheritDoc CCF.rpc.setClaimsDigest
15
+ * @inheritDoc global!CCFRpc.setClaimsDigest
16
16
  */
17
17
  export const setClaimsDigest = ccf.rpc.setClaimsDigest.bind(ccf.rpc);
package/global.d.ts CHANGED
@@ -172,27 +172,15 @@ export interface CryptoKeyPair {
172
172
  */
173
173
  publicKey: string;
174
174
  }
175
- /**
176
- * RSASSA-PKCS1-v1_5 signature algorithm parameters.
177
- */
178
- export interface RsaPkcsParams {
179
- name: "RSASSA-PKCS1-v1_5";
180
- hash: DigestAlgorithm;
181
- }
182
- /**
183
- * ECDSA signature algorithm parameters.
184
- *
185
- * Note: ECDSA signatures are assumed to be encoded according
186
- * to the Web Crypto API specification, which is the same
187
- * format used in JSON Web Tokens and more generally known
188
- * as IEEE P1363 encoding.
189
- */
190
- export interface EcdsaParams {
191
- name: "ECDSA";
192
- hash: DigestAlgorithm;
193
- }
194
- export declare type SigningAlgorithm = RsaPkcsParams | EcdsaParams;
175
+ export declare type AlgorithmName = "RSASSA-PKCS1-v1_5" | "ECDSA" | "EdDSA";
195
176
  export declare type DigestAlgorithm = "SHA-256";
177
+ export interface SigningAlgorithm {
178
+ name: AlgorithmName;
179
+ /**
180
+ * Digest algorithm. It's necessary for "RSASSA-PKCS1-v1_5" and "ECDSA"
181
+ */
182
+ hash?: DigestAlgorithm;
183
+ }
196
184
  /**
197
185
  * Interfaces for JSON Web Key objects, as per [RFC7517](https://www.rfc-editor.org/rfc/rfc751).
198
186
  */
@@ -251,17 +239,27 @@ export interface JsonWebKeyRSAPrivate extends JsonWebKeyRSAPublic {
251
239
  qi: string;
252
240
  }
253
241
  export interface CCFCrypto {
242
+ /**
243
+ * Generate a signature.
244
+ *
245
+ * @param algorithm Signing algorithm and parameters
246
+ * @param key A PEM-encoded private key
247
+ * @param plaintext Input data that will be signed
248
+ * @throws Will throw an error if the key is not compatible with the
249
+ * signing algorithm or if an unknown algorithm is used.
250
+ */
251
+ sign(algorithm: SigningAlgorithm, key: string, plaintext: ArrayBuffer): ArrayBuffer;
254
252
  /**
255
253
  * Returns whether digital signature is valid.
256
254
  *
257
255
  * @param algorithm Signing algorithm and parameters
258
256
  * @param key A PEM-encoded public key or X.509 certificate
259
257
  * @param signature Signature to verify
260
- * @param data Data that was signed
258
+ * @param plaintext Input data that was signed
261
259
  * @throws Will throw an error if the key is not compatible with the
262
260
  * signing algorithm or if an unknown algorithm is used.
263
261
  */
264
- verifySignature(algorithm: SigningAlgorithm, key: string, signature: ArrayBuffer, data: ArrayBuffer): boolean;
262
+ verifySignature(algorithm: SigningAlgorithm, key: string, signature: ArrayBuffer, plaintext: ArrayBuffer): boolean;
265
263
  /**
266
264
  * Generate an AES key.
267
265
  *
@@ -297,7 +295,7 @@ export interface CCFCrypto {
297
295
  /**
298
296
  * Generate a digest (hash) of the given data.
299
297
  */
300
- digest(algorithm: DigestAlgorithm, data: ArrayBuffer): ArrayBuffer;
298
+ digest(algorithm: DigestAlgorithm, plaintext: ArrayBuffer): ArrayBuffer;
301
299
  /**
302
300
  * Returns whether a string is a PEM-encoded bundle of X.509 certificates.
303
301
  *
package/historical.d.ts CHANGED
@@ -3,11 +3,11 @@
3
3
  */
4
4
  export declare const historicalState: import("./global.js").HistoricalState | undefined;
5
5
  /**
6
- * @inheritDoc CCFHistorical.getStateRange
6
+ * @inheritDoc global!CCFHistorical.getStateRange
7
7
  */
8
8
  export declare const getStateRange: (handle: number, startSeqno: number, endSeqno: number, secondsUntilExpiry: number) => import("./global.js").HistoricalState[] | null;
9
9
  /**
10
- * @inheritDoc CCFHistorical.dropCachedStates
10
+ * @inheritDoc global!CCFHistorical.dropCachedStates
11
11
  */
12
12
  export declare const dropCachedStates: (handle: number) => boolean;
13
13
  export { HistoricalState, Receipt, Proof, ProofElement } from "./global";
package/historical.js CHANGED
@@ -33,10 +33,10 @@ import { ccf } from "./global.js";
33
33
  */
34
34
  export const historicalState = ccf.historicalState;
35
35
  /**
36
- * @inheritDoc CCFHistorical.getStateRange
36
+ * @inheritDoc global!CCFHistorical.getStateRange
37
37
  */
38
38
  export const getStateRange = ccf.historical.getStateRange.bind(ccf.historical);
39
39
  /**
40
- * @inheritDoc CCFHistorical.dropCachedStates
40
+ * @inheritDoc global!CCFHistorical.dropCachedStates
41
41
  */
42
42
  export const dropCachedStates = ccf.historical.dropCachedStates.bind(ccf.historical);
package/openenclave.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @inheritDoc OpenEnclave.verifyOpenEnclaveEvidence
2
+ * @inheritDoc global!OpenEnclave.verifyOpenEnclaveEvidence
3
3
  */
4
4
  export declare const verifyOpenEnclaveEvidence: (format: string | undefined, evidence: ArrayBuffer, endorsements?: ArrayBuffer | undefined) => import("./global").EvidenceClaims;
5
5
  export { EvidenceClaims } from "./global";
package/openenclave.js CHANGED
@@ -7,6 +7,6 @@
7
7
  */
8
8
  import { openenclave } from "./global";
9
9
  /**
10
- * @inheritDoc OpenEnclave.verifyOpenEnclaveEvidence
10
+ * @inheritDoc global!OpenEnclave.verifyOpenEnclaveEvidence
11
11
  */
12
12
  export const verifyOpenEnclaveEvidence = openenclave.verifyOpenEnclaveEvidence;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/ccf-app",
3
- "version": "3.0.0-rc0",
3
+ "version": "3.0.0-rc1",
4
4
  "description": "CCF app support package",
5
5
  "main": "index.js",
6
6
  "files": [
package/polyfill.js CHANGED
@@ -92,6 +92,42 @@ class CCFPolyfill {
92
92
  },
93
93
  };
94
94
  this.crypto = {
95
+ sign(algorithm, key, data) {
96
+ let padding = undefined;
97
+ const privKey = jscrypto.createPrivateKey(key);
98
+ if (privKey.asymmetricKeyType == "rsa") {
99
+ if (algorithm.name === "RSASSA-PKCS1-v1_5") {
100
+ padding = jscrypto.constants.RSA_PKCS1_PADDING;
101
+ }
102
+ else {
103
+ throw new Error("incompatible signing algorithm for given key type");
104
+ }
105
+ }
106
+ else if (privKey.asymmetricKeyType == "ec") {
107
+ if (algorithm.name !== "ECDSA") {
108
+ throw new Error("incompatible signing algorithm for given key type");
109
+ }
110
+ }
111
+ else if (privKey.asymmetricKeyType == "ed25519") {
112
+ if (algorithm.name !== "EdDSA") {
113
+ throw new Error("incompatible signing algorithm for given key type");
114
+ }
115
+ }
116
+ else {
117
+ throw new Error("unrecognized signing algorithm");
118
+ }
119
+ if (algorithm.name === "EdDSA") {
120
+ return jscrypto.sign(null, new Uint8Array(data), privKey);
121
+ }
122
+ const hashAlg = algorithm.hash.replace("-", "").toLowerCase();
123
+ const signer = jscrypto.createSign(hashAlg);
124
+ signer.update(new Uint8Array(data));
125
+ return signer.sign({
126
+ key: privKey,
127
+ dsaEncoding: "ieee-p1363",
128
+ padding: padding,
129
+ });
130
+ },
95
131
  verifySignature(algorithm, key, signature, data) {
96
132
  let padding = undefined;
97
133
  const pubKey = jscrypto.createPublicKey(key);
@@ -108,9 +144,17 @@ class CCFPolyfill {
108
144
  throw new Error("incompatible signing algorithm for given key type");
109
145
  }
110
146
  }
147
+ else if (pubKey.asymmetricKeyType == "ed25519") {
148
+ if (algorithm.name !== "EdDSA") {
149
+ throw new Error("incompatible signing algorithm for given key type");
150
+ }
151
+ }
111
152
  else {
112
153
  throw new Error("unrecognized signing algorithm");
113
154
  }
155
+ if (algorithm.name === "EdDSA") {
156
+ return jscrypto.verify(null, new Uint8Array(data), pubKey, new Uint8Array(signature));
157
+ }
114
158
  const hashAlg = algorithm.hash.replace("-", "").toLowerCase();
115
159
  const verifier = jscrypto.createVerify(hashAlg);
116
160
  verifier.update(new Uint8Array(data));