Skip to content

Commit 5ce89d0

Browse files
authored
fix(typehash)!: rename DeleteDataSet typehash param (#757)
Renames EIP-712 DeleteDataSet field clientDataSetId to dataSetId, changing the typehash and the derived DeleteDataSetPermission value. Restores signDeleteDataSet typed-data helper. BREAKING CHANGE: existing session keys for DeleteDataSetPermission must be re-minted. Passing a stale session key to Synapse.create() throws because the permission hash no longer matches.
1 parent 4607b96 commit 5ce89d0

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

packages/synapse-core/src/typed-data/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
export * from './sign-add-pieces.ts'
1212
export * from './sign-create-dataset.ts'
1313
export * from './sign-create-dataset-add-pieces.ts'
14+
export * from './sign-delete-data-set.ts'
1415
export * from './sign-erc20-permit.ts'
1516
export * from './sign-schedule-piece-removals.ts'
1617
export * from './type-definitions.ts'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { type Account, type Chain, type Client, encodeAbiParameters, type Transport } from 'viem'
2+
import { signTypedData } from 'viem/actions'
3+
import { asChain } from '../chains.ts'
4+
import { EIP712Types, getStorageDomain } from './type-definitions.ts'
5+
6+
export type SignDeleteDataSetOptions = {
7+
dataSetId: bigint
8+
}
9+
10+
/**
11+
* Sign the delete data set message and abi encode the signature.
12+
*
13+
* @param client - The client to use to sign the message.
14+
* @param options - The options for the delete data set message.
15+
*/
16+
export async function signDeleteDataSet(client: Client<Transport, Chain, Account>, options: SignDeleteDataSetOptions) {
17+
const chain = asChain(client.chain)
18+
const signature = await signTypedData(client, {
19+
account: client.account,
20+
domain: getStorageDomain({ chain }),
21+
types: EIP712Types,
22+
primaryType: 'DeleteDataSet',
23+
message: {
24+
dataSetId: options.dataSetId,
25+
},
26+
})
27+
const extraData = encodeAbiParameters([{ type: 'bytes' }], [signature])
28+
return extraData
29+
}

packages/synapse-core/src/typed-data/type-definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const EIP712Types = {
2828
{ name: 'clientDataSetId', type: 'uint256' },
2929
{ name: 'pieceIds', type: 'uint256[]' },
3030
],
31-
DeleteDataSet: [{ name: 'clientDataSetId', type: 'uint256' }],
31+
DeleteDataSet: [{ name: 'dataSetId', type: 'uint256' }],
3232

3333
/**
3434
* ERC-2612: Permit Extension for EIP-20 Signed Approvals

packages/synapse-core/test/typed-data.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const FIXTURES = {
3333
clientDataSetId: 12345n,
3434
pieceIds: [1n, 3n, 5n],
3535
},
36+
deleteDataSet: {
37+
extraData:
38+
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004182d85f7517c3ebcf68b9ebe200a46627d451219a3a71a95ea7ffce1cd661cc6d553db47958d27c33ccf1105388e1b640cf575a966b0bd4814ed0ec428daa628a1b00000000000000000000000000000000000000000000000000000000000000' as Hex,
39+
dataSetId: 67890n,
40+
},
3641
},
3742
}
3843

@@ -127,6 +132,18 @@ describe('Typed Data', () => {
127132
)
128133
})
129134

135+
it('should sign delete data set', async () => {
136+
const extraDataActual = await TypedData.signDeleteDataSet(client, {
137+
dataSetId: FIXTURES.signatures.deleteDataSet.dataSetId,
138+
})
139+
140+
assert.strictEqual(
141+
extraDataActual,
142+
FIXTURES.signatures.deleteDataSet.extraData,
143+
'DeleteDataSet extraData should match Solidity reference'
144+
)
145+
})
146+
130147
it('should sign create data set and add pieces', async () => {
131148
const extraDataActual = await TypedData.signCreateDataSetAndAddPieces(client, {
132149
clientDataSetId: FIXTURES.signatures.createDataSet.clientDataSetId,

0 commit comments

Comments
 (0)