Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for starknet account to offchain actions #383

Merged
merged 36 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
931764e
feat: add setAlias to starknet eth sign
wa0x6e Jun 2, 2024
01525c0
Merge branch 'master' into feat-support-starknet-alias
wa0x6e Jun 5, 2024
ea49ce7
fix: use starknet-sig instead of ethereum-sig
wa0x6e Jun 5, 2024
ebb759c
fix: fix signature schema
wa0x6e Jun 5, 2024
9859d9c
fix: update type to include optional properties
wa0x6e Jun 5, 2024
b76f328
Merge branch 'master' into feat-support-starknet-alias
wa0x6e Jul 2, 2024
00fb949
fix: more robust starknet wallet detection
wa0x6e Jul 2, 2024
2bde73b
fix: enable back follow button for starknet wallet
wa0x6e Jul 2, 2024
b92f061
fix: fix typing
wa0x6e Jul 2, 2024
8b6c92d
feat: add support for starknet signature for offchain `send`
wa0x6e Jul 2, 2024
772bf73
fix: use string type to allow starknet address
wa0x6e Jul 4, 2024
df9d133
fix: enable space following/unfollowing for starknet wallets
wa0x6e Jul 4, 2024
abbb177
fix: enable user profile edition for starknet users
wa0x6e Jul 4, 2024
9938d89
fix: use formatted address in alias from
wa0x6e Jul 14, 2024
2300195
fix: always use padded starknet address
wa0x6e Jul 14, 2024
380dd76
Merge branch 'master' into feat-support-starknet-offchain
wa0x6e Jul 15, 2024
554c941
Merge branch 'master' into feat-support-starknet-offchain
wa0x6e Jul 17, 2024
8c9affd
fix: sign sn createAlias on the correct chainId
wa0x6e Jul 19, 2024
787b375
chore: fix tests
wa0x6e Jul 19, 2024
090a266
fix: avoid loading votes from incompatible networks
wa0x6e Jul 19, 2024
fc944ca
fix: add types and domain to starknet envelope
wa0x6e Jul 19, 2024
4aa3468
Update apps/ui/src/composables/useActions.ts
wa0x6e Jul 22, 2024
afb0d93
Merge branch 'master' into feat-support-starknet-offchain
wa0x6e Jul 23, 2024
4f3fa50
fix: revert unrelated change
wa0x6e Jul 24, 2024
e3b6e50
chore: removed unused import
wa0x6e Jul 24, 2024
222ca08
chore: add comments about confusing extra starknet params on evm enve…
wa0x6e Jul 24, 2024
2db20c3
chore: fix import order
wa0x6e Jul 24, 2024
2c5c658
fix: sign alias with first available starknet network
wa0x6e Jul 24, 2024
5468efd
Merge branch 'master' into feat-support-starknet-offchain
wa0x6e Jul 24, 2024
a8a49ec
chore: lint fix
wa0x6e Jul 24, 2024
f9f3e91
chore: add changesets
wa0x6e Jul 24, 2024
f5368c6
Merge branch 'master' into feat-support-starknet-offchain
wa0x6e Jul 24, 2024
f928679
revert: revert back ot use correct starknet chaind ID
wa0x6e Jul 27, 2024
313f2cd
fix: finish revert
wa0x6e Jul 27, 2024
01faa14
fix: fix leftover from merge
wa0x6e Jul 27, 2024
f47e9dc
refactor: simplify starknetNetworkId lookup
Sekhmet Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/ui/src/composables/useActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import type {
VoteType
} from '@/types';
import type { Connector, StrategyConfig } from '@/networks/types';
import { starknetNetworks } from '@snapshot-labs/sx';

const offchainNetworkId = offchainNetworks.filter(network => enabledNetworks.includes(network))[0];
const starknetNetworkId = (Object.keys(starknetNetworks) as NetworkID[])
.filter(network => enabledNetworks.includes(network))
.pop() as NetworkID;
Sekhmet marked this conversation as resolved.
Show resolved Hide resolved

export function useActions() {
const { mixpanel } = useMixpanel();
Expand Down Expand Up @@ -107,7 +111,9 @@ export function useActions() {
}

async function getAliasSigner() {
const network = getNetwork(offchainNetworkId);
const network = getNetwork(
web3.value.type === 'argentx' ? starknetNetworkId : offchainNetworkId
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
);

return alias.getAliasWallet(address =>
wrapPromise(offchainNetworkId, network.actions.setAlias(auth.web3, address))
Expand Down
7 changes: 6 additions & 1 deletion apps/ui/src/networks/starknet/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,12 @@ export function createActions(
},
followSpace: () => {},
unfollowSpace: () => {},
setAlias: () => {},
setAlias(web3: any, alias: string) {
return starkSigClient.setAlias({
signer: web3.provider.account,
data: { alias }
});
},
send: (envelope: any) => starkSigClient.send(envelope) // TODO: extract it out of client to common helper
};
}
27 changes: 25 additions & 2 deletions packages/sx.js/src/clients/starknet/starknet-sig/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import randomBytes from 'randombytes';
import { Account, CallData, shortString, typedData, uint256 } from 'starknet';
import { getStrategiesWithParams } from '../../../utils/strategies';
import { baseDomain, proposeTypes, updateProposalTypes, voteTypes } from './types';
import { aliasTypes, baseDomain, proposeTypes, updateProposalTypes, voteTypes } from './types';
import {
ClientConfig,
ClientOpts,
Envelope,
Propose,
UpdateProposal,
Vote,
Alias,
StarknetEIP712ProposeMessage,
StarknetEIP712UpdateProposalMessage,
StarknetEIP712VoteMessage,
StarknetEIP712AliasMessage,
SignatureData
} from '../../../types';

Expand Down Expand Up @@ -55,6 +57,7 @@ export class StarknetSig {
| StarknetEIP712ProposeMessage
| StarknetEIP712UpdateProposalMessage
| StarknetEIP712VoteMessage
| StarknetEIP712AliasMessage
>(
signer: Account,
verifyingContract: string,
Expand All @@ -74,7 +77,6 @@ export class StarknetSig {
domain,
message
};

const signature = await signer.signMessage(data);

return {
Expand Down Expand Up @@ -198,4 +200,25 @@ export class StarknetSig {
data
};
}

public async setAlias({
signer,
data
}: {
signer: Account;
data: Alias;
}): Promise<Envelope<Alias>> {
const message = {
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
from: signer.address,
timestamp: parseInt((Date.now() / 1e3).toFixed()),
...data
};

const signatureData = await this.sign(signer, '', message, aliasTypes, 'SetAlias');

return {
signatureData,
data
};
}
}
9 changes: 9 additions & 0 deletions packages/sx.js/src/clients/starknet/starknet-sig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ export const updateProposalTypes = {
Strategy: sharedTypes.Strategy,
u256: sharedTypes.u256
};

export const aliasTypes = {
StarkNetDomain: domainTypes.StarkNetDomain,
SetAlias: [
{ name: 'from', type: 'ContractAddress' },
{ name: 'alias', type: 'string' },
{ name: 'timestamp', type: 'felt' }
]
};
12 changes: 11 additions & 1 deletion packages/sx.js/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ export type Vote = {
choice: Choice;
};

export type Message = Propose | Vote | UpdateProposal;
export type Alias = {
alias: string;
};

export type Message = Propose | Vote | UpdateProposal | Alias;

export type SignatureData = {
address: string;
Expand Down Expand Up @@ -180,6 +184,12 @@ export type StarknetEIP712VoteMessage = {
metadataUri: string[];
};

export type StarknetEIP712AliasMessage = {
alias: string;
from?: string;
timestamp?: number;
};

export type EIP712ProposeMessage = StarknetEIP712ProposeMessage & {
authenticator: string;
};
Expand Down
Loading