Skip to content
Snippets Groups Projects
Commit 6958c713 authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll: Committed by Bartek Wrona
Browse files

Add signature provider example based on our extensions

parent 27d63828
No related branches found
No related tags found
No related merge requests found
# https://gitlab.syncad.com/hive group specification, offering aggregated package view: https://gitlab.syncad.com/groups/hive/-/packages
@hiveio:registry=https://gitlab.syncad.com/api/v4/groups/136/-/packages/npm/
{
"extends": "@parcel/config-default",
"transformers": {
"*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
}
}
\ No newline at end of file
# signature-extension
> [!WARNING]
> This example will not be ran automatically on the CI as it requires direct user action, e.g. OAuth 3rd party app Hive blockchain user authorization
This example presents different ways of implementing 3rd party apps authorization using wax
To test this example:
1. Install keychain extension
2. Import `guest4test` posting key to your wallet
3. Install dependencies: `pnpm install`
4. Run parcel: `pnpm test`
5. Goto [http://localhost:1234](http://localhost:1234), sign the transaction and check logs
export const accountName = "guest4test";
export const publicKey = "STM8XQJiRBND7q6Cu1kxyRgLVLU3y1B5iGFU5VAqSpaAK38YFGZP8";
export const privateKey = process.env.PRIVATE_KEY as string;
export const voteData = {
voter: accountName,
author: "c0ff33a",
permlink: "ewxhnjbj",
weight: 2200
};
{
"name": "signature-extension",
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "parcel test/index.html"
},
"dependencies": {
"@hiveio/wax": "file:../../../ts",
"@hiveio/wax-signers-keychain": "file:../../../ts/packages/signers-keychain",
"@hiveio/wax-signers-peakvault": "file:../../../ts/packages/signers-peakvault"
},
"devDependencies": {
"@parcel/config-default": "^2.13.3",
"@parcel/transformer-typescript-tsc": "^2.13.3",
"buffer": "^5.5.0||^6.0.0",
"parcel": "^2.13.3",
"process": "^0.11.10"
}
}
<!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>
{
"extends": "../../../ts/tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"outDir": "dist"
},
"include": [
"."
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment