|
6 | 6 | AccountAuthenticator, |
7 | 7 | AccountAuthenticatorEd25519, |
8 | 8 | AccountAuthenticatorSingleKey, |
| 9 | + MoveVector, |
| 10 | + U8, |
9 | 11 | } from "../../../src"; |
10 | 12 | import { longTestTimeout } from "../../unit/helper"; |
11 | 13 | import { getAptosClient } from "../helper"; |
@@ -216,3 +218,46 @@ describe("sign transaction", () => { |
216 | 218 | }); |
217 | 219 | }); |
218 | 220 | }); |
| 221 | + |
| 222 | +test.only("test", async () => { |
| 223 | + const fromAccount = Account.generate(); |
| 224 | + const newAccount = Account.generate(); |
| 225 | + |
| 226 | + await aptos.fundAccount({ accountAddress: fromAccount.accountAddress, amount: 1_000_000_000 }); |
| 227 | + await aptos.fundAccount({ accountAddress: newAccount.accountAddress, amount: 1_000_000_000 }); |
| 228 | + |
| 229 | + const accountInfo = await aptos.getAccountInfo({ |
| 230 | + accountAddress: fromAccount.accountAddress, |
| 231 | + }); |
| 232 | + |
| 233 | + const challenge = await aptos.createProofChallenge({ |
| 234 | + struct: "0x1::account::RotationProofChallenge", |
| 235 | + data: [ |
| 236 | + BigInt(accountInfo.sequence_number), |
| 237 | + fromAccount.accountAddress, |
| 238 | + accountInfo.authentication_key, |
| 239 | + newAccount.publicKey.toUint8Array(), |
| 240 | + ], |
| 241 | + }); |
| 242 | + |
| 243 | + const proofSignedByCurrentPrivateKey = aptos.signProofChallenge({ challenge, signer: fromAccount }); |
| 244 | + const proofSignedByNewPrivateKey = aptos.signProofChallenge({ challenge, signer: newAccount }); |
| 245 | + |
| 246 | + const transaction = await aptos.transaction.build.simple({ |
| 247 | + sender: fromAccount.accountAddress, |
| 248 | + data: { |
| 249 | + function: "0x1::account::rotate_authentication_key", |
| 250 | + functionArguments: [ |
| 251 | + new U8(fromAccount.signingScheme), // from scheme |
| 252 | + MoveVector.U8(fromAccount.publicKey.toUint8Array()), |
| 253 | + new U8(newAccount.signingScheme), // to scheme |
| 254 | + MoveVector.U8(newAccount.publicKey.toUint8Array()), |
| 255 | + MoveVector.U8(proofSignedByCurrentPrivateKey.toUint8Array()), |
| 256 | + MoveVector.U8(proofSignedByNewPrivateKey.toUint8Array()), |
| 257 | + ], |
| 258 | + }, |
| 259 | + }); |
| 260 | + |
| 261 | + const response = await aptos.signAndSubmitTransaction({ signer: fromAccount, transaction }); |
| 262 | + console.log("response", response); |
| 263 | +}); |
0 commit comments