Skip to content

Commit

Permalink
feat: ensure backward compatibility with remoteEntry.js of snap v2.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
khanti42 committed Sep 17, 2024
1 parent ac41722 commit 9c352cb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/starknet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import type {
ApiParams,
ApiParamsWithKeyDeriver,
ApiRequestParams,
SendTransactionRequestParams,
SignTransactionRequestParams,
} from './types/snapApi';
import type { SnapState } from './types/snapState';
import { upgradeAccContract } from './upgradeAccContract';
Expand Down Expand Up @@ -153,6 +155,26 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
saveMutex,
};

// Ensuring backward compatibility with version 2.9.0 of the federated module.
// In version 2.9.0, the `starknet_sign*` methods used the `signerAddress` parameter.
// The current version expects `address`. This block checks if the old `signerAddress` is present
// and maps it to `address` to maintain compatibility with existing integrations.
const { signerAddress } =
apiParams.requestParams as SignTransactionRequestParams;
if (signerAddress) {
(apiParams.requestParams as any).address = signerAddress;
delete (apiParams.requestParams as any).signerAddress;
}

// In version 2.9.0, the `starknet_execute` and `starknet_declare` methods used the `senderAddress` parameter.
// Similarly, this block checks if `senderAddress` is present and maps it to `address` for backward compatibility.
const { senderAddress } =
apiParams.requestParams as SendTransactionRequestParams;
if (senderAddress) {
(apiParams.requestParams as any).address = senderAddress;
delete (apiParams.requestParams as any).senderAddress;
}

switch (request.method) {
case 'starkNet_createAccount':
apiParams.keyDeriver = await getAddressKeyDeriver(snap);
Expand Down

0 comments on commit 9c352cb

Please sign in to comment.