Skip to content

Commit 025576f

Browse files
committed
fix: hide secure client credentials from accidental logs
1 parent 9e8babe commit 025576f

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

packages/client/src/clients.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,36 @@ type SecureContext = Context & {
4848
};
4949

5050
abstract class AbstractClient<TContext extends Context> {
51-
protected readonly context: TContext;
51+
// Keep the backing context off the public object shape so accidental
52+
// client logs do not print secure credentials.
53+
readonly #context: TContext;
5254

5355
constructor(context: TContext) {
54-
this.context = context;
56+
this.#context = context;
57+
}
58+
59+
protected getContext(): TContext {
60+
return this.#context;
5561
}
5662

5763
/** @internal */
5864
get environment(): EnvironmentConfig {
59-
return this.context.environment;
65+
return this.#context.environment;
6066
}
6167

6268
/** @internal */
6369
get clob(): ServiceClient {
64-
return this.context.clob;
70+
return this.#context.clob;
6571
}
6672

6773
/** @internal */
6874
get gamma(): ServiceClient {
69-
return this.context.gamma;
75+
return this.#context.gamma;
7076
}
7177

7278
/** @internal */
7379
get data(): ServiceClient {
74-
return this.context.data;
80+
return this.#context.data;
7581
}
7682
}
7783

@@ -154,7 +160,10 @@ class PublicClient extends AbstractClient<Context> {
154160
signatureType: SignatureType,
155161
): SecureClient {
156162
return new SecureClient({
157-
...this.context,
163+
environment: this.environment,
164+
clob: this.clob,
165+
gamma: this.gamma,
166+
data: this.data,
158167
address,
159168
credentials,
160169
signatureType,
@@ -165,17 +174,17 @@ class PublicClient extends AbstractClient<Context> {
165174
class SecureClient extends AbstractClient<SecureContext> {
166175
/** @internal */
167176
get credentials(): ApiKeyCreds {
168-
return this.context.credentials;
177+
return this.getContext().credentials;
169178
}
170179

171180
/** @internal */
172181
get address(): EvmAddress {
173-
return this.context.address;
182+
return this.getContext().address;
174183
}
175184

176185
/** @internal */
177186
get signatureType(): SignatureType {
178-
return this.context.signatureType;
187+
return this.getContext().signatureType;
179188
}
180189
}
181190

0 commit comments

Comments
 (0)