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 verify signer sig #1676

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion packages/stacking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const maxAmount = 100000000000n;
// the auth id of the signer (a random id to not allow reusing the signature)
const authId = 702;

const signerPrivateKey = makeRandomPrivKey(); // replace with your signer private key

const signature = client.signPoxSignature({
topic: 'stack-stx', // the topic of the transaction
poxAddress,
Expand All @@ -92,7 +94,7 @@ const signature = client.signPoxSignature({
```

> [!WARNING]
> Make sure to replace `signerPrivateKey` with the signer private key of your setup.
> Make sure to replace `signerPrivateKey` with the signer private key of your setup and keep it private.

### Topics

Expand Down
53 changes: 53 additions & 0 deletions packages/stacking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
principalCV,
principalToString,
someCV,
stringAsciiCV,
uintCV,
validateStacksAddress,
} from '@stacks/transactions';
Expand Down Expand Up @@ -1541,6 +1542,58 @@ export class StackingClient {
});
}

/**
* Call the `verify-signer-key-sig` read-only function on the PoX contract.
* @returns (async) a boolean indicating if the signature is valid
*/
async verifySignerKeySignature({
topic,
poxAddress,
rewardCycle,
period,
signerSignature,
signerKey,
amount,
maxAmount,
authId,
}: {
topic: string;
poxAddress: string;
rewardCycle: number;
period: number;
signerSignature?: string;
signerKey: string;
amount: IntegerType;
maxAmount: IntegerType;
authId: IntegerType;
}): Promise<boolean> {
const poxInfo = await this.getPoxInfo();

const [contractAddress, contractName] = this.parseContractId(poxInfo.contract_id);
const functionName = 'verify-signer-key-sig';

const functionArgs = [
poxAddressToTuple(poxAddress),
uintCV(rewardCycle),
stringAsciiCV(topic),
uintCV(period),
signerSignature ? someCV(bufferCV(hexToBytes(signerSignature))) : noneCV(),
bufferCV(hexToBytes(signerKey)),
uintCV(amount),
uintCV(maxAmount),
uintCV(authId),
];

return callReadOnlyFunction({
contractAddress,
contractName,
functionName,
functionArgs,
network: this.network,
senderAddress: this.address,
}).then(responseCV => responseCV.type === ClarityType.ResponseOk);
}

/**
* @returns {Promise<string>} that resolves to the contract id (address and name) to use for stacking
*/
Expand Down
Loading
Loading