heimdall-tide 0.1.0

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 (42) hide show
  1. package/LICENSE +334 -0
  2. package/README.md +3 -0
  3. package/dist/cjs/enclaves/ApprovalEnclave.d.ts +12 -0
  4. package/dist/cjs/enclaves/ApprovalEnclave.js +57 -0
  5. package/dist/cjs/enclaves/ApprovalEnclave.js.map +1 -0
  6. package/dist/cjs/enclaves/RequestEnclave.d.ts +38 -0
  7. package/dist/cjs/enclaves/RequestEnclave.js +204 -0
  8. package/dist/cjs/enclaves/RequestEnclave.js.map +1 -0
  9. package/dist/cjs/heimdall.d.ts +46 -0
  10. package/dist/cjs/heimdall.js +168 -0
  11. package/dist/cjs/heimdall.js.map +1 -0
  12. package/dist/cjs/index.d.ts +4 -0
  13. package/dist/cjs/index.js +8 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/wrapper.d.ts +16 -0
  16. package/dist/cjs/wrapper.js +232 -0
  17. package/dist/cjs/wrapper.js.map +1 -0
  18. package/dist/esm/enclaves/ApprovalEnclave.d.ts +12 -0
  19. package/dist/esm/enclaves/ApprovalEnclave.js +53 -0
  20. package/dist/esm/enclaves/ApprovalEnclave.js.map +1 -0
  21. package/dist/esm/enclaves/RequestEnclave.d.ts +38 -0
  22. package/dist/esm/enclaves/RequestEnclave.js +200 -0
  23. package/dist/esm/enclaves/RequestEnclave.js.map +1 -0
  24. package/dist/esm/heimdall.d.ts +46 -0
  25. package/dist/esm/heimdall.js +164 -0
  26. package/dist/esm/heimdall.js.map +1 -0
  27. package/dist/esm/index.d.ts +4 -0
  28. package/dist/esm/index.js +5 -0
  29. package/dist/esm/index.js.map +1 -0
  30. package/dist/esm/wrapper.d.ts +16 -0
  31. package/dist/esm/wrapper.js +225 -0
  32. package/dist/esm/wrapper.js.map +1 -0
  33. package/heimdall-tide-0.1.0.tgz +0 -0
  34. package/package.json +44 -0
  35. package/src/enclaves/ApprovalEnclave.ts +63 -0
  36. package/src/enclaves/RequestEnclave.ts +237 -0
  37. package/src/heimdall.ts +204 -0
  38. package/src/index.ts +4 -0
  39. package/src/wrapper.ts +258 -0
  40. package/tsconfig.cjs.json +9 -0
  41. package/tsconfig.esm.json +10 -0
  42. package/tsconfig.json +9 -0
@@ -0,0 +1,46 @@
1
+ export interface HeimdallConstructor {
2
+ vendorId: string;
3
+ homeOrkOrigin: string;
4
+ voucherURL: string;
5
+ signed_client_origin: string;
6
+ }
7
+ export declare abstract class Heimdall<T> implements EnclaveFlow<T> {
8
+ name: string;
9
+ _windowType: windowType;
10
+ enclaveOrigin: string;
11
+ voucherURL: string;
12
+ signed_client_origin: string;
13
+ vendorId: string;
14
+ private enclaveWindow;
15
+ constructor(init: HeimdallConstructor);
16
+ enclaveClosed(): boolean;
17
+ getOrkUrl(): URL;
18
+ open(): Promise<boolean>;
19
+ send(data: any): void;
20
+ recieve(type: string): Promise<any>;
21
+ close(): void;
22
+ onerror(data: any): void;
23
+ private openPopUp;
24
+ private closeHiddenIframe;
25
+ private openHiddenIframe;
26
+ private closePopupEnclave;
27
+ private waitForWindowPostMessage;
28
+ private sendPostWindowMessage;
29
+ private processEvent;
30
+ }
31
+ export declare enum windowType {
32
+ Popup = 0,
33
+ Redirect = 1,
34
+ Hidden = 2
35
+ }
36
+ interface EnclaveFlow<T> {
37
+ name: string;
38
+ _windowType: windowType;
39
+ open(): Promise<boolean>;
40
+ send(data: any): void;
41
+ recieve(type: string): Promise<any>;
42
+ close(): void;
43
+ onerror(data: any): void;
44
+ getOrkUrl(): URL;
45
+ }
46
+ export {};
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ //
3
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
4
+ // Copyright (C) 2022 Tide Foundation Ltd
5
+ //
6
+ // This program is free software and is subject to the terms of
7
+ // the Tide Community Open Code License as published by the
8
+ // Tide Foundation Limited. You may modify it and redistribute
9
+ // it in accordance with and subject to the terms of that License.
10
+ // This program is distributed WITHOUT WARRANTY of any kind,
11
+ // including without any implied warranty of MERCHANTABILITY or
12
+ // FITNESS FOR A PARTICULAR PURPOSE.
13
+ // See the Tide Community Open Code License for more details.
14
+ // You should have received a copy of the Tide Community Open
15
+ // Code License along with this program.
16
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.windowType = exports.Heimdall = void 0;
19
+ class Heimdall {
20
+ constructor(init) {
21
+ this.enclaveOrigin = init.homeOrkOrigin;
22
+ this.voucherURL = init.voucherURL;
23
+ this.signed_client_origin = init.signed_client_origin;
24
+ this.vendorId = init.vendorId;
25
+ }
26
+ enclaveClosed() {
27
+ return this.enclaveWindow.closed;
28
+ }
29
+ getOrkUrl() {
30
+ throw new Error("Method not implemented.");
31
+ }
32
+ async open() {
33
+ switch (this._windowType) {
34
+ case windowType.Popup:
35
+ return this.openPopUp();
36
+ case windowType.Redirect:
37
+ throw new Error("Method not implemented.");
38
+ case windowType.Hidden:
39
+ return this.openHiddenIframe();
40
+ }
41
+ }
42
+ send(data) {
43
+ switch (this._windowType) {
44
+ case windowType.Popup:
45
+ this.sendPostWindowMessage(data);
46
+ break;
47
+ case windowType.Redirect:
48
+ throw new Error("Method not implemented.");
49
+ case windowType.Hidden:
50
+ this.sendPostWindowMessage(data);
51
+ break;
52
+ }
53
+ }
54
+ async recieve(type) {
55
+ switch (this._windowType) {
56
+ case windowType.Popup:
57
+ return this.waitForWindowPostMessage(type);
58
+ case windowType.Redirect:
59
+ throw new Error("Method not implemented.");
60
+ case windowType.Hidden:
61
+ return this.waitForWindowPostMessage(type);
62
+ }
63
+ }
64
+ close() {
65
+ switch (this._windowType) {
66
+ case windowType.Popup:
67
+ this.closePopupEnclave();
68
+ break;
69
+ case windowType.Redirect:
70
+ throw new Error("Method not implemented.");
71
+ case windowType.Hidden:
72
+ this.closeHiddenIframe();
73
+ break;
74
+ default:
75
+ throw "Unknown window type";
76
+ }
77
+ }
78
+ onerror(data) {
79
+ throw new Error("Method not implemented.");
80
+ }
81
+ async openPopUp() {
82
+ const left_pos = (window.length / 2) - 400;
83
+ const w = window.open(this.getOrkUrl(), "_blank", `width=800,height=800,left=${left_pos}`);
84
+ if (!w)
85
+ return false;
86
+ this.enclaveWindow = w;
87
+ await this.waitForWindowPostMessage("pageLoaded"); // we need to wait for the page to load before we send sensitive data
88
+ return true;
89
+ }
90
+ async closeHiddenIframe() {
91
+ window.document
92
+ .querySelectorAll('iframe#heimdall')
93
+ .forEach(iframe => iframe.remove());
94
+ }
95
+ async openHiddenIframe() {
96
+ // Remove any existing iframes with heimdall id
97
+ this.closeHiddenIframe();
98
+ // 1. Create the iframe
99
+ const iframe = document.createElement('iframe');
100
+ iframe.src = this.getOrkUrl().toString();
101
+ iframe.style.display = 'none'; // hide it visually
102
+ iframe.id = "heimdall"; // in case multiple frames get popped up - we only want one
103
+ iframe.setAttribute('aria-hidden', 'true'); // accessibility hint
104
+ // 2. Add it to the document
105
+ document.body.appendChild(iframe);
106
+ // 3. Keep a reference to its window for postMessage
107
+ this.enclaveWindow = iframe.contentWindow;
108
+ if (!this.enclaveWindow)
109
+ return false;
110
+ // 4. Wait for the iframe to signal it’s ready
111
+ await this.waitForWindowPostMessage("pageLoaded");
112
+ return true;
113
+ }
114
+ closePopupEnclave() {
115
+ this.enclaveWindow.close();
116
+ }
117
+ async waitForWindowPostMessage(responseTypeToAwait) {
118
+ return new Promise((resolve) => {
119
+ const handler = (event) => {
120
+ const response = this.processEvent(event.data, event.origin, responseTypeToAwait);
121
+ if (response.ok) {
122
+ resolve(response.message);
123
+ window.removeEventListener("message", handler);
124
+ }
125
+ else {
126
+ if (response.print)
127
+ console.error("[HEIMDALL] Recieved enclave error: " + response.error);
128
+ }
129
+ };
130
+ window.addEventListener("message", handler, false);
131
+ });
132
+ }
133
+ sendPostWindowMessage(message) {
134
+ this.enclaveWindow.postMessage(message, this.enclaveOrigin);
135
+ }
136
+ processEvent(data, origin, expectedType) {
137
+ if (origin !== this.enclaveOrigin) {
138
+ // Something's not right... The message has come from an unknown domain...
139
+ return { ok: false, print: false, error: "WRONG WINDOW SENT MESSAGE" };
140
+ }
141
+ switch (data.type) {
142
+ case "newORKUrl":
143
+ this.enclaveOrigin = new URL(data.url).origin;
144
+ break;
145
+ case "error":
146
+ this.onerror(data);
147
+ return { ok: false, print: false, error: "handled error" };
148
+ }
149
+ if (expectedType !== data.type) {
150
+ console.log("[HEIMDALL] Received type{" + data.type + "} but waiting for type{" + expectedType + "}");
151
+ return { ok: false, print: false, error: "handled error" };
152
+ }
153
+ else {
154
+ console.log("[HEIMDALL] Correctly received type{" + data.type + "}");
155
+ return { ok: true, message: data.message };
156
+ }
157
+ }
158
+ }
159
+ exports.Heimdall = Heimdall;
160
+ var windowType;
161
+ (function (windowType) {
162
+ windowType[windowType["Popup"] = 0] = "Popup";
163
+ windowType[windowType["Redirect"] = 1] = "Redirect";
164
+ windowType[windowType["Hidden"] = 2] = "Hidden";
165
+ })(windowType || (exports.windowType = windowType = {}));
166
+ ;
167
+ ;
168
+ //# sourceMappingURL=heimdall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heimdall.js","sourceRoot":"","sources":["../../src/heimdall.ts"],"names":[],"mappings":";AAAA,GAAG;AACH,gEAAgE;AAChE,yCAAyC;AACzC,GAAG;AACH,gEAAgE;AAChE,4DAA4D;AAC5D,+DAA+D;AAC/D,kEAAkE;AAClE,6DAA6D;AAC7D,gEAAgE;AAChE,oCAAoC;AACpC,6DAA6D;AAC7D,8DAA8D;AAC9D,wCAAwC;AACxC,qDAAqD;;;AAUrD,MAAsB,QAAQ;IAU1B,YAAY,IAAyB;QACjC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;QACtD,IAAI,CAAC,QA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AI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAA;QAC5C,CAAC;IACL,CAAC;CACJ;AAjKD,4BAiKC;AACD,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,6CAAK,CAAA;IACL,mDAAQ,CAAA;IACR,+CAAM,CAAA;AACV,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAAA,CAAC;AAaD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ApprovalEnclave } from "./enclaves/ApprovalEnclave";
2
+ import { RequestEnclave } from "./enclaves/RequestEnclave";
3
+ export { ApprovalEnclave };
4
+ export { RequestEnclave };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestEnclave = exports.ApprovalEnclave = void 0;
4
+ const ApprovalEnclave_1 = require("./enclaves/ApprovalEnclave");
5
+ Object.defineProperty(exports, "ApprovalEnclave", { enumerable: true, get: function () { return ApprovalEnclave_1.ApprovalEnclave; } });
6
+ const RequestEnclave_1 = require("./enclaves/RequestEnclave");
7
+ Object.defineProperty(exports, "RequestEnclave", { enumerable: true, get: function () { return RequestEnclave_1.RequestEnclave; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAEnD,gGAFA,iCAAe,OAEA;AADxB,8DAA0D;AAEjD,+FAFA,+BAAc,OAEA"}
@@ -0,0 +1,16 @@
1
+ export declare const version = "1";
2
+ export declare function wrapper(arr: NestedEntry): TideMemory;
3
+ export declare function encodeStr(str: string, enc: string): Uint8Array;
4
+ export declare function encode(data: number | boolean | Uint8Array): Uint8Array | undefined;
5
+ interface entry {
6
+ value: any;
7
+ encoding?: string;
8
+ }
9
+ type NestedEntry = (entry | Uint8Array | NestedEntry)[];
10
+ export declare class TideMemory extends Uint8Array {
11
+ static CreateFromArray(datas: Uint8Array[]): TideMemory;
12
+ static Create(initialValue: Uint8Array, totalLength: number, version?: number): TideMemory;
13
+ WriteValue(index: number, value: Uint8Array): void;
14
+ GetValue<T extends Uint8Array>(index: number): T;
15
+ }
16
+ export {};
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TideMemory = exports.version = void 0;
4
+ exports.wrapper = wrapper;
5
+ exports.encodeStr = encodeStr;
6
+ exports.encode = encode;
7
+ exports.version = "1";
8
+ function wrapper(arr) {
9
+ // If array is only Uint8Arrays - create a TideMemory out of it
10
+ // If there is any entry in an array that is another array
11
+ // -> Go inside that array and repeat the process
12
+ if (arr.every(a => a instanceof Uint8Array))
13
+ return TideMemory.CreateFromArray(arr);
14
+ else {
15
+ // Go through each entry
16
+ arr.forEach((a) => {
17
+ // If the entry is an array, apply the wappa on it
18
+ if (Array.isArray(a)) {
19
+ // Reassign the value of the entry -> to the serialized wrapper
20
+ a = wrapper(a);
21
+ }
22
+ else if (a["value"]) {
23
+ // Let's check if is a number, boolean or Uint8Array. If none of those, it'll be null
24
+ const res = encode(a["value"]);
25
+ if (res) {
26
+ // serialized correctly
27
+ a = res;
28
+ }
29
+ else {
30
+ if (typeof a["value"] == "string") {
31
+ // Serialize it into Uint8Array
32
+ if (!a["encoding"]) {
33
+ // No encoding provided
34
+ // Let's default to UTF-8
35
+ a = encodeStr(a["value"], "UTF-8");
36
+ }
37
+ else {
38
+ a = encodeStr(a["value"], a["encoding"]);
39
+ }
40
+ }
41
+ else
42
+ throw 'Unsupported type';
43
+ }
44
+ }
45
+ else
46
+ throw 'Unexpected format';
47
+ });
48
+ if (arr.every(a => a instanceof Uint8Array))
49
+ return TideMemory.CreateFromArray(arr); // Check to make sure everything was serialized correctly from the wappa
50
+ else
51
+ throw 'There was an error encoding all your values';
52
+ }
53
+ }
54
+ function encodeStr(str, enc) {
55
+ switch (enc) {
56
+ case "UTF-8":
57
+ return new TextEncoder().encode(str);
58
+ case "HEX":
59
+ // 1) Strip 0x prefix
60
+ let normalized = str.replace(/^0x/i, "");
61
+ // treat empty as invalid
62
+ if (normalized.length === 0) {
63
+ throw new Error("Empty hex string");
64
+ }
65
+ // 2) Pad odd length
66
+ if (normalized.length % 2 !== 0) {
67
+ normalized = "0" + normalized;
68
+ }
69
+ // 3) Validate
70
+ if (!/^[0-9A-Fa-f]+$/.test(normalized)) {
71
+ throw new Error("Invalid hex string");
72
+ }
73
+ // 4) Parse into bytes
74
+ const byteCount = normalized.length / 2;
75
+ const out = new Uint8Array(byteCount);
76
+ for (let i = 0; i < byteCount; i++) {
77
+ out[i] = Number.parseInt(normalized.slice(i * 2, i * 2 + 2), 16);
78
+ }
79
+ return out;
80
+ case "B64":
81
+ const binaryString = atob(str);
82
+ const len = binaryString.length;
83
+ const bytes = new Uint8Array(len);
84
+ for (let i = 0; i < len; i++) {
85
+ bytes[i] = binaryString.charCodeAt(i);
86
+ }
87
+ return bytes;
88
+ case "B64URL":
89
+ // 1) Replace URL-safe chars with standard Base64 chars
90
+ let base64 = str.replace(/-/g, '+').replace(/_/g, '/');
91
+ // 2) Pad with '=' so length is a multiple of 4
92
+ const pad = base64.length % 4;
93
+ if (pad === 2) {
94
+ base64 += '==';
95
+ }
96
+ else if (pad === 3) {
97
+ base64 += '=';
98
+ }
99
+ else if (pad === 1) {
100
+ // This shouldn’t happen for valid Base64-URL, but just in case…
101
+ base64 += '===';
102
+ }
103
+ // 3) Decode to binary string
104
+ const binary = atob(base64);
105
+ // 4) Convert to Uint8Array
106
+ const ulen = binary.length;
107
+ const ubytes = new Uint8Array(ulen);
108
+ for (let i = 0; i < ulen; i++) {
109
+ ubytes[i] = binary.charCodeAt(i);
110
+ }
111
+ return ubytes;
112
+ default:
113
+ // catches anything else (should never happen)
114
+ throw new TypeError(`Unsupported encoding: ${enc}`);
115
+ }
116
+ }
117
+ function encode(data) {
118
+ switch (typeof data) {
119
+ case 'number':
120
+ const buffer = new ArrayBuffer(4);
121
+ const view = new DataView(buffer);
122
+ view.setUint32(0, data, true);
123
+ return new Uint8Array(buffer);
124
+ case 'boolean':
125
+ return new Uint8Array([data ? 1 : 0]);
126
+ case 'object':
127
+ // since a Uint8Array is an object at runtime, we need to check it here
128
+ if (data instanceof Uint8Array) {
129
+ return new Uint8Array(data.slice(0));
130
+ }
131
+ // if we fall through, it wasn't one of our allowed types
132
+ throw new TypeError(`Unsupported object type: ${data}`);
133
+ default:
134
+ // catches anything else (should never happen)
135
+ return undefined;
136
+ }
137
+ }
138
+ // Tide Memory Object helper functions from tide-js
139
+ class TideMemory extends Uint8Array {
140
+ static CreateFromArray(datas) {
141
+ const length = datas.reduce((sum, next) => sum + next.length, 0);
142
+ const mem = this.Create(datas[0], length);
143
+ for (let i = 1; i < datas.length; i++) {
144
+ mem.WriteValue(i, datas[i]);
145
+ }
146
+ return mem;
147
+ }
148
+ static Create(initialValue, totalLength, version = 1) {
149
+ if (totalLength < initialValue.length + 4) {
150
+ 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.");
151
+ }
152
+ // Total buffer length is 4 (version) + totalLength
153
+ const bufferLength = 4 + totalLength;
154
+ const buffer = new TideMemory(bufferLength);
155
+ const dataView = new DataView(buffer.buffer);
156
+ // Write version at position 0 (4 bytes)
157
+ dataView.setInt32(0, version, true); // true for little-endian
158
+ let dataLocationIndex = 4;
159
+ // Write data length of initialValue at position 4 (4 bytes)
160
+ dataView.setInt32(dataLocationIndex, initialValue.length, true);
161
+ dataLocationIndex += 4;
162
+ // Write initialValue starting from position 8
163
+ buffer.set(initialValue, dataLocationIndex);
164
+ return buffer;
165
+ }
166
+ WriteValue(index, value) {
167
+ if (index < 0)
168
+ throw new Error("Index cannot be less than 0");
169
+ if (index === 0)
170
+ throw new Error("Use CreateTideMemory to set value at index 0");
171
+ if (this.length < 4 + value.length)
172
+ throw new Error("Could not write to memory. Memory too small for this value");
173
+ const dataView = new DataView(this.buffer);
174
+ let dataLocationIndex = 4; // Start after the version number
175
+ // Navigate through existing data segments
176
+ for (let i = 0; i < index; i++) {
177
+ if (dataLocationIndex + 4 > this.length) {
178
+ throw new RangeError("Index out of range.");
179
+ }
180
+ // Read data length at current position
181
+ const nextDataLength = dataView.getInt32(dataLocationIndex, true);
182
+ dataLocationIndex += 4;
183
+ dataLocationIndex += nextDataLength;
184
+ }
185
+ // Check if there's enough space to write the value
186
+ if (dataLocationIndex + 4 + value.length > this.length) {
187
+ throw new RangeError("Not enough space to write value");
188
+ }
189
+ // Check if data has already been written to this index
190
+ const existingLength = dataView.getInt32(dataLocationIndex, true);
191
+ if (existingLength !== 0) {
192
+ throw new Error("Data has already been written to this index");
193
+ }
194
+ // Write data length of value at current position
195
+ dataView.setInt32(dataLocationIndex, value.length, true);
196
+ dataLocationIndex += 4;
197
+ // Write value starting from current position
198
+ this.set(value, dataLocationIndex);
199
+ }
200
+ GetValue(index) {
201
+ // 'a' should be an ArrayBuffer or Uint8Array
202
+ if (this.length < 4) {
203
+ throw new Error("Insufficient data to read.");
204
+ }
205
+ // Create a DataView for reading integers in little-endian format
206
+ const dataView = new DataView(this.buffer, this.byteOffset, this.byteLength);
207
+ // Optional: Read the version if needed
208
+ // const version = dataView.getInt32(0, true);
209
+ let dataLocationIndex = 4;
210
+ for (let i = 0; i < index; i++) {
211
+ // Check if there's enough data to read the length of the next segment
212
+ if (dataLocationIndex + 4 > this.length) {
213
+ throw new RangeError("Index out of range.");
214
+ }
215
+ const nextDataLength = dataView.getInt32(dataLocationIndex, true);
216
+ dataLocationIndex += 4 + nextDataLength;
217
+ }
218
+ // Check if there's enough data to read the length of the final segment
219
+ if (dataLocationIndex + 4 > this.length) {
220
+ throw new RangeError("Index out of range.");
221
+ }
222
+ const finalDataLength = dataView.getInt32(dataLocationIndex, true);
223
+ dataLocationIndex += 4;
224
+ // Check if the final data segment is within bounds
225
+ if (dataLocationIndex + finalDataLength > this.length) {
226
+ throw new RangeError("Index out of range.");
227
+ }
228
+ return this.subarray(dataLocationIndex, dataLocationIndex + finalDataLength);
229
+ }
230
+ }
231
+ exports.TideMemory = TideMemory;
232
+ //# sourceMappingURL=wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../../src/wrapper.ts"],"names":[],"mappings":";;;AAEA,0BAqCC;AAED,8BAoEC;AAED,wBAuBC;AAtIY,QAAA,OAAO,GAAG,GAAG,CAAC;AAE3B,SAAgB,OAAO,CAAC,GAAgB;IACpC,gEAAgE;IAChE,0DAA0D;IAC1D,qDAAqD;IACrD,IAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;SAC9E,CAAC;QACF,wBAAwB;QACxB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACd,kDAAkD;YAClD,IAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,CAAC;gBACjB,+DAA+D;gBAC/D,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;iBAAK,IAAG,CAAC,CAAC,OAAO,CAAC,EAAC,CAAC;gBACjB,qFAAqF;gBACrF,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC/B,IAAG,GAAG,EAAC,CAAC;oBACJ,uBAAuB;oBACvB,CAAC,GAAG,GAAG,CAAC;gBACZ,CAAC;qBAAI,CAAC;oBACF,IAAG,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,QAAQ,EAAC,CAAC;wBAC9B,+BAA+B;wBAC/B,IAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAAC,CAAC;4BACf,uBAAuB;4BACvB,yBAAyB;4BACzB,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;wBACvC,CAAC;6BAAI,CAAC;4BACF,CAAC,G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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,CAAM,CAAC;IACtF,CAAC;CACJ;AAjHD,gCAiHC"}
@@ -0,0 +1,12 @@
1
+ import { Heimdall, windowType } from "../heimdall";
2
+ export declare class ApprovalEnclave extends Heimdall<ApprovalEnclave> {
3
+ name: string;
4
+ _windowType: windowType;
5
+ private acceptedAdminIds;
6
+ enclaveUrl: URL;
7
+ private initDone;
8
+ init(data: string[], enclaveUrl: string): ApprovalEnclave;
9
+ getAuthorizerAuthentication(): Promise<any>;
10
+ getAuthorizerApproval(draftToApprove: any, modelId: any, expiry: any, encoding?: string, authflow?: string): Promise<any>;
11
+ getOrkUrl(): URL;
12
+ }
@@ -0,0 +1,53 @@
1
+ import { Heimdall, windowType } from "../heimdall";
2
+ export class ApprovalEnclave extends Heimdall {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.name = "approval";
6
+ this._windowType = windowType.Popup;
7
+ }
8
+ init(data, enclaveUrl) {
9
+ this.acceptedAdminIds = data;
10
+ this.enclaveUrl = new URL(enclaveUrl);
11
+ this.initDone = this.open();
12
+ return this;
13
+ }
14
+ async getAuthorizerAuthentication() {
15
+ await this.initDone;
16
+ // ready to accept reply
17
+ const pre_response = this.recieve("authentication");
18
+ // send to enclave
19
+ this.send({
20
+ type: "authentication",
21
+ message: "pretty please"
22
+ });
23
+ // wait for response - this does not mean that enclave it closed, just that the admin has responded to the approval request from the enclave
24
+ return await pre_response;
25
+ }
26
+ async getAuthorizerApproval(draftToApprove, modelId, expiry, encoding = "bytes", authflow = "") {
27
+ await this.initDone;
28
+ // ready to accept reply
29
+ const pre_response = this.recieve("approval");
30
+ // send to enclave
31
+ this.send({
32
+ type: "approval",
33
+ message: {
34
+ draftToAuthorize: {
35
+ data: draftToApprove,
36
+ encoding: encoding
37
+ },
38
+ modelId: modelId,
39
+ expiry: expiry,
40
+ authflow: authflow
41
+ }
42
+ });
43
+ // wait for response - this does not mean that enclave it closed, just that the admin has responded to the approval request from the enclave
44
+ return await pre_response;
45
+ }
46
+ getOrkUrl() {
47
+ // how to create approval ork url for openinging enclave?
48
+ this.enclaveUrl.searchParams.set("type", "approval");
49
+ this.enclaveUrl.searchParams.set("acceptedIds", JSON.stringify(this.acceptedAdminIds));
50
+ return this.enclaveUrl;
51
+ }
52
+ }
53
+ //# sourceMappingURL=ApprovalEnclave.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApprovalEnclave.js","sourceRoot":"","sources":["../../../src/enclaves/ApprovalEnclave.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,aAAa,CAAC;AAEjD,MAAM,OAAO,eAAgB,SAAQ,QAAyB;IAA9D;;QACI,SAAI,GAAW,UAAU,CAAC;QAC1B,gBAAW,GAAe,UAAU,CAAC,KAAK,CAAC;IA0D/C,CAAC;IArDG,IAAI,CAAC,IAAc,EAAE,UAAkB;QACnC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,2BAA2B;QAC7B,MAAM,IAAI,CAAC,QAAQ,CAAC;QACpB,wBAAwB;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAEpD,kBAAkB;QAClB,IAAI,CAAC,IAAI,CAAC;YACN,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,eAAe;SAC3B,CAAC,CAAC;QAEH,4IAA4I;QAC5I,OAAO,MAAM,YAAY,CAAC;IAC9B,CAAC;IAGD,KAAK,CAAC,qBAAqB,CAAC,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,QAAQ,GAAG,EAAE;QAC1F,MAAM,IAAI,CAAC,QAAQ,CAAC;QACpB,wBAAwB;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAE9C,kBAAkB;QAClB,IAAI,CAAC,IAAI,CAAC;YACN,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACL,gBAAgB,EAAE;oBACd,IAAI,EAAE,cAAc;oBACpB,QAAQ,EAAE,QAAQ;iBACrB;gBACD,OAAO,EAAE,OAAO;gBAChB,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,QAAQ;aACrB;SACJ,CAAC,CAAC;QAEH,4IAA4I;QAC5I,OAAO,MAAM,YAAY,CAAC;IAC9B,CAAC;IAED,SAAS;QACL,yDAAyD;QACzD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;QACvF,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CAEJ"}
@@ -0,0 +1,38 @@
1
+ import { Heimdall, windowType } from "../heimdall";
2
+ import { TideMemory } from "../wrapper";
3
+ interface HiddenInit {
4
+ doken: string;
5
+ /**
6
+ * @returns A refresh doken for Heimdall
7
+ */
8
+ dokenRefreshCallback: () => Promise<string> | undefined;
9
+ /**
10
+ * @returns A function that re authenticates the current user from the client. (Used to update their session key on Identity System). Returns a new doken too.
11
+ */
12
+ requireReloginCallback: () => Promise<string>;
13
+ }
14
+ export declare class RequestEnclave extends Heimdall<RequestEnclave> {
15
+ private doken;
16
+ private dokenRefreshCallback;
17
+ private requireReloginCallback;
18
+ _windowType: windowType;
19
+ private initDone;
20
+ init(data: HiddenInit): RequestEnclave;
21
+ handleHiddenEnclaveResponse(msg: any): Promise<void>;
22
+ getOrkUrl(): URL;
23
+ checkEnclaveOpen(): void;
24
+ execute(data: TideMemory): Promise<Uint8Array[]>;
25
+ decrypt(data: decryptRequest): Promise<Uint8Array[]>;
26
+ encrypt(data: encryptRequest): Promise<Uint8Array[]>;
27
+ updateDoken(doken: string): Promise<void>;
28
+ onerror(data: any): Promise<void>;
29
+ }
30
+ interface decryptRequest {
31
+ encrypted: Uint8Array;
32
+ tags: string[];
33
+ }
34
+ interface encryptRequest {
35
+ data: Uint8Array;
36
+ tags: string[];
37
+ }
38
+ export {};