@notabene/javascript-sdk 2.14.0-next.3 → 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.
@@ -1 +1 @@
1
- "use strict";var W=Object.defineProperty;var k=(e,t,n)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var c=(e,t,n)=>k(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var w=(e=>(e.PRIVATE="WALLET",e.VASP="VASP",e))(w||{}),g=(e=>(e.NATURAL="natural",e.LEGAL="legal",e.SELF="self",e))(g||{}),N=(e=>(e.EMPTY="empty",e.VERIFY="verify",e.PENDING="pending",e.VERIFIED="verified",e.BANNED="banned",e))(N||{}),C=(e=>(e.ALLOWED="allowed",e.PENDING="pending",e))(C||{}),L=(e=>(e.SMS="sms",e.EMAIL="email",e))(L||{}),P=(e=>(e.PENDING="pending",e.APPROVED="approved",e.FAILED="failed",e.EXPIRED="expired",e.MAX_ATTEMPTS_REACHED="max_attempts_reached",e.UNREACHABLE="unreachable",e))(P||{}),R=(e=>(e.COINBASE="coinbase",e))(R||{}),S=(e=>(e.ASSET="asset",e.DESTINATION="destination",e.COUNTERPARTY="counterparty",e.AGENT="agent",e))(S||{}),l=(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||{}),v=(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))(v||{}),T=(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))(T||{}),b=(e=>(e.UPDATE="update",e.REQUEST_RESPONSE="requestResponse",e))(b||{}),_=(e=>(e.PENDING="pending",e.FAILED="rejected",e.FLAGGED="flagged",e.VERIFIED="verified",e))(_||{}),O=(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))(O||{});class j{constructor(){c(this,"listeners",new Map);c(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(t){this.port=t,this.port.onmessage=this.handleMessage,this.port.start()}on(t,n){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(n),()=>this.off(t,n)}off(t,n){const r=this.listeners.get(t);r&&(r.delete(n),r.size===0&&this.listeners.delete(t))}handleMessage(t){const n=t.data;if(typeof n=="object"&&n!==null&&"type"in n){const r=n.type,o=this.listeners.get(r);o&&o.forEach(i=>i(n))}}send(t){this.port&&this.port.postMessage(t)}}class D{constructor(t,n,r){c(this,"_url");c(this,"_value");c(this,"_options");c(this,"_errors",[]);c(this,"iframe");c(this,"eventManager");c(this,"modal");this._url=t,this._value=n,this._options=r,this.eventManager=new j,this.on(l.INVALID,o=>{o.type===l.INVALID&&(this._errors=o.errors,this._value=o.value)}),this.on(l.RESIZE,o=>{o.type===l.RESIZE&&this.iframe&&(this.iframe.style.height=`${o.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(t){const n=document.querySelector(t);if(!n)throw new Error(`parentID ${t} not found`);this.embed(n)}embed(t,n=!1){var r,o;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=>{var s,a;i.source===((s=this.iframe)==null?void 0:s.contentWindow)&&((a=this.eventManager)==null||a.setPort(i.ports[0]))}),(o=(r=this.iframe)==null?void 0:r.contentWindow)==null||o.focus()}removeEmbed(){this.iframe&&this.iframe.remove()}send(t){this.eventManager.send(t)}on(t,n){return this.eventManager.on(t,n)}off(t,n){this.eventManager.off(t,n)}update(t,n){this._value=t,n&&(this._options=n),this.send({type:b.UPDATE,value:t,options:this._options})}completion(){return new Promise((t,n)=>{let r,o,i;function s(){r&&r(),o&&o(),i&&i()}r=this.on(l.COMPLETE,a=>{t(a.response),s()}),o=this.on(l.CANCEL,()=>{n(new Error("User cancelled")),s()}),i=this.on("error",a=>{n(new Error(a.message)),s()})})}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 t=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(()=>{t(),n()})}closeModal(){var t;this.modal&&((t=this.modal)==null||t.close(),this.modal.remove(),this.modal=void 0)}async popup(){const t=window.open(this.url,"_blank","popup=true,width=600,height=600");window.addEventListener("message",o=>{var i;o.source===t&&(console.log("received message from popup",o.data),(i=this.eventManager)==null||i.setPort(o.ports[0]))});const n=this.on(l.CANCEL,()=>{t==null||t.close()}),r=this.on(l.COMPLETE,()=>{t==null||t.close()});return this.completion().finally(()=>{n(),r()})}}function J(e){return Object.entries(e).map(([t,n])=>{if(n==null)return;const r=encodeURIComponent(t),o=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${o}`}).filter(t=>t!==void 0).join("&")}function F(e){const t=e.slice(1);return t?t.split("&").filter(Boolean).reduce((r,o)=>{const[i,s]=o.split("=");return i&&(r[decodeURIComponent(i)]=s?decodeURIComponent(s):""),r},{}):{}}new TextEncoder;const f=new TextDecoder;function q(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function G(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof e=="string"?e:f.decode(e),{alphabet:"base64url"});let t=e;t instanceof Uint8Array&&(t=f.decode(t)),t=t.replace(/-/g,"+").replace(/_/g,"/").replace(/\s/g,"");try{return q(t)}catch{throw new TypeError("The input to be decoded is not correctly encoded.")}}class U extends Error{constructor(n,r){var o;super(n,r);c(this,"code","ERR_JOSE_GENERIC");this.name=this.constructor.name,(o=Error.captureStackTrace)==null||o.call(Error,this,this.constructor)}}c(U,"code","ERR_JOSE_GENERIC");class u extends U{constructor(){super(...arguments);c(this,"code","ERR_JWT_INVALID")}}c(u,"code","ERR_JWT_INVALID");function $(e){return typeof e=="object"&&e!==null}const H=e=>{if(!$(e)||Object.prototype.toString.call(e)!=="[object Object]")return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t};function K(e){if(typeof e!="string")throw new u("JWTs must use Compact JWS serialization, JWT must be a string");const{1:t,length:n}=e.split(".");if(n===5)throw new u("Only JWTs using Compact JWS serialization can be decoded");if(n!==3)throw new u("Invalid JWT");if(!t)throw new u("JWTs must contain a payload");let r;try{r=G(t)}catch{throw new u("Failed to base64url decode the payload")}let o;try{o=JSON.parse(f.decode(r))}catch{throw new u("Failed to parse the decoded payload as JSON")}if(!H(o))throw new u("Invalid JWT Claims Set");return o}function E(e,t){if(t!=null&&t.email)return`did:email:${t.email}`;if(t!=null&&t.name)return`did:name:${encodeURIComponent(t.name.replace(/\s+/g,"-"))}`;throw new Error(`Unable to generate ${e} ID: missing required ${e} information`)}function X(e){const{nameIdentifier:t,...n}=e;return{...n,nameIdentifier:t==null?void 0:t.map(({nameIdentifierType:r,...o})=>({...o,naturalPersonNameIdentifierType:r}))}}function z(e,t){return{naturalPerson:e.naturalPerson?{...e.naturalPerson,name:X(e.naturalPerson.name)}:void 0,legalPerson:e.legalPerson,accountNumber:[t]}}const p=[{addressType:"GEOG",addressLine:["1234 Main Street"],townName:"Unknown",country:"US"}];function Y(e){const t=e.trim();if(!t)return{primaryIdentifier:"",secondaryIdentifier:""};const n=t.split(/\s+/),r=n[n.length-1],o=n.slice(0,-1),i=o.length>0?o.join(" "):r;return{primaryIdentifier:r,secondaryIdentifier:i}}function Q(e,t,n=["1234567890"]){const r=t==null?void 0:t.map(o=>{const i={...o};return i.naturalPerson&&(i.naturalPerson={...i.naturalPerson,geographicAddress:p}),i.legalPerson&&(i.legalPerson={...i.legalPerson,geographicAddress:p}),i});return e==="originator"?{originatorPersons:r,accountNumber:n}:{beneficiaryPersons:r,accountNumber:n}}function Z(e,t="John Doe"){const{primaryIdentifier:n,secondaryIdentifier:r}=Y(t),o={naturalPerson:{name:[{nameIdentifier:[{primaryIdentifier:n,...r?{secondaryIdentifier:r}:{},nameIdentifierType:"LEGL"}]}],geographicAddress:p}};return e==="originator"?{originatorPersons:[o],accountNumber:["1234567890"]}:{beneficiaryPersons:[o],accountNumber:["1234567890"]}}const ee=e=>({...e,name:e.name?[e.name]:void 0}),te=e=>({...e,naturalPerson:e.naturalPerson?ee(e.naturalPerson):void 0}),ne=({beneficiary:e,originator:t},n,r,o,i)=>{var s;{const a=e&&{...e,...o&&{accountNumber:[o]},beneficiaryPersons:(s=e.beneficiaryPersons)==null?void 0:s.map(te)};if(r&&(a!=null&&a.beneficiaryPersons)){const d=Q("originator",a==null?void 0:a.beneficiaryPersons);return{beneficiary:{accountNumber:d.accountNumber,beneficiaryPersons:d.originatorPersons},originator:d}}return{beneficiary:a,originator:Z("originator",n)}}};function re(e,t,n){var i,s;const{beneficiary:r,originator:o}=ne(n,(i=e.customer)==null?void 0:i.name,t.originatorEqualsBeneficiary,e.destination);return{transactionAsset:t.transactionAsset,transactionAmount:t.transactionAmount,beneficiaryDid:(s=e.counterparty)==null?void 0:s.did,originatorVASPdid:t.originatorVASPdid,...t.beneficiaryVASPdid&&!t.beneficiaryProof?{beneficiaryVASPdid:t.beneficiaryVASPdid}:{},transactionBlockchainInfo:{...(o==null?void 0:o.accountNumber)&&{origin:o.accountNumber[0]},...e.destination&&{destination:e.destination}},...t.beneficiaryProof&&{beneficiaryProof:t.beneficiaryProof},...r&&{beneficiary:r},...o&&{originator:o},...t.originatorEqualsBeneficiary&&{originatorEqualsBeneficiary:t.originatorEqualsBeneficiary}}}function x(e,t,n={}){var a,d;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=[];return t.originatorVASPdid&&s.push({"@id":t.originatorVASPdid,for:r,role:"VASP"}),t.beneficiaryVASPdid&&s.push({"@id":t.beneficiaryVASPdid,for:o,role:"VASP"}),e.destination&&((a=e==null?void 0:e.account)!=null&&a.did)&&s.push({"@id":e.account.did,for:t.beneficiaryVASPdid||o,role:"SettlementAddress"}),{originator:{"@id":r},beneficiary:{"@id":o},asset:e.asset,amount:((d=e.amountDecimal)==null?void 0:d.toString())||t.transactionAmount,agents:s,ref:i}}function M(e,t,n={}){var i,s;const r=n.beneficiaryId||E("beneficiary",e.counterparty),o=((s=(i=t.beneficiary)==null?void 0:i.beneficiaryPersons)==null?void 0:s.map(a=>z(a,r)))||[];return{ivms101:{originator:n.originator,beneficiary:{beneficiaryPerson:o}}}}function I(e,t,n){var o;const r={...e};if(!r.originatorId)try{const i=K(t);i!=null&&i.sub&&(r.originatorId=i.sub)}catch{}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}function oe(e){var s;if(!e.txCreate||!e.ivms101)throw new Error("Invalid response: missing required txCreate or ivms101 data");const{value:t,ivms101:n,proof:r,txCreate:o}=e,i={destination:(t==null?void 0:t.destination)||"",counterparty:(t==null?void 0:t.counterparty)||{},agent:t==null?void 0:t.agent,account:t==null?void 0:t.account,proof:r,asset:(t==null?void 0:t.asset)||(typeof o.transactionAsset=="string"?o.transactionAsset:(s=o.transactionAsset)==null?void 0:s.caip19)||"",amountDecimal:(t==null?void 0:t.amountDecimal)||(o.transactionAmount?parseFloat(o.transactionAmount):0),customer:t==null?void 0:t.customer};return re(i,o,n)}function ie(e,t,n={}){if(!e.txCreate||!e.ivms101)throw new Error("Invalid response: missing required txCreate or ivms101 data");const{value:r,txCreate:o,ivms101:i,proof:s}=e,a=I(n,t,r);return{createTx:x(r,o,a),ivms101:M(r,i,a),...s&&{confirmRelationship:{proof:s}}}}function se(e,t,n={}){if(!e.txCreate||!e.ivms101)throw new Error("Invalid response: missing required txCreate or ivms101 data");const{value:r,txCreate:o}=e,i=I(n,t,r);return x(r,o,i)}function ae(e,t,n={}){if(!e.ivms101)throw new Error("Invalid response: missing required ivms101 data");const{value:r,ivms101:o}=e,i=I(n,t,r);return M(r,o,i)}async function y(e,t){const n=JSON.stringify(e),r=new TextEncoder,o=t?A(t):crypto.getRandomValues(new Uint8Array(32)),i=await crypto.subtle.importKey("raw",o,{name:"AES-GCM"},!1,["encrypt"]),s=crypto.getRandomValues(new Uint8Array(12)),a=await crypto.subtle.encrypt({name:"AES-GCM",iv:s},i,r.encode(n));return{ciphertext:`${m(s)}-${m(a)}`,key:m(o)}}async function V({ciphertext:e,key:t}){const[n,r]=e.split("-"),o=new Uint8Array(atob(t).split("").map(B=>B.charCodeAt(0))),i=A(n),s=A(r),a=await crypto.subtle.importKey("raw",o,{name:"AES-GCM"},!1,["decrypt"]),d=new TextDecoder,h=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(i)},a,s);return JSON.parse(d.decode(h))}function m(e){const t=new Uint8Array(e);let n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}function A(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}async function ce(e){const t=await fetch(e.url,{method:"GET"});if(!t.ok)throw new Error(`Failed to get connection: ${await t.text()}`);const n=await t.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 o=n.sealed[n.sealed.length-1],i=await V({ciphertext:o,key:e.key});return n.status==="completed"?{...r,result:i.result}:{...r,tx:i.tx}}class de{constructor(t){c(this,"endpoint");this.endpoint=t}async create(t,n){const r=await y(t),o={metadata:n,sealed:r.ciphertext},i=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!i.ok)throw new Error(`Failed to create connection: ${await i.text()}`);const s=await i.json();return{id:s.id,version:s.version,status:s.status,metadata:n,data:t,key:r.key}}async update(t,n,r,o,i){const s=await y(n,i),a={sealed:s.ciphertext,version:r,status:o},d=await fetch(`${this.endpoint}/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});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:s.key}}async get(t,n){const r=await fetch(`${this.endpoint}/${t}`,{method:"GET"});if(!r.ok)throw new Error(`Failed to get connection: ${await r.text()}`);const o=await r.json(),i=o.sealed[o.sealed.length-1],s=await V({ciphertext:i,key:n});return{id:o.id,status:o.status,version:o.version,metadata:o.metadata,data:s,key:n}}async close(t){const n=await fetch(`${this.endpoint}/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(`Failed to close connection: ${await n.text()}`)}}class le{constructor(t){c(this,"nodeUrl");c(this,"authToken");c(this,"uxUrl");c(this,"theme");c(this,"locale");this.uxUrl=t.uxUrl||"https://connect.notabene.id",this.nodeUrl=t.nodeUrl,this.authToken=t.authToken,this.theme=t.theme,this.locale=t.locale}componentUrl(t,n,r,o){const i=new URL(this.uxUrl);i.pathname=t;const s=J({authToken:this.authToken,value:n,configuration:r});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()}createComponent(t,n,r,o){return new D(this.componentUrl(t,n,r,o),n,r)}createWithdrawalAssist(t,n,r){return this.createComponent("withdrawal-assist",t,n,r)}createConnectWallet(t,n,r){return this.createComponent("connect",t,n,r)}createDepositRequest(t,n,r){return this.createComponent("deposit-request",t,n,r)}createDepositAssist(t,n,r){return this.createComponent("deposit-assist",t,n,r)}}exports.AgentType=w;exports.CMType=l;exports.CodeVerificationStatus=P;exports.ConnectionManager=de;exports.EmbeddedComponent=D;exports.ErrorIdentifierCode=v;exports.HMType=b;exports.IdentityVerificationMethod=L;exports.OAuthProvider=R;exports.PersonType=g;exports.ProofStatus=_;exports.ProofTypes=O;exports.Status=N;exports.VASPSearchControl=C;exports.ValidationSections=S;exports.WarningIdentifierCode=T;exports.componentResponseToIVMS101=ae;exports.componentResponseToTxCreateRequest=se;exports.componentResponseToTxRequests=ie;exports.componentResponseToV1TxCreateRequest=oe;exports.decodeFragmentToObject=F;exports.default=le;exports.getRefreshResult=ce;
1
+ "use strict";var W=Object.defineProperty;var k=(e,t,n)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var c=(e,t,n)=>k(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var N=(e=>(e.PRIVATE="WALLET",e.VASP="VASP",e))(N||{}),m=(e=>(e.NATURAL="natural",e.LEGAL="legal",e.SELF="self",e))(m||{}),w=(e=>(e.EMPTY="empty",e.VERIFY="verify",e.PENDING="pending",e.VERIFIED="verified",e.BANNED="banned",e))(w||{}),C=(e=>(e.ALLOWED="allowed",e.PENDING="pending",e))(C||{}),L=(e=>(e.SMS="sms",e.EMAIL="email",e))(L||{}),P=(e=>(e.PENDING="pending",e.APPROVED="approved",e.FAILED="failed",e.EXPIRED="expired",e.MAX_ATTEMPTS_REACHED="max_attempts_reached",e.UNREACHABLE="unreachable",e))(P||{}),R=(e=>(e.COINBASE="coinbase",e))(R||{}),S=(e=>(e.ASSET="asset",e.DESTINATION="destination",e.COUNTERPARTY="counterparty",e.AGENT="agent",e))(S||{}),l=(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||{}),v=(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))(v||{}),T=(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))(T||{}),b=(e=>(e.UPDATE="update",e.REQUEST_RESPONSE="requestResponse",e))(b||{}),_=(e=>(e.PENDING="pending",e.FAILED="rejected",e.FLAGGED="flagged",e.VERIFIED="verified",e))(_||{}),O=(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))(O||{});class j{constructor(){c(this,"listeners",new Map);c(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(t){this.port=t,this.port.onmessage=this.handleMessage,this.port.start()}on(t,n){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(n),()=>this.off(t,n)}off(t,n){const r=this.listeners.get(t);r&&(r.delete(n),r.size===0&&this.listeners.delete(t))}handleMessage(t){const n=t.data;if(typeof n=="object"&&n!==null&&"type"in n){const r=n.type,o=this.listeners.get(r);o&&o.forEach(i=>i(n))}}send(t){this.port&&this.port.postMessage(t)}}class D{constructor(t,n,r){c(this,"_url");c(this,"_value");c(this,"_options");c(this,"_errors",[]);c(this,"iframe");c(this,"eventManager");c(this,"modal");this._url=t,this._value=n,this._options=r,this.eventManager=new j,this.on(l.INVALID,o=>{o.type===l.INVALID&&(this._errors=o.errors,this._value=o.value)}),this.on(l.RESIZE,o=>{o.type===l.RESIZE&&this.iframe&&(this.iframe.style.height=`${o.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(t){const n=document.querySelector(t);if(!n)throw new Error(`parentID ${t} not found`);this.embed(n)}embed(t,n=!1){var r,o;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=>{var s,a;i.source===((s=this.iframe)==null?void 0:s.contentWindow)&&((a=this.eventManager)==null||a.setPort(i.ports[0]))}),(o=(r=this.iframe)==null?void 0:r.contentWindow)==null||o.focus()}removeEmbed(){this.iframe&&this.iframe.remove()}send(t){this.eventManager.send(t)}on(t,n){return this.eventManager.on(t,n)}off(t,n){this.eventManager.off(t,n)}update(t,n){this._value=t,n&&(this._options=n),this.send({type:b.UPDATE,value:t,options:this._options})}completion(){return new Promise((t,n)=>{let r,o,i;function s(){r&&r(),o&&o(),i&&i()}r=this.on(l.COMPLETE,a=>{t(a.response),s()}),o=this.on(l.CANCEL,()=>{n(new Error("User cancelled")),s()}),i=this.on("error",a=>{n(new Error(a.message)),s()})})}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 t=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(()=>{t(),n()})}closeModal(){var t;this.modal&&((t=this.modal)==null||t.close(),this.modal.remove(),this.modal=void 0)}async popup(){const t=window.open(this.url,"_blank","popup=true,width=600,height=600");window.addEventListener("message",o=>{var i;o.source===t&&(console.log("received message from popup",o.data),(i=this.eventManager)==null||i.setPort(o.ports[0]))});const n=this.on(l.CANCEL,()=>{t==null||t.close()}),r=this.on(l.COMPLETE,()=>{t==null||t.close()});return this.completion().finally(()=>{n(),r()})}}function F(e){return Object.entries(e).map(([t,n])=>{if(n==null)return;const r=encodeURIComponent(t),o=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${o}`}).filter(t=>t!==void 0).join("&")}function J(e){const t=e.slice(1);return t?t.split("&").filter(Boolean).reduce((r,o)=>{const[i,s]=o.split("=");return i&&(r[decodeURIComponent(i)]=s?decodeURIComponent(s):""),r},{}):{}}new TextEncoder;const E=new TextDecoder;function q(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function G(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof e=="string"?e:E.decode(e),{alphabet:"base64url"});let t=e;t instanceof Uint8Array&&(t=E.decode(t)),t=t.replace(/-/g,"+").replace(/_/g,"/").replace(/\s/g,"");try{return q(t)}catch{throw new TypeError("The input to be decoded is not correctly encoded.")}}class U extends Error{constructor(n,r){var o;super(n,r);c(this,"code","ERR_JOSE_GENERIC");this.name=this.constructor.name,(o=Error.captureStackTrace)==null||o.call(Error,this,this.constructor)}}c(U,"code","ERR_JOSE_GENERIC");class u extends U{constructor(){super(...arguments);c(this,"code","ERR_JWT_INVALID")}}c(u,"code","ERR_JWT_INVALID");function $(e){return typeof e=="object"&&e!==null}const H=e=>{if(!$(e)||Object.prototype.toString.call(e)!=="[object Object]")return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t};function K(e){if(typeof e!="string")throw new u("JWTs must use Compact JWS serialization, JWT must be a string");const{1:t,length:n}=e.split(".");if(n===5)throw new u("Only JWTs using Compact JWS serialization can be decoded");if(n!==3)throw new u("Invalid JWT");if(!t)throw new u("JWTs must contain a payload");let r;try{r=G(t)}catch{throw new u("Failed to base64url decode the payload")}let o;try{o=JSON.parse(E.decode(r))}catch{throw new u("Failed to parse the decoded payload as JSON")}if(!H(o))throw new u("Invalid JWT Claims Set");return o}function p(e,t){if(t!=null&&t.email)return`did:email:${t.email}`;if(t!=null&&t.name)return`did:name:${encodeURIComponent(t.name.replace(/\s+/g,"-"))}`;throw new Error(`Unable to generate ${e} ID: missing required ${e} information`)}function X(e){const{nameIdentifier:t,...n}=e;return{...n,nameIdentifier:t==null?void 0:t.map(({nameIdentifierType:r,...o})=>({...o,naturalPersonNameIdentifierType:r}))}}function z(e,t){return{naturalPerson:e.naturalPerson?{...e.naturalPerson,name:X(e.naturalPerson.name)}:void 0,legalPerson:e.legalPerson,accountNumber:[t]}}const A=[{addressType:"GEOG",addressLine:["1234 Main Street"],townName:"Unknown",country:"US"}];function Y(e){const t=e.trim();if(!t)return{primaryIdentifier:"",secondaryIdentifier:""};const n=t.split(/\s+/),r=n[n.length-1],o=n.slice(0,-1),i=o.length>0?o.join(" "):r;return{primaryIdentifier:r,secondaryIdentifier:i}}function Q(e,t,n=["1234567890"]){const r=t==null?void 0:t.map(o=>{const i={...o};return i.naturalPerson&&(i.naturalPerson={...i.naturalPerson,geographicAddress:A}),i.legalPerson&&(i.legalPerson={...i.legalPerson,geographicAddress:A}),i});return e==="originator"?{originatorPersons:r,accountNumber:n}:{beneficiaryPersons:r,accountNumber:n}}function Z(e,t="John Doe"){const{primaryIdentifier:n,secondaryIdentifier:r}=Y(t),o={naturalPerson:{name:[{nameIdentifier:[{primaryIdentifier:n,...r?{secondaryIdentifier:r}:{},nameIdentifierType:"LEGL"}]}],geographicAddress:A}};return e==="originator"?{originatorPersons:[o],accountNumber:["1234567890"]}:{beneficiaryPersons:[o],accountNumber:["1234567890"]}}const ee=e=>({...e,name:e.name?[e.name]:void 0}),te=e=>({...e,naturalPerson:e.naturalPerson?ee(e.naturalPerson):void 0}),ne=({beneficiary:e,originator:t},n,r,o,i)=>{var s;{const a=e&&{...e,...o&&{accountNumber:[o]},beneficiaryPersons:(s=e.beneficiaryPersons)==null?void 0:s.map(te)};if(r&&(a!=null&&a.beneficiaryPersons)){const d=Q("originator",a==null?void 0:a.beneficiaryPersons);return{beneficiary:{accountNumber:d.accountNumber,beneficiaryPersons:d.originatorPersons},originator:d}}return{beneficiary:a,originator:Z("originator",n)}}};function re(e,t,n){var i,s;const{beneficiary:r,originator:o}=ne(n,(i=e.customer)==null?void 0:i.name,t.originatorEqualsBeneficiary,e.destination);return{transactionAsset:t.transactionAsset,transactionAmount:t.transactionAmount,beneficiaryDid:(s=e.counterparty)==null?void 0:s.did,originatorVASPdid:t.originatorVASPdid,...t.beneficiaryVASPdid&&!t.beneficiaryProof?{beneficiaryVASPdid:t.beneficiaryVASPdid}:{},transactionBlockchainInfo:{...(o==null?void 0:o.accountNumber)&&{origin:o.accountNumber[0]},...e.destination&&{destination:e.destination}},...t.beneficiaryProof&&{beneficiaryProof:t.beneficiaryProof},...r&&{beneficiary:r},...o&&{originator:o},...t.originatorEqualsBeneficiary&&{originatorEqualsBeneficiary:t.originatorEqualsBeneficiary}}}function x(e,t,n={}){var a,d;const r=(n==null?void 0:n.originatorId)||p("originator",e.customer),o=(n==null?void 0:n.beneficiaryId)||p("beneficiary",e.counterparty),i=(n==null?void 0:n.referenceId)||Math.random().toString(36).substring(2,15),s=[];return t.originatorVASPdid&&s.push({"@id":t.originatorVASPdid,for:r,role:"VASP"}),t.beneficiaryVASPdid&&s.push({"@id":t.beneficiaryVASPdid,for:o,role:"VASP"}),e.destination&&((a=e==null?void 0:e.account)!=null&&a.did)&&s.push({"@id":e.account.did,for:t.beneficiaryVASPdid||o,role:"SettlementAddress"}),{originator:{"@id":r},beneficiary:{"@id":o},asset:e.asset,amount:((d=e.amountDecimal)==null?void 0:d.toString())||t.transactionAmount,agents:s,ref:i}}function M(e,t,n={}){var i,s,a;const r=n.beneficiaryId||p("beneficiary",e.counterparty),o=((i=e.counterparty)==null?void 0:i.type)===m.SELF&&n.originator?n.originator.originatorPerson:((a=(s=t.beneficiary)==null?void 0:s.beneficiaryPersons)==null?void 0:a.map(d=>z(d,r)))||[];return{ivms101:{originator:n.originator,beneficiary:{beneficiaryPerson:o}}}}function y(e,t,n){var o;const r={...e};if(!r.originatorId)try{const i=K(t);i!=null&&i.sub&&(r.originatorId=i.sub)}catch{}return r.beneficiaryId||(((o=n.counterparty)==null?void 0:o.type)===m.SELF?r.beneficiaryId=r.originatorId:n.destination&&(r.beneficiaryId=`did:key:${n.destination}`)),r}function oe(e){var s;if(!e.txCreate||!e.ivms101)throw new Error("Invalid response: missing required txCreate or ivms101 data");const{value:t,ivms101:n,proof:r,txCreate:o}=e,i={destination:(t==null?void 0:t.destination)||"",counterparty:(t==null?void 0:t.counterparty)||{},agent:t==null?void 0:t.agent,account:t==null?void 0:t.account,proof:r,asset:(t==null?void 0:t.asset)||(typeof o.transactionAsset=="string"?o.transactionAsset:(s=o.transactionAsset)==null?void 0:s.caip19)||"",amountDecimal:(t==null?void 0:t.amountDecimal)||(o.transactionAmount?parseFloat(o.transactionAmount):0),customer:t==null?void 0:t.customer};return re(i,o,n)}function ie(e,t,n={}){if(!e.txCreate||!e.ivms101)throw new Error("Invalid response: missing required txCreate or ivms101 data");const{value:r,txCreate:o,ivms101:i,proof:s}=e,a=y(n,t,r);return{createTx:x(r,o,a),ivms101:M(r,i,a),...s&&{confirmRelationship:{proof:s}}}}function se(e,t,n={}){if(!e.txCreate||!e.ivms101)throw new Error("Invalid response: missing required txCreate or ivms101 data");const{value:r,txCreate:o}=e,i=y(n,t,r);return x(r,o,i)}function ae(e,t,n={}){if(!e.ivms101)throw new Error("Invalid response: missing required ivms101 data");const{value:r,ivms101:o}=e,i=y(n,t,r);return M(r,o,i)}async function I(e,t){const n=JSON.stringify(e),r=new TextEncoder,o=t?g(t):crypto.getRandomValues(new Uint8Array(32)),i=await crypto.subtle.importKey("raw",o,{name:"AES-GCM"},!1,["encrypt"]),s=crypto.getRandomValues(new Uint8Array(12)),a=await crypto.subtle.encrypt({name:"AES-GCM",iv:s},i,r.encode(n));return{ciphertext:`${f(s)}-${f(a)}`,key:f(o)}}async function V({ciphertext:e,key:t}){const[n,r]=e.split("-"),o=new Uint8Array(atob(t).split("").map(B=>B.charCodeAt(0))),i=g(n),s=g(r),a=await crypto.subtle.importKey("raw",o,{name:"AES-GCM"},!1,["decrypt"]),d=new TextDecoder,h=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(i)},a,s);return JSON.parse(d.decode(h))}function f(e){const t=new Uint8Array(e);let n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}function g(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}async function ce(e){const t=await fetch(e.url,{method:"GET"});if(!t.ok)throw new Error(`Failed to get connection: ${await t.text()}`);const n=await t.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 o=n.sealed[n.sealed.length-1],i=await V({ciphertext:o,key:e.key});return n.status==="completed"?{...r,result:i.result}:{...r,tx:i.tx}}class de{constructor(t){c(this,"endpoint");this.endpoint=t}async create(t,n){const r=await I(t),o={metadata:n,sealed:r.ciphertext},i=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!i.ok)throw new Error(`Failed to create connection: ${await i.text()}`);const s=await i.json();return{id:s.id,version:s.version,status:s.status,metadata:n,data:t,key:r.key}}async update(t,n,r,o,i){const s=await I(n,i),a={sealed:s.ciphertext,version:r,status:o},d=await fetch(`${this.endpoint}/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});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:s.key}}async get(t,n){const r=await fetch(`${this.endpoint}/${t}`,{method:"GET"});if(!r.ok)throw new Error(`Failed to get connection: ${await r.text()}`);const o=await r.json(),i=o.sealed[o.sealed.length-1],s=await V({ciphertext:i,key:n});return{id:o.id,status:o.status,version:o.version,metadata:o.metadata,data:s,key:n}}async close(t){const n=await fetch(`${this.endpoint}/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(`Failed to close connection: ${await n.text()}`)}}class le{constructor(t){c(this,"nodeUrl");c(this,"authToken");c(this,"uxUrl");c(this,"theme");c(this,"locale");this.uxUrl=t.uxUrl||"https://connect.notabene.id",this.nodeUrl=t.nodeUrl,this.authToken=t.authToken,this.theme=t.theme,this.locale=t.locale}componentUrl(t,n,r,o){const i=new URL(this.uxUrl);i.pathname=t;const s=F({authToken:this.authToken,value:n,configuration:r});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()}createComponent(t,n,r,o){return new D(this.componentUrl(t,n,r,o),n,r)}createWithdrawalAssist(t,n,r){return this.createComponent("withdrawal-assist",t,n,r)}createConnectWallet(t,n,r){return this.createComponent("connect",t,n,r)}createDepositRequest(t,n,r){return this.createComponent("deposit-request",t,n,r)}createDepositAssist(t,n,r){return this.createComponent("deposit-assist",t,n,r)}}exports.AgentType=N;exports.CMType=l;exports.CodeVerificationStatus=P;exports.ConnectionManager=de;exports.EmbeddedComponent=D;exports.ErrorIdentifierCode=v;exports.HMType=b;exports.IdentityVerificationMethod=L;exports.OAuthProvider=R;exports.PersonType=m;exports.ProofStatus=_;exports.ProofTypes=O;exports.Status=w;exports.VASPSearchControl=C;exports.ValidationSections=S;exports.WarningIdentifierCode=T;exports.componentResponseToIVMS101=ae;exports.componentResponseToTxCreateRequest=se;exports.componentResponseToTxRequests=ie;exports.componentResponseToV1TxCreateRequest=oe;exports.decodeFragmentToObject=J;exports.default=le;exports.getRefreshResult=ce;
@@ -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.14.0-next.3",
13
+ "version": "2.14.0-next.4",
14
14
  "source": "src/notabene.ts",
15
15
  "main": "dist/cjs/notabene.cjs",
16
16
  "module": "dist/esm/notabene.js",