@microsoft/ccf-app 6.0.9 → 6.0.10

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/converters.js CHANGED
@@ -20,6 +20,7 @@
20
20
  * @module
21
21
  */
22
22
  import { ccf } from "./global.js";
23
+ import { toArrayBuffer } from "./utils.js";
23
24
  function checkBoolean(val) {
24
25
  if (typeof val !== "boolean") {
25
26
  throw new TypeError(`Value ${val} is not a boolean`);
@@ -230,7 +231,7 @@ class TypedArrayConverter {
230
231
  this.clazz = clazz;
231
232
  }
232
233
  encode(val) {
233
- return val.buffer.slice(val.byteOffset, val.byteOffset + val.byteLength);
234
+ return toArrayBuffer(val.buffer.slice(val.byteOffset, val.byteOffset + val.byteLength));
234
235
  }
235
236
  decode(buf) {
236
237
  return new this.clazz(buf);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/ccf-app",
3
- "version": "6.0.9",
3
+ "version": "6.0.10",
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": "^5.0.0",
22
22
  "@types/mocha": "^10.0.0",
23
- "@types/node": "^24.0.3",
23
+ "@types/node": "^24.2.0",
24
24
  "@types/node-forge": "^1.0.0",
25
25
  "chai": "^5.0.0",
26
26
  "colors": "1.4.0",
@@ -30,7 +30,7 @@
30
30
  "node-forge": "^1.2.0",
31
31
  "ts-node": "^10.4.0",
32
32
  "typedoc": "^0.28.1",
33
- "typescript": "^5.7.2"
33
+ "typescript": "^5.9.2"
34
34
  },
35
35
  "bin": {
36
36
  "ccf-build-bundle": "scripts/build_bundle.js"
package/polyfill.js CHANGED
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import * as jscrypto from "crypto";
18
18
  import { TextEncoder, TextDecoder } from "util";
19
+ import { toArrayBuffer } from "./utils.js";
19
20
  // JavaScript's Map uses reference equality for non-primitive types,
20
21
  // whereas CCF compares the content of the ArrayBuffer.
21
22
  // To achieve CCF's semantics, all keys are base64-encoded.
@@ -98,7 +99,7 @@ class CCFPolyfill {
98
99
  .toLowerCase();
99
100
  const hmac = jscrypto.createHmac(hashAlg, key);
100
101
  hmac.update(new Uint8Array(data));
101
- return hmac.digest();
102
+ return nodeBufToArrBuf(hmac.digest());
102
103
  }
103
104
  let padding = undefined;
104
105
  const privKey = jscrypto.createPrivateKey(key);
@@ -124,17 +125,17 @@ class CCFPolyfill {
124
125
  throw new Error("unrecognized signing algorithm");
125
126
  }
126
127
  if (algorithm.name === "EdDSA") {
127
- return jscrypto.sign(null, new Uint8Array(data), privKey);
128
+ return nodeBufToArrBuf(jscrypto.sign(null, new Uint8Array(data), privKey));
128
129
  }
129
130
  const hashAlg = algorithm.hash.replace("-", "").toLowerCase();
130
131
  const signer = jscrypto.createSign(hashAlg);
131
132
  signer.update(new Uint8Array(data));
132
- return signer.sign({
133
+ return nodeBufToArrBuf(signer.sign({
133
134
  key: privKey,
134
135
  dsaEncoding: "ieee-p1363",
135
136
  padding: padding,
136
137
  saltLength: algorithm.saltLength ?? 0,
137
- });
138
+ }));
138
139
  },
139
140
  verifySignature(algorithm, key, signature, data) {
140
141
  let padding = undefined;
@@ -539,7 +540,7 @@ function nodeBufToArrBuf(buf) {
539
540
  return arrBuf;
540
541
  }
541
542
  function typedArrToArrBuf(ta) {
542
- return ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
543
+ return toArrayBuffer(ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength));
543
544
  }
544
545
  function base64(buf) {
545
546
  return Buffer.from(buf).toString("base64");
package/utils.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function toUint8ArrayBuffer(buffer: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBuffer>;
2
+ export declare function toArrayBuffer(buffer: ArrayBufferLike | Buffer | Uint8Array): ArrayBuffer;
package/utils.js ADDED
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the Apache 2.0 License.
3
+ // toUint8ArrayBuffer(buffer) converts the buffer into a Uint8Array<ArrayBuffer>
4
+ // If the input is already a Uint8Array<ArrayBuffer>, it returns it directly
5
+ // Otherwise it will copy the data into a new Uint8Array<ArrayBuffer>
6
+ export function toUint8ArrayBuffer(buffer) {
7
+ if (buffer.buffer instanceof ArrayBuffer) {
8
+ return buffer;
9
+ }
10
+ if (buffer.buffer instanceof SharedArrayBuffer) {
11
+ const view = new Uint8Array(new ArrayBuffer(buffer.buffer.byteLength));
12
+ view.set(buffer);
13
+ return new Uint8Array(view.buffer, buffer.byteOffset, buffer.byteLength);
14
+ }
15
+ throw new Error("Unsupported buffer type");
16
+ }
17
+ // toArrayBuffer(buffer) converts the buffer to an ArrayBuffer
18
+ // If the input is already an ArrayBuffer, it returns it directly
19
+ // Otherwise it will copy the data into a new ArrayBuffer
20
+ export function toArrayBuffer(buffer) {
21
+ if (buffer instanceof ArrayBuffer) {
22
+ return buffer;
23
+ }
24
+ if (buffer instanceof SharedArrayBuffer) {
25
+ const view = new Uint8Array(buffer);
26
+ return toUint8ArrayBuffer(view).buffer;
27
+ }
28
+ if (buffer instanceof Uint8Array || buffer instanceof Buffer) {
29
+ return toArrayBuffer(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength));
30
+ }
31
+ throw new Error("Unsupported buffer type");
32
+ }