Skip to content

Commit

Permalink
feat: add verifySignerKeySignature read-only to StackingClient
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Apr 19, 2024
1 parent f067847 commit 9ddbf9b
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
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

0 comments on commit 9ddbf9b

Please sign in to comment.