@opentdf/sdk 0.3.0-beta.2029 → 0.3.0-beta.2166
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/dist/cjs/src/access.js +1 -2
- package/dist/cjs/src/index.js +2 -1
- package/dist/cjs/src/nanoclients.js +13 -6
- package/dist/cjs/src/opentdf.js +4 -3
- package/dist/cjs/src/tdf/Policy.js +15 -12
- package/dist/cjs/tdf3/src/assertions.js +23 -4
- package/dist/cjs/tdf3/src/client/builders.js +1 -1
- package/dist/cjs/tdf3/src/models/attribute.js +3 -0
- package/dist/cjs/tdf3/src/models/index.js +2 -2
- package/dist/cjs/tdf3/src/tdf.js +57 -21
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/nanoclients.d.ts +1 -1
- package/dist/types/src/nanoclients.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +1 -0
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/tdf/Policy.d.ts +4 -2
- package/dist/types/src/tdf/Policy.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +4 -1
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +2 -0
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/attribute.d.ts +16 -0
- package/dist/types/tdf3/src/models/attribute.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/index.d.ts +1 -1
- package/dist/types/tdf3/src/models/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/payload.d.ts +1 -0
- package/dist/types/tdf3/src/models/payload.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/policy.d.ts +1 -1
- package/dist/types/tdf3/src/models/policy.d.ts.map +1 -1
- package/dist/types/tdf3/src/tdf.d.ts +4 -9
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/web/src/access.js +1 -2
- package/dist/web/src/index.js +2 -1
- package/dist/web/src/nanoclients.js +14 -7
- package/dist/web/src/opentdf.js +4 -3
- package/dist/web/src/tdf/Policy.js +13 -10
- package/dist/web/tdf3/src/assertions.js +23 -4
- package/dist/web/tdf3/src/client/builders.js +1 -1
- package/dist/web/tdf3/src/models/attribute.js +2 -0
- package/dist/web/tdf3/src/models/index.js +2 -2
- package/dist/web/tdf3/src/tdf.js +58 -22
- package/package.json +1 -1
- package/src/access.ts +0 -1
- package/src/index.ts +1 -0
- package/src/nanoclients.ts +15 -7
- package/src/opentdf.ts +9 -5
- package/src/tdf/Policy.ts +15 -9
- package/tdf3/src/assertions.ts +29 -7
- package/tdf3/src/client/builders.ts +2 -0
- package/tdf3/src/models/attribute.ts +26 -0
- package/tdf3/src/models/index.ts +1 -1
- package/tdf3/src/models/payload.ts +1 -0
- package/tdf3/src/models/policy.ts +1 -1
- package/tdf3/src/tdf.ts +92 -39
- package/dist/cjs/src/tdf/PolicyObject.js +0 -3
- package/dist/cjs/tdf3/src/models/attribute-set.js +0 -122
- package/dist/types/src/tdf/PolicyObject.d.ts +0 -10
- package/dist/types/src/tdf/PolicyObject.d.ts.map +0 -1
- package/dist/types/tdf3/src/models/attribute-set.d.ts +0 -65
- package/dist/types/tdf3/src/models/attribute-set.d.ts.map +0 -1
- package/dist/web/src/tdf/PolicyObject.js +0 -2
- package/dist/web/tdf3/src/models/attribute-set.js +0 -118
- package/src/tdf/PolicyObject.ts +0 -11
- package/tdf3/src/models/attribute-set.ts +0 -142
package/tdf3/src/tdf.ts
CHANGED
|
@@ -24,7 +24,6 @@ import { generateKeyPair } from '../../src/nanotdf-crypto/generateKeyPair.js';
|
|
|
24
24
|
import { keyAgreement } from '../../src/nanotdf-crypto/keyAgreement.js';
|
|
25
25
|
import { pemPublicToCrypto } from '../../src/nanotdf-crypto/pemPublicToCrypto.js';
|
|
26
26
|
import { type Chunker } from '../../src/seekable.js';
|
|
27
|
-
import { PolicyObject } from '../../src/tdf/PolicyObject.js';
|
|
28
27
|
import { tdfSpecVersion } from '../../src/version.js';
|
|
29
28
|
import { AssertionConfig, AssertionKey, AssertionVerificationKeys } from './assertions.js';
|
|
30
29
|
import * as assertions from './assertions.js';
|
|
@@ -52,13 +51,16 @@ import {
|
|
|
52
51
|
SplitType,
|
|
53
52
|
} from './models/index.js';
|
|
54
53
|
import { unsigned } from './utils/buffer-crc32.js';
|
|
55
|
-
import { ZipReader, ZipWriter, keyMerge, concatUint8 } from './utils/index.js';
|
|
54
|
+
import { ZipReader, ZipWriter, keyMerge, concatUint8, buffToString } from './utils/index.js';
|
|
56
55
|
import { CentralDirectory } from './utils/zip-reader.js';
|
|
57
56
|
import { ztdfSalt } from './crypto/salt.js';
|
|
57
|
+
import { Payload } from './models/payload.js';
|
|
58
58
|
|
|
59
59
|
// TODO: input validation on manifest JSON
|
|
60
60
|
const DEFAULT_SEGMENT_SIZE = 1024 * 1024;
|
|
61
61
|
|
|
62
|
+
const HEX_SEMVER_VERSION = '4.2.2';
|
|
63
|
+
|
|
62
64
|
/**
|
|
63
65
|
* Configuration for TDF3
|
|
64
66
|
*/
|
|
@@ -73,12 +75,7 @@ export type EncryptionOptions = {
|
|
|
73
75
|
|
|
74
76
|
type KeyMiddleware = DecryptParams['keyMiddleware'];
|
|
75
77
|
|
|
76
|
-
export type Metadata =
|
|
77
|
-
connectOptions?: {
|
|
78
|
-
testUrl: string;
|
|
79
|
-
};
|
|
80
|
-
policyObject?: PolicyObject;
|
|
81
|
-
};
|
|
78
|
+
export type Metadata = unknown;
|
|
82
79
|
|
|
83
80
|
export type BuildKeyAccess = {
|
|
84
81
|
type: KeyAccessType;
|
|
@@ -150,6 +147,7 @@ export type EncryptConfiguration = {
|
|
|
150
147
|
keyForEncryption: KeyInfo;
|
|
151
148
|
keyForManifest: KeyInfo;
|
|
152
149
|
assertionConfigs?: AssertionConfig[];
|
|
150
|
+
tdfSpecVersion?: string;
|
|
153
151
|
};
|
|
154
152
|
|
|
155
153
|
export type DecryptConfiguration = {
|
|
@@ -289,10 +287,11 @@ async function _generateManifest(
|
|
|
289
287
|
keyInfo: KeyInfo,
|
|
290
288
|
encryptionInformation: SplitKey,
|
|
291
289
|
policy: Policy,
|
|
292
|
-
mimeType: string | undefined
|
|
290
|
+
mimeType: string | undefined,
|
|
291
|
+
targetSpecVersion: string | undefined
|
|
293
292
|
): Promise<Manifest> {
|
|
294
293
|
// (maybe) Fields are quoted to avoid renaming
|
|
295
|
-
const payload = {
|
|
294
|
+
const payload: Payload = {
|
|
296
295
|
type: 'reference',
|
|
297
296
|
url: '0.payload',
|
|
298
297
|
protocol: 'zip',
|
|
@@ -307,7 +306,8 @@ async function _generateManifest(
|
|
|
307
306
|
// generate the manifest first, then insert integrity information into it
|
|
308
307
|
encryptionInformation: encryptionInformationStr,
|
|
309
308
|
assertions: assertions,
|
|
310
|
-
|
|
309
|
+
// when `targetSpecVersion` is provided, overrides the tdfSpecVersion
|
|
310
|
+
schemaVersion: targetSpecVersion || tdfSpecVersion,
|
|
311
311
|
};
|
|
312
312
|
}
|
|
313
313
|
|
|
@@ -340,6 +340,30 @@ async function getSignature(
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
+
async function getSignatureVersion422(
|
|
344
|
+
unwrappedKeyBinary: Binary,
|
|
345
|
+
payloadBinary: Binary,
|
|
346
|
+
algorithmType: IntegrityAlgorithm,
|
|
347
|
+
cryptoService: CryptoService
|
|
348
|
+
): Promise<string> {
|
|
349
|
+
switch (algorithmType.toUpperCase()) {
|
|
350
|
+
case 'GMAC':
|
|
351
|
+
// use the auth tag baked into the encrypted payload
|
|
352
|
+
return buffToString(Uint8Array.from(payloadBinary.asByteArray()).slice(-16), 'hex');
|
|
353
|
+
case 'HS256':
|
|
354
|
+
return await cryptoService.hmac(
|
|
355
|
+
buffToString(new Uint8Array(unwrappedKeyBinary.asArrayBuffer()), 'hex'),
|
|
356
|
+
buffToString(new Uint8Array(payloadBinary.asArrayBuffer()), 'utf-8')
|
|
357
|
+
);
|
|
358
|
+
default:
|
|
359
|
+
throw new ConfigurationError(`Unsupported signature alg [${algorithmType}]`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function isTargetSpecLegacyTDF(targetSpecVersion?: string): boolean {
|
|
364
|
+
return targetSpecVersion === HEX_SEMVER_VERSION;
|
|
365
|
+
}
|
|
366
|
+
|
|
343
367
|
export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedReadableStream> {
|
|
344
368
|
if (!cfg.authProvider) {
|
|
345
369
|
throw new ConfigurationError('No authorization middleware defined');
|
|
@@ -368,6 +392,7 @@ export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedR
|
|
|
368
392
|
let bytesProcessed = 0;
|
|
369
393
|
let crcCounter = 0;
|
|
370
394
|
let fileByteCount = 0;
|
|
395
|
+
let aggregateHash422 = '';
|
|
371
396
|
const segmentHashList: Uint8Array[] = [];
|
|
372
397
|
|
|
373
398
|
const zipWriter = new ZipWriter();
|
|
@@ -375,7 +400,8 @@ export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedR
|
|
|
375
400
|
cfg.keyForManifest,
|
|
376
401
|
cfg.encryptionInformation,
|
|
377
402
|
cfg.policy,
|
|
378
|
-
cfg.mimeType
|
|
403
|
+
cfg.mimeType,
|
|
404
|
+
cfg.tdfSpecVersion ?? '4.3.0'
|
|
379
405
|
);
|
|
380
406
|
|
|
381
407
|
if (!manifest) {
|
|
@@ -460,17 +486,30 @@ export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedR
|
|
|
460
486
|
crcCounter = 0;
|
|
461
487
|
fileByteCount = 0;
|
|
462
488
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
489
|
+
let aggregateHash: string | Uint8Array;
|
|
490
|
+
if (isTargetSpecLegacyTDF(cfg.tdfSpecVersion)) {
|
|
491
|
+
aggregateHash = aggregateHash422;
|
|
492
|
+
const payloadSigStr = await getSignatureVersion422(
|
|
493
|
+
cfg.keyForEncryption.unwrappedKeyBinary,
|
|
494
|
+
Binary.fromString(aggregateHash),
|
|
495
|
+
cfg.integrityAlgorithm,
|
|
496
|
+
cfg.cryptoService
|
|
497
|
+
);
|
|
498
|
+
manifest.encryptionInformation.integrityInformation.rootSignature.sig =
|
|
499
|
+
base64.encode(payloadSigStr);
|
|
500
|
+
} else {
|
|
501
|
+
// hash the concat of all hashes
|
|
502
|
+
aggregateHash = await concatenateUint8Array(segmentHashList);
|
|
503
|
+
|
|
504
|
+
const payloadSig = await getSignature(
|
|
505
|
+
new Uint8Array(cfg.keyForEncryption.unwrappedKeyBinary.asArrayBuffer()),
|
|
506
|
+
aggregateHash,
|
|
507
|
+
cfg.integrityAlgorithm
|
|
508
|
+
);
|
|
471
509
|
|
|
472
|
-
|
|
473
|
-
|
|
510
|
+
const rootSig = base64.encodeArrayBuffer(payloadSig);
|
|
511
|
+
manifest.encryptionInformation.integrityInformation.rootSignature.sig = rootSig;
|
|
512
|
+
}
|
|
474
513
|
manifest.encryptionInformation.integrityInformation.rootSignature.alg =
|
|
475
514
|
cfg.integrityAlgorithm;
|
|
476
515
|
|
|
@@ -576,16 +615,30 @@ export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedR
|
|
|
576
615
|
cfg.keyForEncryption.unwrappedKeyBinary
|
|
577
616
|
);
|
|
578
617
|
const payloadBuffer = new Uint8Array(encryptedResult.payload.asByteArray());
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
618
|
+
let hash: string;
|
|
619
|
+
if (isTargetSpecLegacyTDF(cfg.tdfSpecVersion)) {
|
|
620
|
+
const payloadSigStr = await getSignatureVersion422(
|
|
621
|
+
cfg.keyForEncryption.unwrappedKeyBinary,
|
|
622
|
+
encryptedResult.payload,
|
|
623
|
+
cfg.segmentIntegrityAlgorithm,
|
|
624
|
+
cfg.cryptoService
|
|
625
|
+
);
|
|
626
|
+
// combined string of all hashes for root signature
|
|
627
|
+
aggregateHash422 += payloadSigStr;
|
|
628
|
+
hash = base64.encode(payloadSigStr);
|
|
629
|
+
} else {
|
|
630
|
+
const payloadSig = await getSignature(
|
|
631
|
+
new Uint8Array(cfg.keyForEncryption.unwrappedKeyBinary.asArrayBuffer()),
|
|
632
|
+
new Uint8Array(encryptedResult.payload.asArrayBuffer()),
|
|
633
|
+
cfg.segmentIntegrityAlgorithm
|
|
634
|
+
);
|
|
584
635
|
|
|
585
|
-
|
|
636
|
+
segmentHashList.push(new Uint8Array(payloadSig));
|
|
637
|
+
hash = base64.encodeArrayBuffer(payloadSig);
|
|
638
|
+
}
|
|
586
639
|
|
|
587
640
|
segmentInfos.push({
|
|
588
|
-
hash
|
|
641
|
+
hash,
|
|
589
642
|
segmentSize: chunk.length === segmentSizeDefault ? undefined : chunk.length,
|
|
590
643
|
encryptedSegmentSize:
|
|
591
644
|
payloadBuffer.length === encryptedSegmentSizeDefault ? undefined : payloadBuffer.length,
|
|
@@ -795,7 +848,7 @@ async function decryptChunk(
|
|
|
795
848
|
hash: string,
|
|
796
849
|
cipher: SymmetricCipher,
|
|
797
850
|
segmentIntegrityAlgorithm: IntegrityAlgorithm,
|
|
798
|
-
|
|
851
|
+
specVersion: string
|
|
799
852
|
): Promise<DecryptResult> {
|
|
800
853
|
if (segmentIntegrityAlgorithm !== 'GMAC' && segmentIntegrityAlgorithm !== 'HS256') {
|
|
801
854
|
throw new UnsupportedError(`Unsupported integrity alg [${segmentIntegrityAlgorithm}]`);
|
|
@@ -806,7 +859,7 @@ async function decryptChunk(
|
|
|
806
859
|
segmentIntegrityAlgorithm
|
|
807
860
|
);
|
|
808
861
|
|
|
809
|
-
const segmentHash =
|
|
862
|
+
const segmentHash = isTargetSpecLegacyTDF(specVersion)
|
|
810
863
|
? base64.encode(hex.encodeArrayBuffer(segmentSig))
|
|
811
864
|
: base64.encodeArrayBuffer(segmentSig);
|
|
812
865
|
|
|
@@ -824,7 +877,7 @@ async function updateChunkQueue(
|
|
|
824
877
|
cipher: SymmetricCipher,
|
|
825
878
|
segmentIntegrityAlgorithm: IntegrityAlgorithm,
|
|
826
879
|
cryptoService: CryptoService,
|
|
827
|
-
|
|
880
|
+
specVersion: string
|
|
828
881
|
) {
|
|
829
882
|
const chunksInOneDownload = 500;
|
|
830
883
|
let requests = [];
|
|
@@ -865,7 +918,7 @@ async function updateChunkQueue(
|
|
|
865
918
|
slice,
|
|
866
919
|
cipher,
|
|
867
920
|
segmentIntegrityAlgorithm,
|
|
868
|
-
|
|
921
|
+
specVersion,
|
|
869
922
|
});
|
|
870
923
|
}
|
|
871
924
|
})()
|
|
@@ -879,7 +932,7 @@ export async function sliceAndDecrypt({
|
|
|
879
932
|
slice,
|
|
880
933
|
cipher,
|
|
881
934
|
segmentIntegrityAlgorithm,
|
|
882
|
-
|
|
935
|
+
specVersion,
|
|
883
936
|
}: {
|
|
884
937
|
buffer: Uint8Array;
|
|
885
938
|
reconstructedKeyBinary: Binary;
|
|
@@ -887,7 +940,7 @@ export async function sliceAndDecrypt({
|
|
|
887
940
|
cipher: SymmetricCipher;
|
|
888
941
|
cryptoService: CryptoService;
|
|
889
942
|
segmentIntegrityAlgorithm: IntegrityAlgorithm;
|
|
890
|
-
|
|
943
|
+
specVersion: string;
|
|
891
944
|
}) {
|
|
892
945
|
for (const index in slice) {
|
|
893
946
|
const { encryptedOffset, encryptedSegmentSize, plainSegmentSize } = slice[index];
|
|
@@ -909,7 +962,7 @@ export async function sliceAndDecrypt({
|
|
|
909
962
|
slice[index]['hash'],
|
|
910
963
|
cipher,
|
|
911
964
|
segmentIntegrityAlgorithm,
|
|
912
|
-
|
|
965
|
+
specVersion
|
|
913
966
|
);
|
|
914
967
|
if (plainSegmentSize && result.payload.length() !== plainSegmentSize) {
|
|
915
968
|
throw new DecryptError(
|
|
@@ -965,8 +1018,8 @@ export async function decryptStreamFrom(
|
|
|
965
1018
|
const encryptedSegmentSizeDefault = defaultSegmentSize || DEFAULT_SEGMENT_SIZE;
|
|
966
1019
|
|
|
967
1020
|
// check if the TDF is a legacy TDF
|
|
968
|
-
const specVersion = manifest.schemaVersion || manifest.tdf_spec_version;
|
|
969
|
-
const isLegacyTDF =
|
|
1021
|
+
const specVersion = manifest.schemaVersion || manifest.tdf_spec_version || '4.2.2';
|
|
1022
|
+
const isLegacyTDF = isTargetSpecLegacyTDF(specVersion);
|
|
970
1023
|
|
|
971
1024
|
// Decode each hash and store it in an array of Uint8Array
|
|
972
1025
|
const segmentHashList = segments.map(
|
|
@@ -1052,7 +1105,7 @@ export async function decryptStreamFrom(
|
|
|
1052
1105
|
cipher,
|
|
1053
1106
|
segmentIntegrityAlg,
|
|
1054
1107
|
cfg.cryptoService,
|
|
1055
|
-
|
|
1108
|
+
specVersion
|
|
1056
1109
|
);
|
|
1057
1110
|
|
|
1058
1111
|
let progress = 0;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUG9saWN5T2JqZWN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RkZi9Qb2xpY3lPYmplY3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AttributeSet = void 0;
|
|
4
|
-
const jose_1 = require("jose");
|
|
5
|
-
class AttributeSet {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.verbose = false;
|
|
8
|
-
this.attributes = [];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Check if attribute is in the list
|
|
12
|
-
* @param attribute URL of the attribute
|
|
13
|
-
* @return if attribute is in the set
|
|
14
|
-
*/
|
|
15
|
-
has(attribute = '') {
|
|
16
|
-
// This could be much more elegant with something other than an
|
|
17
|
-
// array as the data structure. This is OK-ish only because the
|
|
18
|
-
// expected size of the data structure is small
|
|
19
|
-
// console.log(">>> ----- Has Attribute" + attribute);
|
|
20
|
-
return !!this.attributes.find((attrObj) => attrObj.attribute === attribute);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Get an attribute by URL
|
|
24
|
-
* @param attribute URL of the attribute
|
|
25
|
-
* @return attribute in object form, if found
|
|
26
|
-
*/
|
|
27
|
-
get(attribute = '') {
|
|
28
|
-
// This could be much more elegant with something other than an
|
|
29
|
-
// array as the data structure. This is OK-ish only because the
|
|
30
|
-
// expected size of the data structure is small
|
|
31
|
-
// console.log(">>> ----- Get Attribute" + attribute);
|
|
32
|
-
const result = this.attributes.filter((attrObj) => attrObj.attribute == attribute);
|
|
33
|
-
return result.length > 0 ? result[0] : null;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get all the attributes.
|
|
37
|
-
* @return default attribute in object form or null
|
|
38
|
-
*/
|
|
39
|
-
getDefault() {
|
|
40
|
-
return this.defaultAttribute || null;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Get the default attribute, if it exists.
|
|
44
|
-
* @return return all the attribute urls
|
|
45
|
-
*/
|
|
46
|
-
getUrls() {
|
|
47
|
-
return this.attributes.map((attr) => attr.attribute);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Add an attribute to the set. Should be idempotent.
|
|
51
|
-
* @param attrObj AttributeObject to add, in non-JWT form
|
|
52
|
-
* @return the attribute object if successful, or null
|
|
53
|
-
*/
|
|
54
|
-
addAttribute(attrObj) {
|
|
55
|
-
// Check for duplicate entries to assure idempotency.
|
|
56
|
-
if (this.has(attrObj.attribute)) {
|
|
57
|
-
// This may be a common occurance, so only un-comment this log message
|
|
58
|
-
// if you want verbose mode.
|
|
59
|
-
// console.log(`Attribute ${attrObj.attribute} is already loaded.`);
|
|
60
|
-
return null; // reject silently
|
|
61
|
-
}
|
|
62
|
-
if (attrObj.isDefault === true) {
|
|
63
|
-
if (this.defaultAttribute && this.defaultAttribute.attribute !== attrObj.attribute) {
|
|
64
|
-
// Remove the existing default attribute to make room for the new one
|
|
65
|
-
this.deleteAttribute(this.defaultAttribute.attribute);
|
|
66
|
-
}
|
|
67
|
-
this.defaultAttribute = attrObj;
|
|
68
|
-
}
|
|
69
|
-
this.attributes.push(attrObj);
|
|
70
|
-
return attrObj;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Delete an attribute from the set. Should be idempotent.
|
|
74
|
-
* @param attrUrl - URL of Attribute object to delete.
|
|
75
|
-
* @return The attribute object if successful or null if not
|
|
76
|
-
*/
|
|
77
|
-
deleteAttribute(attrUrl = '') {
|
|
78
|
-
const deleted = this.get(attrUrl);
|
|
79
|
-
if (deleted) {
|
|
80
|
-
this.attributes = this.attributes.filter((attrObj) => attrObj.attribute != attrUrl);
|
|
81
|
-
}
|
|
82
|
-
return deleted;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Add a list of attributes in object form
|
|
86
|
-
* @param attributes List of attribute objects as provided in an EntityObject
|
|
87
|
-
* @param easPublicKey EAS public key for decrypting the JWTs
|
|
88
|
-
* @return list of attribute objects
|
|
89
|
-
*/
|
|
90
|
-
addAttributes(attributes = []) {
|
|
91
|
-
return attributes
|
|
92
|
-
.map((attrObj) => {
|
|
93
|
-
return this.addAttribute(attrObj); // Returns promise
|
|
94
|
-
})
|
|
95
|
-
.filter((x) => x);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Add an attribute in JWT form = { jwt: <string jwt> }
|
|
99
|
-
* @param {Object} jwtAttribute - Attribute object in JWT form.
|
|
100
|
-
* @return {Object} - Decrypted and added attribute object
|
|
101
|
-
*/
|
|
102
|
-
addJwtAttribute(jwtAttribute) {
|
|
103
|
-
const attrJwt = jwtAttribute?.jwt;
|
|
104
|
-
// Can't verify the JWT because the client does not have the easPublicKey,
|
|
105
|
-
// but the contents of the JWT can be decoded.
|
|
106
|
-
const attrObjPayload = attrJwt && (0, jose_1.decodeJwt)(attrJwt);
|
|
107
|
-
if (!attrObjPayload) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
// JWT payloads contain many things, incluing .iat and .exp. This
|
|
111
|
-
// extraneous material should be stripped away before adding the
|
|
112
|
-
// attribute to the attributeSet.
|
|
113
|
-
const { attribute, displayName, pubKey, kasUrl } = attrObjPayload;
|
|
114
|
-
const attrObj = { attribute, displayName, pubKey, kasUrl, jwt: attrJwt };
|
|
115
|
-
if (attrObjPayload.isDefault) {
|
|
116
|
-
attrObj.isDefault = !!attrObjPayload.isDefault;
|
|
117
|
-
}
|
|
118
|
-
return this.addAttribute(attrObj);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.AttributeSet = AttributeSet;
|
|
122
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3RkZjMvc3JjL21vZGVscy9hdHRyaWJ1dGUtc2V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLCtCQUFpQztBQVlqQyxNQUFhLFlBQVk7SUFPdkI7UUFKQSxZQUFPLEdBQVksS0FBSyxDQUFDO1FBS3ZCLElBQUksQ0FBQyxVQUFVLEdBQUcsRUFBRSxDQUFDO0lBQ3ZCLENBQUM7SUFFRDs7OztPQUlHO0lBQ0gsR0FBRyxDQUFDLFNBQVMsR0FBRyxFQUFFO1FBQ2hCLCtEQUErRDtRQUMvRCwrREFBK0Q7UUFDL0QsK0NBQStDO1FBQy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|
2
|
-
export interface PolicyObjectBody {
|
|
3
|
-
readonly dataAttributes: AttributeObject[];
|
|
4
|
-
readonly dissem: string[];
|
|
5
|
-
}
|
|
6
|
-
export interface PolicyObject {
|
|
7
|
-
readonly uuid: string;
|
|
8
|
-
readonly body: PolicyObjectBody;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=PolicyObject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PolicyObject.d.ts","sourceRoot":"","sources":["../../../../src/tdf/PolicyObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,cAAc,EAAE,eAAe,EAAE,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACjC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export type AttributeObject = {
|
|
2
|
-
attribute: string;
|
|
3
|
-
kasUrl?: string;
|
|
4
|
-
kid?: string;
|
|
5
|
-
pubKey?: string;
|
|
6
|
-
displayName?: string;
|
|
7
|
-
isDefault?: boolean;
|
|
8
|
-
jwt?: string;
|
|
9
|
-
};
|
|
10
|
-
export declare class AttributeSet {
|
|
11
|
-
attributes: AttributeObject[];
|
|
12
|
-
verbose: boolean;
|
|
13
|
-
defaultAttribute?: AttributeObject;
|
|
14
|
-
constructor();
|
|
15
|
-
/**
|
|
16
|
-
* Check if attribute is in the list
|
|
17
|
-
* @param attribute URL of the attribute
|
|
18
|
-
* @return if attribute is in the set
|
|
19
|
-
*/
|
|
20
|
-
has(attribute?: string): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Get an attribute by URL
|
|
23
|
-
* @param attribute URL of the attribute
|
|
24
|
-
* @return attribute in object form, if found
|
|
25
|
-
*/
|
|
26
|
-
get(attribute?: string): AttributeObject | null;
|
|
27
|
-
/**
|
|
28
|
-
* Get all the attributes.
|
|
29
|
-
* @return default attribute in object form or null
|
|
30
|
-
*/
|
|
31
|
-
getDefault(): AttributeObject | null;
|
|
32
|
-
/**
|
|
33
|
-
* Get the default attribute, if it exists.
|
|
34
|
-
* @return return all the attribute urls
|
|
35
|
-
*/
|
|
36
|
-
getUrls(): string[];
|
|
37
|
-
/**
|
|
38
|
-
* Add an attribute to the set. Should be idempotent.
|
|
39
|
-
* @param attrObj AttributeObject to add, in non-JWT form
|
|
40
|
-
* @return the attribute object if successful, or null
|
|
41
|
-
*/
|
|
42
|
-
addAttribute(attrObj: AttributeObject): AttributeObject | null;
|
|
43
|
-
/**
|
|
44
|
-
* Delete an attribute from the set. Should be idempotent.
|
|
45
|
-
* @param attrUrl - URL of Attribute object to delete.
|
|
46
|
-
* @return The attribute object if successful or null if not
|
|
47
|
-
*/
|
|
48
|
-
deleteAttribute(attrUrl?: string): AttributeObject | null;
|
|
49
|
-
/**
|
|
50
|
-
* Add a list of attributes in object form
|
|
51
|
-
* @param attributes List of attribute objects as provided in an EntityObject
|
|
52
|
-
* @param easPublicKey EAS public key for decrypting the JWTs
|
|
53
|
-
* @return list of attribute objects
|
|
54
|
-
*/
|
|
55
|
-
addAttributes(attributes?: AttributeObject[]): (AttributeObject | null)[];
|
|
56
|
-
/**
|
|
57
|
-
* Add an attribute in JWT form = { jwt: <string jwt> }
|
|
58
|
-
* @param {Object} jwtAttribute - Attribute object in JWT form.
|
|
59
|
-
* @return {Object} - Decrypted and added attribute object
|
|
60
|
-
*/
|
|
61
|
-
addJwtAttribute(jwtAttribute: {
|
|
62
|
-
jwt: string;
|
|
63
|
-
}): AttributeObject | null;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=attribute-set.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attribute-set.d.ts","sourceRoot":"","sources":["../../../../../tdf3/src/models/attribute-set.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,YAAY;IACvB,UAAU,EAAE,eAAe,EAAE,CAAC;IAE9B,OAAO,EAAE,OAAO,CAAS;IAEzB,gBAAgB,CAAC,EAAE,eAAe,CAAC;;IAMnC;;;;OAIG;IACH,GAAG,CAAC,SAAS,SAAK,GAAG,OAAO;IAQ5B;;;;OAIG;IACH,GAAG,CAAC,SAAS,SAAK,GAAG,eAAe,GAAG,IAAI;IAS3C;;;OAGG;IACH,UAAU,IAAI,eAAe,GAAG,IAAI;IAIpC;;;OAGG;IACH,OAAO,IAAI,MAAM,EAAE;IAInB;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,IAAI;IAoB9D;;;;OAIG;IACH,eAAe,CAAC,OAAO,SAAK,GAAG,eAAe,GAAG,IAAI;IAQrD;;;;;OAKG;IACH,aAAa,CAAC,UAAU,GAAE,eAAe,EAAO,GAAG,CAAC,eAAe,GAAG,IAAI,CAAC,EAAE;IAQ7E;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;CAkB9C"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { decodeJwt } from 'jose';
|
|
2
|
-
export class AttributeSet {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.verbose = false;
|
|
5
|
-
this.attributes = [];
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Check if attribute is in the list
|
|
9
|
-
* @param attribute URL of the attribute
|
|
10
|
-
* @return if attribute is in the set
|
|
11
|
-
*/
|
|
12
|
-
has(attribute = '') {
|
|
13
|
-
// This could be much more elegant with something other than an
|
|
14
|
-
// array as the data structure. This is OK-ish only because the
|
|
15
|
-
// expected size of the data structure is small
|
|
16
|
-
// console.log(">>> ----- Has Attribute" + attribute);
|
|
17
|
-
return !!this.attributes.find((attrObj) => attrObj.attribute === attribute);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Get an attribute by URL
|
|
21
|
-
* @param attribute URL of the attribute
|
|
22
|
-
* @return attribute in object form, if found
|
|
23
|
-
*/
|
|
24
|
-
get(attribute = '') {
|
|
25
|
-
// This could be much more elegant with something other than an
|
|
26
|
-
// array as the data structure. This is OK-ish only because the
|
|
27
|
-
// expected size of the data structure is small
|
|
28
|
-
// console.log(">>> ----- Get Attribute" + attribute);
|
|
29
|
-
const result = this.attributes.filter((attrObj) => attrObj.attribute == attribute);
|
|
30
|
-
return result.length > 0 ? result[0] : null;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Get all the attributes.
|
|
34
|
-
* @return default attribute in object form or null
|
|
35
|
-
*/
|
|
36
|
-
getDefault() {
|
|
37
|
-
return this.defaultAttribute || null;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get the default attribute, if it exists.
|
|
41
|
-
* @return return all the attribute urls
|
|
42
|
-
*/
|
|
43
|
-
getUrls() {
|
|
44
|
-
return this.attributes.map((attr) => attr.attribute);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Add an attribute to the set. Should be idempotent.
|
|
48
|
-
* @param attrObj AttributeObject to add, in non-JWT form
|
|
49
|
-
* @return the attribute object if successful, or null
|
|
50
|
-
*/
|
|
51
|
-
addAttribute(attrObj) {
|
|
52
|
-
// Check for duplicate entries to assure idempotency.
|
|
53
|
-
if (this.has(attrObj.attribute)) {
|
|
54
|
-
// This may be a common occurance, so only un-comment this log message
|
|
55
|
-
// if you want verbose mode.
|
|
56
|
-
// console.log(`Attribute ${attrObj.attribute} is already loaded.`);
|
|
57
|
-
return null; // reject silently
|
|
58
|
-
}
|
|
59
|
-
if (attrObj.isDefault === true) {
|
|
60
|
-
if (this.defaultAttribute && this.defaultAttribute.attribute !== attrObj.attribute) {
|
|
61
|
-
// Remove the existing default attribute to make room for the new one
|
|
62
|
-
this.deleteAttribute(this.defaultAttribute.attribute);
|
|
63
|
-
}
|
|
64
|
-
this.defaultAttribute = attrObj;
|
|
65
|
-
}
|
|
66
|
-
this.attributes.push(attrObj);
|
|
67
|
-
return attrObj;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Delete an attribute from the set. Should be idempotent.
|
|
71
|
-
* @param attrUrl - URL of Attribute object to delete.
|
|
72
|
-
* @return The attribute object if successful or null if not
|
|
73
|
-
*/
|
|
74
|
-
deleteAttribute(attrUrl = '') {
|
|
75
|
-
const deleted = this.get(attrUrl);
|
|
76
|
-
if (deleted) {
|
|
77
|
-
this.attributes = this.attributes.filter((attrObj) => attrObj.attribute != attrUrl);
|
|
78
|
-
}
|
|
79
|
-
return deleted;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Add a list of attributes in object form
|
|
83
|
-
* @param attributes List of attribute objects as provided in an EntityObject
|
|
84
|
-
* @param easPublicKey EAS public key for decrypting the JWTs
|
|
85
|
-
* @return list of attribute objects
|
|
86
|
-
*/
|
|
87
|
-
addAttributes(attributes = []) {
|
|
88
|
-
return attributes
|
|
89
|
-
.map((attrObj) => {
|
|
90
|
-
return this.addAttribute(attrObj); // Returns promise
|
|
91
|
-
})
|
|
92
|
-
.filter((x) => x);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Add an attribute in JWT form = { jwt: <string jwt> }
|
|
96
|
-
* @param {Object} jwtAttribute - Attribute object in JWT form.
|
|
97
|
-
* @return {Object} - Decrypted and added attribute object
|
|
98
|
-
*/
|
|
99
|
-
addJwtAttribute(jwtAttribute) {
|
|
100
|
-
const attrJwt = jwtAttribute?.jwt;
|
|
101
|
-
// Can't verify the JWT because the client does not have the easPublicKey,
|
|
102
|
-
// but the contents of the JWT can be decoded.
|
|
103
|
-
const attrObjPayload = attrJwt && decodeJwt(attrJwt);
|
|
104
|
-
if (!attrObjPayload) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
// JWT payloads contain many things, incluing .iat and .exp. This
|
|
108
|
-
// extraneous material should be stripped away before adding the
|
|
109
|
-
// attribute to the attributeSet.
|
|
110
|
-
const { attribute, displayName, pubKey, kasUrl } = attrObjPayload;
|
|
111
|
-
const attrObj = { attribute, displayName, pubKey, kasUrl, jwt: attrJwt };
|
|
112
|
-
if (attrObjPayload.isDefault) {
|
|
113
|
-
attrObj.isDefault = !!attrObjPayload.isDefault;
|
|
114
|
-
}
|
|
115
|
-
return this.addAttribute(attrObj);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3RkZjMvc3JjL21vZGVscy9hdHRyaWJ1dGUtc2V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFZakMsTUFBTSxPQUFPLFlBQVk7SUFPdkI7UUFKQSxZQUFPLEdBQVksS0FBSyxDQUFDO1FBS3ZCLElBQUksQ0FBQyxVQUFVLEdBQUcsRUFBRSxDQUFDO0lBQ3ZCLENBQUM7SUFFRDs7OztPQUlHO0lBQ0gsR0FBRyxDQUFDLFNBQVMsR0FBRyxFQUFFO1FBQ2hCLCtEQUErRDtRQUMvRCwrREFBK0Q7UUFDL0QsK0NBQStDO1FBQy9D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
-
|
|
3
|
-
export interface PolicyObjectBody {
|
|
4
|
-
readonly dataAttributes: AttributeObject[];
|
|
5
|
-
readonly dissem: string[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface PolicyObject {
|
|
9
|
-
readonly uuid: string;
|
|
10
|
-
readonly body: PolicyObjectBody;
|
|
11
|
-
}
|