@notabene/javascript-sdk 2.12.0 → 2.13.0
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/README.md +45 -4
- package/dist/cjs/notabene.cjs +1 -1
- package/dist/cjs/notabene.d.ts +15 -2
- package/dist/cjs/package.json +1 -1
- package/dist/esm/notabene.d.ts +15 -2
- package/dist/esm/notabene.js +106 -105
- package/dist/esm/package.json +1 -1
- package/dist/notabene.d.ts +15 -2
- package/dist/notabene.js +106 -105
- package/docs/README.md +0 -4
- package/docs/_media/TransactionOptions.md +0 -4
- package/docs/types/interfaces/TransactionOptions.md +0 -4
- package/package.json +1 -1
- package/src/notabene.ts +2 -0
- package/src/types.ts +15 -2
- package/src/utils/arbitraries.ts +0 -1
package/README.md
CHANGED
|
@@ -50,6 +50,8 @@ This library is the JavaScript SDK for loading the Notabene UX components in the
|
|
|
50
50
|
- [Retrieving Completed Data](#retrieving-completed-data)
|
|
51
51
|
- [Error handling](#error-handling)
|
|
52
52
|
- [Error reference](#error-reference)
|
|
53
|
+
- [Warning Message handling](#warning-message-handling)
|
|
54
|
+
- [Warning reference](#warning-reference)
|
|
53
55
|
- [Transaction parameters](#transaction-parameters)
|
|
54
56
|
- [Asset specification](#asset-specification)
|
|
55
57
|
- [Transaction amount](#transaction-amount)
|
|
@@ -206,6 +208,12 @@ To be notified of any validation errors use:
|
|
|
206
208
|
withdrawal.on('error',error => ...)
|
|
207
209
|
```
|
|
208
210
|
|
|
211
|
+
To be notified of any errors that won't require remounting the instance use:
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
withdrawal.on('warning', error => ...)
|
|
215
|
+
```
|
|
216
|
+
|
|
209
217
|
To be notified when the component is Ready:
|
|
210
218
|
|
|
211
219
|
```js
|
|
@@ -344,7 +352,6 @@ const withdrawal = notabene.createWithdrawalAssist(
|
|
|
344
352
|
microTransfer: {
|
|
345
353
|
destination: '0x...',
|
|
346
354
|
amountSubunits: '12344',
|
|
347
|
-
timeout: 86440,
|
|
348
355
|
},
|
|
349
356
|
},
|
|
350
357
|
},
|
|
@@ -648,6 +655,43 @@ component.on('error', (error) => {
|
|
|
648
655
|
| WALLET_CONNECTION_FAILED | The connection to the wallet service failed, possibly due to network issues or unsupported wallet types. | ✅ |
|
|
649
656
|
| WALLET_NOT_SUPPORTED | The wallet used does not support the required functionality or blockchain. | |
|
|
650
657
|
|
|
658
|
+
## Warning Message Handling
|
|
659
|
+
|
|
660
|
+
Warning messages include an identifier code to help developers diagnose and handle specific error conditions.
|
|
661
|
+
|
|
662
|
+
```ts
|
|
663
|
+
component.on('warning', (event) => {
|
|
664
|
+
switch(event.identifier) {
|
|
665
|
+
case WarningIdentifierCode.WALLET_ADDRESS_NOT_CONNECTED:
|
|
666
|
+
// Handle wallet connection issue
|
|
667
|
+
break;
|
|
668
|
+
case WarningIdentifierCode.IDV_UNAVAILABLE:
|
|
669
|
+
// Handle identity verification service unavailability
|
|
670
|
+
break;
|
|
671
|
+
case WarningIdentifierCode.WALLET_LOCKED:
|
|
672
|
+
// Handle wallet locked or password is either not entered or invalid
|
|
673
|
+
break;
|
|
674
|
+
case WarningIdentifierCode.WALLET_UNREACHABLE:
|
|
675
|
+
// Handle wallet connection failure
|
|
676
|
+
break;
|
|
677
|
+
case WarningIdentifierCode.JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE:
|
|
678
|
+
// Handle jurisdictional compliance check failure
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
### Warning Reference
|
|
685
|
+
|
|
686
|
+
| Identifier Code | Description | Status |
|
|
687
|
+
|----------------|-------------|--------|
|
|
688
|
+
| `WALLET_ADDRESS_NOT_CONNECTED` | The specified wallet address is not connected to the selected wallet | ✅ Active |
|
|
689
|
+
| `IDV_UNAVAILABLE` | Identity verification service is unavailable for the transaction | ✅ Active |
|
|
690
|
+
| `WALLET_LOCKED` | The wallet in use is either locked or not open. | ✅ Active |
|
|
691
|
+
| `WALLET_UNREACHABLE` | Connection to wallet failed due to network issues or unsupported wallet type | ✅ Active |
|
|
692
|
+
| `JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE` | Unable to retrieve jurisdictional compliance requirements | ✅ Active |
|
|
693
|
+
|
|
694
|
+
|
|
651
695
|
## Transaction parameters
|
|
652
696
|
|
|
653
697
|
### Asset specification
|
|
@@ -714,7 +758,6 @@ const options: TransactionOptions = {
|
|
|
714
758
|
microTransfer: {
|
|
715
759
|
destination: '0x...',
|
|
716
760
|
amountSubunits: '12344',
|
|
717
|
-
timeout: 86440,
|
|
718
761
|
},
|
|
719
762
|
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration], // js ['screenshot','self-declaration']
|
|
720
763
|
deminimis: {
|
|
@@ -786,7 +829,6 @@ withdrawal.update(
|
|
|
786
829
|
microTransfer: {
|
|
787
830
|
destination: '0x...',
|
|
788
831
|
amountSubunits: '12344',
|
|
789
|
-
timeout: 86440,
|
|
790
832
|
},
|
|
791
833
|
},
|
|
792
834
|
},
|
|
@@ -867,7 +909,6 @@ const options: TransactionOptions = {
|
|
|
867
909
|
microTransfer: {
|
|
868
910
|
destination: '0x...',
|
|
869
911
|
amountSubunits: '1234',
|
|
870
|
-
timeout: 86440, // Optional timeout in seconds, which is displayed to the user
|
|
871
912
|
},
|
|
872
913
|
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration], // js ['screenshot','self_declaration']
|
|
873
914
|
},
|
package/dist/cjs/notabene.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var D=(e,t,n)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var a=(e,t,n)=>D(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var f=(e=>(e.PRIVATE="WALLET",e.VASP="VASP",e))(f||{}),w=(e=>(e.NATURAL="natural",e.LEGAL="legal",e.SELF="self",e))(w||{}),A=(e=>(e.EMPTY="empty",e.VERIFY="verify",e.PENDING="pending",e.VERIFIED="verified",e.BANNED="banned",e))(A||{}),v=(e=>(e.ALLOWED="allowed",e.PENDING="pending",e))(v||{}),g=(e=>(e.SMS="sms",e.EMAIL="email",e))(g||{}),I=(e=>(e.PENDING="pending",e.APPROVED="approved",e.FAILED="failed",e.EXPIRED="expired",e.MAX_ATTEMPTS_REACHED="max_attempts_reached",e.UNREACHABLE="unreachable",e))(I||{}),y=(e=>(e.COINBASE="coinbase",e))(y||{}),N=(e=>(e.ASSET="asset",e.DESTINATION="destination",e.COUNTERPARTY="counterparty",e.AGENT="agent",e))(N||{}),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||{}),b=(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))(b||{}),E=(e=>(e.UPDATE="update",e.REQUEST_RESPONSE="requestResponse",e))(E||{}),C=(e=>(e.PENDING="pending",e.FAILED="rejected",e.FLAGGED="flagged",e.VERIFIED="verified",e))(C||{}),L=(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))(L||{});class S{constructor(){a(this,"listeners",new Map);a(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,s=this.listeners.get(r);s&&s.forEach(i=>i(n))}}send(t){this.port&&this.port.postMessage(t)}}class _{constructor(t,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=t,this._value=n,this._options=r,this.eventManager=new S,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(t){const n=document.querySelector(t);if(!n)throw new Error(`parentID ${t} not found`);this.embed(n)}embed(t,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",t.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(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:E.UPDATE,value:t,options:this._options})}completion(){return new Promise((t,n)=>{let r,s,i;function o(){r&&r(),s&&s(),i&&i()}r=this.on(l.COMPLETE,c=>{t(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 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",s=>{var i;s.source===t&&(console.log("received message from popup",s.data),(i=this.eventManager)==null||i.setPort(s.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 x(e){return Object.entries(e).map(([t,n])=>{if(n==null)return;const r=encodeURIComponent(t),s=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${s}`}).filter(t=>t!==void 0).join("&")}function M(e){const t=e.slice(1);return t?t.split("&").filter(Boolean).reduce((r,s)=>{const[i,o]=s.split("=");return i&&(r[decodeURIComponent(i)]=o?decodeURIComponent(o):""),r},{}):{}}async function p(e,t){const n=JSON.stringify(e),r=new TextEncoder,s=t?m(t):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 O({ciphertext:e,key:t}){const[n,r]=e.split("-"),s=new Uint8Array(atob(t).split("").map(R=>R.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(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 m(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 P(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 s=n.sealed[n.sealed.length-1],i=await O({ciphertext:s,key:e.key});return n.status==="completed"?{...r,result:i.result}:{...r,tx:i.tx}}class T{constructor(t){a(this,"endpoint");this.endpoint=t}async create(t,n){const r=await p(t),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:t,key:r.key}}async update(t,n,r,s,i){const o=await p(n,i),c={sealed:o.ciphertext,version:r,status:s},d=await fetch(`${this.endpoint}/${t}`,{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(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 s=await r.json(),i=s.sealed[s.sealed.length-1],o=await O({ciphertext:i,key:n});return{id:s.id,status:s.status,version:s.version,metadata:s.metadata,data:o,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 k{constructor(t){a(this,"nodeUrl");a(this,"authToken");a(this,"uxUrl");a(this,"theme");a(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,s){const i=new URL(this.uxUrl);i.pathname=t;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(t,n,r,s){return new _(this.componentUrl(t,n,r,s),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=f;exports.CMType=l;exports.CodeVerificationStatus=I;exports.ConnectionManager=T;exports.EmbeddedComponent=_;exports.ErrorIdentifierCode=b;exports.HMType=E;exports.IdentityVerificationMethod=g;exports.OAuthProvider=y;exports.PersonType=w;exports.ProofStatus=C;exports.ProofTypes=L;exports.Status=A;exports.VASPSearchControl=v;exports.ValidationSections=N;exports.decodeFragmentToObject=M;exports.default=k;exports.getRefreshResult=P;
|
|
1
|
+
"use strict";var O=Object.defineProperty;var S=(e,t,n)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var a=(e,t,n)=>S(e,typeof t!="symbol"?t+"":t,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var A=(e=>(e.PRIVATE="WALLET",e.VASP="VASP",e))(A||{}),f=(e=>(e.NATURAL="natural",e.LEGAL="legal",e.SELF="self",e))(f||{}),w=(e=>(e.EMPTY="empty",e.VERIFY="verify",e.PENDING="pending",e.VERIFIED="verified",e.BANNED="banned",e))(w||{}),L=(e=>(e.ALLOWED="allowed",e.PENDING="pending",e))(L||{}),N=(e=>(e.SMS="sms",e.EMAIL="email",e))(N||{}),v=(e=>(e.PENDING="pending",e.APPROVED="approved",e.FAILED="failed",e.EXPIRED="expired",e.MAX_ATTEMPTS_REACHED="max_attempts_reached",e.UNREACHABLE="unreachable",e))(v||{}),I=(e=>(e.COINBASE="coinbase",e))(I||{}),g=(e=>(e.ASSET="asset",e.DESTINATION="destination",e.COUNTERPARTY="counterparty",e.AGENT="agent",e))(g||{}),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||{}),_=(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=(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))(C||{}),m=(e=>(e.UPDATE="update",e.REQUEST_RESPONSE="requestResponse",e))(m||{}),y=(e=>(e.PENDING="pending",e.FAILED="rejected",e.FLAGGED="flagged",e.VERIFIED="verified",e))(y||{}),D=(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))(D||{});class T{constructor(){a(this,"listeners",new Map);a(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,s=this.listeners.get(r);s&&s.forEach(o=>o(n))}}send(t){this.port&&this.port.postMessage(t)}}class R{constructor(t,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=t,this._value=n,this._options=r,this.eventManager=new T,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(t){const n=document.querySelector(t);if(!n)throw new Error(`parentID ${t} not found`);this.embed(n)}embed(t,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",t.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(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:m.UPDATE,value:t,options:this._options})}completion(){return new Promise((t,n)=>{let r,s,o;function i(){r&&r(),s&&s(),o&&o()}r=this.on(l.COMPLETE,c=>{t(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 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",s=>{var o;s.source===t&&(console.log("received message from popup",s.data),(o=this.eventManager)==null||o.setPort(s.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 M(e){return Object.entries(e).map(([t,n])=>{if(n==null)return;const r=encodeURIComponent(t),s=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${s}`}).filter(t=>t!==void 0).join("&")}function x(e){const t=e.slice(1);return t?t.split("&").filter(Boolean).reduce((r,s)=>{const[o,i]=s.split("=");return o&&(r[decodeURIComponent(o)]=i?decodeURIComponent(i):""),r},{}):{}}async function p(e,t){const n=JSON.stringify(e),r=new TextEncoder,s=t?E(t):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 U({ciphertext:e,key:t}){const[n,r]=e.split("-"),s=new Uint8Array(atob(t).split("").map(b=>b.charCodeAt(0))),o=E(n),i=E(r),c=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["decrypt"]),h=new TextDecoder,d=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(o)},c,i);return JSON.parse(h.decode(d))}function u(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 E(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 P(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 s=n.sealed[n.sealed.length-1],o=await U({ciphertext:s,key:e.key});return n.status==="completed"?{...r,result:o.result}:{...r,tx:o.tx}}class B{constructor(t){a(this,"endpoint");this.endpoint=t}async create(t,n){const r=await p(t),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:t,key:r.key}}async update(t,n,r,s,o){const i=await p(n,o),c={sealed:i.ciphertext,version:r,status:s},h=await fetch(`${this.endpoint}/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!h.ok)throw new Error(`Failed to update connection: ${await h.text()}`);const d=await h.json();return{id:d.id,metadata:d.metadata,version:d.version,status:d.status,data:n,key:i.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 s=await r.json(),o=s.sealed[s.sealed.length-1],i=await U({ciphertext:o,key:n});return{id:s.id,status:s.status,version:s.version,metadata:s.metadata,data:i,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 k{constructor(t){a(this,"nodeUrl");a(this,"authToken");a(this,"uxUrl");a(this,"theme");a(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,s){const o=new URL(this.uxUrl);o.pathname=t;const i=M({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(t,n,r,s){return new R(this.componentUrl(t,n,r,s),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=A;exports.CMType=l;exports.CodeVerificationStatus=v;exports.ConnectionManager=B;exports.EmbeddedComponent=R;exports.ErrorIdentifierCode=_;exports.HMType=m;exports.IdentityVerificationMethod=N;exports.OAuthProvider=I;exports.PersonType=f;exports.ProofStatus=y;exports.ProofTypes=D;exports.Status=w;exports.VASPSearchControl=L;exports.ValidationSections=g;exports.WarningIdentifierCode=C;exports.decodeFragmentToObject=x;exports.default=k;exports.getRefreshResult=P;
|
package/dist/cjs/notabene.d.ts
CHANGED
|
@@ -1308,7 +1308,7 @@ declare type Originator = {
|
|
|
1308
1308
|
* @public
|
|
1309
1309
|
*/
|
|
1310
1310
|
declare type OriginatorFields = {
|
|
1311
|
-
source?: Source;
|
|
1311
|
+
source?: Source | Source[];
|
|
1312
1312
|
};
|
|
1313
1313
|
|
|
1314
1314
|
/**
|
|
@@ -1690,7 +1690,6 @@ export declare interface TransactionOptions {
|
|
|
1690
1690
|
microTransfer?: {
|
|
1691
1691
|
destination: BlockchainAddress;
|
|
1692
1692
|
amountSubunits: string;
|
|
1693
|
-
timeout?: number;
|
|
1694
1693
|
};
|
|
1695
1694
|
fallbacks?: ProofTypes[];
|
|
1696
1695
|
deminimis?: ThresholdOptions;
|
|
@@ -1915,14 +1914,28 @@ export declare interface Wallet extends Agent {
|
|
|
1915
1914
|
* Represents a warning component message
|
|
1916
1915
|
* @param message - Warning message
|
|
1917
1916
|
* @param description - Description of the warning message
|
|
1917
|
+
* @param identifier - Identifier code of the warning message
|
|
1918
1918
|
* @public
|
|
1919
1919
|
*/
|
|
1920
1920
|
declare type Warning = {
|
|
1921
1921
|
type: CMType.WARNING;
|
|
1922
1922
|
message: string;
|
|
1923
1923
|
description?: string;
|
|
1924
|
+
identifier?: WarningIdentifierCode;
|
|
1924
1925
|
};
|
|
1925
1926
|
|
|
1927
|
+
/**
|
|
1928
|
+
* Identifier codes for warning messages
|
|
1929
|
+
* @public
|
|
1930
|
+
*/
|
|
1931
|
+
export declare enum WarningIdentifierCode {
|
|
1932
|
+
WALLET_ADDRESS_NOT_CONNECTED = "WALLET_ADDRESS_NOT_CONNECTED",
|
|
1933
|
+
WALLET_LOCKED = "WALLET_LOCKED",
|
|
1934
|
+
WALLET_UNREACHABLE = "WALLET_UNREACHABLE",
|
|
1935
|
+
JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE = "JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE",
|
|
1936
|
+
IDV_UNAVAILABLE = "IDV_UNAVAILABLE"
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1926
1939
|
/**
|
|
1927
1940
|
* An object representing a withdrawal transaction
|
|
1928
1941
|
* @public
|
package/dist/cjs/package.json
CHANGED
package/dist/esm/notabene.d.ts
CHANGED
|
@@ -1308,7 +1308,7 @@ declare type Originator = {
|
|
|
1308
1308
|
* @public
|
|
1309
1309
|
*/
|
|
1310
1310
|
declare type OriginatorFields = {
|
|
1311
|
-
source?: Source;
|
|
1311
|
+
source?: Source | Source[];
|
|
1312
1312
|
};
|
|
1313
1313
|
|
|
1314
1314
|
/**
|
|
@@ -1690,7 +1690,6 @@ export declare interface TransactionOptions {
|
|
|
1690
1690
|
microTransfer?: {
|
|
1691
1691
|
destination: BlockchainAddress;
|
|
1692
1692
|
amountSubunits: string;
|
|
1693
|
-
timeout?: number;
|
|
1694
1693
|
};
|
|
1695
1694
|
fallbacks?: ProofTypes[];
|
|
1696
1695
|
deminimis?: ThresholdOptions;
|
|
@@ -1915,14 +1914,28 @@ export declare interface Wallet extends Agent {
|
|
|
1915
1914
|
* Represents a warning component message
|
|
1916
1915
|
* @param message - Warning message
|
|
1917
1916
|
* @param description - Description of the warning message
|
|
1917
|
+
* @param identifier - Identifier code of the warning message
|
|
1918
1918
|
* @public
|
|
1919
1919
|
*/
|
|
1920
1920
|
declare type Warning = {
|
|
1921
1921
|
type: CMType.WARNING;
|
|
1922
1922
|
message: string;
|
|
1923
1923
|
description?: string;
|
|
1924
|
+
identifier?: WarningIdentifierCode;
|
|
1924
1925
|
};
|
|
1925
1926
|
|
|
1927
|
+
/**
|
|
1928
|
+
* Identifier codes for warning messages
|
|
1929
|
+
* @public
|
|
1930
|
+
*/
|
|
1931
|
+
export declare enum WarningIdentifierCode {
|
|
1932
|
+
WALLET_ADDRESS_NOT_CONNECTED = "WALLET_ADDRESS_NOT_CONNECTED",
|
|
1933
|
+
WALLET_LOCKED = "WALLET_LOCKED",
|
|
1934
|
+
WALLET_UNREACHABLE = "WALLET_UNREACHABLE",
|
|
1935
|
+
JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE = "JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE",
|
|
1936
|
+
IDV_UNAVAILABLE = "IDV_UNAVAILABLE"
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1926
1939
|
/**
|
|
1927
1940
|
* An object representing a withdrawal transaction
|
|
1928
1941
|
* @public
|