@didit-protocol/sdk-web 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/didit-sdk.cjs.js +954 -4
- package/dist/didit-sdk.cjs.js.map +1 -1
- package/dist/didit-sdk.esm.js +953 -5
- package/dist/didit-sdk.esm.js.map +1 -1
- package/dist/didit-sdk.umd.js +954 -4
- package/dist/didit-sdk.umd.js.map +1 -1
- package/dist/didit-sdk.umd.min.js +2 -2
- package/dist/didit-sdk.umd.min.js.map +1 -1
- package/dist/index.d.ts +247 -3
- package/package.json +6 -2
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,172 @@ interface VerificationEvent {
|
|
|
53
53
|
type VerificationCallback = (result: VerificationResult) => void;
|
|
54
54
|
type StateChangeCallback = (state: DiditSdkState, error?: string) => void;
|
|
55
55
|
type EventCallback = (event: VerificationEvent) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Payment method attached to a transaction participant.
|
|
58
|
+
*/
|
|
59
|
+
interface DiditTransactionPaymentMethod {
|
|
60
|
+
/** Payment method kind, e.g. "card", "bank_account", "crypto", "unhosted_wallet". */
|
|
61
|
+
type?: string;
|
|
62
|
+
/** Account identifier: card fingerprint, IBAN, wallet address, etc. */
|
|
63
|
+
accountId?: string;
|
|
64
|
+
/** ISO country code of the issuing institution. */
|
|
65
|
+
issuingCountry?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A transaction participant (subject or counterparty).
|
|
69
|
+
*/
|
|
70
|
+
interface DiditTransactionParticipant {
|
|
71
|
+
/** Entity type: "individual" (default) or "company". */
|
|
72
|
+
type?: string;
|
|
73
|
+
/** Your external user id (vendor data). For the subject it is enforced server-side from the transaction token. */
|
|
74
|
+
externalUserId?: string;
|
|
75
|
+
fullName?: string;
|
|
76
|
+
firstName?: string;
|
|
77
|
+
lastName?: string;
|
|
78
|
+
/** Date of birth in YYYY-MM-DD format. */
|
|
79
|
+
dob?: string;
|
|
80
|
+
/** Free-form address object, e.g. { country: "US", city: "..." }. */
|
|
81
|
+
address?: Record<string, unknown>;
|
|
82
|
+
/** Institution details for company participants. */
|
|
83
|
+
institutionInfo?: Record<string, unknown>;
|
|
84
|
+
/** Optional explicit device context. Device intelligence is attached automatically by the SDK. */
|
|
85
|
+
device?: Record<string, unknown>;
|
|
86
|
+
paymentMethod?: DiditTransactionPaymentMethod;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Monetary and routing details of the transaction.
|
|
90
|
+
*/
|
|
91
|
+
interface DiditTransactionDetails {
|
|
92
|
+
/** Direction of the transaction: "in" or "out". */
|
|
93
|
+
direction: string;
|
|
94
|
+
amount: number | string;
|
|
95
|
+
/** Currency code, e.g. "USD" or "BTC". */
|
|
96
|
+
currency: string;
|
|
97
|
+
/** Currency kind: "fiat" or "crypto". */
|
|
98
|
+
currencyType?: string;
|
|
99
|
+
amountInDefaultCurrency?: number | string;
|
|
100
|
+
defaultCurrencyCode?: string;
|
|
101
|
+
/** Free-form payment description. */
|
|
102
|
+
paymentDetails?: string;
|
|
103
|
+
/** Payment reference id; the on-chain transaction hash for crypto transactions. */
|
|
104
|
+
paymentTxnId?: string;
|
|
105
|
+
/** Action type override; defaults to the transaction category. */
|
|
106
|
+
actionType?: string;
|
|
107
|
+
/** Crypto-specific parameters, e.g. { crypto_chain: "ETH" }. */
|
|
108
|
+
cryptoParams?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Travel-rule details for travel-rule transactions.
|
|
112
|
+
*/
|
|
113
|
+
interface DiditTravelRuleDetails {
|
|
114
|
+
status: string;
|
|
115
|
+
protocol?: string;
|
|
116
|
+
required?: boolean;
|
|
117
|
+
obligationsCount?: number;
|
|
118
|
+
originatorData?: Record<string, unknown>;
|
|
119
|
+
beneficiaryData?: Record<string, unknown>;
|
|
120
|
+
metadata?: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The camelCase transaction payload submitted to POST /v1/transactions/.
|
|
124
|
+
*/
|
|
125
|
+
interface DiditTransactionPayload {
|
|
126
|
+
/** Your unique transaction id. */
|
|
127
|
+
txnId: string;
|
|
128
|
+
/** Transaction timestamp as an ISO-8601 string. Defaults to now server-side. */
|
|
129
|
+
txnDate?: string;
|
|
130
|
+
/** IANA time zone id, e.g. "Europe/Madrid". */
|
|
131
|
+
zoneId?: string;
|
|
132
|
+
/** Transaction category, e.g. "finance", "kyc", "travelRule", "userPlatformEvent", "gamblingBet". */
|
|
133
|
+
category: string;
|
|
134
|
+
details: DiditTransactionDetails;
|
|
135
|
+
subject: DiditTransactionParticipant;
|
|
136
|
+
counterparty?: DiditTransactionParticipant;
|
|
137
|
+
/** Custom key/value properties stored with the transaction. */
|
|
138
|
+
customProperties?: Record<string, unknown>;
|
|
139
|
+
travelRule?: DiditTravelRuleDetails;
|
|
140
|
+
/** Force crypto AML screening on/off; defaults to the application monitoring settings. */
|
|
141
|
+
includeCryptoScreening?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/** Known action types: "verification_session" and "wallet_ownership". */
|
|
144
|
+
type TransactionActionType = "verification_session" | "wallet_ownership";
|
|
145
|
+
/**
|
|
146
|
+
* A user action required to complete the transaction, e.g. a biometric
|
|
147
|
+
* verification session or a wallet-ownership confirmation widget.
|
|
148
|
+
*/
|
|
149
|
+
interface TransactionActionRequired {
|
|
150
|
+
/** "verification_session" or "wallet_ownership". */
|
|
151
|
+
type: string;
|
|
152
|
+
/** Hosted URL of the required action flow (didit.me origin). */
|
|
153
|
+
url: string;
|
|
154
|
+
/** Verification session id (verification_session actions). */
|
|
155
|
+
sessionId?: string;
|
|
156
|
+
/** Verification session token (verification_session actions). */
|
|
157
|
+
sessionToken?: string;
|
|
158
|
+
/** Verification session status (verification_session actions). */
|
|
159
|
+
status?: string;
|
|
160
|
+
/** Wallet-ownership widget session id (wallet_ownership actions). */
|
|
161
|
+
widgetSessionId?: string;
|
|
162
|
+
/** Widget expiration timestamp (wallet_ownership actions). */
|
|
163
|
+
expiresAt?: string;
|
|
164
|
+
}
|
|
165
|
+
interface SubmitTransactionResult {
|
|
166
|
+
/** Didit transaction id (UUID). Use it to fetch the transaction later. */
|
|
167
|
+
transactionId: string;
|
|
168
|
+
/** Transaction review status, e.g. "APPROVED", "IN_REVIEW", "AWAITING_USER", "DECLINED". */
|
|
169
|
+
status: string;
|
|
170
|
+
/** Travel-rule exchange status when a travel-rule transfer was initiated. */
|
|
171
|
+
travelRuleStatus?: string;
|
|
172
|
+
/** Present when the end user must complete an additional action. */
|
|
173
|
+
actionRequired?: TransactionActionRequired;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Signal delivered alongside a stale/pre-action `result` when the
|
|
177
|
+
* post-action refresh could not complete (e.g. the transaction token became
|
|
178
|
+
* invalid or expired while the user was in the action flow). `type` mirrors
|
|
179
|
+
* {@link TransactionErrorType}; terminal auth failures (`invalid_token`,
|
|
180
|
+
* `expired_token`) are the only cases currently reported here.
|
|
181
|
+
*/
|
|
182
|
+
interface TransactionActionCompletedError {
|
|
183
|
+
type: TransactionErrorType;
|
|
184
|
+
message: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Called after an auto-launched `wallet_ownership` action flow completes or
|
|
188
|
+
* its modal is closed. `result` is the refreshed transaction, or the original
|
|
189
|
+
* pre-action result when the refresh could not complete - in which case
|
|
190
|
+
* `error` is set so integrators can distinguish "refresh failed" from "the
|
|
191
|
+
* action genuinely left the transaction unchanged". The `error` parameter
|
|
192
|
+
* is additive: existing single-argument callbacks keep working unchanged.
|
|
193
|
+
* Never invoked for a `verification_session` action, since that type is
|
|
194
|
+
* never auto-launched.
|
|
195
|
+
*/
|
|
196
|
+
type TransactionActionCompletedCallback = (result: SubmitTransactionResult, error?: TransactionActionCompletedError) => void;
|
|
197
|
+
interface SubmitTransactionOptions {
|
|
198
|
+
/** Short-lived transaction token minted by your backend via POST /v3/transactions/sdk-token/. */
|
|
199
|
+
transactionToken: string;
|
|
200
|
+
/** Didit verification API base URL. @default "https://verification.didit.me" */
|
|
201
|
+
baseUrl?: string;
|
|
202
|
+
transaction: DiditTransactionPayload;
|
|
203
|
+
/**
|
|
204
|
+
* Automatically open the verification modal when the response contains a
|
|
205
|
+
* `wallet_ownership` actionRequired block. Has no effect on a
|
|
206
|
+
* `verification_session` action, which is never auto-launched and is
|
|
207
|
+
* always returned in the result's `actionRequired` for the host to launch
|
|
208
|
+
* with its own verification integration.
|
|
209
|
+
* @default true
|
|
210
|
+
*/
|
|
211
|
+
autoLaunchAction?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Called with the refreshed transaction after an auto-launched
|
|
214
|
+
* `wallet_ownership` action flow completes or its modal is closed. Not
|
|
215
|
+
* invoked for `verification_session` actions, since those are never
|
|
216
|
+
* auto-launched.
|
|
217
|
+
*/
|
|
218
|
+
onActionCompleted?: TransactionActionCompletedCallback;
|
|
219
|
+
}
|
|
220
|
+
/** Typed error categories thrown by submitTransaction. */
|
|
221
|
+
type TransactionErrorType = "invalid_token" | "expired_token" | "validation" | "network";
|
|
56
222
|
|
|
57
223
|
declare class DiditSdk {
|
|
58
224
|
private static _instance;
|
|
@@ -64,17 +230,76 @@ declare class DiditSdk {
|
|
|
64
230
|
private _url;
|
|
65
231
|
private _modal;
|
|
66
232
|
private _errorMessage;
|
|
233
|
+
private _actionModal;
|
|
234
|
+
private _actionModalSettle;
|
|
235
|
+
/**
|
|
236
|
+
* Bumped by destroy() to invalidate any transaction action in flight
|
|
237
|
+
* (pending action modal and/or its follow-up poll) so a torn-down SDK
|
|
238
|
+
* instance can never deliver a late onActionCompleted. A new
|
|
239
|
+
* submitTransaction call always reads the current generation, so it is
|
|
240
|
+
* unaffected by a destroy() that happened before it started.
|
|
241
|
+
*/
|
|
242
|
+
private _actionGeneration;
|
|
67
243
|
onComplete: VerificationCallback | undefined;
|
|
68
244
|
onStateChange: StateChangeCallback | undefined;
|
|
69
245
|
onEvent: EventCallback | undefined;
|
|
70
246
|
get state(): DiditSdkState;
|
|
71
247
|
get configuration(): DiditSdkConfiguration | undefined;
|
|
72
248
|
get isPresented(): boolean;
|
|
249
|
+
/**
|
|
250
|
+
* True while a transaction's wallet-ownership action modal (auto-launched
|
|
251
|
+
* by submitTransaction) is on screen. verification_session actions are
|
|
252
|
+
* never auto-launched, so they never affect this flag - see
|
|
253
|
+
* {@link submitTransaction}. Tracked separately from {@link isPresented},
|
|
254
|
+
* which reflects the verification modal only.
|
|
255
|
+
*/
|
|
256
|
+
get isActionModalPresented(): boolean;
|
|
73
257
|
get errorMessage(): string | undefined;
|
|
74
258
|
private constructor();
|
|
75
259
|
startVerification(options: StartVerificationOptions): Promise<void>;
|
|
260
|
+
/**
|
|
261
|
+
* Submits a transaction (including travel-rule and crypto-monitoring payloads)
|
|
262
|
+
* directly from the end-user device.
|
|
263
|
+
*
|
|
264
|
+
* The request is authenticated with a short-lived transaction token minted by
|
|
265
|
+
* your backend (POST /v3/transactions/sdk-token/) and sent via the
|
|
266
|
+
* X-Transaction-Token header. Device intelligence is attached automatically:
|
|
267
|
+
* the SDK collects a didit-fp-v2 fingerprint and sends it as the X-Didit-PID /
|
|
268
|
+
* X-Didit-FP-Hash headers plus a `fingerprint_v2` body field.
|
|
269
|
+
*
|
|
270
|
+
* When the response contains an `actionRequired` block, the contract differs
|
|
271
|
+
* by type:
|
|
272
|
+
* - `wallet_ownership` (a same-origin, Didit-hosted widget): when
|
|
273
|
+
* `autoLaunchAction` is not false, the SDK opens the action URL in the
|
|
274
|
+
* verification modal itself. Once the flow completes or the modal is
|
|
275
|
+
* closed, the transaction is re-fetched with a bounded poll (never a
|
|
276
|
+
* single event) and `onActionCompleted` is invoked with the refreshed
|
|
277
|
+
* result.
|
|
278
|
+
* - `verification_session` (a biometric verification session): never
|
|
279
|
+
* auto-launched, regardless of `autoLaunchAction`. It is only ever
|
|
280
|
+
* returned in `result.actionRequired` for the host application to launch
|
|
281
|
+
* with its own verification integration (e.g. `startVerification`).
|
|
282
|
+
*
|
|
283
|
+
* @param options Submission options: transactionToken, transaction payload,
|
|
284
|
+
* optional baseUrl (defaults to https://verification.didit.me),
|
|
285
|
+
* autoLaunchAction (defaults to true, applies to wallet_ownership actions
|
|
286
|
+
* only) and onActionCompleted callback.
|
|
287
|
+
* @returns The created transaction: transactionId, status, travelRuleStatus
|
|
288
|
+
* and actionRequired when a user action is pending.
|
|
289
|
+
* @throws {DiditTransactionError} Typed as "invalid_token", "expired_token",
|
|
290
|
+
* "validation" (with fieldErrors) or "network".
|
|
291
|
+
*/
|
|
292
|
+
submitTransaction(options: SubmitTransactionOptions): Promise<SubmitTransactionResult>;
|
|
293
|
+
/**
|
|
294
|
+
* Dismisses everything currently on screen in one deterministic call: a
|
|
295
|
+
* pending transaction action modal is treated as an abort (no follow-up
|
|
296
|
+
* poll, no onActionCompleted) and the verification modal is always closed
|
|
297
|
+
* afterwards, regardless of whether an action modal was present.
|
|
298
|
+
*/
|
|
76
299
|
close(): void;
|
|
77
300
|
destroy(): void;
|
|
301
|
+
private runTransactionAction;
|
|
302
|
+
private presentTransactionActionModal;
|
|
78
303
|
private handleModalClose;
|
|
79
304
|
private handleModalCloseConfirmed;
|
|
80
305
|
private handleIframeLoad;
|
|
@@ -89,7 +314,26 @@ declare class DiditSdk {
|
|
|
89
314
|
private buildSessionData;
|
|
90
315
|
}
|
|
91
316
|
|
|
92
|
-
declare const
|
|
317
|
+
declare const DEFAULT_TRANSACTION_BASE_URL = "https://verification.didit.me";
|
|
318
|
+
/**
|
|
319
|
+
* Typed error thrown by DiditSdk.submitTransaction.
|
|
320
|
+
*
|
|
321
|
+
* - "invalid_token": the X-Transaction-Token was rejected (missing, revoked, over max uses)
|
|
322
|
+
* - "expired_token": the transaction token TTL has elapsed
|
|
323
|
+
* - "validation": the payload failed validation; see fieldErrors for per-field details
|
|
324
|
+
* - "network": the request could not complete or the API returned an unexpected error
|
|
325
|
+
*/
|
|
326
|
+
declare class DiditTransactionError extends Error {
|
|
327
|
+
readonly type: TransactionErrorType;
|
|
328
|
+
readonly status?: number;
|
|
329
|
+
readonly fieldErrors?: Record<string, unknown>;
|
|
330
|
+
constructor(type: TransactionErrorType, message?: string, options?: {
|
|
331
|
+
status?: number;
|
|
332
|
+
fieldErrors?: Record<string, unknown>;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
declare const SDK_VERSION = "0.2.1";
|
|
93
337
|
|
|
94
|
-
export { DiditSdk, SDK_VERSION, DiditSdk as default };
|
|
95
|
-
export type { DiditSdkConfiguration, DiditSdkState, EventCallback, SessionData, StartVerificationOptions, StateChangeCallback, VerificationCallback, VerificationError, VerificationErrorType, VerificationEvent, VerificationEventData, VerificationEventType, VerificationResult, VerificationResultType, VerificationStatus };
|
|
338
|
+
export { DEFAULT_TRANSACTION_BASE_URL, DiditSdk, DiditTransactionError, SDK_VERSION, DiditSdk as default };
|
|
339
|
+
export type { DiditSdkConfiguration, DiditSdkState, DiditTransactionDetails, DiditTransactionParticipant, DiditTransactionPayload, DiditTransactionPaymentMethod, DiditTravelRuleDetails, EventCallback, SessionData, StartVerificationOptions, StateChangeCallback, SubmitTransactionOptions, SubmitTransactionResult, TransactionActionCompletedCallback, TransactionActionCompletedError, TransactionActionRequired, TransactionActionType, TransactionErrorType, VerificationCallback, VerificationError, VerificationErrorType, VerificationEvent, VerificationEventData, VerificationEventType, VerificationResult, VerificationResultType, VerificationStatus };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@didit-protocol/sdk-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Didit Identity Verification SDK for Web Applications",
|
|
5
5
|
"main": "dist/didit-sdk.cjs.js",
|
|
6
6
|
"module": "dist/didit-sdk.esm.js",
|
|
@@ -38,9 +38,13 @@
|
|
|
38
38
|
"type": "module",
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/didit-protocol/sdk-web.git"
|
|
41
|
+
"url": "git+https://github.com/didit-protocol/sdk-web.git"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://docs.didit.me",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"registry": "https://registry.npmjs.org/",
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
44
48
|
"devDependencies": {
|
|
45
49
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
46
50
|
"@rollup/plugin-typescript": "^11.1.6",
|