@notabene/javascript-sdk 2.0.0-next.7 → 2.0.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/notabene.cjs +1 -1
- package/dist/notabene.d.ts +67 -5
- package/dist/notabene.js +80 -98
- package/package.json +1 -1
- package/src/components/EmbeddedComponent.ts +69 -4
- package/src/notabene.ts +33 -49
- package/src/types.ts +54 -18
package/dist/notabene.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var c=(r,e,t)=>e in r?d(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>c(r,typeof e!="symbol"?e+"":e,t);var h=(r=>(r.COMPLETE="complete",r.RESIZE="resize",r.RESULT="result",r.READY="ready",r.INVALID="invalid",r.MODAL="openModal",r.ERROR="error",r.CLOSE="closeModal",r.CANCEL="cancel",r))(h||{}),l=(r=>(r.UPDATE="update",r.REQUEST_RESPONSE="requestResponse",r))(l||{});class m{constructor(){n(this,"listeners",new Map);n(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(e){this.port=e,this.port.onmessage=this.handleMessage,this.port.start()}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){const s=this.listeners.get(e);s&&(s.delete(t),s.size===0&&this.listeners.delete(e))}handleMessage(e){console.log("received message",e.data);const t=e.data;if(typeof t=="object"&&t!==null&&"type"in t){const s=t.type,o=this.listeners.get(s);o&&o.forEach(i=>i(t))}}send(e){this.port&&this.port.postMessage(e)}}class u{constructor(e,t){n(this,"_url");n(this,"_value");n(this,"_errors",[]);n(this,"iframe");n(this,"eventManager");n(this,"ready",!1);n(this,"modal");this._url=e,this._value=t,this.eventManager=new m,this.on(h.INVALID,s=>{s.type===h.INVALID&&(this._errors=s.errors,this._value=s.value)}),this.on(h.RESIZE,s=>{s.type===h.RESIZE&&this.iframe&&(this.iframe.style.height=`${s.height}px`)})}get url(){return this._url}get value(){return this._value}get errors(){return this._errors}open(){document.location.href=this.url}mount(e){const t=document.querySelector(e);if(!t)throw new Error(`parentID ${e} not found`);this.embed(t)}embed(e){var t,s;this.iframe=document.createElement("iframe"),this.iframe.src=this.url,this.iframe.style.width="100%",this.iframe.style.height="100px",this.iframe.style.border="none",this.iframe.style.overflow="hidden",this.iframe.setAttribute("allowtransparency","true"),this.iframe.style.backgroundColor="transparent",e.appendChild(this.iframe),window.addEventListener("message",o=>{var i,a;o.source===((i=this.iframe)==null?void 0:i.contentWindow)&&(console.log("received message from iframe",o.data),(a=this.eventManager)==null||a.setPort(o.ports[0]),this.ready=!0)}),(s=(t=this.iframe)==null?void 0:t.contentWindow)==null||s.focus()}send(e){this.eventManager.send(e)}on(e,t){this.eventManager.on(e,t)}off(e,t){this.eventManager.off(e,t)}update(e){this._value=e,this.send({type:l.UPDATE,value:e})}completion(){return new Promise((e,t)=>{this.closeModal(),this.on(h.COMPLETE,s=>{e(s.response)}),this.on("error",s=>{t(new Error(s.message))})})}openModal(){this.modal&&this.closeModal(),this.modal=document.createElement("dialog"),document.body.appendChild(this.modal),this.embed(this.modal),this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()})}closeModal(){var e;this.modal&&(console.log("closeModal"),(e=this.modal)==null||e.close(),this.modal.remove(),this.modal=void 0)}}function f(r){return Object.entries(r).map(([e,t])=>{if(!(e&&t))return;const s=encodeURIComponent(e),o=encodeURIComponent(typeof t=="object"?JSON.stringify(t):t);return`${s}=${o}`}).filter(e=>!!e).join("&")}class p{constructor(e){n(this,"nodeUrl");n(this,"authToken");n(this,"uxUrl");n(this,"theme");n(this,"locale");this.uxUrl=e.uxUrl||"https://connect.notabene.id",this.nodeUrl=e.nodeUrl,this.authToken=e.authToken,this.theme=e.theme,this.locale=e.locale}componentUrl(e,t,s,o){const i=new URL(this.uxUrl);i.pathname=e;const a=f({authToken:this.authToken,value:t,configuration:s});return i.hash=a,this.nodeUrl&&i.searchParams.set("nodeUrl",this.nodeUrl),this.theme&&i.searchParams.set("theme",JSON.stringify(this.theme)),this.locale&&i.searchParams.set("locale",this.locale),o&&(o.callback&&i.searchParams.set("callback_url",o.callback),o.redirectUri&&i.searchParams.set("redirect_uri",o.redirectUri)),i.toString()}createComponent(e,t,s,o){return new u(this.componentUrl(e,t,s,o),t)}createWithdrawalAssist(e,t,s){return this.createComponent("withdrawal-assist",e,t,s)}createDepositAssist(e,t,s){return this.createComponent("deposit-assist",e,t,s)}createConnect(e,t,s){return this.createComponent("connect",e,t,s)}createDepositRequest(e,t,s){return this.createComponent("deposit-request",e,t,s)}decodeFragmentToObject(e){return e.slice(1).split("&").reduce((s,o)=>{const[i,a]=o.split("=");return s[decodeURIComponent(i)]=decodeURIComponent(a),s},{})}}module.exports=p;
|
package/dist/notabene.d.ts
CHANGED
|
@@ -152,6 +152,8 @@ export declare interface Counterparty {
|
|
|
152
152
|
verified?: boolean;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
declare type CryptoCredential = `${string}.${string}.mastercard`;
|
|
156
|
+
|
|
155
157
|
/**
|
|
156
158
|
* 5.2.7
|
|
157
159
|
* DateAndPlaceOfBirth
|
|
@@ -171,11 +173,29 @@ export declare interface DeclarationProof extends OwnershipProof {
|
|
|
171
173
|
confirmed: boolean;
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
/**
|
|
177
|
+
* An object representing a deposit transaction
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export declare interface Deposit extends OriginatorFields, Transaction {
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* An object representing a request for a deposit
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
export declare interface DepositRequest extends DepositRequestFields, Transaction {
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
declare type DepositRequestFields = {
|
|
191
|
+
destinations: destination[];
|
|
192
|
+
};
|
|
193
|
+
|
|
174
194
|
/**
|
|
175
195
|
* The destination of a transaction either a blockchain address, a CAIP-19 address, or a travel address.
|
|
176
196
|
* @public
|
|
177
197
|
*/
|
|
178
|
-
export declare type destination = BlockchainAddress | CAIP10 | TravelAddress;
|
|
198
|
+
export declare type destination = BlockchainAddress | CAIP10 | CryptoCredential | TravelAddress;
|
|
179
199
|
|
|
180
200
|
declare type DID = `did:${string}:${string}`;
|
|
181
201
|
|
|
@@ -192,17 +212,21 @@ export declare class EmbeddedComponent {
|
|
|
192
212
|
private iframe?;
|
|
193
213
|
private eventManager;
|
|
194
214
|
private ready;
|
|
215
|
+
private modal?;
|
|
195
216
|
constructor(url: string, value: Partial<Transaction>);
|
|
196
217
|
get url(): string;
|
|
197
218
|
get value(): Partial<Transaction>;
|
|
198
219
|
get errors(): ValidationError[];
|
|
199
220
|
open(): void;
|
|
200
221
|
mount(parentId: string): void;
|
|
222
|
+
embed(parent: Element): void;
|
|
201
223
|
send(message: HostMessage): void;
|
|
202
224
|
on(messageType: string, callback: MessageCallback): void;
|
|
203
225
|
off(messageType: string, callback: MessageCallback): void;
|
|
204
226
|
update(value: Partial<Transaction>): void;
|
|
205
227
|
completion(): Promise<TransactionResponse>;
|
|
228
|
+
openModal(): void;
|
|
229
|
+
private closeModal;
|
|
206
230
|
}
|
|
207
231
|
|
|
208
232
|
declare type Error_2 = {
|
|
@@ -431,9 +455,12 @@ declare class Notabene {
|
|
|
431
455
|
private theme?;
|
|
432
456
|
private locale?;
|
|
433
457
|
constructor(config: NotabeneConfig);
|
|
434
|
-
componentUrl(path: string, value: Partial<Transaction>, configuration?:
|
|
435
|
-
createComponent(path: string, value: Partial<Transaction>, options?:
|
|
436
|
-
createWithdrawalAssist(value: Partial<Withdrawal>, options?:
|
|
458
|
+
componentUrl(path: string, value: Partial<Transaction>, configuration?: TransactionOptions, callbacks?: CallbackOptions): string;
|
|
459
|
+
createComponent(path: string, value: Partial<Transaction>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent;
|
|
460
|
+
createWithdrawalAssist(value: Partial<Withdrawal>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent;
|
|
461
|
+
createDepositAssist(value: Partial<Deposit>, options?: any, callbacks?: CallbackOptions): EmbeddedComponent;
|
|
462
|
+
createConnect(value: Partial<Withdrawal>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent;
|
|
463
|
+
createDepositRequest(value: Partial<DepositRequest>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent;
|
|
437
464
|
decodeFragmentToObject(fragment: string): Record<string, string>;
|
|
438
465
|
}
|
|
439
466
|
export { Notabene }
|
|
@@ -471,6 +498,10 @@ declare type Originator = {
|
|
|
471
498
|
accountNumber?: string[];
|
|
472
499
|
};
|
|
473
500
|
|
|
501
|
+
declare type OriginatorFields = {
|
|
502
|
+
source?: Source;
|
|
503
|
+
};
|
|
504
|
+
|
|
474
505
|
/**
|
|
475
506
|
* Ownership Proof
|
|
476
507
|
* @public
|
|
@@ -589,6 +620,8 @@ export declare interface SignatureProof extends OwnershipProof {
|
|
|
589
620
|
wallet_provider: string;
|
|
590
621
|
}
|
|
591
622
|
|
|
623
|
+
declare type Source = BlockchainAddress | CAIP10;
|
|
624
|
+
|
|
592
625
|
/**
|
|
593
626
|
* The verification status of a transaction
|
|
594
627
|
* @public
|
|
@@ -635,6 +668,15 @@ export declare interface Transaction {
|
|
|
635
668
|
*/
|
|
636
669
|
export declare type TransactionAsset = NotabeneAsset | CAIP19 | DTI;
|
|
637
670
|
|
|
671
|
+
/**
|
|
672
|
+
* Configuration options for Transaction components
|
|
673
|
+
* @public
|
|
674
|
+
*/
|
|
675
|
+
export declare interface TransactionOptions {
|
|
676
|
+
microTransactionAddress?: BlockchainAddress;
|
|
677
|
+
proofFallbacks?: ProofTypes[];
|
|
678
|
+
}
|
|
679
|
+
|
|
638
680
|
/**
|
|
639
681
|
* The response of a transaction
|
|
640
682
|
* @public
|
|
@@ -646,6 +688,7 @@ export declare type TransactionResponse = {
|
|
|
646
688
|
valid: boolean;
|
|
647
689
|
status: Status;
|
|
648
690
|
errors: ValidationError[];
|
|
691
|
+
txCreate?: V1Transaction;
|
|
649
692
|
};
|
|
650
693
|
|
|
651
694
|
/**
|
|
@@ -676,7 +719,7 @@ declare type TransferPath = {
|
|
|
676
719
|
*/
|
|
677
720
|
declare type TransliterationMethodCode = 'arab' | 'aran' | 'armn' | 'cyrl' | 'deva' | 'geor' | 'grek' | 'hani' | 'hebr' | 'kana' | 'kore' | 'thai' | 'othr';
|
|
678
721
|
|
|
679
|
-
declare type TravelAddress = string
|
|
722
|
+
declare type TravelAddress = `ta${string}`;
|
|
680
723
|
|
|
681
724
|
declare type UpdateValue = {
|
|
682
725
|
type: HMType.UPDATE;
|
|
@@ -685,6 +728,25 @@ declare type UpdateValue = {
|
|
|
685
728
|
|
|
686
729
|
declare type URI = string;
|
|
687
730
|
|
|
731
|
+
declare type V1Asset = {
|
|
732
|
+
caip19: CAIP19;
|
|
733
|
+
} | string;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Transaction payload suitable for calling Notabene v1 tx/create
|
|
737
|
+
* @public
|
|
738
|
+
*/
|
|
739
|
+
declare type V1Transaction = {
|
|
740
|
+
transactionAsset: V1Asset;
|
|
741
|
+
transactionAmount: string;
|
|
742
|
+
originatorEqualsBeneficiary?: boolean;
|
|
743
|
+
originatorVASPdid: DID;
|
|
744
|
+
beneficiaryVASPdid: DID;
|
|
745
|
+
beneficiaryProof: OwnershipProof;
|
|
746
|
+
originator: Originator;
|
|
747
|
+
beneficiary: Beneficiary;
|
|
748
|
+
};
|
|
749
|
+
|
|
688
750
|
declare type ValidationError = {
|
|
689
751
|
attribute: string;
|
|
690
752
|
message: string;
|
package/dist/notabene.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var h = /* @__PURE__ */ ((
|
|
2
|
+
var c = (r, e, t) => e in r ? d(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var n = (r, e, t) => c(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
var h = /* @__PURE__ */ ((r) => (r.COMPLETE = "complete", r.RESIZE = "resize", r.RESULT = "result", r.READY = "ready", r.INVALID = "invalid", r.MODAL = "openModal", r.ERROR = "error", r.CLOSE = "closeModal", r.CANCEL = "cancel", r))(h || {}), l = /* @__PURE__ */ ((r) => (r.UPDATE = "update", r.REQUEST_RESPONSE = "requestResponse", r))(l || {});
|
|
5
5
|
class m {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
n(this, "listeners", /* @__PURE__ */ new Map());
|
|
8
|
+
n(this, "port");
|
|
9
9
|
this.handleMessage = this.handleMessage.bind(this);
|
|
10
10
|
}
|
|
11
11
|
setPort(e) {
|
|
@@ -15,15 +15,15 @@ class m {
|
|
|
15
15
|
this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t);
|
|
16
16
|
}
|
|
17
17
|
off(e, t) {
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const s = this.listeners.get(e);
|
|
19
|
+
s && (s.delete(t), s.size === 0 && this.listeners.delete(e));
|
|
20
20
|
}
|
|
21
21
|
handleMessage(e) {
|
|
22
22
|
console.log("received message", e.data);
|
|
23
23
|
const t = e.data;
|
|
24
24
|
if (typeof t == "object" && t !== null && "type" in t) {
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const s = t.type, o = this.listeners.get(s);
|
|
26
|
+
o && o.forEach((i) => i(t));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
// Method to send messages through the port
|
|
@@ -31,18 +31,20 @@ class m {
|
|
|
31
31
|
this.port && this.port.postMessage(e);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
class
|
|
34
|
+
class u {
|
|
35
|
+
// private popup?: HTMLElement;
|
|
35
36
|
constructor(e, t) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
n(this, "_url");
|
|
38
|
+
n(this, "_value");
|
|
39
|
+
n(this, "_errors", []);
|
|
40
|
+
n(this, "iframe");
|
|
41
|
+
n(this, "eventManager");
|
|
42
|
+
n(this, "ready", !1);
|
|
43
|
+
n(this, "modal");
|
|
44
|
+
this._url = e, this._value = t, this.eventManager = new m(), this.on(h.INVALID, (s) => {
|
|
45
|
+
s.type === h.INVALID && (this._errors = s.errors, this._value = s.value);
|
|
46
|
+
}), this.on(h.RESIZE, (s) => {
|
|
47
|
+
s.type === h.RESIZE && this.iframe && (this.iframe.style.height = `${s.height}px`);
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
get url() {
|
|
@@ -58,14 +60,16 @@ class f {
|
|
|
58
60
|
document.location.href = this.url;
|
|
59
61
|
}
|
|
60
62
|
mount(e) {
|
|
61
|
-
var r, n;
|
|
62
|
-
this.iframe = document.createElement("iframe"), this.iframe.src = this.url, this.iframe.style.width = "100%", this.iframe.style.height = "100px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", window.addEventListener("message", (i) => {
|
|
63
|
-
var a, l;
|
|
64
|
-
i.source === ((a = this.iframe) == null ? void 0 : a.contentWindow) && (console.log("received message from iframe", i.data), (l = this.eventManager) == null || l.setPort(i.ports[0]), this.ready = !0);
|
|
65
|
-
});
|
|
66
63
|
const t = document.querySelector(e);
|
|
67
64
|
if (!t) throw new Error(`parentID ${e} not found`);
|
|
68
|
-
|
|
65
|
+
this.embed(t);
|
|
66
|
+
}
|
|
67
|
+
embed(e) {
|
|
68
|
+
var t, s;
|
|
69
|
+
this.iframe = document.createElement("iframe"), this.iframe.src = this.url, this.iframe.style.width = "100%", this.iframe.style.height = "100px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", this.iframe.setAttribute("allowtransparency", "true"), this.iframe.style.backgroundColor = "transparent", e.appendChild(this.iframe), window.addEventListener("message", (o) => {
|
|
70
|
+
var i, a;
|
|
71
|
+
o.source === ((i = this.iframe) == null ? void 0 : i.contentWindow) && (console.log("received message from iframe", o.data), (a = this.eventManager) == null || a.setPort(o.ports[0]), this.ready = !0);
|
|
72
|
+
}), (s = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || s.focus();
|
|
69
73
|
}
|
|
70
74
|
send(e) {
|
|
71
75
|
this.eventManager.send(e);
|
|
@@ -77,109 +81,87 @@ class f {
|
|
|
77
81
|
this.eventManager.off(e, t);
|
|
78
82
|
}
|
|
79
83
|
update(e) {
|
|
80
|
-
this._value = e, this.send({ type:
|
|
84
|
+
this._value = e, this.send({ type: l.UPDATE, value: e });
|
|
81
85
|
}
|
|
82
86
|
completion() {
|
|
83
87
|
return new Promise((e, t) => {
|
|
84
|
-
this.on(h.COMPLETE, (
|
|
85
|
-
e(
|
|
86
|
-
}), this.on("error", (
|
|
87
|
-
t(new Error(
|
|
88
|
+
this.closeModal(), this.on(h.COMPLETE, (s) => {
|
|
89
|
+
e(s.response);
|
|
90
|
+
}), this.on("error", (s) => {
|
|
91
|
+
t(new Error(s.message));
|
|
88
92
|
});
|
|
89
93
|
});
|
|
90
94
|
}
|
|
95
|
+
// popup(): void {
|
|
96
|
+
// this.popup = document.createElement('div');
|
|
97
|
+
// this.popup.style;
|
|
98
|
+
// }
|
|
99
|
+
openModal() {
|
|
100
|
+
this.modal && this.closeModal(), this.modal = document.createElement("dialog"), document.body.appendChild(this.modal), this.embed(this.modal), this.modal.showModal(), this.modal.addEventListener("click", () => {
|
|
101
|
+
this.closeModal();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
closeModal() {
|
|
105
|
+
var e;
|
|
106
|
+
this.modal && (console.log("closeModal"), (e = this.modal) == null || e.close(), this.modal.remove(), this.modal = void 0);
|
|
107
|
+
}
|
|
91
108
|
}
|
|
92
|
-
function
|
|
93
|
-
return Object.entries(
|
|
109
|
+
function f(r) {
|
|
110
|
+
return Object.entries(r).map(([e, t]) => {
|
|
94
111
|
if (!(e && t)) return;
|
|
95
|
-
const
|
|
112
|
+
const s = encodeURIComponent(e), o = encodeURIComponent(
|
|
96
113
|
typeof t == "object" ? JSON.stringify(t) : t
|
|
97
114
|
);
|
|
98
|
-
return `${
|
|
115
|
+
return `${s}=${o}`;
|
|
99
116
|
}).filter((e) => !!e).join("&");
|
|
100
117
|
}
|
|
101
|
-
class
|
|
118
|
+
class E {
|
|
102
119
|
constructor(e) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
n(this, "nodeUrl");
|
|
121
|
+
n(this, "authToken");
|
|
122
|
+
n(this, "uxUrl");
|
|
123
|
+
n(this, "theme");
|
|
124
|
+
n(this, "locale");
|
|
108
125
|
this.uxUrl = e.uxUrl || "https://connect.notabene.id", this.nodeUrl = e.nodeUrl, this.authToken = e.authToken, this.theme = e.theme, this.locale = e.locale;
|
|
109
126
|
}
|
|
110
|
-
componentUrl(e, t,
|
|
127
|
+
componentUrl(e, t, s, o) {
|
|
111
128
|
const i = new URL(this.uxUrl);
|
|
112
129
|
i.pathname = e;
|
|
113
|
-
const a =
|
|
130
|
+
const a = f({
|
|
114
131
|
authToken: this.authToken,
|
|
115
132
|
value: t,
|
|
116
|
-
configuration:
|
|
133
|
+
configuration: s
|
|
117
134
|
});
|
|
118
|
-
return i.hash = a, this.nodeUrl && i.searchParams.set("nodeUrl", this.nodeUrl), this.theme && i.searchParams.set("theme", JSON.stringify(this.theme)), this.locale && i.searchParams.set("locale", this.locale),
|
|
135
|
+
return i.hash = a, this.nodeUrl && i.searchParams.set("nodeUrl", this.nodeUrl), this.theme && i.searchParams.set("theme", JSON.stringify(this.theme)), this.locale && i.searchParams.set("locale", this.locale), o && (o.callback && i.searchParams.set("callback_url", o.callback), o.redirectUri && i.searchParams.set("redirect_uri", o.redirectUri)), i.toString();
|
|
119
136
|
}
|
|
120
|
-
createComponent(e, t,
|
|
121
|
-
return new
|
|
122
|
-
this.componentUrl(e, t,
|
|
137
|
+
createComponent(e, t, s, o) {
|
|
138
|
+
return new u(
|
|
139
|
+
this.componentUrl(e, t, s, o),
|
|
123
140
|
t
|
|
124
141
|
);
|
|
125
142
|
}
|
|
126
|
-
createWithdrawalAssist(e, t,
|
|
127
|
-
return this.createComponent("withdrawal-assist", e, t,
|
|
143
|
+
createWithdrawalAssist(e, t, s) {
|
|
144
|
+
return this.createComponent("withdrawal-assist", e, t, s);
|
|
145
|
+
}
|
|
146
|
+
createDepositAssist(e, t, s) {
|
|
147
|
+
return this.createComponent("deposit-assist", e, t, s);
|
|
148
|
+
}
|
|
149
|
+
createConnect(e, t, s) {
|
|
150
|
+
return this.createComponent("connect", e, t, s);
|
|
151
|
+
}
|
|
152
|
+
createDepositRequest(e, t, s) {
|
|
153
|
+
return this.createComponent("deposit-request", e, t, s);
|
|
128
154
|
}
|
|
129
155
|
decodeFragmentToObject(e) {
|
|
130
156
|
return e.slice(1).split("&").reduce(
|
|
131
|
-
(
|
|
132
|
-
const [i, a] =
|
|
133
|
-
return
|
|
157
|
+
(s, o) => {
|
|
158
|
+
const [i, a] = o.split("=");
|
|
159
|
+
return s[decodeURIComponent(i)] = decodeURIComponent(a), s;
|
|
134
160
|
},
|
|
135
161
|
{}
|
|
136
162
|
);
|
|
137
163
|
}
|
|
138
|
-
// private openModal(url: string): void {
|
|
139
|
-
// if (this.modal) {
|
|
140
|
-
// this.closeModal();
|
|
141
|
-
// }
|
|
142
|
-
// this.modal = document.createElement('div');
|
|
143
|
-
// this.modal.style.position = 'fixed';
|
|
144
|
-
// this.modal.style.top = '0';
|
|
145
|
-
// this.modal.style.left = '0';
|
|
146
|
-
// this.modal.style.width = '100%';
|
|
147
|
-
// this.modal.style.height = '100%';
|
|
148
|
-
// this.modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
|
|
149
|
-
// this.modal.style.display = 'flex';
|
|
150
|
-
// this.modal.style.justifyContent = 'center';
|
|
151
|
-
// this.modal.style.alignItems = 'center';
|
|
152
|
-
// const iframe = document.createElement('iframe');
|
|
153
|
-
// iframe.src = url;
|
|
154
|
-
// iframe.setAttribute('allowtransparency', 'true');
|
|
155
|
-
// // iframe.allowtransparency = true;
|
|
156
|
-
// iframe.style.backgroundColor = 'transparent';
|
|
157
|
-
// iframe.style.width = '90%';
|
|
158
|
-
// iframe.style.height = '90%';
|
|
159
|
-
// iframe.style.border = 'none';
|
|
160
|
-
// iframe.style.overflow = 'hidden';
|
|
161
|
-
// this.modal.appendChild(iframe);
|
|
162
|
-
// document.body.appendChild(this.modal);
|
|
163
|
-
// this.modal.addEventListener('click', () => {
|
|
164
|
-
// console.log('click');
|
|
165
|
-
// this.closeModal();
|
|
166
|
-
// });
|
|
167
|
-
// document.addEventListener('keydown', ({ key }) => {
|
|
168
|
-
// console.log(`key: ${key}`);
|
|
169
|
-
// if (key === 'Escape') {
|
|
170
|
-
// console.log('esc');
|
|
171
|
-
// this.closeModal();
|
|
172
|
-
// }
|
|
173
|
-
// });
|
|
174
|
-
// }
|
|
175
|
-
// private closeModal(): void {
|
|
176
|
-
// if (this.modal) {
|
|
177
|
-
// console.log('this.closeModal');
|
|
178
|
-
// this.modal.remove();
|
|
179
|
-
// this.modal = undefined;
|
|
180
|
-
// }
|
|
181
|
-
// }
|
|
182
164
|
}
|
|
183
165
|
export {
|
|
184
|
-
|
|
166
|
+
E as default
|
|
185
167
|
};
|
package/package.json
CHANGED
|
@@ -23,6 +23,8 @@ export default class EmbeddedComponent {
|
|
|
23
23
|
private iframe?: HTMLIFrameElement;
|
|
24
24
|
private eventManager: MessageEventManager;
|
|
25
25
|
private ready = false;
|
|
26
|
+
private modal?: HTMLDialogElement;
|
|
27
|
+
// private popup?: HTMLElement;
|
|
26
28
|
|
|
27
29
|
constructor(url: string, value: Partial<Transaction>) {
|
|
28
30
|
this._url = url;
|
|
@@ -58,14 +60,23 @@ export default class EmbeddedComponent {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
mount(parentId: string) {
|
|
63
|
+
const parent = document.querySelector(parentId);
|
|
64
|
+
if (!parent) throw new Error(`parentID ${parentId} not found`);
|
|
65
|
+
this.embed(parent);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
embed(parent: Element) {
|
|
61
69
|
this.iframe = document.createElement('iframe');
|
|
62
70
|
this.iframe.src = this.url;
|
|
63
71
|
this.iframe.style.width = '100%';
|
|
64
72
|
this.iframe.style.height = '100px';
|
|
65
73
|
this.iframe.style.border = 'none';
|
|
66
74
|
this.iframe.style.overflow = 'hidden';
|
|
75
|
+
this.iframe.setAttribute('allowtransparency', 'true');
|
|
76
|
+
this.iframe.style.backgroundColor = 'transparent';
|
|
77
|
+
parent.appendChild(this.iframe);
|
|
67
78
|
|
|
68
|
-
window.addEventListener('message', (event) => {
|
|
79
|
+
window.addEventListener('message', (event: MessageEvent) => {
|
|
69
80
|
if (event.source !== this.iframe?.contentWindow) {
|
|
70
81
|
return;
|
|
71
82
|
}
|
|
@@ -74,9 +85,6 @@ export default class EmbeddedComponent {
|
|
|
74
85
|
this.ready = true;
|
|
75
86
|
});
|
|
76
87
|
|
|
77
|
-
const parent = document.querySelector(parentId);
|
|
78
|
-
if (!parent) throw new Error(`parentID ${parentId} not found`);
|
|
79
|
-
parent.appendChild(this.iframe);
|
|
80
88
|
this.iframe?.contentWindow?.focus();
|
|
81
89
|
}
|
|
82
90
|
|
|
@@ -99,6 +107,7 @@ export default class EmbeddedComponent {
|
|
|
99
107
|
|
|
100
108
|
completion(): Promise<TransactionResponse> {
|
|
101
109
|
return new Promise((resolve, reject) => {
|
|
110
|
+
this.closeModal();
|
|
102
111
|
this.on(CMType.COMPLETE, (message) => {
|
|
103
112
|
resolve((message as any).response);
|
|
104
113
|
});
|
|
@@ -107,4 +116,60 @@ export default class EmbeddedComponent {
|
|
|
107
116
|
});
|
|
108
117
|
});
|
|
109
118
|
}
|
|
119
|
+
|
|
120
|
+
// popup(): void {
|
|
121
|
+
// this.popup = document.createElement('div');
|
|
122
|
+
// this.popup.style;
|
|
123
|
+
// }
|
|
124
|
+
|
|
125
|
+
openModal(): void {
|
|
126
|
+
if (this.modal) {
|
|
127
|
+
this.closeModal();
|
|
128
|
+
}
|
|
129
|
+
this.modal = document.createElement('dialog');
|
|
130
|
+
// this.modal.style.maxWidth = '600px';
|
|
131
|
+
// this.modal.style.border = 'none !important';
|
|
132
|
+
// this.modal.style.background = 'transparent';
|
|
133
|
+
// this.modal.style.flexDirection = 'column';
|
|
134
|
+
// this.modal.style.alignItems = 'end';
|
|
135
|
+
// const close = document.createElement('button');
|
|
136
|
+
// close.innerText = 'X';
|
|
137
|
+
// close.style.fontSize = '1rem';
|
|
138
|
+
// close.style.padding = '0.25rem 0.5rem';
|
|
139
|
+
// close.style.display = 'block';
|
|
140
|
+
// close.style.background = 'white';
|
|
141
|
+
// close.style.color = '#aaa';
|
|
142
|
+
// close.style.border = '#aaa';
|
|
143
|
+
// close.addEventListener('click', () => this.closeModal());
|
|
144
|
+
// this.modal.appendChild(close);
|
|
145
|
+
// this.modal.css;
|
|
146
|
+
// this.modal.style.position = 'fixed';
|
|
147
|
+
// this.modal.style.bottom = '0';
|
|
148
|
+
// this.modal.style.left = '0';
|
|
149
|
+
// this.modal.style.right = '0';
|
|
150
|
+
// this.modal.style.top = '0';
|
|
151
|
+
// this.modal.style.left = '0';
|
|
152
|
+
// this.modal.style.width = '100%';
|
|
153
|
+
// this.modal.style.height = '100%';
|
|
154
|
+
// this.modal.style.backgroundColor = 'transparent';
|
|
155
|
+
// this.modal.style.display = 'flex';
|
|
156
|
+
// this.modal.style.justifyContent = 'center';
|
|
157
|
+
// this.modal.style.alignItems = 'center';
|
|
158
|
+
document.body.appendChild(this.modal);
|
|
159
|
+
this.embed(this.modal);
|
|
160
|
+
this.modal.showModal();
|
|
161
|
+
this.modal.addEventListener('click', () => {
|
|
162
|
+
// console.log('click');
|
|
163
|
+
this.closeModal();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private closeModal(): void {
|
|
168
|
+
if (this.modal) {
|
|
169
|
+
console.log('closeModal');
|
|
170
|
+
this.modal?.close();
|
|
171
|
+
this.modal.remove();
|
|
172
|
+
this.modal = undefined;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
110
175
|
}
|
package/src/notabene.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
ComponentMessage,
|
|
7
7
|
Counterparty,
|
|
8
8
|
DeclarationProof,
|
|
9
|
+
Deposit,
|
|
10
|
+
DepositRequest,
|
|
9
11
|
Destination,
|
|
10
12
|
HostMessage,
|
|
11
13
|
IVMS101,
|
|
@@ -20,6 +22,7 @@ import type {
|
|
|
20
22
|
Theme,
|
|
21
23
|
Transaction,
|
|
22
24
|
TransactionAsset,
|
|
25
|
+
TransactionOptions,
|
|
23
26
|
VASP,
|
|
24
27
|
Wallet,
|
|
25
28
|
Withdrawal,
|
|
@@ -35,7 +38,9 @@ export type {
|
|
|
35
38
|
Theme,
|
|
36
39
|
Counterparty,
|
|
37
40
|
Withdrawal,
|
|
41
|
+
Deposit,
|
|
38
42
|
Transaction,
|
|
43
|
+
DepositRequest,
|
|
39
44
|
TransactionResponse,
|
|
40
45
|
Destination as destination,
|
|
41
46
|
TransactionAsset,
|
|
@@ -54,6 +59,7 @@ export type {
|
|
|
54
59
|
Agent,
|
|
55
60
|
AgentType,
|
|
56
61
|
OwnershipProof,
|
|
62
|
+
TransactionOptions,
|
|
57
63
|
};
|
|
58
64
|
|
|
59
65
|
/**
|
|
@@ -93,7 +99,7 @@ export default class Notabene {
|
|
|
93
99
|
public componentUrl(
|
|
94
100
|
path: string,
|
|
95
101
|
value: Partial<Transaction>,
|
|
96
|
-
configuration?:
|
|
102
|
+
configuration?: TransactionOptions,
|
|
97
103
|
callbacks?: CallbackOptions,
|
|
98
104
|
): string {
|
|
99
105
|
const url = new URL(this.uxUrl);
|
|
@@ -125,7 +131,7 @@ export default class Notabene {
|
|
|
125
131
|
public createComponent(
|
|
126
132
|
path: string,
|
|
127
133
|
value: Partial<Transaction>,
|
|
128
|
-
options?:
|
|
134
|
+
options?: TransactionOptions,
|
|
129
135
|
callbacks?: CallbackOptions,
|
|
130
136
|
) {
|
|
131
137
|
return new EmbeddedComponent(
|
|
@@ -136,12 +142,36 @@ export default class Notabene {
|
|
|
136
142
|
|
|
137
143
|
public createWithdrawalAssist(
|
|
138
144
|
value: Partial<Withdrawal>,
|
|
139
|
-
options?:
|
|
145
|
+
options?: TransactionOptions,
|
|
140
146
|
callbacks?: CallbackOptions,
|
|
141
147
|
) {
|
|
142
148
|
return this.createComponent('withdrawal-assist', value, options, callbacks);
|
|
143
149
|
}
|
|
144
150
|
|
|
151
|
+
public createDepositAssist(
|
|
152
|
+
value: Partial<Deposit>,
|
|
153
|
+
options?: any,
|
|
154
|
+
callbacks?: CallbackOptions,
|
|
155
|
+
) {
|
|
156
|
+
return this.createComponent('deposit-assist', value, options, callbacks);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public createConnect(
|
|
160
|
+
value: Partial<Withdrawal>,
|
|
161
|
+
options?: TransactionOptions,
|
|
162
|
+
callbacks?: CallbackOptions,
|
|
163
|
+
) {
|
|
164
|
+
return this.createComponent('connect', value, options, callbacks);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public createDepositRequest(
|
|
168
|
+
value: Partial<DepositRequest>,
|
|
169
|
+
options?: TransactionOptions,
|
|
170
|
+
callbacks?: CallbackOptions,
|
|
171
|
+
) {
|
|
172
|
+
return this.createComponent('deposit-request', value, options, callbacks);
|
|
173
|
+
}
|
|
174
|
+
|
|
145
175
|
public decodeFragmentToObject(fragment: string): Record<string, string> {
|
|
146
176
|
const pairs = fragment.slice(1).split('&');
|
|
147
177
|
return pairs.reduce(
|
|
@@ -153,50 +183,4 @@ export default class Notabene {
|
|
|
153
183
|
{} as Record<string, string>,
|
|
154
184
|
);
|
|
155
185
|
}
|
|
156
|
-
|
|
157
|
-
// private openModal(url: string): void {
|
|
158
|
-
// if (this.modal) {
|
|
159
|
-
// this.closeModal();
|
|
160
|
-
// }
|
|
161
|
-
// this.modal = document.createElement('div');
|
|
162
|
-
// this.modal.style.position = 'fixed';
|
|
163
|
-
// this.modal.style.top = '0';
|
|
164
|
-
// this.modal.style.left = '0';
|
|
165
|
-
// this.modal.style.width = '100%';
|
|
166
|
-
// this.modal.style.height = '100%';
|
|
167
|
-
// this.modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
|
|
168
|
-
// this.modal.style.display = 'flex';
|
|
169
|
-
// this.modal.style.justifyContent = 'center';
|
|
170
|
-
// this.modal.style.alignItems = 'center';
|
|
171
|
-
// const iframe = document.createElement('iframe');
|
|
172
|
-
// iframe.src = url;
|
|
173
|
-
// iframe.setAttribute('allowtransparency', 'true');
|
|
174
|
-
// // iframe.allowtransparency = true;
|
|
175
|
-
// iframe.style.backgroundColor = 'transparent';
|
|
176
|
-
// iframe.style.width = '90%';
|
|
177
|
-
// iframe.style.height = '90%';
|
|
178
|
-
// iframe.style.border = 'none';
|
|
179
|
-
// iframe.style.overflow = 'hidden';
|
|
180
|
-
// this.modal.appendChild(iframe);
|
|
181
|
-
// document.body.appendChild(this.modal);
|
|
182
|
-
// this.modal.addEventListener('click', () => {
|
|
183
|
-
// console.log('click');
|
|
184
|
-
// this.closeModal();
|
|
185
|
-
// });
|
|
186
|
-
// document.addEventListener('keydown', ({ key }) => {
|
|
187
|
-
// console.log(`key: ${key}`);
|
|
188
|
-
// if (key === 'Escape') {
|
|
189
|
-
// console.log('esc');
|
|
190
|
-
// this.closeModal();
|
|
191
|
-
// }
|
|
192
|
-
// });
|
|
193
|
-
// }
|
|
194
|
-
|
|
195
|
-
// private closeModal(): void {
|
|
196
|
-
// if (this.modal) {
|
|
197
|
-
// console.log('this.closeModal');
|
|
198
|
-
// this.modal.remove();
|
|
199
|
-
// this.modal = undefined;
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
186
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Beneficiary,
|
|
2
3
|
DateAndPlaceOfBirth,
|
|
3
4
|
IVMS101,
|
|
4
5
|
NationalIdentification,
|
|
6
|
+
Originator,
|
|
5
7
|
} from './ivms/types';
|
|
6
8
|
|
|
7
9
|
export type { IVMS101 };
|
|
@@ -23,13 +25,18 @@ export type NotabeneAsset = string;
|
|
|
23
25
|
export type TransactionAsset = NotabeneAsset | CAIP19 | DTI;
|
|
24
26
|
|
|
25
27
|
export type BlockchainAddress = string;
|
|
26
|
-
export type TravelAddress = string
|
|
28
|
+
export type TravelAddress = `ta${string}`;
|
|
29
|
+
export type CryptoCredential = `${string}.${string}.mastercard`;
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* The destination of a transaction either a blockchain address, a CAIP-19 address, or a travel address.
|
|
30
33
|
* @public
|
|
31
34
|
*/
|
|
32
|
-
export type Destination =
|
|
35
|
+
export type Destination =
|
|
36
|
+
| BlockchainAddress
|
|
37
|
+
| CAIP10
|
|
38
|
+
| CryptoCredential
|
|
39
|
+
| TravelAddress;
|
|
33
40
|
export type Source = BlockchainAddress | CAIP10;
|
|
34
41
|
export type URI = string;
|
|
35
42
|
export type DID = `did:${string}:${string}`;
|
|
@@ -45,10 +52,6 @@ export type Theme = {
|
|
|
45
52
|
logo: string;
|
|
46
53
|
};
|
|
47
54
|
|
|
48
|
-
export enum ComponentTypes {
|
|
49
|
-
WITHDRAW_ASSIST = 'WITHDRAW_ASSIST',
|
|
50
|
-
}
|
|
51
|
-
|
|
52
55
|
// export type TransactionType = 'VASP_2_VASP' | 'SELF_HOSTED';
|
|
53
56
|
|
|
54
57
|
// export type TransactionTypeAllowed =
|
|
@@ -160,14 +163,18 @@ export interface LegalPerson extends Counterparty {
|
|
|
160
163
|
logo?: string;
|
|
161
164
|
}
|
|
162
165
|
|
|
163
|
-
|
|
166
|
+
type OriginatorFields = {
|
|
164
167
|
source?: Source;
|
|
165
168
|
};
|
|
166
169
|
|
|
167
|
-
|
|
170
|
+
type BeneficiaryFields = {
|
|
168
171
|
destination?: Destination;
|
|
169
172
|
};
|
|
170
173
|
|
|
174
|
+
type DepositRequestFields = {
|
|
175
|
+
destinations: Destination[];
|
|
176
|
+
};
|
|
177
|
+
|
|
171
178
|
/**
|
|
172
179
|
* An abstract transaction object
|
|
173
180
|
* @public
|
|
@@ -190,12 +197,29 @@ export interface Transaction {
|
|
|
190
197
|
* @public
|
|
191
198
|
*/
|
|
192
199
|
export interface Withdrawal extends BeneficiaryFields, Transaction {}
|
|
200
|
+
|
|
193
201
|
/**
|
|
194
202
|
* An object representing a deposit transaction
|
|
195
203
|
* @public
|
|
196
204
|
*/
|
|
197
205
|
export interface Deposit extends OriginatorFields, Transaction {}
|
|
198
206
|
|
|
207
|
+
/**
|
|
208
|
+
* An object representing a request for a deposit
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
export interface DepositRequest extends DepositRequestFields, Transaction {}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Configuration options for Transaction components
|
|
215
|
+
* @public
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
export interface TransactionOptions {
|
|
219
|
+
microTransactionAddress?: BlockchainAddress;
|
|
220
|
+
proofFallbacks?: ProofTypes[];
|
|
221
|
+
}
|
|
222
|
+
|
|
199
223
|
/**
|
|
200
224
|
* The verification status of a transaction
|
|
201
225
|
* @public
|
|
@@ -208,6 +232,27 @@ export enum Status {
|
|
|
208
232
|
BANNED = 'banned',
|
|
209
233
|
}
|
|
210
234
|
|
|
235
|
+
type V1Asset =
|
|
236
|
+
| {
|
|
237
|
+
caip19: CAIP19;
|
|
238
|
+
}
|
|
239
|
+
| string;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Transaction payload suitable for calling Notabene v1 tx/create
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
export type V1Transaction = {
|
|
247
|
+
transactionAsset: V1Asset;
|
|
248
|
+
transactionAmount: string;
|
|
249
|
+
originatorEqualsBeneficiary?: boolean;
|
|
250
|
+
originatorVASPdid: DID;
|
|
251
|
+
beneficiaryVASPdid: DID;
|
|
252
|
+
beneficiaryProof: OwnershipProof;
|
|
253
|
+
originator: Originator;
|
|
254
|
+
beneficiary: Beneficiary;
|
|
255
|
+
};
|
|
211
256
|
/**
|
|
212
257
|
* The response of a transaction
|
|
213
258
|
* @public
|
|
@@ -220,6 +265,7 @@ export type TransactionResponse = {
|
|
|
220
265
|
valid: boolean;
|
|
221
266
|
status: Status;
|
|
222
267
|
errors: ValidationError[];
|
|
268
|
+
txCreate?: V1Transaction;
|
|
223
269
|
};
|
|
224
270
|
|
|
225
271
|
export type ValidationError = {
|
|
@@ -244,16 +290,6 @@ export type FieldsProps = {
|
|
|
244
290
|
[name in FieldName]?: FieldProps;
|
|
245
291
|
};
|
|
246
292
|
|
|
247
|
-
export type WalletNotSupportedFlow = {
|
|
248
|
-
flow: 'WALLET_NOT_SUPPORTED';
|
|
249
|
-
action: 'DECLARATION' | 'REJECT';
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
// This is going to be union type
|
|
253
|
-
export type Fallback = WalletNotSupportedFlow;
|
|
254
|
-
|
|
255
|
-
export type OptInFeature = 'REUSE_ADDRESS_OWNERSHIP_PROOF';
|
|
256
|
-
|
|
257
293
|
/**
|
|
258
294
|
* Component Message Types
|
|
259
295
|
* @internal
|