@microsoft/ccf-app 3.0.0-dev5 → 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/global.d.ts +1 -1
- package/package.json +1 -1
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/global.d.ts
CHANGED
|
@@ -324,7 +324,7 @@ export interface CCF {
|
|
|
324
324
|
/**
|
|
325
325
|
* Generate an ECDSA key pair.
|
|
326
326
|
*
|
|
327
|
-
* @param curve The name of the curve, one of "secp256r1", "secp384r1".
|
|
327
|
+
* @param curve The name of the curve, one of "secp256r1", "secp256k1", "secp384r1".
|
|
328
328
|
*/
|
|
329
329
|
generateEcdsaKeyPair(curve: string): CryptoKeyPair;
|
|
330
330
|
/**
|