Skip to content

Commit

Permalink
only pass in pub/priv key
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard-Pat committed Jun 6, 2024
1 parent 2e395c6 commit 0eb6f40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export function buildClaim(
giftAmount: bigint,
giftMaxFee: bigint,
tokenContract: Contract,
claimSigner: LegacyStarknetKeyPair,
claimPubkey: bigint,
): Claim {
const constructorArgs: AccountConstructorArguments = {
sender: deployer.address,
amount: uint256.bnToUint256(giftAmount),
max_fee: giftMaxFee,
token: tokenContract.address,
claim_pubkey: claimSigner.publicKey,
claim_pubkey: claimPubkey,
};
return {
factory: factory.address,
Expand Down Expand Up @@ -91,28 +91,29 @@ export async function claimExternal(
export async function claimInternal(
factory: Contract,
tokenContract: Contract,
claimSigner: LegacyStarknetKeyPair,
giftPrivateKey = "0x42",
claimSignerPrivateKey: string,
claimSignerPublicKey: bigint,
receiverAddress = "0x42",
useTxV3 = false,
giftAmount = GIFT_AMOUNT,
giftMaxFee = GIFT_MAX_FEE,
): Promise<{
claimAccount: Account;
receiver: string;
}> {
const receiver = giftPrivateKey || `0x${encode.buf2hex(ec.starkCurve.utils.randomPrivateKey())}`;
const receiver = receiverAddress || `0x${encode.buf2hex(ec.starkCurve.utils.randomPrivateKey())}`;
const claimAccountClassHash = await manager.declareLocalContract("ClaimAccount");
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
giftAmount,
giftMaxFee,
tokenContract.address,
claimSigner.publicKey,
claimSignerPublicKey,
);
const claim = buildClaim(factory, claimAccountClassHash, giftAmount, giftMaxFee, tokenContract, claimSigner);
const claim = buildClaim(factory, claimAccountClassHash, giftAmount, giftMaxFee, tokenContract, claimSignerPublicKey);
const txVersion = useTxV3 ? RPC.ETransactionVersion.V3 : RPC.ETransactionVersion.V2;
const claimAccount = new Account(manager, num.toHex(claimAddress), claimSigner, undefined, txVersion);
const claimAccount = new Account(manager, num.toHex(claimAddress), claimSignerPrivateKey, undefined, txVersion);
factory.connect(claimAccount);
await factory.claim_internal(claim, receiver);
return { claimAccount, receiver };
Expand Down
9 changes: 8 additions & 1 deletion lib/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ export async function defaultDepositTestSetup(
factory.address,
);

const claim = buildClaim(factory, claimAccountClassHash, giftAmount, giftMaxFee, tokenContract, claimSigner);
const claim = buildClaim(
factory,
claimAccountClassHash,
giftAmount,
giftMaxFee,
tokenContract,
claimSigner.publicKey,
);

const txVersion = useTxV3 ? RPC.ETransactionVersion.V3 : RPC.ETransactionVersion.V2;
const claimAccount = new Account(manager, num.toHex(claimAddress), claimSigner, undefined, txVersion);
Expand Down

0 comments on commit 0eb6f40

Please sign in to comment.