asgard-tide 0.12.33

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 (38) hide show
  1. package/README.md +2 -0
  2. package/dist/contracts/BaseContract.d.ts +30 -0
  3. package/dist/contracts/BaseContract.d.ts.map +1 -0
  4. package/dist/contracts/BaseContract.js +134 -0
  5. package/dist/contracts/BaseContract.js.map +1 -0
  6. package/dist/contracts/GenericRealmAccessThresholdRoleContract.d.ts +7 -0
  7. package/dist/contracts/GenericRealmAccessThresholdRoleContract.d.ts.map +1 -0
  8. package/dist/contracts/GenericRealmAccessThresholdRoleContract.js +22 -0
  9. package/dist/contracts/GenericRealmAccessThresholdRoleContract.js.map +1 -0
  10. package/dist/contracts/GenericResourceAccessThresholdRoleContract.d.ts +7 -0
  11. package/dist/contracts/GenericResourceAccessThresholdRoleContract.d.ts.map +1 -0
  12. package/dist/contracts/GenericResourceAccessThresholdRoleContract.js +22 -0
  13. package/dist/contracts/GenericResourceAccessThresholdRoleContract.js.map +1 -0
  14. package/dist/index.d.ts +15 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +22 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/models/CustomTideRequest.d.ts +16 -0
  19. package/dist/models/CustomTideRequest.d.ts.map +1 -0
  20. package/dist/models/CustomTideRequest.js +55 -0
  21. package/dist/models/CustomTideRequest.js.map +1 -0
  22. package/dist/models/Policy.d.ts +26 -0
  23. package/dist/models/Policy.d.ts.map +1 -0
  24. package/dist/models/Policy.js +171 -0
  25. package/dist/models/Policy.js.map +1 -0
  26. package/dist/models/TideRequest.d.ts +48 -0
  27. package/dist/models/TideRequest.d.ts.map +1 -0
  28. package/dist/models/TideRequest.js +255 -0
  29. package/dist/models/TideRequest.js.map +1 -0
  30. package/dist/utils/Serialization.d.ts +7 -0
  31. package/dist/utils/Serialization.d.ts.map +1 -0
  32. package/dist/utils/Serialization.js +106 -0
  33. package/dist/utils/Serialization.js.map +1 -0
  34. package/dist/utils/TideMemory.d.ts +10 -0
  35. package/dist/utils/TideMemory.d.ts.map +1 -0
  36. package/dist/utils/TideMemory.js +110 -0
  37. package/dist/utils/TideMemory.js.map +1 -0
  38. package/package.json +32 -0
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # asgard
2
+ Vendor server-side libraries to validate and test Tide Security
@@ -0,0 +1,30 @@
1
+ import { Policy } from "../models/Policy";
2
+ import BaseTideRequest from "../models/TideRequest";
3
+ import { TideMemory } from "../utils/TideMemory";
4
+ export declare abstract class BaseContract {
5
+ abstract id: string;
6
+ private tideRequest;
7
+ protected dokens: Doken[];
8
+ protected authorizedRequestPayload: TideMemory;
9
+ protected informationalRequestPayload: TideMemory;
10
+ /**
11
+ * Inheritors must implement this
12
+ * @param policy Policy object
13
+ */
14
+ protected abstract test(policy: Policy): Promise<void>;
15
+ /**
16
+ * To help with clients testing if their Tide Request will pass their contract's specified contract
17
+ * @param policy Serialized policy from Tide
18
+ * @returns
19
+ */
20
+ testPolicy(policy: Uint8Array | Policy): Promise<boolean>;
21
+ constructor(tideRequest: Uint8Array | BaseTideRequest);
22
+ }
23
+ export declare class Doken {
24
+ private payload;
25
+ constructor(d: Uint8Array);
26
+ hasResourceAccessRole(role: string, client: string): boolean;
27
+ hasRealmAccessRole(role: string): boolean;
28
+ hasVuid(vuid: string): boolean;
29
+ }
30
+ //# sourceMappingURL=BaseContract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseContract.d.ts","sourceRoot":"","sources":["../../src/contracts/BaseContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,8BAAsB,YAAY;IAC9B,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAAkB;IACrC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,CAAM;IAC/B,SAAS,CAAC,wBAAwB,EAAE,UAAU,CAAC;IAC/C,SAAS,CAAC,2BAA2B,EAAE,UAAU,CAAC;IAElD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEtD;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;gBAYnD,WAAW,EAAE,UAAU,GAAG,eAAe;CAaxD;AAKD,qBAAa,KAAK;IACd,OAAO,CAAC,OAAO,CAAM;gBACT,CAAC,EAAE,UAAU;IAuBzB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAkB5D,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAazC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAKjC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Doken = exports.BaseContract = void 0;
7
+ const Policy_1 = require("../models/Policy");
8
+ const TideRequest_1 = __importDefault(require("../models/TideRequest"));
9
+ const Serialization_1 = require("../utils/Serialization");
10
+ class BaseContract {
11
+ /**
12
+ * To help with clients testing if their Tide Request will pass their contract's specified contract
13
+ * @param policy Serialized policy from Tide
14
+ * @returns
15
+ */
16
+ async testPolicy(policy) {
17
+ const p = policy instanceof Uint8Array ? new Policy_1.Policy(policy) : policy;
18
+ if (p.contractId !== this.id)
19
+ throw `Mismatch between policy provided's contract (${p.contractId}) and this contract's id (${this.id})`;
20
+ if (p.modelId !== this.tideRequest.id() && p.modelId !== "any")
21
+ throw `Mismatch between policy provided model id (${p.modelId}) and tide request id (${this.tideRequest.id()})`;
22
+ try {
23
+ await this.test(p);
24
+ return true;
25
+ }
26
+ catch (ex) {
27
+ return false;
28
+ }
29
+ }
30
+ constructor(tideRequest) {
31
+ this.dokens = []; // change to Doken type
32
+ this.tideRequest = tideRequest instanceof Uint8Array ? TideRequest_1.default.decode(tideRequest) : tideRequest;
33
+ this.authorizedRequestPayload = this.tideRequest.draft;
34
+ this.informationalRequestPayload = this.tideRequest.dyanmicData;
35
+ // deserialize dokens
36
+ let res = { result: new Uint8Array() };
37
+ let i = 0;
38
+ while (this.tideRequest.authorizer.TryGetValue(i, res)) {
39
+ this.dokens.push(new Doken(res.result));
40
+ i++;
41
+ }
42
+ }
43
+ }
44
+ exports.BaseContract = BaseContract;
45
+ class Doken {
46
+ constructor(d) {
47
+ if (!d || d.length === 0) {
48
+ throw new Error('Doken constructor: received empty or null Uint8Array');
49
+ }
50
+ const tokenString = (0, Serialization_1.StringFromUint8Array)(d);
51
+ const s = tokenString.split(".");
52
+ if (s.length !== 3) {
53
+ throw new Error(`Doken constructor: invalid token format. Expected 3 parts (header.payload.signature) but got ${s.length} parts in: "${tokenString.substring(0, 50)}..."`);
54
+ }
55
+ try {
56
+ const decodedPayload = base64UrlDecode(s[1]);
57
+ this.payload = JSON.parse(decodedPayload);
58
+ }
59
+ catch (error) {
60
+ throw new Error(`Doken constructor: failed to parse token payload. ${error instanceof Error ? error.message : String(error)}. Raw payload part: "${s[1].substring(0, 50)}..."`);
61
+ }
62
+ if (!this.payload || typeof this.payload !== 'object') {
63
+ throw new Error(`Doken constructor: parsed payload is not a valid object. Got type: ${typeof this.payload}`);
64
+ }
65
+ }
66
+ hasResourceAccessRole(role, client) {
67
+ if (!role)
68
+ throw new Error('hasResourceAccessRole: role parameter is empty or undefined');
69
+ if (!client)
70
+ throw new Error('hasResourceAccessRole: client parameter is empty or undefined');
71
+ if (!this.payload.resource_access) {
72
+ throw new Error(`hasResourceAccessRole: token payload does not contain 'resource_access' field. Available fields: ${Object.keys(this.payload).join(', ')}`);
73
+ }
74
+ if (!this.payload.resource_access[client]) {
75
+ throw new Error(`hasResourceAccessRole: client '${client}' not found in resource_access. Available clients: ${Object.keys(this.payload.resource_access).join(', ')}`);
76
+ }
77
+ if (!Array.isArray(this.payload.resource_access[client].roles)) {
78
+ throw new Error(`hasResourceAccessRole: 'roles' field for client '${client}' is not an array. Got type: ${typeof this.payload.resource_access[client].roles}`);
79
+ }
80
+ return this.payload.resource_access[client].roles.includes(role);
81
+ }
82
+ hasRealmAccessRole(role) {
83
+ if (!role)
84
+ throw new Error('hasRealmAccessRole: role parameter is empty or undefined');
85
+ if (!this.payload.realm_access) {
86
+ throw new Error(`hasRealmAccessRole: token payload does not contain 'realm_access' field. Available fields: ${Object.keys(this.payload).join(', ')}`);
87
+ }
88
+ if (!Array.isArray(this.payload.realm_access.roles)) {
89
+ throw new Error(`hasRealmAccessRole: 'roles' field in realm_access is not an array. Got type: ${typeof this.payload.realm_access.roles}`);
90
+ }
91
+ return this.payload.realm_access.roles.includes(role);
92
+ }
93
+ hasVuid(vuid) {
94
+ if (!vuid)
95
+ throw new Error('hasVuid: vuid cannot be null');
96
+ if (!this.payload.vuid)
97
+ throw new Error("hasVuid: cannot find vuid in paylod");
98
+ return this.payload.vuid === vuid;
99
+ }
100
+ }
101
+ exports.Doken = Doken;
102
+ function base64UrlDecode(input) {
103
+ let output = input
104
+ .replaceAll("-", "+")
105
+ .replaceAll("_", "/");
106
+ switch (output.length % 4) {
107
+ case 0:
108
+ break;
109
+ case 2:
110
+ output += "==";
111
+ break;
112
+ case 3:
113
+ output += "=";
114
+ break;
115
+ default:
116
+ throw new Error("Input is not of the correct length.");
117
+ }
118
+ try {
119
+ return b64DecodeUnicode(output);
120
+ }
121
+ catch (error) {
122
+ return atob(output);
123
+ }
124
+ }
125
+ function b64DecodeUnicode(input) {
126
+ return decodeURIComponent(atob(input).replace(/(.)/g, (m, p) => {
127
+ let code = p.charCodeAt(0).toString(16).toUpperCase();
128
+ if (code.length < 2) {
129
+ code = "0" + code;
130
+ }
131
+ return "%" + code;
132
+ }));
133
+ }
134
+ //# sourceMappingURL=BaseContract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseContract.js","sourceRoot":"","sources":["../../src/contracts/BaseContract.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA0C;AAC1C,wEAAoD;AACpD,0DAA8D;AAI9D,MAAsB,YAAY;IAa9B;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,MAA2B;QACxC,MAAM,CAAC,GAAG,MAAM,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACrE,IAAG,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE;YAAE,MAAM,gDAAgD,CAAC,CAAC,UAAU,6BAA6B,IAAI,CAAC,EAAE,GAAG,CAAC;QACvI,IAAG,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK;YAAE,MAAM,8CAA8C,CAAC,CAAC,OAAO,0BAA0B,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAA;QAC9K,IAAG,CAAC;YACA,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,CAAC;QAChB,CAAC;QAAA,OAAM,EAAE,EAAC,CAAC;YACP,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,YAAY,WAAyC;QA3B3C,WAAM,GAAY,EAAE,CAAC,CAAC,uBAAuB;QA4BnD,IAAI,CAAC,WAAW,GAAG,WAAW,YAAY,UAAU,CAAC,CAAC,CAAC,qBAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QACzG,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QACvD,IAAI,CAAC,2B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M,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC;YACF,MAAM;QACV,KAAK,CAAC;YACF,MAAM,IAAI,IAAI,CAAC;YACf,MAAM;QACV,KAAK,CAAC;YACF,MAAM,IAAI,GAAG,CAAC;YACd,MAAM;QACV;YACI,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,CAAC;QACD,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;AACL,CAAC;AACD,SAAS,gBAAgB,CAAC,KAAa;IACnC,OAAO,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3D,IAAI,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAEtD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClB,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;QACtB,CAAC;QAED,OAAO,GAAG,GAAG,IAAI,CAAC;IACtB,CAAC,CAAC,CAAC,CAAC;AACR,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Policy } from "../models/Policy";
2
+ import { BaseContract } from "./BaseContract";
3
+ export declare class GenericRealmAccessThresholdRoleContract extends BaseContract {
4
+ id: string;
5
+ protected test(policy: Policy): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=GenericRealmAccessThresholdRoleContract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericRealmAccessThresholdRoleContract.d.ts","sourceRoot":"","sources":["../../src/contracts/GenericRealmAccessThresholdRoleContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBAAa,uCAAwC,SAAQ,YAAY;IAC9D,EAAE,EAAE,MAAM,CAAuC;cACxC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQtD"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenericRealmAccessThresholdRoleContract = void 0;
4
+ const BaseContract_1 = require("./BaseContract");
5
+ class GenericRealmAccessThresholdRoleContract extends BaseContract_1.BaseContract {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.id = "GenericRealmAccessThresholdRole:1";
9
+ }
10
+ async test(policy) {
11
+ let successfulDokens = 0;
12
+ this.dokens.forEach(d => {
13
+ if (d.hasRealmAccessRole(policy.params.getParameter("role")))
14
+ successfulDokens++;
15
+ });
16
+ const threshold = policy.params.getParameter("threshold");
17
+ if (successfulDokens < threshold)
18
+ throw 'Not enough successful dokens with requires roles/clients';
19
+ }
20
+ }
21
+ exports.GenericRealmAccessThresholdRoleContract = GenericRealmAccessThresholdRoleContract;
22
+ //# sourceMappingURL=GenericRealmAccessThresholdRoleContract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericRealmAccessThresholdRoleContract.js","sourceRoot":"","sources":["../../src/contracts/GenericRealmAccessThresholdRoleContract.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAE9C,MAAa,uCAAwC,SAAQ,2BAAY;IAAzE;;QACW,OAAE,GAAW,mCAAmC,CAAC;IAS5D,CAAC;IARa,KAAK,CAAC,IAAI,CAAC,MAAc;QAC/B,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACpB,IAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAS,MAAM,CAAC,CAAC;gBAAE,gBAAgB,EAAE,CAAC;QAC5F,CAAC,CAAC,CAAA;QACF,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAS,WAAW,CAAC,CAAC;QAClE,IAAG,gBAAgB,GAAG,SAAS;YAAE,MAAM,0DAA0D,CAAC;IACtG,CAAC;CACJ;AAVD,0FAUC"}
@@ -0,0 +1,7 @@
1
+ import { Policy } from "../models/Policy";
2
+ import { BaseContract } from "./BaseContract";
3
+ export declare class GenericResourceAccessThresholdRoleContract extends BaseContract {
4
+ id: string;
5
+ protected test(policy: Policy): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=GenericResourceAccessThresholdRoleContract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericResourceAccessThresholdRoleContract.d.ts","sourceRoot":"","sources":["../../src/contracts/GenericResourceAccessThresholdRoleContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBAAa,0CAA2C,SAAQ,YAAY;IACjE,EAAE,EAAE,MAAM,CAA0C;cAC3C,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQtD"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenericResourceAccessThresholdRoleContract = void 0;
4
+ const BaseContract_1 = require("./BaseContract");
5
+ class GenericResourceAccessThresholdRoleContract extends BaseContract_1.BaseContract {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.id = "GenericResourceAccessThresholdRole:1";
9
+ }
10
+ async test(policy) {
11
+ let successfulDokens = 0;
12
+ this.dokens.forEach(d => {
13
+ if (d.hasResourceAccessRole(policy.params.getParameter("role"), policy.params.getParameter("resource")))
14
+ successfulDokens++;
15
+ });
16
+ const threshold = policy.params.getParameter("threshold");
17
+ if (successfulDokens < threshold)
18
+ throw 'Not enough successful dokens with requires roles/clients';
19
+ }
20
+ }
21
+ exports.GenericResourceAccessThresholdRoleContract = GenericResourceAccessThresholdRoleContract;
22
+ //# sourceMappingURL=GenericResourceAccessThresholdRoleContract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericResourceAccessThresholdRoleContract.js","sourceRoot":"","sources":["../../src/contracts/GenericResourceAccessThresholdRoleContract.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAE9C,MAAa,0CAA2C,SAAQ,2BAAY;IAA5E;;QACW,OAAE,GAAW,sCAAsC,CAAC;IAS/D,CAAC;IARa,KAAK,CAAC,IAAI,CAAC,MAAc;QAC/B,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACpB,IAAG,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAS,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAS,UAAU,CAAC,CAAC;gBAAE,gBAAgB,EAAE,CAAC;QAC/I,CAAC,CAAC,CAAA;QACF,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAS,WAAW,CAAC,CAAC;QAClE,IAAG,gBAAgB,GAAG,SAAS;YAAE,MAAM,0DAA0D,CAAC;IACtG,CAAC;CACJ;AAVD,gGAUC"}
@@ -0,0 +1,15 @@
1
+ import { BaseContract } from "./contracts/BaseContract";
2
+ import { GenericResourceAccessThresholdRoleContract } from "./contracts/GenericResourceAccessThresholdRoleContract";
3
+ import { GenericRealmAccessThresholdRoleContract } from "./contracts/GenericRealmAccessThresholdRoleContract";
4
+ import { TideMemory } from "./utils/TideMemory";
5
+ import BaseTideRequest from "./models/TideRequest";
6
+ import { Policy, PolicyParameters } from "./models/Policy";
7
+ import CustomTideRequest from "./models/CustomTideRequest";
8
+ export { GenericResourceAccessThresholdRoleContract };
9
+ export { BaseContract };
10
+ export { TideMemory };
11
+ export { BaseTideRequest };
12
+ export { Policy, PolicyParameters };
13
+ export { GenericRealmAccessThresholdRoleContract };
14
+ export { CustomTideRequest };
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,0CAA0C,EAAE,MAAM,wDAAwD,CAAC;AACpH,OAAO,EAAE,uCAAuC,EAAE,MAAM,qDAAqD,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,0CAA0C,EAAE,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,CAAA;AACrB,OAAO,EAAE,eAAe,EAAE,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAA;AACnC,OAAO,EAAE,uCAAuC,EAAE,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CustomTideRequest = exports.GenericRealmAccessThresholdRoleContract = exports.PolicyParameters = exports.Policy = exports.BaseTideRequest = exports.TideMemory = exports.BaseContract = exports.GenericResourceAccessThresholdRoleContract = void 0;
7
+ const BaseContract_1 = require("./contracts/BaseContract");
8
+ Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return BaseContract_1.BaseContract; } });
9
+ const GenericResourceAccessThresholdRoleContract_1 = require("./contracts/GenericResourceAccessThresholdRoleContract");
10
+ Object.defineProperty(exports, "GenericResourceAccessThresholdRoleContract", { enumerable: true, get: function () { return GenericResourceAccessThresholdRoleContract_1.GenericResourceAccessThresholdRoleContract; } });
11
+ const GenericRealmAccessThresholdRoleContract_1 = require("./contracts/GenericRealmAccessThresholdRoleContract");
12
+ Object.defineProperty(exports, "GenericRealmAccessThresholdRoleContract", { enumerable: true, get: function () { return GenericRealmAccessThresholdRoleContract_1.GenericRealmAccessThresholdRoleContract; } });
13
+ const TideMemory_1 = require("./utils/TideMemory");
14
+ Object.defineProperty(exports, "TideMemory", { enumerable: true, get: function () { return TideMemory_1.TideMemory; } });
15
+ const TideRequest_1 = __importDefault(require("./models/TideRequest"));
16
+ exports.BaseTideRequest = TideRequest_1.default;
17
+ const Policy_1 = require("./models/Policy");
18
+ Object.defineProperty(exports, "Policy", { enumerable: true, get: function () { return Policy_1.Policy; } });
19
+ Object.defineProperty(exports, "PolicyParameters", { enumerable: true, get: function () { return Policy_1.PolicyParameters; } });
20
+ const CustomTideRequest_1 = __importDefault(require("./models/CustomTideRequest"));
21
+ exports.CustomTideRequest = CustomTideRequest_1.default;
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAwD;AAU/C,6FAVA,2BAAY,OAUA;AATrB,uHAAoH;AAQ3G,2HARA,uFAA0C,OAQA;AAPnD,iHAA8G;AAYrG,wHAZA,iFAAuC,OAYA;AAXhD,mDAAgD;AAQvC,2FARA,uBAAU,OAQA;AAPnB,uEAAmD;AAQ1C,0BARF,qBAAe,CAQE;AAPxB,4CAA2D;AAQlD,uFARA,eAAM,OAQA;AAAE,iGARA,yBAAgB,OAQA;AAPjC,mFAA2D;AASlD,4BATF,2BAAiB,CASE"}
@@ -0,0 +1,16 @@
1
+ import BaseTideRequest from "./TideRequest";
2
+ export default class CustomTideRequest extends BaseTideRequest {
3
+ customInfo: CustomInfo | undefined;
4
+ datasToSign: Uint8Array[];
5
+ constructor(name: string, version: string, authFlow: string, draft: Uint8Array, dyanmicData: Uint8Array);
6
+ addDataToSign(data: Uint8Array): this;
7
+ setHumanReadableName(n: string): this;
8
+ setAdditionalInfo(info: any): this;
9
+ getAdditionalInfoSupplied(): any;
10
+ }
11
+ interface CustomInfo {
12
+ humanReadableName: string;
13
+ additionalInfo: any;
14
+ }
15
+ export {};
16
+ //# sourceMappingURL=CustomTideRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomTideRequest.d.ts","sourceRoot":"","sources":["../../src/models/CustomTideRequest.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,eAAe,CAAC;AAE5C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,eAAe;IAC1D,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;IACnC,WAAW,EAAE,UAAU,EAAE,CAAM;gBACnB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU;IAIvG,aAAa,CAAC,IAAI,EAAE,UAAU;IAK9B,oBAAoB,CAAC,CAAC,EAAE,MAAM;IAY9B,iBAAiB,CAAC,IAAI,EAAE,GAAG;IAY3B,yBAAyB,IAAI,GAAG;CAInC;AACD,UAAU,UAAU;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,GAAG,CAAC;CACvB"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Serialization_1 = require("../utils/Serialization");
7
+ const TideMemory_1 = require("../utils/TideMemory");
8
+ const TideRequest_1 = __importDefault(require("./TideRequest"));
9
+ class CustomTideRequest extends TideRequest_1.default {
10
+ constructor(name, version, authFlow, draft, dyanmicData) {
11
+ super(name, version, authFlow, draft, dyanmicData);
12
+ this.datasToSign = [];
13
+ if (draft.length > 0)
14
+ this.datasToSign.push(draft); // in case they only want to sign one thing
15
+ }
16
+ addDataToSign(data) {
17
+ this.datasToSign.push(data);
18
+ this.draft = TideMemory_1.TideMemory.CreateFromArray([(0, Serialization_1.StringToUint8Array)(JSON.stringify(this.customInfo)), ...this.datasToSign]); // recreate draft on change
19
+ return this;
20
+ }
21
+ setHumanReadableName(n) {
22
+ if (!this.customInfo) {
23
+ this.customInfo = {
24
+ humanReadableName: n,
25
+ additionalInfo: null
26
+ };
27
+ }
28
+ else {
29
+ this.customInfo["humanReadableName"] = n;
30
+ }
31
+ this.draft = TideMemory_1.TideMemory.CreateFromArray([(0, Serialization_1.StringToUint8Array)(JSON.stringify(this.customInfo)), ...this.datasToSign]); // recreate draft on change
32
+ return this;
33
+ }
34
+ setAdditionalInfo(info) {
35
+ if (!this.customInfo) {
36
+ this.customInfo = {
37
+ humanReadableName: "",
38
+ additionalInfo: info
39
+ };
40
+ }
41
+ else {
42
+ this.customInfo["additionalInfo"] = info;
43
+ }
44
+ this.draft = TideMemory_1.TideMemory.CreateFromArray([(0, Serialization_1.StringToUint8Array)(JSON.stringify(this.customInfo)), ...this.datasToSign]); // recreate draft on change
45
+ return this;
46
+ }
47
+ getAdditionalInfoSupplied() {
48
+ if (this.draft.length > 0)
49
+ return JSON.parse((0, Serialization_1.StringFromUint8Array)(this.draft.GetValue(0)))["additionalInfo"];
50
+ else
51
+ return null;
52
+ }
53
+ }
54
+ exports.default = CustomTideRequest;
55
+ //# sourceMappingURL=CustomTideRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomTideRequest.js","sourceRoot":"","sources":["../../src/models/CustomTideRequest.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkF;AAClF,oDAAi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G,CAAC,IAAI,CAAC,UAAU,EAAC,CAAC;YACjB,IAAI,CAAC,UAAU,GAAG;gBACd,iBAAiB,EAAE,EAAE;gBACrB,cAAc,EAAE,IAAI;aACvB,CAAA;QACL,CAAC;aAAI,CAAC;YACF,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,uBAAU,CAAC,eAAe,CAAC,CAAC,IAAA,kCAAkB,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,GAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,2BAA2B;QACjJ,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,yBAAyB;QACrB,IAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,oCAAoB,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;;YACvG,OAAO,IAAI,CAAC;IACrB,CAAC;CACJ;AAxCD,oCAwCC"}
@@ -0,0 +1,26 @@
1
+ import { TideMemory } from "../utils/TideMemory";
2
+ export declare class Policy {
3
+ version: string;
4
+ contractId: string;
5
+ modelId: string;
6
+ keyId: string;
7
+ params: PolicyParameters;
8
+ dataToVerify: TideMemory | undefined;
9
+ signature: Uint8Array | undefined;
10
+ constructor(data: {
11
+ version: string;
12
+ contractId: string;
13
+ modelId: string;
14
+ keyId: string;
15
+ params: Map<string, any>;
16
+ } | TideMemory | Uint8Array);
17
+ toBytes(): TideMemory;
18
+ }
19
+ export declare class PolicyParameters {
20
+ entries: Map<string, any>;
21
+ constructor(data: Map<string, any> | Uint8Array);
22
+ private static fromBytes;
23
+ getParameter<T extends string | number | bigint | boolean | Uint8Array>(key: string): T;
24
+ toBytes(): Uint8Array;
25
+ }
26
+ //# sourceMappingURL=Policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Policy.d.ts","sourceRoot":"","sources":["../../src/models/Policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,qBAAa,MAAM;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC;IAEzB,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC;IACrC,SAAS,EAAE,UAAU,GAAG,SAAS,CAAC;gBAEtB,IAAI,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAC,GAAG,UAAU,GAAG,UAAU;IA+B3I,OAAO;CAcV;AAED,qBAAa,gBAAgB;IACzB,OAAO,EAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBACf,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAAU;IAQ/C,OAAO,CAAC,MAAM,CAAC,SAAS;IAgDxB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;IAkCvF,OAAO,IAAI,UAAU;CAsCxB"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolicyParameters = exports.Policy = void 0;
4
+ const TideMemory_1 = require("../utils/TideMemory");
5
+ const Serialization_1 = require("../utils/Serialization");
6
+ class Policy {
7
+ constructor(data) {
8
+ if (data instanceof Uint8Array) {
9
+ const d = new TideMemory_1.TideMemory(data.length);
10
+ d.set(data);
11
+ this.dataToVerify = d.GetValue(0);
12
+ this.version = (0, Serialization_1.StringFromUint8Array)(this.dataToVerify.GetValue(0));
13
+ this.contractId = (0, Serialization_1.StringFromUint8Array)(this.dataToVerify.GetValue(1));
14
+ this.modelId = (0, Serialization_1.StringFromUint8Array)(this.dataToVerify.GetValue(2));
15
+ this.keyId = (0, Serialization_1.StringFromUint8Array)(this.dataToVerify.GetValue(3));
16
+ this.params = new PolicyParameters(this.dataToVerify.GetValue(4));
17
+ const sigRes = { result: undefined };
18
+ if (d.TryGetValue(1, sigRes)) {
19
+ this.signature = sigRes.result;
20
+ }
21
+ }
22
+ else {
23
+ if (typeof data["version"] !== "string")
24
+ throw 'Version is not a string';
25
+ this.version = data["version"];
26
+ if (typeof data["contractId"] !== "string")
27
+ throw 'ContractId is not a string';
28
+ this.contractId = data["contractId"];
29
+ if (typeof data["modelId"] !== "string")
30
+ throw 'ModelId is not a string';
31
+ this.modelId = data["modelId"];
32
+ if (typeof data["keyId"] !== "string")
33
+ throw 'KeyId is not a string';
34
+ this.keyId = data["keyId"];
35
+ if (!data["params"])
36
+ throw 'Params is null';
37
+ this.params = new PolicyParameters(data["params"]);
38
+ }
39
+ }
40
+ toBytes() {
41
+ let d = [
42
+ TideMemory_1.TideMemory.CreateFromArray([
43
+ (0, Serialization_1.StringToUint8Array)(this.version),
44
+ (0, Serialization_1.StringToUint8Array)(this.contractId),
45
+ (0, Serialization_1.StringToUint8Array)(this.modelId),
46
+ (0, Serialization_1.StringToUint8Array)(this.keyId),
47
+ this.params.toBytes()
48
+ ])
49
+ ];
50
+ if (this.signature)
51
+ d.push(this.signature);
52
+ return TideMemory_1.TideMemory.CreateFromArray(d);
53
+ }
54
+ }
55
+ exports.Policy = Policy;
56
+ class PolicyParameters {
57
+ constructor(data) {
58
+ if (data instanceof Uint8Array) {
59
+ this.entries = PolicyParameters.fromBytes(data);
60
+ }
61
+ else {
62
+ this.entries = new Map(data);
63
+ }
64
+ }
65
+ static fromBytes(data) {
66
+ let params = new Map();
67
+ let i = 0;
68
+ const value = { result: undefined };
69
+ // Create TideMemory instance to access TryGetValue
70
+ const tideData = new TideMemory_1.TideMemory(data.length);
71
+ tideData.set(data);
72
+ // Try to get values at sequential indices
73
+ while (tideData.TryGetValue(i, value)) {
74
+ const nameBytes = value.result.GetValue(0);
75
+ const name = (0, Serialization_1.StringFromUint8Array)(nameBytes);
76
+ const typeBytes = value.result.GetValue(1);
77
+ const type = (0, Serialization_1.StringFromUint8Array)(typeBytes);
78
+ const dataBytes = value.result.GetValue(2);
79
+ let datum;
80
+ switch (type) {
81
+ case "str":
82
+ datum = (0, Serialization_1.StringFromUint8Array)(dataBytes);
83
+ break;
84
+ case "num":
85
+ const numView = new DataView(dataBytes.buffer, dataBytes.byteOffset, dataBytes.byteLength);
86
+ datum = numView.getInt32(0, true); // little-endian
87
+ break;
88
+ case "bnum":
89
+ // Convert bytes to BigInt (little-endian)
90
+ datum = (0, Serialization_1.BigIntFromByteArray)(dataBytes);
91
+ break;
92
+ case "bln":
93
+ datum = dataBytes[0] === 1;
94
+ break;
95
+ case "byt":
96
+ datum = new Uint8Array(dataBytes);
97
+ break;
98
+ default:
99
+ throw new Error(`Could not find type of ${type}`);
100
+ }
101
+ params.set(name, datum);
102
+ i++;
103
+ }
104
+ return params;
105
+ }
106
+ getParameter(key) {
107
+ if (!this.entries.has(key)) {
108
+ throw new Error(`Parameter '${key}' not found`);
109
+ }
110
+ const value = this.entries.get(key);
111
+ const actualType = value instanceof Uint8Array ? 'Uint8Array' : typeof value;
112
+ // Type checking logic
113
+ let expectedType;
114
+ if (value instanceof Uint8Array) {
115
+ expectedType = 'Uint8Array';
116
+ }
117
+ else {
118
+ expectedType = typeof value;
119
+ }
120
+ // Validate the type matches what was requested
121
+ // We can't directly check T at runtime, so we infer from the value type
122
+ const isCorrectType = (typeof value === 'string' && value.constructor === String) ||
123
+ (typeof value === 'number' && value.constructor === Number) ||
124
+ (typeof value === 'bigint' && value.constructor === BigInt) ||
125
+ (typeof value === 'boolean' && value.constructor === Boolean) ||
126
+ (value instanceof Uint8Array);
127
+ if (!isCorrectType) {
128
+ throw new Error(`Parameter '${key}' exists but has unexpected type '${actualType}'`);
129
+ }
130
+ return value;
131
+ }
132
+ toBytes() {
133
+ let params = [];
134
+ for (const [key, value] of this.entries) {
135
+ const nameBytes = (0, Serialization_1.StringToUint8Array)(key);
136
+ let dataBytes, typeStr;
137
+ if (typeof value === 'string') {
138
+ dataBytes = (0, Serialization_1.StringToUint8Array)(value);
139
+ typeStr = "str";
140
+ }
141
+ else if (typeof value === 'number' && Number.isInteger(value)) {
142
+ const buffer = new ArrayBuffer(4);
143
+ const view = new DataView(buffer);
144
+ view.setInt32(0, value, true); // little-endian
145
+ dataBytes = new Uint8Array(buffer);
146
+ typeStr = "num";
147
+ }
148
+ else if (typeof value === 'bigint') {
149
+ dataBytes = (0, Serialization_1.BigIntToByteArray)(value);
150
+ typeStr = "bnum";
151
+ }
152
+ else if (typeof value === 'boolean') {
153
+ dataBytes = new Uint8Array([value ? 1 : 0]);
154
+ typeStr = "bln";
155
+ }
156
+ else if (value instanceof Uint8Array) {
157
+ dataBytes = value;
158
+ typeStr = "byt";
159
+ }
160
+ else {
161
+ throw new Error(`Could not serialize key '${key}' of type '${typeof value}'`);
162
+ }
163
+ const typeBytes = (0, Serialization_1.StringToUint8Array)(typeStr);
164
+ const paramMemory = TideMemory_1.TideMemory.CreateFromArray([nameBytes, typeBytes, dataBytes]);
165
+ params.push(paramMemory);
166
+ }
167
+ return TideMemory_1.TideMemory.CreateFromArray(params);
168
+ }
169
+ }
170
+ exports.PolicyParameters = PolicyParameters;
171
+ //# sourceMappingURL=Policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Policy.js","sourceRoot":"","sources":["../../src/models/Policy.ts"],"names":[],"mappings":";;;AAAA,oDAAiD;AACjD,0DAA0H;AAE1H,MAAa,MAAM;IAUf,YAAY,IAA+H;Q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,QAAQ,EAAE,CAAC;gBACnC,SAAS,GAAG,IAAA,iCAAiB,EAAC,KAAK,CAAC,CAAC;gBACrC,OAAO,GAAG,MAAM,CAAC;YACrB,CAAC;iBAAM,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;gBACpC,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5C,OAAO,GAAG,KAAK,CAAC;YACpB,CAAC;iBAAM,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;gBACrC,SAAS,GAAG,KAAK,CAAC;gBAClB,OAAO,GAAG,KAAK,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,KAAK,CACX,4BAA4B,GAAG,cAAc,OAAO,KAAK,GAAG,CAC/D,CAAC;YACN,CAAC;YAED,MAAM,SAAS,GAAG,IAAA,kCAAkB,EAAC,OAAO,CAAC,CAAC;YAC9C,MAAM,WAAW,GAAG,uBAAU,CAAC,eAAe,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;YAClF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,uBAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;CACJ;AAlID,4CAkIC"}
@@ -0,0 +1,48 @@
1
+ import { TideMemory } from "../utils/TideMemory.js";
2
+ import { Policy } from "./Policy.js";
3
+ export default class BaseTideRequest {
4
+ static _name: string;
5
+ static _version: string;
6
+ name: string;
7
+ version: string;
8
+ authFlow: string;
9
+ draft: TideMemory;
10
+ dyanmicData: TideMemory;
11
+ authorization: TideMemory;
12
+ authorizerCert: TideMemory;
13
+ authorizer: TideMemory;
14
+ expiry: number;
15
+ policy: TideMemory;
16
+ constructor(name: string, version: string, authFlow: string, draft: Uint8Array, dyanmicData: Uint8Array);
17
+ id(): string;
18
+ /**
19
+ * This isn't copying. Just created another BaseTideRequest object that allows you to point each individual field to OTHER sections of memory.
20
+ * If you modify an existing 'replicated' field, you'll also modify the other object you originally replicated.
21
+ */
22
+ replicate(): BaseTideRequest;
23
+ setNewDynamicData(d: Uint8Array): this;
24
+ setCustomExpiry(timeFromNowInSeconds: number): this;
25
+ addAuthorizer(authorizer: Uint8Array): void;
26
+ addAuthorizerCertificate(authorizerCertificate: Uint8Array): void;
27
+ addAuthorization(authorization: Uint8Array): this;
28
+ addPolicy(policy: Uint8Array): this;
29
+ hasPolicy(): boolean;
30
+ getRequestInitDetails(): Promise<{
31
+ creationTime: Uint8Array<ArrayBufferLike>;
32
+ expireTime: Uint8Array<ArrayBufferLike>;
33
+ modelId: NodeJS.NonSharedUint8Array;
34
+ draftHash: TideMemory;
35
+ }>;
36
+ addCreationSignature(creationTime: Uint8Array, sig: Uint8Array): this;
37
+ isInitialized(): boolean;
38
+ getUniqueId(): string;
39
+ getInitializedTime(): number;
40
+ getCurrentApprovalCount(): number;
41
+ getPolicy(): Policy;
42
+ removeApproval(approvalVuid: string): boolean;
43
+ encode(): TideMemory;
44
+ static decode<T extends BaseTideRequest>(this: new (name: string, version: string, authFlow: string, draft: Uint8Array, dynamicData: Uint8Array) => T, data: Uint8Array): T;
45
+ private static uint32ToUint8ArrayLE;
46
+ private static uint8ArrayToUint32LE;
47
+ }
48
+ //# sourceMappingURL=TideRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TideRequest.d.ts","sourceRoot":"","sources":["../../src/models/TideRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,eAAe;IAChC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC;IAExB,IAAI,EAAE,MAAM,CAAC;IAC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,CAAC,oBAAoB;IAcnC,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAoBtC"}
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const BaseContract_js_1 = require("../contracts/BaseContract.js");
4
+ const TideMemory_js_1 = require("../utils/TideMemory.js");
5
+ const Policy_js_1 = require("./Policy.js");
6
+ class BaseTideRequest {
7
+ constructor(name, version, authFlow, draft, dyanmicData) {
8
+ this.name = name;
9
+ this.version = version;
10
+ this.authFlow = authFlow;
11
+ this.draft = new TideMemory_js_1.TideMemory(draft.length);
12
+ this.draft.set(draft);
13
+ this.dyanmicData = new TideMemory_js_1.TideMemory(dyanmicData.length);
14
+ this.dyanmicData.set(dyanmicData);
15
+ this.authorization = new TideMemory_js_1.TideMemory();
16
+ this.authorizerCert = new TideMemory_js_1.TideMemory();
17
+ ;
18
+ this.authorizer = new TideMemory_js_1.TideMemory();
19
+ this.expiry = Math.floor(Date.now() / 1000) + 30; // default is 30s
20
+ this.policy = new TideMemory_js_1.TideMemory();
21
+ }
22
+ id() {
23
+ return this.name + ":" + this.version;
24
+ }
25
+ /**
26
+ * This isn't copying. Just created another BaseTideRequest object that allows you to point each individual field to OTHER sections of memory.
27
+ * If you modify an existing 'replicated' field, you'll also modify the other object you originally replicated.
28
+ */
29
+ replicate() {
30
+ const r = new BaseTideRequest(this.name, this.version, this.authFlow, this.draft, this.dyanmicData);
31
+ r.authorization = this.authorization;
32
+ r.authorizerCert = this.authorizerCert;
33
+ r.authorizer = this.authorizer;
34
+ r.expiry = this.expiry;
35
+ r.policy = this.policy;
36
+ return r;
37
+ }
38
+ setNewDynamicData(d) {
39
+ this.dyanmicData = new TideMemory_js_1.TideMemory(d.length);
40
+ this.dyanmicData.set(d);
41
+ return this;
42
+ }
43
+ setCustomExpiry(timeFromNowInSeconds) {
44
+ this.expiry = Math.floor(Date.now() / 1000) + timeFromNowInSeconds;
45
+ return this;
46
+ }
47
+ addAuthorizer(authorizer) {
48
+ this.authorizer = new TideMemory_js_1.TideMemory(authorizer.length);
49
+ this.authorizer.set(authorizer);
50
+ }
51
+ addAuthorizerCertificate(authorizerCertificate) {
52
+ this.authorizerCert = new TideMemory_js_1.TideMemory(authorizerCertificate.length);
53
+ this.authorizerCert.set(authorizerCertificate);
54
+ }
55
+ addAuthorization(authorization) {
56
+ this.authorization = new TideMemory_js_1.TideMemory(authorization.length);
57
+ this.authorization.set(authorization);
58
+ return this;
59
+ }
60
+ addPolicy(policy) {
61
+ this.policy = new TideMemory_js_1.TideMemory(policy.length);
62
+ this.policy.set(policy);
63
+ return this;
64
+ }
65
+ hasPolicy() {
66
+ return this.policy.length != 0;
67
+ }
68
+ async getRequestInitDetails() {
69
+ const te = new TextEncoder();
70
+ return {
71
+ "creationTime": BaseTideRequest.uint32ToUint8ArrayLE(Math.floor(Date.now() / 1000)), // now
72
+ "expireTime": BaseTideRequest.uint32ToUint8ArrayLE(this.expiry),
73
+ "modelId": te.encode(this.id()),
74
+ "draftHash": new TideMemory_js_1.TideMemory(await crypto.subtle.digest("SHA-512", this.draft))
75
+ };
76
+ }
77
+ addCreationSignature(creationTime, sig) {
78
+ this.authorization = TideMemory_js_1.TideMemory.CreateFromArray([
79
+ TideMemory_js_1.TideMemory.CreateFromArray([
80
+ creationTime,
81
+ sig
82
+ ]),
83
+ new TideMemory_js_1.TideMemory() // empty as no approvals have been added yet
84
+ ]);
85
+ return this;
86
+ }
87
+ isInitialized() {
88
+ try {
89
+ // check that creation time and sig fields are present
90
+ if (this.authorization.GetValue(0).GetValue(0).length > 0 && this.authorization.GetValue(0).GetValue(1).length == 64)
91
+ return true;
92
+ else
93
+ return false;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ getUniqueId() {
100
+ if (!this.isInitialized())
101
+ throw 'Must initialize request to generate unique id';
102
+ const bytes = this.authorization.GetValue(0).GetValue(1);
103
+ return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(''); // hex
104
+ }
105
+ getInitializedTime() {
106
+ if (!this.isInitialized())
107
+ throw 'Must initialize request to get creation time';
108
+ const time_bytes = this.authorization.GetValue(0).GetValue(0);
109
+ return BaseTideRequest.uint8ArrayToUint32LE(time_bytes);
110
+ }
111
+ getCurrentApprovalCount() {
112
+ if (!this.isInitialized())
113
+ throw 'Must initialize request to get approval count';
114
+ let i = 0;
115
+ let res = { result: undefined };
116
+ while (this.authorizer.TryGetValue(i, res)) {
117
+ i++;
118
+ }
119
+ return i;
120
+ }
121
+ getPolicy() {
122
+ return new Policy_js_1.Policy(this.policy);
123
+ }
124
+ removeApproval(approvalVuid) {
125
+ // find if there are any dokens with this approvalVuid
126
+ if (!this.isInitialized())
127
+ return false;
128
+ if (this.getCurrentApprovalCount() == 0)
129
+ return false;
130
+ try {
131
+ // find doken and it's index
132
+ let i = 0;
133
+ let res = { result: new TideMemory_js_1.TideMemory() };
134
+ let dokenWithVuidFound = {};
135
+ let keepTheseDokensList = [];
136
+ let keepTheseApprovalSigs = [];
137
+ while (this.authorizer.TryGetValue(i, res)) {
138
+ const d = new BaseContract_js_1.Doken(res.result);
139
+ if (d.hasVuid(approvalVuid)) {
140
+ dokenWithVuidFound = {
141
+ index: i,
142
+ value: d
143
+ };
144
+ }
145
+ else {
146
+ keepTheseDokensList.push(res.result);
147
+ keepTheseApprovalSigs.push(this.authorization.GetValue(1).GetValue(i));
148
+ }
149
+ i++;
150
+ }
151
+ // reconstruct authorizers and authorizer sigs of request
152
+ if (dokenWithVuidFound) {
153
+ const creationAuth = this.authorization.GetValue(0);
154
+ this.authorization = TideMemory_js_1.TideMemory.CreateFromArray([
155
+ creationAuth,
156
+ TideMemory_js_1.TideMemory.CreateFromArray(keepTheseApprovalSigs)
157
+ ]);
158
+ this.authorizer = TideMemory_js_1.TideMemory.CreateFromArray(keepTheseDokensList);
159
+ return true;
160
+ }
161
+ else
162
+ return false;
163
+ }
164
+ catch (ex) {
165
+ console.error(ex);
166
+ return false;
167
+ }
168
+ }
169
+ encode() {
170
+ if (this.authorizer == null)
171
+ throw Error("Authorizer not added to request");
172
+ if (this.authorizerCert == null)
173
+ throw Error("Authorizer cert not provided");
174
+ if (this.authorization == null)
175
+ throw Error("Authorize this request first with an authorizer");
176
+ const te = new TextEncoder();
177
+ const name_b = te.encode(this.name);
178
+ const version_b = te.encode(this.version);
179
+ const authFlow_b = te.encode(this.authFlow);
180
+ const expiry = BaseTideRequest.uint32ToUint8ArrayLE(this.expiry);
181
+ const req = TideMemory_js_1.TideMemory.CreateFromArray([
182
+ name_b,
183
+ version_b,
184
+ expiry,
185
+ this.draft,
186
+ authFlow_b,
187
+ this.dyanmicData,
188
+ this.authorizer,
189
+ this.authorization,
190
+ this.authorizerCert,
191
+ this.policy
192
+ ]);
193
+ return req;
194
+ }
195
+ static decode(data) {
196
+ const d = new TideMemory_js_1.TideMemory(data.length);
197
+ d.set(data);
198
+ // Read field 0 (name) - this is part of the TideMemory structure
199
+ const name = new TextDecoder().decode(d.GetValue(0));
200
+ // Read all other fields
201
+ const version = new TextDecoder().decode(d.GetValue(1));
202
+ // Check name and version in static members if set
203
+ if (this._name != undefined && this._version != undefined) {
204
+ if (name != this._name || version != this._version)
205
+ throw Error("Name and Version in decoded data don't match this object's set name and version.");
206
+ }
207
+ const expiry = BaseTideRequest.uint8ArrayToUint32LE(d.GetValue(2));
208
+ const draft = d.GetValue(3);
209
+ const authFlow = new TextDecoder().decode(d.GetValue(4));
210
+ const dynamicData = d.GetValue(5);
211
+ const authorizer = d.GetValue(6);
212
+ const authorization = d.GetValue(7);
213
+ const authorizerCert = d.GetValue(8);
214
+ const policy = d.GetValue(9);
215
+ // Create a new instance using 'this' constructor to support subclasses
216
+ const request = new this(name, version, authFlow, draft, dynamicData);
217
+ // Set the remaining fields
218
+ request.expiry = expiry;
219
+ request.authorizer = authorizer;
220
+ request.authorization = authorization;
221
+ request.authorizerCert = authorizerCert;
222
+ request.policy = policy;
223
+ return request;
224
+ }
225
+ static uint32ToUint8ArrayLE(num) {
226
+ // We want 8 bytes to match .NET Int64 (long) layout: low 32 bits in first 4 bytes, rest zero.
227
+ const arr = new Uint8Array(8);
228
+ // low 32 bits, little-endian
229
+ arr[0] = num & 0xff;
230
+ arr[1] = (num >>> 8) & 0xff;
231
+ arr[2] = (num >>> 16) & 0xff;
232
+ arr[3] = (num >>> 24) & 0xff;
233
+ // arr[4..7] are already 0 from Uint8Array init, matching a .NET long with high 32 bits = 0.
234
+ return arr;
235
+ }
236
+ static uint8ArrayToUint32LE(bytes) {
237
+ if (bytes.length !== 8) {
238
+ throw new Error("Expected 8 bytes for a 64-bit value");
239
+ }
240
+ // Optional safety check: ensure high 32 bits are zero (no real 64-bit longs passed).
241
+ // If you *really* want to enforce the "no longs" assumption, uncomment:
242
+ //
243
+ // if (bytes[4] | bytes[5] | bytes[6] | bytes[7]) {
244
+ // throw new Error("High 32 bits are not zero; expected a 32-bit value stored in 64-bit field.");
245
+ // }
246
+ // Reconstruct from the low 4 bytes (little-endian)
247
+ return (bytes[0] +
248
+ (bytes[1] << 8) +
249
+ (bytes[2] << 16) +
250
+ (bytes[3] * 0x1000000) // avoids sign issues of << 24
251
+ );
252
+ }
253
+ }
254
+ exports.default = BaseTideRequest;
255
+ //# sourceMappingURL=TideRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TideRequest.js","sourceRoot":"","sources":["../../src/models/TideRequest.ts"],"names":[],"mappings":";;AAAA,kEAAqD;AACrD,0DAAoD;AACpD,2CAAqC;AAErC,MAAqB,eAAe;IAehC,YAAY,IAAY,EAAE,OAAe,EAAE,QAAgB,EAAE,KAAiB,EAAE,WAAuB;QACnG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,IAAI,CAAC,KAAK,GAAG,IAAI,0BAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC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toBytes(base64: string): Uint8Array;
3
+ export declare function StringToUint8Array(string: string): Uint8Array;
4
+ export declare function StringFromUint8Array(bytes: Uint8Array): string;
5
+ export declare function BigIntToByteArray(value: bigint): Uint8Array;
6
+ export declare function BigIntFromByteArray(bytes: Uint8Array): bigint;
7
+ //# sourceMappingURL=Serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Serialization.d.ts","sourceRoot":"","sources":["../../src/utils/Serialization.ts"],"names":[],"mappings":"AAOA,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAI,MAAM,CAoBxD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAkCxD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAI,UAAU,CAG9D;AACD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAI,MAAM,CAG/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CA4B3D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAS7D"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bytesToBase64 = bytesToBase64;
4
+ exports.base64toBytes = base64toBytes;
5
+ exports.StringToUint8Array = StringToUint8Array;
6
+ exports.StringFromUint8Array = StringFromUint8Array;
7
+ exports.BigIntToByteArray = BigIntToByteArray;
8
+ exports.BigIntFromByteArray = BigIntFromByteArray;
9
+ const base64abc = [
10
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
11
+ "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
12
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
13
+ "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
14
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"
15
+ ];
16
+ function bytesToBase64(bytes) {
17
+ let result = '', i, l = bytes.length;
18
+ for (i = 2; i < l; i += 3) {
19
+ result += base64abc[bytes[i - 2] >> 2];
20
+ result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];
21
+ result += base64abc[((bytes[i - 1] & 0x0F) << 2) | (bytes[i] >> 6)];
22
+ result += base64abc[bytes[i] & 0x3F];
23
+ }
24
+ if (i === l + 1) { // 1 octet yet to write
25
+ result += base64abc[bytes[i - 2] >> 2];
26
+ result += base64abc[(bytes[i - 2] & 0x03) << 4];
27
+ result += "==";
28
+ }
29
+ if (i === l) { // 2 octets yet to write
30
+ result += base64abc[bytes[i - 2] >> 2];
31
+ result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];
32
+ result += base64abc[(bytes[i - 1] & 0x0F) << 2];
33
+ result += "=";
34
+ }
35
+ return result;
36
+ }
37
+ function base64toBytes(base64) {
38
+ const lookup = {};
39
+ for (let i = 0; i < base64abc.length; i++) {
40
+ lookup[base64abc[i]] = i;
41
+ }
42
+ const len = base64.length;
43
+ let bufferLength = base64.length * 0.75;
44
+ if (base64[len - 1] === "=") {
45
+ bufferLength--;
46
+ if (base64[len - 2] === "=") {
47
+ bufferLength--;
48
+ }
49
+ }
50
+ const bytes = new Uint8Array(bufferLength);
51
+ let p = 0;
52
+ for (let i = 0; i < len; i += 4) {
53
+ const encoded1 = lookup[base64[i]];
54
+ const encoded2 = lookup[base64[i + 1]];
55
+ const encoded3 = lookup[base64[i + 2]];
56
+ const encoded4 = lookup[base64[i + 3]];
57
+ bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
58
+ if (encoded3 !== undefined) {
59
+ bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
60
+ }
61
+ if (encoded4 !== undefined) {
62
+ bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
63
+ }
64
+ }
65
+ return bytes;
66
+ }
67
+ function StringToUint8Array(string) {
68
+ const enc = new TextEncoder();
69
+ return enc.encode(string);
70
+ }
71
+ function StringFromUint8Array(bytes) {
72
+ const enc = new TextDecoder();
73
+ return enc.decode(bytes);
74
+ }
75
+ function BigIntToByteArray(value) {
76
+ if (value < 0n) {
77
+ throw new Error("Negative BigInt values are not supported");
78
+ }
79
+ const bytes = [];
80
+ let temp = value;
81
+ // Extract bytes in little-endian order
82
+ while (temp > 0n) {
83
+ bytes.push(Number(temp & 0xffn));
84
+ temp = temp >> 8n;
85
+ }
86
+ // Handle zero case
87
+ if (bytes.length === 0) {
88
+ bytes.push(0);
89
+ }
90
+ // Pad or trim to specified length
91
+ const targetLength = bytes.length;
92
+ const result = new Uint8Array(targetLength);
93
+ for (let i = 0; i < Math.min(bytes.length, targetLength); i++) {
94
+ result[i] = bytes[i];
95
+ }
96
+ return result;
97
+ }
98
+ function BigIntFromByteArray(bytes) {
99
+ let result = 0n;
100
+ // Read bytes in little-endian order
101
+ for (let i = bytes.length - 1; i >= 0; i--) {
102
+ result = (result << 8n) | BigInt(bytes[i]);
103
+ }
104
+ return result;
105
+ }
106
+ //# sourceMappingURL=Serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Serialization.js","sourceRoot":"","sources":["../../src/utils/Serialization.ts"],"names":[],"mappings":";;AAOA,sCAoBC;AAED,sCAkCC;AAED,gDAGC;AACD,oDAGC;AAED,8CA4BC;AAED,kDASC;AAjHD,MAAM,SAAS,GAAG;IACjB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC/D,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC/D,GAAG,EA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AED,SAAgB,mBAAmB,CAAC,KAAiB;IACnD,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,oCAAoC;IACpC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare class TideMemory extends Uint8Array {
2
+ static CreateFromArray(datas: Uint8Array[]): TideMemory;
3
+ static Create(initialValue: Uint8Array, totalLength: number, version?: number): TideMemory;
4
+ WriteValue(index: number, value: Uint8Array): void;
5
+ GetValue(index: number): TideMemory;
6
+ TryGetValue(index: number, returnObj: {
7
+ result: Uint8Array | undefined;
8
+ }): boolean;
9
+ }
10
+ //# sourceMappingURL=TideMemory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TideMemory.d.ts","sourceRoot":"","sources":["../../src/utils/TideMemory.ts"],"names":[],"mappings":"AACA,qBAAa,UAAW,SAAQ,UAAU;IACtC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU;IASvD,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,MAAU,GAAG,UAAU;IAyB7F,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAwClD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAwCnC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE;QAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAA;KAAC,GAAG,OAAO;CASnF"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TideMemory = void 0;
4
+ // Tide Memory Object helper functions from tide-js
5
+ class TideMemory extends Uint8Array {
6
+ static CreateFromArray(datas) {
7
+ if (datas.length == 0)
8
+ return new TideMemory();
9
+ const length = datas.reduce((sum, next) => sum + 4 + next.length, 0);
10
+ const mem = this.Create(datas[0], length);
11
+ for (let i = 1; i < datas.length; i++) {
12
+ mem.WriteValue(i, datas[i]);
13
+ }
14
+ return mem;
15
+ }
16
+ static Create(initialValue, totalLength, version = 1) {
17
+ if (totalLength < initialValue.length + 4) {
18
+ throw new Error("Not enough space to allocate requested data. Make sure to request more space in totalLength than length of InitialValue plus 4 bytes for length.");
19
+ }
20
+ // Total buffer length is 4 (version) + totalLength
21
+ const bufferLength = 4 + totalLength;
22
+ const buffer = new TideMemory(bufferLength);
23
+ const dataView = new DataView(buffer.buffer);
24
+ // Write version at position 0 (4 bytes)
25
+ dataView.setInt32(0, version, true); // true for little-endian
26
+ let dataLocationIndex = 4;
27
+ // Write data length of initialValue at position 4 (4 bytes)
28
+ dataView.setInt32(dataLocationIndex, initialValue.length, true);
29
+ dataLocationIndex += 4;
30
+ // Write initialValue starting from position 8
31
+ buffer.set(initialValue, dataLocationIndex);
32
+ return buffer;
33
+ }
34
+ WriteValue(index, value) {
35
+ if (index < 0)
36
+ throw new Error("Index cannot be less than 0");
37
+ if (index === 0)
38
+ throw new Error("Use CreateTideMemory to set value at index 0");
39
+ if (this.length < 4 + value.length)
40
+ throw new Error("Could not write to memory. Memory too small for this value");
41
+ const dataView = new DataView(this.buffer);
42
+ let dataLocationIndex = 4; // Start after the version number
43
+ // Navigate through existing data segments
44
+ for (let i = 0; i < index; i++) {
45
+ if (dataLocationIndex + 4 > this.length) {
46
+ throw new RangeError("Index out of range.");
47
+ }
48
+ // Read data length at current position
49
+ const nextDataLength = dataView.getInt32(dataLocationIndex, true);
50
+ dataLocationIndex += 4;
51
+ dataLocationIndex += nextDataLength;
52
+ }
53
+ // Check if there's enough space to write the value
54
+ if (dataLocationIndex + 4 + value.length > this.length) {
55
+ throw new RangeError("Not enough space to write value");
56
+ }
57
+ // Check if data has already been written to this index
58
+ const existingLength = dataView.getInt32(dataLocationIndex, true);
59
+ if (existingLength !== 0) {
60
+ throw new Error("Data has already been written to this index");
61
+ }
62
+ // Write data length of value at current position
63
+ dataView.setInt32(dataLocationIndex, value.length, true);
64
+ dataLocationIndex += 4;
65
+ // Write value starting from current position
66
+ this.set(value, dataLocationIndex);
67
+ }
68
+ GetValue(index) {
69
+ // 'a' should be an ArrayBuffer or Uint8Array
70
+ if (this.length < 4) {
71
+ throw new Error("Insufficient data to read.");
72
+ }
73
+ // Create a DataView for reading integers in little-endian format
74
+ const dataView = new DataView(this.buffer, this.byteOffset, this.byteLength);
75
+ // Optional: Read the version if needed
76
+ // const version = dataView.getInt32(0, true);
77
+ let dataLocationIndex = 4;
78
+ for (let i = 0; i < index; i++) {
79
+ // Check if there's enough data to read the length of the next segment
80
+ if (dataLocationIndex + 4 > this.length) {
81
+ throw new RangeError("Index out of range.");
82
+ }
83
+ const nextDataLength = dataView.getInt32(dataLocationIndex, true);
84
+ dataLocationIndex += 4 + nextDataLength;
85
+ }
86
+ // Check if there's enough data to read the length of the final segment
87
+ if (dataLocationIndex + 4 > this.length) {
88
+ throw new RangeError("Index out of range.");
89
+ }
90
+ const finalDataLength = dataView.getInt32(dataLocationIndex, true);
91
+ dataLocationIndex += 4;
92
+ // Check if the final data segment is within bounds
93
+ if (dataLocationIndex + finalDataLength > this.length) {
94
+ throw new RangeError("Index out of range.");
95
+ }
96
+ return this.subarray(dataLocationIndex, dataLocationIndex + finalDataLength);
97
+ }
98
+ TryGetValue(index, returnObj) {
99
+ try {
100
+ returnObj.result = this.GetValue(index);
101
+ return true;
102
+ }
103
+ catch {
104
+ returnObj.result = undefined;
105
+ return false;
106
+ }
107
+ }
108
+ }
109
+ exports.TideMemory = TideMemory;
110
+ //# sourceMappingURL=TideMemory.js.map
@@ -0,0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,cAAc,CAAC;QAC5C,CAAC;QAED,uEAAuE;QACvE,IAAI,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACtC,MAAM,IAAI,UAAU,CAAC,qBAAqB,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,eAAe,GAAG,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;QACnE,iBAAiB,IAAI,CAAC,CAAC;QAEvB,mDAAmD;QACnD,IAAI,iBAAiB,GAAG,eAAe,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACpD,MAAM,IAAI,UAAU,CAAC,qBAAqB,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,eAAe,CAAe,CAAC;IAC/F,CAAC;IAED,WAAW,CAAC,KAAa,EAAE,SAA2C;QAClE,IAAG,CAAC;YACA,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;QAChB,CAAC;QAAA,MAAK,CAAC;YACH,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC;YAC7B,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ;AA5HD,gCA4HC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "asgard-tide",
3
+ "version": "0.12.33",
4
+ "description": "Vendor server-side libraries to validate and test Tide Security",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf dist",
10
+ "rebuild": "npm run clean && npm run build"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/tide-foundation/asgard.git"
18
+ },
19
+ "keywords": [
20
+ "tide"
21
+ ],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "bugs": {
25
+ "url": "https://github.com/tide-foundation/asgard/issues"
26
+ },
27
+ "homepage": "https://github.com/tide-foundation/asgard#readme",
28
+ "devDependencies": {
29
+ "@types/node": "^24.10.1",
30
+ "typescript": "^5.9.3"
31
+ }
32
+ }