@opentdf/sdk 0.2.0 → 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/auth/auth.js +1 -1
- package/dist/cjs/src/encodings/base64.js +1 -1
- package/dist/cjs/src/index.js +2 -1
- package/dist/cjs/src/nanoclients.js +17 -10
- package/dist/cjs/src/nanotdf/Client.js +1 -1
- package/dist/cjs/src/nanotdf/NanoTDF.js +1 -1
- package/dist/cjs/src/nanotdf/encrypt-dataset.js +1 -1
- package/dist/cjs/src/nanotdf/encrypt.js +1 -1
- package/dist/cjs/src/nanotdf/helpers/getHkdfSalt.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/digest.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/pemPublicToCrypto.js +4 -27
- package/dist/cjs/src/opentdf.js +175 -45
- package/dist/cjs/src/tdf/Policy.js +15 -12
- package/dist/cjs/src/version.js +1 -1
- package/dist/cjs/tdf3/index.js +1 -1
- package/dist/cjs/tdf3/src/assertions.js +1 -1
- package/dist/cjs/tdf3/src/crypto/salt.js +12 -0
- 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/models/key-access.js +3 -2
- package/dist/cjs/tdf3/src/tdf.js +8 -3
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/auth.d.ts +2 -2
- package/dist/types/src/auth/auth.d.ts.map +1 -1
- package/dist/types/src/auth/providers.d.ts.map +1 -1
- package/dist/types/src/encodings/base64.d.ts +1 -1
- package/dist/types/src/encodings/base64.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 +10 -11
- package/dist/types/src/nanoclients.d.ts.map +1 -1
- package/dist/types/src/nanotdf/Client.d.ts +1 -2
- package/dist/types/src/nanotdf/Client.d.ts.map +1 -1
- package/dist/types/src/nanotdf/NanoTDF.d.ts +1 -2
- package/dist/types/src/nanotdf/NanoTDF.d.ts.map +1 -1
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts +1 -2
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts.map +1 -1
- package/dist/types/src/nanotdf/encrypt.d.ts +1 -2
- package/dist/types/src/nanotdf/encrypt.d.ts.map +1 -1
- package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts +1 -2
- package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/digest.d.ts +1 -2
- package/dist/types/src/nanotdf-crypto/digest.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/pemPublicToCrypto.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +29 -5
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/seekable.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/src/utils.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/tdf3/index.d.ts +1 -1
- package/dist/types/tdf3/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +1 -2
- 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/index.d.ts +1 -6
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/validation.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/salt.d.ts +2 -0
- package/dist/types/tdf3/src/crypto/salt.d.ts.map +1 -0
- 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/key-access.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 +5 -9
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/web/src/access.js +1 -2
- package/dist/web/src/auth/auth.js +1 -1
- package/dist/web/src/encodings/base64.js +1 -1
- package/dist/web/src/index.js +2 -1
- package/dist/web/src/nanoclients.js +18 -11
- package/dist/web/src/nanotdf/Client.js +1 -1
- package/dist/web/src/nanotdf/NanoTDF.js +1 -1
- package/dist/web/src/nanotdf/encrypt-dataset.js +1 -1
- package/dist/web/src/nanotdf/encrypt.js +1 -1
- package/dist/web/src/nanotdf/helpers/getHkdfSalt.js +1 -1
- package/dist/web/src/nanotdf-crypto/digest.js +1 -1
- package/dist/web/src/nanotdf-crypto/pemPublicToCrypto.js +4 -27
- package/dist/web/src/opentdf.js +174 -44
- package/dist/web/src/tdf/Policy.js +13 -10
- package/dist/web/src/version.js +1 -1
- package/dist/web/tdf3/index.js +1 -1
- package/dist/web/tdf3/src/assertions.js +1 -1
- package/dist/web/tdf3/src/crypto/salt.js +9 -0
- 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/models/key-access.js +3 -2
- package/dist/web/tdf3/src/tdf.js +7 -3
- package/package.json +12 -12
- package/src/access.ts +0 -1
- package/src/auth/auth.ts +2 -2
- package/src/encodings/base64.ts +1 -1
- package/src/index.ts +1 -0
- package/src/nanoclients.ts +24 -23
- package/src/nanotdf/Client.ts +2 -3
- package/src/nanotdf/NanoTDF.ts +1 -2
- package/src/nanotdf/encrypt-dataset.ts +1 -2
- package/src/nanotdf/encrypt.ts +1 -2
- package/src/nanotdf/helpers/getHkdfSalt.ts +1 -3
- package/src/nanotdf-crypto/digest.ts +1 -3
- package/src/nanotdf-crypto/pemPublicToCrypto.ts +3 -33
- package/src/opentdf.ts +249 -54
- package/src/tdf/Policy.ts +15 -9
- package/src/version.ts +1 -1
- package/tdf3/index.ts +2 -1
- package/tdf3/src/assertions.ts +2 -2
- package/tdf3/src/crypto/salt.ts +11 -0
- package/tdf3/src/models/attribute.ts +26 -0
- package/tdf3/src/models/index.ts +1 -1
- package/tdf3/src/models/key-access.ts +2 -1
- package/tdf3/src/models/payload.ts +1 -0
- package/tdf3/src/models/policy.ts +1 -1
- package/tdf3/src/tdf.ts +22 -13
- package/dist/cjs/src/tdf/PolicyObject.js +0 -3
- package/dist/cjs/src/tdf/TypedArray.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/src/tdf/TypedArray.d.ts +0 -2
- package/dist/types/src/tdf/TypedArray.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/src/tdf/TypedArray.js +0 -2
- package/dist/web/tdf3/src/models/attribute-set.js +0 -118
- package/src/tdf/PolicyObject.ts +0 -11
- package/src/tdf/TypedArray.ts +0 -10
- package/tdf3/src/models/attribute-set.ts +0 -142
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3RkZjMvc3JjL21vZGVscy9hdHRyaWJ1dGUtc2V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLCtCQUFpQztBQVlqQyxNQUFhLFlBQVk7SUFPdkI7UUFKQSxZQUFPLEdBQVksS0FBSyxDQUFDO1FBS3ZCLElBQUksQ0FBQyxVQUFVLEdBQUcsRUFBRSxDQUFDO0lBQ3ZCLENBQUM7SUFFRDs7OztPQUlHO0lBQ0gsR0FBRyxDQUFDLFNBQVMsR0FBRyxFQUFFO1FBQ2hCLCtEQUErRDtRQUMvRCwrREFBK0Q7UUFDL0QsK0NBQStDO1FBQ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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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypedArray.d.ts","sourceRoot":"","sources":["../../../../src/tdf/TypedArray.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,iBAAiB,GACjB,YAAY,GACZ,YAAY,CAAC"}
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3RkZjMvc3JjL21vZGVscy9hdHRyaWJ1dGUtc2V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFZakMsTUFBTSxPQUFPLFlBQVk7SUFPdkI7UU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GNBQWMsQ0FBQyxTQUFTLENBQUM7UUFDakQsQ0FBQztRQUNELE9BQU8sSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUNwQyxDQUFDO0NBQ0YifQ==
|
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
|
-
}
|
package/src/tdf/TypedArray.ts
DELETED
|
@@ -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
|
-
}
|