@signing-room/embed 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/embed/src/index.d.ts +1 -0
- package/apps/embed/src/lib/embed.d.ts +12 -0
- package/index.js +77 -0
- package/package.json +18 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/embed';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class SigningRoomElement extends HTMLElement {
|
|
2
|
+
private iframe;
|
|
3
|
+
private targetOrigin;
|
|
4
|
+
private messageListener?;
|
|
5
|
+
private _isReady;
|
|
6
|
+
private _queuedPsbt;
|
|
7
|
+
constructor();
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
loadPsbt(psbtBase64: string): void;
|
|
10
|
+
disconnectedCallback(): void;
|
|
11
|
+
handleMessage(event: MessageEvent): void;
|
|
12
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// apps/embed/src/lib/embed.ts
|
|
2
|
+
var SigningRoomElement = class extends HTMLElement {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.targetOrigin = "";
|
|
6
|
+
this._isReady = false;
|
|
7
|
+
this._queuedPsbt = null;
|
|
8
|
+
this.attachShadow({ mode: "open" });
|
|
9
|
+
this.iframe = document.createElement("iframe");
|
|
10
|
+
this.iframe.style.width = "100%";
|
|
11
|
+
this.iframe.style.height = "100%";
|
|
12
|
+
this.iframe.style.minHeight = "600px";
|
|
13
|
+
this.iframe.style.border = "none";
|
|
14
|
+
this.iframe.style.borderRadius = "12px";
|
|
15
|
+
this.iframe.allow = "clipboard-write";
|
|
16
|
+
}
|
|
17
|
+
connectedCallback() {
|
|
18
|
+
const rawOrigin = this.getAttribute("relay-endpoint") || "https://signingroom.io";
|
|
19
|
+
this.targetOrigin = rawOrigin.replace(/\/$/, "");
|
|
20
|
+
const network = this.getAttribute("network") || "bitcoin";
|
|
21
|
+
const roomId = this.getAttribute("room-id");
|
|
22
|
+
const key = this.getAttribute("decryption-key");
|
|
23
|
+
const view = this.getAttribute("view");
|
|
24
|
+
const hideHeader = this.getAttribute("hide-header") === "true";
|
|
25
|
+
const hostOrigin = encodeURIComponent(window.location.origin);
|
|
26
|
+
let src = `${this.targetOrigin}/create?embedded=true&network=${network}&host=${hostOrigin}&hideHeader=${hideHeader}`;
|
|
27
|
+
if (view) src += `&view=${view}`;
|
|
28
|
+
if (roomId) {
|
|
29
|
+
src = `${this.targetOrigin}/room/${roomId}?embedded=true&host=${hostOrigin}&hideHeader=${hideHeader}`;
|
|
30
|
+
if (key) src += `#${key}`;
|
|
31
|
+
}
|
|
32
|
+
this.iframe.src = src;
|
|
33
|
+
this.shadowRoot?.appendChild(this.iframe);
|
|
34
|
+
this.messageListener = this.handleMessage.bind(this);
|
|
35
|
+
window.addEventListener("message", this.messageListener);
|
|
36
|
+
}
|
|
37
|
+
loadPsbt(psbtBase64) {
|
|
38
|
+
if (this._isReady && this.iframe.contentWindow) {
|
|
39
|
+
this.iframe.contentWindow.postMessage({
|
|
40
|
+
type: "SIGNING_ROOM_COMMAND",
|
|
41
|
+
action: "LOAD_PSBT",
|
|
42
|
+
payload: psbtBase64
|
|
43
|
+
}, this.targetOrigin);
|
|
44
|
+
} else {
|
|
45
|
+
this._queuedPsbt = psbtBase64;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
disconnectedCallback() {
|
|
49
|
+
if (this.messageListener) {
|
|
50
|
+
window.removeEventListener("message", this.messageListener);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
handleMessage(event) {
|
|
54
|
+
if (event.origin !== this.targetOrigin) return;
|
|
55
|
+
const { type, action, payload } = event.data || {};
|
|
56
|
+
if (type === "SIGNING_ROOM_EVENT" && action) {
|
|
57
|
+
if (action === "WIDGET_READY") {
|
|
58
|
+
this._isReady = true;
|
|
59
|
+
if (this._queuedPsbt) {
|
|
60
|
+
this.loadPsbt(this._queuedPsbt);
|
|
61
|
+
this._queuedPsbt = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
this.dispatchEvent(new CustomEvent(action, {
|
|
65
|
+
detail: payload,
|
|
66
|
+
bubbles: true,
|
|
67
|
+
composed: true
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (typeof window !== "undefined" && typeof customElements !== "undefined" && !customElements.get("signing-room")) {
|
|
73
|
+
customElements.define("signing-room", SigningRoomElement);
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
SigningRoomElement
|
|
77
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signing-room/embed",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.cjs",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"types": "./apps/embed/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./apps/embed/src/index.d.ts",
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"require": "./index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
}
|
|
18
|
+
}
|