Skip to content

Commit

Permalink
fix typos (coinbase#1507)
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-jake authored Feb 5, 2025
1 parent 29331f8 commit d22b865
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions packages/wallet-sdk/src/sign/scw/SCWSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ensureIntNumber, hexStringFromNumber } from ':core/type/util.js';
import { createClients, SDKChain } from ':stores/chain-clients/utils.js';
import { subaccounts } from ':stores/sub-accounts/store.js';
import { assertSubAccountInfo } from ':stores/sub-accounts/utils.js';
import { assetArrayPresence, assetPresence } from ':util/assertPresence.js';
import { assertArrayPresence, assertPresence } from ':util/assertPresence.js';
import {
decryptContent,
encryptContent,
Expand Down Expand Up @@ -309,14 +309,14 @@ export class SCWSigner implements Signer {

await this.communicator.waitForPopupLoaded?.();
let signer = get(request, 'params[0].signer') as string;
assetPresence(state.getSigner, standardErrors.rpc.invalidParams('signer is required'));
assertPresence(state.getSigner, standardErrors.rpc.invalidParams('signer is required'));

const account = await state.getSigner();
if (!signer && account) {
signer = account.publicKey;
}

assetArrayPresence(request.params);
assertArrayPresence(request.params);
request.params[0] = { ...request.params[0], signer };

const response = await this.sendRequestToPopup(request);
Expand All @@ -343,7 +343,7 @@ export class SCWSigner implements Signer {

private async sendRequestToSubAccountSigner(request: RequestArguments) {
const state = subaccounts.getState();
assetPresence(state.account, standardErrors.provider.unauthorized('no active sub account'));
assertPresence(state.account, standardErrors.provider.unauthorized('no active sub account'));

const sender = getSenderFromRequest(request);
// if sender is undefined, we inject the active sub account
Expand Down
20 changes: 10 additions & 10 deletions packages/wallet-sdk/src/sign/scw/utils/createSubAccountSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { standardErrors } from ':core/error/errors.js';
import { RequestArguments } from ':core/provider/interface.js';
import { getBundlerClient, getClient } from ':stores/chain-clients/utils.js';
import { SubAccountInfo, subaccounts } from ':stores/sub-accounts/store.js';
import { assetArrayPresence, assetPresence } from ':util/assertPresence.js';
import { assertArrayPresence, assertPresence } from ':util/assertPresence.js';
import { get } from ':util/get.js';

export async function createSubAccountSigner(subaccount: SubAccountInfo) {
const { getSigner } = subaccounts.getState();
assetPresence(getSigner, standardErrors.rpc.invalidParams('getSigner not found'));
assertPresence(getSigner, standardErrors.rpc.invalidParams('getSigner not found'));

const signer = await getSigner();
assetPresence(signer, standardErrors.rpc.invalidParams('signer not found'));
assertPresence(signer, standardErrors.rpc.invalidParams('signer not found'));

// TODO[jake] how do we handle unsupported chains
const client = getClient(subaccount.chainId ?? baseSepolia.id);
assetPresence(client, standardErrors.rpc.invalidParams('client not found'));
assertPresence(client, standardErrors.rpc.invalidParams('client not found'));

const account = await toCoinbaseSmartAccount({
address: subaccount.address,
Expand All @@ -31,11 +31,11 @@ export async function createSubAccountSigner(subaccount: SubAccountInfo) {
request: async (args: RequestArguments): Promise<Hex> => {
switch (args.method) {
case 'eth_sendTransaction': {
assetArrayPresence(args.params);
assertArrayPresence(args.params);
return account.sign(args.params[0] as { hash: Hex });
}
case 'wallet_sendCalls': {
assetArrayPresence(args.params);
assertArrayPresence(args.params);

// Get the paymaster URL from the requests capabilities
const paymasterURL = get(args.params[0], 'capabilities.paymasterService.url') as string;
Expand All @@ -47,10 +47,10 @@ export async function createSubAccountSigner(subaccount: SubAccountInfo) {
}
// Get the bundler client for the chain
const chainId = get(args.params[0], 'chainId') as number;
assetPresence(chainId, standardErrors.rpc.invalidParams('chainId is required'));
assertPresence(chainId, standardErrors.rpc.invalidParams('chainId is required'));

const bundlerClient = getBundlerClient(chainId);
assetPresence(
assertPresence(
bundlerClient,
standardErrors.rpc.invalidParams('bundler client not found')
);
Expand All @@ -66,13 +66,13 @@ export async function createSubAccountSigner(subaccount: SubAccountInfo) {
throw new Error('Not implemented');
}
case 'personal_sign': {
assetArrayPresence(args.params);
assertArrayPresence(args.params);
return account.signMessage({ message: args.params[0] } as {
message: SignableMessage;
});
}
case 'eth_signTypedData_v4': {
assetArrayPresence(args.params);
assertArrayPresence(args.params);
return account.signTypedData(args.params[1] as TypedDataDefinition);
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class WalletLinkCipher {

const authTagBytes = new Uint8Array(authTag);
const encryptedPlaintextBytes = new Uint8Array(encryptedPlaintext);
const concatted = new Uint8Array([...ivBytes, ...authTagBytes, ...encryptedPlaintextBytes]);
return uint8ArrayToHex(concatted);
const concatenated = new Uint8Array([...ivBytes, ...authTagBytes, ...encryptedPlaintextBytes]);
return uint8ArrayToHex(concatenated);
}

/**
Expand All @@ -70,13 +70,13 @@ export class WalletLinkCipher {
const ivBytes = encrypted.slice(0, 12);
const authTagBytes = encrypted.slice(12, 28);
const encryptedPlaintextBytes = encrypted.slice(28);
const concattedBytes = new Uint8Array([...encryptedPlaintextBytes, ...authTagBytes]);
const concatenatedBytes = new Uint8Array([...encryptedPlaintextBytes, ...authTagBytes]);
const algo = {
name: 'AES-GCM',
iv: new Uint8Array(ivBytes),
};
try {
const decrypted = await window.crypto.subtle.decrypt(algo, secretKey, concattedBytes);
const decrypted = await window.crypto.subtle.decrypt(algo, secretKey, concatenatedBytes);
const decoder = new TextDecoder();
resolve(decoder.decode(decrypted));
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('WalletLinkConnection', () => {
(connection as any).handleSessionMetadataUpdated(metadata);
}

it('should call listner.metadataUpdated when WalletUsername updated', async () => {
it('should call listener.metadataUpdated when WalletUsername updated', async () => {
const listener_metadataUpdatedSpy = vi.spyOn(listener, 'metadataUpdated');

const newUsername = 'new username';
Expand All @@ -79,7 +79,7 @@ describe('WalletLinkConnection', () => {
);
});

it('should call listner.metadataUpdated when AppVersion updated', async () => {
it('should call listener.metadataUpdated when AppVersion updated', async () => {
const listener_metadataUpdatedSpy = vi.spyOn(listener, 'metadataUpdated');

const newAppVersion = 'new app version';
Expand All @@ -92,15 +92,15 @@ describe('WalletLinkConnection', () => {
);
});

it('should call listner.resetAndReload when __destroyed: 1 is received', async () => {
it('should call listener.resetAndReload when __destroyed: 1 is received', async () => {
const listener_resetAndReloadSpy = vi.spyOn(listener, 'resetAndReload');

invoke_handleSessionMetadataUpdated({ __destroyed: '1' });

expect(listener_resetAndReloadSpy).toHaveBeenCalled();
});

it('should call listner.accountUpdated when Account updated', async () => {
it('should call listener.accountUpdated when Account updated', async () => {
const listener_accountUpdatedSpy = vi.spyOn(listener, 'accountUpdated');

const newAccount = 'new account';
Expand All @@ -111,7 +111,7 @@ describe('WalletLinkConnection', () => {
});

describe('chain updates', () => {
it('should NOT call listner.chainUpdated when only one changed', async () => {
it('should NOT call listener.chainUpdated when only one changed', async () => {
const listener_chainUpdatedSpy = vi.spyOn(listener, 'chainUpdated');

const chainIdUpdate = { ChainId: 'new chain id' };
Expand All @@ -125,7 +125,7 @@ describe('WalletLinkConnection', () => {
expect(listener_chainUpdatedSpy).not.toHaveBeenCalled();
});

it('should call listner.chainUpdated when both ChainId and JsonRpcUrl changed', async () => {
it('should call listener.chainUpdated when both ChainId and JsonRpcUrl changed', async () => {
const listener_chainUpdatedSpy = vi.spyOn(listener, 'chainUpdated');

const update = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WalletLinkHTTP {
},
})
)
).catch((error) => console.error('Unabled to mark event as failed:', error));
).catch((error) => console.error('Unable to mark events as seen:', error));
}

async fetchUnseenEvents(): Promise<ServerMessage<'Event'>[]> {
Expand Down
16 changes: 8 additions & 8 deletions packages/wallet-sdk/src/util/assertPresence.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { assetArrayPresence, assetPresence } from './assertPresence.js';
import { assertArrayPresence, assertPresence } from './assertPresence.js';

describe('assertPresence', () => {
it('should throw an error if the value is null', () => {
expect(() => assetPresence(null)).toThrow();
expect(() => assertPresence(null)).toThrow();
});

it('should throw an error if the value is undefined', () => {
expect(() => assetPresence(undefined)).toThrow();
expect(() => assertPresence(undefined)).toThrow();
});

it('should throw an error if the value is null and an error is provided', () => {
expect(() => assetPresence(null, new Error('test'))).toThrow();
expect(() => assertPresence(null, new Error('test'))).toThrow();
});

it('should throw an error if the value is undefined and an error is provided', () => {
expect(() => assetPresence(undefined, new Error('test'))).toThrow();
expect(() => assertPresence(undefined, new Error('test'))).toThrow();
});
});

describe('assetArrayPresence', () => {
describe('assertArrayPresence', () => {
it('should throw an error if the value is not an array', () => {
expect(() => assetArrayPresence(null)).toThrow();
expect(() => assertArrayPresence(null)).toThrow();
});

it('should throw an error if the value is not an array and an error is provided', () => {
expect(() => assetArrayPresence(null, 'test')).toThrow();
expect(() => assertArrayPresence(null, 'test')).toThrow();
});
});
4 changes: 2 additions & 2 deletions packages/wallet-sdk/src/util/assertPresence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { standardErrors } from ':core/error/errors.js';

export function assetPresence<T>(
export function assertPresence<T>(
value: T,
error?: Error,
message?: string
Expand All @@ -16,7 +16,7 @@ export function assetPresence<T>(
}
}

export function assetArrayPresence<T>(
export function assertArrayPresence<T>(
value: unknown,
message?: string
): asserts value is NonNullable<T>[] {
Expand Down

0 comments on commit d22b865

Please sign in to comment.