-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add page to generate stacking signature
- Loading branch information
Showing
12 changed files
with
629 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { openStructuredDataSignatureRequestPopup, SignatureData } from '@stacks/connect'; | ||
import { useCallback, useState } from 'react'; | ||
import { useStacksNetwork } from './use-stacks-network'; | ||
import { useStackingClient } from '@components/stacking-client-provider/stacking-client-provider'; | ||
import { | ||
Pox4SignatureTopic, | ||
pox4SignatureMessage, | ||
verifyPox4SignatureHash, | ||
} from '@stacks/stacking'; | ||
|
||
export interface GenerateSignatureOptions { | ||
rewardCycle: number; | ||
poxAddress: string; | ||
period: number; | ||
topic: Pox4SignatureTopic; | ||
} | ||
|
||
export function useGenerateStackingSignature() { | ||
const _stackingClient = useStackingClient(); | ||
const [signatureData, setSignatureData] = useState<SignatureData | null>(null); | ||
const network = useStacksNetwork(); | ||
const openSignatureRequest = useCallback( | ||
async (options: GenerateSignatureOptions) => { | ||
const { message, domain } = pox4SignatureMessage({ | ||
topic: options.topic, | ||
period: options.period, | ||
network: network.network, | ||
rewardCycle: options.rewardCycle, | ||
poxAddress: options.poxAddress, | ||
}); | ||
|
||
await openStructuredDataSignatureRequestPopup({ | ||
domain, | ||
message, | ||
onFinish: data => { | ||
console.log('signature done', data); | ||
const isValid = verifyPox4SignatureHash({ | ||
topic: options.topic, | ||
period: options.period, | ||
network: network.network, | ||
rewardCycle: options.rewardCycle, | ||
poxAddress: options.poxAddress, | ||
signature: data.signature, | ||
publicKey: data.publicKey, | ||
}); | ||
console.log(isValid); | ||
setSignatureData(data); | ||
}, | ||
}); | ||
}, | ||
[network.network, setSignatureData] | ||
); | ||
|
||
return { | ||
openSignatureRequest, | ||
signatureData, | ||
}; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/pages/stacking/generate-signature/components/auth-id.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useField } from 'formik'; | ||
import { Description, Step } from '../../components/stacking-form-step'; | ||
import { Box, Button, Input, Text } from '@stacks/ui'; | ||
import React from 'react'; | ||
import { ErrorLabel } from '@components/error-label'; | ||
import { ErrorText } from '@components/error-text'; | ||
|
||
export function AuthId() { | ||
const [field, meta, helpers] = useField('authId'); | ||
// const form = useFormikContext<{ topic: string }>(); | ||
const setRandom = React.useCallback(() => { | ||
helpers.setValue(Math.floor(Math.random() * 10000000)); | ||
}, [helpers]); | ||
return ( | ||
<Step title="Auth ID"> | ||
<Description> | ||
<Text>A random number that is used to prevent re-use of the signature</Text> | ||
</Description> | ||
<Box position="relative" my="loose"> | ||
<Input id="authId" placeholder="Maximum amount of STX to lock" {...field} /> | ||
{meta.touched && meta.error && ( | ||
<ErrorLabel> | ||
<ErrorText>{meta.error}</ErrorText> | ||
</ErrorLabel> | ||
)} | ||
<Button | ||
type="button" | ||
mode="tertiary" | ||
size="sm" | ||
height="28px" | ||
right="12px" | ||
top="10px" | ||
style={{ position: 'absolute' }} | ||
width="110px" | ||
onClick={setRandom} | ||
// isDisabled={field.value === MAX_U128.toString()} | ||
> | ||
Random | ||
</Button> | ||
</Box> | ||
</Step> | ||
); | ||
} |
Oops, something went wrong.