Skip to content

Commit 369812b

Browse files
patchy-the-botPatchy Botjeffsmale90
authored
Fix #145: Remove encodePermissionContexts and decodePermissionContexts functions from public interface (#148)
* Remove encodePermissionContexts and decodePermissionContexts wrappers * Remove remaining references to encodePermissionContexts * Fix linting errors * Fix e2e tests that relied on the removed functino --------- Co-authored-by: Patchy Bot <patchy@localhost> Co-authored-by: Jeff Smale <6363749+jeffsmale90@users.noreply.github.com>
1 parent ca9ef7f commit 369812b

5 files changed

Lines changed: 8 additions & 160 deletions

File tree

packages/delegator-e2e/test/delegateAndRedeem.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
type PartialSignature,
2323
} from '@metamask/smart-accounts-kit';
2424
import {
25-
encodePermissionContexts,
25+
encodeDelegations,
2626
encodeExecutionCalldatas,
2727
} from '@metamask/smart-accounts-kit/utils';
2828
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
@@ -123,7 +123,7 @@ test('maincase: Bob increments the counter with a delegation from Alice', async
123123
abi: bobSmartAccount.abi,
124124
functionName: 'redeemDelegations',
125125
args: [
126-
encodePermissionContexts([[signedDelegation]]),
126+
[encodeDelegations([signedDelegation])],
127127
[ExecutionMode.SingleDefault],
128128
encodeExecutionCalldatas([[execution]]),
129129
],
@@ -232,7 +232,7 @@ test("Bob attempts to increment the counter with a delegation from Alice that do
232232
abi: bobSmartAccount.abi,
233233
functionName: 'redeemDelegations',
234234
args: [
235-
encodePermissionContexts([[signedDelegation]]),
235+
[encodeDelegations([signedDelegation])],
236236
[ExecutionMode.SingleDefault],
237237
encodeExecutionCalldatas([[execution]]),
238238
],
@@ -335,7 +335,7 @@ test('Bob increments the counter with a delegation from a multisig account', asy
335335
abi: bobSmartAccount.abi,
336336
functionName: 'redeemDelegations',
337337
args: [
338-
encodePermissionContexts([[signedDelegation]]),
338+
[encodeDelegations([signedDelegation])],
339339
[ExecutionMode.SingleDefault],
340340
encodeExecutionCalldatas([[execution]]),
341341
],
@@ -366,4 +366,4 @@ test('Bob increments the counter with a delegation from a multisig account', asy
366366

367367
const countAfter = await counterContract.read.count();
368368
expect(countAfter, 'Expected final count to have incremented').toEqual(1n);
369-
});
369+
});

packages/smart-accounts-kit/src/DelegationFramework/DelegationManager/methods/redeemDelegations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Address, Client } from 'viem';
33
import { encodeFunctionData } from 'viem';
44
import { simulateContract, writeContract } from 'viem/actions';
55

6-
import { encodePermissionContexts } from '../../../delegation';
6+
import { encodeDelegations } from '../../../delegation';
77
import { encodeExecutionCalldatas } from '../../../executions';
88
import type { ExecutionMode, ExecutionStruct } from '../../../executions';
99
import type { Delegation } from '../../../types';
@@ -37,7 +37,7 @@ export const simulate = async ({
3737
abi: DelegationManager,
3838
functionName: 'redeemDelegations',
3939
args: [
40-
encodePermissionContexts(delegations),
40+
delegations.map((delegationChain) => encodeDelegations(delegationChain)),
4141
modes,
4242
encodeExecutionCalldatas(executions),
4343
],
@@ -71,7 +71,7 @@ export const encode = ({
7171
abi: DelegationManager,
7272
functionName: 'redeemDelegations',
7373
args: [
74-
encodePermissionContexts(delegations),
74+
delegations.map((delegationChain) => encodeDelegations(delegationChain)),
7575
modes,
7676
encodeExecutionCalldatas(executions),
7777
],

packages/smart-accounts-kit/src/delegation.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,6 @@ export const encodeDelegation = (delegation: Delegation): Hex => {
116116
return encodeDelegationCore(delegationStruct);
117117
};
118118

119-
/**
120-
* Abi encodes permission contexts.
121-
*
122-
* @param delegations - The delegation chains to encode.
123-
* @returns The encoded permission contexts.
124-
*/
125-
export const encodePermissionContexts = (delegations: Delegation[][]) => {
126-
const encodedDelegations = delegations.map((delegationChain) =>
127-
encodeDelegations(delegationChain),
128-
);
129-
130-
return encodedDelegations;
131-
};
132-
133119
/**
134120
* Decodes an array of delegations from its ABI-encoded representation.
135121
*
@@ -152,18 +138,6 @@ export const decodeDelegation = (encoded: Hex): Delegation => {
152138
return toDelegation(decodeDelegationCore(encoded));
153139
};
154140

155-
/**
156-
* Decodes an array of encoded permission contexts into an array of delegation chains.
157-
*
158-
* @param encoded - The hex-encoded permission context to decode.
159-
* @returns An array of decoded delegations.
160-
*/
161-
export const decodePermissionContexts = (encoded: Hex[]): Delegation[][] => {
162-
const delegationChains = encoded.map(decodeDelegations);
163-
164-
return delegationChains;
165-
};
166-
167141
/**
168142
* TypedData to be used when signing a Delegation. Delegation value for `signature` and Caveat values for `args` are omitted as they cannot be known at signing time.
169143
*/

packages/smart-accounts-kit/src/utils/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export {
55
decodeDelegation,
66
toDelegationStruct,
77
toDelegation,
8-
encodePermissionContexts,
9-
decodePermissionContexts,
108
DELEGATION_ARRAY_ABI_TYPE,
119
DELEGATION_ABI_TYPE,
1210
DELEGATION_ABI_TYPE_COMPONENTS,

packages/smart-accounts-kit/test/delegation.test.ts

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
decodeDelegations,
1515
encodeDelegation,
1616
decodeDelegation,
17-
encodePermissionContexts,
18-
decodePermissionContexts,
1917
signDelegation,
2018
} from '../src/delegation';
2119
import type {
@@ -711,128 +709,6 @@ describe('decodeDelegation', () => {
711709
});
712710
});
713711

714-
describe('encodePermissionContexts', () => {
715-
const mockDelegation1: Delegation = {
716-
delegate: mockDelegate,
717-
delegator: mockDelegator,
718-
authority: ROOT_AUTHORITY,
719-
caveats: [mockCaveat],
720-
salt: '0x123' as Hex,
721-
signature: mockSignature,
722-
};
723-
724-
const mockDelegation2: Delegation = {
725-
delegate: '0x2222222222222222222222222222222222222222',
726-
delegator: '0x3333333333333333333333333333333333333333',
727-
authority: ROOT_AUTHORITY,
728-
caveats: [
729-
{
730-
enforcer: '0x1111111111111111111111111111111111111111',
731-
terms: '0x',
732-
args: '0x00',
733-
},
734-
],
735-
salt: '0x456' as Hex,
736-
signature: mockSignature,
737-
};
738-
739-
it('should encode a single permission context', () => {
740-
const permissionContexts = [[mockDelegation1]];
741-
const encoded = encodePermissionContexts(permissionContexts);
742-
const decoded = decodePermissionContexts(encoded);
743-
744-
expect(decoded).to.have.length(1);
745-
expect(decoded).to.deep.equal([[mockDelegation1]]);
746-
});
747-
748-
it('should encode multiple permission contexts', () => {
749-
const permissionContexts = [[mockDelegation1], [mockDelegation2]];
750-
const encoded = encodePermissionContexts(permissionContexts);
751-
const decoded = decodePermissionContexts(encoded);
752-
753-
expect(decoded).to.have.length(2);
754-
expect(decoded).to.deep.equal([[mockDelegation1], [mockDelegation2]]);
755-
});
756-
757-
it('should handle permission contexts with multiple delegations', () => {
758-
const permissionContexts = [[mockDelegation1, mockDelegation2]];
759-
const encoded = encodePermissionContexts(permissionContexts);
760-
const decoded = decodePermissionContexts(encoded);
761-
762-
expect(decoded).to.have.length(1);
763-
expect(decoded).to.deep.equal([[mockDelegation1, mockDelegation2]]);
764-
});
765-
766-
it('should handle empty permission contexts', () => {
767-
const permissionContexts: Delegation[][] = [];
768-
const encoded = encodePermissionContexts(permissionContexts);
769-
const decoded = decodePermissionContexts(encoded);
770-
771-
expect(decoded).to.have.length(0);
772-
});
773-
});
774-
775-
describe('decodePermissionContexts', () => {
776-
const mockDelegation1: Delegation = {
777-
delegate: mockDelegate,
778-
delegator: mockDelegator,
779-
authority: ROOT_AUTHORITY,
780-
caveats: [mockCaveat],
781-
salt: '0x123' as Hex,
782-
signature: mockSignature,
783-
};
784-
785-
const mockDelegation2: Delegation = {
786-
delegate: '0x2222222222222222222222222222222222222222',
787-
delegator: '0x3333333333333333333333333333333333333333',
788-
authority: ROOT_AUTHORITY,
789-
caveats: [
790-
{
791-
enforcer: '0x1111111111111111111111111111111111111111',
792-
terms: '0x',
793-
args: '0x00',
794-
},
795-
],
796-
salt: '0x456' as Hex,
797-
signature: mockSignature,
798-
};
799-
800-
it('should decode a single permission context', () => {
801-
const permissionContexts = [[mockDelegation1]];
802-
const encoded = encodePermissionContexts(permissionContexts);
803-
const decoded = decodePermissionContexts(encoded);
804-
805-
expect(decoded).to.have.length(1);
806-
expect(decoded).to.deep.equal([[mockDelegation1]]);
807-
});
808-
809-
it('should decode multiple permission contexts', () => {
810-
const permissionContexts = [[mockDelegation1], [mockDelegation2]];
811-
const encoded = encodePermissionContexts(permissionContexts);
812-
const decoded = decodePermissionContexts(encoded);
813-
814-
expect(decoded).to.have.length(2);
815-
expect(decoded).to.deep.equal([[mockDelegation1], [mockDelegation2]]);
816-
});
817-
818-
it('should handle permission contexts with multiple delegations', () => {
819-
const permissionContexts = [[mockDelegation1, mockDelegation2]];
820-
const encoded = encodePermissionContexts(permissionContexts);
821-
const decoded = decodePermissionContexts(encoded);
822-
823-
expect(decoded).to.have.length(1);
824-
expect(decoded).to.deep.equal([[mockDelegation1, mockDelegation2]]);
825-
});
826-
827-
it('should handle empty permission contexts', () => {
828-
const permissionContexts: Delegation[][] = [];
829-
const encoded = encodePermissionContexts(permissionContexts);
830-
const decoded = decodePermissionContexts(encoded);
831-
832-
expect(decoded).to.have.length(0);
833-
});
834-
});
835-
836712
describe('signDelegation', () => {
837713
const mockPrivateKey: Hex =
838714
'0x1234567890123456789012345678901234567890123456789012345678901234';

0 commit comments

Comments
 (0)