@chipi-stack/backend 14.3.1 → 14.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.
@@ -0,0 +1,221 @@
1
+ import { CreateWalletParams, CreateWalletResponse, CreateCustodialWalletParams, WalletData, GetWalletParams, GetWalletResponse, UpdateWalletEncryptionParams, UpdateWalletEncryptionResponse, GetTokenBalanceParams, GetTokenBalanceResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse } from '@chipi-stack/types';
2
+ import { C as ChipiClient } from './client-CqD_yGH0.js';
3
+
4
+ /**
5
+ * SDK-side orchestrator for the CHIPI v29 → SHHH V8.4 migration flow.
6
+ *
7
+ * 1. POST /chipi-wallets/prepare-migrate-to-shhh
8
+ * Returns the path decision (HAPPY / STRANDED / ALREADY_MIGRATED)
9
+ * plus the parameters the SDK uses to build the [upgrade(SHHH),
10
+ * bootstrap_from_sessions] multicall locally.
11
+ *
12
+ * 2. Build the multicall via `buildMigrationCalls`. Targets the
13
+ * wallet itself (CHIPI v29 sessions account → V8.4 ShhhAccount).
14
+ *
15
+ * 3. Broadcast the multicall through the **existing CHIPI v29
16
+ * transaction flow** (`executePaymasterTransaction` →
17
+ * `/transactions/prepare-typed-data` → SDK signs `(r, s)` locally
18
+ * → `/transactions/execute-sponsored` → paymaster relay). The
19
+ * wallet is still CHIPI v29 at sign time, so the signature must
20
+ * use CHIPI v29's `(r, s)` SNIP-12 format — not V8.4's V2_SNIP12
21
+ * envelope.
22
+ *
23
+ * This is the historical bug fixed by this refactor. The
24
+ * original orchestrator (PR #282) used V8.4's
25
+ * `buildStarkEnvelope` + `serializeExecuteFromOutsideV2Calldata`
26
+ * and sent a 5-felt envelope `[V2_SNIP12, KIND_TAG, len, r, s]`
27
+ * to the wallet. CHIPI v29's
28
+ * `sessions-smart-contract/src/account.cairo::execute_from_outside_v2`
29
+ * read `sig[0:2]` as `(r, s)`, got bogus values, panicked with
30
+ * `SRC9: invalid signature` (line 430). Because CHIPI v29's
31
+ * `_execute_calls` swallows `Result::Err` at line 684, the outer
32
+ * tx still SUCCEEDED but the upgrade(SHHH) call never ran. The
33
+ * class hash stayed CHIPI v29. The wallet panic was confirmed by
34
+ * reading the inner-call `result` field: ASCII-decoded to
35
+ * literal `SRC9: invalid signature`. Reference receipt:
36
+ * `0x0535ed9ca8628f1c82ee2005d84017e59a02436597df371d516b97c2c93a516a`
37
+ * (staging wallet `0x1434aadce…`).
38
+ *
39
+ * 4. POST /chipi-wallets/execute-migrate-to-shhh with the tx hash.
40
+ * chipi-back verifies the on-chain class hash flipped to SHHH
41
+ * V8.4 and patches the DB row.
42
+ *
43
+ * Stranded-state recovery (STRANDED path) is NOT shipped here. The
44
+ * SDK has the builders (`buildBootstrapSignedCall`,
45
+ * `computeBootstrapMessage`, `signBootstrapMessage`) but the flow is
46
+ * sufficiently different from HAPPY that surfacing it cleanly needs
47
+ * its own UI affordance. Throws a clear deferred-feature error so
48
+ * the calling dashboard can route to a stranded-recovery UI.
49
+ */
50
+
51
+ /**
52
+ * Response shape from chipi-back's `prepare-migrate-to-shhh`. Mirrors
53
+ * the union the server returns; the SDK orchestrator switches on
54
+ * `migrationPath` to decide what to do next.
55
+ */
56
+ type PrepareMigrateResponse = {
57
+ migrationPath: "HAPPY";
58
+ walletAddress: string;
59
+ onChainClassHash: string;
60
+ shhhClassHash: string;
61
+ shhhVerifierClassHash: string;
62
+ label: string;
63
+ auditLogId: string;
64
+ } | {
65
+ migrationPath: "STRANDED";
66
+ walletAddress: string;
67
+ onChainClassHash: string;
68
+ shhhVerifierClassHash: string;
69
+ label: string;
70
+ auditLogId: string;
71
+ } | {
72
+ migrationPath: "ALREADY_MIGRATED";
73
+ walletAddress: string;
74
+ onChainClassHash: string;
75
+ primaryKind: string;
76
+ };
77
+ /**
78
+ * Response shape from chipi-back's `execute-migrate-to-shhh`.
79
+ *
80
+ * On terminal success, the server returns the patched wallet shape.
81
+ * On PARTIAL failure (on-chain succeeded + DB patch failed) the
82
+ * server still returns 200 with `partial: true` — the migration tx
83
+ * landed but the calling dashboard should surface "we'll catch up on
84
+ * our end shortly" until the reconciler cron (task #30) patches the
85
+ * row.
86
+ */
87
+ interface ExecuteMigrateResponse {
88
+ walletId: string;
89
+ walletType: "SHHH";
90
+ signerKind: "STARK";
91
+ classHash: string;
92
+ migratedFromClassHash: string;
93
+ transactionHash: string;
94
+ partial?: boolean;
95
+ }
96
+ /**
97
+ * Final result returned by `migrateChipiWalletToShhh`. Either a
98
+ * full migration completed end-to-end, OR an ALREADY_MIGRATED
99
+ * short-circuit where the server patched the DB row but no on-chain
100
+ * tx was needed. Both are terminal; both leave the wallet in SHHH
101
+ * state for subsequent SDK operations.
102
+ */
103
+ type MigrationOutcome = (ExecuteMigrateResponse & {
104
+ kind: "MIGRATED";
105
+ }) | {
106
+ kind: "ALREADY_MIGRATED";
107
+ walletAddress: string;
108
+ onChainClassHash: string;
109
+ primaryKind: string;
110
+ };
111
+ interface MigrateChipiWalletToShhhParams {
112
+ client: ChipiClient;
113
+ bearerToken: string;
114
+ /** Chipi-back wallet row id + the wallet's tenant scope. */
115
+ walletId: string;
116
+ externalUserId: string;
117
+ /** Wallet shape the SDK passes through from its `wallets.getWallet` cache. */
118
+ wallet: {
119
+ publicKey: string;
120
+ encryptedPrivateKey: string;
121
+ };
122
+ /** PIN or passkey-derived secret that decrypts `encryptedPrivateKey`. */
123
+ encryptKey: string;
124
+ /**
125
+ * @deprecated The pre-refactor orchestrator (sdks #282) used this to
126
+ * override the V8.4 SNIP-12 chain id. The new flow inherits chain
127
+ * config from `executePaymasterTransaction`'s RPC endpoint
128
+ * resolution, so this field is ignored. Kept for source-compat with
129
+ * any v14.5.0-rc callers that may have copied the older signature
130
+ * into their codebase before publish.
131
+ */
132
+ chainId?: bigint | string;
133
+ }
134
+ declare function migrateChipiWalletToShhh(params: MigrateChipiWalletToShhhParams): Promise<MigrationOutcome>;
135
+
136
+ /**
137
+ * Wallet management utilities
138
+ */
139
+ declare class ChipiWallets {
140
+ private client;
141
+ constructor(client: ChipiClient);
142
+ /**
143
+ * Create a new wallet on Starknet (gasless, paymaster-sponsored).
144
+ *
145
+ * **PIN is weak — not recommended for production.** `encryptKey` here
146
+ * doubles as the only thing decrypting the wallet's private key. A
147
+ * user-typed PIN is short, low-entropy, and trivially compromised
148
+ * by shoulder-surfing or phishing. Production embedded-wallet apps
149
+ * should derive `encryptKey` from a platform passkey
150
+ * (`@chipi-stack/chipi-passkey` `getWalletEncryptKey` for the legacy
151
+ * PRF flow, or — preferred — `createShhhPasskey` for new SHHH
152
+ * V8.4 wallets where the P-256 key never leaves the platform
153
+ * authenticator at all). PIN remains only as a last-resort
154
+ * recovery surface for users without WebAuthn / biometrics.
155
+ */
156
+ createWallet(params: CreateWalletParams & {
157
+ bearerToken: string;
158
+ }): Promise<CreateWalletResponse>;
159
+ /**
160
+ * Build constructor calldata based on wallet type
161
+ * - CHIPI: Simple OpenZeppelin account with just public_key
162
+ * - ARGENT: Argent X Account with owner/guardian structure
163
+ */
164
+ private buildConstructorCallData;
165
+ /**
166
+ * Create a custodial merchant wallet
167
+ */
168
+ createCustodialWallet({ params, bearerToken, }: {
169
+ params: Omit<CreateCustodialWalletParams, "orgId">;
170
+ bearerToken: string;
171
+ }): Promise<WalletData>;
172
+ getWallet(params: GetWalletParams, bearerToken: string): Promise<GetWalletResponse | null>;
173
+ /**
174
+ * Recover passkey credential metadata for a wallet.
175
+ * Used when localStorage is cleared — SDK recovers credentialId from backend.
176
+ */
177
+ getCredentialRecovery(params: {
178
+ externalUserId: string;
179
+ }, bearerToken: string): Promise<{
180
+ credentialId: string | null;
181
+ authMethod: string | null;
182
+ prfSupported: boolean | null;
183
+ deviceType: string | null;
184
+ }>;
185
+ updateWalletEncryption(params: UpdateWalletEncryptionParams, bearerToken: string): Promise<UpdateWalletEncryptionResponse>;
186
+ getPrivateKeyAX: () => string;
187
+ getTokenBalance({ params, bearerToken, }: {
188
+ params: GetTokenBalanceParams;
189
+ bearerToken: string;
190
+ }): Promise<GetTokenBalanceResponse>;
191
+ /**
192
+ * Prepare a wallet upgrade (e.g., READY → CHIPI or CHIPI v29 → v33).
193
+ * Returns typed data that must be signed by the wallet owner.
194
+ */
195
+ prepareWalletUpgrade(params: PrepareWalletUpgradeParams, bearerToken: string): Promise<PrepareWalletUpgradeResponse>;
196
+ /**
197
+ * Execute a wallet upgrade after the owner has signed the typed data.
198
+ */
199
+ executeWalletUpgrade(params: ExecuteWalletUpgradeParams, bearerToken: string): Promise<ExecuteWalletUpgradeResponse>;
200
+ /**
201
+ * Migrate a CHIPI v29 wallet to SHHH V8.4 in-place at the same
202
+ * on-chain address. Composes the two-phase chipi-back endpoint:
203
+ * prepare returns the path decision + parameters, then this method
204
+ * builds the [upgrade, bootstrap_from_sessions] multicall locally,
205
+ * signs the V8.4 OE with the wallet's STARK key (decrypted via
206
+ * the user's encryptKey), and sends the signed calldata to the
207
+ * execute endpoint. Server forwards verbatim to the paymaster.
208
+ *
209
+ * Returns `{kind: "ALREADY_MIGRATED"}` if the wallet is already
210
+ * SHHH on chain (DB row gets patched server-side; no on-chain tx
211
+ * fires); otherwise `{kind: "MIGRATED", transactionHash, ...}`.
212
+ *
213
+ * Throws on STRANDED-state recovery, UNDEPLOYED wallets, and
214
+ * other deferred-feature paths with actionable error messages.
215
+ *
216
+ * Endpoints contract shipped in chipi-back task #28 (PR #272).
217
+ */
218
+ migrateToShhh(params: Omit<MigrateChipiWalletToShhhParams, "client" | "bearerToken">, bearerToken: string): Promise<MigrationOutcome>;
219
+ }
220
+
221
+ export { ChipiWallets as C, type ExecuteMigrateResponse as E, type MigrateChipiWalletToShhhParams as M, type PrepareMigrateResponse as P, type MigrationOutcome as a, migrateChipiWalletToShhh as m };
@@ -1,56 +1,3 @@
1
- import { CreateWalletParams, CreateWalletResponse, CreateCustodialWalletParams, WalletData, GetWalletParams, GetWalletResponse, UpdateWalletEncryptionParams, UpdateWalletEncryptionResponse, GetTokenBalanceParams, GetTokenBalanceResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse } from '@chipi-stack/types';
2
- import { C as ChipiClient } from './client-CqD_yGH0.mjs';
3
-
4
- /**
5
- * Wallet management utilities
6
- */
7
- declare class ChipiWallets {
8
- private client;
9
- constructor(client: ChipiClient);
10
- createWallet(params: CreateWalletParams & {
11
- bearerToken: string;
12
- }): Promise<CreateWalletResponse>;
13
- /**
14
- * Build constructor calldata based on wallet type
15
- * - CHIPI: Simple OpenZeppelin account with just public_key
16
- * - ARGENT: Argent X Account with owner/guardian structure
17
- */
18
- private buildConstructorCallData;
19
- /**
20
- * Create a custodial merchant wallet
21
- */
22
- createCustodialWallet({ params, bearerToken, }: {
23
- params: Omit<CreateCustodialWalletParams, "orgId">;
24
- bearerToken: string;
25
- }): Promise<WalletData>;
26
- getWallet(params: GetWalletParams, bearerToken: string): Promise<GetWalletResponse | null>;
27
- /**
28
- * Recover passkey credential metadata for a wallet.
29
- * Used when localStorage is cleared — SDK recovers credentialId from backend.
30
- */
31
- getCredentialRecovery(params: {
32
- externalUserId: string;
33
- }, bearerToken: string): Promise<{
34
- credentialId: string | null;
35
- authMethod: string | null;
36
- prfSupported: boolean | null;
37
- deviceType: string | null;
38
- }>;
39
- updateWalletEncryption(params: UpdateWalletEncryptionParams, bearerToken: string): Promise<UpdateWalletEncryptionResponse>;
40
- getPrivateKeyAX: () => string;
41
- getTokenBalance({ params, bearerToken, }: {
42
- params: GetTokenBalanceParams;
43
- bearerToken: string;
44
- }): Promise<GetTokenBalanceResponse>;
45
- /**
46
- * Prepare a wallet upgrade (e.g., READY → CHIPI or CHIPI v29 → v33).
47
- * Returns typed data that must be signed by the wallet owner.
48
- */
49
- prepareWalletUpgrade(params: PrepareWalletUpgradeParams, bearerToken: string): Promise<PrepareWalletUpgradeResponse>;
50
- /**
51
- * Execute a wallet upgrade after the owner has signed the typed data.
52
- */
53
- executeWalletUpgrade(params: ExecuteWalletUpgradeParams, bearerToken: string): Promise<ExecuteWalletUpgradeResponse>;
54
- }
55
-
56
- export { ChipiWallets };
1
+ import '@chipi-stack/types';
2
+ import './client-CqD_yGH0.mjs';
3
+ export { C as ChipiWallets } from './wallets-CYCLyyXY.mjs';
package/dist/wallets.d.ts CHANGED
@@ -1,56 +1,3 @@
1
- import { CreateWalletParams, CreateWalletResponse, CreateCustodialWalletParams, WalletData, GetWalletParams, GetWalletResponse, UpdateWalletEncryptionParams, UpdateWalletEncryptionResponse, GetTokenBalanceParams, GetTokenBalanceResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse } from '@chipi-stack/types';
2
- import { C as ChipiClient } from './client-CqD_yGH0.js';
3
-
4
- /**
5
- * Wallet management utilities
6
- */
7
- declare class ChipiWallets {
8
- private client;
9
- constructor(client: ChipiClient);
10
- createWallet(params: CreateWalletParams & {
11
- bearerToken: string;
12
- }): Promise<CreateWalletResponse>;
13
- /**
14
- * Build constructor calldata based on wallet type
15
- * - CHIPI: Simple OpenZeppelin account with just public_key
16
- * - ARGENT: Argent X Account with owner/guardian structure
17
- */
18
- private buildConstructorCallData;
19
- /**
20
- * Create a custodial merchant wallet
21
- */
22
- createCustodialWallet({ params, bearerToken, }: {
23
- params: Omit<CreateCustodialWalletParams, "orgId">;
24
- bearerToken: string;
25
- }): Promise<WalletData>;
26
- getWallet(params: GetWalletParams, bearerToken: string): Promise<GetWalletResponse | null>;
27
- /**
28
- * Recover passkey credential metadata for a wallet.
29
- * Used when localStorage is cleared — SDK recovers credentialId from backend.
30
- */
31
- getCredentialRecovery(params: {
32
- externalUserId: string;
33
- }, bearerToken: string): Promise<{
34
- credentialId: string | null;
35
- authMethod: string | null;
36
- prfSupported: boolean | null;
37
- deviceType: string | null;
38
- }>;
39
- updateWalletEncryption(params: UpdateWalletEncryptionParams, bearerToken: string): Promise<UpdateWalletEncryptionResponse>;
40
- getPrivateKeyAX: () => string;
41
- getTokenBalance({ params, bearerToken, }: {
42
- params: GetTokenBalanceParams;
43
- bearerToken: string;
44
- }): Promise<GetTokenBalanceResponse>;
45
- /**
46
- * Prepare a wallet upgrade (e.g., READY → CHIPI or CHIPI v29 → v33).
47
- * Returns typed data that must be signed by the wallet owner.
48
- */
49
- prepareWalletUpgrade(params: PrepareWalletUpgradeParams, bearerToken: string): Promise<PrepareWalletUpgradeResponse>;
50
- /**
51
- * Execute a wallet upgrade after the owner has signed the typed data.
52
- */
53
- executeWalletUpgrade(params: ExecuteWalletUpgradeParams, bearerToken: string): Promise<ExecuteWalletUpgradeResponse>;
54
- }
55
-
56
- export { ChipiWallets };
1
+ import '@chipi-stack/types';
2
+ import './client-CqD_yGH0.js';
3
+ export { C as ChipiWallets } from './wallets-DxKnh21Q.js';