@notabene/javascript-sdk 2.13.0 → 2.14.0-next.4

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.js CHANGED
@@ -1,11 +1,11 @@
1
- var f = Object.defineProperty;
2
- var L = (e, t, n) => t in e ? f(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var o = (e, t, n) => L(e, typeof t != "symbol" ? t + "" : t, n);
4
- var N = /* @__PURE__ */ ((e) => (e.PRIVATE = "WALLET", e.VASP = "VASP", e))(N || {}), v = /* @__PURE__ */ ((e) => (e.NATURAL = "natural", e.LEGAL = "legal", e.SELF = "self", e))(v || {}), I = /* @__PURE__ */ ((e) => (e.EMPTY = "empty", e.VERIFY = "verify", e.PENDING = "pending", e.VERIFIED = "verified", e.BANNED = "banned", e))(I || {}), _ = /* @__PURE__ */ ((e) => (e.ALLOWED = "allowed", e.PENDING = "pending", e))(_ || {}), g = /* @__PURE__ */ ((e) => (e.SMS = "sms", e.EMAIL = "email", e))(g || {}), D = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.APPROVED = "approved", e.FAILED = "failed", e.EXPIRED = "expired", e.MAX_ATTEMPTS_REACHED = "max_attempts_reached", e.UNREACHABLE = "unreachable", e))(D || {}), U = /* @__PURE__ */ ((e) => (e.COINBASE = "coinbase", e))(U || {}), R = /* @__PURE__ */ ((e) => (e.ASSET = "asset", e.DESTINATION = "destination", e.COUNTERPARTY = "counterparty", e.AGENT = "agent", e))(R || {}), l = /* @__PURE__ */ ((e) => (e.COMPLETE = "complete", e.RESIZE = "resize", e.RESULT = "result", e.READY = "ready", e.INVALID = "invalid", e.ERROR = "error", e.CANCEL = "cancel", e.WARNING = "warning", e.INFO = "info", e))(l || {}), C = /* @__PURE__ */ ((e) => (e.SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE", e.WALLET_CONNECTION_FAILED = "WALLET_CONNECTION_FAILED", e.WALLET_NOT_SUPPORTED = "WALLET_NOT_SUPPORTED", e.TOKEN_INVALID = "TOKEN_INVALID", e))(C || {}), O = /* @__PURE__ */ ((e) => (e.WALLET_ADDRESS_NOT_CONNECTED = "WALLET_ADDRESS_NOT_CONNECTED", e.WALLET_LOCKED = "WALLET_LOCKED", e.WALLET_UNREACHABLE = "WALLET_UNREACHABLE", e.JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE = "JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE", e.IDV_UNAVAILABLE = "IDV_UNAVAILABLE", e))(O || {}), p = /* @__PURE__ */ ((e) => (e.UPDATE = "update", e.REQUEST_RESPONSE = "requestResponse", e))(p || {}), b = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.FAILED = "rejected", e.FLAGGED = "flagged", e.VERIFIED = "verified", e))(b || {}), y = /* @__PURE__ */ ((e) => (e.SelfDeclaration = "self-declaration", e.SIWE = "siwe", e.SIWX = "siwx", e.SOL_SIWX = "sol-siwx", e.EIP191 = "eip-191", e.EIP712 = "eip-712", e.EIP1271 = "eip-1271", e.BIP137 = "bip-137", e.BIP322 = "bip-322", e.BIP137_XPUB = "xpub", e.TIP191 = "tip-191", e.ED25519 = "ed25519", e.XRP_ED25519 = "xrp-ed25519", e.XLM_ED25519 = "xlm-ed25519", e.CIP8 = "cip-8", e.COSMOS = "cosmos-ecdsa", e.MicroTransfer = "microtransfer", e.Screenshot = "screenshot", e.Connect = "connect", e.CONCORDIUM = "concordium", e))(y || {});
5
- class x {
1
+ var C = Object.defineProperty;
2
+ var R = (e, t, n) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var c = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
4
+ var S = /* @__PURE__ */ ((e) => (e.PRIVATE = "WALLET", e.VASP = "VASP", e))(S || {}), g = /* @__PURE__ */ ((e) => (e.NATURAL = "natural", e.LEGAL = "legal", e.SELF = "self", e))(g || {}), _ = /* @__PURE__ */ ((e) => (e.EMPTY = "empty", e.VERIFY = "verify", e.PENDING = "pending", e.VERIFIED = "verified", e.BANNED = "banned", e))(_ || {}), O = /* @__PURE__ */ ((e) => (e.ALLOWED = "allowed", e.PENDING = "pending", e))(O || {}), T = /* @__PURE__ */ ((e) => (e.SMS = "sms", e.EMAIL = "email", e))(T || {}), D = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.APPROVED = "approved", e.FAILED = "failed", e.EXPIRED = "expired", e.MAX_ATTEMPTS_REACHED = "max_attempts_reached", e.UNREACHABLE = "unreachable", e))(D || {}), U = /* @__PURE__ */ ((e) => (e.COINBASE = "coinbase", e))(U || {}), x = /* @__PURE__ */ ((e) => (e.ASSET = "asset", e.DESTINATION = "destination", e.COUNTERPARTY = "counterparty", e.AGENT = "agent", e))(x || {}), l = /* @__PURE__ */ ((e) => (e.COMPLETE = "complete", e.RESIZE = "resize", e.RESULT = "result", e.READY = "ready", e.INVALID = "invalid", e.ERROR = "error", e.CANCEL = "cancel", e.WARNING = "warning", e.INFO = "info", e))(l || {}), M = /* @__PURE__ */ ((e) => (e.SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE", e.WALLET_CONNECTION_FAILED = "WALLET_CONNECTION_FAILED", e.WALLET_NOT_SUPPORTED = "WALLET_NOT_SUPPORTED", e.TOKEN_INVALID = "TOKEN_INVALID", e))(M || {}), V = /* @__PURE__ */ ((e) => (e.WALLET_ADDRESS_NOT_CONNECTED = "WALLET_ADDRESS_NOT_CONNECTED", e.WALLET_LOCKED = "WALLET_LOCKED", e.WALLET_UNREACHABLE = "WALLET_UNREACHABLE", e.JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE = "JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE", e.IDV_UNAVAILABLE = "IDV_UNAVAILABLE", e))(V || {}), y = /* @__PURE__ */ ((e) => (e.UPDATE = "update", e.REQUEST_RESPONSE = "requestResponse", e))(y || {}), B = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.FAILED = "rejected", e.FLAGGED = "flagged", e.VERIFIED = "verified", e))(B || {}), W = /* @__PURE__ */ ((e) => (e.SelfDeclaration = "self-declaration", e.SIWE = "siwe", e.SIWX = "siwx", e.SOL_SIWX = "sol-siwx", e.EIP191 = "eip-191", e.EIP712 = "eip-712", e.EIP1271 = "eip-1271", e.BIP137 = "bip-137", e.BIP322 = "bip-322", e.BIP137_XPUB = "xpub", e.TIP191 = "tip-191", e.ED25519 = "ed25519", e.XRP_ED25519 = "xrp-ed25519", e.XLM_ED25519 = "xlm-ed25519", e.CIP8 = "cip-8", e.COSMOS = "cosmos-ecdsa", e.MicroTransfer = "microtransfer", e.Screenshot = "screenshot", e.Connect = "connect", e.CONCORDIUM = "concordium", e))(W || {});
5
+ class k {
6
6
  constructor() {
7
- o(this, "listeners", /* @__PURE__ */ new Map());
8
- o(this, "port");
7
+ c(this, "listeners", /* @__PURE__ */ new Map());
8
+ c(this, "port");
9
9
  this.handleMessage = this.handleMessage.bind(this);
10
10
  }
11
11
  /**
@@ -42,8 +42,8 @@ class x {
42
42
  * @param callback - The callback function to remove
43
43
  */
44
44
  off(t, n) {
45
- const s = this.listeners.get(t);
46
- s && (s.delete(n), s.size === 0 && this.listeners.delete(t));
45
+ const r = this.listeners.get(t);
46
+ r && (r.delete(n), r.size === 0 && this.listeners.delete(t));
47
47
  }
48
48
  /**
49
49
  * Internal message handler for processing received messages.
@@ -56,8 +56,8 @@ class x {
56
56
  handleMessage(t) {
57
57
  const n = t.data;
58
58
  if (typeof n == "object" && n !== null && "type" in n) {
59
- const s = n.type, r = this.listeners.get(s);
60
- r && r.forEach((i) => i(n));
59
+ const r = n.type, o = this.listeners.get(r);
60
+ o && o.forEach((i) => i(n));
61
61
  }
62
62
  }
63
63
  /**
@@ -68,24 +68,24 @@ class x {
68
68
  this.port && this.port.postMessage(t);
69
69
  }
70
70
  }
71
- class S {
71
+ class J {
72
72
  /**
73
73
  * Creates an instance of EmbeddedComponent.
74
74
  * @param url - The URL of the embedded component
75
75
  * @param value - The initial transaction value
76
76
  */
77
- constructor(t, n, s) {
78
- o(this, "_url");
79
- o(this, "_value");
80
- o(this, "_options");
81
- o(this, "_errors", []);
82
- o(this, "iframe");
83
- o(this, "eventManager");
84
- o(this, "modal");
85
- this._url = t, this._value = n, this._options = s, this.eventManager = new x(), this.on(l.INVALID, (r) => {
86
- r.type === l.INVALID && (this._errors = r.errors, this._value = r.value);
87
- }), this.on(l.RESIZE, (r) => {
88
- r.type === l.RESIZE && this.iframe && (this.iframe.style.height = `${r.height}px`);
77
+ constructor(t, n, r) {
78
+ c(this, "_url");
79
+ c(this, "_value");
80
+ c(this, "_options");
81
+ c(this, "_errors", []);
82
+ c(this, "iframe");
83
+ c(this, "eventManager");
84
+ c(this, "modal");
85
+ this._url = t, this._value = n, this._options = r, this.eventManager = new k(), this.on(l.INVALID, (o) => {
86
+ o.type === l.INVALID && (this._errors = o.errors, this._value = o.value);
87
+ }), this.on(l.RESIZE, (o) => {
88
+ o.type === l.RESIZE && this.iframe && (this.iframe.style.height = `${o.height}px`);
89
89
  });
90
90
  }
91
91
  /**
@@ -129,11 +129,11 @@ class S {
129
129
  * @param parent - The parent element to embed the component into
130
130
  */
131
131
  embed(t, n = !1) {
132
- var s, r;
132
+ var r, o;
133
133
  this.removeEmbed(), this.iframe = document.createElement("iframe"), this.iframe.src = this.url + (n ? "" : "&embedded=true"), this.iframe.allow = "web-share; clipboard-write; hid; bluetooth;", this.iframe.style.width = "100%", this.iframe.style.height = "0px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", this.iframe.scrolling = "no", t.appendChild(this.iframe), window.addEventListener("message", (i) => {
134
- var a, c;
135
- i.source === ((a = this.iframe) == null ? void 0 : a.contentWindow) && ((c = this.eventManager) == null || c.setPort(i.ports[0]));
136
- }), (r = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || r.focus();
134
+ var s, a;
135
+ i.source === ((s = this.iframe) == null ? void 0 : s.contentWindow) && ((a = this.eventManager) == null || a.setPort(i.ports[0]));
136
+ }), (o = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || o.focus();
137
137
  }
138
138
  removeEmbed() {
139
139
  this.iframe && this.iframe.remove();
@@ -166,7 +166,7 @@ class S {
166
166
  * @param value - The new transaction value
167
167
  */
168
168
  update(t, n) {
169
- this._value = t, n && (this._options = n), this.send({ type: p.UPDATE, value: t, options: this._options });
169
+ this._value = t, n && (this._options = n), this.send({ type: y.UPDATE, value: t, options: this._options });
170
170
  }
171
171
  /**
172
172
  * Waits for the component to complete and returns the transaction response
@@ -174,16 +174,16 @@ class S {
174
174
  */
175
175
  completion() {
176
176
  return new Promise((t, n) => {
177
- let s, r, i;
178
- function a() {
179
- s && s(), r && r(), i && i();
177
+ let r, o, i;
178
+ function s() {
179
+ r && r(), o && o(), i && i();
180
180
  }
181
- s = this.on(l.COMPLETE, (c) => {
182
- t(c.response), a();
183
- }), r = this.on(l.CANCEL, () => {
184
- n(new Error("User cancelled")), a();
185
- }), i = this.on("error", (c) => {
186
- n(new Error(c.message)), a();
181
+ r = this.on(l.COMPLETE, (a) => {
182
+ t(a.response), s();
183
+ }), o = this.on(l.CANCEL, () => {
184
+ n(new Error("User cancelled")), s();
185
+ }), i = this.on("error", (a) => {
186
+ n(new Error(a.message)), s();
187
187
  });
188
188
  });
189
189
  }
@@ -223,87 +223,402 @@ class S {
223
223
  "_blank",
224
224
  "popup=true,width=600,height=600"
225
225
  );
226
- window.addEventListener("message", (r) => {
226
+ window.addEventListener("message", (o) => {
227
227
  var i;
228
- r.source === t && (console.log("received message from popup", r.data), (i = this.eventManager) == null || i.setPort(r.ports[0]));
228
+ o.source === t && (console.log("received message from popup", o.data), (i = this.eventManager) == null || i.setPort(o.ports[0]));
229
229
  });
230
230
  const n = this.on(l.CANCEL, () => {
231
231
  t == null || t.close();
232
- }), s = this.on(l.COMPLETE, () => {
232
+ }), r = this.on(l.COMPLETE, () => {
233
233
  t == null || t.close();
234
234
  });
235
235
  return this.completion().finally(() => {
236
- n(), s();
236
+ n(), r();
237
237
  });
238
238
  }
239
239
  }
240
- function T(e) {
240
+ function F(e) {
241
241
  return Object.entries(e).map(([t, n]) => {
242
242
  if (n == null) return;
243
- const s = encodeURIComponent(t), r = encodeURIComponent(
243
+ const r = encodeURIComponent(t), o = encodeURIComponent(
244
244
  typeof n == "object" ? JSON.stringify(n) : String(n)
245
245
  // Use String() to handle all primitive types
246
246
  );
247
- return `${s}=${r}`;
247
+ return `${r}=${o}`;
248
248
  }).filter((t) => t !== void 0).join("&");
249
249
  }
250
- function B(e) {
250
+ function oe(e) {
251
251
  const t = e.slice(1);
252
252
  return t ? t.split("&").filter(Boolean).reduce(
253
- (s, r) => {
254
- const [i, a] = r.split("=");
255
- return i && (s[decodeURIComponent(i)] = a ? decodeURIComponent(a) : ""), s;
253
+ (r, o) => {
254
+ const [i, s] = o.split("=");
255
+ return i && (r[decodeURIComponent(i)] = s ? decodeURIComponent(s) : ""), r;
256
256
  },
257
257
  {}
258
258
  ) : {};
259
259
  }
260
- async function m(e, t) {
261
- const n = JSON.stringify(e), s = new TextEncoder(), r = t ? u(t) : crypto.getRandomValues(new Uint8Array(32)), i = await crypto.subtle.importKey(
260
+ new TextEncoder();
261
+ const f = new TextDecoder();
262
+ function j(e) {
263
+ if (Uint8Array.fromBase64)
264
+ return Uint8Array.fromBase64(e);
265
+ const t = atob(e), n = new Uint8Array(t.length);
266
+ for (let r = 0; r < t.length; r++)
267
+ n[r] = t.charCodeAt(r);
268
+ return n;
269
+ }
270
+ function G(e) {
271
+ if (Uint8Array.fromBase64)
272
+ return Uint8Array.fromBase64(typeof e == "string" ? e : f.decode(e), {
273
+ alphabet: "base64url"
274
+ });
275
+ let t = e;
276
+ t instanceof Uint8Array && (t = f.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
277
+ try {
278
+ return j(t);
279
+ } catch {
280
+ throw new TypeError("The input to be decoded is not correctly encoded.");
281
+ }
282
+ }
283
+ class N extends Error {
284
+ constructor(n, r) {
285
+ var o;
286
+ super(n, r);
287
+ c(this, "code", "ERR_JOSE_GENERIC");
288
+ this.name = this.constructor.name, (o = Error.captureStackTrace) == null || o.call(Error, this, this.constructor);
289
+ }
290
+ }
291
+ c(N, "code", "ERR_JOSE_GENERIC");
292
+ class u extends N {
293
+ constructor() {
294
+ super(...arguments);
295
+ c(this, "code", "ERR_JWT_INVALID");
296
+ }
297
+ }
298
+ c(u, "code", "ERR_JWT_INVALID");
299
+ function $(e) {
300
+ return typeof e == "object" && e !== null;
301
+ }
302
+ const q = (e) => {
303
+ if (!$(e) || Object.prototype.toString.call(e) !== "[object Object]")
304
+ return !1;
305
+ if (Object.getPrototypeOf(e) === null)
306
+ return !0;
307
+ let t = e;
308
+ for (; Object.getPrototypeOf(t) !== null; )
309
+ t = Object.getPrototypeOf(t);
310
+ return Object.getPrototypeOf(e) === t;
311
+ };
312
+ function K(e) {
313
+ if (typeof e != "string")
314
+ throw new u("JWTs must use Compact JWS serialization, JWT must be a string");
315
+ const { 1: t, length: n } = e.split(".");
316
+ if (n === 5)
317
+ throw new u("Only JWTs using Compact JWS serialization can be decoded");
318
+ if (n !== 3)
319
+ throw new u("Invalid JWT");
320
+ if (!t)
321
+ throw new u("JWTs must contain a payload");
322
+ let r;
323
+ try {
324
+ r = G(t);
325
+ } catch {
326
+ throw new u("Failed to base64url decode the payload");
327
+ }
328
+ let o;
329
+ try {
330
+ o = JSON.parse(f.decode(r));
331
+ } catch {
332
+ throw new u("Failed to parse the decoded payload as JSON");
333
+ }
334
+ if (!q(o))
335
+ throw new u("Invalid JWT Claims Set");
336
+ return o;
337
+ }
338
+ function E(e, t) {
339
+ if (t != null && t.email)
340
+ return `did:email:${t.email}`;
341
+ if (t != null && t.name)
342
+ return `did:name:${encodeURIComponent(t.name.replace(/\s+/g, "-"))}`;
343
+ throw new Error(
344
+ `Unable to generate ${e} ID: missing required ${e} information`
345
+ );
346
+ }
347
+ function H(e) {
348
+ const { nameIdentifier: t, ...n } = e;
349
+ return {
350
+ ...n,
351
+ nameIdentifier: t == null ? void 0 : t.map(({ nameIdentifierType: r, ...o }) => ({
352
+ ...o,
353
+ naturalPersonNameIdentifierType: r
354
+ }))
355
+ };
356
+ }
357
+ function X(e, t) {
358
+ return {
359
+ naturalPerson: e.naturalPerson ? {
360
+ ...e.naturalPerson,
361
+ name: H(e.naturalPerson.name)
362
+ } : void 0,
363
+ legalPerson: e.legalPerson,
364
+ accountNumber: [t]
365
+ };
366
+ }
367
+ const p = [
368
+ {
369
+ addressType: "GEOG",
370
+ addressLine: ["1234 Main Street"],
371
+ townName: "Unknown",
372
+ country: "US"
373
+ }
374
+ ];
375
+ function z(e) {
376
+ const t = e.trim();
377
+ if (!t)
378
+ return { primaryIdentifier: "", secondaryIdentifier: "" };
379
+ const n = t.split(/\s+/), r = n[n.length - 1], o = n.slice(0, -1), i = o.length > 0 ? o.join(" ") : r;
380
+ return { primaryIdentifier: r, secondaryIdentifier: i };
381
+ }
382
+ function Y(e, t, n = ["1234567890"]) {
383
+ const r = t == null ? void 0 : t.map((o) => {
384
+ const i = { ...o };
385
+ return i.naturalPerson && (i.naturalPerson = {
386
+ ...i.naturalPerson,
387
+ geographicAddress: p
388
+ }), i.legalPerson && (i.legalPerson = {
389
+ ...i.legalPerson,
390
+ geographicAddress: p
391
+ }), i;
392
+ });
393
+ return e === "originator" ? { originatorPersons: r, accountNumber: n } : { beneficiaryPersons: r, accountNumber: n };
394
+ }
395
+ function Q(e, t = "John Doe") {
396
+ const { primaryIdentifier: n, secondaryIdentifier: r } = z(t), o = {
397
+ naturalPerson: {
398
+ name: [
399
+ {
400
+ nameIdentifier: [
401
+ {
402
+ primaryIdentifier: n,
403
+ ...r ? { secondaryIdentifier: r } : {},
404
+ nameIdentifierType: "LEGL"
405
+ }
406
+ ]
407
+ }
408
+ ],
409
+ geographicAddress: p
410
+ }
411
+ };
412
+ return e === "originator" ? { originatorPersons: [o], accountNumber: ["1234567890"] } : { beneficiaryPersons: [o], accountNumber: ["1234567890"] };
413
+ }
414
+ const Z = (e) => ({
415
+ ...e,
416
+ // @ts-expect-error Preserving the original logic
417
+ name: e.name ? [e.name] : void 0
418
+ }), ee = (e) => ({
419
+ ...e,
420
+ naturalPerson: e.naturalPerson ? Z(e.naturalPerson) : void 0
421
+ }), te = ({ beneficiary: e, originator: t }, n, r, o, i) => {
422
+ var s;
423
+ {
424
+ const a = e && {
425
+ ...e,
426
+ ...o && { accountNumber: [o] },
427
+ beneficiaryPersons: (s = e.beneficiaryPersons) == null ? void 0 : s.map(ee)
428
+ };
429
+ if (r && (a != null && a.beneficiaryPersons)) {
430
+ const d = Y(
431
+ "originator",
432
+ a == null ? void 0 : a.beneficiaryPersons
433
+ );
434
+ return {
435
+ beneficiary: {
436
+ accountNumber: d.accountNumber,
437
+ beneficiaryPersons: d.originatorPersons
438
+ },
439
+ originator: d
440
+ };
441
+ }
442
+ return {
443
+ beneficiary: a,
444
+ originator: Q("originator", n)
445
+ };
446
+ }
447
+ };
448
+ function ne(e, t, n) {
449
+ var i, s;
450
+ const { beneficiary: r, originator: o } = te(
451
+ n,
452
+ (i = e.customer) == null ? void 0 : i.name,
453
+ t.originatorEqualsBeneficiary,
454
+ e.destination
455
+ );
456
+ return {
457
+ transactionAsset: t.transactionAsset,
458
+ transactionAmount: t.transactionAmount,
459
+ beneficiaryDid: (s = e.counterparty) == null ? void 0 : s.did,
460
+ originatorVASPdid: t.originatorVASPdid,
461
+ ...t.beneficiaryVASPdid && !t.beneficiaryProof ? { beneficiaryVASPdid: t.beneficiaryVASPdid } : {},
462
+ transactionBlockchainInfo: {
463
+ ...(o == null ? void 0 : o.accountNumber) && { origin: o.accountNumber[0] },
464
+ ...e.destination && { destination: e.destination }
465
+ },
466
+ ...t.beneficiaryProof && {
467
+ beneficiaryProof: t.beneficiaryProof
468
+ },
469
+ ...r && { beneficiary: r },
470
+ ...o && { originator: o },
471
+ ...t.originatorEqualsBeneficiary && {
472
+ originatorEqualsBeneficiary: t.originatorEqualsBeneficiary
473
+ }
474
+ };
475
+ }
476
+ function w(e, t, n = {}) {
477
+ var a, d;
478
+ const r = (n == null ? void 0 : n.originatorId) || E("originator", e.customer), o = (n == null ? void 0 : n.beneficiaryId) || E("beneficiary", e.counterparty), i = (n == null ? void 0 : n.referenceId) || Math.random().toString(36).substring(2, 15), s = [];
479
+ return t.originatorVASPdid && s.push({
480
+ "@id": t.originatorVASPdid,
481
+ for: r,
482
+ role: "VASP"
483
+ }), t.beneficiaryVASPdid && s.push({
484
+ "@id": t.beneficiaryVASPdid,
485
+ for: o,
486
+ role: "VASP"
487
+ }), e.destination && ((a = e == null ? void 0 : e.account) != null && a.did) && s.push({
488
+ "@id": e.account.did,
489
+ for: t.beneficiaryVASPdid || o,
490
+ role: "SettlementAddress"
491
+ }), {
492
+ originator: { "@id": r },
493
+ beneficiary: { "@id": o },
494
+ asset: e.asset,
495
+ amount: ((d = e.amountDecimal) == null ? void 0 : d.toString()) || t.transactionAmount,
496
+ agents: s,
497
+ ref: i
498
+ };
499
+ }
500
+ function L(e, t, n = {}) {
501
+ var i, s, a;
502
+ const r = n.beneficiaryId || E("beneficiary", e.counterparty), o = (
503
+ // If counterparty type is SELF, reuse originator data for beneficiary
504
+ ((i = e.counterparty) == null ? void 0 : i.type) === g.SELF && n.originator ? n.originator.originatorPerson : (
505
+ // Convert all beneficiary persons from V1 to V2 format
506
+ ((a = (s = t.beneficiary) == null ? void 0 : s.beneficiaryPersons) == null ? void 0 : a.map(
507
+ (d) => X(d, r)
508
+ )) || []
509
+ )
510
+ );
511
+ return {
512
+ ivms101: {
513
+ originator: n.originator,
514
+ beneficiary: {
515
+ beneficiaryPerson: o
516
+ }
517
+ }
518
+ };
519
+ }
520
+ function b(e, t, n) {
521
+ var o;
522
+ const r = { ...e };
523
+ if (!r.originatorId)
524
+ try {
525
+ const i = K(t);
526
+ i != null && i.sub && (r.originatorId = i.sub);
527
+ } catch {
528
+ }
529
+ return r.beneficiaryId || (((o = n.counterparty) == null ? void 0 : o.type) === g.SELF ? r.beneficiaryId = r.originatorId : n.destination && (r.beneficiaryId = `did:key:${n.destination}`)), r;
530
+ }
531
+ function ie(e) {
532
+ var s;
533
+ if (!e.txCreate || !e.ivms101)
534
+ throw new Error(
535
+ "Invalid response: missing required txCreate or ivms101 data"
536
+ );
537
+ const { value: t, ivms101: n, proof: r, txCreate: o } = e, i = {
538
+ destination: (t == null ? void 0 : t.destination) || "",
539
+ counterparty: (t == null ? void 0 : t.counterparty) || {},
540
+ agent: t == null ? void 0 : t.agent,
541
+ account: t == null ? void 0 : t.account,
542
+ proof: r,
543
+ asset: (t == null ? void 0 : t.asset) || (typeof o.transactionAsset == "string" ? o.transactionAsset : (s = o.transactionAsset) == null ? void 0 : s.caip19) || "",
544
+ amountDecimal: (t == null ? void 0 : t.amountDecimal) || (o.transactionAmount ? parseFloat(o.transactionAmount) : 0),
545
+ customer: t == null ? void 0 : t.customer
546
+ };
547
+ return ne(i, o, n);
548
+ }
549
+ function se(e, t, n = {}) {
550
+ if (!e.txCreate || !e.ivms101)
551
+ throw new Error(
552
+ "Invalid response: missing required txCreate or ivms101 data"
553
+ );
554
+ const { value: r, txCreate: o, ivms101: i, proof: s } = e, a = b(n, t, r);
555
+ return {
556
+ createTx: w(r, o, a),
557
+ ivms101: L(r, i, a),
558
+ ...s && { confirmRelationship: { proof: s } }
559
+ };
560
+ }
561
+ function ae(e, t, n = {}) {
562
+ if (!e.txCreate || !e.ivms101)
563
+ throw new Error(
564
+ "Invalid response: missing required txCreate or ivms101 data"
565
+ );
566
+ const { value: r, txCreate: o } = e, i = b(n, t, r);
567
+ return w(r, o, i);
568
+ }
569
+ function ce(e, t, n = {}) {
570
+ if (!e.ivms101)
571
+ throw new Error("Invalid response: missing required ivms101 data");
572
+ const { value: r, ivms101: o } = e, i = b(n, t, r);
573
+ return L(r, o, i);
574
+ }
575
+ async function I(e, t) {
576
+ const n = JSON.stringify(e), r = new TextEncoder(), o = t ? A(t) : crypto.getRandomValues(new Uint8Array(32)), i = await crypto.subtle.importKey(
262
577
  "raw",
263
- r,
578
+ o,
264
579
  { name: "AES-GCM" },
265
580
  !1,
266
581
  ["encrypt"]
267
- ), a = crypto.getRandomValues(new Uint8Array(12)), c = await crypto.subtle.encrypt(
268
- { name: "AES-GCM", iv: a },
582
+ ), s = crypto.getRandomValues(new Uint8Array(12)), a = await crypto.subtle.encrypt(
583
+ { name: "AES-GCM", iv: s },
269
584
  i,
270
- s.encode(n)
585
+ r.encode(n)
271
586
  );
272
587
  return {
273
- ciphertext: `${E(a)}-${E(c)}`,
274
- key: E(r)
588
+ ciphertext: `${m(s)}-${m(a)}`,
589
+ key: m(o)
275
590
  };
276
591
  }
277
- async function A({ ciphertext: e, key: t }) {
278
- const [n, s] = e.split("-"), r = new Uint8Array(
279
- atob(t).split("").map((w) => w.charCodeAt(0))
280
- ), i = u(n), a = u(s), c = await crypto.subtle.importKey(
592
+ async function P({ ciphertext: e, key: t }) {
593
+ const [n, r] = e.split("-"), o = new Uint8Array(
594
+ atob(t).split("").map((v) => v.charCodeAt(0))
595
+ ), i = A(n), s = A(r), a = await crypto.subtle.importKey(
281
596
  "raw",
282
- r,
597
+ o,
283
598
  { name: "AES-GCM" },
284
599
  !1,
285
600
  ["decrypt"]
286
- ), h = new TextDecoder(), d = await crypto.subtle.decrypt(
601
+ ), d = new TextDecoder(), h = await crypto.subtle.decrypt(
287
602
  { name: "AES-GCM", iv: new Uint8Array(i) },
288
- c,
289
- a
603
+ a,
604
+ s
290
605
  );
291
- return JSON.parse(h.decode(d));
606
+ return JSON.parse(d.decode(h));
292
607
  }
293
- function E(e) {
608
+ function m(e) {
294
609
  const t = new Uint8Array(e);
295
610
  let n = "";
296
- for (let s = 0; s < t.length; s++)
297
- n += String.fromCharCode(t[s]);
611
+ for (let r = 0; r < t.length; r++)
612
+ n += String.fromCharCode(t[r]);
298
613
  return btoa(n);
299
614
  }
300
- function u(e) {
615
+ function A(e) {
301
616
  const t = atob(e), n = new Uint8Array(t.length);
302
- for (let s = 0; s < t.length; s++)
303
- n[s] = t.charCodeAt(s);
617
+ for (let r = 0; r < t.length; r++)
618
+ n[r] = t.charCodeAt(r);
304
619
  return n;
305
620
  }
306
- async function k(e) {
621
+ async function de(e) {
307
622
  const t = await fetch(e.url, {
308
623
  method: "GET"
309
624
  });
@@ -312,28 +627,28 @@ async function k(e) {
312
627
  const n = await t.json();
313
628
  if (!n.id || !n.metadata || !n.status || !n.sealed)
314
629
  throw new Error("Data missing from server response");
315
- const s = {
630
+ const r = {
316
631
  id: n.id,
317
632
  metadata: n.metadata,
318
633
  status: n.status
319
634
  };
320
635
  if (n.status === "closed")
321
- return s;
322
- const r = n.sealed[n.sealed.length - 1], i = await A({
323
- ciphertext: r,
636
+ return r;
637
+ const o = n.sealed[n.sealed.length - 1], i = await P({
638
+ ciphertext: o,
324
639
  key: e.key
325
640
  });
326
641
  return n.status === "completed" ? {
327
- ...s,
642
+ ...r,
328
643
  result: i.result
329
644
  } : {
330
- ...s,
645
+ ...r,
331
646
  tx: i.tx
332
647
  };
333
648
  }
334
- class P {
649
+ class le {
335
650
  constructor(t) {
336
- o(this, "endpoint");
651
+ c(this, "endpoint");
337
652
  this.endpoint = t;
338
653
  }
339
654
  /**
@@ -344,26 +659,26 @@ class P {
344
659
  * @returns Promise resolving to connection details including ID, version, and encryption key
345
660
  */
346
661
  async create(t, n) {
347
- const s = await m(t), r = {
662
+ const r = await I(t), o = {
348
663
  metadata: n,
349
- sealed: s.ciphertext
664
+ sealed: r.ciphertext
350
665
  }, i = await fetch(this.endpoint, {
351
666
  method: "POST",
352
667
  headers: {
353
668
  "Content-Type": "application/json"
354
669
  },
355
- body: JSON.stringify(r)
670
+ body: JSON.stringify(o)
356
671
  });
357
672
  if (!i.ok)
358
673
  throw new Error(`Failed to create connection: ${await i.text()}`);
359
- const a = await i.json();
674
+ const s = await i.json();
360
675
  return {
361
- id: a.id,
362
- version: a.version,
363
- status: a.status,
676
+ id: s.id,
677
+ version: s.version,
678
+ status: s.status,
364
679
  metadata: n,
365
680
  data: t,
366
- key: s.key
681
+ key: r.key
367
682
  };
368
683
  }
369
684
  /**
@@ -376,28 +691,28 @@ class P {
376
691
  * @param key Current encryption key
377
692
  * @returns Promise resolving to updated connection details including new encryption key
378
693
  */
379
- async update(t, n, s, r, i) {
380
- const a = await m(n, i), c = {
381
- sealed: a.ciphertext,
382
- version: s,
383
- status: r
384
- }, h = await fetch(`${this.endpoint}/${t}`, {
694
+ async update(t, n, r, o, i) {
695
+ const s = await I(n, i), a = {
696
+ sealed: s.ciphertext,
697
+ version: r,
698
+ status: o
699
+ }, d = await fetch(`${this.endpoint}/${t}`, {
385
700
  method: "PATCH",
386
701
  headers: {
387
702
  "Content-Type": "application/json"
388
703
  },
389
- body: JSON.stringify(c)
704
+ body: JSON.stringify(a)
390
705
  });
391
- if (!h.ok)
392
- throw new Error(`Failed to update connection: ${await h.text()}`);
393
- const d = await h.json();
706
+ if (!d.ok)
707
+ throw new Error(`Failed to update connection: ${await d.text()}`);
708
+ const h = await d.json();
394
709
  return {
395
- id: d.id,
396
- metadata: d.metadata,
397
- version: d.version,
398
- status: d.status,
710
+ id: h.id,
711
+ metadata: h.metadata,
712
+ version: h.version,
713
+ status: h.status,
399
714
  data: n,
400
- key: a.key
715
+ key: s.key
401
716
  };
402
717
  }
403
718
  /**
@@ -408,21 +723,21 @@ class P {
408
723
  * @returns Promise resolving to connection details including decrypted data
409
724
  */
410
725
  async get(t, n) {
411
- const s = await fetch(`${this.endpoint}/${t}`, {
726
+ const r = await fetch(`${this.endpoint}/${t}`, {
412
727
  method: "GET"
413
728
  });
414
- if (!s.ok)
415
- throw new Error(`Failed to get connection: ${await s.text()}`);
416
- const r = await s.json(), i = r.sealed[r.sealed.length - 1], a = await A({
729
+ if (!r.ok)
730
+ throw new Error(`Failed to get connection: ${await r.text()}`);
731
+ const o = await r.json(), i = o.sealed[o.sealed.length - 1], s = await P({
417
732
  ciphertext: i,
418
733
  key: n
419
734
  });
420
735
  return {
421
- id: r.id,
422
- status: r.status,
423
- version: r.version,
424
- metadata: r.metadata,
425
- data: a,
736
+ id: o.id,
737
+ status: o.status,
738
+ version: o.version,
739
+ metadata: o.metadata,
740
+ data: s,
426
741
  key: n
427
742
  };
428
743
  }
@@ -439,18 +754,18 @@ class P {
439
754
  throw new Error(`Failed to close connection: ${await n.text()}`);
440
755
  }
441
756
  }
442
- class F {
757
+ class ue {
443
758
  /**
444
759
  * Creates a new instance of the Notabene SDK
445
760
  *
446
761
  * @param config - Configuration options for the Notabene SDK
447
762
  */
448
763
  constructor(t) {
449
- o(this, "nodeUrl");
450
- o(this, "authToken");
451
- o(this, "uxUrl");
452
- o(this, "theme");
453
- o(this, "locale");
764
+ c(this, "nodeUrl");
765
+ c(this, "authToken");
766
+ c(this, "uxUrl");
767
+ c(this, "theme");
768
+ c(this, "locale");
454
769
  this.uxUrl = t.uxUrl || "https://connect.notabene.id", this.nodeUrl = t.nodeUrl, this.authToken = t.authToken, this.theme = t.theme, this.locale = t.locale;
455
770
  }
456
771
  /**
@@ -463,15 +778,15 @@ class F {
463
778
  * @returns component URL
464
779
  * @internal
465
780
  */
466
- componentUrl(t, n, s, r) {
781
+ componentUrl(t, n, r, o) {
467
782
  const i = new URL(this.uxUrl);
468
783
  i.pathname = t;
469
- const a = T({
784
+ const s = F({
470
785
  authToken: this.authToken,
471
786
  value: n,
472
- configuration: s
787
+ configuration: r
473
788
  });
474
- 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), r && (r.callback && i.searchParams.set("callback_url", r.callback), r.redirectUri && i.searchParams.set("redirect_uri", r.redirectUri)), i.toString();
789
+ return i.hash = s, 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();
475
790
  }
476
791
  /**
477
792
  * Creates a new embedded component
@@ -483,11 +798,11 @@ class F {
483
798
  * @returns A new EmbeddedComponent instance
484
799
  * @internal
485
800
  */
486
- createComponent(t, n, s, r) {
487
- return new S(
488
- this.componentUrl(t, n, s, r),
801
+ createComponent(t, n, r, o) {
802
+ return new J(
803
+ this.componentUrl(t, n, r, o),
489
804
  n,
490
- s
805
+ r
491
806
  );
492
807
  }
493
808
  /**
@@ -498,12 +813,12 @@ class F {
498
813
  * @param callbacks - Optional callback configuration
499
814
  * @returns A new EmbeddedComponent instance for withdrawal assistance
500
815
  */
501
- createWithdrawalAssist(t, n, s) {
816
+ createWithdrawalAssist(t, n, r) {
502
817
  return this.createComponent(
503
818
  "withdrawal-assist",
504
819
  t,
505
820
  n,
506
- s
821
+ r
507
822
  );
508
823
  }
509
824
  /**
@@ -515,12 +830,12 @@ class F {
515
830
  * @returns A new EmbeddedComponent instance for connection
516
831
  * @alpha
517
832
  */
518
- createConnectWallet(t, n, s) {
833
+ createConnectWallet(t, n, r) {
519
834
  return this.createComponent(
520
835
  "connect",
521
836
  t,
522
837
  n,
523
- s
838
+ r
524
839
  );
525
840
  }
526
841
  /**
@@ -532,12 +847,12 @@ class F {
532
847
  * @returns A new EmbeddedComponent instance for deposit requests
533
848
  * @public
534
849
  */
535
- createDepositRequest(t, n, s) {
850
+ createDepositRequest(t, n, r) {
536
851
  return this.createComponent(
537
852
  "deposit-request",
538
853
  t,
539
854
  n,
540
- s
855
+ r
541
856
  );
542
857
  }
543
858
  /**
@@ -549,33 +864,37 @@ class F {
549
864
  * @returns A new EmbeddedComponent instance for deposit assistance
550
865
  * @public
551
866
  */
552
- createDepositAssist(t, n, s) {
867
+ createDepositAssist(t, n, r) {
553
868
  return this.createComponent(
554
869
  "deposit-assist",
555
870
  t,
556
871
  n,
557
- s
872
+ r
558
873
  );
559
874
  }
560
875
  }
561
876
  export {
562
- N as AgentType,
877
+ S as AgentType,
563
878
  l as CMType,
564
879
  D as CodeVerificationStatus,
565
- P as ConnectionManager,
566
- S as EmbeddedComponent,
567
- C as ErrorIdentifierCode,
568
- p as HMType,
569
- g as IdentityVerificationMethod,
880
+ le as ConnectionManager,
881
+ J as EmbeddedComponent,
882
+ M as ErrorIdentifierCode,
883
+ y as HMType,
884
+ T as IdentityVerificationMethod,
570
885
  U as OAuthProvider,
571
- v as PersonType,
572
- b as ProofStatus,
573
- y as ProofTypes,
574
- I as Status,
575
- _ as VASPSearchControl,
576
- R as ValidationSections,
577
- O as WarningIdentifierCode,
578
- B as decodeFragmentToObject,
579
- F as default,
580
- k as getRefreshResult
886
+ g as PersonType,
887
+ B as ProofStatus,
888
+ W as ProofTypes,
889
+ _ as Status,
890
+ O as VASPSearchControl,
891
+ x as ValidationSections,
892
+ V as WarningIdentifierCode,
893
+ ce as componentResponseToIVMS101,
894
+ ae as componentResponseToTxCreateRequest,
895
+ se as componentResponseToTxRequests,
896
+ ie as componentResponseToV1TxCreateRequest,
897
+ oe as decodeFragmentToObject,
898
+ ue as default,
899
+ de as getRefreshResult
581
900
  };