@notabene/javascript-sdk 2.12.0 → 2.13.0-next.2
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 +237 -2
- package/dist/cjs/package.json +6 -2
- package/dist/esm/notabene.d.ts +237 -2
- package/dist/esm/notabene.js +447 -133
- package/dist/esm/package.json +6 -2
- package/dist/notabene.d.ts +237 -2
- package/dist/notabene.js +447 -133
- package/docs/README.md +0 -4
- package/docs/_media/TransactionOptions.md +0 -4
- package/docs/types/interfaces/TransactionOptions.md +0 -4
- package/package.json +6 -2
- package/src/ivms/index.ts +5 -0
- package/src/ivms/v2Types.ts +35 -0
- package/src/notabene.ts +14 -0
- package/src/responseTransformer/README.md +164 -0
- package/src/responseTransformer/index.ts +21 -0
- package/src/responseTransformer/mappers.ts +293 -0
- package/src/responseTransformer/transformer.ts +278 -0
- package/src/responseTransformer/types.ts +60 -0
- package/src/responseTransformer/utils.ts +61 -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 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;
|
package/dist/cjs/notabene.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { Agent as Agent_2 } from '@taprsvp/types';
|
|
2
|
+
import type { DID as DID_2 } from '@taprsvp/types';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* A blockchain account
|
|
3
6
|
* @public
|
|
@@ -99,6 +102,11 @@ declare type BeneficiaryFields = {
|
|
|
99
102
|
destination?: Destination;
|
|
100
103
|
};
|
|
101
104
|
|
|
105
|
+
declare type BeneficiaryV2 = {
|
|
106
|
+
beneficiaryPerson: PersonV2[];
|
|
107
|
+
customerIdentification?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
102
110
|
/**
|
|
103
111
|
* Beneficiary VASP
|
|
104
112
|
* Represents the VASP which receives the VA transfer
|
|
@@ -320,6 +328,151 @@ export declare interface ComponentResponse {
|
|
|
320
328
|
errors: ValidationError[];
|
|
321
329
|
}
|
|
322
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Transforms a Notabene component response to IVMS101 format
|
|
333
|
+
*
|
|
334
|
+
* @param response - The response from the Notabene Embedded Component
|
|
335
|
+
* @param delegateToken - The JWT delegate token for extracting the originator ID
|
|
336
|
+
* @param config - Configuration object with optional IDs
|
|
337
|
+
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken if not provided)
|
|
338
|
+
* @param config.beneficiaryId - Optional beneficiary ID (auto-generated if not provided)
|
|
339
|
+
* @param config.referenceId - Optional reference ID for the transaction
|
|
340
|
+
* @param config.originator - Optional originator data in V2 format
|
|
341
|
+
* @returns The transformed request body in IVMS101 format
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* import { componentResponseToIVMS101 } from '$lib/notabene-tx-transformer';
|
|
346
|
+
*
|
|
347
|
+
* const requestBody = componentResponseToIVMS101(
|
|
348
|
+
* result.response,
|
|
349
|
+
* session.user.token,
|
|
350
|
+
* { originator: myOriginatorData }
|
|
351
|
+
* );
|
|
352
|
+
*
|
|
353
|
+
* await fetch('/entity/${vaspDid}/tx/${txId}/append', {
|
|
354
|
+
* method: 'POST',
|
|
355
|
+
* body: JSON.stringify(requestBody)
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
export declare function componentResponseToIVMS101(response: TransactionResponse<Withdrawal>, delegateToken: string, config?: ResponseToTxRequestConfig): TransactionIVMS101Request;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Transforms a Notabene component response to a Version 2 transaction create API request body
|
|
363
|
+
*
|
|
364
|
+
* @param response - The response from the Notabene Embedded Component
|
|
365
|
+
* @param delegateToken - The JWT delegate token for extracting the originator ID
|
|
366
|
+
* @param config - Configuration object with optional IDs
|
|
367
|
+
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken if not provided)
|
|
368
|
+
* @param config.beneficiaryId - Optional beneficiary ID (auto-generated if not provided)
|
|
369
|
+
* @param config.referenceId - Optional reference ID for the transaction
|
|
370
|
+
* @returns The transformed request body ready for the Version 2 transaction create API
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* import { componentResponseToTxCreateRequest } from '$lib/notabene-tx-transformer';
|
|
375
|
+
*
|
|
376
|
+
* withdrawal.on('complete', async (result) => {
|
|
377
|
+
* const requestBody = componentResponseToTxCreateRequest(
|
|
378
|
+
* result.response,
|
|
379
|
+
* {
|
|
380
|
+
* originatorId: 'mailto:user@example.com',
|
|
381
|
+
* beneficiaryId: 'urn:beneficiary:recipient',
|
|
382
|
+
* referenceId: 'tx-12345'
|
|
383
|
+
* }
|
|
384
|
+
* );
|
|
385
|
+
*
|
|
386
|
+
* await fetch('/entity/${vaspDid}/tx', {
|
|
387
|
+
* method: 'POST',
|
|
388
|
+
* body: JSON.stringify(requestBody)
|
|
389
|
+
* });
|
|
390
|
+
* });
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
export declare function componentResponseToTxCreateRequest(response: TransactionResponse<Withdrawal>, delegateToken: string, config?: Omit<ResponseToTxRequestConfig, 'originator'>): TransactionCreateRequestV2;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Transforms a Notabene component response into txCreate, IVMS101, and confirmRelationship request bodies
|
|
397
|
+
*
|
|
398
|
+
* This is a convenience function that generates the transaction creation request,
|
|
399
|
+
* the IVMS101 data, and optionally the relationship confirmation proof in a single call,
|
|
400
|
+
* which is useful for V2 workflows where you need to create a transaction first,
|
|
401
|
+
* then append IVMS101 data to it, and finally confirm the relationship.
|
|
402
|
+
*
|
|
403
|
+
* @param response - The response from the Notabene Embedded Component
|
|
404
|
+
* @param delegateToken - The JWT delegate token for extracting the originator ID
|
|
405
|
+
* @param config - Optional configuration for IDs and reference
|
|
406
|
+
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken if not provided)
|
|
407
|
+
* @param config.beneficiaryId - Optional beneficiary ID (auto-generated if not provided)
|
|
408
|
+
* @param config.referenceId - Optional reference ID (auto-generated if not provided)
|
|
409
|
+
* @param config.originator - Optional originator data in V2 format
|
|
410
|
+
* @returns Object with `createTx`, `ivms101`, and optional `confirmRelationship` properties containing the respective request bodies
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```typescript
|
|
414
|
+
* import { componentResponseToTxRequests } from '$lib/notabene-tx-transformer';
|
|
415
|
+
*
|
|
416
|
+
* withdrawal.on('complete', async (result) => {
|
|
417
|
+
* const { createTx, ivms101, confirmRelationship } = componentResponseToTxRequests(
|
|
418
|
+
* result.response,
|
|
419
|
+
* session.user.token,
|
|
420
|
+
* { originator: originatorData }
|
|
421
|
+
* );
|
|
422
|
+
*
|
|
423
|
+
* // First, create the transaction
|
|
424
|
+
* const txResponse = await fetch('/entity/${vaspDid}/tx', {
|
|
425
|
+
* method: 'POST',
|
|
426
|
+
* body: JSON.stringify(createTx)
|
|
427
|
+
* });
|
|
428
|
+
*
|
|
429
|
+
* // Then, append IVMS101 data
|
|
430
|
+
* const txId = txResponse.transfer['@id'];
|
|
431
|
+
* await fetch(`/entity/${vaspDid}/tx/${txId}/append`, {
|
|
432
|
+
* method: 'POST',
|
|
433
|
+
* body: JSON.stringify(ivms101)
|
|
434
|
+
* });
|
|
435
|
+
*
|
|
436
|
+
* // Finally, confirm relationship
|
|
437
|
+
* if (confirmRelationship) {
|
|
438
|
+
* await fetch(`/entity/${vaspDid}/relationship?to=${to}&from=${from}`, {
|
|
439
|
+
* method: 'PATCH',
|
|
440
|
+
* body: JSON.stringify({ proof: confirmRelationship.proof })
|
|
441
|
+
* });
|
|
442
|
+
* }
|
|
443
|
+
* });
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
export declare function componentResponseToTxRequests(response: TransactionResponse<Withdrawal>, delegateToken: string, config?: ResponseToTxRequestConfig): {
|
|
447
|
+
createTx: TransactionCreateRequestV2;
|
|
448
|
+
ivms101: TransactionIVMS101Request;
|
|
449
|
+
confirmRelationship?: {
|
|
450
|
+
proof: OwnershipProof;
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Transforms a Notabene component response to a Version 1 API request body
|
|
456
|
+
*
|
|
457
|
+
* @param response - The response from the Notabene TX Create component
|
|
458
|
+
* @returns The transformed request body ready for the Version 1 API
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```typescript
|
|
462
|
+
* import { componentResponseToV1TxCreateRequest } from '$lib/notabene-tx-transformer';
|
|
463
|
+
*
|
|
464
|
+
* withdrawal.on('complete', async (result) => {
|
|
465
|
+
* const requestBody = componentResponseToV1TxCreateRequest(result.response);
|
|
466
|
+
*
|
|
467
|
+
* await fetch(endpointUrl, {
|
|
468
|
+
* method: 'POST',
|
|
469
|
+
* body: JSON.stringify(requestBody)
|
|
470
|
+
* });
|
|
471
|
+
* });
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
export declare function componentResponseToV1TxCreateRequest(response: TransactionResponse<Withdrawal>): TransactionCreateRequest;
|
|
475
|
+
|
|
323
476
|
export declare interface ConnectionData<T extends ComponentRequest> {
|
|
324
477
|
readonly tx: T;
|
|
325
478
|
readonly authToken?: string;
|
|
@@ -1132,6 +1285,12 @@ declare type NaturalPersonNameID = {
|
|
|
1132
1285
|
nameIdentifierType?: NaturalPersonNameTypeCode;
|
|
1133
1286
|
};
|
|
1134
1287
|
|
|
1288
|
+
declare type NaturalPersonNameIDV2 = {
|
|
1289
|
+
primaryIdentifier?: string;
|
|
1290
|
+
secondaryIdentifier?: string;
|
|
1291
|
+
naturalPersonNameIdentifierType?: NaturalPersonNameTypeCode;
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1135
1294
|
/**
|
|
1136
1295
|
* Natural Person Name Type Code
|
|
1137
1296
|
* Specifies the type of name for a natural person
|
|
@@ -1140,6 +1299,14 @@ declare type NaturalPersonNameID = {
|
|
|
1140
1299
|
*/
|
|
1141
1300
|
declare type NaturalPersonNameTypeCode = 'ALIA' | 'BIRT' | 'MAID' | 'LEGL' | 'MISC';
|
|
1142
1301
|
|
|
1302
|
+
declare type NaturalPersonNameV2 = Omit<NaturalPersonName, 'nameIdentifier'> & {
|
|
1303
|
+
nameIdentifier?: NaturalPersonNameIDV2[];
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
declare type NaturalPersonV2 = Omit<NaturalPerson_2, 'name'> & {
|
|
1307
|
+
name: NaturalPersonNameV2;
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1143
1310
|
/**
|
|
1144
1311
|
* Primary constructor for Notabene UX elements
|
|
1145
1312
|
*
|
|
@@ -1308,7 +1475,12 @@ declare type Originator = {
|
|
|
1308
1475
|
* @public
|
|
1309
1476
|
*/
|
|
1310
1477
|
declare type OriginatorFields = {
|
|
1311
|
-
source?: Source;
|
|
1478
|
+
source?: Source | Source[];
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
declare type OriginatorV2 = {
|
|
1482
|
+
originatorPerson: PersonV2[];
|
|
1483
|
+
customerIdentification?: string;
|
|
1312
1484
|
};
|
|
1313
1485
|
|
|
1314
1486
|
/**
|
|
@@ -1399,6 +1571,11 @@ export declare enum PersonType {
|
|
|
1399
1571
|
SELF = "self"
|
|
1400
1572
|
}
|
|
1401
1573
|
|
|
1574
|
+
declare type PersonV2 = Omit<Person, 'naturalPerson'> & {
|
|
1575
|
+
naturalPerson?: NaturalPersonV2;
|
|
1576
|
+
accountNumber?: string[];
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1402
1579
|
/**
|
|
1403
1580
|
* Status of the ownership proof verification process
|
|
1404
1581
|
*
|
|
@@ -1497,6 +1674,13 @@ export declare type ResizeRequest = {
|
|
|
1497
1674
|
height: number;
|
|
1498
1675
|
};
|
|
1499
1676
|
|
|
1677
|
+
export declare interface ResponseToTxRequestConfig {
|
|
1678
|
+
originatorId?: DID_2;
|
|
1679
|
+
beneficiaryId?: DID_2;
|
|
1680
|
+
referenceId?: string;
|
|
1681
|
+
originator?: OriginatorV2;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1500
1684
|
/**
|
|
1501
1685
|
* Ownership Proof using Screenshot
|
|
1502
1686
|
* @public
|
|
@@ -1680,6 +1864,44 @@ export declare interface Transaction extends ComponentRequest {
|
|
|
1680
1864
|
*/
|
|
1681
1865
|
export declare type TransactionAsset = NotabeneAsset | CAIP19 | DTI;
|
|
1682
1866
|
|
|
1867
|
+
export declare interface TransactionCreateRequest {
|
|
1868
|
+
transactionAsset: any;
|
|
1869
|
+
transactionAmount: string;
|
|
1870
|
+
beneficiaryDid?: string;
|
|
1871
|
+
originatorVASPdid: string;
|
|
1872
|
+
beneficiaryVASPdid?: string;
|
|
1873
|
+
beneficiaryVASPname?: string;
|
|
1874
|
+
beneficiaryVASPwebsite?: string;
|
|
1875
|
+
transactionBlockchainInfo: {
|
|
1876
|
+
origin?: string;
|
|
1877
|
+
destination?: string;
|
|
1878
|
+
};
|
|
1879
|
+
beneficiaryProof?: any;
|
|
1880
|
+
beneficiary?: any;
|
|
1881
|
+
originator?: any;
|
|
1882
|
+
originatorEqualsBeneficiary?: boolean;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
export declare interface TransactionCreateRequestV2 {
|
|
1886
|
+
originator: {
|
|
1887
|
+
'@id': string;
|
|
1888
|
+
};
|
|
1889
|
+
beneficiary: {
|
|
1890
|
+
'@id': string;
|
|
1891
|
+
};
|
|
1892
|
+
asset: string;
|
|
1893
|
+
amount: string;
|
|
1894
|
+
agents: Agent_2[];
|
|
1895
|
+
ref: string;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
export declare interface TransactionIVMS101Request {
|
|
1899
|
+
ivms101: {
|
|
1900
|
+
originator?: OriginatorV2;
|
|
1901
|
+
beneficiary?: BeneficiaryV2;
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1683
1905
|
/**
|
|
1684
1906
|
* Configuration options for Transaction components
|
|
1685
1907
|
* @public
|
|
@@ -1690,7 +1912,6 @@ export declare interface TransactionOptions {
|
|
|
1690
1912
|
microTransfer?: {
|
|
1691
1913
|
destination: BlockchainAddress;
|
|
1692
1914
|
amountSubunits: string;
|
|
1693
|
-
timeout?: number;
|
|
1694
1915
|
};
|
|
1695
1916
|
fallbacks?: ProofTypes[];
|
|
1696
1917
|
deminimis?: ThresholdOptions;
|
|
@@ -1915,14 +2136,28 @@ export declare interface Wallet extends Agent {
|
|
|
1915
2136
|
* Represents a warning component message
|
|
1916
2137
|
* @param message - Warning message
|
|
1917
2138
|
* @param description - Description of the warning message
|
|
2139
|
+
* @param identifier - Identifier code of the warning message
|
|
1918
2140
|
* @public
|
|
1919
2141
|
*/
|
|
1920
2142
|
declare type Warning = {
|
|
1921
2143
|
type: CMType.WARNING;
|
|
1922
2144
|
message: string;
|
|
1923
2145
|
description?: string;
|
|
2146
|
+
identifier?: WarningIdentifierCode;
|
|
1924
2147
|
};
|
|
1925
2148
|
|
|
2149
|
+
/**
|
|
2150
|
+
* Identifier codes for warning messages
|
|
2151
|
+
* @public
|
|
2152
|
+
*/
|
|
2153
|
+
export declare enum WarningIdentifierCode {
|
|
2154
|
+
WALLET_ADDRESS_NOT_CONNECTED = "WALLET_ADDRESS_NOT_CONNECTED",
|
|
2155
|
+
WALLET_LOCKED = "WALLET_LOCKED",
|
|
2156
|
+
WALLET_UNREACHABLE = "WALLET_UNREACHABLE",
|
|
2157
|
+
JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE = "JURISDICTIONAL_REQUIREMENTS_UNAVAILABLE",
|
|
2158
|
+
IDV_UNAVAILABLE = "IDV_UNAVAILABLE"
|
|
2159
|
+
}
|
|
2160
|
+
|
|
1926
2161
|
/**
|
|
1927
2162
|
* An object representing a withdrawal transaction
|
|
1928
2163
|
* @public
|
package/dist/cjs/package.json
CHANGED
|
@@ -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.
|
|
13
|
+
"version": "2.13.0-next.2",
|
|
14
14
|
"source": "src/notabene.ts",
|
|
15
15
|
"main": "dist/cjs/notabene.cjs",
|
|
16
16
|
"module": "dist/esm/notabene.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"import": "./dist/esm/notabene.js",
|
|
33
33
|
"require": "./dist/cjs/notabene.cjs"
|
|
34
34
|
},
|
|
35
|
-
"./src/ivms/types": "./src/ivms/
|
|
35
|
+
"./src/ivms/types": "./src/ivms/index.ts"
|
|
36
36
|
},
|
|
37
37
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
38
38
|
"publishConfig": {
|
|
@@ -104,5 +104,9 @@
|
|
|
104
104
|
"extends": [
|
|
105
105
|
"@commitlint/config-conventional"
|
|
106
106
|
]
|
|
107
|
+
},
|
|
108
|
+
"dependencies": {
|
|
109
|
+
"@taprsvp/types": "^1.13.0",
|
|
110
|
+
"jose": "^6.1.0"
|
|
107
111
|
}
|
|
108
112
|
}
|