Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/wax
1 result
Show changes
Commits on Source (4)
......@@ -271,34 +271,42 @@ private_key_data foundation::cpp_generate_private_key(const std::string& account
std::string foundation::cpp_convert_raw_private_key_to_wif(const std::string& hexData)
{
FC_ASSERT(hexData.size() == 64 && "Expected hex string pointing 32 byte buffer");
return cpp::safe_exception_wrapper(
[&]() -> std::string {
FC_ASSERT(hexData.size() == 64 && "Expected hex string pointing 32 byte buffer");
fc::sha256 sharedSecret(hexData);
fc::sha256 sharedSecret(hexData);
return fc::ecc::private_key::regenerate(sharedSecret).key_to_wif();
return fc::ecc::private_key::regenerate(sharedSecret).key_to_wif();
}
);
}
std::string foundation::cpp_convert_raw_public_key_to_wif(const std::string& hexData)
{
if(hexData.size() == 2 * sizeof(fc::ecc::public_key_data))
{
/// compressed form
fc::ecc::public_key_data keyData;
detail::convert_from_hex(hexData, keyData);
return cpp::safe_exception_wrapper(
[&]() -> std::string {
if(hexData.size() == 2 * sizeof(fc::ecc::public_key_data))
{
/// compressed form
fc::ecc::public_key_data keyData;
detail::convert_from_hex(hexData, keyData);
return fc::ecc::public_key::to_base58_with_prefix(keyData, HIVE_ADDRESS_PREFIX);
return fc::ecc::public_key::to_base58_with_prefix(keyData, HIVE_ADDRESS_PREFIX);
}
else
{
FC_ASSERT(hexData.size() == 2 * sizeof(fc::ecc::public_key_point_data), "Invalid size of raw public key buffer: ${s}", ("s", (hexData.size())));
/// uncompressed form
fc::ecc::public_key_point_data keyData;
detail::convert_from_hex(hexData, keyData);
}
else
{
FC_ASSERT(hexData.size() == 2 * sizeof(fc::ecc::public_key_point_data), "Invalid size of raw public key buffer: ${s}", ("s", (hexData.size())));
/// uncompressed form
fc::ecc::public_key_point_data keyData;
detail::convert_from_hex(hexData, keyData);
fc::ecc::public_key key(keyData);
return key.to_base58_with_prefix(HIVE_ADDRESS_PREFIX);
}
fc::ecc::public_key key(keyData);
return key.to_base58_with_prefix(HIVE_ADDRESS_PREFIX);
}
}
);
}
brain_key_data foundation::cpp_suggest_brain_key()
......
# 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
......@@ -848,6 +848,22 @@ test.describe('Wax object interface foundation tests', () => {
expect(retVal).toBe('5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n');
});
test('Should be able to convert between raw compressed public key -> WIF formats', async ({ waxTest }) => {
const retVal = await waxTest(({ base }) => {
return base.convertRawPublicKeyToWif('02be643d4c424ac7cf2f3cf51dd048773cbdcee30b111adb30d89c27668c501705');
});
expect(retVal).toBe('STM6LLegbAgLAy28EHrffBVuANFWcFgmqRMW13wBmTExqFE9SCkg4');
});
test('Should be able to convert between raw uncompressed public key -> WIF formats', async ({ waxTest }) => {
const retVal = await waxTest(({ base }) => {
return base.convertRawPublicKeyToWif('04be643d4c424ac7cf2f3cf51dd048773cbdcee30b111adb30d89c27668c5017051a9cc2866c479818522ffd2b4a3d7a5a64d1b98c968f8f6ea2ef6745a637eb92');
});
expect(retVal).toBe('STM6LLegbAgLAy28EHrffBVuANFWcFgmqRMW13wBmTExqFE9SCkg4');
});
test('Should be able to estimate hive collateral', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.estimateHiveCollateral(201, 1000, 197, 1000, 100000);
......
......@@ -493,6 +493,11 @@ export class WaxBaseApi implements IWaxBaseInterface {
return wif;
}
public convertRawPublicKeyToWif(rawPublicKey: THexString): string {
const wif = safeWasmCall(() => this.proto.cpp_convert_raw_public_key_to_wif(rawPublicKey));
return wif;
}
public calculateAccountHp(vests: TNaiAssetSource, totalVestingFundHive: TNaiAssetSource, totalVestingShares: TNaiAssetSource): NaiAsset {
const vestsAsset = this.createAssetWithRequiredSymbol(EAssetName.VESTS, vests);
const totalVestingFundHiveAsset = this.createAssetWithRequiredSymbol(EAssetName.HIVE, totalVestingFundHive);
......
......@@ -831,6 +831,13 @@ export interface IWaxBaseInterface {
*/
convertRawPrivateKeyToWif(rawPrivateKey: THexString): string;
/**
* Allows to convert raw public key to WIF format.
* @param rawPublicKey 33 or 65 bytes buffer (doubled characters hex string) representing compressed or uncompressed public key data
* @returns WIF formatted public key (including prefix)
*/
convertRawPublicKeyToWif(rawPublicKey: THexString): string;
/**
* Encrypts given data using two keys and dumps result to the encrypted string in `#encrypted` format
*
......