@microsoft/ccf-app 3.0.0-rc1 → 4.0.0-dev0
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 +2 -2
- package/crypto.d.ts +14 -6
- package/crypto.js +14 -6
- package/endpoints.d.ts +3 -3
- package/global.d.ts +40 -8
- package/package.json +1 -3
- package/polyfill.js +86 -21
package/converters.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JsonCompatible<T> = any;
|
|
2
2
|
export interface DataConverter<T> {
|
|
3
3
|
encode(val: T): ArrayBuffer;
|
|
4
4
|
decode(arr: ArrayBuffer): T;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type TypedArray = ArrayBufferView;
|
|
7
7
|
export interface TypedArrayConstructor<T extends TypedArray> {
|
|
8
8
|
new (buffer: ArrayBuffer, byteOffset?: number, length?: number): T;
|
|
9
9
|
}
|
package/crypto.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @inheritDoc global!
|
|
2
|
+
* @inheritDoc global!CCFCrypto.generateAesKey
|
|
3
3
|
*/
|
|
4
4
|
export declare const generateAesKey: (size: number) => ArrayBuffer;
|
|
5
5
|
/**
|
|
6
|
-
* @inheritDoc global!
|
|
6
|
+
* @inheritDoc global!CCFCrypto.generateRsaKeyPair
|
|
7
7
|
*/
|
|
8
8
|
export declare const generateRsaKeyPair: (size: number, exponent?: number | undefined) => import("./global.js").CryptoKeyPair;
|
|
9
9
|
/**
|
|
10
|
-
* @inheritDoc global!
|
|
10
|
+
* @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
|
|
11
11
|
*/
|
|
12
12
|
export declare const generateEcdsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
|
|
13
13
|
/**
|
|
14
|
-
* @inheritDoc global!
|
|
14
|
+
* @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
|
|
15
15
|
*/
|
|
16
16
|
export declare const generateEddsaKeyPair: (curve: string) => import("./global.js").CryptoKeyPair;
|
|
17
17
|
/**
|
|
18
|
-
* @inheritDoc global!
|
|
18
|
+
* @inheritDoc global!CCFCrypto.wrapKey
|
|
19
19
|
*/
|
|
20
20
|
export declare const wrapKey: (key: ArrayBuffer, wrappingKey: ArrayBuffer, wrapAlgo: import("./global.js").WrapAlgoParams) => ArrayBuffer;
|
|
21
21
|
/**
|
|
22
|
-
* @inheritDoc global!CCFCrypto.
|
|
22
|
+
* @inheritDoc global!CCFCrypto.sign
|
|
23
23
|
*/
|
|
24
24
|
export declare const sign: (algorithm: import("./global.js").SigningAlgorithm, key: string, plaintext: ArrayBuffer) => ArrayBuffer;
|
|
25
25
|
/**
|
|
@@ -54,4 +54,12 @@ export declare const pubRsaPemToJwk: (pem: string, kid?: string | undefined) =>
|
|
|
54
54
|
* @inheritDoc global!CCFCrypto.rsaPemToJwk
|
|
55
55
|
*/
|
|
56
56
|
export declare const rsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyRSAPrivate;
|
|
57
|
+
/**
|
|
58
|
+
* @inheritDoc global!CCFCrypto.pubEddsaPemToJwk
|
|
59
|
+
*/
|
|
60
|
+
export declare const pubEddsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyEdDSAPrivate;
|
|
61
|
+
/**
|
|
62
|
+
* @inheritDoc global!CCFCrypto.eddsaPemToJwk
|
|
63
|
+
*/
|
|
64
|
+
export declare const eddsaPemToJwk: (pem: string, kid?: string | undefined) => import("./global.js").JsonWebKeyEdDSAPrivate;
|
|
57
65
|
export { WrapAlgoParams, AesKwpParams, RsaOaepParams, RsaOaepAesKwpParams, CryptoKeyPair, DigestAlgorithm, SigningAlgorithm, } from "./global";
|
package/crypto.js
CHANGED
|
@@ -15,27 +15,27 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { ccf } from "./global.js";
|
|
17
17
|
/**
|
|
18
|
-
* @inheritDoc global!
|
|
18
|
+
* @inheritDoc global!CCFCrypto.generateAesKey
|
|
19
19
|
*/
|
|
20
20
|
export const generateAesKey = ccf.crypto.generateAesKey;
|
|
21
21
|
/**
|
|
22
|
-
* @inheritDoc global!
|
|
22
|
+
* @inheritDoc global!CCFCrypto.generateRsaKeyPair
|
|
23
23
|
*/
|
|
24
24
|
export const generateRsaKeyPair = ccf.crypto.generateRsaKeyPair;
|
|
25
25
|
/**
|
|
26
|
-
* @inheritDoc global!
|
|
26
|
+
* @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
|
|
27
27
|
*/
|
|
28
28
|
export const generateEcdsaKeyPair = ccf.crypto.generateEcdsaKeyPair;
|
|
29
29
|
/**
|
|
30
|
-
* @inheritDoc global!
|
|
30
|
+
* @inheritDoc global!CCFCrypto.generateEcdsaKeyPair
|
|
31
31
|
*/
|
|
32
32
|
export const generateEddsaKeyPair = ccf.crypto.generateEddsaKeyPair;
|
|
33
33
|
/**
|
|
34
|
-
* @inheritDoc global!
|
|
34
|
+
* @inheritDoc global!CCFCrypto.wrapKey
|
|
35
35
|
*/
|
|
36
36
|
export const wrapKey = ccf.crypto.wrapKey;
|
|
37
37
|
/**
|
|
38
|
-
* @inheritDoc global!CCFCrypto.
|
|
38
|
+
* @inheritDoc global!CCFCrypto.sign
|
|
39
39
|
*/
|
|
40
40
|
export const sign = ccf.crypto.sign;
|
|
41
41
|
/**
|
|
@@ -70,3 +70,11 @@ export const pubRsaPemToJwk = ccf.crypto.pubRsaPemToJwk;
|
|
|
70
70
|
* @inheritDoc global!CCFCrypto.rsaPemToJwk
|
|
71
71
|
*/
|
|
72
72
|
export const rsaPemToJwk = ccf.crypto.rsaPemToJwk;
|
|
73
|
+
/**
|
|
74
|
+
* @inheritDoc global!CCFCrypto.pubEddsaPemToJwk
|
|
75
|
+
*/
|
|
76
|
+
export const pubEddsaPemToJwk = ccf.crypto.pubEddsaPemToJwk;
|
|
77
|
+
/**
|
|
78
|
+
* @inheritDoc global!CCFCrypto.eddsaPemToJwk
|
|
79
|
+
*/
|
|
80
|
+
export const eddsaPemToJwk = ccf.crypto.eddsaPemToJwk;
|
package/endpoints.d.ts
CHANGED
|
@@ -152,9 +152,9 @@ export interface JwtAuthnIdentity extends AuthnIdentityCommon {
|
|
|
152
152
|
* Each identity corresponds to a matching {@linkcode AuthnIdentityCommon.policy | policy}.
|
|
153
153
|
* Policies have to be declared for each endpoint in ``app.json``.
|
|
154
154
|
*/
|
|
155
|
-
export
|
|
155
|
+
export type AuthnIdentity = EmptyAuthnIdentity | UserCertAuthnIdentity | MemberCertAuthnIdentity | UserSignatureAuthnIdentity | MemberSignatureAuthnIdentity | JwtAuthnIdentity;
|
|
156
156
|
/** See {@linkcode Response.body}. */
|
|
157
|
-
export
|
|
157
|
+
export type ResponseBodyType<T> = string | ArrayBuffer | JsonCompatible<T>;
|
|
158
158
|
/**
|
|
159
159
|
* The response object returned from an endpoint function.
|
|
160
160
|
*
|
|
@@ -219,7 +219,7 @@ export interface Response<T extends ResponseBodyType<T> = any> {
|
|
|
219
219
|
* { ... }
|
|
220
220
|
* ```
|
|
221
221
|
*/
|
|
222
|
-
export
|
|
222
|
+
export type EndpointFn<A extends JsonCompatible<A> = any, B extends ResponseBodyType<B> = any> = (request: Request<A>) => Response<B>;
|
|
223
223
|
/**
|
|
224
224
|
* @inheritDoc global!CCFRpc.setApplyWrites
|
|
225
225
|
*/
|
package/global.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* @module
|
|
15
15
|
*/
|
|
16
16
|
export declare const ccf: CCF;
|
|
17
|
-
export
|
|
17
|
+
export type JsonCompatible<T> = any;
|
|
18
18
|
/**
|
|
19
19
|
* A map in the Key Value Store.
|
|
20
20
|
*
|
|
@@ -35,7 +35,7 @@ export interface KvMap {
|
|
|
35
35
|
/**
|
|
36
36
|
* @inheritDoc CCF.kv
|
|
37
37
|
*/
|
|
38
|
-
export
|
|
38
|
+
export type KvMaps = {
|
|
39
39
|
[key: string]: KvMap;
|
|
40
40
|
};
|
|
41
41
|
export interface ProofElement {
|
|
@@ -65,7 +65,7 @@ export interface LeafComponents {
|
|
|
65
65
|
/**
|
|
66
66
|
* @inheritDoc Receipt.proof
|
|
67
67
|
*/
|
|
68
|
-
export
|
|
68
|
+
export type Proof = ProofElement[];
|
|
69
69
|
export interface Receipt {
|
|
70
70
|
/**
|
|
71
71
|
* Base64-encoded signature of the Merkle tree root hash.
|
|
@@ -115,7 +115,7 @@ export interface TransactionId {
|
|
|
115
115
|
view: number;
|
|
116
116
|
seqno: number;
|
|
117
117
|
}
|
|
118
|
-
export
|
|
118
|
+
export type TransactionStatus = "Committed" | "Invalid" | "Pending" | "Unknown";
|
|
119
119
|
/**
|
|
120
120
|
* [RSA-OAEP](https://datatracker.ietf.org/doc/html/rfc8017)
|
|
121
121
|
* key wrapping with SHA-256 as digest function.
|
|
@@ -161,7 +161,7 @@ export interface RsaOaepAesKwpParams {
|
|
|
161
161
|
*/
|
|
162
162
|
label?: ArrayBuffer;
|
|
163
163
|
}
|
|
164
|
-
export
|
|
164
|
+
export type WrapAlgoParams = RsaOaepParams | AesKwpParams | RsaOaepAesKwpParams;
|
|
165
165
|
export interface CryptoKeyPair {
|
|
166
166
|
/**
|
|
167
167
|
* Private key in PEM encoding.
|
|
@@ -172,8 +172,8 @@ export interface CryptoKeyPair {
|
|
|
172
172
|
*/
|
|
173
173
|
publicKey: string;
|
|
174
174
|
}
|
|
175
|
-
export
|
|
176
|
-
export
|
|
175
|
+
export type AlgorithmName = "RSASSA-PKCS1-v1_5" | "ECDSA" | "EdDSA";
|
|
176
|
+
export type DigestAlgorithm = "SHA-256";
|
|
177
177
|
export interface SigningAlgorithm {
|
|
178
178
|
name: AlgorithmName;
|
|
179
179
|
/**
|
|
@@ -182,7 +182,7 @@ export interface SigningAlgorithm {
|
|
|
182
182
|
hash?: DigestAlgorithm;
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
* Interfaces for JSON Web Key objects, as per [RFC7517](https://www.rfc-editor.org/rfc/
|
|
185
|
+
* Interfaces for JSON Web Key objects, as per [RFC7517](https://www.rfc-editor.org/rfc/rfc7517).
|
|
186
186
|
*/
|
|
187
187
|
export interface JsonWebKey {
|
|
188
188
|
/**
|
|
@@ -238,6 +238,22 @@ export interface JsonWebKeyRSAPrivate extends JsonWebKeyRSAPublic {
|
|
|
238
238
|
dq: string;
|
|
239
239
|
qi: string;
|
|
240
240
|
}
|
|
241
|
+
export interface JsonWebKeyEdDSAPublic extends JsonWebKey {
|
|
242
|
+
/**
|
|
243
|
+
* Elliptic curve identifier.
|
|
244
|
+
*/
|
|
245
|
+
crv: string;
|
|
246
|
+
/**
|
|
247
|
+
* Base64url-encoded public key.
|
|
248
|
+
*/
|
|
249
|
+
x: string;
|
|
250
|
+
}
|
|
251
|
+
export interface JsonWebKeyEdDSAPrivate extends JsonWebKeyEdDSAPublic {
|
|
252
|
+
/**
|
|
253
|
+
* Base64url-encoded private key.
|
|
254
|
+
*/
|
|
255
|
+
d: string;
|
|
256
|
+
}
|
|
241
257
|
export interface CCFCrypto {
|
|
242
258
|
/**
|
|
243
259
|
* Generate a signature.
|
|
@@ -337,6 +353,22 @@ export interface CCFCrypto {
|
|
|
337
353
|
* @param kid Key identifier (optional)
|
|
338
354
|
*/
|
|
339
355
|
rsaPemToJwk(pem: string, kid?: string): JsonWebKeyRSAPrivate;
|
|
356
|
+
/**
|
|
357
|
+
* Converts an EdDSA public key as PEM to JSON Web Key (JWK) object.
|
|
358
|
+
* Currently only Curve25519 is supported.
|
|
359
|
+
*
|
|
360
|
+
* @param pem EdDSA public key as PEM
|
|
361
|
+
* @param kid Key identifier (optional)
|
|
362
|
+
*/
|
|
363
|
+
pubEddsaPemToJwk(pem: string, kid?: string): JsonWebKeyEdDSAPrivate;
|
|
364
|
+
/**
|
|
365
|
+
* Converts an EdDSA private key as PEM to JSON Web Key (JWK) object.
|
|
366
|
+
* Currently only Curve25519 is supported.
|
|
367
|
+
*
|
|
368
|
+
* @param pem EdDSA private key as PEM
|
|
369
|
+
* @param kid Key identifier (optional)
|
|
370
|
+
*/
|
|
371
|
+
eddsaPemToJwk(pem: string, kid?: string): JsonWebKeyEdDSAPrivate;
|
|
340
372
|
}
|
|
341
373
|
export interface CCFRpc {
|
|
342
374
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/ccf-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-dev0",
|
|
4
4
|
"description": "CCF app support package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,14 +19,12 @@
|
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/chai": "^4.2.15",
|
|
22
|
-
"@types/jsrsasign": "^10.5.4",
|
|
23
22
|
"@types/mocha": "^10.0.0",
|
|
24
23
|
"@types/node": "^18.0.0",
|
|
25
24
|
"@types/node-forge": "^1.0.0",
|
|
26
25
|
"chai": "^4.3.4",
|
|
27
26
|
"colors": "1.4.0",
|
|
28
27
|
"cross-env": "^7.0.3",
|
|
29
|
-
"jsrsasign": "^10.5.27",
|
|
30
28
|
"mocha": "^10.0.0",
|
|
31
29
|
"node-forge": "^1.2.0",
|
|
32
30
|
"ts-node": "^10.4.0",
|
package/polyfill.js
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import * as jscrypto from "crypto";
|
|
18
18
|
import { TextEncoder, TextDecoder } from "util";
|
|
19
|
-
import * as rs from "jsrsasign";
|
|
20
19
|
// JavaScript's Map uses reference equality for non-primitive types,
|
|
21
20
|
// whereas CCF compares the content of the ArrayBuffer.
|
|
22
21
|
// To achieve CCF's semantics, all keys are base64-encoded.
|
|
@@ -320,32 +319,98 @@ class CCFPolyfill {
|
|
|
320
319
|
}
|
|
321
320
|
},
|
|
322
321
|
pubPemToJwk(pem, kid) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
322
|
+
const key = jscrypto.createPublicKey({
|
|
323
|
+
key: pem,
|
|
324
|
+
});
|
|
325
|
+
const jwk = key.export({
|
|
326
|
+
format: "jwk",
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
crv: jwk.crv,
|
|
330
|
+
x: jwk.x,
|
|
331
|
+
y: jwk.y,
|
|
332
|
+
kty: jwk.kty,
|
|
333
|
+
kid: kid,
|
|
334
|
+
};
|
|
328
335
|
},
|
|
329
336
|
pemToJwk(pem, kid) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
const key = jscrypto.createPrivateKey({
|
|
338
|
+
key: pem,
|
|
339
|
+
});
|
|
340
|
+
const jwk = key.export({
|
|
341
|
+
format: "jwk",
|
|
342
|
+
});
|
|
343
|
+
return {
|
|
344
|
+
d: jwk.d,
|
|
345
|
+
crv: jwk.crv,
|
|
346
|
+
x: jwk.x,
|
|
347
|
+
y: jwk.y,
|
|
348
|
+
kty: jwk.kty,
|
|
349
|
+
kid: kid,
|
|
350
|
+
};
|
|
335
351
|
},
|
|
336
352
|
pubRsaPemToJwk(pem, kid) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
353
|
+
const key = jscrypto.createPublicKey({
|
|
354
|
+
key: pem,
|
|
355
|
+
});
|
|
356
|
+
const jwk = key.export({
|
|
357
|
+
format: "jwk",
|
|
358
|
+
});
|
|
359
|
+
return {
|
|
360
|
+
n: jwk.n,
|
|
361
|
+
e: jwk.e,
|
|
362
|
+
kty: jwk.kty,
|
|
363
|
+
kid: kid,
|
|
364
|
+
};
|
|
342
365
|
},
|
|
343
366
|
rsaPemToJwk(pem, kid) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
367
|
+
const key = jscrypto.createPrivateKey({
|
|
368
|
+
key: pem,
|
|
369
|
+
});
|
|
370
|
+
const jwk = key.export({
|
|
371
|
+
format: "jwk",
|
|
372
|
+
});
|
|
373
|
+
return {
|
|
374
|
+
d: jwk.d,
|
|
375
|
+
p: jwk.p,
|
|
376
|
+
q: jwk.d,
|
|
377
|
+
dp: jwk.dp,
|
|
378
|
+
dq: jwk.dq,
|
|
379
|
+
qi: jwk.qi,
|
|
380
|
+
n: jwk.n,
|
|
381
|
+
e: jwk.e,
|
|
382
|
+
kty: jwk.kty,
|
|
383
|
+
kid: kid,
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
pubEddsaPemToJwk(pem, kid) {
|
|
387
|
+
const key = jscrypto.createPublicKey({
|
|
388
|
+
key: pem,
|
|
389
|
+
});
|
|
390
|
+
const jwk = key.export({
|
|
391
|
+
format: "jwk",
|
|
392
|
+
});
|
|
393
|
+
return {
|
|
394
|
+
crv: jwk.crv,
|
|
395
|
+
x: jwk.x,
|
|
396
|
+
kty: jwk.kty,
|
|
397
|
+
kid: kid,
|
|
398
|
+
};
|
|
399
|
+
},
|
|
400
|
+
eddsaPemToJwk(pem, kid) {
|
|
401
|
+
const key = jscrypto.createPrivateKey({
|
|
402
|
+
key: pem,
|
|
403
|
+
});
|
|
404
|
+
const jwk = key.export({
|
|
405
|
+
format: "jwk",
|
|
406
|
+
});
|
|
407
|
+
return {
|
|
408
|
+
crv: jwk.crv,
|
|
409
|
+
x: jwk.x,
|
|
410
|
+
d: jwk.d,
|
|
411
|
+
kty: jwk.kty,
|
|
412
|
+
kid: kid,
|
|
413
|
+
};
|
|
349
414
|
},
|
|
350
415
|
};
|
|
351
416
|
}
|