@microsoft/ccf-app 3.0.0 → 3.0.1

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/crypto.d.ts CHANGED
@@ -1,25 +1,25 @@
1
1
  /**
2
- * @inheritDoc global!CCF.generateAesKey
2
+ * @inheritDoc global!CCFCrypto.generateAesKey
3
3
  */
4
4
  export declare const generateAesKey: (size: number) => ArrayBuffer;
5
5
  /**
6
- * @inheritDoc global!CCF.generateRsaKeyPair
6
+ * @inheritDoc global!CCFCrypto.generateRsaKeyPair
7
7
  */
8
8
  export declare const generateRsaKeyPair: (size: number, exponent?: number | undefined) => import("./global.js").CryptoKeyPair;
9
9
  /**
10
- * @inheritDoc global!CCF.generateEcdsaKeyPair
10
+ * @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
11
11
  */
12
12
  export declare const generateEcdsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
13
13
  /**
14
- * @inheritDoc global!CCF.generateEcdsaKeyPair
14
+ * @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
15
15
  */
16
16
  export declare const generateEddsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
17
17
  /**
18
- * @inheritDoc global!CCF.wrapKey
18
+ * @inheritDoc global!CCFCrypto.wrapKey
19
19
  */
20
20
  export declare const wrapKey: (key: ArrayBuffer, wrappingKey: ArrayBuffer, wrapAlgo: import("./global.js").WrapAlgoParams) => ArrayBuffer;
21
21
  /**
22
- * @inheritDoc global!CCFCrypto.verifySignature
22
+ * @inheritDoc global!CCFCrypto.sign
23
23
  */
24
24
  export declare const sign: (algorithm: import("./global.js").SigningAlgorithm, key: string, plaintext: ArrayBuffer) => ArrayBuffer;
25
25
  /**
@@ -54,4 +54,12 @@ export declare const pubRsaPemToJwk: (pem: string, kid?: string | undefined) =>
54
54
  * @inheritDoc global!CCFCrypto.rsaPemToJwk
55
55
  */
56
56
  export declare const rsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyRSAPrivate;
57
+ /**
58
+ * @inheritDoc global!CCFCrypto.pubEddsaPemToJwk
59
+ */
60
+ export declare const pubEddsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyEdDSAPrivate;
61
+ /**
62
+ * @inheritDoc global!CCFCrypto.eddsaPemToJwk
63
+ */
64
+ export declare const eddsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyEdDSAPrivate;
57
65
  export { WrapAlgoParams, AesKwpParams, RsaOaepParams, RsaOaepAesKwpParams, CryptoKeyPair, DigestAlgorithm, SigningAlgorithm, } from "./global";
package/crypto.js CHANGED
@@ -15,27 +15,27 @@
15
15
  */
16
16
  import { ccf } from "./global.js";
17
17
  /**
18
- * @inheritDoc global!CCF.generateAesKey
18
+ * @inheritDoc global!CCFCrypto.generateAesKey
19
19
  */
20
20
  export const generateAesKey = ccf.crypto.generateAesKey;
21
21
  /**
22
- * @inheritDoc global!CCF.generateRsaKeyPair
22
+ * @inheritDoc global!CCFCrypto.generateRsaKeyPair
23
23
  */
24
24
  export const generateRsaKeyPair = ccf.crypto.generateRsaKeyPair;
25
25
  /**
26
- * @inheritDoc global!CCF.generateEcdsaKeyPair
26
+ * @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
27
27
  */
28
28
  export const generateEcdsaKeyPair = ccf.crypto.generateEcdsaKeyPair;
29
29
  /**
30
- * @inheritDoc global!CCF.generateEcdsaKeyPair
30
+ * @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
31
31
  */
32
32
  export const generateEddsaKeyPair = ccf.crypto.generateEddsaKeyPair;
33
33
  /**
34
- * @inheritDoc global!CCF.wrapKey
34
+ * @inheritDoc global!CCFCrypto.wrapKey
35
35
  */
36
36
  export const wrapKey = ccf.crypto.wrapKey;
37
37
  /**
38
- * @inheritDoc global!CCFCrypto.verifySignature
38
+ * @inheritDoc global!CCFCrypto.sign
39
39
  */
40
40
  export const sign = ccf.crypto.sign;
41
41
  /**
@@ -70,3 +70,11 @@ export const pubRsaPemToJwk = ccf.crypto.pubRsaPemToJwk;
70
70
  * @inheritDoc global!CCFCrypto.rsaPemToJwk
71
71
  */
72
72
  export const rsaPemToJwk = ccf.crypto.rsaPemToJwk;
73
+ /**
74
+ * @inheritDoc global!CCFCrypto.pubEddsaPemToJwk
75
+ */
76
+ export const pubEddsaPemToJwk = ccf.crypto.pubEddsaPemToJwk;
77
+ /**
78
+ * @inheritDoc global!CCFCrypto.eddsaPemToJwk
79
+ */
80
+ export const eddsaPemToJwk = ccf.crypto.eddsaPemToJwk;
package/global.d.ts CHANGED
@@ -182,7 +182,7 @@ export interface SigningAlgorithm {
182
182
  hash?: DigestAlgorithm;
183
183
  }
184
184
  /**
185
- * Interfaces for JSON Web Key objects, as per [RFC7517](https://www.rfc-editor.org/rfc/rfc751).
185
+ * Interfaces for JSON Web Key objects, as per [RFC7517](https://www.rfc-editor.org/rfc/rfc7517).
186
186
  */
187
187
  export interface JsonWebKey {
188
188
  /**
@@ -238,6 +238,22 @@ export interface JsonWebKeyRSAPrivate extends JsonWebKeyRSAPublic {
238
238
  dq: string;
239
239
  qi: string;
240
240
  }
241
+ export interface JsonWebKeyEdDSAPublic extends JsonWebKey {
242
+ /**
243
+ * Elliptic curve identifier.
244
+ */
245
+ crv: string;
246
+ /**
247
+ * Base64url-encoded public key.
248
+ */
249
+ x: string;
250
+ }
251
+ export interface JsonWebKeyEdDSAPrivate extends JsonWebKeyEdDSAPublic {
252
+ /**
253
+ * Base64url-encoded private key.
254
+ */
255
+ d: string;
256
+ }
241
257
  export interface CCFCrypto {
242
258
  /**
243
259
  * Generate a signature.
@@ -337,6 +353,22 @@ export interface CCFCrypto {
337
353
  * @param kid Key identifier (optional)
338
354
  */
339
355
  rsaPemToJwk(pem: string, kid?: string): JsonWebKeyRSAPrivate;
356
+ /**
357
+ * Converts an EdDSA public key as PEM to JSON Web Key (JWK) object.
358
+ * Currently only Curve25519 is supported.
359
+ *
360
+ * @param pem EdDSA public key as PEM
361
+ * @param kid Key identifier (optional)
362
+ */
363
+ pubEddsaPemToJwk(pem: string, kid?: string): JsonWebKeyEdDSAPrivate;
364
+ /**
365
+ * Converts an EdDSA private key as PEM to JSON Web Key (JWK) object.
366
+ * Currently only Curve25519 is supported.
367
+ *
368
+ * @param pem EdDSA private key as PEM
369
+ * @param kid Key identifier (optional)
370
+ */
371
+ eddsaPemToJwk(pem: string, kid?: string): JsonWebKeyEdDSAPrivate;
340
372
  }
341
373
  export interface CCFRpc {
342
374
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/ccf-app",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "CCF app support package",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -19,14 +19,12 @@
19
19
  "license": "Apache-2.0",
20
20
  "devDependencies": {
21
21
  "@types/chai": "^4.2.15",
22
- "@types/jsrsasign": "^10.5.4",
23
22
  "@types/mocha": "^10.0.0",
24
23
  "@types/node": "^18.0.0",
25
24
  "@types/node-forge": "^1.0.0",
26
25
  "chai": "^4.3.4",
27
26
  "colors": "1.4.0",
28
27
  "cross-env": "^7.0.3",
29
- "jsrsasign": "^10.5.27",
30
28
  "mocha": "^10.0.0",
31
29
  "node-forge": "^1.2.0",
32
30
  "ts-node": "^10.4.0",
package/polyfill.js CHANGED
@@ -16,7 +16,6 @@
16
16
  */
17
17
  import * as jscrypto from "crypto";
18
18
  import { TextEncoder, TextDecoder } from "util";
19
- import * as rs from "jsrsasign";
20
19
  // JavaScript's Map uses reference equality for non-primitive types,
21
20
  // whereas CCF compares the content of the ArrayBuffer.
22
21
  // To achieve CCF's semantics, all keys are base64-encoded.
@@ -320,32 +319,98 @@ class CCFPolyfill {
320
319
  }
321
320
  },
322
321
  pubPemToJwk(pem, kid) {
323
- let jwk = rs.KEYUTIL.getJWK(rs.KEYUTIL.getKey(pem));
324
- if (kid !== undefined) {
325
- jwk.kid = kid;
326
- }
327
- return jwk;
322
+ const key = jscrypto.createPublicKey({
323
+ key: pem,
324
+ });
325
+ const jwk = key.export({
326
+ format: "jwk",
327
+ });
328
+ return {
329
+ crv: jwk.crv,
330
+ x: jwk.x,
331
+ y: jwk.y,
332
+ kty: jwk.kty,
333
+ kid: kid,
334
+ };
328
335
  },
329
336
  pemToJwk(pem, kid) {
330
- let jwk = rs.KEYUTIL.getJWK(rs.KEYUTIL.getKey(pem));
331
- if (kid !== undefined) {
332
- jwk.kid = kid;
333
- }
334
- return jwk;
337
+ const key = jscrypto.createPrivateKey({
338
+ key: pem,
339
+ });
340
+ const jwk = key.export({
341
+ format: "jwk",
342
+ });
343
+ return {
344
+ d: jwk.d,
345
+ crv: jwk.crv,
346
+ x: jwk.x,
347
+ y: jwk.y,
348
+ kty: jwk.kty,
349
+ kid: kid,
350
+ };
335
351
  },
336
352
  pubRsaPemToJwk(pem, kid) {
337
- let jwk = rs.KEYUTIL.getJWK(rs.KEYUTIL.getKey(pem));
338
- if (kid !== undefined) {
339
- jwk.kid = kid;
340
- }
341
- return jwk;
353
+ const key = jscrypto.createPublicKey({
354
+ key: pem,
355
+ });
356
+ const jwk = key.export({
357
+ format: "jwk",
358
+ });
359
+ return {
360
+ n: jwk.n,
361
+ e: jwk.e,
362
+ kty: jwk.kty,
363
+ kid: kid,
364
+ };
342
365
  },
343
366
  rsaPemToJwk(pem, kid) {
344
- let jwk = rs.KEYUTIL.getJWK(rs.KEYUTIL.getKey(pem));
345
- if (kid !== undefined) {
346
- jwk.kid = kid;
347
- }
348
- return jwk;
367
+ const key = jscrypto.createPrivateKey({
368
+ key: pem,
369
+ });
370
+ const jwk = key.export({
371
+ format: "jwk",
372
+ });
373
+ return {
374
+ d: jwk.d,
375
+ p: jwk.p,
376
+ q: jwk.d,
377
+ dp: jwk.dp,
378
+ dq: jwk.dq,
379
+ qi: jwk.qi,
380
+ n: jwk.n,
381
+ e: jwk.e,
382
+ kty: jwk.kty,
383
+ kid: kid,
384
+ };
385
+ },
386
+ pubEddsaPemToJwk(pem, kid) {
387
+ const key = jscrypto.createPublicKey({
388
+ key: pem,
389
+ });
390
+ const jwk = key.export({
391
+ format: "jwk",
392
+ });
393
+ return {
394
+ crv: jwk.crv,
395
+ x: jwk.x,
396
+ kty: jwk.kty,
397
+ kid: kid,
398
+ };
399
+ },
400
+ eddsaPemToJwk(pem, kid) {
401
+ const key = jscrypto.createPrivateKey({
402
+ key: pem,
403
+ });
404
+ const jwk = key.export({
405
+ format: "jwk",
406
+ });
407
+ return {
408
+ crv: jwk.crv,
409
+ x: jwk.x,
410
+ d: jwk.d,
411
+ kty: jwk.kty,
412
+ kid: kid,
413
+ };
349
414
  },
350
415
  };
351
416
  }