@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.
Files changed (67) hide show
  1. package/dist/cjs/src/access.js +1 -2
  2. package/dist/cjs/src/index.js +2 -1
  3. package/dist/cjs/src/nanoclients.js +13 -6
  4. package/dist/cjs/src/opentdf.js +4 -3
  5. package/dist/cjs/src/tdf/Policy.js +15 -12
  6. package/dist/cjs/tdf3/src/assertions.js +23 -4
  7. package/dist/cjs/tdf3/src/client/builders.js +1 -1
  8. package/dist/cjs/tdf3/src/models/attribute.js +3 -0
  9. package/dist/cjs/tdf3/src/models/index.js +2 -2
  10. package/dist/cjs/tdf3/src/tdf.js +57 -21
  11. package/dist/types/src/access.d.ts.map +1 -1
  12. package/dist/types/src/index.d.ts +1 -0
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/nanoclients.d.ts +1 -1
  15. package/dist/types/src/nanoclients.d.ts.map +1 -1
  16. package/dist/types/src/opentdf.d.ts +1 -0
  17. package/dist/types/src/opentdf.d.ts.map +1 -1
  18. package/dist/types/src/tdf/Policy.d.ts +4 -2
  19. package/dist/types/src/tdf/Policy.d.ts.map +1 -1
  20. package/dist/types/tdf3/src/assertions.d.ts +4 -1
  21. package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
  22. package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +1 -1
  23. package/dist/types/tdf3/src/client/builders.d.ts +2 -0
  24. package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
  25. package/dist/types/tdf3/src/models/attribute.d.ts +16 -0
  26. package/dist/types/tdf3/src/models/attribute.d.ts.map +1 -0
  27. package/dist/types/tdf3/src/models/index.d.ts +1 -1
  28. package/dist/types/tdf3/src/models/index.d.ts.map +1 -1
  29. package/dist/types/tdf3/src/models/payload.d.ts +1 -0
  30. package/dist/types/tdf3/src/models/payload.d.ts.map +1 -1
  31. package/dist/types/tdf3/src/models/policy.d.ts +1 -1
  32. package/dist/types/tdf3/src/models/policy.d.ts.map +1 -1
  33. package/dist/types/tdf3/src/tdf.d.ts +4 -9
  34. package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
  35. package/dist/web/src/access.js +1 -2
  36. package/dist/web/src/index.js +2 -1
  37. package/dist/web/src/nanoclients.js +14 -7
  38. package/dist/web/src/opentdf.js +4 -3
  39. package/dist/web/src/tdf/Policy.js +13 -10
  40. package/dist/web/tdf3/src/assertions.js +23 -4
  41. package/dist/web/tdf3/src/client/builders.js +1 -1
  42. package/dist/web/tdf3/src/models/attribute.js +2 -0
  43. package/dist/web/tdf3/src/models/index.js +2 -2
  44. package/dist/web/tdf3/src/tdf.js +58 -22
  45. package/package.json +1 -1
  46. package/src/access.ts +0 -1
  47. package/src/index.ts +1 -0
  48. package/src/nanoclients.ts +15 -7
  49. package/src/opentdf.ts +9 -5
  50. package/src/tdf/Policy.ts +15 -9
  51. package/tdf3/src/assertions.ts +29 -7
  52. package/tdf3/src/client/builders.ts +2 -0
  53. package/tdf3/src/models/attribute.ts +26 -0
  54. package/tdf3/src/models/index.ts +1 -1
  55. package/tdf3/src/models/payload.ts +1 -0
  56. package/tdf3/src/models/policy.ts +1 -1
  57. package/tdf3/src/tdf.ts +92 -39
  58. package/dist/cjs/src/tdf/PolicyObject.js +0 -3
  59. package/dist/cjs/tdf3/src/models/attribute-set.js +0 -122
  60. package/dist/types/src/tdf/PolicyObject.d.ts +0 -10
  61. package/dist/types/src/tdf/PolicyObject.d.ts.map +0 -1
  62. package/dist/types/tdf3/src/models/attribute-set.d.ts +0 -65
  63. package/dist/types/tdf3/src/models/attribute-set.d.ts.map +0 -1
  64. package/dist/web/src/tdf/PolicyObject.js +0 -2
  65. package/dist/web/tdf3/src/models/attribute-set.js +0 -118
  66. package/src/tdf/PolicyObject.ts +0 -11
  67. package/tdf3/src/models/attribute-set.ts +0 -142
@@ -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
- }