@microsoft/ccf-app 3.0.0-dev4 → 3.0.0-dev6
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 +32 -0
- package/crypto.d.ts +4 -0
- package/crypto.js +4 -0
- package/global.d.ts +6 -0
- package/package.json +2 -2
- package/polyfill.js +17 -0
package/converters.js
CHANGED
|
@@ -19,8 +19,29 @@
|
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
21
|
import { ccf } from "./global.js";
|
|
22
|
+
function checkBoolean(val) {
|
|
23
|
+
if (typeof val !== "boolean") {
|
|
24
|
+
throw new TypeError(`Value ${val} is not a boolean`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function checkNumber(val) {
|
|
28
|
+
if (typeof val !== "number") {
|
|
29
|
+
throw new TypeError(`Value ${val} is not a number`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function checkBigInt(val) {
|
|
33
|
+
if (typeof val !== "bigint") {
|
|
34
|
+
throw new TypeError(`Value ${val} is not a bigint`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function checkString(val) {
|
|
38
|
+
if (typeof val !== "string") {
|
|
39
|
+
throw new TypeError(`Value ${val} is not a string`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
22
42
|
class BoolConverter {
|
|
23
43
|
encode(val) {
|
|
44
|
+
checkBoolean(val);
|
|
24
45
|
const buf = new ArrayBuffer(1);
|
|
25
46
|
new DataView(buf).setUint8(0, val ? 1 : 0);
|
|
26
47
|
return buf;
|
|
@@ -31,6 +52,7 @@ class BoolConverter {
|
|
|
31
52
|
}
|
|
32
53
|
class Int8Converter {
|
|
33
54
|
encode(val) {
|
|
55
|
+
checkNumber(val);
|
|
34
56
|
if (val < -128 || val > 127) {
|
|
35
57
|
throw new RangeError("value is not within int8 range");
|
|
36
58
|
}
|
|
@@ -44,6 +66,7 @@ class Int8Converter {
|
|
|
44
66
|
}
|
|
45
67
|
class Uint8Converter {
|
|
46
68
|
encode(val) {
|
|
69
|
+
checkNumber(val);
|
|
47
70
|
if (val < 0 || val > 255) {
|
|
48
71
|
throw new RangeError("value is not within uint8 range");
|
|
49
72
|
}
|
|
@@ -57,6 +80,7 @@ class Uint8Converter {
|
|
|
57
80
|
}
|
|
58
81
|
class Int16Converter {
|
|
59
82
|
encode(val) {
|
|
83
|
+
checkNumber(val);
|
|
60
84
|
if (val < -32768 || val > 32767) {
|
|
61
85
|
throw new RangeError("value is not within int16 range");
|
|
62
86
|
}
|
|
@@ -70,6 +94,7 @@ class Int16Converter {
|
|
|
70
94
|
}
|
|
71
95
|
class Uint16Converter {
|
|
72
96
|
encode(val) {
|
|
97
|
+
checkNumber(val);
|
|
73
98
|
if (val < 0 || val > 65535) {
|
|
74
99
|
throw new RangeError("value is not within uint16 range");
|
|
75
100
|
}
|
|
@@ -83,6 +108,7 @@ class Uint16Converter {
|
|
|
83
108
|
}
|
|
84
109
|
class Int32Converter {
|
|
85
110
|
encode(val) {
|
|
111
|
+
checkNumber(val);
|
|
86
112
|
if (val < -2147483648 || val > 2147483647) {
|
|
87
113
|
throw new RangeError("value is not within int32 range");
|
|
88
114
|
}
|
|
@@ -96,6 +122,7 @@ class Int32Converter {
|
|
|
96
122
|
}
|
|
97
123
|
class Uint32Converter {
|
|
98
124
|
encode(val) {
|
|
125
|
+
checkNumber(val);
|
|
99
126
|
if (val < 0 || val > 4294967295) {
|
|
100
127
|
throw new RangeError("value is not within uint32 range");
|
|
101
128
|
}
|
|
@@ -109,6 +136,7 @@ class Uint32Converter {
|
|
|
109
136
|
}
|
|
110
137
|
class Int64Converter {
|
|
111
138
|
encode(val) {
|
|
139
|
+
checkBigInt(val);
|
|
112
140
|
const buf = new ArrayBuffer(8);
|
|
113
141
|
new DataView(buf).setBigInt64(0, val, true);
|
|
114
142
|
return buf;
|
|
@@ -119,6 +147,7 @@ class Int64Converter {
|
|
|
119
147
|
}
|
|
120
148
|
class Uint64Converter {
|
|
121
149
|
encode(val) {
|
|
150
|
+
checkBigInt(val);
|
|
122
151
|
const buf = new ArrayBuffer(8);
|
|
123
152
|
new DataView(buf).setBigUint64(0, val, true);
|
|
124
153
|
return buf;
|
|
@@ -129,6 +158,7 @@ class Uint64Converter {
|
|
|
129
158
|
}
|
|
130
159
|
class Float32Converter {
|
|
131
160
|
encode(val) {
|
|
161
|
+
checkNumber(val);
|
|
132
162
|
const buf = new ArrayBuffer(4);
|
|
133
163
|
new DataView(buf).setFloat32(0, val, true);
|
|
134
164
|
return buf;
|
|
@@ -139,6 +169,7 @@ class Float32Converter {
|
|
|
139
169
|
}
|
|
140
170
|
class Float64Converter {
|
|
141
171
|
encode(val) {
|
|
172
|
+
checkNumber(val);
|
|
142
173
|
const buf = new ArrayBuffer(8);
|
|
143
174
|
new DataView(buf).setFloat64(0, val, true);
|
|
144
175
|
return buf;
|
|
@@ -149,6 +180,7 @@ class Float64Converter {
|
|
|
149
180
|
}
|
|
150
181
|
class StringConverter {
|
|
151
182
|
encode(val) {
|
|
183
|
+
checkString(val);
|
|
152
184
|
return ccf.strToBuf(val);
|
|
153
185
|
}
|
|
154
186
|
decode(buf) {
|
package/crypto.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare const generateAesKey: (size: number) => ArrayBuffer;
|
|
|
6
6
|
* @inheritDoc CCF.generateRsaKeyPair
|
|
7
7
|
*/
|
|
8
8
|
export declare const generateRsaKeyPair: (size: number, exponent?: number | undefined) => import("./global.js").CryptoKeyPair;
|
|
9
|
+
/**
|
|
10
|
+
* @inheritDoc CCF.generateEcdsaKeyPair
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateEcdsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
|
|
9
13
|
/**
|
|
10
14
|
* @inheritDoc CCF.wrapKey
|
|
11
15
|
*/
|
package/crypto.js
CHANGED
|
@@ -22,6 +22,10 @@ export const generateAesKey = ccf.generateAesKey;
|
|
|
22
22
|
* @inheritDoc CCF.generateRsaKeyPair
|
|
23
23
|
*/
|
|
24
24
|
export const generateRsaKeyPair = ccf.generateRsaKeyPair;
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc CCF.generateEcdsaKeyPair
|
|
27
|
+
*/
|
|
28
|
+
export const generateEcdsaKeyPair = ccf.generateEcdsaKeyPair;
|
|
25
29
|
/**
|
|
26
30
|
* @inheritDoc CCF.wrapKey
|
|
27
31
|
*/
|
package/global.d.ts
CHANGED
|
@@ -321,6 +321,12 @@ export interface CCF {
|
|
|
321
321
|
* @param exponent The public exponent. Default: 65537.
|
|
322
322
|
*/
|
|
323
323
|
generateRsaKeyPair(size: number, exponent?: number): CryptoKeyPair;
|
|
324
|
+
/**
|
|
325
|
+
* Generate an ECDSA key pair.
|
|
326
|
+
*
|
|
327
|
+
* @param curve The name of the curve, one of "secp256r1", "secp256k1", "secp384r1".
|
|
328
|
+
*/
|
|
329
|
+
generateEcdsaKeyPair(curve: string): CryptoKeyPair;
|
|
324
330
|
/**
|
|
325
331
|
* Wraps a key using a wrapping key.
|
|
326
332
|
*
|
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.0-dev6",
|
|
4
4
|
"description": "CCF app support package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/chai": "^4.2.15",
|
|
22
|
-
"@types/mocha": "^
|
|
22
|
+
"@types/mocha": "^10.0.0",
|
|
23
23
|
"@types/node": "^18.0.0",
|
|
24
24
|
"@types/node-forge": "^1.0.0",
|
|
25
25
|
"chai": "^4.3.4",
|
package/polyfill.js
CHANGED
|
@@ -151,6 +151,23 @@ class CCFPolyfill {
|
|
|
151
151
|
});
|
|
152
152
|
return rsaKeyPair;
|
|
153
153
|
}
|
|
154
|
+
generateEcdsaKeyPair(curve) {
|
|
155
|
+
var curve_name = curve;
|
|
156
|
+
if (curve == "secp256r1")
|
|
157
|
+
curve_name = "prime256v1";
|
|
158
|
+
const ecdsaKeyPair = crypto.generateKeyPairSync("ec", {
|
|
159
|
+
namedCurve: curve_name,
|
|
160
|
+
publicKeyEncoding: {
|
|
161
|
+
type: "spki",
|
|
162
|
+
format: "pem",
|
|
163
|
+
},
|
|
164
|
+
privateKeyEncoding: {
|
|
165
|
+
type: "pkcs8",
|
|
166
|
+
format: "pem",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return ecdsaKeyPair;
|
|
170
|
+
}
|
|
154
171
|
wrapKey(key, wrappingKey, parameters) {
|
|
155
172
|
if (parameters.name === "RSA-OAEP") {
|
|
156
173
|
return nodeBufToArrBuf(crypto.publicEncrypt({
|