@notabene/javascript-sdk 2.9.0-next.1 → 2.9.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/notabene.cjs +1 -1
- package/dist/cjs/notabene.d.ts +29 -2
- package/dist/cjs/package.json +1 -1
- package/dist/esm/notabene.d.ts +29 -2
- package/dist/esm/notabene.js +148 -115
- package/dist/esm/package.json +1 -1
- package/dist/notabene.d.ts +29 -2
- package/dist/notabene.js +148 -115
- package/package.json +1 -1
- package/src/notabene.ts +7 -0
- package/src/types.ts +13 -0
- package/src/utils/__tests__/connections.test.ts +184 -31
- package/src/utils/connections.ts +74 -2
- package/src/utils/encryption.ts +5 -3
package/dist/cjs/notabene.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var _=(t,e,n)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>_(t,typeof e!="symbol"?e+"":e,n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var f=(t=>(t.PRIVATE="WALLET",t.VASP="VASP",t))(f||{}),w=(t=>(t.NATURAL="natural",t.LEGAL="legal",t.SELF="self",t))(w||{}),g=(t=>(t.EMPTY="empty",t.VERIFY="verify",t.PENDING="pending",t.VERIFIED="verified",t.BANNED="banned",t))(g||{}),v=(t=>(t.ALLOWED="allowed",t.PENDING="pending",t))(v||{}),y=(t=>(t.ASSET="asset",t.DESTINATION="destination",t.COUNTERPARTY="counterparty",t.AGENT="agent",t))(y||{}),l=(t=>(t.COMPLETE="complete",t.RESIZE="resize",t.RESULT="result",t.READY="ready",t.INVALID="invalid",t.ERROR="error",t.CANCEL="cancel",t))(l||{}),A=(t=>(t.SERVICE_UNAVAILABLE="SERVICE_UNAVAILABLE",t.WALLET_CONNECTION_FAILED="WALLET_CONNECTION_FAILED",t.WALLET_NOT_SUPPORTED="WALLET_NOT_SUPPORTED",t.TOKEN_INVALID="TOKEN_INVALID",t))(A||{}),p=(t=>(t.UPDATE="update",t.REQUEST_RESPONSE="requestResponse",t))(p||{}),C=(t=>(t.PENDING="pending",t.FAILED="rejected",t.FLAGGED="flagged",t.VERIFIED="verified",t))(C||{}),b=(t=>(t.SelfDeclaration="self-declaration",t.SIWE="siwe",t.SIWX="siwx",t.EIP191="eip-191",t.EIP712="eip-712",t.EIP1271="eip-1271",t.BIP137="bip-137",t.BIP322="bip-322",t.BIP137_XPUB="xpub",t.TIP191="tip-191",t.ED25519="ed25519",t.XRP_ED25519="xrp-ed25519",t.XLM_ED25519="xlm-ed25519",t.CIP8="cip-8",t.MicroTransfer="microtransfer",t.Screenshot="screenshot",t.Connect="connect",t))(b||{});class R{constructor(){a(this,"listeners",new Map);a(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(e){this.port=e,this.port.onmessage=this.handleMessage,this.port.start()}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>this.off(e,n)}off(e,n){const r=this.listeners.get(e);r&&(r.delete(n),r.size===0&&this.listeners.delete(e))}handleMessage(e){const n=e.data;if(typeof n=="object"&&n!==null&&"type"in n){const r=n.type,s=this.listeners.get(r);s&&s.forEach(i=>i(n))}}send(e){this.port&&this.port.postMessage(e)}}class I{constructor(e,n,r){a(this,"_url");a(this,"_value");a(this,"_options");a(this,"_errors",[]);a(this,"iframe");a(this,"eventManager");a(this,"modal");this._url=e,this._value=n,this._options=r,this.eventManager=new R,this.on(l.INVALID,s=>{s.type===l.INVALID&&(this._errors=s.errors,this._value=s.value)}),this.on(l.RESIZE,s=>{s.type===l.RESIZE&&this.iframe&&(this.iframe.style.height=`${s.height}px`)})}get url(){return this._url}get value(){return this._value}get options(){return this._options}get errors(){return this._errors}open(){document.location.href=this.url}mount(e){const n=document.querySelector(e);if(!n)throw new Error(`parentID ${e} not found`);this.embed(n)}embed(e,n=!1){var r,s;this.removeEmbed(),this.iframe=document.createElement("iframe"),this.iframe.src=this.url+(n?"":"&embedded=true"),this.iframe.allow="web-share; clipboard-write; hid; bluetooth;",this.iframe.style.width="100%",this.iframe.style.height="0px",this.iframe.style.border="none",this.iframe.style.overflow="hidden",this.iframe.scrolling="no",e.appendChild(this.iframe),window.addEventListener("message",i=>{var o,c;i.source===((o=this.iframe)==null?void 0:o.contentWindow)&&((c=this.eventManager)==null||c.setPort(i.ports[0]))}),(s=(r=this.iframe)==null?void 0:r.contentWindow)==null||s.focus()}removeEmbed(){this.iframe&&this.iframe.remove()}send(e){this.eventManager.send(e)}on(e,n){return this.eventManager.on(e,n)}off(e,n){this.eventManager.off(e,n)}update(e,n){this._value=e,n&&(this._options=n),this.send({type:p.UPDATE,value:e,options:this._options})}completion(){return new Promise((e,n)=>{let r,s,i;function o(){r&&r(),s&&s(),i&&i()}r=this.on(l.COMPLETE,c=>{e(c.response),o()}),s=this.on(l.CANCEL,()=>{n(new Error("User cancelled")),o()}),i=this.on("error",c=>{n(new Error(c.message)),o()})})}async openModal(){this.modal&&this.closeModal(),this.modal=document.createElement("dialog"),this.modal.style.border="none",this.modal.style.backgroundColor="white",this.modal.style.maxWidth="100vw",this.modal.style.maxHeight="100vh",this.modal.style.width="600px",this.modal.style.height="600px",document.body.appendChild(this.modal),this.embed(this.modal,!0);const e=this.on(l.CANCEL,()=>{this.closeModal()}),n=this.on(l.COMPLETE,()=>{this.closeModal()});return this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()}),this.completion().finally(()=>{e(),n()})}closeModal(){var e;this.modal&&((e=this.modal)==null||e.close(),this.modal.remove(),this.modal=void 0)}async popup(){const e=window.open(this.url,"_blank","popup=true,width=600,height=600");window.addEventListener("message",s=>{var i;s.source===e&&(console.log("received message from popup",s.data),(i=this.eventManager)==null||i.setPort(s.ports[0]))});const n=this.on(l.CANCEL,()=>{e==null||e.close()}),r=this.on(l.COMPLETE,()=>{e==null||e.close()});return this.completion().finally(()=>{n(),r()})}}function x(t){return Object.entries(t).map(([e,n])=>{if(n==null)return;const r=encodeURIComponent(e),s=encodeURIComponent(typeof n=="object"?JSON.stringify(n):String(n));return`${r}=${s}`}).filter(e=>e!==void 0).join("&")}function D(t){const e=t.slice(1);return e?e.split("&").filter(Boolean).reduce((r,s)=>{const[i,o]=s.split("=");return i&&(r[decodeURIComponent(i)]=o?decodeURIComponent(o):""),r},{}):{}}async function E(t,e){const n=JSON.stringify(t),r=new TextEncoder,s=e?m(e):crypto.getRandomValues(new Uint8Array(32)),i=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["encrypt"]),o=crypto.getRandomValues(new Uint8Array(12)),c=await crypto.subtle.encrypt({name:"AES-GCM",iv:o},i,r.encode(n));return{ciphertext:`${u(o)}-${u(c)}`,key:u(s)}}async function L({ciphertext:t,key:e}){const[n,r]=t.split("-"),s=new Uint8Array(atob(e).split("").map(N=>N.charCodeAt(0))),i=m(n),o=m(r),c=await crypto.subtle.importKey("raw",s,{name:"AES-GCM"},!1,["decrypt"]),d=new TextDecoder,h=await crypto.subtle.decrypt({name:"AES-GCM",iv:new Uint8Array(i)},c,o);return JSON.parse(d.decode(h))}function u(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++)n+=String.fromCharCode(e[r]);return btoa(n)}function m(t){const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}async function S(t){const e=await fetch(t.url,{method:"GET"});if(!e.ok)throw new Error(`Failed to get connection: ${await e.text()}`);const n=await e.json();if(!n.id||!n.metadata||!n.status||!n.sealed)throw new Error("Data missing from server response");const r={id:n.id,metadata:n.metadata,status:n.status};if(n.status==="closed")return r;const s=n.sealed[n.sealed.length-1],i=await L({ciphertext:s,key:t.key});return n.status==="completed"?{...r,result:i.result}:{...r,tx:i.tx}}class M{constructor(e){a(this,"endpoint");this.endpoint=e}async create(e,n){const r=await E(e),s={metadata:n,sealed:r.ciphertext},i=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!i.ok)throw new Error(`Failed to create connection: ${await i.text()}`);const o=await i.json();return{id:o.id,version:o.version,status:o.status,metadata:n,data:e,key:r.key}}async update(e,n,r,s,i){const o=await E(n,i),c={sealed:o.ciphertext,version:r,status:s},d=await fetch(`${this.endpoint}/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok)throw new Error(`Failed to update connection: ${await d.text()}`);const h=await d.json();return{id:h.id,metadata:h.metadata,version:h.version,status:h.status,data:n,key:o.key}}async get(e,n){const r=await fetch(`${this.endpoint}/${e}`,{method:"GET"});if(!r.ok)throw new Error(`Failed to get connection: ${await r.text()}`);const s=await r.json(),i=s.sealed[s.sealed.length-1],o=await L({ciphertext:i,key:n});return{id:s.id,status:s.status,version:s.version,metadata:s.metadata,data:o,key:n}}async close(e){const n=await fetch(`${this.endpoint}/${e}`,{method:"DELETE"});if(!n.ok)throw new Error(`Failed to close connection: ${await n.text()}`)}}class O{constructor(e){a(this,"nodeUrl");a(this,"authToken");a(this,"uxUrl");a(this,"theme");a(this,"locale");this.uxUrl=e.uxUrl||"https://connect.notabene.id",this.nodeUrl=e.nodeUrl,this.authToken=e.authToken,this.theme=e.theme,this.locale=e.locale}componentUrl(e,n,r,s){const i=new URL(this.uxUrl);i.pathname=e;const o=x({authToken:this.authToken,value:n,configuration:r});return i.hash=o,this.nodeUrl&&i.searchParams.set("nodeUrl",this.nodeUrl),this.theme&&i.searchParams.set("theme",JSON.stringify(this.theme)),this.locale&&i.searchParams.set("locale",this.locale),s&&(s.callback&&i.searchParams.set("callback_url",s.callback),s.redirectUri&&i.searchParams.set("redirect_uri",s.redirectUri)),i.toString()}createComponent(e,n,r,s){return new I(this.componentUrl(e,n,r,s),n,r)}createWithdrawalAssist(e,n,r){return this.createComponent("withdrawal-assist",e,n,r)}createConnectWallet(e,n,r){return this.createComponent("connect",e,n,r)}createDepositRequest(e,n,r){return this.createComponent("deposit-request",e,n,r)}createDepositAssist(e,n,r){return this.createComponent("deposit-assist",e,n,r)}}exports.AgentType=f;exports.CMType=l;exports.ConnectionManager=M;exports.EmbeddedComponent=I;exports.ErrorIdentifierCode=A;exports.HMType=p;exports.PersonType=w;exports.ProofStatus=C;exports.ProofTypes=b;exports.Status=g;exports.VASPSearchControl=v;exports.ValidationSections=y;exports.decodeFragmentToObject=D;exports.default=O;exports.getRefreshResult=S;
|
package/dist/cjs/notabene.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A blockchain account
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export declare interface Account {
|
|
6
|
+
did?: DID;
|
|
7
|
+
blockchainAddress?: BlockchainAddress;
|
|
8
|
+
chain?: CAIP2;
|
|
9
|
+
caip10?: CAIP10;
|
|
10
|
+
identifier?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* Address
|
|
3
15
|
* Represents a physical address
|
|
@@ -294,6 +306,7 @@ export declare interface ConnectionData<T extends ComponentRequest> {
|
|
|
294
306
|
tx: T;
|
|
295
307
|
authToken?: string;
|
|
296
308
|
txOptions?: TransactionOptions;
|
|
309
|
+
result?: TransactionResponse<T>;
|
|
297
310
|
}
|
|
298
311
|
|
|
299
312
|
/**
|
|
@@ -316,7 +329,7 @@ export declare class ConnectionManager {
|
|
|
316
329
|
* @param version Current version number
|
|
317
330
|
* @returns Promise resolving to updated connection details including new encryption key
|
|
318
331
|
*/
|
|
319
|
-
update<T extends ComponentRequest>(id: UUID, data: ConnectionData<T>, version: number): Promise<ConnectionResponse<T>>;
|
|
332
|
+
update<T extends ComponentRequest>(id: UUID, data: ConnectionData<T>, version: number, status: ConnectionStatus, key: string): Promise<ConnectionResponse<T>>;
|
|
320
333
|
/**
|
|
321
334
|
* Retrieves and decrypts connection data
|
|
322
335
|
* @param id Connection ID
|
|
@@ -354,11 +367,22 @@ export declare interface ConnectionRequest extends ComponentRequest {
|
|
|
354
367
|
export declare interface ConnectionResponse<T extends ComponentRequest> {
|
|
355
368
|
id: UUID;
|
|
356
369
|
version: number;
|
|
370
|
+
status: ConnectionStatus;
|
|
357
371
|
metadata: ConnectionMetadata;
|
|
358
372
|
data: ConnectionData<T>;
|
|
359
373
|
key: string;
|
|
360
374
|
}
|
|
361
375
|
|
|
376
|
+
export declare interface ConnectionResult<T extends ComponentRequest> {
|
|
377
|
+
id: UUID;
|
|
378
|
+
metadata: ConnectionMetadata;
|
|
379
|
+
status: ConnectionStatus;
|
|
380
|
+
tx?: T;
|
|
381
|
+
result?: TransactionResponse<T>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export declare type ConnectionStatus = 'active' | 'completed' | 'closed';
|
|
385
|
+
|
|
362
386
|
/**
|
|
363
387
|
* The counterparty of a transaction.
|
|
364
388
|
* @public
|
|
@@ -642,6 +666,8 @@ export declare type FieldTypes = {
|
|
|
642
666
|
legalPerson?: LegalPersonFields;
|
|
643
667
|
};
|
|
644
668
|
|
|
669
|
+
export declare function getRefreshResult<T extends ComponentRequest>(refreshSource: RefreshSource): Promise<ConnectionResult<T>>;
|
|
670
|
+
|
|
645
671
|
/**
|
|
646
672
|
* Host Message Type enum representing different message types that can be sent
|
|
647
673
|
* from the host application.
|
|
@@ -1352,7 +1378,7 @@ declare interface Refreshable {
|
|
|
1352
1378
|
refreshSource?: RefreshSource;
|
|
1353
1379
|
}
|
|
1354
1380
|
|
|
1355
|
-
declare interface RefreshSource {
|
|
1381
|
+
export declare interface RefreshSource {
|
|
1356
1382
|
url: URI;
|
|
1357
1383
|
key: string;
|
|
1358
1384
|
}
|
|
@@ -1485,6 +1511,7 @@ export declare interface Transaction extends ComponentRequest {
|
|
|
1485
1511
|
price: number;
|
|
1486
1512
|
currency: ISOCurrency;
|
|
1487
1513
|
};
|
|
1514
|
+
account?: Account;
|
|
1488
1515
|
}
|
|
1489
1516
|
|
|
1490
1517
|
/**
|
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.9.0-next.
|
|
13
|
+
"version": "2.9.0-next.3",
|
|
14
14
|
"source": "src/notabene.ts",
|
|
15
15
|
"main": "dist/cjs/notabene.cjs",
|
|
16
16
|
"module": "dist/esm/notabene.js",
|
package/dist/esm/notabene.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A blockchain account
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export declare interface Account {
|
|
6
|
+
did?: DID;
|
|
7
|
+
blockchainAddress?: BlockchainAddress;
|
|
8
|
+
chain?: CAIP2;
|
|
9
|
+
caip10?: CAIP10;
|
|
10
|
+
identifier?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* Address
|
|
3
15
|
* Represents a physical address
|
|
@@ -294,6 +306,7 @@ export declare interface ConnectionData<T extends ComponentRequest> {
|
|
|
294
306
|
tx: T;
|
|
295
307
|
authToken?: string;
|
|
296
308
|
txOptions?: TransactionOptions;
|
|
309
|
+
result?: TransactionResponse<T>;
|
|
297
310
|
}
|
|
298
311
|
|
|
299
312
|
/**
|
|
@@ -316,7 +329,7 @@ export declare class ConnectionManager {
|
|
|
316
329
|
* @param version Current version number
|
|
317
330
|
* @returns Promise resolving to updated connection details including new encryption key
|
|
318
331
|
*/
|
|
319
|
-
update<T extends ComponentRequest>(id: UUID, data: ConnectionData<T>, version: number): Promise<ConnectionResponse<T>>;
|
|
332
|
+
update<T extends ComponentRequest>(id: UUID, data: ConnectionData<T>, version: number, status: ConnectionStatus, key: string): Promise<ConnectionResponse<T>>;
|
|
320
333
|
/**
|
|
321
334
|
* Retrieves and decrypts connection data
|
|
322
335
|
* @param id Connection ID
|
|
@@ -354,11 +367,22 @@ export declare interface ConnectionRequest extends ComponentRequest {
|
|
|
354
367
|
export declare interface ConnectionResponse<T extends ComponentRequest> {
|
|
355
368
|
id: UUID;
|
|
356
369
|
version: number;
|
|
370
|
+
status: ConnectionStatus;
|
|
357
371
|
metadata: ConnectionMetadata;
|
|
358
372
|
data: ConnectionData<T>;
|
|
359
373
|
key: string;
|
|
360
374
|
}
|
|
361
375
|
|
|
376
|
+
export declare interface ConnectionResult<T extends ComponentRequest> {
|
|
377
|
+
id: UUID;
|
|
378
|
+
metadata: ConnectionMetadata;
|
|
379
|
+
status: ConnectionStatus;
|
|
380
|
+
tx?: T;
|
|
381
|
+
result?: TransactionResponse<T>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export declare type ConnectionStatus = 'active' | 'completed' | 'closed';
|
|
385
|
+
|
|
362
386
|
/**
|
|
363
387
|
* The counterparty of a transaction.
|
|
364
388
|
* @public
|
|
@@ -642,6 +666,8 @@ export declare type FieldTypes = {
|
|
|
642
666
|
legalPerson?: LegalPersonFields;
|
|
643
667
|
};
|
|
644
668
|
|
|
669
|
+
export declare function getRefreshResult<T extends ComponentRequest>(refreshSource: RefreshSource): Promise<ConnectionResult<T>>;
|
|
670
|
+
|
|
645
671
|
/**
|
|
646
672
|
* Host Message Type enum representing different message types that can be sent
|
|
647
673
|
* from the host application.
|
|
@@ -1352,7 +1378,7 @@ declare interface Refreshable {
|
|
|
1352
1378
|
refreshSource?: RefreshSource;
|
|
1353
1379
|
}
|
|
1354
1380
|
|
|
1355
|
-
declare interface RefreshSource {
|
|
1381
|
+
export declare interface RefreshSource {
|
|
1356
1382
|
url: URI;
|
|
1357
1383
|
key: string;
|
|
1358
1384
|
}
|
|
@@ -1485,6 +1511,7 @@ export declare interface Transaction extends ComponentRequest {
|
|
|
1485
1511
|
price: number;
|
|
1486
1512
|
currency: ISOCurrency;
|
|
1487
1513
|
};
|
|
1514
|
+
account?: Account;
|
|
1488
1515
|
}
|
|
1489
1516
|
|
|
1490
1517
|
/**
|