Skip to content
Snippets Groups Projects

Add signature providers

Merged Mateusz Tyszczak requested to merge tm-sign-ext into develop
7 files
+ 120
0
Compare changes
  • Side-by-side
  • Inline
Files
7
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Signing example</h1>
<h3>Remember to unlock Peak Vault before using it</h3>
<button onclick="useKeychain()">Use Keychain</button>
<button onclick="usePeakVault()">Use Peak Vault</button>
<pre><code id="tx-result"></code></pre>
<script type="module">
import { createHiveChain } from "@hiveio/wax";
import { accountName, publicKey, voteData } from "../common-data";
import KeychainProvider from "@hiveio/wax-signers-keychain";
import PeakVaultProvider from "@hiveio/wax-signers-peakvault";
const txResult = document.getElementById('tx-result');
(async()=> {
const keychainProvider = KeychainProvider.for(accountName, "posting");
const peakVaultProvider = PeakVaultProvider.for(accountName, "posting");
const chain = await createHiveChain();
const createTransaction = async () => {
txResult.textContent = 'Signing...';
const tx = await chain.createTransaction();
tx.pushOperation({
vote: voteData
});
console.log(tx.transaction);
console.log(`Sig digest: ${tx.sigDigest}`);
return tx;
};
const sign = async (provider) => {
try {
const tx = await createTransaction();
await tx.sign(provider);
const apiJson = tx.toApiJson();
console.log('Transaction:', apiJson);
console.log(`Keys match: ${tx.signatureKeys[0] === publicKey}`);
txResult.textContent = JSON.stringify(apiJson, null, 2);
} catch (error) {
console.error(error);
txResult.textContent = `Error: ${error.message}`;
}
};
window.useKeychain = () => void sign(keychainProvider);
window.usePeakVault = () => void sign(peakVaultProvider);
})();
</script>
</body>
</html>
Loading