@notabene/javascript-sdk 2.9.0-next.2 → 2.9.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.
Files changed (135) hide show
  1. package/dist/cjs/notabene.cjs +1 -1
  2. package/dist/cjs/notabene.d.ts +32 -2
  3. package/dist/cjs/package.json +1 -1
  4. package/dist/esm/notabene.d.ts +32 -2
  5. package/dist/esm/notabene.js +86 -79
  6. package/dist/esm/package.json +1 -1
  7. package/dist/notabene.d.ts +32 -2
  8. package/dist/notabene.js +86 -79
  9. package/docs/README.md +12 -3
  10. package/docs/_media/TransactionOptions.md +16 -6
  11. package/docs/ivms/types/enumerations/PayloadVersionCode.md +2 -2
  12. package/docs/ivms/types/interfaces/PayloadMetadata.md +2 -2
  13. package/docs/ivms/types/type-aliases/Address.md +1 -1
  14. package/docs/ivms/types/type-aliases/AddressTypeCode.md +1 -1
  15. package/docs/ivms/types/type-aliases/Beneficiary.md +1 -1
  16. package/docs/ivms/types/type-aliases/BeneficiaryVASP.md +1 -1
  17. package/docs/ivms/types/type-aliases/DateAndPlaceOfBirth.md +1 -1
  18. package/docs/ivms/types/type-aliases/ISOCountryCode.md +1 -1
  19. package/docs/ivms/types/type-aliases/ISODate.md +1 -1
  20. package/docs/ivms/types/type-aliases/IVMS101.md +1 -1
  21. package/docs/ivms/types/type-aliases/IntermediaryVASP.md +1 -1
  22. package/docs/ivms/types/type-aliases/LegalPerson.md +1 -1
  23. package/docs/ivms/types/type-aliases/LegalPersonName.md +1 -1
  24. package/docs/ivms/types/type-aliases/LegalPersonNameID.md +1 -1
  25. package/docs/ivms/types/type-aliases/LegalPersonNameTypeCode.md +1 -1
  26. package/docs/ivms/types/type-aliases/LocalLegalPersonNameID.md +1 -1
  27. package/docs/ivms/types/type-aliases/LocalNaturalPersonNameID.md +1 -1
  28. package/docs/ivms/types/type-aliases/NationalIdentification.md +1 -1
  29. package/docs/ivms/types/type-aliases/NationalIdentifierTypeCode.md +1 -1
  30. package/docs/ivms/types/type-aliases/NaturalPerson.md +1 -1
  31. package/docs/ivms/types/type-aliases/NaturalPersonName.md +1 -1
  32. package/docs/ivms/types/type-aliases/NaturalPersonNameID.md +1 -1
  33. package/docs/ivms/types/type-aliases/NaturalPersonNameTypeCode.md +1 -1
  34. package/docs/ivms/types/type-aliases/OriginatingVASP.md +1 -1
  35. package/docs/ivms/types/type-aliases/Originator.md +1 -1
  36. package/docs/ivms/types/type-aliases/Person.md +1 -1
  37. package/docs/ivms/types/type-aliases/TransferPath.md +1 -1
  38. package/docs/ivms/types/type-aliases/TransliterationMethodCode.md +1 -1
  39. package/docs/notabene/README.md +15 -0
  40. package/docs/notabene/classes/ConnectionManager.md +14 -6
  41. package/docs/notabene/classes/EmbeddedComponent.md +17 -17
  42. package/docs/notabene/classes/default.md +7 -7
  43. package/docs/notabene/functions/decodeFragmentToObject.md +1 -1
  44. package/docs/notabene/functions/getRefreshResult.md +27 -0
  45. package/docs/notabene/interfaces/ConnectionData.md +13 -3
  46. package/docs/notabene/interfaces/ConnectionMetadata.md +3 -3
  47. package/docs/notabene/interfaces/ConnectionResponse.md +15 -5
  48. package/docs/notabene/interfaces/ConnectionResult.md +61 -0
  49. package/docs/notabene/interfaces/NotabeneConfig.md +5 -5
  50. package/docs/notabene/type-aliases/ConnectionStatus.md +13 -0
  51. package/docs/notabene/type-aliases/MessageCallback.md +1 -1
  52. package/docs/notabene/type-aliases/TransactionType.md +1 -1
  53. package/docs/types/README.md +1 -0
  54. package/docs/types/enumerations/AgentType.md +2 -2
  55. package/docs/types/enumerations/CMType.md +7 -7
  56. package/docs/types/enumerations/ErrorIdentifierCode.md +4 -4
  57. package/docs/types/enumerations/HMType.md +2 -2
  58. package/docs/types/enumerations/PersonType.md +3 -3
  59. package/docs/types/enumerations/ProofStatus.md +4 -4
  60. package/docs/types/enumerations/ProofTypes.md +17 -17
  61. package/docs/types/enumerations/Status.md +5 -5
  62. package/docs/types/enumerations/VASPSearchControl.md +2 -2
  63. package/docs/types/enumerations/ValidationSections.md +4 -4
  64. package/docs/types/interfaces/Agent.md +6 -6
  65. package/docs/types/interfaces/CallbackOptions.md +2 -2
  66. package/docs/types/interfaces/ComponentRequest.md +2 -2
  67. package/docs/types/interfaces/ComponentResponse.md +4 -4
  68. package/docs/types/interfaces/ConnectionRecord.md +7 -7
  69. package/docs/types/interfaces/ConnectionRequest.md +3 -3
  70. package/docs/types/interfaces/Counterparty.md +10 -10
  71. package/docs/types/interfaces/DeclarationProof.md +6 -6
  72. package/docs/types/interfaces/Deposit.md +11 -11
  73. package/docs/types/interfaces/DepositRequest.md +7 -7
  74. package/docs/types/interfaces/DepositRequestOptions.md +1 -1
  75. package/docs/types/interfaces/DepositTransaction.md +9 -9
  76. package/docs/types/interfaces/LegalPerson.md +13 -13
  77. package/docs/types/interfaces/MicroTransferProof.md +9 -9
  78. package/docs/types/interfaces/NaturalPerson.md +13 -13
  79. package/docs/types/interfaces/OwnershipProof.md +4 -4
  80. package/docs/types/interfaces/RefreshSource.md +2 -2
  81. package/docs/types/interfaces/Refreshable.md +1 -1
  82. package/docs/types/interfaces/ScreenshotProof.md +5 -5
  83. package/docs/types/interfaces/SignatureProof.md +9 -9
  84. package/docs/types/interfaces/ThresholdOptions.md +3 -3
  85. package/docs/types/interfaces/Transaction.md +8 -8
  86. package/docs/types/interfaces/TransactionOptions.md +16 -6
  87. package/docs/types/interfaces/TransactionResponse.md +9 -9
  88. package/docs/types/interfaces/VASP.md +9 -9
  89. package/docs/types/interfaces/Wallet.md +8 -8
  90. package/docs/types/interfaces/Withdrawal.md +10 -10
  91. package/docs/types/type-aliases/BlockchainAddress.md +1 -1
  92. package/docs/types/type-aliases/CAIP10.md +1 -1
  93. package/docs/types/type-aliases/CAIP19.md +1 -1
  94. package/docs/types/type-aliases/CAIP2.md +1 -1
  95. package/docs/types/type-aliases/CAIP220.md +1 -1
  96. package/docs/types/type-aliases/Cancel.md +1 -1
  97. package/docs/types/type-aliases/Completed.md +1 -1
  98. package/docs/types/type-aliases/ComponentMessage.md +1 -1
  99. package/docs/types/type-aliases/ConnectionOptions.md +1 -1
  100. package/docs/types/type-aliases/CounterpartyAssistConfig.md +19 -0
  101. package/docs/types/type-aliases/CryptoCredential.md +1 -1
  102. package/docs/types/type-aliases/DID.md +1 -1
  103. package/docs/types/type-aliases/DTI.md +1 -1
  104. package/docs/types/type-aliases/Destination.md +1 -1
  105. package/docs/types/type-aliases/Error.md +1 -1
  106. package/docs/types/type-aliases/FieldOptions.md +1 -1
  107. package/docs/types/type-aliases/FieldTypes.md +1 -1
  108. package/docs/types/type-aliases/HostMessage.md +1 -1
  109. package/docs/types/type-aliases/ISOCurrency.md +1 -1
  110. package/docs/types/type-aliases/InvalidValue.md +1 -1
  111. package/docs/types/type-aliases/LEI.md +1 -1
  112. package/docs/types/type-aliases/LegalPersonFieldName.md +1 -1
  113. package/docs/types/type-aliases/LegalPersonFields.md +1 -1
  114. package/docs/types/type-aliases/NationalIdentifierTypeFieldOptions.md +1 -1
  115. package/docs/types/type-aliases/NaturalPersonFieldName.md +1 -1
  116. package/docs/types/type-aliases/NaturalPersonFields.md +1 -1
  117. package/docs/types/type-aliases/NotabeneAsset.md +1 -1
  118. package/docs/types/type-aliases/Ready.md +1 -1
  119. package/docs/types/type-aliases/ResizeRequest.md +1 -1
  120. package/docs/types/type-aliases/Source.md +1 -1
  121. package/docs/types/type-aliases/Theme.md +1 -1
  122. package/docs/types/type-aliases/TransactionAsset.md +1 -1
  123. package/docs/types/type-aliases/TravelAddress.md +1 -1
  124. package/docs/types/type-aliases/URI.md +1 -1
  125. package/docs/types/type-aliases/UUID.md +1 -1
  126. package/docs/types/type-aliases/UpdateValue.md +1 -1
  127. package/docs/types/type-aliases/V1Asset.md +1 -1
  128. package/docs/types/type-aliases/V1Transaction.md +1 -1
  129. package/docs/types/type-aliases/VASPOptions.md +1 -1
  130. package/docs/types/type-aliases/ValidationError.md +1 -1
  131. package/package.json +1 -1
  132. package/src/notabene.ts +4 -0
  133. package/src/types.ts +33 -1
  134. package/src/utils/__tests__/connections.test.ts +160 -24
  135. package/src/utils/connections.ts +21 -7
@@ -1 +1 @@
1
- "use strict";var U=Object.defineProperty;var _=(t,e,n)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>_(t,typeof e!="symbol"?e+"":e,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var f=(t=>(t.PRIVATE="WALLET",t.VASP="VASP",t))(f||{}),w=(t=>(t.NATURAL="natural",t.LEGAL="legal",t.SELF="self",t))(w||{}),g=(t=>(t.EMPTY="empty",t.VERIFY="verify",t.PENDING="pending",t.VERIFIED="verified",t.BANNED="banned",t))(g||{}),v=(t=>(t.ALLOWED="allowed",t.PENDING="pending",t))(v||{}),y=(t=>(t.ASSET="asset",t.DESTINATION="destination",t.COUNTERPARTY="counterparty",t.AGENT="agent",t))(y||{}),l=(t=>(t.COMPLETE="complete",t.RESIZE="resize",t.RESULT="result",t.READY="ready",t.INVALID="invalid",t.ERROR="error",t.CANCEL="cancel",t))(l||{}),A=(t=>(t.SERVICE_UNAVAILABLE="SERVICE_UNAVAILABLE",t.WALLET_CONNECTION_FAILED="WALLET_CONNECTION_FAILED",t.WALLET_NOT_SUPPORTED="WALLET_NOT_SUPPORTED",t.TOKEN_INVALID="TOKEN_INVALID",t))(A||{}),p=(t=>(t.UPDATE="update",t.REQUEST_RESPONSE="requestResponse",t))(p||{}),C=(t=>(t.PENDING="pending",t.FAILED="rejected",t.FLAGGED="flagged",t.VERIFIED="verified",t))(C||{}),b=(t=>(t.SelfDeclaration="self-declaration",t.SIWE="siwe",t.SIWX="siwx",t.EIP191="eip-191",t.EIP712="eip-712",t.EIP1271="eip-1271",t.BIP137="bip-137",t.BIP322="bip-322",t.BIP137_XPUB="xpub",t.TIP191="tip-191",t.ED25519="ed25519",t.XRP_ED25519="xrp-ed25519",t.XLM_ED25519="xlm-ed25519",t.CIP8="cip-8",t.MicroTransfer="microtransfer",t.Screenshot="screenshot",t.Connect="connect",t))(b||{});class R{constructor(){a(this,"listeners",new Map);a(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(e){this.port=e,this.port.onmessage=this.handleMessage,this.port.start()}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>this.off(e,n)}off(e,n){const r=this.listeners.get(e);r&&(r.delete(n),r.size===0&&this.listeners.delete(e))}handleMessage(e){const n=e.data;if(typeof n=="object"&&n!==null&&"type"in n){const r=n.type,s=this.listeners.get(r);s&&s.forEach(o=>o(n))}}send(e){this.port&&this.port.postMessage(e)}}class I{constructor(e,n,r){a(this,"_url");a(this,"_value");a(this,"_options");a(this,"_errors",[]);a(this,"iframe");a(this,"eventManager");a(this,"modal");this._url=e,this._value=n,this._options=r,this.eventManager=new R,this.on(l.INVALID,s=>{s.type===l.INVALID&&(this._errors=s.errors,this._value=s.value)}),this.on(l.RESIZE,s=>{s.type===l.RESIZE&&this.iframe&&(this.iframe.style.height=`${s.height}px`)})}get url(){return this._url}get value(){return this._value}get options(){return this._options}get errors(){return this._errors}open(){document.location.href=this.url}mount(e){const n=document.querySelector(e);if(!n)throw new Error(`parentID ${e} not found`);this.embed(n)}embed(e,n=!1){var r,s;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",e.appendChild(this.iframe),window.addEventListener("message",o=>{var i,c;o.source===((i=this.iframe)==null?void 0:i.contentWindow)&&((c=this.eventManager)==null||c.setPort(o.ports[0]))}),(s=(r=this.iframe)==null?void 0:r.contentWindow)==null||s.focus()}removeEmbed(){this.iframe&&this.iframe.remove()}send(e){this.eventManager.send(e)}on(e,n){return this.eventManager.on(e,n)}off(e,n){this.eventManager.off(e,n)}update(e,n){this._value=e,n&&(this._options=n),this.send({type:p.UPDATE,value:e,options:this._options})}completion(){return new Promise((e,n)=>{let r,s,o;function i(){r&&r(),s&&s(),o&&o()}r=this.on(l.COMPLETE,c=>{e(c.response),i()}),s=this.on(l.CANCEL,()=>{n(new Error("User cancelled")),i()}),o=this.on("error",c=>{n(new Error(c.message)),i()})})}async openModal(){this.modal&&this.closeModal(),this.modal=document.createElement("dialog"),this.modal.style.border="none",this.modal.style.backgroundColor="white",this.modal.style.maxWidth="100vw",this.modal.style.maxHeight="100vh",this.modal.style.width="600px",this.modal.style.height="600px",document.body.appendChild(this.modal),this.embed(this.modal,!0);const e=this.on(l.CANCEL,()=>{this.closeModal()}),n=this.on(l.COMPLETE,()=>{this.closeModal()});return this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()}),this.completion().finally(()=>{e(),n()})}closeModal(){var e;this.modal&&((e=this.modal)==null||e.close(),this.modal.remove(),this.modal=void 0)}async popup(){const e=window.open(this.url,"_blank","popup=true,width=600,height=600");window.addEventListener("message",s=>{var o;s.source===e&&(console.log("received message from popup",s.data),(o=this.eventManager)==null||o.setPort(s.ports[0]))});const n=this.on(l.CANCEL,()=>{e==null||e.close()}),r=this.on(l.COMPLETE,()=>{e==null||e.close()});return this.completion().finally(()=>{n(),r()})}}function x(t){return Object.entries(t).map(([e,n])=>{if(n==null)return;const r=encodeURIComponent(e),s=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${s}`}).filter(e=>e!==void 0).join("&")}function S(t){const e=t.slice(1);return e?e.split("&").filter(Boolean).reduce((r,s)=>{const[o,i]=s.split("=");return o&&(r[decodeURIComponent(o)]=i?decodeURIComponent(i):""),r},{}):{}}async function E(t,e){const n=JSON.stringify(t),r=new TextEncoder,s=e?m(e):crypto.getRandomValues(new Uint8Array(32)),o=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["encrypt"]),i=crypto.getRandomValues(new Uint8Array(12)),c=await crypto.subtle.encrypt({name:"AES-GCM",iv:i},o,r.encode(n));return{ciphertext:`${u(i)}-${u(c)}`,key:u(s)}}async function L({ciphertext:t,key:e}){const[n,r]=t.split("-"),s=new Uint8Array(atob(e).split("").map(N=>N.charCodeAt(0))),o=m(n),i=m(r),c=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["decrypt"]),d=new TextDecoder,h=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(o)},c,i);return JSON.parse(d.decode(h))}function u(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++)n+=String.fromCharCode(e[r]);return btoa(n)}function m(t){const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}async function M(t){const e=await fetch(t.url,{method:"GET"});if(!e.ok)throw new Error(`Failed to get connection: ${await e.text()}`);const n=await e.json();if(!n.sealed)throw new Error("No data found");const r=n.sealed[n.sealed.length-1],s=await L({ciphertext:r,key:t.key});return{id:n.id,metadata:n.metadata,status:n.status,tx:s.tx,result:s.result}}class O{constructor(e){a(this,"endpoint");this.endpoint=e}async create(e,n){const r=await E(e),s={metadata:n,sealed:r.ciphertext},o=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok)throw new Error(`Failed to create connection: ${await o.text()}`);const i=await o.json();return{id:i.id,version:i.version,status:i.status,metadata:n,data:e,key:r.key}}async update(e,n,r,s,o){const i=await E(n,o),c={sealed:i.ciphertext,version:r,status:s},d=await fetch(`${this.endpoint}/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok)throw new Error(`Failed to update connection: ${await d.text()}`);const h=await d.json();return{id:h.id,metadata:h.metadata,version:h.version,status:h.status,data:n,key:i.key}}async get(e,n){const r=await fetch(`${this.endpoint}/${e}`,{method:"GET"});if(!r.ok)throw new Error(`Failed to get connection: ${await r.text()}`);const s=await r.json(),o=s.sealed[s.sealed.length-1],i=await L({ciphertext:o,key:n});return{id:s.id,status:s.status,version:s.version,metadata:s.metadata,data:i,key:n}}async close(e){const n=await fetch(`${this.endpoint}/${e}`,{method:"DELETE"});if(!n.ok)throw new Error(`Failed to close connection: ${await n.text()}`)}}class D{constructor(e){a(this,"nodeUrl");a(this,"authToken");a(this,"uxUrl");a(this,"theme");a(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,n,r,s){const o=new URL(this.uxUrl);o.pathname=e;const i=x({authToken:this.authToken,value:n,configuration:r});return o.hash=i,this.nodeUrl&&o.searchParams.set("nodeUrl",this.nodeUrl),this.theme&&o.searchParams.set("theme",JSON.stringify(this.theme)),this.locale&&o.searchParams.set("locale",this.locale),s&&(s.callback&&o.searchParams.set("callback_url",s.callback),s.redirectUri&&o.searchParams.set("redirect_uri",s.redirectUri)),o.toString()}createComponent(e,n,r,s){return new I(this.componentUrl(e,n,r,s),n,r)}createWithdrawalAssist(e,n,r){return this.createComponent("withdrawal-assist",e,n,r)}createConnectWallet(e,n,r){return this.createComponent("connect",e,n,r)}createDepositRequest(e,n,r){return this.createComponent("deposit-request",e,n,r)}createDepositAssist(e,n,r){return this.createComponent("deposit-assist",e,n,r)}}exports.AgentType=f;exports.CMType=l;exports.ConnectionManager=O;exports.EmbeddedComponent=I;exports.ErrorIdentifierCode=A;exports.HMType=p;exports.PersonType=w;exports.ProofStatus=C;exports.ProofTypes=b;exports.Status=g;exports.VASPSearchControl=v;exports.ValidationSections=y;exports.decodeFragmentToObject=S;exports.default=D;exports.getRefreshResult=M;
1
+ "use strict";var U=Object.defineProperty;var _=(t,e,n)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>_(t,typeof e!="symbol"?e+"":e,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var f=(t=>(t.PRIVATE="WALLET",t.VASP="VASP",t))(f||{}),w=(t=>(t.NATURAL="natural",t.LEGAL="legal",t.SELF="self",t))(w||{}),g=(t=>(t.EMPTY="empty",t.VERIFY="verify",t.PENDING="pending",t.VERIFIED="verified",t.BANNED="banned",t))(g||{}),v=(t=>(t.ALLOWED="allowed",t.PENDING="pending",t))(v||{}),y=(t=>(t.ASSET="asset",t.DESTINATION="destination",t.COUNTERPARTY="counterparty",t.AGENT="agent",t))(y||{}),l=(t=>(t.COMPLETE="complete",t.RESIZE="resize",t.RESULT="result",t.READY="ready",t.INVALID="invalid",t.ERROR="error",t.CANCEL="cancel",t))(l||{}),A=(t=>(t.SERVICE_UNAVAILABLE="SERVICE_UNAVAILABLE",t.WALLET_CONNECTION_FAILED="WALLET_CONNECTION_FAILED",t.WALLET_NOT_SUPPORTED="WALLET_NOT_SUPPORTED",t.TOKEN_INVALID="TOKEN_INVALID",t))(A||{}),p=(t=>(t.UPDATE="update",t.REQUEST_RESPONSE="requestResponse",t))(p||{}),C=(t=>(t.PENDING="pending",t.FAILED="rejected",t.FLAGGED="flagged",t.VERIFIED="verified",t))(C||{}),b=(t=>(t.SelfDeclaration="self-declaration",t.SIWE="siwe",t.SIWX="siwx",t.EIP191="eip-191",t.EIP712="eip-712",t.EIP1271="eip-1271",t.BIP137="bip-137",t.BIP322="bip-322",t.BIP137_XPUB="xpub",t.TIP191="tip-191",t.ED25519="ed25519",t.XRP_ED25519="xrp-ed25519",t.XLM_ED25519="xlm-ed25519",t.CIP8="cip-8",t.MicroTransfer="microtransfer",t.Screenshot="screenshot",t.Connect="connect",t))(b||{});class R{constructor(){a(this,"listeners",new Map);a(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(e){this.port=e,this.port.onmessage=this.handleMessage,this.port.start()}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>this.off(e,n)}off(e,n){const r=this.listeners.get(e);r&&(r.delete(n),r.size===0&&this.listeners.delete(e))}handleMessage(e){const n=e.data;if(typeof n=="object"&&n!==null&&"type"in n){const r=n.type,s=this.listeners.get(r);s&&s.forEach(i=>i(n))}}send(e){this.port&&this.port.postMessage(e)}}class I{constructor(e,n,r){a(this,"_url");a(this,"_value");a(this,"_options");a(this,"_errors",[]);a(this,"iframe");a(this,"eventManager");a(this,"modal");this._url=e,this._value=n,this._options=r,this.eventManager=new R,this.on(l.INVALID,s=>{s.type===l.INVALID&&(this._errors=s.errors,this._value=s.value)}),this.on(l.RESIZE,s=>{s.type===l.RESIZE&&this.iframe&&(this.iframe.style.height=`${s.height}px`)})}get url(){return this._url}get value(){return this._value}get options(){return this._options}get errors(){return this._errors}open(){document.location.href=this.url}mount(e){const n=document.querySelector(e);if(!n)throw new Error(`parentID ${e} not found`);this.embed(n)}embed(e,n=!1){var r,s;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",e.appendChild(this.iframe),window.addEventListener("message",i=>{var o,c;i.source===((o=this.iframe)==null?void 0:o.contentWindow)&&((c=this.eventManager)==null||c.setPort(i.ports[0]))}),(s=(r=this.iframe)==null?void 0:r.contentWindow)==null||s.focus()}removeEmbed(){this.iframe&&this.iframe.remove()}send(e){this.eventManager.send(e)}on(e,n){return this.eventManager.on(e,n)}off(e,n){this.eventManager.off(e,n)}update(e,n){this._value=e,n&&(this._options=n),this.send({type:p.UPDATE,value:e,options:this._options})}completion(){return new Promise((e,n)=>{let r,s,i;function o(){r&&r(),s&&s(),i&&i()}r=this.on(l.COMPLETE,c=>{e(c.response),o()}),s=this.on(l.CANCEL,()=>{n(new Error("User cancelled")),o()}),i=this.on("error",c=>{n(new Error(c.message)),o()})})}async openModal(){this.modal&&this.closeModal(),this.modal=document.createElement("dialog"),this.modal.style.border="none",this.modal.style.backgroundColor="white",this.modal.style.maxWidth="100vw",this.modal.style.maxHeight="100vh",this.modal.style.width="600px",this.modal.style.height="600px",document.body.appendChild(this.modal),this.embed(this.modal,!0);const e=this.on(l.CANCEL,()=>{this.closeModal()}),n=this.on(l.COMPLETE,()=>{this.closeModal()});return this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()}),this.completion().finally(()=>{e(),n()})}closeModal(){var e;this.modal&&((e=this.modal)==null||e.close(),this.modal.remove(),this.modal=void 0)}async popup(){const e=window.open(this.url,"_blank","popup=true,width=600,height=600");window.addEventListener("message",s=>{var i;s.source===e&&(console.log("received message from popup",s.data),(i=this.eventManager)==null||i.setPort(s.ports[0]))});const n=this.on(l.CANCEL,()=>{e==null||e.close()}),r=this.on(l.COMPLETE,()=>{e==null||e.close()});return this.completion().finally(()=>{n(),r()})}}function x(t){return Object.entries(t).map(([e,n])=>{if(n==null)return;const r=encodeURIComponent(e),s=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${s}`}).filter(e=>e!==void 0).join("&")}function D(t){const e=t.slice(1);return e?e.split("&").filter(Boolean).reduce((r,s)=>{const[i,o]=s.split("=");return i&&(r[decodeURIComponent(i)]=o?decodeURIComponent(o):""),r},{}):{}}async function E(t,e){const n=JSON.stringify(t),r=new TextEncoder,s=e?m(e):crypto.getRandomValues(new Uint8Array(32)),i=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["encrypt"]),o=crypto.getRandomValues(new Uint8Array(12)),c=await crypto.subtle.encrypt({name:"AES-GCM",iv:o},i,r.encode(n));return{ciphertext:`${u(o)}-${u(c)}`,key:u(s)}}async function L({ciphertext:t,key:e}){const[n,r]=t.split("-"),s=new Uint8Array(atob(e).split("").map(N=>N.charCodeAt(0))),i=m(n),o=m(r),c=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["decrypt"]),d=new TextDecoder,h=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(i)},c,o);return JSON.parse(d.decode(h))}function u(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++)n+=String.fromCharCode(e[r]);return btoa(n)}function m(t){const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}async function S(t){const e=await fetch(t.url,{method:"GET"});if(!e.ok)throw new Error(`Failed to get connection: ${await e.text()}`);const n=await e.json();if(!n.id||!n.metadata||!n.status||!n.sealed)throw new Error("Data missing from server response");const r={id:n.id,metadata:n.metadata,status:n.status};if(n.status==="closed")return r;const s=n.sealed[n.sealed.length-1],i=await L({ciphertext:s,key:t.key});return n.status==="completed"?{...r,result:i.result}:{...r,tx:i.tx}}class M{constructor(e){a(this,"endpoint");this.endpoint=e}async create(e,n){const r=await E(e),s={metadata:n,sealed:r.ciphertext},i=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!i.ok)throw new Error(`Failed to create connection: ${await i.text()}`);const o=await i.json();return{id:o.id,version:o.version,status:o.status,metadata:n,data:e,key:r.key}}async update(e,n,r,s,i){const o=await E(n,i),c={sealed:o.ciphertext,version:r,status:s},d=await fetch(`${this.endpoint}/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok)throw new Error(`Failed to update connection: ${await d.text()}`);const h=await d.json();return{id:h.id,metadata:h.metadata,version:h.version,status:h.status,data:n,key:o.key}}async get(e,n){const r=await fetch(`${this.endpoint}/${e}`,{method:"GET"});if(!r.ok)throw new Error(`Failed to get connection: ${await r.text()}`);const s=await r.json(),i=s.sealed[s.sealed.length-1],o=await L({ciphertext:i,key:n});return{id:s.id,status:s.status,version:s.version,metadata:s.metadata,data:o,key:n}}async close(e){const n=await fetch(`${this.endpoint}/${e}`,{method:"DELETE"});if(!n.ok)throw new Error(`Failed to close connection: ${await n.text()}`)}}class O{constructor(e){a(this,"nodeUrl");a(this,"authToken");a(this,"uxUrl");a(this,"theme");a(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,n,r,s){const i=new URL(this.uxUrl);i.pathname=e;const o=x({authToken:this.authToken,value:n,configuration:r});return i.hash=o,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),s&&(s.callback&&i.searchParams.set("callback_url",s.callback),s.redirectUri&&i.searchParams.set("redirect_uri",s.redirectUri)),i.toString()}createComponent(e,n,r,s){return new I(this.componentUrl(e,n,r,s),n,r)}createWithdrawalAssist(e,n,r){return this.createComponent("withdrawal-assist",e,n,r)}createConnectWallet(e,n,r){return this.createComponent("connect",e,n,r)}createDepositRequest(e,n,r){return this.createComponent("deposit-request",e,n,r)}createDepositAssist(e,n,r){return this.createComponent("deposit-assist",e,n,r)}}exports.AgentType=f;exports.CMType=l;exports.ConnectionManager=M;exports.EmbeddedComponent=I;exports.ErrorIdentifierCode=A;exports.HMType=p;exports.PersonType=w;exports.ProofStatus=C;exports.ProofTypes=b;exports.Status=g;exports.VASPSearchControl=v;exports.ValidationSections=y;exports.decodeFragmentToObject=D;exports.default=O;exports.getRefreshResult=S;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * A blockchain account
3
+ * @public
4
+ */
5
+ export declare interface Account {
6
+ did?: DID;
7
+ blockchainAddress?: BlockchainAddress;
8
+ chain?: CAIP2;
9
+ caip10?: CAIP10;
10
+ identifier?: string;
11
+ }
12
+
1
13
  /**
2
14
  * Address
3
15
  * Represents a physical address
@@ -365,7 +377,7 @@ export declare interface ConnectionResult<T extends ComponentRequest> {
365
377
  id: UUID;
366
378
  metadata: ConnectionMetadata;
367
379
  status: ConnectionStatus;
368
- tx: T;
380
+ tx?: T;
369
381
  result?: TransactionResponse<T>;
370
382
  }
371
383
 
@@ -410,6 +422,22 @@ export declare interface Counterparty {
410
422
  email?: string;
411
423
  }
412
424
 
425
+ /**
426
+ * Counterparty Assist Configuration options for recipient selection
427
+ *
428
+ * @remarks
429
+ * Controls for each person type, whether to show the share feature or not.
430
+ *
431
+ * @public
432
+ */
433
+ export declare type CounterpartyAssistConfig = {
434
+ enabled?: boolean;
435
+ } | {
436
+ [key in PersonType]: {
437
+ enabled?: boolean;
438
+ };
439
+ };
440
+
413
441
  /**
414
442
  * A crypto credential
415
443
  * @public
@@ -467,7 +495,7 @@ export declare interface DepositRequest extends DepositRequestFields, ComponentR
467
495
  declare type DepositRequestFields = {
468
496
  destination: BlockchainAddress | CAIP10;
469
497
  asset: TransactionAsset;
470
- amountDecimal?: number;
498
+ amountDecimal: number;
471
499
  travelAddress?: TravelAddress;
472
500
  cryptoCredential?: CryptoCredential;
473
501
  };
@@ -1499,6 +1527,7 @@ export declare interface Transaction extends ComponentRequest {
1499
1527
  price: number;
1500
1528
  currency: ISOCurrency;
1501
1529
  };
1530
+ account?: Account;
1502
1531
  }
1503
1532
 
1504
1533
  /**
@@ -1527,6 +1556,7 @@ export declare interface TransactionOptions {
1527
1556
  fields?: FieldTypes;
1528
1557
  vasps?: VASPOptions;
1529
1558
  hide?: ValidationSections[];
1559
+ counterpartyAssistConfig?: CounterpartyAssistConfig;
1530
1560
  }
1531
1561
 
1532
1562
  /**
@@ -10,7 +10,7 @@
10
10
  "author": "Notabene <developers@notabene.id>",
11
11
  "license": "MIT",
12
12
  "packageManager": "yarn@4.5.1",
13
- "version": "2.9.0-next.2",
13
+ "version": "2.9.0-next.4",
14
14
  "source": "src/notabene.ts",
15
15
  "main": "dist/cjs/notabene.cjs",
16
16
  "module": "dist/esm/notabene.js",
@@ -1,3 +1,15 @@
1
+ /**
2
+ * A blockchain account
3
+ * @public
4
+ */
5
+ export declare interface Account {
6
+ did?: DID;
7
+ blockchainAddress?: BlockchainAddress;
8
+ chain?: CAIP2;
9
+ caip10?: CAIP10;
10
+ identifier?: string;
11
+ }
12
+
1
13
  /**
2
14
  * Address
3
15
  * Represents a physical address
@@ -365,7 +377,7 @@ export declare interface ConnectionResult<T extends ComponentRequest> {
365
377
  id: UUID;
366
378
  metadata: ConnectionMetadata;
367
379
  status: ConnectionStatus;
368
- tx: T;
380
+ tx?: T;
369
381
  result?: TransactionResponse<T>;
370
382
  }
371
383
 
@@ -410,6 +422,22 @@ export declare interface Counterparty {
410
422
  email?: string;
411
423
  }
412
424
 
425
+ /**
426
+ * Counterparty Assist Configuration options for recipient selection
427
+ *
428
+ * @remarks
429
+ * Controls for each person type, whether to show the share feature or not.
430
+ *
431
+ * @public
432
+ */
433
+ export declare type CounterpartyAssistConfig = {
434
+ enabled?: boolean;
435
+ } | {
436
+ [key in PersonType]: {
437
+ enabled?: boolean;
438
+ };
439
+ };
440
+
413
441
  /**
414
442
  * A crypto credential
415
443
  * @public
@@ -467,7 +495,7 @@ export declare interface DepositRequest extends DepositRequestFields, ComponentR
467
495
  declare type DepositRequestFields = {
468
496
  destination: BlockchainAddress | CAIP10;
469
497
  asset: TransactionAsset;
470
- amountDecimal?: number;
498
+ amountDecimal: number;
471
499
  travelAddress?: TravelAddress;
472
500
  cryptoCredential?: CryptoCredential;
473
501
  };
@@ -1499,6 +1527,7 @@ export declare interface Transaction extends ComponentRequest {
1499
1527
  price: number;
1500
1528
  currency: ISOCurrency;
1501
1529
  };
1530
+ account?: Account;
1502
1531
  }
1503
1532
 
1504
1533
  /**
@@ -1527,6 +1556,7 @@ export declare interface TransactionOptions {
1527
1556
  fields?: FieldTypes;
1528
1557
  vasps?: VASPOptions;
1529
1558
  hide?: ValidationSections[];
1559
+ counterpartyAssistConfig?: CounterpartyAssistConfig;
1530
1560
  }
1531
1561
 
1532
1562
  /**
@@ -1,7 +1,7 @@
1
1
  var v = Object.defineProperty;
2
2
  var g = (t, e, n) => e in t ? v(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
3
  var a = (t, e, n) => g(t, typeof e != "symbol" ? e + "" : e, n);
4
- var A = /* @__PURE__ */ ((t) => (t.PRIVATE = "WALLET", t.VASP = "VASP", t))(A || {}), y = /* @__PURE__ */ ((t) => (t.NATURAL = "natural", t.LEGAL = "legal", t.SELF = "self", t))(y || {}), I = /* @__PURE__ */ ((t) => (t.EMPTY = "empty", t.VERIFY = "verify", t.PENDING = "pending", t.VERIFIED = "verified", t.BANNED = "banned", t))(I || {}), L = /* @__PURE__ */ ((t) => (t.ALLOWED = "allowed", t.PENDING = "pending", t))(L || {}), C = /* @__PURE__ */ ((t) => (t.ASSET = "asset", t.DESTINATION = "destination", t.COUNTERPARTY = "counterparty", t.AGENT = "agent", t))(C || {}), l = /* @__PURE__ */ ((t) => (t.COMPLETE = "complete", t.RESIZE = "resize", t.RESULT = "result", t.READY = "ready", t.INVALID = "invalid", t.ERROR = "error", t.CANCEL = "cancel", t))(l || {}), N = /* @__PURE__ */ ((t) => (t.SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE", t.WALLET_CONNECTION_FAILED = "WALLET_CONNECTION_FAILED", t.WALLET_NOT_SUPPORTED = "WALLET_NOT_SUPPORTED", t.TOKEN_INVALID = "TOKEN_INVALID", t))(N || {}), E = /* @__PURE__ */ ((t) => (t.UPDATE = "update", t.REQUEST_RESPONSE = "requestResponse", t))(E || {}), b = /* @__PURE__ */ ((t) => (t.PENDING = "pending", t.FAILED = "rejected", t.FLAGGED = "flagged", t.VERIFIED = "verified", t))(b || {}), U = /* @__PURE__ */ ((t) => (t.SelfDeclaration = "self-declaration", t.SIWE = "siwe", t.SIWX = "siwx", t.EIP191 = "eip-191", t.EIP712 = "eip-712", t.EIP1271 = "eip-1271", t.BIP137 = "bip-137", t.BIP322 = "bip-322", t.BIP137_XPUB = "xpub", t.TIP191 = "tip-191", t.ED25519 = "ed25519", t.XRP_ED25519 = "xrp-ed25519", t.XLM_ED25519 = "xlm-ed25519", t.CIP8 = "cip-8", t.MicroTransfer = "microtransfer", t.Screenshot = "screenshot", t.Connect = "connect", t))(U || {});
4
+ var A = /* @__PURE__ */ ((t) => (t.PRIVATE = "WALLET", t.VASP = "VASP", t))(A || {}), y = /* @__PURE__ */ ((t) => (t.NATURAL = "natural", t.LEGAL = "legal", t.SELF = "self", t))(y || {}), I = /* @__PURE__ */ ((t) => (t.EMPTY = "empty", t.VERIFY = "verify", t.PENDING = "pending", t.VERIFIED = "verified", t.BANNED = "banned", t))(I || {}), L = /* @__PURE__ */ ((t) => (t.ALLOWED = "allowed", t.PENDING = "pending", t))(L || {}), b = /* @__PURE__ */ ((t) => (t.ASSET = "asset", t.DESTINATION = "destination", t.COUNTERPARTY = "counterparty", t.AGENT = "agent", t))(b || {}), l = /* @__PURE__ */ ((t) => (t.COMPLETE = "complete", t.RESIZE = "resize", t.RESULT = "result", t.READY = "ready", t.INVALID = "invalid", t.ERROR = "error", t.CANCEL = "cancel", t))(l || {}), C = /* @__PURE__ */ ((t) => (t.SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE", t.WALLET_CONNECTION_FAILED = "WALLET_CONNECTION_FAILED", t.WALLET_NOT_SUPPORTED = "WALLET_NOT_SUPPORTED", t.TOKEN_INVALID = "TOKEN_INVALID", t))(C || {}), E = /* @__PURE__ */ ((t) => (t.UPDATE = "update", t.REQUEST_RESPONSE = "requestResponse", t))(E || {}), N = /* @__PURE__ */ ((t) => (t.PENDING = "pending", t.FAILED = "rejected", t.FLAGGED = "flagged", t.VERIFIED = "verified", t))(N || {}), U = /* @__PURE__ */ ((t) => (t.SelfDeclaration = "self-declaration", t.SIWE = "siwe", t.SIWX = "siwx", t.EIP191 = "eip-191", t.EIP712 = "eip-712", t.EIP1271 = "eip-1271", t.BIP137 = "bip-137", t.BIP322 = "bip-322", t.BIP137_XPUB = "xpub", t.TIP191 = "tip-191", t.ED25519 = "ed25519", t.XRP_ED25519 = "xrp-ed25519", t.XLM_ED25519 = "xlm-ed25519", t.CIP8 = "cip-8", t.MicroTransfer = "microtransfer", t.Screenshot = "screenshot", t.Connect = "connect", t))(U || {});
5
5
  class _ {
6
6
  constructor() {
7
7
  a(this, "listeners", /* @__PURE__ */ new Map());
@@ -42,8 +42,8 @@ class _ {
42
42
  * @param callback - The callback function to remove
43
43
  */
44
44
  off(e, n) {
45
- const r = this.listeners.get(e);
46
- r && (r.delete(n), r.size === 0 && this.listeners.delete(e));
45
+ const s = this.listeners.get(e);
46
+ s && (s.delete(n), s.size === 0 && this.listeners.delete(e));
47
47
  }
48
48
  /**
49
49
  * Internal message handler for processing received messages.
@@ -56,8 +56,8 @@ class _ {
56
56
  handleMessage(e) {
57
57
  const n = e.data;
58
58
  if (typeof n == "object" && n !== null && "type" in n) {
59
- const r = n.type, s = this.listeners.get(r);
60
- s && s.forEach((i) => i(n));
59
+ const s = n.type, r = this.listeners.get(s);
60
+ r && r.forEach((i) => i(n));
61
61
  }
62
62
  }
63
63
  /**
@@ -74,7 +74,7 @@ class x {
74
74
  * @param url - The URL of the embedded component
75
75
  * @param value - The initial transaction value
76
76
  */
77
- constructor(e, n, r) {
77
+ constructor(e, n, s) {
78
78
  a(this, "_url");
79
79
  a(this, "_value");
80
80
  a(this, "_options");
@@ -82,10 +82,10 @@ class x {
82
82
  a(this, "iframe");
83
83
  a(this, "eventManager");
84
84
  a(this, "modal");
85
- this._url = e, this._value = n, this._options = r, this.eventManager = new _(), this.on(l.INVALID, (s) => {
86
- s.type === l.INVALID && (this._errors = s.errors, this._value = s.value);
87
- }), this.on(l.RESIZE, (s) => {
88
- s.type === l.RESIZE && this.iframe && (this.iframe.style.height = `${s.height}px`);
85
+ this._url = e, this._value = n, this._options = s, this.eventManager = new _(), 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`);
89
89
  });
90
90
  }
91
91
  /**
@@ -129,11 +129,11 @@ class x {
129
129
  * @param parent - The parent element to embed the component into
130
130
  */
131
131
  embed(e, n = !1) {
132
- var r, s;
132
+ var s, r;
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", e.appendChild(this.iframe), window.addEventListener("message", (i) => {
134
134
  var o, c;
135
135
  i.source === ((o = this.iframe) == null ? void 0 : o.contentWindow) && ((c = this.eventManager) == null || c.setPort(i.ports[0]));
136
- }), (s = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || s.focus();
136
+ }), (r = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || r.focus();
137
137
  }
138
138
  removeEmbed() {
139
139
  this.iframe && this.iframe.remove();
@@ -174,13 +174,13 @@ class x {
174
174
  */
175
175
  completion() {
176
176
  return new Promise((e, n) => {
177
- let r, s, i;
177
+ let s, r, i;
178
178
  function o() {
179
- r && r(), s && s(), i && i();
179
+ s && s(), r && r(), i && i();
180
180
  }
181
- r = this.on(l.COMPLETE, (c) => {
181
+ s = this.on(l.COMPLETE, (c) => {
182
182
  e(c.response), o();
183
- }), s = this.on(l.CANCEL, () => {
183
+ }), r = this.on(l.CANCEL, () => {
184
184
  n(new Error("User cancelled")), o();
185
185
  }), i = this.on("error", (c) => {
186
186
  n(new Error(c.message)), o();
@@ -223,63 +223,63 @@ class x {
223
223
  "_blank",
224
224
  "popup=true,width=600,height=600"
225
225
  );
226
- window.addEventListener("message", (s) => {
226
+ window.addEventListener("message", (r) => {
227
227
  var i;
228
- s.source === e && (console.log("received message from popup", s.data), (i = this.eventManager) == null || i.setPort(s.ports[0]));
228
+ r.source === e && (console.log("received message from popup", r.data), (i = this.eventManager) == null || i.setPort(r.ports[0]));
229
229
  });
230
230
  const n = this.on(l.CANCEL, () => {
231
231
  e == null || e.close();
232
- }), r = this.on(l.COMPLETE, () => {
232
+ }), s = this.on(l.COMPLETE, () => {
233
233
  e == null || e.close();
234
234
  });
235
235
  return this.completion().finally(() => {
236
- n(), r();
236
+ n(), s();
237
237
  });
238
238
  }
239
239
  }
240
- function R(t) {
240
+ function D(t) {
241
241
  return Object.entries(t).map(([e, n]) => {
242
242
  if (n == null) return;
243
- const r = encodeURIComponent(e), s = encodeURIComponent(
243
+ const s = encodeURIComponent(e), r = encodeURIComponent(
244
244
  typeof n == "object" ? JSON.stringify(n) : String(n)
245
245
  // Use String() to handle all primitive types
246
246
  );
247
- return `${r}=${s}`;
247
+ return `${s}=${r}`;
248
248
  }).filter((e) => e !== void 0).join("&");
249
249
  }
250
250
  function O(t) {
251
251
  const e = t.slice(1);
252
252
  return e ? e.split("&").filter(Boolean).reduce(
253
- (r, s) => {
254
- const [i, o] = s.split("=");
255
- return i && (r[decodeURIComponent(i)] = o ? decodeURIComponent(o) : ""), r;
253
+ (s, r) => {
254
+ const [i, o] = r.split("=");
255
+ return i && (s[decodeURIComponent(i)] = o ? decodeURIComponent(o) : ""), s;
256
256
  },
257
257
  {}
258
258
  ) : {};
259
259
  }
260
260
  async function p(t, e) {
261
- const n = JSON.stringify(t), r = new TextEncoder(), s = e ? m(e) : crypto.getRandomValues(new Uint8Array(32)), i = await crypto.subtle.importKey(
261
+ const n = JSON.stringify(t), s = new TextEncoder(), r = e ? m(e) : crypto.getRandomValues(new Uint8Array(32)), i = await crypto.subtle.importKey(
262
262
  "raw",
263
- s,
263
+ r,
264
264
  { name: "AES-GCM" },
265
265
  !1,
266
266
  ["encrypt"]
267
267
  ), o = crypto.getRandomValues(new Uint8Array(12)), c = await crypto.subtle.encrypt(
268
268
  { name: "AES-GCM", iv: o },
269
269
  i,
270
- r.encode(n)
270
+ s.encode(n)
271
271
  );
272
272
  return {
273
273
  ciphertext: `${u(o)}-${u(c)}`,
274
- key: u(s)
274
+ key: u(r)
275
275
  };
276
276
  }
277
277
  async function f({ ciphertext: t, key: e }) {
278
- const [n, r] = t.split("-"), s = new Uint8Array(
278
+ const [n, s] = t.split("-"), r = new Uint8Array(
279
279
  atob(e).split("").map((w) => w.charCodeAt(0))
280
- ), i = m(n), o = m(r), c = await crypto.subtle.importKey(
280
+ ), i = m(n), o = m(s), c = await crypto.subtle.importKey(
281
281
  "raw",
282
- s,
282
+ r,
283
283
  { name: "AES-GCM" },
284
284
  !1,
285
285
  ["decrypt"]
@@ -293,14 +293,14 @@ async function f({ ciphertext: t, key: e }) {
293
293
  function u(t) {
294
294
  const e = new Uint8Array(t);
295
295
  let n = "";
296
- for (let r = 0; r < e.length; r++)
297
- n += String.fromCharCode(e[r]);
296
+ for (let s = 0; s < e.length; s++)
297
+ n += String.fromCharCode(e[s]);
298
298
  return btoa(n);
299
299
  }
300
300
  function m(t) {
301
301
  const e = atob(t), n = new Uint8Array(e.length);
302
- for (let r = 0; r < e.length; r++)
303
- n[r] = e.charCodeAt(r);
302
+ for (let s = 0; s < e.length; s++)
303
+ n[s] = e.charCodeAt(s);
304
304
  return n;
305
305
  }
306
306
  async function M(t) {
@@ -310,18 +310,25 @@ async function M(t) {
310
310
  if (!e.ok)
311
311
  throw new Error(`Failed to get connection: ${await e.text()}`);
312
312
  const n = await e.json();
313
- if (!n.sealed)
314
- throw new Error("No data found");
315
- const r = n.sealed[n.sealed.length - 1], s = await f({
313
+ if (!n.id || !n.metadata || !n.status || !n.sealed)
314
+ throw new Error("Data missing from server response");
315
+ const s = {
316
+ id: n.id,
317
+ metadata: n.metadata,
318
+ status: n.status
319
+ };
320
+ if (n.status === "closed")
321
+ return s;
322
+ const r = n.sealed[n.sealed.length - 1], i = await f({
316
323
  ciphertext: r,
317
324
  key: t.key
318
325
  });
319
- return {
320
- id: n.id,
321
- metadata: n.metadata,
322
- status: n.status,
323
- tx: s.tx,
324
- result: s.result
326
+ return n.status === "completed" ? {
327
+ ...s,
328
+ result: i.result
329
+ } : {
330
+ ...s,
331
+ tx: i.tx
325
332
  };
326
333
  }
327
334
  class S {
@@ -336,15 +343,15 @@ class S {
336
343
  * @returns Promise resolving to connection details including ID, version, and encryption key
337
344
  */
338
345
  async create(e, n) {
339
- const r = await p(e), s = {
346
+ const s = await p(e), r = {
340
347
  metadata: n,
341
- sealed: r.ciphertext
348
+ sealed: s.ciphertext
342
349
  }, i = await fetch(this.endpoint, {
343
350
  method: "POST",
344
351
  headers: {
345
352
  "Content-Type": "application/json"
346
353
  },
347
- body: JSON.stringify(s)
354
+ body: JSON.stringify(r)
348
355
  });
349
356
  if (!i.ok)
350
357
  throw new Error(`Failed to create connection: ${await i.text()}`);
@@ -355,7 +362,7 @@ class S {
355
362
  status: o.status,
356
363
  metadata: n,
357
364
  data: e,
358
- key: r.key
365
+ key: s.key
359
366
  };
360
367
  }
361
368
  /**
@@ -365,11 +372,11 @@ class S {
365
372
  * @param version Current version number
366
373
  * @returns Promise resolving to updated connection details including new encryption key
367
374
  */
368
- async update(e, n, r, s, i) {
375
+ async update(e, n, s, r, i) {
369
376
  const o = await p(n, i), c = {
370
377
  sealed: o.ciphertext,
371
- version: r,
372
- status: s
378
+ version: s,
379
+ status: r
373
380
  }, h = await fetch(`${this.endpoint}/${e}`, {
374
381
  method: "PATCH",
375
382
  headers: {
@@ -396,20 +403,20 @@ class S {
396
403
  * @returns Promise resolving to connection details including decrypted data
397
404
  */
398
405
  async get(e, n) {
399
- const r = await fetch(`${this.endpoint}/${e}`, {
406
+ const s = await fetch(`${this.endpoint}/${e}`, {
400
407
  method: "GET"
401
408
  });
402
- if (!r.ok)
403
- throw new Error(`Failed to get connection: ${await r.text()}`);
404
- const s = await r.json(), i = s.sealed[s.sealed.length - 1], o = await f({
409
+ if (!s.ok)
410
+ throw new Error(`Failed to get connection: ${await s.text()}`);
411
+ const r = await s.json(), i = r.sealed[r.sealed.length - 1], o = await f({
405
412
  ciphertext: i,
406
413
  key: n
407
414
  });
408
415
  return {
409
- id: s.id,
410
- status: s.status,
411
- version: s.version,
412
- metadata: s.metadata,
416
+ id: r.id,
417
+ status: r.status,
418
+ version: r.version,
419
+ metadata: r.metadata,
413
420
  data: o,
414
421
  key: n
415
422
  };
@@ -450,15 +457,15 @@ class k {
450
457
  * @returns component URL
451
458
  * @internal
452
459
  */
453
- componentUrl(e, n, r, s) {
460
+ componentUrl(e, n, s, r) {
454
461
  const i = new URL(this.uxUrl);
455
462
  i.pathname = e;
456
- const o = R({
463
+ const o = D({
457
464
  authToken: this.authToken,
458
465
  value: n,
459
- configuration: r
466
+ configuration: s
460
467
  });
461
- return i.hash = o, 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), s && (s.callback && i.searchParams.set("callback_url", s.callback), s.redirectUri && i.searchParams.set("redirect_uri", s.redirectUri)), i.toString();
468
+ return i.hash = o, 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();
462
469
  }
463
470
  /**
464
471
  * Creates a new embedded component
@@ -470,11 +477,11 @@ class k {
470
477
  * @returns A new EmbeddedComponent instance
471
478
  * @internal
472
479
  */
473
- createComponent(e, n, r, s) {
480
+ createComponent(e, n, s, r) {
474
481
  return new x(
475
- this.componentUrl(e, n, r, s),
482
+ this.componentUrl(e, n, s, r),
476
483
  n,
477
- r
484
+ s
478
485
  );
479
486
  }
480
487
  /**
@@ -485,12 +492,12 @@ class k {
485
492
  * @param callbacks - Optional callback configuration
486
493
  * @returns A new EmbeddedComponent instance for withdrawal assistance
487
494
  */
488
- createWithdrawalAssist(e, n, r) {
495
+ createWithdrawalAssist(e, n, s) {
489
496
  return this.createComponent(
490
497
  "withdrawal-assist",
491
498
  e,
492
499
  n,
493
- r
500
+ s
494
501
  );
495
502
  }
496
503
  /**
@@ -502,12 +509,12 @@ class k {
502
509
  * @returns A new EmbeddedComponent instance for connection
503
510
  * @alpha
504
511
  */
505
- createConnectWallet(e, n, r) {
512
+ createConnectWallet(e, n, s) {
506
513
  return this.createComponent(
507
514
  "connect",
508
515
  e,
509
516
  n,
510
- r
517
+ s
511
518
  );
512
519
  }
513
520
  /**
@@ -519,12 +526,12 @@ class k {
519
526
  * @returns A new EmbeddedComponent instance for deposit requests
520
527
  * @public
521
528
  */
522
- createDepositRequest(e, n, r) {
529
+ createDepositRequest(e, n, s) {
523
530
  return this.createComponent(
524
531
  "deposit-request",
525
532
  e,
526
533
  n,
527
- r
534
+ s
528
535
  );
529
536
  }
530
537
  /**
@@ -536,12 +543,12 @@ class k {
536
543
  * @returns A new EmbeddedComponent instance for deposit assistance
537
544
  * @public
538
545
  */
539
- createDepositAssist(e, n, r) {
546
+ createDepositAssist(e, n, s) {
540
547
  return this.createComponent(
541
548
  "deposit-assist",
542
549
  e,
543
550
  n,
544
- r
551
+ s
545
552
  );
546
553
  }
547
554
  }
@@ -550,14 +557,14 @@ export {
550
557
  l as CMType,
551
558
  S as ConnectionManager,
552
559
  x as EmbeddedComponent,
553
- N as ErrorIdentifierCode,
560
+ C as ErrorIdentifierCode,
554
561
  E as HMType,
555
562
  y as PersonType,
556
- b as ProofStatus,
563
+ N as ProofStatus,
557
564
  U as ProofTypes,
558
565
  I as Status,
559
566
  L as VASPSearchControl,
560
- C as ValidationSections,
567
+ b as ValidationSections,
561
568
  O as decodeFragmentToObject,
562
569
  k as default,
563
570
  M as getRefreshResult
@@ -10,7 +10,7 @@
10
10
  "author": "Notabene <developers@notabene.id>",
11
11
  "license": "MIT",
12
12
  "packageManager": "yarn@4.5.1",
13
- "version": "2.9.0-next.2",
13
+ "version": "2.9.0-next.4",
14
14
  "source": "src/notabene.ts",
15
15
  "main": "dist/cjs/notabene.cjs",
16
16
  "module": "dist/esm/notabene.js",