@goodwidget/ai-credits-widget 0.1.6 → 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.
@@ -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,6 +270,7 @@ 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>;
@@ -263,11 +291,11 @@ interface AiCreditsWidgetAdapterState {
263
291
  gdUsdPerToken: number | null;
264
292
  totalCreditUsd: string | null;
265
293
  isGoodIdVerified: boolean;
266
- /** Active buyer public address. */
267
- buyerPubKey: string | null;
268
- /** Active buyer private key from the local per-payer key map. */
269
- buyerPrvKey: string | null;
270
- /** Active buyer deep-link operator signature, if present. */
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. */
271
299
  operatorSignature: string | null;
272
300
  operatorConsented: boolean;
273
301
  /** True while submitting / waiting for on-chain operator consent. */
@@ -277,6 +305,8 @@ interface AiCreditsWidgetAdapterState {
277
305
  currentOperator: string | null;
278
306
  minDepositUsd: string | null;
279
307
  minStreamUsd: string | null;
308
+ /** Bonus credit earned so far, in micro-USD. Folded into `totalCreditUsd`. */
309
+ totalBonusUsd: string | null;
280
310
  totalGdDepositedG: string | null;
281
311
  monthlyStreamG: string | null;
282
312
  withdrawableUsd: string | null;
@@ -284,39 +314,40 @@ interface AiCreditsWidgetAdapterState {
284
314
  streamBonusPercent: number;
285
315
  error: string | null;
286
316
  activeTab: AiCreditsWidgetTab;
287
- buyers: string[];
288
- /** Deterministic buyer derived from the payer wallet Sign & Generate path. */
289
- derivedBuyerAddress: string | null;
317
+ signers: string[];
318
+ /** Deterministic signer derived from the payer wallet Sign & Generate path. */
319
+ derivedSignerAddress: string | null;
290
320
  }
291
321
  interface AiCreditsWidgetAdapterActions {
292
322
  connect: () => Promise<void>;
293
323
  switchChain: () => Promise<void>;
294
324
  /**
295
- * Creates or restores the single deterministic buyer for this payer wallet.
296
- * If a derived key already exists locally, selects that buyer without re-signing.
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.
297
327
  */
298
- generateBuyerKey: () => Promise<void>;
328
+ generateSignerKey: () => Promise<void>;
299
329
  /**
300
- * Switches the active buyer and reloads that buyer's account view.
301
- * Address should be in `state.buyers`.
330
+ * Switches the active signer and reloads that signer's account view.
331
+ * Address should be in `state.signers`.
302
332
  */
303
- selectBuyer: (address: string) => Promise<void>;
304
- discoverBuyers: (addresses: string[]) => void;
333
+ selectSigner: (address: string) => Promise<void>;
334
+ discoverSigners: (addresses: string[]) => void;
305
335
  /**
306
- * Imports a signer key, stores it and selects it as the active buyer.
307
- * Resolves with the imported buyer address, or `null` when the key could
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
308
338
  * not be imported — callers use that to report the outcome of *this* import
309
- * rather than the state of whichever buyer happened to be active.
339
+ * rather than the state of whichever signer happened to be active.
310
340
  */
311
- importBuyerFromPrivateKey: (privateKey: string) => Promise<string | null>;
341
+ importSignerFromPrivateKey: (privateKey: string) => Promise<string | null>;
312
342
  /**
313
- * Applies an NCDI deep-link buyer assignment from URL GET parameters
314
- * (`buyerAddress` + `operatorSignature`). Selects the buyer immediately,
343
+ * Applies an NCDI deep-link signer assignment from URL GET parameters
344
+ * (`signerAddress` + `operatorSignature`). Selects the signer immediately,
315
345
  * submits the pre-signed operator approval token, and starts the buy flow.
316
- * Never accepts a buyer private key.
346
+ * Never accepts a signer private key.
317
347
  */
318
- applyDeepLinkBuyer: (address: string, operatorSignature: string) => Promise<void>;
348
+ applyDeepLinkSigner: (address: string, operatorSignature: string) => Promise<void>;
319
349
  signOperatorConsent: () => Promise<void>;
350
+ revokeOperatorConsent: () => Promise<void>;
320
351
  syncOperatorConsentFromChain: () => Promise<void>;
321
352
  buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
322
353
  pay: (quote: AiCreditsQuote) => Promise<void>;
@@ -347,7 +378,7 @@ interface AiCreditsPaySuccessDetail {
347
378
  address: string;
348
379
  chainId: number;
349
380
  transactionHash: string;
350
- buyerPubKey: string;
381
+ signerPubKey: string;
351
382
  creditUsdMicro: string;
352
383
  }
353
384
  interface AiCreditsPayErrorDetail {
@@ -379,6 +410,31 @@ interface AiCreditsWidgetProps {
379
410
  disconnectLabel?: string;
380
411
  /** Icon for the chip's menu action, mirroring `disconnectLabel`. */
381
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;
382
438
  environment?: AiCreditsWidgetEnvironment;
383
439
  backendUrl?: string;
384
440
  baseRpcUrl?: string;
@@ -396,4 +452,4 @@ interface AiCreditsWidgetProps {
396
452
  testId?: string;
397
453
  }
398
454
 
399
- 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 };
@@ -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,6 +270,7 @@ 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>;
@@ -263,11 +291,11 @@ interface AiCreditsWidgetAdapterState {
263
291
  gdUsdPerToken: number | null;
264
292
  totalCreditUsd: string | null;
265
293
  isGoodIdVerified: boolean;
266
- /** Active buyer public address. */
267
- buyerPubKey: string | null;
268
- /** Active buyer private key from the local per-payer key map. */
269
- buyerPrvKey: string | null;
270
- /** Active buyer deep-link operator signature, if present. */
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. */
271
299
  operatorSignature: string | null;
272
300
  operatorConsented: boolean;
273
301
  /** True while submitting / waiting for on-chain operator consent. */
@@ -277,6 +305,8 @@ interface AiCreditsWidgetAdapterState {
277
305
  currentOperator: string | null;
278
306
  minDepositUsd: string | null;
279
307
  minStreamUsd: string | null;
308
+ /** Bonus credit earned so far, in micro-USD. Folded into `totalCreditUsd`. */
309
+ totalBonusUsd: string | null;
280
310
  totalGdDepositedG: string | null;
281
311
  monthlyStreamG: string | null;
282
312
  withdrawableUsd: string | null;
@@ -284,39 +314,40 @@ interface AiCreditsWidgetAdapterState {
284
314
  streamBonusPercent: number;
285
315
  error: string | null;
286
316
  activeTab: AiCreditsWidgetTab;
287
- buyers: string[];
288
- /** Deterministic buyer derived from the payer wallet Sign & Generate path. */
289
- derivedBuyerAddress: string | null;
317
+ signers: string[];
318
+ /** Deterministic signer derived from the payer wallet Sign & Generate path. */
319
+ derivedSignerAddress: string | null;
290
320
  }
291
321
  interface AiCreditsWidgetAdapterActions {
292
322
  connect: () => Promise<void>;
293
323
  switchChain: () => Promise<void>;
294
324
  /**
295
- * Creates or restores the single deterministic buyer for this payer wallet.
296
- * If a derived key already exists locally, selects that buyer without re-signing.
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.
297
327
  */
298
- generateBuyerKey: () => Promise<void>;
328
+ generateSignerKey: () => Promise<void>;
299
329
  /**
300
- * Switches the active buyer and reloads that buyer's account view.
301
- * Address should be in `state.buyers`.
330
+ * Switches the active signer and reloads that signer's account view.
331
+ * Address should be in `state.signers`.
302
332
  */
303
- selectBuyer: (address: string) => Promise<void>;
304
- discoverBuyers: (addresses: string[]) => void;
333
+ selectSigner: (address: string) => Promise<void>;
334
+ discoverSigners: (addresses: string[]) => void;
305
335
  /**
306
- * Imports a signer key, stores it and selects it as the active buyer.
307
- * Resolves with the imported buyer address, or `null` when the key could
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
308
338
  * not be imported — callers use that to report the outcome of *this* import
309
- * rather than the state of whichever buyer happened to be active.
339
+ * rather than the state of whichever signer happened to be active.
310
340
  */
311
- importBuyerFromPrivateKey: (privateKey: string) => Promise<string | null>;
341
+ importSignerFromPrivateKey: (privateKey: string) => Promise<string | null>;
312
342
  /**
313
- * Applies an NCDI deep-link buyer assignment from URL GET parameters
314
- * (`buyerAddress` + `operatorSignature`). Selects the buyer immediately,
343
+ * Applies an NCDI deep-link signer assignment from URL GET parameters
344
+ * (`signerAddress` + `operatorSignature`). Selects the signer immediately,
315
345
  * submits the pre-signed operator approval token, and starts the buy flow.
316
- * Never accepts a buyer private key.
346
+ * Never accepts a signer private key.
317
347
  */
318
- applyDeepLinkBuyer: (address: string, operatorSignature: string) => Promise<void>;
348
+ applyDeepLinkSigner: (address: string, operatorSignature: string) => Promise<void>;
319
349
  signOperatorConsent: () => Promise<void>;
350
+ revokeOperatorConsent: () => Promise<void>;
320
351
  syncOperatorConsentFromChain: () => Promise<void>;
321
352
  buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
322
353
  pay: (quote: AiCreditsQuote) => Promise<void>;
@@ -347,7 +378,7 @@ interface AiCreditsPaySuccessDetail {
347
378
  address: string;
348
379
  chainId: number;
349
380
  transactionHash: string;
350
- buyerPubKey: string;
381
+ signerPubKey: string;
351
382
  creditUsdMicro: string;
352
383
  }
353
384
  interface AiCreditsPayErrorDetail {
@@ -379,6 +410,31 @@ interface AiCreditsWidgetProps {
379
410
  disconnectLabel?: string;
380
411
  /** Icon for the chip's menu action, mirroring `disconnectLabel`. */
381
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;
382
438
  environment?: AiCreditsWidgetEnvironment;
383
439
  backendUrl?: string;
384
440
  baseRpcUrl?: string;
@@ -396,4 +452,4 @@ interface AiCreditsWidgetProps {
396
452
  testId?: string;
397
453
  }
398
454
 
399
- 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodwidget/ai-credits-widget",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "GoodWidget for buying AI coding credits with G$ on Celo",
5
5
  "repository": {
6
6
  "type": "git",