@opentdf/sdk 0.3.0-beta.2029 → 0.3.0-beta.2050
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 +3 -3
- package/dist/cjs/src/tdf/Policy.js +15 -12
- 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 +1 -1
- 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/tdf/Policy.d.ts +4 -2
- package/dist/types/src/tdf/Policy.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +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 +1 -7
- 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 +3 -3
- package/dist/web/src/tdf/Policy.js +13 -10
- 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 +1 -1
- 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 +5 -5
- package/src/tdf/Policy.ts +15 -9
- 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 +3 -8
- 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/src/opentdf.ts
CHANGED
|
@@ -29,8 +29,8 @@ import {
|
|
|
29
29
|
type IntegrityAlgorithm,
|
|
30
30
|
} from '../tdf3/src/tdf.js';
|
|
31
31
|
import { base64 } from './encodings/index.js';
|
|
32
|
-
import { PolicyObject } from './tdf/PolicyObject.js';
|
|
33
32
|
import PolicyType from './nanotdf/enum/PolicyTypeEnum.js';
|
|
33
|
+
import { Policy } from '../tdf3/src/models/policy.js';
|
|
34
34
|
|
|
35
35
|
export {
|
|
36
36
|
type Assertion,
|
|
@@ -525,8 +525,8 @@ class NanoTDFReader {
|
|
|
525
525
|
throw new Error('unsupported policy type');
|
|
526
526
|
}
|
|
527
527
|
const policyString = new TextDecoder().decode(nanotdf.header.policy.content);
|
|
528
|
-
const policy = JSON.parse(policyString) as
|
|
529
|
-
return policy
|
|
528
|
+
const policy = JSON.parse(policyString) as Policy;
|
|
529
|
+
return policy?.body?.dataAttributes.map((a) => a.attribute) || [];
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
532
|
|
|
@@ -593,8 +593,8 @@ class ZTDFReader {
|
|
|
593
593
|
async attributes(): Promise<string[]> {
|
|
594
594
|
const manifest = await this.manifest();
|
|
595
595
|
const policyJSON = base64.decode(manifest.encryptionInformation.policy);
|
|
596
|
-
const policy = JSON.parse(policyJSON) as
|
|
597
|
-
return policy
|
|
596
|
+
const policy = JSON.parse(policyJSON) as Policy;
|
|
597
|
+
return policy?.body?.dataAttributes.map((a) => a.attribute) || [];
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
|
package/src/tdf/Policy.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type AttributeObject } from './AttributeObject.js';
|
|
2
1
|
import { v4 as uuid } from 'uuid';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { type AttributeObject } from '../../tdf3/src/models/attribute.js';
|
|
4
|
+
import { type Policy } from '../../tdf3/src/models/policy.js';
|
|
5
|
+
|
|
6
|
+
export class PolicyBuilder {
|
|
5
7
|
static CURRENT_VERSION = '1.1.0';
|
|
6
8
|
|
|
7
9
|
private uuidStr = uuid();
|
|
@@ -33,18 +35,22 @@ export class Policy {
|
|
|
33
35
|
this.dataAttributesList.push(attribute);
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
toPolicy(): Policy {
|
|
39
|
+
return {
|
|
40
|
+
uuid: this.uuidStr,
|
|
41
|
+
body: {
|
|
42
|
+
dataAttributes: this.dataAttributesList,
|
|
43
|
+
dissem: this.dissemList,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
/**
|
|
37
49
|
* Returns the JSON string of Policy object
|
|
38
50
|
*
|
|
39
51
|
* @return {string} [The constructed Policy object as JSON string]
|
|
40
52
|
*/
|
|
41
53
|
toJSON(): string {
|
|
42
|
-
return JSON.stringify(
|
|
43
|
-
uuid: this.uuidStr,
|
|
44
|
-
body: {
|
|
45
|
-
dataAttributes: this.dataAttributesList,
|
|
46
|
-
dissem: this.dissemList,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
54
|
+
return JSON.stringify(this.toPolicy());
|
|
49
55
|
}
|
|
50
56
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Information about a data or entity attribute, its meaning and interpretation.
|
|
3
|
+
* While usually we just refer to an attribute by its URL,
|
|
4
|
+
* we often need to store additional information about it,
|
|
5
|
+
* for display or analysis.
|
|
6
|
+
*/
|
|
7
|
+
export type AttributeObject = {
|
|
8
|
+
// The fully qualified name of the attribute, generally a URL
|
|
9
|
+
attribute: string;
|
|
10
|
+
// Optional descriptive name of the attribute
|
|
11
|
+
displayName?: string;
|
|
12
|
+
// Indicates a default attribute, usually for all policies associated with a KAS
|
|
13
|
+
isDefault?: boolean;
|
|
14
|
+
|
|
15
|
+
// Optional: A cryptographically bound version of the attribute. Deprecated: use a JWS with this as the payload.
|
|
16
|
+
jwt?: string;
|
|
17
|
+
|
|
18
|
+
// A KAS that is associated with the attribute.
|
|
19
|
+
kasUrl?: string;
|
|
20
|
+
|
|
21
|
+
// The preferred public key for the attribute
|
|
22
|
+
kid?: string;
|
|
23
|
+
|
|
24
|
+
// The public key value for the attribute
|
|
25
|
+
pubKey?: string;
|
|
26
|
+
};
|
package/tdf3/src/models/index.ts
CHANGED
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';
|
|
@@ -55,6 +54,7 @@ import { unsigned } from './utils/buffer-crc32.js';
|
|
|
55
54
|
import { ZipReader, ZipWriter, keyMerge, concatUint8 } 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;
|
|
@@ -73,12 +73,7 @@ export type EncryptionOptions = {
|
|
|
73
73
|
|
|
74
74
|
type KeyMiddleware = DecryptParams['keyMiddleware'];
|
|
75
75
|
|
|
76
|
-
export type Metadata =
|
|
77
|
-
connectOptions?: {
|
|
78
|
-
testUrl: string;
|
|
79
|
-
};
|
|
80
|
-
policyObject?: PolicyObject;
|
|
81
|
-
};
|
|
76
|
+
export type Metadata = unknown;
|
|
82
77
|
|
|
83
78
|
export type BuildKeyAccess = {
|
|
84
79
|
type: KeyAccessType;
|
|
@@ -292,7 +287,7 @@ async function _generateManifest(
|
|
|
292
287
|
mimeType: string | undefined
|
|
293
288
|
): Promise<Manifest> {
|
|
294
289
|
// (maybe) Fields are quoted to avoid renaming
|
|
295
|
-
const payload = {
|
|
290
|
+
const payload: Payload = {
|
|
296
291
|
type: 'reference',
|
|
297
292
|
url: '0.payload',
|
|
298
293
|
protocol: 'zip',
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3RkZjMvc3JjL21vZGVscy9hdHRyaWJ1dGUtc2V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLCtCQUFpQztBQVlqQyxNQUFhLFlBQVk7SU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csQ0FBQyxDQUFDLGNBQWMsQ0FBQyxTQUFTLENBQUM7UUFDakQsQ0FBQztRQUNELE9BQU8sSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUNwQyxDQUFDO0NBQ0Y7QUFqSUQsb0NBaUlDIn0=
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type AttributeObject } from './AttributeObject.js';
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3RkZjMvc3JjL21vZGVscy9hdHRyaWJ1dGUtc2V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFZakMsTUFBTSxPQUFPLFlBQVk7SUFP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DQUFDLGNBQWMsQ0FBQyxTQUFTLENBQUM7UUFDakQsQ0FBQztRQUNELE9BQU8sSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUNwQyxDQUFDO0NBQ0YifQ==
|
package/src/tdf/PolicyObject.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type AttributeObject } from './AttributeObject.js';
|
|
2
|
-
|
|
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
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { decodeJwt } from 'jose';
|
|
2
|
-
|
|
3
|
-
export type AttributeObject = {
|
|
4
|
-
attribute: string;
|
|
5
|
-
kasUrl?: string;
|
|
6
|
-
kid?: string;
|
|
7
|
-
pubKey?: string;
|
|
8
|
-
displayName?: string;
|
|
9
|
-
isDefault?: boolean;
|
|
10
|
-
jwt?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class AttributeSet {
|
|
14
|
-
attributes: AttributeObject[];
|
|
15
|
-
|
|
16
|
-
verbose: boolean = false;
|
|
17
|
-
|
|
18
|
-
defaultAttribute?: AttributeObject;
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
this.attributes = [];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Check if attribute is in the list
|
|
26
|
-
* @param attribute URL of the attribute
|
|
27
|
-
* @return if attribute is in the set
|
|
28
|
-
*/
|
|
29
|
-
has(attribute = ''): boolean {
|
|
30
|
-
// This could be much more elegant with something other than an
|
|
31
|
-
// array as the data structure. This is OK-ish only because the
|
|
32
|
-
// expected size of the data structure is small
|
|
33
|
-
// console.log(">>> ----- Has Attribute" + attribute);
|
|
34
|
-
return !!this.attributes.find((attrObj) => attrObj.attribute === attribute);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get an attribute by URL
|
|
39
|
-
* @param attribute URL of the attribute
|
|
40
|
-
* @return attribute in object form, if found
|
|
41
|
-
*/
|
|
42
|
-
get(attribute = ''): AttributeObject | null {
|
|
43
|
-
// This could be much more elegant with something other than an
|
|
44
|
-
// array as the data structure. This is OK-ish only because the
|
|
45
|
-
// expected size of the data structure is small
|
|
46
|
-
// console.log(">>> ----- Get Attribute" + attribute);
|
|
47
|
-
const result = this.attributes.filter((attrObj) => attrObj.attribute == attribute);
|
|
48
|
-
return result.length > 0 ? result[0] : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get all the attributes.
|
|
53
|
-
* @return default attribute in object form or null
|
|
54
|
-
*/
|
|
55
|
-
getDefault(): AttributeObject | null {
|
|
56
|
-
return this.defaultAttribute || null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Get the default attribute, if it exists.
|
|
61
|
-
* @return return all the attribute urls
|
|
62
|
-
*/
|
|
63
|
-
getUrls(): string[] {
|
|
64
|
-
return this.attributes.map((attr) => attr.attribute);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Add an attribute to the set. Should be idempotent.
|
|
69
|
-
* @param attrObj AttributeObject to add, in non-JWT form
|
|
70
|
-
* @return the attribute object if successful, or null
|
|
71
|
-
*/
|
|
72
|
-
addAttribute(attrObj: AttributeObject): AttributeObject | null {
|
|
73
|
-
// Check for duplicate entries to assure idempotency.
|
|
74
|
-
if (this.has(attrObj.attribute)) {
|
|
75
|
-
// This may be a common occurance, so only un-comment this log message
|
|
76
|
-
// if you want verbose mode.
|
|
77
|
-
// console.log(`Attribute ${attrObj.attribute} is already loaded.`);
|
|
78
|
-
return null; // reject silently
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (attrObj.isDefault === true) {
|
|
82
|
-
if (this.defaultAttribute && this.defaultAttribute.attribute !== attrObj.attribute) {
|
|
83
|
-
// Remove the existing default attribute to make room for the new one
|
|
84
|
-
this.deleteAttribute(this.defaultAttribute.attribute);
|
|
85
|
-
}
|
|
86
|
-
this.defaultAttribute = attrObj;
|
|
87
|
-
}
|
|
88
|
-
this.attributes.push(attrObj);
|
|
89
|
-
return attrObj;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Delete an attribute from the set. Should be idempotent.
|
|
94
|
-
* @param attrUrl - URL of Attribute object to delete.
|
|
95
|
-
* @return The attribute object if successful or null if not
|
|
96
|
-
*/
|
|
97
|
-
deleteAttribute(attrUrl = ''): AttributeObject | null {
|
|
98
|
-
const deleted = this.get(attrUrl);
|
|
99
|
-
if (deleted) {
|
|
100
|
-
this.attributes = this.attributes.filter((attrObj) => attrObj.attribute != attrUrl);
|
|
101
|
-
}
|
|
102
|
-
return deleted;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Add a list of attributes in object form
|
|
107
|
-
* @param attributes List of attribute objects as provided in an EntityObject
|
|
108
|
-
* @param easPublicKey EAS public key for decrypting the JWTs
|
|
109
|
-
* @return list of attribute objects
|
|
110
|
-
*/
|
|
111
|
-
addAttributes(attributes: AttributeObject[] = []): (AttributeObject | null)[] {
|
|
112
|
-
return attributes
|
|
113
|
-
.map((attrObj) => {
|
|
114
|
-
return this.addAttribute(attrObj); // Returns promise
|
|
115
|
-
})
|
|
116
|
-
.filter((x) => x);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Add an attribute in JWT form = { jwt: <string jwt> }
|
|
121
|
-
* @param {Object} jwtAttribute - Attribute object in JWT form.
|
|
122
|
-
* @return {Object} - Decrypted and added attribute object
|
|
123
|
-
*/
|
|
124
|
-
addJwtAttribute(jwtAttribute: { jwt: string }) {
|
|
125
|
-
const attrJwt = jwtAttribute?.jwt;
|
|
126
|
-
// Can't verify the JWT because the client does not have the easPublicKey,
|
|
127
|
-
// but the contents of the JWT can be decoded.
|
|
128
|
-
const attrObjPayload = attrJwt && decodeJwt(attrJwt);
|
|
129
|
-
if (!attrObjPayload) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
// JWT payloads contain many things, incluing .iat and .exp. This
|
|
133
|
-
// extraneous material should be stripped away before adding the
|
|
134
|
-
// attribute to the attributeSet.
|
|
135
|
-
const { attribute, displayName, pubKey, kasUrl } = attrObjPayload as AttributeObject;
|
|
136
|
-
const attrObj: AttributeObject = { attribute, displayName, pubKey, kasUrl, jwt: attrJwt };
|
|
137
|
-
if (attrObjPayload.isDefault) {
|
|
138
|
-
attrObj.isDefault = !!attrObjPayload.isDefault;
|
|
139
|
-
}
|
|
140
|
-
return this.addAttribute(attrObj);
|
|
141
|
-
}
|
|
142
|
-
}
|