Skip to content

Commit edac950

Browse files
committed
Minor improvements:
- use string concatenation to produce storage key in profile sync - introduce ZERO_ADDRESS constant that is shared between consumers in gator snap
1 parent 7bd452f commit edac950

5 files changed

Lines changed: 9 additions & 16 deletions

File tree

packages/gator-permissions-snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snap-7715-permissions.git"
88
},
99
"source": {
10-
"shasum": "KIkyDs5vhOacg5T4j5WoWvVF0m9UTxQIez+pNhEYnWQ=",
10+
"shasum": "W8+w9wW8zF3UrtMX6lJNQt02TGxIoqh/4d5X4gX2B4s=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/gator-permissions-snap/src/clients/accountApiClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { logger } from '@metamask/7715-permissions-shared/utils';
22
import { type Hex } from '@metamask/delegation-core';
3+
import { ZERO_ADDRESS } from '../constants';
34

45
import type { TokenBalanceAndMetadata } from './types';
56

@@ -35,8 +36,7 @@ type TokenBalanceResponse = {
3536
export class AccountApiClient {
3637
static readonly #supportedTokenTypes = ['native', 'erc20'];
3738

38-
static readonly #nativeTokenAddress =
39-
'0x0000000000000000000000000000000000000000';
39+
static readonly #nativeTokenAddress = ZERO_ADDRESS;
4040

4141
readonly #fetch: typeof globalThis.fetch;
4242

packages/gator-permissions-snap/src/clients/blockchainMetadataClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { logger } from '@metamask/7715-permissions-shared/utils';
22
import { decodeSingle } from '@metamask/abi-utils';
33
import type { Hex } from '@metamask/delegation-core';
44
import type { SnapsEthereumProvider } from '@metamask/snaps-sdk';
5+
import { ZERO_ADDRESS } from '../constants';
56

67
import type { TokenBalanceAndMetadata, TokenMetadataClient } from './types';
78

@@ -11,8 +12,7 @@ import type { TokenBalanceAndMetadata, TokenMetadataClient } from './types';
1112
export class BlockchainTokenMetadataClient implements TokenMetadataClient {
1213
readonly #ethereumProvider: SnapsEthereumProvider;
1314

14-
static readonly #nativeTokenAddress =
15-
'0x0000000000000000000000000000000000000000';
15+
static readonly #nativeTokenAddress = ZERO_ADDRESS;
1616

1717
static readonly #nativeTokenDecimals = 18;
1818

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const ZERO_ADDRESS =
2+
'0x0000000000000000000000000000000000000000' as const;

packages/gator-permissions-snap/src/profileSync/profileSync.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
JwtBearerAuth,
1313
UserStorage,
1414
} from '@metamask/profile-sync-controller/sdk';
15-
import { bytesToHex } from '@metamask/utils';
1615

1716
export type ProfileSyncManager = {
1817
getAllGrantedPermissions: () => Promise<StoredGrantedPermission[]>;
@@ -80,18 +79,10 @@ export function createProfileSyncManager(
8079
function generateObjectKey(permissionContext: Hex): Hex {
8180
const delegations = decodeDelegations(permissionContext);
8281
const hashes = delegations.map((delegation) =>
83-
hashDelegation(delegation, { out: 'bytes' }),
82+
hashDelegation(delegation).slice(2),
8483
);
8584

86-
const keyBytes = new Uint8Array(hashes.length * 32);
87-
for (let i = 0; i < hashes.length; i++) {
88-
const hash = hashes[i];
89-
if (hash) {
90-
keyBytes.set(hash, i * 32);
91-
}
92-
}
93-
94-
return bytesToHex(keyBytes);
85+
return `0x${hashes.join('')}`;
9586
}
9687

9788
/**

0 commit comments

Comments
 (0)