Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
feat: use .toNormalizedCaipChainId to compute CAIP chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
ccharly committed Mar 15, 2024
1 parent 88745b4 commit 5af018d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/SnapKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { EventEmitter } from 'events';
import { assert, mask, object, string } from 'superstruct';
import { v4 as uuid } from 'uuid';

import { toCaipChainId, CaipNamespaces } from './caip';
import { toNormalizedCaipChainId, CaipNamespaces } from './caip';
import { DeferredPromise } from './DeferredPromise';
import { KeyringSnapControllerClient } from './KeyringSnapControllerClient';
import { projectLogger as log } from './logger';
Expand Down Expand Up @@ -610,7 +610,7 @@ export class SnapKeyring extends EventEmitter {
address,
method: EthMethod.SignTransaction,
params: [tx],
chainId: toCaipChainId(CaipNamespaces.Eip155, `${chainId}`),
chainId: toNormalizedCaipChainId(CaipNamespaces.Eip155, `${chainId}`),
});

// ! It's *** CRITICAL *** that we mask the signature here, otherwise the
Expand Down Expand Up @@ -666,7 +666,12 @@ export class SnapKeyring extends EventEmitter {
params: toJson<Json[]>([address, data]),
...(chainId === undefined
? {}
: { chainId: toCaipChainId(CaipNamespaces.Eip155, `${chainId}`) }),
: {
chainId: toNormalizedCaipChainId(
CaipNamespaces.Eip155,
`${chainId}`,
),
}),
}),
EthBytesStruct,
);
Expand Down Expand Up @@ -730,12 +735,9 @@ export class SnapKeyring extends EventEmitter {
method: EthMethod.PrepareUserOperation,
params: toJson<Json[]>(transactions),
expectSync: true,
// Assuming the chain ID is a number for now, later on the CAIP-2 chain ID
// would have to come from the caller directly, but for now this is good
// enough for our use case.
chainId: toCaipChainId(
chainId: toNormalizedCaipChainId(
CaipNamespaces.Eip155,
`${Number(context.chainId)}`,
context.chainId,
),
}),
EthBaseUserOperationStruct,
Expand All @@ -762,9 +764,9 @@ export class SnapKeyring extends EventEmitter {
method: EthMethod.PatchUserOperation,
params: toJson<Json[]>([userOp]),
expectSync: true,
chainId: toCaipChainId(
chainId: toNormalizedCaipChainId(
CaipNamespaces.Eip155,
`${Number(context.chainId)}`, // See `.prepareUserOperation` comment.
context.chainId,
),
}),
EthUserOperationPatchStruct,
Expand All @@ -789,9 +791,9 @@ export class SnapKeyring extends EventEmitter {
address,
method: EthMethod.SignUserOperation,
params: toJson<Json[]>([userOp]),
chainId: toCaipChainId(
chainId: toNormalizedCaipChainId(
CaipNamespaces.Eip155,
`${Number(context.chainId)}`, // See `.prepareUserOperation` comment.
context.chainId,
),
}),
EthBytesStruct,
Expand Down

0 comments on commit 5af018d

Please sign in to comment.