@microsoft/ccf-app 7.0.0-dev1 → 7.0.0-dev10
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 +1 -1
- package/converters.js +2 -1
- package/crypto.d.ts +1 -1
- package/endpoints.d.ts +1 -1
- package/historical.d.ts +1 -1
- package/kv.d.ts +3 -3
- package/kv.js +1 -0
- package/package.json +15 -9
- package/polyfill.js +58 -17
- package/utils.d.ts +2 -0
- package/utils.js +32 -0
package/consensus.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export declare const getStatusForTxId: (view: number, seqno: number) => import("
|
|
|
10
10
|
* @inheritDoc global!CCFConsensus.getViewForSeqno
|
|
11
11
|
*/
|
|
12
12
|
export declare const getViewForSeqno: (seqno: number) => number | null;
|
|
13
|
-
export { TransactionStatus } from "./global";
|
|
13
|
+
export type { TransactionStatus } from "./global";
|
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/crypto.d.ts
CHANGED
|
@@ -90,4 +90,4 @@ export declare const pubEddsaJwkToPem: (jwk: import("./global.js").JsonWebKeyEdD
|
|
|
90
90
|
* @inheritDoc global!CCFCrypto.eddsaJwkToPem
|
|
91
91
|
*/
|
|
92
92
|
export declare const eddsaJwkToPem: (jwk: import("./global.js").JsonWebKeyEdDSAPrivate) => string;
|
|
93
|
-
export { WrapAlgoParams, AesKwpParams, RsaOaepParams, RsaOaepAesKwpParams, CryptoKeyPair, DigestAlgorithm, SigningAlgorithm, } from "./global";
|
|
93
|
+
export type { WrapAlgoParams, AesKwpParams, RsaOaepParams, RsaOaepAesKwpParams, CryptoKeyPair, DigestAlgorithm, SigningAlgorithm, } from "./global";
|
package/endpoints.d.ts
CHANGED
package/historical.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export declare const getStateRange: (handle: number, startSeqno: number, endSeqn
|
|
|
10
10
|
* @inheritDoc global!CCFHistorical.dropCachedStates
|
|
11
11
|
*/
|
|
12
12
|
export declare const dropCachedStates: (handle: number) => boolean;
|
|
13
|
-
export { HistoricalState, Receipt, Proof, ProofElement } from "./global";
|
|
13
|
+
export type { HistoricalState, Receipt, Proof, ProofElement } from "./global";
|
package/kv.d.ts
CHANGED
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
*
|
|
34
34
|
* @module
|
|
35
35
|
*/
|
|
36
|
-
import { KvMap } from "./global.js";
|
|
37
|
-
import { DataConverter } from "./converters.js";
|
|
36
|
+
import { type KvMap } from "./global.js";
|
|
37
|
+
import { type DataConverter } from "./converters.js";
|
|
38
38
|
export declare class TypedKvMap<K, V> {
|
|
39
39
|
private kv;
|
|
40
40
|
private kt;
|
|
@@ -92,4 +92,4 @@ export declare function typedKvSet<K, V>(nameOrMap: string | KvMap, kt: DataConv
|
|
|
92
92
|
* @inheritDoc global!CCF.kv
|
|
93
93
|
*/
|
|
94
94
|
export declare const rawKv: import("./global.js").KvMaps;
|
|
95
|
-
export { KvMap, KvSet, KvMaps } from "./global";
|
|
95
|
+
export type { KvMap, KvSet, KvMaps } from "./global";
|
package/kv.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/ccf-app",
|
|
3
|
-
"
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/microsoft/ccf"
|
|
6
|
+
},
|
|
7
|
+
"version": "7.0.0-dev10",
|
|
4
8
|
"description": "CCF app support package",
|
|
5
9
|
"main": "index.js",
|
|
6
10
|
"files": [
|
|
@@ -20,19 +24,21 @@
|
|
|
20
24
|
"devDependencies": {
|
|
21
25
|
"@types/chai": "^5.0.0",
|
|
22
26
|
"@types/mocha": "^10.0.0",
|
|
23
|
-
"@types/node": "^
|
|
27
|
+
"@types/node": "^25.0.2",
|
|
24
28
|
"@types/node-forge": "^1.0.0",
|
|
25
|
-
"chai": "^
|
|
26
|
-
"
|
|
27
|
-
"cross-env": "^7.0.3",
|
|
29
|
+
"chai": "^6.0.1",
|
|
30
|
+
"cross-env": "^10.0.0",
|
|
28
31
|
"get-func-name": "3.0.0",
|
|
29
|
-
"mocha": "^11.
|
|
32
|
+
"mocha": "^11.7.5",
|
|
30
33
|
"node-forge": "^1.2.0",
|
|
31
|
-
"ts-node": "^10.
|
|
32
|
-
"typedoc": "^0.28.
|
|
33
|
-
"typescript": "^5.
|
|
34
|
+
"ts-node": "^10.9.2",
|
|
35
|
+
"typedoc": "^0.28.10",
|
|
36
|
+
"typescript": "^5.9.2"
|
|
34
37
|
},
|
|
35
38
|
"bin": {
|
|
36
39
|
"ccf-build-bundle": "scripts/build_bundle.js"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"colors": "1.4.0"
|
|
37
43
|
}
|
|
38
44
|
}
|
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;
|
|
@@ -383,8 +384,14 @@ class CCFPolyfill {
|
|
|
383
384
|
const jwk = key.export({
|
|
384
385
|
format: "jwk",
|
|
385
386
|
});
|
|
386
|
-
|
|
387
|
-
|
|
387
|
+
const jwkWithKid = {
|
|
388
|
+
kty: jwk.kty,
|
|
389
|
+
crv: jwk.crv,
|
|
390
|
+
x: jwk.x,
|
|
391
|
+
y: jwk.y,
|
|
392
|
+
kid: kid,
|
|
393
|
+
};
|
|
394
|
+
return jwkWithKid;
|
|
388
395
|
},
|
|
389
396
|
pemToJwk(pem, kid) {
|
|
390
397
|
const key = jscrypto.createPrivateKey({
|
|
@@ -393,8 +400,15 @@ class CCFPolyfill {
|
|
|
393
400
|
const jwk = key.export({
|
|
394
401
|
format: "jwk",
|
|
395
402
|
});
|
|
396
|
-
|
|
397
|
-
|
|
403
|
+
const jwkWithKid = {
|
|
404
|
+
kty: jwk.kty,
|
|
405
|
+
crv: jwk.crv,
|
|
406
|
+
x: jwk.x,
|
|
407
|
+
y: jwk.y,
|
|
408
|
+
d: jwk.d,
|
|
409
|
+
kid: kid,
|
|
410
|
+
};
|
|
411
|
+
return jwkWithKid;
|
|
398
412
|
},
|
|
399
413
|
pubRsaPemToJwk(pem, kid) {
|
|
400
414
|
const key = jscrypto.createPublicKey({
|
|
@@ -403,8 +417,13 @@ class CCFPolyfill {
|
|
|
403
417
|
const jwk = key.export({
|
|
404
418
|
format: "jwk",
|
|
405
419
|
});
|
|
406
|
-
|
|
407
|
-
|
|
420
|
+
const jwkWithKid = {
|
|
421
|
+
kty: jwk.kty,
|
|
422
|
+
n: jwk.n,
|
|
423
|
+
e: jwk.e,
|
|
424
|
+
kid: kid,
|
|
425
|
+
};
|
|
426
|
+
return jwkWithKid;
|
|
408
427
|
},
|
|
409
428
|
rsaPemToJwk(pem, kid) {
|
|
410
429
|
const key = jscrypto.createPrivateKey({
|
|
@@ -413,8 +432,19 @@ class CCFPolyfill {
|
|
|
413
432
|
const jwk = key.export({
|
|
414
433
|
format: "jwk",
|
|
415
434
|
});
|
|
416
|
-
|
|
417
|
-
|
|
435
|
+
const jwkWithKid = {
|
|
436
|
+
kty: jwk.kty,
|
|
437
|
+
n: jwk.n,
|
|
438
|
+
e: jwk.e,
|
|
439
|
+
d: jwk.d,
|
|
440
|
+
p: jwk.p,
|
|
441
|
+
q: jwk.q,
|
|
442
|
+
dp: jwk.dp,
|
|
443
|
+
dq: jwk.dq,
|
|
444
|
+
qi: jwk.qi,
|
|
445
|
+
kid: kid,
|
|
446
|
+
};
|
|
447
|
+
return jwkWithKid;
|
|
418
448
|
},
|
|
419
449
|
pubEddsaPemToJwk(pem, kid) {
|
|
420
450
|
const key = jscrypto.createPublicKey({
|
|
@@ -423,8 +453,13 @@ class CCFPolyfill {
|
|
|
423
453
|
const jwk = key.export({
|
|
424
454
|
format: "jwk",
|
|
425
455
|
});
|
|
426
|
-
|
|
427
|
-
|
|
456
|
+
const jwkWithKid = {
|
|
457
|
+
kty: jwk.kty,
|
|
458
|
+
crv: jwk.crv,
|
|
459
|
+
x: jwk.x,
|
|
460
|
+
kid: kid,
|
|
461
|
+
};
|
|
462
|
+
return jwkWithKid;
|
|
428
463
|
},
|
|
429
464
|
eddsaPemToJwk(pem, kid) {
|
|
430
465
|
const key = jscrypto.createPrivateKey({
|
|
@@ -433,8 +468,14 @@ class CCFPolyfill {
|
|
|
433
468
|
const jwk = key.export({
|
|
434
469
|
format: "jwk",
|
|
435
470
|
});
|
|
436
|
-
|
|
437
|
-
|
|
471
|
+
const jwkWithKid = {
|
|
472
|
+
kty: jwk.kty,
|
|
473
|
+
crv: jwk.crv,
|
|
474
|
+
x: jwk.x,
|
|
475
|
+
d: jwk.d,
|
|
476
|
+
kid: kid,
|
|
477
|
+
};
|
|
478
|
+
return jwkWithKid;
|
|
438
479
|
},
|
|
439
480
|
pubJwkToPem(jwk) {
|
|
440
481
|
const key = jscrypto.createPublicKey({
|
|
@@ -539,7 +580,7 @@ function nodeBufToArrBuf(buf) {
|
|
|
539
580
|
return arrBuf;
|
|
540
581
|
}
|
|
541
582
|
function typedArrToArrBuf(ta) {
|
|
542
|
-
return ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
|
|
583
|
+
return toArrayBuffer(ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength));
|
|
543
584
|
}
|
|
544
585
|
function base64(buf) {
|
|
545
586
|
return Buffer.from(buf).toString("base64");
|
package/utils.d.ts
ADDED
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
|
+
}
|