@notabene/javascript-sdk 2.14.1-next.1 → 2.14.1-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/notabene.cjs +23 -1
- package/dist/cjs/notabene.d.ts +6 -2
- package/dist/cjs/package.json +1 -1
- package/dist/esm/notabene.d.ts +6 -2
- package/dist/esm/notabene.js +12099 -467
- package/dist/esm/package.json +1 -1
- package/dist/notabene.d.ts +6 -2
- package/dist/notabene.js +12099 -467
- package/package.json +1 -1
- package/src/responseTransformer/__tests__/transformer.test.ts +41 -0
- package/src/responseTransformer/__tests__/utils.test.ts +35 -0
- package/src/responseTransformer/mappers.ts +19 -11
- package/src/responseTransformer/types.ts +1 -0
- package/src/responseTransformer/utils.ts +24 -1
- package/src/types.ts +5 -2
- package/src/utils/arbitraries.ts +1 -1
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "Notabene <developers@notabene.id>",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"packageManager": "yarn@4.5.1",
|
|
13
|
-
"version": "2.14.1-next.
|
|
13
|
+
"version": "2.14.1-next.3",
|
|
14
14
|
"source": "src/notabene.ts",
|
|
15
15
|
"main": "dist/cjs/notabene.cjs",
|
|
16
16
|
"module": "dist/esm/notabene.js",
|
|
@@ -102,6 +102,7 @@ const depositResponse = {
|
|
|
102
102
|
transactionId: DEPOSIT_TX_ID,
|
|
103
103
|
customer: { type: 'natural', name: 'Jane Doe' },
|
|
104
104
|
agent: walletAgent,
|
|
105
|
+
account: testAccount,
|
|
105
106
|
counterparty: {
|
|
106
107
|
type: 'natural',
|
|
107
108
|
name: 'Jane Doe',
|
|
@@ -339,6 +340,46 @@ describe('componentResponseToTxRequests', () => {
|
|
|
339
340
|
});
|
|
340
341
|
});
|
|
341
342
|
|
|
343
|
+
it('should transform a deposit response with source array and settlementAddress', () => {
|
|
344
|
+
const depositWithSourceArray = {
|
|
345
|
+
...depositResponse,
|
|
346
|
+
value: {
|
|
347
|
+
...depositResponse.value,
|
|
348
|
+
source: [TEST_ADDRESS_DID, 'did:pkh:eip155:1:0xsecondaddress'],
|
|
349
|
+
},
|
|
350
|
+
} as unknown as TransactionResponse<Deposit>;
|
|
351
|
+
|
|
352
|
+
const settlementAddress = '0xsettlementaddress123';
|
|
353
|
+
|
|
354
|
+
const result = componentResponseToTxRequests(
|
|
355
|
+
depositWithSourceArray,
|
|
356
|
+
TEST_DELEGATE_TOKEN,
|
|
357
|
+
{
|
|
358
|
+
originatorId: TEST_ORIGINATOR_ID,
|
|
359
|
+
beneficiaryId: TEST_BENEFICIARY_ID,
|
|
360
|
+
settlementAddress,
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
expect(result.createTx.agents).toEqual([
|
|
365
|
+
{
|
|
366
|
+
'@id': BENEFICIARY_VASP_DID,
|
|
367
|
+
for: TEST_BENEFICIARY_ID,
|
|
368
|
+
role: 'VASP',
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
'@id': TEST_ADDRESS_DID,
|
|
372
|
+
for: TEST_ORIGINATOR_ID,
|
|
373
|
+
role: 'SourceAddress',
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
'@id': `did:pkh:eip155:1:${settlementAddress}`,
|
|
377
|
+
for: BENEFICIARY_VASP_DID,
|
|
378
|
+
role: 'SettlementAddress',
|
|
379
|
+
},
|
|
380
|
+
]);
|
|
381
|
+
});
|
|
382
|
+
|
|
342
383
|
it('should transform a withdrawal response using txCreate', () => {
|
|
343
384
|
const result = componentResponseToTxRequests(
|
|
344
385
|
withdrawalResponse,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getCaip10ChainPrefix } from '../utils';
|
|
3
|
+
|
|
4
|
+
describe('getCaip10ChainPrefix', () => {
|
|
5
|
+
it('should extract chain prefix from EIP155 CAIP-10 address', () => {
|
|
6
|
+
const caip10 = 'eip155:1:0xd7914021b50a5090d3a13bb4ecae2abf014fafbd';
|
|
7
|
+
const result = getCaip10ChainPrefix(caip10);
|
|
8
|
+
expect(result).toBe('eip155:1');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should extract chain prefix from Solana CAIP-10 address', () => {
|
|
12
|
+
const caip10 =
|
|
13
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7kfAoE5opxrCN7rHjBNWvZQ1Fxm7vvhqZz9ZQWF8XGTo';
|
|
14
|
+
const result = getCaip10ChainPrefix(caip10);
|
|
15
|
+
expect(result).toBe('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should extract chain prefix from Polygon CAIP-10 address', () => {
|
|
19
|
+
const caip10 = 'eip155:137:0xd7914021b50a5090d3a13bb4ecae2abf014fafbd';
|
|
20
|
+
const result = getCaip10ChainPrefix(caip10);
|
|
21
|
+
expect(result).toBe('eip155:137');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should throw error for invalid CAIP-10 format', () => {
|
|
25
|
+
expect(() => getCaip10ChainPrefix('invalid')).toThrow(
|
|
26
|
+
'Invalid CAIP-10 format: "invalid". Expected format: {namespace}:{chainId}:{address}',
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should throw error for CAIP-10 with missing address', () => {
|
|
31
|
+
expect(() => getCaip10ChainPrefix('eip155:1')).toThrow(
|
|
32
|
+
'Invalid CAIP-10 format',
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
} from './types';
|
|
23
23
|
import {
|
|
24
24
|
convertPersonToV2,
|
|
25
|
+
getCaip10ChainPrefix,
|
|
25
26
|
getPartyId,
|
|
26
27
|
isDeposit,
|
|
27
28
|
isWithdrawal,
|
|
@@ -274,11 +275,7 @@ export function mapToTransactCreateRequest(
|
|
|
274
275
|
});
|
|
275
276
|
}
|
|
276
277
|
|
|
277
|
-
if (
|
|
278
|
-
isWithdrawal(transaction) &&
|
|
279
|
-
transaction.destination &&
|
|
280
|
-
transaction?.account?.did
|
|
281
|
-
) {
|
|
278
|
+
if (isWithdrawal(transaction) && transaction?.account?.did) {
|
|
282
279
|
agents.push({
|
|
283
280
|
'@id': transaction.account.did,
|
|
284
281
|
for: payload.beneficiaryVASPdid || beneficiaryId,
|
|
@@ -286,12 +283,23 @@ export function mapToTransactCreateRequest(
|
|
|
286
283
|
});
|
|
287
284
|
}
|
|
288
285
|
|
|
289
|
-
if (isDeposit(transaction) && transaction
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
286
|
+
if (isDeposit(transaction) && transaction?.account) {
|
|
287
|
+
if (transaction.account.did) {
|
|
288
|
+
agents.push({
|
|
289
|
+
'@id': transaction.account.did,
|
|
290
|
+
for: payload.originatorVASPdid || originatorId,
|
|
291
|
+
role: 'SourceAddress',
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (config.settlementAddress && transaction.account.caip10) {
|
|
296
|
+
const chainPrefix = getCaip10ChainPrefix(transaction.account.caip10);
|
|
297
|
+
agents.push({
|
|
298
|
+
'@id': `did:pkh:${chainPrefix}:${config.settlementAddress}`,
|
|
299
|
+
for: payload.beneficiaryVASPdid || beneficiaryId,
|
|
300
|
+
role: 'SettlementAddress',
|
|
301
|
+
});
|
|
302
|
+
}
|
|
295
303
|
}
|
|
296
304
|
|
|
297
305
|
return {
|
|
@@ -2,7 +2,7 @@ import type {
|
|
|
2
2
|
NaturalPersonName,
|
|
3
3
|
Person,
|
|
4
4
|
} from '@notabene/javascript-sdk/src/ivms/types';
|
|
5
|
-
import type
|
|
5
|
+
import { CAIP10Schema, type DID } from '@taprsvp/types';
|
|
6
6
|
import type { NaturalPersonNameV2, PersonV2 } from '../ivms';
|
|
7
7
|
import { Deposit, Withdrawal } from '../types';
|
|
8
8
|
|
|
@@ -72,3 +72,26 @@ export function convertPersonToV2(
|
|
|
72
72
|
accountNumber: [accountNumber],
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Extracts the chain prefix ({namespace}:{chainId}) from a CAIP-10 address
|
|
78
|
+
* @param caip10Address - An address in the format {namespace}:{chainId}:{address}
|
|
79
|
+
* @returns The chain prefix (e.g., eip155:1)
|
|
80
|
+
* @throws Error if the address is not in valid CAIP-10 format
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* getCaip10ChainPrefix('eip155:1:0x123...') // returns 'eip155:1'
|
|
84
|
+
* getCaip10ChainPrefix('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7kfAoE5o...') // returns 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
|
|
85
|
+
*/
|
|
86
|
+
export function getCaip10ChainPrefix(caip10Address: string): string {
|
|
87
|
+
const result = CAIP10Schema.safeParse(caip10Address);
|
|
88
|
+
if (!result.success) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Invalid CAIP-10 format: "${caip10Address}". Expected format: {namespace}:{chainId}:{address}`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Extract chain (namespace:chainId) by removing the last segment (address)
|
|
95
|
+
const lastColonIndex = caip10Address.lastIndexOf(':');
|
|
96
|
+
return caip10Address.slice(0, lastColonIndex);
|
|
97
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -237,8 +237,11 @@ export type ISOCurrency = string;
|
|
|
237
237
|
*/
|
|
238
238
|
export type Theme = {
|
|
239
239
|
mode: 'light' | 'dark'; // Defaults to 'light'
|
|
240
|
+
backgroundColor?: string;
|
|
240
241
|
primaryColor?: string;
|
|
242
|
+
primaryForeground?: string;
|
|
241
243
|
secondaryColor?: string;
|
|
244
|
+
secondaryForeground?: string;
|
|
242
245
|
fontFamily?: string;
|
|
243
246
|
logo?: string;
|
|
244
247
|
};
|
|
@@ -491,7 +494,7 @@ export type LegalPersonFields = Partial<{
|
|
|
491
494
|
* @public
|
|
492
495
|
*/
|
|
493
496
|
type OriginatorFields = {
|
|
494
|
-
source
|
|
497
|
+
source: Source | Source[];
|
|
495
498
|
};
|
|
496
499
|
|
|
497
500
|
/**
|
|
@@ -499,7 +502,7 @@ type OriginatorFields = {
|
|
|
499
502
|
* @public
|
|
500
503
|
*/
|
|
501
504
|
type BeneficiaryFields = {
|
|
502
|
-
destination
|
|
505
|
+
destination: Destination;
|
|
503
506
|
};
|
|
504
507
|
|
|
505
508
|
/**
|
package/src/utils/arbitraries.ts
CHANGED
|
@@ -250,5 +250,5 @@ export const arbitraryDeposit = (): fc.Arbitrary<Deposit> =>
|
|
|
250
250
|
asset: arbitraryTransactionAsset(),
|
|
251
251
|
amountDecimal: fc.float({ min: 0, max: 1e6 }),
|
|
252
252
|
origin: fc.oneof(arbitraryBlockchainAddress(), arbitraryCAIP10()),
|
|
253
|
-
|
|
253
|
+
source: fc.oneof(arbitraryBlockchainAddress(), arbitraryCAIP10()),
|
|
254
254
|
});
|