@kasufinance/kasu-sdk 2.5.0 → 2.6.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.
Files changed (72) hide show
  1. package/README.md +17 -5
  2. package/dist/bundle.cjs.js +797 -16
  3. package/dist/bundle.esm.js +771 -17
  4. package/dist/domain/au-minimum.d.ts +135 -0
  5. package/dist/domain/au-minimum.js +154 -0
  6. package/dist/domain/au-minimum.js.map +1 -0
  7. package/dist/domain/au-minimum.test.d.ts +1 -0
  8. package/dist/domain/au-minimum.test.js +202 -0
  9. package/dist/domain/au-minimum.test.js.map +1 -0
  10. package/dist/domain/index.d.ts +17 -3
  11. package/dist/domain/index.js +13 -3
  12. package/dist/domain/index.js.map +1 -1
  13. package/dist/domain/loan-contract.d.ts +174 -0
  14. package/dist/domain/loan-contract.js +160 -0
  15. package/dist/domain/loan-contract.js.map +1 -0
  16. package/dist/domain/loan-contract.test.d.ts +1 -0
  17. package/dist/domain/loan-contract.test.js +255 -0
  18. package/dist/domain/loan-contract.test.js.map +1 -0
  19. package/dist/domain/requests.d.ts +181 -0
  20. package/dist/domain/requests.js +202 -0
  21. package/dist/domain/requests.js.map +1 -0
  22. package/dist/domain/requests.test.d.ts +1 -0
  23. package/dist/domain/requests.test.js +470 -0
  24. package/dist/domain/requests.test.js.map +1 -0
  25. package/dist/domain/settlement.d.ts +97 -0
  26. package/dist/domain/settlement.js +117 -0
  27. package/dist/domain/settlement.js.map +1 -0
  28. package/dist/domain/settlement.test.d.ts +1 -0
  29. package/dist/domain/settlement.test.js +152 -0
  30. package/dist/domain/settlement.test.js.map +1 -0
  31. package/dist/domain/wallet-errors.d.ts +37 -0
  32. package/dist/domain/wallet-errors.js +56 -0
  33. package/dist/domain/wallet-errors.js.map +1 -0
  34. package/dist/domain/wallet-errors.test.d.ts +1 -0
  35. package/dist/domain/wallet-errors.test.js +71 -0
  36. package/dist/domain/wallet-errors.test.js.map +1 -0
  37. package/dist/facade/chain-configs.js +7 -1
  38. package/dist/facade/chain-configs.js.map +1 -1
  39. package/dist/facade/facade.test.js +82 -5
  40. package/dist/facade/facade.test.js.map +1 -1
  41. package/dist/facade/user-portfolio.d.ts +18 -0
  42. package/dist/facade/user-portfolio.js +23 -0
  43. package/dist/facade/user-portfolio.js.map +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/index.js.map +1 -1
  47. package/dist/services/DataService/data-service.js +3 -10
  48. package/dist/services/DataService/data-service.js.map +1 -1
  49. package/dist/services/DataService/directus-client.d.ts +26 -0
  50. package/dist/services/DataService/directus-client.js +38 -0
  51. package/dist/services/DataService/directus-client.js.map +1 -0
  52. package/dist/services/UserLending/user-lending.js +11 -7
  53. package/dist/services/UserLending/user-lending.js.map +1 -1
  54. package/package.json +1 -1
  55. package/src/domain/au-minimum.test.ts +371 -0
  56. package/src/domain/au-minimum.ts +192 -0
  57. package/src/domain/index.ts +67 -3
  58. package/src/domain/loan-contract.test.ts +343 -0
  59. package/src/domain/loan-contract.ts +275 -0
  60. package/src/domain/requests.test.ts +653 -0
  61. package/src/domain/requests.ts +414 -0
  62. package/src/domain/settlement.test.ts +198 -0
  63. package/src/domain/settlement.ts +161 -0
  64. package/src/domain/wallet-errors.test.ts +100 -0
  65. package/src/domain/wallet-errors.ts +56 -0
  66. package/src/facade/chain-configs.ts +7 -1
  67. package/src/facade/facade.test.ts +124 -0
  68. package/src/facade/user-portfolio.ts +24 -0
  69. package/src/index.ts +2 -0
  70. package/src/services/DataService/data-service.ts +7 -24
  71. package/src/services/DataService/directus-client.ts +54 -0
  72. package/src/services/UserLending/user-lending.ts +17 -21
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Loan-contract protocol: the strings and the bytes kasu-backend verifies.
3
+ *
4
+ * ⚠️ THE ONE EXCEPTION TO "NUMBERS AND CODES ONLY". Everything this module
5
+ * returns as a string is a PROTOCOL string, not copy. The backend reconstructs
6
+ * each of these messages byte-for-byte and verifies the lender's signature
7
+ * against it; a changed word, separator, line break or date format does not
8
+ * read differently — it stops every signature verifying. They are here, in the
9
+ * shared layer, for exactly the reason `getTrancheDisplayName` is: so the
10
+ * applications cannot drift apart on them.
11
+ *
12
+ * Any change to a builder below is a coordinated multi-repo change that has to
13
+ * land in kasu-backend at the same moment. Do not "tidy" this file.
14
+ *
15
+ * Lifted from kasu-ui's `features/lending/lib/{contract-types, sign-message}.ts`
16
+ * and `encode-deposit-data.ts` — the last rewritten from viem to ethers v5
17
+ * (kasu-mobile already runs that port; the tests pin the two byte-identical).
18
+ */
19
+ /** Recursive list nesting: `list-N-list`, etc. — indexed by string keys. */
20
+ export type ContractListItem = {
21
+ label?: string;
22
+ description?: string;
23
+ } & Record<string, unknown>;
24
+ export type ContractSection = {
25
+ title?: string;
26
+ description?: string;
27
+ } & Record<`list-${number}`, ContractListItem | undefined> & Record<string, unknown>;
28
+ export type RetailLoanContract = {
29
+ important?: {
30
+ title?: string;
31
+ description?: string;
32
+ };
33
+ intro?: string;
34
+ between?: string;
35
+ parties?: ContractSection;
36
+ background?: ContractSection;
37
+ witnesses?: ContractSection;
38
+ } & Record<`subheader-${number}`, ContractSection | undefined> & Record<string, unknown>;
39
+ /**
40
+ * The exempt (wholesale) contract renders from the same tree as the retail
41
+ * one; the templates differ, the SHAPE does not. Kept as its own name because
42
+ * `contractType` distinguishes them everywhere else.
43
+ */
44
+ export type ExemptLoanContract = RetailLoanContract;
45
+ /** Either contract, parsed. Both are the same tree. */
46
+ export type LoanContractFormatted = RetailLoanContract;
47
+ /**
48
+ * `contractType` arrives over the wire as a free string; these are the two the
49
+ * version byte encodes.
50
+ */
51
+ export type ContractType = 'retail' | 'exempt';
52
+ export interface GenerateContractResponse {
53
+ fullName: string;
54
+ /** The plaintext the lender signs (EIP-191). */
55
+ contractMessage: string;
56
+ /** Returned as a JSON-encoded string; parse before rendering. */
57
+ formattedMessage: string;
58
+ contractType: ContractType;
59
+ /** Template version (>= 1). */
60
+ contractVersion: number;
61
+ /** ms-epoch; feeds the on-chain `depositData` and the TTL guard. */
62
+ timestamp: number;
63
+ }
64
+ export type ResolvedContractResponse = GenerateContractResponse & {
65
+ isValid: boolean;
66
+ };
67
+ /** Narrow the backend's loose `contractType` string to the encoded union. */
68
+ export declare function asContractType(raw: string): ContractType;
69
+ /**
70
+ * Parse the server's JSON-string `formattedMessage` into a tree. Returns
71
+ * `null` on parse failure so a renderer can fall back to the plaintext.
72
+ */
73
+ export declare function parseFormattedMessage(raw: string): LoanContractFormatted | null;
74
+ /**
75
+ * Pack the contract version and type into the `versionType` word.
76
+ *
77
+ * ```
78
+ * high byte = contract version (>= 1)
79
+ * low byte = 0 for retail, 1 for exempt
80
+ * ```
81
+ */
82
+ export declare function buildContractVersionType(contractVersion: number, contractType: ContractType): number;
83
+ /**
84
+ * Build the on-chain `depositData` blob that `requestDepositWithKyc` expects.
85
+ *
86
+ * The KasuController decodes the bytes as
87
+ * `(bytes signature, uint256 timestamp, uint256 versionType)` and uses the
88
+ * embedded acceptance signature to verify — retrospectively, via the
89
+ * agreements service `/contract/resolve` — that the lender signed the
90
+ * loan-contract text. The ABI tuple and the packing are consensus-critical:
91
+ * these bytes go on chain.
92
+ *
93
+ * kasu-ui encodes this with viem, kasu-mobile with ethers v5 (viem is not
94
+ * available on Expo). This is the ethers v5 implementation, and
95
+ * `loan-contract.test.ts` pins its output byte-for-byte against fixtures
96
+ * produced by the viem version, so the two apps can never diverge here.
97
+ *
98
+ * @param args.signature EIP-191 signature from the lender accepting
99
+ * `contractMessage`, as a 0x-prefixed hex string.
100
+ * @param args.timestamp ms-epoch from the contract response.
101
+ */
102
+ export declare function encodeDepositData(args: {
103
+ signature: string;
104
+ timestamp: number;
105
+ contractVersion: number;
106
+ contractType: ContractType;
107
+ }): string;
108
+ /**
109
+ * Format a unix timestamp as `{day} {MonthName} {yyyy}, {HH}:{mm}` in UTC.
110
+ * Day is non-padded; hour and minute are zero-padded to two digits (24h). A
111
+ * timestamp with >= 13 digits is treated as milliseconds, otherwise as seconds
112
+ * — the same auto-detection kasu-backend applies.
113
+ *
114
+ * Deliberately a manual formatter with English month names: no locale, no
115
+ * `Intl`, so the output is byte-identical across runtimes and time zones. This
116
+ * is not a display date. It goes inside a signed message.
117
+ *
118
+ * e.g. 1785313320000 → `"29 July 2026, 08:22"`
119
+ */
120
+ export declare function formatSignTimestampUtc(timestamp: number): string;
121
+ /**
122
+ * The 4-line human-readable message a lender signs to generate their loan
123
+ * agreement for review — `POST /contract/generate`.
124
+ *
125
+ * ⚠️ BYTE-EXACT PROTOCOL STRING. kasu-backend rebuilds this string from the
126
+ * request body and verifies the signature against it, so the wording,
127
+ * ordering, separators, line breaks and date format are all part of the wire
128
+ * contract. The separator between the line-2 fields is a MIDDLE DOT U+00B7
129
+ * (·) with a single space on each side; the four lines are joined with `\n`.
130
+ *
131
+ * The backend takes this format only when all four display fields are present
132
+ * and non-empty, and it cross-checks `amountLabel`'s leading number against
133
+ * the `depositAmount` it was sent (thousands separators stripped) — a message
134
+ * that states an amount other than the one being executed is refused.
135
+ */
136
+ export declare function buildLoanAgreementSignMessage(p: {
137
+ strategyName: string;
138
+ region: string;
139
+ optionName: string;
140
+ amountLabel: string;
141
+ timestamp: number;
142
+ }): string;
143
+ /**
144
+ * The legacy `/contract/generate` and `/contract/resolve` message.
145
+ *
146
+ * ⚠️ BYTE-EXACT PROTOCOL STRING. kasu-backend rebuilds it as
147
+ * `` `I request contract content for ${address} at ${timestamp}.` `` from the
148
+ * `address` and `timestamp` fields of the request body — so the string signed
149
+ * and the body sent must agree exactly, INCLUDING the address casing. This
150
+ * builder lowercases, and the request body must carry the same lowercased
151
+ * address; that is what both apps signing this format do today.
152
+ *
153
+ * The backend takes this path whenever the four human-readable display fields
154
+ * are absent, and documents it as permanent until the legacy app is
155
+ * decommissioned. `/contract/resolve` has no other format — every consumer
156
+ * signs this one to retrieve an existing agreement.
157
+ *
158
+ * @param timestampMs ms-epoch, and the same value sent as the body's
159
+ * `timestamp`.
160
+ */
161
+ export declare function buildLegacyContractRequestMessage(address: string, timestampMs: number): string;
162
+ /**
163
+ * The `POST /contract/fullname` message.
164
+ *
165
+ * ⚠️ BYTE-EXACT PROTOCOL STRING, on the same terms as
166
+ * `buildLegacyContractRequestMessage`: kasu-backend rebuilds
167
+ * `` `I request my full name for ${address} at ${timestamp}.` `` from the
168
+ * request body and verifies the signature against it, so the body must carry
169
+ * the same lowercased address this builder signs.
170
+ *
171
+ * @param timestampMs ms-epoch, and the same value sent as the body's
172
+ * `timestamp`.
173
+ */
174
+ export declare function buildFullNameRequestMessage(address: string, timestampMs: number): string;
@@ -0,0 +1,160 @@
1
+ import { ethers } from 'ethers';
2
+ /** Narrow the backend's loose `contractType` string to the encoded union. */
3
+ export function asContractType(raw) {
4
+ return raw === 'exempt' ? 'exempt' : 'retail';
5
+ }
6
+ /**
7
+ * Parse the server's JSON-string `formattedMessage` into a tree. Returns
8
+ * `null` on parse failure so a renderer can fall back to the plaintext.
9
+ */
10
+ export function parseFormattedMessage(raw) {
11
+ try {
12
+ const parsed = JSON.parse(raw);
13
+ if (parsed && typeof parsed === 'object')
14
+ return parsed;
15
+ return null;
16
+ }
17
+ catch (_a) {
18
+ return null;
19
+ }
20
+ }
21
+ // ---------------------------------------------------------------------------
22
+ // The on-chain `depositData` blob
23
+ // ---------------------------------------------------------------------------
24
+ /**
25
+ * Pack the contract version and type into the `versionType` word.
26
+ *
27
+ * ```
28
+ * high byte = contract version (>= 1)
29
+ * low byte = 0 for retail, 1 for exempt
30
+ * ```
31
+ */
32
+ export function buildContractVersionType(contractVersion, contractType) {
33
+ return (contractVersion << 8) + (contractType === 'retail' ? 0 : 1);
34
+ }
35
+ /**
36
+ * Build the on-chain `depositData` blob that `requestDepositWithKyc` expects.
37
+ *
38
+ * The KasuController decodes the bytes as
39
+ * `(bytes signature, uint256 timestamp, uint256 versionType)` and uses the
40
+ * embedded acceptance signature to verify — retrospectively, via the
41
+ * agreements service `/contract/resolve` — that the lender signed the
42
+ * loan-contract text. The ABI tuple and the packing are consensus-critical:
43
+ * these bytes go on chain.
44
+ *
45
+ * kasu-ui encodes this with viem, kasu-mobile with ethers v5 (viem is not
46
+ * available on Expo). This is the ethers v5 implementation, and
47
+ * `loan-contract.test.ts` pins its output byte-for-byte against fixtures
48
+ * produced by the viem version, so the two apps can never diverge here.
49
+ *
50
+ * @param args.signature EIP-191 signature from the lender accepting
51
+ * `contractMessage`, as a 0x-prefixed hex string.
52
+ * @param args.timestamp ms-epoch from the contract response.
53
+ */
54
+ export function encodeDepositData(args) {
55
+ const versionType = buildContractVersionType(args.contractVersion, args.contractType);
56
+ return ethers.utils.defaultAbiCoder.encode(['bytes', 'uint256', 'uint256'], [
57
+ args.signature,
58
+ ethers.BigNumber.from(args.timestamp),
59
+ ethers.BigNumber.from(versionType),
60
+ ]);
61
+ }
62
+ // ---------------------------------------------------------------------------
63
+ // The signed messages
64
+ // ---------------------------------------------------------------------------
65
+ const MONTH_NAMES = [
66
+ 'January',
67
+ 'February',
68
+ 'March',
69
+ 'April',
70
+ 'May',
71
+ 'June',
72
+ 'July',
73
+ 'August',
74
+ 'September',
75
+ 'October',
76
+ 'November',
77
+ 'December',
78
+ ];
79
+ /**
80
+ * Format a unix timestamp as `{day} {MonthName} {yyyy}, {HH}:{mm}` in UTC.
81
+ * Day is non-padded; hour and minute are zero-padded to two digits (24h). A
82
+ * timestamp with >= 13 digits is treated as milliseconds, otherwise as seconds
83
+ * — the same auto-detection kasu-backend applies.
84
+ *
85
+ * Deliberately a manual formatter with English month names: no locale, no
86
+ * `Intl`, so the output is byte-identical across runtimes and time zones. This
87
+ * is not a display date. It goes inside a signed message.
88
+ *
89
+ * e.g. 1785313320000 → `"29 July 2026, 08:22"`
90
+ */
91
+ export function formatSignTimestampUtc(timestamp) {
92
+ const ms = timestamp.toString().length >= 13 ? timestamp : timestamp * 1000;
93
+ const date = new Date(ms);
94
+ const day = date.getUTCDate();
95
+ const month = MONTH_NAMES[date.getUTCMonth()];
96
+ const year = date.getUTCFullYear();
97
+ const hours = String(date.getUTCHours()).padStart(2, '0');
98
+ const minutes = String(date.getUTCMinutes()).padStart(2, '0');
99
+ return `${day} ${month} ${year}, ${hours}:${minutes}`;
100
+ }
101
+ /**
102
+ * The 4-line human-readable message a lender signs to generate their loan
103
+ * agreement for review — `POST /contract/generate`.
104
+ *
105
+ * ⚠️ BYTE-EXACT PROTOCOL STRING. kasu-backend rebuilds this string from the
106
+ * request body and verifies the signature against it, so the wording,
107
+ * ordering, separators, line breaks and date format are all part of the wire
108
+ * contract. The separator between the line-2 fields is a MIDDLE DOT U+00B7
109
+ * (·) with a single space on each side; the four lines are joined with `\n`.
110
+ *
111
+ * The backend takes this format only when all four display fields are present
112
+ * and non-empty, and it cross-checks `amountLabel`'s leading number against
113
+ * the `depositAmount` it was sent (thousands separators stripped) — a message
114
+ * that states an amount other than the one being executed is refused.
115
+ */
116
+ export function buildLoanAgreementSignMessage(p) {
117
+ return [
118
+ 'Generate my Loan Agreement for review:',
119
+ `${p.strategyName} · ${p.region} · ${p.optionName} · ${p.amountLabel}.`,
120
+ `Request made ${formatSignTimestampUtc(p.timestamp)} UTC.`,
121
+ 'This request does not commit me to lend.',
122
+ ].join('\n');
123
+ }
124
+ /**
125
+ * The legacy `/contract/generate` and `/contract/resolve` message.
126
+ *
127
+ * ⚠️ BYTE-EXACT PROTOCOL STRING. kasu-backend rebuilds it as
128
+ * `` `I request contract content for ${address} at ${timestamp}.` `` from the
129
+ * `address` and `timestamp` fields of the request body — so the string signed
130
+ * and the body sent must agree exactly, INCLUDING the address casing. This
131
+ * builder lowercases, and the request body must carry the same lowercased
132
+ * address; that is what both apps signing this format do today.
133
+ *
134
+ * The backend takes this path whenever the four human-readable display fields
135
+ * are absent, and documents it as permanent until the legacy app is
136
+ * decommissioned. `/contract/resolve` has no other format — every consumer
137
+ * signs this one to retrieve an existing agreement.
138
+ *
139
+ * @param timestampMs ms-epoch, and the same value sent as the body's
140
+ * `timestamp`.
141
+ */
142
+ export function buildLegacyContractRequestMessage(address, timestampMs) {
143
+ return `I request contract content for ${address.toLowerCase()} at ${timestampMs}.`;
144
+ }
145
+ /**
146
+ * The `POST /contract/fullname` message.
147
+ *
148
+ * ⚠️ BYTE-EXACT PROTOCOL STRING, on the same terms as
149
+ * `buildLegacyContractRequestMessage`: kasu-backend rebuilds
150
+ * `` `I request my full name for ${address} at ${timestamp}.` `` from the
151
+ * request body and verifies the signature against it, so the body must carry
152
+ * the same lowercased address this builder signs.
153
+ *
154
+ * @param timestampMs ms-epoch, and the same value sent as the body's
155
+ * `timestamp`.
156
+ */
157
+ export function buildFullNameRequestMessage(address, timestampMs) {
158
+ return `I request my full name for ${address.toLowerCase()} at ${timestampMs}.`;
159
+ }
160
+ //# sourceMappingURL=loan-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loan-contract.js","sourceRoot":"","sources":["../../src/domain/loan-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAgFhC,6EAA6E;AAC7E,MAAM,UAAU,cAAc,CAAC,GAAW;IACtC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACjC,GAAW;IAEX,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAY,CAAC;QAC1C,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;YACpC,OAAO,MAA+B,CAAC;QAC3C,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,WAAM,CAAC;QACL,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AAED,8EAA8E;AAC9E,kCAAkC;AAClC,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACpC,eAAuB,EACvB,YAA0B;IAE1B,OAAO,CAAC,eAAe,IA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KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,GAAG,GAAG,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,OAAO,EAAE,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,CAM7C;IACG,OAAO;QACH,wCAAwC;QACxC,GAAG,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,WAAW,GAAG;QACvE,gBAAgB,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO;QAC1D,0CAA0C;KAC7C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,iCAAiC,CAC7C,OAAe,EACf,WAAmB;IAEnB,OAAO,kCAAkC,OAAO,CAAC,WAAW,EAAE,OAAO,WAAW,GAAG,CAAC;AACxF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,2BAA2B,CACvC,OAAe,EACf,WAAmB;IAEnB,OAAO,8BAA8B,OAAO,CAAC,WAAW,EAAE,OAAO,WAAW,GAAG,CAAC;AACpF,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,255 @@
1
+ import { ethers } from 'ethers';
2
+ import { asContractType, buildContractVersionType, buildFullNameRequestMessage, buildLegacyContractRequestMessage, buildLoanAgreementSignMessage, encodeDepositData, formatSignTimestampUtc, parseFormattedMessage, } from './loan-contract';
3
+ /**
4
+ * Ported from kasu-ui `src/features/lending/lib/encode-deposit-data.test.ts`
5
+ * and `sign-message.test.ts`.
6
+ *
7
+ * PINNED CROSS-REPO CONTRACT. The expected strings and byte strings here are
8
+ * what kasu-backend reconstructs and verifies against. A diff in this file
9
+ * without a matching kasu-backend diff means signatures stop verifying in
10
+ * production.
11
+ */
12
+ describe('buildContractVersionType', () => {
13
+ it('packs version 1 retail as 0x0100 (256)', () => {
14
+ expect(buildContractVersionType(1, 'retail')).toBe(256);
15
+ });
16
+ it('packs version 1 exempt as 0x0101 (257)', () => {
17
+ expect(buildContractVersionType(1, 'exempt')).toBe(257);
18
+ });
19
+ it('packs version 0 retail as 0', () => {
20
+ expect(buildContractVersionType(0, 'retail')).toBe(0);
21
+ });
22
+ it('packs version 2 exempt as 0x0201 (513)', () => {
23
+ expect(buildContractVersionType(2, 'exempt')).toBe(513);
24
+ });
25
+ });
26
+ const SIG_65 = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' +
27
+ 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef1c';
28
+ const SIG_65_B = '0x4a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8' +
29
+ '4a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f81b';
30
+ /**
31
+ * BYTE FIXTURES — produced by the viem implementation kasu-ui runs
32
+ * (`encodeAbiParameters(parseAbiParameters('bytes, uint256, uint256'), …)`)
33
+ * and pasted here verbatim. This is the whole point of the port: the ethers v5
34
+ * encoder in `loan-contract.ts` must emit exactly these bytes, because kasu-ui
35
+ * and kasu-mobile write the same `depositData` field on the same contract.
36
+ *
37
+ * Covers both contract types, a contract version >= 2, a short signature and
38
+ * the empty-signature/zero-timestamp floor.
39
+ */
40
+ const VIEM_FIXTURES = [
41
+ {
42
+ name: 'v1 retail, ms timestamp',
43
+ signature: SIG_65,
44
+ timestamp: 1700000000000,
45
+ contractVersion: 1,
46
+ contractType: 'retail',
47
+ expected: '0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000018bcfe5680000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000041deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef1c00000000000000000000000000000000000000000000000000000000000000',
48
+ },
49
+ {
50
+ name: 'v1 exempt, ms timestamp',
51
+ signature: SIG_65,
52
+ timestamp: 1700000000000,
53
+ contractVersion: 1,
54
+ contractType: 'exempt',
55
+ expected: '0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000018bcfe5680000000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000000000000000041deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef1c00000000000000000000000000000000000000000000000000000000000000',
56
+ },
57
+ {
58
+ name: 'v2 retail, deck timestamp',
59
+ signature: SIG_65_B,
60
+ timestamp: 1785313320000,
61
+ contractVersion: 2,
62
+ contractType: 'retail',
63
+ expected: '0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000019facf75c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000414a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f84a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f81b00000000000000000000000000000000000000000000000000000000000000',
64
+ },
65
+ {
66
+ name: 'v2 exempt, deck timestamp',
67
+ signature: SIG_65_B,
68
+ timestamp: 1785313320000,
69
+ contractVersion: 2,
70
+ contractType: 'exempt',
71
+ expected: '0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000019facf75c40000000000000000000000000000000000000000000000000000000000000020100000000000000000000000000000000000000000000000000000000000000414a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f84a1e2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f81b00000000000000000000000000000000000000000000000000000000000000',
72
+ },
73
+ {
74
+ name: 'short signature, v3 exempt, timestamp 1',
75
+ signature: '0x1234',
76
+ timestamp: 1,
77
+ contractVersion: 3,
78
+ contractType: 'exempt',
79
+ expected: '0x00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000030100000000000000000000000000000000000000000000000000000000000000021234000000000000000000000000000000000000000000000000000000000000',
80
+ },
81
+ {
82
+ name: 'empty signature, v0 retail, timestamp 0',
83
+ signature: '0x',
84
+ timestamp: 0,
85
+ contractVersion: 0,
86
+ contractType: 'retail',
87
+ expected: '0x0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
88
+ },
89
+ ];
90
+ describe('encodeDepositData — byte-identical to the viem implementation', () => {
91
+ for (const fixture of VIEM_FIXTURES) {
92
+ it(`matches the viem fixture: ${fixture.name}`, () => {
93
+ expect(encodeDepositData({
94
+ signature: fixture.signature,
95
+ timestamp: fixture.timestamp,
96
+ contractVersion: fixture.contractVersion,
97
+ contractType: fixture.contractType,
98
+ })).toBe(fixture.expected);
99
+ });
100
+ }
101
+ it('produces a 0x-prefixed hex string', () => {
102
+ const out = encodeDepositData({
103
+ signature: SIG_65,
104
+ timestamp: 1700000000000,
105
+ contractVersion: 1,
106
+ contractType: 'retail',
107
+ });
108
+ expect(out).toMatch(/^0x[0-9a-f]+$/i);
109
+ });
110
+ it('round-trips through the same ABI tuple', () => {
111
+ const out = encodeDepositData({
112
+ signature: SIG_65,
113
+ timestamp: 1700000000000,
114
+ contractVersion: 1,
115
+ contractType: 'exempt',
116
+ });
117
+ const [sigOut, tsOut, vtOut] = ethers.utils.defaultAbiCoder.decode(['bytes', 'uint256', 'uint256'], out);
118
+ expect(sigOut).toBe(SIG_65);
119
+ expect(tsOut.toString()).toBe('1700000000000');
120
+ expect(vtOut.toString()).toBe('257'); // version 1 exempt
121
+ });
122
+ it('encodes retail with low-byte 0 and exempt with low-byte 1', () => {
123
+ const vt = (contractType) => {
124
+ const [, , v] = ethers.utils.defaultAbiCoder.decode(['bytes', 'uint256', 'uint256'], encodeDepositData({
125
+ signature: SIG_65,
126
+ timestamp: 1,
127
+ contractVersion: 1,
128
+ contractType,
129
+ }));
130
+ return v.toString();
131
+ };
132
+ expect(vt('retail')).toBe('256');
133
+ expect(vt('exempt')).toBe('257');
134
+ });
135
+ });
136
+ describe('formatSignTimestampUtc', () => {
137
+ // 29 July 2026, 08:22:00 UTC.
138
+ const ms = 1785313320000; // 13 digits → milliseconds
139
+ const seconds = 1785313320; // 10 digits → seconds
140
+ it('formats a millisecond timestamp (>= 13 digits)', () => {
141
+ expect(formatSignTimestampUtc(ms)).toBe('29 July 2026, 08:22');
142
+ });
143
+ it('formats a second timestamp (< 13 digits) to the same instant', () => {
144
+ expect(formatSignTimestampUtc(seconds)).toBe('29 July 2026, 08:22');
145
+ });
146
+ it('pads hour/minute but not the day, at a month-boundary midnight', () => {
147
+ // 1 August 2026, 00:05:00 UTC — day non-padded ("1"), minute padded.
148
+ const midnight = Date.UTC(2026, 7, 1, 0, 5, 0);
149
+ expect(formatSignTimestampUtc(midnight)).toBe('1 August 2026, 00:05');
150
+ });
151
+ });
152
+ describe('buildLoanAgreementSignMessage', () => {
153
+ it('builds the exact 4-line message from a millisecond timestamp', () => {
154
+ expect(buildLoanAgreementSignMessage({
155
+ strategyName: 'Taxation Funding (Tax Pay)',
156
+ region: 'Australia',
157
+ optionName: 'Upper Mezzanine',
158
+ amountLabel: '500 AUDD',
159
+ timestamp: 1785313320000,
160
+ })).toBe('Generate my Loan Agreement for review:\n' +
161
+ 'Taxation Funding (Tax Pay) · Australia · Upper Mezzanine · 500 AUDD.\n' +
162
+ 'Request made 29 July 2026, 08:22 UTC.\n' +
163
+ 'This request does not commit me to lend.');
164
+ });
165
+ it('builds the identical message from the equivalent second timestamp', () => {
166
+ expect(buildLoanAgreementSignMessage({
167
+ strategyName: 'Whole Ledger Funding',
168
+ region: 'Australia',
169
+ optionName: 'Mezzanine',
170
+ amountLabel: '1,260.37 USDC',
171
+ timestamp: 1785313320, // seconds form of the same instant
172
+ })).toBe('Generate my Loan Agreement for review:\n' +
173
+ 'Whole Ledger Funding · Australia · Mezzanine · 1,260.37 USDC.\n' +
174
+ 'Request made 29 July 2026, 08:22 UTC.\n' +
175
+ 'This request does not commit me to lend.');
176
+ });
177
+ it('formats a month-boundary/midnight request line', () => {
178
+ expect(buildLoanAgreementSignMessage({
179
+ strategyName: 'Professional Fee Funding',
180
+ region: 'Australia',
181
+ optionName: 'Junior',
182
+ amountLabel: '10 USDC',
183
+ timestamp: Date.UTC(2026, 7, 1, 0, 5, 0),
184
+ })).toBe('Generate my Loan Agreement for review:\n' +
185
+ 'Professional Fee Funding · Australia · Junior · 10 USDC.\n' +
186
+ 'Request made 1 August 2026, 00:05 UTC.\n' +
187
+ 'This request does not commit me to lend.');
188
+ });
189
+ it('separates the line-2 fields with U+00B7 surrounded by single spaces', () => {
190
+ const message = buildLoanAgreementSignMessage({
191
+ strategyName: 'A',
192
+ region: 'B',
193
+ optionName: 'C',
194
+ amountLabel: 'D',
195
+ timestamp: 1785313320000,
196
+ });
197
+ expect(message.split('\n')[1]).toBe('A · B · C · D.');
198
+ expect(message.split('\n')).toHaveLength(4);
199
+ });
200
+ });
201
+ describe('buildLegacyContractRequestMessage', () => {
202
+ const ADDRESS = '0x4c0d92e9c862B58b0FFeAAD031004A049d2c360D';
203
+ it('builds the exact legacy template with a lowercased address', () => {
204
+ expect(buildLegacyContractRequestMessage(ADDRESS, 1785313320000)).toBe('I request contract content for ' +
205
+ '0x4c0d92e9c862b58b0ffeaad031004a049d2c360d at 1785313320000.');
206
+ });
207
+ it('is insensitive to the casing the caller hands over', () => {
208
+ expect(buildLegacyContractRequestMessage(ADDRESS, 1)).toBe(buildLegacyContractRequestMessage(ADDRESS.toLowerCase(), 1));
209
+ });
210
+ it('prints the timestamp verbatim — no seconds/ms normalisation', () => {
211
+ // The backend echoes the body's `timestamp` into the string it
212
+ // verifies, so whatever is signed must be what is sent.
213
+ expect(buildLegacyContractRequestMessage(ADDRESS, 1785313320)).toBe('I request contract content for ' +
214
+ '0x4c0d92e9c862b58b0ffeaad031004a049d2c360d at 1785313320.');
215
+ });
216
+ });
217
+ describe('buildFullNameRequestMessage', () => {
218
+ const ADDRESS = '0x26b5b8060A704b0420734d5Ccd657384fb1366C2';
219
+ it('builds the exact full-name template with a lowercased address', () => {
220
+ expect(buildFullNameRequestMessage(ADDRESS, 1785313320000)).toBe('I request my full name for ' +
221
+ '0x26b5b8060a704b0420734d5ccd657384fb1366c2 at 1785313320000.');
222
+ });
223
+ it('is a different message from the contract-content one', () => {
224
+ expect(buildFullNameRequestMessage(ADDRESS, 1)).not.toBe(buildLegacyContractRequestMessage(ADDRESS, 1));
225
+ });
226
+ });
227
+ describe('parseFormattedMessage', () => {
228
+ it('parses the server’s JSON-encoded tree', () => {
229
+ const parsed = parseFormattedMessage(JSON.stringify({ intro: 'x', 'subheader-1': { title: 't' } }));
230
+ expect(parsed === null || parsed === void 0 ? void 0 : parsed.intro).toBe('x');
231
+ });
232
+ it('returns null on malformed JSON so a renderer can fall back', () => {
233
+ expect(parseFormattedMessage('not json')).toBeNull();
234
+ expect(parseFormattedMessage('')).toBeNull();
235
+ });
236
+ it('returns null for a JSON scalar, which is not a contract tree', () => {
237
+ expect(parseFormattedMessage('42')).toBeNull();
238
+ expect(parseFormattedMessage('null')).toBeNull();
239
+ expect(parseFormattedMessage('"a string"')).toBeNull();
240
+ });
241
+ });
242
+ describe('asContractType', () => {
243
+ it('narrows the wire string to the two encoded types', () => {
244
+ expect(asContractType('exempt')).toBe('exempt');
245
+ expect(asContractType('retail')).toBe('retail');
246
+ });
247
+ it('falls back to retail for anything else', () => {
248
+ // Retail is the stricter contract; an unrecognised type must not be
249
+ // silently treated as the exempt one.
250
+ expect(asContractType('')).toBe('retail');
251
+ expect(asContractType('Exempt')).toBe('retail');
252
+ expect(asContractType('whatever')).toBe('retail');
253
+ });
254
+ });
255
+ //# sourceMappingURL=loan-contract.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loan-contract.test.js","sourceRoot":"","sources":["../../src/domain/loan-contract.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACH,cAAc,EACd,wBAAwB,EACxB,2BAA2B,EAC3B,iCAAiC,EACjC,6BAA6B,EAE7B,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,GACxB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AAEH,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,wBAAwB,CAAC,CAAC,E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