@goodwidget/ai-credits-widget 0.1.5 → 0.1.7

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.
@@ -1,5 +1,5 @@
1
1
  import { Address } from 'viem';
2
- import { GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
2
+ import { IconName, GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
3
3
 
4
4
  type Eip712SigningPayload = {
5
5
  primaryType: string;
@@ -15,10 +15,10 @@ type Eip712SigningPayload = {
15
15
  }>>;
16
16
  message: Record<string, string | number>;
17
17
  };
18
- type BuyerOperatorStatus = {
18
+ type SignerOperatorStatus = {
19
19
  enabled: boolean;
20
20
  account: string;
21
- buyerAddress: string;
21
+ signerAddress: string;
22
22
  operatorAddress?: string;
23
23
  currentOperator: string;
24
24
  operatorAccepted: boolean;
@@ -27,13 +27,13 @@ type BuyerOperatorStatus = {
27
27
  type OperatorConsentPayloadResponse = {
28
28
  enabled: boolean;
29
29
  account: string;
30
- buyerAddress: string;
30
+ signerAddress: string;
31
31
  typedData?: Eip712SigningPayload;
32
32
  };
33
33
 
34
34
  type AccountRef = {
35
35
  payer: string;
36
- buyer: string;
36
+ signer: string;
37
37
  };
38
38
  type UserCreditProfile = {
39
39
  account: string;
@@ -64,7 +64,13 @@ type GdCreditEntry = {
64
64
  logIndex?: number;
65
65
  createdAt: string;
66
66
  streamUpdateMonth: string;
67
- buyerAddress?: string;
67
+ /**
68
+ * Renamed from the wire's `buyerAddress` in `getCreditHistory`. Keep the
69
+ * mapping there: reading the wire name directly leaves this undefined, and an
70
+ * entry with no signer address matches no signer filter — it only ever shows
71
+ * under "All signers".
72
+ */
73
+ signerAddress?: string;
68
74
  };
69
75
  type AccountCreditResponse = {
70
76
  account: string;
@@ -88,10 +94,16 @@ type CreditHistoryQuery = {
88
94
  };
89
95
  type AccountView = {
90
96
  account: string;
91
- buyer: string | null;
97
+ signer: string | null;
92
98
  profile: UserCreditProfile;
93
- operator: BuyerOperatorStatus;
94
- withdrawableUsd: string;
99
+ /**
100
+ * Null when the operator read did not answer. Distinct from a read that came
101
+ * back saying "no operator": callers must not present an unread status as
102
+ * "not authorized", or an already-authorized account looks unconfigured.
103
+ */
104
+ operator: SignerOperatorStatus | null;
105
+ /** Null when the withdrawable read did not answer. */
106
+ withdrawableUsd: string | null;
95
107
  outstandingFundingUsd: string;
96
108
  outstandingFundingCount: number;
97
109
  };
@@ -115,7 +127,7 @@ type DiscountConfig = {
115
127
  streamBonusPercent: number;
116
128
  };
117
129
 
118
- declare const DEFAULT_BASE_RPC_URL = "https://mainnet.base.org";
130
+ declare const DEFAULT_BASE_RPC_URL = "https://base.drpc.org";
119
131
  declare const CELO_GOODID_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
120
132
  declare const DEFAULT_CELO_RPC_URL = "https://forno.celo.org";
121
133
  type AiCreditsChainClientOptions = {
@@ -128,22 +140,24 @@ type AiCreditsChainClientOptions = {
128
140
  };
129
141
  interface AiCreditsChainClient {
130
142
  fetchGdUsdPerToken(): Promise<number>;
143
+ /** Resolves the GoodID whitelist state, or rejects when the read fails. */
131
144
  isGoodIdVerified(account: string): Promise<boolean>;
132
145
  buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
133
- getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus>;
134
- buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: BuyerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
135
- getWithdrawableUsd(buyer: string): Promise<string>;
146
+ getSignerOperatorStatus(ref: AccountRef): Promise<SignerOperatorStatus>;
147
+ buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: SignerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
148
+ getWithdrawableUsd(signer: string): Promise<string>;
149
+ getSignerAuthNonce(signer: string): Promise<bigint>;
136
150
  }
137
151
  declare function createChainClient(options?: AiCreditsChainClientOptions): AiCreditsChainClient;
138
152
 
139
153
  type WithdrawPrincipalRequest = {
140
154
  amount: string;
141
155
  recipient: string;
142
- timestamp: number;
156
+ nonce: string;
143
157
  signature: string;
144
158
  };
145
159
  type ChannelOperationRequest = {
146
- timestamp?: number;
160
+ nonce?: string;
147
161
  signature?: string;
148
162
  };
149
163
  type BridgeResponse = {
@@ -165,23 +179,34 @@ type OperatorConsentRequest = {
165
179
  signature: string;
166
180
  };
167
181
  type OperatorConsentResponse = {
168
- buyer: string;
182
+ signer: string;
169
183
  bridge: BridgeResponse;
170
184
  };
185
+ type OperatorRevokeRequest = {
186
+ nonce: string;
187
+ signature: string;
188
+ };
189
+ type OperatorRevokeResponse = OperatorConsentResponse;
171
190
  declare function totalCreditUsdFromProfile(profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>): string;
172
191
  declare function totalCreditUsdFromStatus(status: {
173
192
  profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>;
174
193
  }): string;
175
194
  type AccountEnrichment = {
176
195
  totalCreditUsd: string;
177
- goodIdVerified: boolean;
178
196
  totalGdDepositedG: string;
179
197
  monthlyStreamG: string;
180
198
  };
181
199
  type BuildAccountViewOptions = {
182
- buyerAddress?: string | null;
200
+ signerAddress?: string | null;
183
201
  };
184
- declare function enrichAccountView(view: AccountView, chain: AiCreditsChainClient): Promise<AccountEnrichment>;
202
+ /**
203
+ * Derives the display fields that need no further network access.
204
+ *
205
+ * GoodID verification is deliberately not read here. Chaining it to the backend
206
+ * credit fetch meant any backend error also cleared the verified flag, and it
207
+ * re-ran on every refresh; the adapter resolves it once per account instead.
208
+ */
209
+ declare function enrichAccountView(view: AccountView): AccountEnrichment;
185
210
  interface AiCreditsBackendClient {
186
211
  getDiscountConfig(): Promise<DiscountConfig>;
187
212
  getAccountCredit(payer: string): Promise<AccountCreditResponse>;
@@ -201,8 +226,9 @@ interface AiCreditsBackendClient {
201
226
  previousBalance?: string;
202
227
  }): Promise<SettlementResult>;
203
228
  closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
204
- withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
205
- submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
229
+ withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
230
+ submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
231
+ revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
206
232
  }
207
233
  declare const DEFAULT_DISCOUNT_CONFIG: DiscountConfig;
208
234
  declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient {
@@ -228,8 +254,9 @@ declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient
228
254
  previousBalance?: string;
229
255
  }): Promise<SettlementResult>;
230
256
  closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
231
- withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
232
- submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
257
+ withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
258
+ submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
259
+ revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
233
260
  }
234
261
  declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClient {
235
262
  private unavailable;
@@ -243,17 +270,19 @@ declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClien
243
270
  closeChannel(): Promise<never>;
244
271
  withdrawCredits(): Promise<never>;
245
272
  submitOperatorConsent(): Promise<never>;
273
+ revokeOperatorConsent(): Promise<never>;
246
274
  }
247
275
  declare function createBackendClient(backendUrl: string | undefined): AiCreditsBackendClient;
248
276
  declare function buildAccountView(payer: string, backend: AiCreditsBackendClient, chain: AiCreditsChainClient, options?: BuildAccountViewOptions): Promise<AccountView>;
249
277
 
250
278
  type AiCreditsWidgetEnvironment = 'production' | 'staging' | 'development';
251
279
  type AiCreditsWidgetStatus = 'disconnected' | 'connecting' | 'purchase_setup' | 'quote_ready' | 'payment_pending' | 'payment_confirmed' | 'insufficient_g_balance' | 'payment_failed' | 'backend_unavailable' | 'unsupported_chain';
252
- type AiCreditsWidgetTab = 'buy' | 'manage' | 'history';
280
+ type AiCreditsWidgetTab = 'buy' | 'setup' | 'manage' | 'history';
253
281
  interface AiCreditsQuote {
254
282
  depositAmountG: string;
255
283
  streamAmountG: string;
256
284
  }
285
+
257
286
  interface AiCreditsWidgetAdapterState {
258
287
  status: AiCreditsWidgetStatus;
259
288
  address: string | null;
@@ -262,12 +291,22 @@ interface AiCreditsWidgetAdapterState {
262
291
  gdUsdPerToken: number | null;
263
292
  totalCreditUsd: string | null;
264
293
  isGoodIdVerified: boolean;
265
- buyerPubKey: string | null;
266
- buyerPrvKey: string | null;
294
+ /** Active signer public address. */
295
+ signerPubKey: string | null;
296
+ /** Active signer private key from the local per-payer key map. */
297
+ signerPrvKey: string | null;
298
+ /** Active signer deep-link operator signature, if present. */
299
+ operatorSignature: string | null;
267
300
  operatorConsented: boolean;
301
+ /** True while submitting / waiting for on-chain operator consent. */
302
+ operatorConsentPending: boolean;
268
303
  operatorAddress: string | null;
304
+ /** Operator currently configured for the active signer, if any. */
305
+ currentOperator: string | null;
269
306
  minDepositUsd: string | null;
270
307
  minStreamUsd: string | null;
308
+ /** Bonus credit earned so far, in micro-USD. Folded into `totalCreditUsd`. */
309
+ totalBonusUsd: string | null;
271
310
  totalGdDepositedG: string | null;
272
311
  monthlyStreamG: string | null;
273
312
  withdrawableUsd: string | null;
@@ -275,12 +314,40 @@ interface AiCreditsWidgetAdapterState {
275
314
  streamBonusPercent: number;
276
315
  error: string | null;
277
316
  activeTab: AiCreditsWidgetTab;
317
+ signers: string[];
318
+ /** Deterministic signer derived from the payer wallet Sign & Generate path. */
319
+ derivedSignerAddress: string | null;
278
320
  }
279
321
  interface AiCreditsWidgetAdapterActions {
280
322
  connect: () => Promise<void>;
281
323
  switchChain: () => Promise<void>;
282
- generateBuyerKey: () => Promise<void>;
324
+ /**
325
+ * Creates or restores the single deterministic signer for this payer wallet.
326
+ * If a derived key already exists locally, selects that signer without re-signing.
327
+ */
328
+ generateSignerKey: () => Promise<void>;
329
+ /**
330
+ * Switches the active signer and reloads that signer's account view.
331
+ * Address should be in `state.signers`.
332
+ */
333
+ selectSigner: (address: string) => Promise<void>;
334
+ discoverSigners: (addresses: string[]) => void;
335
+ /**
336
+ * Imports a signer key, stores it and selects it as the active signer.
337
+ * Resolves with the imported Signer Address, or `null` when the key could
338
+ * not be imported — callers use that to report the outcome of *this* import
339
+ * rather than the state of whichever signer happened to be active.
340
+ */
341
+ importSignerFromPrivateKey: (privateKey: string) => Promise<string | null>;
342
+ /**
343
+ * Applies an NCDI deep-link signer assignment from URL GET parameters
344
+ * (`signerAddress` + `operatorSignature`). Selects the signer immediately,
345
+ * submits the pre-signed operator approval token, and starts the buy flow.
346
+ * Never accepts a signer private key.
347
+ */
348
+ applyDeepLinkSigner: (address: string, operatorSignature: string) => Promise<void>;
283
349
  signOperatorConsent: () => Promise<void>;
350
+ revokeOperatorConsent: () => Promise<void>;
284
351
  syncOperatorConsentFromChain: () => Promise<void>;
285
352
  buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
286
353
  pay: (quote: AiCreditsQuote) => Promise<void>;
@@ -311,7 +378,7 @@ interface AiCreditsPaySuccessDetail {
311
378
  address: string;
312
379
  chainId: number;
313
380
  transactionHash: string;
314
- buyerPubKey: string;
381
+ signerPubKey: string;
315
382
  creditUsdMicro: string;
316
383
  }
317
384
  interface AiCreditsPayErrorDetail {
@@ -322,6 +389,52 @@ interface AiCreditsPayErrorDetail {
322
389
  interface AiCreditsWidgetProps {
323
390
  provider?: unknown;
324
391
  connectOverride?: () => Promise<void>;
392
+ /**
393
+ * Shows the connected-wallet chip (address, and disconnect when the host supplies
394
+ * `disconnectOverride`) in the widget header.
395
+ *
396
+ * Off by default: wallet hosts own the connection and must not offer a second,
397
+ * widget-local way to end it. Standalone deployments and Storybook opt in.
398
+ */
399
+ showWalletControls?: boolean;
400
+ /**
401
+ * Integrator-owned wallet disconnect flow. Without it the chip renders the address
402
+ * only, and its menu explains that the session belongs to the host.
403
+ */
404
+ disconnectOverride?: () => Promise<void>;
405
+ /**
406
+ * Label for the chip's menu action. Defaults to "Disconnect", which only fits when
407
+ * `disconnectOverride` really ends the session — integrators who instead open an
408
+ * account modal should relabel it.
409
+ */
410
+ disconnectLabel?: string;
411
+ /** Icon for the chip's menu action, mirroring `disconnectLabel`. */
412
+ disconnectIcon?: IconName;
413
+ /**
414
+ * Integrator-owned live address (e.g. from a wallet-connection SDK's own
415
+ * reactive account hook). See `GoodWidgetProviderProps.addressOverride`.
416
+ */
417
+ addressOverride?: string | null;
418
+ /**
419
+ * Integrator-owned live chain id, mirroring `addressOverride`. See
420
+ * `GoodWidgetProviderProps.chainIdOverride`. Worth supplying for connectors
421
+ * that do not reliably emit `chainChanged` — a WalletConnect session bridged
422
+ * through AppKit, for one — otherwise the widget can keep reporting the wrong
423
+ * network after the user has already switched.
424
+ */
425
+ chainIdOverride?: number | null;
426
+ /**
427
+ * Integrator-owned chain-switch fallback, used when the wallet rejects or
428
+ * ignores `wallet_switchEthereumChain`. See
429
+ * `GoodWidgetProviderProps.switchChainOverride`. Without it, wallets that
430
+ * cannot be switched from a page leave the user stuck on the wrong network.
431
+ */
432
+ switchChainOverride?: (chainId: number) => Promise<void>;
433
+ /**
434
+ * Chain ids the passed-down provider can currently execute on. See
435
+ * `GoodWidgetProviderProps.availableChainIdsOverride`.
436
+ */
437
+ availableChainIdsOverride?: number[] | null;
325
438
  environment?: AiCreditsWidgetEnvironment;
326
439
  backendUrl?: string;
327
440
  baseRpcUrl?: string;
@@ -339,4 +452,4 @@ interface AiCreditsWidgetProps {
339
452
  testId?: string;
340
453
  }
341
454
 
342
- export { type AiCreditsWidgetEnvironment as A, type BuyerOperatorStatus as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryQuery as F, type GdCreditEntry as G, type CreditHistoryResponse as H, type CeloEventsRecordResponse as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorConsentPayloadResponse as L, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SettlementResult as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
455
+ export { type AiCreditsWidgetEnvironment as A, type CreditHistoryQuery as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryResponse as F, type GdCreditEntry as G, type CeloEventsRecordResponse as H, type SettlementResult as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorRevokeResponse as L, type OperatorConsentPayloadResponse as M, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SignerOperatorStatus as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
@@ -1,5 +1,5 @@
1
1
  import { Address } from 'viem';
2
- import { GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
2
+ import { IconName, GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
3
3
 
4
4
  type Eip712SigningPayload = {
5
5
  primaryType: string;
@@ -15,10 +15,10 @@ type Eip712SigningPayload = {
15
15
  }>>;
16
16
  message: Record<string, string | number>;
17
17
  };
18
- type BuyerOperatorStatus = {
18
+ type SignerOperatorStatus = {
19
19
  enabled: boolean;
20
20
  account: string;
21
- buyerAddress: string;
21
+ signerAddress: string;
22
22
  operatorAddress?: string;
23
23
  currentOperator: string;
24
24
  operatorAccepted: boolean;
@@ -27,13 +27,13 @@ type BuyerOperatorStatus = {
27
27
  type OperatorConsentPayloadResponse = {
28
28
  enabled: boolean;
29
29
  account: string;
30
- buyerAddress: string;
30
+ signerAddress: string;
31
31
  typedData?: Eip712SigningPayload;
32
32
  };
33
33
 
34
34
  type AccountRef = {
35
35
  payer: string;
36
- buyer: string;
36
+ signer: string;
37
37
  };
38
38
  type UserCreditProfile = {
39
39
  account: string;
@@ -64,7 +64,13 @@ type GdCreditEntry = {
64
64
  logIndex?: number;
65
65
  createdAt: string;
66
66
  streamUpdateMonth: string;
67
- buyerAddress?: string;
67
+ /**
68
+ * Renamed from the wire's `buyerAddress` in `getCreditHistory`. Keep the
69
+ * mapping there: reading the wire name directly leaves this undefined, and an
70
+ * entry with no signer address matches no signer filter — it only ever shows
71
+ * under "All signers".
72
+ */
73
+ signerAddress?: string;
68
74
  };
69
75
  type AccountCreditResponse = {
70
76
  account: string;
@@ -88,10 +94,16 @@ type CreditHistoryQuery = {
88
94
  };
89
95
  type AccountView = {
90
96
  account: string;
91
- buyer: string | null;
97
+ signer: string | null;
92
98
  profile: UserCreditProfile;
93
- operator: BuyerOperatorStatus;
94
- withdrawableUsd: string;
99
+ /**
100
+ * Null when the operator read did not answer. Distinct from a read that came
101
+ * back saying "no operator": callers must not present an unread status as
102
+ * "not authorized", or an already-authorized account looks unconfigured.
103
+ */
104
+ operator: SignerOperatorStatus | null;
105
+ /** Null when the withdrawable read did not answer. */
106
+ withdrawableUsd: string | null;
95
107
  outstandingFundingUsd: string;
96
108
  outstandingFundingCount: number;
97
109
  };
@@ -115,7 +127,7 @@ type DiscountConfig = {
115
127
  streamBonusPercent: number;
116
128
  };
117
129
 
118
- declare const DEFAULT_BASE_RPC_URL = "https://mainnet.base.org";
130
+ declare const DEFAULT_BASE_RPC_URL = "https://base.drpc.org";
119
131
  declare const CELO_GOODID_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
120
132
  declare const DEFAULT_CELO_RPC_URL = "https://forno.celo.org";
121
133
  type AiCreditsChainClientOptions = {
@@ -128,22 +140,24 @@ type AiCreditsChainClientOptions = {
128
140
  };
129
141
  interface AiCreditsChainClient {
130
142
  fetchGdUsdPerToken(): Promise<number>;
143
+ /** Resolves the GoodID whitelist state, or rejects when the read fails. */
131
144
  isGoodIdVerified(account: string): Promise<boolean>;
132
145
  buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
133
- getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus>;
134
- buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: BuyerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
135
- getWithdrawableUsd(buyer: string): Promise<string>;
146
+ getSignerOperatorStatus(ref: AccountRef): Promise<SignerOperatorStatus>;
147
+ buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: SignerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
148
+ getWithdrawableUsd(signer: string): Promise<string>;
149
+ getSignerAuthNonce(signer: string): Promise<bigint>;
136
150
  }
137
151
  declare function createChainClient(options?: AiCreditsChainClientOptions): AiCreditsChainClient;
138
152
 
139
153
  type WithdrawPrincipalRequest = {
140
154
  amount: string;
141
155
  recipient: string;
142
- timestamp: number;
156
+ nonce: string;
143
157
  signature: string;
144
158
  };
145
159
  type ChannelOperationRequest = {
146
- timestamp?: number;
160
+ nonce?: string;
147
161
  signature?: string;
148
162
  };
149
163
  type BridgeResponse = {
@@ -165,23 +179,34 @@ type OperatorConsentRequest = {
165
179
  signature: string;
166
180
  };
167
181
  type OperatorConsentResponse = {
168
- buyer: string;
182
+ signer: string;
169
183
  bridge: BridgeResponse;
170
184
  };
185
+ type OperatorRevokeRequest = {
186
+ nonce: string;
187
+ signature: string;
188
+ };
189
+ type OperatorRevokeResponse = OperatorConsentResponse;
171
190
  declare function totalCreditUsdFromProfile(profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>): string;
172
191
  declare function totalCreditUsdFromStatus(status: {
173
192
  profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>;
174
193
  }): string;
175
194
  type AccountEnrichment = {
176
195
  totalCreditUsd: string;
177
- goodIdVerified: boolean;
178
196
  totalGdDepositedG: string;
179
197
  monthlyStreamG: string;
180
198
  };
181
199
  type BuildAccountViewOptions = {
182
- buyerAddress?: string | null;
200
+ signerAddress?: string | null;
183
201
  };
184
- declare function enrichAccountView(view: AccountView, chain: AiCreditsChainClient): Promise<AccountEnrichment>;
202
+ /**
203
+ * Derives the display fields that need no further network access.
204
+ *
205
+ * GoodID verification is deliberately not read here. Chaining it to the backend
206
+ * credit fetch meant any backend error also cleared the verified flag, and it
207
+ * re-ran on every refresh; the adapter resolves it once per account instead.
208
+ */
209
+ declare function enrichAccountView(view: AccountView): AccountEnrichment;
185
210
  interface AiCreditsBackendClient {
186
211
  getDiscountConfig(): Promise<DiscountConfig>;
187
212
  getAccountCredit(payer: string): Promise<AccountCreditResponse>;
@@ -201,8 +226,9 @@ interface AiCreditsBackendClient {
201
226
  previousBalance?: string;
202
227
  }): Promise<SettlementResult>;
203
228
  closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
204
- withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
205
- submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
229
+ withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
230
+ submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
231
+ revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
206
232
  }
207
233
  declare const DEFAULT_DISCOUNT_CONFIG: DiscountConfig;
208
234
  declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient {
@@ -228,8 +254,9 @@ declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient
228
254
  previousBalance?: string;
229
255
  }): Promise<SettlementResult>;
230
256
  closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
231
- withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
232
- submitOperatorConsent(buyer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
257
+ withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
258
+ submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
259
+ revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
233
260
  }
234
261
  declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClient {
235
262
  private unavailable;
@@ -243,17 +270,19 @@ declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClien
243
270
  closeChannel(): Promise<never>;
244
271
  withdrawCredits(): Promise<never>;
245
272
  submitOperatorConsent(): Promise<never>;
273
+ revokeOperatorConsent(): Promise<never>;
246
274
  }
247
275
  declare function createBackendClient(backendUrl: string | undefined): AiCreditsBackendClient;
248
276
  declare function buildAccountView(payer: string, backend: AiCreditsBackendClient, chain: AiCreditsChainClient, options?: BuildAccountViewOptions): Promise<AccountView>;
249
277
 
250
278
  type AiCreditsWidgetEnvironment = 'production' | 'staging' | 'development';
251
279
  type AiCreditsWidgetStatus = 'disconnected' | 'connecting' | 'purchase_setup' | 'quote_ready' | 'payment_pending' | 'payment_confirmed' | 'insufficient_g_balance' | 'payment_failed' | 'backend_unavailable' | 'unsupported_chain';
252
- type AiCreditsWidgetTab = 'buy' | 'manage' | 'history';
280
+ type AiCreditsWidgetTab = 'buy' | 'setup' | 'manage' | 'history';
253
281
  interface AiCreditsQuote {
254
282
  depositAmountG: string;
255
283
  streamAmountG: string;
256
284
  }
285
+
257
286
  interface AiCreditsWidgetAdapterState {
258
287
  status: AiCreditsWidgetStatus;
259
288
  address: string | null;
@@ -262,12 +291,22 @@ interface AiCreditsWidgetAdapterState {
262
291
  gdUsdPerToken: number | null;
263
292
  totalCreditUsd: string | null;
264
293
  isGoodIdVerified: boolean;
265
- buyerPubKey: string | null;
266
- buyerPrvKey: string | null;
294
+ /** Active signer public address. */
295
+ signerPubKey: string | null;
296
+ /** Active signer private key from the local per-payer key map. */
297
+ signerPrvKey: string | null;
298
+ /** Active signer deep-link operator signature, if present. */
299
+ operatorSignature: string | null;
267
300
  operatorConsented: boolean;
301
+ /** True while submitting / waiting for on-chain operator consent. */
302
+ operatorConsentPending: boolean;
268
303
  operatorAddress: string | null;
304
+ /** Operator currently configured for the active signer, if any. */
305
+ currentOperator: string | null;
269
306
  minDepositUsd: string | null;
270
307
  minStreamUsd: string | null;
308
+ /** Bonus credit earned so far, in micro-USD. Folded into `totalCreditUsd`. */
309
+ totalBonusUsd: string | null;
271
310
  totalGdDepositedG: string | null;
272
311
  monthlyStreamG: string | null;
273
312
  withdrawableUsd: string | null;
@@ -275,12 +314,40 @@ interface AiCreditsWidgetAdapterState {
275
314
  streamBonusPercent: number;
276
315
  error: string | null;
277
316
  activeTab: AiCreditsWidgetTab;
317
+ signers: string[];
318
+ /** Deterministic signer derived from the payer wallet Sign & Generate path. */
319
+ derivedSignerAddress: string | null;
278
320
  }
279
321
  interface AiCreditsWidgetAdapterActions {
280
322
  connect: () => Promise<void>;
281
323
  switchChain: () => Promise<void>;
282
- generateBuyerKey: () => Promise<void>;
324
+ /**
325
+ * Creates or restores the single deterministic signer for this payer wallet.
326
+ * If a derived key already exists locally, selects that signer without re-signing.
327
+ */
328
+ generateSignerKey: () => Promise<void>;
329
+ /**
330
+ * Switches the active signer and reloads that signer's account view.
331
+ * Address should be in `state.signers`.
332
+ */
333
+ selectSigner: (address: string) => Promise<void>;
334
+ discoverSigners: (addresses: string[]) => void;
335
+ /**
336
+ * Imports a signer key, stores it and selects it as the active signer.
337
+ * Resolves with the imported Signer Address, or `null` when the key could
338
+ * not be imported — callers use that to report the outcome of *this* import
339
+ * rather than the state of whichever signer happened to be active.
340
+ */
341
+ importSignerFromPrivateKey: (privateKey: string) => Promise<string | null>;
342
+ /**
343
+ * Applies an NCDI deep-link signer assignment from URL GET parameters
344
+ * (`signerAddress` + `operatorSignature`). Selects the signer immediately,
345
+ * submits the pre-signed operator approval token, and starts the buy flow.
346
+ * Never accepts a signer private key.
347
+ */
348
+ applyDeepLinkSigner: (address: string, operatorSignature: string) => Promise<void>;
283
349
  signOperatorConsent: () => Promise<void>;
350
+ revokeOperatorConsent: () => Promise<void>;
284
351
  syncOperatorConsentFromChain: () => Promise<void>;
285
352
  buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
286
353
  pay: (quote: AiCreditsQuote) => Promise<void>;
@@ -311,7 +378,7 @@ interface AiCreditsPaySuccessDetail {
311
378
  address: string;
312
379
  chainId: number;
313
380
  transactionHash: string;
314
- buyerPubKey: string;
381
+ signerPubKey: string;
315
382
  creditUsdMicro: string;
316
383
  }
317
384
  interface AiCreditsPayErrorDetail {
@@ -322,6 +389,52 @@ interface AiCreditsPayErrorDetail {
322
389
  interface AiCreditsWidgetProps {
323
390
  provider?: unknown;
324
391
  connectOverride?: () => Promise<void>;
392
+ /**
393
+ * Shows the connected-wallet chip (address, and disconnect when the host supplies
394
+ * `disconnectOverride`) in the widget header.
395
+ *
396
+ * Off by default: wallet hosts own the connection and must not offer a second,
397
+ * widget-local way to end it. Standalone deployments and Storybook opt in.
398
+ */
399
+ showWalletControls?: boolean;
400
+ /**
401
+ * Integrator-owned wallet disconnect flow. Without it the chip renders the address
402
+ * only, and its menu explains that the session belongs to the host.
403
+ */
404
+ disconnectOverride?: () => Promise<void>;
405
+ /**
406
+ * Label for the chip's menu action. Defaults to "Disconnect", which only fits when
407
+ * `disconnectOverride` really ends the session — integrators who instead open an
408
+ * account modal should relabel it.
409
+ */
410
+ disconnectLabel?: string;
411
+ /** Icon for the chip's menu action, mirroring `disconnectLabel`. */
412
+ disconnectIcon?: IconName;
413
+ /**
414
+ * Integrator-owned live address (e.g. from a wallet-connection SDK's own
415
+ * reactive account hook). See `GoodWidgetProviderProps.addressOverride`.
416
+ */
417
+ addressOverride?: string | null;
418
+ /**
419
+ * Integrator-owned live chain id, mirroring `addressOverride`. See
420
+ * `GoodWidgetProviderProps.chainIdOverride`. Worth supplying for connectors
421
+ * that do not reliably emit `chainChanged` — a WalletConnect session bridged
422
+ * through AppKit, for one — otherwise the widget can keep reporting the wrong
423
+ * network after the user has already switched.
424
+ */
425
+ chainIdOverride?: number | null;
426
+ /**
427
+ * Integrator-owned chain-switch fallback, used when the wallet rejects or
428
+ * ignores `wallet_switchEthereumChain`. See
429
+ * `GoodWidgetProviderProps.switchChainOverride`. Without it, wallets that
430
+ * cannot be switched from a page leave the user stuck on the wrong network.
431
+ */
432
+ switchChainOverride?: (chainId: number) => Promise<void>;
433
+ /**
434
+ * Chain ids the passed-down provider can currently execute on. See
435
+ * `GoodWidgetProviderProps.availableChainIdsOverride`.
436
+ */
437
+ availableChainIdsOverride?: number[] | null;
325
438
  environment?: AiCreditsWidgetEnvironment;
326
439
  backendUrl?: string;
327
440
  baseRpcUrl?: string;
@@ -339,4 +452,4 @@ interface AiCreditsWidgetProps {
339
452
  testId?: string;
340
453
  }
341
454
 
342
- export { type AiCreditsWidgetEnvironment as A, type BuyerOperatorStatus as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryQuery as F, type GdCreditEntry as G, type CreditHistoryResponse as H, type CeloEventsRecordResponse as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorConsentPayloadResponse as L, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SettlementResult as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
455
+ export { type AiCreditsWidgetEnvironment as A, type CreditHistoryQuery as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryResponse as F, type GdCreditEntry as G, type CeloEventsRecordResponse as H, type SettlementResult as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorRevokeResponse as L, type OperatorConsentPayloadResponse as M, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SignerOperatorStatus as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@goodwidget/ai-credits-widget",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "GoodWidget for buying AI coding credits with G$ on Celo",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/GoodDollar/GoodWidget.git",
8
+ "directory": "packages/ai-credits-widget"
9
+ },
5
10
  "files": [
6
11
  "dist",
7
12
  "README.md"