Skip to content

Commit 5117680

Browse files
update offline public tx signing
1 parent 1bcd379 commit 5117680

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

create-leo-app/template-offline-public-transaction-ts/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function preDownloadTransferKeys() {
2828
const keysDirPath = path.join(__dirname, "keys");
2929
await fsPromises.mkdir(keysDirPath, { recursive: true });
3030

31-
for (const keyData of [CREDITS_PROGRAM_KEYS.transfer_public, CREDITS_PROGRAM_KEYS.fee_public]) {
31+
for (const keyData of [CREDITS_PROGRAM_KEYS.transfer_public, CREDITS_PROGRAM_KEYS.fee_public, CREDITS_PROGRAM_KEYS.transfer_public_as_signer]) {
3232
try {
3333
keyPaths[keyData.locator] = await downloadAndSaveKey(keyData, keysDirPath);
3434
} catch (error) {

create-leo-app/template-offline-public-transaction-ts/src/index.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n
1717
const feePublicKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.fee_public.locator]);
1818
const transferPublicAsSignerKeyBytes = await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator]);
1919
const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
20-
const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicAsSignerKeyBytes);
21-
20+
const transferPublicProvingKey = ProvingKey.fromBytes(
21+
await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.transfer_public.locator])
22+
);
23+
2224
// Create an offline key provider
2325
console.log("Creating offline key provider");
2426
const offlineKeyProvider = new OfflineKeyProvider();
@@ -27,10 +29,25 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n
2729
// keys into the key manager.
2830
console.log("Inserting proving keys into key provider");
2931
offlineKeyProvider.insertFeePublicKeys(feePublicProvingKey);
32+
33+
try {
3034
offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);
35+
console.log("Successfully inserted proving key");
36+
} catch (err) {
37+
console.error("Failed to insert proving key:", err);
38+
}
39+
3140

3241
// Create an offline query to complete the inclusion proof
33-
const offlineQuery = new OfflineQuery(latestStateRoot);
42+
let offlineQuery: OfflineQuery;
43+
const blockHeight = 0;
44+
// TODO this is a placeholder block height for now, which offlineQuery now requires
45+
try {
46+
const offlineQuery = new OfflineQuery(blockHeight, latestStateRoot);
47+
console.log("Successfully created OfflineQuery", offlineQuery);
48+
} catch (err) {
49+
console.error("Failed to create OfflineQuery:", err);
50+
}
3451

3552
// Insert the key provider into the program manager
3653
programManager.setKeyProvider(offlineKeyProvider);
@@ -84,13 +101,10 @@ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress:
84101
// Build the bonding transactions offline
85102
console.log("Building a bond_public execution transaction offline");
86103
const bondPublicOptions = {
87-
executionParams: {
88-
keySearchParams: OfflineSearchParams.bondPublicKeyParams()
89-
},
90-
offlineParams: {
91-
offlineQuery: new OfflineQuery(latestStateRoot)
92-
}
93-
}
104+
keySearchParams: OfflineSearchParams.bondPublicKeyParams(),
105+
offlineQuery: new OfflineQuery(latestStateRoot)
106+
};
107+
94108

95109
const bondTx = <Transaction>await programManager.buildBondPublicTransaction(
96110
stakerAddress.to_string(),
@@ -103,27 +117,19 @@ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress:
103117

104118
console.log("Building an unbond_public execution transaction offline")
105119
const unbondPublicOptions = {
106-
executionParams: {
107-
keySearchParams: OfflineSearchParams.unbondPublicKeyParams()
108-
},
109-
offlineParams: {
110-
offlineQuery: new OfflineQuery(latestStateRoot)
111-
}
112-
}
120+
keySearchParams: OfflineSearchParams.unbondPublicKeyParams(),
121+
offlineQuery: new OfflineQuery(latestStateRoot)
122+
};
113123

114124
const unBondTx = <Transaction>await programManager.buildUnbondPublicTransaction(stakerAddress.to_string(), amount, unbondPublicOptions);
115125
console.log("\nunbond_public transaction built!\n");
116126

117127
console.log("Building a claim_unbond_public transaction offline")
118128
// Build the claim unbonding transaction offline
119129
const claimUnbondPublicOptions = {
120-
executionParams: {
121-
keySearchParams: OfflineSearchParams.claimUnbondPublicKeyParams()
122-
},
123-
offlineParams: {
124-
offlineQuery: new OfflineQuery(latestStateRoot)
125-
}
126-
}
130+
keySearchParams: OfflineSearchParams.claimUnbondPublicKeyParams(),
131+
offlineQuery: new OfflineQuery(latestStateRoot)
132+
};
127133

128134
const claimUnbondTx = <Transaction>await programManager.buildClaimUnbondPublicTransaction(stakerAddress.to_string(), claimUnbondPublicOptions);
129135
console.log("\nclaim_unbond_public transaction built!\n");

0 commit comments

Comments
 (0)