@microsoft/ccf-app 5.0.0-dev9 → 5.0.0-rc1
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.d.ts +26 -0
- package/converters.js +63 -7
- package/crypto.d.ts +8 -8
- package/crypto.js +1 -1
- package/endpoints.d.ts +12 -3
- package/global.d.ts +30 -29
- package/global.js +0 -1
- package/kv.d.ts +26 -1
- package/kv.js +48 -0
- package/package.json +3 -3
- package/polyfill.js +0 -6
- package/snp_attestation.d.ts +1 -1
- package/textcodec.d.ts +26 -0
- package/textcodec.js +53 -0
- package/openenclave.d.ts +0 -5
- package/openenclave.js +0 -12
package/converters.d.ts
CHANGED
|
@@ -157,6 +157,32 @@ export declare const string: DataConverter<string>;
|
|
|
157
157
|
* ```
|
|
158
158
|
*/
|
|
159
159
|
export declare const json: <T extends JsonCompatible<T>>() => DataConverter<T>;
|
|
160
|
+
/**
|
|
161
|
+
* Returns a converter for JSON-compatible objects or values, with errors for
|
|
162
|
+
* known-incompatible types.
|
|
163
|
+
*
|
|
164
|
+
* Based on {@linkcode json}, but additionally runs a check during every encode
|
|
165
|
+
* call, throwing an error if the object contains fields which cannot be round-tripped
|
|
166
|
+
* to JSON (Date, Map). This incurs some cost in checking each instance, but gives
|
|
167
|
+
* clear errors rather than late serdes mismatches.
|
|
168
|
+
*
|
|
169
|
+
* Example:
|
|
170
|
+
* ```
|
|
171
|
+
* interface Data {
|
|
172
|
+
* m: Map<string, string>
|
|
173
|
+
* }
|
|
174
|
+
* const d: Data = { m: new Map<string, string>() };
|
|
175
|
+
* d.m.set("hello", "John");
|
|
176
|
+
*
|
|
177
|
+
* const conv = ccfapp.json<Data>();
|
|
178
|
+
* const buffer = conv.encode(d); // ArrayBuffer, but contents of map silently lost!
|
|
179
|
+
* const d2 = conv.decode(buffer); // Data, but doesn't match d!
|
|
180
|
+
*
|
|
181
|
+
* const convChecked = ccfapp.checkedJson<Data>();
|
|
182
|
+
* const buffer2 = convChecked.encode(d); // Throws TypeError
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare const checkedJson: <T extends JsonCompatible<T>>() => DataConverter<T>;
|
|
160
186
|
/**
|
|
161
187
|
* Returns a converter for [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) objects.
|
|
162
188
|
*
|
package/converters.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* This module provides converters to and from `ArrayBuffer` objects.
|
|
5
5
|
*
|
|
6
|
-
* Converters are commonly used as {@linkcode kv.typedKv}
|
|
6
|
+
* Converters are commonly used as {@linkcode kv.typedKv} or
|
|
7
|
+
* {@linkcode kv.typedKvSet} arguments.
|
|
7
8
|
* Another use case is {@linkcode crypto.wrapKey} to convert
|
|
8
9
|
* PEM-encoded keys to `ArrayBuffer`.
|
|
9
10
|
*
|
|
@@ -29,6 +30,12 @@ function checkNumber(val) {
|
|
|
29
30
|
throw new TypeError(`Value ${val} is not a number`);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
33
|
+
function checkInt(val) {
|
|
34
|
+
checkNumber(val);
|
|
35
|
+
if (!Number.isInteger(val)) {
|
|
36
|
+
throw new TypeError(`Value ${val} is not an integer`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
32
39
|
function checkBigInt(val) {
|
|
33
40
|
if (typeof val !== "bigint") {
|
|
34
41
|
throw new TypeError(`Value ${val} is not a bigint`);
|
|
@@ -39,6 +46,23 @@ function checkString(val) {
|
|
|
39
46
|
throw new TypeError(`Value ${val} is not a string`);
|
|
40
47
|
}
|
|
41
48
|
}
|
|
49
|
+
function checkJsonSafe(val) {
|
|
50
|
+
// Hard to be exhaustive, but throw errors for any Map or Date elements found
|
|
51
|
+
if (val instanceof Map) {
|
|
52
|
+
throw TypeError(`Value contains a Map, which cannot be converted to JSON`);
|
|
53
|
+
}
|
|
54
|
+
if (val instanceof Date) {
|
|
55
|
+
throw TypeError(`Value contains a Date, which cannot be converted back from JSON`);
|
|
56
|
+
}
|
|
57
|
+
if (typeof val === "object") {
|
|
58
|
+
if (Array.isArray(val)) {
|
|
59
|
+
val.every((e) => checkJsonSafe(e));
|
|
60
|
+
}
|
|
61
|
+
else if (val !== null) {
|
|
62
|
+
Object.entries(val).every(([k, v]) => checkJsonSafe(v));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
42
66
|
class BoolConverter {
|
|
43
67
|
encode(val) {
|
|
44
68
|
checkBoolean(val);
|
|
@@ -52,7 +76,7 @@ class BoolConverter {
|
|
|
52
76
|
}
|
|
53
77
|
class Int8Converter {
|
|
54
78
|
encode(val) {
|
|
55
|
-
|
|
79
|
+
checkInt(val);
|
|
56
80
|
if (val < -128 || val > 127) {
|
|
57
81
|
throw new RangeError("value is not within int8 range");
|
|
58
82
|
}
|
|
@@ -66,7 +90,7 @@ class Int8Converter {
|
|
|
66
90
|
}
|
|
67
91
|
class Uint8Converter {
|
|
68
92
|
encode(val) {
|
|
69
|
-
|
|
93
|
+
checkInt(val);
|
|
70
94
|
if (val < 0 || val > 255) {
|
|
71
95
|
throw new RangeError("value is not within uint8 range");
|
|
72
96
|
}
|
|
@@ -80,7 +104,7 @@ class Uint8Converter {
|
|
|
80
104
|
}
|
|
81
105
|
class Int16Converter {
|
|
82
106
|
encode(val) {
|
|
83
|
-
|
|
107
|
+
checkInt(val);
|
|
84
108
|
if (val < -32768 || val > 32767) {
|
|
85
109
|
throw new RangeError("value is not within int16 range");
|
|
86
110
|
}
|
|
@@ -94,7 +118,7 @@ class Int16Converter {
|
|
|
94
118
|
}
|
|
95
119
|
class Uint16Converter {
|
|
96
120
|
encode(val) {
|
|
97
|
-
|
|
121
|
+
checkInt(val);
|
|
98
122
|
if (val < 0 || val > 65535) {
|
|
99
123
|
throw new RangeError("value is not within uint16 range");
|
|
100
124
|
}
|
|
@@ -108,7 +132,7 @@ class Uint16Converter {
|
|
|
108
132
|
}
|
|
109
133
|
class Int32Converter {
|
|
110
134
|
encode(val) {
|
|
111
|
-
|
|
135
|
+
checkInt(val);
|
|
112
136
|
if (val < -2147483648 || val > 2147483647) {
|
|
113
137
|
throw new RangeError("value is not within int32 range");
|
|
114
138
|
}
|
|
@@ -122,7 +146,7 @@ class Int32Converter {
|
|
|
122
146
|
}
|
|
123
147
|
class Uint32Converter {
|
|
124
148
|
encode(val) {
|
|
125
|
-
|
|
149
|
+
checkInt(val);
|
|
126
150
|
if (val < 0 || val > 4294967295) {
|
|
127
151
|
throw new RangeError("value is not within uint32 range");
|
|
128
152
|
}
|
|
@@ -195,6 +219,12 @@ class JSONConverter {
|
|
|
195
219
|
return ccf.bufToJsonCompatible(buf);
|
|
196
220
|
}
|
|
197
221
|
}
|
|
222
|
+
class CheckedJSONConverter extends JSONConverter {
|
|
223
|
+
encode(val) {
|
|
224
|
+
checkJsonSafe(val);
|
|
225
|
+
return super.encode(val);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
198
228
|
class TypedArrayConverter {
|
|
199
229
|
constructor(clazz) {
|
|
200
230
|
this.clazz = clazz;
|
|
@@ -364,6 +394,32 @@ export const string = new StringConverter();
|
|
|
364
394
|
* ```
|
|
365
395
|
*/
|
|
366
396
|
export const json = () => new JSONConverter();
|
|
397
|
+
/**
|
|
398
|
+
* Returns a converter for JSON-compatible objects or values, with errors for
|
|
399
|
+
* known-incompatible types.
|
|
400
|
+
*
|
|
401
|
+
* Based on {@linkcode json}, but additionally runs a check during every encode
|
|
402
|
+
* call, throwing an error if the object contains fields which cannot be round-tripped
|
|
403
|
+
* to JSON (Date, Map). This incurs some cost in checking each instance, but gives
|
|
404
|
+
* clear errors rather than late serdes mismatches.
|
|
405
|
+
*
|
|
406
|
+
* Example:
|
|
407
|
+
* ```
|
|
408
|
+
* interface Data {
|
|
409
|
+
* m: Map<string, string>
|
|
410
|
+
* }
|
|
411
|
+
* const d: Data = { m: new Map<string, string>() };
|
|
412
|
+
* d.m.set("hello", "John");
|
|
413
|
+
*
|
|
414
|
+
* const conv = ccfapp.json<Data>();
|
|
415
|
+
* const buffer = conv.encode(d); // ArrayBuffer, but contents of map silently lost!
|
|
416
|
+
* const d2 = conv.decode(buffer); // Data, but doesn't match d!
|
|
417
|
+
*
|
|
418
|
+
* const convChecked = ccfapp.checkedJson<Data>();
|
|
419
|
+
* const buffer2 = convChecked.encode(d); // Throws TypeError
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
export const checkedJson = () => new CheckedJSONConverter();
|
|
367
423
|
/**
|
|
368
424
|
* Returns a converter for [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) objects.
|
|
369
425
|
*
|
package/crypto.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const generateAesKey: (size: number) => ArrayBuffer;
|
|
|
5
5
|
/**
|
|
6
6
|
* @inheritDoc global!CCFCrypto.generateRsaKeyPair
|
|
7
7
|
*/
|
|
8
|
-
export declare const generateRsaKeyPair: (size: number, exponent?: number
|
|
8
|
+
export declare const generateRsaKeyPair: (size: number, exponent?: number) => import("./global.js").CryptoKeyPair;
|
|
9
9
|
/**
|
|
10
10
|
* @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
|
|
11
11
|
*/
|
|
@@ -45,33 +45,33 @@ export declare const isValidX509CertChain: (chain: string, trusted: string) => b
|
|
|
45
45
|
/**
|
|
46
46
|
* @inheritDoc global!CCFCrypto.pubPemToJwk
|
|
47
47
|
*/
|
|
48
|
-
export declare const pubPemToJwk: (pem: string, kid?: string
|
|
48
|
+
export declare const pubPemToJwk: (pem: string, kid?: string) => import("./global.js").JsonWebKeyECPublic;
|
|
49
49
|
/**
|
|
50
50
|
* @inheritDoc global!CCFCrypto.pemToJwk
|
|
51
51
|
*/
|
|
52
|
-
export declare const pemToJwk: (pem: string, kid?: string
|
|
52
|
+
export declare const pemToJwk: (pem: string, kid?: string) => import("./global.js").JsonWebKeyECPrivate;
|
|
53
53
|
/**
|
|
54
54
|
* @inheritDoc global!CCFCrypto.pubRsaPemToJwk
|
|
55
55
|
*/
|
|
56
|
-
export declare const pubRsaPemToJwk: (pem: string, kid?: string
|
|
56
|
+
export declare const pubRsaPemToJwk: (pem: string, kid?: string) => import("./global.js").JsonWebKeyRSAPublic;
|
|
57
57
|
/**
|
|
58
58
|
* @inheritDoc global!CCFCrypto.rsaPemToJwk
|
|
59
59
|
*/
|
|
60
|
-
export declare const rsaPemToJwk: (pem: string, kid?: string
|
|
60
|
+
export declare const rsaPemToJwk: (pem: string, kid?: string) => import("./global.js").JsonWebKeyRSAPrivate;
|
|
61
61
|
/**
|
|
62
62
|
* @inheritDoc global!CCFCrypto.pubEddsaPemToJwk
|
|
63
63
|
*/
|
|
64
|
-
export declare const pubEddsaPemToJwk: (pem: string, kid?: string
|
|
64
|
+
export declare const pubEddsaPemToJwk: (pem: string, kid?: string) => import("./global.js").JsonWebKeyEdDSAPublic;
|
|
65
65
|
/**
|
|
66
66
|
* @inheritDoc global!CCFCrypto.eddsaPemToJwk
|
|
67
67
|
*/
|
|
68
|
-
export declare const eddsaPemToJwk: (pem: string, kid?: string
|
|
68
|
+
export declare const eddsaPemToJwk: (pem: string, kid?: string) => import("./global.js").JsonWebKeyEdDSAPrivate;
|
|
69
69
|
/**
|
|
70
70
|
* @inheritDoc global!CCFCrypto.pubJwkToPem
|
|
71
71
|
*/
|
|
72
72
|
export declare const pubJwkToPem: (jwk: import("./global.js").JsonWebKeyECPublic) => string;
|
|
73
73
|
/**
|
|
74
|
-
* @inheritDoc global!CCFCrypto.
|
|
74
|
+
* @inheritDoc global!CCFCrypto.jwkToPem
|
|
75
75
|
*/
|
|
76
76
|
export declare const jwkToPem: (jwk: import("./global.js").JsonWebKeyECPrivate) => string;
|
|
77
77
|
/**
|
package/crypto.js
CHANGED
|
@@ -87,7 +87,7 @@ export const eddsaPemToJwk = ccf.crypto.eddsaPemToJwk;
|
|
|
87
87
|
*/
|
|
88
88
|
export const pubJwkToPem = ccf.crypto.pubJwkToPem;
|
|
89
89
|
/**
|
|
90
|
-
* @inheritDoc global!CCFCrypto.
|
|
90
|
+
* @inheritDoc global!CCFCrypto.jwkToPem
|
|
91
91
|
*/
|
|
92
92
|
export const jwkToPem = ccf.crypto.jwkToPem;
|
|
93
93
|
/**
|
package/endpoints.d.ts
CHANGED
|
@@ -93,9 +93,10 @@ export interface AuthnIdentityCommon {
|
|
|
93
93
|
/**
|
|
94
94
|
* A string indicating which policy accepted this request,
|
|
95
95
|
* for use when multiple policies are listed in the endpoint
|
|
96
|
-
* configuration of ``app.json
|
|
96
|
+
* configuration of ``app.json``, or list-of-strings to identify
|
|
97
|
+
* an all_of policy.
|
|
97
98
|
*/
|
|
98
|
-
policy: string;
|
|
99
|
+
policy: string | string[];
|
|
99
100
|
}
|
|
100
101
|
export interface EmptyAuthnIdentity extends AuthnIdentityCommon {
|
|
101
102
|
policy: "no_auth";
|
|
@@ -155,12 +156,20 @@ export interface JwtAuthnIdentity extends AuthnIdentityCommon {
|
|
|
155
156
|
payload: any;
|
|
156
157
|
};
|
|
157
158
|
}
|
|
159
|
+
export interface AllOfAuthnIdentity extends AuthnIdentityCommon {
|
|
160
|
+
policy: string[];
|
|
161
|
+
user_cert?: UserCertAuthnIdentity;
|
|
162
|
+
member_cert?: MemberCertAuthnIdentity;
|
|
163
|
+
user_cose_sign1?: UserCOSESign1AuthnIdentity;
|
|
164
|
+
member_cose_sign1?: MemberCOSESign1AuthnIdentity;
|
|
165
|
+
jwt?: JwtAuthnIdentity;
|
|
166
|
+
}
|
|
158
167
|
/**
|
|
159
168
|
* Authentication identities supported by CCF.
|
|
160
169
|
* Each identity corresponds to a matching {@linkcode AuthnIdentityCommon.policy | policy}.
|
|
161
170
|
* Policies have to be declared for each endpoint in ``app.json``.
|
|
162
171
|
*/
|
|
163
|
-
export type AuthnIdentity = EmptyAuthnIdentity | UserCertAuthnIdentity | MemberCertAuthnIdentity | JwtAuthnIdentity | MemberCOSESign1AuthnIdentity | UserCOSESign1AuthnIdentity;
|
|
172
|
+
export type AuthnIdentity = EmptyAuthnIdentity | UserCertAuthnIdentity | MemberCertAuthnIdentity | JwtAuthnIdentity | MemberCOSESign1AuthnIdentity | UserCOSESign1AuthnIdentity | AllOfAuthnIdentity;
|
|
164
173
|
/** See {@linkcode Response.body}. */
|
|
165
174
|
export type ResponseBodyType<T> = string | ArrayBuffer | JsonCompatible<T>;
|
|
166
175
|
/**
|
package/global.d.ts
CHANGED
|
@@ -32,6 +32,22 @@ export interface KvMap {
|
|
|
32
32
|
forEach(callback: (value: ArrayBuffer, key: ArrayBuffer, kvmap: KvMap) => void): void;
|
|
33
33
|
size: number;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A set in the Key Value Store.
|
|
37
|
+
*
|
|
38
|
+
* `KVSet` is modelled after JavaScript's `Set` object,
|
|
39
|
+
* except that keys must be of type `ArrayBuffer`
|
|
40
|
+
* and no guarantees on iteration order are provided.
|
|
41
|
+
*/
|
|
42
|
+
export interface KvSet {
|
|
43
|
+
has(key: ArrayBuffer): boolean;
|
|
44
|
+
getVersionOfPreviousWrite(key: ArrayBuffer): number | undefined;
|
|
45
|
+
add(key: ArrayBuffer): KvSet;
|
|
46
|
+
delete(key: ArrayBuffer): void;
|
|
47
|
+
clear(): void;
|
|
48
|
+
forEach(callback: (value: ArrayBuffer, kvset: KvSet) => void): void;
|
|
49
|
+
size: number;
|
|
50
|
+
}
|
|
35
51
|
/**
|
|
36
52
|
* @inheritDoc CCF.kv
|
|
37
53
|
*/
|
|
@@ -107,7 +123,7 @@ export interface HistoricalState {
|
|
|
107
123
|
/**
|
|
108
124
|
* An object that provides access to the maps of the Key-Value Store
|
|
109
125
|
* associated with the historic transaction.
|
|
110
|
-
* Fields are map names and values are {@linkcode KvMap}
|
|
126
|
+
* Fields are map names and values are {@linkcode KvMap} objects.
|
|
111
127
|
*/
|
|
112
128
|
kv: KvMaps;
|
|
113
129
|
}
|
|
@@ -385,33 +401,33 @@ export interface CCFCrypto {
|
|
|
385
401
|
/**
|
|
386
402
|
* Converts an elliptic curve private key as JSON Web Key (JWK) object to PEM.
|
|
387
403
|
*
|
|
388
|
-
* @param
|
|
404
|
+
* @param jwk Elliptic curve private key as JWK
|
|
389
405
|
*/
|
|
390
406
|
jwkToPem(jwk: JsonWebKeyECPrivate): string;
|
|
391
407
|
/**
|
|
392
408
|
* Converts an RSA public key as JSON Web Key (JWK) object to PEM.
|
|
393
409
|
*
|
|
394
|
-
* @param
|
|
410
|
+
* @param jwk RSA public key as JWK
|
|
395
411
|
*/
|
|
396
412
|
pubRsaJwkToPem(jwk: JsonWebKeyRSAPublic): string;
|
|
397
413
|
/**
|
|
398
414
|
* Converts an RSA private key as JSON Web Key (JWK) object to PEM.
|
|
399
415
|
*
|
|
400
|
-
* @param
|
|
416
|
+
* @param jwk RSA private key as JWK
|
|
401
417
|
*/
|
|
402
418
|
rsaJwkToPem(jwk: JsonWebKeyRSAPrivate): string;
|
|
403
419
|
/**
|
|
404
420
|
* Converts an EdDSA public key as JSON Web Key (JWK) object to PEM.
|
|
405
421
|
* Currently only Curve25519 is supported.
|
|
406
422
|
*
|
|
407
|
-
* @param
|
|
423
|
+
* @param jwk EdDSA public key as JWK
|
|
408
424
|
*/
|
|
409
425
|
pubEddsaJwkToPem(jwk: JsonWebKeyEdDSAPublic): string;
|
|
410
426
|
/**
|
|
411
427
|
* Converts an EdDSA private key as JSON Web Key (JWK) object to PEM.
|
|
412
428
|
* Currently only Curve25519 is supported.
|
|
413
429
|
*
|
|
414
|
-
* @param
|
|
430
|
+
* @param jwk EdDSA private key as JWK
|
|
415
431
|
*/
|
|
416
432
|
eddsaJwkToPem(jwk: JsonWebKeyEdDSAPrivate): string;
|
|
417
433
|
}
|
|
@@ -592,29 +608,6 @@ export interface CCF {
|
|
|
592
608
|
*/
|
|
593
609
|
enableMetricsLogging(enable: boolean): boolean;
|
|
594
610
|
}
|
|
595
|
-
export declare const openenclave: OpenEnclave;
|
|
596
|
-
export interface EvidenceClaims {
|
|
597
|
-
claims: {
|
|
598
|
-
[name: string]: ArrayBuffer;
|
|
599
|
-
};
|
|
600
|
-
customClaims: {
|
|
601
|
-
[name: string]: ArrayBuffer;
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
export interface OpenEnclave {
|
|
605
|
-
/**
|
|
606
|
-
* Verifies Open Enclave evidence and returns the claims of the evidence.
|
|
607
|
-
*
|
|
608
|
-
* @param format The optional format id of the evidence to be verified as
|
|
609
|
-
* a UUID of the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
|
|
610
|
-
* If this parameter is `undefined`, the evidence and endorsement
|
|
611
|
-
* must either contain data with an attestation header holding a valid
|
|
612
|
-
* format id, or be an Open Enclave report generated by the legacy API function
|
|
613
|
-
* `oe_get_report()`. Otherwise, this parameter must be a valid format id, and
|
|
614
|
-
* the evidence and endorsements data must not be wrapped with an attestation header.
|
|
615
|
-
*/
|
|
616
|
-
verifyOpenEnclaveEvidence(format: string | undefined, evidence: ArrayBuffer, endorsements?: ArrayBuffer): EvidenceClaims;
|
|
617
|
-
}
|
|
618
611
|
export interface TcbVersion {
|
|
619
612
|
boot_loader: number;
|
|
620
613
|
tee: number;
|
|
@@ -677,5 +670,13 @@ export interface SnpAttestationResult {
|
|
|
677
670
|
}
|
|
678
671
|
export declare const snp_attestation: SnpAttestation;
|
|
679
672
|
export interface SnpAttestation {
|
|
673
|
+
/**
|
|
674
|
+
* Verify SNP Attestation
|
|
675
|
+
*
|
|
676
|
+
* @param evidence Raw SNP attestation evidence
|
|
677
|
+
* @param endorsements SNP attestation endorsements
|
|
678
|
+
* @param uvm_endorsements UVM endorsements, optional
|
|
679
|
+
* @param endorsed_tcb Endorsed TCB version, optional
|
|
680
|
+
*/
|
|
680
681
|
verifySnpAttestation(evidence: ArrayBuffer, endorsements: ArrayBuffer, uvm_endorsements?: ArrayBuffer, endorsed_tcb?: string): SnpAttestationResult;
|
|
681
682
|
}
|
package/global.js
CHANGED
package/kv.d.ts
CHANGED
|
@@ -49,6 +49,18 @@ export declare class TypedKvMap<K, V> {
|
|
|
49
49
|
forEach(callback: (value: V, key: K, table: TypedKvMap<K, V>) => void): void;
|
|
50
50
|
get size(): number;
|
|
51
51
|
}
|
|
52
|
+
export declare class TypedKvSet<K> {
|
|
53
|
+
private kv;
|
|
54
|
+
private kt;
|
|
55
|
+
constructor(kv: KvMap, kt: DataConverter<K>);
|
|
56
|
+
has(key: K): boolean;
|
|
57
|
+
getVersionOfPreviousWrite(key: K): number | undefined;
|
|
58
|
+
add(key: K): TypedKvSet<K>;
|
|
59
|
+
delete(key: K): void;
|
|
60
|
+
clear(): void;
|
|
61
|
+
forEach(callback: (key: K, table: TypedKvSet<K>) => void): void;
|
|
62
|
+
get size(): number;
|
|
63
|
+
}
|
|
52
64
|
/**
|
|
53
65
|
* Returns a typed view of a map in the Key-Value Store,
|
|
54
66
|
* where keys and values are automatically converted
|
|
@@ -63,8 +75,21 @@ export declare class TypedKvMap<K, V> {
|
|
|
63
75
|
* @param vt The converter to use for map values.
|
|
64
76
|
*/
|
|
65
77
|
export declare function typedKv<K, V>(nameOrMap: string | KvMap, kt: DataConverter<K>, vt: DataConverter<V>): TypedKvMap<K, V>;
|
|
78
|
+
/**
|
|
79
|
+
* Returns a typed view of a set in the Key-Value Store,
|
|
80
|
+
* where keys are automatically converted
|
|
81
|
+
* to and from ``ArrayBuffer`` based on the given key
|
|
82
|
+
* converter.
|
|
83
|
+
*
|
|
84
|
+
* See the {@linkcode converters} module for available converters.
|
|
85
|
+
*
|
|
86
|
+
* @param nameOrMap Either the map name in the Key-Value Store,
|
|
87
|
+
* or a ``KvMap`` object.
|
|
88
|
+
* @param kt The converter to use for map keys.
|
|
89
|
+
*/
|
|
90
|
+
export declare function typedKvSet<K, V>(nameOrMap: string | KvMap, kt: DataConverter<K>): TypedKvSet<K>;
|
|
66
91
|
/**
|
|
67
92
|
* @inheritDoc global!CCF.kv
|
|
68
93
|
*/
|
|
69
94
|
export declare const rawKv: import("./global.js").KvMaps;
|
|
70
|
-
export { KvMap, KvMaps } from "./global";
|
|
95
|
+
export { KvMap, KvSet, KvMaps } from "./global";
|
package/kv.js
CHANGED
|
@@ -74,6 +74,38 @@ export class TypedKvMap {
|
|
|
74
74
|
return this.kv.size;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
export class TypedKvSet {
|
|
78
|
+
constructor(kv, kt) {
|
|
79
|
+
this.kv = kv;
|
|
80
|
+
this.kt = kt;
|
|
81
|
+
}
|
|
82
|
+
has(key) {
|
|
83
|
+
return this.kv.has(this.kt.encode(key));
|
|
84
|
+
}
|
|
85
|
+
getVersionOfPreviousWrite(key) {
|
|
86
|
+
return this.kv.getVersionOfPreviousWrite(this.kt.encode(key));
|
|
87
|
+
}
|
|
88
|
+
add(key) {
|
|
89
|
+
this.kv.set(this.kt.encode(key), new ArrayBuffer(8));
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
delete(key) {
|
|
93
|
+
this.kv.delete(this.kt.encode(key));
|
|
94
|
+
}
|
|
95
|
+
clear() {
|
|
96
|
+
this.kv.clear();
|
|
97
|
+
}
|
|
98
|
+
forEach(callback) {
|
|
99
|
+
let kt = this.kt;
|
|
100
|
+
let typedSet = this;
|
|
101
|
+
this.kv.forEach(function (raw_v, raw_k, table) {
|
|
102
|
+
callback(kt.decode(raw_k), typedSet);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
get size() {
|
|
106
|
+
return this.kv.size;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
77
109
|
/**
|
|
78
110
|
* Returns a typed view of a map in the Key-Value Store,
|
|
79
111
|
* where keys and values are automatically converted
|
|
@@ -91,6 +123,22 @@ export function typedKv(nameOrMap, kt, vt) {
|
|
|
91
123
|
const kvMap = typeof nameOrMap === "string" ? ccf.kv[nameOrMap] : nameOrMap;
|
|
92
124
|
return new TypedKvMap(kvMap, kt, vt);
|
|
93
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns a typed view of a set in the Key-Value Store,
|
|
128
|
+
* where keys are automatically converted
|
|
129
|
+
* to and from ``ArrayBuffer`` based on the given key
|
|
130
|
+
* converter.
|
|
131
|
+
*
|
|
132
|
+
* See the {@linkcode converters} module for available converters.
|
|
133
|
+
*
|
|
134
|
+
* @param nameOrMap Either the map name in the Key-Value Store,
|
|
135
|
+
* or a ``KvMap`` object.
|
|
136
|
+
* @param kt The converter to use for map keys.
|
|
137
|
+
*/
|
|
138
|
+
export function typedKvSet(nameOrMap, kt) {
|
|
139
|
+
const kvMap = typeof nameOrMap === "string" ? ccf.kv[nameOrMap] : nameOrMap;
|
|
140
|
+
return new TypedKvSet(kvMap, kt);
|
|
141
|
+
}
|
|
94
142
|
/**
|
|
95
143
|
* @inheritDoc global!CCF.kv
|
|
96
144
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/ccf-app",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-rc1",
|
|
4
4
|
"description": "CCF app support package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"@types/mocha": "^10.0.0",
|
|
23
23
|
"@types/node": "^20.1.0",
|
|
24
24
|
"@types/node-forge": "^1.0.0",
|
|
25
|
-
"chai": "^
|
|
25
|
+
"chai": "^5.0.0",
|
|
26
26
|
"colors": "1.4.0",
|
|
27
27
|
"cross-env": "^7.0.3",
|
|
28
28
|
"get-func-name": "3.0.0",
|
|
29
29
|
"mocha": "^10.0.0",
|
|
30
30
|
"node-forge": "^1.2.0",
|
|
31
31
|
"ts-node": "^10.4.0",
|
|
32
|
-
"typedoc": "^0.
|
|
32
|
+
"typedoc": "^0.26.2",
|
|
33
33
|
"typescript": "^5.0.2"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/polyfill.js
CHANGED
|
@@ -524,12 +524,6 @@ class CCFPolyfill {
|
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
globalThis.ccf = new CCFPolyfill();
|
|
527
|
-
class OpenEnclavePolyfill {
|
|
528
|
-
verifyOpenEnclaveEvidence(format, evidence, endorsements) {
|
|
529
|
-
throw new Error("Method not implemented.");
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
globalThis.openenclave = new OpenEnclavePolyfill();
|
|
533
527
|
class SnpAttestationPolyfill {
|
|
534
528
|
verifySnpAttestation(evidence, endorsements, uvm_endorsements, endorsed_tcb) {
|
|
535
529
|
throw new Error("Method not implemented.");
|
package/snp_attestation.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @inheritDoc global!SnpAttestation.verifySnpAttestation
|
|
3
3
|
*/
|
|
4
|
-
export declare const verifySnpAttestation: (evidence: ArrayBuffer, endorsements: ArrayBuffer, uvm_endorsements?: ArrayBuffer
|
|
4
|
+
export declare const verifySnpAttestation: (evidence: ArrayBuffer, endorsements: ArrayBuffer, uvm_endorsements?: ArrayBuffer, endorsed_tcb?: string) => import("./global").SnpAttestationResult;
|
package/textcodec.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type TextEncoderEncodeIntoResult = {
|
|
2
|
+
read?: number;
|
|
3
|
+
written?: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* TextEncoder can be used to encode string to Uint8Array.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TextEncoder {
|
|
9
|
+
/**
|
|
10
|
+
* Always returns "utf-8".
|
|
11
|
+
*/
|
|
12
|
+
readonly encoding: string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns Uint8Array containing UTF-8 encoded text.
|
|
15
|
+
* @param input Input string to encode.
|
|
16
|
+
* @returns Encoded bytes.
|
|
17
|
+
*/
|
|
18
|
+
encode(input: string): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Not implemented.
|
|
21
|
+
* @param input
|
|
22
|
+
* @param output
|
|
23
|
+
* @throws Always throws an Error object.
|
|
24
|
+
*/
|
|
25
|
+
encodeInto(input: string, output: Uint8Array): TextEncoderEncodeIntoResult;
|
|
26
|
+
}
|
package/textcodec.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the Apache 2.0 License.
|
|
3
|
+
/**
|
|
4
|
+
* The `textcodec` module provides access to TextEncoder Web API class.
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
* ```
|
|
8
|
+
* import * as ccftextcodec from '@microsoft/ccf-app/textcodec.js';
|
|
9
|
+
*
|
|
10
|
+
* const bytes = new ccftextcodec.TextEncoder().encode("foo")
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* If you need TextEncoder Web API as a globally accessible class:
|
|
14
|
+
* ```
|
|
15
|
+
* import * as ccftextcodec from '@microsoft/ccf-app/textcodec.js';
|
|
16
|
+
*
|
|
17
|
+
* if (globalThis != undefined && (globalThis as any).TextEncoder == undefined) {
|
|
18
|
+
* (globalThis as any).TextEncoder = ccftextcodec.TextEncoder;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { ccf } from "./global.js";
|
|
26
|
+
/**
|
|
27
|
+
* TextEncoder can be used to encode string to Uint8Array.
|
|
28
|
+
*/
|
|
29
|
+
export class TextEncoder {
|
|
30
|
+
constructor() {
|
|
31
|
+
/**
|
|
32
|
+
* Always returns "utf-8".
|
|
33
|
+
*/
|
|
34
|
+
this.encoding = "utf-8";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns Uint8Array containing UTF-8 encoded text.
|
|
38
|
+
* @param input Input string to encode.
|
|
39
|
+
* @returns Encoded bytes.
|
|
40
|
+
*/
|
|
41
|
+
encode(input) {
|
|
42
|
+
return new Uint8Array(ccf.strToBuf(input));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Not implemented.
|
|
46
|
+
* @param input
|
|
47
|
+
* @param output
|
|
48
|
+
* @throws Always throws an Error object.
|
|
49
|
+
*/
|
|
50
|
+
encodeInto(input, output) {
|
|
51
|
+
throw new Error("Not implemented");
|
|
52
|
+
}
|
|
53
|
+
}
|
package/openenclave.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @inheritDoc global!OpenEnclave.verifyOpenEnclaveEvidence
|
|
3
|
-
*/
|
|
4
|
-
export declare const verifyOpenEnclaveEvidence: (format: string | undefined, evidence: ArrayBuffer, endorsements?: ArrayBuffer | undefined) => import("./global").EvidenceClaims;
|
|
5
|
-
export { EvidenceClaims } from "./global";
|
package/openenclave.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the Apache 2.0 License.
|
|
3
|
-
/**
|
|
4
|
-
* The `openenclave` module provides access to Open Enclave functionality.
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
import { openenclave } from "./global";
|
|
9
|
-
/**
|
|
10
|
-
* @inheritDoc global!OpenEnclave.verifyOpenEnclaveEvidence
|
|
11
|
-
*/
|
|
12
|
-
export const verifyOpenEnclaveEvidence = openenclave.verifyOpenEnclaveEvidence;
|