@microsoft/ccf-app 4.0.7 → 5.0.0-dev0

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
@@ -29,7 +29,7 @@ export declare const verifySignature: (algorithm: import("./global.js").SigningA
29
29
  /**
30
30
  * @inheritDoc global!CCFCrypto.digest
31
31
  */
32
- export declare const digest: (algorithm: "SHA-256", plaintext: ArrayBuffer) => ArrayBuffer;
32
+ export declare const digest: (algorithm: import("./global.js").DigestAlgorithm, plaintext: ArrayBuffer) => ArrayBuffer;
33
33
  /**
34
34
  * @inheritDoc global!CCFCrypto.isValidX509CertBundle
35
35
  */
package/global.d.ts CHANGED
@@ -172,12 +172,12 @@ export interface CryptoKeyPair {
172
172
  */
173
173
  publicKey: string;
174
174
  }
175
- export type AlgorithmName = "RSASSA-PKCS1-v1_5" | "ECDSA" | "EdDSA";
176
- export type DigestAlgorithm = "SHA-256";
175
+ export type AlgorithmName = "RSASSA-PKCS1-v1_5" | "ECDSA" | "EdDSA" | "HMAC";
176
+ export type DigestAlgorithm = "SHA-256" | "SHA-384" | "SHA-512";
177
177
  export interface SigningAlgorithm {
178
178
  name: AlgorithmName;
179
179
  /**
180
- * Digest algorithm. It's necessary for "RSASSA-PKCS1-v1_5" and "ECDSA"
180
+ * Digest algorithm. It's necessary for "RSASSA-PKCS1-v1_5", "ECDSA", and "HMAC"
181
181
  */
182
182
  hash?: DigestAlgorithm;
183
183
  }
@@ -496,6 +496,9 @@ export interface CCF {
496
496
  strToBuf(v: string): ArrayBuffer;
497
497
  /**
498
498
  * Convert an ArrayBuffer into a string.
499
+ *
500
+ * Note that this function does not perform any encoding validation, and may produce
501
+ * an invalid JS string if the input is not valid UTF-8.
499
502
  */
500
503
  bufToStr(v: ArrayBuffer): string;
501
504
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/ccf-app",
3
- "version": "4.0.7",
3
+ "version": "5.0.0-dev0",
4
4
  "description": "CCF app support package",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "devDependencies": {
21
21
  "@types/chai": "^4.2.15",
22
22
  "@types/mocha": "^10.0.0",
23
- "@types/node": "^18.0.0",
23
+ "@types/node": "^20.1.0",
24
24
  "@types/node-forge": "^1.0.0",
25
25
  "chai": "^4.3.4",
26
26
  "colors": "1.4.0",
package/polyfill.js CHANGED
@@ -92,6 +92,14 @@ class CCFPolyfill {
92
92
  };
93
93
  this.crypto = {
94
94
  sign(algorithm, key, data) {
95
+ if (algorithm.name === "HMAC") {
96
+ const hashAlg = algorithm.hash
97
+ .replace("-", "")
98
+ .toLowerCase();
99
+ const hmac = jscrypto.createHmac(hashAlg, key);
100
+ hmac.update(new Uint8Array(data));
101
+ return hmac.digest();
102
+ }
95
103
  let padding = undefined;
96
104
  const privKey = jscrypto.createPrivateKey(key);
97
105
  if (privKey.asymmetricKeyType == "rsa") {
@@ -425,8 +433,10 @@ class CCFPolyfill {
425
433
  strToBuf(s) {
426
434
  return typedArrToArrBuf(new TextEncoder().encode(s));
427
435
  }
436
+ // Note: this is stricter than CCF's bufToStr, as it will
437
+ // reject buffers that are not valid UTF-8.
428
438
  bufToStr(v) {
429
- return new TextDecoder().decode(v);
439
+ return new TextDecoder("utf-8", { fatal: true }).decode(v);
430
440
  }
431
441
  jsonCompatibleToBuf(v) {
432
442
  return this.strToBuf(JSON.stringify(v));