@notabene/javascript-sdk 2.14.0-next.4 → 2.14.1-next.1
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 +73 -51
- package/dist/cjs/package.json +1 -1
- package/dist/esm/notabene.d.ts +73 -51
- package/dist/esm/notabene.js +363 -335
- package/dist/esm/package.json +1 -1
- package/dist/notabene.d.ts +73 -51
- package/dist/notabene.js +363 -335
- package/package.json +1 -1
- package/src/responseTransformer/__tests__/transformer.test.ts +597 -0
- package/src/responseTransformer/mappers.ts +80 -26
- package/src/responseTransformer/transformer.ts +121 -73
- package/src/responseTransformer/types.ts +11 -1
- package/src/responseTransformer/utils.ts +13 -0
- package/src/types.ts +0 -3
|
@@ -7,18 +7,25 @@ import type {
|
|
|
7
7
|
} from '@notabene/javascript-sdk/src/ivms/types';
|
|
8
8
|
import type { Agent } from '@taprsvp/types';
|
|
9
9
|
import {
|
|
10
|
+
Deposit,
|
|
10
11
|
PersonType,
|
|
11
12
|
type IVMS101,
|
|
12
13
|
type V1Transaction,
|
|
13
14
|
type Withdrawal,
|
|
14
15
|
} from '../types';
|
|
15
16
|
import type {
|
|
16
|
-
|
|
17
|
+
ResponseToIVMS101RequestConfig,
|
|
18
|
+
ResponseToTxCreateRequestConfig,
|
|
17
19
|
TransactionCreateRequest,
|
|
18
20
|
TransactionCreateRequestV2,
|
|
19
21
|
TransactionIVMS101Request,
|
|
20
22
|
} from './types';
|
|
21
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
convertPersonToV2,
|
|
25
|
+
getPartyId,
|
|
26
|
+
isDeposit,
|
|
27
|
+
isWithdrawal,
|
|
28
|
+
} from './utils';
|
|
22
29
|
|
|
23
30
|
// Constants
|
|
24
31
|
const DEFAULT_GEOGRAPHIC_ADDRESS = [
|
|
@@ -227,16 +234,28 @@ export function mapToV1CreateRequest(
|
|
|
227
234
|
}
|
|
228
235
|
|
|
229
236
|
export function mapToTransactCreateRequest(
|
|
230
|
-
|
|
237
|
+
transaction: Withdrawal | Deposit,
|
|
231
238
|
payload: V1Transaction,
|
|
232
|
-
config:
|
|
239
|
+
config: ResponseToTxCreateRequestConfig = {},
|
|
233
240
|
): TransactionCreateRequestV2 {
|
|
241
|
+
// For withdrawals: customer sends to counterparty
|
|
242
|
+
// For deposits: counterparty sends to customer
|
|
243
|
+
const isWithdrawalTx = isWithdrawal(transaction);
|
|
244
|
+
const originatorParty = isWithdrawalTx
|
|
245
|
+
? transaction.customer
|
|
246
|
+
: transaction.counterparty;
|
|
247
|
+
const beneficiaryParty = isWithdrawalTx
|
|
248
|
+
? transaction.counterparty
|
|
249
|
+
: transaction.customer;
|
|
250
|
+
|
|
234
251
|
const originatorId =
|
|
235
|
-
config?.originatorId || getPartyId('originator',
|
|
252
|
+
config?.originatorId || getPartyId('originator', originatorParty);
|
|
236
253
|
const beneficiaryId =
|
|
237
|
-
config?.beneficiaryId || getPartyId('beneficiary',
|
|
254
|
+
config?.beneficiaryId || getPartyId('beneficiary', beneficiaryParty);
|
|
238
255
|
const referenceId =
|
|
239
|
-
config?.referenceId ||
|
|
256
|
+
config?.referenceId ||
|
|
257
|
+
payload.transactionId ||
|
|
258
|
+
Math.random().toString(36).substring(2, 15);
|
|
240
259
|
const agents: Agent[] = [];
|
|
241
260
|
|
|
242
261
|
if (payload.originatorVASPdid) {
|
|
@@ -255,47 +274,82 @@ export function mapToTransactCreateRequest(
|
|
|
255
274
|
});
|
|
256
275
|
}
|
|
257
276
|
|
|
258
|
-
if (
|
|
277
|
+
if (
|
|
278
|
+
isWithdrawal(transaction) &&
|
|
279
|
+
transaction.destination &&
|
|
280
|
+
transaction?.account?.did
|
|
281
|
+
) {
|
|
259
282
|
agents.push({
|
|
260
|
-
'@id':
|
|
283
|
+
'@id': transaction.account.did,
|
|
261
284
|
for: payload.beneficiaryVASPdid || beneficiaryId,
|
|
262
285
|
role: 'SettlementAddress',
|
|
263
286
|
});
|
|
264
287
|
}
|
|
265
288
|
|
|
289
|
+
if (isDeposit(transaction) && transaction.source && transaction.agent?.did) {
|
|
290
|
+
agents.push({
|
|
291
|
+
'@id': transaction.agent.did,
|
|
292
|
+
for: payload.originatorVASPdid || originatorId,
|
|
293
|
+
role: 'SourceAddress',
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
266
297
|
return {
|
|
267
298
|
originator: { '@id': originatorId },
|
|
268
299
|
beneficiary: { '@id': beneficiaryId },
|
|
269
|
-
asset:
|
|
270
|
-
amount:
|
|
300
|
+
asset: transaction.asset,
|
|
301
|
+
amount: transaction.amountDecimal?.toString() || payload.transactionAmount,
|
|
271
302
|
agents,
|
|
272
303
|
ref: referenceId,
|
|
273
304
|
};
|
|
274
305
|
}
|
|
275
306
|
|
|
276
307
|
export function mapToAppendPiiRequest(
|
|
277
|
-
|
|
308
|
+
transaction: Withdrawal | Deposit,
|
|
278
309
|
ivms101: IVMS101,
|
|
279
|
-
config:
|
|
310
|
+
config: ResponseToIVMS101RequestConfig = {},
|
|
280
311
|
): TransactionIVMS101Request {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
312
|
+
if (isWithdrawal(transaction)) {
|
|
313
|
+
const beneficiaryId =
|
|
314
|
+
config.beneficiaryId ||
|
|
315
|
+
getPartyId('beneficiary', transaction.counterparty);
|
|
316
|
+
|
|
317
|
+
const beneficiaryPersons =
|
|
318
|
+
// If counterparty type is SELF, reuse originator data for beneficiary
|
|
319
|
+
transaction.counterparty?.type === PersonType.SELF && config.originator
|
|
320
|
+
? config.originator.originatorPerson
|
|
321
|
+
: // Convert all beneficiary persons from V1 to V2 format
|
|
322
|
+
ivms101.beneficiary?.beneficiaryPersons?.map((person) =>
|
|
323
|
+
convertPersonToV2(person, beneficiaryId),
|
|
324
|
+
) || [];
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
ivms101: {
|
|
328
|
+
originator: config.originator,
|
|
329
|
+
beneficiary: {
|
|
330
|
+
beneficiaryPerson: beneficiaryPersons,
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const originatorId =
|
|
337
|
+
config.originatorId || getPartyId('originator', transaction.counterparty);
|
|
338
|
+
|
|
339
|
+
const originatorPersons =
|
|
340
|
+
transaction.counterparty?.type === PersonType.SELF && config.beneficiary
|
|
341
|
+
? config.beneficiary.beneficiaryPerson
|
|
342
|
+
: // Convert all originator persons from V1 to V2 format
|
|
343
|
+
ivms101.originator?.originatorPersons?.map((person) =>
|
|
344
|
+
convertPersonToV2(person, originatorId),
|
|
291
345
|
) || [];
|
|
292
346
|
|
|
293
347
|
return {
|
|
294
348
|
ivms101: {
|
|
295
|
-
originator:
|
|
296
|
-
|
|
297
|
-
beneficiaryPerson: beneficiaryPersons,
|
|
349
|
+
originator: {
|
|
350
|
+
originatorPerson: originatorPersons,
|
|
298
351
|
},
|
|
352
|
+
beneficiary: config.beneficiary,
|
|
299
353
|
},
|
|
300
354
|
};
|
|
301
355
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { decodeJwt } from 'jose';
|
|
2
2
|
import {
|
|
3
|
+
Deposit,
|
|
4
|
+
DID,
|
|
3
5
|
PersonType,
|
|
4
6
|
type OwnershipProof,
|
|
5
7
|
type TransactionResponse,
|
|
@@ -12,42 +14,65 @@ import {
|
|
|
12
14
|
} from './mappers';
|
|
13
15
|
import type {
|
|
14
16
|
DelegateToken,
|
|
17
|
+
ResponseToIVMS101RequestConfig,
|
|
18
|
+
ResponseToTxCreateRequestConfig,
|
|
15
19
|
ResponseToTxRequestConfig,
|
|
16
20
|
TransactionCreateRequest,
|
|
17
21
|
TransactionCreateRequestV2,
|
|
18
22
|
TransactionIVMS101Request,
|
|
19
23
|
} from './types';
|
|
24
|
+
import { isDeposit, isWithdrawal } from './utils';
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
|
-
* Fills in missing config values by extracting them from the delegate token and
|
|
27
|
+
* Fills in missing config values by extracting them from the delegate token and transaction data
|
|
23
28
|
* @internal
|
|
24
29
|
*/
|
|
25
|
-
function enrichConfig(
|
|
30
|
+
export function enrichConfig(
|
|
26
31
|
config: ResponseToTxRequestConfig,
|
|
27
32
|
delegateToken: string,
|
|
28
|
-
|
|
33
|
+
transaction: Withdrawal | Deposit,
|
|
29
34
|
): ResponseToTxRequestConfig {
|
|
30
35
|
const enrichedConfig = { ...config };
|
|
31
36
|
|
|
32
|
-
// Extract
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
// Extract customer ID from delegate token
|
|
38
|
+
// For withdrawals: customer is originator, for deposits: customer is beneficiary
|
|
39
|
+
let customerIdFromToken: DID | undefined;
|
|
40
|
+
try {
|
|
41
|
+
const tokenPayload = decodeJwt<DelegateToken>(delegateToken);
|
|
42
|
+
customerIdFromToken = tokenPayload?.sub;
|
|
43
|
+
} catch {
|
|
44
|
+
// If decoding fails, customerIdFromToken remains undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isWithdrawal(transaction)) {
|
|
48
|
+
// Withdrawal: customer sends to counterparty
|
|
49
|
+
if (!enrichedConfig.originatorId && customerIdFromToken) {
|
|
50
|
+
enrichedConfig.originatorId = customerIdFromToken;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!enrichedConfig.beneficiaryId) {
|
|
54
|
+
if (transaction.counterparty?.type === PersonType.SELF) {
|
|
55
|
+
enrichedConfig.beneficiaryId = enrichedConfig.originatorId;
|
|
56
|
+
} else if (transaction.destination) {
|
|
57
|
+
// Generate beneficiaryId from destination if not provided.
|
|
58
|
+
// TODO: Replace with proper DID key identifier creation
|
|
59
|
+
enrichedConfig.beneficiaryId = `did:key:${transaction.destination}`;
|
|
38
60
|
}
|
|
39
|
-
} catch {
|
|
40
|
-
// If decoding fails, originatorId remains undefined
|
|
41
61
|
}
|
|
42
|
-
}
|
|
62
|
+
} else if (isDeposit(transaction)) {
|
|
63
|
+
// Deposit: counterparty sends to customer
|
|
64
|
+
if (!enrichedConfig.beneficiaryId && customerIdFromToken) {
|
|
65
|
+
enrichedConfig.beneficiaryId = customerIdFromToken;
|
|
66
|
+
}
|
|
43
67
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
if (!enrichedConfig.originatorId) {
|
|
69
|
+
if (transaction.counterparty?.type === PersonType.SELF) {
|
|
70
|
+
enrichedConfig.originatorId = enrichedConfig.beneficiaryId;
|
|
71
|
+
} else if (transaction.source) {
|
|
72
|
+
// Generate originatorId from source if not provided.
|
|
73
|
+
// TODO: Replace with proper DID key identifier creation
|
|
74
|
+
enrichedConfig.originatorId = `did:key:${transaction.source}`;
|
|
75
|
+
}
|
|
51
76
|
}
|
|
52
77
|
}
|
|
53
78
|
|
|
@@ -115,51 +140,51 @@ export function componentResponseToV1TxCreateRequest(
|
|
|
115
140
|
* which is useful for V2 workflows where you need to create a transaction first,
|
|
116
141
|
* then append IVMS101 data to it, and finally confirm the relationship.
|
|
117
142
|
*
|
|
143
|
+
* ## IVMS101 Config by Transaction Type
|
|
144
|
+
*
|
|
145
|
+
* The `originator` and `beneficiary` config options provide the customer's PII data.
|
|
146
|
+
* Which one to use depends on the transaction type:
|
|
147
|
+
*
|
|
148
|
+
* - **Withdrawals**: Pass `originator` - the customer is sending funds (customer = originator)
|
|
149
|
+
* - **Deposits**: Pass `beneficiary` - the customer is receiving funds (customer = beneficiary)
|
|
150
|
+
*
|
|
151
|
+
* For self-transfers, the provided data is automatically reused for both parties.
|
|
152
|
+
*
|
|
118
153
|
* @param response - The response from the Notabene Embedded Component
|
|
119
|
-
* @param delegateToken - The JWT delegate token for extracting the
|
|
154
|
+
* @param delegateToken - The JWT delegate token for extracting the customer ID
|
|
120
155
|
* @param config - Optional configuration for IDs and reference
|
|
121
|
-
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken
|
|
122
|
-
* @param config.beneficiaryId - Optional beneficiary ID (auto-
|
|
156
|
+
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken for withdrawals)
|
|
157
|
+
* @param config.beneficiaryId - Optional beneficiary ID (auto-extracted from delegateToken for deposits)
|
|
123
158
|
* @param config.referenceId - Optional reference ID (auto-generated if not provided)
|
|
124
|
-
* @param config.originator -
|
|
159
|
+
* @param config.originator - Customer's IVMS101 data for withdrawals (customer is the sender)
|
|
160
|
+
* @param config.beneficiary - Customer's IVMS101 data for deposits (customer is the receiver)
|
|
125
161
|
* @returns Object with `createTx`, `ivms101`, and optional `confirmRelationship` properties containing the respective request bodies
|
|
126
162
|
*
|
|
127
163
|
* @example
|
|
128
164
|
* ```typescript
|
|
129
165
|
* import { componentResponseToTxRequests } from '$lib/notabene-tx-transformer';
|
|
130
166
|
*
|
|
167
|
+
* // For withdrawals: pass originator (customer is sending)
|
|
131
168
|
* withdrawal.on('complete', async (result) => {
|
|
132
|
-
* const { createTx, ivms101
|
|
169
|
+
* const { createTx, ivms101 } = componentResponseToTxRequests(
|
|
133
170
|
* result.response,
|
|
134
|
-
*
|
|
135
|
-
* { originator:
|
|
171
|
+
* delegateToken,
|
|
172
|
+
* { originator: customerIvmsData }
|
|
136
173
|
* );
|
|
174
|
+
* });
|
|
137
175
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* const txId = txResponse.transfer['@id'];
|
|
146
|
-
* await fetch(`/entity/${vaspDid}/tx/${txId}/append`, {
|
|
147
|
-
* method: 'POST',
|
|
148
|
-
* body: JSON.stringify(ivms101)
|
|
149
|
-
* });
|
|
150
|
-
*
|
|
151
|
-
* // Finally, confirm relationship
|
|
152
|
-
* if (confirmRelationship) {
|
|
153
|
-
* await fetch(`/entity/${vaspDid}/relationship?to=${to}&from=${from}`, {
|
|
154
|
-
* method: 'PATCH',
|
|
155
|
-
* body: JSON.stringify({ proof: confirmRelationship.proof })
|
|
156
|
-
* });
|
|
157
|
-
* }
|
|
176
|
+
* // For deposits: pass beneficiary (customer is receiving)
|
|
177
|
+
* deposit.on('complete', async (result) => {
|
|
178
|
+
* const { createTx, ivms101 } = componentResponseToTxRequests(
|
|
179
|
+
* result.response,
|
|
180
|
+
* delegateToken,
|
|
181
|
+
* { beneficiary: customerIvmsData }
|
|
182
|
+
* );
|
|
158
183
|
* });
|
|
159
184
|
* ```
|
|
160
185
|
*/
|
|
161
186
|
export function componentResponseToTxRequests(
|
|
162
|
-
response: TransactionResponse<Withdrawal>,
|
|
187
|
+
response: TransactionResponse<Withdrawal | Deposit>,
|
|
163
188
|
delegateToken: string,
|
|
164
189
|
config: ResponseToTxRequestConfig = {},
|
|
165
190
|
): {
|
|
@@ -169,17 +194,21 @@ export function componentResponseToTxRequests(
|
|
|
169
194
|
proof: OwnershipProof;
|
|
170
195
|
};
|
|
171
196
|
} {
|
|
172
|
-
|
|
197
|
+
const { value, txCreate, txUpdate, ivms101, proof } = response;
|
|
198
|
+
|
|
199
|
+
// For withdrawals: use txCreate, for deposits: use txUpdate
|
|
200
|
+
const txPayload = isWithdrawal(value) ? txCreate : txUpdate;
|
|
201
|
+
|
|
202
|
+
if (!txPayload || !ivms101) {
|
|
173
203
|
throw new Error(
|
|
174
|
-
'Invalid response: missing required txCreate or ivms101 data',
|
|
204
|
+
'Invalid response: missing required txCreate/txUpdate or ivms101 data',
|
|
175
205
|
);
|
|
176
206
|
}
|
|
177
207
|
|
|
178
|
-
const { value, txCreate, ivms101, proof } = response;
|
|
179
208
|
const enrichedConfig = enrichConfig(config, delegateToken, value);
|
|
180
209
|
|
|
181
210
|
return {
|
|
182
|
-
createTx: mapToTransactCreateRequest(value,
|
|
211
|
+
createTx: mapToTransactCreateRequest(value, txPayload, enrichedConfig),
|
|
183
212
|
ivms101: mapToAppendPiiRequest(value, ivms101, enrichedConfig),
|
|
184
213
|
...(proof && { confirmRelationship: { proof } }),
|
|
185
214
|
};
|
|
@@ -200,9 +229,11 @@ export function componentResponseToTxRequests(
|
|
|
200
229
|
* ```typescript
|
|
201
230
|
* import { componentResponseToTxCreateRequest } from '$lib/notabene-tx-transformer';
|
|
202
231
|
*
|
|
203
|
-
* withdrawal
|
|
232
|
+
* // Works with both withdrawal and deposit responses
|
|
233
|
+
* transaction.on('complete', async (result) => {
|
|
204
234
|
* const requestBody = componentResponseToTxCreateRequest(
|
|
205
235
|
* result.response,
|
|
236
|
+
* delegateToken,
|
|
206
237
|
* {
|
|
207
238
|
* originatorId: 'mailto:user@example.com',
|
|
208
239
|
* beneficiaryId: 'urn:beneficiary:recipient',
|
|
@@ -218,54 +249,71 @@ export function componentResponseToTxRequests(
|
|
|
218
249
|
* ```
|
|
219
250
|
*/
|
|
220
251
|
export function componentResponseToTxCreateRequest(
|
|
221
|
-
response: TransactionResponse<Withdrawal>,
|
|
252
|
+
response: TransactionResponse<Withdrawal | Deposit>,
|
|
222
253
|
delegateToken: string,
|
|
223
|
-
config:
|
|
254
|
+
config: ResponseToTxCreateRequestConfig = {},
|
|
224
255
|
) {
|
|
225
|
-
|
|
256
|
+
const { value, txCreate, txUpdate } = response;
|
|
257
|
+
|
|
258
|
+
// For withdrawals: use txCreate, for deposits: use txUpdate
|
|
259
|
+
const txPayload = isWithdrawal(value) ? txCreate : txUpdate;
|
|
260
|
+
|
|
261
|
+
if (!txPayload || !response.ivms101) {
|
|
226
262
|
throw new Error(
|
|
227
|
-
'Invalid response: missing required txCreate or ivms101 data',
|
|
263
|
+
'Invalid response: missing required txCreate/txUpdate or ivms101 data',
|
|
228
264
|
);
|
|
229
265
|
}
|
|
230
266
|
|
|
231
|
-
const { value, txCreate } = response;
|
|
232
267
|
const enrichedConfig = enrichConfig(config, delegateToken, value);
|
|
233
268
|
|
|
234
|
-
return mapToTransactCreateRequest(value,
|
|
269
|
+
return mapToTransactCreateRequest(value, txPayload, enrichedConfig);
|
|
235
270
|
}
|
|
236
271
|
|
|
237
272
|
/**
|
|
238
273
|
* Transforms a Notabene component response to IVMS101 format
|
|
239
274
|
*
|
|
275
|
+
* ## IVMS101 Config by Transaction Type
|
|
276
|
+
*
|
|
277
|
+
* The `originator` and `beneficiary` config options provide the customer's PII data.
|
|
278
|
+
* Which one to use depends on the transaction type:
|
|
279
|
+
*
|
|
280
|
+
* - **Withdrawals**: Pass `originator` - the customer is sending funds (customer = originator)
|
|
281
|
+
* - **Deposits**: Pass `beneficiary` - the customer is receiving funds (customer = beneficiary)
|
|
282
|
+
*
|
|
283
|
+
* For self-transfers, the provided data is automatically reused for both parties.
|
|
284
|
+
*
|
|
240
285
|
* @param response - The response from the Notabene Embedded Component
|
|
241
|
-
* @param delegateToken - The JWT delegate token for extracting the
|
|
286
|
+
* @param delegateToken - The JWT delegate token for extracting the customer ID
|
|
242
287
|
* @param config - Configuration object with optional IDs
|
|
243
|
-
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken
|
|
244
|
-
* @param config.beneficiaryId - Optional beneficiary ID (auto-
|
|
245
|
-
* @param config.
|
|
246
|
-
* @param config.
|
|
288
|
+
* @param config.originatorId - Optional originator ID (auto-extracted from delegateToken for withdrawals)
|
|
289
|
+
* @param config.beneficiaryId - Optional beneficiary ID (auto-extracted from delegateToken for deposits)
|
|
290
|
+
* @param config.originator - Customer's IVMS101 data for withdrawals (customer is the sender)
|
|
291
|
+
* @param config.beneficiary - Customer's IVMS101 data for deposits (customer is the receiver)
|
|
247
292
|
* @returns The transformed request body in IVMS101 format
|
|
248
293
|
*
|
|
249
294
|
* @example
|
|
250
295
|
* ```typescript
|
|
251
296
|
* import { componentResponseToIVMS101 } from '$lib/notabene-tx-transformer';
|
|
252
297
|
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
298
|
+
* // For withdrawals: pass originator (customer is sending)
|
|
299
|
+
* const withdrawalIvms = componentResponseToIVMS101(
|
|
300
|
+
* withdrawalResponse,
|
|
301
|
+
* delegateToken,
|
|
302
|
+
* { originator: customerIvmsData }
|
|
257
303
|
* );
|
|
258
304
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
305
|
+
* // For deposits: pass beneficiary (customer is receiving)
|
|
306
|
+
* const depositIvms = componentResponseToIVMS101(
|
|
307
|
+
* depositResponse,
|
|
308
|
+
* delegateToken,
|
|
309
|
+
* { beneficiary: customerIvmsData }
|
|
310
|
+
* );
|
|
263
311
|
* ```
|
|
264
312
|
*/
|
|
265
313
|
export function componentResponseToIVMS101(
|
|
266
|
-
response: TransactionResponse<Withdrawal>,
|
|
314
|
+
response: TransactionResponse<Withdrawal | Deposit>,
|
|
267
315
|
delegateToken: string,
|
|
268
|
-
config:
|
|
316
|
+
config: ResponseToIVMS101RequestConfig = {},
|
|
269
317
|
) {
|
|
270
318
|
if (!response.ivms101) {
|
|
271
319
|
throw new Error('Invalid response: missing required ivms101 data');
|
|
@@ -14,13 +14,23 @@ export interface DelegateToken {
|
|
|
14
14
|
iat?: number;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
interface BaseRequestConfig {
|
|
18
18
|
originatorId?: DID;
|
|
19
19
|
beneficiaryId?: DID;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ResponseToTxCreateRequestConfig extends BaseRequestConfig {
|
|
20
23
|
referenceId?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ResponseToIVMS101RequestConfig extends BaseRequestConfig {
|
|
21
27
|
originator?: OriginatorV2;
|
|
28
|
+
beneficiary?: BeneficiaryV2;
|
|
22
29
|
}
|
|
23
30
|
|
|
31
|
+
export type ResponseToTxRequestConfig = ResponseToTxCreateRequestConfig &
|
|
32
|
+
ResponseToIVMS101RequestConfig;
|
|
33
|
+
|
|
24
34
|
export interface TransactionCreateRequest {
|
|
25
35
|
transactionAsset: any;
|
|
26
36
|
transactionAmount: string;
|
|
@@ -4,6 +4,19 @@ import type {
|
|
|
4
4
|
} from '@notabene/javascript-sdk/src/ivms/types';
|
|
5
5
|
import type { DID } from '@taprsvp/types';
|
|
6
6
|
import type { NaturalPersonNameV2, PersonV2 } from '../ivms';
|
|
7
|
+
import { Deposit, Withdrawal } from '../types';
|
|
8
|
+
|
|
9
|
+
export function isDeposit(
|
|
10
|
+
transaction: Withdrawal | Deposit,
|
|
11
|
+
): transaction is Deposit {
|
|
12
|
+
return 'source' in transaction && transaction.source !== undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isWithdrawal(
|
|
16
|
+
transaction: Withdrawal | Deposit,
|
|
17
|
+
): transaction is Withdrawal {
|
|
18
|
+
return !isDeposit(transaction);
|
|
19
|
+
}
|
|
7
20
|
|
|
8
21
|
/**
|
|
9
22
|
* Generates a backup DID identifier for a party
|
package/src/types.ts
CHANGED
|
@@ -1164,7 +1164,6 @@ export enum ProofStatus {
|
|
|
1164
1164
|
* - ED25519: Ed25519 signature (used in Solana)
|
|
1165
1165
|
* - XRP_ED25519: Ed25519 signature (used in XRP)
|
|
1166
1166
|
* - XLM_ED25519: Ed25519 signature (used in Stellar)
|
|
1167
|
-
* - XPUB: Extended public key signature for HD wallets
|
|
1168
1167
|
* - MicroTransfer: Proof via small blockchain transaction
|
|
1169
1168
|
* - Screenshot: Image proof of ownership/access
|
|
1170
1169
|
* - CIP8: Cardano message signing standard (CIP-8)
|
|
@@ -1185,7 +1184,6 @@ export enum ProofTypes {
|
|
|
1185
1184
|
EIP1271 = 'eip-1271',
|
|
1186
1185
|
BIP137 = 'bip-137',
|
|
1187
1186
|
BIP322 = 'bip-322',
|
|
1188
|
-
BIP137_XPUB = 'xpub',
|
|
1189
1187
|
TIP191 = 'tip-191',
|
|
1190
1188
|
ED25519 = 'ed25519',
|
|
1191
1189
|
XRP_ED25519 = 'xrp-ed25519',
|
|
@@ -1316,7 +1314,6 @@ export interface SignatureProof extends OwnershipProof {
|
|
|
1316
1314
|
| ProofTypes.EIP1271
|
|
1317
1315
|
| ProofTypes.BIP137
|
|
1318
1316
|
| ProofTypes.BIP322
|
|
1319
|
-
| ProofTypes.BIP137_XPUB
|
|
1320
1317
|
| ProofTypes.ED25519
|
|
1321
1318
|
| ProofTypes.TIP191
|
|
1322
1319
|
| ProofTypes.SIWX
|