@notabene/javascript-sdk 2.0.0-next.16 → 2.0.0-next.17
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 +25 -24
- package/dist/notabene.cjs +1 -1
- package/dist/notabene.d.ts +37 -43
- package/dist/notabene.js +32 -18
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +21 -20
- package/src/components/EmbeddedComponent.ts +17 -19
- package/src/components/__tests__/EmbeddedComponent.test.ts +11 -31
- package/src/notabene.ts +25 -20
- package/src/types.ts +23 -28
- package/src/utils/MessageEventManager.ts +7 -7
- package/src/utils/__tests__/MessageEventManager.test.ts +3 -3
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ Create a new Notabene instance:
|
|
|
83
83
|
const notabene = new Notabene({
|
|
84
84
|
nodeUrl: 'https://api.notabene.id', // use `https://api.notabene.dev` for testing
|
|
85
85
|
authToken: '{CUSTOMER_TOKEN}',
|
|
86
|
-
locale: 'de' // default locale = `en`
|
|
86
|
+
locale: 'de', // default locale = `en`
|
|
87
87
|
});
|
|
88
88
|
```
|
|
89
89
|
|
|
@@ -107,19 +107,20 @@ Instantiate the withdrawal element and mount it using the id from above
|
|
|
107
107
|
|
|
108
108
|
```js
|
|
109
109
|
const withdrawal = notabene.createWithdrawalAssist(tx, options);
|
|
110
|
-
withdrawal.mount(
|
|
110
|
+
withdrawal.mount('nb-withdrawal');
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
The simplest way to get the result is to use:
|
|
114
114
|
|
|
115
115
|
```js
|
|
116
116
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
const { valid, value, txCreate, ivms101, proof } =
|
|
118
|
+
await withdrawal.completion();
|
|
119
|
+
if (valid) {
|
|
120
|
+
// Submit result to your backend
|
|
121
|
+
}
|
|
121
122
|
} catch (e) {
|
|
122
|
-
|
|
123
|
+
console.error(e);
|
|
123
124
|
}
|
|
124
125
|
```
|
|
125
126
|
|
|
@@ -131,7 +132,7 @@ To update the component as users enter transaction details:
|
|
|
131
132
|
withdrawal.update({
|
|
132
133
|
asset: 'ETH',
|
|
133
134
|
destination: '0x8d12a197cb00d4747a1fe03395095ce2a5cc6819',
|
|
134
|
-
amountDecimal: 1.12
|
|
135
|
+
amountDecimal: 1.12,
|
|
135
136
|
});
|
|
136
137
|
```
|
|
137
138
|
|
|
@@ -218,13 +219,12 @@ The `asset` field the following types of assets specified:
|
|
|
218
219
|
- [CAIP-19](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md_) is a chain agnostic format allows you to support the widest amount of assets and blockchains including NFTs.
|
|
219
220
|
- [DTI](https://www.iso.org/standard/80601.html) is the ISO Digital Token Identifier format. See [DTI registry](https://dtif.org/registry-search/) for supported tokens.
|
|
220
221
|
|
|
221
|
-
|
|
222
222
|
### Modal
|
|
223
223
|
|
|
224
224
|
Instantiate the modal and open it
|
|
225
225
|
|
|
226
226
|
```js
|
|
227
|
-
const connect = notabene.createConnectWallet({asset:'ETH'}, options);
|
|
227
|
+
const connect = notabene.createConnectWallet({ asset: 'ETH' }, options);
|
|
228
228
|
const { valid, value, txCreate, ivms101, proof } = await connect.openModal();
|
|
229
229
|
```
|
|
230
230
|
|
|
@@ -269,10 +269,10 @@ The following shows the full set of options in typescript:
|
|
|
269
269
|
|
|
270
270
|
```ts
|
|
271
271
|
import Notabene, {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
272
|
+
AgentType,
|
|
273
|
+
PersonType,
|
|
274
|
+
ProofTypes,
|
|
275
|
+
} from '@notabene/javascript-sdk';
|
|
276
276
|
|
|
277
277
|
const options: TransactionOptions = {
|
|
278
278
|
proofs: {
|
|
@@ -313,8 +313,8 @@ const options: TransactionOptions = {
|
|
|
313
313
|
},
|
|
314
314
|
vasps: {
|
|
315
315
|
addUnknown: true, // Allow users to add a missing VASP - Defaults to false
|
|
316
|
-
onlyActive: true // Only list active VASPs - Default false
|
|
317
|
-
}
|
|
316
|
+
onlyActive: true, // Only list active VASPs - Default false
|
|
317
|
+
},
|
|
318
318
|
},
|
|
319
319
|
};
|
|
320
320
|
const withdrawal = notabene.createWithdrawalAssist(tx, options);
|
|
@@ -352,7 +352,6 @@ const options: TransactionOptions = {
|
|
|
352
352
|
|
|
353
353
|
By default components support message signing proofs.
|
|
354
354
|
|
|
355
|
-
|
|
356
355
|
#### Supporting Micro Transactions (aka Satoshi tests)
|
|
357
356
|
|
|
358
357
|
You can support Micro Transfers (aka Satoshi tests) by adding a deposit address for the test.
|
|
@@ -368,8 +367,8 @@ const options: TransactionOptions = {
|
|
|
368
367
|
timeout: 86440, // Optional timeout in seconds, which is displayed to the user
|
|
369
368
|
},
|
|
370
369
|
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration], // js ['screenshot','self_declaration']
|
|
371
|
-
}
|
|
372
|
-
}
|
|
370
|
+
},
|
|
371
|
+
};
|
|
373
372
|
```
|
|
374
373
|
|
|
375
374
|
Notabene does not currently verify these tests automatically as you likely already have the infrastructure to do so.
|
|
@@ -396,9 +395,10 @@ You may accept a few options if none of the other are available. We do not recom
|
|
|
396
395
|
const options: TransactionOptions = {
|
|
397
396
|
proofs: {
|
|
398
397
|
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration], // js ['screenshot','self_declaration']
|
|
399
|
-
}
|
|
400
|
-
}
|
|
398
|
+
},
|
|
399
|
+
};
|
|
401
400
|
```
|
|
401
|
+
|
|
402
402
|
The two options are:
|
|
403
403
|
|
|
404
404
|
- `screenshot` Where a user is requested to upload a screenshot of their wallet
|
|
@@ -418,6 +418,7 @@ Each field can be configured like this:
|
|
|
418
418
|
- `{ transmit: true }` Include in beneficiary field of IVMS101 to be transmitted to counterparty
|
|
419
419
|
|
|
420
420
|
Eg:
|
|
421
|
+
|
|
421
422
|
```ts
|
|
422
423
|
{
|
|
423
424
|
naturalPerson: {
|
|
@@ -427,13 +428,13 @@ Eg:
|
|
|
427
428
|
}
|
|
428
429
|
}
|
|
429
430
|
```
|
|
431
|
+
|
|
430
432
|
The above will always ask the user for the following for natural persons:
|
|
431
433
|
|
|
432
434
|
- `name` since it is on by default (you can disable it explicitly by setting it to `false`)
|
|
433
435
|
- `website` is show but is optional
|
|
434
436
|
- `email` is required
|
|
435
437
|
|
|
436
|
-
|
|
437
438
|
#### Full Example
|
|
438
439
|
|
|
439
440
|
```ts
|
|
@@ -447,7 +448,7 @@ const options: TransactionOptions = {
|
|
|
447
448
|
geographicAddress: false,
|
|
448
449
|
nationalIdentification: false,
|
|
449
450
|
dateOfBirth: {
|
|
450
|
-
transmit: true
|
|
451
|
+
transmit: true,
|
|
451
452
|
},
|
|
452
453
|
placeOfBirth: false,
|
|
453
454
|
countryOfResidence: true,
|
|
@@ -469,7 +470,7 @@ const options: TransactionOptions = {
|
|
|
469
470
|
#### Field reference
|
|
470
471
|
|
|
471
472
|
| Field name | Natural | Legal | IVMS101 | Transmitted | description |
|
|
472
|
-
|
|
473
|
+
| ------------------------ | ------- | ----- | ------- | ----------- | --------------------------------------------- |
|
|
473
474
|
| `name` | ✅ | ✅ | ✅ | ✅ | Full name |
|
|
474
475
|
| `email` | 🟩 | 🟩 | -- | -- | Email (for your internal purposes) |
|
|
475
476
|
| `website` | -- | ✅ | -- | -- | Business Website (for your internal purposes) |
|
package/dist/notabene.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var v=(t,e,s)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var o=(t,e,s)=>v(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var d=(t=>(t.PRIVATE="WALLET",t.VASP="VASP",t))(d||{}),c=(t=>(t.NATURAL="natural",t.LEGAL="legal",t.SELF="self",t))(c||{}),m=(t=>(t.EMPTY="empty",t.VERIFY="verify",t.PENDING="pending",t.VERIFIED="verified",t.BANNED="banned",t))(m||{}),a=(t=>(t.COMPLETE="complete",t.RESIZE="resize",t.RESULT="result",t.READY="ready",t.INVALID="invalid",t.ERROR="error",t.CANCEL="cancel",t))(a||{}),u=(t=>(t.UPDATE="update",t.REQUEST_RESPONSE="requestResponse",t))(u||{}),p=(t=>(t.PENDING="pending",t.FAILED="rejected",t.FLAGGED="flagged",t.VERIFIED="verified",t))(p||{}),f=(t=>(t.SelfDeclaration="self-declaration",t.PersonalSignEIP191="eip-191",t.SIWE="siwe",t.PersonalSignEIP712="eip-712",t.PersonalSignBIP137="bip-137",t.PersonalSignXPUB="xpub",t.MicroTransfer="microtransfer",t.Screenshot="screenshot",t))(f||{});class w{constructor(){o(this,"listeners",new Map);o(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(e){this.port=e,this.port.onmessage=this.handleMessage,this.port.start()}on(e,s){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(s)}off(e,s){const r=this.listeners.get(e);r&&(r.delete(s),r.size===0&&this.listeners.delete(e))}handleMessage(e){const s=e.data;if(typeof s=="object"&&s!==null&&"type"in s){const r=s.type,i=this.listeners.get(r);i&&i.forEach(n=>n(s))}}send(e){this.port&&this.port.postMessage(e)}}class E{constructor(e,s){o(this,"_url");o(this,"_value");o(this,"_errors",[]);o(this,"iframe");o(this,"eventManager");o(this,"modal");this._url=e,this._value=s,this.eventManager=new w,this.on(a.INVALID,r=>{r.type===a.INVALID&&(this._errors=r.errors,this._value=r.value)}),this.on(a.RESIZE,r=>{r.type===a.RESIZE&&this.iframe&&(this.iframe.style.height=`${r.height}px`)})}get url(){return this._url}get value(){return this._value}get errors(){return this._errors}open(){document.location.href=this.url}mount(e){const s=document.querySelector(e);if(!s)throw new Error(`parentID ${e} not found`);this.embed(s)}embed(e,s=!1){var r,i;this.iframe=document.createElement("iframe"),this.iframe.src=this.url+(s?"":"&embedded=true"),this.iframe.allow="web-share",this.iframe.style.width="100%",this.iframe.style.height="100px",this.iframe.style.border="none",this.iframe.style.overflow="hidden",e.appendChild(this.iframe),window.addEventListener("message",n=>{var l,h;n.source===((l=this.iframe)==null?void 0:l.contentWindow)&&((h=this.eventManager)==null||h.setPort(n.ports[0]))}),(i=(r=this.iframe)==null?void 0:r.contentWindow)==null||i.focus()}send(e){this.eventManager.send(e)}on(e,s){this.eventManager.on(e,s)}off(e,s){this.eventManager.off(e,s)}update(e){this._value=e,this.send({type:u.UPDATE,value:e})}completion(){return new Promise((e,s)=>{this.on(a.COMPLETE,r=>{e(r.response)}),this.on("error",r=>{s(new Error(r.message))})})}openModal(){return 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),this.on(a.CANCEL,()=>{this.closeModal()}),this.on(a.COMPLETE,()=>{this.closeModal()}),this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()}),this.completion()}closeModal(){var e;this.modal&&((e=this.modal)==null||e.close(),this.modal.remove(),this.modal=void 0)}}function I(t){return Object.entries(t).map(([e,s])=>{if(!(e&&s))return;const r=encodeURIComponent(e),i=encodeURIComponent(typeof s=="object"?JSON.stringify(s):s);return`${r}=${i}`}).filter(e=>!!e).join("&")}class U{constructor(e){o(this,"nodeUrl");o(this,"authToken");o(this,"uxUrl");o(this,"theme");o(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,s,r,i){const n=new URL(this.uxUrl);n.pathname=e;const l=I({authToken:this.authToken,value:s,configuration:r});return n.hash=l,this.nodeUrl&&n.searchParams.set("nodeUrl",this.nodeUrl),this.theme&&n.searchParams.set("theme",JSON.stringify(this.theme)),this.locale&&n.searchParams.set("locale",this.locale),i&&(i.callback&&n.searchParams.set("callback_url",i.callback),i.redirectUri&&n.searchParams.set("redirect_uri",i.redirectUri)),n.toString()}createComponent(e,s,r,i){return new E(this.componentUrl(e,s,r,i),s)}createWithdrawalAssist(e,s,r){return this.createComponent("withdrawal-assist",e,s,r)}createWalletAssist(e,s,r){return this.createComponent("wallet-assist",e,s,r)}createDepositAssist(e,s,r){return this.createComponent("deposit-assist",e,s,r)}createConnectWallet(e,s,r){return this.createComponent("connect",e,s,r)}createDepositRequest(e,s,r){return this.createComponent("deposit-request",e,s,r)}decodeFragmentToObject(e){return e.slice(1).split("&").reduce((r,i)=>{const[n,l]=i.split("=");return r[decodeURIComponent(n)]=decodeURIComponent(l),r},{})}}exports.AgentType=d;exports.CMType=a;exports.EmbeddedComponent=E;exports.PersonType=c;exports.ProofStatus=p;exports.ProofTypes=f;exports.Status=m;exports.default=U;
|
package/dist/notabene.d.ts
CHANGED
|
@@ -141,7 +141,7 @@ export declare interface CallbackOptions {
|
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* Represents a cancel component message
|
|
144
|
-
* @
|
|
144
|
+
* @internal
|
|
145
145
|
*/
|
|
146
146
|
declare type Cancel = {
|
|
147
147
|
type: CMType.CANCEL;
|
|
@@ -157,26 +157,26 @@ export declare const enum CMType {
|
|
|
157
157
|
RESULT = "result",
|
|
158
158
|
READY = "ready",
|
|
159
159
|
INVALID = "invalid",
|
|
160
|
-
MODAL = "openModal",
|
|
161
160
|
ERROR = "error",
|
|
162
|
-
CLOSE = "closeModal",
|
|
163
161
|
CANCEL = "cancel"
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
/**
|
|
167
165
|
* Represents a completed component message
|
|
166
|
+
* @typeParam T - The overall Value type being returned
|
|
167
|
+
* @param response - The Response object which wraps T
|
|
168
168
|
* @public
|
|
169
169
|
*/
|
|
170
|
-
declare type Completed = {
|
|
170
|
+
declare type Completed<T> = {
|
|
171
171
|
type: CMType.COMPLETE;
|
|
172
|
-
response:
|
|
172
|
+
response: TransactionResponse<T>;
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* Component Message
|
|
177
177
|
* @public
|
|
178
178
|
*/
|
|
179
|
-
export declare type ComponentMessage = Completed | Cancel | Error_2 | Ready | ResizeRequest | InvalidValue
|
|
179
|
+
export declare type ComponentMessage<T> = Completed<T> | Cancel | Error_2 | Ready | ResizeRequest | InvalidValue<T>;
|
|
180
180
|
|
|
181
181
|
/**
|
|
182
182
|
* An abstract request for communicating with a component
|
|
@@ -202,17 +202,6 @@ export declare interface ConnectionRequest extends ComponentRequest {
|
|
|
202
202
|
asset: TransactionAsset;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
/**
|
|
206
|
-
* An object representing a connection response
|
|
207
|
-
* @public
|
|
208
|
-
*/
|
|
209
|
-
export declare interface ConnectionResponse extends ComponentResponse {
|
|
210
|
-
value: ConnectionRequest;
|
|
211
|
-
ivms: IVMS101;
|
|
212
|
-
proof?: OwnershipProof;
|
|
213
|
-
txCreate?: V1Transaction;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
205
|
/**
|
|
217
206
|
* The counterparty of a transaction.
|
|
218
207
|
* @public
|
|
@@ -304,7 +293,7 @@ declare type DTI = string;
|
|
|
304
293
|
* An embedded Notabene component
|
|
305
294
|
* @public
|
|
306
295
|
*/
|
|
307
|
-
export declare class EmbeddedComponent<V
|
|
296
|
+
export declare class EmbeddedComponent<V> {
|
|
308
297
|
private _url;
|
|
309
298
|
private _value;
|
|
310
299
|
private _errors;
|
|
@@ -316,7 +305,7 @@ export declare class EmbeddedComponent<V, R> {
|
|
|
316
305
|
* @param url - The URL of the embedded component
|
|
317
306
|
* @param value - The initial transaction value
|
|
318
307
|
*/
|
|
319
|
-
constructor(url: string, value: V);
|
|
308
|
+
constructor(url: string, value: Partial<V>);
|
|
320
309
|
/**
|
|
321
310
|
* Gets the URL of the embedded component
|
|
322
311
|
* @returns The URL of the embedded component
|
|
@@ -326,7 +315,7 @@ export declare class EmbeddedComponent<V, R> {
|
|
|
326
315
|
* Gets the current transaction value
|
|
327
316
|
* @returns The current transaction value
|
|
328
317
|
*/
|
|
329
|
-
get value(): V
|
|
318
|
+
get value(): Partial<V>;
|
|
330
319
|
get errors(): ValidationError[];
|
|
331
320
|
/**
|
|
332
321
|
* Opens the component URL in the current window
|
|
@@ -347,33 +336,33 @@ export declare class EmbeddedComponent<V, R> {
|
|
|
347
336
|
* Sends a message to the embedded component
|
|
348
337
|
* @param message - The message to send
|
|
349
338
|
*/
|
|
350
|
-
send(message: HostMessage): void;
|
|
339
|
+
send(message: HostMessage<V>): void;
|
|
351
340
|
/**
|
|
352
341
|
* Adds an event listener for a specific message type
|
|
353
342
|
* @param messageType - The type of message to listen for
|
|
354
343
|
* @param callback - The callback function to execute when the message is received
|
|
355
344
|
*/
|
|
356
|
-
on(messageType: string, callback: MessageCallback): void;
|
|
345
|
+
on(messageType: string, callback: MessageCallback<V>): void;
|
|
357
346
|
/**
|
|
358
347
|
* Removes an event listener for a specific message type
|
|
359
348
|
* @param messageType - The type of message to stop listening for
|
|
360
349
|
* @param callback - The callback function to remove
|
|
361
350
|
*/
|
|
362
|
-
off(messageType: string, callback: MessageCallback): void;
|
|
351
|
+
off(messageType: string, callback: MessageCallback<V>): void;
|
|
363
352
|
/**
|
|
364
353
|
* Updates the transaction value and sends an update message to the component
|
|
365
354
|
* @param value - The new transaction value
|
|
366
355
|
*/
|
|
367
|
-
update(value: V): void;
|
|
356
|
+
update(value: Partial<V>): void;
|
|
368
357
|
/**
|
|
369
358
|
* Waits for the component to complete and returns the transaction response
|
|
370
359
|
* @returns A promise that resolves with the transaction response
|
|
371
360
|
*/
|
|
372
|
-
completion(): Promise<
|
|
361
|
+
completion(): Promise<TransactionResponse<V>>;
|
|
373
362
|
/**
|
|
374
363
|
* Opens the component in a modal dialog
|
|
375
364
|
*/
|
|
376
|
-
openModal(): Promise<
|
|
365
|
+
openModal(): Promise<TransactionResponse<V>>;
|
|
377
366
|
/**
|
|
378
367
|
* Closes the modal dialog
|
|
379
368
|
*
|
|
@@ -383,6 +372,7 @@ export declare class EmbeddedComponent<V, R> {
|
|
|
383
372
|
|
|
384
373
|
/**
|
|
385
374
|
* Represents an error component message
|
|
375
|
+
* @param message - Error message
|
|
386
376
|
* @public
|
|
387
377
|
*/
|
|
388
378
|
declare type Error_2 = {
|
|
@@ -417,7 +407,7 @@ declare const enum HMType {
|
|
|
417
407
|
* Host Messages
|
|
418
408
|
* @public
|
|
419
409
|
*/
|
|
420
|
-
export declare type HostMessage = UpdateValue
|
|
410
|
+
export declare type HostMessage<T> = UpdateValue<T>;
|
|
421
411
|
|
|
422
412
|
/**
|
|
423
413
|
* Intermediary VASP
|
|
@@ -433,11 +423,14 @@ declare type IntermediaryVASP = {
|
|
|
433
423
|
|
|
434
424
|
/**
|
|
435
425
|
* Represents an invalid value component message
|
|
436
|
-
* @
|
|
426
|
+
* @typeParam T - The overall Value type being returned
|
|
427
|
+
* @param value - The current Partial value
|
|
428
|
+
* @param errors - Array of validation errors
|
|
429
|
+
* @internal
|
|
437
430
|
*/
|
|
438
|
-
declare type InvalidValue = {
|
|
431
|
+
declare type InvalidValue<T> = {
|
|
439
432
|
type: CMType.INVALID;
|
|
440
|
-
value:
|
|
433
|
+
value: Partial<T>;
|
|
441
434
|
errors: ValidationError[];
|
|
442
435
|
};
|
|
443
436
|
|
|
@@ -573,7 +566,7 @@ declare type LocalNaturalPersonNameID = {
|
|
|
573
566
|
nameIdentifierType?: NaturalPersonNameTypeCode;
|
|
574
567
|
};
|
|
575
568
|
|
|
576
|
-
declare type MessageCallback = (message: ComponentMessage) => void;
|
|
569
|
+
declare type MessageCallback<T> = (message: ComponentMessage<T>) => void;
|
|
577
570
|
|
|
578
571
|
/**
|
|
579
572
|
* Ownership Proof using Micro Transfer
|
|
@@ -721,7 +714,7 @@ declare class Notabene {
|
|
|
721
714
|
* @returns A new EmbeddedComponent instance
|
|
722
715
|
* @internal
|
|
723
716
|
*/
|
|
724
|
-
createComponent<V
|
|
717
|
+
createComponent<V>(path: string, value: Partial<V>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<V>;
|
|
725
718
|
/**
|
|
726
719
|
* Creates a withdrawal assist component
|
|
727
720
|
*
|
|
@@ -730,7 +723,7 @@ declare class Notabene {
|
|
|
730
723
|
* @param callbacks - Optional callback configuration
|
|
731
724
|
* @returns A new EmbeddedComponent instance for withdrawal assistance
|
|
732
725
|
*/
|
|
733
|
-
createWithdrawalAssist(value: Partial<Withdrawal>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<
|
|
726
|
+
createWithdrawalAssist(value: Partial<Withdrawal>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<Withdrawal>;
|
|
734
727
|
/**
|
|
735
728
|
* Creates a wallet assist component
|
|
736
729
|
*
|
|
@@ -740,7 +733,7 @@ declare class Notabene {
|
|
|
740
733
|
* @returns A new EmbeddedComponent instance for withdrawal assistance
|
|
741
734
|
* @alpha
|
|
742
735
|
*/
|
|
743
|
-
createWalletAssist(value: Partial<Withdrawal>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<
|
|
736
|
+
createWalletAssist(value: Partial<Withdrawal>, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<Withdrawal>;
|
|
744
737
|
/**
|
|
745
738
|
* Creates a deposit assist component
|
|
746
739
|
*
|
|
@@ -750,7 +743,7 @@ declare class Notabene {
|
|
|
750
743
|
* @returns A new EmbeddedComponent instance for deposit assistance
|
|
751
744
|
* @alpha
|
|
752
745
|
*/
|
|
753
|
-
createDepositAssist(value: Partial<Deposit>, options?: any, callbacks?: CallbackOptions): EmbeddedComponent<
|
|
746
|
+
createDepositAssist(value: Partial<Deposit>, options?: any, callbacks?: CallbackOptions): EmbeddedComponent<Deposit>;
|
|
754
747
|
/**
|
|
755
748
|
* Creates a connect component
|
|
756
749
|
*
|
|
@@ -760,7 +753,7 @@ declare class Notabene {
|
|
|
760
753
|
* @returns A new EmbeddedComponent instance for connection
|
|
761
754
|
* @alpha
|
|
762
755
|
*/
|
|
763
|
-
createConnectWallet(value: ConnectionRequest, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<ConnectionRequest
|
|
756
|
+
createConnectWallet(value: ConnectionRequest, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<ConnectionRequest>;
|
|
764
757
|
/**
|
|
765
758
|
* Creates a deposit request component
|
|
766
759
|
*
|
|
@@ -770,7 +763,7 @@ declare class Notabene {
|
|
|
770
763
|
* @returns A new EmbeddedComponent instance for deposit requests
|
|
771
764
|
* @public
|
|
772
765
|
*/
|
|
773
|
-
createDepositRequest(value: DepositRequest, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<DepositRequest
|
|
766
|
+
createDepositRequest(value: DepositRequest, options?: TransactionOptions, callbacks?: CallbackOptions): EmbeddedComponent<DepositRequest>;
|
|
774
767
|
/**
|
|
775
768
|
* Decodes a URL fragment into an object
|
|
776
769
|
*
|
|
@@ -923,6 +916,7 @@ export declare enum ProofStatus {
|
|
|
923
916
|
export declare enum ProofTypes {
|
|
924
917
|
SelfDeclaration = "self-declaration",
|
|
925
918
|
PersonalSignEIP191 = "eip-191",
|
|
919
|
+
SIWE = "siwe",
|
|
926
920
|
PersonalSignEIP712 = "eip-712",
|
|
927
921
|
PersonalSignBIP137 = "bip-137",
|
|
928
922
|
PersonalSignXPUB = "xpub",
|
|
@@ -941,8 +935,8 @@ declare type Ready = {
|
|
|
941
935
|
declare type RequestID = UUID;
|
|
942
936
|
|
|
943
937
|
/**
|
|
944
|
-
* Represents a resize request component message
|
|
945
|
-
* @
|
|
938
|
+
* Represents a resize request component message. This is handled by the library.
|
|
939
|
+
* @internal
|
|
946
940
|
*/
|
|
947
941
|
declare type ResizeRequest = {
|
|
948
942
|
type: CMType.RESIZE;
|
|
@@ -963,7 +957,7 @@ export declare interface ScreenshotProof extends OwnershipProof {
|
|
|
963
957
|
* @public
|
|
964
958
|
*/
|
|
965
959
|
export declare interface SignatureProof extends OwnershipProof {
|
|
966
|
-
type: ProofTypes.PersonalSignEIP191 | ProofTypes.PersonalSignEIP712 | ProofTypes.PersonalSignBIP137 | ProofTypes.PersonalSignXPUB;
|
|
960
|
+
type: ProofTypes.PersonalSignEIP191 | ProofTypes.PersonalSignEIP712 | ProofTypes.PersonalSignBIP137 | ProofTypes.SIWE | ProofTypes.PersonalSignXPUB;
|
|
967
961
|
proof: string;
|
|
968
962
|
attestation: string;
|
|
969
963
|
wallet_provider: string;
|
|
@@ -1074,12 +1068,12 @@ declare type TransliterationMethodCode = 'arab' | 'aran' | 'armn' | 'cyrl' | 'de
|
|
|
1074
1068
|
declare type TravelAddress = `ta${string}`;
|
|
1075
1069
|
|
|
1076
1070
|
/**
|
|
1077
|
-
* Represents an update value host message
|
|
1071
|
+
* Represents an update value host message. This is sent from Host to component.
|
|
1078
1072
|
* @public
|
|
1079
1073
|
*/
|
|
1080
|
-
declare type UpdateValue = {
|
|
1074
|
+
declare type UpdateValue<T> = {
|
|
1081
1075
|
type: HMType.UPDATE;
|
|
1082
|
-
value:
|
|
1076
|
+
value: Partial<T>;
|
|
1083
1077
|
};
|
|
1084
1078
|
|
|
1085
1079
|
/**
|
package/dist/notabene.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var c = Object.defineProperty;
|
|
2
2
|
var m = (t, e, s) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
3
|
var o = (t, e, s) => m(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
-
var u = /* @__PURE__ */ ((t) => (t.PRIVATE = "WALLET", t.VASP = "VASP", t))(u || {}), E = /* @__PURE__ */ ((t) => (t.NATURAL = "natural", t.LEGAL = "legal", t.SELF = "self", t))(E || {}), f = /* @__PURE__ */ ((t) => (t.EMPTY = "empty", t.VERIFY = "verify", t.PENDING = "pending", t.VERIFIED = "verified", t.BANNED = "banned", t))(f || {}), a = /* @__PURE__ */ ((t) => (t.COMPLETE = "complete", t.RESIZE = "resize", t.RESULT = "result", t.READY = "ready", t.INVALID = "invalid", t.
|
|
4
|
+
var u = /* @__PURE__ */ ((t) => (t.PRIVATE = "WALLET", t.VASP = "VASP", t))(u || {}), E = /* @__PURE__ */ ((t) => (t.NATURAL = "natural", t.LEGAL = "legal", t.SELF = "self", t))(E || {}), f = /* @__PURE__ */ ((t) => (t.EMPTY = "empty", t.VERIFY = "verify", t.PENDING = "pending", t.VERIFIED = "verified", t.BANNED = "banned", t))(f || {}), a = /* @__PURE__ */ ((t) => (t.COMPLETE = "complete", t.RESIZE = "resize", t.RESULT = "result", t.READY = "ready", t.INVALID = "invalid", t.ERROR = "error", t.CANCEL = "cancel", t))(a || {}), d = /* @__PURE__ */ ((t) => (t.UPDATE = "update", t.REQUEST_RESPONSE = "requestResponse", t))(d || {}), p = /* @__PURE__ */ ((t) => (t.PENDING = "pending", t.FAILED = "rejected", t.FLAGGED = "flagged", t.VERIFIED = "verified", t))(p || {}), g = /* @__PURE__ */ ((t) => (t.SelfDeclaration = "self-declaration", t.PersonalSignEIP191 = "eip-191", t.SIWE = "siwe", t.PersonalSignEIP712 = "eip-712", t.PersonalSignBIP137 = "bip-137", t.PersonalSignXPUB = "xpub", t.MicroTransfer = "microtransfer", t.Screenshot = "screenshot", t))(g || {});
|
|
5
5
|
class v {
|
|
6
6
|
constructor() {
|
|
7
7
|
o(this, "listeners", /* @__PURE__ */ new Map());
|
|
@@ -30,7 +30,7 @@ class v {
|
|
|
30
30
|
this.port && this.port.postMessage(e);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class w {
|
|
34
34
|
/**
|
|
35
35
|
* Creates an instance of EmbeddedComponent.
|
|
36
36
|
* @param url - The URL of the embedded component
|
|
@@ -89,8 +89,8 @@ class I {
|
|
|
89
89
|
embed(e, s = !1) {
|
|
90
90
|
var r, i;
|
|
91
91
|
this.iframe = document.createElement("iframe"), this.iframe.src = this.url + (s ? "" : "&embedded=true"), this.iframe.allow = "web-share", this.iframe.style.width = "100%", this.iframe.style.height = "100px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", e.appendChild(this.iframe), window.addEventListener("message", (n) => {
|
|
92
|
-
var
|
|
93
|
-
n.source === ((
|
|
92
|
+
var h, l;
|
|
93
|
+
n.source === ((h = this.iframe) == null ? void 0 : h.contentWindow) && ((l = this.eventManager) == null || l.setPort(n.ports[0]));
|
|
94
94
|
}), (i = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || i.focus();
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -140,9 +140,7 @@ class I {
|
|
|
140
140
|
* Opens the component in a modal dialog
|
|
141
141
|
*/
|
|
142
142
|
openModal() {
|
|
143
|
-
return this.modal && this.closeModal(), this.modal = document.createElement("dialog"), this.modal.style.border = "none", this.modal.style.backgroundColor = "
|
|
144
|
-
this.closeModal();
|
|
145
|
-
}), this.on(a.CLOSE, () => {
|
|
143
|
+
return 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), this.on(a.CANCEL, () => {
|
|
146
144
|
this.closeModal();
|
|
147
145
|
}), this.on(a.COMPLETE, () => {
|
|
148
146
|
this.closeModal();
|
|
@@ -159,7 +157,7 @@ class I {
|
|
|
159
157
|
this.modal && ((e = this.modal) == null || e.close(), this.modal.remove(), this.modal = void 0);
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
|
-
function
|
|
160
|
+
function I(t) {
|
|
163
161
|
return Object.entries(t).map(([e, s]) => {
|
|
164
162
|
if (!(e && s)) return;
|
|
165
163
|
const r = encodeURIComponent(e), i = encodeURIComponent(
|
|
@@ -168,7 +166,7 @@ function U(t) {
|
|
|
168
166
|
return `${r}=${i}`;
|
|
169
167
|
}).filter((e) => !!e).join("&");
|
|
170
168
|
}
|
|
171
|
-
class
|
|
169
|
+
class R {
|
|
172
170
|
/**
|
|
173
171
|
* Creates a new instance of the Notabene SDK
|
|
174
172
|
*
|
|
@@ -195,12 +193,12 @@ class L {
|
|
|
195
193
|
componentUrl(e, s, r, i) {
|
|
196
194
|
const n = new URL(this.uxUrl);
|
|
197
195
|
n.pathname = e;
|
|
198
|
-
const
|
|
196
|
+
const h = I({
|
|
199
197
|
authToken: this.authToken,
|
|
200
198
|
value: s,
|
|
201
199
|
configuration: r
|
|
202
200
|
});
|
|
203
|
-
return n.hash =
|
|
201
|
+
return n.hash = h, this.nodeUrl && n.searchParams.set("nodeUrl", this.nodeUrl), this.theme && n.searchParams.set("theme", JSON.stringify(this.theme)), this.locale && n.searchParams.set("locale", this.locale), i && (i.callback && n.searchParams.set("callback_url", i.callback), i.redirectUri && n.searchParams.set("redirect_uri", i.redirectUri)), n.toString();
|
|
204
202
|
}
|
|
205
203
|
/**
|
|
206
204
|
* Creates a new embedded component
|
|
@@ -213,7 +211,7 @@ class L {
|
|
|
213
211
|
* @internal
|
|
214
212
|
*/
|
|
215
213
|
createComponent(e, s, r, i) {
|
|
216
|
-
return new
|
|
214
|
+
return new w(
|
|
217
215
|
this.componentUrl(e, s, r, i),
|
|
218
216
|
s
|
|
219
217
|
);
|
|
@@ -227,7 +225,12 @@ class L {
|
|
|
227
225
|
* @returns A new EmbeddedComponent instance for withdrawal assistance
|
|
228
226
|
*/
|
|
229
227
|
createWithdrawalAssist(e, s, r) {
|
|
230
|
-
return this.createComponent(
|
|
228
|
+
return this.createComponent(
|
|
229
|
+
"withdrawal-assist",
|
|
230
|
+
e,
|
|
231
|
+
s,
|
|
232
|
+
r
|
|
233
|
+
);
|
|
231
234
|
}
|
|
232
235
|
/**
|
|
233
236
|
* Creates a wallet assist component
|
|
@@ -239,7 +242,12 @@ class L {
|
|
|
239
242
|
* @alpha
|
|
240
243
|
*/
|
|
241
244
|
createWalletAssist(e, s, r) {
|
|
242
|
-
return this.createComponent(
|
|
245
|
+
return this.createComponent(
|
|
246
|
+
"wallet-assist",
|
|
247
|
+
e,
|
|
248
|
+
s,
|
|
249
|
+
r
|
|
250
|
+
);
|
|
243
251
|
}
|
|
244
252
|
/**
|
|
245
253
|
* Creates a deposit assist component
|
|
@@ -285,7 +293,12 @@ class L {
|
|
|
285
293
|
* @public
|
|
286
294
|
*/
|
|
287
295
|
createDepositRequest(e, s, r) {
|
|
288
|
-
return this.createComponent(
|
|
296
|
+
return this.createComponent(
|
|
297
|
+
"deposit-request",
|
|
298
|
+
e,
|
|
299
|
+
s,
|
|
300
|
+
r
|
|
301
|
+
);
|
|
289
302
|
}
|
|
290
303
|
/**
|
|
291
304
|
* Decodes a URL fragment into an object
|
|
@@ -296,8 +309,8 @@ class L {
|
|
|
296
309
|
decodeFragmentToObject(e) {
|
|
297
310
|
return e.slice(1).split("&").reduce(
|
|
298
311
|
(r, i) => {
|
|
299
|
-
const [n,
|
|
300
|
-
return r[decodeURIComponent(n)] = decodeURIComponent(
|
|
312
|
+
const [n, h] = i.split("=");
|
|
313
|
+
return r[decodeURIComponent(n)] = decodeURIComponent(h), r;
|
|
301
314
|
},
|
|
302
315
|
{}
|
|
303
316
|
);
|
|
@@ -306,9 +319,10 @@ class L {
|
|
|
306
319
|
export {
|
|
307
320
|
u as AgentType,
|
|
308
321
|
a as CMType,
|
|
322
|
+
w as EmbeddedComponent,
|
|
309
323
|
E as PersonType,
|
|
310
324
|
p as ProofStatus,
|
|
311
325
|
g as ProofTypes,
|
|
312
326
|
f as Status,
|
|
313
|
-
|
|
327
|
+
R as default
|
|
314
328
|
};
|
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"author": "Notabene <developers@notabene.id>",
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "2.0.0-next.
|
|
12
|
+
"version": "2.0.0-next.17",
|
|
13
13
|
"source": "src/notabene.ts",
|
|
14
14
|
"main": "dist/notabene.js",
|
|
15
15
|
"types": "dist/notabene.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"build:clean": "rimraf dist/ ts-out",
|
|
31
31
|
"build": "yarn lint && vite build && tsc && api-extractor run && yarn docs ",
|
|
32
32
|
"lint": "eslint .",
|
|
33
|
+
"format": "prettier --write .",
|
|
33
34
|
"test": "vitest",
|
|
34
35
|
"release": "semantic-release",
|
|
35
36
|
"publish": "yarn build && npm publish --tag next"
|
|
@@ -37,32 +38,32 @@
|
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@commitlint/cli": "^19.5.0",
|
|
39
40
|
"@commitlint/config-conventional": "^19.5.0",
|
|
40
|
-
"@eslint/js": "^9.
|
|
41
|
+
"@eslint/js": "^9.13.0",
|
|
41
42
|
"@fast-check/vitest": "^0.1.3",
|
|
42
|
-
"@microsoft/api-extractor": "^7.47.
|
|
43
|
+
"@microsoft/api-extractor": "^7.47.11",
|
|
43
44
|
"@semantic-release/git": "^10.0.1",
|
|
44
|
-
"@semantic-release/gitlab": "^
|
|
45
|
-
"@semantic-release/npm": "^
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
47
|
-
"@typescript-eslint/parser": "^8.
|
|
48
|
-
"eslint": "^9.
|
|
45
|
+
"@semantic-release/gitlab": "^13.2.1",
|
|
46
|
+
"@semantic-release/npm": "^12.0.1",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
|
48
|
+
"@typescript-eslint/parser": "^8.11.0",
|
|
49
|
+
"eslint": "^9.13.0",
|
|
49
50
|
"eslint-config-prettier": "^9.1.0",
|
|
50
51
|
"eslint-plugin-prettier": "^5.2.1",
|
|
51
52
|
"fast-check": "^3.22.0",
|
|
52
|
-
"globals": "^15.
|
|
53
|
-
"husky": "^
|
|
54
|
-
"jsdom": "^25.0.
|
|
55
|
-
"lint-staged": "^
|
|
56
|
-
"organize-imports-cli": "^0.
|
|
53
|
+
"globals": "^15.11.0",
|
|
54
|
+
"husky": "^9.1.6",
|
|
55
|
+
"jsdom": "^25.0.1",
|
|
56
|
+
"lint-staged": "^15.2.10",
|
|
57
|
+
"organize-imports-cli": "^0.10.0",
|
|
57
58
|
"prettier": "^3.3.3",
|
|
58
59
|
"rimraf": "^6.0.1",
|
|
59
|
-
"semantic-release": "^24.1.
|
|
60
|
-
"typedoc": "^0.26.
|
|
61
|
-
"typedoc-plugin-markdown": "^4.2.
|
|
62
|
-
"typescript": "^5.6.
|
|
63
|
-
"typescript-eslint": "^8.
|
|
64
|
-
"vite": "^5.4.
|
|
65
|
-
"vitest": "^2.1.
|
|
60
|
+
"semantic-release": "^24.1.3",
|
|
61
|
+
"typedoc": "^0.26.10",
|
|
62
|
+
"typedoc-plugin-markdown": "^4.2.9",
|
|
63
|
+
"typescript": "^5.6.3",
|
|
64
|
+
"typescript-eslint": "^8.11.0",
|
|
65
|
+
"vite": "^5.4.10",
|
|
66
|
+
"vitest": "^2.1.3"
|
|
66
67
|
},
|
|
67
68
|
"lint-staged": {
|
|
68
69
|
"*.ts": [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CMType,
|
|
3
|
-
ComponentRequest,
|
|
4
3
|
HMType,
|
|
5
4
|
HostMessage,
|
|
5
|
+
TransactionResponse,
|
|
6
6
|
ValidationError,
|
|
7
7
|
} from '../types';
|
|
8
8
|
import {
|
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
export default class EmbeddedComponent<V
|
|
18
|
+
export default class EmbeddedComponent<V> {
|
|
19
19
|
private _url: string;
|
|
20
|
-
private _value: V
|
|
20
|
+
private _value: Partial<V>;
|
|
21
21
|
private _errors: ValidationError[] = [];
|
|
22
22
|
|
|
23
23
|
private iframe?: HTMLIFrameElement;
|
|
24
|
-
private eventManager: MessageEventManager
|
|
24
|
+
private eventManager: MessageEventManager<V>;
|
|
25
25
|
private modal?: HTMLDialogElement;
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -30,10 +30,10 @@ export default class EmbeddedComponent<V, R> {
|
|
|
30
30
|
* @param value - The initial transaction value
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
constructor(url: string, value: V) {
|
|
33
|
+
constructor(url: string, value: Partial<V>) {
|
|
34
34
|
this._url = url;
|
|
35
35
|
this._value = value;
|
|
36
|
-
this.eventManager = new MessageEventManager();
|
|
36
|
+
this.eventManager = new MessageEventManager<V>();
|
|
37
37
|
this.on(CMType.INVALID, (message) => {
|
|
38
38
|
if (message.type === CMType.INVALID) {
|
|
39
39
|
this._errors = message.errors;
|
|
@@ -59,7 +59,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
59
59
|
* @returns The current transaction value
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
|
-
public get value(): V {
|
|
62
|
+
public get value(): Partial<V> {
|
|
63
63
|
return this._value;
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -119,7 +119,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
119
119
|
* Sends a message to the embedded component
|
|
120
120
|
* @param message - The message to send
|
|
121
121
|
*/
|
|
122
|
-
send(message: HostMessage): void {
|
|
122
|
+
send(message: HostMessage<V>): void {
|
|
123
123
|
this.eventManager.send(message);
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -129,7 +129,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
129
129
|
* @param callback - The callback function to execute when the message is received
|
|
130
130
|
*/
|
|
131
131
|
|
|
132
|
-
on(messageType: string, callback: MessageCallback): void {
|
|
132
|
+
on(messageType: string, callback: MessageCallback<V>): void {
|
|
133
133
|
this.eventManager.on(messageType, callback);
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -139,7 +139,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
139
139
|
* @param callback - The callback function to remove
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
|
-
off(messageType: string, callback: MessageCallback): void {
|
|
142
|
+
off(messageType: string, callback: MessageCallback<V>): void {
|
|
143
143
|
this.eventManager.off(messageType, callback);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -147,9 +147,9 @@ export default class EmbeddedComponent<V, R> {
|
|
|
147
147
|
* Updates the transaction value and sends an update message to the component
|
|
148
148
|
* @param value - The new transaction value
|
|
149
149
|
*/
|
|
150
|
-
update(value: V) {
|
|
150
|
+
update(value: Partial<V>) {
|
|
151
151
|
this._value = value;
|
|
152
|
-
this.send({ type: HMType.UPDATE, value: value
|
|
152
|
+
this.send({ type: HMType.UPDATE, value: value });
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
@@ -157,7 +157,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
157
157
|
* @returns A promise that resolves with the transaction response
|
|
158
158
|
*/
|
|
159
159
|
|
|
160
|
-
completion(): Promise<
|
|
160
|
+
completion(): Promise<TransactionResponse<V>> {
|
|
161
161
|
return new Promise((resolve, reject) => {
|
|
162
162
|
this.on(CMType.COMPLETE, (message) => {
|
|
163
163
|
resolve((message as any).response);
|
|
@@ -172,26 +172,24 @@ export default class EmbeddedComponent<V, R> {
|
|
|
172
172
|
* Opens the component in a modal dialog
|
|
173
173
|
*/
|
|
174
174
|
|
|
175
|
-
openModal(): Promise<
|
|
175
|
+
openModal(): Promise<TransactionResponse<V>> {
|
|
176
176
|
if (this.modal) {
|
|
177
177
|
this.closeModal();
|
|
178
178
|
}
|
|
179
179
|
this.modal = document.createElement('dialog');
|
|
180
180
|
this.modal.style.border = 'none';
|
|
181
|
-
this.modal.style.backgroundColor = '
|
|
181
|
+
this.modal.style.backgroundColor = 'white';
|
|
182
182
|
this.modal.style.maxWidth = '100vw';
|
|
183
183
|
this.modal.style.maxHeight = '100vh';
|
|
184
184
|
this.modal.style.width = '600px';
|
|
185
|
-
this.modal.style.height = '
|
|
185
|
+
this.modal.style.height = '600px';
|
|
186
186
|
|
|
187
187
|
document.body.appendChild(this.modal);
|
|
188
188
|
this.embed(this.modal, true);
|
|
189
189
|
this.on(CMType.CANCEL, () => {
|
|
190
190
|
this.closeModal();
|
|
191
191
|
});
|
|
192
|
-
|
|
193
|
-
this.closeModal();
|
|
194
|
-
});
|
|
192
|
+
|
|
195
193
|
this.on(CMType.COMPLETE, () => {
|
|
196
194
|
this.closeModal();
|
|
197
195
|
});
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
HMType,
|
|
5
5
|
HostMessage,
|
|
6
6
|
Transaction,
|
|
7
|
-
TransactionResponse,
|
|
8
7
|
Withdrawal,
|
|
9
8
|
} from '../../types';
|
|
10
9
|
import EmbeddedComponent from '../EmbeddedComponent';
|
|
@@ -15,15 +14,11 @@ const value: Partial<Transaction> = { amountDecimal: 100 };
|
|
|
15
14
|
|
|
16
15
|
describe('EmbeddedComponent', () => {
|
|
17
16
|
describe('creation', () => {
|
|
18
|
-
let component: EmbeddedComponent<
|
|
19
|
-
Partial<Withdrawal>,
|
|
20
|
-
TransactionResponse<Withdrawal>
|
|
21
|
-
>;
|
|
17
|
+
let component: EmbeddedComponent<Withdrawal>;
|
|
22
18
|
beforeEach(() => {
|
|
23
|
-
component = new EmbeddedComponent<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
>(url, { amountDecimal: 100 });
|
|
19
|
+
component = new EmbeddedComponent<Withdrawal>(url, {
|
|
20
|
+
amountDecimal: 100,
|
|
21
|
+
});
|
|
27
22
|
});
|
|
28
23
|
|
|
29
24
|
test('sets value', () => {
|
|
@@ -73,20 +68,14 @@ describe('EmbeddedComponent', () => {
|
|
|
73
68
|
});
|
|
74
69
|
|
|
75
70
|
test('mount', () => {
|
|
76
|
-
const component = new EmbeddedComponent<
|
|
77
|
-
Partial<Withdrawal>,
|
|
78
|
-
TransactionResponse<Withdrawal>
|
|
79
|
-
>(url, value);
|
|
71
|
+
const component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
80
72
|
component.mount(parentId);
|
|
81
73
|
expect(iframe?.src).toBe(url + '&embedded=true');
|
|
82
74
|
expect(parentElement.appendChild).toHaveBeenCalledWith(iframe);
|
|
83
75
|
});
|
|
84
76
|
|
|
85
77
|
test('on', () => {
|
|
86
|
-
const component = new EmbeddedComponent<
|
|
87
|
-
Partial<Withdrawal>,
|
|
88
|
-
TransactionResponse<Withdrawal>
|
|
89
|
-
>(url, value);
|
|
78
|
+
const component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
90
79
|
const messageType = 'customEvent';
|
|
91
80
|
const callback = vi.fn();
|
|
92
81
|
component.on(messageType, callback);
|
|
@@ -97,10 +86,7 @@ describe('EmbeddedComponent', () => {
|
|
|
97
86
|
});
|
|
98
87
|
|
|
99
88
|
test('off', () => {
|
|
100
|
-
const component = new EmbeddedComponent<
|
|
101
|
-
Partial<Withdrawal>,
|
|
102
|
-
TransactionResponse<Withdrawal>
|
|
103
|
-
>(url, value);
|
|
89
|
+
const component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
104
90
|
const messageType = 'customEvent';
|
|
105
91
|
const callback = vi.fn();
|
|
106
92
|
component.on(messageType, callback);
|
|
@@ -118,10 +104,7 @@ describe('EmbeddedComponent', () => {
|
|
|
118
104
|
let messageHandler: (event: MessageEvent) => void;
|
|
119
105
|
let port: MessagePort;
|
|
120
106
|
let handshake: MessageEvent;
|
|
121
|
-
let component: EmbeddedComponent<
|
|
122
|
-
Partial<Withdrawal>,
|
|
123
|
-
TransactionResponse<Withdrawal>
|
|
124
|
-
>;
|
|
107
|
+
let component: EmbeddedComponent<Withdrawal>;
|
|
125
108
|
|
|
126
109
|
beforeEach(() => {
|
|
127
110
|
port = {
|
|
@@ -138,10 +121,7 @@ describe('EmbeddedComponent', () => {
|
|
|
138
121
|
.mockImplementation((event, handler) => {
|
|
139
122
|
messageHandler = handler;
|
|
140
123
|
});
|
|
141
|
-
component = new EmbeddedComponent<
|
|
142
|
-
Partial<Withdrawal>,
|
|
143
|
-
TransactionResponse<Withdrawal>
|
|
144
|
-
>(url, value);
|
|
124
|
+
component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
145
125
|
component.mount(parentId);
|
|
146
126
|
|
|
147
127
|
expect(messageHandler).toBeDefined();
|
|
@@ -149,7 +129,7 @@ describe('EmbeddedComponent', () => {
|
|
|
149
129
|
});
|
|
150
130
|
|
|
151
131
|
test('send', () => {
|
|
152
|
-
const message: HostMessage = {
|
|
132
|
+
const message: HostMessage<Withdrawal> = {
|
|
153
133
|
type: HMType.UPDATE,
|
|
154
134
|
value: {
|
|
155
135
|
requestId: 'id',
|
|
@@ -175,7 +155,7 @@ describe('EmbeddedComponent', () => {
|
|
|
175
155
|
// @ts-expect-error - we've already verified that port exists
|
|
176
156
|
port.onmessage({
|
|
177
157
|
data: { type: CMType.COMPLETE, response },
|
|
178
|
-
}
|
|
158
|
+
});
|
|
179
159
|
|
|
180
160
|
promise.then((result) => {
|
|
181
161
|
expect(result).toBe(response);
|
package/src/notabene.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
CallbackOptions,
|
|
5
5
|
ComponentMessage,
|
|
6
6
|
ConnectionRequest,
|
|
7
|
-
ConnectionResponse,
|
|
8
7
|
Counterparty,
|
|
9
8
|
DeclarationProof,
|
|
10
9
|
Deposit,
|
|
@@ -35,11 +34,11 @@ import {
|
|
|
35
34
|
} from './types';
|
|
36
35
|
import { encodeObjectToFragment } from './utils/urls';
|
|
37
36
|
|
|
37
|
+
// Must be exported for React Native SDK to use
|
|
38
|
+
export { default as EmbeddedComponent } from './components/EmbeddedComponent';
|
|
38
39
|
export type {
|
|
39
40
|
ComponentMessage,
|
|
40
|
-
EmbeddedComponent,
|
|
41
41
|
ConnectionRequest,
|
|
42
|
-
ConnectionResponse,
|
|
43
42
|
HostMessage,
|
|
44
43
|
Theme,
|
|
45
44
|
Counterparty,
|
|
@@ -182,13 +181,13 @@ export default class Notabene {
|
|
|
182
181
|
* @returns A new EmbeddedComponent instance
|
|
183
182
|
* @internal
|
|
184
183
|
*/
|
|
185
|
-
createComponent<V
|
|
184
|
+
createComponent<V>(
|
|
186
185
|
path: string,
|
|
187
|
-
value: V
|
|
186
|
+
value: Partial<V>,
|
|
188
187
|
options?: TransactionOptions,
|
|
189
188
|
callbacks?: CallbackOptions,
|
|
190
189
|
) {
|
|
191
|
-
return new EmbeddedComponent<V
|
|
190
|
+
return new EmbeddedComponent<V>(
|
|
192
191
|
this.componentUrl(path, value, options, callbacks),
|
|
193
192
|
value,
|
|
194
193
|
);
|
|
@@ -207,10 +206,12 @@ export default class Notabene {
|
|
|
207
206
|
options?: TransactionOptions,
|
|
208
207
|
callbacks?: CallbackOptions,
|
|
209
208
|
) {
|
|
210
|
-
return this.createComponent<
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
return this.createComponent<Withdrawal>(
|
|
210
|
+
'withdrawal-assist',
|
|
211
|
+
value,
|
|
212
|
+
options,
|
|
213
|
+
callbacks,
|
|
214
|
+
);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
/**
|
|
@@ -227,10 +228,12 @@ export default class Notabene {
|
|
|
227
228
|
options?: TransactionOptions,
|
|
228
229
|
callbacks?: CallbackOptions,
|
|
229
230
|
) {
|
|
230
|
-
return this.createComponent<
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
return this.createComponent<Withdrawal>(
|
|
232
|
+
'wallet-assist',
|
|
233
|
+
value,
|
|
234
|
+
options,
|
|
235
|
+
callbacks,
|
|
236
|
+
);
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
/**
|
|
@@ -247,7 +250,7 @@ export default class Notabene {
|
|
|
247
250
|
options?: any,
|
|
248
251
|
callbacks?: CallbackOptions,
|
|
249
252
|
) {
|
|
250
|
-
return this.createComponent<
|
|
253
|
+
return this.createComponent<Deposit>(
|
|
251
254
|
'deposit-assist',
|
|
252
255
|
value,
|
|
253
256
|
options,
|
|
@@ -269,7 +272,7 @@ export default class Notabene {
|
|
|
269
272
|
options?: TransactionOptions,
|
|
270
273
|
callbacks?: CallbackOptions,
|
|
271
274
|
) {
|
|
272
|
-
return this.createComponent<ConnectionRequest
|
|
275
|
+
return this.createComponent<ConnectionRequest>(
|
|
273
276
|
'connect',
|
|
274
277
|
value,
|
|
275
278
|
options,
|
|
@@ -291,10 +294,12 @@ export default class Notabene {
|
|
|
291
294
|
options?: TransactionOptions,
|
|
292
295
|
callbacks?: CallbackOptions,
|
|
293
296
|
) {
|
|
294
|
-
return this.createComponent<
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
297
|
+
return this.createComponent<DepositRequest>(
|
|
298
|
+
'deposit-request',
|
|
299
|
+
value,
|
|
300
|
+
options,
|
|
301
|
+
callbacks,
|
|
302
|
+
);
|
|
298
303
|
}
|
|
299
304
|
|
|
300
305
|
/**
|
package/src/types.ts
CHANGED
|
@@ -355,17 +355,6 @@ export interface ConnectionRequest extends ComponentRequest {
|
|
|
355
355
|
asset: TransactionAsset;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
/**
|
|
359
|
-
* An object representing a connection response
|
|
360
|
-
* @public
|
|
361
|
-
*/
|
|
362
|
-
export interface ConnectionResponse extends ComponentResponse {
|
|
363
|
-
value: ConnectionRequest;
|
|
364
|
-
ivms: IVMS101;
|
|
365
|
-
proof?: OwnershipProof;
|
|
366
|
-
txCreate?: V1Transaction;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
358
|
/**
|
|
370
359
|
* The verification status of a transaction
|
|
371
360
|
* @public
|
|
@@ -469,19 +458,19 @@ export const enum CMType {
|
|
|
469
458
|
RESULT = 'result',
|
|
470
459
|
READY = 'ready',
|
|
471
460
|
INVALID = 'invalid',
|
|
472
|
-
MODAL = 'openModal',
|
|
473
461
|
ERROR = 'error',
|
|
474
|
-
CLOSE = 'closeModal',
|
|
475
462
|
CANCEL = 'cancel',
|
|
476
463
|
}
|
|
477
464
|
|
|
478
465
|
/**
|
|
479
466
|
* Represents a completed component message
|
|
467
|
+
* @typeParam T - The overall Value type being returned
|
|
468
|
+
* @param response - The Response object which wraps T
|
|
480
469
|
* @public
|
|
481
470
|
*/
|
|
482
|
-
export type Completed = {
|
|
471
|
+
export type Completed<T> = {
|
|
483
472
|
type: CMType.COMPLETE;
|
|
484
|
-
response:
|
|
473
|
+
response: TransactionResponse<T>;
|
|
485
474
|
};
|
|
486
475
|
|
|
487
476
|
/**
|
|
@@ -493,8 +482,8 @@ export type Ready = {
|
|
|
493
482
|
};
|
|
494
483
|
|
|
495
484
|
/**
|
|
496
|
-
* Represents a resize request component message
|
|
497
|
-
* @
|
|
485
|
+
* Represents a resize request component message. This is handled by the library.
|
|
486
|
+
* @internal
|
|
498
487
|
*/
|
|
499
488
|
export type ResizeRequest = {
|
|
500
489
|
type: CMType.RESIZE;
|
|
@@ -503,6 +492,7 @@ export type ResizeRequest = {
|
|
|
503
492
|
|
|
504
493
|
/**
|
|
505
494
|
* Represents an error component message
|
|
495
|
+
* @param message - Error message
|
|
506
496
|
* @public
|
|
507
497
|
*/
|
|
508
498
|
export type Error = {
|
|
@@ -512,7 +502,7 @@ export type Error = {
|
|
|
512
502
|
|
|
513
503
|
/**
|
|
514
504
|
* Represents a cancel component message
|
|
515
|
-
* @
|
|
505
|
+
* @internal
|
|
516
506
|
*/
|
|
517
507
|
export type Cancel = {
|
|
518
508
|
type: CMType.CANCEL;
|
|
@@ -520,11 +510,14 @@ export type Cancel = {
|
|
|
520
510
|
|
|
521
511
|
/**
|
|
522
512
|
* Represents an invalid value component message
|
|
523
|
-
* @
|
|
513
|
+
* @typeParam T - The overall Value type being returned
|
|
514
|
+
* @param value - The current Partial value
|
|
515
|
+
* @param errors - Array of validation errors
|
|
516
|
+
* @internal
|
|
524
517
|
*/
|
|
525
|
-
export type InvalidValue = {
|
|
518
|
+
export type InvalidValue<T> = {
|
|
526
519
|
type: CMType.INVALID;
|
|
527
|
-
value:
|
|
520
|
+
value: Partial<T>;
|
|
528
521
|
errors: ValidationError[];
|
|
529
522
|
};
|
|
530
523
|
|
|
@@ -532,13 +525,13 @@ export type InvalidValue = {
|
|
|
532
525
|
* Component Message
|
|
533
526
|
* @public
|
|
534
527
|
*/
|
|
535
|
-
export type ComponentMessage =
|
|
536
|
-
| Completed
|
|
528
|
+
export type ComponentMessage<T> =
|
|
529
|
+
| Completed<T>
|
|
537
530
|
| Cancel
|
|
538
531
|
| Error
|
|
539
532
|
| Ready
|
|
540
533
|
| ResizeRequest
|
|
541
|
-
| InvalidValue
|
|
534
|
+
| InvalidValue<T>;
|
|
542
535
|
|
|
543
536
|
/**
|
|
544
537
|
* Host Message Types
|
|
@@ -551,19 +544,19 @@ export const enum HMType {
|
|
|
551
544
|
}
|
|
552
545
|
|
|
553
546
|
/**
|
|
554
|
-
* Represents an update value host message
|
|
547
|
+
* Represents an update value host message. This is sent from Host to component.
|
|
555
548
|
* @public
|
|
556
549
|
*/
|
|
557
|
-
export type UpdateValue = {
|
|
550
|
+
export type UpdateValue<T> = {
|
|
558
551
|
type: HMType.UPDATE;
|
|
559
|
-
value:
|
|
552
|
+
value: Partial<T>;
|
|
560
553
|
};
|
|
561
554
|
|
|
562
555
|
/**
|
|
563
556
|
* Host Messages
|
|
564
557
|
* @public
|
|
565
558
|
*/
|
|
566
|
-
export type HostMessage = UpdateValue
|
|
559
|
+
export type HostMessage<T> = UpdateValue<T>;
|
|
567
560
|
|
|
568
561
|
/**
|
|
569
562
|
* Options for callback and redirect URIs
|
|
@@ -592,6 +585,7 @@ export enum ProofStatus {
|
|
|
592
585
|
export enum ProofTypes {
|
|
593
586
|
SelfDeclaration = 'self-declaration',
|
|
594
587
|
PersonalSignEIP191 = 'eip-191',
|
|
588
|
+
SIWE = 'siwe',
|
|
595
589
|
PersonalSignEIP712 = 'eip-712',
|
|
596
590
|
PersonalSignBIP137 = 'bip-137',
|
|
597
591
|
PersonalSignXPUB = 'xpub',
|
|
@@ -619,6 +613,7 @@ export interface SignatureProof extends OwnershipProof {
|
|
|
619
613
|
| ProofTypes.PersonalSignEIP191
|
|
620
614
|
| ProofTypes.PersonalSignEIP712
|
|
621
615
|
| ProofTypes.PersonalSignBIP137
|
|
616
|
+
| ProofTypes.SIWE
|
|
622
617
|
| ProofTypes.PersonalSignXPUB;
|
|
623
618
|
proof: string;
|
|
624
619
|
attestation: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ComponentMessage, HostMessage } from '../types';
|
|
2
2
|
|
|
3
|
-
export type MessageCallback = (message: ComponentMessage) => void;
|
|
3
|
+
export type MessageCallback<T> = (message: ComponentMessage<T>) => void;
|
|
4
4
|
|
|
5
|
-
export class MessageEventManager {
|
|
6
|
-
private listeners: Map<string, Set<MessageCallback
|
|
5
|
+
export class MessageEventManager<T> {
|
|
6
|
+
private listeners: Map<string, Set<MessageCallback<T>>> = new Map();
|
|
7
7
|
private port?: MessagePort;
|
|
8
8
|
|
|
9
9
|
constructor() {
|
|
@@ -16,14 +16,14 @@ export class MessageEventManager {
|
|
|
16
16
|
this.port.start();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
on(messageType: string, callback: MessageCallback): void {
|
|
19
|
+
on(messageType: string, callback: MessageCallback<T>): void {
|
|
20
20
|
if (!this.listeners.has(messageType)) {
|
|
21
21
|
this.listeners.set(messageType, new Set());
|
|
22
22
|
}
|
|
23
23
|
this.listeners.get(messageType)!.add(callback);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
off(messageType: string, callback: MessageCallback): void {
|
|
26
|
+
off(messageType: string, callback: MessageCallback<T>): void {
|
|
27
27
|
const callbacks = this.listeners.get(messageType);
|
|
28
28
|
if (callbacks) {
|
|
29
29
|
callbacks.delete(callback);
|
|
@@ -33,7 +33,7 @@ export class MessageEventManager {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
private handleMessage(event: MessageEvent): void {
|
|
36
|
+
private handleMessage(event: MessageEvent<ComponentMessage<T>>): void {
|
|
37
37
|
// console.log('received message', event.data);
|
|
38
38
|
const message = event.data;
|
|
39
39
|
if (typeof message === 'object' && message !== null && 'type' in message) {
|
|
@@ -46,7 +46,7 @@ export class MessageEventManager {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Method to send messages through the port
|
|
49
|
-
send(message: HostMessage): void {
|
|
49
|
+
send(message: HostMessage<T>): void {
|
|
50
50
|
if (this.port) {
|
|
51
51
|
this.port.postMessage(message);
|
|
52
52
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { HMType, UpdateValue } from '../../types';
|
|
2
|
+
import { HMType, UpdateValue, Withdrawal } from '../../types';
|
|
3
3
|
import { MessageEventManager } from '../MessageEventManager';
|
|
4
4
|
|
|
5
5
|
describe('MessageEventManager', () => {
|
|
6
|
-
let messageEventManager: MessageEventManager
|
|
6
|
+
let messageEventManager: MessageEventManager<Withdrawal>;
|
|
7
7
|
let mockPort: MessagePort;
|
|
8
8
|
|
|
9
9
|
beforeEach(() => {
|
|
@@ -73,7 +73,7 @@ describe('MessageEventManager', () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
it('should send messages through the port', () => {
|
|
76
|
-
const message: UpdateValue = {
|
|
76
|
+
const message: UpdateValue<Withdrawal> = {
|
|
77
77
|
type: HMType.UPDATE,
|
|
78
78
|
value: { requestId: 'id' },
|
|
79
79
|
};
|